starblade
starblade•5mo ago

Problems using @apple/app-store-server-library, how do I debug?

Hi, I'm attempting to build out the backend of an IOS app on Supabase and want to be able to verify the purchase of in-app purchases using an edge function. I have a block of code working perfectly in nodejs on my local machine i.e.,
import { AppStoreServerAPIClient, Environment, SignedDataVerifier } from "@apple/app-store-server-library";
import { AppStoreServerAPIClient, Environment, SignedDataVerifier } from "@apple/app-store-server-library";
When I go to use this library inside of an edge function I'm getting errors pop up inside of dependencies of the app-store-server-library module. I've tried the import using the npm: prefix like so
import pkg from "npm:@apple/app-store-server-library";
const { AppStoreServerAPIClient, Environment, SignedDataVerifier } = pkg;
import pkg from "npm:@apple/app-store-server-library";
const { AppStoreServerAPIClient, Environment, SignedDataVerifier } = pkg;
And when i attempt to run my code I get this error
Error getting transaction history Error: "alg" parameter "ES256" requires curve "prime256v1".
at module.exports (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/jsonwebtoken/9.0.2/lib/validateAsymmetricKey.js:46:15)
at module.exports [as sign] (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/jsonwebtoken/9.0.2/sign.js:179:7)
at AppStoreServerAPIClient.createBearerToken (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:323:29)
at AppStoreServerAPIClient.makeRequest (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:93:47)
at AppStoreServerAPIClient.getTransactionInfo (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:285:27)
at getTransactionInformation (file:///home/deno/functions/_shared/apple-helpers.ts:49:31)
at eventLoopTick (ext:core/01_core.js:64:7)
at async Object.handler (file:///home/deno/functions/apple-pay-test/index.ts:14:16)
at async handleHttp (ext:sb_core_main_js/js/http.js:102:17)
Error getting transaction history Error: "alg" parameter "ES256" requires curve "prime256v1".
at module.exports (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/jsonwebtoken/9.0.2/lib/validateAsymmetricKey.js:46:15)
at module.exports [as sign] (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/jsonwebtoken/9.0.2/sign.js:179:7)
at AppStoreServerAPIClient.createBearerToken (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:323:29)
at AppStoreServerAPIClient.makeRequest (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:93:47)
at AppStoreServerAPIClient.getTransactionInfo (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@apple/app-store-server-library/1.0.1/dist/index.js:285:27)
at getTransactionInformation (file:///home/deno/functions/_shared/apple-helpers.ts:49:31)
at eventLoopTick (ext:core/01_core.js:64:7)
at async Object.handler (file:///home/deno/functions/apple-pay-test/index.ts:14:16)
at async handleHttp (ext:sb_core_main_js/js/http.js:102:17)
This is my first time using Deno and I'm feeling a little lost. Any help is appreciated! Thanks
5 Replies
starblade
starblade•5mo ago
I've also tried using esm.sh like so:
import pkg from "https://esm.sh/@apple/app-store-server-library";
const { AppStoreServerAPIClient, Environment, SignedDataVerifier } = pkg;
import pkg from "https://esm.sh/@apple/app-store-server-library";
const { AppStoreServerAPIClient, Environment, SignedDataVerifier } = pkg;
which results in a different error:
Error getting transaction history TypeError: Right-hand side of 'instanceof' is not an object
at de.exports [as sign] (https://esm.sh/v135/jsonwebtoken@9.0.2/esnext/jsonwebtoken.mjs:21:10119)
at e.createBearerToken (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:44515)
at e.makeRequest (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:41417)
at e.getTransactionInfo (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:43969)
at getTransactionInformation (file:///home/deno/functions/_shared/apple-helpers.ts:49:31)
at eventLoopTick (ext:core/01_core.js:64:7)
at async Object.handler (file:///home/deno/functions/apple-pay-test/index.ts:14:16)
at async handleHttp (ext:sb_core_main_js/js/http.js:102:17)
Error getting transaction history TypeError: Right-hand side of 'instanceof' is not an object
at de.exports [as sign] (https://esm.sh/v135/jsonwebtoken@9.0.2/esnext/jsonwebtoken.mjs:21:10119)
at e.createBearerToken (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:44515)
at e.makeRequest (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:41417)
at e.getTransactionInfo (https://esm.sh/v135/@apple/app-store-server-library@1.0.1/esnext/app-store-server-library.mjs:14:43969)
at getTransactionInformation (file:///home/deno/functions/_shared/apple-helpers.ts:49:31)
at eventLoopTick (ext:core/01_core.js:64:7)
at async Object.handler (file:///home/deno/functions/apple-pay-test/index.ts:14:16)
at async handleHttp (ext:sb_core_main_js/js/http.js:102:17)
Deno AI Helper
Deno AI Helper•5mo ago
I'm sorry, but I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, it seems like you're encountering an issue with the @apple/app-store-server-library when trying to use it within an edge function in Deno. The error message you're seeing suggests that there is a problem with the algorithm parameter "ES256" which requires the curve "prime256v1". This could be related to the cryptographic operations that the library is trying to perform. While I cannot provide a solution based on the Deno documentation, I can suggest that you ensure that the cryptographic libraries and dependencies used by @apple/app-store-server-library are compatible with the Deno runtime environment. It's possible that the library or its dependencies might be using Node.js-specific APIs or features that are not available or work differently in Deno. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. Since this is your first time using Deno and you're feeling a bit lost, I would recommend reaching out to the community or the maintainers of the @apple/app-store-server-library for further assistance, as they might have more experience with this specific library and its compatibility with Deno.
Deno AI Helper
Deno AI Helper•5mo ago
🦕 Oops! Can you pinpoint where I went wrong to help me improve? 📈
starblade
starblade•5mo ago
I'm still working on this and still stuck. I'm now able to reproduce the problem locally using the deno command line utility. I've got it hooked up to a debugger and I've pinpointed the resulting issue but still can't figure out the underlying cause or how to fix it. In the end some cryptographic named curve is coming back as 'p256' in deno but it comes back as 'prime256v1' in node, which is causing the error to be thrown in the jsonwebtoken library when it attempts to validate the key. I'm debugging into a file called ext:deno_node/internal/crypto/keys.ts
export function createPrivateKey(key) {
const { data, format, type } = prepareAsymmetricKey(key);
const details = op_node_create_private_key(data, format, type);
const handle = setOwnedKey(copyBuffer(data));
return new PrivateKeyObject(handle, details);
}
export function createPrivateKey(key) {
const { data, format, type } = prepareAsymmetricKey(key);
const details = op_node_create_private_key(data, format, type);
const handle = setOwnedKey(copyBuffer(data));
return new PrivateKeyObject(handle, details);
}
The op_node_create_private_key function is the first instance of the string 'p256' I can see appearing in my program, but I can't step into it.
starblade
starblade•5mo ago
GitHub
deno/ext/node/ops/crypto/mod.rs at c10d96cb21d5f75b4c6f7b7d8d96d12a...
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.