D
Deno

help

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

Sstarblade3/11/2024
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 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)
DAHDeno AI Helper3/12/2024
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.
DAHDeno AI Helper3/12/2024
🦕 Oops! Can you pinpoint where I went wrong to help me improve? 📈
Sstarblade3/12/2024
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.
Sstarblade3/12/2024
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.

Looking for more? Join the community!

Recommended Posts
Is there an easy way to read tls certificate and key from a filesystem?I do the following: ```js if (Deno.env.has("TLS_CERT_PATH") && Deno.env.has("TLS_PKEY_PATH")) { coPartials in a redirect ???Does anyone have any idea how i can redirect after login to a route with initialised partial: ExamHow to troubleshoot runaway (100% CPU) deno processDeno has been running a couple of websites rock solid for many months. But during last week or so I'Import SCSS in TS filesHey, I am currently building a template for web development and I want to use ESBuild as a bundler. How to modify HTTP cache folderHello, I'm using Astro framework with Deno and Directus, but after a while of the website running onDeno deployment can't connect to the Mongo Cloud, due to the Mongo Cloud Network Access Rules.Is there a way to add the Deno Deploy IP to Mongo Cloud? The Deno Depoy Regions only region names fIs there a way to pull a module from x in favour of jsr?I have ported my module `@vicary/fresh-graphql` to JSR and I would like to redirect my users go JSR In-Source Testing with deno test?Can I do something like [vitest's In-Source Testing](https://vitest.dev/guide/in-source.html) with `How to use vendoring with node_modulesAs trying to recreate a `DENO_DIR` via `deno cache` creates different results on different machines,Make an image cropper that crops from data uriHow to make an image cropper that crops to the given dimensionsBest practice for releasing a deno package on GitHubIs there a best practice for the release process of a Deno library on GitHub? I use semantic-releasedeno oak : howto force reply immediatly, and process the request later ?Bonjour, My server needs to reply an ACK (200 OK) for each request. If it did not, the client dies.