@simplewebauthn/server 9.0.3 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +2 -2
  2. package/esm/authentication/generateAuthenticationOptions.d.ts +16 -14
  3. package/esm/authentication/generateAuthenticationOptions.js +21 -16
  4. package/esm/authentication/verifyAuthenticationResponse.d.ts +13 -18
  5. package/esm/authentication/verifyAuthenticationResponse.js +12 -17
  6. package/esm/deps.d.ts +1 -1
  7. package/esm/helpers/convertCertBufferToPEM.js +1 -1
  8. package/esm/helpers/decodeClientDataJSON.d.ts +2 -1
  9. package/esm/helpers/decodeClientDataJSON.js +1 -1
  10. package/esm/helpers/generateUserID.d.ts +7 -0
  11. package/esm/helpers/generateUserID.js +17 -0
  12. package/esm/helpers/index.d.ts +2 -1
  13. package/esm/helpers/index.js +2 -1
  14. package/esm/helpers/iso/isoBase64URL.d.ts +10 -5
  15. package/esm/helpers/iso/isoBase64URL.js +13 -7
  16. package/esm/helpers/iso/isoCrypto/getWebCrypto.d.ts +0 -289
  17. package/esm/helpers/iso/isoCrypto/getWebCrypto.js +26 -41
  18. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +2 -1
  19. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.js +58 -16
  20. package/esm/helpers/iso/isoCrypto/verify.js +6 -2
  21. package/esm/metadata/parseJWT.js +2 -2
  22. package/esm/registration/generateRegistrationOptions.d.ts +19 -19
  23. package/esm/registration/generateRegistrationOptions.js +40 -22
  24. package/esm/registration/verifications/verifyAttestationAndroidSafetyNet.js +2 -2
  25. package/esm/registration/verifyRegistrationResponse.d.ts +9 -12
  26. package/esm/registration/verifyRegistrationResponse.js +8 -11
  27. package/package.json +3 -3
  28. package/script/authentication/generateAuthenticationOptions.d.ts +16 -14
  29. package/script/authentication/generateAuthenticationOptions.js +21 -16
  30. package/script/authentication/verifyAuthenticationResponse.d.ts +13 -18
  31. package/script/authentication/verifyAuthenticationResponse.js +12 -17
  32. package/script/deps.d.ts +1 -1
  33. package/script/helpers/convertCertBufferToPEM.js +1 -1
  34. package/script/helpers/decodeClientDataJSON.d.ts +2 -1
  35. package/script/helpers/decodeClientDataJSON.js +1 -1
  36. package/script/helpers/generateUserID.d.ts +7 -0
  37. package/script/helpers/generateUserID.js +21 -0
  38. package/script/helpers/index.d.ts +2 -1
  39. package/script/helpers/index.js +3 -1
  40. package/script/helpers/iso/isoBase64URL.d.ts +10 -5
  41. package/script/helpers/iso/isoBase64URL.js +18 -11
  42. package/script/helpers/iso/isoCrypto/getWebCrypto.d.ts +0 -288
  43. package/script/helpers/iso/isoCrypto/getWebCrypto.js +26 -64
  44. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +2 -1
  45. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.js +58 -16
  46. package/script/helpers/iso/isoCrypto/verify.js +5 -1
  47. package/script/metadata/parseJWT.js +2 -2
  48. package/script/registration/generateRegistrationOptions.d.ts +19 -19
  49. package/script/registration/generateRegistrationOptions.js +40 -22
  50. package/script/registration/verifications/verifyAttestationAndroidSafetyNet.js +2 -2
  51. package/script/registration/verifyRegistrationResponse.d.ts +9 -12
  52. package/script/registration/verifyRegistrationResponse.js +8 -11
@@ -1,10 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node/crypto.js" />
5
- /// <reference types=".deno/@types+node@18.16.19/node_modules/@types/node/crypto.js" />
6
- /// <reference types="node/stream.js" />
7
- /// <reference types=".deno/@types+node@18.16.19/node_modules/@types/node/stream.js" />
8
1
  import type { Crypto } from '../../../deps.js';
