PeculiarVentures / PKI.js

PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
http://pkijs.org
Other
1.25k stars 204 forks source link

`crypto` parameter is not passed on in AuthenticatedSafe #379

Open zner0L opened 1 year ago

zner0L commented 1 year ago

While developing for nodejs, I got an:

Error: Please call 'setEngine' before call to 'getEngine'

I didn’t call setEngine() because I pass the crypto engine to each function myself. I instantiated the engine like this:

import { webcrypto } from 'crypto';
const crypto = new CryptoEngine({ name: 'node-webcrypto', crypto: webcrypto as Crypto });

The stack trace told me the error originated in AuthenticatedSafe.makeInternalValues(), so I looked there if maybe the crypto param wasn’t passed down, and I think I found the culprit here:

https://github.com/PeculiarVentures/PKI.js/blob/469c403d102ee5149e8eb9ad19754c9696ed7c55/src/AuthenticatedSafe.ts#L304

My node version: v18.14.2