@sd-jwt/core 0.19.1-next.1 → 0.19.1-next.11

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.
@@ -0,0 +1,150 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { unpackObj } from '../src/decode';
3
+ import { Disclosure } from '../src/utils';
4
+
5
+ /**
6
+ * Tests for RFC 9901 validation checks added to unpackObj / unpackObjInternal.
7
+ *
8
+ * Section 7.1 step 4: Duplicate digest rejection
9
+ * Section 7.1 step 5: Unreferenced disclosure rejection
10
+ * Section 7.1 step 3c.ii.3: Claim name collision rejection
11
+ */
12
+
13
+ const makeDisclosure = (
14
+ digest: string,
15
+ key: string | undefined,
16
+ value: unknown,
17
+ ) =>
18
+ Disclosure.fromArray(key ? ['salt', key, value] : ['salt', value], {
19
+ digest,
20
+ encoded: `encoded-${digest}`,
21
+ });
22
+
23
+ describe('RFC 9901 validation', () => {
24
+ // ──────────────────────────────────────────
25
+ // 7.1 step 4 — Duplicate digest in _sd array
26
+ // ──────────────────────────────────────────
27
+ test('rejects duplicate digest in _sd array', () => {
28
+ const digest = 'abc123';
29
+ const payload = { _sd: [digest, digest] };
30
+ const map: Record<string, Disclosure> = {
31
+ [digest]: makeDisclosure(digest, 'foo', 'bar'),
32
+ };
33
+ expect(() => unpackObj(payload, map)).toThrow(
34
+ 'Duplicate digest found in SD-JWT payload',
35
+ );
36
+ });
37
+
38
+ // ──────────────────────────────────────────
39
+ // 7.1 step 4 — Duplicate digest across nested _sd
40
+ // ──────────────────────────────────────────
41
+ test('rejects duplicate digest across nested _sd arrays', () => {
42
+ const digest = 'dup1';
43
+ const payload = {
44
+ _sd: [digest],
45
+ nested: {
46
+ _sd: [digest],
47
+ },
48
+ };
49
+ const map: Record<string, Disclosure> = {
50
+ [digest]: makeDisclosure(digest, 'x', 'y'),
51
+ };
52
+ expect(() => unpackObj(payload, map)).toThrow(
53
+ 'Duplicate digest found in SD-JWT payload',
54
+ );
55
+ });
56
+
57
+ // ──────────────────────────────────────────
58
+ // 7.1 step 4 — Duplicate digest in array items
59
+ // ──────────────────────────────────────────
60
+ test('rejects duplicate digest in array element disclosures', () => {
61
+ const digest = 'arrdup';
62
+ const payload = {
63
+ arr: [{ '...': digest }, { '...': digest }],
64
+ };
65
+ const map: Record<string, Disclosure> = {
66
+ [digest]: makeDisclosure(digest, undefined, 'val'),
67
+ };
68
+ expect(() => unpackObj(payload, map)).toThrow(
69
+ 'Duplicate digest found in SD-JWT payload',
70
+ );
71
+ });
72
+
73
+ // ──────────────────────────────────────────
74
+ // 7.1 step 5 — Unreferenced disclosure
75
+ // ──────────────────────────────────────────
76
+ test('rejects unreferenced disclosure', () => {
77
+ const usedDigest = 'used1';
78
+ const unusedDigest = 'unused1';
79
+ const payload = { _sd: [usedDigest] };
80
+ const map: Record<string, Disclosure> = {
81
+ [usedDigest]: makeDisclosure(usedDigest, 'a', 1),
82
+ [unusedDigest]: makeDisclosure(unusedDigest, 'b', 2),
83
+ };
84
+ expect(() => unpackObj(payload, map)).toThrow(
85
+ 'Unreferenced disclosure(s) detected in SD-JWT',
86
+ );
87
+ });
88
+
89
+ test('rejects when no digests exist in payload but disclosures provided', () => {
90
+ const payload = { plain: 'value' };
91
+ const map: Record<string, Disclosure> = {
92
+ orphan: makeDisclosure('orphan', 'k', 'v'),
93
+ };
94
+ expect(() => unpackObj(payload, map)).toThrow(
95
+ 'Unreferenced disclosure(s) detected in SD-JWT',
96
+ );
97
+ });
98
+
99
+ // ──────────────────────────────────────────
100
+ // 7.1 step 3c.ii.3 — Claim name collision
101
+ // ──────────────────────────────────────────
102
+ test('rejects disclosed claim name that conflicts with plaintext key', () => {
103
+ const digest = 'col1';
104
+ // The payload has both a plaintext "name" and a disclosure that would add "name"
105
+ const payload = { name: 'Alice', _sd: [digest] };
106
+ const map: Record<string, Disclosure> = {
107
+ [digest]: makeDisclosure(digest, 'name', 'Mallory'),
108
+ };
109
+ expect(() => unpackObj(payload, map)).toThrow(
110
+ 'Disclosed claim name "name" conflicts with existing payload key',
111
+ );
112
+ });
113
+
114
+ // ──────────────────────────────────────────
115
+ // Positive: valid SD-JWT unpacks without error
116
+ // ──────────────────────────────────────────
117
+ test('unpacks valid SD-JWT without errors', () => {
118
+ const d1 = 'digest1';
119
+ const d2 = 'digest2';
120
+ const payload = { _sd: [d1, d2], plain: 'hello' };
121
+ const map: Record<string, Disclosure> = {
122
+ [d1]: makeDisclosure(d1, 'foo', 'bar'),
123
+ [d2]: makeDisclosure(d2, 'baz', 42),
124
+ };
125
+ const { unpackedObj, disclosureKeymap } = unpackObj(payload, map);
126
+ expect(unpackedObj).toEqual({ plain: 'hello', foo: 'bar', baz: 42 });
127
+ expect(disclosureKeymap).toEqual({ foo: d1, baz: d2 });
128
+ });
129
+
130
+ test('unpacks valid SD-JWT with array disclosures', () => {
131
+ const d1 = 'arrdig1';
132
+ const d2 = 'arrdig2';
133
+ const payload = {
134
+ arr: [{ '...': d1 }, 'plainItem', { '...': d2 }],
135
+ };
136
+ const map: Record<string, Disclosure> = {
137
+ [d1]: makeDisclosure(d1, undefined, 'secret1'),
138
+ [d2]: makeDisclosure(d2, undefined, 'secret2'),
139
+ };
140
+ const { unpackedObj } = unpackObj(payload, map);
141
+ expect(unpackedObj).toEqual({ arr: ['secret1', 'plainItem', 'secret2'] });
142
+ });
143
+
144
+ test('allows empty disclosure map with no _sd in payload', () => {
145
+ const payload = { plain: 'value' };
146
+ const map: Record<string, Disclosure> = {};
147
+ const { unpackedObj } = unpackObj(payload, map);
148
+ expect(unpackedObj).toEqual({ plain: 'value' });
149
+ });
150
+ });
package/CHANGELOG.md DELETED
@@ -1,240 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [0.19.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.18.1...v0.19.0) (2026-01-23)
7
-
8
- **Note:** Version bump only for package @sd-jwt/core
9
-
10
-
11
-
12
-
13
-
14
- ## [0.18.1](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.18.0...v0.18.1) (2026-01-14)
15
-
16
- **Note:** Version bump only for package @sd-jwt/core
17
-
18
-
19
-
20
-
21
-
22
- # [0.18.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.17.1...v0.18.0) (2026-01-11)
23
-
24
- **Note:** Version bump only for package @sd-jwt/core
25
-
26
-
27
-
28
-
29
-
30
- # [0.17.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.16.0...v0.17.0) (2025-10-23)
31
-
32
- **Note:** Version bump only for package @sd-jwt/core
33
-
34
-
35
-
36
-
37
-
38
- # [0.16.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.15.1...v0.16.0) (2025-10-07)
39
-
40
-
41
- ### Bug Fixes
42
-
43
- * change repo url from labs to other one ([#323](https://github.com/openwallet-foundation/sd-jwt-js/issues/323)) ([f68c847](https://github.com/openwallet-foundation/sd-jwt-js/commit/f68c8476c2f04bb9d53acd4059b59caf271df015))
44
- * set correct url in package json ([#321](https://github.com/openwallet-foundation/sd-jwt-js/issues/321)) ([554152c](https://github.com/openwallet-foundation/sd-jwt-js/commit/554152cc819bbc3afb504b25f4a2018a92fb72f1))
45
-
46
-
47
- ### Features
48
-
49
- * Adding validation during issuance when a schema is passed ([#308](https://github.com/openwallet-foundation/sd-jwt-js/issues/308)) ([90eef6b](https://github.com/openwallet-foundation/sd-jwt-js/commit/90eef6be1c0838d334ecdef083dbb609c3812357))
50
- * updates all dependencies to latest versions + biome updates ([#324](https://github.com/openwallet-foundation/sd-jwt-js/issues/324)) ([75d5780](https://github.com/openwallet-foundation/sd-jwt-js/commit/75d5780fb53c5e2c886537b283503fc6fb088a4a))
51
-
52
-
53
-
54
-
55
-
56
- # [0.15.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.14.1...v0.15.0) (2025-08-20)
57
-
58
- **Note:** Version bump only for package @sd-jwt/core
59
-
60
-
61
-
62
-
63
-
64
- ## [0.14.1](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.14.0...v0.14.1) (2025-08-02)
65
-
66
-
67
- ### Bug Fixes
68
-
69
- * pass required options parameter ([#303](https://github.com/openwallet-foundation/sd-jwt-js/issues/303)) ([f3aed2d](https://github.com/openwallet-foundation/sd-jwt-js/commit/f3aed2d54fa4c365c41014c9ba65bf7dd5b7c413))
70
-
71
-
72
-
73
-
74
-
75
- # [0.14.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.13.0...v0.14.0) (2025-06-30)
76
-
77
-
78
- ### Features
79
-
80
- * Add Verifier options ([#297](https://github.com/openwallet-foundation/sd-jwt-js/issues/297)) ([2a6a367](https://github.com/openwallet-foundation/sd-jwt-js/commit/2a6a3674f94742f48feaf660056226b1a54145e7))
81
-
82
-
83
-
84
-
85
-
86
- # [0.13.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.12.0...v0.13.0) (2025-06-25)
87
-
88
- **Note:** Version bump only for package @sd-jwt/core
89
-
90
-
91
-
92
-
93
-
94
- # [0.12.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.11.0...v0.12.0) (2025-06-21)
95
-
96
- **Note:** Version bump only for package @sd-jwt/core
97
-
98
-
99
-
100
-
101
-
102
- # [0.11.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.10.0...v0.11.0) (2025-06-17)
103
-
104
-
105
- ### Features
106
-
107
- * SD JWT Instances VCT Metadata get separated from verify ([#285](https://github.com/openwallet-foundation/sd-jwt-js/issues/285)) ([bc91fd7](https://github.com/openwallet-foundation/sd-jwt-js/commit/bc91fd71f7d721298ad5c08d4379bc870903f65f))
108
-
109
-
110
-
111
-
112
-
113
- # [0.10.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.9.2...v0.10.0) (2025-03-24)
114
-
115
-
116
- ### Features
117
-
118
- * fix encoding bug for flattenJSON and generalJSON ([#277](https://github.com/openwallet-foundation/sd-jwt-js/issues/277)) ([cc455a6](https://github.com/openwallet-foundation/sd-jwt-js/commit/cc455a6f3d431fa59cca1d21dad49daac135d3bc))
119
-
120
-
121
-
122
-
123
-
124
- ## [0.9.2](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.9.1...v0.9.2) (2025-01-29)
125
-
126
- **Note:** Version bump only for package @sd-jwt/core
127
-
128
-
129
-
130
-
131
-
132
- ## [0.9.1](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.9.0...v0.9.1) (2024-12-13)
133
-
134
- **Note:** Version bump only for package @sd-jwt/core
135
-
136
-
137
-
138
-
139
-
140
- # [0.9.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.8.0...v0.9.0) (2024-12-10)
141
-
142
- **Note:** Version bump only for package @sd-jwt/core
143
-
144
-
145
-
146
-
147
-
148
- # [0.8.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.7.2...v0.8.0) (2024-11-26)
149
-
150
-
151
- ### Features
152
-
153
- * add jws serialization feature ([#253](https://github.com/openwallet-foundation/sd-jwt-js/issues/253)) ([e83b494](https://github.com/openwallet-foundation/sd-jwt-js/commit/e83b4946595d043f56647e6cdc98ad34edf0acde))
154
-
155
-
156
-
157
-
158
-
159
- ## [0.7.2](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.7.1...v0.7.2) (2024-07-19)
160
-
161
- **Note:** Version bump only for package @sd-jwt/core
162
-
163
-
164
-
165
-
166
-
167
- ## [0.7.1](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.7.0...v0.7.1) (2024-05-21)
168
-
169
- **Note:** Version bump only for package @sd-jwt/core
170
-
171
-
172
-
173
-
174
-
175
- # [0.7.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.6.1...v0.7.0) (2024-05-13)
176
-
177
- **Note:** Version bump only for package @sd-jwt/core
178
-
179
-
180
-
181
-
182
-
183
- ## [0.6.1](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.6.0...v0.6.1) (2024-03-18)
184
-
185
-
186
- ### Bug Fixes
187
-
188
- * base64url convention ([#179](https://github.com/openwallet-foundation/sd-jwt-js/issues/179)) ([f8db275](https://github.com/openwallet-foundation/sd-jwt-js/commit/f8db275690dab88000a039838680a3478b3b61ec))
189
-
190
-
191
-
192
-
193
-
194
- # [0.6.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.5.0...v0.6.0) (2024-03-12)
195
-
196
- **Note:** Version bump only for package @sd-jwt/core
197
-
198
-
199
-
200
-
201
-
202
- # [0.5.0](https://github.com/openwallet-foundation/sd-jwt-js/compare/v0.4.0...v0.5.0) (2024-03-11)
203
-
204
-
205
- ### Bug Fixes
206
-
207
- * validate JWT signed other implemenation ([#158](https://github.com/openwallet-foundation/sd-jwt-js/issues/158)) ([a0c1ddb](https://github.com/openwallet-foundation/sd-jwt-js/commit/a0c1ddbb4c3785d03fc7302183f9c13e3c3fd955))
208
-
209
-
210
- ### Features
211
-
212
- * make _digest value public in disclosure ([#151](https://github.com/openwallet-foundation/sd-jwt-js/issues/151)) ([7a3fbd7](https://github.com/openwallet-foundation/sd-jwt-js/commit/7a3fbd7db19b6501978340c972b171743d287285))
213
-
214
-
215
-
216
-
217
-
218
- # 0.4.0 (2024-03-08)
219
-
220
-
221
- ### Bug Fixes
222
-
223
- * add publish config ([#93](https://github.com/openwallet-foundation/sd-jwt-js/issues/93)) ([2e4c5c1](https://github.com/openwallet-foundation/sd-jwt-js/commit/2e4c5c176dc88e58e49d06783b7658d8ad872313))
224
- * add the payload that is required ([6c53580](https://github.com/openwallet-foundation/sd-jwt-js/commit/6c53580d12e4361c40435b90628302749fa32b1c))
225
- * change SDJwtPayload to SdJwtPayload ([9f06ef7](https://github.com/openwallet-foundation/sd-jwt-js/commit/9f06ef7bd31a1dff4e9bf988e425200a5e1aa82d))
226
- * convert any usage into or typed version ([#80](https://github.com/openwallet-foundation/sd-jwt-js/issues/80)) ([de4df54](https://github.com/openwallet-foundation/sd-jwt-js/commit/de4df54f2a0a77fdbf97e10abac555a98e70c6e0))
227
- * implement kbverify function ([#127](https://github.com/openwallet-foundation/sd-jwt-js/issues/127)) ([e5609f2](https://github.com/openwallet-foundation/sd-jwt-js/commit/e5609f26fab8c4991d3bd6c36066a95a30cfb972))
228
- * make sdjwt instance non abstract ([#122](https://github.com/openwallet-foundation/sd-jwt-js/issues/122)) ([e85aae8](https://github.com/openwallet-foundation/sd-jwt-js/commit/e85aae89910f5d9468e29ef14ef3b3d3215b86fd))
229
-
230
-
231
- ### Features
232
-
233
- * add jwk type ([#130](https://github.com/openwallet-foundation/sd-jwt-js/issues/130)) ([8ce255a](https://github.com/openwallet-foundation/sd-jwt-js/commit/8ce255a64b0940e92e647aa544bf5990b48279b7))
234
- * add new package for sd-jwt-vc ([ed99188](https://github.com/openwallet-foundation/sd-jwt-js/commit/ed99188f13184d58db64b4211e39fb67f3f78cb5))
235
- * Apply lerna to move src to core ([#67](https://github.com/openwallet-foundation/sd-jwt-js/issues/67)) ([49e272b](https://github.com/openwallet-foundation/sd-jwt-js/commit/49e272b6b51c5226e22732c469e566fd3c14c57c))
236
- * calcuate sd_hash in kb JWT ([#117](https://github.com/openwallet-foundation/sd-jwt-js/issues/117)) ([3415550](https://github.com/openwallet-foundation/sd-jwt-js/commit/3415550fbcd99f97babff442a4928cc827c5c9cc))
237
- * checking kb header value ([#133](https://github.com/openwallet-foundation/sd-jwt-js/issues/133)) ([cd2991b](https://github.com/openwallet-foundation/sd-jwt-js/commit/cd2991b88a0522e39251c5ca2b67593130baa585))
238
- * create kb jwt when present all ([#129](https://github.com/openwallet-foundation/sd-jwt-js/issues/129)) ([72ed1ad](https://github.com/openwallet-foundation/sd-jwt-js/commit/72ed1ad64b850876ba3b5d5e5df6128471fb44ac))
239
- * fix async handling in jwt verify ([#131](https://github.com/openwallet-foundation/sd-jwt-js/issues/131)) ([76cb930](https://github.com/openwallet-foundation/sd-jwt-js/commit/76cb93021dd62c241c87656975f74dd44b3766cf))
240
- * fixing exclude _sd_alg when no disclosure ([#120](https://github.com/openwallet-foundation/sd-jwt-js/issues/120)) ([dcaf1f6](https://github.com/openwallet-foundation/sd-jwt-js/commit/dcaf1f6fad3289ea7cbe0f3f410fdc15c0f77fda))