@sphereon/ssi-sdk.sd-jwt 0.24.1-next.112

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/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 reasonable and customary use in describing the
141
+ origin of the Work and 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 2019 Consensys AG
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,3 @@
1
+ # Veramo selective disclosure JWT plugin
2
+
3
+ This package provides a Veramo plugin that can create, present and verify selective disclosure JWTs.
@@ -0,0 +1,69 @@
1
+ import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
2
+ import { IAgentPlugin } from '@veramo/core';
3
+ import { SdJWTImplementation, ICreateSdJwtVcArgs, ICreateSdJwtVcResult, ICreateSdJwtPresentationArgs, ICreateSdJwtPresentationResult, IRequiredContext, ISDJwtPlugin, IVerifySdJwtVcArgs, IVerifySdJwtVcResult, IVerifySdJwtPresentationArgs, IVerifySdJwtPresentationResult } from './types';
4
+ /**
5
+ * @beta
6
+ * SD-JWT plugin for Veramo
7
+ */
8
+ export declare class SDJwtPlugin implements IAgentPlugin {
9
+ private algorithms;
10
+ readonly schema: any;
11
+ constructor(algorithms: SdJWTImplementation);
12
+ readonly methods: ISDJwtPlugin;
13
+ /**
14
+ * Create a signed SD-JWT credential.
15
+ * @param args - Arguments necessary for the creation of a SD-JWT credential.
16
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
17
+ * @returns A signed SD-JWT credential.
18
+ */
19
+ createSdJwtVc(args: ICreateSdJwtVcArgs, context: IRequiredContext): Promise<ICreateSdJwtVcResult>;
20
+ /**
21
+ * Get the key to sign the SD-JWT
22
+ * @param issuer - did url like did:exmaple.com#key-1
23
+ * @param context - agent instance
24
+ * @returns the key to sign the SD-JWT
25
+ */
26
+ private getSignKey;
27
+ /**
28
+ * Create a signed SD-JWT presentation.
29
+ * @param args - Arguments necessary for the creation of a SD-JWT presentation.
30
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
31
+ * @returns A signed SD-JWT presentation.
32
+ */
33
+ createSdJwtPresentation(args: ICreateSdJwtPresentationArgs, context: IRequiredContext): Promise<ICreateSdJwtPresentationResult>;
34
+ /**
35
+ * Verify a signed SD-JWT credential.
36
+ * @param args - Arguments necessary for the verify a SD-JWT credential.
37
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
38
+ * @returns
39
+ */
40
+ verifySdJwtVc(args: IVerifySdJwtVcArgs, context: IRequiredContext): Promise<IVerifySdJwtVcResult>;
41
+ /**
42
+ * Verify the key binding of a SD-JWT by validating the signature of the key bound to the SD-JWT
43
+ * @param sdjwt - SD-JWT instance
44
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
45
+ * @param data - signed data
46
+ * @param signature - The signature
47
+ * @param payload - The payload of the SD-JWT
48
+ * @returns
49
+ */
50
+ private verifyKb;
51
+ /**
52
+ * Validates the signature of a SD-JWT
53
+ * @param sdjwt - SD-JWT instance
54
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
55
+ * @param data - signed data
56
+ * @param signature - The signature
57
+ * @returns
58
+ */
59
+ verify(sdjwt: SDJwtVcInstance, context: IRequiredContext, data: string, signature: string): Promise<boolean>;
60
+ /**
61
+ * Verify a signed SD-JWT presentation.
62
+ * @param args - Arguments necessary for the verify a SD-JWT presentation.
63
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
64
+ * @returns
65
+ */
66
+ verifySdJwtPresentation(args: IVerifySdJwtPresentationArgs, context: IRequiredContext): Promise<IVerifySdJwtPresentationResult>;
67
+ private getKeyTypeAlgorithm;
68
+ }
69
+ //# sourceMappingURL=action-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-handler.d.ts","sourceRoot":"","sources":["../src/action-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAkB,MAAM,mBAAmB,CAAA;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAE/B,MAAM,SAAS,CAAA;AAIhB;;;GAGG;AACH,qBAAa,WAAY,YAAW,YAAY;IAGlC,OAAO,CAAC,UAAU;IAF9B,QAAQ,CAAC,MAAM,MAAsB;gBAEjB,UAAU,EAAE,mBAAmB;IAGnD,QAAQ,CAAC,OAAO,EAAE,YAAY,CAK7B;IAED;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0BvG;;;;;OAKG;YACW,UAAU;IAiBxB;;;;;OAKG;IACG,uBAAuB,CAAC,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAmCrI;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAYvG;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;IAQhB;;;;;;;OAOG;IACG,MAAM,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAqB/F;;;;;OAKG;IACG,uBAAuB,CAAC,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAiBrI,OAAO,CAAC,mBAAmB;CAY5B"}
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SDJwtPlugin = void 0;
13
+ const index_1 = require("./index");
14
+ const core_1 = require("@sd-jwt/core");
15
+ const sd_jwt_vc_1 = require("@sd-jwt/sd-jwt-vc");
16
+ const ssi_sdk_ext_did_utils_1 = require("@sphereon/ssi-sdk-ext.did-utils");
17
+ const utils_1 = require("@veramo/utils");
18
+ /**
19
+ * @beta
20
+ * SD-JWT plugin for Veramo
21
+ */
22
+ class SDJwtPlugin {
23
+ constructor(algorithms) {
24
+ this.algorithms = algorithms;
25
+ this.schema = index_1.schema.ISDJwtPlugin;
26
+ // map the methods your plugin is declaring to their implementation
27
+ this.methods = {
28
+ createSdJwtVc: this.createSdJwtVc.bind(this),
29
+ createSdJwtPresentation: this.createSdJwtPresentation.bind(this),
30
+ verifySdJwtVc: this.verifySdJwtVc.bind(this),
31
+ verifySdJwtPresentation: this.verifySdJwtPresentation.bind(this),
32
+ };
33
+ }
34
+ /**
35
+ * Create a signed SD-JWT credential.
36
+ * @param args - Arguments necessary for the creation of a SD-JWT credential.
37
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
38
+ * @returns A signed SD-JWT credential.
39
+ */
40
+ createSdJwtVc(args, context) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const issuer = args.credentialPayload.iss;
43
+ if (!issuer) {
44
+ throw new Error('credential.issuer must not be empty');
45
+ }
46
+ const { alg, key } = yield this.getSignKey(issuer, context);
47
+ //TODO: let the user also insert a method to sign the data
48
+ const signer = (data) => __awaiter(this, void 0, void 0, function* () { return context.agent.keyManagerSign({ keyRef: key.kid, data }); });
49
+ const sdjwt = new sd_jwt_vc_1.SDJwtVcInstance({
50
+ signer,
51
+ hasher: this.algorithms.hasher,
52
+ saltGenerator: this.algorithms.saltGenerator,
53
+ signAlg: alg,
54
+ hashAlg: 'SHA-256',
55
+ });
56
+ const credential = yield sdjwt.issue(args.credentialPayload, args.disclosureFrame);
57
+ return { credential };
58
+ });
59
+ }
60
+ /**
61
+ * Get the key to sign the SD-JWT
62
+ * @param issuer - did url like did:exmaple.com#key-1
63
+ * @param context - agent instance
64
+ * @returns the key to sign the SD-JWT
65
+ */
66
+ getSignKey(issuer, context) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const identifier = yield context.agent.didManagerGet({
69
+ did: issuer.split('#')[0],
70
+ });
71
+ const doc = yield (0, ssi_sdk_ext_did_utils_1.mapIdentifierKeysToDocWithJwkSupport)(identifier, 'assertionMethod', context);
72
+ if (!doc || doc.length === 0) {
73
+ throw new Error('No key found for signing');
74
+ }
75
+ const key = doc.find((key) => key.meta.verificationMethod.id === issuer);
76
+ if (!key) {
77
+ throw new Error(`No key found with the given id: ${issuer}`);
78
+ }
79
+ const alg = this.getKeyTypeAlgorithm(key.type);
80
+ return { alg, key };
81
+ });
82
+ }
83
+ /**
84
+ * Create a signed SD-JWT presentation.
85
+ * @param args - Arguments necessary for the creation of a SD-JWT presentation.
86
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
87
+ * @returns A signed SD-JWT presentation.
88
+ */
89
+ createSdJwtPresentation(args, context) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ var _a;
92
+ const cred = yield core_1.SDJwt.fromEncode(args.presentation, this.algorithms.hasher);
93
+ const claims = yield cred.getClaims(this.algorithms.hasher);
94
+ let holderDID;
95
+ // we primarly look for a cnf field, if it's not there we look for a sub field. If this is also not given, we throw an error since we can not sign it.
96
+ if ((_a = claims.cnf) === null || _a === void 0 ? void 0 : _a.jwk) {
97
+ const key = claims.cnf.jwk;
98
+ //TODO SDK-19: convert the JWK to hex and search for the appropriate key and associated DID
99
+ //doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
100
+ holderDID = `did:jwk:${(0, utils_1.encodeJoseBlob)(key)}#0`;
101
+ }
102
+ else if (claims.sub) {
103
+ holderDID = claims.sub;
104
+ }
105
+ else {
106
+ throw new Error('invalid_argument: credential does not include a holder reference');
107
+ }
108
+ const { alg, key } = yield this.getSignKey(holderDID, context);
109
+ const signer = (data) => __awaiter(this, void 0, void 0, function* () {
110
+ return context.agent.keyManagerSign({ keyRef: key.kid, data });
111
+ });
112
+ const sdjwt = new sd_jwt_vc_1.SDJwtVcInstance({
113
+ hasher: this.algorithms.hasher,
114
+ saltGenerator: this.algorithms.saltGenerator,
115
+ kbSigner: signer,
116
+ kbSignAlg: alg,
117
+ });
118
+ const credential = yield sdjwt.present(args.presentation, args.presentationFrame, { kb: args.kb });
119
+ return { presentation: credential };
120
+ });
121
+ }
122
+ /**
123
+ * Verify a signed SD-JWT credential.
124
+ * @param args - Arguments necessary for the verify a SD-JWT credential.
125
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
126
+ * @returns
127
+ */
128
+ verifySdJwtVc(args, context) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ // biome-ignore lint/style/useConst: <explanation>
131
+ let sdjwt;
132
+ const verifier = (data, signature) => __awaiter(this, void 0, void 0, function* () { return this.verify(sdjwt, context, data, signature); });
133
+ sdjwt = new sd_jwt_vc_1.SDJwtVcInstance({ verifier, hasher: this.algorithms.hasher });
134
+ const verifiedPayloads = yield sdjwt.verify(args.credential);
135
+ return { verifiedPayloads };
136
+ });
137
+ }
138
+ /**
139
+ * Verify the key binding of a SD-JWT by validating the signature of the key bound to the SD-JWT
140
+ * @param sdjwt - SD-JWT instance
141
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
142
+ * @param data - signed data
143
+ * @param signature - The signature
144
+ * @param payload - The payload of the SD-JWT
145
+ * @returns
146
+ */
147
+ verifyKb(sdjwt, context, data, signature, payload) {
148
+ if (!payload.cnf) {
149
+ throw Error('other method than cnf is not supported yet');
150
+ }
151
+ const key = payload.cnf.jwk;
152
+ return this.algorithms.verifySignature(data, signature, key);
153
+ }
154
+ /**
155
+ * Validates the signature of a SD-JWT
156
+ * @param sdjwt - SD-JWT instance
157
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
158
+ * @param data - signed data
159
+ * @param signature - The signature
160
+ * @returns
161
+ */
162
+ verify(sdjwt, context, data, signature) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ var _a, _b;
165
+ const decodedVC = yield sdjwt.decode(`${data}.${signature}`);
166
+ const issuer = decodedVC.jwt.payload.iss;
167
+ if (!issuer.startsWith('did:')) {
168
+ throw new Error('invalid_issuer: issuer must be a did');
169
+ }
170
+ const didDoc = yield context.agent.resolveDid({ didUrl: issuer });
171
+ if (!didDoc) {
172
+ throw new Error('invalid_issuer: issuer did not resolve to a did document');
173
+ }
174
+ //TODO SDK-20: This should be checking for an assertionMethod and not just an verificationMethod with an id
175
+ const didDocumentKey = (_b = (_a = didDoc.didDocument) === null || _a === void 0 ? void 0 : _a.verificationMethod) === null || _b === void 0 ? void 0 : _b.find((key) => key.id);
176
+ if (!didDocumentKey) {
177
+ throw new Error('invalid_issuer: issuer did document does not include referenced key');
178
+ }
179
+ //FIXME SDK-21: in case it's another did method, the value of the key can be also encoded as a base64url
180
+ //needs more checks. some DID methods do not expose the keys as publicKeyJwk
181
+ const key = didDocumentKey.publicKeyJwk;
182
+ return this.algorithms.verifySignature(data, signature, key);
183
+ });
184
+ }
185
+ /**
186
+ * Verify a signed SD-JWT presentation.
187
+ * @param args - Arguments necessary for the verify a SD-JWT presentation.
188
+ * @param context - This reserved param is automatically added and handled by the framework, *do not override*
189
+ * @returns
190
+ */
191
+ verifySdJwtPresentation(args, context) {
192
+ return __awaiter(this, void 0, void 0, function* () {
193
+ // biome-ignore lint/style/useConst: <explanation>
194
+ let sdjwt;
195
+ const verifier = (data, signature) => __awaiter(this, void 0, void 0, function* () { return this.verify(sdjwt, context, data, signature); });
196
+ const verifierKb = (data, signature, payload) => __awaiter(this, void 0, void 0, function* () { return this.verifyKb(sdjwt, context, data, signature, payload); });
197
+ sdjwt = new sd_jwt_vc_1.SDJwtVcInstance({
198
+ verifier,
199
+ hasher: this.algorithms.hasher,
200
+ kbVerifier: verifierKb,
201
+ });
202
+ const verifiedPayloads = yield sdjwt.verify(args.presentation, args.requiredClaimKeys, args.kb);
203
+ return { verifiedPayloads };
204
+ });
205
+ }
206
+ getKeyTypeAlgorithm(keyType) {
207
+ switch (keyType) {
208
+ case 'Ed25519':
209
+ return 'EdDSA';
210
+ case 'Secp256k1':
211
+ return 'ES256K';
212
+ case 'Secp256r1':
213
+ return 'ES256';
214
+ default:
215
+ throw new Error(`unsupported key type ${keyType}`);
216
+ }
217
+ }
218
+ }
219
+ exports.SDJwtPlugin = SDJwtPlugin;
220
+ //# sourceMappingURL=action-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-handler.js","sourceRoot":"","sources":["../src/action-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAgC;AAChC,uCAAyC;AACzC,iDAAmE;AAiBnE,2EAAsF;AACtF,yCAA8C;AAE9C;;;GAGG;AACH,MAAa,WAAW;IAGtB,YAAoB,UAA+B;QAA/B,eAAU,GAAV,UAAU,CAAqB;QAF1C,WAAM,GAAG,cAAM,CAAC,YAAY,CAAA;QAIrC,mEAAmE;QAC1D,YAAO,GAAiB;YAC/B,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5C,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;YAChE,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5C,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;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AAA;YAChB;gBACE,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;CACF;AAhND,kCAgNC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @public
3
+ */
4
+ declare const schema: any;
5
+ export { schema };
6
+ export { SDJwtPlugin } from './action-handler';
7
+ export * from './types';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,MAAM,KAAmC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,cAAc,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SDJwtPlugin = exports.schema = void 0;
18
+ /**
19
+ * @public
20
+ */
21
+ const schema = require('../plugin.schema.json');
22
+ exports.schema = schema;
23
+ var action_handler_1 = require("./action-handler");
24
+ Object.defineProperty(exports, "SDJwtPlugin", { enumerable: true, get: function () { return action_handler_1.SDJwtPlugin; } });
25
+ __exportStar(require("./types"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AACtC,wBAAM;AACf,mDAA8C;AAArC,6GAAA,WAAW,OAAA;AACpB,0CAAuB"}