@sd-jwt/present 0.2.1 → 0.3.2-next.100

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 [yyyy] [name of copyright owner]
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 CHANGED
@@ -1,97 +1,41 @@
1
- # Selective Disclosure JWT (SD-JWT) Draft 06 & Selective Disclosure JWT VC 01
1
+ ![License](https://img.shields.io/github/license/openwallet-foundation-labs/sd-jwt-js.svg)
2
+ ![NPM](https://img.shields.io/npm/v/%40sd-jwt%2Fpresent)
3
+ ![Release](https://img.shields.io/github/v/release/openwallet-foundation-labs/sd-jwt-js)
4
+ ![Stars](https://img.shields.io/github/stars/openwallet-foundation-labs/sd-jwt-js)
2
5
 
3
- ## Compliant with
6
+ # SD-JWT Implementation in JavaScript (TypeScript)
4
7
 
5
- - [sd-jwt
6
- 06](https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/06/)
7
- - [sd-jwt-vc
8
- 01](https://datatracker.ietf.org/doc/draft-ietf-oauth-sd-jwt-vc/01/)
8
+ ## SD-JWT Present
9
9
 
10
- ## Design decisions
10
+ ### About
11
11
 
12
- ### Bring your own crypto
12
+ Present SD JWT
13
13
 
14
- This library does not provide any of the cryptographic primitives required for
15
- encryption, decryption, signing, verification and hashing. It is expected that
16
- the user of this library provides this. The main reason for this is that most
17
- libraries have their own library and KMS. Providing private keys to this
18
- library adds another layer of insecurity which should be avoided. Hashing has
19
- not been added for platform compatibility between node,js, browser and React
20
- Native. In the future a platform-independent sha2-256 may be provided.
14
+ Check the detail description in our github [repo](https://github.com/openwallet-foundation-labs/sd-jwt-js).
21
15
 
22
- ### Specification backwards compatibility
16
+ ### Installation
23
17
 
24
- Since these specifications are in early drafts, no time will be spend in
25
- supporting earlier versions of the specifications. This library may work for
26
- older versions, e.g. the addition of selectively disclosable items in an array
27
- does not break previous implementations. Once a non-draft specification is
28
- released it will stay up-to-date with that version.
18
+ To install this project, run the following command:
29
19
 
30
- ### Dependencies
31
-
32
- This library only has one dependency on `buffer` which makes sure this library
33
- works in Node.js, the browser and React Native. Buffer is used internally for
34
- `base64-url-no-pad` encoding.
35
-
36
- ### Usage
37
-
38
- I'd highly recommend to check out the [examples folder](example) to see how
39
- this library can be leveraged.
20
+ ```bash
21
+ # using npm
22
+ npm install @sd-jwt/present
40
23
 
41
- ### Issuance API
24
+ # using yarn
25
+ yarn add @sd-jwt/present
42
26
 
43
- The issuance API takes an object called a `disclosureFrame`. This
44
- `disclosureFrame` is a Boolean Map of the payload which allows you to specify
45
- which attributes of the payload may be selectively disclosed. If an attribute is not provided in the `disclosureFrame`, it will be included in the clear-text payload. For example:
46
-
47
- ```jsonc
48
- // The payload
49
- {
50
- "iss": "https://example.org/issuer",
51
- "is_age_over_21": true,
52
- "is_age_over_24": true,
53
- "is_age_over_65": false,
54
- "date_of_birth": "1990-01-01",
55
- "address": {
56
- "street": "some street",
57
- "house_number": 200,
58
- "zipcode": "2344GH"
59
- }
60
- }
27
+ # using pnpm
28
+ pnpm install @sd-jwt/present
61
29
  ```
62
30
 
63
- ```jsonc
64
- // The disclosure frame
65
- {
66
- "is_age_over_21": true,
67
- "is_age_over_24": true,
68
- "is_age_over_65": true,
69
- "date_of_birth": true,
70
- "address": {
71
- "street": true,
72
- "house_number": true,
73
- "zipcode": true
74
- }
75
- }
31
+ Ensure you have Node.js installed as a prerequisite.
76
32
 
77
- // or to only disclose the address as a group
78
- {
79
- "is_age_over_21": true,
80
- "is_age_over_24": true,
81
- "is_age_over_65": true,
82
- "date_of_birth": true,
83
- "address": true
84
- }
85
- ```
33
+ ### Usage
86
34
 
87
- ### Presentation and verification API
35
+ Check out more details in our [documentation](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/next/docs) or [examples](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/next/examples)
36
+
37
+ ### Dependencies
88
38
 
89
- Since there is officially standardized way to request and present a
90
- presentation, [High Assurance Interoperability
91
- Profile](https://vcstuff.github.io/oid4vc-haip-sd-jwt-vc/draft-oid4vc-haip-sd-jwt-vc.html)
92
- may be used, the API is defined in a way which works in a primitive manner for
93
- now. For example, to present you can provide a list of indices of the
94
- disclosures which will be included. Examples of this can be found in the
95
- [examples folder](example). For verification a list of keys or required
96
- claims can be provided. It does not matter whether these are selectively
97
- disclosable claims, or if they are included inside the payload.
39
+ - @sd-jwt/decode
40
+ - @sd-jwt/types
41
+ - @sd-jwt/utils
@@ -0,0 +1,10 @@
1
+ import { Hasher } from '@sd-jwt/types';
2
+ import { Disclosure } from '@sd-jwt/utils';
3
+ import { HasherSync } from '@sd-jwt/types/src/type';
4
+
5
+ declare const presentableKeys: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: Hasher) => Promise<string[]>;
6
+ declare const presentableKeysSync: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: HasherSync) => string[];
7
+ declare const present: (sdJwt: string, keys: string[], hasher: Hasher) => Promise<string>;
8
+ declare const presentSync: (sdJwt: string, keys: string[], hasher: HasherSync) => string;
9
+
10
+ export { present, presentSync, presentableKeys, presentableKeysSync };
@@ -0,0 +1,10 @@
1
+ import { Hasher } from '@sd-jwt/types';
2
+ import { Disclosure } from '@sd-jwt/utils';
3
+ import { HasherSync } from '@sd-jwt/types/src/type';
4
+
5
+ declare const presentableKeys: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: Hasher) => Promise<string[]>;
6
+ declare const presentableKeysSync: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: HasherSync) => string[];
7
+ declare const present: (sdJwt: string, keys: string[], hasher: Hasher) => Promise<string>;
8
+ declare const presentSync: (sdJwt: string, keys: string[], hasher: HasherSync) => string;
9
+
10
+ export { present, presentSync, presentableKeys, presentableKeysSync };
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __async = (__this, __arguments, generator) => {
20
+ return new Promise((resolve, reject) => {
21
+ var fulfilled = (value) => {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ };
28
+ var rejected = (value) => {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
+ step((generator = generator.apply(__this, __arguments)).next());
37
+ });
38
+ };
39
+
40
+ // src/index.ts
41
+ var src_exports = {};
42
+ __export(src_exports, {
43
+ present: () => present,
44
+ presentSync: () => presentSync,
45
+ presentableKeys: () => presentableKeys,
46
+ presentableKeysSync: () => presentableKeysSync
47
+ });
48
+ module.exports = __toCommonJS(src_exports);
49
+
50
+ // src/present.ts
51
+ var import_types = require("@sd-jwt/types");
52
+ var import_utils = require("@sd-jwt/utils");
53
+ var import_decode = require("@sd-jwt/decode");
54
+ var presentableKeys = (rawPayload, disclosures, hasher) => __async(void 0, null, function* () {
55
+ const { disclosureKeymap } = yield (0, import_decode.unpack)(rawPayload, disclosures, hasher);
56
+ return Object.keys(disclosureKeymap).sort();
57
+ });
58
+ var presentableKeysSync = (rawPayload, disclosures, hasher) => {
59
+ const { disclosureKeymap } = (0, import_decode.unpackSync)(rawPayload, disclosures, hasher);
60
+ return Object.keys(disclosureKeymap).sort();
61
+ };
62
+ var present = (sdJwt, keys, hasher) => __async(void 0, null, function* () {
63
+ const { jwt, kbJwt } = (0, import_decode.splitSdJwt)(sdJwt);
64
+ const {
65
+ jwt: { payload },
66
+ disclosures
67
+ } = yield (0, import_decode.decodeSdJwt)(sdJwt, hasher);
68
+ const { _sd_alg: alg } = (0, import_decode.getSDAlgAndPayload)(payload);
69
+ const hash = { alg, hasher };
70
+ const hashmap = yield (0, import_decode.createHashMapping)(disclosures, hash);
71
+ const { disclosureKeymap } = yield (0, import_decode.unpack)(payload, disclosures, hasher);
72
+ const presentableKeys2 = Object.keys(disclosureKeymap);
73
+ const missingKeys = keys.filter((k) => !presentableKeys2.includes(k));
74
+ if (missingKeys.length > 0) {
75
+ throw new import_utils.SDJWTException(
76
+ `Invalid sd-jwt: invalid present keys: ${missingKeys.join(", ")}`
77
+ );
78
+ }
79
+ const presentedDisclosures = keys.map((k) => hashmap[disclosureKeymap[k]]);
80
+ return [
81
+ jwt,
82
+ ...presentedDisclosures.map((d) => d.encode()),
83
+ kbJwt != null ? kbJwt : ""
84
+ ].join(import_types.SD_SEPARATOR);
85
+ });
86
+ var presentSync = (sdJwt, keys, hasher) => {
87
+ const { jwt, kbJwt } = (0, import_decode.splitSdJwt)(sdJwt);
88
+ const {
89
+ jwt: { payload },
90
+ disclosures
91
+ } = (0, import_decode.decodeSdJwtSync)(sdJwt, hasher);
92
+ const { _sd_alg: alg } = (0, import_decode.getSDAlgAndPayload)(payload);
93
+ const hash = { alg, hasher };
94
+ const hashmap = (0, import_decode.createHashMappingSync)(disclosures, hash);
95
+ const { disclosureKeymap } = (0, import_decode.unpackSync)(payload, disclosures, hasher);
96
+ const presentableKeys2 = Object.keys(disclosureKeymap);
97
+ const missingKeys = keys.filter((k) => !presentableKeys2.includes(k));
98
+ if (missingKeys.length > 0) {
99
+ throw new import_utils.SDJWTException(
100
+ `Invalid sd-jwt: invalid present keys: ${missingKeys.join(", ")}`
101
+ );
102
+ }
103
+ const presentedDisclosures = keys.map((k) => hashmap[disclosureKeymap[k]]);
104
+ return [
105
+ jwt,
106
+ ...presentedDisclosures.map((d) => d.encode()),
107
+ kbJwt != null ? kbJwt : ""
108
+ ].join(import_types.SD_SEPARATOR);
109
+ };
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ present,
113
+ presentSync,
114
+ presentableKeys,
115
+ presentableKeysSync
116
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,96 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/present.ts
23
+ import { SD_SEPARATOR } from "@sd-jwt/types";
24
+ import { SDJWTException } from "@sd-jwt/utils";
25
+ import {
26
+ createHashMapping,
27
+ decodeSdJwt,
28
+ getSDAlgAndPayload,
29
+ splitSdJwt,
30
+ unpack,
31
+ createHashMappingSync,
32
+ decodeSdJwtSync,
33
+ unpackSync
34
+ } from "@sd-jwt/decode";
35
+ var presentableKeys = (rawPayload, disclosures, hasher) => __async(void 0, null, function* () {
36
+ const { disclosureKeymap } = yield unpack(rawPayload, disclosures, hasher);
37
+ return Object.keys(disclosureKeymap).sort();
38
+ });
39
+ var presentableKeysSync = (rawPayload, disclosures, hasher) => {
40
+ const { disclosureKeymap } = unpackSync(rawPayload, disclosures, hasher);
41
+ return Object.keys(disclosureKeymap).sort();
42
+ };
43
+ var present = (sdJwt, keys, hasher) => __async(void 0, null, function* () {
44
+ const { jwt, kbJwt } = splitSdJwt(sdJwt);
45
+ const {
46
+ jwt: { payload },
47
+ disclosures
48
+ } = yield decodeSdJwt(sdJwt, hasher);
49
+ const { _sd_alg: alg } = getSDAlgAndPayload(payload);
50
+ const hash = { alg, hasher };
51
+ const hashmap = yield createHashMapping(disclosures, hash);
52
+ const { disclosureKeymap } = yield unpack(payload, disclosures, hasher);
53
+ const presentableKeys2 = Object.keys(disclosureKeymap);
54
+ const missingKeys = keys.filter((k) => !presentableKeys2.includes(k));
55
+ if (missingKeys.length > 0) {
56
+ throw new SDJWTException(
57
+ `Invalid sd-jwt: invalid present keys: ${missingKeys.join(", ")}`
58
+ );
59
+ }
60
+ const presentedDisclosures = keys.map((k) => hashmap[disclosureKeymap[k]]);
61
+ return [
62
+ jwt,
63
+ ...presentedDisclosures.map((d) => d.encode()),
64
+ kbJwt != null ? kbJwt : ""
65
+ ].join(SD_SEPARATOR);
66
+ });
67
+ var presentSync = (sdJwt, keys, hasher) => {
68
+ const { jwt, kbJwt } = splitSdJwt(sdJwt);
69
+ const {
70
+ jwt: { payload },
71
+ disclosures
72
+ } = decodeSdJwtSync(sdJwt, hasher);
73
+ const { _sd_alg: alg } = getSDAlgAndPayload(payload);
74
+ const hash = { alg, hasher };
75
+ const hashmap = createHashMappingSync(disclosures, hash);
76
+ const { disclosureKeymap } = unpackSync(payload, disclosures, hasher);
77
+ const presentableKeys2 = Object.keys(disclosureKeymap);
78
+ const missingKeys = keys.filter((k) => !presentableKeys2.includes(k));
79
+ if (missingKeys.length > 0) {
80
+ throw new SDJWTException(
81
+ `Invalid sd-jwt: invalid present keys: ${missingKeys.join(", ")}`
82
+ );
83
+ }
84
+ const presentedDisclosures = keys.map((k) => hashmap[disclosureKeymap[k]]);
85
+ return [
86
+ jwt,
87
+ ...presentedDisclosures.map((d) => d.encode()),
88
+ kbJwt != null ? kbJwt : ""
89
+ ].join(SD_SEPARATOR);
90
+ };
91
+ export {
92
+ present,
93
+ presentSync,
94
+ presentableKeys,
95
+ presentableKeysSync
96
+ };
package/package.json CHANGED
@@ -1,49 +1,65 @@
1
1
  {
2
- "name": "@sd-jwt/present",
3
- "version": "0.2.1",
4
- "description": "Presentation implementation of sd-jwt Draft 06 and sd-jwt-vc Draft 01",
5
- "license": "(MIT OR Apache-2.0)",
6
- "author": "Berend Sliedrecht <sliedrecht@berend.io>",
7
- "readme": "../../README.md",
8
- "keywords": [
9
- "jwt",
10
- "jwt-sd",
11
- "sd-jwt",
12
- "sd-jwt-vc",
13
- "decentralized-identity",
14
- "ssi",
15
- "oauth",
16
- "oauth2",
17
- "openid-connect"
2
+ "name": "@sd-jwt/present",
3
+ "version": "0.3.2-next.100+838c288",
4
+ "description": "sd-jwt draft 7 implementation in typescript",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "rm -rf **/dist && tsup",
16
+ "lint": "biome lint ./src",
17
+ "test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
18
+ "test:node": "vitest run ./src/test/*.spec.ts",
19
+ "test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
20
+ "test:cov": "vitest run --coverage"
21
+ },
22
+ "keywords": [
23
+ "sd-jwt",
24
+ "sdjwt",
25
+ "sd-jwt-vc"
26
+ ],
27
+ "engines": {
28
+ "node": ">=16"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/openwallet-foundation-labs/sd-jwt-js"
33
+ },
34
+ "author": "Lukas.J.Han <lukas.j.han@gmail.com>",
35
+ "homepage": "https://github.com/openwallet-foundation-labs/sd-jwt-js/wiki",
36
+ "bugs": {
37
+ "url": "https://github.com/openwallet-foundation-labs/sd-jwt-js/issues"
38
+ },
39
+ "license": "Apache-2.0",
40
+ "devDependencies": {
41
+ "@sd-jwt/crypto-nodejs": "0.3.2-next.100+838c288"
42
+ },
43
+ "dependencies": {
44
+ "@sd-jwt/decode": "0.3.2-next.100+838c288",
45
+ "@sd-jwt/types": "0.3.2-next.100+838c288",
46
+ "@sd-jwt/utils": "0.3.2-next.100+838c288"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "tsup": {
52
+ "entry": [
53
+ "./src/index.ts"
18
54
  ],
19
- "repository": {
20
- "url": "https://github.com/berendsliedrecht/sd-jwt-ts",
21
- "type": "git"
22
- },
23
- "homepage": "https://github.com/berendsliedrecht/sd-jwt-ts",
24
- "bugs": {
25
- "url": "https://github.com/berendsliedrecht/sd-jwt-ts/issues",
26
- "email": "sliedrecht@berend.io"
27
- },
28
- "publishConfig": {
29
- "access": "public"
30
- },
31
- "main": "build/index.js",
32
- "files": [
33
- "build"
34
- ],
35
- "scripts": {
36
- "build": "tsc",
37
- "test": "node --require ts-node/register --test ./tests/*.test.ts"
38
- },
39
- "dependencies": {
40
- "@sd-jwt/types": "0.2.1",
41
- "@sd-jwt/utils": "0.2.1"
42
- },
43
- "devDependencies": {
44
- "@types/node": "*",
45
- "ts-node": "*",
46
- "typescript": "*"
47
- },
48
- "gitHead": "a1fb5fad0b938081e033233bae5569ae3b9fe8cb"
55
+ "sourceMap": true,
56
+ "splitting": false,
57
+ "clean": true,
58
+ "dts": true,
59
+ "format": [
60
+ "cjs",
61
+ "esm"
62
+ ]
63
+ },
64
+ "gitHead": "838c2887b6b853b4dc1803c92ebb7ae4491a76e0"
49
65
  }