@simplewebauthn/server 13.3.3 → 14.0.0
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.
- package/README.md +8 -4
- package/esm/authentication/generateAuthenticationOptions.d.ts +2 -2
- package/esm/authentication/generateAuthenticationOptions.d.ts.map +1 -1
- package/esm/authentication/verifyAuthenticationResponse.d.ts +1 -0
- package/esm/authentication/verifyAuthenticationResponse.d.ts.map +1 -1
- package/esm/authentication/verifyAuthenticationResponse.js +40 -2
- package/esm/helpers/cose.d.ts +18 -2
- package/esm/helpers/cose.d.ts.map +1 -1
- package/esm/helpers/cose.js +12 -0
- package/esm/helpers/decodeClientDataJSON.d.ts +1 -0
- package/esm/helpers/decodeClientDataJSON.d.ts.map +1 -1
- package/esm/helpers/index.d.ts +2 -0
- package/esm/helpers/index.d.ts.map +1 -1
- package/esm/helpers/index.js +2 -0
- package/esm/helpers/iso/isoCrypto/digest.js +2 -2
- package/esm/helpers/iso/isoCrypto/getWebCrypto.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/getWebCrypto.js +12 -0
- package/esm/helpers/iso/isoCrypto/importJWKKey.d.ts +9 -0
- package/esm/helpers/iso/isoCrypto/importJWKKey.d.ts.map +1 -0
- package/esm/helpers/iso/isoCrypto/{importKey.js → importJWKKey.js} +6 -4
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoHashAlgName.d.ts +10 -0
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoHashAlgName.d.ts.map +1 -0
- package/esm/helpers/iso/isoCrypto/{mapCoseAlgToWebCryptoAlg.js → mapCoseAlgToWebCryptoHashAlgName.js} +6 -3
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +4 -1
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +15 -0
- package/esm/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.d.ts +7 -0
- package/esm/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.d.ts.map +1 -0
- package/esm/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.js +16 -0
- package/esm/helpers/iso/isoCrypto/structs.d.ts +1 -1
- package/esm/helpers/iso/isoCrypto/structs.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/verify.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/verify.js +5 -1
- package/esm/helpers/iso/isoCrypto/verifyAKP.d.ts +9 -0
- package/esm/helpers/iso/isoCrypto/verifyAKP.d.ts.map +1 -0
- package/esm/helpers/iso/isoCrypto/verifyAKP.js +47 -0
- package/esm/helpers/iso/isoCrypto/verifyEC2.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/verifyEC2.js +5 -8
- package/esm/helpers/iso/isoCrypto/verifyOKP.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/verifyOKP.js +2 -5
- package/esm/helpers/iso/isoCrypto/verifyRSA.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/verifyRSA.js +5 -8
- package/esm/helpers/logging.d.ts +28 -10
- package/esm/helpers/logging.d.ts.map +1 -1
- package/esm/helpers/logging.js +27 -16
- package/esm/helpers/validateCertificatePath.d.ts.map +1 -1
- package/esm/helpers/validateCertificatePath.js +25 -7
- package/esm/registration/generateRegistrationOptions.d.ts +10 -8
- package/esm/registration/generateRegistrationOptions.d.ts.map +1 -1
- package/esm/registration/generateRegistrationOptions.js +11 -29
- package/esm/registration/verifications/tpm/constants.d.ts +1 -2
- package/esm/registration/verifications/tpm/constants.d.ts.map +1 -1
- package/esm/registration/verifications/tpm/constants.js +1 -2
- package/esm/registration/verifications/tpm/isValidTPMManufacturerID.d.ts +3 -0
- package/esm/registration/verifications/tpm/isValidTPMManufacturerID.d.ts.map +1 -0
- package/esm/registration/verifications/tpm/isValidTPMManufacturerID.js +6 -0
- package/esm/registration/verifications/tpm/verifyAttestationTPM.d.ts.map +1 -1
- package/esm/registration/verifications/tpm/verifyAttestationTPM.js +3 -2
- package/esm/registration/verifyRegistrationResponse.d.ts +3 -3
- package/esm/registration/verifyRegistrationResponse.d.ts.map +1 -1
- package/esm/registration/verifyRegistrationResponse.js +3 -3
- package/esm/services/metadataService.d.ts +4 -0
- package/esm/services/metadataService.d.ts.map +1 -1
- package/esm/services/metadataService.js +16 -10
- package/esm/services/settingsService.d.ts +4 -0
- package/esm/services/settingsService.d.ts.map +1 -1
- package/esm/services/settingsService.js +12 -0
- package/esm/types/dom.d.ts +236 -3
- package/esm/types/dom.d.ts.map +1 -1
- package/esm/types/index.d.ts +158 -44
- package/esm/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/authentication/generateAuthenticationOptions.d.ts +2 -2
- package/script/authentication/generateAuthenticationOptions.d.ts.map +1 -1
- package/script/authentication/verifyAuthenticationResponse.d.ts +1 -0
- package/script/authentication/verifyAuthenticationResponse.d.ts.map +1 -1
- package/script/authentication/verifyAuthenticationResponse.js +40 -2
- package/script/helpers/cose.d.ts +18 -2
- package/script/helpers/cose.d.ts.map +1 -1
- package/script/helpers/cose.js +13 -0
- package/script/helpers/decodeClientDataJSON.d.ts +1 -0
- package/script/helpers/decodeClientDataJSON.d.ts.map +1 -1
- package/script/helpers/index.d.ts +2 -0
- package/script/helpers/index.d.ts.map +1 -1
- package/script/helpers/index.js +4 -1
- package/script/helpers/iso/isoCrypto/digest.js +2 -2
- package/script/helpers/iso/isoCrypto/getWebCrypto.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/getWebCrypto.js +12 -0
- package/script/helpers/iso/isoCrypto/importJWKKey.d.ts +9 -0
- package/script/helpers/iso/isoCrypto/importJWKKey.d.ts.map +1 -0
- package/script/helpers/iso/isoCrypto/{importKey.js → importJWKKey.js} +7 -5
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoHashAlgName.d.ts +10 -0
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoHashAlgName.d.ts.map +1 -0
- package/script/helpers/iso/isoCrypto/{mapCoseAlgToWebCryptoAlg.js → mapCoseAlgToWebCryptoHashAlgName.js} +7 -4
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +4 -1
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +15 -0
- package/script/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.d.ts +7 -0
- package/script/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.d.ts.map +1 -0
- package/script/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.js +19 -0
- package/script/helpers/iso/isoCrypto/structs.d.ts +1 -1
- package/script/helpers/iso/isoCrypto/structs.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/verify.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/verify.js +4 -0
- package/script/helpers/iso/isoCrypto/verifyAKP.d.ts +9 -0
- package/script/helpers/iso/isoCrypto/verifyAKP.d.ts.map +1 -0
- package/script/helpers/iso/isoCrypto/verifyAKP.js +50 -0
- package/script/helpers/iso/isoCrypto/verifyEC2.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/verifyEC2.js +5 -8
- package/script/helpers/iso/isoCrypto/verifyOKP.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/verifyOKP.js +2 -5
- package/script/helpers/iso/isoCrypto/verifyRSA.d.ts.map +1 -1
- package/script/helpers/iso/isoCrypto/verifyRSA.js +5 -8
- package/script/helpers/logging.d.ts +28 -10
- package/script/helpers/logging.d.ts.map +1 -1
- package/script/helpers/logging.js +29 -17
- package/script/helpers/validateCertificatePath.d.ts.map +1 -1
- package/script/helpers/validateCertificatePath.js +25 -7
- package/script/registration/generateRegistrationOptions.d.ts +10 -8
- package/script/registration/generateRegistrationOptions.d.ts.map +1 -1
- package/script/registration/generateRegistrationOptions.js +13 -31
- package/script/registration/verifications/tpm/constants.d.ts +1 -2
- package/script/registration/verifications/tpm/constants.d.ts.map +1 -1
- package/script/registration/verifications/tpm/constants.js +1 -2
- package/script/registration/verifications/tpm/isValidTPMManufacturerID.d.ts +3 -0
- package/script/registration/verifications/tpm/isValidTPMManufacturerID.d.ts.map +1 -0
- package/script/registration/verifications/tpm/isValidTPMManufacturerID.js +9 -0
- package/script/registration/verifications/tpm/verifyAttestationTPM.d.ts.map +1 -1
- package/script/registration/verifications/tpm/verifyAttestationTPM.js +2 -1
- package/script/registration/verifyRegistrationResponse.d.ts +3 -3
- package/script/registration/verifyRegistrationResponse.d.ts.map +1 -1
- package/script/registration/verifyRegistrationResponse.js +2 -2
- package/script/services/metadataService.d.ts +4 -0
- package/script/services/metadataService.d.ts.map +1 -1
- package/script/services/metadataService.js +15 -9
- package/script/services/settingsService.d.ts +4 -0
- package/script/services/settingsService.d.ts.map +1 -1
- package/script/services/settingsService.js +12 -0
- package/script/types/dom.d.ts +236 -3
- package/script/types/dom.d.ts.map +1 -1
- package/script/types/index.d.ts +158 -44
- package/script/types/index.d.ts.map +1 -1
- package/esm/helpers/iso/isoCrypto/importKey.d.ts +0 -5
- package/esm/helpers/iso/isoCrypto/importKey.d.ts.map +0 -1
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +0 -7
- package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts.map +0 -1
- package/script/helpers/iso/isoCrypto/importKey.d.ts +0 -5
- package/script/helpers/iso/isoCrypto/importKey.d.ts.map +0 -1
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +0 -7
- package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
[](https://jsr.io/@simplewebauthn/server)
|
|
6
6
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
|
-
- [Node LTS
|
|
9
|
-
- [Deno
|
|
8
|
+
- [Node LTS 22.x and higher](#node-lts-22x-and-higher)
|
|
9
|
+
- [Deno v2.4.x and higher](#deno-v24x-and-higher)
|
|
10
10
|
- [Documentation](#documentation)
|
|
11
11
|
- [Supported Attestation Formats](#supported-attestation-formats)
|
|
12
12
|
|
|
@@ -15,18 +15,22 @@
|
|
|
15
15
|
This package can be installed from **[NPM](https://www.npmjs.com/package/@simplewebauthn/server)**
|
|
16
16
|
and **[JSR](https://jsr.io/@simplewebauthn/server)**:
|
|
17
17
|
|
|
18
|
-
### Node LTS
|
|
18
|
+
### Node LTS 22.x and higher
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @simplewebauthn/server
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
> NOTE: This project will aim to support Node LTS releases through their Active and Maintenance windows as tracked on [the Node.js Releases page](https://nodejs.org/en/about/previous-releases).
|
|
25
|
+
|
|
26
|
+
### Deno v2.4.x and higher
|
|
25
27
|
|
|
26
28
|
```sh
|
|
27
29
|
deno add jsr:@simplewebauthn/server
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
> NOTE: [Deno no longer has LTS releases to track after April 30, 2026](https://docs.deno.com/runtime/fundamentals/stability_and_releases/#long-term-support-(lts)). This project will aim to support Deno minor releases for up to one year after their release.
|
|
33
|
+
|
|
30
34
|
## Documentation
|
|
31
35
|
|
|
32
36
|
You can find in-depth documentation on this package here:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthenticationExtensionsClientInputs,
|
|
1
|
+
import type { AuthenticationExtensionsClientInputs, Base64URLString, PublicKeyCredentialRequestOptionsJSON, Uint8Array_ } from '../types/index.js';
|
|
2
2
|
export type GenerateAuthenticationOptionsOpts = Parameters<typeof generateAuthenticationOptions>[0];
|
|
3
3
|
/**
|
|
4
4
|
* Prepare a value to pass into navigator.credentials.get(...) for authenticator authentication
|
|
@@ -16,7 +16,7 @@ export declare function generateAuthenticationOptions(options: {
|
|
|
16
16
|
rpID: string;
|
|
17
17
|
allowCredentials?: {
|
|
18
18
|
id: Base64URLString;
|
|
19
|
-
transports?:
|
|
19
|
+
transports?: string[];
|
|
20
20
|
}[];
|
|
21
21
|
challenge?: string | Uint8Array_;
|
|
22
22
|
timeout?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateAuthenticationOptions.d.ts","sourceRoot":"","sources":["../../src/authentication/generateAuthenticationOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,
|
|
1
|
+
{"version":3,"file":"generateAuthenticationOptions.d.ts","sourceRoot":"","sources":["../../src/authentication/generateAuthenticationOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,eAAe,EACf,qCAAqC,EACrC,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAI3B,MAAM,MAAM,iCAAiC,GAAG,UAAU,CAAC,OAAO,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpG;;;;;;;;;;;GAWG;AACH,wBAAsB,6BAA6B,CACjD,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE;QACjB,EAAE,EAAE,eAAe,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,EAAE,CAAC;IACJ,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC;IAC5D,UAAU,CAAC,EAAE,oCAAoC,CAAC;CACnD,GACA,OAAO,CAAC,qCAAqC,CAAC,CAoChD"}
|
|
@@ -26,6 +26,7 @@ export declare function verifyAuthenticationResponse(options: {
|
|
|
26
26
|
expectedRPID: string | string[];
|
|
27
27
|
credential: WebAuthnCredential;
|
|
28
28
|
expectedType?: string | string[];
|
|
29
|
+
expectedTopOrigin?: string | string[];
|
|
29
30
|
requireUserVerification?: boolean;
|
|
30
31
|
advancedFIDOConfig?: {
|
|
31
32
|
userVerification?: UserVerificationRequirement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyAuthenticationResponse.d.ts","sourceRoot":"","sources":["../../src/authentication/verifyAuthenticationResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EAAE,4CAA4C,EAAE,MAAM,6CAA6C,CAAC;AAIhH;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC,CAAC,CAAC,CAAC;AAElG;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE;IACP,QAAQ,EAAE,0BAA0B,CAAC;IACrC,iBAAiB,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE;QACnB,gBAAgB,CAAC,EAAE,2BAA2B,CAAC;KAChD,CAAC;CACH,GACA,OAAO,CAAC,8BAA8B,CAAC,
|
|
1
|
+
{"version":3,"file":"verifyAuthenticationResponse.d.ts","sourceRoot":"","sources":["../../src/authentication/verifyAuthen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ACf,IAAI,EAAE,MAAM,CAAC;QACb,6BAA6B,CAAC,EAAE,4CAA4C,CAAC;KAC9E,CAAC;CACH,CAAC"}
|
|
@@ -21,7 +21,7 @@ import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.js';
|
|
|
21
21
|
* @param advancedFIDOConfig.userVerification **(Optional)** - Enable alternative rules for evaluating the User Presence and User Verified flags in authenticator data: UV (and UP) flags are optional unless this value is `"required"`
|
|
22
22
|
*/
|
|
23
23
|
export async function verifyAuthenticationResponse(options) {
|
|
24
|
-
const { response, expectedChallenge, expectedOrigin, expectedRPID, expectedType, credential, requireUserVerification = true, advancedFIDOConfig, } = options;
|
|
24
|
+
const { response, expectedChallenge, expectedOrigin, expectedRPID, expectedType, expectedTopOrigin, credential, requireUserVerification = true, advancedFIDOConfig, } = options;
|
|
25
25
|
const { id, rawId, type: credentialType, response: assertionResponse } = response;
|
|
26
26
|
// Ensure credential specified an ID
|
|
27
27
|
if (!id) {
|
|
@@ -42,7 +42,7 @@ export async function verifyAuthenticationResponse(options) {
|
|
|
42
42
|
throw new Error('Credential response clientDataJSON was not a string');
|
|
43
43
|
}
|
|
44
44
|
const clientDataJSON = decodeClientDataJSON(assertionResponse.clientDataJSON);
|
|
45
|
-
const { type, origin, challenge, tokenBinding } = clientDataJSON;
|
|
45
|
+
const { type, origin, challenge, tokenBinding, crossOrigin, topOrigin } = clientDataJSON;
|
|
46
46
|
// Make sure we're handling an authentication
|
|
47
47
|
if (Array.isArray(expectedType)) {
|
|
48
48
|
if (!expectedType.includes(type)) {
|
|
@@ -67,6 +67,44 @@ export async function verifyAuthenticationResponse(options) {
|
|
|
67
67
|
else if (challenge !== expectedChallenge) {
|
|
68
68
|
throw new Error(`Unexpected authentication response challenge "${challenge}", expected "${expectedChallenge}"`);
|
|
69
69
|
}
|
|
70
|
+
// Check that the authentication response is within an expected iframe
|
|
71
|
+
if (crossOrigin) {
|
|
72
|
+
/**
|
|
73
|
+
* TODO: Since Safari doesn't support `topOrigin` as of May 2026, only check this when
|
|
74
|
+
* `topOrigin` is available for now.
|
|
75
|
+
*/
|
|
76
|
+
if (topOrigin) {
|
|
77
|
+
if (!expectedTopOrigin) {
|
|
78
|
+
/**
|
|
79
|
+
* If `expectedTopOrigin` is not set, this should be considered an unexpected cross-origin
|
|
80
|
+
* request. Reject the response while helping the RP understand how they need to update this
|
|
81
|
+
* method call if they want to support verification of such WebAuthn authentication requests.
|
|
82
|
+
*/
|
|
83
|
+
throw new Error(`Detected cross-origin authentication response from top origin of "${topOrigin}", but a value for \`expectedTopOrigin\` was not specified when calling \`verifyAuthenticationResponse()\``);
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(expectedTopOrigin)) {
|
|
86
|
+
if (!expectedTopOrigin.includes(topOrigin)) {
|
|
87
|
+
const joinedExpectedTopOrigin = expectedTopOrigin.join(', ');
|
|
88
|
+
throw new Error(`Unexpected cross-origin authentication response top origin of "${topOrigin}", expected one of: ${joinedExpectedTopOrigin}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (topOrigin !== expectedTopOrigin) {
|
|
93
|
+
throw new Error(`Unexpected cross-origin authentication response top origin of "${topOrigin}", expected: ${expectedTopOrigin}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (topOrigin) {
|
|
100
|
+
/**
|
|
101
|
+
* If `topOrigin` is set despite `crossOrigin` being false, this is an unexpected request.
|
|
102
|
+
*
|
|
103
|
+
* See https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin.
|
|
104
|
+
*/
|
|
105
|
+
throw new Error(`Unexpected top origin of "${topOrigin}" within a non-cross-origin authentication response. This error should be reported to the browser vendor as a WebAuthn specification violation with a link to https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
70
108
|
// Check that the origin is our site
|
|
71
109
|
if (Array.isArray(expectedOrigin)) {
|
|
72
110
|
if (!expectedOrigin.includes(origin)) {
|
package/esm/helpers/cose.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ export type COSEPublicKeyRSA = COSEPublicKey & {
|
|
|
48
48
|
set(key: COSEKEYS.n, value: Uint8Array_): void;
|
|
49
49
|
set(key: COSEKEYS.e, value: Uint8Array_): void;
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Values specific for AKP (ML-DSA) public keys
|
|
53
|
+
*/
|
|
54
|
+
export type COSEPublicKeyAKP = COSEPublicKey & {
|
|
55
|
+
get(key: COSEKEYS.pub): Uint8Array_ | undefined;
|
|
56
|
+
set(key: COSEKEYS.pub, value: Uint8Array_): void;
|
|
57
|
+
};
|
|
51
58
|
/**
|
|
52
59
|
* A type guard for determining if a COSE public key is an OKP key pair
|
|
53
60
|
*/
|
|
@@ -60,6 +67,10 @@ export declare function isCOSEPublicKeyEC2(cosePublicKey: COSEPublicKey): cosePu
|
|
|
60
67
|
* A type guard for determining if a COSE public key is an RSA key pair
|
|
61
68
|
*/
|
|
62
69
|
export declare function isCOSEPublicKeyRSA(cosePublicKey: COSEPublicKey): cosePublicKey is COSEPublicKeyRSA;
|
|
70
|
+
/**
|
|
71
|
+
* A type guard for determining if a COSE public key is an AKP key pair
|
|
72
|
+
*/
|
|
73
|
+
export declare function isCOSEPublicKeyAKP(cosePublicKey: COSEPublicKey): cosePublicKey is COSEPublicKeyAKP;
|
|
63
74
|
/**
|
|
64
75
|
* COSE Keys
|
|
65
76
|
*
|
|
@@ -73,7 +84,8 @@ export declare enum COSEKEYS {
|
|
|
73
84
|
x = -2,
|
|
74
85
|
y = -3,
|
|
75
86
|
n = -1,
|
|
76
|
-
e = -2
|
|
87
|
+
e = -2,
|
|
88
|
+
pub = -1
|
|
77
89
|
}
|
|
78
90
|
/**
|
|
79
91
|
* COSE Key Types
|
|
@@ -83,7 +95,8 @@ export declare enum COSEKEYS {
|
|
|
83
95
|
export declare enum COSEKTY {
|
|
84
96
|
OKP = 1,
|
|
85
97
|
EC2 = 2,
|
|
86
|
-
RSA = 3
|
|
98
|
+
RSA = 3,
|
|
99
|
+
AKP = 7
|
|
87
100
|
}
|
|
88
101
|
export declare function isCOSEKty(kty: number | undefined): kty is COSEKTY;
|
|
89
102
|
/**
|
|
@@ -113,6 +126,9 @@ export declare enum COSEALG {
|
|
|
113
126
|
PS384 = -38,
|
|
114
127
|
PS512 = -39,
|
|
115
128
|
ES256K = -47,
|
|
129
|
+
ML_DSA_44 = -48,
|
|
130
|
+
ML_DSA_65 = -49,
|
|
131
|
+
ML_DSA_87 = -50,
|
|
116
132
|
RS256 = -257,
|
|
117
133
|
RS384 = -258,
|
|
118
134
|
RS512 = -259,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cose.d.ts","sourceRoot":"","sources":["../../src/helpers/cose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAE1B,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,OAAO,GAAG,SAAS,CAAC;IAC5C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,OAAO,GAAG,SAAS,CAAC;IAE5C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAE7C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3C,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,GAAG,WAAW,GAA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AAK,MAAM;IACX,KAAK,MAAM;IACX,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,SAAS,MAAM;IACf,SAAS,MAAM;IACf,SAAS,MAAM;IACf,KAAK,OAAO;IACZ,KAAK,OAAO;IACZ,KAAK,OAAO;IACZ,GAAG,SAAS;CACb;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,IAAI,OAAO,CAEjE"}
|
package/esm/helpers/cose.js
CHANGED
|
@@ -19,6 +19,13 @@ export function isCOSEPublicKeyRSA(cosePublicKey) {
|
|
|
19
19
|
const kty = cosePublicKey.get(COSEKEYS.kty);
|
|
20
20
|
return isCOSEKty(kty) && kty === COSEKTY.RSA;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* A type guard for determining if a COSE public key is an AKP key pair
|
|
24
|
+
*/
|
|
25
|
+
export function isCOSEPublicKeyAKP(cosePublicKey) {
|
|
26
|
+
const kty = cosePublicKey.get(COSEKEYS.kty);
|
|
27
|
+
return isCOSEKty(kty) && kty === COSEKTY.AKP;
|
|
28
|
+
}
|
|
22
29
|
/**
|
|
23
30
|
* COSE Keys
|
|
24
31
|
*
|
|
@@ -34,6 +41,7 @@ export var COSEKEYS;
|
|
|
34
41
|
COSEKEYS[COSEKEYS["y"] = -3] = "y";
|
|
35
42
|
COSEKEYS[COSEKEYS["n"] = -1] = "n";
|
|
36
43
|
COSEKEYS[COSEKEYS["e"] = -2] = "e";
|
|
44
|
+
COSEKEYS[COSEKEYS["pub"] = -1] = "pub";
|
|
37
45
|
})(COSEKEYS || (COSEKEYS = {}));
|
|
38
46
|
/**
|
|
39
47
|
* COSE Key Types
|
|
@@ -45,6 +53,7 @@ export var COSEKTY;
|
|
|
45
53
|
COSEKTY[COSEKTY["OKP"] = 1] = "OKP";
|
|
46
54
|
COSEKTY[COSEKTY["EC2"] = 2] = "EC2";
|
|
47
55
|
COSEKTY[COSEKTY["RSA"] = 3] = "RSA";
|
|
56
|
+
COSEKTY[COSEKTY["AKP"] = 7] = "AKP";
|
|
48
57
|
})(COSEKTY || (COSEKTY = {}));
|
|
49
58
|
export function isCOSEKty(kty) {
|
|
50
59
|
return Object.values(COSEKTY).indexOf(kty) >= 0;
|
|
@@ -80,6 +89,9 @@ export var COSEALG;
|
|
|
80
89
|
COSEALG[COSEALG["PS384"] = -38] = "PS384";
|
|
81
90
|
COSEALG[COSEALG["PS512"] = -39] = "PS512";
|
|
82
91
|
COSEALG[COSEALG["ES256K"] = -47] = "ES256K";
|
|
92
|
+
COSEALG[COSEALG["ML_DSA_44"] = -48] = "ML_DSA_44";
|
|
93
|
+
COSEALG[COSEALG["ML_DSA_65"] = -49] = "ML_DSA_65";
|
|
94
|
+
COSEALG[COSEALG["ML_DSA_87"] = -50] = "ML_DSA_87";
|
|
83
95
|
COSEALG[COSEALG["RS256"] = -257] = "RS256";
|
|
84
96
|
COSEALG[COSEALG["RS384"] = -258] = "RS384";
|
|
85
97
|
COSEALG[COSEALG["RS512"] = -259] = "RS512";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodeClientDataJSON.d.ts","sourceRoot":"","sources":["../../src/helpers/decodeClientDataJSON.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,CAK1E;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;KACnD,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,8BAA8B;sBACvB,cAAc;CACjC,CAAC"}
|
|
1
|
+
{"version":3,"file":"decodeClientDataJSON.d.ts","sourceRoot":"","sources":["../../src/helpers/decodeClientDataJSON.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,CAK1E;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;KACnD,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,8BAA8B;sBACvB,cAAc;CACjC,CAAC"}
|
package/esm/helpers/index.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ export * from './verifySignature.js';
|
|
|
15
15
|
export * from './iso/index.js';
|
|
16
16
|
export * from '../metadata/verifyMDSBlob.js';
|
|
17
17
|
export * as cose from './cose.js';
|
|
18
|
+
export { COSEALG } from './cose.js';
|
|
19
|
+
export { type SimpleWebAuthnLogger } from './logging.js';
|
|
18
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
package/esm/helpers/index.js
CHANGED
|
@@ -15,3 +15,5 @@ export * from './verifySignature.js';
|
|
|
15
15
|
export * from './iso/index.js';
|
|
16
16
|
export * from '../metadata/verifyMDSBlob.js';
|
|
17
17
|
export * as cose from './cose.js';
|
|
18
|
+
// Specially exporting this for easier `supportedAlgorithmIDs` argument definition
|
|
19
|
+
export { COSEALG } from './cose.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mapCoseAlgToWebCryptoHashAlgName } from './mapCoseAlgToWebCryptoHashAlgName.js';
|
|
2
2
|
import { getWebCrypto } from './getWebCrypto.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generate a digest of the provided data.
|
|
@@ -8,7 +8,7 @@ import { getWebCrypto } from './getWebCrypto.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export async function digest(data, algorithm) {
|
|
10
10
|
const WebCrypto = await getWebCrypto();
|
|
11
|
-
const subtleAlgorithm =
|
|
11
|
+
const subtleAlgorithm = mapCoseAlgToWebCryptoHashAlgName(algorithm);
|
|
12
12
|
const hashed = await WebCrypto.subtle.digest(subtleAlgorithm, data);
|
|
13
13
|
return new Uint8Array(hashed);
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWebCrypto.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/getWebCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"getWebCrypto.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/getWebCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CA4C9C;AAED,qBAAa,gBAAiB,SAAQ,KAAK;;CAM1C;AAGD,eAAO,MAAM,sBAAsB;;iCAGJ,MAAM,GAAG,SAAS;CAGhD,CAAC"}
|
|
@@ -24,6 +24,18 @@ export function getWebCrypto() {
|
|
|
24
24
|
*/
|
|
25
25
|
const _globalThisCrypto = _getWebCryptoInternals.stubThisGlobalThisCrypto();
|
|
26
26
|
if (_globalThisCrypto) {
|
|
27
|
+
/**
|
|
28
|
+
* In Deno v2.7.x, TypeScript 5.9 defines `Crypto.getRandomValues()` as the following type:
|
|
29
|
+
*
|
|
30
|
+
* `getRandomValues<T extends ArrayBufferView>(array: T): T;`
|
|
31
|
+
*
|
|
32
|
+
* However in earlier versions of TypeScript, `Crypto.getRandomValues()` is defined as such:
|
|
33
|
+
*
|
|
34
|
+
* `getRandomValues<T extends ArrayBufferView | null>(array: T): T;`
|
|
35
|
+
*
|
|
36
|
+
* Casting to `as unknown as Crypto` here (using this project's `Crypto` types extracted from
|
|
37
|
+
* DOM types in an older, minimum-supported-Deno version of TypeScript) helps bridge the gap.
|
|
38
|
+
*/
|
|
27
39
|
webCrypto = _globalThisCrypto;
|
|
28
40
|
return resolve(webCrypto);
|
|
29
41
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a JWK-formatted public key into a WebCrypto CryptoKey that can be used for
|
|
3
|
+
* signature verification
|
|
4
|
+
*/
|
|
5
|
+
export declare function importJWKKey(opts: {
|
|
6
|
+
keyData: JsonWebKey;
|
|
7
|
+
algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams;
|
|
8
|
+
}): Promise<CryptoKey>;
|
|
9
|
+
//# sourceMappingURL=importJWKKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importJWKKey.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/importJWKKey.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,UAAU,CAAC;IACpB,SAAS,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,iBAAiB,CAAC;CAC5E,GAAG,OAAO,CAAC,SAAS,CAAC,CAMrB"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { getWebCrypto } from './getWebCrypto.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Convert a JWK-formatted public key into a WebCrypto CryptoKey that can be used for
|
|
4
|
+
* signature verification
|
|
5
|
+
*/
|
|
6
|
+
export async function importJWKKey(opts) {
|
|
3
7
|
const WebCrypto = await getWebCrypto();
|
|
4
8
|
const { keyData, algorithm } = opts;
|
|
5
|
-
return WebCrypto.subtle.importKey('jwk', keyData, algorithm, false, [
|
|
6
|
-
'verify',
|
|
7
|
-
]);
|
|
9
|
+
return WebCrypto.subtle.importKey('jwk', keyData, algorithm, false, ['verify']);
|
|
8
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SubtleCryptoAlg } from './structs.js';
|
|
2
|
+
import { COSEALG } from '../../cose.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert a COSE alg ID into a corresponding hash algorithm string value that WebCrypto APIs expect
|
|
5
|
+
*
|
|
6
|
+
* Unless otherwise specified, mappings were referenced from
|
|
7
|
+
* https://w3c.github.io/webcrypto/#jwk-mapping-alg
|
|
8
|
+
*/
|
|
9
|
+
export declare function mapCoseAlgToWebCryptoHashAlgName(alg: COSEALG): SubtleCryptoAlg;
|
|
10
|
+
//# sourceMappingURL=mapCoseAlgToWebCryptoHashAlgName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapCoseAlgToWebCryptoHashAlgName.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoHashAlgName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAe9E"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { COSEALG } from '../../cose.js';
|
|
2
2
|
/**
|
|
3
|
-
* Convert a COSE alg ID into a corresponding string value that WebCrypto APIs expect
|
|
3
|
+
* Convert a COSE alg ID into a corresponding hash algorithm string value that WebCrypto APIs expect
|
|
4
|
+
*
|
|
5
|
+
* Unless otherwise specified, mappings were referenced from
|
|
6
|
+
* https://w3c.github.io/webcrypto/#jwk-mapping-alg
|
|
4
7
|
*/
|
|
5
|
-
export function
|
|
8
|
+
export function mapCoseAlgToWebCryptoHashAlgName(alg) {
|
|
6
9
|
if ([COSEALG.RS1].indexOf(alg) >= 0) {
|
|
7
10
|
return 'SHA-1';
|
|
8
11
|
}
|
|
@@ -16,5 +19,5 @@ export function mapCoseAlgToWebCryptoAlg(alg) {
|
|
|
16
19
|
0) {
|
|
17
20
|
return 'SHA-512';
|
|
18
21
|
}
|
|
19
|
-
throw new Error(`Could not map COSE alg value of ${alg} to a WebCrypto alg`);
|
|
22
|
+
throw new Error(`Could not map COSE alg value of ${alg} to a WebCrypto hash alg name`);
|
|
20
23
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { COSEALG } from '../../cose.js';
|
|
2
|
-
import { SubtleCryptoKeyAlgName } from './structs.js';
|
|
2
|
+
import type { SubtleCryptoKeyAlgName } from './structs.js';
|
|
3
3
|
/**
|
|
4
4
|
* Convert a COSE alg ID into a corresponding key algorithm string value that WebCrypto APIs expect
|
|
5
|
+
*
|
|
6
|
+
* Unless otherwise specified, mappings were referenced from
|
|
7
|
+
* https://w3c.github.io/webcrypto/#jwk-mapping-alg
|
|
5
8
|
*/
|
|
6
9
|
export declare function mapCoseAlgToWebCryptoKeyAlgName(alg: COSEALG): SubtleCryptoKeyAlgName;
|
|
7
10
|
//# sourceMappingURL=mapCoseAlgToWebCryptoKeyAlgName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapCoseAlgToWebCryptoKeyAlgName.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"mapCoseAlgToWebCryptoKeyAlgName.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,OAAO,GACX,sBAAsB,CAuBxB"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { COSEALG } from '../../cose.js';
|
|
2
2
|
/**
|
|
3
3
|
* Convert a COSE alg ID into a corresponding key algorithm string value that WebCrypto APIs expect
|
|
4
|
+
*
|
|
5
|
+
* Unless otherwise specified, mappings were referenced from
|
|
6
|
+
* https://w3c.github.io/webcrypto/#jwk-mapping-alg
|
|
4
7
|
*/
|
|
5
8
|
export function mapCoseAlgToWebCryptoKeyAlgName(alg) {
|
|
6
9
|
if ([COSEALG.EdDSA].indexOf(alg) >= 0) {
|
|
@@ -15,5 +18,17 @@ export function mapCoseAlgToWebCryptoKeyAlgName(alg) {
|
|
|
15
18
|
else if ([COSEALG.PS256, COSEALG.PS384, COSEALG.PS512].indexOf(alg) >= 0) {
|
|
16
19
|
return 'RSA-PSS';
|
|
17
20
|
}
|
|
21
|
+
else if ([COSEALG.ML_DSA_44].indexOf(alg) >= 0) {
|
|
22
|
+
// https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-registration
|
|
23
|
+
return 'ML-DSA-44';
|
|
24
|
+
}
|
|
25
|
+
else if ([COSEALG.ML_DSA_65].indexOf(alg) >= 0) {
|
|
26
|
+
// https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-registration
|
|
27
|
+
return 'ML-DSA-65';
|
|
28
|
+
}
|
|
29
|
+
else if ([COSEALG.ML_DSA_87].indexOf(alg) >= 0) {
|
|
30
|
+
// https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-registration
|
|
31
|
+
return 'ML-DSA-87';
|
|
32
|
+
}
|
|
18
33
|
throw new Error(`Could not map COSE alg value of ${alg} to a WebCrypto key alg name`);
|
|
19
34
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AlgorithmIdentifier } from '../../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Use SubtleCrypto.supports() to understand if the runtime supports using the given key algorithm
|
|
4
|
+
* for signature verification.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runtimeSupportsWebCryptoKeyAlg(alg: AlgorithmIdentifier): boolean;
|
|
7
|
+
//# sourceMappingURL=runtimeSupportsWebCryptoKeyAlg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeSupportsWebCryptoKeyAlg.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/runtimeSupportsWebCryptoKeyAlg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAsB,MAAM,yBAAyB,CAAC;AAEvF;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAYhF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use SubtleCrypto.supports() to understand if the runtime supports using the given key algorithm
|
|
3
|
+
* for signature verification.
|
|
4
|
+
*/
|
|
5
|
+
export function runtimeSupportsWebCryptoKeyAlg(alg) {
|
|
6
|
+
const globalSubtleCrypto = globalThis.SubtleCrypto;
|
|
7
|
+
if (typeof globalSubtleCrypto.supports !== 'function') {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return globalSubtleCrypto.supports('verify', alg);
|
|
12
|
+
}
|
|
13
|
+
catch (_err) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type SubtleCryptoAlg = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
2
2
|
export type SubtleCryptoCrv = 'P-256' | 'P-384' | 'P-521' | 'Ed25519';
|
|
3
|
-
export type SubtleCryptoKeyAlgName = 'ECDSA' | 'Ed25519' | 'RSASSA-PKCS1-v1_5' | 'RSA-PSS';
|
|
3
|
+
export type SubtleCryptoKeyAlgName = 'ECDSA' | 'Ed25519' | 'ML-DSA-44' | 'ML-DSA-65' | 'ML-DSA-87' | 'RSASSA-PKCS1-v1_5' | 'RSA-PSS';
|
|
4
4
|
//# sourceMappingURL=structs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/structs.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AACtE,MAAM,MAAM,sBAAsB,GAC9B,OAAO,GACP,SAAS,GACT,mBAAmB,GACnB,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/structs.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AACtE,MAAM,MAAM,sBAAsB,GAC9B,OAAO,GACP,SAAS,GACT,WAAW,GACX,WAAW,GACX,WAAW,GACX,mBAAmB,GACnB,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,aAAa,EAMnB,MAAM,eAAe,CAAC;AAMvB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE;IAC3B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BnB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { COSEKEYS, isCOSECrv, isCOSEPublicKeyEC2, isCOSEPublicKeyOKP, isCOSEPublicKeyRSA, } from '../../cose.js';
|
|
1
|
+
import { COSEKEYS, isCOSECrv, isCOSEPublicKeyAKP, isCOSEPublicKeyEC2, isCOSEPublicKeyOKP, isCOSEPublicKeyRSA, } from '../../cose.js';
|
|
2
|
+
import { verifyAKP } from './verifyAKP.js';
|
|
2
3
|
import { verifyEC2 } from './verifyEC2.js';
|
|
3
4
|
import { verifyRSA } from './verifyRSA.js';
|
|
4
5
|
import { verifyOKP } from './verifyOKP.js';
|
|
@@ -27,6 +28,9 @@ export function verify(opts) {
|
|
|
27
28
|
else if (isCOSEPublicKeyOKP(cosePublicKey)) {
|
|
28
29
|
return verifyOKP({ cosePublicKey, signature, data });
|
|
29
30
|
}
|
|
31
|
+
else if (isCOSEPublicKeyAKP(cosePublicKey)) {
|
|
32
|
+
return verifyAKP({ cosePublicKey, signature, data });
|
|
33
|
+
}
|
|
30
34
|
const kty = cosePublicKey.get(COSEKEYS.kty);
|
|
31
35
|
throw new Error(`Signature verification with public key of kty ${kty} is not supported by this method`);
|
|
32
36
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type COSEPublicKeyAKP } from '../../cose.js';
|
|
2
|
+
import type { Uint8Array_ } from '../../../types/index.js';
|
|
3
|
+
/** AKP, a.k.a ML-DSA */
|
|
4
|
+
export declare function verifyAKP(opts: {
|
|
5
|
+
cosePublicKey: COSEPublicKeyAKP;
|
|
6
|
+
signature: Uint8Array_;
|
|
7
|
+
data: Uint8Array_;
|
|
8
|
+
}): Promise<boolean>;
|
|
9
|
+
//# sourceMappingURL=verifyAKP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyAKP.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verifyAKP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAa,MAAM,eAAe,CAAC;AAK3E,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE5E,wBAAwB;AACxB,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;CACnB,GAAG,OAAO,CAAC,OAAO,CAAC,CAkDnB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { COSEKEYS, isCOSEAlg } from '../../cose.js';
|
|
2
|
+
import { isoBase64URL } from '../../index.js';
|
|
3
|
+
import { importJWKKey } from './importJWKKey.js';
|
|
4
|
+
import { getWebCrypto } from './getWebCrypto.js';
|
|
5
|
+
import { mapCoseAlgToWebCryptoKeyAlgName } from './mapCoseAlgToWebCryptoKeyAlgName.js';
|
|
6
|
+
/** AKP, a.k.a ML-DSA */
|
|
7
|
+
export async function verifyAKP(opts) {
|
|
8
|
+
const { cosePublicKey, signature, data } = opts;
|
|
9
|
+
const WebCrypto = await getWebCrypto();
|
|
10
|
+
const alg = cosePublicKey.get(COSEKEYS.alg);
|
|
11
|
+
const pub = cosePublicKey.get(COSEKEYS.pub);
|
|
12
|
+
if (!alg) {
|
|
13
|
+
throw new Error('Public key was missing alg (AKP)');
|
|
14
|
+
}
|
|
15
|
+
if (!isCOSEAlg(alg)) {
|
|
16
|
+
throw new Error(`Public key had invalid alg ${alg} (AKP)`);
|
|
17
|
+
}
|
|
18
|
+
if (!pub) {
|
|
19
|
+
throw new Error('Public key was missing pub (AKP)');
|
|
20
|
+
}
|
|
21
|
+
const webCryptoAlg = mapCoseAlgToWebCryptoKeyAlgName(alg);
|
|
22
|
+
// See https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-import-key -> "jwk"
|
|
23
|
+
const keyData = {
|
|
24
|
+
kty: 'AKP',
|
|
25
|
+
alg: webCryptoAlg,
|
|
26
|
+
pub: isoBase64URL.fromBuffer(pub),
|
|
27
|
+
ext: false,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* ML-DSA support is pretty cutting edge, so take some steps to help RP's understand this instead
|
|
31
|
+
* of them getting a `NotSupportedError: Unrecognized algorithm name` and trying to interpret it.
|
|
32
|
+
*/
|
|
33
|
+
let key;
|
|
34
|
+
try {
|
|
35
|
+
key = await importJWKKey({ keyData, algorithm: webCryptoAlg });
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const _err = err;
|
|
39
|
+
if (_err.name === 'NotSupportedError') {
|
|
40
|
+
throw new Error(`This runtime's WebCrypto.subtle does not support use of ${webCryptoAlg}. See the \`cause\` property of this error for more info`, { cause: err });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return WebCrypto.subtle.verify(webCryptoAlg, key, signature, data);
|
|
47
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyEC2.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verifyEC2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAMvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"verifyEC2.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verifyEC2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAMvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC,OAAO,CAAC,CAuEnB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { COSECRV, COSEKEYS } from '../../cose.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { mapCoseAlgToWebCryptoHashAlgName } from './mapCoseAlgToWebCryptoHashAlgName.js';
|
|
3
|
+
import { importJWKKey } from './importJWKKey.js';
|
|
4
4
|
import { isoBase64URL } from '../index.js';
|
|
5
5
|
import { getWebCrypto } from './getWebCrypto.js';
|
|
6
6
|
/**
|
|
@@ -56,14 +56,11 @@ export async function verifyEC2(opts) {
|
|
|
56
56
|
name: 'ECDSA',
|
|
57
57
|
namedCurve: _crv,
|
|
58
58
|
};
|
|
59
|
-
const key = await
|
|
60
|
-
keyData,
|
|
61
|
-
algorithm: keyAlgorithm,
|
|
62
|
-
});
|
|
59
|
+
const key = await importJWKKey({ keyData, algorithm: keyAlgorithm });
|
|
63
60
|
// Determine which SHA algorithm to use for signature verification
|
|
64
|
-
let subtleAlg =
|
|
61
|
+
let subtleAlg = mapCoseAlgToWebCryptoHashAlgName(alg);
|
|
65
62
|
if (shaHashOverride) {
|
|
66
|
-
subtleAlg =
|
|
63
|
+
subtleAlg = mapCoseAlgToWebCryptoHashAlgName(shaHashOverride);
|
|
67
64
|
}
|
|
68
65
|
const verifyAlgorithm = {
|
|
69
66
|
name: 'ECDSA',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyOKP.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verifyOKP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAa,MAAM,eAAe,CAAC;AAKpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;CACnB,GAAG,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"verifyOKP.d.ts","sourceRoot":"","sources":["../../../../src/helpers/iso/isoCrypto/verifyOKP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAa,MAAM,eAAe,CAAC;AAKpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;CACnB,GAAG,OAAO,CAAC,OAAO,CAAC,CAsDnB"}
|