PeculiarVentures / webcrypto

A WebCrypto Polyfill for NodeJS
MIT License
185 stars 23 forks source link

crypto3.getCiphers is not a function #70

Open cre8 opened 9 months ago

cre8 commented 9 months ago

I am using your package in one of my subpackages in the browser with Angular. However when I call it, I am getting this error:

webcrypto.es.js:2233 Uncaught TypeError: crypto3.getCiphers is not a function
    at new SubtleCrypto2 (webcrypto.es.js:2233:32)
    at new Crypto2 (webcrypto.es.js:2276:23)
    at node_modules/@transmute/web-crypto-key-pair/dist/web-crypto-key-pair.esm.js (web-crypto-key-pair.esm.js:814:27)
    at __init (chunk-QPLMLQ3O.js?v=8ada0fd4:45:56)
    at node_modules/@transmute/json-web-signature/dist/json-web-signature.esm.js (json-web-signature.esm.js:5:1)
    at __init (chunk-QPLMLQ3O.js?v=8ada0fd4:45:56)
    at node_modules/@cef-ebsi/verifiable-credential/dist/index.js (index.js:18:30)
    at __require2 (chunk-QPLMLQ3O.js?v=8ada0fd4:48:50)
    at node_modules/@cef-ebsi/verifiable-presentation/dist/index.js (index.js:20:33)
    at __require2 (chunk-QPLMLQ3O.js?v=8ada0fd4:48:50)

I am using esbuild and added the polyfills like

import { polyfillNode } from 'esbuild-plugin-polyfill-node';

export default polyfillNode();

On the backend it's working fine, it seems to be a problem with the browser. Do you know if there needs to be an extra import?

lemoustachiste commented 2 months ago

Did you find a fix for that?

I have a suspicion it could be a collusion with another crypto polyfill library but I'm still investigating.

cre8 commented 2 months ago

Did you find a fix for that?

I have a suspicion it could be a collusion with another crypto polyfill library but I'm still investigating.

I am not working on the project anymore (no access anymore) so I don't know if this could be the problem...

lemoustachiste commented 2 months ago

For maintainers I have tried to turn things around but the problem persist.

So getCiphers is used here: https://github.com/PeculiarVentures/webcrypto/blob/919c67e3d578d06916e3f57a070d3ad5ebef19d5/src/subtle.ts#L34, and if I manually remove the call I get a subsequent error on getHashes https://github.com/PeculiarVentures/webcrypto/blob/919c67e3d578d06916e3f57a070d3ad5ebef19d5/src/subtle.ts#L80.

Those functions come from crypto (node:crypto) as imported here https://github.com/PeculiarVentures/webcrypto/blob/919c67e3d578d06916e3f57a070d3ad5ebef19d5/src/subtle.ts#L1.

However, it seems that getCiphers and getHashes have been deprecated from node 20, as they don't appear in the docs anymore from that version.

I also couldn't find getCiphers in polyfill libraries for rollup and vite, and only this mention of getHashes in this licence (https://github.com/FredKSchott/rollup-plugin-polyfill-node/blob/31face71b94b8408a907f04753318dff589adc2f/polyfills/LICENSE-crypto-browserify.txt#L55), which means I cannot inject them in my browser build either.

What do you advise from here?

microshine commented 2 months ago

I don't see any indication that these methods are deprecated. They are still present in the documentation for version v22:

If you're trying to build your application using Rollup for Node.js, you should exclude the crypto module from the bundle to prevent it from being included.

If you're building the application for the browser, use the native crypto module instead of @peculiar/webcrypto, as that module is intended for implementing the WebCrypto API in Node.js.

lemoustachiste commented 2 months ago

Thanks for checking the docs, I swear I couldn't find them.

If you're building the application for the browser, use the native crypto module instead of @peculiar/webcrypto, as that module is intended for implementing the WebCrypto API in Node.js.

My main problem here is that webcrypto supports secp256k1 which the original crypto does not, in the browser or in nodejs.

microshine commented 1 month ago

Try webcrypto-liner. It supports the K-256 named curve.