9
2
  /**
10
3
  * Try to get an instance of the Crypto API from the current runtime. Should support Node,
@@ -15,287 +8,6 @@ export declare class MissingWebCrypto extends Error {
15
8
  constructor();
16
9
  }
17
10
  export declare const _getWebCryptoInternals: {
18
- stubThisImportNodeCrypto: () => Promise<{
19
- default: typeof import("crypto");
20
- createHash(algorithm: string, options?: import("crypto").HashOptions | undefined): import("crypto").Hash;
21
- createHash(algorithm: string, options?: import("crypto").HashOptions | undefined): import("crypto").Hash;
22
- createHmac(algorithm: string, key: import("crypto").KeyObject | import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Hmac;
23
- createHmac(algorithm: string, key: import("crypto").KeyObject | import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Hmac;
24
- createCipher(algorithm: import("crypto").CipherCCMTypes, password: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").CipherCCM;
25
- createCipher(algorithm: import("crypto").CipherGCMTypes, password: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").CipherGCM;
26
- createCipher(algorithm: string, password: import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Cipher;
27
- createCipher(algorithm: import("crypto").CipherCCMTypes, password: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").CipherCCM;
28
- createCipher(algorithm: import("crypto").CipherGCMTypes, password: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").CipherGCM;
29
- createCipher(algorithm: string, password: import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Cipher;
30
- createCipheriv(algorithm: import("crypto").CipherCCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").CipherCCM;
31
- createCipheriv(algorithm: import("crypto").CipherOCBTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherOCBOptions): import("crypto").CipherOCB;
32
- createCipheriv(algorithm: import("crypto").CipherGCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").CipherGCM;
33
- createCipheriv(algorithm: string, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike | null, options?: import("stream").TransformOptions | undefined): import("crypto").Cipher;
34
- createCipheriv(algorithm: import("crypto").CipherCCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").CipherCCM;
35
- createCipheriv(algorithm: import("crypto").CipherOCBTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherOCBOptions): import("crypto").CipherOCB;
36
- createCipheriv(algorithm: import("crypto").CipherGCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").CipherGCM;
37
- createCipheriv(algorithm: string, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike | null, options?: import("stream").TransformOptions | undefined): import("crypto").Cipher;
38
- createDecipher(algorithm: import("crypto").CipherCCMTypes, password: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").DecipherCCM;
39
- createDecipher(algorithm: import("crypto").CipherGCMTypes, password: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").DecipherGCM;
40
- createDecipher(algorithm: string, password: import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Decipher;
41
- createDecipher(algorithm: import("crypto").CipherCCMTypes, password: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").DecipherCCM;
42
- createDecipher(algorithm: import("crypto").CipherGCMTypes, password: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").DecipherGCM;
43
- createDecipher(algorithm: string, password: import("crypto").BinaryLike, options?: import("stream").TransformOptions | undefined): import("crypto").Decipher;
44
- createDecipheriv(algorithm: import("crypto").CipherCCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").DecipherCCM;
45
- createDecipheriv(algorithm: import("crypto").CipherOCBTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherOCBOptions): import("crypto").DecipherOCB;
46
- createDecipheriv(algorithm: import("crypto").CipherGCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").DecipherGCM;
47
- createDecipheriv(algorithm: string, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike | null, options?: import("stream").TransformOptions | undefined): import("crypto").Decipher;
48
- createDecipheriv(algorithm: import("crypto").CipherCCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherCCMOptions): import("crypto").DecipherCCM;
49
- createDecipheriv(algorithm: import("crypto").CipherOCBTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options: import("crypto").CipherOCBOptions): import("crypto").DecipherOCB;
50
- createDecipheriv(algorithm: import("crypto").CipherGCMTypes, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike, options?: import("crypto").CipherGCMOptions | undefined): import("crypto").DecipherGCM;
51
- createDecipheriv(algorithm: string, key: import("crypto").CipherKey, iv: import("crypto").BinaryLike | null, options?: import("stream").TransformOptions | undefined): import("crypto").Decipher;
52
- generateKey(type: "hmac" | "aes", options: {
53
- length: number;
54
- }, callback: (err: Error | null, key: import("crypto").KeyObject) => void): void;
55
- generateKey(type: "hmac" | "aes", options: {
56
- length: number;
57
- }, callback: (err: Error | null, key: import("crypto").KeyObject) => void): void;
58
- generateKeySync(type: "hmac" | "aes", options: {
59
- length: number;
60
- }): import("crypto").KeyObject;
61
- generateKeySync(type: "hmac" | "aes", options: {
62
- length: number;
63
- }): import("crypto").KeyObject;
64
- createPrivateKey(key: string | import("crypto").PrivateKeyInput | Buffer | import("crypto").JsonWebKeyInput): import("crypto").KeyObject;
65
- createPrivateKey(key: string | import("crypto").PrivateKeyInput | Buffer | import("crypto").JsonWebKeyInput): import("crypto").KeyObject;
66
- createPublicKey(key: string | import("crypto").KeyObject | Buffer | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput): import("crypto").KeyObject;
67
- createPublicKey(key: string | import("crypto").KeyObject | Buffer | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput): import("crypto").KeyObject;
68
- createSecretKey(key: NodeJS.ArrayBufferView): import("crypto").KeyObject;
69
- createSecretKey(key: string, encoding: BufferEncoding): import("crypto").KeyObject;
70
- createSecretKey(key: NodeJS.ArrayBufferView): import("crypto").KeyObject;
71
- createSecretKey(key: string, encoding: BufferEncoding): import("crypto").KeyObject;
72
- createSign(algorithm: string, options?: import("stream").WritableOptions | undefined): import("crypto").Sign;
73
- createSign(algorithm: string, options?: import("stream").WritableOptions | undefined): import("crypto").Sign;
74
- createVerify(algorithm: string, options?: import("stream").WritableOptions | undefined): import("crypto").Verify;
75
- createVerify(algorithm: string, options?: import("stream").WritableOptions | undefined): import("crypto").Verify;
76
- createDiffieHellman(primeLength: number, generator?: number | undefined): import("crypto").DiffieHellman;
77
- createDiffieHellman(prime: ArrayBuffer | NodeJS.ArrayBufferView, generator?: number | ArrayBuffer | NodeJS.ArrayBufferView | undefined): import("crypto").DiffieHellman;
78
- createDiffieHellman(prime: ArrayBuffer | NodeJS.ArrayBufferView, generator: string, generatorEncoding: import("crypto").BinaryToTextEncoding): import("crypto").DiffieHellman;
79
- createDiffieHellman(prime: string, primeEncoding: import("crypto").BinaryToTextEncoding, generator?: number | ArrayBuffer | NodeJS.ArrayBufferView | undefined): import("crypto").DiffieHellman;
80
- createDiffieHellman(prime: string, primeEncoding: import("crypto").BinaryToTextEncoding, generator: string, generatorEncoding: import("crypto").BinaryToTextEncoding): import("crypto").DiffieHellman;
81
- createDiffieHellman(primeLength: number, generator?: number | undefined): import("crypto").DiffieHellman;
82
- createDiffieHellman(prime: ArrayBuffer | NodeJS.ArrayBufferView, generator?: number | ArrayBuffer | NodeJS.ArrayBufferView | undefined): import("crypto").DiffieHellman;
83
- createDiffieHellman(prime: ArrayBuffer | NodeJS.ArrayBufferView, generator: string, generatorEncoding: import("crypto").BinaryToTextEncoding): import("crypto").DiffieHellman;
84
- createDiffieHellman(prime: string, primeEncoding: import("crypto").BinaryToTextEncoding, generator?: number | ArrayBuffer | NodeJS.ArrayBufferView | undefined): import("crypto").DiffieHellman;
85
- createDiffieHellman(prime: string, primeEncoding: import("crypto").BinaryToTextEncoding, generator: string, generatorEncoding: import("crypto").BinaryToTextEncoding): import("crypto").DiffieHellman;
86
- getDiffieHellman(groupName: string): import("crypto").DiffieHellmanGroup;
87
- getDiffieHellman(groupName: string): import("crypto").DiffieHellmanGroup;
88
- createDiffieHellmanGroup(name: string): import("crypto").DiffieHellmanGroup;
89
- createDiffieHellmanGroup(name: string): import("crypto").DiffieHellmanGroup;
90
- pbkdf2(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey: Buffer) => void): void;
91
- pbkdf2(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey: Buffer) => void): void;
92
- pbkdf2Sync(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, iterations: number, keylen: number, digest: string): Buffer;
93
- pbkdf2Sync(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, iterations: number, keylen: number, digest: string): Buffer;
94
- randomBytes(size: number): Buffer;
95
- randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
96
- randomBytes(size: number): Buffer;
97
- randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
98
- pseudoRandomBytes(size: number): Buffer;
99
- pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
100
- pseudoRandomBytes(size: number): Buffer;
101
- pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
102
- randomInt(max: number): number;
103
- randomInt(min: number, max: number): number;
104
- randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
105
- randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
106
- randomInt(max: number): number;
107
- randomInt(min: number, max: number): number;
108
- randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
109
- randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
110
- randomFillSync<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number | undefined, size?: number | undefined): T;
111
- randomFillSync<T_1 extends NodeJS.ArrayBufferView>(buffer: T_1, offset?: number | undefined, size?: number | undefined): T_1;
112
- randomFill<T_2 extends NodeJS.ArrayBufferView>(buffer: T_2, callback: (err: Error | null, buf: T_2) => void): void;
113
- randomFill<T_3 extends NodeJS.ArrayBufferView>(buffer: T_3, offset: number, callback: (err: Error | null, buf: T_3) => void): void;
114
- randomFill<T_4 extends NodeJS.ArrayBufferView>(buffer: T_4, offset: number, size: number, callback: (err: Error | null, buf: T_4) => void): void;
115
- randomFill<T_5 extends NodeJS.ArrayBufferView>(buffer: T_5, callback: (err: Error | null, buf: T_5) => void): void;
116
- randomFill<T_6 extends NodeJS.ArrayBufferView>(buffer: T_6, offset: number, callback: (err: Error | null, buf: T_6) => void): void;
117
- randomFill<T_7 extends NodeJS.ArrayBufferView>(buffer: T_7, offset: number, size: number, callback: (err: Error | null, buf: T_7) => void): void;
118
- scrypt(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void;
119
- scrypt(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, options: import("crypto").ScryptOptions, callback: (err: Error | null, derivedKey: Buffer) => void): void;
120
- scrypt(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void;
121
- scrypt(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, options: import("crypto").ScryptOptions, callback: (err: Error | null, derivedKey: Buffer) => void): void;
122
- scryptSync(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, options?: import("crypto").ScryptOptions | undefined): Buffer;
123
- scryptSync(password: import("crypto").BinaryLike, salt: import("crypto").BinaryLike, keylen: number, options?: import("crypto").ScryptOptions | undefined): Buffer;
124
- publicEncrypt(key: import("crypto").RsaPublicKey | import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
125
- publicEncrypt(key: import("crypto").RsaPublicKey | import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
126
- publicDecrypt(key: import("crypto").RsaPublicKey | import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
127
- publicDecrypt(key: import("crypto").RsaPublicKey | import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
128
- privateDecrypt(privateKey: import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
129
- privateDecrypt(privateKey: import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
130
- privateEncrypt(privateKey: import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
131
- privateEncrypt(privateKey: import("crypto").RsaPrivateKey | import("crypto").KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
132
- getCiphers(): string[];
133
- getCiphers(): string[];
134
- getCurves(): string[];
135
- getCurves(): string[];
136
- getFips(): 0 | 1;
137
- getFips(): 0 | 1;
138
- setFips(bool: boolean): void;
139
- setFips(bool: boolean): void;
140
- getHashes(): string[];
141
- getHashes(): string[];
142
- createECDH(curveName: string): import("crypto").ECDH;
143
- createECDH(curveName: string): import("crypto").ECDH;
144
- timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
145
- timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
146
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
147
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
148
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
149
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
150
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
151
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
152
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
153
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
154
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
155
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
156
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
157
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
158
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
159
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
160
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
161
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
162
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
163
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
164
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
165
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
166
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
167
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
168
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
169
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
170
- generateKeyPairSync(type: "ed25519", options?: import("crypto").ED25519KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
171
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
172
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
173
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
174
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
175
- generateKeyPairSync(type: "ed448", options?: import("crypto").ED448KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
176
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
177
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
178
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
179
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
180
- generateKeyPairSync(type: "x25519", options?: import("crypto").X25519KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
181
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
182
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
183
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
184
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
185
- generateKeyPairSync(type: "x448", options?: import("crypto").X448KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
186
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
187
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
188
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
189
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
190
- generateKeyPairSync(type: "rsa", options: import("crypto").RSAKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
191
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
192
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
193
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
194
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
195
- generateKeyPairSync(type: "rsa-pss", options: import("crypto").RSAPSSKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
196
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
197
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
198
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
199
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
200
- generateKeyPairSync(type: "dsa", options: import("crypto").DSAKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
201
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
202
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
203
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
204
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
205
- generateKeyPairSync(type: "ec", options: import("crypto").ECKeyPairKeyObjectOptions): import("crypto").KeyPairKeyObjectResult;
206
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
207
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
208
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
209
- generateKeyPairSync(type: "ed25519", options: import("crypto").ED25519KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
210
- generateKeyPairSync(type: "ed25519", options?: import("crypto").ED25519KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
211
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
212
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
213
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
214
- generateKeyPairSync(type: "ed448", options: import("crypto").ED448KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
215
- generateKeyPairSync(type: "ed448", options?: import("crypto").ED448KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
216
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
217
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
218
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
219
- generateKeyPairSync(type: "x25519", options: import("crypto").X25519KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
220
- generateKeyPairSync(type: "x25519", options?: import("crypto").X25519KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
221
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"pem", "pem">): import("crypto").KeyPairSyncResult<string, string>;
222
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"pem", "der">): import("crypto").KeyPairSyncResult<string, Buffer>;
223
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"der", "pem">): import("crypto").KeyPairSyncResult<Buffer, string>;
224
- generateKeyPairSync(type: "x448", options: import("crypto").X448KeyPairOptions<"der", "der">): import("crypto").KeyPairSyncResult<Buffer, Buffer>;
225
- generateKeyPairSync(type: "x448", options?: import("crypto").X448KeyPairKeyObjectOptions | undefined): import("crypto").KeyPairKeyObjectResult;
226
- generateKeyPair: typeof import("crypto").generateKeyPair;
227
- sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").SignKeyObjectInput | import("crypto").SignPrivateKeyInput): Buffer;
228
- sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").SignKeyObjectInput | import("crypto").SignPrivateKeyInput, callback: (error: Error | null, data: Buffer) => void): void;
229
- sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").SignKeyObjectInput | import("crypto").SignPrivateKeyInput): Buffer;
230
- sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").SignKeyObjectInput | import("crypto").SignPrivateKeyInput, callback: (error: Error | null, data: Buffer) => void): void;
231
- verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").VerifyKeyObjectInput | import("crypto").VerifyPublicKeyInput | import("crypto").VerifyJsonWebKeyInput, signature: NodeJS.ArrayBufferView): boolean;
232
- verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").VerifyKeyObjectInput | import("crypto").VerifyPublicKeyInput | import("crypto").VerifyJsonWebKeyInput, signature: NodeJS.ArrayBufferView, callback: (error: Error | null, result: boolean) => void): void;
233
- verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").VerifyKeyObjectInput | import("crypto").VerifyPublicKeyInput | import("crypto").VerifyJsonWebKeyInput, signature: NodeJS.ArrayBufferView): boolean;
234
- verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: import("crypto").KeyLike | import("crypto").VerifyKeyObjectInput | import("crypto").VerifyPublicKeyInput | import("crypto").VerifyJsonWebKeyInput, signature: NodeJS.ArrayBufferView, callback: (error: Error | null, result: boolean) => void): void;
235
- diffieHellman(options: {
236
- privateKey: import("crypto").KeyObject;
237
- publicKey: import("crypto").KeyObject;
238
- }): Buffer;
239
- diffieHellman(options: {
240
- privateKey: import("crypto").KeyObject;
241
- publicKey: import("crypto").KeyObject;
242
- }): Buffer;
243
- getCipherInfo(nameOrNid: string | number, options?: import("crypto").CipherInfoOptions | undefined): import("crypto").CipherInfo | undefined;
244
- getCipherInfo(nameOrNid: string | number, options?: import("crypto").CipherInfoOptions | undefined): import("crypto").CipherInfo | undefined;
245
- hkdf(digest: string, irm: import("crypto").KeyObject | import("crypto").BinaryLike, salt: import("crypto").BinaryLike, info: import("crypto").BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
246
- hkdf(digest: string, irm: import("crypto").KeyObject | import("crypto").BinaryLike, salt: import("crypto").BinaryLike, info: import("crypto").BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
247
- hkdfSync(digest: string, ikm: import("crypto").KeyObject | import("crypto").BinaryLike, salt: import("crypto").BinaryLike, info: import("crypto").BinaryLike, keylen: number): ArrayBuffer;
248
- hkdfSync(digest: string, ikm: import("crypto").KeyObject | import("crypto").BinaryLike, salt: import("crypto").BinaryLike, info: import("crypto").BinaryLike, keylen: number): ArrayBuffer;
249
- secureHeapUsed(): import("crypto").SecureHeapUsage;
250
- secureHeapUsed(): import("crypto").SecureHeapUsage;
251
- randomUUID(options?: import("crypto").RandomUUIDOptions | undefined): `${string}-${string}-${string}-${string}-${string}`;
252
- randomUUID(options?: import("crypto").RandomUUIDOptions | undefined): `${string}-${string}-${string}-${string}-${string}`;
253
- generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
254
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
255
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
256
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptions, callback: (err: Error | null, prime: bigint | ArrayBuffer) => void): void;
257
- generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
258
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
259
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
260
- generatePrime(size: number, options: import("crypto").GeneratePrimeOptions, callback: (err: Error | null, prime: bigint | ArrayBuffer) => void): void;
261
- generatePrimeSync(size: number): ArrayBuffer;
262
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptionsBigInt): bigint;
263
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
264
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptions): bigint | ArrayBuffer;
265
- generatePrimeSync(size: number): ArrayBuffer;
266
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptionsBigInt): bigint;
267
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
268
- generatePrimeSync(size: number, options: import("crypto").GeneratePrimeOptions): bigint | ArrayBuffer;
269
- checkPrime(value: import("crypto").LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
270
- checkPrime(value: import("crypto").LargeNumberLike, options: import("crypto").CheckPrimeOptions, callback: (err: Error | null, result: boolean) => void): void;
271
- checkPrime(value: import("crypto").LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
272
- checkPrime(value: import("crypto").LargeNumberLike, options: import("crypto").CheckPrimeOptions, callback: (err: Error | null, result: boolean) => void): void;
273
- checkPrimeSync(candidate: import("crypto").LargeNumberLike, options?: import("crypto").CheckPrimeOptions | undefined): boolean;
274
- checkPrimeSync(candidate: import("crypto").LargeNumberLike, options?: import("crypto").CheckPrimeOptions | undefined): boolean;
275
- setEngine(engine: string, flags?: number | undefined): void;
276
- setEngine(engine: string, flags?: number | undefined): void;
277
- getRandomValues<T_8 extends import("crypto").webcrypto.BufferSource>(typedArray: T_8): T_8;
278
- getRandomValues<T_9 extends import("crypto").webcrypto.BufferSource>(typedArray: T_9): T_9;
279
- Certificate: typeof import("crypto").Certificate;
280
- constants: typeof import("crypto").constants;
281
- fips: boolean;
282
- Hash: typeof import("crypto").Hash;
283
- Hmac: typeof import("crypto").Hmac;
284
- KeyObject: typeof import("crypto").KeyObject;
285
- Cipher: typeof import("crypto").Cipher;
286
- Decipher: typeof import("crypto").Decipher;
287
- Sign: typeof import("crypto").Sign;
288
- Verify: typeof import("crypto").Verify;
289
- DiffieHellman: typeof import("crypto").DiffieHellman;
290
- DiffieHellmanGroup: import("crypto").DiffieHellmanGroupConstructor;
291
- ECDH: typeof import("crypto").ECDH;
292
- DEFAULT_ENCODING: BufferEncoding;
293
- X509Certificate: typeof import("crypto").X509Certificate;
294
- subtle: import("crypto").webcrypto.SubtleCrypto;
295
- webcrypto: import("crypto").webcrypto.Crypto;
296
- } | {
297
- webcrypto: undefined;
298
- }>;
299
11
  stubThisGlobalThisCrypto: () => globalThis.Crypto;
300
12
  setCachedCrypto: (newCrypto: Crypto | undefined) => void;
301
13
  };
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports._getWebCryptoInternals = exports.MissingWebCrypto = exports.getWebCrypto = void 0;
27
4
  let webCrypto = undefined;
@@ -29,29 +6,34 @@ let webCrypto = undefined;
29
6
  * Try to get an instance of the Crypto API from the current runtime. Should support Node,
30
7
  * as well as others, like Deno, that implement Web APIs.
31
8
  */
