SyntaxError: Could not find export 'diffieHellman' in module 'crypto'
- Dominant language
- Rust
- Stars
- 8.8k
- Forks
- 393
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 45
Description
It appears that all of `crypto` is not in the build? When I try to run `verify()` below I get an error. This use case is for verifying a JWT with a public key using the `jose` library. We have a lambda authorizer that reads the JWT from a cookie and verifies it using a public key.
```typescript
import * as jose from 'jose';
async function verify({ jwt, publicKeyBase64 }: { jwt: string; publicKeyBase64: string; }) {
const publicKey: jose.KeyLike = await createPublicKeyFromBase64String(publicKeyBase64);
//we're passing in the issuer so we can quickly ignore any jwts that don't have expected values
const verifyResult = await jose.jwtVerify(jwt, publicKey, {
issuer: JWT_ISSUER,
//prevent algorith confusion attacks: https://portswigger.net/web-security/jwt/algorithm-confusion
algorithms: [JWT_ALGORITHM],
//prevent the scenario where a valid token was made with a very distant expiration
maxTokenAge: 60 * 30,
//add a small clock tolerance.. this can help with tests and enforcing maxTokenAge which requires 'iat' to be in the past.
//if 'iat' is the same at Date.now(), the test will fail
clockTolerance: 5,
});
return verifyResult.payload as Record;
}
function chunkSubstr(str: string, size: number) {
const numChunks = Math.ceil(str.length / size);
const chunks: string[] = new Array(numChunks);
for (let i = 0, o = 0; i < numChunks; ++i, o += size) {
chunks[i] = str.substring(o, o + size);
}
return chunks;
}
async function createPublicKeyFromBase64String(publicKeyBase64: string) {
const publicKeyIn64CharLines = chunkSubstr(publicKeyBase64, 64).join('\n');
const str = `-----BEGIN PUBLIC KEY-----\n${publicKeyIn64CharLines}\n-----END PUBLIC KEY-----`;
return await jose.importSPKI(str, JWT_ALGORITHM);
}
```
Contributor guide
Research direction
Start by reproducing the missing `diffieHellman` export while running the reported `jose.jwtVerify` and `jose.importSPKI` flow in LLRT. Trace the `crypto` module entry point and compare its exports with what `jose` requires; done means the supplied public-key JWT verification example no longer fails with this export error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100