Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report — Runtime APIs: Error: [unenv] crypto.X509Certificate is not implemented yet! #2720

Open
1yasa opened this issue Sep 17, 2024 · 4 comments · Fixed by unjs/unenv#310

Comments

@1yasa
Copy link

1yasa commented Sep 17, 2024

Codes:
截屏2024-09-17 20 47 22

Error:
截屏2024-09-17 20 47 00

Crypto supports on workers doc:
截屏2024-09-17 20 48 44

Config:
截屏2024-09-17 20 50 08

So my question is, why does the official website state that it supports crypto.X509Certificate, and in the code, it can also print out that X509Certificate is an anonymous class, why does it report an error when used: Error: [unenv] crypto.X509Certificate is not implemented yet!

Both local and deploy to the server.

I really need help with this; if Cloudflare can't use the X509Certificate, it will be very troublesome!

@1yasa
Copy link
Author

1yasa commented Sep 17, 2024

Success with compatibility_flags = ["nodejs_compat"]:
image

But compatibility_flags = ["nodejs_compat_v2"] can treat cryptp as node:crypto, even import * from 'crypto' in packages, it use unenv as polyfills for nodejs apis, However, when it polyfills the crypto module for Node.js, it ignores the internal implementation of workerd.

So is there a way to merge the Node.js API implementation of workerd with that of unenv (using workerd's implementation when the API is not implemented in unenv, instead of throwing an Error: [unenv] crypto.X509Certificate is not implemented yet!)?

@IgorMinar
Copy link
Collaborator

it's because this code is outdated now that we have a native crypto implementation:

https://github.com/unjs/unenv/blob/main/src/runtime/node/crypto/%24cloudflare.ts#L12-L41

related issue: #2097

more recent discussion on how to stay up to date: unjs/unenv#294

@anonrig
Copy link
Member

anonrig commented Sep 18, 2024

This will be fixed with the next release.

@1yasa
Copy link
Author

1yasa commented Sep 19, 2024

This will be fixed with the next release.

image

Unrecognized or unimplemented EC curve \"id-ecPublicKey\" requested when use crypto with compatibility_flags = ["nodejs_compat"].

Here is the error source:

https://github.com/agisboye/app-store-server-api/blob/main/src/Decoding.ts#L47

截屏2024-09-19 21 16 03

Here is the error detail:
截屏2024-09-19 21 17 04

So my question is, the X509 implemented by workerd seems to be completely unusable when using the decodeJWS function of /app-store-server-api.

Did I make a mistake, or does the X509 implementation in workerd indeed throw an error when trying to get the public key with cert.publicKey? Below is my business code (for reproduction):

const app_store_api = getAppStoreApi()
const res_subscription = await app_store_api.getSubscriptionStatuses(tid!)

const item = res_subscription.data[0].lastTransactions.find(item => item.originalTransactionId === tid)!

const res_transaction = await decodeTransaction(item.signedTransactionInfo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants