Skip to content

Commit 17a54d2

Browse files
committed
refactor(experimental): make the polyfill set the crypto global in Node
1 parent 3dfbca7 commit 17a54d2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

packages/webcrypto-ed25519-polyfill/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"node": ">=17.4"
6363
},
6464
"dependencies": {
65-
"@noble/ed25519": "^2.0.0"
65+
"@noble/ed25519": "^2.0.0",
66+
"crypto-impl": "workspace:*"
6667
},
6768
"devDependencies": {
6869
"@solana/eslint-config-solana": "^1.0.2",

packages/webcrypto-ed25519-polyfill/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import cryptoImpl from 'crypto-impl';
2+
13
import {
24
exportKeyPolyfill,
35
generateKeyPolyfill,
@@ -7,6 +9,14 @@ import {
79
verifyPolyfill,
810
} from './secrets';
911

12+
if (__NODEJS__) {
13+
/**
14+
* Node only sets the `crypto` global variable when run with `--experimental-global-webcrypto`.
15+
* Let's set it unconditionally here.
16+
*/
17+
globalThis.crypto ||= cryptoImpl;
18+
}
19+
1020
if (!__BROWSER__ || globalThis.isSecureContext) {
1121
/**
1222
* Create `crypto.subtle` if it doesn't exist.

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)