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