@fido4vc/fido-vc-cryptosuite-ts 1.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 (39) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +159 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +45 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/cryptosuite.d.ts +5 -0
  8. package/dist/lib/cryptosuite.d.ts.map +1 -0
  9. package/dist/lib/cryptosuite.js +25 -0
  10. package/dist/lib/cryptosuite.js.map +1 -0
  11. package/dist/lib/did.d.ts +3 -0
  12. package/dist/lib/did.d.ts.map +1 -0
  13. package/dist/lib/did.js +21 -0
  14. package/dist/lib/did.js.map +1 -0
  15. package/dist/lib/utils.d.ts +23 -0
  16. package/dist/lib/utils.d.ts.map +1 -0
  17. package/dist/lib/utils.js +16 -0
  18. package/dist/lib/utils.js.map +1 -0
  19. package/dist/suites/fido4vc/fido4vc-cryptosuite.d.ts +12 -0
  20. package/dist/suites/fido4vc/fido4vc-cryptosuite.d.ts.map +1 -0
  21. package/dist/suites/fido4vc/fido4vc-cryptosuite.js +53 -0
  22. package/dist/suites/fido4vc/fido4vc-cryptosuite.js.map +1 -0
  23. package/dist/suites/fido4vc/helpers.d.ts +11 -0
  24. package/dist/suites/fido4vc/helpers.d.ts.map +1 -0
  25. package/dist/suites/fido4vc/helpers.js +40 -0
  26. package/dist/suites/fido4vc/helpers.js.map +1 -0
  27. package/dist/suites/fido4vc/unwrap-ec2-signature.d.ts +9 -0
  28. package/dist/suites/fido4vc/unwrap-ec2-signature.d.ts.map +1 -0
  29. package/dist/suites/fido4vc/unwrap-ec2-signature.js +75 -0
  30. package/dist/suites/fido4vc/unwrap-ec2-signature.js.map +1 -0
  31. package/dist/suites/fido4vc/verify-signature-jwk.d.ts +11 -0
  32. package/dist/suites/fido4vc/verify-signature-jwk.d.ts.map +1 -0
  33. package/dist/suites/fido4vc/verify-signature-jwk.js +170 -0
  34. package/dist/suites/fido4vc/verify-signature-jwk.js.map +1 -0
  35. package/dist/types.d.ts +44 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +3 -0
  38. package/dist/types.js.map +1 -0
  39. package/package.json +78 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 The FIDO4VC Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # fido-vc-cryptosuite-ts
2
+
3
+ > TypeScript reference implementation of the [`fido4vc-jcs-2026`](https://fido4vc.github.io/spec/fido4vc-jcs-2026/) W3C VC Data Integrity cryptosuite.
4
+ > Part of the [FIDO4VC project](https://fido4vc.github.io).
5
+
6
+ A W3C [Verifiable Credential Data Integrity](https://www.w3.org/TR/vc-data-integrity/) cryptosuite for **FIDO/WebAuthn-signed Verifiable Presentations**.
7
+
8
+ When a holder presents a VP using a FIDO authenticator (Passkey, YubiKey, Touch ID, Windows Hello, …), the resulting WebAuthn assertion is wrapped as a Data Integrity proof on the VP. This package canonicalizes such documents, validates the WebAuthn challenge binding, and verifies the FIDO signature against the public key resolved from the proof's DID.
9
+
10
+ ## Features
11
+
12
+ - W3C VC Data Integrity-shaped `ICryptosuite` interface (`canonicalize` / `sign` / `verify`).
13
+ - Pluggable cryptosuite registry — register additional suites alongside the built-in one.
14
+ - Built-in suite: **`fido4vc-jcs-2026`** — verifies VPs whose proof is a FIDO/WebAuthn assertion.
15
+ - DID resolution helpers (currently supports `did:jwk`).
16
+ - Zero-config: JCS canonicalization + SHA-256 hashing of `{document, proof options}`.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install fido-vc-cryptosuite-ts
22
+ ```
23
+
24
+ Or, when developing inside this monorepo, depend on it via a local file reference:
25
+
26
+ ```json
27
+ {
28
+ "dependencies": {
29
+ "fido-vc-cryptosuite-ts": "file:../fido-vc-cryptosuite-ts"
30
+ }
31
+ }
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### Verify a Verifiable Presentation
37
+
38
+ ```ts
39
+ import { getCryptosuiteForDocument, VerifiablePresentation } from 'fido-vc-cryptosuite-ts';
40
+
41
+ async function verify(vp: VerifiablePresentation) {
42
+ const suite = getCryptosuiteForDocument(vp);
43
+ const result = await suite.verify(vp);
44
+ // { verified: true } | { verified: false, error: '...' }
45
+ return result;
46
+ }
47
+ ```
48
+
49
+ `getCryptosuiteForDocument` reads `proof.cryptosuite` from the document and returns the matching registered suite, or throws if the name is not registered.
50
+
51
+ ### Use a specific suite directly
52
+
53
+ ```ts
54
+ import { Fido4vcCryptosuite } from 'fido-vc-cryptosuite-ts';
55
+
56
+ // Compute the challenge a FIDO authenticator must sign over
57
+ const challenge = await Fido4vcCryptosuite.canonicalize(unsignedVp);
58
+
59
+ // Later, verify the assertion-signed VP
60
+ const result = await Fido4vcCryptosuite.verify(signedVp);
61
+ ```
62
+
63
+ > Note: `fido4vc-jcs-2026` is verify-only by design — the signature comes from the FIDO authenticator, not from this library. Calling `sign(...)` will throw.
64
+
65
+ ### Resolve a DID
66
+
67
+ ```ts
68
+ import { did } from 'fido-vc-cryptosuite-ts';
69
+
70
+ const jwk = did.resolveDid('did:jwk:eyJ...'); // returns the JWK public key
71
+ ```
72
+
73
+ ## Supported cryptosuites
74
+
75
+ | Name | Sign | Verify | Notes |
76
+ |------------------|------|--------|-------|
77
+ | `fido4vc-jcs-2026` | ❌ | ✅ | FIDO2/WebAuthn assertions over JCS-canonicalized VP |
78
+
79
+ ## Supported DID methods
80
+
81
+ | Method | Status |
82
+ |------------|--------|
83
+ | `did:jwk` | ✅ |
84
+
85
+ ## How verification works (`fido4vc-jcs-2026`)
86
+
87
+ 1. Strip the `proof` from the VP; JCS-canonicalize the document and the proof options separately.
88
+ 2. SHA-256 hash them in sequence — this is the **expected challenge**.
89
+ 3. Extract `clientData.challenge` from the proof value and confirm it equals the expected challenge.
90
+ 4. Resolve `proof.verificationMethod` (DID) to a JWK public key.
91
+ 5. Recompute the WebAuthn signed bytes (`authenticatorData || sha256(clientData)`) and verify the signature against the resolved key.
92
+
93
+ Any failure returns `{ verified: false, error }`; success returns `{ verified: true }`.
94
+
95
+ ## Public API
96
+
97
+ ```ts
98
+ export interface ICryptosuite {
99
+ name: string;
100
+ canonicalize(document: JsonDocument): Promise<Buffer>;
101
+ sign<T>(document: JsonLdDocument): Promise<T>;
102
+ verify(document: JsonLdDocument): Promise<VerificationResult>;
103
+ }
104
+
105
+ export function getCryptosuite(name: string): ICryptosuite;
106
+ export function getCryptosuiteForDocument(vp: VerifiablePresentation): ICryptosuite;
107
+
108
+ export const Fido4vcCryptosuite: ICryptosuite;
109
+ export const did: { resolveDid(did: string): JwkPublicKey };
110
+
111
+ // Types: JsonDocument, JsonLdDocument, Proof, VerifiablePresentation,
112
+ // SignOptions, VerificationResult, JwkPublicKey, ProofValueType
113
+ ```
114
+
115
+ ## Develop locally
116
+
117
+ Prerequisites: Node.js ≥ 18, npm.
118
+
119
+ ```bash
120
+ git clone https://github.com/fido4vc/fido-vc-cryptosuite-ts
121
+ cd fido-vc-cryptosuite-ts
122
+ npm install
123
+ npm run build # compile TS -> dist/
124
+ npm test # run Jest test suite
125
+ ```
126
+
127
+ ## Scripts
128
+
129
+ | Script | What it does |
130
+ |---------------------|-----------------------------------------------|
131
+ | `npm run build` | Compile TypeScript to `dist/` |
132
+ | `npm run watch` | Compile in watch mode |
133
+ | `npm run clean` | Remove `dist/` |
134
+ | `npm test` | Run Jest tests |
135
+ | `npm run lint` | Run ESLint |
136
+ | `npm run lint:fix` | Run ESLint with `--fix` |
137
+ | `npm run format` | Format source with Prettier |
138
+
139
+ ## Publishing
140
+
141
+ `prepublishOnly` cleans and rebuilds before publish, so a fresh `dist/` is always shipped. The published tarball contains only `dist/`, `README.md`, and `LICENSE` (see `files` in [package.json](./package.json)).
142
+
143
+ ```bash
144
+ npm publish
145
+ ```
146
+
147
+ For private registries, configure `publishConfig.registry` in `package.json` accordingly.
148
+
149
+ ## Related projects
150
+
151
+ Part of the [FIDO4VC project](https://github.com/fido4vc):
152
+
153
+ - [fido-vc-middleware](https://github.com/fido4vc/fido-vc-middleware) — Express bridge between FIDO/WebAuthn and the walt.id Wallet API. Consumes this package.
154
+ - [fido-vc-verifier-sidecar](https://github.com/fido4vc/fido-vc-verifier-sidecar) — HTTP service exposing this cryptosuite's verification to non-Node verifier stacks.
155
+ - [fido-vc-wallet-ui](https://github.com/fido4vc/fido-vc-wallet-ui) — Next.js user-facing wallet UI.
156
+
157
+ ## License
158
+
159
+ Licensed under the [Apache License 2.0](./LICENSE).
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './lib/cryptosuite';
3
+ export { Fido4vcCryptosuite } from './suites/fido4vc/fido4vc-cryptosuite';
4
+ export * as did from './lib/did';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.did = exports.Fido4vcCryptosuite = void 0;
40
+ __exportStar(require("./types"), exports);
41
+ __exportStar(require("./lib/cryptosuite"), exports);
42
+ var fido4vc_cryptosuite_1 = require("./suites/fido4vc/fido4vc-cryptosuite");
43
+ Object.defineProperty(exports, "Fido4vcCryptosuite", { enumerable: true, get: function () { return fido4vc_cryptosuite_1.Fido4vcCryptosuite; } });
44
+ exports.did = __importStar(require("./lib/did"));
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,oDAAkC;AAClC,4EAA0E;AAAjE,yHAAA,kBAAkB,OAAA;AAC3B,iDAAiC"}
@@ -0,0 +1,5 @@
1
+ import { ICryptosuite, VerifiablePresentation } from '../types';
2
+ export declare const supportedSuites: Map<string, ICryptosuite>;
3
+ export declare function getCryptosuite(cryptosuiteName: string): ICryptosuite;
4
+ export declare function getCryptosuiteForDocument(document: VerifiablePresentation): ICryptosuite;
5
+ //# sourceMappingURL=cryptosuite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptosuite.d.ts","sourceRoot":"","sources":["../../src/lib/cryptosuite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIhE,eAAO,MAAM,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAEpD,CAAC;AAEH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,YAAY,CAMpE;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,YAAY,CAMxF"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.supportedSuites = void 0;
4
+ exports.getCryptosuite = getCryptosuite;
5
+ exports.getCryptosuiteForDocument = getCryptosuiteForDocument;
6
+ const fido4vc_cryptosuite_1 = require("../suites/fido4vc/fido4vc-cryptosuite");
7
+ const utils_1 = require("../lib/utils");
8
+ exports.supportedSuites = new Map([
9
+ [fido4vc_cryptosuite_1.Fido4vcCryptosuite.name, fido4vc_cryptosuite_1.Fido4vcCryptosuite],
10
+ ]);
11
+ function getCryptosuite(cryptosuiteName) {
12
+ const suiteObj = exports.supportedSuites.get(cryptosuiteName);
13
+ if (!suiteObj) {
14
+ throw new Error(`Unsupported cryptosuite: ${cryptosuiteName}`);
15
+ }
16
+ return suiteObj;
17
+ }
18
+ function getCryptosuiteForDocument(document) {
19
+ const cryptosuite = (0, utils_1.getProofData)(document).proof.cryptosuite;
20
+ if (!cryptosuite || typeof cryptosuite !== 'string') {
21
+ throw new Error('Cryptosuite type is missing or invalid in the document proof');
22
+ }
23
+ return getCryptosuite(cryptosuite);
24
+ }
25
+ //# sourceMappingURL=cryptosuite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cryptosuite.js","sourceRoot":"","sources":["../../src/lib/cryptosuite.ts"],"names":[],"mappings":";;;AAQA,wCAMC;AAED,8DAMC;AArBD,+EAA2E;AAC3E,wCAA4C;AAE/B,QAAA,eAAe,GAA8B,IAAI,GAAG,CAAC;IAChE,CAAC,wCAAkB,CAAC,IAAI,EAAE,wCAAkB,CAAC;CAC9C,CAAC,CAAC;AAEH,SAAgB,cAAc,CAAC,eAAuB;IACpD,MAAM,QAAQ,GAAG,uBAAe,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACtD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,eAAe,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,yBAAyB,CAAC,QAAgC;IACxE,MAAM,WAAW,GAAG,IAAA,oBAAY,EAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC;IAC7D,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,cAAc,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { JwkPublicKey } from '../types';
2
+ export declare function resolveDid(did: string): JwkPublicKey;
3
+ //# sourceMappingURL=did.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../../src/lib/did.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAKpD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDid = resolveDid;
4
+ const utils_1 = require("./utils");
5
+ function resolveDid(did) {
6
+ const [prefix, method, identifier] = did.split(':');
7
+ if (prefix !== 'did')
8
+ throw new Error('Invalid DID prefix');
9
+ if (method === 'jwk')
10
+ return resolveJwkDid(identifier);
11
+ throw new Error(`Unsupported DID method: ${method}`);
12
+ }
13
+ function resolveJwkDid(identifier) {
14
+ const base = identifier.split('#')[0];
15
+ const decoded = (0, utils_1.base64urlToUtf8)(base);
16
+ const jwk = JSON.parse(decoded);
17
+ if (!jwk.kty)
18
+ throw new Error('Invalid JWK DID: missing "kty" field');
19
+ return jwk;
20
+ }
21
+ //# sourceMappingURL=did.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.js","sourceRoot":"","sources":["../../src/lib/did.ts"],"names":[],"mappings":";;AAGA,gCAKC;AAPD,mCAA0C;AAE1C,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpD,IAAI,MAAM,KAAK,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC5D,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,aAAa,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,aAAa,CAAC,UAAkB;IACvC,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtE,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { VerifiablePresentation } from '../types';
2
+ export declare function getProofData(document: VerifiablePresentation): {
3
+ proof: import("../types").Proof;
4
+ proofValue: import("../types").ProofValueType;
5
+ docWithoutProof: {
6
+ [key: string]: unknown;
7
+ type: string | string[];
8
+ verifiableCredential?: unknown[];
9
+ holder?: string;
10
+ '@context': string | string[] | object | object[];
11
+ };
12
+ proofOptions: {
13
+ type: string;
14
+ cryptosuite: string;
15
+ verificationMethod: string;
16
+ proofPurpose: string;
17
+ created?: string;
18
+ challenge?: string;
19
+ domain?: string;
20
+ };
21
+ };
22
+ export declare function base64urlToUtf8(base64urlString: string): string;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;EAM5D;AAED,wBAAgB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAE/D"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProofData = getProofData;
4
+ exports.base64urlToUtf8 = base64urlToUtf8;
5
+ function getProofData(document) {
6
+ const { proof, ...docWithoutProof } = document;
7
+ if (!proof)
8
+ throw new Error('Proof is missing in the document');
9
+ const proofObj = Array.isArray(proof) ? proof[0] : proof;
10
+ const { proofValue, ...proofOptions } = proofObj;
11
+ return { proof: proofObj, proofValue, docWithoutProof, proofOptions };
12
+ }
13
+ function base64urlToUtf8(base64urlString) {
14
+ return Buffer.from(base64urlString, 'base64url').toString('utf8');
15
+ }
16
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":";;AAEA,oCAMC;AAED,0CAEC;AAVD,SAAgB,YAAY,CAAC,QAAgC;IAC3D,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,EAAE,GAAG,QAAQ,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,EAAE,GAAG,QAAQ,CAAC;IACjD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AACxE,CAAC;AAED,SAAgB,eAAe,CAAC,eAAuB;IACrD,OAAO,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { ICryptosuite, JsonLdDocument, VerifiablePresentation } from '../../types';
2
+ export declare function canonicalize(document: VerifiablePresentation): Promise<NonSharedBuffer>;
3
+ export declare function sign<ProofValue>(_options: JsonLdDocument): Promise<ProofValue>;
4
+ export declare function verify(document: VerifiablePresentation): Promise<{
5
+ verified: boolean;
6
+ error?: undefined;
7
+ } | {
8
+ verified: boolean;
9
+ error: string;
10
+ }>;
11
+ export declare const Fido4vcCryptosuite: ICryptosuite;
12
+ //# sourceMappingURL=fido4vc-cryptosuite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fido4vc-cryptosuite.d.ts","sourceRoot":"","sources":["../../../src/suites/fido4vc/fido4vc-cryptosuite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAQnF,wBAAsB,YAAY,CAAC,QAAQ,EAAE,sBAAsB,4BASlE;AAED,wBAAsB,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAEpF;AAED,wBAAsB,MAAM,CAAC,QAAQ,EAAE,sBAAsB;;;;;;GAiB5D;AAED,eAAO,MAAM,kBAAkB,EAAE,YAKhC,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Fido4vcCryptosuite = void 0;
7
+ exports.canonicalize = canonicalize;
8
+ exports.sign = sign;
9
+ exports.verify = verify;
10
+ const crypto_1 = require("crypto");
11
+ const utils_1 = require("../../lib/utils");
12
+ const canonicalize_1 = __importDefault(require("canonicalize"));
13
+ const helpers_1 = require("./helpers");
14
+ const did_1 = require("../../lib/did");
15
+ const name = 'fido4vc-jcs-2026';
16
+ async function canonicalize(document) {
17
+ const { proofOptions, docWithoutProof } = (0, utils_1.getProofData)(document);
18
+ const canonical = (0, canonicalize_1.default)(docWithoutProof);
19
+ const canonicalProofOptions = (0, canonicalize_1.default)(proofOptions);
20
+ const hash = (0, crypto_1.createHash)('sha256');
21
+ hash.update(canonical);
22
+ hash.update(canonicalProofOptions);
23
+ return hash.digest();
24
+ }
25
+ async function sign(_options) {
26
+ throw new Error(`${name} doesn't support signing.`);
27
+ }
28
+ async function verify(document) {
29
+ try {
30
+ const proofValue = (0, helpers_1.extractProofValue)(document);
31
+ const challenge = await canonicalize(document).then((buf) => buf.toString('base64url'));
32
+ const extractedChallenge = (0, helpers_1.extractChallenge)(proofValue.clientData);
33
+ if (challenge !== extractedChallenge) {
34
+ throw new Error('Challenge mismatch');
35
+ }
36
+ const publicKey = (0, did_1.resolveDid)((0, utils_1.getProofData)(document).proof.verificationMethod);
37
+ const isSignatureValid = await (0, helpers_1.verifyProofSignature)(proofValue, publicKey);
38
+ if (!isSignatureValid) {
39
+ throw new Error('Invalid signature');
40
+ }
41
+ return { verified: true };
42
+ }
43
+ catch (error) {
44
+ return { verified: false, error: error.message };
45
+ }
46
+ }
47
+ exports.Fido4vcCryptosuite = {
48
+ name,
49
+ canonicalize,
50
+ sign,
51
+ verify,
52
+ };
53
+ //# sourceMappingURL=fido4vc-cryptosuite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fido4vc-cryptosuite.js","sourceRoot":"","sources":["../../../src/suites/fido4vc/fido4vc-cryptosuite.ts"],"names":[],"mappings":";;;;;;AASA,oCASC;AAED,oBAEC;AAED,wBAiBC;AAzCD,mCAAoC;AAEpC,2CAA+C;AAC/C,gEAA2C;AAC3C,uCAAsF;AACtF,uCAA2C;AAE3C,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEzB,KAAK,UAAU,YAAY,CAAC,QAAgC;IACjE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,IAAA,oBAAY,EAAC,QAAQ,CAAC,CAAC;IACjE,MAAM,SAAS,GAAG,IAAA,sBAAe,EAAC,eAAe,CAAE,CAAC;IACpD,MAAM,qBAAqB,GAAG,IAAA,sBAAe,EAAC,YAAY,CAAE,CAAC;IAE7D,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACvB,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;AACvB,CAAC;AAEM,KAAK,UAAU,IAAI,CAAa,QAAwB;IAC7D,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,2BAA2B,CAAC,CAAC;AACtD,CAAC;AAEM,KAAK,UAAU,MAAM,CAAC,QAAgC;IAC3D,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,IAAA,2BAAiB,EAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;QACxF,MAAM,kBAAkB,GAAG,IAAA,0BAAgB,EAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACnE,IAAI,SAAS,KAAK,kBAAkB,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,SAAS,GAAG,IAAA,gBAAU,EAAC,IAAA,oBAAY,EAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC9E,MAAM,gBAAgB,GAAG,MAAM,IAAA,8BAAoB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QAC3E,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,CAAC;IAC9D,CAAC;AACH,CAAC;AAEY,QAAA,kBAAkB,GAAiB;IAC9C,IAAI;IACJ,YAAY;IACZ,IAAI;IACJ,MAAM;CACP,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { JwkPublicKey, VerifiablePresentation } from '../../types';
2
+ interface ProofValue {
3
+ clientData: string;
4
+ authenticatorData: string;
5
+ signature: string;
6
+ }
7
+ export declare function extractProofValue(document: VerifiablePresentation): ProofValue;
8
+ export declare function verifyProofSignature(proofValue: ProofValue, publicKey: JwkPublicKey): Promise<boolean>;
9
+ export declare function extractChallenge(clientData: string): string;
10
+ export {};
11
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/suites/fido4vc/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAInE,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,UAAU,CAgB9E;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,YAAY,GACtB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAO3D"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractProofValue = extractProofValue;
4
+ exports.verifyProofSignature = verifyProofSignature;
5
+ exports.extractChallenge = extractChallenge;
6
+ const crypto_1 = require("crypto");
7
+ const utils_1 = require("../../lib/utils");
8
+ const verify_signature_jwk_1 = require("./verify-signature-jwk");
9
+ function extractProofValue(document) {
10
+ const { proofValue } = (0, utils_1.getProofData)(document);
11
+ if (!proofValue || typeof proofValue !== 'object')
12
+ throw new Error('Invalid type of proofValue in document');
13
+ const { clientData, authenticatorData, signature } = proofValue;
14
+ if (!clientData || !authenticatorData || !signature) {
15
+ throw new Error('Missing fields in proofValue');
16
+ }
17
+ if (typeof clientData !== 'string' ||
18
+ typeof authenticatorData !== 'string' ||
19
+ typeof signature !== 'string') {
20
+ throw new Error('Invalid types in proofValue fields');
21
+ }
22
+ return { clientData, authenticatorData, signature };
23
+ }
24
+ async function verifyProofSignature(proofValue, publicKey) {
25
+ const clientDataBuffer = Buffer.from(proofValue.clientData, 'base64url');
26
+ const clientDataHash = (0, crypto_1.createHash)('sha256').update(clientDataBuffer).digest();
27
+ const authDataBuffer = Buffer.from(proofValue.authenticatorData, 'base64url');
28
+ const data = Buffer.concat([authDataBuffer, clientDataHash]);
29
+ const signatureBuffer = Buffer.from(proofValue.signature, 'base64url');
30
+ return await (0, verify_signature_jwk_1.verifyFidoSignature)({ keyData: publicKey, signature: signatureBuffer, data });
31
+ }
32
+ function extractChallenge(clientData) {
33
+ const clientDataDecoded = (0, utils_1.base64urlToUtf8)(clientData);
34
+ const clientDataJSON = JSON.parse(clientDataDecoded);
35
+ if (!clientDataJSON.challenge) {
36
+ throw new Error('Challenge not found in clientData');
37
+ }
38
+ return clientDataJSON.challenge;
39
+ }
40
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/suites/fido4vc/helpers.ts"],"names":[],"mappings":";;AAWA,8CAgBC;AAED,oDAUC;AAED,4CAOC;AAhDD,mCAAoC;AAEpC,2CAAgE;AAChE,iEAA6D;AAQ7D,SAAgB,iBAAiB,CAAC,QAAgC;IAChE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,oBAAY,EAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ;QAC/C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;IAChE,IAAI,CAAC,UAAU,IAAI,CAAC,iBAAiB,IAAI,CAAC,SAAS,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,IACE,OAAO,UAAU,KAAK,QAAQ;QAC9B,OAAO,iBAAiB,KAAK,QAAQ;QACrC,OAAO,SAAS,KAAK,QAAQ,EAC7B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC;AACtD,CAAC;AAEM,KAAK,UAAU,oBAAoB,CACxC,UAAsB,EACtB,SAAuB;IAEvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IACzE,MAAM,cAAc,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC;IAC9E,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;IAC7D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACvE,OAAO,MAAM,IAAA,0CAAmB,EAAC,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7F,CAAC;AAED,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,MAAM,iBAAiB,GAAG,IAAA,uBAAe,EAAC,UAAU,CAAC,CAAC;IACtD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrD,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,cAAc,CAAC,SAAS,CAAC;AAClC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { cose } from '@simplewebauthn/server/helpers';
2
+ import { Uint8Array_ } from '@simplewebauthn/server';
3
+ /**
4
+ * In WebAuthn, EC2 signatures are wrapped in ASN.1 structure so we need to peel r and s apart.
5
+ *
6
+ * See https://www.w3.org/TR/webauthn-2/#sctn-signature-attestation-types
7
+ */
8
+ export declare function unwrapEC2Signature(signature: Uint8Array_, crv: cose.COSECRV): Uint8Array_;
9
+ //# sourceMappingURL=unwrap-ec2-signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap-ec2-signature.d.ts","sourceRoot":"","sources":["../../../src/suites/fido4vc/unwrap-ec2-signature.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,GAAG,WAAW,CAczF"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapEC2Signature = unwrapEC2Signature;
4
+ const asn1_schema_1 = require("@peculiar/asn1-schema");
5
+ const asn1_ecc_1 = require("@peculiar/asn1-ecc");
6
+ const helpers_1 = require("@simplewebauthn/server/helpers");
7
+ /**
8
+ * In WebAuthn, EC2 signatures are wrapped in ASN.1 structure so we need to peel r and s apart.
9
+ *
10
+ * See https://www.w3.org/TR/webauthn-2/#sctn-signature-attestation-types
11
+ */
12
+ function unwrapEC2Signature(signature, crv) {
13
+ const parsedSignature = asn1_schema_1.AsnParser.parse(signature, asn1_ecc_1.ECDSASigValue);
14
+ const rBytes = new Uint8Array(parsedSignature.r);
15
+ const sBytes = new Uint8Array(parsedSignature.s);
16
+ const componentLength = getSignatureComponentLength(crv);
17
+ const rNormalizedBytes = toNormalizedBytes(rBytes, componentLength);
18
+ const sNormalizedBytes = toNormalizedBytes(sBytes, componentLength);
19
+ const finalSignature = new Uint8Array(rNormalizedBytes.length + sNormalizedBytes.length);
20
+ finalSignature.set(rNormalizedBytes, 0);
21
+ finalSignature.set(sNormalizedBytes, rNormalizedBytes.length);
22
+ return finalSignature;
23
+ }
24
+ /**
25
+ * The SubtleCrypto Web Crypto API expects ECDSA signatures with `r` and `s` values to be encoded
26
+ * to a specific length depending on the order of the curve. This function returns the expected
27
+ * byte-length for each of the `r` and `s` signature components.
28
+ *
29
+ * See <https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations>
30
+ */
31
+ function getSignatureComponentLength(crv) {
32
+ switch (crv) {
33
+ case helpers_1.cose.COSECRV.P256:
34
+ return 32;
35
+ case helpers_1.cose.COSECRV.P384:
36
+ return 48;
37
+ case helpers_1.cose.COSECRV.P521:
38
+ return 66;
39
+ default:
40
+ throw new Error(`Unexpected COSE crv value of ${crv} (EC2)`);
41
+ }
42
+ }
43
+ /**
44
+ * Converts the ASN.1 integer representation to bytes of a specific length `n`.
45
+ *
46
+ * DER encodes integers as big-endian byte arrays, with as small as possible representation and
47
+ * requires a leading `0` byte to disambiguate between negative and positive numbers. This means
48
+ * that `r` and `s` can potentially not be the expected byte-length that is needed by the
49
+ * SubtleCrypto Web Crypto API: if there are leading `0`s it can be shorter than expected, and if
50
+ * it has a leading `1` bit, it can be one byte longer.
51
+ *
52
+ * See <https://www.itu.int/rec/T-REC-X.690-202102-I/en>
53
+ * See <https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations>
54
+ */
55
+ function toNormalizedBytes(bytes, componentLength) {
56
+ let normalizedBytes;
57
+ if (bytes.length < componentLength) {
58
+ // In case the bytes are shorter than expected, we need to pad it with leading `0`s.
59
+ normalizedBytes = new Uint8Array(componentLength);
60
+ normalizedBytes.set(bytes, componentLength - bytes.length);
61
+ }
62
+ else if (bytes.length === componentLength) {
63
+ normalizedBytes = bytes;
64
+ }
65
+ else if (bytes.length === componentLength + 1 && bytes[0] === 0 && (bytes[1] & 0x80) === 0x80) {
66
+ // The bytes contain a leading `0` to encode that the integer is positive. This leading `0`
67
+ // needs to be removed for compatibility with the SubtleCrypto Web Crypto API.
68
+ normalizedBytes = bytes.subarray(1);
69
+ }
70
+ else {
71
+ throw new Error(`Invalid signature component length ${bytes.length}, expected ${componentLength}`);
72
+ }
73
+ return normalizedBytes;
74
+ }
75
+ //# sourceMappingURL=unwrap-ec2-signature.js.map
@@ -0,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IAAI,KAAK,CAAC,gCAAgC,GAAG,QAAQ,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CAAC,KAAkB,EAAE,eAAuB;IACpE,IAAI,eAA4B,CAAC;IAEjC,IAAI,KAAK,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QACnC,oFAAoF;QACpF,eAAe,GAAG,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC;QAClD,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;SAAM,IAAI,KAAK,CAAC,MAAM,KAAK,eAAe,EAAE,CAAC;QAC5C,eAAe,GAAG,KAAK,CAAC;IAC1B,CAAC;SAAM,IAAI,KAAK,CAAC,MAAM,KAAK,eAAe,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAChG,2FAA2F;QAC3F,8EAA8E;QAC9E,eAAe,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,sCAAsC,KAAK,CAAC,MAAM,cAAc,eAAe,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { webcrypto } from 'crypto';
2
+ import type { Uint8Array_ } from '@simplewebauthn/server';
3
+ /**
4
+ * Verify signatures with JWK public key. Supports EC2, OKP, and RSA public keys.
5
+ */
6
+ export declare function verifyFidoSignature(opts: {
7
+ keyData: webcrypto.JsonWebKey;
8
+ signature: Uint8Array_;
9
+ data: Uint8Array_;
10
+ }): Promise<boolean>;
11
+ //# sourceMappingURL=verify-signature-jwk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-signature-jwk.d.ts","sourceRoot":"","sources":["../../../src/suites/fido4vc/verify-signature-jwk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAyK1D;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAC9C,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC;IAC9B,SAAS,EAAE,WAAW,CAAC;IACvB,IAAI,EAAE,WAAW,CAAC;CACnB,GAAG,OAAO,CAAC,OAAO,CAAC,CAyBnB"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyFidoSignature = verifyFidoSignature;
4
+ const helpers_1 = require("@simplewebauthn/server/helpers");
5
+ const unwrap_ec2_signature_1 = require("./unwrap-ec2-signature");
6
+ /**
7
+ * Import a JWK key using Node.js crypto
8
+ */
9
+ async function importKey(opts) {
10
+ const { keyData, algorithm } = opts;
11
+ return crypto.subtle.importKey('jwk', keyData, algorithm, false, ['verify']);
12
+ }
13
+ /**
14
+ * Verify a signature using an EC2 public key in JWK format
15
+ */
16
+ async function verifyEC2(opts) {
17
+ const { keyData, signature, data } = opts;
18
+ if (!keyData.crv) {
19
+ throw new Error('JWK was missing crv (EC2)');
20
+ }
21
+ const keyAlgorithm = {
22
+ name: 'ECDSA',
23
+ namedCurve: keyData.crv,
24
+ };
25
+ const key = await importKey({
26
+ keyData,
27
+ algorithm: keyAlgorithm,
28
+ });
29
+ // Determine which SHA algorithm to use for signature verification
30
+ // Default to SHA-256 for P-256, SHA-384 for P-384, SHA-512 for P-521
31
+ let hashName = 'SHA-256';
32
+ if (keyData.crv === 'P-384') {
33
+ hashName = 'SHA-384';
34
+ }
35
+ else if (keyData.crv === 'P-521') {
36
+ hashName = 'SHA-512';
37
+ }
38
+ const verifyAlgorithm = {
39
+ name: 'ECDSA',
40
+ hash: { name: hashName },
41
+ };
42
+ return crypto.subtle.verify(verifyAlgorithm, key, signature, data);
43
+ }
44
+ /**
45
+ * Verify a signature using an OKP public key in JWK format
46
+ */
47
+ async function verifyOKP(opts) {
48
+ const { keyData, signature, data } = opts;
49
+ if (!keyData.crv) {
50
+ throw new Error('JWK was missing crv (OKP)');
51
+ }
52
+ let _crv;
53
+ if (keyData.crv === 'Ed25519') {
54
+ _crv = 'Ed25519';
55
+ }
56
+ else {
57
+ throw new Error(`Unexpected JWK crv value of ${keyData.crv} (OKP)`);
58
+ }
59
+ const keyAlgorithm = {
60
+ name: _crv,
61
+ namedCurve: _crv,
62
+ };
63
+ const key = await importKey({
64
+ keyData,
65
+ algorithm: keyAlgorithm,
66
+ });
67
+ const verifyAlgorithm = {
68
+ name: _crv,
69
+ };
70
+ return crypto.subtle.verify(verifyAlgorithm, key, signature, data);
71
+ }
72
+ /**
73
+ * Verify a signature using an RSA public key in JWK format
74
+ */
75
+ async function verifyRSA(opts) {
76
+ const { keyData, signature, data } = opts;
77
+ if (!keyData.alg) {
78
+ throw new Error('JWK was missing alg (RSA)');
79
+ }
80
+ // Determine algorithm name and hash from JWK alg
81
+ let algorithmName;
82
+ let hashName;
83
+ let saltLength;
84
+ if (keyData.alg === 'RS256' ||
85
+ keyData.alg === 'RS384' ||
86
+ keyData.alg === 'RS512' ||
87
+ keyData.alg === 'RS1') {
88
+ algorithmName = 'RSASSA-PKCS1-v1_5';
89
+ if (keyData.alg === 'RS256') {
90
+ hashName = 'SHA-256';
91
+ }
92
+ else if (keyData.alg === 'RS384') {
93
+ hashName = 'SHA-384';
94
+ }
95
+ else if (keyData.alg === 'RS512') {
96
+ hashName = 'SHA-512';
97
+ }
98
+ else if (keyData.alg === 'RS1') {
99
+ hashName = 'SHA-1';
100
+ }
101
+ else {
102
+ throw new Error(`Unexpected RSA alg ${keyData.alg}`);
103
+ }
104
+ }
105
+ else if (keyData.alg === 'PS256' || keyData.alg === 'PS384' || keyData.alg === 'PS512') {
106
+ algorithmName = 'RSA-PSS';
107
+ if (keyData.alg === 'PS256') {
108
+ hashName = 'SHA-256';
109
+ saltLength = 32;
110
+ }
111
+ else if (keyData.alg === 'PS384') {
112
+ hashName = 'SHA-384';
113
+ saltLength = 48;
114
+ }
115
+ else if (keyData.alg === 'PS512') {
116
+ hashName = 'SHA-512';
117
+ saltLength = 64;
118
+ }
119
+ else {
120
+ throw new Error(`Unexpected RSA-PSS alg ${keyData.alg}`);
121
+ }
122
+ }
123
+ else {
124
+ throw new Error(`Unsupported RSA algorithm ${keyData.alg}`);
125
+ }
126
+ const keyAlgorithm = {
127
+ name: algorithmName,
128
+ hash: { name: hashName },
129
+ };
130
+ const key = await importKey({
131
+ keyData,
132
+ algorithm: keyAlgorithm,
133
+ });
134
+ const verifyAlgorithm = {
135
+ name: algorithmName,
136
+ saltLength,
137
+ };
138
+ return crypto.subtle.verify(verifyAlgorithm, key, signature, data);
139
+ }
140
+ /**
141
+ * Verify signatures with JWK public key. Supports EC2, OKP, and RSA public keys.
142
+ */
143
+ async function verifyFidoSignature(opts) {
144
+ const { keyData, signature, data } = opts;
145
+ if (keyData.kty === 'EC') {
146
+ let unwrappedSignature = signature;
147
+ if (keyData.crv === 'P-256') {
148
+ unwrappedSignature = (0, unwrap_ec2_signature_1.unwrapEC2Signature)(signature, helpers_1.cose.COSECRV.P256);
149
+ }
150
+ else if (keyData.crv === 'P-384') {
151
+ unwrappedSignature = (0, unwrap_ec2_signature_1.unwrapEC2Signature)(signature, helpers_1.cose.COSECRV.P384);
152
+ }
153
+ else if (keyData.crv === 'P-521') {
154
+ unwrappedSignature = (0, unwrap_ec2_signature_1.unwrapEC2Signature)(signature, helpers_1.cose.COSECRV.P521);
155
+ }
156
+ return verifyEC2({
157
+ keyData,
158
+ signature: unwrappedSignature,
159
+ data,
160
+ });
161
+ }
162
+ else if (keyData.kty === 'RSA') {
163
+ return verifyRSA({ keyData, signature, data });
164
+ }
165
+ else if (keyData.kty === 'OKP') {
166
+ return verifyOKP({ keyData, signature, data });
167
+ }
168
+ throw new Error(`Signature verification with JWK of kty ${keyData.kty} is not supported`);
169
+ }
170
+ //# sourceMappingURL=verify-signature-jwk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-signature-jwk.js","sourceRoot":"","sources":["../../../src/suites/fido4vc/verify-signature-jwk.ts"],"names":[],"mappings":";;AA8KA,kDA6BC;AA1MD,4DAAsD;AAEtD,iEAA4D;AAE5D;;GAEG;AACH,KAAK,UAAU,SAAS,CAAC,IAMxB;IACC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,SAAS,CAAC,IAIxB;IACC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAE1C,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,YAAY,GAAgC;QAChD,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,OAAO,CAAC,GAAG;KACxB,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC;QAC1B,OAAO;QACP,SAAS,EAAE,YAAY;KACxB,CAAC,CAAC;IAEH,kEAAkE;IAClE,qEAAqE;IACrE,IAAI,QAAQ,GAAG,SAAS,CAAC;IACzB,IAAI,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;QAC5B,QAAQ,GAAG,SAAS,CAAC;IACvB,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;QACnC,QAAQ,GAAG,SAAS,CAAC;IACvB,CAAC;IAED,MAAM,eA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,CAAC;aAAM,IAAI,OAAO,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;YACnC,kBAAkB,GAAG,IAAA,yCAAkB,EAAC,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,SAAS,CAAC;YACf,OAAO;YACP,SAAS,EAAE,kBAAkB;YAC7B,IAAI;SACL,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,OAAO,CAAC,GAAG,mBAAmB,CAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { webcrypto } from 'crypto';
2
+ export type JwkPublicKey = webcrypto.JsonWebKey;
3
+ export type ProofValueType = string | number | JsonDocument;
4
+ export interface JsonDocument {
5
+ [key: string]: unknown;
6
+ }
7
+ export interface JsonLdDocument extends JsonDocument {
8
+ '@context': string | string[] | object | object[];
9
+ }
10
+ export interface Proof {
11
+ type: string;
12
+ cryptosuite: string;
13
+ verificationMethod: string;
14
+ proofPurpose: string;
15
+ proofValue: ProofValueType;
16
+ created?: string;
17
+ challenge?: string;
18
+ domain?: string;
19
+ }
20
+ export interface VerifiablePresentation extends JsonLdDocument {
21
+ type: string | string[];
22
+ verifiableCredential?: unknown[];
23
+ holder?: string;
24
+ proof?: Proof | Proof[];
25
+ }
26
+ export interface SignOptions {
27
+ document: JsonLdDocument;
28
+ privateKey: JwkPublicKey;
29
+ verificationMethod: string;
30
+ proofPurpose: string;
31
+ challenge?: string;
32
+ domain?: string;
33
+ }
34
+ export interface VerificationResult {
35
+ verified: boolean;
36
+ error?: string;
37
+ }
38
+ export interface ICryptosuite {
39
+ name: string;
40
+ canonicalize(document: JsonDocument): Promise<Buffer<ArrayBuffer>>;
41
+ sign<T extends ProofValueType>(options: JsonLdDocument): Promise<T>;
42
+ verify(options: JsonLdDocument): Promise<VerificationResult>;
43
+ }
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC;AAChD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,oBAAoB,CAAC,EAAE,OAAO,EAAE,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,YAAY,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,IAAI,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC9D"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@fido4vc/fido-vc-cryptosuite-ts",
3
+ "version": "1.0.1",
4
+ "description": "W3C VC Data Integrity cryptosuite for FIDO/WebAuthn-signed Verifiable Presentations — TypeScript reference implementation.",
5
+ "license": "Apache-2.0",
6
+ "author": "",
7
+ "type": "commonjs",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "module": "dist/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "require": "./dist/index.js",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "keywords": [
27
+ "fido",
28
+ "fido2",
29
+ "webauthn",
30
+ "verifiable-credentials",
31
+ "verifiable-presentations",
32
+ "vc",
33
+ "json-ld",
34
+ "data-integrity",
35
+ "cryptosuite",
36
+ "did",
37
+ "ssi"
38
+ ],
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/fido4vc/fido-vc-cryptosuite-ts.git"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "registry": "https://registry.npmjs.org/"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc",
49
+ "watch": "tsc --watch",
50
+ "clean": "rimraf dist",
51
+ "prepublishOnly": "npm run clean && npm run build",
52
+ "test": "jest",
53
+ "lint": "eslint . --ext .ts",
54
+ "lint:fix": "eslint . --ext .ts --fix",
55
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
56
+ "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\""
57
+ },
58
+ "devDependencies": {
59
+ "@semantic-release/changelog": "^6.0.3",
60
+ "@semantic-release/git": "^10.0.1",
61
+ "@types/jest": "^30.0.0",
62
+ "@types/node": "^25.0.9",
63
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
64
+ "@typescript-eslint/parser": "^8.0.0",
65
+ "eslint": "^9.0.0",
66
+ "eslint-config-prettier": "^9.1.0",
67
+ "jest": "^30.2.0",
68
+ "prettier": "^3.4.0",
69
+ "rimraf": "^6.0.0",
70
+ "semantic-release": "^24.2.0",
71
+ "ts-jest": "^29.4.6",
72
+ "typescript": "^5.9.3"
73
+ },
74
+ "dependencies": {
75
+ "@simplewebauthn/server": "^13.2.2",
76
+ "canonicalize": "^2.1.0"
77
+ }
78
+ }