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

crypto3.getCiphers is not a function #70

Open
cre8 opened this issue Jan 30, 2024 · 6 comments
Open

crypto3.getCiphers is not a function #70

cre8 opened this issue Jan 30, 2024 · 6 comments

Comments

@cre8
Copy link

cre8 commented Jan 30, 2024

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
Copy link

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
Copy link
Author

cre8 commented Sep 15, 2024

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
Copy link

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

So getCiphers is used here:

const ciphers = crypto.getCiphers();
, and if I manually remove the call I get a subsequent error on getHashes
const hashes = crypto.getHashes();
.

Those functions come from crypto (node:crypto) as imported here

import crypto from "crypto";
.

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
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator

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

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

No branches or pull requests

3 participants