@freedomofpress/sigstore-browser 0.1.5 → 0.1.6
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-CRFtwdjM.js +4528 -0
- package/dist/index-CRFtwdjM.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +266 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +371 -0
- package/dist/policy.js.map +1 -0
- package/dist/sigstore.min.js +6 -0
- package/dist/sigstore.min.js.map +1 -0
- package/dist/trust/tuf.d.ts.map +1 -1
- package/dist/trust/tuf.js +3 -1
- package/dist/trust/tuf.js.map +1 -1
- package/dist/tuf-D48cBq5i.js +377 -0
- package/dist/tuf-D48cBq5i.js.map +1 -0
- package/dist/tuf-root-D8m0y2I4.js +5 -0
- package/dist/tuf-root-D8m0y2I4.js.map +1 -0
- package/dist/x509/cert.d.ts +42 -1
- package/dist/x509/cert.d.ts.map +1 -1
- package/dist/x509/cert.js +103 -4
- package/dist/x509/cert.js.map +1 -1
- package/dist/x509/ext.d.ts +66 -2
- package/dist/x509/ext.d.ts.map +1 -1
- package/dist/x509/ext.js +133 -8
- package/dist/x509/ext.js.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +78 -2
- package/src/policy.ts +476 -0
- package/src/trust/tuf.ts +3 -1
- package/src/x509/cert.ts +141 -3
- package/src/x509/ext.ts +154 -8
- package/vite.config.ts +12 -3
|
@@ -0,0 +1,4528 @@
|
|
|
1
|
+
class Lt extends Error {
|
|
2
|
+
}
|
|
3
|
+
class $t extends Error {
|
|
4
|
+
}
|
|
5
|
+
const It = {
|
|
6
|
+
BOOLEAN: 1,
|
|
7
|
+
INTEGER: 2,
|
|
8
|
+
BIT_STRING: 3,
|
|
9
|
+
OCTET_STRING: 4,
|
|
10
|
+
OBJECT_IDENTIFIER: 6,
|
|
11
|
+
UTC_TIME: 23,
|
|
12
|
+
GENERALIZED_TIME: 24
|
|
13
|
+
}, we = {
|
|
14
|
+
UNIVERSAL: 0,
|
|
15
|
+
CONTEXT_SPECIFIC: 2
|
|
16
|
+
};
|
|
17
|
+
class Es {
|
|
18
|
+
constructor(t) {
|
|
19
|
+
if (this.number = t & 31, this.constructed = (t & 32) === 32, this.class = t >> 6, this.number === 31)
|
|
20
|
+
throw new Lt("long form tags not supported");
|
|
21
|
+
if (this.class === we.UNIVERSAL && this.number === 0)
|
|
22
|
+
throw new Lt("unsupported tag 0x00");
|
|
23
|
+
}
|
|
24
|
+
isUniversal() {
|
|
25
|
+
return this.class === we.UNIVERSAL;
|
|
26
|
+
}
|
|
27
|
+
isContextSpecific(t) {
|
|
28
|
+
const s = this.class === we.CONTEXT_SPECIFIC;
|
|
29
|
+
return t !== void 0 ? s && this.number === t : s;
|
|
30
|
+
}
|
|
31
|
+
isBoolean() {
|
|
32
|
+
return this.isUniversal() && this.number === It.BOOLEAN;
|
|
33
|
+
}
|
|
34
|
+
isInteger() {
|
|
35
|
+
return this.isUniversal() && this.number === It.INTEGER;
|
|
36
|
+
}
|
|
37
|
+
isBitString() {
|
|
38
|
+
return this.isUniversal() && this.number === It.BIT_STRING;
|
|
39
|
+
}
|
|
40
|
+
isOctetString() {
|
|
41
|
+
return this.isUniversal() && this.number === It.OCTET_STRING;
|
|
42
|
+
}
|
|
43
|
+
isOID() {
|
|
44
|
+
return this.isUniversal() && this.number === It.OBJECT_IDENTIFIER;
|
|
45
|
+
}
|
|
46
|
+
isUTCTime() {
|
|
47
|
+
return this.isUniversal() && this.number === It.UTC_TIME;
|
|
48
|
+
}
|
|
49
|
+
isGeneralizedTime() {
|
|
50
|
+
return this.isUniversal() && this.number === It.GENERALIZED_TIME;
|
|
51
|
+
}
|
|
52
|
+
toDER() {
|
|
53
|
+
return this.number | (this.constructed ? 32 : 0) | this.class << 6;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function xs(e) {
|
|
57
|
+
const t = e.getUint8();
|
|
58
|
+
if ((t & 128) === 0)
|
|
59
|
+
return t;
|
|
60
|
+
const s = t & 127;
|
|
61
|
+
if (s > 6)
|
|
62
|
+
throw new Lt("length exceeds 6 byte limit");
|
|
63
|
+
let n = 0;
|
|
64
|
+
for (let r = 0; r < s; r++)
|
|
65
|
+
n = n * 256 + e.getUint8();
|
|
66
|
+
if (n === 0)
|
|
67
|
+
throw new Lt("indefinite length encoding not supported");
|
|
68
|
+
return n;
|
|
69
|
+
}
|
|
70
|
+
function Ss(e) {
|
|
71
|
+
if (e < 128)
|
|
72
|
+
return new Uint8Array([e]);
|
|
73
|
+
let t = BigInt(e);
|
|
74
|
+
const s = [];
|
|
75
|
+
for (; t > 0n; )
|
|
76
|
+
s.unshift(Number(t & 255n)), t = t >> 8n;
|
|
77
|
+
return new Uint8Array([128 | s.length, ...s]);
|
|
78
|
+
}
|
|
79
|
+
function S(e) {
|
|
80
|
+
const t = atob(e), s = t.length, n = new Uint8Array(s);
|
|
81
|
+
for (let r = 0; r < s; r++)
|
|
82
|
+
n[r] = t.charCodeAt(r);
|
|
83
|
+
return n;
|
|
84
|
+
}
|
|
85
|
+
function qe(e) {
|
|
86
|
+
let t = e.replace(/-/g, "+").replace(/_/g, "/");
|
|
87
|
+
for (; t.length % 4 !== 0; )
|
|
88
|
+
t += "=";
|
|
89
|
+
return S(t);
|
|
90
|
+
}
|
|
91
|
+
function Me(e) {
|
|
92
|
+
let t = "";
|
|
93
|
+
for (let s = 0; s < e.length; s++)
|
|
94
|
+
t += String.fromCharCode(e[s]);
|
|
95
|
+
return btoa(t);
|
|
96
|
+
}
|
|
97
|
+
function Kt(e) {
|
|
98
|
+
if (e.length % 2 !== 0)
|
|
99
|
+
throw new Error("Hex string must have an even length");
|
|
100
|
+
const t = e.length / 2, s = new Uint8Array(t);
|
|
101
|
+
for (let n = 0; n < t; n++)
|
|
102
|
+
s[n] = parseInt(e.slice(n * 2, n * 2 + 2), 16);
|
|
103
|
+
return s;
|
|
104
|
+
}
|
|
105
|
+
function ht(e) {
|
|
106
|
+
let t = "";
|
|
107
|
+
for (let s = 0; s < e.length; s++) {
|
|
108
|
+
let n = e[s].toString(16);
|
|
109
|
+
n.length === 1 && (n = "0" + n), t += n;
|
|
110
|
+
}
|
|
111
|
+
return t;
|
|
112
|
+
}
|
|
113
|
+
function un(e) {
|
|
114
|
+
return new TextEncoder().encode(e);
|
|
115
|
+
}
|
|
116
|
+
function Q(e) {
|
|
117
|
+
return new TextDecoder("utf-8").decode(e);
|
|
118
|
+
}
|
|
119
|
+
function Is(e, t) {
|
|
120
|
+
t === void 0 && (t = 0);
|
|
121
|
+
const s = ht(e.slice(t, t + 8));
|
|
122
|
+
return BigInt(`0x${s}`);
|
|
123
|
+
}
|
|
124
|
+
function ln(e) {
|
|
125
|
+
return Q(S(e));
|
|
126
|
+
}
|
|
127
|
+
function H(e, t) {
|
|
128
|
+
if (e.byteLength !== t.byteLength)
|
|
129
|
+
return !1;
|
|
130
|
+
let s = 0;
|
|
131
|
+
for (let n = 0; n < e.byteLength; n++)
|
|
132
|
+
s |= e[n] ^ t[n];
|
|
133
|
+
return s === 0;
|
|
134
|
+
}
|
|
135
|
+
const vs = /^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\.\d{3})?Z$/, As = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\.\d{3})?Z$/;
|
|
136
|
+
function Os(e) {
|
|
137
|
+
let t = 0;
|
|
138
|
+
const s = e.length;
|
|
139
|
+
let n = e[t];
|
|
140
|
+
const r = n > 127, i = r ? 255 : 0;
|
|
141
|
+
for (; n == i && ++t < s; )
|
|
142
|
+
n = e[t];
|
|
143
|
+
if (s - t === 0)
|
|
144
|
+
return BigInt(r ? -1 : 0);
|
|
145
|
+
n = r ? n - 256 : n;
|
|
146
|
+
let a = BigInt(n);
|
|
147
|
+
for (let c = t + 1; c < s; ++c)
|
|
148
|
+
a = a * BigInt(256) + BigInt(e[c]);
|
|
149
|
+
return a;
|
|
150
|
+
}
|
|
151
|
+
function Bs(e) {
|
|
152
|
+
return Q(e);
|
|
153
|
+
}
|
|
154
|
+
function Ze(e, t) {
|
|
155
|
+
const s = Bs(e), n = t ? vs.exec(s) : As.exec(s);
|
|
156
|
+
if (!n)
|
|
157
|
+
throw new Error("invalid time");
|
|
158
|
+
if (t) {
|
|
159
|
+
let r = Number(n[1]);
|
|
160
|
+
r += r >= 50 ? 1900 : 2e3, n[1] = r.toString();
|
|
161
|
+
}
|
|
162
|
+
return /* @__PURE__ */ new Date(`${n[1]}-${n[2]}-${n[3]}T${n[4]}:${n[5]}:${n[6]}Z`);
|
|
163
|
+
}
|
|
164
|
+
function Rs(e) {
|
|
165
|
+
let t = 0;
|
|
166
|
+
const s = e.length;
|
|
167
|
+
let n = e[t++];
|
|
168
|
+
const r = Math.floor(n / 40), i = n % 40;
|
|
169
|
+
let o = `${r}.${i}`, a = 0;
|
|
170
|
+
for (; t < s; ++t)
|
|
171
|
+
n = e[t], a = (a << 7) + (n & 127), (n & 128) === 0 && (o += `.${a}`, a = 0);
|
|
172
|
+
return o;
|
|
173
|
+
}
|
|
174
|
+
function Cs(e) {
|
|
175
|
+
return e[0] !== 0;
|
|
176
|
+
}
|
|
177
|
+
function Ts(e) {
|
|
178
|
+
const t = e[0], s = 1, n = e.length, r = [];
|
|
179
|
+
for (let i = s; i < n; ++i) {
|
|
180
|
+
const o = e[i], a = i === n - 1 ? t : 0;
|
|
181
|
+
for (let c = 7; c >= a; --c)
|
|
182
|
+
r.push(o >> c & 1);
|
|
183
|
+
}
|
|
184
|
+
return r;
|
|
185
|
+
}
|
|
186
|
+
class Ds extends Error {
|
|
187
|
+
}
|
|
188
|
+
class rt {
|
|
189
|
+
constructor(t) {
|
|
190
|
+
this.start = 0, this.view = t ?? new Uint8Array(0);
|
|
191
|
+
}
|
|
192
|
+
get buffer() {
|
|
193
|
+
return this.view.subarray(0, this.start);
|
|
194
|
+
}
|
|
195
|
+
get length() {
|
|
196
|
+
return this.view.byteLength;
|
|
197
|
+
}
|
|
198
|
+
get position() {
|
|
199
|
+
return this.start;
|
|
200
|
+
}
|
|
201
|
+
seek(t) {
|
|
202
|
+
this.start = t;
|
|
203
|
+
}
|
|
204
|
+
slice(t, s) {
|
|
205
|
+
const n = t + s;
|
|
206
|
+
if (n > this.length)
|
|
207
|
+
throw new Ds("request past end of buffer");
|
|
208
|
+
return this.view.subarray(t, n);
|
|
209
|
+
}
|
|
210
|
+
appendChar(t) {
|
|
211
|
+
this.ensureCapacity(1), this.view[this.start] = t, this.start += 1;
|
|
212
|
+
}
|
|
213
|
+
appendUint16(t) {
|
|
214
|
+
this.ensureCapacity(2);
|
|
215
|
+
const s = new Uint16Array([t]), n = new Uint8Array(s.buffer);
|
|
216
|
+
this.view[this.start] = n[1], this.view[this.start + 1] = n[0], this.start += 2;
|
|
217
|
+
}
|
|
218
|
+
appendUint24(t) {
|
|
219
|
+
this.ensureCapacity(3);
|
|
220
|
+
const s = new Uint32Array([t]), n = new Uint8Array(s.buffer);
|
|
221
|
+
this.view[this.start] = n[2], this.view[this.start + 1] = n[1], this.view[this.start + 2] = n[0], this.start += 3;
|
|
222
|
+
}
|
|
223
|
+
appendView(t) {
|
|
224
|
+
this.ensureCapacity(t.length), this.view.set(t, this.start), this.start += t.length;
|
|
225
|
+
}
|
|
226
|
+
getBlock(t) {
|
|
227
|
+
if (t <= 0)
|
|
228
|
+
return new Uint8Array(0);
|
|
229
|
+
if (this.start + t > this.view.length)
|
|
230
|
+
throw new Error("request past end of buffer");
|
|
231
|
+
const s = this.view.subarray(this.start, this.start + t);
|
|
232
|
+
return this.start += t, s;
|
|
233
|
+
}
|
|
234
|
+
getUint8() {
|
|
235
|
+
return this.getBlock(1)[0];
|
|
236
|
+
}
|
|
237
|
+
getUint16() {
|
|
238
|
+
const t = this.getBlock(2);
|
|
239
|
+
return t[0] << 8 | t[1];
|
|
240
|
+
}
|
|
241
|
+
ensureCapacity(t) {
|
|
242
|
+
if (this.start + t > this.view.byteLength) {
|
|
243
|
+
const s = rt.BLOCK_SIZE + (t > rt.BLOCK_SIZE ? t : 0);
|
|
244
|
+
this.realloc(this.view.byteLength + s);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
realloc(t) {
|
|
248
|
+
const s = new Uint8Array(t);
|
|
249
|
+
s.set(this.view), this.view = s;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
rt.BLOCK_SIZE = 1024;
|
|
253
|
+
class Mt {
|
|
254
|
+
constructor(t, s, n) {
|
|
255
|
+
this.tag = t, this.value = s, this.subs = n;
|
|
256
|
+
}
|
|
257
|
+
// Constructs an ASN.1 object from a Buffer of DER-encoded bytes.
|
|
258
|
+
static parseBuffer(t) {
|
|
259
|
+
return hn(new rt(t));
|
|
260
|
+
}
|
|
261
|
+
toDER() {
|
|
262
|
+
const t = new rt();
|
|
263
|
+
if (this.subs.length > 0)
|
|
264
|
+
for (const r of this.subs)
|
|
265
|
+
t.appendView(r.toDER());
|
|
266
|
+
else
|
|
267
|
+
t.appendView(this.value);
|
|
268
|
+
const s = t.buffer, n = new rt();
|
|
269
|
+
return n.appendChar(this.tag.toDER()), n.appendView(Ss(s.length)), n.appendView(s), n.buffer;
|
|
270
|
+
}
|
|
271
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
272
|
+
// Convenience methods for parsing ASN.1 primitives into JS types
|
|
273
|
+
// Returns the ASN.1 object's value as a boolean. Throws an error if the
|
|
274
|
+
// object is not a boolean.
|
|
275
|
+
toBoolean() {
|
|
276
|
+
if (!this.tag.isBoolean())
|
|
277
|
+
throw new $t("not a boolean");
|
|
278
|
+
return Cs(this.value);
|
|
279
|
+
}
|
|
280
|
+
// Returns the ASN.1 object's value as a BigInt. Throws an error if the
|
|
281
|
+
// object is not an integer.
|
|
282
|
+
toInteger() {
|
|
283
|
+
if (!this.tag.isInteger())
|
|
284
|
+
throw new $t("not an integer");
|
|
285
|
+
return Os(this.value);
|
|
286
|
+
}
|
|
287
|
+
// Returns the ASN.1 object's value as an OID string. Throws an error if the
|
|
288
|
+
// object is not an OID.
|
|
289
|
+
toOID() {
|
|
290
|
+
if (!this.tag.isOID())
|
|
291
|
+
throw new $t("not an OID");
|
|
292
|
+
return Rs(this.value);
|
|
293
|
+
}
|
|
294
|
+
// Returns the ASN.1 object's value as a Date. Throws an error if the object
|
|
295
|
+
// is not either a UTCTime or a GeneralizedTime.
|
|
296
|
+
toDate() {
|
|
297
|
+
switch (!0) {
|
|
298
|
+
case this.tag.isUTCTime():
|
|
299
|
+
return Ze(this.value, !0);
|
|
300
|
+
case this.tag.isGeneralizedTime():
|
|
301
|
+
return Ze(this.value, !1);
|
|
302
|
+
default:
|
|
303
|
+
throw new $t("not a date");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Returns the ASN.1 object's value as a number[] where each number is the
|
|
307
|
+
// value of a bit in the bit string. Throws an error if the object is not a
|
|
308
|
+
// bit string.
|
|
309
|
+
toBitString() {
|
|
310
|
+
if (!this.tag.isBitString())
|
|
311
|
+
throw new $t("not a bit string");
|
|
312
|
+
return Ts(this.value);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function hn(e) {
|
|
316
|
+
const t = new Es(e.getUint8()), s = xs(e), n = e.slice(e.position, s), r = e.position;
|
|
317
|
+
let i = [];
|
|
318
|
+
if (t.constructed)
|
|
319
|
+
i = We(e, s);
|
|
320
|
+
else if (t.isOctetString())
|
|
321
|
+
try {
|
|
322
|
+
i = We(e, s);
|
|
323
|
+
} catch {
|
|
324
|
+
}
|
|
325
|
+
return i.length === 0 && e.seek(r + s), new Mt(t, n, i);
|
|
326
|
+
}
|
|
327
|
+
function We(e, t) {
|
|
328
|
+
const s = e.position + t;
|
|
329
|
+
if (s > e.length)
|
|
330
|
+
throw new Lt("invalid length");
|
|
331
|
+
const n = [];
|
|
332
|
+
for (; e.position < s; )
|
|
333
|
+
n.push(hn(e));
|
|
334
|
+
if (e.position !== s)
|
|
335
|
+
throw new Lt("invalid length");
|
|
336
|
+
return n;
|
|
337
|
+
}
|
|
338
|
+
const Us = /-----BEGIN (.*)-----/, _s = /-----END (.*)-----/;
|
|
339
|
+
function dn(e) {
|
|
340
|
+
let t = "";
|
|
341
|
+
return e.split(`
|
|
342
|
+
`).forEach((s) => {
|
|
343
|
+
s.match(Us) || s.match(_s) || (t += s);
|
|
344
|
+
}), S(t);
|
|
345
|
+
}
|
|
346
|
+
const Ye = ",", Ns = ":", Hs = "[", Vs = "]", js = "{", ks = "}";
|
|
347
|
+
function ze(e) {
|
|
348
|
+
return '"' + e.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
|
349
|
+
}
|
|
350
|
+
function Oe(e) {
|
|
351
|
+
const t = [];
|
|
352
|
+
if (typeof e == "string")
|
|
353
|
+
t.push(ze(e));
|
|
354
|
+
else if (typeof e == "boolean")
|
|
355
|
+
t.push(JSON.stringify(e));
|
|
356
|
+
else if (Number.isInteger(e))
|
|
357
|
+
t.push(JSON.stringify(e));
|
|
358
|
+
else if (e === null)
|
|
359
|
+
t.push(JSON.stringify(e));
|
|
360
|
+
else if (Array.isArray(e)) {
|
|
361
|
+
t.push(Hs);
|
|
362
|
+
let s = !0;
|
|
363
|
+
e.forEach((n) => {
|
|
364
|
+
s || t.push(Ye), s = !1, t.push(Oe(n));
|
|
365
|
+
}), t.push(Vs);
|
|
366
|
+
} else if (typeof e == "object") {
|
|
367
|
+
t.push(js);
|
|
368
|
+
let s = !0;
|
|
369
|
+
Object.keys(e).sort().forEach((n) => {
|
|
370
|
+
s || t.push(Ye), s = !1, t.push(ze(n)), t.push(Ns), t.push(Oe(e[n]));
|
|
371
|
+
}), t.push(ks);
|
|
372
|
+
} else
|
|
373
|
+
throw new TypeError("cannot encode " + e);
|
|
374
|
+
return t.join("");
|
|
375
|
+
}
|
|
376
|
+
var P;
|
|
377
|
+
(function(e) {
|
|
378
|
+
e.Ecdsa = "ECDSA", e.Ed25519 = "Ed25519", e.RSA = "RSA";
|
|
379
|
+
})(P || (P = {}));
|
|
380
|
+
var it;
|
|
381
|
+
(function(e) {
|
|
382
|
+
e.P256 = "P-256", e.P384 = "P-384", e.P521 = "P-521";
|
|
383
|
+
})(it || (it = {}));
|
|
384
|
+
var U;
|
|
385
|
+
(function(e) {
|
|
386
|
+
e.SHA256 = "SHA-256", e.SHA384 = "SHA-384", e.SHA512 = "SHA-512";
|
|
387
|
+
})(U || (U = {}));
|
|
388
|
+
var Bt;
|
|
389
|
+
(function(e) {
|
|
390
|
+
e.PKCS1v15 = "RSASSA-PKCS1-v1_5", e.PSS = "RSA-PSS";
|
|
391
|
+
})(Bt || (Bt = {}));
|
|
392
|
+
var oe;
|
|
393
|
+
(function(e) {
|
|
394
|
+
e.PKCS1 = "PKCS1", e.RSAPKCS1 = "RSAPKCS1";
|
|
395
|
+
})(oe || (oe = {}));
|
|
396
|
+
const _t = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
397
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
398
|
+
function de(e) {
|
|
399
|
+
return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
|
|
400
|
+
}
|
|
401
|
+
function Be(e) {
|
|
402
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
403
|
+
throw new Error("positive integer expected, got " + e);
|
|
404
|
+
}
|
|
405
|
+
function Ct(e, ...t) {
|
|
406
|
+
if (!de(e))
|
|
407
|
+
throw new Error("Uint8Array expected");
|
|
408
|
+
if (t.length > 0 && !t.includes(e.length))
|
|
409
|
+
throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
|
|
410
|
+
}
|
|
411
|
+
function gn(e) {
|
|
412
|
+
if (typeof e != "function" || typeof e.create != "function")
|
|
413
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
414
|
+
Be(e.outputLen), Be(e.blockLen);
|
|
415
|
+
}
|
|
416
|
+
function ae(e, t = !0) {
|
|
417
|
+
if (e.destroyed)
|
|
418
|
+
throw new Error("Hash instance has been destroyed");
|
|
419
|
+
if (t && e.finished)
|
|
420
|
+
throw new Error("Hash#digest() has already been called");
|
|
421
|
+
}
|
|
422
|
+
function Ls(e, t) {
|
|
423
|
+
Ct(e);
|
|
424
|
+
const s = t.outputLen;
|
|
425
|
+
if (e.length < s)
|
|
426
|
+
throw new Error("digestInto() expects output buffer of length at least " + s);
|
|
427
|
+
}
|
|
428
|
+
function Pt(...e) {
|
|
429
|
+
for (let t = 0; t < e.length; t++)
|
|
430
|
+
e[t].fill(0);
|
|
431
|
+
}
|
|
432
|
+
function be(e) {
|
|
433
|
+
return new DataView(e.buffer, e.byteOffset, e.byteLength);
|
|
434
|
+
}
|
|
435
|
+
function at(e, t) {
|
|
436
|
+
return e << 32 - t | e >>> t;
|
|
437
|
+
}
|
|
438
|
+
const wn = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Ks = /* @__PURE__ */ Array.from({ length: 256 }, (e, t) => t.toString(16).padStart(2, "0"));
|
|
439
|
+
function jt(e) {
|
|
440
|
+
if (Ct(e), wn)
|
|
441
|
+
return e.toHex();
|
|
442
|
+
let t = "";
|
|
443
|
+
for (let s = 0; s < e.length; s++)
|
|
444
|
+
t += Ks[e[s]];
|
|
445
|
+
return t;
|
|
446
|
+
}
|
|
447
|
+
const ut = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
448
|
+
function Je(e) {
|
|
449
|
+
if (e >= ut._0 && e <= ut._9)
|
|
450
|
+
return e - ut._0;
|
|
451
|
+
if (e >= ut.A && e <= ut.F)
|
|
452
|
+
return e - (ut.A - 10);
|
|
453
|
+
if (e >= ut.a && e <= ut.f)
|
|
454
|
+
return e - (ut.a - 10);
|
|
455
|
+
}
|
|
456
|
+
function ce(e) {
|
|
457
|
+
if (typeof e != "string")
|
|
458
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
459
|
+
if (wn)
|
|
460
|
+
return Uint8Array.fromHex(e);
|
|
461
|
+
const t = e.length, s = t / 2;
|
|
462
|
+
if (t % 2)
|
|
463
|
+
throw new Error("hex string expected, got unpadded hex of length " + t);
|
|
464
|
+
const n = new Uint8Array(s);
|
|
465
|
+
for (let r = 0, i = 0; r < s; r++, i += 2) {
|
|
466
|
+
const o = Je(e.charCodeAt(i)), a = Je(e.charCodeAt(i + 1));
|
|
467
|
+
if (o === void 0 || a === void 0) {
|
|
468
|
+
const c = e[i] + e[i + 1];
|
|
469
|
+
throw new Error('hex string expected, got non-hex character "' + c + '" at index ' + i);
|
|
470
|
+
}
|
|
471
|
+
n[r] = o * 16 + a;
|
|
472
|
+
}
|
|
473
|
+
return n;
|
|
474
|
+
}
|
|
475
|
+
function Ps(e) {
|
|
476
|
+
if (typeof e != "string")
|
|
477
|
+
throw new Error("string expected");
|
|
478
|
+
return new Uint8Array(new TextEncoder().encode(e));
|
|
479
|
+
}
|
|
480
|
+
function De(e) {
|
|
481
|
+
return typeof e == "string" && (e = Ps(e)), Ct(e), e;
|
|
482
|
+
}
|
|
483
|
+
function xt(...e) {
|
|
484
|
+
let t = 0;
|
|
485
|
+
for (let n = 0; n < e.length; n++) {
|
|
486
|
+
const r = e[n];
|
|
487
|
+
Ct(r), t += r.length;
|
|
488
|
+
}
|
|
489
|
+
const s = new Uint8Array(t);
|
|
490
|
+
for (let n = 0, r = 0; n < e.length; n++) {
|
|
491
|
+
const i = e[n];
|
|
492
|
+
s.set(i, r), r += i.length;
|
|
493
|
+
}
|
|
494
|
+
return s;
|
|
495
|
+
}
|
|
496
|
+
class bn {
|
|
497
|
+
}
|
|
498
|
+
function Ue(e) {
|
|
499
|
+
const t = (n) => e().update(De(n)).digest(), s = e();
|
|
500
|
+
return t.outputLen = s.outputLen, t.blockLen = s.blockLen, t.create = () => e(), t;
|
|
501
|
+
}
|
|
502
|
+
function pn(e = 32) {
|
|
503
|
+
if (_t && typeof _t.getRandomValues == "function")
|
|
504
|
+
return _t.getRandomValues(new Uint8Array(e));
|
|
505
|
+
if (_t && typeof _t.randomBytes == "function")
|
|
506
|
+
return Uint8Array.from(_t.randomBytes(e));
|
|
507
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
508
|
+
}
|
|
509
|
+
function Fs(e, t, s, n) {
|
|
510
|
+
if (typeof e.setBigUint64 == "function")
|
|
511
|
+
return e.setBigUint64(t, s, n);
|
|
512
|
+
const r = BigInt(32), i = BigInt(4294967295), o = Number(s >> r & i), a = Number(s & i), c = n ? 4 : 0, l = n ? 0 : 4;
|
|
513
|
+
e.setUint32(t + c, o, n), e.setUint32(t + l, a, n);
|
|
514
|
+
}
|
|
515
|
+
function Gs(e, t, s) {
|
|
516
|
+
return e & t ^ ~e & s;
|
|
517
|
+
}
|
|
518
|
+
function $s(e, t, s) {
|
|
519
|
+
return e & t ^ e & s ^ t & s;
|
|
520
|
+
}
|
|
521
|
+
class yn extends bn {
|
|
522
|
+
constructor(t, s, n, r) {
|
|
523
|
+
super(), this.finished = !1, this.length = 0, this.pos = 0, this.destroyed = !1, this.blockLen = t, this.outputLen = s, this.padOffset = n, this.isLE = r, this.buffer = new Uint8Array(t), this.view = be(this.buffer);
|
|
524
|
+
}
|
|
525
|
+
update(t) {
|
|
526
|
+
ae(this), t = De(t), Ct(t);
|
|
527
|
+
const { view: s, buffer: n, blockLen: r } = this, i = t.length;
|
|
528
|
+
for (let o = 0; o < i; ) {
|
|
529
|
+
const a = Math.min(r - this.pos, i - o);
|
|
530
|
+
if (a === r) {
|
|
531
|
+
const c = be(t);
|
|
532
|
+
for (; r <= i - o; o += r)
|
|
533
|
+
this.process(c, o);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
n.set(t.subarray(o, o + a), this.pos), this.pos += a, o += a, this.pos === r && (this.process(s, 0), this.pos = 0);
|
|
537
|
+
}
|
|
538
|
+
return this.length += t.length, this.roundClean(), this;
|
|
539
|
+
}
|
|
540
|
+
digestInto(t) {
|
|
541
|
+
ae(this), Ls(t, this), this.finished = !0;
|
|
542
|
+
const { buffer: s, view: n, blockLen: r, isLE: i } = this;
|
|
543
|
+
let { pos: o } = this;
|
|
544
|
+
s[o++] = 128, Pt(this.buffer.subarray(o)), this.padOffset > r - o && (this.process(n, 0), o = 0);
|
|
545
|
+
for (let u = o; u < r; u++)
|
|
546
|
+
s[u] = 0;
|
|
547
|
+
Fs(n, r - 8, BigInt(this.length * 8), i), this.process(n, 0);
|
|
548
|
+
const a = be(t), c = this.outputLen;
|
|
549
|
+
if (c % 4)
|
|
550
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
551
|
+
const l = c / 4, h = this.get();
|
|
552
|
+
if (l > h.length)
|
|
553
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
554
|
+
for (let u = 0; u < l; u++)
|
|
555
|
+
a.setUint32(4 * u, h[u], i);
|
|
556
|
+
}
|
|
557
|
+
digest() {
|
|
558
|
+
const { buffer: t, outputLen: s } = this;
|
|
559
|
+
this.digestInto(t);
|
|
560
|
+
const n = t.slice(0, s);
|
|
561
|
+
return this.destroy(), n;
|
|
562
|
+
}
|
|
563
|
+
_cloneInto(t) {
|
|
564
|
+
t || (t = new this.constructor()), t.set(...this.get());
|
|
565
|
+
const { blockLen: s, buffer: n, length: r, finished: i, destroyed: o, pos: a } = this;
|
|
566
|
+
return t.destroyed = o, t.finished = i, t.length = r, t.pos = a, r % s && t.buffer.set(n), t;
|
|
567
|
+
}
|
|
568
|
+
clone() {
|
|
569
|
+
return this._cloneInto();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const pt = /* @__PURE__ */ Uint32Array.from([
|
|
573
|
+
1779033703,
|
|
574
|
+
3144134277,
|
|
575
|
+
1013904242,
|
|
576
|
+
2773480762,
|
|
577
|
+
1359893119,
|
|
578
|
+
2600822924,
|
|
579
|
+
528734635,
|
|
580
|
+
1541459225
|
|
581
|
+
]), $ = /* @__PURE__ */ Uint32Array.from([
|
|
582
|
+
3418070365,
|
|
583
|
+
3238371032,
|
|
584
|
+
1654270250,
|
|
585
|
+
914150663,
|
|
586
|
+
2438529370,
|
|
587
|
+
812702999,
|
|
588
|
+
355462360,
|
|
589
|
+
4144912697,
|
|
590
|
+
1731405415,
|
|
591
|
+
4290775857,
|
|
592
|
+
2394180231,
|
|
593
|
+
1750603025,
|
|
594
|
+
3675008525,
|
|
595
|
+
1694076839,
|
|
596
|
+
1203062813,
|
|
597
|
+
3204075428
|
|
598
|
+
]), X = /* @__PURE__ */ Uint32Array.from([
|
|
599
|
+
1779033703,
|
|
600
|
+
4089235720,
|
|
601
|
+
3144134277,
|
|
602
|
+
2227873595,
|
|
603
|
+
1013904242,
|
|
604
|
+
4271175723,
|
|
605
|
+
2773480762,
|
|
606
|
+
1595750129,
|
|
607
|
+
1359893119,
|
|
608
|
+
2917565137,
|
|
609
|
+
2600822924,
|
|
610
|
+
725511199,
|
|
611
|
+
528734635,
|
|
612
|
+
4215389547,
|
|
613
|
+
1541459225,
|
|
614
|
+
327033209
|
|
615
|
+
]), zt = /* @__PURE__ */ BigInt(2 ** 32 - 1), Qe = /* @__PURE__ */ BigInt(32);
|
|
616
|
+
function Xs(e, t = !1) {
|
|
617
|
+
return t ? { h: Number(e & zt), l: Number(e >> Qe & zt) } : { h: Number(e >> Qe & zt) | 0, l: Number(e & zt) | 0 };
|
|
618
|
+
}
|
|
619
|
+
function qs(e, t = !1) {
|
|
620
|
+
const s = e.length;
|
|
621
|
+
let n = new Uint32Array(s), r = new Uint32Array(s);
|
|
622
|
+
for (let i = 0; i < s; i++) {
|
|
623
|
+
const { h: o, l: a } = Xs(e[i], t);
|
|
624
|
+
[n[i], r[i]] = [o, a];
|
|
625
|
+
}
|
|
626
|
+
return [n, r];
|
|
627
|
+
}
|
|
628
|
+
const tn = (e, t, s) => e >>> s, en = (e, t, s) => e << 32 - s | t >>> s, Nt = (e, t, s) => e >>> s | t << 32 - s, Ht = (e, t, s) => e << 32 - s | t >>> s, Jt = (e, t, s) => e << 64 - s | t >>> s - 32, Qt = (e, t, s) => e >>> s - 32 | t << 64 - s;
|
|
629
|
+
function lt(e, t, s, n) {
|
|
630
|
+
const r = (t >>> 0) + (n >>> 0);
|
|
631
|
+
return { h: e + s + (r / 2 ** 32 | 0) | 0, l: r | 0 };
|
|
632
|
+
}
|
|
633
|
+
const Ms = (e, t, s) => (e >>> 0) + (t >>> 0) + (s >>> 0), Zs = (e, t, s, n) => t + s + n + (e / 2 ** 32 | 0) | 0, Ws = (e, t, s, n) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0), Ys = (e, t, s, n, r) => t + s + n + r + (e / 2 ** 32 | 0) | 0, zs = (e, t, s, n, r) => (e >>> 0) + (t >>> 0) + (s >>> 0) + (n >>> 0) + (r >>> 0), Js = (e, t, s, n, r, i) => t + s + n + r + i + (e / 2 ** 32 | 0) | 0, Qs = /* @__PURE__ */ Uint32Array.from([
|
|
634
|
+
1116352408,
|
|
635
|
+
1899447441,
|
|
636
|
+
3049323471,
|
|
637
|
+
3921009573,
|
|
638
|
+
961987163,
|
|
639
|
+
1508970993,
|
|
640
|
+
2453635748,
|
|
641
|
+
2870763221,
|
|
642
|
+
3624381080,
|
|
643
|
+
310598401,
|
|
644
|
+
607225278,
|
|
645
|
+
1426881987,
|
|
646
|
+
1925078388,
|
|
647
|
+
2162078206,
|
|
648
|
+
2614888103,
|
|
649
|
+
3248222580,
|
|
650
|
+
3835390401,
|
|
651
|
+
4022224774,
|
|
652
|
+
264347078,
|
|
653
|
+
604807628,
|
|
654
|
+
770255983,
|
|
655
|
+
1249150122,
|
|
656
|
+
1555081692,
|
|
657
|
+
1996064986,
|
|
658
|
+
2554220882,
|
|
659
|
+
2821834349,
|
|
660
|
+
2952996808,
|
|
661
|
+
3210313671,
|
|
662
|
+
3336571891,
|
|
663
|
+
3584528711,
|
|
664
|
+
113926993,
|
|
665
|
+
338241895,
|
|
666
|
+
666307205,
|
|
667
|
+
773529912,
|
|
668
|
+
1294757372,
|
|
669
|
+
1396182291,
|
|
670
|
+
1695183700,
|
|
671
|
+
1986661051,
|
|
672
|
+
2177026350,
|
|
673
|
+
2456956037,
|
|
674
|
+
2730485921,
|
|
675
|
+
2820302411,
|
|
676
|
+
3259730800,
|
|
677
|
+
3345764771,
|
|
678
|
+
3516065817,
|
|
679
|
+
3600352804,
|
|
680
|
+
4094571909,
|
|
681
|
+
275423344,
|
|
682
|
+
430227734,
|
|
683
|
+
506948616,
|
|
684
|
+
659060556,
|
|
685
|
+
883997877,
|
|
686
|
+
958139571,
|
|
687
|
+
1322822218,
|
|
688
|
+
1537002063,
|
|
689
|
+
1747873779,
|
|
690
|
+
1955562222,
|
|
691
|
+
2024104815,
|
|
692
|
+
2227730452,
|
|
693
|
+
2361852424,
|
|
694
|
+
2428436474,
|
|
695
|
+
2756734187,
|
|
696
|
+
3204031479,
|
|
697
|
+
3329325298
|
|
698
|
+
]), yt = /* @__PURE__ */ new Uint32Array(64);
|
|
699
|
+
class tr extends yn {
|
|
700
|
+
constructor(t = 32) {
|
|
701
|
+
super(64, t, 8, !1), this.A = pt[0] | 0, this.B = pt[1] | 0, this.C = pt[2] | 0, this.D = pt[3] | 0, this.E = pt[4] | 0, this.F = pt[5] | 0, this.G = pt[6] | 0, this.H = pt[7] | 0;
|
|
702
|
+
}
|
|
703
|
+
get() {
|
|
704
|
+
const { A: t, B: s, C: n, D: r, E: i, F: o, G: a, H: c } = this;
|
|
705
|
+
return [t, s, n, r, i, o, a, c];
|
|
706
|
+
}
|
|
707
|
+
// prettier-ignore
|
|
708
|
+
set(t, s, n, r, i, o, a, c) {
|
|
709
|
+
this.A = t | 0, this.B = s | 0, this.C = n | 0, this.D = r | 0, this.E = i | 0, this.F = o | 0, this.G = a | 0, this.H = c | 0;
|
|
710
|
+
}
|
|
711
|
+
process(t, s) {
|
|
712
|
+
for (let u = 0; u < 16; u++, s += 4)
|
|
713
|
+
yt[u] = t.getUint32(s, !1);
|
|
714
|
+
for (let u = 16; u < 64; u++) {
|
|
715
|
+
const f = yt[u - 15], d = yt[u - 2], p = at(f, 7) ^ at(f, 18) ^ f >>> 3, m = at(d, 17) ^ at(d, 19) ^ d >>> 10;
|
|
716
|
+
yt[u] = m + yt[u - 7] + p + yt[u - 16] | 0;
|
|
717
|
+
}
|
|
718
|
+
let { A: n, B: r, C: i, D: o, E: a, F: c, G: l, H: h } = this;
|
|
719
|
+
for (let u = 0; u < 64; u++) {
|
|
720
|
+
const f = at(a, 6) ^ at(a, 11) ^ at(a, 25), d = h + f + Gs(a, c, l) + Qs[u] + yt[u] | 0, m = (at(n, 2) ^ at(n, 13) ^ at(n, 22)) + $s(n, r, i) | 0;
|
|
721
|
+
h = l, l = c, c = a, a = o + d | 0, o = i, i = r, r = n, n = d + m | 0;
|
|
722
|
+
}
|
|
723
|
+
n = n + this.A | 0, r = r + this.B | 0, i = i + this.C | 0, o = o + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, h = h + this.H | 0, this.set(n, r, i, o, a, c, l, h);
|
|
724
|
+
}
|
|
725
|
+
roundClean() {
|
|
726
|
+
Pt(yt);
|
|
727
|
+
}
|
|
728
|
+
destroy() {
|
|
729
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0), Pt(this.buffer);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
const mn = qs([
|
|
733
|
+
"0x428a2f98d728ae22",
|
|
734
|
+
"0x7137449123ef65cd",
|
|
735
|
+
"0xb5c0fbcfec4d3b2f",
|
|
736
|
+
"0xe9b5dba58189dbbc",
|
|
737
|
+
"0x3956c25bf348b538",
|
|
738
|
+
"0x59f111f1b605d019",
|
|
739
|
+
"0x923f82a4af194f9b",
|
|
740
|
+
"0xab1c5ed5da6d8118",
|
|
741
|
+
"0xd807aa98a3030242",
|
|
742
|
+
"0x12835b0145706fbe",
|
|
743
|
+
"0x243185be4ee4b28c",
|
|
744
|
+
"0x550c7dc3d5ffb4e2",
|
|
745
|
+
"0x72be5d74f27b896f",
|
|
746
|
+
"0x80deb1fe3b1696b1",
|
|
747
|
+
"0x9bdc06a725c71235",
|
|
748
|
+
"0xc19bf174cf692694",
|
|
749
|
+
"0xe49b69c19ef14ad2",
|
|
750
|
+
"0xefbe4786384f25e3",
|
|
751
|
+
"0x0fc19dc68b8cd5b5",
|
|
752
|
+
"0x240ca1cc77ac9c65",
|
|
753
|
+
"0x2de92c6f592b0275",
|
|
754
|
+
"0x4a7484aa6ea6e483",
|
|
755
|
+
"0x5cb0a9dcbd41fbd4",
|
|
756
|
+
"0x76f988da831153b5",
|
|
757
|
+
"0x983e5152ee66dfab",
|
|
758
|
+
"0xa831c66d2db43210",
|
|
759
|
+
"0xb00327c898fb213f",
|
|
760
|
+
"0xbf597fc7beef0ee4",
|
|
761
|
+
"0xc6e00bf33da88fc2",
|
|
762
|
+
"0xd5a79147930aa725",
|
|
763
|
+
"0x06ca6351e003826f",
|
|
764
|
+
"0x142929670a0e6e70",
|
|
765
|
+
"0x27b70a8546d22ffc",
|
|
766
|
+
"0x2e1b21385c26c926",
|
|
767
|
+
"0x4d2c6dfc5ac42aed",
|
|
768
|
+
"0x53380d139d95b3df",
|
|
769
|
+
"0x650a73548baf63de",
|
|
770
|
+
"0x766a0abb3c77b2a8",
|
|
771
|
+
"0x81c2c92e47edaee6",
|
|
772
|
+
"0x92722c851482353b",
|
|
773
|
+
"0xa2bfe8a14cf10364",
|
|
774
|
+
"0xa81a664bbc423001",
|
|
775
|
+
"0xc24b8b70d0f89791",
|
|
776
|
+
"0xc76c51a30654be30",
|
|
777
|
+
"0xd192e819d6ef5218",
|
|
778
|
+
"0xd69906245565a910",
|
|
779
|
+
"0xf40e35855771202a",
|
|
780
|
+
"0x106aa07032bbd1b8",
|
|
781
|
+
"0x19a4c116b8d2d0c8",
|
|
782
|
+
"0x1e376c085141ab53",
|
|
783
|
+
"0x2748774cdf8eeb99",
|
|
784
|
+
"0x34b0bcb5e19b48a8",
|
|
785
|
+
"0x391c0cb3c5c95a63",
|
|
786
|
+
"0x4ed8aa4ae3418acb",
|
|
787
|
+
"0x5b9cca4f7763e373",
|
|
788
|
+
"0x682e6ff3d6b2b8a3",
|
|
789
|
+
"0x748f82ee5defb2fc",
|
|
790
|
+
"0x78a5636f43172f60",
|
|
791
|
+
"0x84c87814a1f0ab72",
|
|
792
|
+
"0x8cc702081a6439ec",
|
|
793
|
+
"0x90befffa23631e28",
|
|
794
|
+
"0xa4506cebde82bde9",
|
|
795
|
+
"0xbef9a3f7b2c67915",
|
|
796
|
+
"0xc67178f2e372532b",
|
|
797
|
+
"0xca273eceea26619c",
|
|
798
|
+
"0xd186b8c721c0c207",
|
|
799
|
+
"0xeada7dd6cde0eb1e",
|
|
800
|
+
"0xf57d4f7fee6ed178",
|
|
801
|
+
"0x06f067aa72176fba",
|
|
802
|
+
"0x0a637dc5a2c898a6",
|
|
803
|
+
"0x113f9804bef90dae",
|
|
804
|
+
"0x1b710b35131c471b",
|
|
805
|
+
"0x28db77f523047d84",
|
|
806
|
+
"0x32caab7b40c72493",
|
|
807
|
+
"0x3c9ebe0a15c9bebc",
|
|
808
|
+
"0x431d67c49c100d4c",
|
|
809
|
+
"0x4cc5d4becb3e42b6",
|
|
810
|
+
"0x597f299cfc657e2a",
|
|
811
|
+
"0x5fcb6fab3ad6faec",
|
|
812
|
+
"0x6c44198c4a475817"
|
|
813
|
+
].map((e) => BigInt(e))), er = mn[0], nr = mn[1], mt = /* @__PURE__ */ new Uint32Array(80), Et = /* @__PURE__ */ new Uint32Array(80);
|
|
814
|
+
class En extends yn {
|
|
815
|
+
constructor(t = 64) {
|
|
816
|
+
super(128, t, 16, !1), this.Ah = X[0] | 0, this.Al = X[1] | 0, this.Bh = X[2] | 0, this.Bl = X[3] | 0, this.Ch = X[4] | 0, this.Cl = X[5] | 0, this.Dh = X[6] | 0, this.Dl = X[7] | 0, this.Eh = X[8] | 0, this.El = X[9] | 0, this.Fh = X[10] | 0, this.Fl = X[11] | 0, this.Gh = X[12] | 0, this.Gl = X[13] | 0, this.Hh = X[14] | 0, this.Hl = X[15] | 0;
|
|
817
|
+
}
|
|
818
|
+
// prettier-ignore
|
|
819
|
+
get() {
|
|
820
|
+
const { Ah: t, Al: s, Bh: n, Bl: r, Ch: i, Cl: o, Dh: a, Dl: c, Eh: l, El: h, Fh: u, Fl: f, Gh: d, Gl: p, Hh: m, Hl: R } = this;
|
|
821
|
+
return [t, s, n, r, i, o, a, c, l, h, u, f, d, p, m, R];
|
|
822
|
+
}
|
|
823
|
+
// prettier-ignore
|
|
824
|
+
set(t, s, n, r, i, o, a, c, l, h, u, f, d, p, m, R) {
|
|
825
|
+
this.Ah = t | 0, this.Al = s | 0, this.Bh = n | 0, this.Bl = r | 0, this.Ch = i | 0, this.Cl = o | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = l | 0, this.El = h | 0, this.Fh = u | 0, this.Fl = f | 0, this.Gh = d | 0, this.Gl = p | 0, this.Hh = m | 0, this.Hl = R | 0;
|
|
826
|
+
}
|
|
827
|
+
process(t, s) {
|
|
828
|
+
for (let A = 0; A < 16; A++, s += 4)
|
|
829
|
+
mt[A] = t.getUint32(s), Et[A] = t.getUint32(s += 4);
|
|
830
|
+
for (let A = 16; A < 80; A++) {
|
|
831
|
+
const q = mt[A - 15] | 0, K = Et[A - 15] | 0, ot = Nt(q, K, 1) ^ Nt(q, K, 8) ^ tn(q, K, 7), bt = Ht(q, K, 1) ^ Ht(q, K, 8) ^ en(q, K, 7), F = mt[A - 2] | 0, B = Et[A - 2] | 0, ft = Nt(F, B, 19) ^ Jt(F, B, 61) ^ tn(F, B, 6), nt = Ht(F, B, 19) ^ Qt(F, B, 61) ^ en(F, B, 6), T = Ws(bt, nt, Et[A - 7], Et[A - 16]), b = Ys(T, ot, ft, mt[A - 7], mt[A - 16]);
|
|
832
|
+
mt[A] = b | 0, Et[A] = T | 0;
|
|
833
|
+
}
|
|
834
|
+
let { Ah: n, Al: r, Bh: i, Bl: o, Ch: a, Cl: c, Dh: l, Dl: h, Eh: u, El: f, Fh: d, Fl: p, Gh: m, Gl: R, Hh: _, Hl: et } = this;
|
|
835
|
+
for (let A = 0; A < 80; A++) {
|
|
836
|
+
const q = Nt(u, f, 14) ^ Nt(u, f, 18) ^ Jt(u, f, 41), K = Ht(u, f, 14) ^ Ht(u, f, 18) ^ Qt(u, f, 41), ot = u & d ^ ~u & m, bt = f & p ^ ~f & R, F = zs(et, K, bt, nr[A], Et[A]), B = Js(F, _, q, ot, er[A], mt[A]), ft = F | 0, nt = Nt(n, r, 28) ^ Jt(n, r, 34) ^ Jt(n, r, 39), T = Ht(n, r, 28) ^ Qt(n, r, 34) ^ Qt(n, r, 39), b = n & i ^ n & a ^ i & a, w = r & o ^ r & c ^ o & c;
|
|
837
|
+
_ = m | 0, et = R | 0, m = d | 0, R = p | 0, d = u | 0, p = f | 0, { h: u, l: f } = lt(l | 0, h | 0, B | 0, ft | 0), l = a | 0, h = c | 0, a = i | 0, c = o | 0, i = n | 0, o = r | 0;
|
|
838
|
+
const g = Ms(ft, T, w);
|
|
839
|
+
n = Zs(g, B, nt, b), r = g | 0;
|
|
840
|
+
}
|
|
841
|
+
({ h: n, l: r } = lt(this.Ah | 0, this.Al | 0, n | 0, r | 0)), { h: i, l: o } = lt(this.Bh | 0, this.Bl | 0, i | 0, o | 0), { h: a, l: c } = lt(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: l, l: h } = lt(this.Dh | 0, this.Dl | 0, l | 0, h | 0), { h: u, l: f } = lt(this.Eh | 0, this.El | 0, u | 0, f | 0), { h: d, l: p } = lt(this.Fh | 0, this.Fl | 0, d | 0, p | 0), { h: m, l: R } = lt(this.Gh | 0, this.Gl | 0, m | 0, R | 0), { h: _, l: et } = lt(this.Hh | 0, this.Hl | 0, _ | 0, et | 0), this.set(n, r, i, o, a, c, l, h, u, f, d, p, m, R, _, et);
|
|
842
|
+
}
|
|
843
|
+
roundClean() {
|
|
844
|
+
Pt(mt, Et);
|
|
845
|
+
}
|
|
846
|
+
destroy() {
|
|
847
|
+
Pt(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
class sr extends En {
|
|
851
|
+
constructor() {
|
|
852
|
+
super(48), this.Ah = $[0] | 0, this.Al = $[1] | 0, this.Bh = $[2] | 0, this.Bl = $[3] | 0, this.Ch = $[4] | 0, this.Cl = $[5] | 0, this.Dh = $[6] | 0, this.Dl = $[7] | 0, this.Eh = $[8] | 0, this.El = $[9] | 0, this.Fh = $[10] | 0, this.Fl = $[11] | 0, this.Gh = $[12] | 0, this.Gl = $[13] | 0, this.Hh = $[14] | 0, this.Hl = $[15] | 0;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const rr = /* @__PURE__ */ Ue(() => new tr()), ir = /* @__PURE__ */ Ue(() => new En()), or = /* @__PURE__ */ Ue(() => new sr());
|
|
856
|
+
class xn extends bn {
|
|
857
|
+
constructor(t, s) {
|
|
858
|
+
super(), this.finished = !1, this.destroyed = !1, gn(t);
|
|
859
|
+
const n = De(s);
|
|
860
|
+
if (this.iHash = t.create(), typeof this.iHash.update != "function")
|
|
861
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
862
|
+
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
863
|
+
const r = this.blockLen, i = new Uint8Array(r);
|
|
864
|
+
i.set(n.length > r ? t.create().update(n).digest() : n);
|
|
865
|
+
for (let o = 0; o < i.length; o++)
|
|
866
|
+
i[o] ^= 54;
|
|
867
|
+
this.iHash.update(i), this.oHash = t.create();
|
|
868
|
+
for (let o = 0; o < i.length; o++)
|
|
869
|
+
i[o] ^= 106;
|
|
870
|
+
this.oHash.update(i), Pt(i);
|
|
871
|
+
}
|
|
872
|
+
update(t) {
|
|
873
|
+
return ae(this), this.iHash.update(t), this;
|
|
874
|
+
}
|
|
875
|
+
digestInto(t) {
|
|
876
|
+
ae(this), Ct(t, this.outputLen), this.finished = !0, this.iHash.digestInto(t), this.oHash.update(t), this.oHash.digestInto(t), this.destroy();
|
|
877
|
+
}
|
|
878
|
+
digest() {
|
|
879
|
+
const t = new Uint8Array(this.oHash.outputLen);
|
|
880
|
+
return this.digestInto(t), t;
|
|
881
|
+
}
|
|
882
|
+
_cloneInto(t) {
|
|
883
|
+
t || (t = Object.create(Object.getPrototypeOf(this), {}));
|
|
884
|
+
const { oHash: s, iHash: n, finished: r, destroyed: i, blockLen: o, outputLen: a } = this;
|
|
885
|
+
return t = t, t.finished = r, t.destroyed = i, t.blockLen = o, t.outputLen = a, t.oHash = s._cloneInto(t.oHash), t.iHash = n._cloneInto(t.iHash), t;
|
|
886
|
+
}
|
|
887
|
+
clone() {
|
|
888
|
+
return this._cloneInto();
|
|
889
|
+
}
|
|
890
|
+
destroy() {
|
|
891
|
+
this.destroyed = !0, this.oHash.destroy(), this.iHash.destroy();
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
const Sn = (e, t, s) => new xn(e, t).update(s).digest();
|
|
895
|
+
Sn.create = (e, t) => new xn(e, t);
|
|
896
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
897
|
+
const _e = /* @__PURE__ */ BigInt(0), Re = /* @__PURE__ */ BigInt(1);
|
|
898
|
+
function fe(e, t = "") {
|
|
899
|
+
if (typeof e != "boolean") {
|
|
900
|
+
const s = t && `"${t}"`;
|
|
901
|
+
throw new Error(s + "expected boolean, got type=" + typeof e);
|
|
902
|
+
}
|
|
903
|
+
return e;
|
|
904
|
+
}
|
|
905
|
+
function vt(e, t, s = "") {
|
|
906
|
+
const n = de(e), r = e?.length, i = t !== void 0;
|
|
907
|
+
if (!n || i && r !== t) {
|
|
908
|
+
const o = s && `"${s}" `, a = i ? ` of length ${t}` : "", c = n ? `length=${r}` : `type=${typeof e}`;
|
|
909
|
+
throw new Error(o + "expected Uint8Array" + a + ", got " + c);
|
|
910
|
+
}
|
|
911
|
+
return e;
|
|
912
|
+
}
|
|
913
|
+
function te(e) {
|
|
914
|
+
const t = e.toString(16);
|
|
915
|
+
return t.length & 1 ? "0" + t : t;
|
|
916
|
+
}
|
|
917
|
+
function In(e) {
|
|
918
|
+
if (typeof e != "string")
|
|
919
|
+
throw new Error("hex string expected, got " + typeof e);
|
|
920
|
+
return e === "" ? _e : BigInt("0x" + e);
|
|
921
|
+
}
|
|
922
|
+
function ge(e) {
|
|
923
|
+
return In(jt(e));
|
|
924
|
+
}
|
|
925
|
+
function vn(e) {
|
|
926
|
+
return Ct(e), In(jt(Uint8Array.from(e).reverse()));
|
|
927
|
+
}
|
|
928
|
+
function Ne(e, t) {
|
|
929
|
+
return ce(e.toString(16).padStart(t * 2, "0"));
|
|
930
|
+
}
|
|
931
|
+
function An(e, t) {
|
|
932
|
+
return Ne(e, t).reverse();
|
|
933
|
+
}
|
|
934
|
+
function z(e, t, s) {
|
|
935
|
+
let n;
|
|
936
|
+
if (typeof t == "string")
|
|
937
|
+
try {
|
|
938
|
+
n = ce(t);
|
|
939
|
+
} catch (r) {
|
|
940
|
+
throw new Error(e + " must be hex string or Uint8Array, cause: " + r);
|
|
941
|
+
}
|
|
942
|
+
else if (de(t))
|
|
943
|
+
n = Uint8Array.from(t);
|
|
944
|
+
else
|
|
945
|
+
throw new Error(e + " must be hex string or Uint8Array");
|
|
946
|
+
return n.length, n;
|
|
947
|
+
}
|
|
948
|
+
const pe = (e) => typeof e == "bigint" && _e <= e;
|
|
949
|
+
function ar(e, t, s) {
|
|
950
|
+
return pe(e) && pe(t) && pe(s) && t <= e && e < s;
|
|
951
|
+
}
|
|
952
|
+
function cr(e, t, s, n) {
|
|
953
|
+
if (!ar(t, s, n))
|
|
954
|
+
throw new Error("expected valid " + e + ": " + s + " <= n < " + n + ", got " + t);
|
|
955
|
+
}
|
|
956
|
+
function On(e) {
|
|
957
|
+
let t;
|
|
958
|
+
for (t = 0; e > _e; e >>= Re, t += 1)
|
|
959
|
+
;
|
|
960
|
+
return t;
|
|
961
|
+
}
|
|
962
|
+
const Wt = (e) => (Re << BigInt(e)) - Re;
|
|
963
|
+
function fr(e, t, s) {
|
|
964
|
+
if (typeof e != "number" || e < 2)
|
|
965
|
+
throw new Error("hashLen must be a number");
|
|
966
|
+
if (typeof t != "number" || t < 2)
|
|
967
|
+
throw new Error("qByteLen must be a number");
|
|
968
|
+
if (typeof s != "function")
|
|
969
|
+
throw new Error("hmacFn must be a function");
|
|
970
|
+
const n = (d) => new Uint8Array(d), r = (d) => Uint8Array.of(d);
|
|
971
|
+
let i = n(e), o = n(e), a = 0;
|
|
972
|
+
const c = () => {
|
|
973
|
+
i.fill(1), o.fill(0), a = 0;
|
|
974
|
+
}, l = (...d) => s(o, i, ...d), h = (d = n(0)) => {
|
|
975
|
+
o = l(r(0), d), i = l(), d.length !== 0 && (o = l(r(1), d), i = l());
|
|
976
|
+
}, u = () => {
|
|
977
|
+
if (a++ >= 1e3)
|
|
978
|
+
throw new Error("drbg: tried 1000 values");
|
|
979
|
+
let d = 0;
|
|
980
|
+
const p = [];
|
|
981
|
+
for (; d < t; ) {
|
|
982
|
+
i = l();
|
|
983
|
+
const m = i.slice();
|
|
984
|
+
p.push(m), d += i.length;
|
|
985
|
+
}
|
|
986
|
+
return xt(...p);
|
|
987
|
+
};
|
|
988
|
+
return (d, p) => {
|
|
989
|
+
c(), h(d);
|
|
990
|
+
let m;
|
|
991
|
+
for (; !(m = p(u())); )
|
|
992
|
+
h();
|
|
993
|
+
return c(), m;
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
function He(e, t, s = {}) {
|
|
997
|
+
if (!e || typeof e != "object")
|
|
998
|
+
throw new Error("expected valid options object");
|
|
999
|
+
function n(r, i, o) {
|
|
1000
|
+
const a = e[r];
|
|
1001
|
+
if (o && a === void 0)
|
|
1002
|
+
return;
|
|
1003
|
+
const c = typeof a;
|
|
1004
|
+
if (c !== i || a === null)
|
|
1005
|
+
throw new Error(`param "${r}" is invalid: expected ${i}, got ${c}`);
|
|
1006
|
+
}
|
|
1007
|
+
Object.entries(t).forEach(([r, i]) => n(r, i, !1)), Object.entries(s).forEach(([r, i]) => n(r, i, !0));
|
|
1008
|
+
}
|
|
1009
|
+
function nn(e) {
|
|
1010
|
+
const t = /* @__PURE__ */ new WeakMap();
|
|
1011
|
+
return (s, ...n) => {
|
|
1012
|
+
const r = t.get(s);
|
|
1013
|
+
if (r !== void 0)
|
|
1014
|
+
return r;
|
|
1015
|
+
const i = e(s, ...n);
|
|
1016
|
+
return t.set(s, i), i;
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1020
|
+
const tt = BigInt(0), M = BigInt(1), At = /* @__PURE__ */ BigInt(2), Bn = /* @__PURE__ */ BigInt(3), Rn = /* @__PURE__ */ BigInt(4), Cn = /* @__PURE__ */ BigInt(5), ur = /* @__PURE__ */ BigInt(7), Tn = /* @__PURE__ */ BigInt(8), lr = /* @__PURE__ */ BigInt(9), Dn = /* @__PURE__ */ BigInt(16);
|
|
1021
|
+
function st(e, t) {
|
|
1022
|
+
const s = e % t;
|
|
1023
|
+
return s >= tt ? s : t + s;
|
|
1024
|
+
}
|
|
1025
|
+
function sn(e, t) {
|
|
1026
|
+
if (e === tt)
|
|
1027
|
+
throw new Error("invert: expected non-zero number");
|
|
1028
|
+
if (t <= tt)
|
|
1029
|
+
throw new Error("invert: expected positive modulus, got " + t);
|
|
1030
|
+
let s = st(e, t), n = t, r = tt, i = M;
|
|
1031
|
+
for (; s !== tt; ) {
|
|
1032
|
+
const a = n / s, c = n % s, l = r - i * a;
|
|
1033
|
+
n = s, s = c, r = i, i = l;
|
|
1034
|
+
}
|
|
1035
|
+
if (n !== M)
|
|
1036
|
+
throw new Error("invert: does not exist");
|
|
1037
|
+
return st(r, t);
|
|
1038
|
+
}
|
|
1039
|
+
function Ve(e, t, s) {
|
|
1040
|
+
if (!e.eql(e.sqr(t), s))
|
|
1041
|
+
throw new Error("Cannot find square root");
|
|
1042
|
+
}
|
|
1043
|
+
function Un(e, t) {
|
|
1044
|
+
const s = (e.ORDER + M) / Rn, n = e.pow(t, s);
|
|
1045
|
+
return Ve(e, n, t), n;
|
|
1046
|
+
}
|
|
1047
|
+
function hr(e, t) {
|
|
1048
|
+
const s = (e.ORDER - Cn) / Tn, n = e.mul(t, At), r = e.pow(n, s), i = e.mul(t, r), o = e.mul(e.mul(i, At), r), a = e.mul(i, e.sub(o, e.ONE));
|
|
1049
|
+
return Ve(e, a, t), a;
|
|
1050
|
+
}
|
|
1051
|
+
function dr(e) {
|
|
1052
|
+
const t = Tt(e), s = _n(e), n = s(t, t.neg(t.ONE)), r = s(t, n), i = s(t, t.neg(n)), o = (e + ur) / Dn;
|
|
1053
|
+
return (a, c) => {
|
|
1054
|
+
let l = a.pow(c, o), h = a.mul(l, n);
|
|
1055
|
+
const u = a.mul(l, r), f = a.mul(l, i), d = a.eql(a.sqr(h), c), p = a.eql(a.sqr(u), c);
|
|
1056
|
+
l = a.cmov(l, h, d), h = a.cmov(f, u, p);
|
|
1057
|
+
const m = a.eql(a.sqr(h), c), R = a.cmov(l, h, m);
|
|
1058
|
+
return Ve(a, R, c), R;
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function _n(e) {
|
|
1062
|
+
if (e < Bn)
|
|
1063
|
+
throw new Error("sqrt is not defined for small field");
|
|
1064
|
+
let t = e - M, s = 0;
|
|
1065
|
+
for (; t % At === tt; )
|
|
1066
|
+
t /= At, s++;
|
|
1067
|
+
let n = At;
|
|
1068
|
+
const r = Tt(e);
|
|
1069
|
+
for (; rn(r, n) === 1; )
|
|
1070
|
+
if (n++ > 1e3)
|
|
1071
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
1072
|
+
if (s === 1)
|
|
1073
|
+
return Un;
|
|
1074
|
+
let i = r.pow(n, t);
|
|
1075
|
+
const o = (t + M) / At;
|
|
1076
|
+
return function(c, l) {
|
|
1077
|
+
if (c.is0(l))
|
|
1078
|
+
return l;
|
|
1079
|
+
if (rn(c, l) !== 1)
|
|
1080
|
+
throw new Error("Cannot find square root");
|
|
1081
|
+
let h = s, u = c.mul(c.ONE, i), f = c.pow(l, t), d = c.pow(l, o);
|
|
1082
|
+
for (; !c.eql(f, c.ONE); ) {
|
|
1083
|
+
if (c.is0(f))
|
|
1084
|
+
return c.ZERO;
|
|
1085
|
+
let p = 1, m = c.sqr(f);
|
|
1086
|
+
for (; !c.eql(m, c.ONE); )
|
|
1087
|
+
if (p++, m = c.sqr(m), p === h)
|
|
1088
|
+
throw new Error("Cannot find square root");
|
|
1089
|
+
const R = M << BigInt(h - p - 1), _ = c.pow(u, R);
|
|
1090
|
+
h = p, u = c.sqr(_), f = c.mul(f, u), d = c.mul(d, _);
|
|
1091
|
+
}
|
|
1092
|
+
return d;
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function gr(e) {
|
|
1096
|
+
return e % Rn === Bn ? Un : e % Tn === Cn ? hr : e % Dn === lr ? dr(e) : _n(e);
|
|
1097
|
+
}
|
|
1098
|
+
const wr = [
|
|
1099
|
+
"create",
|
|
1100
|
+
"isValid",
|
|
1101
|
+
"is0",
|
|
1102
|
+
"neg",
|
|
1103
|
+
"inv",
|
|
1104
|
+
"sqrt",
|
|
1105
|
+
"sqr",
|
|
1106
|
+
"eql",
|
|
1107
|
+
"add",
|
|
1108
|
+
"sub",
|
|
1109
|
+
"mul",
|
|
1110
|
+
"pow",
|
|
1111
|
+
"div",
|
|
1112
|
+
"addN",
|
|
1113
|
+
"subN",
|
|
1114
|
+
"mulN",
|
|
1115
|
+
"sqrN"
|
|
1116
|
+
];
|
|
1117
|
+
function br(e) {
|
|
1118
|
+
const t = {
|
|
1119
|
+
ORDER: "bigint",
|
|
1120
|
+
MASK: "bigint",
|
|
1121
|
+
BYTES: "number",
|
|
1122
|
+
BITS: "number"
|
|
1123
|
+
}, s = wr.reduce((n, r) => (n[r] = "function", n), t);
|
|
1124
|
+
return He(e, s), e;
|
|
1125
|
+
}
|
|
1126
|
+
function pr(e, t, s) {
|
|
1127
|
+
if (s < tt)
|
|
1128
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
1129
|
+
if (s === tt)
|
|
1130
|
+
return e.ONE;
|
|
1131
|
+
if (s === M)
|
|
1132
|
+
return t;
|
|
1133
|
+
let n = e.ONE, r = t;
|
|
1134
|
+
for (; s > tt; )
|
|
1135
|
+
s & M && (n = e.mul(n, r)), r = e.sqr(r), s >>= M;
|
|
1136
|
+
return n;
|
|
1137
|
+
}
|
|
1138
|
+
function Nn(e, t, s = !1) {
|
|
1139
|
+
const n = new Array(t.length).fill(s ? e.ZERO : void 0), r = t.reduce((o, a, c) => e.is0(a) ? o : (n[c] = o, e.mul(o, a)), e.ONE), i = e.inv(r);
|
|
1140
|
+
return t.reduceRight((o, a, c) => e.is0(a) ? o : (n[c] = e.mul(o, n[c]), e.mul(o, a)), i), n;
|
|
1141
|
+
}
|
|
1142
|
+
function rn(e, t) {
|
|
1143
|
+
const s = (e.ORDER - M) / At, n = e.pow(t, s), r = e.eql(n, e.ONE), i = e.eql(n, e.ZERO), o = e.eql(n, e.neg(e.ONE));
|
|
1144
|
+
if (!r && !i && !o)
|
|
1145
|
+
throw new Error("invalid Legendre symbol result");
|
|
1146
|
+
return r ? 1 : i ? 0 : -1;
|
|
1147
|
+
}
|
|
1148
|
+
function Hn(e, t) {
|
|
1149
|
+
t !== void 0 && Be(t);
|
|
1150
|
+
const s = t !== void 0 ? t : e.toString(2).length, n = Math.ceil(s / 8);
|
|
1151
|
+
return { nBitLength: s, nByteLength: n };
|
|
1152
|
+
}
|
|
1153
|
+
function Tt(e, t, s = !1, n = {}) {
|
|
1154
|
+
if (e <= tt)
|
|
1155
|
+
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
1156
|
+
let r, i, o = !1, a;
|
|
1157
|
+
if (typeof t == "object" && t != null) {
|
|
1158
|
+
if (n.sqrt || s)
|
|
1159
|
+
throw new Error("cannot specify opts in two arguments");
|
|
1160
|
+
const f = t;
|
|
1161
|
+
f.BITS && (r = f.BITS), f.sqrt && (i = f.sqrt), typeof f.isLE == "boolean" && (s = f.isLE), typeof f.modFromBytes == "boolean" && (o = f.modFromBytes), a = f.allowedLengths;
|
|
1162
|
+
} else
|
|
1163
|
+
typeof t == "number" && (r = t), n.sqrt && (i = n.sqrt);
|
|
1164
|
+
const { nBitLength: c, nByteLength: l } = Hn(e, r);
|
|
1165
|
+
if (l > 2048)
|
|
1166
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
1167
|
+
let h;
|
|
1168
|
+
const u = Object.freeze({
|
|
1169
|
+
ORDER: e,
|
|
1170
|
+
isLE: s,
|
|
1171
|
+
BITS: c,
|
|
1172
|
+
BYTES: l,
|
|
1173
|
+
MASK: Wt(c),
|
|
1174
|
+
ZERO: tt,
|
|
1175
|
+
ONE: M,
|
|
1176
|
+
allowedLengths: a,
|
|
1177
|
+
create: (f) => st(f, e),
|
|
1178
|
+
isValid: (f) => {
|
|
1179
|
+
if (typeof f != "bigint")
|
|
1180
|
+
throw new Error("invalid field element: expected bigint, got " + typeof f);
|
|
1181
|
+
return tt <= f && f < e;
|
|
1182
|
+
},
|
|
1183
|
+
is0: (f) => f === tt,
|
|
1184
|
+
// is valid and invertible
|
|
1185
|
+
isValidNot0: (f) => !u.is0(f) && u.isValid(f),
|
|
1186
|
+
isOdd: (f) => (f & M) === M,
|
|
1187
|
+
neg: (f) => st(-f, e),
|
|
1188
|
+
eql: (f, d) => f === d,
|
|
1189
|
+
sqr: (f) => st(f * f, e),
|
|
1190
|
+
add: (f, d) => st(f + d, e),
|
|
1191
|
+
sub: (f, d) => st(f - d, e),
|
|
1192
|
+
mul: (f, d) => st(f * d, e),
|
|
1193
|
+
pow: (f, d) => pr(u, f, d),
|
|
1194
|
+
div: (f, d) => st(f * sn(d, e), e),
|
|
1195
|
+
// Same as above, but doesn't normalize
|
|
1196
|
+
sqrN: (f) => f * f,
|
|
1197
|
+
addN: (f, d) => f + d,
|
|
1198
|
+
subN: (f, d) => f - d,
|
|
1199
|
+
mulN: (f, d) => f * d,
|
|
1200
|
+
inv: (f) => sn(f, e),
|
|
1201
|
+
sqrt: i || ((f) => (h || (h = gr(e)), h(u, f))),
|
|
1202
|
+
toBytes: (f) => s ? An(f, l) : Ne(f, l),
|
|
1203
|
+
fromBytes: (f, d = !0) => {
|
|
1204
|
+
if (a) {
|
|
1205
|
+
if (!a.includes(f.length) || f.length > l)
|
|
1206
|
+
throw new Error("Field.fromBytes: expected " + a + " bytes, got " + f.length);
|
|
1207
|
+
const m = new Uint8Array(l);
|
|
1208
|
+
m.set(f, s ? 0 : m.length - f.length), f = m;
|
|
1209
|
+
}
|
|
1210
|
+
if (f.length !== l)
|
|
1211
|
+
throw new Error("Field.fromBytes: expected " + l + " bytes, got " + f.length);
|
|
1212
|
+
let p = s ? vn(f) : ge(f);
|
|
1213
|
+
if (o && (p = st(p, e)), !d && !u.isValid(p))
|
|
1214
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
1215
|
+
return p;
|
|
1216
|
+
},
|
|
1217
|
+
// TODO: we don't need it here, move out to separate fn
|
|
1218
|
+
invertBatch: (f) => Nn(u, f),
|
|
1219
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
1220
|
+
// and it's unclear what to return in there.
|
|
1221
|
+
cmov: (f, d, p) => p ? d : f
|
|
1222
|
+
});
|
|
1223
|
+
return Object.freeze(u);
|
|
1224
|
+
}
|
|
1225
|
+
function Vn(e) {
|
|
1226
|
+
if (typeof e != "bigint")
|
|
1227
|
+
throw new Error("field order must be bigint");
|
|
1228
|
+
const t = e.toString(2).length;
|
|
1229
|
+
return Math.ceil(t / 8);
|
|
1230
|
+
}
|
|
1231
|
+
function jn(e) {
|
|
1232
|
+
const t = Vn(e);
|
|
1233
|
+
return t + Math.ceil(t / 2);
|
|
1234
|
+
}
|
|
1235
|
+
function yr(e, t, s = !1) {
|
|
1236
|
+
const n = e.length, r = Vn(t), i = jn(t);
|
|
1237
|
+
if (n < 16 || n < i || n > 1024)
|
|
1238
|
+
throw new Error("expected " + i + "-1024 bytes of input, got " + n);
|
|
1239
|
+
const o = s ? vn(e) : ge(e), a = st(o, t - M) + M;
|
|
1240
|
+
return s ? An(a, r) : Ne(a, r);
|
|
1241
|
+
}
|
|
1242
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1243
|
+
const Ft = BigInt(0), Ot = BigInt(1);
|
|
1244
|
+
function ue(e, t) {
|
|
1245
|
+
const s = t.negate();
|
|
1246
|
+
return e ? s : t;
|
|
1247
|
+
}
|
|
1248
|
+
function ye(e, t) {
|
|
1249
|
+
const s = Nn(e.Fp, t.map((n) => n.Z));
|
|
1250
|
+
return t.map((n, r) => e.fromAffine(n.toAffine(s[r])));
|
|
1251
|
+
}
|
|
1252
|
+
function kn(e, t) {
|
|
1253
|
+
if (!Number.isSafeInteger(e) || e <= 0 || e > t)
|
|
1254
|
+
throw new Error("invalid window size, expected [1.." + t + "], got W=" + e);
|
|
1255
|
+
}
|
|
1256
|
+
function me(e, t) {
|
|
1257
|
+
kn(e, t);
|
|
1258
|
+
const s = Math.ceil(t / e) + 1, n = 2 ** (e - 1), r = 2 ** e, i = Wt(e), o = BigInt(e);
|
|
1259
|
+
return { windows: s, windowSize: n, mask: i, maxNumber: r, shiftBy: o };
|
|
1260
|
+
}
|
|
1261
|
+
function on(e, t, s) {
|
|
1262
|
+
const { windowSize: n, mask: r, maxNumber: i, shiftBy: o } = s;
|
|
1263
|
+
let a = Number(e & r), c = e >> o;
|
|
1264
|
+
a > n && (a -= i, c += Ot);
|
|
1265
|
+
const l = t * n, h = l + Math.abs(a) - 1, u = a === 0, f = a < 0, d = t % 2 !== 0;
|
|
1266
|
+
return { nextN: c, offset: h, isZero: u, isNeg: f, isNegF: d, offsetF: l };
|
|
1267
|
+
}
|
|
1268
|
+
function mr(e, t) {
|
|
1269
|
+
if (!Array.isArray(e))
|
|
1270
|
+
throw new Error("array expected");
|
|
1271
|
+
e.forEach((s, n) => {
|
|
1272
|
+
if (!(s instanceof t))
|
|
1273
|
+
throw new Error("invalid point at index " + n);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
function Er(e, t) {
|
|
1277
|
+
if (!Array.isArray(e))
|
|
1278
|
+
throw new Error("array of scalars expected");
|
|
1279
|
+
e.forEach((s, n) => {
|
|
1280
|
+
if (!t.isValid(s))
|
|
1281
|
+
throw new Error("invalid scalar at index " + n);
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
const Ee = /* @__PURE__ */ new WeakMap(), Ln = /* @__PURE__ */ new WeakMap();
|
|
1285
|
+
function xe(e) {
|
|
1286
|
+
return Ln.get(e) || 1;
|
|
1287
|
+
}
|
|
1288
|
+
function an(e) {
|
|
1289
|
+
if (e !== Ft)
|
|
1290
|
+
throw new Error("invalid wNAF");
|
|
1291
|
+
}
|
|
1292
|
+
class xr {
|
|
1293
|
+
// Parametrized with a given Point class (not individual point)
|
|
1294
|
+
constructor(t, s) {
|
|
1295
|
+
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = s;
|
|
1296
|
+
}
|
|
1297
|
+
// non-const time multiplication ladder
|
|
1298
|
+
_unsafeLadder(t, s, n = this.ZERO) {
|
|
1299
|
+
let r = t;
|
|
1300
|
+
for (; s > Ft; )
|
|
1301
|
+
s & Ot && (n = n.add(r)), r = r.double(), s >>= Ot;
|
|
1302
|
+
return n;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
1306
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
1307
|
+
* Number of precomputed points depends on the curve size:
|
|
1308
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
1309
|
+
* - 𝑊 is the window size
|
|
1310
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
1311
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
1312
|
+
* @param point Point instance
|
|
1313
|
+
* @param W window size
|
|
1314
|
+
* @returns precomputed point tables flattened to a single array
|
|
1315
|
+
*/
|
|
1316
|
+
precomputeWindow(t, s) {
|
|
1317
|
+
const { windows: n, windowSize: r } = me(s, this.bits), i = [];
|
|
1318
|
+
let o = t, a = o;
|
|
1319
|
+
for (let c = 0; c < n; c++) {
|
|
1320
|
+
a = o, i.push(a);
|
|
1321
|
+
for (let l = 1; l < r; l++)
|
|
1322
|
+
a = a.add(o), i.push(a);
|
|
1323
|
+
o = a.double();
|
|
1324
|
+
}
|
|
1325
|
+
return i;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1329
|
+
* More compact implementation:
|
|
1330
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
1331
|
+
* @returns real and fake (for const-time) points
|
|
1332
|
+
*/
|
|
1333
|
+
wNAF(t, s, n) {
|
|
1334
|
+
if (!this.Fn.isValid(n))
|
|
1335
|
+
throw new Error("invalid scalar");
|
|
1336
|
+
let r = this.ZERO, i = this.BASE;
|
|
1337
|
+
const o = me(t, this.bits);
|
|
1338
|
+
for (let a = 0; a < o.windows; a++) {
|
|
1339
|
+
const { nextN: c, offset: l, isZero: h, isNeg: u, isNegF: f, offsetF: d } = on(n, a, o);
|
|
1340
|
+
n = c, h ? i = i.add(ue(f, s[d])) : r = r.add(ue(u, s[l]));
|
|
1341
|
+
}
|
|
1342
|
+
return an(n), { p: r, f: i };
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
1346
|
+
* @param acc accumulator point to add result of multiplication
|
|
1347
|
+
* @returns point
|
|
1348
|
+
*/
|
|
1349
|
+
wNAFUnsafe(t, s, n, r = this.ZERO) {
|
|
1350
|
+
const i = me(t, this.bits);
|
|
1351
|
+
for (let o = 0; o < i.windows && n !== Ft; o++) {
|
|
1352
|
+
const { nextN: a, offset: c, isZero: l, isNeg: h } = on(n, o, i);
|
|
1353
|
+
if (n = a, !l) {
|
|
1354
|
+
const u = s[c];
|
|
1355
|
+
r = r.add(h ? u.negate() : u);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
return an(n), r;
|
|
1359
|
+
}
|
|
1360
|
+
getPrecomputes(t, s, n) {
|
|
1361
|
+
let r = Ee.get(s);
|
|
1362
|
+
return r || (r = this.precomputeWindow(s, t), t !== 1 && (typeof n == "function" && (r = n(r)), Ee.set(s, r))), r;
|
|
1363
|
+
}
|
|
1364
|
+
cached(t, s, n) {
|
|
1365
|
+
const r = xe(t);
|
|
1366
|
+
return this.wNAF(r, this.getPrecomputes(r, t, n), s);
|
|
1367
|
+
}
|
|
1368
|
+
unsafe(t, s, n, r) {
|
|
1369
|
+
const i = xe(t);
|
|
1370
|
+
return i === 1 ? this._unsafeLadder(t, s, r) : this.wNAFUnsafe(i, this.getPrecomputes(i, t, n), s, r);
|
|
1371
|
+
}
|
|
1372
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
1373
|
+
// using windowed method. This specifies window size and
|
|
1374
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
1375
|
+
createCache(t, s) {
|
|
1376
|
+
kn(s, this.bits), Ln.set(t, s), Ee.delete(t);
|
|
1377
|
+
}
|
|
1378
|
+
hasCache(t) {
|
|
1379
|
+
return xe(t) !== 1;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
function Sr(e, t, s, n) {
|
|
1383
|
+
let r = t, i = e.ZERO, o = e.ZERO;
|
|
1384
|
+
for (; s > Ft || n > Ft; )
|
|
1385
|
+
s & Ot && (i = i.add(r)), n & Ot && (o = o.add(r)), r = r.double(), s >>= Ot, n >>= Ot;
|
|
1386
|
+
return { p1: i, p2: o };
|
|
1387
|
+
}
|
|
1388
|
+
function Ir(e, t, s, n) {
|
|
1389
|
+
mr(s, e), Er(n, t);
|
|
1390
|
+
const r = s.length, i = n.length;
|
|
1391
|
+
if (r !== i)
|
|
1392
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
1393
|
+
const o = e.ZERO, a = On(BigInt(r));
|
|
1394
|
+
let c = 1;
|
|
1395
|
+
a > 12 ? c = a - 3 : a > 4 ? c = a - 2 : a > 0 && (c = 2);
|
|
1396
|
+
const l = Wt(c), h = new Array(Number(l) + 1).fill(o), u = Math.floor((t.BITS - 1) / c) * c;
|
|
1397
|
+
let f = o;
|
|
1398
|
+
for (let d = u; d >= 0; d -= c) {
|
|
1399
|
+
h.fill(o);
|
|
1400
|
+
for (let m = 0; m < i; m++) {
|
|
1401
|
+
const R = n[m], _ = Number(R >> BigInt(d) & l);
|
|
1402
|
+
h[_] = h[_].add(s[m]);
|
|
1403
|
+
}
|
|
1404
|
+
let p = o;
|
|
1405
|
+
for (let m = h.length - 1, R = o; m > 0; m--)
|
|
1406
|
+
R = R.add(h[m]), p = p.add(R);
|
|
1407
|
+
if (f = f.add(p), d !== 0)
|
|
1408
|
+
for (let m = 0; m < c; m++)
|
|
1409
|
+
f = f.double();
|
|
1410
|
+
}
|
|
1411
|
+
return f;
|
|
1412
|
+
}
|
|
1413
|
+
function cn(e, t, s) {
|
|
1414
|
+
if (t) {
|
|
1415
|
+
if (t.ORDER !== e)
|
|
1416
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
1417
|
+
return br(t), t;
|
|
1418
|
+
} else
|
|
1419
|
+
return Tt(e, { isLE: s });
|
|
1420
|
+
}
|
|
1421
|
+
function vr(e, t, s = {}, n) {
|
|
1422
|
+
if (n === void 0 && (n = e === "edwards"), !t || typeof t != "object")
|
|
1423
|
+
throw new Error(`expected valid ${e} CURVE object`);
|
|
1424
|
+
for (const c of ["p", "n", "h"]) {
|
|
1425
|
+
const l = t[c];
|
|
1426
|
+
if (!(typeof l == "bigint" && l > Ft))
|
|
1427
|
+
throw new Error(`CURVE.${c} must be positive bigint`);
|
|
1428
|
+
}
|
|
1429
|
+
const r = cn(t.p, s.Fp, n), i = cn(t.n, s.Fn, n), a = ["Gx", "Gy", "a", "b"];
|
|
1430
|
+
for (const c of a)
|
|
1431
|
+
if (!r.isValid(t[c]))
|
|
1432
|
+
throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
|
|
1433
|
+
return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: r, Fn: i };
|
|
1434
|
+
}
|
|
1435
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
1436
|
+
const fn = (e, t) => (e + (e >= 0 ? t : -t) / Kn) / t;
|
|
1437
|
+
function Ar(e, t, s) {
|
|
1438
|
+
const [[n, r], [i, o]] = t, a = fn(o * e, s), c = fn(-r * e, s);
|
|
1439
|
+
let l = e - a * n - c * i, h = -a * r - c * o;
|
|
1440
|
+
const u = l < gt, f = h < gt;
|
|
1441
|
+
u && (l = -l), f && (h = -h);
|
|
1442
|
+
const d = Wt(Math.ceil(On(s) / 2)) + kt;
|
|
1443
|
+
if (l < gt || l >= d || h < gt || h >= d)
|
|
1444
|
+
throw new Error("splitScalar (endomorphism): failed, k=" + e);
|
|
1445
|
+
return { k1neg: u, k1: l, k2neg: f, k2: h };
|
|
1446
|
+
}
|
|
1447
|
+
function Ce(e) {
|
|
1448
|
+
if (!["compact", "recovered", "der"].includes(e))
|
|
1449
|
+
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
1450
|
+
return e;
|
|
1451
|
+
}
|
|
1452
|
+
function Se(e, t) {
|
|
1453
|
+
const s = {};
|
|
1454
|
+
for (let n of Object.keys(t))
|
|
1455
|
+
s[n] = e[n] === void 0 ? t[n] : e[n];
|
|
1456
|
+
return fe(s.lowS, "lowS"), fe(s.prehash, "prehash"), s.format !== void 0 && Ce(s.format), s;
|
|
1457
|
+
}
|
|
1458
|
+
class Or extends Error {
|
|
1459
|
+
constructor(t = "") {
|
|
1460
|
+
super(t);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
const dt = {
|
|
1464
|
+
// asn.1 DER encoding utils
|
|
1465
|
+
Err: Or,
|
|
1466
|
+
// Basic building block is TLV (Tag-Length-Value)
|
|
1467
|
+
_tlv: {
|
|
1468
|
+
encode: (e, t) => {
|
|
1469
|
+
const { Err: s } = dt;
|
|
1470
|
+
if (e < 0 || e > 256)
|
|
1471
|
+
throw new s("tlv.encode: wrong tag");
|
|
1472
|
+
if (t.length & 1)
|
|
1473
|
+
throw new s("tlv.encode: unpadded data");
|
|
1474
|
+
const n = t.length / 2, r = te(n);
|
|
1475
|
+
if (r.length / 2 & 128)
|
|
1476
|
+
throw new s("tlv.encode: long form length too big");
|
|
1477
|
+
const i = n > 127 ? te(r.length / 2 | 128) : "";
|
|
1478
|
+
return te(e) + i + r + t;
|
|
1479
|
+
},
|
|
1480
|
+
// v - value, l - left bytes (unparsed)
|
|
1481
|
+
decode(e, t) {
|
|
1482
|
+
const { Err: s } = dt;
|
|
1483
|
+
let n = 0;
|
|
1484
|
+
if (e < 0 || e > 256)
|
|
1485
|
+
throw new s("tlv.encode: wrong tag");
|
|
1486
|
+
if (t.length < 2 || t[n++] !== e)
|
|
1487
|
+
throw new s("tlv.decode: wrong tlv");
|
|
1488
|
+
const r = t[n++], i = !!(r & 128);
|
|
1489
|
+
let o = 0;
|
|
1490
|
+
if (!i)
|
|
1491
|
+
o = r;
|
|
1492
|
+
else {
|
|
1493
|
+
const c = r & 127;
|
|
1494
|
+
if (!c)
|
|
1495
|
+
throw new s("tlv.decode(long): indefinite length not supported");
|
|
1496
|
+
if (c > 4)
|
|
1497
|
+
throw new s("tlv.decode(long): byte length is too big");
|
|
1498
|
+
const l = t.subarray(n, n + c);
|
|
1499
|
+
if (l.length !== c)
|
|
1500
|
+
throw new s("tlv.decode: length bytes not complete");
|
|
1501
|
+
if (l[0] === 0)
|
|
1502
|
+
throw new s("tlv.decode(long): zero leftmost byte");
|
|
1503
|
+
for (const h of l)
|
|
1504
|
+
o = o << 8 | h;
|
|
1505
|
+
if (n += c, o < 128)
|
|
1506
|
+
throw new s("tlv.decode(long): not minimal encoding");
|
|
1507
|
+
}
|
|
1508
|
+
const a = t.subarray(n, n + o);
|
|
1509
|
+
if (a.length !== o)
|
|
1510
|
+
throw new s("tlv.decode: wrong value length");
|
|
1511
|
+
return { v: a, l: t.subarray(n + o) };
|
|
1512
|
+
}
|
|
1513
|
+
},
|
|
1514
|
+
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
1515
|
+
// since we always use positive integers here. It must always be empty:
|
|
1516
|
+
// - add zero byte if exists
|
|
1517
|
+
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
1518
|
+
_int: {
|
|
1519
|
+
encode(e) {
|
|
1520
|
+
const { Err: t } = dt;
|
|
1521
|
+
if (e < gt)
|
|
1522
|
+
throw new t("integer: negative integers are not allowed");
|
|
1523
|
+
let s = te(e);
|
|
1524
|
+
if (Number.parseInt(s[0], 16) & 8 && (s = "00" + s), s.length & 1)
|
|
1525
|
+
throw new t("unexpected DER parsing assertion: unpadded hex");
|
|
1526
|
+
return s;
|
|
1527
|
+
},
|
|
1528
|
+
decode(e) {
|
|
1529
|
+
const { Err: t } = dt;
|
|
1530
|
+
if (e[0] & 128)
|
|
1531
|
+
throw new t("invalid signature integer: negative");
|
|
1532
|
+
if (e[0] === 0 && !(e[1] & 128))
|
|
1533
|
+
throw new t("invalid signature integer: unnecessary leading zero");
|
|
1534
|
+
return ge(e);
|
|
1535
|
+
}
|
|
1536
|
+
},
|
|
1537
|
+
toSig(e) {
|
|
1538
|
+
const { Err: t, _int: s, _tlv: n } = dt, r = z("signature", e), { v: i, l: o } = n.decode(48, r);
|
|
1539
|
+
if (o.length)
|
|
1540
|
+
throw new t("invalid signature: left bytes after parsing");
|
|
1541
|
+
const { v: a, l: c } = n.decode(2, i), { v: l, l: h } = n.decode(2, c);
|
|
1542
|
+
if (h.length)
|
|
1543
|
+
throw new t("invalid signature: left bytes after parsing");
|
|
1544
|
+
return { r: s.decode(a), s: s.decode(l) };
|
|
1545
|
+
},
|
|
1546
|
+
hexFromSig(e) {
|
|
1547
|
+
const { _tlv: t, _int: s } = dt, n = t.encode(2, s.encode(e.r)), r = t.encode(2, s.encode(e.s)), i = n + r;
|
|
1548
|
+
return t.encode(48, i);
|
|
1549
|
+
}
|
|
1550
|
+
}, gt = BigInt(0), kt = BigInt(1), Kn = BigInt(2), ee = BigInt(3), Br = BigInt(4);
|
|
1551
|
+
function Vt(e, t) {
|
|
1552
|
+
const { BYTES: s } = e;
|
|
1553
|
+
let n;
|
|
1554
|
+
if (typeof t == "bigint")
|
|
1555
|
+
n = t;
|
|
1556
|
+
else {
|
|
1557
|
+
let r = z("private key", t);
|
|
1558
|
+
try {
|
|
1559
|
+
n = e.fromBytes(r);
|
|
1560
|
+
} catch {
|
|
1561
|
+
throw new Error(`invalid private key: expected ui8a of size ${s}, got ${typeof t}`);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
if (!e.isValidNot0(n))
|
|
1565
|
+
throw new Error("invalid private key: out of range [1..N-1]");
|
|
1566
|
+
return n;
|
|
1567
|
+
}
|
|
1568
|
+
function Rr(e, t = {}) {
|
|
1569
|
+
const s = vr("weierstrass", e, t), { Fp: n, Fn: r } = s;
|
|
1570
|
+
let i = s.CURVE;
|
|
1571
|
+
const { h: o, n: a } = i;
|
|
1572
|
+
He(t, {}, {
|
|
1573
|
+
allowInfinityPoint: "boolean",
|
|
1574
|
+
clearCofactor: "function",
|
|
1575
|
+
isTorsionFree: "function",
|
|
1576
|
+
fromBytes: "function",
|
|
1577
|
+
toBytes: "function",
|
|
1578
|
+
endo: "object",
|
|
1579
|
+
wrapPrivateKey: "boolean"
|
|
1580
|
+
});
|
|
1581
|
+
const { endo: c } = t;
|
|
1582
|
+
if (c && (!n.is0(i.a) || typeof c.beta != "bigint" || !Array.isArray(c.basises)))
|
|
1583
|
+
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
1584
|
+
const l = Fn(n, r);
|
|
1585
|
+
function h() {
|
|
1586
|
+
if (!n.isOdd)
|
|
1587
|
+
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
1588
|
+
}
|
|
1589
|
+
function u(T, b, w) {
|
|
1590
|
+
const { x: g, y } = b.toAffine(), E = n.toBytes(g);
|
|
1591
|
+
if (fe(w, "isCompressed"), w) {
|
|
1592
|
+
h();
|
|
1593
|
+
const v = !n.isOdd(y);
|
|
1594
|
+
return xt(Pn(v), E);
|
|
1595
|
+
} else
|
|
1596
|
+
return xt(Uint8Array.of(4), E, n.toBytes(y));
|
|
1597
|
+
}
|
|
1598
|
+
function f(T) {
|
|
1599
|
+
vt(T, void 0, "Point");
|
|
1600
|
+
const { publicKey: b, publicKeyUncompressed: w } = l, g = T.length, y = T[0], E = T.subarray(1);
|
|
1601
|
+
if (g === b && (y === 2 || y === 3)) {
|
|
1602
|
+
const v = n.fromBytes(E);
|
|
1603
|
+
if (!n.isValid(v))
|
|
1604
|
+
throw new Error("bad point: is not on curve, wrong x");
|
|
1605
|
+
const I = m(v);
|
|
1606
|
+
let x;
|
|
1607
|
+
try {
|
|
1608
|
+
x = n.sqrt(I);
|
|
1609
|
+
} catch (k) {
|
|
1610
|
+
const N = k instanceof Error ? ": " + k.message : "";
|
|
1611
|
+
throw new Error("bad point: is not on curve, sqrt error" + N);
|
|
1612
|
+
}
|
|
1613
|
+
h();
|
|
1614
|
+
const O = n.isOdd(x);
|
|
1615
|
+
return (y & 1) === 1 !== O && (x = n.neg(x)), { x: v, y: x };
|
|
1616
|
+
} else if (g === w && y === 4) {
|
|
1617
|
+
const v = n.BYTES, I = n.fromBytes(E.subarray(0, v)), x = n.fromBytes(E.subarray(v, v * 2));
|
|
1618
|
+
if (!R(I, x))
|
|
1619
|
+
throw new Error("bad point: is not on curve");
|
|
1620
|
+
return { x: I, y: x };
|
|
1621
|
+
} else
|
|
1622
|
+
throw new Error(`bad point: got length ${g}, expected compressed=${b} or uncompressed=${w}`);
|
|
1623
|
+
}
|
|
1624
|
+
const d = t.toBytes || u, p = t.fromBytes || f;
|
|
1625
|
+
function m(T) {
|
|
1626
|
+
const b = n.sqr(T), w = n.mul(b, T);
|
|
1627
|
+
return n.add(n.add(w, n.mul(T, i.a)), i.b);
|
|
1628
|
+
}
|
|
1629
|
+
function R(T, b) {
|
|
1630
|
+
const w = n.sqr(b), g = m(T);
|
|
1631
|
+
return n.eql(w, g);
|
|
1632
|
+
}
|
|
1633
|
+
if (!R(i.Gx, i.Gy))
|
|
1634
|
+
throw new Error("bad curve params: generator point");
|
|
1635
|
+
const _ = n.mul(n.pow(i.a, ee), Br), et = n.mul(n.sqr(i.b), BigInt(27));
|
|
1636
|
+
if (n.is0(n.add(_, et)))
|
|
1637
|
+
throw new Error("bad curve params: a or b");
|
|
1638
|
+
function A(T, b, w = !1) {
|
|
1639
|
+
if (!n.isValid(b) || w && n.is0(b))
|
|
1640
|
+
throw new Error(`bad point coordinate ${T}`);
|
|
1641
|
+
return b;
|
|
1642
|
+
}
|
|
1643
|
+
function q(T) {
|
|
1644
|
+
if (!(T instanceof B))
|
|
1645
|
+
throw new Error("ProjectivePoint expected");
|
|
1646
|
+
}
|
|
1647
|
+
function K(T) {
|
|
1648
|
+
if (!c || !c.basises)
|
|
1649
|
+
throw new Error("no endo");
|
|
1650
|
+
return Ar(T, c.basises, r.ORDER);
|
|
1651
|
+
}
|
|
1652
|
+
const ot = nn((T, b) => {
|
|
1653
|
+
const { X: w, Y: g, Z: y } = T;
|
|
1654
|
+
if (n.eql(y, n.ONE))
|
|
1655
|
+
return { x: w, y: g };
|
|
1656
|
+
const E = T.is0();
|
|
1657
|
+
b == null && (b = E ? n.ONE : n.inv(y));
|
|
1658
|
+
const v = n.mul(w, b), I = n.mul(g, b), x = n.mul(y, b);
|
|
1659
|
+
if (E)
|
|
1660
|
+
return { x: n.ZERO, y: n.ZERO };
|
|
1661
|
+
if (!n.eql(x, n.ONE))
|
|
1662
|
+
throw new Error("invZ was invalid");
|
|
1663
|
+
return { x: v, y: I };
|
|
1664
|
+
}), bt = nn((T) => {
|
|
1665
|
+
if (T.is0()) {
|
|
1666
|
+
if (t.allowInfinityPoint && !n.is0(T.Y))
|
|
1667
|
+
return;
|
|
1668
|
+
throw new Error("bad point: ZERO");
|
|
1669
|
+
}
|
|
1670
|
+
const { x: b, y: w } = T.toAffine();
|
|
1671
|
+
if (!n.isValid(b) || !n.isValid(w))
|
|
1672
|
+
throw new Error("bad point: x or y not field elements");
|
|
1673
|
+
if (!R(b, w))
|
|
1674
|
+
throw new Error("bad point: equation left != right");
|
|
1675
|
+
if (!T.isTorsionFree())
|
|
1676
|
+
throw new Error("bad point: not in prime-order subgroup");
|
|
1677
|
+
return !0;
|
|
1678
|
+
});
|
|
1679
|
+
function F(T, b, w, g, y) {
|
|
1680
|
+
return w = new B(n.mul(w.X, T), w.Y, w.Z), b = ue(g, b), w = ue(y, w), b.add(w);
|
|
1681
|
+
}
|
|
1682
|
+
class B {
|
|
1683
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1684
|
+
constructor(b, w, g) {
|
|
1685
|
+
this.X = A("x", b), this.Y = A("y", w, !0), this.Z = A("z", g), Object.freeze(this);
|
|
1686
|
+
}
|
|
1687
|
+
static CURVE() {
|
|
1688
|
+
return i;
|
|
1689
|
+
}
|
|
1690
|
+
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
1691
|
+
static fromAffine(b) {
|
|
1692
|
+
const { x: w, y: g } = b || {};
|
|
1693
|
+
if (!b || !n.isValid(w) || !n.isValid(g))
|
|
1694
|
+
throw new Error("invalid affine point");
|
|
1695
|
+
if (b instanceof B)
|
|
1696
|
+
throw new Error("projective point not allowed");
|
|
1697
|
+
return n.is0(w) && n.is0(g) ? B.ZERO : new B(w, g, n.ONE);
|
|
1698
|
+
}
|
|
1699
|
+
static fromBytes(b) {
|
|
1700
|
+
const w = B.fromAffine(p(vt(b, void 0, "point")));
|
|
1701
|
+
return w.assertValidity(), w;
|
|
1702
|
+
}
|
|
1703
|
+
static fromHex(b) {
|
|
1704
|
+
return B.fromBytes(z("pointHex", b));
|
|
1705
|
+
}
|
|
1706
|
+
get x() {
|
|
1707
|
+
return this.toAffine().x;
|
|
1708
|
+
}
|
|
1709
|
+
get y() {
|
|
1710
|
+
return this.toAffine().y;
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
*
|
|
1714
|
+
* @param windowSize
|
|
1715
|
+
* @param isLazy true will defer table computation until the first multiplication
|
|
1716
|
+
* @returns
|
|
1717
|
+
*/
|
|
1718
|
+
precompute(b = 8, w = !0) {
|
|
1719
|
+
return nt.createCache(this, b), w || this.multiply(ee), this;
|
|
1720
|
+
}
|
|
1721
|
+
// TODO: return `this`
|
|
1722
|
+
/** A point on curve is valid if it conforms to equation. */
|
|
1723
|
+
assertValidity() {
|
|
1724
|
+
bt(this);
|
|
1725
|
+
}
|
|
1726
|
+
hasEvenY() {
|
|
1727
|
+
const { y: b } = this.toAffine();
|
|
1728
|
+
if (!n.isOdd)
|
|
1729
|
+
throw new Error("Field doesn't support isOdd");
|
|
1730
|
+
return !n.isOdd(b);
|
|
1731
|
+
}
|
|
1732
|
+
/** Compare one point to another. */
|
|
1733
|
+
equals(b) {
|
|
1734
|
+
q(b);
|
|
1735
|
+
const { X: w, Y: g, Z: y } = this, { X: E, Y: v, Z: I } = b, x = n.eql(n.mul(w, I), n.mul(E, y)), O = n.eql(n.mul(g, I), n.mul(v, y));
|
|
1736
|
+
return x && O;
|
|
1737
|
+
}
|
|
1738
|
+
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
1739
|
+
negate() {
|
|
1740
|
+
return new B(this.X, n.neg(this.Y), this.Z);
|
|
1741
|
+
}
|
|
1742
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
1743
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1744
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1745
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1746
|
+
double() {
|
|
1747
|
+
const { a: b, b: w } = i, g = n.mul(w, ee), { X: y, Y: E, Z: v } = this;
|
|
1748
|
+
let I = n.ZERO, x = n.ZERO, O = n.ZERO, C = n.mul(y, y), k = n.mul(E, E), N = n.mul(v, v), D = n.mul(y, E);
|
|
1749
|
+
return D = n.add(D, D), O = n.mul(y, v), O = n.add(O, O), I = n.mul(b, O), x = n.mul(g, N), x = n.add(I, x), I = n.sub(k, x), x = n.add(k, x), x = n.mul(I, x), I = n.mul(D, I), O = n.mul(g, O), N = n.mul(b, N), D = n.sub(C, N), D = n.mul(b, D), D = n.add(D, O), O = n.add(C, C), C = n.add(O, C), C = n.add(C, N), C = n.mul(C, D), x = n.add(x, C), N = n.mul(E, v), N = n.add(N, N), C = n.mul(N, D), I = n.sub(I, C), O = n.mul(N, k), O = n.add(O, O), O = n.add(O, O), new B(I, x, O);
|
|
1750
|
+
}
|
|
1751
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
1752
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1753
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1754
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1755
|
+
add(b) {
|
|
1756
|
+
q(b);
|
|
1757
|
+
const { X: w, Y: g, Z: y } = this, { X: E, Y: v, Z: I } = b;
|
|
1758
|
+
let x = n.ZERO, O = n.ZERO, C = n.ZERO;
|
|
1759
|
+
const k = i.a, N = n.mul(i.b, ee);
|
|
1760
|
+
let D = n.mul(w, E), V = n.mul(g, v), L = n.mul(y, I), Y = n.add(w, g), j = n.add(E, v);
|
|
1761
|
+
Y = n.mul(Y, j), j = n.add(D, V), Y = n.sub(Y, j), j = n.add(w, y);
|
|
1762
|
+
let G = n.add(E, I);
|
|
1763
|
+
return j = n.mul(j, G), G = n.add(D, L), j = n.sub(j, G), G = n.add(g, y), x = n.add(v, I), G = n.mul(G, x), x = n.add(V, L), G = n.sub(G, x), C = n.mul(k, j), x = n.mul(N, L), C = n.add(x, C), x = n.sub(V, C), C = n.add(V, C), O = n.mul(x, C), V = n.add(D, D), V = n.add(V, D), L = n.mul(k, L), j = n.mul(N, j), V = n.add(V, L), L = n.sub(D, L), L = n.mul(k, L), j = n.add(j, L), D = n.mul(V, j), O = n.add(O, D), D = n.mul(G, j), x = n.mul(Y, x), x = n.sub(x, D), D = n.mul(Y, V), C = n.mul(G, C), C = n.add(C, D), new B(x, O, C);
|
|
1764
|
+
}
|
|
1765
|
+
subtract(b) {
|
|
1766
|
+
return this.add(b.negate());
|
|
1767
|
+
}
|
|
1768
|
+
is0() {
|
|
1769
|
+
return this.equals(B.ZERO);
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Constant time multiplication.
|
|
1773
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1774
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
1775
|
+
* Uses precomputes when available.
|
|
1776
|
+
* Uses endomorphism for Koblitz curves.
|
|
1777
|
+
* @param scalar by which the point would be multiplied
|
|
1778
|
+
* @returns New point
|
|
1779
|
+
*/
|
|
1780
|
+
multiply(b) {
|
|
1781
|
+
const { endo: w } = t;
|
|
1782
|
+
if (!r.isValidNot0(b))
|
|
1783
|
+
throw new Error("invalid scalar: out of range");
|
|
1784
|
+
let g, y;
|
|
1785
|
+
const E = (v) => nt.cached(this, v, (I) => ye(B, I));
|
|
1786
|
+
if (w) {
|
|
1787
|
+
const { k1neg: v, k1: I, k2neg: x, k2: O } = K(b), { p: C, f: k } = E(I), { p: N, f: D } = E(O);
|
|
1788
|
+
y = k.add(D), g = F(w.beta, C, N, v, x);
|
|
1789
|
+
} else {
|
|
1790
|
+
const { p: v, f: I } = E(b);
|
|
1791
|
+
g = v, y = I;
|
|
1792
|
+
}
|
|
1793
|
+
return ye(B, [g, y])[0];
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1797
|
+
* It's faster, but should only be used when you don't care about
|
|
1798
|
+
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
1799
|
+
*/
|
|
1800
|
+
multiplyUnsafe(b) {
|
|
1801
|
+
const { endo: w } = t, g = this;
|
|
1802
|
+
if (!r.isValid(b))
|
|
1803
|
+
throw new Error("invalid scalar: out of range");
|
|
1804
|
+
if (b === gt || g.is0())
|
|
1805
|
+
return B.ZERO;
|
|
1806
|
+
if (b === kt)
|
|
1807
|
+
return g;
|
|
1808
|
+
if (nt.hasCache(this))
|
|
1809
|
+
return this.multiply(b);
|
|
1810
|
+
if (w) {
|
|
1811
|
+
const { k1neg: y, k1: E, k2neg: v, k2: I } = K(b), { p1: x, p2: O } = Sr(B, g, E, I);
|
|
1812
|
+
return F(w.beta, x, O, y, v);
|
|
1813
|
+
} else
|
|
1814
|
+
return nt.unsafe(g, b);
|
|
1815
|
+
}
|
|
1816
|
+
multiplyAndAddUnsafe(b, w, g) {
|
|
1817
|
+
const y = this.multiplyUnsafe(w).add(b.multiplyUnsafe(g));
|
|
1818
|
+
return y.is0() ? void 0 : y;
|
|
1819
|
+
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Converts Projective point to affine (x, y) coordinates.
|
|
1822
|
+
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
1823
|
+
*/
|
|
1824
|
+
toAffine(b) {
|
|
1825
|
+
return ot(this, b);
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
1829
|
+
* Always torsion-free for cofactor=1 curves.
|
|
1830
|
+
*/
|
|
1831
|
+
isTorsionFree() {
|
|
1832
|
+
const { isTorsionFree: b } = t;
|
|
1833
|
+
return o === kt ? !0 : b ? b(B, this) : nt.unsafe(this, a).is0();
|
|
1834
|
+
}
|
|
1835
|
+
clearCofactor() {
|
|
1836
|
+
const { clearCofactor: b } = t;
|
|
1837
|
+
return o === kt ? this : b ? b(B, this) : this.multiplyUnsafe(o);
|
|
1838
|
+
}
|
|
1839
|
+
isSmallOrder() {
|
|
1840
|
+
return this.multiplyUnsafe(o).is0();
|
|
1841
|
+
}
|
|
1842
|
+
toBytes(b = !0) {
|
|
1843
|
+
return fe(b, "isCompressed"), this.assertValidity(), d(B, this, b);
|
|
1844
|
+
}
|
|
1845
|
+
toHex(b = !0) {
|
|
1846
|
+
return jt(this.toBytes(b));
|
|
1847
|
+
}
|
|
1848
|
+
toString() {
|
|
1849
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1850
|
+
}
|
|
1851
|
+
// TODO: remove
|
|
1852
|
+
get px() {
|
|
1853
|
+
return this.X;
|
|
1854
|
+
}
|
|
1855
|
+
get py() {
|
|
1856
|
+
return this.X;
|
|
1857
|
+
}
|
|
1858
|
+
get pz() {
|
|
1859
|
+
return this.Z;
|
|
1860
|
+
}
|
|
1861
|
+
toRawBytes(b = !0) {
|
|
1862
|
+
return this.toBytes(b);
|
|
1863
|
+
}
|
|
1864
|
+
_setWindowSize(b) {
|
|
1865
|
+
this.precompute(b);
|
|
1866
|
+
}
|
|
1867
|
+
static normalizeZ(b) {
|
|
1868
|
+
return ye(B, b);
|
|
1869
|
+
}
|
|
1870
|
+
static msm(b, w) {
|
|
1871
|
+
return Ir(B, r, b, w);
|
|
1872
|
+
}
|
|
1873
|
+
static fromPrivateKey(b) {
|
|
1874
|
+
return B.BASE.multiply(Vt(r, b));
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
B.BASE = new B(i.Gx, i.Gy, n.ONE), B.ZERO = new B(n.ZERO, n.ONE, n.ZERO), B.Fp = n, B.Fn = r;
|
|
1878
|
+
const ft = r.BITS, nt = new xr(B, t.endo ? Math.ceil(ft / 2) : ft);
|
|
1879
|
+
return B.BASE.precompute(8), B;
|
|
1880
|
+
}
|
|
1881
|
+
function Pn(e) {
|
|
1882
|
+
return Uint8Array.of(e ? 2 : 3);
|
|
1883
|
+
}
|
|
1884
|
+
function Fn(e, t) {
|
|
1885
|
+
return {
|
|
1886
|
+
secretKey: t.BYTES,
|
|
1887
|
+
publicKey: 1 + e.BYTES,
|
|
1888
|
+
publicKeyUncompressed: 1 + 2 * e.BYTES,
|
|
1889
|
+
publicKeyHasPrefix: !0,
|
|
1890
|
+
signature: 2 * t.BYTES
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
function Cr(e, t = {}) {
|
|
1894
|
+
const { Fn: s } = e, n = t.randomBytes || pn, r = Object.assign(Fn(e.Fp, s), { seed: jn(s.ORDER) });
|
|
1895
|
+
function i(d) {
|
|
1896
|
+
try {
|
|
1897
|
+
return !!Vt(s, d);
|
|
1898
|
+
} catch {
|
|
1899
|
+
return !1;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
function o(d, p) {
|
|
1903
|
+
const { publicKey: m, publicKeyUncompressed: R } = r;
|
|
1904
|
+
try {
|
|
1905
|
+
const _ = d.length;
|
|
1906
|
+
return p === !0 && _ !== m || p === !1 && _ !== R ? !1 : !!e.fromBytes(d);
|
|
1907
|
+
} catch {
|
|
1908
|
+
return !1;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
function a(d = n(r.seed)) {
|
|
1912
|
+
return yr(vt(d, r.seed, "seed"), s.ORDER);
|
|
1913
|
+
}
|
|
1914
|
+
function c(d, p = !0) {
|
|
1915
|
+
return e.BASE.multiply(Vt(s, d)).toBytes(p);
|
|
1916
|
+
}
|
|
1917
|
+
function l(d) {
|
|
1918
|
+
const p = a(d);
|
|
1919
|
+
return { secretKey: p, publicKey: c(p) };
|
|
1920
|
+
}
|
|
1921
|
+
function h(d) {
|
|
1922
|
+
if (typeof d == "bigint")
|
|
1923
|
+
return !1;
|
|
1924
|
+
if (d instanceof e)
|
|
1925
|
+
return !0;
|
|
1926
|
+
const { secretKey: p, publicKey: m, publicKeyUncompressed: R } = r;
|
|
1927
|
+
if (s.allowedLengths || p === m)
|
|
1928
|
+
return;
|
|
1929
|
+
const _ = z("key", d).length;
|
|
1930
|
+
return _ === m || _ === R;
|
|
1931
|
+
}
|
|
1932
|
+
function u(d, p, m = !0) {
|
|
1933
|
+
if (h(d) === !0)
|
|
1934
|
+
throw new Error("first arg must be private key");
|
|
1935
|
+
if (h(p) === !1)
|
|
1936
|
+
throw new Error("second arg must be public key");
|
|
1937
|
+
const R = Vt(s, d);
|
|
1938
|
+
return e.fromHex(p).multiply(R).toBytes(m);
|
|
1939
|
+
}
|
|
1940
|
+
return Object.freeze({ getPublicKey: c, getSharedSecret: u, keygen: l, Point: e, utils: {
|
|
1941
|
+
isValidSecretKey: i,
|
|
1942
|
+
isValidPublicKey: o,
|
|
1943
|
+
randomSecretKey: a,
|
|
1944
|
+
// TODO: remove
|
|
1945
|
+
isValidPrivateKey: i,
|
|
1946
|
+
randomPrivateKey: a,
|
|
1947
|
+
normPrivateKeyToScalar: (d) => Vt(s, d),
|
|
1948
|
+
precompute(d = 8, p = e.BASE) {
|
|
1949
|
+
return p.precompute(d, !1);
|
|
1950
|
+
}
|
|
1951
|
+
}, lengths: r });
|
|
1952
|
+
}
|
|
1953
|
+
function Tr(e, t, s = {}) {
|
|
1954
|
+
gn(t), He(s, {}, {
|
|
1955
|
+
hmac: "function",
|
|
1956
|
+
lowS: "boolean",
|
|
1957
|
+
randomBytes: "function",
|
|
1958
|
+
bits2int: "function",
|
|
1959
|
+
bits2int_modN: "function"
|
|
1960
|
+
});
|
|
1961
|
+
const n = s.randomBytes || pn, r = s.hmac || ((w, ...g) => Sn(t, w, xt(...g))), { Fp: i, Fn: o } = e, { ORDER: a, BITS: c } = o, { keygen: l, getPublicKey: h, getSharedSecret: u, utils: f, lengths: d } = Cr(e, s), p = {
|
|
1962
|
+
prehash: !1,
|
|
1963
|
+
lowS: typeof s.lowS == "boolean" ? s.lowS : !1,
|
|
1964
|
+
format: void 0,
|
|
1965
|
+
//'compact' as ECDSASigFormat,
|
|
1966
|
+
extraEntropy: !1
|
|
1967
|
+
}, m = "compact";
|
|
1968
|
+
function R(w) {
|
|
1969
|
+
const g = a >> kt;
|
|
1970
|
+
return w > g;
|
|
1971
|
+
}
|
|
1972
|
+
function _(w, g) {
|
|
1973
|
+
if (!o.isValidNot0(g))
|
|
1974
|
+
throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);
|
|
1975
|
+
return g;
|
|
1976
|
+
}
|
|
1977
|
+
function et(w, g) {
|
|
1978
|
+
Ce(g);
|
|
1979
|
+
const y = d.signature, E = g === "compact" ? y : g === "recovered" ? y + 1 : void 0;
|
|
1980
|
+
return vt(w, E, `${g} signature`);
|
|
1981
|
+
}
|
|
1982
|
+
class A {
|
|
1983
|
+
constructor(g, y, E) {
|
|
1984
|
+
this.r = _("r", g), this.s = _("s", y), E != null && (this.recovery = E), Object.freeze(this);
|
|
1985
|
+
}
|
|
1986
|
+
static fromBytes(g, y = m) {
|
|
1987
|
+
et(g, y);
|
|
1988
|
+
let E;
|
|
1989
|
+
if (y === "der") {
|
|
1990
|
+
const { r: O, s: C } = dt.toSig(vt(g));
|
|
1991
|
+
return new A(O, C);
|
|
1992
|
+
}
|
|
1993
|
+
y === "recovered" && (E = g[0], y = "compact", g = g.subarray(1));
|
|
1994
|
+
const v = o.BYTES, I = g.subarray(0, v), x = g.subarray(v, v * 2);
|
|
1995
|
+
return new A(o.fromBytes(I), o.fromBytes(x), E);
|
|
1996
|
+
}
|
|
1997
|
+
static fromHex(g, y) {
|
|
1998
|
+
return this.fromBytes(ce(g), y);
|
|
1999
|
+
}
|
|
2000
|
+
addRecoveryBit(g) {
|
|
2001
|
+
return new A(this.r, this.s, g);
|
|
2002
|
+
}
|
|
2003
|
+
recoverPublicKey(g) {
|
|
2004
|
+
const y = i.ORDER, { r: E, s: v, recovery: I } = this;
|
|
2005
|
+
if (I == null || ![0, 1, 2, 3].includes(I))
|
|
2006
|
+
throw new Error("recovery id invalid");
|
|
2007
|
+
if (a * Kn < y && I > 1)
|
|
2008
|
+
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
2009
|
+
const O = I === 2 || I === 3 ? E + a : E;
|
|
2010
|
+
if (!i.isValid(O))
|
|
2011
|
+
throw new Error("recovery id 2 or 3 invalid");
|
|
2012
|
+
const C = i.toBytes(O), k = e.fromBytes(xt(Pn((I & 1) === 0), C)), N = o.inv(O), D = K(z("msgHash", g)), V = o.create(-D * N), L = o.create(v * N), Y = e.BASE.multiplyUnsafe(V).add(k.multiplyUnsafe(L));
|
|
2013
|
+
if (Y.is0())
|
|
2014
|
+
throw new Error("point at infinify");
|
|
2015
|
+
return Y.assertValidity(), Y;
|
|
2016
|
+
}
|
|
2017
|
+
// Signatures should be low-s, to prevent malleability.
|
|
2018
|
+
hasHighS() {
|
|
2019
|
+
return R(this.s);
|
|
2020
|
+
}
|
|
2021
|
+
toBytes(g = m) {
|
|
2022
|
+
if (Ce(g), g === "der")
|
|
2023
|
+
return ce(dt.hexFromSig(this));
|
|
2024
|
+
const y = o.toBytes(this.r), E = o.toBytes(this.s);
|
|
2025
|
+
if (g === "recovered") {
|
|
2026
|
+
if (this.recovery == null)
|
|
2027
|
+
throw new Error("recovery bit must be present");
|
|
2028
|
+
return xt(Uint8Array.of(this.recovery), y, E);
|
|
2029
|
+
}
|
|
2030
|
+
return xt(y, E);
|
|
2031
|
+
}
|
|
2032
|
+
toHex(g) {
|
|
2033
|
+
return jt(this.toBytes(g));
|
|
2034
|
+
}
|
|
2035
|
+
// TODO: remove
|
|
2036
|
+
assertValidity() {
|
|
2037
|
+
}
|
|
2038
|
+
static fromCompact(g) {
|
|
2039
|
+
return A.fromBytes(z("sig", g), "compact");
|
|
2040
|
+
}
|
|
2041
|
+
static fromDER(g) {
|
|
2042
|
+
return A.fromBytes(z("sig", g), "der");
|
|
2043
|
+
}
|
|
2044
|
+
normalizeS() {
|
|
2045
|
+
return this.hasHighS() ? new A(this.r, o.neg(this.s), this.recovery) : this;
|
|
2046
|
+
}
|
|
2047
|
+
toDERRawBytes() {
|
|
2048
|
+
return this.toBytes("der");
|
|
2049
|
+
}
|
|
2050
|
+
toDERHex() {
|
|
2051
|
+
return jt(this.toBytes("der"));
|
|
2052
|
+
}
|
|
2053
|
+
toCompactRawBytes() {
|
|
2054
|
+
return this.toBytes("compact");
|
|
2055
|
+
}
|
|
2056
|
+
toCompactHex() {
|
|
2057
|
+
return jt(this.toBytes("compact"));
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
const q = s.bits2int || function(g) {
|
|
2061
|
+
if (g.length > 8192)
|
|
2062
|
+
throw new Error("input is too large");
|
|
2063
|
+
const y = ge(g), E = g.length * 8 - c;
|
|
2064
|
+
return E > 0 ? y >> BigInt(E) : y;
|
|
2065
|
+
}, K = s.bits2int_modN || function(g) {
|
|
2066
|
+
return o.create(q(g));
|
|
2067
|
+
}, ot = Wt(c);
|
|
2068
|
+
function bt(w) {
|
|
2069
|
+
return cr("num < 2^" + c, w, gt, ot), o.toBytes(w);
|
|
2070
|
+
}
|
|
2071
|
+
function F(w, g) {
|
|
2072
|
+
return vt(w, void 0, "message"), g ? vt(t(w), void 0, "prehashed message") : w;
|
|
2073
|
+
}
|
|
2074
|
+
function B(w, g, y) {
|
|
2075
|
+
if (["recovered", "canonical"].some((V) => V in y))
|
|
2076
|
+
throw new Error("sign() legacy options not supported");
|
|
2077
|
+
const { lowS: E, prehash: v, extraEntropy: I } = Se(y, p);
|
|
2078
|
+
w = F(w, v);
|
|
2079
|
+
const x = K(w), O = Vt(o, g), C = [bt(O), bt(x)];
|
|
2080
|
+
if (I != null && I !== !1) {
|
|
2081
|
+
const V = I === !0 ? n(d.secretKey) : I;
|
|
2082
|
+
C.push(z("extraEntropy", V));
|
|
2083
|
+
}
|
|
2084
|
+
const k = xt(...C), N = x;
|
|
2085
|
+
function D(V) {
|
|
2086
|
+
const L = q(V);
|
|
2087
|
+
if (!o.isValidNot0(L))
|
|
2088
|
+
return;
|
|
2089
|
+
const Y = o.inv(L), j = e.BASE.multiply(L).toAffine(), G = o.create(j.x);
|
|
2090
|
+
if (G === gt)
|
|
2091
|
+
return;
|
|
2092
|
+
const Yt = o.create(Y * o.create(N + G * O));
|
|
2093
|
+
if (Yt === gt)
|
|
2094
|
+
return;
|
|
2095
|
+
let $e = (j.x === G ? 0 : 2) | Number(j.y & kt), Xe = Yt;
|
|
2096
|
+
return E && R(Yt) && (Xe = o.neg(Yt), $e ^= 1), new A(G, Xe, $e);
|
|
2097
|
+
}
|
|
2098
|
+
return { seed: k, k2sig: D };
|
|
2099
|
+
}
|
|
2100
|
+
function ft(w, g, y = {}) {
|
|
2101
|
+
w = z("message", w);
|
|
2102
|
+
const { seed: E, k2sig: v } = B(w, g, y);
|
|
2103
|
+
return fr(t.outputLen, o.BYTES, r)(E, v);
|
|
2104
|
+
}
|
|
2105
|
+
function nt(w) {
|
|
2106
|
+
let g;
|
|
2107
|
+
const y = typeof w == "string" || de(w), E = !y && w !== null && typeof w == "object" && typeof w.r == "bigint" && typeof w.s == "bigint";
|
|
2108
|
+
if (!y && !E)
|
|
2109
|
+
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
2110
|
+
if (E)
|
|
2111
|
+
g = new A(w.r, w.s);
|
|
2112
|
+
else if (y) {
|
|
2113
|
+
try {
|
|
2114
|
+
g = A.fromBytes(z("sig", w), "der");
|
|
2115
|
+
} catch (v) {
|
|
2116
|
+
if (!(v instanceof dt.Err))
|
|
2117
|
+
throw v;
|
|
2118
|
+
}
|
|
2119
|
+
if (!g)
|
|
2120
|
+
try {
|
|
2121
|
+
g = A.fromBytes(z("sig", w), "compact");
|
|
2122
|
+
} catch {
|
|
2123
|
+
return !1;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
return g || !1;
|
|
2127
|
+
}
|
|
2128
|
+
function T(w, g, y, E = {}) {
|
|
2129
|
+
const { lowS: v, prehash: I, format: x } = Se(E, p);
|
|
2130
|
+
if (y = z("publicKey", y), g = F(z("message", g), I), "strict" in E)
|
|
2131
|
+
throw new Error("options.strict was renamed to lowS");
|
|
2132
|
+
const O = x === void 0 ? nt(w) : A.fromBytes(z("sig", w), x);
|
|
2133
|
+
if (O === !1)
|
|
2134
|
+
return !1;
|
|
2135
|
+
try {
|
|
2136
|
+
const C = e.fromBytes(y);
|
|
2137
|
+
if (v && O.hasHighS())
|
|
2138
|
+
return !1;
|
|
2139
|
+
const { r: k, s: N } = O, D = K(g), V = o.inv(N), L = o.create(D * V), Y = o.create(k * V), j = e.BASE.multiplyUnsafe(L).add(C.multiplyUnsafe(Y));
|
|
2140
|
+
return j.is0() ? !1 : o.create(j.x) === k;
|
|
2141
|
+
} catch {
|
|
2142
|
+
return !1;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
function b(w, g, y = {}) {
|
|
2146
|
+
const { prehash: E } = Se(y, p);
|
|
2147
|
+
return g = F(g, E), A.fromBytes(w, "recovered").recoverPublicKey(g).toBytes();
|
|
2148
|
+
}
|
|
2149
|
+
return Object.freeze({
|
|
2150
|
+
keygen: l,
|
|
2151
|
+
getPublicKey: h,
|
|
2152
|
+
getSharedSecret: u,
|
|
2153
|
+
utils: f,
|
|
2154
|
+
lengths: d,
|
|
2155
|
+
Point: e,
|
|
2156
|
+
sign: ft,
|
|
2157
|
+
verify: T,
|
|
2158
|
+
recoverPublicKey: b,
|
|
2159
|
+
Signature: A,
|
|
2160
|
+
hash: t
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function Dr(e) {
|
|
2164
|
+
const t = {
|
|
2165
|
+
a: e.a,
|
|
2166
|
+
b: e.b,
|
|
2167
|
+
p: e.Fp.ORDER,
|
|
2168
|
+
n: e.n,
|
|
2169
|
+
h: e.h,
|
|
2170
|
+
Gx: e.Gx,
|
|
2171
|
+
Gy: e.Gy
|
|
2172
|
+
}, s = e.Fp;
|
|
2173
|
+
let n = e.allowedPrivateKeyLengths ? Array.from(new Set(e.allowedPrivateKeyLengths.map((o) => Math.ceil(o / 2)))) : void 0;
|
|
2174
|
+
const r = Tt(t.n, {
|
|
2175
|
+
BITS: e.nBitLength,
|
|
2176
|
+
allowedLengths: n,
|
|
2177
|
+
modFromBytes: e.wrapPrivateKey
|
|
2178
|
+
}), i = {
|
|
2179
|
+
Fp: s,
|
|
2180
|
+
Fn: r,
|
|
2181
|
+
allowInfinityPoint: e.allowInfinityPoint,
|
|
2182
|
+
endo: e.endo,
|
|
2183
|
+
isTorsionFree: e.isTorsionFree,
|
|
2184
|
+
clearCofactor: e.clearCofactor,
|
|
2185
|
+
fromBytes: e.fromBytes,
|
|
2186
|
+
toBytes: e.toBytes
|
|
2187
|
+
};
|
|
2188
|
+
return { CURVE: t, curveOpts: i };
|
|
2189
|
+
}
|
|
2190
|
+
function Ur(e) {
|
|
2191
|
+
const { CURVE: t, curveOpts: s } = Dr(e), n = {
|
|
2192
|
+
hmac: e.hmac,
|
|
2193
|
+
randomBytes: e.randomBytes,
|
|
2194
|
+
lowS: e.lowS,
|
|
2195
|
+
bits2int: e.bits2int,
|
|
2196
|
+
bits2int_modN: e.bits2int_modN
|
|
2197
|
+
};
|
|
2198
|
+
return { CURVE: t, curveOpts: s, hash: e.hash, ecdsaOpts: n };
|
|
2199
|
+
}
|
|
2200
|
+
function _r(e, t) {
|
|
2201
|
+
const s = t.Point;
|
|
2202
|
+
return Object.assign({}, t, {
|
|
2203
|
+
ProjectivePoint: s,
|
|
2204
|
+
CURVE: Object.assign({}, e, Hn(s.Fn.ORDER, s.Fn.BITS))
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
function Nr(e) {
|
|
2208
|
+
const { CURVE: t, curveOpts: s, hash: n, ecdsaOpts: r } = Ur(e), i = Rr(t, s), o = Tr(i, n, r);
|
|
2209
|
+
return _r(e, o);
|
|
2210
|
+
}
|
|
2211
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2212
|
+
function je(e, t) {
|
|
2213
|
+
const s = (n) => Nr({ ...e, hash: n });
|
|
2214
|
+
return { ...s(t), create: s };
|
|
2215
|
+
}
|
|
2216
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2217
|
+
const Gn = {
|
|
2218
|
+
p: BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),
|
|
2219
|
+
n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
|
|
2220
|
+
h: BigInt(1),
|
|
2221
|
+
a: BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),
|
|
2222
|
+
b: BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),
|
|
2223
|
+
Gx: BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),
|
|
2224
|
+
Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")
|
|
2225
|
+
}, $n = {
|
|
2226
|
+
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),
|
|
2227
|
+
n: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),
|
|
2228
|
+
h: BigInt(1),
|
|
2229
|
+
a: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),
|
|
2230
|
+
b: BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),
|
|
2231
|
+
Gx: BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),
|
|
2232
|
+
Gy: BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")
|
|
2233
|
+
}, Xn = {
|
|
2234
|
+
p: BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
|
|
2235
|
+
n: BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),
|
|
2236
|
+
h: BigInt(1),
|
|
2237
|
+
a: BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),
|
|
2238
|
+
b: BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),
|
|
2239
|
+
Gx: BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),
|
|
2240
|
+
Gy: BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")
|
|
2241
|
+
}, Hr = Tt(Gn.p), Vr = Tt($n.p), jr = Tt(Xn.p), kr = je({ ...Gn, Fp: Hr, lowS: !1 }, rr), Lr = je({ ...$n, Fp: Vr, lowS: !1 }, or), Kr = je({ ...Xn, Fp: jr, lowS: !1, allowedPrivateKeyLengths: [130, 131, 132] }, ir);
|
|
2242
|
+
function Pr(e) {
|
|
2243
|
+
const t = new Uint8Array([
|
|
2244
|
+
48,
|
|
2245
|
+
13,
|
|
2246
|
+
6,
|
|
2247
|
+
9,
|
|
2248
|
+
42,
|
|
2249
|
+
134,
|
|
2250
|
+
72,
|
|
2251
|
+
134,
|
|
2252
|
+
247,
|
|
2253
|
+
13,
|
|
2254
|
+
1,
|
|
2255
|
+
1,
|
|
2256
|
+
1,
|
|
2257
|
+
5,
|
|
2258
|
+
0
|
|
2259
|
+
]), s = e.length + 1, n = t.length + 1 + ne(s).length + s, r = new Uint8Array(1 + ne(n).length + n);
|
|
2260
|
+
let i = 0;
|
|
2261
|
+
r[i++] = 48;
|
|
2262
|
+
const o = ne(n);
|
|
2263
|
+
r.set(o, i), i += o.length, r.set(t, i), i += t.length, r[i++] = 3;
|
|
2264
|
+
const a = ne(s);
|
|
2265
|
+
return r.set(a, i), i += a.length, r[i++] = 0, r.set(e, i), r;
|
|
2266
|
+
}
|
|
2267
|
+
function ne(e) {
|
|
2268
|
+
return e < 128 ? new Uint8Array([e]) : e < 256 ? new Uint8Array([129, e]) : new Uint8Array([130, e >> 8 & 255, e & 255]);
|
|
2269
|
+
}
|
|
2270
|
+
async function Zt(e, t, s) {
|
|
2271
|
+
class n {
|
|
2272
|
+
constructor() {
|
|
2273
|
+
this.format = "spki", this.keyData = new Uint8Array(0), this.algorithm = { name: P.Ecdsa }, this.extractable = !0, this.usage = ["verify"];
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
const r = new n();
|
|
2277
|
+
if (s.includes("BEGIN"))
|
|
2278
|
+
r.format = "spki", r.keyData = dn(s);
|
|
2279
|
+
else if (/^[0-9A-Fa-f]+$/.test(s))
|
|
2280
|
+
r.format = "raw", r.keyData = Kt(s);
|
|
2281
|
+
else {
|
|
2282
|
+
r.format = "spki";
|
|
2283
|
+
const i = S(s);
|
|
2284
|
+
e.toLowerCase().includes("pkcs1") && i[0] === 48 && i[1] === 130 && i[4] === 2 && i[5] === 130 ? r.keyData = Pr(i) : r.keyData = i;
|
|
2285
|
+
}
|
|
2286
|
+
if (e.toLowerCase().includes("ecdsa"))
|
|
2287
|
+
if (t.includes("256"))
|
|
2288
|
+
r.algorithm = { name: P.Ecdsa, namedCurve: it.P256 };
|
|
2289
|
+
else if (t.includes("384"))
|
|
2290
|
+
r.algorithm = { name: P.Ecdsa, namedCurve: it.P384 };
|
|
2291
|
+
else if (t.includes("521"))
|
|
2292
|
+
r.algorithm = { name: P.Ecdsa, namedCurve: it.P521 };
|
|
2293
|
+
else
|
|
2294
|
+
throw new Error("Cannot determine ECDSA key size.");
|
|
2295
|
+
else if (e.toLowerCase().includes("ed25519"))
|
|
2296
|
+
r.algorithm = { name: P.Ed25519 };
|
|
2297
|
+
else if (e.toLowerCase().includes("rsa") || e.toLowerCase().includes("pkcs1")) {
|
|
2298
|
+
let i = U.SHA256;
|
|
2299
|
+
const o = t.toUpperCase().replace(/[-_]/g, "");
|
|
2300
|
+
o.includes("SHA256") || o.includes("256") ? i = U.SHA256 : o.includes("SHA384") || o.includes("384") ? i = U.SHA384 : (o.includes("SHA512") || o.includes("512")) && (i = U.SHA512), o.includes(oe.PKCS1) || o.includes(oe.RSAPKCS1) ? r.algorithm = {
|
|
2301
|
+
name: Bt.PKCS1v15,
|
|
2302
|
+
hash: { name: i }
|
|
2303
|
+
} : r.algorithm = {
|
|
2304
|
+
name: Bt.PSS,
|
|
2305
|
+
hash: { name: i }
|
|
2306
|
+
};
|
|
2307
|
+
} else
|
|
2308
|
+
throw new Error(`Unsupported ${e}`);
|
|
2309
|
+
return await crypto.subtle.importKey(r.format, r.keyData, r.algorithm, r.extractable, r.usage);
|
|
2310
|
+
}
|
|
2311
|
+
async function Rt(e, t, s, n = "sha256") {
|
|
2312
|
+
const r = {
|
|
2313
|
+
name: e.algorithm.name
|
|
2314
|
+
};
|
|
2315
|
+
if (e.algorithm.name === P.Ecdsa) {
|
|
2316
|
+
const i = e.algorithm.namedCurve;
|
|
2317
|
+
let o = 32;
|
|
2318
|
+
if (i === it.P256 ? o = 32 : i === it.P384 ? o = 48 : i === it.P521 && (o = 66), r.hash = { name: "" }, n.includes("256"))
|
|
2319
|
+
r.hash.name = U.SHA256;
|
|
2320
|
+
else if (n.includes("384"))
|
|
2321
|
+
r.hash.name = U.SHA384;
|
|
2322
|
+
else if (n.includes("512"))
|
|
2323
|
+
r.hash.name = U.SHA512;
|
|
2324
|
+
else
|
|
2325
|
+
throw new Error("Cannot determine hashing algorithm;");
|
|
2326
|
+
let a;
|
|
2327
|
+
try {
|
|
2328
|
+
const c = Mt.parseBuffer(s), l = c.subs[0].toInteger(), h = c.subs[1].toInteger(), u = Kt(l.toString(16).padStart(o * 2, "0")), f = Kt(h.toString(16).padStart(o * 2, "0"));
|
|
2329
|
+
a = new Uint8Array(u.length + f.length), a.set(u, 0), a.set(f, u.length);
|
|
2330
|
+
} catch {
|
|
2331
|
+
return !1;
|
|
2332
|
+
}
|
|
2333
|
+
return await crypto.subtle.verify(r, e, a, t);
|
|
2334
|
+
} else {
|
|
2335
|
+
if (e.algorithm.name === P.Ed25519)
|
|
2336
|
+
return await crypto.subtle.verify(e.algorithm.name, e, s, t);
|
|
2337
|
+
if (e.algorithm.name === Bt.PSS) {
|
|
2338
|
+
const i = e.algorithm.hash.name, o = i === U.SHA256 ? 32 : i === U.SHA384 ? 48 : i === U.SHA512 ? 64 : 32;
|
|
2339
|
+
return await crypto.subtle.verify({
|
|
2340
|
+
name: Bt.PSS,
|
|
2341
|
+
saltLength: o
|
|
2342
|
+
}, e, s, t);
|
|
2343
|
+
} else {
|
|
2344
|
+
if (e.algorithm.name === Bt.PKCS1v15)
|
|
2345
|
+
return await crypto.subtle.verify(e.algorithm.name, e, s, t);
|
|
2346
|
+
throw new Error("Unsupported key type!");
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
async function Fr(e, t, s) {
|
|
2351
|
+
if (e.algorithm.name !== P.Ecdsa)
|
|
2352
|
+
throw new Error("verifySignatureOverDigest only supports ECDSA keys");
|
|
2353
|
+
const n = e.algorithm.namedCurve;
|
|
2354
|
+
let r;
|
|
2355
|
+
if (n === it.P256)
|
|
2356
|
+
r = kr;
|
|
2357
|
+
else if (n === it.P384)
|
|
2358
|
+
r = Lr;
|
|
2359
|
+
else if (n === it.P521)
|
|
2360
|
+
r = Kr;
|
|
2361
|
+
else
|
|
2362
|
+
throw new Error(`Unsupported curve: ${n}`);
|
|
2363
|
+
const i = await crypto.subtle.exportKey("jwk", e);
|
|
2364
|
+
if (!i.x || !i.y)
|
|
2365
|
+
throw new Error("Invalid ECDSA public key: missing x or y coordinates");
|
|
2366
|
+
const o = qe(i.x), a = qe(i.y), c = new Uint8Array(1 + o.length + a.length);
|
|
2367
|
+
return c[0] = 4, c.set(o, 1), c.set(a, 1 + o.length), r.verify(s, t, c, { format: "der", prehash: !1, lowS: !1 });
|
|
2368
|
+
}
|
|
2369
|
+
var ie = /* @__PURE__ */ ((e) => (e.certificateAuthorities = "certificateAuthorities", e.ctlogs = "ctlogs", e.timestampAuthorities = "timestampAuthorities", e.tlogs = "tlogs", e))(ie || {});
|
|
2370
|
+
const Gr = {
|
|
2371
|
+
sha256: U.SHA256,
|
|
2372
|
+
sha384: U.SHA384,
|
|
2373
|
+
sha512: U.SHA512,
|
|
2374
|
+
SHA2_256: U.SHA256,
|
|
2375
|
+
SHA2_384: U.SHA384,
|
|
2376
|
+
SHA2_512: U.SHA512
|
|
2377
|
+
};
|
|
2378
|
+
function ke(e) {
|
|
2379
|
+
const t = Gr[e];
|
|
2380
|
+
if (!t)
|
|
2381
|
+
throw new Error(`Unsupported hash algorithm: ${e}`);
|
|
2382
|
+
return t;
|
|
2383
|
+
}
|
|
2384
|
+
const le = {
|
|
2385
|
+
"1.2.840.10045.4.3.1": "sha224",
|
|
2386
|
+
"1.2.840.10045.4.3.2": "sha256",
|
|
2387
|
+
"1.2.840.10045.4.3.3": "sha384",
|
|
2388
|
+
"1.2.840.10045.4.3.4": "sha512"
|
|
2389
|
+
}, he = {
|
|
2390
|
+
"1.2.840.113549.1.1.11": "sha256",
|
|
2391
|
+
// sha256WithRSAEncryption
|
|
2392
|
+
"1.2.840.113549.1.1.12": "sha384",
|
|
2393
|
+
// sha384WithRSAEncryption
|
|
2394
|
+
"1.2.840.113549.1.1.13": "sha512",
|
|
2395
|
+
// sha512WithRSAEncryption
|
|
2396
|
+
"1.2.840.113549.1.1.5": "sha1"
|
|
2397
|
+
// sha1WithRSAEncryption
|
|
2398
|
+
}, Ie = "1.2.840.113549.1.1.10", Le = {
|
|
2399
|
+
"2.16.840.1.101.3.4.2.1": "sha256",
|
|
2400
|
+
"2.16.840.1.101.3.4.2.2": "sha384",
|
|
2401
|
+
"2.16.840.1.101.3.4.2.3": "sha512"
|
|
2402
|
+
}, se = "sha256", $r = {
|
|
2403
|
+
"1.2.840.10045.3.1.7": "secp256r1",
|
|
2404
|
+
"1.3.132.0.34": "secp384r1",
|
|
2405
|
+
"1.3.132.0.35": "secp521r1"
|
|
2406
|
+
};
|
|
2407
|
+
class Ke {
|
|
2408
|
+
version;
|
|
2409
|
+
logID;
|
|
2410
|
+
timestamp;
|
|
2411
|
+
extensions;
|
|
2412
|
+
hashAlgorithm;
|
|
2413
|
+
signatureAlgorithm;
|
|
2414
|
+
signature;
|
|
2415
|
+
constructor(t) {
|
|
2416
|
+
this.version = t.version, this.logID = t.logID, this.timestamp = t.timestamp, this.extensions = t.extensions, this.hashAlgorithm = t.hashAlgorithm, this.signatureAlgorithm = t.signatureAlgorithm, this.signature = t.signature;
|
|
2417
|
+
}
|
|
2418
|
+
get datetime() {
|
|
2419
|
+
return new Date(Number(Is(this.timestamp)));
|
|
2420
|
+
}
|
|
2421
|
+
// Returns the hash algorithm used to generate the SCT's signature.
|
|
2422
|
+
// https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.4.1
|
|
2423
|
+
get algorithm() {
|
|
2424
|
+
switch (this.hashAlgorithm) {
|
|
2425
|
+
/* istanbul ignore next */
|
|
2426
|
+
case 0:
|
|
2427
|
+
return "none";
|
|
2428
|
+
/* istanbul ignore next */
|
|
2429
|
+
case 1:
|
|
2430
|
+
return "md5";
|
|
2431
|
+
/* istanbul ignore next */
|
|
2432
|
+
case 2:
|
|
2433
|
+
return "sha1";
|
|
2434
|
+
/* istanbul ignore next */
|
|
2435
|
+
case 3:
|
|
2436
|
+
return "sha224";
|
|
2437
|
+
case 4:
|
|
2438
|
+
return "sha256";
|
|
2439
|
+
/* istanbul ignore next */
|
|
2440
|
+
case 5:
|
|
2441
|
+
return "sha384";
|
|
2442
|
+
/* istanbul ignore next */
|
|
2443
|
+
case 6:
|
|
2444
|
+
return "sha512";
|
|
2445
|
+
/* istanbul ignore next */
|
|
2446
|
+
default:
|
|
2447
|
+
return "unknown";
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
async verify(t, s) {
|
|
2451
|
+
const n = new rt();
|
|
2452
|
+
return n.appendChar(this.version), n.appendChar(0), n.appendView(this.timestamp), n.appendUint16(1), n.appendView(t), n.appendUint16(this.extensions.byteLength), this.extensions.byteLength > 0 && n.appendView(this.extensions), await Rt(
|
|
2453
|
+
s,
|
|
2454
|
+
n.buffer,
|
|
2455
|
+
this.signature,
|
|
2456
|
+
this.algorithm
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2459
|
+
// Parses a SignedCertificateTimestamp from a buffer. SCTs are encoded using
|
|
2460
|
+
// TLS encoding which means the fields and lengths of most fields are
|
|
2461
|
+
// specified as part of the SCT and TLS specs.
|
|
2462
|
+
// https://www.rfc-editor.org/rfc/rfc6962#section-3.2
|
|
2463
|
+
// https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.4.1
|
|
2464
|
+
static parse(t) {
|
|
2465
|
+
const s = new rt(t), n = s.getUint8();
|
|
2466
|
+
if (n !== 0)
|
|
2467
|
+
throw new Error(`Unsupported SCT version: ${n} (expected 0 for v1)`);
|
|
2468
|
+
const r = s.getBlock(32), i = s.getBlock(8), o = s.getUint16(), a = s.getBlock(o), c = s.getUint8(), l = s.getUint8(), h = s.getUint16(), u = s.getBlock(h);
|
|
2469
|
+
if (s.position !== t.length)
|
|
2470
|
+
throw new Error("SCT buffer length mismatch");
|
|
2471
|
+
return new Ke({
|
|
2472
|
+
version: n,
|
|
2473
|
+
logID: r,
|
|
2474
|
+
timestamp: i,
|
|
2475
|
+
extensions: a,
|
|
2476
|
+
hashAlgorithm: c,
|
|
2477
|
+
signatureAlgorithm: l,
|
|
2478
|
+
signature: u
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
class wt {
|
|
2483
|
+
root;
|
|
2484
|
+
constructor(t) {
|
|
2485
|
+
this.root = t;
|
|
2486
|
+
}
|
|
2487
|
+
get oid() {
|
|
2488
|
+
return this.root.subs[0].toOID();
|
|
2489
|
+
}
|
|
2490
|
+
get critical() {
|
|
2491
|
+
return this.root.subs.length === 3 ? this.root.subs[1].toBoolean() : !1;
|
|
2492
|
+
}
|
|
2493
|
+
get value() {
|
|
2494
|
+
return this.extnValueObj.value;
|
|
2495
|
+
}
|
|
2496
|
+
get valueObj() {
|
|
2497
|
+
return this.extnValueObj;
|
|
2498
|
+
}
|
|
2499
|
+
get extnValueObj() {
|
|
2500
|
+
return this.root.subs[this.root.subs.length - 1];
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
class Xr extends wt {
|
|
2504
|
+
get isCA() {
|
|
2505
|
+
return this.sequence.subs[0]?.toBoolean() ?? !1;
|
|
2506
|
+
}
|
|
2507
|
+
get pathLenConstraint() {
|
|
2508
|
+
return this.sequence.subs.length > 1 ? this.sequence.subs[1].toInteger() : void 0;
|
|
2509
|
+
}
|
|
2510
|
+
// The extnValue field contains a single sequence wrapping the isCA and
|
|
2511
|
+
// pathLenConstraint.
|
|
2512
|
+
get sequence() {
|
|
2513
|
+
return this.extnValueObj.subs[0];
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
class qr extends wt {
|
|
2517
|
+
get digitalSignature() {
|
|
2518
|
+
return this.bitString[0] === 1;
|
|
2519
|
+
}
|
|
2520
|
+
get keyCertSign() {
|
|
2521
|
+
return this.bitString[5] === 1;
|
|
2522
|
+
}
|
|
2523
|
+
get crlSign() {
|
|
2524
|
+
return this.bitString[6] === 1;
|
|
2525
|
+
}
|
|
2526
|
+
// The extnValue field contains a single bit string which is a bit mask
|
|
2527
|
+
// indicating which key usages are enabled.
|
|
2528
|
+
get bitString() {
|
|
2529
|
+
return this.extnValueObj.subs[0].toBitString();
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
class Mr extends wt {
|
|
2533
|
+
get rfc822Name() {
|
|
2534
|
+
const t = this.findGeneralName(1)?.value;
|
|
2535
|
+
if (t !== void 0)
|
|
2536
|
+
return Q(t);
|
|
2537
|
+
}
|
|
2538
|
+
get uri() {
|
|
2539
|
+
const t = this.findGeneralName(6)?.value;
|
|
2540
|
+
if (t !== void 0)
|
|
2541
|
+
return Q(t);
|
|
2542
|
+
}
|
|
2543
|
+
// Retrieve the value of an otherName with the given OID.
|
|
2544
|
+
otherName(t) {
|
|
2545
|
+
const s = this.findGeneralName(0);
|
|
2546
|
+
if (s === void 0 || s.subs[0].toOID() !== t)
|
|
2547
|
+
return;
|
|
2548
|
+
const r = s.subs[1];
|
|
2549
|
+
return Q(r.subs[0].value);
|
|
2550
|
+
}
|
|
2551
|
+
findGeneralName(t) {
|
|
2552
|
+
return this.generalNames.find((s) => s.tag.isContextSpecific(t));
|
|
2553
|
+
}
|
|
2554
|
+
// The extnValue field contains a sequence of GeneralNames.
|
|
2555
|
+
get generalNames() {
|
|
2556
|
+
return this.extnValueObj.subs[0].subs;
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
class Zr extends wt {
|
|
2560
|
+
get keyIdentifier() {
|
|
2561
|
+
return this.findSequenceMember(0)?.value;
|
|
2562
|
+
}
|
|
2563
|
+
findSequenceMember(t) {
|
|
2564
|
+
return this.sequence.subs.find((s) => s.tag.isContextSpecific(t));
|
|
2565
|
+
}
|
|
2566
|
+
// The extnValue field contains a single sequence wrapping the keyIdentifier
|
|
2567
|
+
get sequence() {
|
|
2568
|
+
return this.extnValueObj.subs[0];
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
class Wr extends wt {
|
|
2572
|
+
get keyIdentifier() {
|
|
2573
|
+
return this.extnValueObj.subs[0].value;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
class Gt extends wt {
|
|
2577
|
+
get stringValue() {
|
|
2578
|
+
return Q(this.extnValueObj.value);
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
class Z extends wt {
|
|
2582
|
+
get stringValue() {
|
|
2583
|
+
return Q(this.extnValueObj.subs[0].value);
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
class Yr extends Gt {
|
|
2587
|
+
get issuer() {
|
|
2588
|
+
return this.stringValue;
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
class zr extends Gt {
|
|
2592
|
+
get workflowTrigger() {
|
|
2593
|
+
return this.stringValue;
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
class Jr extends Gt {
|
|
2597
|
+
get workflowSHA() {
|
|
2598
|
+
return this.stringValue;
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
class Qr extends Gt {
|
|
2602
|
+
get workflowName() {
|
|
2603
|
+
return this.stringValue;
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
class ti extends Gt {
|
|
2607
|
+
get workflowRepository() {
|
|
2608
|
+
return this.stringValue;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
class ei extends Gt {
|
|
2612
|
+
get workflowRef() {
|
|
2613
|
+
return this.stringValue;
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
class ni extends Z {
|
|
2617
|
+
get issuer() {
|
|
2618
|
+
return this.stringValue;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
class si extends Z {
|
|
2622
|
+
get buildSignerURI() {
|
|
2623
|
+
return this.stringValue;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
class ri extends Z {
|
|
2627
|
+
get buildSignerDigest() {
|
|
2628
|
+
return this.stringValue;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
class ii extends Z {
|
|
2632
|
+
get runnerEnvironment() {
|
|
2633
|
+
return this.stringValue;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
class oi extends Z {
|
|
2637
|
+
get sourceRepositoryURI() {
|
|
2638
|
+
return this.stringValue;
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
class ai extends Z {
|
|
2642
|
+
get sourceRepositoryDigest() {
|
|
2643
|
+
return this.stringValue;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
class ci extends Z {
|
|
2647
|
+
get sourceRepositoryRef() {
|
|
2648
|
+
return this.stringValue;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
class fi extends Z {
|
|
2652
|
+
get sourceRepositoryIdentifier() {
|
|
2653
|
+
return this.stringValue;
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
class ui extends Z {
|
|
2657
|
+
get sourceRepositoryOwnerURI() {
|
|
2658
|
+
return this.stringValue;
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
class li extends Z {
|
|
2662
|
+
get sourceRepositoryOwnerIdentifier() {
|
|
2663
|
+
return this.stringValue;
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
class hi extends Z {
|
|
2667
|
+
get buildConfigURI() {
|
|
2668
|
+
return this.stringValue;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
class di extends Z {
|
|
2672
|
+
get buildConfigDigest() {
|
|
2673
|
+
return this.stringValue;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
class gi extends Z {
|
|
2677
|
+
get buildTrigger() {
|
|
2678
|
+
return this.stringValue;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
class wi extends Z {
|
|
2682
|
+
get runInvocationURI() {
|
|
2683
|
+
return this.stringValue;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
class bi extends Z {
|
|
2687
|
+
get sourceRepositoryVisibility() {
|
|
2688
|
+
return this.stringValue;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
class qn extends wt {
|
|
2692
|
+
constructor(t) {
|
|
2693
|
+
super(t);
|
|
2694
|
+
}
|
|
2695
|
+
get signedCertificateTimestamps() {
|
|
2696
|
+
const t = this.extnValueObj.subs[0].value, s = new rt(t), n = s.getUint16() + 2, r = [];
|
|
2697
|
+
for (; s.position < n; ) {
|
|
2698
|
+
const i = s.getUint16(), o = s.getBlock(i);
|
|
2699
|
+
r.push(Ke.parse(o));
|
|
2700
|
+
}
|
|
2701
|
+
if (s.position !== n)
|
|
2702
|
+
throw new Error("SCT list length does not match actual length");
|
|
2703
|
+
return r;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
const pi = "2.5.29.14", yi = "2.5.29.15", mi = "2.5.29.17", Ei = "2.5.29.19", xi = "2.5.29.35", Mn = "1.3.6.1.4.1.11129.2.4.2", Zn = "1.3.6.1.4.1.57264.1.1", Wn = "1.3.6.1.4.1.57264.1.2", Yn = "1.3.6.1.4.1.57264.1.3", zn = "1.3.6.1.4.1.57264.1.4", Jn = "1.3.6.1.4.1.57264.1.5", Qn = "1.3.6.1.4.1.57264.1.6", Si = "1.3.6.1.4.1.57264.1.7", ts = "1.3.6.1.4.1.57264.1.8", es = "1.3.6.1.4.1.57264.1.9", ns = "1.3.6.1.4.1.57264.1.10", ss = "1.3.6.1.4.1.57264.1.11", rs = "1.3.6.1.4.1.57264.1.12", is = "1.3.6.1.4.1.57264.1.13", os = "1.3.6.1.4.1.57264.1.14", as = "1.3.6.1.4.1.57264.1.15", cs = "1.3.6.1.4.1.57264.1.16", fs = "1.3.6.1.4.1.57264.1.17", us = "1.3.6.1.4.1.57264.1.18", ls = "1.3.6.1.4.1.57264.1.19", hs = "1.3.6.1.4.1.57264.1.20", ds = "1.3.6.1.4.1.57264.1.21", gs = "1.3.6.1.4.1.57264.1.22";
|
|
2707
|
+
class J {
|
|
2708
|
+
root;
|
|
2709
|
+
constructor(t) {
|
|
2710
|
+
this.root = t;
|
|
2711
|
+
}
|
|
2712
|
+
static parse(t) {
|
|
2713
|
+
const s = typeof t == "string" ? dn(t) : t, n = Mt.parseBuffer(s);
|
|
2714
|
+
return new J(n);
|
|
2715
|
+
}
|
|
2716
|
+
get tbsCertificate() {
|
|
2717
|
+
return this.tbsCertificateObj;
|
|
2718
|
+
}
|
|
2719
|
+
get version() {
|
|
2720
|
+
return `v${(this.versionObj.subs[0].toInteger() + BigInt(1)).toString()}`;
|
|
2721
|
+
}
|
|
2722
|
+
get serialNumber() {
|
|
2723
|
+
return this.serialNumberObj.value;
|
|
2724
|
+
}
|
|
2725
|
+
get notBefore() {
|
|
2726
|
+
return this.validityObj.subs[0].toDate();
|
|
2727
|
+
}
|
|
2728
|
+
get notAfter() {
|
|
2729
|
+
return this.validityObj.subs[1].toDate();
|
|
2730
|
+
}
|
|
2731
|
+
get issuer() {
|
|
2732
|
+
return this.issuerObj.value;
|
|
2733
|
+
}
|
|
2734
|
+
get subject() {
|
|
2735
|
+
return this.subjectObj.value;
|
|
2736
|
+
}
|
|
2737
|
+
get publicKey() {
|
|
2738
|
+
return this.subjectPublicKeyInfoObj.toDER();
|
|
2739
|
+
}
|
|
2740
|
+
/**
|
|
2741
|
+
* Import the public key with a specific hash algorithm and signature scheme for RSA keys.
|
|
2742
|
+
* For ECDSA keys, both parameters are ignored.
|
|
2743
|
+
* @param hashAlg - Hash algorithm (e.g., "sha384") for RSA keys
|
|
2744
|
+
* @param usePss - If true, import as RSA-PSS key; if false, import as PKCS#1 v1.5
|
|
2745
|
+
*/
|
|
2746
|
+
async getPublicKeyObj(t, s) {
|
|
2747
|
+
const n = this.subjectPublicKeyInfoObj.toDER(), r = Mt.parseBuffer(n), i = r.subs[0].subs[0].toOID(), o = i === "1.2.840.113549.1.1.1";
|
|
2748
|
+
if (i === Ie)
|
|
2749
|
+
throw new Error(
|
|
2750
|
+
"RSA-PSS public keys (id-RSASSA-PSS OID) are not supported by WebCrypto. Only certificates with standard RSA keys (rsaEncryption OID) signed using RSA-PSS are supported."
|
|
2751
|
+
);
|
|
2752
|
+
if (o) {
|
|
2753
|
+
const c = t || se, l = s ? c : `PKCS1_${c}`;
|
|
2754
|
+
return Zt(P.RSA, l, Me(n));
|
|
2755
|
+
} else {
|
|
2756
|
+
const c = r.subs[0].subs[1]?.toOID(), l = $r[c];
|
|
2757
|
+
if (!l)
|
|
2758
|
+
throw new Error(`Unknown ECDSA curve OID: ${c}`);
|
|
2759
|
+
return Zt(P.Ecdsa, l, Me(n));
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
get publicKeyObj() {
|
|
2763
|
+
return this.getPublicKeyObj();
|
|
2764
|
+
}
|
|
2765
|
+
get signatureAlgorithm() {
|
|
2766
|
+
const t = this.signatureAlgorithmObj.subs[0].toOID();
|
|
2767
|
+
return le[t] || he[t] || this.parseRsaPssHashAlgorithm();
|
|
2768
|
+
}
|
|
2769
|
+
get signatureAlgorithmOid() {
|
|
2770
|
+
return this.signatureAlgorithmObj.subs[0].toOID();
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Parse hash algorithm from RSA-PSS signature algorithm parameters.
|
|
2774
|
+
* RSA-PSS parameters are: SEQUENCE { hashAlgorithm, maskGenAlgorithm, saltLength, trailerField }
|
|
2775
|
+
*/
|
|
2776
|
+
parseRsaPssHashAlgorithm() {
|
|
2777
|
+
if (this.signatureAlgorithmObj.subs[0].toOID() !== Ie)
|
|
2778
|
+
return "";
|
|
2779
|
+
const s = this.signatureAlgorithmObj.subs[1];
|
|
2780
|
+
if (!s || s.subs.length === 0)
|
|
2781
|
+
return se;
|
|
2782
|
+
const n = s.subs[0];
|
|
2783
|
+
if (n && n.subs.length > 0) {
|
|
2784
|
+
const r = n.subs[0];
|
|
2785
|
+
if (r && r.subs.length > 0) {
|
|
2786
|
+
const i = r.subs[0].toOID();
|
|
2787
|
+
return Le[i] || se;
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
return se;
|
|
2791
|
+
}
|
|
2792
|
+
get signatureValue() {
|
|
2793
|
+
return this.signatureValueObj.value.subarray(1);
|
|
2794
|
+
}
|
|
2795
|
+
get subjectAltName() {
|
|
2796
|
+
const t = this.extSubjectAltName;
|
|
2797
|
+
return t?.uri || t?.rfc822Name;
|
|
2798
|
+
}
|
|
2799
|
+
get extensions() {
|
|
2800
|
+
return this.extensionsObj?.subs[0]?.subs || /* istanbul ignore next */
|
|
2801
|
+
[];
|
|
2802
|
+
}
|
|
2803
|
+
get extKeyUsage() {
|
|
2804
|
+
const t = this.findExtension(yi);
|
|
2805
|
+
return t ? new qr(t) : void 0;
|
|
2806
|
+
}
|
|
2807
|
+
get extBasicConstraints() {
|
|
2808
|
+
const t = this.findExtension(Ei);
|
|
2809
|
+
return t ? new Xr(t) : void 0;
|
|
2810
|
+
}
|
|
2811
|
+
get extSubjectAltName() {
|
|
2812
|
+
const t = this.findExtension(mi);
|
|
2813
|
+
return t ? new Mr(t) : void 0;
|
|
2814
|
+
}
|
|
2815
|
+
get extAuthorityKeyID() {
|
|
2816
|
+
const t = this.findExtension(xi);
|
|
2817
|
+
return t ? new Zr(t) : void 0;
|
|
2818
|
+
}
|
|
2819
|
+
get extSubjectKeyID() {
|
|
2820
|
+
const t = this.findExtension(pi);
|
|
2821
|
+
return t ? new Wr(t) : (
|
|
2822
|
+
/* istanbul ignore next */
|
|
2823
|
+
void 0
|
|
2824
|
+
);
|
|
2825
|
+
}
|
|
2826
|
+
get extSCT() {
|
|
2827
|
+
const t = this.findExtension(Mn);
|
|
2828
|
+
return t ? new qn(t) : void 0;
|
|
2829
|
+
}
|
|
2830
|
+
get extFulcioIssuerV1() {
|
|
2831
|
+
const t = this.findExtension(Zn);
|
|
2832
|
+
return t ? new Yr(t) : void 0;
|
|
2833
|
+
}
|
|
2834
|
+
get extFulcioIssuerV2() {
|
|
2835
|
+
const t = this.findExtension(ts);
|
|
2836
|
+
return t ? new ni(t) : void 0;
|
|
2837
|
+
}
|
|
2838
|
+
get extGitHubWorkflowTrigger() {
|
|
2839
|
+
const t = this.findExtension(Wn);
|
|
2840
|
+
return t ? new zr(t) : void 0;
|
|
2841
|
+
}
|
|
2842
|
+
get extGitHubWorkflowSHA() {
|
|
2843
|
+
const t = this.findExtension(Yn);
|
|
2844
|
+
return t ? new Jr(t) : void 0;
|
|
2845
|
+
}
|
|
2846
|
+
get extGitHubWorkflowName() {
|
|
2847
|
+
const t = this.findExtension(zn);
|
|
2848
|
+
return t ? new Qr(t) : void 0;
|
|
2849
|
+
}
|
|
2850
|
+
get extGitHubWorkflowRepository() {
|
|
2851
|
+
const t = this.findExtension(Jn);
|
|
2852
|
+
return t ? new ti(t) : void 0;
|
|
2853
|
+
}
|
|
2854
|
+
get extGitHubWorkflowRef() {
|
|
2855
|
+
const t = this.findExtension(Qn);
|
|
2856
|
+
return t ? new ei(t) : void 0;
|
|
2857
|
+
}
|
|
2858
|
+
get extBuildSignerURI() {
|
|
2859
|
+
const t = this.findExtension(es);
|
|
2860
|
+
return t ? new si(t) : void 0;
|
|
2861
|
+
}
|
|
2862
|
+
get extBuildSignerDigest() {
|
|
2863
|
+
const t = this.findExtension(ns);
|
|
2864
|
+
return t ? new ri(t) : void 0;
|
|
2865
|
+
}
|
|
2866
|
+
get extRunnerEnvironment() {
|
|
2867
|
+
const t = this.findExtension(ss);
|
|
2868
|
+
return t ? new ii(t) : void 0;
|
|
2869
|
+
}
|
|
2870
|
+
get extSourceRepositoryURI() {
|
|
2871
|
+
const t = this.findExtension(rs);
|
|
2872
|
+
return t ? new oi(t) : void 0;
|
|
2873
|
+
}
|
|
2874
|
+
get extSourceRepositoryDigest() {
|
|
2875
|
+
const t = this.findExtension(is);
|
|
2876
|
+
return t ? new ai(t) : void 0;
|
|
2877
|
+
}
|
|
2878
|
+
get extSourceRepositoryRef() {
|
|
2879
|
+
const t = this.findExtension(os);
|
|
2880
|
+
return t ? new ci(t) : void 0;
|
|
2881
|
+
}
|
|
2882
|
+
get extSourceRepositoryIdentifier() {
|
|
2883
|
+
const t = this.findExtension(as);
|
|
2884
|
+
return t ? new fi(t) : void 0;
|
|
2885
|
+
}
|
|
2886
|
+
get extSourceRepositoryOwnerURI() {
|
|
2887
|
+
const t = this.findExtension(cs);
|
|
2888
|
+
return t ? new ui(t) : void 0;
|
|
2889
|
+
}
|
|
2890
|
+
get extSourceRepositoryOwnerIdentifier() {
|
|
2891
|
+
const t = this.findExtension(fs);
|
|
2892
|
+
return t ? new li(t) : void 0;
|
|
2893
|
+
}
|
|
2894
|
+
get extBuildConfigURI() {
|
|
2895
|
+
const t = this.findExtension(us);
|
|
2896
|
+
return t ? new hi(t) : void 0;
|
|
2897
|
+
}
|
|
2898
|
+
get extBuildConfigDigest() {
|
|
2899
|
+
const t = this.findExtension(ls);
|
|
2900
|
+
return t ? new di(t) : void 0;
|
|
2901
|
+
}
|
|
2902
|
+
get extBuildTrigger() {
|
|
2903
|
+
const t = this.findExtension(hs);
|
|
2904
|
+
return t ? new gi(t) : void 0;
|
|
2905
|
+
}
|
|
2906
|
+
get extRunInvocationURI() {
|
|
2907
|
+
const t = this.findExtension(ds);
|
|
2908
|
+
return t ? new wi(t) : void 0;
|
|
2909
|
+
}
|
|
2910
|
+
get extSourceRepositoryVisibility() {
|
|
2911
|
+
const t = this.findExtension(gs);
|
|
2912
|
+
return t ? new bi(t) : void 0;
|
|
2913
|
+
}
|
|
2914
|
+
get isCA() {
|
|
2915
|
+
const t = this.extBasicConstraints?.isCA || !1;
|
|
2916
|
+
return this.extKeyUsage ? t && this.extKeyUsage.keyCertSign : t;
|
|
2917
|
+
}
|
|
2918
|
+
extension(t) {
|
|
2919
|
+
const s = this.findExtension(t);
|
|
2920
|
+
return s ? new wt(s) : void 0;
|
|
2921
|
+
}
|
|
2922
|
+
async verify(t) {
|
|
2923
|
+
const s = this.signatureAlgorithmOid, n = s === Ie, r = n ? this.parseRsaPssHashAlgorithm() : he[s] || le[s], i = t ? await t.getPublicKeyObj(r, n) : await this.getPublicKeyObj(r, n);
|
|
2924
|
+
return await Rt(
|
|
2925
|
+
i,
|
|
2926
|
+
this.tbsCertificate.toDER(),
|
|
2927
|
+
this.signatureValue,
|
|
2928
|
+
this.signatureAlgorithm
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
validForDate(t) {
|
|
2932
|
+
return this.notBefore <= t && t <= this.notAfter;
|
|
2933
|
+
}
|
|
2934
|
+
equals(t) {
|
|
2935
|
+
return H(this.root.toDER(), t.root.toDER());
|
|
2936
|
+
}
|
|
2937
|
+
// Creates a copy of the certificate with a new buffer
|
|
2938
|
+
clone() {
|
|
2939
|
+
const t = this.root.toDER(), s = new Uint8Array(t);
|
|
2940
|
+
return J.parse(s);
|
|
2941
|
+
}
|
|
2942
|
+
findExtension(t) {
|
|
2943
|
+
return this.extensions.find((s) => s.subs[0].toOID() === t);
|
|
2944
|
+
}
|
|
2945
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
2946
|
+
// The following properties use the documented x509 structure to locate the
|
|
2947
|
+
// desired ASN.1 object
|
|
2948
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1
|
|
2949
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.1.1
|
|
2950
|
+
get tbsCertificateObj() {
|
|
2951
|
+
return this.root.subs[0];
|
|
2952
|
+
}
|
|
2953
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.1.2
|
|
2954
|
+
get signatureAlgorithmObj() {
|
|
2955
|
+
return this.root.subs[1];
|
|
2956
|
+
}
|
|
2957
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.1.3
|
|
2958
|
+
get signatureValueObj() {
|
|
2959
|
+
return this.root.subs[2];
|
|
2960
|
+
}
|
|
2961
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.1
|
|
2962
|
+
get versionObj() {
|
|
2963
|
+
return this.tbsCertificateObj.subs[0];
|
|
2964
|
+
}
|
|
2965
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.2
|
|
2966
|
+
get serialNumberObj() {
|
|
2967
|
+
return this.tbsCertificateObj.subs[1];
|
|
2968
|
+
}
|
|
2969
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.4
|
|
2970
|
+
get issuerObj() {
|
|
2971
|
+
return this.tbsCertificateObj.subs[3];
|
|
2972
|
+
}
|
|
2973
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.5
|
|
2974
|
+
get validityObj() {
|
|
2975
|
+
return this.tbsCertificateObj.subs[4];
|
|
2976
|
+
}
|
|
2977
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.6
|
|
2978
|
+
get subjectObj() {
|
|
2979
|
+
return this.tbsCertificateObj.subs[5];
|
|
2980
|
+
}
|
|
2981
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.7
|
|
2982
|
+
get subjectPublicKeyInfoObj() {
|
|
2983
|
+
return this.tbsCertificateObj.subs[6];
|
|
2984
|
+
}
|
|
2985
|
+
// Extensions can't be located by index because their position varies. Instead,
|
|
2986
|
+
// we need to find the extensions context specific tag
|
|
2987
|
+
// https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.9
|
|
2988
|
+
get extensionsObj() {
|
|
2989
|
+
return this.tbsCertificateObj.subs.find(
|
|
2990
|
+
(t) => t.tag.isContextSpecific(3)
|
|
2991
|
+
);
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
class ws {
|
|
2995
|
+
untrustedCert;
|
|
2996
|
+
trustedCerts;
|
|
2997
|
+
localCerts;
|
|
2998
|
+
timestamp;
|
|
2999
|
+
constructor(t) {
|
|
3000
|
+
this.untrustedCert = t.untrustedCert, this.trustedCerts = t.trustedCerts, this.localCerts = Ii([
|
|
3001
|
+
...t.trustedCerts,
|
|
3002
|
+
t.untrustedCert
|
|
3003
|
+
]), this.timestamp = t.timestamp;
|
|
3004
|
+
}
|
|
3005
|
+
async verify() {
|
|
3006
|
+
const t = await this.sort();
|
|
3007
|
+
if (this.checkPath(t), !t.every(
|
|
3008
|
+
(n) => n.validForDate(this.timestamp)
|
|
3009
|
+
))
|
|
3010
|
+
throw new Error(
|
|
3011
|
+
"certificate is not valid or expired at the specified date"
|
|
3012
|
+
);
|
|
3013
|
+
return t;
|
|
3014
|
+
}
|
|
3015
|
+
async sort() {
|
|
3016
|
+
const t = this.untrustedCert;
|
|
3017
|
+
let s = await this.buildPaths(t);
|
|
3018
|
+
if (s = s.filter(
|
|
3019
|
+
(r) => r.some((i) => this.trustedCerts.includes(i))
|
|
3020
|
+
), s.length === 0)
|
|
3021
|
+
throw new Error("no trusted certificate path found");
|
|
3022
|
+
const n = s.reduce(
|
|
3023
|
+
(r, i) => r.length < i.length ? r : i
|
|
3024
|
+
);
|
|
3025
|
+
return [t, ...n].slice(0, -1);
|
|
3026
|
+
}
|
|
3027
|
+
async buildPaths(t) {
|
|
3028
|
+
const s = [], n = await this.findIssuer(t);
|
|
3029
|
+
if (n.length === 0)
|
|
3030
|
+
throw new Error("no valid certificate path found");
|
|
3031
|
+
for (let r = 0; r < n.length; r++) {
|
|
3032
|
+
const i = n[r];
|
|
3033
|
+
if (i.equals(t)) {
|
|
3034
|
+
s.push([t]);
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
const o = await this.buildPaths(i);
|
|
3038
|
+
for (let a = 0; a < o.length; a++)
|
|
3039
|
+
s.push([i, ...o[a]]);
|
|
3040
|
+
}
|
|
3041
|
+
return s;
|
|
3042
|
+
}
|
|
3043
|
+
async findIssuer(t) {
|
|
3044
|
+
let s = [], n;
|
|
3045
|
+
if (H(t.subject, t.issuer) && await t.verify())
|
|
3046
|
+
return [t];
|
|
3047
|
+
t.extAuthorityKeyID && (n = t.extAuthorityKeyID.keyIdentifier), this.localCerts.forEach((i) => {
|
|
3048
|
+
if (n && i.extSubjectKeyID) {
|
|
3049
|
+
H(
|
|
3050
|
+
i.extSubjectKeyID.keyIdentifier,
|
|
3051
|
+
n
|
|
3052
|
+
) && s.push(i);
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
H(i.subject, t.issuer) && s.push(i);
|
|
3056
|
+
});
|
|
3057
|
+
const r = [];
|
|
3058
|
+
for (const i of s)
|
|
3059
|
+
try {
|
|
3060
|
+
await t.verify(i) && r.push(i);
|
|
3061
|
+
} catch {
|
|
3062
|
+
}
|
|
3063
|
+
return r;
|
|
3064
|
+
}
|
|
3065
|
+
checkPath(t) {
|
|
3066
|
+
if (t.length < 1)
|
|
3067
|
+
throw new Error(
|
|
3068
|
+
"certificate chain must contain at least one certificate"
|
|
3069
|
+
);
|
|
3070
|
+
if (!t.slice(1).every((n) => n.isCA))
|
|
3071
|
+
throw new Error("intermediate certificate is not a CA");
|
|
3072
|
+
for (let n = t.length - 2; n >= 0; n--)
|
|
3073
|
+
if (!H(t[n].issuer, t[n + 1].subject))
|
|
3074
|
+
throw new Error("incorrect certificate name chaining");
|
|
3075
|
+
for (let n = 0; n < t.length; n++) {
|
|
3076
|
+
const r = t[n];
|
|
3077
|
+
if (r.extBasicConstraints?.isCA) {
|
|
3078
|
+
const i = r.extBasicConstraints.pathLenConstraint;
|
|
3079
|
+
if (i !== void 0 && i < BigInt(n - 1))
|
|
3080
|
+
throw new Error("path length constraint exceeded");
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
function Ii(e) {
|
|
3086
|
+
for (let t = 0; t < e.length; t++)
|
|
3087
|
+
for (let s = t + 1; s < e.length; s++)
|
|
3088
|
+
e[t].equals(e[s]) && (e.splice(s, 1), s--);
|
|
3089
|
+
return e;
|
|
3090
|
+
}
|
|
3091
|
+
const vi = "DSSEv1";
|
|
3092
|
+
function Ai(e, t) {
|
|
3093
|
+
const s = [
|
|
3094
|
+
vi,
|
|
3095
|
+
e.length,
|
|
3096
|
+
e,
|
|
3097
|
+
t.length,
|
|
3098
|
+
""
|
|
3099
|
+
].join(" "), r = new TextEncoder().encode(s);
|
|
3100
|
+
for (let o = 0; o < r.length; o++)
|
|
3101
|
+
if (r[o] > 127)
|
|
3102
|
+
throw new Error(`Invalid non-ASCII character in PAE prefix at position ${o}`);
|
|
3103
|
+
const i = new Uint8Array(r.length + t.length);
|
|
3104
|
+
return i.set(r, 0), i.set(t, r.length), i;
|
|
3105
|
+
}
|
|
3106
|
+
const ve = new Uint8Array([0]), re = new Uint8Array([1]);
|
|
3107
|
+
async function Oi(e) {
|
|
3108
|
+
if (!e.inclusionProof)
|
|
3109
|
+
throw new Error("Missing inclusion proof");
|
|
3110
|
+
const t = e.inclusionProof, s = BigInt(t.logIndex), n = BigInt(t.treeSize);
|
|
3111
|
+
if (s < 0n || s >= n)
|
|
3112
|
+
throw new Error(`Invalid log index: ${s}`);
|
|
3113
|
+
const { inner: r, border: i } = Bi(s, n);
|
|
3114
|
+
if (t.hashes.length !== r + i)
|
|
3115
|
+
throw new Error("Invalid hash count in inclusion proof");
|
|
3116
|
+
const o = t.hashes.slice(0, r).map((u) => S(u)), a = t.hashes.slice(r).map((u) => S(u)), c = await _i(S(e.canonicalizedBody)), l = await Ci(
|
|
3117
|
+
await Ri(c, o, s),
|
|
3118
|
+
a
|
|
3119
|
+
), h = S(t.rootHash);
|
|
3120
|
+
if (!H(l, h))
|
|
3121
|
+
throw new Error("Calculated root hash does not match inclusion proof");
|
|
3122
|
+
}
|
|
3123
|
+
function Bi(e, t) {
|
|
3124
|
+
const s = Ti(e, t), n = Di(e >> BigInt(s));
|
|
3125
|
+
return { inner: s, border: n };
|
|
3126
|
+
}
|
|
3127
|
+
async function Ri(e, t, s) {
|
|
3128
|
+
let n = e;
|
|
3129
|
+
for (let r = 0; r < t.length; r++) {
|
|
3130
|
+
const i = t[r];
|
|
3131
|
+
s >> BigInt(r) & BigInt(1) ? n = await Te(i, n) : n = await Te(n, i);
|
|
3132
|
+
}
|
|
3133
|
+
return n;
|
|
3134
|
+
}
|
|
3135
|
+
async function Ci(e, t) {
|
|
3136
|
+
let s = e;
|
|
3137
|
+
for (const n of t)
|
|
3138
|
+
s = await Te(n, s);
|
|
3139
|
+
return s;
|
|
3140
|
+
}
|
|
3141
|
+
function Ti(e, t) {
|
|
3142
|
+
return Ui(e ^ t - BigInt(1));
|
|
3143
|
+
}
|
|
3144
|
+
function Di(e) {
|
|
3145
|
+
return e.toString(2).split("1").length - 1;
|
|
3146
|
+
}
|
|
3147
|
+
function Ui(e) {
|
|
3148
|
+
return e === 0n ? 0 : e.toString(2).length;
|
|
3149
|
+
}
|
|
3150
|
+
async function Te(e, t) {
|
|
3151
|
+
const s = new Uint8Array(
|
|
3152
|
+
re.length + e.length + t.length
|
|
3153
|
+
);
|
|
3154
|
+
s.set(re, 0), s.set(e, re.length), s.set(t, re.length + e.length);
|
|
3155
|
+
const n = await crypto.subtle.digest(U.SHA256, s);
|
|
3156
|
+
return new Uint8Array(n);
|
|
3157
|
+
}
|
|
3158
|
+
async function _i(e) {
|
|
3159
|
+
const t = new Uint8Array(ve.length + e.length);
|
|
3160
|
+
t.set(ve, 0), t.set(e, ve.length);
|
|
3161
|
+
const s = await crypto.subtle.digest(U.SHA256, t);
|
|
3162
|
+
return new Uint8Array(s);
|
|
3163
|
+
}
|
|
3164
|
+
const Ae = `
|
|
3165
|
+
|
|
3166
|
+
`, Ni = /\u2014 (\S+) (\S+)\n/g;
|
|
3167
|
+
class Pe {
|
|
3168
|
+
note;
|
|
3169
|
+
signatures;
|
|
3170
|
+
constructor(t, s) {
|
|
3171
|
+
this.note = t, this.signatures = s;
|
|
3172
|
+
}
|
|
3173
|
+
static fromString(t) {
|
|
3174
|
+
if (!t.includes(Ae))
|
|
3175
|
+
throw new Error("Missing checkpoint separator");
|
|
3176
|
+
const s = t.indexOf(Ae), n = t.slice(0, s + 1), i = t.slice(s + Ae.length).matchAll(Ni), o = [];
|
|
3177
|
+
for (const a of i) {
|
|
3178
|
+
const [, c, l] = a, h = S(l);
|
|
3179
|
+
if (h.length < 5)
|
|
3180
|
+
throw new Error("Malformed checkpoint signature");
|
|
3181
|
+
o.push({
|
|
3182
|
+
name: c,
|
|
3183
|
+
keyHint: h.subarray(0, 4),
|
|
3184
|
+
signature: h.subarray(4)
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
if (o.length === 0)
|
|
3188
|
+
throw new Error("No signatures found in checkpoint");
|
|
3189
|
+
return new Pe(n, o);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
class Fe {
|
|
3193
|
+
origin;
|
|
3194
|
+
logSize;
|
|
3195
|
+
logHash;
|
|
3196
|
+
rest;
|
|
3197
|
+
constructor(t, s, n, r) {
|
|
3198
|
+
this.origin = t, this.logSize = s, this.logHash = n, this.rest = r;
|
|
3199
|
+
}
|
|
3200
|
+
static fromString(t) {
|
|
3201
|
+
const s = t.trimEnd().split(`
|
|
3202
|
+
`);
|
|
3203
|
+
if (s.length < 3)
|
|
3204
|
+
throw new Error("Too few lines in checkpoint header");
|
|
3205
|
+
const n = s[0], r = BigInt(s[1]), i = S(s[2]), o = s.slice(3);
|
|
3206
|
+
return new Fe(n, r, i, o);
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
async function Hi(e, t) {
|
|
3210
|
+
if (!e.inclusionProof?.checkpoint)
|
|
3211
|
+
throw new Error("Missing checkpoint in inclusion proof");
|
|
3212
|
+
const s = S(e.logId.keyId), n = t.filter((l) => {
|
|
3213
|
+
const h = S(l.logId.keyId);
|
|
3214
|
+
return H(h, s);
|
|
3215
|
+
}), r = e.integratedTime ? ji(n, new Date(Number(e.integratedTime) * 1e3)) : n, i = e.inclusionProof, o = Pe.fromString(i.checkpoint.envelope), a = Fe.fromString(o.note);
|
|
3216
|
+
if (!await Vi(o, r))
|
|
3217
|
+
throw new Error("Invalid checkpoint signature");
|
|
3218
|
+
const c = S(i.rootHash);
|
|
3219
|
+
if (!H(a.logHash, c))
|
|
3220
|
+
throw new Error("Root hash mismatch between checkpoint and inclusion proof");
|
|
3221
|
+
}
|
|
3222
|
+
async function Vi(e, t) {
|
|
3223
|
+
const s = un(e.note);
|
|
3224
|
+
let n = !1;
|
|
3225
|
+
for (const r of e.signatures) {
|
|
3226
|
+
const i = t.find((c) => {
|
|
3227
|
+
const l = S(c.logId.keyId);
|
|
3228
|
+
return H(l.subarray(0, 4), r.keyHint);
|
|
3229
|
+
});
|
|
3230
|
+
if (!i)
|
|
3231
|
+
continue;
|
|
3232
|
+
const o = await ki(i);
|
|
3233
|
+
await Rt(
|
|
3234
|
+
o,
|
|
3235
|
+
s,
|
|
3236
|
+
r.signature,
|
|
3237
|
+
i.hashAlgorithm
|
|
3238
|
+
) && (n = !0);
|
|
3239
|
+
}
|
|
3240
|
+
return n;
|
|
3241
|
+
}
|
|
3242
|
+
function ji(e, t) {
|
|
3243
|
+
return e.filter((s) => {
|
|
3244
|
+
const n = new Date(s.publicKey.validFor.start), r = s.publicKey.validFor.end ? new Date(s.publicKey.validFor.end) : null;
|
|
3245
|
+
return t >= n && (!r || t <= r);
|
|
3246
|
+
});
|
|
3247
|
+
}
|
|
3248
|
+
async function ki(e) {
|
|
3249
|
+
const t = e.publicKey.keyDetails;
|
|
3250
|
+
let s, n;
|
|
3251
|
+
if (t === "ecdsa-sha2-nistp256")
|
|
3252
|
+
s = P.Ecdsa, n = "P256-SHA256";
|
|
3253
|
+
else if (t.includes("ECDSA"))
|
|
3254
|
+
s = P.Ecdsa, n = t.replace("PKIX_ECDSA_", "").replaceAll("_", "-");
|
|
3255
|
+
else if (t.includes("ED25519"))
|
|
3256
|
+
s = P.Ed25519, n = P.Ed25519;
|
|
3257
|
+
else if (t.includes("RSA"))
|
|
3258
|
+
s = P.RSA, n = t.replace("PKIX_RSA_", "").replaceAll("_", "-");
|
|
3259
|
+
else
|
|
3260
|
+
throw new Error(`Unsupported key type in keyDetails: ${t}`);
|
|
3261
|
+
return Zt(
|
|
3262
|
+
s,
|
|
3263
|
+
n,
|
|
3264
|
+
e.publicKey.rawBytes
|
|
3265
|
+
);
|
|
3266
|
+
}
|
|
3267
|
+
async function Li(e, t) {
|
|
3268
|
+
const s = e;
|
|
3269
|
+
switch (s.apiVersion) {
|
|
3270
|
+
case "0.0.1":
|
|
3271
|
+
return Ki(s, t);
|
|
3272
|
+
case "0.0.2":
|
|
3273
|
+
return Pi(s, t);
|
|
3274
|
+
default:
|
|
3275
|
+
throw new Error(
|
|
3276
|
+
`Unsupported hashedrekord version: ${s.apiVersion}`
|
|
3277
|
+
);
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
function Ki(e, t) {
|
|
3281
|
+
const s = e.spec;
|
|
3282
|
+
if (!t.messageSignature)
|
|
3283
|
+
throw new Error("Bundle missing messageSignature for hashedrekord entry");
|
|
3284
|
+
const n = s.signature.content || "", r = S(n), i = S(t.messageSignature.signature);
|
|
3285
|
+
if (!H(r, i))
|
|
3286
|
+
throw new Error("Signature mismatch between TLog entry and bundle");
|
|
3287
|
+
const o = s.data.hash?.value || "", a = Kt(o), c = S(
|
|
3288
|
+
t.messageSignature.messageDigest.digest
|
|
3289
|
+
);
|
|
3290
|
+
if (!H(a, c))
|
|
3291
|
+
throw new Error("Digest mismatch between TLog entry and bundle");
|
|
3292
|
+
}
|
|
3293
|
+
function Pi(e, t) {
|
|
3294
|
+
const s = e.spec.hashedRekordV002;
|
|
3295
|
+
if (!t.messageSignature)
|
|
3296
|
+
throw new Error("Bundle missing messageSignature for hashedrekord v0.0.2 entry");
|
|
3297
|
+
const n = s.signature.content || "", r = S(n), i = S(t.messageSignature.signature);
|
|
3298
|
+
if (!H(r, i))
|
|
3299
|
+
throw new Error("Signature mismatch between TLog entry and bundle (v0.0.2)");
|
|
3300
|
+
const o = s.data.digest || "", a = S(o), c = S(
|
|
3301
|
+
t.messageSignature.messageDigest.digest
|
|
3302
|
+
);
|
|
3303
|
+
if (!H(a, c))
|
|
3304
|
+
throw new Error("Digest mismatch between TLog entry and bundle (v0.0.2)");
|
|
3305
|
+
}
|
|
3306
|
+
async function Fi(e, t) {
|
|
3307
|
+
const s = e;
|
|
3308
|
+
switch (s.apiVersion) {
|
|
3309
|
+
case "0.0.1":
|
|
3310
|
+
return Gi(s, t);
|
|
3311
|
+
case "0.0.2":
|
|
3312
|
+
return $i(s, t);
|
|
3313
|
+
default:
|
|
3314
|
+
throw new Error(
|
|
3315
|
+
`Unsupported dsse version: ${s.apiVersion}`
|
|
3316
|
+
);
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
async function Gi(e, t) {
|
|
3320
|
+
if (!t.dsseEnvelope)
|
|
3321
|
+
throw new Error("Bundle missing dsseEnvelope for DSSE entry");
|
|
3322
|
+
if (!e.spec.signatures || e.spec.signatures.length !== 1)
|
|
3323
|
+
throw new Error("DSSE entry must have exactly one signature");
|
|
3324
|
+
const s = e.spec.signatures[0].signature, n = S(s);
|
|
3325
|
+
if (t.dsseEnvelope.signatures.length === 0)
|
|
3326
|
+
throw new Error("Bundle DSSE envelope missing signatures");
|
|
3327
|
+
const r = S(t.dsseEnvelope.signatures[0].sig);
|
|
3328
|
+
if (!H(n, r))
|
|
3329
|
+
throw new Error("DSSE signature mismatch between TLog entry and bundle");
|
|
3330
|
+
if (!e.spec.payloadHash?.value || !e.spec.payloadHash?.algorithm)
|
|
3331
|
+
throw new Error("DSSE entry missing payloadHash or algorithm");
|
|
3332
|
+
const i = ke(e.spec.payloadHash.algorithm), o = Kt(e.spec.payloadHash.value), a = S(t.dsseEnvelope.payload), c = new Uint8Array(
|
|
3333
|
+
await crypto.subtle.digest(i, a)
|
|
3334
|
+
);
|
|
3335
|
+
if (!H(o, c))
|
|
3336
|
+
throw new Error("DSSE payload hash mismatch between TLog entry and bundle");
|
|
3337
|
+
}
|
|
3338
|
+
async function $i(e, t) {
|
|
3339
|
+
if (!t.dsseEnvelope)
|
|
3340
|
+
throw new Error("Bundle missing dsseEnvelope for DSSE v0.0.2 entry");
|
|
3341
|
+
const s = e.spec.dsseV002;
|
|
3342
|
+
if (!s)
|
|
3343
|
+
throw new Error("DSSE v0.0.2 entry missing dsseV002 spec");
|
|
3344
|
+
if (!s.signatures || s.signatures.length !== 1)
|
|
3345
|
+
throw new Error("DSSE v0.0.2 entry must have exactly one signature");
|
|
3346
|
+
const n = s.signatures[0].content, r = S(n);
|
|
3347
|
+
if (t.dsseEnvelope.signatures.length === 0)
|
|
3348
|
+
throw new Error("Bundle DSSE envelope missing signatures");
|
|
3349
|
+
const i = S(t.dsseEnvelope.signatures[0].sig);
|
|
3350
|
+
if (!H(r, i))
|
|
3351
|
+
throw new Error("DSSE signature mismatch between TLog entry and bundle (v0.0.2)");
|
|
3352
|
+
if (!s.payloadHash?.digest || !s.payloadHash?.algorithm)
|
|
3353
|
+
throw new Error("DSSE v0.0.2 entry missing payloadHash or algorithm");
|
|
3354
|
+
const o = ke(s.payloadHash.algorithm), a = S(s.payloadHash.digest), c = S(t.dsseEnvelope.payload), l = new Uint8Array(
|
|
3355
|
+
await crypto.subtle.digest(o, c)
|
|
3356
|
+
);
|
|
3357
|
+
if (!H(a, l))
|
|
3358
|
+
throw new Error("DSSE payload hash mismatch between TLog entry and bundle (v0.0.2)");
|
|
3359
|
+
}
|
|
3360
|
+
async function Xi(e, t) {
|
|
3361
|
+
const s = e;
|
|
3362
|
+
if (s.apiVersion !== "0.0.2")
|
|
3363
|
+
throw new Error(
|
|
3364
|
+
`Unsupported intoto version: ${s.apiVersion}`
|
|
3365
|
+
);
|
|
3366
|
+
if (!t.dsseEnvelope)
|
|
3367
|
+
throw new Error("Bundle missing dsseEnvelope for intoto entry");
|
|
3368
|
+
const n = s.spec.content.envelope;
|
|
3369
|
+
if (!n.signatures || n.signatures.length !== 1)
|
|
3370
|
+
throw new Error("Intoto entry must have exactly one signature");
|
|
3371
|
+
const r = n.signatures[0].sig, i = ln(r), o = S(i);
|
|
3372
|
+
if (t.dsseEnvelope.signatures.length === 0)
|
|
3373
|
+
throw new Error("Bundle DSSE envelope missing signatures");
|
|
3374
|
+
const a = S(t.dsseEnvelope.signatures[0].sig);
|
|
3375
|
+
if (!H(o, a))
|
|
3376
|
+
throw new Error("Intoto signature mismatch between TLog entry and bundle");
|
|
3377
|
+
if (s.spec.content.payloadHash) {
|
|
3378
|
+
if (!s.spec.content.payloadHash.algorithm)
|
|
3379
|
+
throw new Error("Intoto entry missing payloadHash algorithm");
|
|
3380
|
+
const c = ke(s.spec.content.payloadHash.algorithm), l = Kt(s.spec.content.payloadHash.value), h = S(t.dsseEnvelope.payload), u = new Uint8Array(
|
|
3381
|
+
await crypto.subtle.digest(c, h)
|
|
3382
|
+
);
|
|
3383
|
+
if (!H(l, u))
|
|
3384
|
+
throw new Error("Intoto payload hash mismatch between TLog entry and bundle");
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
async function qi(e, t) {
|
|
3388
|
+
const s = Mi(e), { kind: n, version: r } = e.kindVersion;
|
|
3389
|
+
if (n !== s.kind || r !== s.apiVersion)
|
|
3390
|
+
throw new Error(
|
|
3391
|
+
`kind/version mismatch - expected: ${n}/${r}, received: ${s.kind}/${s.apiVersion}`
|
|
3392
|
+
);
|
|
3393
|
+
switch (s.kind) {
|
|
3394
|
+
case "hashedrekord":
|
|
3395
|
+
return Li(s, t);
|
|
3396
|
+
case "dsse":
|
|
3397
|
+
return Fi(s, t);
|
|
3398
|
+
case "intoto":
|
|
3399
|
+
return Xi(s, t);
|
|
3400
|
+
default:
|
|
3401
|
+
throw new Error(`Unsupported TLog entry kind: ${s.kind}`);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
function Mi(e) {
|
|
3405
|
+
try {
|
|
3406
|
+
const t = ln(e.canonicalizedBody), s = JSON.parse(t);
|
|
3407
|
+
if (!s.apiVersion || !s.kind || !s.spec)
|
|
3408
|
+
throw new Error("Invalid Rekor entry structure");
|
|
3409
|
+
return s;
|
|
3410
|
+
} catch (t) {
|
|
3411
|
+
throw new Error(
|
|
3412
|
+
`Failed to parse canonicalized body: ${t instanceof Error ? t.message : String(t)}`
|
|
3413
|
+
);
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
class ct extends Error {
|
|
3417
|
+
}
|
|
3418
|
+
class Zi {
|
|
3419
|
+
root;
|
|
3420
|
+
constructor(t) {
|
|
3421
|
+
this.root = t;
|
|
3422
|
+
}
|
|
3423
|
+
get version() {
|
|
3424
|
+
return this.root.subs[0].toInteger();
|
|
3425
|
+
}
|
|
3426
|
+
get genTime() {
|
|
3427
|
+
return this.root.subs[4].toDate();
|
|
3428
|
+
}
|
|
3429
|
+
get messageImprintHashAlgorithm() {
|
|
3430
|
+
const t = this.messageImprintObj.subs[0].subs[0].toOID(), s = Le[t];
|
|
3431
|
+
if (!s)
|
|
3432
|
+
throw new Error(`Unknown message imprint hash algorithm OID: ${t}`);
|
|
3433
|
+
return s;
|
|
3434
|
+
}
|
|
3435
|
+
get messageImprintHashedMessage() {
|
|
3436
|
+
return this.messageImprintObj.subs[1].value;
|
|
3437
|
+
}
|
|
3438
|
+
get raw() {
|
|
3439
|
+
return this.root.toDER();
|
|
3440
|
+
}
|
|
3441
|
+
async verify(t) {
|
|
3442
|
+
const s = this.messageImprintHashAlgorithm, n = s === "sha256" ? U.SHA256 : s === "sha384" ? U.SHA384 : s === "sha512" ? U.SHA512 : s, r = await crypto.subtle.digest(
|
|
3443
|
+
n,
|
|
3444
|
+
t
|
|
3445
|
+
);
|
|
3446
|
+
if (!H(new Uint8Array(r), this.messageImprintHashedMessage))
|
|
3447
|
+
throw new ct(
|
|
3448
|
+
"message imprint does not match artifact"
|
|
3449
|
+
);
|
|
3450
|
+
}
|
|
3451
|
+
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
3452
|
+
get messageImprintObj() {
|
|
3453
|
+
return this.root.subs[2];
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
const Wi = "1.2.840.113549.1.7.2", Yi = "1.2.840.113549.1.9.16.1.4", zi = "1.2.840.113549.1.9.4";
|
|
3457
|
+
class Ge {
|
|
3458
|
+
root;
|
|
3459
|
+
constructor(t) {
|
|
3460
|
+
this.root = t;
|
|
3461
|
+
}
|
|
3462
|
+
static parse(t) {
|
|
3463
|
+
const s = Mt.parseBuffer(t);
|
|
3464
|
+
return new Ge(s);
|
|
3465
|
+
}
|
|
3466
|
+
get status() {
|
|
3467
|
+
return this.pkiStatusInfoObj.subs[0].toInteger();
|
|
3468
|
+
}
|
|
3469
|
+
get contentType() {
|
|
3470
|
+
return this.contentTypeObj.toOID();
|
|
3471
|
+
}
|
|
3472
|
+
get eContentType() {
|
|
3473
|
+
return this.eContentTypeObj.toOID();
|
|
3474
|
+
}
|
|
3475
|
+
get signingTime() {
|
|
3476
|
+
return this.tstInfo.genTime;
|
|
3477
|
+
}
|
|
3478
|
+
get signerIssuer() {
|
|
3479
|
+
return this.signerSidObj.subs[0].value;
|
|
3480
|
+
}
|
|
3481
|
+
get signerSerialNumber() {
|
|
3482
|
+
return this.signerSidObj.subs[1].value;
|
|
3483
|
+
}
|
|
3484
|
+
get signerDigestAlgorithm() {
|
|
3485
|
+
const t = this.signerDigestAlgorithmObj.subs[0].toOID(), s = Le[t];
|
|
3486
|
+
if (!s)
|
|
3487
|
+
throw new Error(`Unknown digest algorithm OID: ${t}`);
|
|
3488
|
+
return s;
|
|
3489
|
+
}
|
|
3490
|
+
get signatureAlgorithm() {
|
|
3491
|
+
const t = this.signatureAlgorithmObj.subs[0].toOID();
|
|
3492
|
+
return le[t] || he[t];
|
|
3493
|
+
}
|
|
3494
|
+
get signatureValue() {
|
|
3495
|
+
return this.signatureValueObj.value;
|
|
3496
|
+
}
|
|
3497
|
+
get tstInfo() {
|
|
3498
|
+
return new Zi(this.eContentObj.subs[0].subs[0]);
|
|
3499
|
+
}
|
|
3500
|
+
async verify(t, s) {
|
|
3501
|
+
if (!this.timeStampTokenObj)
|
|
3502
|
+
throw new ct("timeStampToken is missing");
|
|
3503
|
+
if (this.contentType !== Wi)
|
|
3504
|
+
throw new ct(
|
|
3505
|
+
`incorrect content type: ${this.contentType}`
|
|
3506
|
+
);
|
|
3507
|
+
if (this.eContentType !== Yi)
|
|
3508
|
+
throw new ct(
|
|
3509
|
+
`incorrect encapsulated content type: ${this.eContentType}`
|
|
3510
|
+
);
|
|
3511
|
+
await this.tstInfo.verify(t), await this.verifyMessageDigest(), await this.verifySignature(s);
|
|
3512
|
+
}
|
|
3513
|
+
async verifyMessageDigest() {
|
|
3514
|
+
const t = this.signerDigestAlgorithm, s = t === "sha256" ? U.SHA256 : t === "sha384" ? U.SHA384 : t === "sha512" ? U.SHA512 : t, n = await crypto.subtle.digest(
|
|
3515
|
+
s,
|
|
3516
|
+
this.tstInfo.raw
|
|
3517
|
+
), r = this.messageDigestAttributeObj.subs[1].subs[0].value;
|
|
3518
|
+
if (!H(new Uint8Array(n), r))
|
|
3519
|
+
throw new ct(
|
|
3520
|
+
"signed data does not match tstInfo"
|
|
3521
|
+
);
|
|
3522
|
+
}
|
|
3523
|
+
async verifySignature(t) {
|
|
3524
|
+
const s = this.signedAttrsObj.toDER();
|
|
3525
|
+
s[0] = 49;
|
|
3526
|
+
const n = this.signatureAlgorithmObj.subs[0].toOID(), r = le[n] || he[n];
|
|
3527
|
+
if (!r)
|
|
3528
|
+
throw new ct(
|
|
3529
|
+
`Unsupported signature algorithm OID: ${n}`
|
|
3530
|
+
);
|
|
3531
|
+
if (!await Rt(
|
|
3532
|
+
t,
|
|
3533
|
+
s,
|
|
3534
|
+
this.signatureValue,
|
|
3535
|
+
r
|
|
3536
|
+
))
|
|
3537
|
+
throw new ct(
|
|
3538
|
+
"signature verification failed"
|
|
3539
|
+
);
|
|
3540
|
+
}
|
|
3541
|
+
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
3542
|
+
get pkiStatusInfoObj() {
|
|
3543
|
+
return this.root.subs[0];
|
|
3544
|
+
}
|
|
3545
|
+
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2
|
|
3546
|
+
get timeStampTokenObj() {
|
|
3547
|
+
return this.root.subs[1];
|
|
3548
|
+
}
|
|
3549
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-3
|
|
3550
|
+
get contentTypeObj() {
|
|
3551
|
+
return this.timeStampTokenObj.subs[0];
|
|
3552
|
+
}
|
|
3553
|
+
// https://www.rfc-editor.org/rfc/rfc5652#section-3
|
|
3554
|
+
get signedDataObj() {
|
|
3555
|
+
const t = this.timeStampTokenObj.subs.find(
|
|
3556
|
+
(s) => s.tag.isContextSpecific(0)
|
|
3557
|
+
);
|
|
3558
|
+
if (!t)
|
|
3559
|
+
throw new ct(
|
|
3560
|
+
"Missing timeStampTokenObj sub."
|
|
3561
|
+
);
|
|
3562
|
+
return t.subs[0];
|
|
3563
|
+
}
|
|
3564
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.1
|
|
3565
|
+
get encapContentInfoObj() {
|
|
3566
|
+
return this.signedDataObj.subs[2];
|
|
3567
|
+
}
|
|
3568
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.1
|
|
3569
|
+
get signerInfosObj() {
|
|
3570
|
+
const t = this.signedDataObj;
|
|
3571
|
+
return t.subs[t.subs.length - 1];
|
|
3572
|
+
}
|
|
3573
|
+
// https://www.rfc-editor.org/rfc/rfc5652#section-5.1
|
|
3574
|
+
get signerInfoObj() {
|
|
3575
|
+
return this.signerInfosObj.subs[0];
|
|
3576
|
+
}
|
|
3577
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.2
|
|
3578
|
+
get eContentTypeObj() {
|
|
3579
|
+
return this.encapContentInfoObj.subs[0];
|
|
3580
|
+
}
|
|
3581
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.2
|
|
3582
|
+
get eContentObj() {
|
|
3583
|
+
return this.encapContentInfoObj.subs[1];
|
|
3584
|
+
}
|
|
3585
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3586
|
+
get signedAttrsObj() {
|
|
3587
|
+
const t = this.signerInfoObj.subs.find(
|
|
3588
|
+
(s) => s.tag.isContextSpecific(0)
|
|
3589
|
+
);
|
|
3590
|
+
if (!t)
|
|
3591
|
+
throw new ct("Missing signedAttrsObj.");
|
|
3592
|
+
return t;
|
|
3593
|
+
}
|
|
3594
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3595
|
+
get messageDigestAttributeObj() {
|
|
3596
|
+
const t = this.signedAttrsObj.subs.find(
|
|
3597
|
+
(s) => s.subs[0].tag.isOID() && s.subs[0].toOID() === zi
|
|
3598
|
+
);
|
|
3599
|
+
if (!t)
|
|
3600
|
+
throw new ct("Missing messageDigest.");
|
|
3601
|
+
return t;
|
|
3602
|
+
}
|
|
3603
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3604
|
+
get signerSidObj() {
|
|
3605
|
+
return this.signerInfoObj.subs[1];
|
|
3606
|
+
}
|
|
3607
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3608
|
+
get signerDigestAlgorithmObj() {
|
|
3609
|
+
return this.signerInfoObj.subs[2];
|
|
3610
|
+
}
|
|
3611
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3612
|
+
get signatureAlgorithmObj() {
|
|
3613
|
+
return this.signerInfoObj.subs[4];
|
|
3614
|
+
}
|
|
3615
|
+
// https://datatracker.ietf.org/doc/html/rfc5652#section-5.3
|
|
3616
|
+
get signatureValueObj() {
|
|
3617
|
+
return this.signerInfoObj.subs[5];
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
async function Ji(e, t, s) {
|
|
3621
|
+
const n = e.signingTime;
|
|
3622
|
+
let r = Qi(
|
|
3623
|
+
s,
|
|
3624
|
+
n
|
|
3625
|
+
);
|
|
3626
|
+
r = to(r, {
|
|
3627
|
+
serialNumber: e.signerSerialNumber,
|
|
3628
|
+
issuer: e.signerIssuer
|
|
3629
|
+
});
|
|
3630
|
+
const i = await Promise.allSettled(
|
|
3631
|
+
r.map((a) => eo(e, t, a))
|
|
3632
|
+
);
|
|
3633
|
+
if (!i.some(
|
|
3634
|
+
(a) => a.status === "fulfilled"
|
|
3635
|
+
)) {
|
|
3636
|
+
const a = i.filter((c) => c.status === "rejected").map((c) => c.reason?.message || "Unknown error");
|
|
3637
|
+
throw new Error(`Timestamp could not be verified against any trusted authority. Errors: ${a.join(", ")}`);
|
|
3638
|
+
}
|
|
3639
|
+
return n;
|
|
3640
|
+
}
|
|
3641
|
+
function Qi(e, t) {
|
|
3642
|
+
return e.filter((s) => {
|
|
3643
|
+
if (s.validFor) {
|
|
3644
|
+
const n = s.validFor.start ? new Date(s.validFor.start) : null, r = s.validFor.end ? new Date(s.validFor.end) : null;
|
|
3645
|
+
if (n && t < n || r && t > r)
|
|
3646
|
+
return !1;
|
|
3647
|
+
}
|
|
3648
|
+
return !0;
|
|
3649
|
+
});
|
|
3650
|
+
}
|
|
3651
|
+
function to(e, t) {
|
|
3652
|
+
return e.filter((s) => {
|
|
3653
|
+
if (!s.certChain || s.certChain.certificates.length === 0)
|
|
3654
|
+
return !1;
|
|
3655
|
+
const n = J.parse(
|
|
3656
|
+
S(s.certChain.certificates[0].rawBytes)
|
|
3657
|
+
);
|
|
3658
|
+
return H(n.serialNumber, t.serialNumber) && H(n.issuer, t.issuer);
|
|
3659
|
+
});
|
|
3660
|
+
}
|
|
3661
|
+
async function eo(e, t, s) {
|
|
3662
|
+
if (!s.certChain || s.certChain.certificates.length === 0)
|
|
3663
|
+
throw new Error("Certificate authority missing certificate chain");
|
|
3664
|
+
const n = J.parse(
|
|
3665
|
+
S(s.certChain.certificates[0].rawBytes)
|
|
3666
|
+
), r = e.signingTime, i = s.certChain.certificates.slice(1).map((a) => J.parse(S(a.rawBytes)));
|
|
3667
|
+
try {
|
|
3668
|
+
await new ws({
|
|
3669
|
+
untrustedCert: n,
|
|
3670
|
+
trustedCerts: i,
|
|
3671
|
+
timestamp: r
|
|
3672
|
+
}).verify();
|
|
3673
|
+
} catch (a) {
|
|
3674
|
+
throw new Error(`TSA certificate chain verification failed: ${a instanceof Error ? a.message : String(a)}`);
|
|
3675
|
+
}
|
|
3676
|
+
const o = await n.publicKeyObj;
|
|
3677
|
+
await e.verify(t, o);
|
|
3678
|
+
}
|
|
3679
|
+
async function no(e, t, s) {
|
|
3680
|
+
if (!e?.rfc3161Timestamps?.length)
|
|
3681
|
+
return [];
|
|
3682
|
+
const n = [];
|
|
3683
|
+
for (const r of e.rfc3161Timestamps) {
|
|
3684
|
+
const i = S(r.signedTimestamp), o = Ge.parse(i), a = await Ji(
|
|
3685
|
+
o,
|
|
3686
|
+
t,
|
|
3687
|
+
s
|
|
3688
|
+
);
|
|
3689
|
+
n.push({
|
|
3690
|
+
signingTime: a,
|
|
3691
|
+
signerSerialNumber: Array.from(o.signerSerialNumber).join(",")
|
|
3692
|
+
});
|
|
3693
|
+
}
|
|
3694
|
+
for (let r = 0; r < n.length; r++)
|
|
3695
|
+
for (let i = r + 1; i < n.length; i++)
|
|
3696
|
+
if (n[r].signingTime.getTime() === n[i].signingTime.getTime() && n[r].signerSerialNumber === n[i].signerSerialNumber)
|
|
3697
|
+
throw new Error("Duplicate TSA timestamp detected");
|
|
3698
|
+
return n.map((r) => r.signingTime);
|
|
3699
|
+
}
|
|
3700
|
+
const Xt = {
|
|
3701
|
+
metadataUrl: "https://tuf-repo-cdn.sigstore.dev/",
|
|
3702
|
+
targetBaseUrl: "https://tuf-repo-cdn.sigstore.dev/targets/",
|
|
3703
|
+
namespace: "sigstore-browser",
|
|
3704
|
+
trustedRootTarget: "trusted_root.json",
|
|
3705
|
+
cacheTTL: 36e5
|
|
3706
|
+
// 1 hour
|
|
3707
|
+
};
|
|
3708
|
+
class so {
|
|
3709
|
+
metadataUrl;
|
|
3710
|
+
targetBaseUrl;
|
|
3711
|
+
initialRoot;
|
|
3712
|
+
namespace;
|
|
3713
|
+
trustedRootTarget;
|
|
3714
|
+
cacheTTL;
|
|
3715
|
+
tufClient;
|
|
3716
|
+
cachedRoot;
|
|
3717
|
+
cacheTimestamp;
|
|
3718
|
+
constructor(t = {}) {
|
|
3719
|
+
const s = t.metadataUrl || Xt.metadataUrl;
|
|
3720
|
+
this.metadataUrl = s.endsWith("/") ? s : `${s}/`;
|
|
3721
|
+
const n = t.targetBaseUrl || Xt.targetBaseUrl;
|
|
3722
|
+
this.targetBaseUrl = n.endsWith("/") ? n : `${n}/`, this.initialRoot = t.initialRoot, this.namespace = t.namespace || Xt.namespace, this.trustedRootTarget = t.trustedRootTarget || Xt.trustedRootTarget, this.cacheTTL = t.cacheTTL ?? Xt.cacheTTL;
|
|
3723
|
+
}
|
|
3724
|
+
/**
|
|
3725
|
+
* Initialize the TUF client
|
|
3726
|
+
* Lazy initialization to avoid loading TUF client until needed
|
|
3727
|
+
*/
|
|
3728
|
+
async initTUFClient() {
|
|
3729
|
+
if (!this.tufClient)
|
|
3730
|
+
try {
|
|
3731
|
+
const { TUFClient: t } = await import("./tuf-D48cBq5i.js"), s = this.initialRoot || await this.getDefaultRoot();
|
|
3732
|
+
this.tufClient = new t(
|
|
3733
|
+
this.metadataUrl,
|
|
3734
|
+
s,
|
|
3735
|
+
this.namespace,
|
|
3736
|
+
this.targetBaseUrl
|
|
3737
|
+
);
|
|
3738
|
+
} catch (t) {
|
|
3739
|
+
throw new Error(
|
|
3740
|
+
`Failed to initialize TUF client: ${t instanceof Error ? t.message : String(t)}`
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
/**
|
|
3745
|
+
* Get the default embedded root metadata
|
|
3746
|
+
* Returns the TUF root.json that bootstraps the TUF client
|
|
3747
|
+
*/
|
|
3748
|
+
async getDefaultRoot() {
|
|
3749
|
+
const s = (await import("./tuf-root-D8m0y2I4.js")).default, n = new TextDecoder(), r = Uint8Array.from(atob(s), (i) => i.charCodeAt(0));
|
|
3750
|
+
return n.decode(r);
|
|
3751
|
+
}
|
|
3752
|
+
/**
|
|
3753
|
+
* Check if cached trusted root is still valid
|
|
3754
|
+
*/
|
|
3755
|
+
isCacheValid() {
|
|
3756
|
+
return !this.cachedRoot || !this.cacheTimestamp ? !1 : Date.now() - this.cacheTimestamp < this.cacheTTL;
|
|
3757
|
+
}
|
|
3758
|
+
/**
|
|
3759
|
+
* Get the Sigstore trusted root metadata
|
|
3760
|
+
* Uses TUF to securely fetch and verify the trusted root
|
|
3761
|
+
*
|
|
3762
|
+
* @returns Promise<TrustedRoot> The verified trusted root metadata
|
|
3763
|
+
* @throws Error if TUF verification fails or root cannot be fetched
|
|
3764
|
+
*/
|
|
3765
|
+
async getTrustedRoot() {
|
|
3766
|
+
if (this.isCacheValid() && this.cachedRoot)
|
|
3767
|
+
return this.cachedRoot;
|
|
3768
|
+
if (await this.initTUFClient(), !this.tufClient)
|
|
3769
|
+
throw new Error("TUF client not initialized");
|
|
3770
|
+
try {
|
|
3771
|
+
await this.tufClient.updateTUF();
|
|
3772
|
+
const t = await this.tufClient.getTarget(this.trustedRootTarget), s = Q(new Uint8Array(t)), n = JSON.parse(s);
|
|
3773
|
+
return this.cachedRoot = n, this.cacheTimestamp = Date.now(), n;
|
|
3774
|
+
} catch (t) {
|
|
3775
|
+
throw new Error(
|
|
3776
|
+
`Failed to fetch trusted root via TUF: ${t instanceof Error ? t.message : String(t)}`
|
|
3777
|
+
);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
/**
|
|
3781
|
+
* Manually refresh the trusted root from TUF
|
|
3782
|
+
* Bypasses cache and forces a fresh fetch
|
|
3783
|
+
*
|
|
3784
|
+
* @returns Promise<TrustedRoot> The updated trusted root metadata
|
|
3785
|
+
*/
|
|
3786
|
+
async refreshTrustedRoot() {
|
|
3787
|
+
return this.cachedRoot = void 0, this.cacheTimestamp = void 0, await this.getTrustedRoot();
|
|
3788
|
+
}
|
|
3789
|
+
/**
|
|
3790
|
+
* Clear the cached trusted root
|
|
3791
|
+
* Next call to getTrustedRoot() will fetch fresh data
|
|
3792
|
+
*/
|
|
3793
|
+
clearCache() {
|
|
3794
|
+
this.cachedRoot = void 0, this.cacheTimestamp = void 0;
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
const qt = "application/vnd.dev.sigstore.bundle";
|
|
3798
|
+
function ro(e) {
|
|
3799
|
+
switch (e) {
|
|
3800
|
+
case `${qt}+json;version=0.1`:
|
|
3801
|
+
return "0.1";
|
|
3802
|
+
case `${qt}+json;version=0.2`:
|
|
3803
|
+
return "0.2";
|
|
3804
|
+
case `${qt}+json;version=0.3`:
|
|
3805
|
+
return "0.3";
|
|
3806
|
+
}
|
|
3807
|
+
if (e.startsWith(`${qt}.v`) && e.endsWith("+json")) {
|
|
3808
|
+
const t = e.replace(`${qt}.v`, "").replace("+json", "");
|
|
3809
|
+
if (/^\d+\.\d+(\.\d+)?$/.test(t))
|
|
3810
|
+
return t;
|
|
3811
|
+
}
|
|
3812
|
+
return "0.1";
|
|
3813
|
+
}
|
|
3814
|
+
class oo {
|
|
3815
|
+
root;
|
|
3816
|
+
rawRoot;
|
|
3817
|
+
options;
|
|
3818
|
+
constructor(t = {}) {
|
|
3819
|
+
this.root = void 0, this.rawRoot = void 0, this.options = {
|
|
3820
|
+
tlogThreshold: t.tlogThreshold ?? 1,
|
|
3821
|
+
ctlogThreshold: t.ctlogThreshold ?? 1,
|
|
3822
|
+
tsaThreshold: t.tsaThreshold ?? 0
|
|
3823
|
+
};
|
|
3824
|
+
}
|
|
3825
|
+
async loadLog(t, s) {
|
|
3826
|
+
for (const n of s)
|
|
3827
|
+
if (t > new Date(n.publicKey.validFor.start) && (!n.publicKey.validFor.end || new Date(n.publicKey.validFor.end) > t))
|
|
3828
|
+
return {
|
|
3829
|
+
publicKey: await Zt(
|
|
3830
|
+
n.publicKey.keyDetails,
|
|
3831
|
+
n.publicKey.keyDetails,
|
|
3832
|
+
n.publicKey.rawBytes
|
|
3833
|
+
),
|
|
3834
|
+
logId: S(n.logId.keyId)
|
|
3835
|
+
};
|
|
3836
|
+
}
|
|
3837
|
+
async loadCTLogs(t, s) {
|
|
3838
|
+
const n = [];
|
|
3839
|
+
for (const r of s) {
|
|
3840
|
+
const i = new Date(r.publicKey.validFor.start), o = r.publicKey.validFor.end ? new Date(r.publicKey.validFor.end) : /* @__PURE__ */ new Date("9999-12-31");
|
|
3841
|
+
if (i <= t) {
|
|
3842
|
+
const a = await Zt(
|
|
3843
|
+
r.publicKey.keyDetails,
|
|
3844
|
+
r.publicKey.keyDetails,
|
|
3845
|
+
r.publicKey.rawBytes
|
|
3846
|
+
);
|
|
3847
|
+
n.push({
|
|
3848
|
+
logID: S(r.logId.keyId),
|
|
3849
|
+
publicKey: a,
|
|
3850
|
+
validFor: { start: i, end: o }
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
if (n.length === 0)
|
|
3855
|
+
throw new Error("Could not find any valid CT logs in sigstore root.");
|
|
3856
|
+
return n;
|
|
3857
|
+
}
|
|
3858
|
+
// Adapted from https://github.com/sigstore/sigstore-js/blob/main/packages/verify/src/key/certificate.ts#L22-L53
|
|
3859
|
+
// Verifies that the leaf certificate chains to a trusted CA and is valid at the given timestamp.
|
|
3860
|
+
// Differences from sigstore-js:
|
|
3861
|
+
// - This is async (uses await) because our CertificateChainVerifier.verify() is async
|
|
3862
|
+
// - sigstore-js filters CAs using filterCertAuthorities() before calling this function,
|
|
3863
|
+
// we do the timestamp filtering inline within this function
|
|
3864
|
+
async verifyCertificateChain(t, s, n) {
|
|
3865
|
+
let r;
|
|
3866
|
+
for (const i of n)
|
|
3867
|
+
if (!(t < i.validFor.start || t > i.validFor.end))
|
|
3868
|
+
try {
|
|
3869
|
+
return await new ws({
|
|
3870
|
+
trustedCerts: i.certChain,
|
|
3871
|
+
untrustedCert: s,
|
|
3872
|
+
timestamp: t
|
|
3873
|
+
}).verify();
|
|
3874
|
+
} catch (o) {
|
|
3875
|
+
r = o;
|
|
3876
|
+
}
|
|
3877
|
+
throw new Error(`Failed to verify certificate chain: ${r?.message || "No valid CAs found"}`);
|
|
3878
|
+
}
|
|
3879
|
+
// Load timestamp authorities that are valid at the frozen timestamp.
|
|
3880
|
+
// Unlike sigstore-js which doesn't pre-load TSAs (it passes raw TSA data to timestamp verification),
|
|
3881
|
+
// we parse and filter them at initialization time for consistency with how we handle CAs and other roots.
|
|
3882
|
+
loadTSA(t, s) {
|
|
3883
|
+
if (!s || s.length === 0)
|
|
3884
|
+
return [];
|
|
3885
|
+
const n = [];
|
|
3886
|
+
for (const r of s) {
|
|
3887
|
+
const i = new Date(r.validFor.start), o = r.validFor.end ? new Date(r.validFor.end) : /* @__PURE__ */ new Date(864e13);
|
|
3888
|
+
if (t > i && t < o) {
|
|
3889
|
+
const a = r.certChain.certificates.map(
|
|
3890
|
+
(c) => J.parse(S(c.rawBytes))
|
|
3891
|
+
);
|
|
3892
|
+
a.length > 0 && n.push({
|
|
3893
|
+
certChain: a,
|
|
3894
|
+
validFor: { start: i, end: o }
|
|
3895
|
+
});
|
|
3896
|
+
}
|
|
3897
|
+
}
|
|
3898
|
+
return n;
|
|
3899
|
+
}
|
|
3900
|
+
// Load certificate authorities (Fulcio CAs) that are valid at the frozen timestamp.
|
|
3901
|
+
// Similar to sigstore-js's filterCertAuthorities() in trust/filter.ts, but we also
|
|
3902
|
+
// parse the certificates at load time whereas sigstore-js keeps them in the trust material
|
|
3903
|
+
// and parses them during verification. This pre-loading approach is consistent with our
|
|
3904
|
+
// architecture of loading all trusted roots at initialization.
|
|
3905
|
+
loadCA(t, s) {
|
|
3906
|
+
const n = [];
|
|
3907
|
+
for (const r of s) {
|
|
3908
|
+
const i = new Date(r.validFor.start), o = r.validFor.end ? new Date(r.validFor.end) : /* @__PURE__ */ new Date(864e13);
|
|
3909
|
+
if (t > i && t < o) {
|
|
3910
|
+
const a = r.certChain.certificates.map(
|
|
3911
|
+
(c) => J.parse(S(c.rawBytes))
|
|
3912
|
+
);
|
|
3913
|
+
a.length > 0 && n.push({
|
|
3914
|
+
certChain: a,
|
|
3915
|
+
validFor: { start: i, end: o }
|
|
3916
|
+
});
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
return n;
|
|
3920
|
+
}
|
|
3921
|
+
async loadSigstoreRoot(t) {
|
|
3922
|
+
const s = /* @__PURE__ */ new Date();
|
|
3923
|
+
this.rawRoot = t, this.root = {
|
|
3924
|
+
rekor: await this.loadLog(s, t[ie.tlogs]),
|
|
3925
|
+
ctlogs: await this.loadCTLogs(s, t[ie.ctlogs]),
|
|
3926
|
+
certificateAuthorities: this.loadCA(
|
|
3927
|
+
s,
|
|
3928
|
+
t[ie.certificateAuthorities]
|
|
3929
|
+
),
|
|
3930
|
+
timestampAuthorities: this.loadTSA(s, t.timestampAuthorities)
|
|
3931
|
+
};
|
|
3932
|
+
}
|
|
3933
|
+
/**
|
|
3934
|
+
* Load Sigstore trusted root via TUF
|
|
3935
|
+
* Uses The Update Framework for secure, verified updates of trusted root metadata
|
|
3936
|
+
*
|
|
3937
|
+
* @param tufProvider Optional TrustedRootProvider instance. If not provided, uses default Sigstore TUF repository
|
|
3938
|
+
*/
|
|
3939
|
+
async loadSigstoreRootWithTUF(t) {
|
|
3940
|
+
const n = await (t || new so()).getTrustedRoot();
|
|
3941
|
+
await this.loadSigstoreRoot(n);
|
|
3942
|
+
}
|
|
3943
|
+
// Adapted from https://github.com/sigstore/sigstore-js/blob/main/packages/verify/src/key/sct.ts
|
|
3944
|
+
// Key differences:
|
|
3945
|
+
// - Adds duplicate SCT detection (not in reference)
|
|
3946
|
+
// - Inline CT log filtering by logID and validity period (reference uses filterTLogAuthorities)
|
|
3947
|
+
// - Returns array of verified SCT logIDs for threshold checking (matches reference behavior)
|
|
3948
|
+
async verifySCT(t, s, n) {
|
|
3949
|
+
let r;
|
|
3950
|
+
const i = t.clone();
|
|
3951
|
+
for (let u = 0; u < i.extensions.length; u++) {
|
|
3952
|
+
const f = i.extensions[u];
|
|
3953
|
+
if (f.subs[0].toOID() === Mn) {
|
|
3954
|
+
r = new qn(f), i.extensions.splice(u, 1);
|
|
3955
|
+
break;
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3958
|
+
if (!r)
|
|
3959
|
+
throw new Error("Certificate is missing required SCT extension");
|
|
3960
|
+
if (r.signedCertificateTimestamps.length === 0)
|
|
3961
|
+
throw new Error("SCT extension is present but contains no SCTs");
|
|
3962
|
+
const o = /* @__PURE__ */ new Set();
|
|
3963
|
+
for (const u of r.signedCertificateTimestamps) {
|
|
3964
|
+
const f = ht(u.logID);
|
|
3965
|
+
if (o.has(f))
|
|
3966
|
+
throw new Error(`Duplicate SCT found for log ID: ${f}`);
|
|
3967
|
+
o.add(f);
|
|
3968
|
+
}
|
|
3969
|
+
const a = new rt(), c = new Uint8Array(
|
|
3970
|
+
await crypto.subtle.digest(U.SHA256, s.publicKey)
|
|
3971
|
+
);
|
|
3972
|
+
a.appendView(c);
|
|
3973
|
+
const l = i.tbsCertificate.toDER();
|
|
3974
|
+
a.appendUint24(l.length), a.appendView(l);
|
|
3975
|
+
const h = [];
|
|
3976
|
+
for (const u of r.signedCertificateTimestamps) {
|
|
3977
|
+
const f = n.filter((p) => H(p.logID, u.logID) ? p.validFor.start <= u.datetime && u.datetime <= p.validFor.end : !1);
|
|
3978
|
+
if (!await (async () => {
|
|
3979
|
+
for (const p of f)
|
|
3980
|
+
try {
|
|
3981
|
+
if (await u.verify(a.buffer, p.publicKey))
|
|
3982
|
+
return !0;
|
|
3983
|
+
} catch {
|
|
3984
|
+
}
|
|
3985
|
+
return !1;
|
|
3986
|
+
})())
|
|
3987
|
+
throw new Error("SCT verification failed");
|
|
3988
|
+
h.push(u.logID);
|
|
3989
|
+
}
|
|
3990
|
+
return h;
|
|
3991
|
+
}
|
|
3992
|
+
async verifyInclusionPromise(t, s, n) {
|
|
3993
|
+
const r = s.verificationMaterial.tlogEntries;
|
|
3994
|
+
if (r.length < this.options.tlogThreshold)
|
|
3995
|
+
throw new Error(
|
|
3996
|
+
`Not enough tlog entries: ${r.length} < ${this.options.tlogThreshold}`
|
|
3997
|
+
);
|
|
3998
|
+
const i = 32;
|
|
3999
|
+
if (r.length > i)
|
|
4000
|
+
throw new Error(
|
|
4001
|
+
`Too many tlog entries: ${r.length} > ${i}`
|
|
4002
|
+
);
|
|
4003
|
+
for (let h = 0; h < r.length; h++)
|
|
4004
|
+
for (let u = h + 1; u < r.length; u++) {
|
|
4005
|
+
const f = ht(S(r[h].logId.keyId)), d = ht(S(r[u].logId.keyId));
|
|
4006
|
+
if (f === d && r[h].logIndex === r[u].logIndex)
|
|
4007
|
+
throw new Error(
|
|
4008
|
+
`Duplicate tlog entry found: logID=${f}, logIndex=${r[h].logIndex}`
|
|
4009
|
+
);
|
|
4010
|
+
}
|
|
4011
|
+
const o = r[0], a = ro(s.mediaType);
|
|
4012
|
+
if (parseFloat(a) >= 0.2 && !o.inclusionProof)
|
|
4013
|
+
throw new Error(
|
|
4014
|
+
"Bundle v0.2+ requires an inclusion proof."
|
|
4015
|
+
);
|
|
4016
|
+
if (o.inclusionPromise?.signedEntryTimestamp) {
|
|
4017
|
+
if (!(!n && o.inclusionProof)) {
|
|
4018
|
+
if (!n)
|
|
4019
|
+
throw new Error("Rekor public key not found in trusted root");
|
|
4020
|
+
const h = S(o.logId.keyId);
|
|
4021
|
+
if (!H(n.logId, h))
|
|
4022
|
+
throw new Error(
|
|
4023
|
+
`Rekor log ID mismatch: bundle uses ${ht(h)} but loaded key is for ${ht(n.logId)}`
|
|
4024
|
+
);
|
|
4025
|
+
const u = S(
|
|
4026
|
+
o.inclusionPromise.signedEntryTimestamp
|
|
4027
|
+
), f = ht(h), d = Number(o.integratedTime), p = un(
|
|
4028
|
+
Oe({
|
|
4029
|
+
body: o.canonicalizedBody,
|
|
4030
|
+
integratedTime: d,
|
|
4031
|
+
logIndex: Number(o.logIndex),
|
|
4032
|
+
logID: f
|
|
4033
|
+
})
|
|
4034
|
+
);
|
|
4035
|
+
if (!await Rt(n.publicKey, p, u))
|
|
4036
|
+
throw new Error(
|
|
4037
|
+
"Failed to verify the inclusion promise in the provided bundle."
|
|
4038
|
+
);
|
|
4039
|
+
}
|
|
4040
|
+
} else if (!o.inclusionProof)
|
|
4041
|
+
throw new Error(
|
|
4042
|
+
"Bundle must have either an inclusion promise or an inclusion proof."
|
|
4043
|
+
);
|
|
4044
|
+
if (o.integratedTime) {
|
|
4045
|
+
const h = Number(o.integratedTime), u = new Date(h * 1e3);
|
|
4046
|
+
if (!t.validForDate(u))
|
|
4047
|
+
throw new Error(
|
|
4048
|
+
"Artifact signing was logged outside of the certificate validity."
|
|
4049
|
+
);
|
|
4050
|
+
} else if (!s.verificationMaterial.timestampVerificationData)
|
|
4051
|
+
throw new Error(
|
|
4052
|
+
"Rekor v2 bundles require a timestamp for verification."
|
|
4053
|
+
);
|
|
4054
|
+
const l = JSON.parse(Q(S(o.canonicalizedBody)));
|
|
4055
|
+
if (l.kind === "hashedrekord") {
|
|
4056
|
+
let h;
|
|
4057
|
+
if (l.spec.hashedRekordV002) {
|
|
4058
|
+
const u = l.spec.hashedRekordV002.signature.verifier;
|
|
4059
|
+
u?.x509Certificate && (h = u.x509Certificate.rawBytes);
|
|
4060
|
+
} else l.spec.signature?.publicKey && (h = l.spec.signature.publicKey.content);
|
|
4061
|
+
if (h) {
|
|
4062
|
+
let u;
|
|
4063
|
+
if (l.spec.hashedRekordV002)
|
|
4064
|
+
u = J.parse(S(h));
|
|
4065
|
+
else {
|
|
4066
|
+
const f = Q(S(h));
|
|
4067
|
+
u = J.parse(f);
|
|
4068
|
+
}
|
|
4069
|
+
if (!t.equals(u))
|
|
4070
|
+
throw new Error(
|
|
4071
|
+
"Certificate in Rekor log does not match the signing certificate."
|
|
4072
|
+
);
|
|
4073
|
+
}
|
|
4074
|
+
} else if (l.kind === "dsse") {
|
|
4075
|
+
const h = l.spec.signatures?.[0]?.verifier;
|
|
4076
|
+
if (h) {
|
|
4077
|
+
const u = Q(S(h)), f = J.parse(u);
|
|
4078
|
+
if (!t.equals(f))
|
|
4079
|
+
throw new Error(
|
|
4080
|
+
"Certificate in DSSE tlog entry does not match the signing certificate."
|
|
4081
|
+
);
|
|
4082
|
+
}
|
|
4083
|
+
} else if (l.kind === "intoto") {
|
|
4084
|
+
const h = l.spec.content?.envelope?.signatures?.[0]?.publicKey;
|
|
4085
|
+
if (h) {
|
|
4086
|
+
const u = Q(S(h)), f = J.parse(u);
|
|
4087
|
+
if (!t.equals(f))
|
|
4088
|
+
throw new Error(
|
|
4089
|
+
"Certificate in intoto tlog entry does not match the signing certificate."
|
|
4090
|
+
);
|
|
4091
|
+
}
|
|
4092
|
+
} else
|
|
4093
|
+
throw new Error(`Unsupported tlog entry kind: ${l.kind}`);
|
|
4094
|
+
return !0;
|
|
4095
|
+
}
|
|
4096
|
+
async verifyInclusionProof(t) {
|
|
4097
|
+
if (!this.rawRoot)
|
|
4098
|
+
throw new Error("Sigstore root is undefined");
|
|
4099
|
+
if (t.verificationMaterial.tlogEntries.length < 1)
|
|
4100
|
+
throw new Error("No transparency log entries found in bundle");
|
|
4101
|
+
for (const s of t.verificationMaterial.tlogEntries)
|
|
4102
|
+
s.inclusionProof && (await Oi(s), s.inclusionProof.checkpoint && await Hi(s, this.rawRoot.tlogs));
|
|
4103
|
+
}
|
|
4104
|
+
async verifyArtifact(t, s, n, r, i = !1) {
|
|
4105
|
+
if (!this.root)
|
|
4106
|
+
throw new Error("Sigstore root is undefined");
|
|
4107
|
+
const o = n.verificationMaterial.certificate || n.verificationMaterial.x509CertificateChain?.certificates[0];
|
|
4108
|
+
if (!o)
|
|
4109
|
+
throw new Error("No certificate found in bundle");
|
|
4110
|
+
const a = J.parse(S(o.rawBytes));
|
|
4111
|
+
let c;
|
|
4112
|
+
if (n.messageSignature)
|
|
4113
|
+
c = S(n.messageSignature.signature);
|
|
4114
|
+
else if (n.dsseEnvelope) {
|
|
4115
|
+
if (!n.dsseEnvelope.signatures || n.dsseEnvelope.signatures.length === 0)
|
|
4116
|
+
throw new Error("DSSE envelope has no signatures");
|
|
4117
|
+
c = S(n.dsseEnvelope.signatures[0].sig);
|
|
4118
|
+
} else
|
|
4119
|
+
throw new Error("Bundle does not contain a message signature or DSSE envelope");
|
|
4120
|
+
if (a.subjectAltName !== t)
|
|
4121
|
+
throw new Error(
|
|
4122
|
+
"Certificate identity (subjectAltName) do not match the verifying one."
|
|
4123
|
+
);
|
|
4124
|
+
if ((a.extFulcioIssuerV2?.issuer || a.extFulcioIssuerV1?.issuer) !== s)
|
|
4125
|
+
throw new Error("Identity issuer is not the verifying one.");
|
|
4126
|
+
const h = await this.verifyCertificateChain(
|
|
4127
|
+
a.notBefore,
|
|
4128
|
+
a,
|
|
4129
|
+
this.root.certificateAuthorities
|
|
4130
|
+
), u = h.length > 1 ? h[1] : h[0], f = await this.verifySCT(a, u, this.root.ctlogs);
|
|
4131
|
+
if (f.length < this.options.ctlogThreshold)
|
|
4132
|
+
throw new Error(
|
|
4133
|
+
`Not enough valid SCTs: found ${f.length}, required ${this.options.ctlogThreshold}`
|
|
4134
|
+
);
|
|
4135
|
+
if (!await this.verifyInclusionPromise(a, n, this.root.rekor))
|
|
4136
|
+
throw new Error("Inclusion promise validation failed.");
|
|
4137
|
+
await this.verifyInclusionProof(n);
|
|
4138
|
+
for (const p of n.verificationMaterial.tlogEntries)
|
|
4139
|
+
await qi(p, n);
|
|
4140
|
+
const d = await no(
|
|
4141
|
+
n.verificationMaterial.timestampVerificationData,
|
|
4142
|
+
c,
|
|
4143
|
+
this.rawRoot?.timestampAuthorities || []
|
|
4144
|
+
);
|
|
4145
|
+
if (d.length < this.options.tsaThreshold)
|
|
4146
|
+
throw new Error(
|
|
4147
|
+
`Not enough verified TSA timestamps: ${d.length} < ${this.options.tsaThreshold}`
|
|
4148
|
+
);
|
|
4149
|
+
for (const p of d)
|
|
4150
|
+
if (!a.validForDate(p))
|
|
4151
|
+
throw new Error(
|
|
4152
|
+
"Certificate was not valid at the time of timestamping"
|
|
4153
|
+
);
|
|
4154
|
+
if (n.dsseEnvelope) {
|
|
4155
|
+
const p = S(n.dsseEnvelope.payload), m = JSON.parse(Q(p));
|
|
4156
|
+
if (!m.subject || m.subject.length === 0)
|
|
4157
|
+
throw new Error("DSSE payload has no subject");
|
|
4158
|
+
let R;
|
|
4159
|
+
i ? R = ht(r) : R = ht(
|
|
4160
|
+
new Uint8Array(await crypto.subtle.digest(U.SHA256, r))
|
|
4161
|
+
);
|
|
4162
|
+
let _ = null;
|
|
4163
|
+
for (const K of m.subject) {
|
|
4164
|
+
const ot = K.digest?.sha256;
|
|
4165
|
+
if (ot && R === ot.toLowerCase()) {
|
|
4166
|
+
_ = K;
|
|
4167
|
+
break;
|
|
4168
|
+
}
|
|
4169
|
+
}
|
|
4170
|
+
if (!_)
|
|
4171
|
+
throw new Error(
|
|
4172
|
+
`Artifact digest ${R} does not match any subject in DSSE payload`
|
|
4173
|
+
);
|
|
4174
|
+
const et = Ai(n.dsseEnvelope.payloadType, p), A = await a.publicKeyObj;
|
|
4175
|
+
if (!await Rt(A, et, c))
|
|
4176
|
+
throw new Error("DSSE signature verification failed");
|
|
4177
|
+
} else {
|
|
4178
|
+
const p = await a.publicKeyObj;
|
|
4179
|
+
if (i) {
|
|
4180
|
+
if (!await Fr(p, r, c))
|
|
4181
|
+
throw new Error("Error verifying signature over digest");
|
|
4182
|
+
} else if (!await Rt(p, r, c)) {
|
|
4183
|
+
const R = p.algorithm.name || "unknown";
|
|
4184
|
+
throw new Error(`Error verifying artifact signature. Key algorithm: ${R}, Data length: ${r.length}, Signature length: ${c.length}`);
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
return !0;
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
class Dt extends Error {
|
|
4191
|
+
constructor(t, s) {
|
|
4192
|
+
super(s), this.code = t, this.name = "VerificationError", Object.setPrototypeOf(this, Dt.prototype);
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
class bs extends Dt {
|
|
4196
|
+
constructor(t) {
|
|
4197
|
+
super("TIMESTAMP_ERROR", t), this.name = "TimestampError", Object.setPrototypeOf(this, bs.prototype);
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
class ps extends Dt {
|
|
4201
|
+
constructor(t) {
|
|
4202
|
+
super("CERTIFICATE_ERROR", t), this.name = "CertificateError", Object.setPrototypeOf(this, ps.prototype);
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
class ys extends Dt {
|
|
4206
|
+
constructor(t) {
|
|
4207
|
+
super("TLOG_ERROR", t), this.name = "TLogError", Object.setPrototypeOf(this, ys.prototype);
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
class ms extends Dt {
|
|
4211
|
+
constructor(t) {
|
|
4212
|
+
super("SIGNATURE_ERROR", t), this.name = "SignatureError", Object.setPrototypeOf(this, ms.prototype);
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
class St extends Dt {
|
|
4216
|
+
constructor(t) {
|
|
4217
|
+
super("POLICY_ERROR", t), this.name = "PolicyError", Object.setPrototypeOf(this, St.prototype);
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
const ao = "https://token.actions.githubusercontent.com";
|
|
4221
|
+
class Ut {
|
|
4222
|
+
expectedValue;
|
|
4223
|
+
constructor(t) {
|
|
4224
|
+
this.expectedValue = t;
|
|
4225
|
+
}
|
|
4226
|
+
verify(t) {
|
|
4227
|
+
const s = this.getExtensionValue(t);
|
|
4228
|
+
if (s === void 0)
|
|
4229
|
+
throw new St(
|
|
4230
|
+
`Certificate does not contain ${this.name} (${this.oid}) extension`
|
|
4231
|
+
);
|
|
4232
|
+
if (s !== this.expectedValue)
|
|
4233
|
+
throw new St(
|
|
4234
|
+
`Certificate's ${this.name} does not match (got '${s}', expected '${this.expectedValue}')`
|
|
4235
|
+
);
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
class W extends Ut {
|
|
4239
|
+
}
|
|
4240
|
+
class io extends Ut {
|
|
4241
|
+
oid = Zn;
|
|
4242
|
+
name = "OIDCIssuer";
|
|
4243
|
+
getExtensionValue(t) {
|
|
4244
|
+
return t.extFulcioIssuerV1?.issuer;
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
class co extends Ut {
|
|
4248
|
+
oid = Wn;
|
|
4249
|
+
name = "GitHubWorkflowTrigger";
|
|
4250
|
+
getExtensionValue(t) {
|
|
4251
|
+
return t.extGitHubWorkflowTrigger?.workflowTrigger;
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
class fo extends Ut {
|
|
4255
|
+
oid = Yn;
|
|
4256
|
+
name = "GitHubWorkflowSHA";
|
|
4257
|
+
getExtensionValue(t) {
|
|
4258
|
+
return t.extGitHubWorkflowSHA?.workflowSHA;
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
class uo extends Ut {
|
|
4262
|
+
oid = zn;
|
|
4263
|
+
name = "GitHubWorkflowName";
|
|
4264
|
+
getExtensionValue(t) {
|
|
4265
|
+
return t.extGitHubWorkflowName?.workflowName;
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
class lo extends Ut {
|
|
4269
|
+
oid = Jn;
|
|
4270
|
+
name = "GitHubWorkflowRepository";
|
|
4271
|
+
getExtensionValue(t) {
|
|
4272
|
+
return t.extGitHubWorkflowRepository?.workflowRepository;
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
class ho extends Ut {
|
|
4276
|
+
oid = Qn;
|
|
4277
|
+
name = "GitHubWorkflowRef";
|
|
4278
|
+
getExtensionValue(t) {
|
|
4279
|
+
return t.extGitHubWorkflowRef?.workflowRef;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
class go extends W {
|
|
4283
|
+
oid = ts;
|
|
4284
|
+
name = "OIDCIssuerV2";
|
|
4285
|
+
getExtensionValue(t) {
|
|
4286
|
+
return t.extFulcioIssuerV2?.issuer;
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
class wo extends W {
|
|
4290
|
+
oid = es;
|
|
4291
|
+
name = "OIDCBuildSignerURI";
|
|
4292
|
+
getExtensionValue(t) {
|
|
4293
|
+
return t.extBuildSignerURI?.buildSignerURI;
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
class bo extends W {
|
|
4297
|
+
oid = ns;
|
|
4298
|
+
name = "OIDCBuildSignerDigest";
|
|
4299
|
+
getExtensionValue(t) {
|
|
4300
|
+
return t.extBuildSignerDigest?.buildSignerDigest;
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
4303
|
+
class po extends W {
|
|
4304
|
+
oid = ss;
|
|
4305
|
+
name = "OIDCRunnerEnvironment";
|
|
4306
|
+
getExtensionValue(t) {
|
|
4307
|
+
return t.extRunnerEnvironment?.runnerEnvironment;
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
class yo extends W {
|
|
4311
|
+
oid = rs;
|
|
4312
|
+
name = "OIDCSourceRepositoryURI";
|
|
4313
|
+
getExtensionValue(t) {
|
|
4314
|
+
return t.extSourceRepositoryURI?.sourceRepositoryURI;
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
class mo extends W {
|
|
4318
|
+
oid = is;
|
|
4319
|
+
name = "OIDCSourceRepositoryDigest";
|
|
4320
|
+
getExtensionValue(t) {
|
|
4321
|
+
return t.extSourceRepositoryDigest?.sourceRepositoryDigest;
|
|
4322
|
+
}
|
|
4323
|
+
}
|
|
4324
|
+
class Eo extends W {
|
|
4325
|
+
oid = os;
|
|
4326
|
+
name = "OIDCSourceRepositoryRef";
|
|
4327
|
+
getExtensionValue(t) {
|
|
4328
|
+
return t.extSourceRepositoryRef?.sourceRepositoryRef;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
class xo extends W {
|
|
4332
|
+
oid = as;
|
|
4333
|
+
name = "OIDCSourceRepositoryIdentifier";
|
|
4334
|
+
getExtensionValue(t) {
|
|
4335
|
+
return t.extSourceRepositoryIdentifier?.sourceRepositoryIdentifier;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
class So extends W {
|
|
4339
|
+
oid = cs;
|
|
4340
|
+
name = "OIDCSourceRepositoryOwnerURI";
|
|
4341
|
+
getExtensionValue(t) {
|
|
4342
|
+
return t.extSourceRepositoryOwnerURI?.sourceRepositoryOwnerURI;
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
class Io extends W {
|
|
4346
|
+
oid = fs;
|
|
4347
|
+
name = "OIDCSourceRepositoryOwnerIdentifier";
|
|
4348
|
+
getExtensionValue(t) {
|
|
4349
|
+
return t.extSourceRepositoryOwnerIdentifier?.sourceRepositoryOwnerIdentifier;
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
class vo extends W {
|
|
4353
|
+
oid = us;
|
|
4354
|
+
name = "OIDCBuildConfigURI";
|
|
4355
|
+
getExtensionValue(t) {
|
|
4356
|
+
return t.extBuildConfigURI?.buildConfigURI;
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
class Ao extends W {
|
|
4360
|
+
oid = ls;
|
|
4361
|
+
name = "OIDCBuildConfigDigest";
|
|
4362
|
+
getExtensionValue(t) {
|
|
4363
|
+
return t.extBuildConfigDigest?.buildConfigDigest;
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
class Oo extends W {
|
|
4367
|
+
oid = hs;
|
|
4368
|
+
name = "OIDCBuildTrigger";
|
|
4369
|
+
getExtensionValue(t) {
|
|
4370
|
+
return t.extBuildTrigger?.buildTrigger;
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
class Bo extends W {
|
|
4374
|
+
oid = ds;
|
|
4375
|
+
name = "OIDCRunInvocationURI";
|
|
4376
|
+
getExtensionValue(t) {
|
|
4377
|
+
return t.extRunInvocationURI?.runInvocationURI;
|
|
4378
|
+
}
|
|
4379
|
+
}
|
|
4380
|
+
class Ro extends W {
|
|
4381
|
+
oid = gs;
|
|
4382
|
+
name = "OIDCSourceRepositoryVisibility";
|
|
4383
|
+
getExtensionValue(t) {
|
|
4384
|
+
return t.extSourceRepositoryVisibility?.sourceRepositoryVisibility;
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
class Co {
|
|
4388
|
+
children;
|
|
4389
|
+
constructor(t) {
|
|
4390
|
+
this.children = t;
|
|
4391
|
+
}
|
|
4392
|
+
verify(t) {
|
|
4393
|
+
for (const s of this.children)
|
|
4394
|
+
try {
|
|
4395
|
+
s.verify(t);
|
|
4396
|
+
return;
|
|
4397
|
+
} catch {
|
|
4398
|
+
}
|
|
4399
|
+
throw new St(`0 of ${this.children.length} policies succeeded`);
|
|
4400
|
+
}
|
|
4401
|
+
}
|
|
4402
|
+
class To {
|
|
4403
|
+
children;
|
|
4404
|
+
constructor(t) {
|
|
4405
|
+
this.children = t;
|
|
4406
|
+
}
|
|
4407
|
+
verify(t) {
|
|
4408
|
+
if (this.children.length < 1)
|
|
4409
|
+
throw new St("no child policies to verify");
|
|
4410
|
+
for (const s of this.children)
|
|
4411
|
+
s.verify(t);
|
|
4412
|
+
}
|
|
4413
|
+
}
|
|
4414
|
+
class Do {
|
|
4415
|
+
identity;
|
|
4416
|
+
issuerPolicy;
|
|
4417
|
+
constructor(t) {
|
|
4418
|
+
this.identity = t.identity, this.issuerPolicy = t.issuer ? new io(t.issuer) : null;
|
|
4419
|
+
}
|
|
4420
|
+
verify(t) {
|
|
4421
|
+
this.issuerPolicy && this.issuerPolicy.verify(t);
|
|
4422
|
+
const s = t.extSubjectAltName;
|
|
4423
|
+
if (!s)
|
|
4424
|
+
throw new St("Certificate does not contain SubjectAlternativeName extension");
|
|
4425
|
+
const n = /* @__PURE__ */ new Set();
|
|
4426
|
+
s.rfc822Name && n.add(s.rfc822Name), s.uri && n.add(s.uri);
|
|
4427
|
+
const r = s.otherName(Si);
|
|
4428
|
+
if (r && n.add(r), !n.has(this.identity))
|
|
4429
|
+
throw new St(
|
|
4430
|
+
`Certificate's SANs do not match ${this.identity}; actual SANs: ${Array.from(n).join(", ")}`
|
|
4431
|
+
);
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
export {
|
|
4435
|
+
ri as $,
|
|
4436
|
+
os as A,
|
|
4437
|
+
as as B,
|
|
4438
|
+
ps as C,
|
|
4439
|
+
cs as D,
|
|
4440
|
+
Mn as E,
|
|
4441
|
+
fs as F,
|
|
4442
|
+
us as G,
|
|
4443
|
+
U as H,
|
|
4444
|
+
ls as I,
|
|
4445
|
+
hs as J,
|
|
4446
|
+
ds as K,
|
|
4447
|
+
gs as L,
|
|
4448
|
+
wt as M,
|
|
4449
|
+
Yr as N,
|
|
4450
|
+
ni as O,
|
|
4451
|
+
St as P,
|
|
4452
|
+
zr as Q,
|
|
4453
|
+
Jr as R,
|
|
4454
|
+
oo as S,
|
|
4455
|
+
bs as T,
|
|
4456
|
+
ht as U,
|
|
4457
|
+
Dt as V,
|
|
4458
|
+
Qr as W,
|
|
4459
|
+
J as X,
|
|
4460
|
+
ti as Y,
|
|
4461
|
+
ei as Z,
|
|
4462
|
+
si as _,
|
|
4463
|
+
Me as a,
|
|
4464
|
+
ii as a0,
|
|
4465
|
+
oi as a1,
|
|
4466
|
+
ai as a2,
|
|
4467
|
+
ci as a3,
|
|
4468
|
+
fi as a4,
|
|
4469
|
+
ui as a5,
|
|
4470
|
+
li as a6,
|
|
4471
|
+
hi as a7,
|
|
4472
|
+
di as a8,
|
|
4473
|
+
gi as a9,
|
|
4474
|
+
Co as aA,
|
|
4475
|
+
Do as aB,
|
|
4476
|
+
wi as aa,
|
|
4477
|
+
bi as ab,
|
|
4478
|
+
ws as ac,
|
|
4479
|
+
ao as ad,
|
|
4480
|
+
io as ae,
|
|
4481
|
+
go as af,
|
|
4482
|
+
co as ag,
|
|
4483
|
+
fo as ah,
|
|
4484
|
+
uo as ai,
|
|
4485
|
+
lo as aj,
|
|
4486
|
+
ho as ak,
|
|
4487
|
+
wo as al,
|
|
4488
|
+
bo as am,
|
|
4489
|
+
po as an,
|
|
4490
|
+
yo as ao,
|
|
4491
|
+
mo as ap,
|
|
4492
|
+
Eo as aq,
|
|
4493
|
+
xo as ar,
|
|
4494
|
+
So as as,
|
|
4495
|
+
Io as at,
|
|
4496
|
+
vo as au,
|
|
4497
|
+
Ao as av,
|
|
4498
|
+
Oo as aw,
|
|
4499
|
+
Bo as ax,
|
|
4500
|
+
Ro as ay,
|
|
4501
|
+
To as az,
|
|
4502
|
+
S as b,
|
|
4503
|
+
Oe as c,
|
|
4504
|
+
Q as d,
|
|
4505
|
+
ys as e,
|
|
4506
|
+
ms as f,
|
|
4507
|
+
Ji as g,
|
|
4508
|
+
Kt as h,
|
|
4509
|
+
Zt as i,
|
|
4510
|
+
no as j,
|
|
4511
|
+
so as k,
|
|
4512
|
+
Zn as l,
|
|
4513
|
+
Wn as m,
|
|
4514
|
+
Yn as n,
|
|
4515
|
+
zn as o,
|
|
4516
|
+
Jn as p,
|
|
4517
|
+
Qn as q,
|
|
4518
|
+
Si as r,
|
|
4519
|
+
un as s,
|
|
4520
|
+
ts as t,
|
|
4521
|
+
es as u,
|
|
4522
|
+
Rt as v,
|
|
4523
|
+
ns as w,
|
|
4524
|
+
ss as x,
|
|
4525
|
+
rs as y,
|
|
4526
|
+
is as z
|
|
4527
|
+
};
|
|
4528
|
+
//# sourceMappingURL=index-CRFtwdjM.js.map
|