@sd-jwt/sd-jwt-vc 0.3.2-next.94
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 +201 -0
- package/README.md +87 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +454 -0
- package/dist/index.mjs +442 -0
- package/package.json +65 -0
- package/src/index.ts +55 -0
- package/test/app-e2e.spec.ts +266 -0
- package/test/array_data_types.json +29 -0
- package/test/array_full_sd.json +21 -0
- package/test/array_in_sd.json +13 -0
- package/test/array_nested_in_plain.json +20 -0
- package/test/array_none_disclosed.json +17 -0
- package/test/array_of_nulls.json +15 -0
- package/test/array_of_objects.json +58 -0
- package/test/array_of_scalars.json +15 -0
- package/test/array_recursive_sd.json +35 -0
- package/test/array_recursive_sd_some_disclosed.json +55 -0
- package/test/complex.json +43 -0
- package/test/header_mod.json +44 -0
- package/test/json_serialization.json +44 -0
- package/test/key_binding.json +44 -0
- package/test/no_sd.json +36 -0
- package/test/object_data_types.json +60 -0
- package/test/recursions.json +98 -0
- package/tsconfig.json +7 -0
- package/vitest.config.mts +4 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/js-base64@3.7.6/node_modules/js-base64/base64.js
|
|
28
|
+
var require_base64 = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/js-base64@3.7.6/node_modules/js-base64/base64.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
(function(global2, factory) {
|
|
32
|
+
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (
|
|
33
|
+
// cf. https://github.com/dankogai/js-base64/issues/119
|
|
34
|
+
function() {
|
|
35
|
+
var _Base64 = global2.Base64;
|
|
36
|
+
var gBase64 = factory();
|
|
37
|
+
gBase64.noConflict = function() {
|
|
38
|
+
global2.Base64 = _Base64;
|
|
39
|
+
return gBase64;
|
|
40
|
+
};
|
|
41
|
+
if (global2.Meteor) {
|
|
42
|
+
Base64 = gBase64;
|
|
43
|
+
}
|
|
44
|
+
global2.Base64 = gBase64;
|
|
45
|
+
}()
|
|
46
|
+
);
|
|
47
|
+
})(typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : exports, function() {
|
|
48
|
+
"use strict";
|
|
49
|
+
var version = "3.7.6";
|
|
50
|
+
var VERSION = version;
|
|
51
|
+
var _hasatob = typeof atob === "function";
|
|
52
|
+
var _hasbtoa = typeof btoa === "function";
|
|
53
|
+
var _hasBuffer = typeof Buffer === "function";
|
|
54
|
+
var _TD = typeof TextDecoder === "function" ? new TextDecoder() : void 0;
|
|
55
|
+
var _TE = typeof TextEncoder === "function" ? new TextEncoder() : void 0;
|
|
56
|
+
var b64ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
57
|
+
var b64chs = Array.prototype.slice.call(b64ch);
|
|
58
|
+
var b64tab = function(a) {
|
|
59
|
+
var tab = {};
|
|
60
|
+
a.forEach(function(c, i) {
|
|
61
|
+
return tab[c] = i;
|
|
62
|
+
});
|
|
63
|
+
return tab;
|
|
64
|
+
}(b64chs);
|
|
65
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
66
|
+
var _fromCC = String.fromCharCode.bind(String);
|
|
67
|
+
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : function(it) {
|
|
68
|
+
return new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
69
|
+
};
|
|
70
|
+
var _mkUriSafe = function(src) {
|
|
71
|
+
return src.replace(/=/g, "").replace(/[+\/]/g, function(m0) {
|
|
72
|
+
return m0 == "+" ? "-" : "_";
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var _tidyB64 = function(s) {
|
|
76
|
+
return s.replace(/[^A-Za-z0-9\+\/]/g, "");
|
|
77
|
+
};
|
|
78
|
+
var btoaPolyfill = function(bin) {
|
|
79
|
+
var u32, c0, c1, c2, asc = "";
|
|
80
|
+
var pad = bin.length % 3;
|
|
81
|
+
for (var i = 0; i < bin.length; ) {
|
|
82
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255)
|
|
83
|
+
throw new TypeError("invalid character found");
|
|
84
|
+
u32 = c0 << 16 | c1 << 8 | c2;
|
|
85
|
+
asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63];
|
|
86
|
+
}
|
|
87
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
88
|
+
};
|
|
89
|
+
var _btoa = _hasbtoa ? function(bin) {
|
|
90
|
+
return btoa(bin);
|
|
91
|
+
} : _hasBuffer ? function(bin) {
|
|
92
|
+
return Buffer.from(bin, "binary").toString("base64");
|
|
93
|
+
} : btoaPolyfill;
|
|
94
|
+
var _fromUint8Array = _hasBuffer ? function(u8a) {
|
|
95
|
+
return Buffer.from(u8a).toString("base64");
|
|
96
|
+
} : function(u8a) {
|
|
97
|
+
var maxargs = 4096;
|
|
98
|
+
var strs = [];
|
|
99
|
+
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
100
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
101
|
+
}
|
|
102
|
+
return _btoa(strs.join(""));
|
|
103
|
+
};
|
|
104
|
+
var fromUint8Array = function(u8a, urlsafe) {
|
|
105
|
+
if (urlsafe === void 0) {
|
|
106
|
+
urlsafe = false;
|
|
107
|
+
}
|
|
108
|
+
return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
|
109
|
+
};
|
|
110
|
+
var cb_utob = function(c) {
|
|
111
|
+
if (c.length < 2) {
|
|
112
|
+
var cc = c.charCodeAt(0);
|
|
113
|
+
return cc < 128 ? c : cc < 2048 ? _fromCC(192 | cc >>> 6) + _fromCC(128 | cc & 63) : _fromCC(224 | cc >>> 12 & 15) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
114
|
+
} else {
|
|
115
|
+
var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
116
|
+
return _fromCC(240 | cc >>> 18 & 7) + _fromCC(128 | cc >>> 12 & 63) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
120
|
+
var utob = function(u) {
|
|
121
|
+
return u.replace(re_utob, cb_utob);
|
|
122
|
+
};
|
|
123
|
+
var _encode = _hasBuffer ? function(s) {
|
|
124
|
+
return Buffer.from(s, "utf8").toString("base64");
|
|
125
|
+
} : _TE ? function(s) {
|
|
126
|
+
return _fromUint8Array(_TE.encode(s));
|
|
127
|
+
} : function(s) {
|
|
128
|
+
return _btoa(utob(s));
|
|
129
|
+
};
|
|
130
|
+
var encode = function(src, urlsafe) {
|
|
131
|
+
if (urlsafe === void 0) {
|
|
132
|
+
urlsafe = false;
|
|
133
|
+
}
|
|
134
|
+
return urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
|
|
135
|
+
};
|
|
136
|
+
var encodeURI = function(src) {
|
|
137
|
+
return encode(src, true);
|
|
138
|
+
};
|
|
139
|
+
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
140
|
+
var cb_btou = function(cccc) {
|
|
141
|
+
switch (cccc.length) {
|
|
142
|
+
case 4:
|
|
143
|
+
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
144
|
+
return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
|
|
145
|
+
case 3:
|
|
146
|
+
return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
|
|
147
|
+
default:
|
|
148
|
+
return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var btou = function(b) {
|
|
152
|
+
return b.replace(re_btou, cb_btou);
|
|
153
|
+
};
|
|
154
|
+
var atobPolyfill = function(asc) {
|
|
155
|
+
asc = asc.replace(/\s+/g, "");
|
|
156
|
+
if (!b64re.test(asc))
|
|
157
|
+
throw new TypeError("malformed base64.");
|
|
158
|
+
asc += "==".slice(2 - (asc.length & 3));
|
|
159
|
+
var u24, bin = "", r1, r2;
|
|
160
|
+
for (var i = 0; i < asc.length; ) {
|
|
161
|
+
u24 = b64tab[asc.charAt(i++)] << 18 | b64tab[asc.charAt(i++)] << 12 | (r1 = b64tab[asc.charAt(i++)]) << 6 | (r2 = b64tab[asc.charAt(i++)]);
|
|
162
|
+
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255) : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255) : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
|
163
|
+
}
|
|
164
|
+
return bin;
|
|
165
|
+
};
|
|
166
|
+
var _atob = _hasatob ? function(asc) {
|
|
167
|
+
return atob(_tidyB64(asc));
|
|
168
|
+
} : _hasBuffer ? function(asc) {
|
|
169
|
+
return Buffer.from(asc, "base64").toString("binary");
|
|
170
|
+
} : atobPolyfill;
|
|
171
|
+
var _toUint8Array = _hasBuffer ? function(a) {
|
|
172
|
+
return _U8Afrom(Buffer.from(a, "base64"));
|
|
173
|
+
} : function(a) {
|
|
174
|
+
return _U8Afrom(_atob(a).split("").map(function(c) {
|
|
175
|
+
return c.charCodeAt(0);
|
|
176
|
+
}));
|
|
177
|
+
};
|
|
178
|
+
var toUint8Array = function(a) {
|
|
179
|
+
return _toUint8Array(_unURI(a));
|
|
180
|
+
};
|
|
181
|
+
var _decode = _hasBuffer ? function(a) {
|
|
182
|
+
return Buffer.from(a, "base64").toString("utf8");
|
|
183
|
+
} : _TD ? function(a) {
|
|
184
|
+
return _TD.decode(_toUint8Array(a));
|
|
185
|
+
} : function(a) {
|
|
186
|
+
return btou(_atob(a));
|
|
187
|
+
};
|
|
188
|
+
var _unURI = function(a) {
|
|
189
|
+
return _tidyB64(a.replace(/[-_]/g, function(m0) {
|
|
190
|
+
return m0 == "-" ? "+" : "/";
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
var decode = function(src) {
|
|
194
|
+
return _decode(_unURI(src));
|
|
195
|
+
};
|
|
196
|
+
var isValid = function(src) {
|
|
197
|
+
if (typeof src !== "string")
|
|
198
|
+
return false;
|
|
199
|
+
var s = src.replace(/\s+/g, "").replace(/={0,2}$/, "");
|
|
200
|
+
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
|
201
|
+
};
|
|
202
|
+
var _noEnum = function(v) {
|
|
203
|
+
return {
|
|
204
|
+
value: v,
|
|
205
|
+
enumerable: false,
|
|
206
|
+
writable: true,
|
|
207
|
+
configurable: true
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
var extendString = function() {
|
|
211
|
+
var _add = function(name, body) {
|
|
212
|
+
return Object.defineProperty(String.prototype, name, _noEnum(body));
|
|
213
|
+
};
|
|
214
|
+
_add("fromBase64", function() {
|
|
215
|
+
return decode(this);
|
|
216
|
+
});
|
|
217
|
+
_add("toBase64", function(urlsafe) {
|
|
218
|
+
return encode(this, urlsafe);
|
|
219
|
+
});
|
|
220
|
+
_add("toBase64URI", function() {
|
|
221
|
+
return encode(this, true);
|
|
222
|
+
});
|
|
223
|
+
_add("toBase64URL", function() {
|
|
224
|
+
return encode(this, true);
|
|
225
|
+
});
|
|
226
|
+
_add("toUint8Array", function() {
|
|
227
|
+
return toUint8Array(this);
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
var extendUint8Array = function() {
|
|
231
|
+
var _add = function(name, body) {
|
|
232
|
+
return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
|
|
233
|
+
};
|
|
234
|
+
_add("toBase64", function(urlsafe) {
|
|
235
|
+
return fromUint8Array(this, urlsafe);
|
|
236
|
+
});
|
|
237
|
+
_add("toBase64URI", function() {
|
|
238
|
+
return fromUint8Array(this, true);
|
|
239
|
+
});
|
|
240
|
+
_add("toBase64URL", function() {
|
|
241
|
+
return fromUint8Array(this, true);
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
var extendBuiltins = function() {
|
|
245
|
+
extendString();
|
|
246
|
+
extendUint8Array();
|
|
247
|
+
};
|
|
248
|
+
var gBase64 = {
|
|
249
|
+
version,
|
|
250
|
+
VERSION,
|
|
251
|
+
atob: _atob,
|
|
252
|
+
atobPolyfill,
|
|
253
|
+
btoa: _btoa,
|
|
254
|
+
btoaPolyfill,
|
|
255
|
+
fromBase64: decode,
|
|
256
|
+
toBase64: encode,
|
|
257
|
+
encode,
|
|
258
|
+
encodeURI,
|
|
259
|
+
encodeURL: encodeURI,
|
|
260
|
+
utob,
|
|
261
|
+
btou,
|
|
262
|
+
decode,
|
|
263
|
+
isValid,
|
|
264
|
+
fromUint8Array,
|
|
265
|
+
toUint8Array,
|
|
266
|
+
extendString,
|
|
267
|
+
extendUint8Array,
|
|
268
|
+
extendBuiltins
|
|
269
|
+
};
|
|
270
|
+
gBase64.Base64 = {};
|
|
271
|
+
Object.keys(gBase64).forEach(function(k) {
|
|
272
|
+
return gBase64.Base64[k] = gBase64[k];
|
|
273
|
+
});
|
|
274
|
+
return gBase64;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ../utils/dist/index.js
|
|
280
|
+
var require_dist = __commonJS({
|
|
281
|
+
"../utils/dist/index.js"(exports, module) {
|
|
282
|
+
"use strict";
|
|
283
|
+
var __defProp2 = Object.defineProperty;
|
|
284
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
285
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
286
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
287
|
+
var __export = (target, all) => {
|
|
288
|
+
for (var name in all)
|
|
289
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
290
|
+
};
|
|
291
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
292
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
293
|
+
for (let key of __getOwnPropNames2(from))
|
|
294
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
295
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
296
|
+
}
|
|
297
|
+
return to;
|
|
298
|
+
};
|
|
299
|
+
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
300
|
+
var __async = (__this, __arguments, generator) => {
|
|
301
|
+
return new Promise((resolve, reject) => {
|
|
302
|
+
var fulfilled = (value) => {
|
|
303
|
+
try {
|
|
304
|
+
step(generator.next(value));
|
|
305
|
+
} catch (e) {
|
|
306
|
+
reject(e);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var rejected = (value) => {
|
|
310
|
+
try {
|
|
311
|
+
step(generator.throw(value));
|
|
312
|
+
} catch (e) {
|
|
313
|
+
reject(e);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
317
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
var src_exports = {};
|
|
321
|
+
__export(src_exports, {
|
|
322
|
+
Base64urlDecode: () => Base64urlDecode,
|
|
323
|
+
Base64urlEncode: () => Base64urlEncode,
|
|
324
|
+
Disclosure: () => Disclosure,
|
|
325
|
+
SDJWTException: () => SDJWTException2,
|
|
326
|
+
Uint8ArrayToBase64Url: () => Uint8ArrayToBase64Url
|
|
327
|
+
});
|
|
328
|
+
module.exports = __toCommonJS(src_exports);
|
|
329
|
+
var import_js_base64 = require_base64();
|
|
330
|
+
var Base64urlEncode = import_js_base64.Base64.encodeURI;
|
|
331
|
+
var Base64urlDecode = import_js_base64.Base64.decode;
|
|
332
|
+
var Uint8ArrayToBase64Url = (input) => import_js_base64.Base64.fromUint8Array(input, true);
|
|
333
|
+
var SDJWTException2 = class _SDJWTException extends Error {
|
|
334
|
+
constructor(message, details) {
|
|
335
|
+
super(message);
|
|
336
|
+
Object.setPrototypeOf(this, _SDJWTException.prototype);
|
|
337
|
+
this.name = "SDJWTException";
|
|
338
|
+
this.details = details;
|
|
339
|
+
}
|
|
340
|
+
getFullMessage() {
|
|
341
|
+
return `${this.name}: ${this.message} ${this.details ? `- ${JSON.stringify(this.details)}` : ""}`;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
var Disclosure = class _Disclosure {
|
|
345
|
+
constructor(data, _meta) {
|
|
346
|
+
this._digest = _meta == null ? void 0 : _meta.digest;
|
|
347
|
+
this._encoded = _meta == null ? void 0 : _meta.encoded;
|
|
348
|
+
if (data.length === 2) {
|
|
349
|
+
this.salt = data[0];
|
|
350
|
+
this.value = data[1];
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (data.length === 3) {
|
|
354
|
+
this.salt = data[0];
|
|
355
|
+
this.key = data[1];
|
|
356
|
+
this.value = data[2];
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
throw new SDJWTException2("Invalid disclosure data");
|
|
360
|
+
}
|
|
361
|
+
// We need to digest of the original encoded data.
|
|
362
|
+
// After decode process, we use JSON.stringify to encode the data.
|
|
363
|
+
// This can be different from the original encoded data.
|
|
364
|
+
static fromEncode(s, hash) {
|
|
365
|
+
return __async(this, null, function* () {
|
|
366
|
+
const { hasher, alg } = hash;
|
|
367
|
+
const digest = yield hasher(s, alg);
|
|
368
|
+
const digestStr = Uint8ArrayToBase64Url(digest);
|
|
369
|
+
const item = JSON.parse(Base64urlDecode(s));
|
|
370
|
+
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
static fromEncodeSync(s, hash) {
|
|
374
|
+
const { hasher, alg } = hash;
|
|
375
|
+
const digest = hasher(s, alg);
|
|
376
|
+
const digestStr = Uint8ArrayToBase64Url(digest);
|
|
377
|
+
const item = JSON.parse(Base64urlDecode(s));
|
|
378
|
+
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
379
|
+
}
|
|
380
|
+
static fromArray(item, _meta) {
|
|
381
|
+
return new _Disclosure(item, _meta);
|
|
382
|
+
}
|
|
383
|
+
encode() {
|
|
384
|
+
if (!this._encoded) {
|
|
385
|
+
this._encoded = Base64urlEncode(JSON.stringify(this.decode()));
|
|
386
|
+
}
|
|
387
|
+
return this._encoded;
|
|
388
|
+
}
|
|
389
|
+
decode() {
|
|
390
|
+
return this.key ? [this.salt, this.key, this.value] : [this.salt, this.value];
|
|
391
|
+
}
|
|
392
|
+
digest(hash) {
|
|
393
|
+
return __async(this, null, function* () {
|
|
394
|
+
const { hasher, alg } = hash;
|
|
395
|
+
if (!this._digest) {
|
|
396
|
+
const hash2 = yield hasher(this.encode(), alg);
|
|
397
|
+
this._digest = Uint8ArrayToBase64Url(hash2);
|
|
398
|
+
}
|
|
399
|
+
return this._digest;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
digestSync(hash) {
|
|
403
|
+
const { hasher, alg } = hash;
|
|
404
|
+
if (!this._digest) {
|
|
405
|
+
const hash2 = hasher(this.encode(), alg);
|
|
406
|
+
this._digest = Uint8ArrayToBase64Url(hash2);
|
|
407
|
+
}
|
|
408
|
+
return this._digest;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// src/index.ts
|
|
415
|
+
var import_dist = __toESM(require_dist());
|
|
416
|
+
import { SDJwtInstance } from "@sd-jwt/core";
|
|
417
|
+
var SDJwtVcInstance = class extends SDJwtInstance {
|
|
418
|
+
constructor() {
|
|
419
|
+
super(...arguments);
|
|
420
|
+
this.type = "sd-jwt-vc";
|
|
421
|
+
}
|
|
422
|
+
validateReservedFields(disclosureFrame) {
|
|
423
|
+
if ((disclosureFrame == null ? void 0 : disclosureFrame._sd) && Array.isArray(disclosureFrame._sd) && disclosureFrame._sd.length > 0) {
|
|
424
|
+
const reservedNames = [
|
|
425
|
+
"iss",
|
|
426
|
+
"iat",
|
|
427
|
+
"nbf",
|
|
428
|
+
"exp",
|
|
429
|
+
"cnf",
|
|
430
|
+
"vct",
|
|
431
|
+
"status"
|
|
432
|
+
];
|
|
433
|
+
const reservedNamesInDisclosureFrame = disclosureFrame._sd.filter((key) => reservedNames.includes(key));
|
|
434
|
+
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
435
|
+
throw new import_dist.SDJWTException("Cannot disclose protected field");
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
export {
|
|
441
|
+
SDJwtVcInstance
|
|
442
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sd-jwt/sd-jwt-vc",
|
|
3
|
+
"version": "0.3.2-next.94+32af6cf",
|
|
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:e2e && pnpm run test:cov",
|
|
18
|
+
"test:node": "vitest run ./src/test/*.spec.ts && vitest run ./src/test/*.spec.ts --environment jsdom",
|
|
19
|
+
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
|
|
20
|
+
"test:e2e": "vitest run ./test/*e2e.spec.ts --environment node",
|
|
21
|
+
"test:cov": "vitest run --coverage"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"sd-jwt",
|
|
25
|
+
"sdjwt",
|
|
26
|
+
"sd-jwt-vc"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=16"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/openwallet-foundation-labs/sd-jwt-js"
|
|
34
|
+
},
|
|
35
|
+
"author": "Lukas.J.Han <lukas.j.han@gmail.com>",
|
|
36
|
+
"homepage": "https://github.com/openwallet-foundation-labs/sd-jwt-js/wiki",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/openwallet-foundation-labs/sd-jwt-js/issues"
|
|
39
|
+
},
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@sd-jwt/core": "0.3.2-next.94+32af6cf"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@sd-jwt/crypto-nodejs": "0.3.2-next.94+32af6cf",
|
|
46
|
+
"@sd-jwt/types": "0.3.2-next.94+32af6cf"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"tsup": {
|
|
52
|
+
"entry": [
|
|
53
|
+
"./src/index.ts"
|
|
54
|
+
],
|
|
55
|
+
"sourceMap": true,
|
|
56
|
+
"splitting": false,
|
|
57
|
+
"clean": true,
|
|
58
|
+
"dts": true,
|
|
59
|
+
"format": [
|
|
60
|
+
"cjs",
|
|
61
|
+
"esm"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "32af6cfa150fceb440fc9225bcaf2791a6aeee90"
|
|
65
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { SDJwt, SDJwtInstance, SdJwtPayload } from '@sd-jwt/core';
|
|
2
|
+
import { DisclosureFrame } from '@sd-jwt/types';
|
|
3
|
+
import { SDJWTException } from '../../utils/dist';
|
|
4
|
+
|
|
5
|
+
export interface SdJwtVcPayload extends SdJwtPayload {
|
|
6
|
+
// The Issuer of the Verifiable Credential. The value of iss MUST be a URI. See [RFC7519] for more information.
|
|
7
|
+
iss: string;
|
|
8
|
+
// The time of issuance of the Verifiable Credential. See [RFC7519] for more information.
|
|
9
|
+
iat: number;
|
|
10
|
+
// OPTIONAL. The time before which the Verifiable Credential MUST NOT be accepted before validating. See [RFC7519] for more information.
|
|
11
|
+
nbf?: number;
|
|
12
|
+
//OPTIONAL. The expiry time of the Verifiable Credential after which the Verifiable Credential is no longer valid. See [RFC7519] for more information.
|
|
13
|
+
exp?: number;
|
|
14
|
+
// REQUIRED when Cryptographic Key Binding is to be supported. Contains the confirmation method as defined in [RFC7800]. It is RECOMMENDED that this contains a JWK as defined in Section 3.2 of [RFC7800]. For Cryptographic Key Binding, the Key Binding JWT in the Combined Format for Presentation MUST be signed by the key identified in this claim.
|
|
15
|
+
cnf?: unknown;
|
|
16
|
+
//REQUIRED. The type of the Verifiable Credential, e.g., https://credentials.example.com/identity_credential, as defined in Section 3.2.2.1.1.
|
|
17
|
+
vct: string;
|
|
18
|
+
// OPTIONAL. The information on how to read the status of the Verifiable Credential. See [I-D.looker-oauth-jwt-cwt-status-list] for more information.
|
|
19
|
+
status?: unknown;
|
|
20
|
+
|
|
21
|
+
//The identifier of the Subject of the Verifiable Credential. The Issuer MAY use it to provide the Subject identifier known by the Issuer. There is no requirement for a binding to exist between sub and cnf claims.
|
|
22
|
+
sub?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
26
|
+
protected type = 'sd-jwt-vc';
|
|
27
|
+
|
|
28
|
+
protected validateReservedFields(
|
|
29
|
+
disclosureFrame: DisclosureFrame<SdJwtVcPayload>,
|
|
30
|
+
): void {
|
|
31
|
+
//validate disclosureFrame according to https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-01.html#section-3.2.2.2
|
|
32
|
+
if (
|
|
33
|
+
disclosureFrame?._sd &&
|
|
34
|
+
Array.isArray(disclosureFrame._sd) &&
|
|
35
|
+
disclosureFrame._sd.length > 0
|
|
36
|
+
) {
|
|
37
|
+
const reservedNames = [
|
|
38
|
+
'iss',
|
|
39
|
+
'iat',
|
|
40
|
+
'nbf',
|
|
41
|
+
'exp',
|
|
42
|
+
'cnf',
|
|
43
|
+
'vct',
|
|
44
|
+
'status',
|
|
45
|
+
];
|
|
46
|
+
// check if there is any reserved names in the disclosureFrame._sd array
|
|
47
|
+
const reservedNamesInDisclosureFrame = (
|
|
48
|
+
disclosureFrame._sd as string[]
|
|
49
|
+
).filter((key) => reservedNames.includes(key));
|
|
50
|
+
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
51
|
+
throw new SDJWTException('Cannot disclose protected field');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|