22// so extract it separately from the other exports
33import {
44 Cipher ,
5- Cipheriv ,
65 constants ,
76 createCipher ,
8- createCipheriv ,
97 createDecipher ,
10- createDecipheriv ,
11- createECDH ,
12- createSign ,
13- createVerify ,
148 Decipher ,
15- Decipheriv ,
16- diffieHellman ,
17- ECDH ,
18- getCipherInfo ,
19- hash ,
20- privateDecrypt ,
21- privateEncrypt ,
229 pseudoRandomBytes ,
23- publicDecrypt ,
24- publicEncrypt ,
25- Sign ,
26- sign ,
2710 webcrypto as unenvCryptoWebcrypto ,
28- Verify ,
29- verify ,
3011} from "unenv/node/crypto" ;
3112import type nodeCrypto from "node:crypto" ;
3213
33- export {
34- Cipher ,
35- Cipheriv ,
36- Decipher ,
37- Decipheriv ,
38- ECDH ,
39- Sign ,
40- Verify ,
41- constants ,
42- createCipheriv ,
43- createDecipheriv ,
44- createECDH ,
45- createSign ,
46- createVerify ,
47- diffieHellman ,
48- getCipherInfo ,
49- hash ,
50- privateDecrypt ,
51- privateEncrypt ,
52- publicDecrypt ,
53- publicEncrypt ,
54- sign ,
55- verify ,
56- } from "unenv/node/crypto" ;
14+ export { Cipher , constants , Decipher } from "unenv/node/crypto" ;
5715
5816const workerdCrypto = process . getBuiltinModule ( "node:crypto" ) ;
5917
60- // TODO: Ideally this list is not hardcoded but instead is generated when the preset is being generated in the `env()` call
61- // This generation should use information from https://github.com/cloudflare/workerd/issues/2097
6218export const {
6319 Certificate,
64- DiffieHellman,
65- DiffieHellmanGroup,
66- Hash,
67- Hmac,
68- KeyObject,
69- X509Certificate,
7020 checkPrime,
7121 checkPrimeSync,
22+ Cipheriv,
23+ createCipheriv,
24+ createDecipheriv,
7225 createDiffieHellman,
7326 createDiffieHellmanGroup,
27+ createECDH,
7428 createHash,
7529 createHmac,
7630 createPrivateKey,
7731 createPublicKey,
7832 createSecretKey,
33+ createSign,
34+ createVerify,
35+ Decipheriv,
36+ diffieHellman,
37+ DiffieHellman,
38+ DiffieHellmanGroup,
39+ ECDH ,
40+ fips,
7941 generateKey,
8042 generateKeyPair,
8143 generateKeyPairSync,
8244 generateKeySync,
8345 generatePrime,
8446 generatePrimeSync,
47+ getCipherInfo,
8548 getCiphers,
8649 getCurves,
8750 getDiffieHellman,
8851 getFips,
8952 getHashes,
53+ getRandomValues,
54+ hash,
55+ Hash,
9056 hkdf,
9157 hkdfSync,
58+ Hmac,
59+ KeyObject,
9260 pbkdf2,
9361 pbkdf2Sync,
62+ privateDecrypt,
63+ privateEncrypt,
64+ publicDecrypt,
65+ publicEncrypt,
9466 randomBytes,
9567 randomFill,
9668 randomFillSync,
@@ -101,27 +73,24 @@ export const {
10173 secureHeapUsed,
10274 setEngine,
10375 setFips,
76+ sign,
77+ Sign,
10478 subtle,
10579 timingSafeEqual,
80+ verify,
81+ Verify,
82+ X509Certificate,
10683} = workerdCrypto ;
10784
108- // Special case getRandomValues as it must be bound to the webcrypto object
109- export const getRandomValues = workerdCrypto . getRandomValues . bind (
110- workerdCrypto . webcrypto
111- ) ;
112-
85+ // See https://github.com/cloudflare/workerd/issues/3751
11386export const webcrypto = {
114- // @ts -expect-error unenv has unknown type
87+ // @ts -expect-error
11588 CryptoKey : unenvCryptoWebcrypto . CryptoKey ,
11689 getRandomValues,
11790 randomUUID,
11891 subtle,
11992} satisfies typeof nodeCrypto . webcrypto ;
12093
121- // Node.js exposes fips only via the default export 🤷🏼♂️
122- // so extract it separately from the other exports
123- const fips = workerdCrypto . fips ;
124-
12594export default {
12695 /**
12796 * manually unroll unenv-polyfilled-symbols to make it tree-shakeable
@@ -137,35 +106,22 @@ export default {
137106 X509Certificate,
138107 // @ts -expect-error @types/node is out of date - this is a bug in typings
139108 constants,
140- // @ts -expect-error unenv has unknown type
141109 createCipheriv,
142- // @ts -expect-error unenv has unknown type
143110 createDecipheriv,
144- // @ts -expect-error unenv has unknown type
145111 createECDH,
146- // @ts -expect-error unenv has unknown type
147112 createSign,
148- // @ts -expect-error unenv has unknown type
149113 createVerify,
150114 // @ts -expect-error unenv has unknown type
151115 diffieHellman,
152- // @ts -expect-error unenv has unknown type
153116 getCipherInfo,
154- // @ts -expect-error unenv has unknown type
155117 hash,
156- // @ts -expect-error unenv has unknown type
157118 privateDecrypt,
158- // @ts -expect-error unenv has unknown type
159119 privateEncrypt,
160- // @ts -expect-error unenv has unknown type
161120 publicDecrypt,
162- // @ts -expect-error unenv has unknown type
163121 publicEncrypt,
164122 scrypt,
165123 scryptSync,
166- // @ts -expect-error unenv has unknown type
167124 sign,
168- // @ts -expect-error unenv has unknown type
169125 verify,
170126
171127 // default-only export from unenv
0 commit comments