32
- async function getWebCrypto() {
33
- if (webCrypto) {
34
- return webCrypto;
35
- }
36
- /**
37
- * Naively attempt to access Crypto as a global object, which popular alternative run-times
38
- * support.
39
- */
40
- const _globalThisCrypto = exports._getWebCryptoInternals.stubThisGlobalThisCrypto();
41
- if (_globalThisCrypto) {
42
- webCrypto = _globalThisCrypto;
43
- return webCrypto;
44
- }
9
+ function getWebCrypto() {
45
10
  /**
46
- * `globalThis.crypto` isn't available, so attempt a Node import...
11
+ * Hello there! If you came here wondering why this method is asynchronous when use of
12
+ * `globalThis.crypto` is not, it's to minimize a bunch of refactor related to making this
13
+ * synchronous. For example, `generateRegistrationOptions()` and `generateAuthenticationOptions()`
14
+ * become synchronous if we make this synchronous (since nothing else in that method is async)
15
+ * which represents a breaking API change in this library's core API.
16
+ *
17
+ * TODO: If it's after February 2025 when you read this then consider whether it still makes sense
18
+ * to keep this method asynchronous.
47
19
  */
48
- const _nodeCrypto = await exports._getWebCryptoInternals.stubThisImportNodeCrypto();
49
- if (_nodeCrypto?.webcrypto) {
50
- webCrypto = _nodeCrypto.webcrypto;
51
- return webCrypto;
52
- }
53
- // We tried to access it both in Node and globally, so bail out
54
- throw new MissingWebCrypto();
20
+ const toResolve = new Promise((resolve, reject) => {
21
+ if (webCrypto) {
22
+ return resolve(webCrypto);
23
+ }
24
+ /**
25
+ * Naively attempt to access Crypto as a global object, which popular ESM-centric run-times
26
+ * support (and Node v20+)
27
+ */
28
+ const _globalThisCrypto = exports._getWebCryptoInternals.stubThisGlobalThisCrypto();
29
+ if (_globalThisCrypto) {
30
+ webCrypto = _globalThisCrypto;
31
+ return resolve(webCrypto);
32
+ }
33
+ // We tried to access it both in Node and globally, so bail out
34
+ return reject(new MissingWebCrypto());
35
+ });
36
+ return toResolve;
55
37
  }
56
38
  exports.getWebCrypto = getWebCrypto;
57
39
  class MissingWebCrypto extends Error {
@@ -64,26 +46,6 @@ class MissingWebCrypto extends Error {
64
46
  exports.MissingWebCrypto = MissingWebCrypto;
65
47
  // Make it possible to stub return values during testing
66
48
  exports._getWebCryptoInternals = {
67
- stubThisImportNodeCrypto: async () => {
68
- try {
69
- // dnt-shim-ignore
70
- /**
71
- * The `webpackIgnore` here is to help support Next.js' Edge runtime.
72
- * See https://github.com/MasterKale/SimpleWebAuthn/issues/517 for more info.
73
- */
74
- const _nodeCrypto = await Promise.resolve().then(() => __importStar(require(/* webpackIgnore: true */ 'crypto')));
75
- return _nodeCrypto;
76
- }
77
- catch (_err) {
78
- /**
79
- * Intentionally declaring webcrypto as undefined because we're assuming the Node import
80
- * failed due to either:
81
- * - `import()` isn't supported
82
- * - `node:crypto` is unavailable.
83
- */
84
- return { webcrypto: undefined };
85
- }
86
- },
87
49
  stubThisGlobalThisCrypto: () => globalThis.crypto,
88
50
  // Make it possible to reset the `webCrypto` at the top of the file
89
51
  setCachedCrypto: (newCrypto) => {
@@ -1,6 +1,7 @@
1
+ import { COSECRV } from '../../cose.js';
1
2
  /**
2
3
  * In WebAuthn, EC2 signatures are wrapped in ASN.1 structure so we need to peel r and s apart.
3
4
  *
4
5
  * See https://www.w3.org/TR/webauthn-2/#sctn-signature-attestation-types
5
6
  */
6
- export declare function unwrapEC2Signature(signature: Uint8Array): Uint8Array;
7
+ export declare function unwrapEC2Signature(signature: Uint8Array, crv: COSECRV): Uint8Array;
@@ -2,33 +2,75 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unwrapEC2Signature = void 0;
4
4
  const deps_js_1 = require("../../../deps.js");
5
+ const cose_js_1 = require("../../cose.js");
5
6
  const index_js_1 = require("../index.js");
6
7
  /**
7
8
  * In WebAuthn, EC2 signatures are wrapped in ASN.1 structure so we need to peel r and s apart.
8
9
  *
9
10
  * See https://www.w3.org/TR/webauthn-2/#sctn-signature-attestation-types
10
11
  */
11
- function unwrapEC2Signature(signature) {
12
+ function unwrapEC2Signature(signature, crv) {
12
13
  const parsedSignature = deps_js_1.AsnParser.parse(signature, deps_js_1.ECDSASigValue);
13
- let rBytes = new Uint8Array(parsedSignature.r);
14
- let sBytes = new Uint8Array(parsedSignature.s);
15
- if (shouldRemoveLeadingZero(rBytes)) {
16
- rBytes = rBytes.slice(1);
17
- }
18
- if (shouldRemoveLeadingZero(sBytes)) {
19
- sBytes = sBytes.slice(1);
20
- }
21
- const finalSignature = index_js_1.isoUint8Array.concat([rBytes, sBytes]);
14
+ const rBytes = new Uint8Array(parsedSignature.r);
15
+ const sBytes = new Uint8Array(parsedSignature.s);
16
+ const componentLength = getSignatureComponentLength(crv);
17
+ const rNormalizedBytes = toNormalizedBytes(rBytes, componentLength);
18
+ const sNormalizedBytes = toNormalizedBytes(sBytes, componentLength);
19
+ const finalSignature = index_js_1.isoUint8Array.concat([
20
+ rNormalizedBytes,
21
+ sNormalizedBytes,
22
+ ]);
22
23
  return finalSignature;
23
24
  }
24
25
  exports.unwrapEC2Signature = unwrapEC2Signature;
25
26
  /**
26
- * Determine if the DER-specific `00` byte at the start of an ECDSA signature byte sequence
27
- * should be removed based on the following logic:
27
+ * The SubtleCrypto Web Crypto API expects ECDSA signatures with `r` and `s` values to be encoded
28
+ * to a specific length depending on the order of the curve. This function returns the expected
29
+ * byte-length for each of the `r` and `s` signature components.
30
+ *
31
+ * See <https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations>
32
+ */
33
+ function getSignatureComponentLength(crv) {
34
+ switch (crv) {
35
+ case cose_js_1.COSECRV.P256:
36
+ return 32;
37
+ case cose_js_1.COSECRV.P384:
38
+ return 48;
39
+ case cose_js_1.COSECRV.P521:
40
+ return 66;
41
+ default:
42
+ throw new Error(`Unexpected COSE crv value of ${crv} (EC2)`);
43
+ }
44
+ }
45
+ /**
46
+ * Converts the ASN.1 integer representation to bytes of a specific length `n`.
47
+ *
48
+ * DER encodes integers as big-endian byte arrays, with as small as possible representation and
49
+ * requires a leading `0` byte to disambiguate between negative and positive numbers. This means
50
+ * that `r` and `s` can potentially not be the expected byte-length that is needed by the
51
+ * SubtleCrypto Web Crypto API: if there are leading `0`s it can be shorter than expected, and if
52
+ * it has a leading `1` bit, it can be one byte longer.
28
53
  *
29
- * "If the leading byte is 0x0, and the the high order bit on the second byte is not set to 0,
30
- * then remove the leading 0x0 byte"
54
+ * See <https://www.itu.int/rec/T-REC-X.690-202102-I/en>
55
+ * See <https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations>
31
56
  */
32
- function shouldRemoveLeadingZero(bytes) {
33
- return bytes[0] === 0x0 && (bytes[1] & (1 << 7)) !== 0;
57
+ function toNormalizedBytes(bytes, componentLength) {
58
+ let normalizedBytes;
59
+ if (bytes.length < componentLength) {
60
+ // In case the bytes are shorter than expected, we need to pad it with leading `0`s.
61
+ normalizedBytes = new Uint8Array(componentLength);
62
+ normalizedBytes.set(bytes, componentLength - bytes.length);
63
+ }
64
+ else if (bytes.length === componentLength) {
65
+ normalizedBytes = bytes;
66
+ }
67
+ else if (bytes.length === componentLength + 1 && bytes[0] === 0 && (bytes[1] & 0x80) === 0x80) {
68
+ // The bytes contain a leading `0` to encode that the integer is positive. This leading `0`
69
+ // needs to be removed for compatibility with the SubtleCrypto Web Crypto API.
70
+ normalizedBytes = bytes.subarray(1);
71
+ }
72
+ else {
73
+ throw new Error(`Invalid signature component length ${bytes.length}, expected ${componentLength}`);
74
+ }
75
+ return normalizedBytes;
34
76
  }
@@ -12,7 +12,11 @@ const unwrapEC2Signature_js_1 = require("./unwrapEC2Signature.js");
12
12
  function verify(opts) {
13
13
  const { cosePublicKey, signature, data, shaHashOverride } = opts;
14
14
  if ((0, cose_js_1.isCOSEPublicKeyEC2)(cosePublicKey)) {
15
- const unwrappedSignature = (0, unwrapEC2Signature_js_1.unwrapEC2Signature)(signature);
15
+ const crv = cosePublicKey.get(cose_js_1.COSEKEYS.crv);
16
+ if (!(0, cose_js_1.isCOSECrv)(crv)) {
17
+ throw new Error(`unknown COSE curve ${crv}`);
18
+ }
19
+ const unwrappedSignature = (0, unwrapEC2Signature_js_1.unwrapEC2Signature)(signature, crv);
16
20
  return (0, verifyEC2_js_1.verifyEC2)({
17
21
  cosePublicKey,
18
22
  signature: unwrappedSignature,
@@ -8,8 +8,8 @@ const index_js_1 = require("../helpers/iso/index.js");
8
8
  function parseJWT(jwt) {
9
9
  const parts = jwt.split('.');
10
10
  return [
11
- JSON.parse(index_js_1.isoBase64URL.toString(parts[0])),
12
- JSON.parse(index_js_1.isoBase64URL.toString(parts[1])),
11
+ JSON.parse(index_js_1.isoBase64URL.toUTF8String(parts[0])),
12
+ JSON.parse(index_js_1.isoBase64URL.toUTF8String(parts[1])),
13
13
  parts[2],
14
14
  ];
15
15
  }