@vitia.ai/secure-api-client-vue 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.mjs +3084 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3084 @@
|
|
|
1
|
+
const Z = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
2
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
function at(n) {
|
|
4
|
+
return n instanceof Uint8Array || ArrayBuffer.isView(n) && n.constructor.name === "Uint8Array";
|
|
5
|
+
}
|
|
6
|
+
function Wr(n) {
|
|
7
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
8
|
+
throw new Error("positive integer expected, got " + n);
|
|
9
|
+
}
|
|
10
|
+
function Ve(n, ...e) {
|
|
11
|
+
if (!at(n))
|
|
12
|
+
throw new Error("Uint8Array expected");
|
|
13
|
+
if (e.length > 0 && !e.includes(n.length))
|
|
14
|
+
throw new Error("Uint8Array expected of length " + e + ", got length=" + n.length);
|
|
15
|
+
}
|
|
16
|
+
const lt = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", Zr = /* @__PURE__ */ Array.from({ length: 256 }, (n, e) => e.toString(16).padStart(2, "0"));
|
|
17
|
+
function ut(n) {
|
|
18
|
+
if (Ve(n), lt)
|
|
19
|
+
return n.toHex();
|
|
20
|
+
let e = "";
|
|
21
|
+
for (let t = 0; t < n.length; t++)
|
|
22
|
+
e += Zr[n[t]];
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
const _ = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
26
|
+
function ze(n) {
|
|
27
|
+
if (n >= _._0 && n <= _._9)
|
|
28
|
+
return n - _._0;
|
|
29
|
+
if (n >= _.A && n <= _.F)
|
|
30
|
+
return n - (_.A - 10);
|
|
31
|
+
if (n >= _.a && n <= _.f)
|
|
32
|
+
return n - (_.a - 10);
|
|
33
|
+
}
|
|
34
|
+
function ht(n) {
|
|
35
|
+
if (typeof n != "string")
|
|
36
|
+
throw new Error("hex string expected, got " + typeof n);
|
|
37
|
+
if (lt)
|
|
38
|
+
return Uint8Array.fromHex(n);
|
|
39
|
+
const e = n.length, t = e / 2;
|
|
40
|
+
if (e % 2)
|
|
41
|
+
throw new Error("hex string expected, got unpadded hex of length " + e);
|
|
42
|
+
const r = new Uint8Array(t);
|
|
43
|
+
for (let s = 0, i = 0; s < t; s++, i += 2) {
|
|
44
|
+
const o = ze(n.charCodeAt(i)), c = ze(n.charCodeAt(i + 1));
|
|
45
|
+
if (o === void 0 || c === void 0) {
|
|
46
|
+
const a = n[i] + n[i + 1];
|
|
47
|
+
throw new Error('hex string expected, got non-hex character "' + a + '" at index ' + i);
|
|
48
|
+
}
|
|
49
|
+
r[s] = o * 16 + c;
|
|
50
|
+
}
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
function zr(n = 32) {
|
|
54
|
+
if (Z && typeof Z.getRandomValues == "function")
|
|
55
|
+
return Z.getRandomValues(new Uint8Array(n));
|
|
56
|
+
if (Z && typeof Z.randomBytes == "function")
|
|
57
|
+
return Uint8Array.from(Z.randomBytes(n));
|
|
58
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
59
|
+
}
|
|
60
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
61
|
+
const ft = /* @__PURE__ */ BigInt(0), Xe = /* @__PURE__ */ BigInt(1);
|
|
62
|
+
function dt(n) {
|
|
63
|
+
if (typeof n != "string")
|
|
64
|
+
throw new Error("hex string expected, got " + typeof n);
|
|
65
|
+
return n === "" ? ft : BigInt("0x" + n);
|
|
66
|
+
}
|
|
67
|
+
function Xr(n) {
|
|
68
|
+
return dt(ut(n));
|
|
69
|
+
}
|
|
70
|
+
function pe(n) {
|
|
71
|
+
return Ve(n), dt(ut(Uint8Array.from(n).reverse()));
|
|
72
|
+
}
|
|
73
|
+
function gt(n, e) {
|
|
74
|
+
return ht(n.toString(16).padStart(e * 2, "0"));
|
|
75
|
+
}
|
|
76
|
+
function wt(n, e) {
|
|
77
|
+
return gt(n, e).reverse();
|
|
78
|
+
}
|
|
79
|
+
function Ye(n, e, t) {
|
|
80
|
+
let r;
|
|
81
|
+
if (typeof e == "string")
|
|
82
|
+
try {
|
|
83
|
+
r = ht(e);
|
|
84
|
+
} catch (i) {
|
|
85
|
+
throw new Error(n + " must be hex string or Uint8Array, cause: " + i);
|
|
86
|
+
}
|
|
87
|
+
else if (at(e))
|
|
88
|
+
r = Uint8Array.from(e);
|
|
89
|
+
else
|
|
90
|
+
throw new Error(n + " must be hex string or Uint8Array");
|
|
91
|
+
const s = r.length;
|
|
92
|
+
if (typeof t == "number" && s !== t)
|
|
93
|
+
throw new Error(n + " of length " + t + " expected, got " + s);
|
|
94
|
+
return r;
|
|
95
|
+
}
|
|
96
|
+
const xe = (n) => typeof n == "bigint" && ft <= n;
|
|
97
|
+
function Yr(n, e, t) {
|
|
98
|
+
return xe(n) && xe(e) && xe(t) && e <= n && n < t;
|
|
99
|
+
}
|
|
100
|
+
function Qe(n, e, t, r) {
|
|
101
|
+
if (!Yr(e, t, r))
|
|
102
|
+
throw new Error("expected valid " + n + ": " + t + " <= n < " + r + ", got " + e);
|
|
103
|
+
}
|
|
104
|
+
const Qr = (n) => (Xe << BigInt(n)) - Xe;
|
|
105
|
+
function es(n, e, t = {}) {
|
|
106
|
+
if (!n || typeof n != "object")
|
|
107
|
+
throw new Error("expected valid options object");
|
|
108
|
+
function r(s, i, o) {
|
|
109
|
+
const c = n[s];
|
|
110
|
+
if (o && c === void 0)
|
|
111
|
+
return;
|
|
112
|
+
const a = typeof c;
|
|
113
|
+
if (a !== i || c === null)
|
|
114
|
+
throw new Error(`param "${s}" is invalid: expected ${i}, got ${a}`);
|
|
115
|
+
}
|
|
116
|
+
Object.entries(e).forEach(([s, i]) => r(s, i, !1)), Object.entries(t).forEach(([s, i]) => r(s, i, !0));
|
|
117
|
+
}
|
|
118
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
119
|
+
const x = BigInt(0), p = BigInt(1), F = /* @__PURE__ */ BigInt(2), Bt = /* @__PURE__ */ BigInt(3), yt = /* @__PURE__ */ BigInt(4), bt = /* @__PURE__ */ BigInt(5), ts = /* @__PURE__ */ BigInt(7), vt = /* @__PURE__ */ BigInt(8), rs = /* @__PURE__ */ BigInt(9), kt = /* @__PURE__ */ BigInt(16);
|
|
120
|
+
function I(n, e) {
|
|
121
|
+
const t = n % e;
|
|
122
|
+
return t >= x ? t : e + t;
|
|
123
|
+
}
|
|
124
|
+
function U(n, e, t) {
|
|
125
|
+
let r = n;
|
|
126
|
+
for (; e-- > x; )
|
|
127
|
+
r *= r, r %= t;
|
|
128
|
+
return r;
|
|
129
|
+
}
|
|
130
|
+
function et(n, e) {
|
|
131
|
+
if (n === x)
|
|
132
|
+
throw new Error("invert: expected non-zero number");
|
|
133
|
+
if (e <= x)
|
|
134
|
+
throw new Error("invert: expected positive modulus, got " + e);
|
|
135
|
+
let t = I(n, e), r = e, s = x, i = p;
|
|
136
|
+
for (; t !== x; ) {
|
|
137
|
+
const c = r / t, a = r % t, u = s - i * c;
|
|
138
|
+
r = t, t = a, s = i, i = u;
|
|
139
|
+
}
|
|
140
|
+
if (r !== p)
|
|
141
|
+
throw new Error("invert: does not exist");
|
|
142
|
+
return I(s, e);
|
|
143
|
+
}
|
|
144
|
+
function Te(n, e, t) {
|
|
145
|
+
if (!n.eql(n.sqr(e), t))
|
|
146
|
+
throw new Error("Cannot find square root");
|
|
147
|
+
}
|
|
148
|
+
function mt(n, e) {
|
|
149
|
+
const t = (n.ORDER + p) / yt, r = n.pow(e, t);
|
|
150
|
+
return Te(n, r, e), r;
|
|
151
|
+
}
|
|
152
|
+
function ss(n, e) {
|
|
153
|
+
const t = (n.ORDER - bt) / vt, r = n.mul(e, F), s = n.pow(r, t), i = n.mul(e, s), o = n.mul(n.mul(i, F), s), c = n.mul(i, n.sub(o, n.ONE));
|
|
154
|
+
return Te(n, c, e), c;
|
|
155
|
+
}
|
|
156
|
+
function ns(n) {
|
|
157
|
+
const e = Ce(n), t = At(n), r = t(e, e.neg(e.ONE)), s = t(e, r), i = t(e, e.neg(r)), o = (n + ts) / kt;
|
|
158
|
+
return (c, a) => {
|
|
159
|
+
let u = c.pow(a, o), f = c.mul(u, r);
|
|
160
|
+
const h = c.mul(u, s), l = c.mul(u, i), g = c.eql(c.sqr(f), a), B = c.eql(c.sqr(h), a);
|
|
161
|
+
u = c.cmov(u, f, g), f = c.cmov(l, h, B);
|
|
162
|
+
const m = c.eql(c.sqr(f), a), b = c.cmov(u, f, m);
|
|
163
|
+
return Te(c, b, a), b;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function At(n) {
|
|
167
|
+
if (n < Bt)
|
|
168
|
+
throw new Error("sqrt is not defined for small field");
|
|
169
|
+
let e = n - p, t = 0;
|
|
170
|
+
for (; e % F === x; )
|
|
171
|
+
e /= F, t++;
|
|
172
|
+
let r = F;
|
|
173
|
+
const s = Ce(n);
|
|
174
|
+
for (; tt(s, r) === 1; )
|
|
175
|
+
if (r++ > 1e3)
|
|
176
|
+
throw new Error("Cannot find square root: probably non-prime P");
|
|
177
|
+
if (t === 1)
|
|
178
|
+
return mt;
|
|
179
|
+
let i = s.pow(r, e);
|
|
180
|
+
const o = (e + p) / F;
|
|
181
|
+
return function(a, u) {
|
|
182
|
+
if (a.is0(u))
|
|
183
|
+
return u;
|
|
184
|
+
if (tt(a, u) !== 1)
|
|
185
|
+
throw new Error("Cannot find square root");
|
|
186
|
+
let f = t, h = a.mul(a.ONE, i), l = a.pow(u, e), g = a.pow(u, o);
|
|
187
|
+
for (; !a.eql(l, a.ONE); ) {
|
|
188
|
+
if (a.is0(l))
|
|
189
|
+
return a.ZERO;
|
|
190
|
+
let B = 1, m = a.sqr(l);
|
|
191
|
+
for (; !a.eql(m, a.ONE); )
|
|
192
|
+
if (B++, m = a.sqr(m), B === f)
|
|
193
|
+
throw new Error("Cannot find square root");
|
|
194
|
+
const b = p << BigInt(f - B - 1), D = a.pow(h, b);
|
|
195
|
+
f = B, h = a.sqr(D), l = a.mul(l, h), g = a.mul(g, D);
|
|
196
|
+
}
|
|
197
|
+
return g;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function is(n) {
|
|
201
|
+
return n % yt === Bt ? mt : n % vt === bt ? ss : n % kt === rs ? ns(n) : At(n);
|
|
202
|
+
}
|
|
203
|
+
function os(n, e, t) {
|
|
204
|
+
if (t < x)
|
|
205
|
+
throw new Error("invalid exponent, negatives unsupported");
|
|
206
|
+
if (t === x)
|
|
207
|
+
return n.ONE;
|
|
208
|
+
if (t === p)
|
|
209
|
+
return e;
|
|
210
|
+
let r = n.ONE, s = e;
|
|
211
|
+
for (; t > x; )
|
|
212
|
+
t & p && (r = n.mul(r, s)), s = n.sqr(s), t >>= p;
|
|
213
|
+
return r;
|
|
214
|
+
}
|
|
215
|
+
function cs(n, e, t = !1) {
|
|
216
|
+
const r = new Array(e.length).fill(t ? n.ZERO : void 0), s = e.reduce((o, c, a) => n.is0(c) ? o : (r[a] = o, n.mul(o, c)), n.ONE), i = n.inv(s);
|
|
217
|
+
return e.reduceRight((o, c, a) => n.is0(c) ? o : (r[a] = n.mul(o, r[a]), n.mul(o, c)), i), r;
|
|
218
|
+
}
|
|
219
|
+
function tt(n, e) {
|
|
220
|
+
const t = (n.ORDER - p) / F, r = n.pow(e, t), s = n.eql(r, n.ONE), i = n.eql(r, n.ZERO), o = n.eql(r, n.neg(n.ONE));
|
|
221
|
+
if (!s && !i && !o)
|
|
222
|
+
throw new Error("invalid Legendre symbol result");
|
|
223
|
+
return s ? 1 : i ? 0 : -1;
|
|
224
|
+
}
|
|
225
|
+
function as(n, e) {
|
|
226
|
+
e !== void 0 && Wr(e);
|
|
227
|
+
const t = e !== void 0 ? e : n.toString(2).length, r = Math.ceil(t / 8);
|
|
228
|
+
return { nBitLength: t, nByteLength: r };
|
|
229
|
+
}
|
|
230
|
+
function Ce(n, e, t = !1, r = {}) {
|
|
231
|
+
if (n <= x)
|
|
232
|
+
throw new Error("invalid field: expected ORDER > 0, got " + n);
|
|
233
|
+
let s, i, o = !1, c;
|
|
234
|
+
if (typeof e == "object" && e != null) {
|
|
235
|
+
if (r.sqrt || t)
|
|
236
|
+
throw new Error("cannot specify opts in two arguments");
|
|
237
|
+
const l = e;
|
|
238
|
+
l.BITS && (s = l.BITS), l.sqrt && (i = l.sqrt), typeof l.isLE == "boolean" && (t = l.isLE), typeof l.modFromBytes == "boolean" && (o = l.modFromBytes), c = l.allowedLengths;
|
|
239
|
+
} else
|
|
240
|
+
typeof e == "number" && (s = e), r.sqrt && (i = r.sqrt);
|
|
241
|
+
const { nBitLength: a, nByteLength: u } = as(n, s);
|
|
242
|
+
if (u > 2048)
|
|
243
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
244
|
+
let f;
|
|
245
|
+
const h = Object.freeze({
|
|
246
|
+
ORDER: n,
|
|
247
|
+
isLE: t,
|
|
248
|
+
BITS: a,
|
|
249
|
+
BYTES: u,
|
|
250
|
+
MASK: Qr(a),
|
|
251
|
+
ZERO: x,
|
|
252
|
+
ONE: p,
|
|
253
|
+
allowedLengths: c,
|
|
254
|
+
create: (l) => I(l, n),
|
|
255
|
+
isValid: (l) => {
|
|
256
|
+
if (typeof l != "bigint")
|
|
257
|
+
throw new Error("invalid field element: expected bigint, got " + typeof l);
|
|
258
|
+
return x <= l && l < n;
|
|
259
|
+
},
|
|
260
|
+
is0: (l) => l === x,
|
|
261
|
+
// is valid and invertible
|
|
262
|
+
isValidNot0: (l) => !h.is0(l) && h.isValid(l),
|
|
263
|
+
isOdd: (l) => (l & p) === p,
|
|
264
|
+
neg: (l) => I(-l, n),
|
|
265
|
+
eql: (l, g) => l === g,
|
|
266
|
+
sqr: (l) => I(l * l, n),
|
|
267
|
+
add: (l, g) => I(l + g, n),
|
|
268
|
+
sub: (l, g) => I(l - g, n),
|
|
269
|
+
mul: (l, g) => I(l * g, n),
|
|
270
|
+
pow: (l, g) => os(h, l, g),
|
|
271
|
+
div: (l, g) => I(l * et(g, n), n),
|
|
272
|
+
// Same as above, but doesn't normalize
|
|
273
|
+
sqrN: (l) => l * l,
|
|
274
|
+
addN: (l, g) => l + g,
|
|
275
|
+
subN: (l, g) => l - g,
|
|
276
|
+
mulN: (l, g) => l * g,
|
|
277
|
+
inv: (l) => et(l, n),
|
|
278
|
+
sqrt: i || ((l) => (f || (f = is(n)), f(h, l))),
|
|
279
|
+
toBytes: (l) => t ? wt(l, u) : gt(l, u),
|
|
280
|
+
fromBytes: (l, g = !0) => {
|
|
281
|
+
if (c) {
|
|
282
|
+
if (!c.includes(l.length) || l.length > u)
|
|
283
|
+
throw new Error("Field.fromBytes: expected " + c + " bytes, got " + l.length);
|
|
284
|
+
const m = new Uint8Array(u);
|
|
285
|
+
m.set(l, t ? 0 : m.length - l.length), l = m;
|
|
286
|
+
}
|
|
287
|
+
if (l.length !== u)
|
|
288
|
+
throw new Error("Field.fromBytes: expected " + u + " bytes, got " + l.length);
|
|
289
|
+
let B = t ? pe(l) : Xr(l);
|
|
290
|
+
if (o && (B = I(B, n)), !g && !h.isValid(B))
|
|
291
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
292
|
+
return B;
|
|
293
|
+
},
|
|
294
|
+
// TODO: we don't need it here, move out to separate fn
|
|
295
|
+
invertBatch: (l) => cs(h, l),
|
|
296
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
297
|
+
// and it's unclear what to return in there.
|
|
298
|
+
cmov: (l, g, B) => B ? g : l
|
|
299
|
+
});
|
|
300
|
+
return Object.freeze(h);
|
|
301
|
+
}
|
|
302
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
303
|
+
const re = BigInt(0), z = BigInt(1), fe = BigInt(2);
|
|
304
|
+
function ls(n) {
|
|
305
|
+
return es(n, {
|
|
306
|
+
adjustScalarBytes: "function",
|
|
307
|
+
powPminus2: "function"
|
|
308
|
+
}), Object.freeze({ ...n });
|
|
309
|
+
}
|
|
310
|
+
function us(n) {
|
|
311
|
+
const e = ls(n), { P: t, type: r, adjustScalarBytes: s, powPminus2: i, randomBytes: o } = e, c = r === "x25519";
|
|
312
|
+
if (!c && r !== "x448")
|
|
313
|
+
throw new Error("invalid type");
|
|
314
|
+
const a = o || zr, u = c ? 255 : 448, f = c ? 32 : 56, h = BigInt(c ? 9 : 5), l = BigInt(c ? 121665 : 39081), g = c ? fe ** BigInt(254) : fe ** BigInt(447), B = c ? BigInt(8) * fe ** BigInt(251) - z : BigInt(4) * fe ** BigInt(445) - z, m = g + B + z, b = (y) => I(y, t), D = le(h);
|
|
315
|
+
function le(y) {
|
|
316
|
+
return wt(b(y), f);
|
|
317
|
+
}
|
|
318
|
+
function Be(y) {
|
|
319
|
+
const k = Ye("u coordinate", y, f);
|
|
320
|
+
return c && (k[31] &= 127), b(pe(k));
|
|
321
|
+
}
|
|
322
|
+
function ye(y) {
|
|
323
|
+
return pe(s(Ye("scalar", y, f)));
|
|
324
|
+
}
|
|
325
|
+
function ee(y, k) {
|
|
326
|
+
const C = be(Be(k), ye(y));
|
|
327
|
+
if (C === re)
|
|
328
|
+
throw new Error("invalid private or public key received");
|
|
329
|
+
return le(C);
|
|
330
|
+
}
|
|
331
|
+
function J(y) {
|
|
332
|
+
return ee(y, D);
|
|
333
|
+
}
|
|
334
|
+
function K(y, k, C) {
|
|
335
|
+
const he = b(y * (k - C));
|
|
336
|
+
return k = b(k - he), C = b(C + he), { x_2: k, x_3: C };
|
|
337
|
+
}
|
|
338
|
+
function be(y, k) {
|
|
339
|
+
Qe("u", y, re, t), Qe("scalar", k, g, m);
|
|
340
|
+
const C = k, he = y;
|
|
341
|
+
let R = z, M = re, $ = y, P = z, W = re;
|
|
342
|
+
for (let ve = BigInt(u - 1); ve >= re; ve--) {
|
|
343
|
+
const je = C >> ve & z;
|
|
344
|
+
W ^= je, { x_2: R, x_3: $ } = K(W, R, $), { x_2: M, x_3: P } = K(W, M, P), W = je;
|
|
345
|
+
const ke = R + M, me = b(ke * ke), Ae = R - M, qe = b(Ae * Ae), Ge = me - qe, Jr = $ + P, Kr = $ - P, Je = b(Kr * ke), Ke = b(Jr * Ae), We = Je + Ke, Ze = Je - Ke;
|
|
346
|
+
$ = b(We * We), P = b(he * b(Ze * Ze)), R = b(me * qe), M = b(Ge * (me + b(l * Ge)));
|
|
347
|
+
}
|
|
348
|
+
({ x_2: R, x_3: $ } = K(W, R, $)), { x_2: M, x_3: P } = K(W, M, P);
|
|
349
|
+
const Gr = i(M);
|
|
350
|
+
return b(R * Gr);
|
|
351
|
+
}
|
|
352
|
+
const ue = {
|
|
353
|
+
secretKey: f,
|
|
354
|
+
publicKey: f,
|
|
355
|
+
seed: f
|
|
356
|
+
}, te = (y = a(f)) => (Ve(y, ue.seed), y);
|
|
357
|
+
function qr(y) {
|
|
358
|
+
const k = te(y);
|
|
359
|
+
return { secretKey: k, publicKey: J(k) };
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
keygen: qr,
|
|
363
|
+
getSharedSecret: (y, k) => ee(y, k),
|
|
364
|
+
getPublicKey: (y) => J(y),
|
|
365
|
+
scalarMult: ee,
|
|
366
|
+
scalarMultBase: J,
|
|
367
|
+
utils: {
|
|
368
|
+
randomSecretKey: te,
|
|
369
|
+
randomPrivateKey: te
|
|
370
|
+
},
|
|
371
|
+
GuBytes: D.slice(),
|
|
372
|
+
lengths: ue
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
376
|
+
const hs = BigInt(1), rt = BigInt(2), fs = BigInt(3), ds = BigInt(5), gs = BigInt(8), xt = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"), ws = {
|
|
377
|
+
p: xt,
|
|
378
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
379
|
+
h: gs,
|
|
380
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
381
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
382
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
383
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
384
|
+
};
|
|
385
|
+
function Bs(n) {
|
|
386
|
+
const e = BigInt(10), t = BigInt(20), r = BigInt(40), s = BigInt(80), i = xt, c = n * n % i * n % i, a = U(c, rt, i) * c % i, u = U(a, hs, i) * n % i, f = U(u, ds, i) * u % i, h = U(f, e, i) * f % i, l = U(h, t, i) * h % i, g = U(l, r, i) * l % i, B = U(g, s, i) * g % i, m = U(B, s, i) * g % i, b = U(m, e, i) * f % i;
|
|
387
|
+
return { pow_p_5_8: U(b, rt, i) * n % i, b2: c };
|
|
388
|
+
}
|
|
389
|
+
function ys(n) {
|
|
390
|
+
return n[0] &= 248, n[31] &= 127, n[31] |= 64, n;
|
|
391
|
+
}
|
|
392
|
+
const bs = Ce(ws.p, { isLE: !0 }), Se = /* @__PURE__ */ (() => {
|
|
393
|
+
const n = bs.ORDER;
|
|
394
|
+
return us({
|
|
395
|
+
P: n,
|
|
396
|
+
type: "x25519",
|
|
397
|
+
powPminus2: (e) => {
|
|
398
|
+
const { pow_p_5_8: t, b2: r } = Bs(e);
|
|
399
|
+
return I(U(t, fs, n) * r, n);
|
|
400
|
+
},
|
|
401
|
+
adjustScalarBytes: ys
|
|
402
|
+
});
|
|
403
|
+
})();
|
|
404
|
+
/*!
|
|
405
|
+
* MIT License
|
|
406
|
+
*
|
|
407
|
+
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
408
|
+
*
|
|
409
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
410
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
411
|
+
* in the Software without restriction, including without limitation the rights
|
|
412
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
413
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
414
|
+
* furnished to do so, subject to the following conditions:
|
|
415
|
+
*
|
|
416
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
417
|
+
* copies or substantial portions of the Software.
|
|
418
|
+
*
|
|
419
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
420
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
421
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
422
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
423
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
424
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
425
|
+
* SOFTWARE.
|
|
426
|
+
*
|
|
427
|
+
*/
|
|
428
|
+
const vs = "[object ArrayBuffer]";
|
|
429
|
+
class w {
|
|
430
|
+
static isArrayBuffer(e) {
|
|
431
|
+
return Object.prototype.toString.call(e) === vs;
|
|
432
|
+
}
|
|
433
|
+
static toArrayBuffer(e) {
|
|
434
|
+
return this.isArrayBuffer(e) ? e : e.byteLength === e.buffer.byteLength || e.byteOffset === 0 && e.byteLength === e.buffer.byteLength ? e.buffer : this.toUint8Array(e.buffer).slice(e.byteOffset, e.byteOffset + e.byteLength).buffer;
|
|
435
|
+
}
|
|
436
|
+
static toUint8Array(e) {
|
|
437
|
+
return this.toView(e, Uint8Array);
|
|
438
|
+
}
|
|
439
|
+
static toView(e, t) {
|
|
440
|
+
if (e.constructor === t)
|
|
441
|
+
return e;
|
|
442
|
+
if (this.isArrayBuffer(e))
|
|
443
|
+
return new t(e);
|
|
444
|
+
if (this.isArrayBufferView(e))
|
|
445
|
+
return new t(e.buffer, e.byteOffset, e.byteLength);
|
|
446
|
+
throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");
|
|
447
|
+
}
|
|
448
|
+
static isBufferSource(e) {
|
|
449
|
+
return this.isArrayBufferView(e) || this.isArrayBuffer(e);
|
|
450
|
+
}
|
|
451
|
+
static isArrayBufferView(e) {
|
|
452
|
+
return ArrayBuffer.isView(e) || e && this.isArrayBuffer(e.buffer);
|
|
453
|
+
}
|
|
454
|
+
static isEqual(e, t) {
|
|
455
|
+
const r = w.toUint8Array(e), s = w.toUint8Array(t);
|
|
456
|
+
if (r.length !== s.byteLength)
|
|
457
|
+
return !1;
|
|
458
|
+
for (let i = 0; i < r.length; i++)
|
|
459
|
+
if (r[i] !== s[i])
|
|
460
|
+
return !1;
|
|
461
|
+
return !0;
|
|
462
|
+
}
|
|
463
|
+
static concat(...e) {
|
|
464
|
+
let t;
|
|
465
|
+
Array.isArray(e[0]) && !(e[1] instanceof Function) || Array.isArray(e[0]) && e[1] instanceof Function ? t = e[0] : e[e.length - 1] instanceof Function ? t = e.slice(0, e.length - 1) : t = e;
|
|
466
|
+
let r = 0;
|
|
467
|
+
for (const o of t)
|
|
468
|
+
r += o.byteLength;
|
|
469
|
+
const s = new Uint8Array(r);
|
|
470
|
+
let i = 0;
|
|
471
|
+
for (const o of t) {
|
|
472
|
+
const c = this.toUint8Array(o);
|
|
473
|
+
s.set(c, i), i += c.length;
|
|
474
|
+
}
|
|
475
|
+
return e[e.length - 1] instanceof Function ? this.toView(s, e[e.length - 1]) : s.buffer;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const Ee = "string", ks = /^[0-9a-f\s]+$/i, ms = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, As = /^[a-zA-Z0-9-_]+$/;
|
|
479
|
+
class st {
|
|
480
|
+
static fromString(e) {
|
|
481
|
+
const t = unescape(encodeURIComponent(e)), r = new Uint8Array(t.length);
|
|
482
|
+
for (let s = 0; s < t.length; s++)
|
|
483
|
+
r[s] = t.charCodeAt(s);
|
|
484
|
+
return r.buffer;
|
|
485
|
+
}
|
|
486
|
+
static toString(e) {
|
|
487
|
+
const t = w.toUint8Array(e);
|
|
488
|
+
let r = "";
|
|
489
|
+
for (let i = 0; i < t.length; i++)
|
|
490
|
+
r += String.fromCharCode(t[i]);
|
|
491
|
+
return decodeURIComponent(escape(r));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
class V {
|
|
495
|
+
static toString(e, t = !1) {
|
|
496
|
+
const r = w.toArrayBuffer(e), s = new DataView(r);
|
|
497
|
+
let i = "";
|
|
498
|
+
for (let o = 0; o < r.byteLength; o += 2) {
|
|
499
|
+
const c = s.getUint16(o, t);
|
|
500
|
+
i += String.fromCharCode(c);
|
|
501
|
+
}
|
|
502
|
+
return i;
|
|
503
|
+
}
|
|
504
|
+
static fromString(e, t = !1) {
|
|
505
|
+
const r = new ArrayBuffer(e.length * 2), s = new DataView(r);
|
|
506
|
+
for (let i = 0; i < e.length; i++)
|
|
507
|
+
s.setUint16(i * 2, e.charCodeAt(i), t);
|
|
508
|
+
return r;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
class v {
|
|
512
|
+
static isHex(e) {
|
|
513
|
+
return typeof e === Ee && ks.test(e);
|
|
514
|
+
}
|
|
515
|
+
static isBase64(e) {
|
|
516
|
+
return typeof e === Ee && ms.test(e);
|
|
517
|
+
}
|
|
518
|
+
static isBase64Url(e) {
|
|
519
|
+
return typeof e === Ee && As.test(e);
|
|
520
|
+
}
|
|
521
|
+
static ToString(e, t = "utf8") {
|
|
522
|
+
const r = w.toUint8Array(e);
|
|
523
|
+
switch (t.toLowerCase()) {
|
|
524
|
+
case "utf8":
|
|
525
|
+
return this.ToUtf8String(r);
|
|
526
|
+
case "binary":
|
|
527
|
+
return this.ToBinary(r);
|
|
528
|
+
case "hex":
|
|
529
|
+
return this.ToHex(r);
|
|
530
|
+
case "base64":
|
|
531
|
+
return this.ToBase64(r);
|
|
532
|
+
case "base64url":
|
|
533
|
+
return this.ToBase64Url(r);
|
|
534
|
+
case "utf16le":
|
|
535
|
+
return V.toString(r, !0);
|
|
536
|
+
case "utf16":
|
|
537
|
+
case "utf16be":
|
|
538
|
+
return V.toString(r);
|
|
539
|
+
default:
|
|
540
|
+
throw new Error(`Unknown type of encoding '${t}'`);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
static FromString(e, t = "utf8") {
|
|
544
|
+
if (!e)
|
|
545
|
+
return new ArrayBuffer(0);
|
|
546
|
+
switch (t.toLowerCase()) {
|
|
547
|
+
case "utf8":
|
|
548
|
+
return this.FromUtf8String(e);
|
|
549
|
+
case "binary":
|
|
550
|
+
return this.FromBinary(e);
|
|
551
|
+
case "hex":
|
|
552
|
+
return this.FromHex(e);
|
|
553
|
+
case "base64":
|
|
554
|
+
return this.FromBase64(e);
|
|
555
|
+
case "base64url":
|
|
556
|
+
return this.FromBase64Url(e);
|
|
557
|
+
case "utf16le":
|
|
558
|
+
return V.fromString(e, !0);
|
|
559
|
+
case "utf16":
|
|
560
|
+
case "utf16be":
|
|
561
|
+
return V.fromString(e);
|
|
562
|
+
default:
|
|
563
|
+
throw new Error(`Unknown type of encoding '${t}'`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
static ToBase64(e) {
|
|
567
|
+
const t = w.toUint8Array(e);
|
|
568
|
+
if (typeof btoa < "u") {
|
|
569
|
+
const r = this.ToString(t, "binary");
|
|
570
|
+
return btoa(r);
|
|
571
|
+
} else
|
|
572
|
+
return Buffer.from(t).toString("base64");
|
|
573
|
+
}
|
|
574
|
+
static FromBase64(e) {
|
|
575
|
+
const t = this.formatString(e);
|
|
576
|
+
if (!t)
|
|
577
|
+
return new ArrayBuffer(0);
|
|
578
|
+
if (!v.isBase64(t))
|
|
579
|
+
throw new TypeError("Argument 'base64Text' is not Base64 encoded");
|
|
580
|
+
return typeof atob < "u" ? this.FromBinary(atob(t)) : new Uint8Array(Buffer.from(t, "base64")).buffer;
|
|
581
|
+
}
|
|
582
|
+
static FromBase64Url(e) {
|
|
583
|
+
const t = this.formatString(e);
|
|
584
|
+
if (!t)
|
|
585
|
+
return new ArrayBuffer(0);
|
|
586
|
+
if (!v.isBase64Url(t))
|
|
587
|
+
throw new TypeError("Argument 'base64url' is not Base64Url encoded");
|
|
588
|
+
return this.FromBase64(this.Base64Padding(t.replace(/\-/g, "+").replace(/\_/g, "/")));
|
|
589
|
+
}
|
|
590
|
+
static ToBase64Url(e) {
|
|
591
|
+
return this.ToBase64(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=/g, "");
|
|
592
|
+
}
|
|
593
|
+
static FromUtf8String(e, t = v.DEFAULT_UTF8_ENCODING) {
|
|
594
|
+
switch (t) {
|
|
595
|
+
case "ascii":
|
|
596
|
+
return this.FromBinary(e);
|
|
597
|
+
case "utf8":
|
|
598
|
+
return st.fromString(e);
|
|
599
|
+
case "utf16":
|
|
600
|
+
case "utf16be":
|
|
601
|
+
return V.fromString(e);
|
|
602
|
+
case "utf16le":
|
|
603
|
+
case "usc2":
|
|
604
|
+
return V.fromString(e, !0);
|
|
605
|
+
default:
|
|
606
|
+
throw new Error(`Unknown type of encoding '${t}'`);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
static ToUtf8String(e, t = v.DEFAULT_UTF8_ENCODING) {
|
|
610
|
+
switch (t) {
|
|
611
|
+
case "ascii":
|
|
612
|
+
return this.ToBinary(e);
|
|
613
|
+
case "utf8":
|
|
614
|
+
return st.toString(e);
|
|
615
|
+
case "utf16":
|
|
616
|
+
case "utf16be":
|
|
617
|
+
return V.toString(e);
|
|
618
|
+
case "utf16le":
|
|
619
|
+
case "usc2":
|
|
620
|
+
return V.toString(e, !0);
|
|
621
|
+
default:
|
|
622
|
+
throw new Error(`Unknown type of encoding '${t}'`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
static FromBinary(e) {
|
|
626
|
+
const t = e.length, r = new Uint8Array(t);
|
|
627
|
+
for (let s = 0; s < t; s++)
|
|
628
|
+
r[s] = e.charCodeAt(s);
|
|
629
|
+
return r.buffer;
|
|
630
|
+
}
|
|
631
|
+
static ToBinary(e) {
|
|
632
|
+
const t = w.toUint8Array(e);
|
|
633
|
+
let r = "";
|
|
634
|
+
for (let s = 0; s < t.length; s++)
|
|
635
|
+
r += String.fromCharCode(t[s]);
|
|
636
|
+
return r;
|
|
637
|
+
}
|
|
638
|
+
static ToHex(e) {
|
|
639
|
+
const t = w.toUint8Array(e);
|
|
640
|
+
let r = "";
|
|
641
|
+
const s = t.length;
|
|
642
|
+
for (let i = 0; i < s; i++) {
|
|
643
|
+
const o = t[i];
|
|
644
|
+
o < 16 && (r += "0"), r += o.toString(16);
|
|
645
|
+
}
|
|
646
|
+
return r;
|
|
647
|
+
}
|
|
648
|
+
static FromHex(e) {
|
|
649
|
+
let t = this.formatString(e);
|
|
650
|
+
if (!t)
|
|
651
|
+
return new ArrayBuffer(0);
|
|
652
|
+
if (!v.isHex(t))
|
|
653
|
+
throw new TypeError("Argument 'hexString' is not HEX encoded");
|
|
654
|
+
t.length % 2 && (t = `0${t}`);
|
|
655
|
+
const r = new Uint8Array(t.length / 2);
|
|
656
|
+
for (let s = 0; s < t.length; s = s + 2) {
|
|
657
|
+
const i = t.slice(s, s + 2);
|
|
658
|
+
r[s / 2] = parseInt(i, 16);
|
|
659
|
+
}
|
|
660
|
+
return r.buffer;
|
|
661
|
+
}
|
|
662
|
+
static ToUtf16String(e, t = !1) {
|
|
663
|
+
return V.toString(e, t);
|
|
664
|
+
}
|
|
665
|
+
static FromUtf16String(e, t = !1) {
|
|
666
|
+
return V.fromString(e, t);
|
|
667
|
+
}
|
|
668
|
+
static Base64Padding(e) {
|
|
669
|
+
const t = 4 - e.length % 4;
|
|
670
|
+
if (t < 4)
|
|
671
|
+
for (let r = 0; r < t; r++)
|
|
672
|
+
e += "=";
|
|
673
|
+
return e;
|
|
674
|
+
}
|
|
675
|
+
static formatString(e) {
|
|
676
|
+
return (e == null ? void 0 : e.replace(/[\n\r\t ]/g, "")) || "";
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
v.DEFAULT_UTF8_ENCODING = "utf8";
|
|
680
|
+
/*!
|
|
681
|
+
Copyright (c) Peculiar Ventures, LLC
|
|
682
|
+
*/
|
|
683
|
+
function X(n, e) {
|
|
684
|
+
let t = 0;
|
|
685
|
+
if (n.length === 1)
|
|
686
|
+
return n[0];
|
|
687
|
+
for (let r = n.length - 1; r >= 0; r--)
|
|
688
|
+
t += n[n.length - 1 - r] * Math.pow(2, e * r);
|
|
689
|
+
return t;
|
|
690
|
+
}
|
|
691
|
+
function j(n, e, t = -1) {
|
|
692
|
+
const r = t;
|
|
693
|
+
let s = n, i = 0, o = Math.pow(2, e);
|
|
694
|
+
for (let c = 1; c < 8; c++) {
|
|
695
|
+
if (n < o) {
|
|
696
|
+
let a;
|
|
697
|
+
if (r < 0)
|
|
698
|
+
a = new ArrayBuffer(c), i = c;
|
|
699
|
+
else {
|
|
700
|
+
if (r < c)
|
|
701
|
+
return new ArrayBuffer(0);
|
|
702
|
+
a = new ArrayBuffer(r), i = r;
|
|
703
|
+
}
|
|
704
|
+
const u = new Uint8Array(a);
|
|
705
|
+
for (let f = c - 1; f >= 0; f--) {
|
|
706
|
+
const h = Math.pow(2, f * e);
|
|
707
|
+
u[i - f - 1] = Math.floor(s / h), s -= u[i - f - 1] * h;
|
|
708
|
+
}
|
|
709
|
+
return a;
|
|
710
|
+
}
|
|
711
|
+
o *= Math.pow(2, e);
|
|
712
|
+
}
|
|
713
|
+
return new ArrayBuffer(0);
|
|
714
|
+
}
|
|
715
|
+
function Ne(...n) {
|
|
716
|
+
let e = 0, t = 0;
|
|
717
|
+
for (const i of n)
|
|
718
|
+
e += i.length;
|
|
719
|
+
const r = new ArrayBuffer(e), s = new Uint8Array(r);
|
|
720
|
+
for (const i of n)
|
|
721
|
+
s.set(i, t), t += i.length;
|
|
722
|
+
return s;
|
|
723
|
+
}
|
|
724
|
+
function St() {
|
|
725
|
+
const n = new Uint8Array(this.valueHex);
|
|
726
|
+
if (this.valueHex.byteLength >= 2) {
|
|
727
|
+
const c = n[0] === 255 && n[1] & 128, a = n[0] === 0 && (n[1] & 128) === 0;
|
|
728
|
+
(c || a) && this.warnings.push("Needlessly long format");
|
|
729
|
+
}
|
|
730
|
+
const e = new ArrayBuffer(this.valueHex.byteLength), t = new Uint8Array(e);
|
|
731
|
+
for (let c = 0; c < this.valueHex.byteLength; c++)
|
|
732
|
+
t[c] = 0;
|
|
733
|
+
t[0] = n[0] & 128;
|
|
734
|
+
const r = X(t, 8), s = new ArrayBuffer(this.valueHex.byteLength), i = new Uint8Array(s);
|
|
735
|
+
for (let c = 0; c < this.valueHex.byteLength; c++)
|
|
736
|
+
i[c] = n[c];
|
|
737
|
+
return i[0] &= 127, X(i, 8) - r;
|
|
738
|
+
}
|
|
739
|
+
function xs(n) {
|
|
740
|
+
const e = n < 0 ? n * -1 : n;
|
|
741
|
+
let t = 128;
|
|
742
|
+
for (let r = 1; r < 8; r++) {
|
|
743
|
+
if (e <= t) {
|
|
744
|
+
if (n < 0) {
|
|
745
|
+
const o = t - e, c = j(o, 8, r), a = new Uint8Array(c);
|
|
746
|
+
return a[0] |= 128, c;
|
|
747
|
+
}
|
|
748
|
+
let s = j(e, 8, r), i = new Uint8Array(s);
|
|
749
|
+
if (i[0] & 128) {
|
|
750
|
+
const o = s.slice(0), c = new Uint8Array(o);
|
|
751
|
+
s = new ArrayBuffer(s.byteLength + 1), i = new Uint8Array(s);
|
|
752
|
+
for (let a = 0; a < o.byteLength; a++)
|
|
753
|
+
i[a + 1] = c[a];
|
|
754
|
+
i[0] = 0;
|
|
755
|
+
}
|
|
756
|
+
return s;
|
|
757
|
+
}
|
|
758
|
+
t *= Math.pow(2, 8);
|
|
759
|
+
}
|
|
760
|
+
return new ArrayBuffer(0);
|
|
761
|
+
}
|
|
762
|
+
function Ss(n, e) {
|
|
763
|
+
if (n.byteLength !== e.byteLength)
|
|
764
|
+
return !1;
|
|
765
|
+
const t = new Uint8Array(n), r = new Uint8Array(e);
|
|
766
|
+
for (let s = 0; s < t.length; s++)
|
|
767
|
+
if (t[s] !== r[s])
|
|
768
|
+
return !1;
|
|
769
|
+
return !0;
|
|
770
|
+
}
|
|
771
|
+
function E(n, e) {
|
|
772
|
+
const t = n.toString(10);
|
|
773
|
+
if (e < t.length)
|
|
774
|
+
return "";
|
|
775
|
+
const r = e - t.length, s = new Array(r);
|
|
776
|
+
for (let o = 0; o < r; o++)
|
|
777
|
+
s[o] = "0";
|
|
778
|
+
return s.join("").concat(t);
|
|
779
|
+
}
|
|
780
|
+
/*!
|
|
781
|
+
* Copyright (c) 2014, GMO GlobalSign
|
|
782
|
+
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
783
|
+
* All rights reserved.
|
|
784
|
+
*
|
|
785
|
+
* Author 2014-2019, Yury Strozhevsky
|
|
786
|
+
*
|
|
787
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
788
|
+
* are permitted provided that the following conditions are met:
|
|
789
|
+
*
|
|
790
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
|
791
|
+
* list of conditions and the following disclaimer.
|
|
792
|
+
*
|
|
793
|
+
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
794
|
+
* list of conditions and the following disclaimer in the documentation and/or
|
|
795
|
+
* other materials provided with the distribution.
|
|
796
|
+
*
|
|
797
|
+
* * Neither the name of the copyright holder nor the names of its
|
|
798
|
+
* contributors may be used to endorse or promote products derived from
|
|
799
|
+
* this software without specific prior written permission.
|
|
800
|
+
*
|
|
801
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
802
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
803
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
804
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
805
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
806
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
807
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
808
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
809
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
810
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
811
|
+
*
|
|
812
|
+
*/
|
|
813
|
+
function de() {
|
|
814
|
+
if (typeof BigInt > "u")
|
|
815
|
+
throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.");
|
|
816
|
+
}
|
|
817
|
+
function _e(n) {
|
|
818
|
+
let e = 0, t = 0;
|
|
819
|
+
for (let s = 0; s < n.length; s++) {
|
|
820
|
+
const i = n[s];
|
|
821
|
+
e += i.byteLength;
|
|
822
|
+
}
|
|
823
|
+
const r = new Uint8Array(e);
|
|
824
|
+
for (let s = 0; s < n.length; s++) {
|
|
825
|
+
const i = n[s];
|
|
826
|
+
r.set(new Uint8Array(i), t), t += i.byteLength;
|
|
827
|
+
}
|
|
828
|
+
return r.buffer;
|
|
829
|
+
}
|
|
830
|
+
function H(n, e, t, r) {
|
|
831
|
+
return e instanceof Uint8Array ? e.byteLength ? t < 0 ? (n.error = "Wrong parameter: inputOffset less than zero", !1) : r < 0 ? (n.error = "Wrong parameter: inputLength less than zero", !1) : e.byteLength - t - r < 0 ? (n.error = "End of input reached before message was fully decoded (inconsistent offset and length values)", !1) : !0 : (n.error = "Wrong parameter: inputBuffer has zero length", !1) : (n.error = "Wrong parameter: inputBuffer must be 'Uint8Array'", !1);
|
|
832
|
+
}
|
|
833
|
+
class He {
|
|
834
|
+
constructor() {
|
|
835
|
+
this.items = [];
|
|
836
|
+
}
|
|
837
|
+
write(e) {
|
|
838
|
+
this.items.push(e);
|
|
839
|
+
}
|
|
840
|
+
final() {
|
|
841
|
+
return _e(this.items);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const se = [new Uint8Array([1])], nt = "0123456789", Y = "", T = new ArrayBuffer(0), Le = new Uint8Array(0), ae = "EndOfContent", Et = "OCTET STRING", pt = "BIT STRING";
|
|
845
|
+
function L(n) {
|
|
846
|
+
var e;
|
|
847
|
+
return e = class extends n {
|
|
848
|
+
get valueHex() {
|
|
849
|
+
return this.valueHexView.slice().buffer;
|
|
850
|
+
}
|
|
851
|
+
set valueHex(r) {
|
|
852
|
+
this.valueHexView = new Uint8Array(r);
|
|
853
|
+
}
|
|
854
|
+
constructor(...r) {
|
|
855
|
+
var s;
|
|
856
|
+
super(...r);
|
|
857
|
+
const i = r[0] || {};
|
|
858
|
+
this.isHexOnly = (s = i.isHexOnly) !== null && s !== void 0 ? s : !1, this.valueHexView = i.valueHex ? w.toUint8Array(i.valueHex) : Le;
|
|
859
|
+
}
|
|
860
|
+
fromBER(r, s, i) {
|
|
861
|
+
const o = r instanceof ArrayBuffer ? new Uint8Array(r) : r;
|
|
862
|
+
if (!H(this, o, s, i))
|
|
863
|
+
return -1;
|
|
864
|
+
const c = s + i;
|
|
865
|
+
return this.valueHexView = o.subarray(s, c), this.valueHexView.length ? (this.blockLength = i, c) : (this.warnings.push("Zero buffer length"), s);
|
|
866
|
+
}
|
|
867
|
+
toBER(r = !1) {
|
|
868
|
+
return this.isHexOnly ? r ? new ArrayBuffer(this.valueHexView.byteLength) : this.valueHexView.byteLength === this.valueHexView.buffer.byteLength ? this.valueHexView.buffer : this.valueHexView.slice().buffer : (this.error = "Flag 'isHexOnly' is not set, abort", T);
|
|
869
|
+
}
|
|
870
|
+
toJSON() {
|
|
871
|
+
return {
|
|
872
|
+
...super.toJSON(),
|
|
873
|
+
isHexOnly: this.isHexOnly,
|
|
874
|
+
valueHex: v.ToHex(this.valueHexView)
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
}, e.NAME = "hexBlock", e;
|
|
878
|
+
}
|
|
879
|
+
class q {
|
|
880
|
+
static blockName() {
|
|
881
|
+
return this.NAME;
|
|
882
|
+
}
|
|
883
|
+
get valueBeforeDecode() {
|
|
884
|
+
return this.valueBeforeDecodeView.slice().buffer;
|
|
885
|
+
}
|
|
886
|
+
set valueBeforeDecode(e) {
|
|
887
|
+
this.valueBeforeDecodeView = new Uint8Array(e);
|
|
888
|
+
}
|
|
889
|
+
constructor({ blockLength: e = 0, error: t = Y, warnings: r = [], valueBeforeDecode: s = Le } = {}) {
|
|
890
|
+
this.blockLength = e, this.error = t, this.warnings = r, this.valueBeforeDecodeView = w.toUint8Array(s);
|
|
891
|
+
}
|
|
892
|
+
toJSON() {
|
|
893
|
+
return {
|
|
894
|
+
blockName: this.constructor.NAME,
|
|
895
|
+
blockLength: this.blockLength,
|
|
896
|
+
error: this.error,
|
|
897
|
+
warnings: this.warnings,
|
|
898
|
+
valueBeforeDecode: v.ToHex(this.valueBeforeDecodeView)
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
q.NAME = "baseBlock";
|
|
903
|
+
class S extends q {
|
|
904
|
+
fromBER(e, t, r) {
|
|
905
|
+
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
|
906
|
+
}
|
|
907
|
+
toBER(e, t) {
|
|
908
|
+
throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'");
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
S.NAME = "valueBlock";
|
|
912
|
+
class Nt extends L(q) {
|
|
913
|
+
constructor({ idBlock: e = {} } = {}) {
|
|
914
|
+
var t, r, s, i;
|
|
915
|
+
super(), e ? (this.isHexOnly = (t = e.isHexOnly) !== null && t !== void 0 ? t : !1, this.valueHexView = e.valueHex ? w.toUint8Array(e.valueHex) : Le, this.tagClass = (r = e.tagClass) !== null && r !== void 0 ? r : -1, this.tagNumber = (s = e.tagNumber) !== null && s !== void 0 ? s : -1, this.isConstructed = (i = e.isConstructed) !== null && i !== void 0 ? i : !1) : (this.tagClass = -1, this.tagNumber = -1, this.isConstructed = !1);
|
|
916
|
+
}
|
|
917
|
+
toBER(e = !1) {
|
|
918
|
+
let t = 0;
|
|
919
|
+
switch (this.tagClass) {
|
|
920
|
+
case 1:
|
|
921
|
+
t |= 0;
|
|
922
|
+
break;
|
|
923
|
+
case 2:
|
|
924
|
+
t |= 64;
|
|
925
|
+
break;
|
|
926
|
+
case 3:
|
|
927
|
+
t |= 128;
|
|
928
|
+
break;
|
|
929
|
+
case 4:
|
|
930
|
+
t |= 192;
|
|
931
|
+
break;
|
|
932
|
+
default:
|
|
933
|
+
return this.error = "Unknown tag class", T;
|
|
934
|
+
}
|
|
935
|
+
if (this.isConstructed && (t |= 32), this.tagNumber < 31 && !this.isHexOnly) {
|
|
936
|
+
const s = new Uint8Array(1);
|
|
937
|
+
if (!e) {
|
|
938
|
+
let i = this.tagNumber;
|
|
939
|
+
i &= 31, t |= i, s[0] = t;
|
|
940
|
+
}
|
|
941
|
+
return s.buffer;
|
|
942
|
+
}
|
|
943
|
+
if (!this.isHexOnly) {
|
|
944
|
+
const s = j(this.tagNumber, 7), i = new Uint8Array(s), o = s.byteLength, c = new Uint8Array(o + 1);
|
|
945
|
+
if (c[0] = t | 31, !e) {
|
|
946
|
+
for (let a = 0; a < o - 1; a++)
|
|
947
|
+
c[a + 1] = i[a] | 128;
|
|
948
|
+
c[o] = i[o - 1];
|
|
949
|
+
}
|
|
950
|
+
return c.buffer;
|
|
951
|
+
}
|
|
952
|
+
const r = new Uint8Array(this.valueHexView.byteLength + 1);
|
|
953
|
+
if (r[0] = t | 31, !e) {
|
|
954
|
+
const s = this.valueHexView;
|
|
955
|
+
for (let i = 0; i < s.length - 1; i++)
|
|
956
|
+
r[i + 1] = s[i] | 128;
|
|
957
|
+
r[this.valueHexView.byteLength] = s[s.length - 1];
|
|
958
|
+
}
|
|
959
|
+
return r.buffer;
|
|
960
|
+
}
|
|
961
|
+
fromBER(e, t, r) {
|
|
962
|
+
const s = w.toUint8Array(e);
|
|
963
|
+
if (!H(this, s, t, r))
|
|
964
|
+
return -1;
|
|
965
|
+
const i = s.subarray(t, t + r);
|
|
966
|
+
if (i.length === 0)
|
|
967
|
+
return this.error = "Zero buffer length", -1;
|
|
968
|
+
switch (i[0] & 192) {
|
|
969
|
+
case 0:
|
|
970
|
+
this.tagClass = 1;
|
|
971
|
+
break;
|
|
972
|
+
case 64:
|
|
973
|
+
this.tagClass = 2;
|
|
974
|
+
break;
|
|
975
|
+
case 128:
|
|
976
|
+
this.tagClass = 3;
|
|
977
|
+
break;
|
|
978
|
+
case 192:
|
|
979
|
+
this.tagClass = 4;
|
|
980
|
+
break;
|
|
981
|
+
default:
|
|
982
|
+
return this.error = "Unknown tag class", -1;
|
|
983
|
+
}
|
|
984
|
+
this.isConstructed = (i[0] & 32) === 32, this.isHexOnly = !1;
|
|
985
|
+
const c = i[0] & 31;
|
|
986
|
+
if (c !== 31)
|
|
987
|
+
this.tagNumber = c, this.blockLength = 1;
|
|
988
|
+
else {
|
|
989
|
+
let a = 1, u = this.valueHexView = new Uint8Array(255), f = 255;
|
|
990
|
+
for (; i[a] & 128; ) {
|
|
991
|
+
if (u[a - 1] = i[a] & 127, a++, a >= i.length)
|
|
992
|
+
return this.error = "End of input reached before message was fully decoded", -1;
|
|
993
|
+
if (a === f) {
|
|
994
|
+
f += 255;
|
|
995
|
+
const l = new Uint8Array(f);
|
|
996
|
+
for (let g = 0; g < u.length; g++)
|
|
997
|
+
l[g] = u[g];
|
|
998
|
+
u = this.valueHexView = new Uint8Array(f);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
this.blockLength = a + 1, u[a - 1] = i[a] & 127;
|
|
1002
|
+
const h = new Uint8Array(a);
|
|
1003
|
+
for (let l = 0; l < a; l++)
|
|
1004
|
+
h[l] = u[l];
|
|
1005
|
+
u = this.valueHexView = new Uint8Array(a), u.set(h), this.blockLength <= 9 ? this.tagNumber = X(u, 7) : (this.isHexOnly = !0, this.warnings.push("Tag too long, represented as hex-coded"));
|
|
1006
|
+
}
|
|
1007
|
+
if (this.tagClass === 1 && this.isConstructed)
|
|
1008
|
+
switch (this.tagNumber) {
|
|
1009
|
+
case 1:
|
|
1010
|
+
case 2:
|
|
1011
|
+
case 5:
|
|
1012
|
+
case 6:
|
|
1013
|
+
case 9:
|
|
1014
|
+
case 13:
|
|
1015
|
+
case 14:
|
|
1016
|
+
case 23:
|
|
1017
|
+
case 24:
|
|
1018
|
+
case 31:
|
|
1019
|
+
case 32:
|
|
1020
|
+
case 33:
|
|
1021
|
+
case 34:
|
|
1022
|
+
return this.error = "Constructed encoding used for primitive type", -1;
|
|
1023
|
+
}
|
|
1024
|
+
return t + this.blockLength;
|
|
1025
|
+
}
|
|
1026
|
+
toJSON() {
|
|
1027
|
+
return {
|
|
1028
|
+
...super.toJSON(),
|
|
1029
|
+
tagClass: this.tagClass,
|
|
1030
|
+
tagNumber: this.tagNumber,
|
|
1031
|
+
isConstructed: this.isConstructed
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
Nt.NAME = "identificationBlock";
|
|
1036
|
+
class It extends q {
|
|
1037
|
+
constructor({ lenBlock: e = {} } = {}) {
|
|
1038
|
+
var t, r, s;
|
|
1039
|
+
super(), this.isIndefiniteForm = (t = e.isIndefiniteForm) !== null && t !== void 0 ? t : !1, this.longFormUsed = (r = e.longFormUsed) !== null && r !== void 0 ? r : !1, this.length = (s = e.length) !== null && s !== void 0 ? s : 0;
|
|
1040
|
+
}
|
|
1041
|
+
fromBER(e, t, r) {
|
|
1042
|
+
const s = w.toUint8Array(e);
|
|
1043
|
+
if (!H(this, s, t, r))
|
|
1044
|
+
return -1;
|
|
1045
|
+
const i = s.subarray(t, t + r);
|
|
1046
|
+
if (i.length === 0)
|
|
1047
|
+
return this.error = "Zero buffer length", -1;
|
|
1048
|
+
if (i[0] === 255)
|
|
1049
|
+
return this.error = "Length block 0xFF is reserved by standard", -1;
|
|
1050
|
+
if (this.isIndefiniteForm = i[0] === 128, this.isIndefiniteForm)
|
|
1051
|
+
return this.blockLength = 1, t + this.blockLength;
|
|
1052
|
+
if (this.longFormUsed = !!(i[0] & 128), this.longFormUsed === !1)
|
|
1053
|
+
return this.length = i[0], this.blockLength = 1, t + this.blockLength;
|
|
1054
|
+
const o = i[0] & 127;
|
|
1055
|
+
if (o > 8)
|
|
1056
|
+
return this.error = "Too big integer", -1;
|
|
1057
|
+
if (o + 1 > i.length)
|
|
1058
|
+
return this.error = "End of input reached before message was fully decoded", -1;
|
|
1059
|
+
const c = t + 1, a = s.subarray(c, c + o);
|
|
1060
|
+
return a[o - 1] === 0 && this.warnings.push("Needlessly long encoded length"), this.length = X(a, 8), this.longFormUsed && this.length <= 127 && this.warnings.push("Unnecessary usage of long length form"), this.blockLength = o + 1, t + this.blockLength;
|
|
1061
|
+
}
|
|
1062
|
+
toBER(e = !1) {
|
|
1063
|
+
let t, r;
|
|
1064
|
+
if (this.length > 127 && (this.longFormUsed = !0), this.isIndefiniteForm)
|
|
1065
|
+
return t = new ArrayBuffer(1), e === !1 && (r = new Uint8Array(t), r[0] = 128), t;
|
|
1066
|
+
if (this.longFormUsed) {
|
|
1067
|
+
const s = j(this.length, 8);
|
|
1068
|
+
if (s.byteLength > 127)
|
|
1069
|
+
return this.error = "Too big length", T;
|
|
1070
|
+
if (t = new ArrayBuffer(s.byteLength + 1), e)
|
|
1071
|
+
return t;
|
|
1072
|
+
const i = new Uint8Array(s);
|
|
1073
|
+
r = new Uint8Array(t), r[0] = s.byteLength | 128;
|
|
1074
|
+
for (let o = 0; o < s.byteLength; o++)
|
|
1075
|
+
r[o + 1] = i[o];
|
|
1076
|
+
return t;
|
|
1077
|
+
}
|
|
1078
|
+
return t = new ArrayBuffer(1), e === !1 && (r = new Uint8Array(t), r[0] = this.length), t;
|
|
1079
|
+
}
|
|
1080
|
+
toJSON() {
|
|
1081
|
+
return {
|
|
1082
|
+
...super.toJSON(),
|
|
1083
|
+
isIndefiniteForm: this.isIndefiniteForm,
|
|
1084
|
+
longFormUsed: this.longFormUsed,
|
|
1085
|
+
length: this.length
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
It.NAME = "lengthBlock";
|
|
1090
|
+
const d = {};
|
|
1091
|
+
class A extends q {
|
|
1092
|
+
constructor({ name: e = Y, optional: t = !1, primitiveSchema: r, ...s } = {}, i) {
|
|
1093
|
+
super(s), this.name = e, this.optional = t, r && (this.primitiveSchema = r), this.idBlock = new Nt(s), this.lenBlock = new It(s), this.valueBlock = i ? new i(s) : new S(s);
|
|
1094
|
+
}
|
|
1095
|
+
fromBER(e, t, r) {
|
|
1096
|
+
const s = this.valueBlock.fromBER(e, t, this.lenBlock.isIndefiniteForm ? r : this.lenBlock.length);
|
|
1097
|
+
return s === -1 ? (this.error = this.valueBlock.error, s) : (this.idBlock.error.length || (this.blockLength += this.idBlock.blockLength), this.lenBlock.error.length || (this.blockLength += this.lenBlock.blockLength), this.valueBlock.error.length || (this.blockLength += this.valueBlock.blockLength), s);
|
|
1098
|
+
}
|
|
1099
|
+
toBER(e, t) {
|
|
1100
|
+
const r = t || new He();
|
|
1101
|
+
t || Ut(this);
|
|
1102
|
+
const s = this.idBlock.toBER(e);
|
|
1103
|
+
if (r.write(s), this.lenBlock.isIndefiniteForm)
|
|
1104
|
+
r.write(new Uint8Array([128]).buffer), this.valueBlock.toBER(e, r), r.write(new ArrayBuffer(2));
|
|
1105
|
+
else {
|
|
1106
|
+
const i = this.valueBlock.toBER(e);
|
|
1107
|
+
this.lenBlock.length = i.byteLength;
|
|
1108
|
+
const o = this.lenBlock.toBER(e);
|
|
1109
|
+
r.write(o), r.write(i);
|
|
1110
|
+
}
|
|
1111
|
+
return t ? T : r.final();
|
|
1112
|
+
}
|
|
1113
|
+
toJSON() {
|
|
1114
|
+
const e = {
|
|
1115
|
+
...super.toJSON(),
|
|
1116
|
+
idBlock: this.idBlock.toJSON(),
|
|
1117
|
+
lenBlock: this.lenBlock.toJSON(),
|
|
1118
|
+
valueBlock: this.valueBlock.toJSON(),
|
|
1119
|
+
name: this.name,
|
|
1120
|
+
optional: this.optional
|
|
1121
|
+
};
|
|
1122
|
+
return this.primitiveSchema && (e.primitiveSchema = this.primitiveSchema.toJSON()), e;
|
|
1123
|
+
}
|
|
1124
|
+
toString(e = "ascii") {
|
|
1125
|
+
return e === "ascii" ? this.onAsciiEncoding() : v.ToHex(this.toBER());
|
|
1126
|
+
}
|
|
1127
|
+
onAsciiEncoding() {
|
|
1128
|
+
const e = this.constructor.NAME, t = v.ToHex(this.valueBlock.valueBeforeDecodeView);
|
|
1129
|
+
return `${e} : ${t}`;
|
|
1130
|
+
}
|
|
1131
|
+
isEqual(e) {
|
|
1132
|
+
if (this === e)
|
|
1133
|
+
return !0;
|
|
1134
|
+
if (!(e instanceof this.constructor))
|
|
1135
|
+
return !1;
|
|
1136
|
+
const t = this.toBER(), r = e.toBER();
|
|
1137
|
+
return Ss(t, r);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
A.NAME = "BaseBlock";
|
|
1141
|
+
function Ut(n) {
|
|
1142
|
+
var e;
|
|
1143
|
+
if (n instanceof d.Constructed)
|
|
1144
|
+
for (const t of n.valueBlock.value)
|
|
1145
|
+
Ut(t) && (n.lenBlock.isIndefiniteForm = !0);
|
|
1146
|
+
return !!(!((e = n.lenBlock) === null || e === void 0) && e.isIndefiniteForm);
|
|
1147
|
+
}
|
|
1148
|
+
class Vt extends A {
|
|
1149
|
+
getValue() {
|
|
1150
|
+
return this.valueBlock.value;
|
|
1151
|
+
}
|
|
1152
|
+
setValue(e) {
|
|
1153
|
+
this.valueBlock.value = e;
|
|
1154
|
+
}
|
|
1155
|
+
constructor({ value: e = Y, ...t } = {}, r) {
|
|
1156
|
+
super(t, r), e && this.fromString(e);
|
|
1157
|
+
}
|
|
1158
|
+
fromBER(e, t, r) {
|
|
1159
|
+
const s = this.valueBlock.fromBER(e, t, this.lenBlock.isIndefiniteForm ? r : this.lenBlock.length);
|
|
1160
|
+
return s === -1 ? (this.error = this.valueBlock.error, s) : (this.fromBuffer(this.valueBlock.valueHexView), this.idBlock.error.length || (this.blockLength += this.idBlock.blockLength), this.lenBlock.error.length || (this.blockLength += this.lenBlock.blockLength), this.valueBlock.error.length || (this.blockLength += this.valueBlock.blockLength), s);
|
|
1161
|
+
}
|
|
1162
|
+
onAsciiEncoding() {
|
|
1163
|
+
return `${this.constructor.NAME} : '${this.valueBlock.value}'`;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
Vt.NAME = "BaseStringBlock";
|
|
1167
|
+
class Tt extends L(S) {
|
|
1168
|
+
constructor({ isHexOnly: e = !0, ...t } = {}) {
|
|
1169
|
+
super(t), this.isHexOnly = e;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
Tt.NAME = "PrimitiveValueBlock";
|
|
1173
|
+
var Ct;
|
|
1174
|
+
class _t extends A {
|
|
1175
|
+
constructor(e = {}) {
|
|
1176
|
+
super(e, Tt), this.idBlock.isConstructed = !1;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
Ct = _t;
|
|
1180
|
+
d.Primitive = Ct;
|
|
1181
|
+
_t.NAME = "PRIMITIVE";
|
|
1182
|
+
function Es(n, e) {
|
|
1183
|
+
if (n instanceof e)
|
|
1184
|
+
return n;
|
|
1185
|
+
const t = new e();
|
|
1186
|
+
return t.idBlock = n.idBlock, t.lenBlock = n.lenBlock, t.warnings = n.warnings, t.valueBeforeDecodeView = n.valueBeforeDecodeView, t;
|
|
1187
|
+
}
|
|
1188
|
+
function we(n, e = 0, t = n.length) {
|
|
1189
|
+
const r = e;
|
|
1190
|
+
let s = new A({}, S);
|
|
1191
|
+
const i = new q();
|
|
1192
|
+
if (!H(i, n, e, t))
|
|
1193
|
+
return s.error = i.error, {
|
|
1194
|
+
offset: -1,
|
|
1195
|
+
result: s
|
|
1196
|
+
};
|
|
1197
|
+
if (!n.subarray(e, e + t).length)
|
|
1198
|
+
return s.error = "Zero buffer length", {
|
|
1199
|
+
offset: -1,
|
|
1200
|
+
result: s
|
|
1201
|
+
};
|
|
1202
|
+
let c = s.idBlock.fromBER(n, e, t);
|
|
1203
|
+
if (s.idBlock.warnings.length && s.warnings.concat(s.idBlock.warnings), c === -1)
|
|
1204
|
+
return s.error = s.idBlock.error, {
|
|
1205
|
+
offset: -1,
|
|
1206
|
+
result: s
|
|
1207
|
+
};
|
|
1208
|
+
if (e = c, t -= s.idBlock.blockLength, c = s.lenBlock.fromBER(n, e, t), s.lenBlock.warnings.length && s.warnings.concat(s.lenBlock.warnings), c === -1)
|
|
1209
|
+
return s.error = s.lenBlock.error, {
|
|
1210
|
+
offset: -1,
|
|
1211
|
+
result: s
|
|
1212
|
+
};
|
|
1213
|
+
if (e = c, t -= s.lenBlock.blockLength, !s.idBlock.isConstructed && s.lenBlock.isIndefiniteForm)
|
|
1214
|
+
return s.error = "Indefinite length form used for primitive encoding form", {
|
|
1215
|
+
offset: -1,
|
|
1216
|
+
result: s
|
|
1217
|
+
};
|
|
1218
|
+
let a = A;
|
|
1219
|
+
switch (s.idBlock.tagClass) {
|
|
1220
|
+
case 1:
|
|
1221
|
+
if (s.idBlock.tagNumber >= 37 && s.idBlock.isHexOnly === !1)
|
|
1222
|
+
return s.error = "UNIVERSAL 37 and upper tags are reserved by ASN.1 standard", {
|
|
1223
|
+
offset: -1,
|
|
1224
|
+
result: s
|
|
1225
|
+
};
|
|
1226
|
+
switch (s.idBlock.tagNumber) {
|
|
1227
|
+
case 0:
|
|
1228
|
+
if (s.idBlock.isConstructed && s.lenBlock.length > 0)
|
|
1229
|
+
return s.error = "Type [UNIVERSAL 0] is reserved", {
|
|
1230
|
+
offset: -1,
|
|
1231
|
+
result: s
|
|
1232
|
+
};
|
|
1233
|
+
a = d.EndOfContent;
|
|
1234
|
+
break;
|
|
1235
|
+
case 1:
|
|
1236
|
+
a = d.Boolean;
|
|
1237
|
+
break;
|
|
1238
|
+
case 2:
|
|
1239
|
+
a = d.Integer;
|
|
1240
|
+
break;
|
|
1241
|
+
case 3:
|
|
1242
|
+
a = d.BitString;
|
|
1243
|
+
break;
|
|
1244
|
+
case 4:
|
|
1245
|
+
a = d.OctetString;
|
|
1246
|
+
break;
|
|
1247
|
+
case 5:
|
|
1248
|
+
a = d.Null;
|
|
1249
|
+
break;
|
|
1250
|
+
case 6:
|
|
1251
|
+
a = d.ObjectIdentifier;
|
|
1252
|
+
break;
|
|
1253
|
+
case 10:
|
|
1254
|
+
a = d.Enumerated;
|
|
1255
|
+
break;
|
|
1256
|
+
case 12:
|
|
1257
|
+
a = d.Utf8String;
|
|
1258
|
+
break;
|
|
1259
|
+
case 13:
|
|
1260
|
+
a = d.RelativeObjectIdentifier;
|
|
1261
|
+
break;
|
|
1262
|
+
case 14:
|
|
1263
|
+
a = d.TIME;
|
|
1264
|
+
break;
|
|
1265
|
+
case 15:
|
|
1266
|
+
return s.error = "[UNIVERSAL 15] is reserved by ASN.1 standard", {
|
|
1267
|
+
offset: -1,
|
|
1268
|
+
result: s
|
|
1269
|
+
};
|
|
1270
|
+
case 16:
|
|
1271
|
+
a = d.Sequence;
|
|
1272
|
+
break;
|
|
1273
|
+
case 17:
|
|
1274
|
+
a = d.Set;
|
|
1275
|
+
break;
|
|
1276
|
+
case 18:
|
|
1277
|
+
a = d.NumericString;
|
|
1278
|
+
break;
|
|
1279
|
+
case 19:
|
|
1280
|
+
a = d.PrintableString;
|
|
1281
|
+
break;
|
|
1282
|
+
case 20:
|
|
1283
|
+
a = d.TeletexString;
|
|
1284
|
+
break;
|
|
1285
|
+
case 21:
|
|
1286
|
+
a = d.VideotexString;
|
|
1287
|
+
break;
|
|
1288
|
+
case 22:
|
|
1289
|
+
a = d.IA5String;
|
|
1290
|
+
break;
|
|
1291
|
+
case 23:
|
|
1292
|
+
a = d.UTCTime;
|
|
1293
|
+
break;
|
|
1294
|
+
case 24:
|
|
1295
|
+
a = d.GeneralizedTime;
|
|
1296
|
+
break;
|
|
1297
|
+
case 25:
|
|
1298
|
+
a = d.GraphicString;
|
|
1299
|
+
break;
|
|
1300
|
+
case 26:
|
|
1301
|
+
a = d.VisibleString;
|
|
1302
|
+
break;
|
|
1303
|
+
case 27:
|
|
1304
|
+
a = d.GeneralString;
|
|
1305
|
+
break;
|
|
1306
|
+
case 28:
|
|
1307
|
+
a = d.UniversalString;
|
|
1308
|
+
break;
|
|
1309
|
+
case 29:
|
|
1310
|
+
a = d.CharacterString;
|
|
1311
|
+
break;
|
|
1312
|
+
case 30:
|
|
1313
|
+
a = d.BmpString;
|
|
1314
|
+
break;
|
|
1315
|
+
case 31:
|
|
1316
|
+
a = d.DATE;
|
|
1317
|
+
break;
|
|
1318
|
+
case 32:
|
|
1319
|
+
a = d.TimeOfDay;
|
|
1320
|
+
break;
|
|
1321
|
+
case 33:
|
|
1322
|
+
a = d.DateTime;
|
|
1323
|
+
break;
|
|
1324
|
+
case 34:
|
|
1325
|
+
a = d.Duration;
|
|
1326
|
+
break;
|
|
1327
|
+
default: {
|
|
1328
|
+
const u = s.idBlock.isConstructed ? new d.Constructed() : new d.Primitive();
|
|
1329
|
+
u.idBlock = s.idBlock, u.lenBlock = s.lenBlock, u.warnings = s.warnings, s = u;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
break;
|
|
1333
|
+
case 2:
|
|
1334
|
+
case 3:
|
|
1335
|
+
case 4:
|
|
1336
|
+
default:
|
|
1337
|
+
a = s.idBlock.isConstructed ? d.Constructed : d.Primitive;
|
|
1338
|
+
}
|
|
1339
|
+
return s = Es(s, a), c = s.fromBER(n, e, s.lenBlock.isIndefiniteForm ? t : s.lenBlock.length), s.valueBeforeDecodeView = n.subarray(r, r + s.blockLength), {
|
|
1340
|
+
offset: c,
|
|
1341
|
+
result: s
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function ps(n) {
|
|
1345
|
+
if (!n.byteLength) {
|
|
1346
|
+
const e = new A({}, S);
|
|
1347
|
+
return e.error = "Input buffer has zero length", {
|
|
1348
|
+
offset: -1,
|
|
1349
|
+
result: e
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
return we(w.toUint8Array(n).slice(), 0, n.byteLength);
|
|
1353
|
+
}
|
|
1354
|
+
function Ns(n, e) {
|
|
1355
|
+
return n ? 1 : e;
|
|
1356
|
+
}
|
|
1357
|
+
class O extends S {
|
|
1358
|
+
constructor({ value: e = [], isIndefiniteForm: t = !1, ...r } = {}) {
|
|
1359
|
+
super(r), this.value = e, this.isIndefiniteForm = t;
|
|
1360
|
+
}
|
|
1361
|
+
fromBER(e, t, r) {
|
|
1362
|
+
const s = w.toUint8Array(e);
|
|
1363
|
+
if (!H(this, s, t, r))
|
|
1364
|
+
return -1;
|
|
1365
|
+
if (this.valueBeforeDecodeView = s.subarray(t, t + r), this.valueBeforeDecodeView.length === 0)
|
|
1366
|
+
return this.warnings.push("Zero buffer length"), t;
|
|
1367
|
+
let i = t;
|
|
1368
|
+
for (; Ns(this.isIndefiniteForm, r) > 0; ) {
|
|
1369
|
+
const o = we(s, i, r);
|
|
1370
|
+
if (o.offset === -1)
|
|
1371
|
+
return this.error = o.result.error, this.warnings.concat(o.result.warnings), -1;
|
|
1372
|
+
if (i = o.offset, this.blockLength += o.result.blockLength, r -= o.result.blockLength, this.value.push(o.result), this.isIndefiniteForm && o.result.constructor.NAME === ae)
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
return this.isIndefiniteForm && (this.value[this.value.length - 1].constructor.NAME === ae ? this.value.pop() : this.warnings.push("No EndOfContent block encoded")), i;
|
|
1376
|
+
}
|
|
1377
|
+
toBER(e, t) {
|
|
1378
|
+
const r = t || new He();
|
|
1379
|
+
for (let s = 0; s < this.value.length; s++)
|
|
1380
|
+
this.value[s].toBER(e, r);
|
|
1381
|
+
return t ? T : r.final();
|
|
1382
|
+
}
|
|
1383
|
+
toJSON() {
|
|
1384
|
+
const e = {
|
|
1385
|
+
...super.toJSON(),
|
|
1386
|
+
isIndefiniteForm: this.isIndefiniteForm,
|
|
1387
|
+
value: []
|
|
1388
|
+
};
|
|
1389
|
+
for (const t of this.value)
|
|
1390
|
+
e.value.push(t.toJSON());
|
|
1391
|
+
return e;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
O.NAME = "ConstructedValueBlock";
|
|
1395
|
+
var Ht;
|
|
1396
|
+
class Q extends A {
|
|
1397
|
+
constructor(e = {}) {
|
|
1398
|
+
super(e, O), this.idBlock.isConstructed = !0;
|
|
1399
|
+
}
|
|
1400
|
+
fromBER(e, t, r) {
|
|
1401
|
+
this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm;
|
|
1402
|
+
const s = this.valueBlock.fromBER(e, t, this.lenBlock.isIndefiniteForm ? r : this.lenBlock.length);
|
|
1403
|
+
return s === -1 ? (this.error = this.valueBlock.error, s) : (this.idBlock.error.length || (this.blockLength += this.idBlock.blockLength), this.lenBlock.error.length || (this.blockLength += this.lenBlock.blockLength), this.valueBlock.error.length || (this.blockLength += this.valueBlock.blockLength), s);
|
|
1404
|
+
}
|
|
1405
|
+
onAsciiEncoding() {
|
|
1406
|
+
const e = [];
|
|
1407
|
+
for (const r of this.valueBlock.value)
|
|
1408
|
+
e.push(r.toString("ascii").split(`
|
|
1409
|
+
`).map((s) => ` ${s}`).join(`
|
|
1410
|
+
`));
|
|
1411
|
+
const t = this.idBlock.tagClass === 3 ? `[${this.idBlock.tagNumber}]` : this.constructor.NAME;
|
|
1412
|
+
return e.length ? `${t} :
|
|
1413
|
+
${e.join(`
|
|
1414
|
+
`)}` : `${t} :`;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
Ht = Q;
|
|
1418
|
+
d.Constructed = Ht;
|
|
1419
|
+
Q.NAME = "CONSTRUCTED";
|
|
1420
|
+
class Lt extends S {
|
|
1421
|
+
fromBER(e, t, r) {
|
|
1422
|
+
return t;
|
|
1423
|
+
}
|
|
1424
|
+
toBER(e) {
|
|
1425
|
+
return T;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
Lt.override = "EndOfContentValueBlock";
|
|
1429
|
+
var Rt;
|
|
1430
|
+
class Mt extends A {
|
|
1431
|
+
constructor(e = {}) {
|
|
1432
|
+
super(e, Lt), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 0;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
Rt = Mt;
|
|
1436
|
+
d.EndOfContent = Rt;
|
|
1437
|
+
Mt.NAME = ae;
|
|
1438
|
+
var Ot;
|
|
1439
|
+
class Dt extends A {
|
|
1440
|
+
constructor(e = {}) {
|
|
1441
|
+
super(e, S), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 5;
|
|
1442
|
+
}
|
|
1443
|
+
fromBER(e, t, r) {
|
|
1444
|
+
return this.lenBlock.length > 0 && this.warnings.push("Non-zero length of value block for Null type"), this.idBlock.error.length || (this.blockLength += this.idBlock.blockLength), this.lenBlock.error.length || (this.blockLength += this.lenBlock.blockLength), this.blockLength += r, t + r > e.byteLength ? (this.error = "End of input reached before message was fully decoded (inconsistent offset and length values)", -1) : t + r;
|
|
1445
|
+
}
|
|
1446
|
+
toBER(e, t) {
|
|
1447
|
+
const r = new ArrayBuffer(2);
|
|
1448
|
+
if (!e) {
|
|
1449
|
+
const s = new Uint8Array(r);
|
|
1450
|
+
s[0] = 5, s[1] = 0;
|
|
1451
|
+
}
|
|
1452
|
+
return t && t.write(r), r;
|
|
1453
|
+
}
|
|
1454
|
+
onAsciiEncoding() {
|
|
1455
|
+
return `${this.constructor.NAME}`;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
Ot = Dt;
|
|
1459
|
+
d.Null = Ot;
|
|
1460
|
+
Dt.NAME = "NULL";
|
|
1461
|
+
class $t extends L(S) {
|
|
1462
|
+
get value() {
|
|
1463
|
+
for (const e of this.valueHexView)
|
|
1464
|
+
if (e > 0)
|
|
1465
|
+
return !0;
|
|
1466
|
+
return !1;
|
|
1467
|
+
}
|
|
1468
|
+
set value(e) {
|
|
1469
|
+
this.valueHexView[0] = e ? 255 : 0;
|
|
1470
|
+
}
|
|
1471
|
+
constructor({ value: e, ...t } = {}) {
|
|
1472
|
+
super(t), t.valueHex ? this.valueHexView = w.toUint8Array(t.valueHex) : this.valueHexView = new Uint8Array(1), e && (this.value = e);
|
|
1473
|
+
}
|
|
1474
|
+
fromBER(e, t, r) {
|
|
1475
|
+
const s = w.toUint8Array(e);
|
|
1476
|
+
return H(this, s, t, r) ? (this.valueHexView = s.subarray(t, t + r), r > 1 && this.warnings.push("Boolean value encoded in more then 1 octet"), this.isHexOnly = !0, St.call(this), this.blockLength = r, t + r) : -1;
|
|
1477
|
+
}
|
|
1478
|
+
toBER() {
|
|
1479
|
+
return this.valueHexView.slice();
|
|
1480
|
+
}
|
|
1481
|
+
toJSON() {
|
|
1482
|
+
return {
|
|
1483
|
+
...super.toJSON(),
|
|
1484
|
+
value: this.value
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
$t.NAME = "BooleanValueBlock";
|
|
1489
|
+
var Pt;
|
|
1490
|
+
class Ft extends A {
|
|
1491
|
+
getValue() {
|
|
1492
|
+
return this.valueBlock.value;
|
|
1493
|
+
}
|
|
1494
|
+
setValue(e) {
|
|
1495
|
+
this.valueBlock.value = e;
|
|
1496
|
+
}
|
|
1497
|
+
constructor(e = {}) {
|
|
1498
|
+
super(e, $t), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 1;
|
|
1499
|
+
}
|
|
1500
|
+
onAsciiEncoding() {
|
|
1501
|
+
return `${this.constructor.NAME} : ${this.getValue}`;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
Pt = Ft;
|
|
1505
|
+
d.Boolean = Pt;
|
|
1506
|
+
Ft.NAME = "BOOLEAN";
|
|
1507
|
+
class jt extends L(O) {
|
|
1508
|
+
constructor({ isConstructed: e = !1, ...t } = {}) {
|
|
1509
|
+
super(t), this.isConstructed = e;
|
|
1510
|
+
}
|
|
1511
|
+
fromBER(e, t, r) {
|
|
1512
|
+
let s = 0;
|
|
1513
|
+
if (this.isConstructed) {
|
|
1514
|
+
if (this.isHexOnly = !1, s = O.prototype.fromBER.call(this, e, t, r), s === -1)
|
|
1515
|
+
return s;
|
|
1516
|
+
for (let i = 0; i < this.value.length; i++) {
|
|
1517
|
+
const o = this.value[i].constructor.NAME;
|
|
1518
|
+
if (o === ae) {
|
|
1519
|
+
if (this.isIndefiniteForm)
|
|
1520
|
+
break;
|
|
1521
|
+
return this.error = "EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only", -1;
|
|
1522
|
+
}
|
|
1523
|
+
if (o !== Et)
|
|
1524
|
+
return this.error = "OCTET STRING may consists of OCTET STRINGs only", -1;
|
|
1525
|
+
}
|
|
1526
|
+
} else
|
|
1527
|
+
this.isHexOnly = !0, s = super.fromBER(e, t, r), this.blockLength = r;
|
|
1528
|
+
return s;
|
|
1529
|
+
}
|
|
1530
|
+
toBER(e, t) {
|
|
1531
|
+
return this.isConstructed ? O.prototype.toBER.call(this, e, t) : e ? new ArrayBuffer(this.valueHexView.byteLength) : this.valueHexView.slice().buffer;
|
|
1532
|
+
}
|
|
1533
|
+
toJSON() {
|
|
1534
|
+
return {
|
|
1535
|
+
...super.toJSON(),
|
|
1536
|
+
isConstructed: this.isConstructed
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
jt.NAME = "OctetStringValueBlock";
|
|
1541
|
+
var Re;
|
|
1542
|
+
class qt extends A {
|
|
1543
|
+
constructor({ idBlock: e = {}, lenBlock: t = {}, ...r } = {}) {
|
|
1544
|
+
var s, i;
|
|
1545
|
+
(s = r.isConstructed) !== null && s !== void 0 || (r.isConstructed = !!(!((i = r.value) === null || i === void 0) && i.length)), super({
|
|
1546
|
+
idBlock: {
|
|
1547
|
+
isConstructed: r.isConstructed,
|
|
1548
|
+
...e
|
|
1549
|
+
},
|
|
1550
|
+
lenBlock: {
|
|
1551
|
+
...t,
|
|
1552
|
+
isIndefiniteForm: !!r.isIndefiniteForm
|
|
1553
|
+
},
|
|
1554
|
+
...r
|
|
1555
|
+
}, jt), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 4;
|
|
1556
|
+
}
|
|
1557
|
+
fromBER(e, t, r) {
|
|
1558
|
+
if (this.valueBlock.isConstructed = this.idBlock.isConstructed, this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm, r === 0)
|
|
1559
|
+
return this.idBlock.error.length === 0 && (this.blockLength += this.idBlock.blockLength), this.lenBlock.error.length === 0 && (this.blockLength += this.lenBlock.blockLength), t;
|
|
1560
|
+
if (!this.valueBlock.isConstructed) {
|
|
1561
|
+
const i = (e instanceof ArrayBuffer ? new Uint8Array(e) : e).subarray(t, t + r);
|
|
1562
|
+
try {
|
|
1563
|
+
if (i.byteLength) {
|
|
1564
|
+
const o = we(i, 0, i.byteLength);
|
|
1565
|
+
o.offset !== -1 && o.offset === r && (this.valueBlock.value = [o.result]);
|
|
1566
|
+
}
|
|
1567
|
+
} catch {
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return super.fromBER(e, t, r);
|
|
1571
|
+
}
|
|
1572
|
+
onAsciiEncoding() {
|
|
1573
|
+
if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length)
|
|
1574
|
+
return Q.prototype.onAsciiEncoding.call(this);
|
|
1575
|
+
const e = this.constructor.NAME, t = v.ToHex(this.valueBlock.valueHexView);
|
|
1576
|
+
return `${e} : ${t}`;
|
|
1577
|
+
}
|
|
1578
|
+
getValue() {
|
|
1579
|
+
if (!this.idBlock.isConstructed)
|
|
1580
|
+
return this.valueBlock.valueHexView.slice().buffer;
|
|
1581
|
+
const e = [];
|
|
1582
|
+
for (const t of this.valueBlock.value)
|
|
1583
|
+
t instanceof Re && e.push(t.valueBlock.valueHexView);
|
|
1584
|
+
return w.concat(e);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
Re = qt;
|
|
1588
|
+
d.OctetString = Re;
|
|
1589
|
+
qt.NAME = Et;
|
|
1590
|
+
class Gt extends L(O) {
|
|
1591
|
+
constructor({ unusedBits: e = 0, isConstructed: t = !1, ...r } = {}) {
|
|
1592
|
+
super(r), this.unusedBits = e, this.isConstructed = t, this.blockLength = this.valueHexView.byteLength;
|
|
1593
|
+
}
|
|
1594
|
+
fromBER(e, t, r) {
|
|
1595
|
+
if (!r)
|
|
1596
|
+
return t;
|
|
1597
|
+
let s = -1;
|
|
1598
|
+
if (this.isConstructed) {
|
|
1599
|
+
if (s = O.prototype.fromBER.call(this, e, t, r), s === -1)
|
|
1600
|
+
return s;
|
|
1601
|
+
for (const c of this.value) {
|
|
1602
|
+
const a = c.constructor.NAME;
|
|
1603
|
+
if (a === ae) {
|
|
1604
|
+
if (this.isIndefiniteForm)
|
|
1605
|
+
break;
|
|
1606
|
+
return this.error = "EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only", -1;
|
|
1607
|
+
}
|
|
1608
|
+
if (a !== pt)
|
|
1609
|
+
return this.error = "BIT STRING may consists of BIT STRINGs only", -1;
|
|
1610
|
+
const u = c.valueBlock;
|
|
1611
|
+
if (this.unusedBits > 0 && u.unusedBits > 0)
|
|
1612
|
+
return this.error = 'Using of "unused bits" inside constructive BIT STRING allowed for least one only', -1;
|
|
1613
|
+
this.unusedBits = u.unusedBits;
|
|
1614
|
+
}
|
|
1615
|
+
return s;
|
|
1616
|
+
}
|
|
1617
|
+
const i = w.toUint8Array(e);
|
|
1618
|
+
if (!H(this, i, t, r))
|
|
1619
|
+
return -1;
|
|
1620
|
+
const o = i.subarray(t, t + r);
|
|
1621
|
+
if (this.unusedBits = o[0], this.unusedBits > 7)
|
|
1622
|
+
return this.error = "Unused bits for BitString must be in range 0-7", -1;
|
|
1623
|
+
if (!this.unusedBits) {
|
|
1624
|
+
const c = o.subarray(1);
|
|
1625
|
+
try {
|
|
1626
|
+
if (c.byteLength) {
|
|
1627
|
+
const a = we(c, 0, c.byteLength);
|
|
1628
|
+
a.offset !== -1 && a.offset === r - 1 && (this.value = [a.result]);
|
|
1629
|
+
}
|
|
1630
|
+
} catch {
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
return this.valueHexView = o.subarray(1), this.blockLength = o.length, t + r;
|
|
1634
|
+
}
|
|
1635
|
+
toBER(e, t) {
|
|
1636
|
+
if (this.isConstructed)
|
|
1637
|
+
return O.prototype.toBER.call(this, e, t);
|
|
1638
|
+
if (e)
|
|
1639
|
+
return new ArrayBuffer(this.valueHexView.byteLength + 1);
|
|
1640
|
+
if (!this.valueHexView.byteLength) {
|
|
1641
|
+
const s = new Uint8Array(1);
|
|
1642
|
+
return s[0] = 0, s.buffer;
|
|
1643
|
+
}
|
|
1644
|
+
const r = new Uint8Array(this.valueHexView.length + 1);
|
|
1645
|
+
return r[0] = this.unusedBits, r.set(this.valueHexView, 1), r.buffer;
|
|
1646
|
+
}
|
|
1647
|
+
toJSON() {
|
|
1648
|
+
return {
|
|
1649
|
+
...super.toJSON(),
|
|
1650
|
+
unusedBits: this.unusedBits,
|
|
1651
|
+
isConstructed: this.isConstructed
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
Gt.NAME = "BitStringValueBlock";
|
|
1656
|
+
var Jt;
|
|
1657
|
+
class Me extends A {
|
|
1658
|
+
constructor({ idBlock: e = {}, lenBlock: t = {}, ...r } = {}) {
|
|
1659
|
+
var s, i;
|
|
1660
|
+
(s = r.isConstructed) !== null && s !== void 0 || (r.isConstructed = !!(!((i = r.value) === null || i === void 0) && i.length)), super({
|
|
1661
|
+
idBlock: {
|
|
1662
|
+
isConstructed: r.isConstructed,
|
|
1663
|
+
...e
|
|
1664
|
+
},
|
|
1665
|
+
lenBlock: {
|
|
1666
|
+
...t,
|
|
1667
|
+
isIndefiniteForm: !!r.isIndefiniteForm
|
|
1668
|
+
},
|
|
1669
|
+
...r
|
|
1670
|
+
}, Gt), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 3;
|
|
1671
|
+
}
|
|
1672
|
+
fromBER(e, t, r) {
|
|
1673
|
+
return this.valueBlock.isConstructed = this.idBlock.isConstructed, this.valueBlock.isIndefiniteForm = this.lenBlock.isIndefiniteForm, super.fromBER(e, t, r);
|
|
1674
|
+
}
|
|
1675
|
+
onAsciiEncoding() {
|
|
1676
|
+
if (this.valueBlock.isConstructed || this.valueBlock.value && this.valueBlock.value.length)
|
|
1677
|
+
return Q.prototype.onAsciiEncoding.call(this);
|
|
1678
|
+
{
|
|
1679
|
+
const e = [], t = this.valueBlock.valueHexView;
|
|
1680
|
+
for (const o of t)
|
|
1681
|
+
e.push(o.toString(2).padStart(8, "0"));
|
|
1682
|
+
const r = e.join(""), s = this.constructor.NAME, i = r.substring(0, r.length - this.valueBlock.unusedBits);
|
|
1683
|
+
return `${s} : ${i}`;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
Jt = Me;
|
|
1688
|
+
d.BitString = Jt;
|
|
1689
|
+
Me.NAME = pt;
|
|
1690
|
+
var Kt;
|
|
1691
|
+
function Is(n, e) {
|
|
1692
|
+
const t = new Uint8Array([0]), r = new Uint8Array(n), s = new Uint8Array(e);
|
|
1693
|
+
let i = r.slice(0);
|
|
1694
|
+
const o = i.length - 1, c = s.slice(0), a = c.length - 1;
|
|
1695
|
+
let u = 0;
|
|
1696
|
+
const f = a < o ? o : a;
|
|
1697
|
+
let h = 0;
|
|
1698
|
+
for (let l = f; l >= 0; l--, h++) {
|
|
1699
|
+
switch (!0) {
|
|
1700
|
+
case h < c.length:
|
|
1701
|
+
u = i[o - h] + c[a - h] + t[0];
|
|
1702
|
+
break;
|
|
1703
|
+
default:
|
|
1704
|
+
u = i[o - h] + t[0];
|
|
1705
|
+
}
|
|
1706
|
+
switch (t[0] = u / 10, !0) {
|
|
1707
|
+
case h >= i.length:
|
|
1708
|
+
i = Ne(new Uint8Array([u % 10]), i);
|
|
1709
|
+
break;
|
|
1710
|
+
default:
|
|
1711
|
+
i[o - h] = u % 10;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return t[0] > 0 && (i = Ne(t, i)), i;
|
|
1715
|
+
}
|
|
1716
|
+
function it(n) {
|
|
1717
|
+
if (n >= se.length)
|
|
1718
|
+
for (let e = se.length; e <= n; e++) {
|
|
1719
|
+
const t = new Uint8Array([0]);
|
|
1720
|
+
let r = se[e - 1].slice(0);
|
|
1721
|
+
for (let s = r.length - 1; s >= 0; s--) {
|
|
1722
|
+
const i = new Uint8Array([(r[s] << 1) + t[0]]);
|
|
1723
|
+
t[0] = i[0] / 10, r[s] = i[0] % 10;
|
|
1724
|
+
}
|
|
1725
|
+
t[0] > 0 && (r = Ne(t, r)), se.push(r);
|
|
1726
|
+
}
|
|
1727
|
+
return se[n];
|
|
1728
|
+
}
|
|
1729
|
+
function Us(n, e) {
|
|
1730
|
+
let t = 0;
|
|
1731
|
+
const r = new Uint8Array(n), s = new Uint8Array(e), i = r.slice(0), o = i.length - 1, c = s.slice(0), a = c.length - 1;
|
|
1732
|
+
let u, f = 0;
|
|
1733
|
+
for (let h = a; h >= 0; h--, f++)
|
|
1734
|
+
switch (u = i[o - f] - c[a - f] - t, !0) {
|
|
1735
|
+
case u < 0:
|
|
1736
|
+
t = 1, i[o - f] = u + 10;
|
|
1737
|
+
break;
|
|
1738
|
+
default:
|
|
1739
|
+
t = 0, i[o - f] = u;
|
|
1740
|
+
}
|
|
1741
|
+
if (t > 0)
|
|
1742
|
+
for (let h = o - a + 1; h >= 0; h--, f++)
|
|
1743
|
+
if (u = i[o - f] - t, u < 0)
|
|
1744
|
+
t = 1, i[o - f] = u + 10;
|
|
1745
|
+
else {
|
|
1746
|
+
t = 0, i[o - f] = u;
|
|
1747
|
+
break;
|
|
1748
|
+
}
|
|
1749
|
+
return i.slice();
|
|
1750
|
+
}
|
|
1751
|
+
class Oe extends L(S) {
|
|
1752
|
+
setValueHex() {
|
|
1753
|
+
this.valueHexView.length >= 4 ? (this.warnings.push("Too big Integer for decoding, hex only"), this.isHexOnly = !0, this._valueDec = 0) : (this.isHexOnly = !1, this.valueHexView.length > 0 && (this._valueDec = St.call(this)));
|
|
1754
|
+
}
|
|
1755
|
+
constructor({ value: e, ...t } = {}) {
|
|
1756
|
+
super(t), this._valueDec = 0, t.valueHex && this.setValueHex(), e !== void 0 && (this.valueDec = e);
|
|
1757
|
+
}
|
|
1758
|
+
set valueDec(e) {
|
|
1759
|
+
this._valueDec = e, this.isHexOnly = !1, this.valueHexView = new Uint8Array(xs(e));
|
|
1760
|
+
}
|
|
1761
|
+
get valueDec() {
|
|
1762
|
+
return this._valueDec;
|
|
1763
|
+
}
|
|
1764
|
+
fromDER(e, t, r, s = 0) {
|
|
1765
|
+
const i = this.fromBER(e, t, r);
|
|
1766
|
+
if (i === -1)
|
|
1767
|
+
return i;
|
|
1768
|
+
const o = this.valueHexView;
|
|
1769
|
+
return o[0] === 0 && o[1] & 128 ? this.valueHexView = o.subarray(1) : s !== 0 && o.length < s && (s - o.length > 1 && (s = o.length + 1), this.valueHexView = o.subarray(s - o.length)), i;
|
|
1770
|
+
}
|
|
1771
|
+
toDER(e = !1) {
|
|
1772
|
+
const t = this.valueHexView;
|
|
1773
|
+
switch (!0) {
|
|
1774
|
+
case (t[0] & 128) !== 0:
|
|
1775
|
+
{
|
|
1776
|
+
const r = new Uint8Array(this.valueHexView.length + 1);
|
|
1777
|
+
r[0] = 0, r.set(t, 1), this.valueHexView = r;
|
|
1778
|
+
}
|
|
1779
|
+
break;
|
|
1780
|
+
case (t[0] === 0 && (t[1] & 128) === 0):
|
|
1781
|
+
this.valueHexView = this.valueHexView.subarray(1);
|
|
1782
|
+
break;
|
|
1783
|
+
}
|
|
1784
|
+
return this.toBER(e);
|
|
1785
|
+
}
|
|
1786
|
+
fromBER(e, t, r) {
|
|
1787
|
+
const s = super.fromBER(e, t, r);
|
|
1788
|
+
return s === -1 || this.setValueHex(), s;
|
|
1789
|
+
}
|
|
1790
|
+
toBER(e) {
|
|
1791
|
+
return e ? new ArrayBuffer(this.valueHexView.length) : this.valueHexView.slice().buffer;
|
|
1792
|
+
}
|
|
1793
|
+
toJSON() {
|
|
1794
|
+
return {
|
|
1795
|
+
...super.toJSON(),
|
|
1796
|
+
valueDec: this.valueDec
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
toString() {
|
|
1800
|
+
const e = this.valueHexView.length * 8 - 1;
|
|
1801
|
+
let t = new Uint8Array(this.valueHexView.length * 8 / 3), r = 0, s;
|
|
1802
|
+
const i = this.valueHexView;
|
|
1803
|
+
let o = "", c = !1;
|
|
1804
|
+
for (let a = i.byteLength - 1; a >= 0; a--) {
|
|
1805
|
+
s = i[a];
|
|
1806
|
+
for (let u = 0; u < 8; u++) {
|
|
1807
|
+
if ((s & 1) === 1)
|
|
1808
|
+
switch (r) {
|
|
1809
|
+
case e:
|
|
1810
|
+
t = Us(it(r), t), o = "-";
|
|
1811
|
+
break;
|
|
1812
|
+
default:
|
|
1813
|
+
t = Is(t, it(r));
|
|
1814
|
+
}
|
|
1815
|
+
r++, s >>= 1;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
for (let a = 0; a < t.length; a++)
|
|
1819
|
+
t[a] && (c = !0), c && (o += nt.charAt(t[a]));
|
|
1820
|
+
return c === !1 && (o += nt.charAt(0)), o;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
Kt = Oe;
|
|
1824
|
+
Oe.NAME = "IntegerValueBlock";
|
|
1825
|
+
Object.defineProperty(Kt.prototype, "valueHex", {
|
|
1826
|
+
set: function(n) {
|
|
1827
|
+
this.valueHexView = new Uint8Array(n), this.setValueHex();
|
|
1828
|
+
},
|
|
1829
|
+
get: function() {
|
|
1830
|
+
return this.valueHexView.slice().buffer;
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
var oe;
|
|
1834
|
+
class De extends A {
|
|
1835
|
+
constructor(e = {}) {
|
|
1836
|
+
super(e, Oe), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 2;
|
|
1837
|
+
}
|
|
1838
|
+
toBigInt() {
|
|
1839
|
+
return de(), BigInt(this.valueBlock.toString());
|
|
1840
|
+
}
|
|
1841
|
+
static fromBigInt(e) {
|
|
1842
|
+
de();
|
|
1843
|
+
const t = BigInt(e), r = new He(), s = t.toString(16).replace(/^-/, ""), i = new Uint8Array(v.FromHex(s));
|
|
1844
|
+
if (t < 0) {
|
|
1845
|
+
const c = new Uint8Array(i.length + (i[0] & 128 ? 1 : 0));
|
|
1846
|
+
c[0] |= 128;
|
|
1847
|
+
const u = BigInt(`0x${v.ToHex(c)}`) + t, f = w.toUint8Array(v.FromHex(u.toString(16)));
|
|
1848
|
+
f[0] |= 128, r.write(f);
|
|
1849
|
+
} else
|
|
1850
|
+
i[0] & 128 && r.write(new Uint8Array([0])), r.write(i);
|
|
1851
|
+
return new oe({ valueHex: r.final() });
|
|
1852
|
+
}
|
|
1853
|
+
convertToDER() {
|
|
1854
|
+
const e = new oe({ valueHex: this.valueBlock.valueHexView });
|
|
1855
|
+
return e.valueBlock.toDER(), e;
|
|
1856
|
+
}
|
|
1857
|
+
convertFromDER() {
|
|
1858
|
+
return new oe({
|
|
1859
|
+
valueHex: this.valueBlock.valueHexView[0] === 0 ? this.valueBlock.valueHexView.subarray(1) : this.valueBlock.valueHexView
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
onAsciiEncoding() {
|
|
1863
|
+
return `${this.constructor.NAME} : ${this.valueBlock.toString()}`;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
oe = De;
|
|
1867
|
+
d.Integer = oe;
|
|
1868
|
+
De.NAME = "INTEGER";
|
|
1869
|
+
var Wt;
|
|
1870
|
+
class Zt extends De {
|
|
1871
|
+
constructor(e = {}) {
|
|
1872
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 10;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
Wt = Zt;
|
|
1876
|
+
d.Enumerated = Wt;
|
|
1877
|
+
Zt.NAME = "ENUMERATED";
|
|
1878
|
+
class Ie extends L(S) {
|
|
1879
|
+
constructor({ valueDec: e = -1, isFirstSid: t = !1, ...r } = {}) {
|
|
1880
|
+
super(r), this.valueDec = e, this.isFirstSid = t;
|
|
1881
|
+
}
|
|
1882
|
+
fromBER(e, t, r) {
|
|
1883
|
+
if (!r)
|
|
1884
|
+
return t;
|
|
1885
|
+
const s = w.toUint8Array(e);
|
|
1886
|
+
if (!H(this, s, t, r))
|
|
1887
|
+
return -1;
|
|
1888
|
+
const i = s.subarray(t, t + r);
|
|
1889
|
+
this.valueHexView = new Uint8Array(r);
|
|
1890
|
+
for (let c = 0; c < r && (this.valueHexView[c] = i[c] & 127, this.blockLength++, !!(i[c] & 128)); c++)
|
|
1891
|
+
;
|
|
1892
|
+
const o = new Uint8Array(this.blockLength);
|
|
1893
|
+
for (let c = 0; c < this.blockLength; c++)
|
|
1894
|
+
o[c] = this.valueHexView[c];
|
|
1895
|
+
return this.valueHexView = o, i[this.blockLength - 1] & 128 ? (this.error = "End of input reached before message was fully decoded", -1) : (this.valueHexView[0] === 0 && this.warnings.push("Needlessly long format of SID encoding"), this.blockLength <= 8 ? this.valueDec = X(this.valueHexView, 7) : (this.isHexOnly = !0, this.warnings.push("Too big SID for decoding, hex only")), t + this.blockLength);
|
|
1896
|
+
}
|
|
1897
|
+
set valueBigInt(e) {
|
|
1898
|
+
de();
|
|
1899
|
+
let t = BigInt(e).toString(2);
|
|
1900
|
+
for (; t.length % 7; )
|
|
1901
|
+
t = "0" + t;
|
|
1902
|
+
const r = new Uint8Array(t.length / 7);
|
|
1903
|
+
for (let s = 0; s < r.length; s++)
|
|
1904
|
+
r[s] = parseInt(t.slice(s * 7, s * 7 + 7), 2) + (s + 1 < r.length ? 128 : 0);
|
|
1905
|
+
this.fromBER(r.buffer, 0, r.length);
|
|
1906
|
+
}
|
|
1907
|
+
toBER(e) {
|
|
1908
|
+
if (this.isHexOnly) {
|
|
1909
|
+
if (e)
|
|
1910
|
+
return new ArrayBuffer(this.valueHexView.byteLength);
|
|
1911
|
+
const s = this.valueHexView, i = new Uint8Array(this.blockLength);
|
|
1912
|
+
for (let o = 0; o < this.blockLength - 1; o++)
|
|
1913
|
+
i[o] = s[o] | 128;
|
|
1914
|
+
return i[this.blockLength - 1] = s[this.blockLength - 1], i.buffer;
|
|
1915
|
+
}
|
|
1916
|
+
const t = j(this.valueDec, 7);
|
|
1917
|
+
if (t.byteLength === 0)
|
|
1918
|
+
return this.error = "Error during encoding SID value", T;
|
|
1919
|
+
const r = new Uint8Array(t.byteLength);
|
|
1920
|
+
if (!e) {
|
|
1921
|
+
const s = new Uint8Array(t), i = t.byteLength - 1;
|
|
1922
|
+
for (let o = 0; o < i; o++)
|
|
1923
|
+
r[o] = s[o] | 128;
|
|
1924
|
+
r[i] = s[i];
|
|
1925
|
+
}
|
|
1926
|
+
return r;
|
|
1927
|
+
}
|
|
1928
|
+
toString() {
|
|
1929
|
+
let e = "";
|
|
1930
|
+
if (this.isHexOnly)
|
|
1931
|
+
e = v.ToHex(this.valueHexView);
|
|
1932
|
+
else if (this.isFirstSid) {
|
|
1933
|
+
let t = this.valueDec;
|
|
1934
|
+
this.valueDec <= 39 ? e = "0." : this.valueDec <= 79 ? (e = "1.", t -= 40) : (e = "2.", t -= 80), e += t.toString();
|
|
1935
|
+
} else
|
|
1936
|
+
e = this.valueDec.toString();
|
|
1937
|
+
return e;
|
|
1938
|
+
}
|
|
1939
|
+
toJSON() {
|
|
1940
|
+
return {
|
|
1941
|
+
...super.toJSON(),
|
|
1942
|
+
valueDec: this.valueDec,
|
|
1943
|
+
isFirstSid: this.isFirstSid
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
Ie.NAME = "sidBlock";
|
|
1948
|
+
class zt extends S {
|
|
1949
|
+
constructor({ value: e = Y, ...t } = {}) {
|
|
1950
|
+
super(t), this.value = [], e && this.fromString(e);
|
|
1951
|
+
}
|
|
1952
|
+
fromBER(e, t, r) {
|
|
1953
|
+
let s = t;
|
|
1954
|
+
for (; r > 0; ) {
|
|
1955
|
+
const i = new Ie();
|
|
1956
|
+
if (s = i.fromBER(e, s, r), s === -1)
|
|
1957
|
+
return this.blockLength = 0, this.error = i.error, s;
|
|
1958
|
+
this.value.length === 0 && (i.isFirstSid = !0), this.blockLength += i.blockLength, r -= i.blockLength, this.value.push(i);
|
|
1959
|
+
}
|
|
1960
|
+
return s;
|
|
1961
|
+
}
|
|
1962
|
+
toBER(e) {
|
|
1963
|
+
const t = [];
|
|
1964
|
+
for (let r = 0; r < this.value.length; r++) {
|
|
1965
|
+
const s = this.value[r].toBER(e);
|
|
1966
|
+
if (s.byteLength === 0)
|
|
1967
|
+
return this.error = this.value[r].error, T;
|
|
1968
|
+
t.push(s);
|
|
1969
|
+
}
|
|
1970
|
+
return _e(t);
|
|
1971
|
+
}
|
|
1972
|
+
fromString(e) {
|
|
1973
|
+
this.value = [];
|
|
1974
|
+
let t = 0, r = 0, s = "", i = !1;
|
|
1975
|
+
do
|
|
1976
|
+
if (r = e.indexOf(".", t), r === -1 ? s = e.substring(t) : s = e.substring(t, r), t = r + 1, i) {
|
|
1977
|
+
const o = this.value[0];
|
|
1978
|
+
let c = 0;
|
|
1979
|
+
switch (o.valueDec) {
|
|
1980
|
+
case 0:
|
|
1981
|
+
break;
|
|
1982
|
+
case 1:
|
|
1983
|
+
c = 40;
|
|
1984
|
+
break;
|
|
1985
|
+
case 2:
|
|
1986
|
+
c = 80;
|
|
1987
|
+
break;
|
|
1988
|
+
default:
|
|
1989
|
+
this.value = [];
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
const a = parseInt(s, 10);
|
|
1993
|
+
if (isNaN(a))
|
|
1994
|
+
return;
|
|
1995
|
+
o.valueDec = a + c, i = !1;
|
|
1996
|
+
} else {
|
|
1997
|
+
const o = new Ie();
|
|
1998
|
+
if (s > Number.MAX_SAFE_INTEGER) {
|
|
1999
|
+
de();
|
|
2000
|
+
const c = BigInt(s);
|
|
2001
|
+
o.valueBigInt = c;
|
|
2002
|
+
} else if (o.valueDec = parseInt(s, 10), isNaN(o.valueDec))
|
|
2003
|
+
return;
|
|
2004
|
+
this.value.length || (o.isFirstSid = !0, i = !0), this.value.push(o);
|
|
2005
|
+
}
|
|
2006
|
+
while (r !== -1);
|
|
2007
|
+
}
|
|
2008
|
+
toString() {
|
|
2009
|
+
let e = "", t = !1;
|
|
2010
|
+
for (let r = 0; r < this.value.length; r++) {
|
|
2011
|
+
t = this.value[r].isHexOnly;
|
|
2012
|
+
let s = this.value[r].toString();
|
|
2013
|
+
r !== 0 && (e = `${e}.`), t ? (s = `{${s}}`, this.value[r].isFirstSid ? e = `2.{${s} - 80}` : e += s) : e += s;
|
|
2014
|
+
}
|
|
2015
|
+
return e;
|
|
2016
|
+
}
|
|
2017
|
+
toJSON() {
|
|
2018
|
+
const e = {
|
|
2019
|
+
...super.toJSON(),
|
|
2020
|
+
value: this.toString(),
|
|
2021
|
+
sidArray: []
|
|
2022
|
+
};
|
|
2023
|
+
for (let t = 0; t < this.value.length; t++)
|
|
2024
|
+
e.sidArray.push(this.value[t].toJSON());
|
|
2025
|
+
return e;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
zt.NAME = "ObjectIdentifierValueBlock";
|
|
2029
|
+
var Xt;
|
|
2030
|
+
class $e extends A {
|
|
2031
|
+
getValue() {
|
|
2032
|
+
return this.valueBlock.toString();
|
|
2033
|
+
}
|
|
2034
|
+
setValue(e) {
|
|
2035
|
+
this.valueBlock.fromString(e);
|
|
2036
|
+
}
|
|
2037
|
+
constructor(e = {}) {
|
|
2038
|
+
super(e, zt), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 6;
|
|
2039
|
+
}
|
|
2040
|
+
onAsciiEncoding() {
|
|
2041
|
+
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
|
2042
|
+
}
|
|
2043
|
+
toJSON() {
|
|
2044
|
+
return {
|
|
2045
|
+
...super.toJSON(),
|
|
2046
|
+
value: this.getValue()
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
Xt = $e;
|
|
2051
|
+
d.ObjectIdentifier = Xt;
|
|
2052
|
+
$e.NAME = "OBJECT IDENTIFIER";
|
|
2053
|
+
class Ue extends L(q) {
|
|
2054
|
+
constructor({ valueDec: e = 0, ...t } = {}) {
|
|
2055
|
+
super(t), this.valueDec = e;
|
|
2056
|
+
}
|
|
2057
|
+
fromBER(e, t, r) {
|
|
2058
|
+
if (r === 0)
|
|
2059
|
+
return t;
|
|
2060
|
+
const s = w.toUint8Array(e);
|
|
2061
|
+
if (!H(this, s, t, r))
|
|
2062
|
+
return -1;
|
|
2063
|
+
const i = s.subarray(t, t + r);
|
|
2064
|
+
this.valueHexView = new Uint8Array(r);
|
|
2065
|
+
for (let c = 0; c < r && (this.valueHexView[c] = i[c] & 127, this.blockLength++, !!(i[c] & 128)); c++)
|
|
2066
|
+
;
|
|
2067
|
+
const o = new Uint8Array(this.blockLength);
|
|
2068
|
+
for (let c = 0; c < this.blockLength; c++)
|
|
2069
|
+
o[c] = this.valueHexView[c];
|
|
2070
|
+
return this.valueHexView = o, i[this.blockLength - 1] & 128 ? (this.error = "End of input reached before message was fully decoded", -1) : (this.valueHexView[0] === 0 && this.warnings.push("Needlessly long format of SID encoding"), this.blockLength <= 8 ? this.valueDec = X(this.valueHexView, 7) : (this.isHexOnly = !0, this.warnings.push("Too big SID for decoding, hex only")), t + this.blockLength);
|
|
2071
|
+
}
|
|
2072
|
+
toBER(e) {
|
|
2073
|
+
if (this.isHexOnly) {
|
|
2074
|
+
if (e)
|
|
2075
|
+
return new ArrayBuffer(this.valueHexView.byteLength);
|
|
2076
|
+
const s = this.valueHexView, i = new Uint8Array(this.blockLength);
|
|
2077
|
+
for (let o = 0; o < this.blockLength - 1; o++)
|
|
2078
|
+
i[o] = s[o] | 128;
|
|
2079
|
+
return i[this.blockLength - 1] = s[this.blockLength - 1], i.buffer;
|
|
2080
|
+
}
|
|
2081
|
+
const t = j(this.valueDec, 7);
|
|
2082
|
+
if (t.byteLength === 0)
|
|
2083
|
+
return this.error = "Error during encoding SID value", T;
|
|
2084
|
+
const r = new Uint8Array(t.byteLength);
|
|
2085
|
+
if (!e) {
|
|
2086
|
+
const s = new Uint8Array(t), i = t.byteLength - 1;
|
|
2087
|
+
for (let o = 0; o < i; o++)
|
|
2088
|
+
r[o] = s[o] | 128;
|
|
2089
|
+
r[i] = s[i];
|
|
2090
|
+
}
|
|
2091
|
+
return r.buffer;
|
|
2092
|
+
}
|
|
2093
|
+
toString() {
|
|
2094
|
+
let e = "";
|
|
2095
|
+
return this.isHexOnly ? e = v.ToHex(this.valueHexView) : e = this.valueDec.toString(), e;
|
|
2096
|
+
}
|
|
2097
|
+
toJSON() {
|
|
2098
|
+
return {
|
|
2099
|
+
...super.toJSON(),
|
|
2100
|
+
valueDec: this.valueDec
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
Ue.NAME = "relativeSidBlock";
|
|
2105
|
+
class Yt extends S {
|
|
2106
|
+
constructor({ value: e = Y, ...t } = {}) {
|
|
2107
|
+
super(t), this.value = [], e && this.fromString(e);
|
|
2108
|
+
}
|
|
2109
|
+
fromBER(e, t, r) {
|
|
2110
|
+
let s = t;
|
|
2111
|
+
for (; r > 0; ) {
|
|
2112
|
+
const i = new Ue();
|
|
2113
|
+
if (s = i.fromBER(e, s, r), s === -1)
|
|
2114
|
+
return this.blockLength = 0, this.error = i.error, s;
|
|
2115
|
+
this.blockLength += i.blockLength, r -= i.blockLength, this.value.push(i);
|
|
2116
|
+
}
|
|
2117
|
+
return s;
|
|
2118
|
+
}
|
|
2119
|
+
toBER(e, t) {
|
|
2120
|
+
const r = [];
|
|
2121
|
+
for (let s = 0; s < this.value.length; s++) {
|
|
2122
|
+
const i = this.value[s].toBER(e);
|
|
2123
|
+
if (i.byteLength === 0)
|
|
2124
|
+
return this.error = this.value[s].error, T;
|
|
2125
|
+
r.push(i);
|
|
2126
|
+
}
|
|
2127
|
+
return _e(r);
|
|
2128
|
+
}
|
|
2129
|
+
fromString(e) {
|
|
2130
|
+
this.value = [];
|
|
2131
|
+
let t = 0, r = 0, s = "";
|
|
2132
|
+
do {
|
|
2133
|
+
r = e.indexOf(".", t), r === -1 ? s = e.substring(t) : s = e.substring(t, r), t = r + 1;
|
|
2134
|
+
const i = new Ue();
|
|
2135
|
+
if (i.valueDec = parseInt(s, 10), isNaN(i.valueDec))
|
|
2136
|
+
return !0;
|
|
2137
|
+
this.value.push(i);
|
|
2138
|
+
} while (r !== -1);
|
|
2139
|
+
return !0;
|
|
2140
|
+
}
|
|
2141
|
+
toString() {
|
|
2142
|
+
let e = "", t = !1;
|
|
2143
|
+
for (let r = 0; r < this.value.length; r++) {
|
|
2144
|
+
t = this.value[r].isHexOnly;
|
|
2145
|
+
let s = this.value[r].toString();
|
|
2146
|
+
r !== 0 && (e = `${e}.`), t && (s = `{${s}}`), e += s;
|
|
2147
|
+
}
|
|
2148
|
+
return e;
|
|
2149
|
+
}
|
|
2150
|
+
toJSON() {
|
|
2151
|
+
const e = {
|
|
2152
|
+
...super.toJSON(),
|
|
2153
|
+
value: this.toString(),
|
|
2154
|
+
sidArray: []
|
|
2155
|
+
};
|
|
2156
|
+
for (let t = 0; t < this.value.length; t++)
|
|
2157
|
+
e.sidArray.push(this.value[t].toJSON());
|
|
2158
|
+
return e;
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
Yt.NAME = "RelativeObjectIdentifierValueBlock";
|
|
2162
|
+
var Qt;
|
|
2163
|
+
class er extends A {
|
|
2164
|
+
getValue() {
|
|
2165
|
+
return this.valueBlock.toString();
|
|
2166
|
+
}
|
|
2167
|
+
setValue(e) {
|
|
2168
|
+
this.valueBlock.fromString(e);
|
|
2169
|
+
}
|
|
2170
|
+
constructor(e = {}) {
|
|
2171
|
+
super(e, Yt), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 13;
|
|
2172
|
+
}
|
|
2173
|
+
onAsciiEncoding() {
|
|
2174
|
+
return `${this.constructor.NAME} : ${this.valueBlock.toString() || "empty"}`;
|
|
2175
|
+
}
|
|
2176
|
+
toJSON() {
|
|
2177
|
+
return {
|
|
2178
|
+
...super.toJSON(),
|
|
2179
|
+
value: this.getValue()
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
Qt = er;
|
|
2184
|
+
d.RelativeObjectIdentifier = Qt;
|
|
2185
|
+
er.NAME = "RelativeObjectIdentifier";
|
|
2186
|
+
var tr;
|
|
2187
|
+
class ge extends Q {
|
|
2188
|
+
constructor(e = {}) {
|
|
2189
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 16;
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
tr = ge;
|
|
2193
|
+
d.Sequence = tr;
|
|
2194
|
+
ge.NAME = "SEQUENCE";
|
|
2195
|
+
var rr;
|
|
2196
|
+
class sr extends Q {
|
|
2197
|
+
constructor(e = {}) {
|
|
2198
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 17;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
rr = sr;
|
|
2202
|
+
d.Set = rr;
|
|
2203
|
+
sr.NAME = "SET";
|
|
2204
|
+
class nr extends L(S) {
|
|
2205
|
+
constructor({ ...e } = {}) {
|
|
2206
|
+
super(e), this.isHexOnly = !0, this.value = Y;
|
|
2207
|
+
}
|
|
2208
|
+
toJSON() {
|
|
2209
|
+
return {
|
|
2210
|
+
...super.toJSON(),
|
|
2211
|
+
value: this.value
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
nr.NAME = "StringValueBlock";
|
|
2216
|
+
class ir extends nr {
|
|
2217
|
+
}
|
|
2218
|
+
ir.NAME = "SimpleStringValueBlock";
|
|
2219
|
+
class N extends Vt {
|
|
2220
|
+
constructor({ ...e } = {}) {
|
|
2221
|
+
super(e, ir);
|
|
2222
|
+
}
|
|
2223
|
+
fromBuffer(e) {
|
|
2224
|
+
this.valueBlock.value = String.fromCharCode.apply(null, w.toUint8Array(e));
|
|
2225
|
+
}
|
|
2226
|
+
fromString(e) {
|
|
2227
|
+
const t = e.length, r = this.valueBlock.valueHexView = new Uint8Array(t);
|
|
2228
|
+
for (let s = 0; s < t; s++)
|
|
2229
|
+
r[s] = e.charCodeAt(s);
|
|
2230
|
+
this.valueBlock.value = e;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
N.NAME = "SIMPLE STRING";
|
|
2234
|
+
class or extends N {
|
|
2235
|
+
fromBuffer(e) {
|
|
2236
|
+
this.valueBlock.valueHexView = w.toUint8Array(e);
|
|
2237
|
+
try {
|
|
2238
|
+
this.valueBlock.value = v.ToUtf8String(e);
|
|
2239
|
+
} catch (t) {
|
|
2240
|
+
this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`), this.valueBlock.value = v.ToBinary(e);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
fromString(e) {
|
|
2244
|
+
this.valueBlock.valueHexView = new Uint8Array(v.FromUtf8String(e)), this.valueBlock.value = e;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
or.NAME = "Utf8StringValueBlock";
|
|
2248
|
+
var cr;
|
|
2249
|
+
class G extends or {
|
|
2250
|
+
constructor(e = {}) {
|
|
2251
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 12;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
cr = G;
|
|
2255
|
+
d.Utf8String = cr;
|
|
2256
|
+
G.NAME = "UTF8String";
|
|
2257
|
+
class ar extends N {
|
|
2258
|
+
fromBuffer(e) {
|
|
2259
|
+
this.valueBlock.value = v.ToUtf16String(e), this.valueBlock.valueHexView = w.toUint8Array(e);
|
|
2260
|
+
}
|
|
2261
|
+
fromString(e) {
|
|
2262
|
+
this.valueBlock.value = e, this.valueBlock.valueHexView = new Uint8Array(v.FromUtf16String(e));
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
ar.NAME = "BmpStringValueBlock";
|
|
2266
|
+
var lr;
|
|
2267
|
+
class ur extends ar {
|
|
2268
|
+
constructor({ ...e } = {}) {
|
|
2269
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 30;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
lr = ur;
|
|
2273
|
+
d.BmpString = lr;
|
|
2274
|
+
ur.NAME = "BMPString";
|
|
2275
|
+
class hr extends N {
|
|
2276
|
+
fromBuffer(e) {
|
|
2277
|
+
const t = ArrayBuffer.isView(e) ? e.slice().buffer : e.slice(0), r = new Uint8Array(t);
|
|
2278
|
+
for (let s = 0; s < r.length; s += 4)
|
|
2279
|
+
r[s] = r[s + 3], r[s + 1] = r[s + 2], r[s + 2] = 0, r[s + 3] = 0;
|
|
2280
|
+
this.valueBlock.value = String.fromCharCode.apply(null, new Uint32Array(t));
|
|
2281
|
+
}
|
|
2282
|
+
fromString(e) {
|
|
2283
|
+
const t = e.length, r = this.valueBlock.valueHexView = new Uint8Array(t * 4);
|
|
2284
|
+
for (let s = 0; s < t; s++) {
|
|
2285
|
+
const i = j(e.charCodeAt(s), 8), o = new Uint8Array(i);
|
|
2286
|
+
if (o.length > 4)
|
|
2287
|
+
continue;
|
|
2288
|
+
const c = 4 - o.length;
|
|
2289
|
+
for (let a = o.length - 1; a >= 0; a--)
|
|
2290
|
+
r[s * 4 + a + c] = o[a];
|
|
2291
|
+
}
|
|
2292
|
+
this.valueBlock.value = e;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
hr.NAME = "UniversalStringValueBlock";
|
|
2296
|
+
var fr;
|
|
2297
|
+
class dr extends hr {
|
|
2298
|
+
constructor({ ...e } = {}) {
|
|
2299
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 28;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
fr = dr;
|
|
2303
|
+
d.UniversalString = fr;
|
|
2304
|
+
dr.NAME = "UniversalString";
|
|
2305
|
+
var gr;
|
|
2306
|
+
class wr extends N {
|
|
2307
|
+
constructor(e = {}) {
|
|
2308
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 18;
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
gr = wr;
|
|
2312
|
+
d.NumericString = gr;
|
|
2313
|
+
wr.NAME = "NumericString";
|
|
2314
|
+
var Br;
|
|
2315
|
+
class yr extends N {
|
|
2316
|
+
constructor(e = {}) {
|
|
2317
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 19;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
Br = yr;
|
|
2321
|
+
d.PrintableString = Br;
|
|
2322
|
+
yr.NAME = "PrintableString";
|
|
2323
|
+
var br;
|
|
2324
|
+
class vr extends N {
|
|
2325
|
+
constructor(e = {}) {
|
|
2326
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 20;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
br = vr;
|
|
2330
|
+
d.TeletexString = br;
|
|
2331
|
+
vr.NAME = "TeletexString";
|
|
2332
|
+
var kr;
|
|
2333
|
+
class mr extends N {
|
|
2334
|
+
constructor(e = {}) {
|
|
2335
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 21;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
kr = mr;
|
|
2339
|
+
d.VideotexString = kr;
|
|
2340
|
+
mr.NAME = "VideotexString";
|
|
2341
|
+
var Ar;
|
|
2342
|
+
class xr extends N {
|
|
2343
|
+
constructor(e = {}) {
|
|
2344
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 22;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
Ar = xr;
|
|
2348
|
+
d.IA5String = Ar;
|
|
2349
|
+
xr.NAME = "IA5String";
|
|
2350
|
+
var Sr;
|
|
2351
|
+
class Er extends N {
|
|
2352
|
+
constructor(e = {}) {
|
|
2353
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 25;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
Sr = Er;
|
|
2357
|
+
d.GraphicString = Sr;
|
|
2358
|
+
Er.NAME = "GraphicString";
|
|
2359
|
+
var pr;
|
|
2360
|
+
class Pe extends N {
|
|
2361
|
+
constructor(e = {}) {
|
|
2362
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 26;
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
pr = Pe;
|
|
2366
|
+
d.VisibleString = pr;
|
|
2367
|
+
Pe.NAME = "VisibleString";
|
|
2368
|
+
var Nr;
|
|
2369
|
+
class Ir extends N {
|
|
2370
|
+
constructor(e = {}) {
|
|
2371
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 27;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
Nr = Ir;
|
|
2375
|
+
d.GeneralString = Nr;
|
|
2376
|
+
Ir.NAME = "GeneralString";
|
|
2377
|
+
var Ur;
|
|
2378
|
+
class Vr extends N {
|
|
2379
|
+
constructor(e = {}) {
|
|
2380
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 29;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
Ur = Vr;
|
|
2384
|
+
d.CharacterString = Ur;
|
|
2385
|
+
Vr.NAME = "CharacterString";
|
|
2386
|
+
var Tr;
|
|
2387
|
+
class Fe extends Pe {
|
|
2388
|
+
constructor({ value: e, valueDate: t, ...r } = {}) {
|
|
2389
|
+
if (super(r), this.year = 0, this.month = 0, this.day = 0, this.hour = 0, this.minute = 0, this.second = 0, e) {
|
|
2390
|
+
this.fromString(e), this.valueBlock.valueHexView = new Uint8Array(e.length);
|
|
2391
|
+
for (let s = 0; s < e.length; s++)
|
|
2392
|
+
this.valueBlock.valueHexView[s] = e.charCodeAt(s);
|
|
2393
|
+
}
|
|
2394
|
+
t && (this.fromDate(t), this.valueBlock.valueHexView = new Uint8Array(this.toBuffer())), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 23;
|
|
2395
|
+
}
|
|
2396
|
+
fromBuffer(e) {
|
|
2397
|
+
this.fromString(String.fromCharCode.apply(null, w.toUint8Array(e)));
|
|
2398
|
+
}
|
|
2399
|
+
toBuffer() {
|
|
2400
|
+
const e = this.toString(), t = new ArrayBuffer(e.length), r = new Uint8Array(t);
|
|
2401
|
+
for (let s = 0; s < e.length; s++)
|
|
2402
|
+
r[s] = e.charCodeAt(s);
|
|
2403
|
+
return t;
|
|
2404
|
+
}
|
|
2405
|
+
fromDate(e) {
|
|
2406
|
+
this.year = e.getUTCFullYear(), this.month = e.getUTCMonth() + 1, this.day = e.getUTCDate(), this.hour = e.getUTCHours(), this.minute = e.getUTCMinutes(), this.second = e.getUTCSeconds();
|
|
2407
|
+
}
|
|
2408
|
+
toDate() {
|
|
2409
|
+
return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second));
|
|
2410
|
+
}
|
|
2411
|
+
fromString(e) {
|
|
2412
|
+
const r = /(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);
|
|
2413
|
+
if (r === null) {
|
|
2414
|
+
this.error = "Wrong input string for conversion";
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
const s = parseInt(r[1], 10);
|
|
2418
|
+
s >= 50 ? this.year = 1900 + s : this.year = 2e3 + s, this.month = parseInt(r[2], 10), this.day = parseInt(r[3], 10), this.hour = parseInt(r[4], 10), this.minute = parseInt(r[5], 10), this.second = parseInt(r[6], 10);
|
|
2419
|
+
}
|
|
2420
|
+
toString(e = "iso") {
|
|
2421
|
+
if (e === "iso") {
|
|
2422
|
+
const t = new Array(7);
|
|
2423
|
+
return t[0] = E(this.year < 2e3 ? this.year - 1900 : this.year - 2e3, 2), t[1] = E(this.month, 2), t[2] = E(this.day, 2), t[3] = E(this.hour, 2), t[4] = E(this.minute, 2), t[5] = E(this.second, 2), t[6] = "Z", t.join("");
|
|
2424
|
+
}
|
|
2425
|
+
return super.toString(e);
|
|
2426
|
+
}
|
|
2427
|
+
onAsciiEncoding() {
|
|
2428
|
+
return `${this.constructor.NAME} : ${this.toDate().toISOString()}`;
|
|
2429
|
+
}
|
|
2430
|
+
toJSON() {
|
|
2431
|
+
return {
|
|
2432
|
+
...super.toJSON(),
|
|
2433
|
+
year: this.year,
|
|
2434
|
+
month: this.month,
|
|
2435
|
+
day: this.day,
|
|
2436
|
+
hour: this.hour,
|
|
2437
|
+
minute: this.minute,
|
|
2438
|
+
second: this.second
|
|
2439
|
+
};
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
Tr = Fe;
|
|
2443
|
+
d.UTCTime = Tr;
|
|
2444
|
+
Fe.NAME = "UTCTime";
|
|
2445
|
+
var Cr;
|
|
2446
|
+
class _r extends Fe {
|
|
2447
|
+
constructor(e = {}) {
|
|
2448
|
+
var t;
|
|
2449
|
+
super(e), (t = this.millisecond) !== null && t !== void 0 || (this.millisecond = 0), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 24;
|
|
2450
|
+
}
|
|
2451
|
+
fromDate(e) {
|
|
2452
|
+
super.fromDate(e), this.millisecond = e.getUTCMilliseconds();
|
|
2453
|
+
}
|
|
2454
|
+
toDate() {
|
|
2455
|
+
const e = Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond);
|
|
2456
|
+
return new Date(e);
|
|
2457
|
+
}
|
|
2458
|
+
fromString(e) {
|
|
2459
|
+
let t = !1, r = "", s = "", i = 0, o, c = 0, a = 0;
|
|
2460
|
+
if (e[e.length - 1] === "Z")
|
|
2461
|
+
r = e.substring(0, e.length - 1), t = !0;
|
|
2462
|
+
else {
|
|
2463
|
+
const h = new Number(e[e.length - 1]);
|
|
2464
|
+
if (isNaN(h.valueOf()))
|
|
2465
|
+
throw new Error("Wrong input string for conversion");
|
|
2466
|
+
r = e;
|
|
2467
|
+
}
|
|
2468
|
+
if (t) {
|
|
2469
|
+
if (r.indexOf("+") !== -1)
|
|
2470
|
+
throw new Error("Wrong input string for conversion");
|
|
2471
|
+
if (r.indexOf("-") !== -1)
|
|
2472
|
+
throw new Error("Wrong input string for conversion");
|
|
2473
|
+
} else {
|
|
2474
|
+
let h = 1, l = r.indexOf("+"), g = "";
|
|
2475
|
+
if (l === -1 && (l = r.indexOf("-"), h = -1), l !== -1) {
|
|
2476
|
+
if (g = r.substring(l + 1), r = r.substring(0, l), g.length !== 2 && g.length !== 4)
|
|
2477
|
+
throw new Error("Wrong input string for conversion");
|
|
2478
|
+
let B = parseInt(g.substring(0, 2), 10);
|
|
2479
|
+
if (isNaN(B.valueOf()))
|
|
2480
|
+
throw new Error("Wrong input string for conversion");
|
|
2481
|
+
if (c = h * B, g.length === 4) {
|
|
2482
|
+
if (B = parseInt(g.substring(2, 4), 10), isNaN(B.valueOf()))
|
|
2483
|
+
throw new Error("Wrong input string for conversion");
|
|
2484
|
+
a = h * B;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
let u = r.indexOf(".");
|
|
2489
|
+
if (u === -1 && (u = r.indexOf(",")), u !== -1) {
|
|
2490
|
+
const h = new Number(`0${r.substring(u)}`);
|
|
2491
|
+
if (isNaN(h.valueOf()))
|
|
2492
|
+
throw new Error("Wrong input string for conversion");
|
|
2493
|
+
i = h.valueOf(), s = r.substring(0, u);
|
|
2494
|
+
} else
|
|
2495
|
+
s = r;
|
|
2496
|
+
switch (!0) {
|
|
2497
|
+
case s.length === 8:
|
|
2498
|
+
if (o = /(\d{4})(\d{2})(\d{2})/ig, u !== -1)
|
|
2499
|
+
throw new Error("Wrong input string for conversion");
|
|
2500
|
+
break;
|
|
2501
|
+
case s.length === 10:
|
|
2502
|
+
if (o = /(\d{4})(\d{2})(\d{2})(\d{2})/ig, u !== -1) {
|
|
2503
|
+
let h = 60 * i;
|
|
2504
|
+
this.minute = Math.floor(h), h = 60 * (h - this.minute), this.second = Math.floor(h), h = 1e3 * (h - this.second), this.millisecond = Math.floor(h);
|
|
2505
|
+
}
|
|
2506
|
+
break;
|
|
2507
|
+
case s.length === 12:
|
|
2508
|
+
if (o = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig, u !== -1) {
|
|
2509
|
+
let h = 60 * i;
|
|
2510
|
+
this.second = Math.floor(h), h = 1e3 * (h - this.second), this.millisecond = Math.floor(h);
|
|
2511
|
+
}
|
|
2512
|
+
break;
|
|
2513
|
+
case s.length === 14:
|
|
2514
|
+
if (o = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig, u !== -1) {
|
|
2515
|
+
const h = 1e3 * i;
|
|
2516
|
+
this.millisecond = Math.floor(h);
|
|
2517
|
+
}
|
|
2518
|
+
break;
|
|
2519
|
+
default:
|
|
2520
|
+
throw new Error("Wrong input string for conversion");
|
|
2521
|
+
}
|
|
2522
|
+
const f = o.exec(s);
|
|
2523
|
+
if (f === null)
|
|
2524
|
+
throw new Error("Wrong input string for conversion");
|
|
2525
|
+
for (let h = 1; h < f.length; h++)
|
|
2526
|
+
switch (h) {
|
|
2527
|
+
case 1:
|
|
2528
|
+
this.year = parseInt(f[h], 10);
|
|
2529
|
+
break;
|
|
2530
|
+
case 2:
|
|
2531
|
+
this.month = parseInt(f[h], 10);
|
|
2532
|
+
break;
|
|
2533
|
+
case 3:
|
|
2534
|
+
this.day = parseInt(f[h], 10);
|
|
2535
|
+
break;
|
|
2536
|
+
case 4:
|
|
2537
|
+
this.hour = parseInt(f[h], 10) + c;
|
|
2538
|
+
break;
|
|
2539
|
+
case 5:
|
|
2540
|
+
this.minute = parseInt(f[h], 10) + a;
|
|
2541
|
+
break;
|
|
2542
|
+
case 6:
|
|
2543
|
+
this.second = parseInt(f[h], 10);
|
|
2544
|
+
break;
|
|
2545
|
+
default:
|
|
2546
|
+
throw new Error("Wrong input string for conversion");
|
|
2547
|
+
}
|
|
2548
|
+
if (t === !1) {
|
|
2549
|
+
const h = new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond);
|
|
2550
|
+
this.year = h.getUTCFullYear(), this.month = h.getUTCMonth(), this.day = h.getUTCDay(), this.hour = h.getUTCHours(), this.minute = h.getUTCMinutes(), this.second = h.getUTCSeconds(), this.millisecond = h.getUTCMilliseconds();
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
toString(e = "iso") {
|
|
2554
|
+
if (e === "iso") {
|
|
2555
|
+
const t = [];
|
|
2556
|
+
return t.push(E(this.year, 4)), t.push(E(this.month, 2)), t.push(E(this.day, 2)), t.push(E(this.hour, 2)), t.push(E(this.minute, 2)), t.push(E(this.second, 2)), this.millisecond !== 0 && (t.push("."), t.push(E(this.millisecond, 3))), t.push("Z"), t.join("");
|
|
2557
|
+
}
|
|
2558
|
+
return super.toString(e);
|
|
2559
|
+
}
|
|
2560
|
+
toJSON() {
|
|
2561
|
+
return {
|
|
2562
|
+
...super.toJSON(),
|
|
2563
|
+
millisecond: this.millisecond
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
Cr = _r;
|
|
2568
|
+
d.GeneralizedTime = Cr;
|
|
2569
|
+
_r.NAME = "GeneralizedTime";
|
|
2570
|
+
var Hr;
|
|
2571
|
+
class Lr extends G {
|
|
2572
|
+
constructor(e = {}) {
|
|
2573
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 31;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
Hr = Lr;
|
|
2577
|
+
d.DATE = Hr;
|
|
2578
|
+
Lr.NAME = "DATE";
|
|
2579
|
+
var Rr;
|
|
2580
|
+
class Mr extends G {
|
|
2581
|
+
constructor(e = {}) {
|
|
2582
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 32;
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
Rr = Mr;
|
|
2586
|
+
d.TimeOfDay = Rr;
|
|
2587
|
+
Mr.NAME = "TimeOfDay";
|
|
2588
|
+
var Or;
|
|
2589
|
+
class Dr extends G {
|
|
2590
|
+
constructor(e = {}) {
|
|
2591
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 33;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
Or = Dr;
|
|
2595
|
+
d.DateTime = Or;
|
|
2596
|
+
Dr.NAME = "DateTime";
|
|
2597
|
+
var $r;
|
|
2598
|
+
class Pr extends G {
|
|
2599
|
+
constructor(e = {}) {
|
|
2600
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 34;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
$r = Pr;
|
|
2604
|
+
d.Duration = $r;
|
|
2605
|
+
Pr.NAME = "Duration";
|
|
2606
|
+
var Fr;
|
|
2607
|
+
class jr extends G {
|
|
2608
|
+
constructor(e = {}) {
|
|
2609
|
+
super(e), this.idBlock.tagClass = 1, this.idBlock.tagNumber = 14;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
Fr = jr;
|
|
2613
|
+
d.TIME = Fr;
|
|
2614
|
+
jr.NAME = "TIME";
|
|
2615
|
+
function Vs(n) {
|
|
2616
|
+
const e = n.slice().buffer, t = new ge({
|
|
2617
|
+
value: [new $e({ value: "1.3.101.110" })]
|
|
2618
|
+
// id-X25519
|
|
2619
|
+
}), r = new Me({
|
|
2620
|
+
valueHex: e
|
|
2621
|
+
}), s = new ge({
|
|
2622
|
+
value: [t, r]
|
|
2623
|
+
});
|
|
2624
|
+
return new Uint8Array(s.toBER());
|
|
2625
|
+
}
|
|
2626
|
+
function Ts(n) {
|
|
2627
|
+
const e = n.slice().buffer, s = ps(e).result.valueBlock.value[1];
|
|
2628
|
+
return new Uint8Array(s.valueBlock.valueHex);
|
|
2629
|
+
}
|
|
2630
|
+
function ne(n) {
|
|
2631
|
+
let e = "";
|
|
2632
|
+
for (let t = 0; t < n.length; t++)
|
|
2633
|
+
e += String.fromCharCode(n[t]);
|
|
2634
|
+
return btoa(e);
|
|
2635
|
+
}
|
|
2636
|
+
function ie(n) {
|
|
2637
|
+
const e = n.replace(/\s+/g, ""), t = atob(e), r = new Uint8Array(t.length);
|
|
2638
|
+
for (let s = 0; s < t.length; s++) r[s] = t.charCodeAt(s);
|
|
2639
|
+
return r;
|
|
2640
|
+
}
|
|
2641
|
+
function ot(n) {
|
|
2642
|
+
if (n instanceof ArrayBuffer)
|
|
2643
|
+
return n;
|
|
2644
|
+
const e = n, { buffer: t, byteOffset: r, byteLength: s } = e;
|
|
2645
|
+
if (t instanceof ArrayBuffer)
|
|
2646
|
+
return t.slice(r, r + s);
|
|
2647
|
+
const i = new Uint8Array(s);
|
|
2648
|
+
return i.set(new Uint8Array(t, r, s)), i.buffer;
|
|
2649
|
+
}
|
|
2650
|
+
function ce(n) {
|
|
2651
|
+
return n.buffer;
|
|
2652
|
+
}
|
|
2653
|
+
async function Cs(n, e, t, r) {
|
|
2654
|
+
const s = await crypto.subtle.importKey(
|
|
2655
|
+
"raw",
|
|
2656
|
+
ce(n),
|
|
2657
|
+
"HKDF",
|
|
2658
|
+
!1,
|
|
2659
|
+
["deriveBits"]
|
|
2660
|
+
), i = await crypto.subtle.deriveBits(
|
|
2661
|
+
{
|
|
2662
|
+
name: "HKDF",
|
|
2663
|
+
hash: "SHA-256",
|
|
2664
|
+
salt: ce(e),
|
|
2665
|
+
info: ce(t)
|
|
2666
|
+
},
|
|
2667
|
+
s,
|
|
2668
|
+
r * 8
|
|
2669
|
+
);
|
|
2670
|
+
return new Uint8Array(i);
|
|
2671
|
+
}
|
|
2672
|
+
async function _s(n) {
|
|
2673
|
+
return crypto.subtle.importKey(
|
|
2674
|
+
"raw",
|
|
2675
|
+
ce(n),
|
|
2676
|
+
{
|
|
2677
|
+
name: "HMAC",
|
|
2678
|
+
hash: "SHA-256"
|
|
2679
|
+
},
|
|
2680
|
+
!1,
|
|
2681
|
+
["sign"]
|
|
2682
|
+
);
|
|
2683
|
+
}
|
|
2684
|
+
async function Hs(n, e) {
|
|
2685
|
+
const t = await crypto.subtle.sign(
|
|
2686
|
+
"HMAC",
|
|
2687
|
+
n,
|
|
2688
|
+
ce(e)
|
|
2689
|
+
);
|
|
2690
|
+
return new Uint8Array(t);
|
|
2691
|
+
}
|
|
2692
|
+
function Ls(n) {
|
|
2693
|
+
const e = n.replace(/\r/g, "").match(/-----BEGIN [^-]+-----([\s\S]*?)-----END [^-]+-----/);
|
|
2694
|
+
if (!e) throw new Error("Invalid PEM");
|
|
2695
|
+
const t = e[1].replace(/[\n\r\s]/g, ""), r = atob(t), s = new Uint8Array(r.length);
|
|
2696
|
+
for (let i = 0; i < r.length; i++) s[i] = r.charCodeAt(i);
|
|
2697
|
+
return s.buffer;
|
|
2698
|
+
}
|
|
2699
|
+
async function Rs(n, e, t) {
|
|
2700
|
+
const r = Ls(n), s = await crypto.subtle.importKey(
|
|
2701
|
+
"spki",
|
|
2702
|
+
r,
|
|
2703
|
+
// SPKI "-----BEGIN PUBLIC KEY-----"
|
|
2704
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
2705
|
+
!0,
|
|
2706
|
+
["verify"]
|
|
2707
|
+
);
|
|
2708
|
+
return crypto.subtle.verify(
|
|
2709
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
2710
|
+
s,
|
|
2711
|
+
ot(t),
|
|
2712
|
+
// <= P1363 (64 bytes)
|
|
2713
|
+
ot(e)
|
|
2714
|
+
// <= raw SPKI DER bytes the server says it signed
|
|
2715
|
+
);
|
|
2716
|
+
}
|
|
2717
|
+
class Ms {
|
|
2718
|
+
constructor(e) {
|
|
2719
|
+
this.ws = null, this.listeners = {}, this.subscriptions = { request: {}, status: {}, topic: {} }, this._shouldReconnect = !0, this._reconnectAttempt = 0, this.generateRandomString = (t) => {
|
|
2720
|
+
let r = "";
|
|
2721
|
+
for (; r.length < t; )
|
|
2722
|
+
r += Math.random().toString(36).substring(2, 2 + (t - r.length));
|
|
2723
|
+
return r;
|
|
2724
|
+
}, this.client = e;
|
|
2725
|
+
}
|
|
2726
|
+
scheduleReconnect() {
|
|
2727
|
+
if (!this._shouldReconnect) return;
|
|
2728
|
+
const e = Math.min(3e4, 1e3 * 2 ** this._reconnectAttempt);
|
|
2729
|
+
this._reconnectAttempt++, setTimeout(() => {
|
|
2730
|
+
this._connectPromise = void 0, this.connect().catch(() => {
|
|
2731
|
+
});
|
|
2732
|
+
}, e);
|
|
2733
|
+
}
|
|
2734
|
+
close() {
|
|
2735
|
+
var e;
|
|
2736
|
+
this._shouldReconnect = !1, this._connectPromise = void 0, (e = this.ws) == null || e.close(), this.ws = null;
|
|
2737
|
+
}
|
|
2738
|
+
async connect() {
|
|
2739
|
+
var e;
|
|
2740
|
+
if (await this.client.ensureSession(), !this.client.getAccessToken())
|
|
2741
|
+
throw new Error("Cannot connect to notifications: user is not logged in.");
|
|
2742
|
+
if (!(this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING))) {
|
|
2743
|
+
if (this._connectPromise) return this._connectPromise;
|
|
2744
|
+
this._connectPromise = (async () => {
|
|
2745
|
+
const { url: t } = await this.client.get("/url/notifications");
|
|
2746
|
+
this.ws = new WebSocket(t), this.ws.onopen = () => {
|
|
2747
|
+
this._reconnectAttempt = 0, console.log("Notifications connected");
|
|
2748
|
+
}, this.ws.onmessage = async (r) => {
|
|
2749
|
+
try {
|
|
2750
|
+
const s = JSON.parse(r.data), i = await this.client.decryptAndVerify(s), o = this.subscriptions.request[i == null ? void 0 : i.correlation_id];
|
|
2751
|
+
o && Object.values(o).length > 0 && Object.values(o).forEach((u) => u(i));
|
|
2752
|
+
const c = this.subscriptions.status[i == null ? void 0 : i.status];
|
|
2753
|
+
c && Object.values(c).length > 0 && Object.values(c).forEach((u) => u(i));
|
|
2754
|
+
const a = this.subscriptions.topic[i == null ? void 0 : i.topic];
|
|
2755
|
+
a && Object.values(a).length > 0 && Object.values(a).forEach((u) => u(i)), Object.values(this.listeners).forEach((u) => u(i));
|
|
2756
|
+
} catch (s) {
|
|
2757
|
+
console.warn("Failed to process notification:", s);
|
|
2758
|
+
}
|
|
2759
|
+
}, this.ws.onerror = (r) => {
|
|
2760
|
+
console.error("Notifications error", r);
|
|
2761
|
+
}, this.ws.onclose = () => {
|
|
2762
|
+
this.scheduleReconnect(), console.log("Notifications closed");
|
|
2763
|
+
};
|
|
2764
|
+
})();
|
|
2765
|
+
try {
|
|
2766
|
+
await this._connectPromise;
|
|
2767
|
+
} finally {
|
|
2768
|
+
((e = this.ws) == null ? void 0 : e.readyState) === WebSocket.OPEN ? this._connectPromise = void 0 : (!this.ws || this.ws.readyState === WebSocket.CLOSED) && (this._connectPromise = void 0);
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
unsuscribe(e, t, r) {
|
|
2773
|
+
delete this.subscriptions[e][t][r];
|
|
2774
|
+
}
|
|
2775
|
+
unlisten(e) {
|
|
2776
|
+
delete this.listeners[e];
|
|
2777
|
+
}
|
|
2778
|
+
suscribe(e, t, r, s) {
|
|
2779
|
+
let i = s;
|
|
2780
|
+
return i == null && (i = this.generateRandomString(16)), this.subscriptions[e] || (this.subscriptions[e] = {}), this.subscriptions[e][t] || (this.subscriptions[e][t] = {}), this.subscriptions[e][t][i] = r, () => this.unsuscribe(e, t, i);
|
|
2781
|
+
}
|
|
2782
|
+
onMessage(e, t) {
|
|
2783
|
+
let r = t;
|
|
2784
|
+
return r == null && (r = this.generateRandomString(16)), this.listeners[r] = e, () => this.unlisten(r);
|
|
2785
|
+
}
|
|
2786
|
+
disconnect() {
|
|
2787
|
+
var e;
|
|
2788
|
+
(e = this.ws) == null || e.close(), this.ws = null;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
const ct = "secure_api_session_v1";
|
|
2792
|
+
class Os {
|
|
2793
|
+
constructor(e) {
|
|
2794
|
+
this.session = null, this.baseUrl = e.baseUrl, this.clientId = e.clientId, this.serverPublicKeyPem = e.serverPublicKeyPem, this.clientIdentityKeyPromise = $s(
|
|
2795
|
+
e.clientIdentityPrivateKeyPem
|
|
2796
|
+
), this.loadPersistedSession(), this.notifications = new Ms(this);
|
|
2797
|
+
}
|
|
2798
|
+
loadPersistedSession() {
|
|
2799
|
+
try {
|
|
2800
|
+
const e = localStorage.getItem(ct);
|
|
2801
|
+
if (!e) return;
|
|
2802
|
+
const t = JSON.parse(e);
|
|
2803
|
+
if (!t) return;
|
|
2804
|
+
t.sessionId && t.sessionExpiresAt ? this.session = {
|
|
2805
|
+
sessionId: t.sessionId,
|
|
2806
|
+
sessionExpiresAt: t.sessionExpiresAt,
|
|
2807
|
+
encKey: void 0,
|
|
2808
|
+
macKey: void 0,
|
|
2809
|
+
userId: t.userId,
|
|
2810
|
+
accessToken: t.accessToken,
|
|
2811
|
+
tokenType: t.tokenType,
|
|
2812
|
+
expiresAt: t.expiresAt,
|
|
2813
|
+
refreshToken: t.refreshToken
|
|
2814
|
+
} : this.session = {
|
|
2815
|
+
sessionId: "",
|
|
2816
|
+
sessionExpiresAt: "",
|
|
2817
|
+
encKey: void 0,
|
|
2818
|
+
macKey: void 0,
|
|
2819
|
+
userId: t.userId,
|
|
2820
|
+
accessToken: t.accessToken,
|
|
2821
|
+
tokenType: t.tokenType,
|
|
2822
|
+
expiresAt: t.expiresAt,
|
|
2823
|
+
refreshToken: t.refreshToken
|
|
2824
|
+
};
|
|
2825
|
+
} catch {
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
persistSession() {
|
|
2829
|
+
try {
|
|
2830
|
+
const e = this.session, t = e ? {
|
|
2831
|
+
sessionId: e.sessionId,
|
|
2832
|
+
sessionExpiresAt: e.sessionExpiresAt,
|
|
2833
|
+
userId: e.userId,
|
|
2834
|
+
accessToken: e.accessToken,
|
|
2835
|
+
tokenType: e.tokenType,
|
|
2836
|
+
expiresAt: e.expiresAt,
|
|
2837
|
+
refreshToken: e.refreshToken
|
|
2838
|
+
} : {};
|
|
2839
|
+
localStorage.setItem(ct, JSON.stringify(t));
|
|
2840
|
+
} catch {
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
async handshake() {
|
|
2844
|
+
const e = await this.clientIdentityKeyPromise, t = Se.utils.randomSecretKey(), r = Se.getPublicKey(t), s = Vs(r), i = ne(s), o = await crypto.subtle.sign(
|
|
2845
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
2846
|
+
e,
|
|
2847
|
+
Ps(s)
|
|
2848
|
+
), c = Fs(new Uint8Array(o)), a = ne(c), u = await fetch(`${this.baseUrl}/handshake`, {
|
|
2849
|
+
method: "POST",
|
|
2850
|
+
headers: {
|
|
2851
|
+
"Content-Type": "application/json"
|
|
2852
|
+
},
|
|
2853
|
+
body: JSON.stringify({
|
|
2854
|
+
client_id: this.clientId,
|
|
2855
|
+
user_id: this.getUserId(),
|
|
2856
|
+
client_pub: i,
|
|
2857
|
+
client_sig: a,
|
|
2858
|
+
client_alg: "ES256"
|
|
2859
|
+
})
|
|
2860
|
+
});
|
|
2861
|
+
if (!u.ok)
|
|
2862
|
+
throw new Error(`Handshake failed: ${u.status} ${u.statusText}`);
|
|
2863
|
+
const f = await u.json(), { session_id: h, server_pub: l, server_sig: g, session_expires_at: B } = f;
|
|
2864
|
+
if (window.__akv = { server_pub: l, server_sig: g }, !h || !l || !g)
|
|
2865
|
+
throw new Error("Handshake response missing fields");
|
|
2866
|
+
const m = ie(l), b = ie(g);
|
|
2867
|
+
if (!await Rs(
|
|
2868
|
+
this.serverPublicKeyPem,
|
|
2869
|
+
m,
|
|
2870
|
+
b
|
|
2871
|
+
))
|
|
2872
|
+
throw new Error("Server signature verification failed");
|
|
2873
|
+
const le = Ts(m), Be = Se.getSharedSecret(t, le), ye = new Uint8Array(0), ee = new TextEncoder().encode("health-api-v1"), J = await Cs(Be, ye, ee, 64), K = J.slice(0, 32), be = J.slice(32, 64), ue = await crypto.subtle.importKey(
|
|
2874
|
+
"raw",
|
|
2875
|
+
K,
|
|
2876
|
+
"AES-GCM",
|
|
2877
|
+
!1,
|
|
2878
|
+
["encrypt", "decrypt"]
|
|
2879
|
+
), te = await _s(be);
|
|
2880
|
+
this.updateSession({
|
|
2881
|
+
sessionId: h,
|
|
2882
|
+
encKey: ue,
|
|
2883
|
+
macKey: te,
|
|
2884
|
+
sessionExpiresAt: B
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
getUserId() {
|
|
2888
|
+
var e;
|
|
2889
|
+
return (e = this.session) == null ? void 0 : e.userId;
|
|
2890
|
+
}
|
|
2891
|
+
getAccessToken() {
|
|
2892
|
+
var e;
|
|
2893
|
+
return (e = this.session) == null ? void 0 : e.accessToken;
|
|
2894
|
+
}
|
|
2895
|
+
updateSession(e) {
|
|
2896
|
+
if (!this.session) {
|
|
2897
|
+
this.session = e, this.persistSession();
|
|
2898
|
+
return;
|
|
2899
|
+
}
|
|
2900
|
+
Object.assign(this.session, e), this.persistSession();
|
|
2901
|
+
}
|
|
2902
|
+
getSession() {
|
|
2903
|
+
if (!this.session)
|
|
2904
|
+
throw new Error("No session");
|
|
2905
|
+
return this.session;
|
|
2906
|
+
}
|
|
2907
|
+
async encryptBody(e) {
|
|
2908
|
+
if (!e) return { ciphertextB64: "", ivB64: "" };
|
|
2909
|
+
await this.ensureSession();
|
|
2910
|
+
const { encKey: t } = this.session, r = crypto.getRandomValues(new Uint8Array(12)), s = new TextEncoder().encode(JSON.stringify(e)), i = await crypto.subtle.encrypt(
|
|
2911
|
+
{ name: "AES-GCM", iv: r },
|
|
2912
|
+
t,
|
|
2913
|
+
s
|
|
2914
|
+
);
|
|
2915
|
+
return {
|
|
2916
|
+
ciphertextB64: ne(new Uint8Array(i)),
|
|
2917
|
+
ivB64: ne(r)
|
|
2918
|
+
};
|
|
2919
|
+
}
|
|
2920
|
+
async signRequest(e, t, r) {
|
|
2921
|
+
await this.ensureSession();
|
|
2922
|
+
const { sessionId: s, macKey: i } = this.session, o = e.toUpperCase() === "GET" ? "" : { data: Array.isArray(r) ? r : [r] }, { ciphertextB64: c, ivB64: a } = await this.encryptBody(o), u = Math.floor(Date.now() / 1e3).toString(), f = `${e.toUpperCase()} ${t}
|
|
2923
|
+
${u}
|
|
2924
|
+
${c}`, h = await Hs(i, new TextEncoder().encode(f)), l = ne(h), g = new Headers({
|
|
2925
|
+
"X-Session-Id": s,
|
|
2926
|
+
"X-Client-Id": this.clientId,
|
|
2927
|
+
"X-Timestamp": u,
|
|
2928
|
+
"X-Signature": l,
|
|
2929
|
+
"Content-Type": "application/json"
|
|
2930
|
+
});
|
|
2931
|
+
return this.getUserId() && g.append("X-User-Id", this.getUserId()), this.getAccessToken() && !this.isTokenExpired() && g.append("Authorization", `Bearer ${this.getAccessToken()}`), {
|
|
2932
|
+
headers: g,
|
|
2933
|
+
payload: {
|
|
2934
|
+
content: c,
|
|
2935
|
+
iv: a
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
}
|
|
2939
|
+
async get(e) {
|
|
2940
|
+
const { headers: t } = await this.signRequest("GET", e, null), r = await fetch(`${this.baseUrl}${e}`, {
|
|
2941
|
+
method: "GET",
|
|
2942
|
+
headers: t
|
|
2943
|
+
});
|
|
2944
|
+
if (!r.ok)
|
|
2945
|
+
throw new Error(`GET ${e} failed: ${r.status} ${r.statusText}`);
|
|
2946
|
+
return this.decryptAndVerify(await r.json());
|
|
2947
|
+
}
|
|
2948
|
+
async post(e, t) {
|
|
2949
|
+
const { headers: r, payload: s } = await this.signRequest("POST", e, t), i = await fetch(`${this.baseUrl}${e}`, {
|
|
2950
|
+
method: "POST",
|
|
2951
|
+
headers: r,
|
|
2952
|
+
body: JSON.stringify(s)
|
|
2953
|
+
});
|
|
2954
|
+
if (!i.ok)
|
|
2955
|
+
throw new Error(`POST ${e} failed: ${i.status} ${i.statusText}`);
|
|
2956
|
+
return e.endsWith("/handshake") ? await i.json() : this.decryptAndVerify(await i.json());
|
|
2957
|
+
}
|
|
2958
|
+
async ensureSession() {
|
|
2959
|
+
var t, r, s;
|
|
2960
|
+
(!this.session || !this.session.sessionId || !this.session.sessionExpiresAt || !this.session.encKey || !this.session.macKey) && await this.handshake();
|
|
2961
|
+
const e = new Date(Date.now() + 5 * 60 * 1e3);
|
|
2962
|
+
(t = this.session) != null && t.sessionExpiresAt && new Date((r = this.session) == null ? void 0 : r.sessionExpiresAt) < e && await this.extendHandshake(), (s = this.session) != null && s.userId && this.isTokenExpired() && await this.refresh();
|
|
2963
|
+
}
|
|
2964
|
+
async extendHandshake() {
|
|
2965
|
+
await this.post("/handshake/extend", {}).then(async (e) => {
|
|
2966
|
+
var t;
|
|
2967
|
+
e && (e.session_id !== ((t = this.session) == null ? void 0 : t.sessionId) ? await this.handshake() : this.updateSession({
|
|
2968
|
+
sessionExpiresAt: e.session_expires_at
|
|
2969
|
+
}));
|
|
2970
|
+
}).catch(async (e) => {
|
|
2971
|
+
await this.handshake();
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2974
|
+
async decryptAndVerify(e) {
|
|
2975
|
+
const { ciphertext: t, iv: r, signature: s, ...i } = e;
|
|
2976
|
+
if (!t || !r || !s)
|
|
2977
|
+
throw new Error("Malformed notification");
|
|
2978
|
+
const { encKey: o, macKey: c } = this.getSession(), a = ie(s), u = await crypto.subtle.sign(
|
|
2979
|
+
"HMAC",
|
|
2980
|
+
c,
|
|
2981
|
+
new TextEncoder().encode(t)
|
|
2982
|
+
);
|
|
2983
|
+
if (!this.constantTimeEqual(a, new Uint8Array(u)))
|
|
2984
|
+
throw new Error("Invalid notification signature");
|
|
2985
|
+
const f = Uint8Array.from(ie(r)), h = Uint8Array.from(ie(t)), l = await crypto.subtle.decrypt(
|
|
2986
|
+
{ name: "AES-GCM", iv: f },
|
|
2987
|
+
o,
|
|
2988
|
+
h
|
|
2989
|
+
), g = new TextDecoder().decode(l);
|
|
2990
|
+
return { ...JSON.parse(g), ...i };
|
|
2991
|
+
}
|
|
2992
|
+
constantTimeEqual(e, t) {
|
|
2993
|
+
if (e.length !== t.length) return !1;
|
|
2994
|
+
let r = 0;
|
|
2995
|
+
for (let s = 0; s < e.length; s++) r |= e[s] ^ t[s];
|
|
2996
|
+
return r === 0;
|
|
2997
|
+
}
|
|
2998
|
+
async login(e) {
|
|
2999
|
+
await this.ensureSession();
|
|
3000
|
+
const t = {};
|
|
3001
|
+
"username" in e && "password" in e && (t.username = e.username, t.password = e.password, t.scope = e.scope), "email" in e && "socialLoginId" in e && (t.email = e.email, t.social_login_id = e.socialLoginId, t.scope = e.scope), "jwt" in e && this.updateSession({
|
|
3002
|
+
accessToken: e.jwt,
|
|
3003
|
+
tokenType: "Bearer"
|
|
3004
|
+
}), "refreshToken" in e && (t.refresh_token = e.refreshToken);
|
|
3005
|
+
const r = await this.post("/oauth/authorize", t), {
|
|
3006
|
+
access_token: s,
|
|
3007
|
+
token_type: i,
|
|
3008
|
+
expires_at: o,
|
|
3009
|
+
refresh_token: c
|
|
3010
|
+
} = r;
|
|
3011
|
+
return s && this.updateSession({ accessToken: s }), i && this.updateSession({ tokenType: i }), o && this.updateSession({ expiresAt: o }), c && this.updateSession({ refreshToken: c }), {
|
|
3012
|
+
accessToken: s,
|
|
3013
|
+
tokenType: i,
|
|
3014
|
+
expiresAt: o,
|
|
3015
|
+
refreshToken: c
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
3018
|
+
async refresh() {
|
|
3019
|
+
const e = this.getSession();
|
|
3020
|
+
if (!(e != null && e.refreshToken))
|
|
3021
|
+
throw new Error("No refresh token available");
|
|
3022
|
+
if (e && e.refreshToken)
|
|
3023
|
+
return this.login({
|
|
3024
|
+
refreshToken: e.refreshToken
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
isTokenExpired() {
|
|
3028
|
+
const e = this.getSession();
|
|
3029
|
+
if (!(e != null && e.expiresAt)) return !0;
|
|
3030
|
+
if (e && e.expiresAt)
|
|
3031
|
+
return Math.floor(Date.now() / 1e3) >= e.expiresAt;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
function Ds(n) {
|
|
3035
|
+
const e = n.replace(/-----BEGIN PRIVATE KEY-----/, "").replace(/-----END PRIVATE KEY-----/, "").replace(/\s+/g, ""), t = atob(e), r = new Uint8Array(t.length);
|
|
3036
|
+
for (let s = 0; s < t.length; s++)
|
|
3037
|
+
r[s] = t.charCodeAt(s);
|
|
3038
|
+
return r.buffer;
|
|
3039
|
+
}
|
|
3040
|
+
async function $s(n) {
|
|
3041
|
+
const e = Ds(n);
|
|
3042
|
+
return crypto.subtle.importKey(
|
|
3043
|
+
"pkcs8",
|
|
3044
|
+
e,
|
|
3045
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
3046
|
+
!1,
|
|
3047
|
+
["sign"]
|
|
3048
|
+
);
|
|
3049
|
+
}
|
|
3050
|
+
function Ps(n) {
|
|
3051
|
+
return Uint8Array.from(n).buffer;
|
|
3052
|
+
}
|
|
3053
|
+
function Fs(n) {
|
|
3054
|
+
const e = n.slice(0, 32), t = n.slice(32, 64);
|
|
3055
|
+
function r(f) {
|
|
3056
|
+
let h = 0;
|
|
3057
|
+
for (; h < f.length - 1 && f[h] === 0; ) h++;
|
|
3058
|
+
return f.slice(h);
|
|
3059
|
+
}
|
|
3060
|
+
function s(f) {
|
|
3061
|
+
const h = r(f);
|
|
3062
|
+
if (h[0] & 128) {
|
|
3063
|
+
const l = new Uint8Array(h.length + 1);
|
|
3064
|
+
return l[0] = 0, l.set(h, 1), l;
|
|
3065
|
+
}
|
|
3066
|
+
return h;
|
|
3067
|
+
}
|
|
3068
|
+
const i = s(e), o = s(t), c = 2 + i.length + 2 + o.length, a = new Uint8Array(2 + c);
|
|
3069
|
+
let u = 0;
|
|
3070
|
+
return a[u++] = 48, a[u++] = c, a[u++] = 2, a[u++] = i.length, a.set(i, u), u += i.length, a[u++] = 2, a[u++] = o.length, a.set(o, u), a;
|
|
3071
|
+
}
|
|
3072
|
+
const js = Symbol("SDK_CLIENT"), Js = {
|
|
3073
|
+
install(n, e) {
|
|
3074
|
+
const t = new Os(e);
|
|
3075
|
+
n.provide(js, t);
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
export {
|
|
3079
|
+
Ms as Notifications,
|
|
3080
|
+
js as SDK_CLIENT,
|
|
3081
|
+
Js as SdkPlugin,
|
|
3082
|
+
Os as SecureApiClient
|
|
3083
|
+
};
|
|
3084
|
+
//# sourceMappingURL=index.mjs.map
|