@sd-jwt/sd-jwt-vc 0.7.1-next.0 → 0.7.1-next.2
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/dist/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +6 -403
- package/dist/index.mjs +5 -416
- package/package.json +7 -6
- package/src/index.ts +4 -138
- package/src/sd-jwt-vc-instance.ts +141 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
2
1
|
import { SDJWTConfig, DisclosureFrame } from '@sd-jwt/types';
|
|
2
|
+
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for SD-JWT-VC
|
|
6
|
+
*/
|
|
7
|
+
type SDJWTVCConfig = SDJWTConfig & {
|
|
8
|
+
statusListFetcher?: (uri: string) => Promise<string>;
|
|
9
|
+
statusValidator?: (status: number) => Promise<void>;
|
|
10
|
+
};
|
|
3
11
|
|
|
4
12
|
interface SDJWTVCStatusReference {
|
|
5
13
|
status_list: {
|
|
@@ -19,14 +27,6 @@ interface SdJwtVcPayload extends SdJwtPayload {
|
|
|
19
27
|
iat?: number;
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
/**
|
|
23
|
-
* Configuration for SD-JWT-VC
|
|
24
|
-
*/
|
|
25
|
-
type SDJWTVCConfig = SDJWTConfig & {
|
|
26
|
-
statusListFetcher?: (uri: string) => Promise<string>;
|
|
27
|
-
statusValidator?: (status: number) => Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
30
|
declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
31
31
|
/**
|
|
32
32
|
* The type of the SD-JWT-VC set in the header.typ field.
|
|
@@ -60,4 +60,4 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
|
60
60
|
}>;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export { SDJwtVcInstance };
|
|
63
|
+
export { type SDJWTVCConfig, type SDJWTVCStatusReference, SDJwtVcInstance, type SdJwtVcPayload };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
2
1
|
import { SDJWTConfig, DisclosureFrame } from '@sd-jwt/types';
|
|
2
|
+
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for SD-JWT-VC
|
|
6
|
+
*/
|
|
7
|
+
type SDJWTVCConfig = SDJWTConfig & {
|
|
8
|
+
statusListFetcher?: (uri: string) => Promise<string>;
|
|
9
|
+
statusValidator?: (status: number) => Promise<void>;
|
|
10
|
+
};
|
|
3
11
|
|
|
4
12
|
interface SDJWTVCStatusReference {
|
|
5
13
|
status_list: {
|
|
@@ -19,14 +27,6 @@ interface SdJwtVcPayload extends SdJwtPayload {
|
|
|
19
27
|
iat?: number;
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
/**
|
|
23
|
-
* Configuration for SD-JWT-VC
|
|
24
|
-
*/
|
|
25
|
-
type SDJWTVCConfig = SDJWTConfig & {
|
|
26
|
-
statusListFetcher?: (uri: string) => Promise<string>;
|
|
27
|
-
statusValidator?: (status: number) => Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
30
|
declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
31
31
|
/**
|
|
32
32
|
* The type of the SD-JWT-VC set in the header.typ field.
|
|
@@ -60,4 +60,4 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
|
60
60
|
}>;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export { SDJwtVcInstance };
|
|
63
|
+
export { type SDJWTVCConfig, type SDJWTVCStatusReference, SDJwtVcInstance, type SdJwtVcPayload };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
7
|
var __reflectGet = Reflect.get;
|
|
9
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
-
};
|
|
12
8
|
var __export = (target, all) => {
|
|
13
9
|
for (var name in all)
|
|
14
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -21,14 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
21
17
|
}
|
|
22
18
|
return to;
|
|
23
19
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
-
mod
|
|
31
|
-
));
|
|
32
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
21
|
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
34
22
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -52,401 +40,16 @@ var __async = (__this, __arguments, generator) => {
|
|
|
52
40
|
});
|
|
53
41
|
};
|
|
54
42
|
|
|
55
|
-
// ../../node_modules/.pnpm/js-base64@3.7.6/node_modules/js-base64/base64.js
|
|
56
|
-
var require_base64 = __commonJS({
|
|
57
|
-
"../../node_modules/.pnpm/js-base64@3.7.6/node_modules/js-base64/base64.js"(exports2, module2) {
|
|
58
|
-
"use strict";
|
|
59
|
-
(function(global2, factory) {
|
|
60
|
-
typeof exports2 === "object" && typeof module2 !== "undefined" ? module2.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (
|
|
61
|
-
// cf. https://github.com/dankogai/js-base64/issues/119
|
|
62
|
-
function() {
|
|
63
|
-
var _Base64 = global2.Base64;
|
|
64
|
-
var gBase64 = factory();
|
|
65
|
-
gBase64.noConflict = function() {
|
|
66
|
-
global2.Base64 = _Base64;
|
|
67
|
-
return gBase64;
|
|
68
|
-
};
|
|
69
|
-
if (global2.Meteor) {
|
|
70
|
-
Base64 = gBase64;
|
|
71
|
-
}
|
|
72
|
-
global2.Base64 = gBase64;
|
|
73
|
-
}()
|
|
74
|
-
);
|
|
75
|
-
})(typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : exports2, function() {
|
|
76
|
-
"use strict";
|
|
77
|
-
var version = "3.7.6";
|
|
78
|
-
var VERSION = version;
|
|
79
|
-
var _hasatob = typeof atob === "function";
|
|
80
|
-
var _hasbtoa = typeof btoa === "function";
|
|
81
|
-
var _hasBuffer = typeof Buffer === "function";
|
|
82
|
-
var _TD = typeof TextDecoder === "function" ? new TextDecoder() : void 0;
|
|
83
|
-
var _TE = typeof TextEncoder === "function" ? new TextEncoder() : void 0;
|
|
84
|
-
var b64ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
85
|
-
var b64chs = Array.prototype.slice.call(b64ch);
|
|
86
|
-
var b64tab = function(a) {
|
|
87
|
-
var tab = {};
|
|
88
|
-
a.forEach(function(c, i) {
|
|
89
|
-
return tab[c] = i;
|
|
90
|
-
});
|
|
91
|
-
return tab;
|
|
92
|
-
}(b64chs);
|
|
93
|
-
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
94
|
-
var _fromCC = String.fromCharCode.bind(String);
|
|
95
|
-
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : function(it) {
|
|
96
|
-
return new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
97
|
-
};
|
|
98
|
-
var _mkUriSafe = function(src) {
|
|
99
|
-
return src.replace(/=/g, "").replace(/[+\/]/g, function(m0) {
|
|
100
|
-
return m0 == "+" ? "-" : "_";
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
var _tidyB64 = function(s) {
|
|
104
|
-
return s.replace(/[^A-Za-z0-9\+\/]/g, "");
|
|
105
|
-
};
|
|
106
|
-
var btoaPolyfill = function(bin) {
|
|
107
|
-
var u32, c0, c1, c2, asc = "";
|
|
108
|
-
var pad = bin.length % 3;
|
|
109
|
-
for (var i = 0; i < bin.length; ) {
|
|
110
|
-
if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255)
|
|
111
|
-
throw new TypeError("invalid character found");
|
|
112
|
-
u32 = c0 << 16 | c1 << 8 | c2;
|
|
113
|
-
asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63];
|
|
114
|
-
}
|
|
115
|
-
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
116
|
-
};
|
|
117
|
-
var _btoa = _hasbtoa ? function(bin) {
|
|
118
|
-
return btoa(bin);
|
|
119
|
-
} : _hasBuffer ? function(bin) {
|
|
120
|
-
return Buffer.from(bin, "binary").toString("base64");
|
|
121
|
-
} : btoaPolyfill;
|
|
122
|
-
var _fromUint8Array = _hasBuffer ? function(u8a) {
|
|
123
|
-
return Buffer.from(u8a).toString("base64");
|
|
124
|
-
} : function(u8a) {
|
|
125
|
-
var maxargs = 4096;
|
|
126
|
-
var strs = [];
|
|
127
|
-
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
128
|
-
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
129
|
-
}
|
|
130
|
-
return _btoa(strs.join(""));
|
|
131
|
-
};
|
|
132
|
-
var fromUint8Array = function(u8a, urlsafe) {
|
|
133
|
-
if (urlsafe === void 0) {
|
|
134
|
-
urlsafe = false;
|
|
135
|
-
}
|
|
136
|
-
return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
|
137
|
-
};
|
|
138
|
-
var cb_utob = function(c) {
|
|
139
|
-
if (c.length < 2) {
|
|
140
|
-
var cc = c.charCodeAt(0);
|
|
141
|
-
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);
|
|
142
|
-
} else {
|
|
143
|
-
var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
144
|
-
return _fromCC(240 | cc >>> 18 & 7) + _fromCC(128 | cc >>> 12 & 63) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
148
|
-
var utob = function(u) {
|
|
149
|
-
return u.replace(re_utob, cb_utob);
|
|
150
|
-
};
|
|
151
|
-
var _encode = _hasBuffer ? function(s) {
|
|
152
|
-
return Buffer.from(s, "utf8").toString("base64");
|
|
153
|
-
} : _TE ? function(s) {
|
|
154
|
-
return _fromUint8Array(_TE.encode(s));
|
|
155
|
-
} : function(s) {
|
|
156
|
-
return _btoa(utob(s));
|
|
157
|
-
};
|
|
158
|
-
var encode = function(src, urlsafe) {
|
|
159
|
-
if (urlsafe === void 0) {
|
|
160
|
-
urlsafe = false;
|
|
161
|
-
}
|
|
162
|
-
return urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
|
|
163
|
-
};
|
|
164
|
-
var encodeURI = function(src) {
|
|
165
|
-
return encode(src, true);
|
|
166
|
-
};
|
|
167
|
-
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
168
|
-
var cb_btou = function(cccc) {
|
|
169
|
-
switch (cccc.length) {
|
|
170
|
-
case 4:
|
|
171
|
-
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
172
|
-
return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
|
|
173
|
-
case 3:
|
|
174
|
-
return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
|
|
175
|
-
default:
|
|
176
|
-
return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
var btou = function(b) {
|
|
180
|
-
return b.replace(re_btou, cb_btou);
|
|
181
|
-
};
|
|
182
|
-
var atobPolyfill = function(asc) {
|
|
183
|
-
asc = asc.replace(/\s+/g, "");
|
|
184
|
-
if (!b64re.test(asc))
|
|
185
|
-
throw new TypeError("malformed base64.");
|
|
186
|
-
asc += "==".slice(2 - (asc.length & 3));
|
|
187
|
-
var u24, bin = "", r1, r2;
|
|
188
|
-
for (var i = 0; i < asc.length; ) {
|
|
189
|
-
u24 = b64tab[asc.charAt(i++)] << 18 | b64tab[asc.charAt(i++)] << 12 | (r1 = b64tab[asc.charAt(i++)]) << 6 | (r2 = b64tab[asc.charAt(i++)]);
|
|
190
|
-
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);
|
|
191
|
-
}
|
|
192
|
-
return bin;
|
|
193
|
-
};
|
|
194
|
-
var _atob = _hasatob ? function(asc) {
|
|
195
|
-
return atob(_tidyB64(asc));
|
|
196
|
-
} : _hasBuffer ? function(asc) {
|
|
197
|
-
return Buffer.from(asc, "base64").toString("binary");
|
|
198
|
-
} : atobPolyfill;
|
|
199
|
-
var _toUint8Array = _hasBuffer ? function(a) {
|
|
200
|
-
return _U8Afrom(Buffer.from(a, "base64"));
|
|
201
|
-
} : function(a) {
|
|
202
|
-
return _U8Afrom(_atob(a).split("").map(function(c) {
|
|
203
|
-
return c.charCodeAt(0);
|
|
204
|
-
}));
|
|
205
|
-
};
|
|
206
|
-
var toUint8Array = function(a) {
|
|
207
|
-
return _toUint8Array(_unURI(a));
|
|
208
|
-
};
|
|
209
|
-
var _decode = _hasBuffer ? function(a) {
|
|
210
|
-
return Buffer.from(a, "base64").toString("utf8");
|
|
211
|
-
} : _TD ? function(a) {
|
|
212
|
-
return _TD.decode(_toUint8Array(a));
|
|
213
|
-
} : function(a) {
|
|
214
|
-
return btou(_atob(a));
|
|
215
|
-
};
|
|
216
|
-
var _unURI = function(a) {
|
|
217
|
-
return _tidyB64(a.replace(/[-_]/g, function(m0) {
|
|
218
|
-
return m0 == "-" ? "+" : "/";
|
|
219
|
-
}));
|
|
220
|
-
};
|
|
221
|
-
var decode = function(src) {
|
|
222
|
-
return _decode(_unURI(src));
|
|
223
|
-
};
|
|
224
|
-
var isValid = function(src) {
|
|
225
|
-
if (typeof src !== "string")
|
|
226
|
-
return false;
|
|
227
|
-
var s = src.replace(/\s+/g, "").replace(/={0,2}$/, "");
|
|
228
|
-
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
|
229
|
-
};
|
|
230
|
-
var _noEnum = function(v) {
|
|
231
|
-
return {
|
|
232
|
-
value: v,
|
|
233
|
-
enumerable: false,
|
|
234
|
-
writable: true,
|
|
235
|
-
configurable: true
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
var extendString = function() {
|
|
239
|
-
var _add = function(name, body) {
|
|
240
|
-
return Object.defineProperty(String.prototype, name, _noEnum(body));
|
|
241
|
-
};
|
|
242
|
-
_add("fromBase64", function() {
|
|
243
|
-
return decode(this);
|
|
244
|
-
});
|
|
245
|
-
_add("toBase64", function(urlsafe) {
|
|
246
|
-
return encode(this, urlsafe);
|
|
247
|
-
});
|
|
248
|
-
_add("toBase64URI", function() {
|
|
249
|
-
return encode(this, true);
|
|
250
|
-
});
|
|
251
|
-
_add("toBase64URL", function() {
|
|
252
|
-
return encode(this, true);
|
|
253
|
-
});
|
|
254
|
-
_add("toUint8Array", function() {
|
|
255
|
-
return toUint8Array(this);
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
var extendUint8Array = function() {
|
|
259
|
-
var _add = function(name, body) {
|
|
260
|
-
return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
|
|
261
|
-
};
|
|
262
|
-
_add("toBase64", function(urlsafe) {
|
|
263
|
-
return fromUint8Array(this, urlsafe);
|
|
264
|
-
});
|
|
265
|
-
_add("toBase64URI", function() {
|
|
266
|
-
return fromUint8Array(this, true);
|
|
267
|
-
});
|
|
268
|
-
_add("toBase64URL", function() {
|
|
269
|
-
return fromUint8Array(this, true);
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
var extendBuiltins = function() {
|
|
273
|
-
extendString();
|
|
274
|
-
extendUint8Array();
|
|
275
|
-
};
|
|
276
|
-
var gBase64 = {
|
|
277
|
-
version,
|
|
278
|
-
VERSION,
|
|
279
|
-
atob: _atob,
|
|
280
|
-
atobPolyfill,
|
|
281
|
-
btoa: _btoa,
|
|
282
|
-
btoaPolyfill,
|
|
283
|
-
fromBase64: decode,
|
|
284
|
-
toBase64: encode,
|
|
285
|
-
encode,
|
|
286
|
-
encodeURI,
|
|
287
|
-
encodeURL: encodeURI,
|
|
288
|
-
utob,
|
|
289
|
-
btou,
|
|
290
|
-
decode,
|
|
291
|
-
isValid,
|
|
292
|
-
fromUint8Array,
|
|
293
|
-
toUint8Array,
|
|
294
|
-
extendString,
|
|
295
|
-
extendUint8Array,
|
|
296
|
-
extendBuiltins
|
|
297
|
-
};
|
|
298
|
-
gBase64.Base64 = {};
|
|
299
|
-
Object.keys(gBase64).forEach(function(k) {
|
|
300
|
-
return gBase64.Base64[k] = gBase64[k];
|
|
301
|
-
});
|
|
302
|
-
return gBase64;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
// ../utils/dist/index.js
|
|
308
|
-
var require_dist = __commonJS({
|
|
309
|
-
"../utils/dist/index.js"(exports2, module2) {
|
|
310
|
-
"use strict";
|
|
311
|
-
var __defProp2 = Object.defineProperty;
|
|
312
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
313
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
314
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
315
|
-
var __export2 = (target, all) => {
|
|
316
|
-
for (var name in all)
|
|
317
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
318
|
-
};
|
|
319
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
320
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
321
|
-
for (let key of __getOwnPropNames2(from))
|
|
322
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
323
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
324
|
-
}
|
|
325
|
-
return to;
|
|
326
|
-
};
|
|
327
|
-
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
328
|
-
var __async2 = (__this, __arguments, generator) => {
|
|
329
|
-
return new Promise((resolve, reject) => {
|
|
330
|
-
var fulfilled = (value) => {
|
|
331
|
-
try {
|
|
332
|
-
step(generator.next(value));
|
|
333
|
-
} catch (e) {
|
|
334
|
-
reject(e);
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
var rejected = (value) => {
|
|
338
|
-
try {
|
|
339
|
-
step(generator.throw(value));
|
|
340
|
-
} catch (e) {
|
|
341
|
-
reject(e);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
345
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
var src_exports2 = {};
|
|
349
|
-
__export2(src_exports2, {
|
|
350
|
-
Disclosure: () => Disclosure,
|
|
351
|
-
SDJWTException: () => SDJWTException2,
|
|
352
|
-
base64urlDecode: () => base64urlDecode,
|
|
353
|
-
base64urlEncode: () => base64urlEncode,
|
|
354
|
-
uint8ArrayToBase64Url: () => uint8ArrayToBase64Url
|
|
355
|
-
});
|
|
356
|
-
module2.exports = __toCommonJS2(src_exports2);
|
|
357
|
-
var import_js_base64 = require_base64();
|
|
358
|
-
var base64urlEncode = import_js_base64.Base64.encodeURI;
|
|
359
|
-
var base64urlDecode = import_js_base64.Base64.decode;
|
|
360
|
-
var uint8ArrayToBase64Url = (input) => import_js_base64.Base64.fromUint8Array(input, true);
|
|
361
|
-
var SDJWTException2 = class _SDJWTException extends Error {
|
|
362
|
-
constructor(message, details) {
|
|
363
|
-
super(message);
|
|
364
|
-
Object.setPrototypeOf(this, _SDJWTException.prototype);
|
|
365
|
-
this.name = "SDJWTException";
|
|
366
|
-
this.details = details;
|
|
367
|
-
}
|
|
368
|
-
getFullMessage() {
|
|
369
|
-
return `${this.name}: ${this.message} ${this.details ? `- ${JSON.stringify(this.details)}` : ""}`;
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
var Disclosure = class _Disclosure {
|
|
373
|
-
constructor(data, _meta) {
|
|
374
|
-
this._digest = _meta == null ? void 0 : _meta.digest;
|
|
375
|
-
this._encoded = _meta == null ? void 0 : _meta.encoded;
|
|
376
|
-
if (data.length === 2) {
|
|
377
|
-
this.salt = data[0];
|
|
378
|
-
this.value = data[1];
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
if (data.length === 3) {
|
|
382
|
-
this.salt = data[0];
|
|
383
|
-
this.key = data[1];
|
|
384
|
-
this.value = data[2];
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
throw new SDJWTException2("Invalid disclosure data");
|
|
388
|
-
}
|
|
389
|
-
// We need to digest of the original encoded data.
|
|
390
|
-
// After decode process, we use JSON.stringify to encode the data.
|
|
391
|
-
// This can be different from the original encoded data.
|
|
392
|
-
static fromEncode(s, hash) {
|
|
393
|
-
return __async2(this, null, function* () {
|
|
394
|
-
const { hasher, alg } = hash;
|
|
395
|
-
const digest = yield hasher(s, alg);
|
|
396
|
-
const digestStr = uint8ArrayToBase64Url(digest);
|
|
397
|
-
const item = JSON.parse(base64urlDecode(s));
|
|
398
|
-
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
static fromEncodeSync(s, hash) {
|
|
402
|
-
const { hasher, alg } = hash;
|
|
403
|
-
const digest = hasher(s, alg);
|
|
404
|
-
const digestStr = uint8ArrayToBase64Url(digest);
|
|
405
|
-
const item = JSON.parse(base64urlDecode(s));
|
|
406
|
-
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
407
|
-
}
|
|
408
|
-
static fromArray(item, _meta) {
|
|
409
|
-
return new _Disclosure(item, _meta);
|
|
410
|
-
}
|
|
411
|
-
encode() {
|
|
412
|
-
if (!this._encoded) {
|
|
413
|
-
this._encoded = base64urlEncode(JSON.stringify(this.decode()));
|
|
414
|
-
}
|
|
415
|
-
return this._encoded;
|
|
416
|
-
}
|
|
417
|
-
decode() {
|
|
418
|
-
return this.key ? [this.salt, this.key, this.value] : [this.salt, this.value];
|
|
419
|
-
}
|
|
420
|
-
digest(hash) {
|
|
421
|
-
return __async2(this, null, function* () {
|
|
422
|
-
const { hasher, alg } = hash;
|
|
423
|
-
if (!this._digest) {
|
|
424
|
-
const hash2 = yield hasher(this.encode(), alg);
|
|
425
|
-
this._digest = uint8ArrayToBase64Url(hash2);
|
|
426
|
-
}
|
|
427
|
-
return this._digest;
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
digestSync(hash) {
|
|
431
|
-
const { hasher, alg } = hash;
|
|
432
|
-
if (!this._digest) {
|
|
433
|
-
const hash2 = hasher(this.encode(), alg);
|
|
434
|
-
this._digest = uint8ArrayToBase64Url(hash2);
|
|
435
|
-
}
|
|
436
|
-
return this._digest;
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
|
|
442
43
|
// src/index.ts
|
|
443
44
|
var src_exports = {};
|
|
444
45
|
__export(src_exports, {
|
|
445
46
|
SDJwtVcInstance: () => SDJwtVcInstance
|
|
446
47
|
});
|
|
447
48
|
module.exports = __toCommonJS(src_exports);
|
|
49
|
+
|
|
50
|
+
// src/sd-jwt-vc-instance.ts
|
|
448
51
|
var import_core = require("@sd-jwt/core");
|
|
449
|
-
var
|
|
52
|
+
var import_utils = require("@sd-jwt/utils");
|
|
450
53
|
var import_jwt_status_list = require("@sd-jwt/jwt-status-list");
|
|
451
54
|
var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
|
|
452
55
|
constructor(userConfig) {
|
|
@@ -469,7 +72,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
|
|
|
469
72
|
const reservedNames = ["iss", "nbf", "exp", "cnf", "vct", "status"];
|
|
470
73
|
const reservedNamesInDisclosureFrame = disclosureFrame._sd.filter((key) => reservedNames.includes(key));
|
|
471
74
|
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
472
|
-
throw new
|
|
75
|
+
throw new import_utils.SDJWTException("Cannot disclose protected field");
|
|
473
76
|
}
|
|
474
77
|
}
|
|
475
78
|
}
|
|
@@ -503,7 +106,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
|
|
|
503
106
|
statusValidator(status) {
|
|
504
107
|
return __async(this, null, function* () {
|
|
505
108
|
if (status !== 0)
|
|
506
|
-
throw new
|
|
109
|
+
throw new import_utils.SDJWTException("Status is not valid");
|
|
507
110
|
return Promise.resolve();
|
|
508
111
|
});
|
|
509
112
|
}
|
|
@@ -525,7 +128,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
|
|
|
525
128
|
const slJWT = import_core.Jwt.fromEncode(statusListJWT);
|
|
526
129
|
yield slJWT.verify(this.userConfig.verifier);
|
|
527
130
|
if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < Date.now() / 1e3) {
|
|
528
|
-
throw new
|
|
131
|
+
throw new import_utils.SDJWTException("Status list is expired");
|
|
529
132
|
}
|
|
530
133
|
const statusList = (0, import_jwt_status_list.getListFromStatusListJWT)(statusListJWT);
|
|
531
134
|
const status = statusList.getStatus(
|
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
1
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
2
|
var __reflectGet = Reflect.get;
|
|
8
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
3
|
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
28
4
|
var __async = (__this, __arguments, generator) => {
|
|
29
5
|
return new Promise((resolve, reject) => {
|
|
@@ -46,396 +22,9 @@ var __async = (__this, __arguments, generator) => {
|
|
|
46
22
|
});
|
|
47
23
|
};
|
|
48
24
|
|
|
49
|
-
//
|
|
50
|
-
var require_base64 = __commonJS({
|
|
51
|
-
"../../node_modules/.pnpm/js-base64@3.7.6/node_modules/js-base64/base64.js"(exports, module) {
|
|
52
|
-
"use strict";
|
|
53
|
-
(function(global2, factory) {
|
|
54
|
-
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (
|
|
55
|
-
// cf. https://github.com/dankogai/js-base64/issues/119
|
|
56
|
-
function() {
|
|
57
|
-
var _Base64 = global2.Base64;
|
|
58
|
-
var gBase64 = factory();
|
|
59
|
-
gBase64.noConflict = function() {
|
|
60
|
-
global2.Base64 = _Base64;
|
|
61
|
-
return gBase64;
|
|
62
|
-
};
|
|
63
|
-
if (global2.Meteor) {
|
|
64
|
-
Base64 = gBase64;
|
|
65
|
-
}
|
|
66
|
-
global2.Base64 = gBase64;
|
|
67
|
-
}()
|
|
68
|
-
);
|
|
69
|
-
})(typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : exports, function() {
|
|
70
|
-
"use strict";
|
|
71
|
-
var version = "3.7.6";
|
|
72
|
-
var VERSION = version;
|
|
73
|
-
var _hasatob = typeof atob === "function";
|
|
74
|
-
var _hasbtoa = typeof btoa === "function";
|
|
75
|
-
var _hasBuffer = typeof Buffer === "function";
|
|
76
|
-
var _TD = typeof TextDecoder === "function" ? new TextDecoder() : void 0;
|
|
77
|
-
var _TE = typeof TextEncoder === "function" ? new TextEncoder() : void 0;
|
|
78
|
-
var b64ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
79
|
-
var b64chs = Array.prototype.slice.call(b64ch);
|
|
80
|
-
var b64tab = function(a) {
|
|
81
|
-
var tab = {};
|
|
82
|
-
a.forEach(function(c, i) {
|
|
83
|
-
return tab[c] = i;
|
|
84
|
-
});
|
|
85
|
-
return tab;
|
|
86
|
-
}(b64chs);
|
|
87
|
-
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
88
|
-
var _fromCC = String.fromCharCode.bind(String);
|
|
89
|
-
var _U8Afrom = typeof Uint8Array.from === "function" ? Uint8Array.from.bind(Uint8Array) : function(it) {
|
|
90
|
-
return new Uint8Array(Array.prototype.slice.call(it, 0));
|
|
91
|
-
};
|
|
92
|
-
var _mkUriSafe = function(src) {
|
|
93
|
-
return src.replace(/=/g, "").replace(/[+\/]/g, function(m0) {
|
|
94
|
-
return m0 == "+" ? "-" : "_";
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
var _tidyB64 = function(s) {
|
|
98
|
-
return s.replace(/[^A-Za-z0-9\+\/]/g, "");
|
|
99
|
-
};
|
|
100
|
-
var btoaPolyfill = function(bin) {
|
|
101
|
-
var u32, c0, c1, c2, asc = "";
|
|
102
|
-
var pad = bin.length % 3;
|
|
103
|
-
for (var i = 0; i < bin.length; ) {
|
|
104
|
-
if ((c0 = bin.charCodeAt(i++)) > 255 || (c1 = bin.charCodeAt(i++)) > 255 || (c2 = bin.charCodeAt(i++)) > 255)
|
|
105
|
-
throw new TypeError("invalid character found");
|
|
106
|
-
u32 = c0 << 16 | c1 << 8 | c2;
|
|
107
|
-
asc += b64chs[u32 >> 18 & 63] + b64chs[u32 >> 12 & 63] + b64chs[u32 >> 6 & 63] + b64chs[u32 & 63];
|
|
108
|
-
}
|
|
109
|
-
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
|
110
|
-
};
|
|
111
|
-
var _btoa = _hasbtoa ? function(bin) {
|
|
112
|
-
return btoa(bin);
|
|
113
|
-
} : _hasBuffer ? function(bin) {
|
|
114
|
-
return Buffer.from(bin, "binary").toString("base64");
|
|
115
|
-
} : btoaPolyfill;
|
|
116
|
-
var _fromUint8Array = _hasBuffer ? function(u8a) {
|
|
117
|
-
return Buffer.from(u8a).toString("base64");
|
|
118
|
-
} : function(u8a) {
|
|
119
|
-
var maxargs = 4096;
|
|
120
|
-
var strs = [];
|
|
121
|
-
for (var i = 0, l = u8a.length; i < l; i += maxargs) {
|
|
122
|
-
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
|
123
|
-
}
|
|
124
|
-
return _btoa(strs.join(""));
|
|
125
|
-
};
|
|
126
|
-
var fromUint8Array = function(u8a, urlsafe) {
|
|
127
|
-
if (urlsafe === void 0) {
|
|
128
|
-
urlsafe = false;
|
|
129
|
-
}
|
|
130
|
-
return urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
|
|
131
|
-
};
|
|
132
|
-
var cb_utob = function(c) {
|
|
133
|
-
if (c.length < 2) {
|
|
134
|
-
var cc = c.charCodeAt(0);
|
|
135
|
-
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);
|
|
136
|
-
} else {
|
|
137
|
-
var cc = 65536 + (c.charCodeAt(0) - 55296) * 1024 + (c.charCodeAt(1) - 56320);
|
|
138
|
-
return _fromCC(240 | cc >>> 18 & 7) + _fromCC(128 | cc >>> 12 & 63) + _fromCC(128 | cc >>> 6 & 63) + _fromCC(128 | cc & 63);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
|
142
|
-
var utob = function(u) {
|
|
143
|
-
return u.replace(re_utob, cb_utob);
|
|
144
|
-
};
|
|
145
|
-
var _encode = _hasBuffer ? function(s) {
|
|
146
|
-
return Buffer.from(s, "utf8").toString("base64");
|
|
147
|
-
} : _TE ? function(s) {
|
|
148
|
-
return _fromUint8Array(_TE.encode(s));
|
|
149
|
-
} : function(s) {
|
|
150
|
-
return _btoa(utob(s));
|
|
151
|
-
};
|
|
152
|
-
var encode = function(src, urlsafe) {
|
|
153
|
-
if (urlsafe === void 0) {
|
|
154
|
-
urlsafe = false;
|
|
155
|
-
}
|
|
156
|
-
return urlsafe ? _mkUriSafe(_encode(src)) : _encode(src);
|
|
157
|
-
};
|
|
158
|
-
var encodeURI = function(src) {
|
|
159
|
-
return encode(src, true);
|
|
160
|
-
};
|
|
161
|
-
var re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
|
162
|
-
var cb_btou = function(cccc) {
|
|
163
|
-
switch (cccc.length) {
|
|
164
|
-
case 4:
|
|
165
|
-
var cp = (7 & cccc.charCodeAt(0)) << 18 | (63 & cccc.charCodeAt(1)) << 12 | (63 & cccc.charCodeAt(2)) << 6 | 63 & cccc.charCodeAt(3), offset = cp - 65536;
|
|
166
|
-
return _fromCC((offset >>> 10) + 55296) + _fromCC((offset & 1023) + 56320);
|
|
167
|
-
case 3:
|
|
168
|
-
return _fromCC((15 & cccc.charCodeAt(0)) << 12 | (63 & cccc.charCodeAt(1)) << 6 | 63 & cccc.charCodeAt(2));
|
|
169
|
-
default:
|
|
170
|
-
return _fromCC((31 & cccc.charCodeAt(0)) << 6 | 63 & cccc.charCodeAt(1));
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
var btou = function(b) {
|
|
174
|
-
return b.replace(re_btou, cb_btou);
|
|
175
|
-
};
|
|
176
|
-
var atobPolyfill = function(asc) {
|
|
177
|
-
asc = asc.replace(/\s+/g, "");
|
|
178
|
-
if (!b64re.test(asc))
|
|
179
|
-
throw new TypeError("malformed base64.");
|
|
180
|
-
asc += "==".slice(2 - (asc.length & 3));
|
|
181
|
-
var u24, bin = "", r1, r2;
|
|
182
|
-
for (var i = 0; i < asc.length; ) {
|
|
183
|
-
u24 = b64tab[asc.charAt(i++)] << 18 | b64tab[asc.charAt(i++)] << 12 | (r1 = b64tab[asc.charAt(i++)]) << 6 | (r2 = b64tab[asc.charAt(i++)]);
|
|
184
|
-
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);
|
|
185
|
-
}
|
|
186
|
-
return bin;
|
|
187
|
-
};
|
|
188
|
-
var _atob = _hasatob ? function(asc) {
|
|
189
|
-
return atob(_tidyB64(asc));
|
|
190
|
-
} : _hasBuffer ? function(asc) {
|
|
191
|
-
return Buffer.from(asc, "base64").toString("binary");
|
|
192
|
-
} : atobPolyfill;
|
|
193
|
-
var _toUint8Array = _hasBuffer ? function(a) {
|
|
194
|
-
return _U8Afrom(Buffer.from(a, "base64"));
|
|
195
|
-
} : function(a) {
|
|
196
|
-
return _U8Afrom(_atob(a).split("").map(function(c) {
|
|
197
|
-
return c.charCodeAt(0);
|
|
198
|
-
}));
|
|
199
|
-
};
|
|
200
|
-
var toUint8Array = function(a) {
|
|
201
|
-
return _toUint8Array(_unURI(a));
|
|
202
|
-
};
|
|
203
|
-
var _decode = _hasBuffer ? function(a) {
|
|
204
|
-
return Buffer.from(a, "base64").toString("utf8");
|
|
205
|
-
} : _TD ? function(a) {
|
|
206
|
-
return _TD.decode(_toUint8Array(a));
|
|
207
|
-
} : function(a) {
|
|
208
|
-
return btou(_atob(a));
|
|
209
|
-
};
|
|
210
|
-
var _unURI = function(a) {
|
|
211
|
-
return _tidyB64(a.replace(/[-_]/g, function(m0) {
|
|
212
|
-
return m0 == "-" ? "+" : "/";
|
|
213
|
-
}));
|
|
214
|
-
};
|
|
215
|
-
var decode = function(src) {
|
|
216
|
-
return _decode(_unURI(src));
|
|
217
|
-
};
|
|
218
|
-
var isValid = function(src) {
|
|
219
|
-
if (typeof src !== "string")
|
|
220
|
-
return false;
|
|
221
|
-
var s = src.replace(/\s+/g, "").replace(/={0,2}$/, "");
|
|
222
|
-
return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
|
|
223
|
-
};
|
|
224
|
-
var _noEnum = function(v) {
|
|
225
|
-
return {
|
|
226
|
-
value: v,
|
|
227
|
-
enumerable: false,
|
|
228
|
-
writable: true,
|
|
229
|
-
configurable: true
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
var extendString = function() {
|
|
233
|
-
var _add = function(name, body) {
|
|
234
|
-
return Object.defineProperty(String.prototype, name, _noEnum(body));
|
|
235
|
-
};
|
|
236
|
-
_add("fromBase64", function() {
|
|
237
|
-
return decode(this);
|
|
238
|
-
});
|
|
239
|
-
_add("toBase64", function(urlsafe) {
|
|
240
|
-
return encode(this, urlsafe);
|
|
241
|
-
});
|
|
242
|
-
_add("toBase64URI", function() {
|
|
243
|
-
return encode(this, true);
|
|
244
|
-
});
|
|
245
|
-
_add("toBase64URL", function() {
|
|
246
|
-
return encode(this, true);
|
|
247
|
-
});
|
|
248
|
-
_add("toUint8Array", function() {
|
|
249
|
-
return toUint8Array(this);
|
|
250
|
-
});
|
|
251
|
-
};
|
|
252
|
-
var extendUint8Array = function() {
|
|
253
|
-
var _add = function(name, body) {
|
|
254
|
-
return Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
|
|
255
|
-
};
|
|
256
|
-
_add("toBase64", function(urlsafe) {
|
|
257
|
-
return fromUint8Array(this, urlsafe);
|
|
258
|
-
});
|
|
259
|
-
_add("toBase64URI", function() {
|
|
260
|
-
return fromUint8Array(this, true);
|
|
261
|
-
});
|
|
262
|
-
_add("toBase64URL", function() {
|
|
263
|
-
return fromUint8Array(this, true);
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
var extendBuiltins = function() {
|
|
267
|
-
extendString();
|
|
268
|
-
extendUint8Array();
|
|
269
|
-
};
|
|
270
|
-
var gBase64 = {
|
|
271
|
-
version,
|
|
272
|
-
VERSION,
|
|
273
|
-
atob: _atob,
|
|
274
|
-
atobPolyfill,
|
|
275
|
-
btoa: _btoa,
|
|
276
|
-
btoaPolyfill,
|
|
277
|
-
fromBase64: decode,
|
|
278
|
-
toBase64: encode,
|
|
279
|
-
encode,
|
|
280
|
-
encodeURI,
|
|
281
|
-
encodeURL: encodeURI,
|
|
282
|
-
utob,
|
|
283
|
-
btou,
|
|
284
|
-
decode,
|
|
285
|
-
isValid,
|
|
286
|
-
fromUint8Array,
|
|
287
|
-
toUint8Array,
|
|
288
|
-
extendString,
|
|
289
|
-
extendUint8Array,
|
|
290
|
-
extendBuiltins
|
|
291
|
-
};
|
|
292
|
-
gBase64.Base64 = {};
|
|
293
|
-
Object.keys(gBase64).forEach(function(k) {
|
|
294
|
-
return gBase64.Base64[k] = gBase64[k];
|
|
295
|
-
});
|
|
296
|
-
return gBase64;
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// ../utils/dist/index.js
|
|
302
|
-
var require_dist = __commonJS({
|
|
303
|
-
"../utils/dist/index.js"(exports, module) {
|
|
304
|
-
"use strict";
|
|
305
|
-
var __defProp2 = Object.defineProperty;
|
|
306
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
307
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
308
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
309
|
-
var __export = (target, all) => {
|
|
310
|
-
for (var name in all)
|
|
311
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
312
|
-
};
|
|
313
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
314
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
315
|
-
for (let key of __getOwnPropNames2(from))
|
|
316
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
317
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
318
|
-
}
|
|
319
|
-
return to;
|
|
320
|
-
};
|
|
321
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
322
|
-
var __async2 = (__this, __arguments, generator) => {
|
|
323
|
-
return new Promise((resolve, reject) => {
|
|
324
|
-
var fulfilled = (value) => {
|
|
325
|
-
try {
|
|
326
|
-
step(generator.next(value));
|
|
327
|
-
} catch (e) {
|
|
328
|
-
reject(e);
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
var rejected = (value) => {
|
|
332
|
-
try {
|
|
333
|
-
step(generator.throw(value));
|
|
334
|
-
} catch (e) {
|
|
335
|
-
reject(e);
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
339
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
340
|
-
});
|
|
341
|
-
};
|
|
342
|
-
var src_exports = {};
|
|
343
|
-
__export(src_exports, {
|
|
344
|
-
Disclosure: () => Disclosure,
|
|
345
|
-
SDJWTException: () => SDJWTException2,
|
|
346
|
-
base64urlDecode: () => base64urlDecode,
|
|
347
|
-
base64urlEncode: () => base64urlEncode,
|
|
348
|
-
uint8ArrayToBase64Url: () => uint8ArrayToBase64Url
|
|
349
|
-
});
|
|
350
|
-
module.exports = __toCommonJS(src_exports);
|
|
351
|
-
var import_js_base64 = require_base64();
|
|
352
|
-
var base64urlEncode = import_js_base64.Base64.encodeURI;
|
|
353
|
-
var base64urlDecode = import_js_base64.Base64.decode;
|
|
354
|
-
var uint8ArrayToBase64Url = (input) => import_js_base64.Base64.fromUint8Array(input, true);
|
|
355
|
-
var SDJWTException2 = class _SDJWTException extends Error {
|
|
356
|
-
constructor(message, details) {
|
|
357
|
-
super(message);
|
|
358
|
-
Object.setPrototypeOf(this, _SDJWTException.prototype);
|
|
359
|
-
this.name = "SDJWTException";
|
|
360
|
-
this.details = details;
|
|
361
|
-
}
|
|
362
|
-
getFullMessage() {
|
|
363
|
-
return `${this.name}: ${this.message} ${this.details ? `- ${JSON.stringify(this.details)}` : ""}`;
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
var Disclosure = class _Disclosure {
|
|
367
|
-
constructor(data, _meta) {
|
|
368
|
-
this._digest = _meta == null ? void 0 : _meta.digest;
|
|
369
|
-
this._encoded = _meta == null ? void 0 : _meta.encoded;
|
|
370
|
-
if (data.length === 2) {
|
|
371
|
-
this.salt = data[0];
|
|
372
|
-
this.value = data[1];
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
if (data.length === 3) {
|
|
376
|
-
this.salt = data[0];
|
|
377
|
-
this.key = data[1];
|
|
378
|
-
this.value = data[2];
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
throw new SDJWTException2("Invalid disclosure data");
|
|
382
|
-
}
|
|
383
|
-
// We need to digest of the original encoded data.
|
|
384
|
-
// After decode process, we use JSON.stringify to encode the data.
|
|
385
|
-
// This can be different from the original encoded data.
|
|
386
|
-
static fromEncode(s, hash) {
|
|
387
|
-
return __async2(this, null, function* () {
|
|
388
|
-
const { hasher, alg } = hash;
|
|
389
|
-
const digest = yield hasher(s, alg);
|
|
390
|
-
const digestStr = uint8ArrayToBase64Url(digest);
|
|
391
|
-
const item = JSON.parse(base64urlDecode(s));
|
|
392
|
-
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
static fromEncodeSync(s, hash) {
|
|
396
|
-
const { hasher, alg } = hash;
|
|
397
|
-
const digest = hasher(s, alg);
|
|
398
|
-
const digestStr = uint8ArrayToBase64Url(digest);
|
|
399
|
-
const item = JSON.parse(base64urlDecode(s));
|
|
400
|
-
return _Disclosure.fromArray(item, { digest: digestStr, encoded: s });
|
|
401
|
-
}
|
|
402
|
-
static fromArray(item, _meta) {
|
|
403
|
-
return new _Disclosure(item, _meta);
|
|
404
|
-
}
|
|
405
|
-
encode() {
|
|
406
|
-
if (!this._encoded) {
|
|
407
|
-
this._encoded = base64urlEncode(JSON.stringify(this.decode()));
|
|
408
|
-
}
|
|
409
|
-
return this._encoded;
|
|
410
|
-
}
|
|
411
|
-
decode() {
|
|
412
|
-
return this.key ? [this.salt, this.key, this.value] : [this.salt, this.value];
|
|
413
|
-
}
|
|
414
|
-
digest(hash) {
|
|
415
|
-
return __async2(this, null, function* () {
|
|
416
|
-
const { hasher, alg } = hash;
|
|
417
|
-
if (!this._digest) {
|
|
418
|
-
const hash2 = yield hasher(this.encode(), alg);
|
|
419
|
-
this._digest = uint8ArrayToBase64Url(hash2);
|
|
420
|
-
}
|
|
421
|
-
return this._digest;
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
digestSync(hash) {
|
|
425
|
-
const { hasher, alg } = hash;
|
|
426
|
-
if (!this._digest) {
|
|
427
|
-
const hash2 = hasher(this.encode(), alg);
|
|
428
|
-
this._digest = uint8ArrayToBase64Url(hash2);
|
|
429
|
-
}
|
|
430
|
-
return this._digest;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
// src/index.ts
|
|
437
|
-
var import_dist = __toESM(require_dist());
|
|
25
|
+
// src/sd-jwt-vc-instance.ts
|
|
438
26
|
import { Jwt, SDJwtInstance } from "@sd-jwt/core";
|
|
27
|
+
import { SDJWTException } from "@sd-jwt/utils";
|
|
439
28
|
import {
|
|
440
29
|
getListFromStatusListJWT
|
|
441
30
|
} from "@sd-jwt/jwt-status-list";
|
|
@@ -460,7 +49,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
|
|
|
460
49
|
const reservedNames = ["iss", "nbf", "exp", "cnf", "vct", "status"];
|
|
461
50
|
const reservedNamesInDisclosureFrame = disclosureFrame._sd.filter((key) => reservedNames.includes(key));
|
|
462
51
|
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
463
|
-
throw new
|
|
52
|
+
throw new SDJWTException("Cannot disclose protected field");
|
|
464
53
|
}
|
|
465
54
|
}
|
|
466
55
|
}
|
|
@@ -494,7 +83,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
|
|
|
494
83
|
statusValidator(status) {
|
|
495
84
|
return __async(this, null, function* () {
|
|
496
85
|
if (status !== 0)
|
|
497
|
-
throw new
|
|
86
|
+
throw new SDJWTException("Status is not valid");
|
|
498
87
|
return Promise.resolve();
|
|
499
88
|
});
|
|
500
89
|
}
|
|
@@ -516,7 +105,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
|
|
|
516
105
|
const slJWT = Jwt.fromEncode(statusListJWT);
|
|
517
106
|
yield slJWT.verify(this.userConfig.verifier);
|
|
518
107
|
if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < Date.now() / 1e3) {
|
|
519
|
-
throw new
|
|
108
|
+
throw new SDJWTException("Status list is expired");
|
|
520
109
|
}
|
|
521
110
|
const statusList = getListFromStatusListJWT(statusListJWT);
|
|
522
111
|
const status = statusList.getStatus(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/sd-jwt-vc",
|
|
3
|
-
"version": "0.7.1-next.
|
|
3
|
+
"version": "0.7.1-next.2+0329a6b",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
},
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@sd-jwt/core": "0.7.1-next.
|
|
43
|
-
"@sd-jwt/jwt-status-list": "0.7.1-next.
|
|
42
|
+
"@sd-jwt/core": "0.7.1-next.2+0329a6b",
|
|
43
|
+
"@sd-jwt/jwt-status-list": "0.7.1-next.2+0329a6b",
|
|
44
|
+
"@sd-jwt/utils": "0.7.1-next.2+0329a6b"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@sd-jwt/crypto-nodejs": "0.7.1-next.
|
|
47
|
-
"@sd-jwt/types": "0.7.1-next.
|
|
47
|
+
"@sd-jwt/crypto-nodejs": "0.7.1-next.2+0329a6b",
|
|
48
|
+
"@sd-jwt/types": "0.7.1-next.2+0329a6b",
|
|
48
49
|
"jose": "^5.2.2"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"esm"
|
|
64
65
|
]
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "0329a6b4e8ba11d2fd727c41606c17acbb68e3c5"
|
|
67
68
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,138 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { SDJWTVCConfig } from './sd-jwt-vc-config';
|
|
6
|
-
import {
|
|
7
|
-
type StatusListJWTHeaderParameters,
|
|
8
|
-
type StatusListJWTPayload,
|
|
9
|
-
getListFromStatusListJWT,
|
|
10
|
-
} from '@sd-jwt/jwt-status-list';
|
|
11
|
-
export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
12
|
-
/**
|
|
13
|
-
* The type of the SD-JWT-VC set in the header.typ field.
|
|
14
|
-
*/
|
|
15
|
-
protected type = 'vc+sd-jwt';
|
|
16
|
-
|
|
17
|
-
protected userConfig: SDJWTVCConfig = {};
|
|
18
|
-
|
|
19
|
-
constructor(userConfig?: SDJWTVCConfig) {
|
|
20
|
-
super(userConfig);
|
|
21
|
-
if (userConfig) {
|
|
22
|
-
this.userConfig = userConfig;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
28
|
-
* @param disclosureFrame
|
|
29
|
-
*/
|
|
30
|
-
protected validateReservedFields(
|
|
31
|
-
disclosureFrame: DisclosureFrame<SdJwtVcPayload>,
|
|
32
|
-
): void {
|
|
33
|
-
//validate disclosureFrame according to https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-03.html#section-3.2.2.2
|
|
34
|
-
if (
|
|
35
|
-
disclosureFrame?._sd &&
|
|
36
|
-
Array.isArray(disclosureFrame._sd) &&
|
|
37
|
-
disclosureFrame._sd.length > 0
|
|
38
|
-
) {
|
|
39
|
-
const reservedNames = ['iss', 'nbf', 'exp', 'cnf', 'vct', 'status'];
|
|
40
|
-
// check if there is any reserved names in the disclosureFrame._sd array
|
|
41
|
-
const reservedNamesInDisclosureFrame = (
|
|
42
|
-
disclosureFrame._sd as string[]
|
|
43
|
-
).filter((key) => reservedNames.includes(key));
|
|
44
|
-
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
45
|
-
throw new SDJWTException('Cannot disclose protected field');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Fetches the status list from the uri with a timeout of 10 seconds.
|
|
52
|
-
* @param uri The URI to fetch from.
|
|
53
|
-
* @returns A promise that resolves to a compact JWT.
|
|
54
|
-
*/
|
|
55
|
-
private async statusListFetcher(uri: string): Promise<string> {
|
|
56
|
-
const controller = new AbortController();
|
|
57
|
-
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const response = await fetch(uri, { signal: controller.signal });
|
|
61
|
-
if (!response.ok) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Error fetching status list: ${
|
|
64
|
-
response.status
|
|
65
|
-
} ${await response.text()}`,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return response.text();
|
|
70
|
-
} finally {
|
|
71
|
-
clearTimeout(timeoutId);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Validates the status, throws an error if the status is not 0.
|
|
77
|
-
* @param status
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
private async statusValidator(status: number): Promise<void> {
|
|
81
|
-
if (status !== 0) throw new SDJWTException('Status is not valid');
|
|
82
|
-
return Promise.resolve();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Verifies the SD-JWT-VC.
|
|
87
|
-
*/
|
|
88
|
-
async verify(
|
|
89
|
-
encodedSDJwt: string,
|
|
90
|
-
requiredClaimKeys?: string[],
|
|
91
|
-
requireKeyBindings?: boolean,
|
|
92
|
-
) {
|
|
93
|
-
// Call the parent class's verify method
|
|
94
|
-
const result = await super
|
|
95
|
-
.verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings)
|
|
96
|
-
.then((res) => {
|
|
97
|
-
return { payload: res.payload as SdJwtVcPayload, header: res.header };
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (result.payload.status) {
|
|
101
|
-
//checks if a status field is present in the payload based on https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-02.html
|
|
102
|
-
if (result.payload.status.status_list) {
|
|
103
|
-
// fetch the status list from the uri
|
|
104
|
-
const fetcher =
|
|
105
|
-
this.userConfig.statusListFetcher ?? this.statusListFetcher;
|
|
106
|
-
// fetch the status list from the uri
|
|
107
|
-
const statusListJWT = await fetcher(
|
|
108
|
-
result.payload.status.status_list.uri,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const slJWT = Jwt.fromEncode<
|
|
112
|
-
StatusListJWTHeaderParameters,
|
|
113
|
-
StatusListJWTPayload
|
|
114
|
-
>(statusListJWT);
|
|
115
|
-
// check if the status list has a valid signature. The presence of the verifier is checked in the parent class.
|
|
116
|
-
await slJWT.verify(this.userConfig.verifier as Verifier);
|
|
117
|
-
|
|
118
|
-
//check if the status list is expired
|
|
119
|
-
if (slJWT.payload?.exp && slJWT.payload.exp < Date.now() / 1000) {
|
|
120
|
-
throw new SDJWTException('Status list is expired');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// get the status list from the status list JWT
|
|
124
|
-
const statusList = getListFromStatusListJWT(statusListJWT);
|
|
125
|
-
const status = statusList.getStatus(
|
|
126
|
-
result.payload.status.status_list.idx,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// validate the status
|
|
130
|
-
const statusValidator =
|
|
131
|
-
this.userConfig.statusValidator ?? this.statusValidator;
|
|
132
|
-
await statusValidator(status);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
1
|
+
export * from './sd-jwt-vc-config';
|
|
2
|
+
export * from './sd-jwt-vc-instance';
|
|
3
|
+
export * from './sd-jwt-vc-payload';
|
|
4
|
+
export * from './sd-jwt-vc-status-reference';
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Jwt, SDJwtInstance } from '@sd-jwt/core';
|
|
2
|
+
import type { DisclosureFrame, Verifier } from '@sd-jwt/types';
|
|
3
|
+
import { SDJWTException } from '@sd-jwt/utils';
|
|
4
|
+
import type { SdJwtVcPayload } from './sd-jwt-vc-payload';
|
|
5
|
+
import type { SDJWTVCConfig } from './sd-jwt-vc-config';
|
|
6
|
+
import {
|
|
7
|
+
type StatusListJWTPayload,
|
|
8
|
+
getListFromStatusListJWT,
|
|
9
|
+
} from '@sd-jwt/jwt-status-list';
|
|
10
|
+
import type { StatusListJWTHeaderParameters } from '@sd-jwt/jwt-status-list';
|
|
11
|
+
export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
12
|
+
/**
|
|
13
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
14
|
+
*/
|
|
15
|
+
protected type = 'vc+sd-jwt';
|
|
16
|
+
|
|
17
|
+
protected userConfig: SDJWTVCConfig = {};
|
|
18
|
+
|
|
19
|
+
constructor(userConfig?: SDJWTVCConfig) {
|
|
20
|
+
super(userConfig);
|
|
21
|
+
if (userConfig) {
|
|
22
|
+
this.userConfig = userConfig;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
28
|
+
* @param disclosureFrame
|
|
29
|
+
*/
|
|
30
|
+
protected validateReservedFields(
|
|
31
|
+
disclosureFrame: DisclosureFrame<SdJwtVcPayload>,
|
|
32
|
+
): void {
|
|
33
|
+
//validate disclosureFrame according to https://www.ietf.org/archive/id/draft-ietf-oauth-sd-jwt-vc-03.html#section-3.2.2.2
|
|
34
|
+
if (
|
|
35
|
+
disclosureFrame?._sd &&
|
|
36
|
+
Array.isArray(disclosureFrame._sd) &&
|
|
37
|
+
disclosureFrame._sd.length > 0
|
|
38
|
+
) {
|
|
39
|
+
const reservedNames = ['iss', 'nbf', 'exp', 'cnf', 'vct', 'status'];
|
|
40
|
+
// check if there is any reserved names in the disclosureFrame._sd array
|
|
41
|
+
const reservedNamesInDisclosureFrame = (
|
|
42
|
+
disclosureFrame._sd as string[]
|
|
43
|
+
).filter((key) => reservedNames.includes(key));
|
|
44
|
+
if (reservedNamesInDisclosureFrame.length > 0) {
|
|
45
|
+
throw new SDJWTException('Cannot disclose protected field');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the status list from the uri with a timeout of 10 seconds.
|
|
52
|
+
* @param uri The URI to fetch from.
|
|
53
|
+
* @returns A promise that resolves to a compact JWT.
|
|
54
|
+
*/
|
|
55
|
+
private async statusListFetcher(uri: string): Promise<string> {
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(uri, { signal: controller.signal });
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Error fetching status list: ${
|
|
64
|
+
response.status
|
|
65
|
+
} ${await response.text()}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return response.text();
|
|
70
|
+
} finally {
|
|
71
|
+
clearTimeout(timeoutId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates the status, throws an error if the status is not 0.
|
|
77
|
+
* @param status
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
private async statusValidator(status: number): Promise<void> {
|
|
81
|
+
if (status !== 0) throw new SDJWTException('Status is not valid');
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Verifies the SD-JWT-VC.
|
|
87
|
+
*/
|
|
88
|
+
async verify(
|
|
89
|
+
encodedSDJwt: string,
|
|
90
|
+
requiredClaimKeys?: string[],
|
|
91
|
+
requireKeyBindings?: boolean,
|
|
92
|
+
) {
|
|
93
|
+
// Call the parent class's verify method
|
|
94
|
+
const result = await super
|
|
95
|
+
.verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings)
|
|
96
|
+
.then((res) => {
|
|
97
|
+
return { payload: res.payload as SdJwtVcPayload, header: res.header };
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (result.payload.status) {
|
|
101
|
+
//checks if a status field is present in the payload based on https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-02.html
|
|
102
|
+
if (result.payload.status.status_list) {
|
|
103
|
+
// fetch the status list from the uri
|
|
104
|
+
const fetcher =
|
|
105
|
+
this.userConfig.statusListFetcher ?? this.statusListFetcher;
|
|
106
|
+
// fetch the status list from the uri
|
|
107
|
+
const statusListJWT = await fetcher(
|
|
108
|
+
result.payload.status.status_list.uri,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const slJWT = Jwt.fromEncode<
|
|
112
|
+
StatusListJWTHeaderParameters,
|
|
113
|
+
StatusListJWTPayload
|
|
114
|
+
>(statusListJWT);
|
|
115
|
+
// check if the status list has a valid signature. The presence of the verifier is checked in the parent class.
|
|
116
|
+
await slJWT.verify(this.userConfig.verifier as Verifier);
|
|
117
|
+
|
|
118
|
+
//check if the status list is expired
|
|
119
|
+
if (
|
|
120
|
+
slJWT.payload?.exp &&
|
|
121
|
+
(slJWT.payload.exp as number) < Date.now() / 1000
|
|
122
|
+
) {
|
|
123
|
+
throw new SDJWTException('Status list is expired');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// get the status list from the status list JWT
|
|
127
|
+
const statusList = getListFromStatusListJWT(statusListJWT);
|
|
128
|
+
const status = statusList.getStatus(
|
|
129
|
+
result.payload.status.status_list.idx,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// validate the status
|
|
133
|
+
const statusValidator =
|
|
134
|
+
this.userConfig.statusValidator ?? this.statusValidator;
|
|
135
|
+
await statusValidator(status);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
}
|