@starfish-codes/hellgate 3.8.1 → 3.9.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/dist/card/card-handler.d.ts +9 -1
- package/dist/card/typings.d.ts +10 -3
- package/dist/card/ui/elements/card-expiration-month.d.ts +9 -0
- package/dist/card/ui/elements/card-expiration-year.d.ts +9 -0
- package/dist/card/ui/elements/utils.d.ts +4 -0
- package/dist/card/ui/iframe/elements/card-expiration-month.d.ts +10 -0
- package/dist/card/ui/iframe/elements/card-expiration-year.d.ts +9 -0
- package/dist/card/ui/typings.d.ts +2 -1
- package/dist/hellgate-sdk.mjs +440 -350
- package/dist/hellgate-sdk.umd.js +1 -1
- package/package.json +2 -2
package/dist/hellgate-sdk.mjs
CHANGED
|
@@ -4,11 +4,11 @@ function re(t) {
|
|
|
4
4
|
typeof r == "object" && r && !Array.isArray(r) ? re(r) : r
|
|
5
5
|
]).filter(([e, r]) => typeof r == "object" && r && !Array.isArray(r) ? !!Object.keys(r).length : r != null && r != null));
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function C(t, e) {
|
|
8
8
|
const r = { ...t, ...e }, n = Object.keys(r);
|
|
9
9
|
for (const i of n) {
|
|
10
10
|
const a = t[i], s = e[i];
|
|
11
|
-
typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (r[i] =
|
|
11
|
+
typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (r[i] = C(a, s));
|
|
12
12
|
}
|
|
13
13
|
return r;
|
|
14
14
|
}
|
|
@@ -17,8 +17,8 @@ function V(t) {
|
|
|
17
17
|
throw t;
|
|
18
18
|
return t.json();
|
|
19
19
|
}
|
|
20
|
-
const
|
|
21
|
-
class
|
|
20
|
+
const xe = 2e3;
|
|
21
|
+
class He {
|
|
22
22
|
constructor(e, r) {
|
|
23
23
|
Object.defineProperty(this, "session", {
|
|
24
24
|
enumerable: !0,
|
|
@@ -121,13 +121,13 @@ class Pe {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
}), this.domContainer = r.domContainer ??
|
|
124
|
+
}), this.domContainer = r.domContainer ?? I(), this.disposers.push(this.session.onStateChange(this.sessionStateHandle)), this.labelText = r.labelText;
|
|
125
125
|
}
|
|
126
126
|
dispose() {
|
|
127
127
|
this.disposers.forEach((e) => e()), this.check3dsIframeDisposers.forEach((e) => e());
|
|
128
128
|
}
|
|
129
129
|
initCheck3DSIframes(e, r) {
|
|
130
|
-
const n =
|
|
130
|
+
const n = I();
|
|
131
131
|
n.insertAdjacentHTML("beforeend", `<iframe id="check_3ds_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${e}"></iframe>`);
|
|
132
132
|
const i = n.querySelector(`#check_3ds_${this.iframeId}`);
|
|
133
133
|
if (i) {
|
|
@@ -146,7 +146,7 @@ class Pe {
|
|
|
146
146
|
this.check3dsIframeDisposers.forEach((e) => e()), this.check3dsIframeDisposers = [];
|
|
147
147
|
}
|
|
148
148
|
startChallenge(e, r) {
|
|
149
|
-
const n =
|
|
149
|
+
const n = I(), i = `<div style="display: flex; flex-direction: column; gap: 10px; align-items: center; ${this.domContainer === n ? 'border:0; max-width: 800px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width:100% " ' : 'border:0;" width="100%" height="100%"'}><iframe id="cha_${this.iframeId}" src="${e}" width="100%" height="500"></iframe>${this.labelText ? '<span id="tds_label_text" style="font-size: large;">' + this.labelText + "</span>" : ""}<div>`;
|
|
150
150
|
this.domContainer.insertAdjacentHTML("beforeend", this.domContainer === n ? `<div id="cha_${this.iframeId}_wrap" style="background: #fff; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 10000;">${i}</div>` : i);
|
|
151
151
|
const a = this.domContainer.querySelector(`#cha_${this.iframeId}`), s = this.domContainer.querySelector(`#cha_${this.iframeId}_wrap`);
|
|
152
152
|
if (!a)
|
|
@@ -155,15 +155,15 @@ class Pe {
|
|
|
155
155
|
a.remove(), s == null || s.remove();
|
|
156
156
|
});
|
|
157
157
|
const o = new Promise((u) => {
|
|
158
|
-
const d = (
|
|
159
|
-
|
|
158
|
+
const d = (h) => {
|
|
159
|
+
h.source !== a.contentWindow || h.data.event !== "AuthResultReady" || u(h.data);
|
|
160
160
|
};
|
|
161
161
|
window.addEventListener("message", d), this.disposers.push(() => window.removeEventListener("message", d));
|
|
162
162
|
}), c = new Promise((u) => {
|
|
163
|
-
const d = this.startAuthResultPolling(r, (
|
|
164
|
-
|
|
165
|
-
requestor_trans_id:
|
|
166
|
-
event:
|
|
163
|
+
const d = this.startAuthResultPolling(r, (h) => {
|
|
164
|
+
h.event === "AuthResultReady" && (d(), u({
|
|
165
|
+
requestor_trans_id: h.threeDSRequestorTransID,
|
|
166
|
+
event: h.event
|
|
167
167
|
}));
|
|
168
168
|
});
|
|
169
169
|
});
|
|
@@ -187,58 +187,58 @@ class Pe {
|
|
|
187
187
|
return window.clearTimeout(this.resultPollingTimer), this.resultPollingTimer = window.setTimeout(() => fetch(e).then((n) => V(n)).then((n) => {
|
|
188
188
|
this.startAuthResultPolling(e, r), r(n);
|
|
189
189
|
}).catch(() => {
|
|
190
|
-
}),
|
|
190
|
+
}), xe), () => window.clearTimeout(this.resultPollingTimer);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function I() {
|
|
194
194
|
return document.body;
|
|
195
195
|
}
|
|
196
|
-
const
|
|
196
|
+
const f = crypto, A = (t) => t instanceof CryptoKey, Ke = async (t, e) => {
|
|
197
197
|
const r = `SHA-${t.slice(-3)}`;
|
|
198
|
-
return new Uint8Array(await
|
|
199
|
-
},
|
|
200
|
-
function
|
|
198
|
+
return new Uint8Array(await f.subtle.digest(r, e));
|
|
199
|
+
}, O = new TextEncoder(), ne = new TextDecoder(), R = 2 ** 32;
|
|
200
|
+
function M(...t) {
|
|
201
201
|
const e = t.reduce((i, { length: a }) => i + a, 0), r = new Uint8Array(e);
|
|
202
202
|
let n = 0;
|
|
203
203
|
for (const i of t)
|
|
204
204
|
r.set(i, n), n += i.length;
|
|
205
205
|
return r;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
return
|
|
207
|
+
function Te(t, e) {
|
|
208
|
+
return M(O.encode(t), new Uint8Array([0]), e);
|
|
209
209
|
}
|
|
210
210
|
function J(t, e, r) {
|
|
211
|
-
if (e < 0 || e >=
|
|
212
|
-
throw new RangeError(`value must be >= 0 and <= ${
|
|
211
|
+
if (e < 0 || e >= R)
|
|
212
|
+
throw new RangeError(`value must be >= 0 and <= ${R - 1}. Received ${e}`);
|
|
213
213
|
t.set([e >>> 24, e >>> 16, e >>> 8, e & 255], r);
|
|
214
214
|
}
|
|
215
|
-
function
|
|
216
|
-
const e = Math.floor(t /
|
|
215
|
+
function De(t) {
|
|
216
|
+
const e = Math.floor(t / R), r = t % R, n = new Uint8Array(8);
|
|
217
217
|
return J(n, e, 0), J(n, r, 4), n;
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function Y(t) {
|
|
220
220
|
const e = new Uint8Array(4);
|
|
221
221
|
return J(e, t), e;
|
|
222
222
|
}
|
|
223
223
|
function U(t) {
|
|
224
|
-
return
|
|
224
|
+
return M(Y(t.length), t);
|
|
225
225
|
}
|
|
226
|
-
async function
|
|
226
|
+
async function Me(t, e, r) {
|
|
227
227
|
const n = Math.ceil((e >> 3) / 32), i = new Uint8Array(n * 32);
|
|
228
228
|
for (let a = 0; a < n; a++) {
|
|
229
229
|
const s = new Uint8Array(4 + t.length + r.length);
|
|
230
|
-
s.set(
|
|
230
|
+
s.set(Y(a + 1)), s.set(t, 4), s.set(r, 4 + t.length), i.set(await Ke("sha256", s), a * 32);
|
|
231
231
|
}
|
|
232
232
|
return i.slice(0, e >> 3);
|
|
233
233
|
}
|
|
234
|
-
const
|
|
234
|
+
const je = (t) => {
|
|
235
235
|
let e = t;
|
|
236
|
-
typeof e == "string" && (e =
|
|
236
|
+
typeof e == "string" && (e = O.encode(e));
|
|
237
237
|
const r = 32768, n = [];
|
|
238
238
|
for (let i = 0; i < e.length; i += r)
|
|
239
239
|
n.push(String.fromCharCode.apply(null, e.subarray(i, i + r)));
|
|
240
240
|
return btoa(n.join(""));
|
|
241
|
-
},
|
|
241
|
+
}, w = (t) => je(t).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"), Re = (t) => {
|
|
242
242
|
const e = atob(t), r = new Uint8Array(e.length);
|
|
243
243
|
for (let n = 0; n < e.length; n++)
|
|
244
244
|
r[n] = e.charCodeAt(n);
|
|
@@ -247,7 +247,7 @@ const Ke = (t) => {
|
|
|
247
247
|
let e = t;
|
|
248
248
|
e instanceof Uint8Array && (e = ne.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
249
249
|
try {
|
|
250
|
-
return
|
|
250
|
+
return Re(e);
|
|
251
251
|
} catch {
|
|
252
252
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
253
253
|
}
|
|
@@ -261,7 +261,7 @@ class ae extends Error {
|
|
|
261
261
|
super(e), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
class
|
|
264
|
+
class b extends ae {
|
|
265
265
|
constructor() {
|
|
266
266
|
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
267
267
|
}
|
|
@@ -269,7 +269,7 @@ class f extends ae {
|
|
|
269
269
|
return "ERR_JOSE_NOT_SUPPORTED";
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
class
|
|
272
|
+
class P extends ae {
|
|
273
273
|
constructor() {
|
|
274
274
|
super(...arguments), this.code = "ERR_JWE_INVALID";
|
|
275
275
|
}
|
|
@@ -277,7 +277,7 @@ class A extends ae {
|
|
|
277
277
|
return "ERR_JWE_INVALID";
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
const
|
|
280
|
+
const k = f.getRandomValues.bind(f);
|
|
281
281
|
function se(t) {
|
|
282
282
|
switch (t) {
|
|
283
283
|
case "A128GCM":
|
|
@@ -292,27 +292,27 @@ function se(t) {
|
|
|
292
292
|
case "A256CBC-HS512":
|
|
293
293
|
return 128;
|
|
294
294
|
default:
|
|
295
|
-
throw new
|
|
295
|
+
throw new b(`Unsupported JWE Algorithm: ${t}`);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
const
|
|
298
|
+
const Ie = (t) => k(new Uint8Array(se(t) >> 3)), Ue = (t, e) => {
|
|
299
299
|
if (e.length << 3 !== se(t))
|
|
300
|
-
throw new
|
|
300
|
+
throw new P("Invalid Initialization Vector length");
|
|
301
301
|
}, Z = (t, e) => {
|
|
302
302
|
const r = t.byteLength << 3;
|
|
303
303
|
if (r !== e)
|
|
304
|
-
throw new
|
|
304
|
+
throw new P(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`);
|
|
305
305
|
};
|
|
306
|
-
function
|
|
306
|
+
function S(t, e = "algorithm.name") {
|
|
307
307
|
return new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);
|
|
308
308
|
}
|
|
309
309
|
function j(t, e) {
|
|
310
310
|
return t.name === e;
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function $e(t) {
|
|
313
313
|
return parseInt(t.name.slice(4), 10);
|
|
314
314
|
}
|
|
315
|
-
function
|
|
315
|
+
function We(t, e) {
|
|
316
316
|
if (e.length && !e.some((r) => t.usages.includes(r))) {
|
|
317
317
|
let r = "CryptoKey does not support this operation, its usages must include ";
|
|
318
318
|
if (e.length > 2) {
|
|
@@ -322,26 +322,26 @@ function Ie(t, e) {
|
|
|
322
322
|
throw new TypeError(r);
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
function
|
|
325
|
+
function T(t, e, ...r) {
|
|
326
326
|
switch (e) {
|
|
327
327
|
case "A128GCM":
|
|
328
328
|
case "A192GCM":
|
|
329
329
|
case "A256GCM": {
|
|
330
330
|
if (!j(t.algorithm, "AES-GCM"))
|
|
331
|
-
throw
|
|
331
|
+
throw S("AES-GCM");
|
|
332
332
|
const n = parseInt(e.slice(1, 4), 10);
|
|
333
333
|
if (t.algorithm.length !== n)
|
|
334
|
-
throw
|
|
334
|
+
throw S(n, "algorithm.length");
|
|
335
335
|
break;
|
|
336
336
|
}
|
|
337
337
|
case "A128KW":
|
|
338
338
|
case "A192KW":
|
|
339
339
|
case "A256KW": {
|
|
340
340
|
if (!j(t.algorithm, "AES-KW"))
|
|
341
|
-
throw
|
|
341
|
+
throw S("AES-KW");
|
|
342
342
|
const n = parseInt(e.slice(1, 4), 10);
|
|
343
343
|
if (t.algorithm.length !== n)
|
|
344
|
-
throw
|
|
344
|
+
throw S(n, "algorithm.length");
|
|
345
345
|
break;
|
|
346
346
|
}
|
|
347
347
|
case "ECDH": {
|
|
@@ -351,7 +351,7 @@ function x(t, e, ...r) {
|
|
|
351
351
|
case "X448":
|
|
352
352
|
break;
|
|
353
353
|
default:
|
|
354
|
-
throw
|
|
354
|
+
throw S("ECDH, X25519, or X448");
|
|
355
355
|
}
|
|
356
356
|
break;
|
|
357
357
|
}
|
|
@@ -359,23 +359,23 @@ function x(t, e, ...r) {
|
|
|
359
359
|
case "PBES2-HS384+A192KW":
|
|
360
360
|
case "PBES2-HS512+A256KW":
|
|
361
361
|
if (!j(t.algorithm, "PBKDF2"))
|
|
362
|
-
throw
|
|
362
|
+
throw S("PBKDF2");
|
|
363
363
|
break;
|
|
364
364
|
case "RSA-OAEP":
|
|
365
365
|
case "RSA-OAEP-256":
|
|
366
366
|
case "RSA-OAEP-384":
|
|
367
367
|
case "RSA-OAEP-512": {
|
|
368
368
|
if (!j(t.algorithm, "RSA-OAEP"))
|
|
369
|
-
throw
|
|
369
|
+
throw S("RSA-OAEP");
|
|
370
370
|
const n = parseInt(e.slice(9), 10) || 1;
|
|
371
|
-
if (
|
|
372
|
-
throw
|
|
371
|
+
if ($e(t.algorithm.hash) !== n)
|
|
372
|
+
throw S(`SHA-${n}`, "algorithm.hash");
|
|
373
373
|
break;
|
|
374
374
|
}
|
|
375
375
|
default:
|
|
376
376
|
throw new TypeError("CryptoKey does not support this operation");
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
We(t, r);
|
|
379
379
|
}
|
|
380
380
|
function oe(t, e, ...r) {
|
|
381
381
|
var n;
|
|
@@ -385,11 +385,11 @@ function oe(t, e, ...r) {
|
|
|
385
385
|
} else r.length === 2 ? t += `one of type ${r[0]} or ${r[1]}.` : t += `of type ${r[0]}.`;
|
|
386
386
|
return e == null ? t += ` Received ${e}` : typeof e == "function" && e.name ? t += ` Received function ${e.name}` : typeof e == "object" && e != null && (n = e.constructor) != null && n.name && (t += ` Received an instance of ${e.constructor.name}`), t;
|
|
387
387
|
}
|
|
388
|
-
const
|
|
388
|
+
const _ = (t, ...e) => oe("Key must be ", t, ...e);
|
|
389
389
|
function ce(t, e, ...r) {
|
|
390
390
|
return oe(`Key for the ${t} algorithm must be `, e, ...r);
|
|
391
391
|
}
|
|
392
|
-
const le = (t) =>
|
|
392
|
+
const le = (t) => A(t) ? !0 : (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", g = ["CryptoKey"], Ne = (...t) => {
|
|
393
393
|
const e = t.filter(Boolean);
|
|
394
394
|
if (e.length === 0 || e.length === 1)
|
|
395
395
|
return !0;
|
|
@@ -408,11 +408,11 @@ const le = (t) => w(t) ? !0 : (t == null ? void 0 : t[Symbol.toStringTag]) === "
|
|
|
408
408
|
}
|
|
409
409
|
return !0;
|
|
410
410
|
};
|
|
411
|
-
function
|
|
411
|
+
function Le(t) {
|
|
412
412
|
return typeof t == "object" && t !== null;
|
|
413
413
|
}
|
|
414
|
-
function
|
|
415
|
-
if (!
|
|
414
|
+
function Fe(t) {
|
|
415
|
+
if (!Le(t) || Object.prototype.toString.call(t) !== "[object Object]")
|
|
416
416
|
return !1;
|
|
417
417
|
if (Object.getPrototypeOf(t) === null)
|
|
418
418
|
return !0;
|
|
@@ -426,62 +426,62 @@ const ue = [
|
|
|
426
426
|
!0,
|
|
427
427
|
["sign"]
|
|
428
428
|
];
|
|
429
|
-
function
|
|
429
|
+
function Be(t, e) {
|
|
430
430
|
if (t.algorithm.length !== parseInt(e.slice(1, 4), 10))
|
|
431
431
|
throw new TypeError(`Invalid key size for alg: ${e}`);
|
|
432
432
|
}
|
|
433
|
-
function
|
|
434
|
-
if (
|
|
435
|
-
return
|
|
433
|
+
function Ve(t, e, r) {
|
|
434
|
+
if (A(t))
|
|
435
|
+
return T(t, e, r), t;
|
|
436
436
|
if (t instanceof Uint8Array)
|
|
437
|
-
return
|
|
438
|
-
throw new TypeError(
|
|
437
|
+
return f.subtle.importKey("raw", t, "AES-KW", !0, [r]);
|
|
438
|
+
throw new TypeError(_(t, ...g, "Uint8Array"));
|
|
439
439
|
}
|
|
440
440
|
const z = async (t, e, r) => {
|
|
441
|
-
const n = await
|
|
442
|
-
|
|
443
|
-
const i = await
|
|
444
|
-
return new Uint8Array(await
|
|
441
|
+
const n = await Ve(e, t, "wrapKey");
|
|
442
|
+
Be(n, t);
|
|
443
|
+
const i = await f.subtle.importKey("raw", r, ...ue);
|
|
444
|
+
return new Uint8Array(await f.subtle.wrapKey("raw", i, n, "AES-KW"));
|
|
445
445
|
};
|
|
446
|
-
async function
|
|
447
|
-
if (!
|
|
448
|
-
throw new TypeError(
|
|
449
|
-
if (
|
|
450
|
-
throw new TypeError(
|
|
451
|
-
|
|
452
|
-
const s =
|
|
446
|
+
async function Je(t, e, r, n, i = new Uint8Array(0), a = new Uint8Array(0)) {
|
|
447
|
+
if (!A(t))
|
|
448
|
+
throw new TypeError(_(t, ...g));
|
|
449
|
+
if (T(t, "ECDH"), !A(e))
|
|
450
|
+
throw new TypeError(_(e, ...g));
|
|
451
|
+
T(e, "ECDH", "deriveBits");
|
|
452
|
+
const s = M(U(O.encode(r)), U(i), U(a), Y(n));
|
|
453
453
|
let o;
|
|
454
454
|
t.algorithm.name === "X25519" ? o = 256 : t.algorithm.name === "X448" ? o = 448 : o = Math.ceil(parseInt(t.algorithm.namedCurve.substr(-3), 10) / 8) << 3;
|
|
455
|
-
const c = new Uint8Array(await
|
|
455
|
+
const c = new Uint8Array(await f.subtle.deriveBits({
|
|
456
456
|
name: t.algorithm.name,
|
|
457
457
|
public: t
|
|
458
458
|
}, e, o));
|
|
459
|
-
return
|
|
459
|
+
return Me(c, n, s);
|
|
460
460
|
}
|
|
461
|
-
async function
|
|
462
|
-
if (!
|
|
463
|
-
throw new TypeError(
|
|
464
|
-
return
|
|
461
|
+
async function ze(t) {
|
|
462
|
+
if (!A(t))
|
|
463
|
+
throw new TypeError(_(t, ...g));
|
|
464
|
+
return f.subtle.generateKey(t.algorithm, !0, ["deriveBits"]);
|
|
465
465
|
}
|
|
466
|
-
function
|
|
467
|
-
if (!
|
|
468
|
-
throw new TypeError(
|
|
466
|
+
function Ge(t) {
|
|
467
|
+
if (!A(t))
|
|
468
|
+
throw new TypeError(_(t, ...g));
|
|
469
469
|
return ["P-256", "P-384", "P-521"].includes(t.algorithm.namedCurve) || t.algorithm.name === "X25519" || t.algorithm.name === "X448";
|
|
470
470
|
}
|
|
471
|
-
function
|
|
471
|
+
function Ye(t) {
|
|
472
472
|
if (!(t instanceof Uint8Array) || t.length < 8)
|
|
473
|
-
throw new
|
|
473
|
+
throw new P("PBES2 Salt Input must be 8 or more octets");
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function ke(t, e) {
|
|
476
476
|
if (t instanceof Uint8Array)
|
|
477
|
-
return
|
|
478
|
-
if (
|
|
479
|
-
return
|
|
480
|
-
throw new TypeError(
|
|
481
|
-
}
|
|
482
|
-
async function
|
|
483
|
-
|
|
484
|
-
const i =
|
|
477
|
+
return f.subtle.importKey("raw", t, "PBKDF2", !1, ["deriveBits"]);
|
|
478
|
+
if (A(t))
|
|
479
|
+
return T(t, e, "deriveBits", "deriveKey"), t;
|
|
480
|
+
throw new TypeError(_(t, ...g, "Uint8Array"));
|
|
481
|
+
}
|
|
482
|
+
async function qe(t, e, r, n) {
|
|
483
|
+
Ye(t);
|
|
484
|
+
const i = Te(e, t), a = parseInt(e.slice(13, 16), 10), s = {
|
|
485
485
|
hash: `SHA-${e.slice(8, 11)}`,
|
|
486
486
|
iterations: r,
|
|
487
487
|
name: "PBKDF2",
|
|
@@ -489,16 +489,16 @@ async function ze(t, e, r, n) {
|
|
|
489
489
|
}, o = {
|
|
490
490
|
length: a,
|
|
491
491
|
name: "AES-KW"
|
|
492
|
-
}, c = await
|
|
492
|
+
}, c = await ke(n, e);
|
|
493
493
|
if (c.usages.includes("deriveBits"))
|
|
494
|
-
return new Uint8Array(await
|
|
494
|
+
return new Uint8Array(await f.subtle.deriveBits(s, c, a));
|
|
495
495
|
if (c.usages.includes("deriveKey"))
|
|
496
|
-
return
|
|
496
|
+
return f.subtle.deriveKey(s, c, o, !1, ["wrapKey", "unwrapKey"]);
|
|
497
497
|
throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
|
|
498
498
|
}
|
|
499
|
-
const
|
|
500
|
-
const a = await
|
|
501
|
-
return { encryptedKey: await z(t.slice(-6), a, r), p2c: n, p2s:
|
|
499
|
+
const Xe = async (t, e, r, n = 2048, i = k(new Uint8Array(16))) => {
|
|
500
|
+
const a = await qe(i, t, n, e);
|
|
501
|
+
return { encryptedKey: await z(t.slice(-6), a, r), p2c: n, p2s: w(i) };
|
|
502
502
|
};
|
|
503
503
|
function Q(t) {
|
|
504
504
|
switch (t) {
|
|
@@ -508,27 +508,27 @@ function Q(t) {
|
|
|
508
508
|
case "RSA-OAEP-512":
|
|
509
509
|
return "RSA-OAEP";
|
|
510
510
|
default:
|
|
511
|
-
throw new
|
|
511
|
+
throw new b(`alg ${t} is not supported either by JOSE or your javascript runtime`);
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
const
|
|
514
|
+
const Ze = (t, e) => {
|
|
515
515
|
if (t.startsWith("RS") || t.startsWith("PS")) {
|
|
516
516
|
const { modulusLength: r } = e.algorithm;
|
|
517
517
|
if (typeof r != "number" || r < 2048)
|
|
518
518
|
throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`);
|
|
519
519
|
}
|
|
520
|
-
},
|
|
521
|
-
if (!
|
|
522
|
-
throw new TypeError(
|
|
523
|
-
if (
|
|
524
|
-
return new Uint8Array(await
|
|
520
|
+
}, Qe = async (t, e, r) => {
|
|
521
|
+
if (!A(e))
|
|
522
|
+
throw new TypeError(_(e, ...g));
|
|
523
|
+
if (T(e, t, "encrypt", "wrapKey"), Ze(t, e), e.usages.includes("encrypt"))
|
|
524
|
+
return new Uint8Array(await f.subtle.encrypt(Q(t), e, r));
|
|
525
525
|
if (e.usages.includes("wrapKey")) {
|
|
526
|
-
const n = await
|
|
527
|
-
return new Uint8Array(await
|
|
526
|
+
const n = await f.subtle.importKey("raw", r, ...ue);
|
|
527
|
+
return new Uint8Array(await f.subtle.wrapKey("raw", n, e, Q(t)));
|
|
528
528
|
}
|
|
529
529
|
throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
|
|
530
530
|
};
|
|
531
|
-
function
|
|
531
|
+
function et(t) {
|
|
532
532
|
let e, r;
|
|
533
533
|
switch (t.kty) {
|
|
534
534
|
case "RSA": {
|
|
@@ -553,7 +553,7 @@ function Xe(t) {
|
|
|
553
553
|
}, r = t.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
554
554
|
break;
|
|
555
555
|
default:
|
|
556
|
-
throw new
|
|
556
|
+
throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
557
557
|
}
|
|
558
558
|
break;
|
|
559
559
|
}
|
|
@@ -575,7 +575,7 @@ function Xe(t) {
|
|
|
575
575
|
e = { name: "ECDH", namedCurve: t.crv }, r = t.d ? ["deriveBits"] : [];
|
|
576
576
|
break;
|
|
577
577
|
default:
|
|
578
|
-
throw new
|
|
578
|
+
throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
579
579
|
}
|
|
580
580
|
break;
|
|
581
581
|
}
|
|
@@ -591,24 +591,24 @@ function Xe(t) {
|
|
|
591
591
|
e = { name: t.crv }, r = t.d ? ["deriveBits"] : [];
|
|
592
592
|
break;
|
|
593
593
|
default:
|
|
594
|
-
throw new
|
|
594
|
+
throw new b('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
595
595
|
}
|
|
596
596
|
break;
|
|
597
597
|
}
|
|
598
598
|
default:
|
|
599
|
-
throw new
|
|
599
|
+
throw new b('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
600
600
|
}
|
|
601
601
|
return { algorithm: e, keyUsages: r };
|
|
602
602
|
}
|
|
603
603
|
const de = async (t) => {
|
|
604
604
|
if (!t.alg)
|
|
605
605
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
606
|
-
const { algorithm: e, keyUsages: r } =
|
|
606
|
+
const { algorithm: e, keyUsages: r } = et(t), n = [
|
|
607
607
|
e,
|
|
608
608
|
t.ext ?? !1,
|
|
609
609
|
t.key_ops ?? r
|
|
610
610
|
], i = { ...t };
|
|
611
|
-
return delete i.alg, delete i.use,
|
|
611
|
+
return delete i.alg, delete i.use, f.subtle.importKey("jwk", i, ...n);
|
|
612
612
|
}, he = (t) => ie(t);
|
|
613
613
|
let $, W;
|
|
614
614
|
const fe = (t) => (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", pe = async (t, e, r, n) => {
|
|
@@ -617,19 +617,19 @@ const fe = (t) => (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject",
|
|
|
617
617
|
return i[n];
|
|
618
618
|
const a = await de({ ...r, alg: n });
|
|
619
619
|
return i ? i[n] = a : t.set(e, { [n]: a }), a;
|
|
620
|
-
},
|
|
620
|
+
}, tt = (t, e) => {
|
|
621
621
|
if (fe(t)) {
|
|
622
622
|
let r = t.export({ format: "jwk" });
|
|
623
623
|
return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? he(r.k) : (W || (W = /* @__PURE__ */ new WeakMap()), pe(W, t, r, e));
|
|
624
624
|
}
|
|
625
625
|
return t;
|
|
626
|
-
},
|
|
626
|
+
}, rt = (t, e) => {
|
|
627
627
|
if (fe(t)) {
|
|
628
628
|
let r = t.export({ format: "jwk" });
|
|
629
629
|
return r.k ? he(r.k) : ($ || ($ = /* @__PURE__ */ new WeakMap()), pe($, t, r, e));
|
|
630
630
|
}
|
|
631
631
|
return t;
|
|
632
|
-
}, N = { normalizePublicKey:
|
|
632
|
+
}, N = { normalizePublicKey: tt, normalizePrivateKey: rt };
|
|
633
633
|
function me(t) {
|
|
634
634
|
switch (t) {
|
|
635
635
|
case "A128GCM":
|
|
@@ -644,12 +644,12 @@ function me(t) {
|
|
|
644
644
|
case "A256CBC-HS512":
|
|
645
645
|
return 512;
|
|
646
646
|
default:
|
|
647
|
-
throw new
|
|
647
|
+
throw new b(`Unsupported JWE Algorithm: ${t}`);
|
|
648
648
|
}
|
|
649
649
|
}
|
|
650
|
-
const
|
|
651
|
-
async function
|
|
652
|
-
if (
|
|
650
|
+
const D = (t) => k(new Uint8Array(me(t) >> 3));
|
|
651
|
+
async function nt(t, e) {
|
|
652
|
+
if (!Fe(t))
|
|
653
653
|
throw new TypeError("JWK must be an object");
|
|
654
654
|
switch (t.kty) {
|
|
655
655
|
case "oct":
|
|
@@ -658,47 +658,47 @@ async function Qe(t, e) {
|
|
|
658
658
|
return ie(t.k);
|
|
659
659
|
case "RSA":
|
|
660
660
|
if (t.oth !== void 0)
|
|
661
|
-
throw new
|
|
661
|
+
throw new b('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
662
662
|
case "EC":
|
|
663
663
|
case "OKP":
|
|
664
664
|
return de({ ...t, alg: e });
|
|
665
665
|
default:
|
|
666
|
-
throw new
|
|
666
|
+
throw new b('Unsupported "kty" (Key Type) Parameter value');
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
|
-
const G = (t) => t == null ? void 0 : t[Symbol.toStringTag],
|
|
669
|
+
const G = (t) => t == null ? void 0 : t[Symbol.toStringTag], it = (t, e) => {
|
|
670
670
|
if (!(e instanceof Uint8Array)) {
|
|
671
671
|
if (!le(e))
|
|
672
|
-
throw new TypeError(ce(t, e, ...
|
|
672
|
+
throw new TypeError(ce(t, e, ...g, "Uint8Array"));
|
|
673
673
|
if (e.type !== "secret")
|
|
674
674
|
throw new TypeError(`${G(e)} instances for symmetric algorithms must be of type "secret"`);
|
|
675
675
|
}
|
|
676
|
-
},
|
|
676
|
+
}, at = (t, e, r) => {
|
|
677
677
|
if (!le(e))
|
|
678
|
-
throw new TypeError(ce(t, e, ...
|
|
678
|
+
throw new TypeError(ce(t, e, ...g));
|
|
679
679
|
if (e.type === "secret")
|
|
680
680
|
throw new TypeError(`${G(e)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
681
681
|
if (e.algorithm, e.algorithm && r === "encrypt" && e.type === "private")
|
|
682
682
|
throw new TypeError(`${G(e)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
683
|
-
},
|
|
684
|
-
t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ?
|
|
683
|
+
}, st = (t, e, r) => {
|
|
684
|
+
t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? it(t, e) : at(t, e, r);
|
|
685
685
|
};
|
|
686
|
-
async function
|
|
686
|
+
async function ot(t, e, r, n, i) {
|
|
687
687
|
if (!(r instanceof Uint8Array))
|
|
688
|
-
throw new TypeError(
|
|
689
|
-
const a = parseInt(t.slice(1, 4), 10), s = await
|
|
688
|
+
throw new TypeError(_(r, "Uint8Array"));
|
|
689
|
+
const a = parseInt(t.slice(1, 4), 10), s = await f.subtle.importKey("raw", r.subarray(a >> 3), "AES-CBC", !1, ["encrypt"]), o = await f.subtle.importKey("raw", r.subarray(0, a >> 3), {
|
|
690
690
|
hash: `SHA-${a << 1}`,
|
|
691
691
|
name: "HMAC"
|
|
692
|
-
}, !1, ["sign"]), c = new Uint8Array(await
|
|
692
|
+
}, !1, ["sign"]), c = new Uint8Array(await f.subtle.encrypt({
|
|
693
693
|
iv: n,
|
|
694
694
|
name: "AES-CBC"
|
|
695
|
-
}, s, e)), u =
|
|
695
|
+
}, s, e)), u = M(i, n, c, De(i.length << 3)), d = new Uint8Array((await f.subtle.sign("HMAC", o, u)).slice(0, a >> 3));
|
|
696
696
|
return { ciphertext: c, tag: d, iv: n };
|
|
697
697
|
}
|
|
698
|
-
async function
|
|
698
|
+
async function ct(t, e, r, n, i) {
|
|
699
699
|
let a;
|
|
700
|
-
r instanceof Uint8Array ? a = await
|
|
701
|
-
const s = new Uint8Array(await
|
|
700
|
+
r instanceof Uint8Array ? a = await f.subtle.importKey("raw", r, "AES-GCM", !1, ["encrypt"]) : (T(r, t, "encrypt"), a = r);
|
|
701
|
+
const s = new Uint8Array(await f.subtle.encrypt({
|
|
702
702
|
additionalData: i,
|
|
703
703
|
iv: n,
|
|
704
704
|
name: "AES-GCM",
|
|
@@ -707,30 +707,30 @@ async function it(t, e, r, n, i) {
|
|
|
707
707
|
return { ciphertext: s.slice(0, -16), tag: o, iv: n };
|
|
708
708
|
}
|
|
709
709
|
const be = async (t, e, r, n, i) => {
|
|
710
|
-
if (!
|
|
711
|
-
throw new TypeError(
|
|
712
|
-
switch (n ?
|
|
710
|
+
if (!A(r) && !(r instanceof Uint8Array))
|
|
711
|
+
throw new TypeError(_(r, ...g, "Uint8Array"));
|
|
712
|
+
switch (n ? Ue(t, n) : n = Ie(t), t) {
|
|
713
713
|
case "A128CBC-HS256":
|
|
714
714
|
case "A192CBC-HS384":
|
|
715
715
|
case "A256CBC-HS512":
|
|
716
|
-
return r instanceof Uint8Array && Z(r, parseInt(t.slice(-3), 10)),
|
|
716
|
+
return r instanceof Uint8Array && Z(r, parseInt(t.slice(-3), 10)), ot(t, e, r, n, i);
|
|
717
717
|
case "A128GCM":
|
|
718
718
|
case "A192GCM":
|
|
719
719
|
case "A256GCM":
|
|
720
|
-
return r instanceof Uint8Array && Z(r, parseInt(t.slice(1, 4), 10)),
|
|
720
|
+
return r instanceof Uint8Array && Z(r, parseInt(t.slice(1, 4), 10)), ct(t, e, r, n, i);
|
|
721
721
|
default:
|
|
722
|
-
throw new
|
|
722
|
+
throw new b("Unsupported JWE Content Encryption Algorithm");
|
|
723
723
|
}
|
|
724
724
|
};
|
|
725
|
-
async function
|
|
725
|
+
async function lt(t, e, r, n) {
|
|
726
726
|
const i = t.slice(0, 7), a = await be(i, r, e, n, new Uint8Array(0));
|
|
727
727
|
return {
|
|
728
728
|
encryptedKey: a.ciphertext,
|
|
729
|
-
iv:
|
|
730
|
-
tag:
|
|
729
|
+
iv: w(a.iv),
|
|
730
|
+
tag: w(a.tag)
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
-
function
|
|
733
|
+
function ut(t, e, r, n, i) {
|
|
734
734
|
if (i.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
735
735
|
throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
736
736
|
if (!n || n.crit === void 0)
|
|
@@ -741,7 +741,7 @@ function st(t, e, r, n, i) {
|
|
|
741
741
|
r !== void 0 ? a = new Map([...Object.entries(r), ...e.entries()]) : a = e;
|
|
742
742
|
for (const s of n.crit) {
|
|
743
743
|
if (!a.has(s))
|
|
744
|
-
throw new
|
|
744
|
+
throw new b(`Extension Header Parameter "${s}" is not recognized`);
|
|
745
745
|
if (i[s] === void 0)
|
|
746
746
|
throw new t(`Extension Header Parameter "${s}" is missing`);
|
|
747
747
|
if (a.get(s) && n[s] === void 0)
|
|
@@ -749,26 +749,26 @@ function st(t, e, r, n, i) {
|
|
|
749
749
|
}
|
|
750
750
|
return new Set(n.crit);
|
|
751
751
|
}
|
|
752
|
-
const
|
|
752
|
+
const dt = async (t) => {
|
|
753
753
|
if (t instanceof Uint8Array)
|
|
754
754
|
return {
|
|
755
755
|
kty: "oct",
|
|
756
|
-
k:
|
|
756
|
+
k: w(t)
|
|
757
757
|
};
|
|
758
|
-
if (!
|
|
759
|
-
throw new TypeError(
|
|
758
|
+
if (!A(t))
|
|
759
|
+
throw new TypeError(_(t, ...g, "Uint8Array"));
|
|
760
760
|
if (!t.extractable)
|
|
761
761
|
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
762
|
-
const { ext: e, key_ops: r, alg: n, use: i, ...a } = await
|
|
762
|
+
const { ext: e, key_ops: r, alg: n, use: i, ...a } = await f.subtle.exportKey("jwk", t);
|
|
763
763
|
return a;
|
|
764
764
|
};
|
|
765
|
-
async function
|
|
766
|
-
return
|
|
765
|
+
async function ht(t) {
|
|
766
|
+
return dt(t);
|
|
767
767
|
}
|
|
768
|
-
async function
|
|
768
|
+
async function ft(t, e, r, n, i = {}) {
|
|
769
769
|
var c;
|
|
770
770
|
let a, s, o;
|
|
771
|
-
switch (
|
|
771
|
+
switch (st(t, r, "encrypt"), r = await ((c = N.normalizePublicKey) == null ? void 0 : c.call(N, r, t)) || r, t) {
|
|
772
772
|
case "dir": {
|
|
773
773
|
o = r;
|
|
774
774
|
break;
|
|
@@ -777,19 +777,19 @@ async function lt(t, e, r, n, i = {}) {
|
|
|
777
777
|
case "ECDH-ES+A128KW":
|
|
778
778
|
case "ECDH-ES+A192KW":
|
|
779
779
|
case "ECDH-ES+A256KW": {
|
|
780
|
-
if (!
|
|
781
|
-
throw new
|
|
780
|
+
if (!Ge(r))
|
|
781
|
+
throw new b("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
782
782
|
const { apu: u, apv: d } = i;
|
|
783
|
-
let { epk:
|
|
784
|
-
|
|
785
|
-
const { x:
|
|
786
|
-
if (s = { epk: { x:
|
|
787
|
-
o =
|
|
783
|
+
let { epk: h } = i;
|
|
784
|
+
h || (h = (await ze(r)).privateKey);
|
|
785
|
+
const { x: p, y: E, crv: l, kty: m } = await ht(h), X = await Je(r, h, t === "ECDH-ES" ? e : t, t === "ECDH-ES" ? me(e) : parseInt(t.slice(-5, -2), 10), u, d);
|
|
786
|
+
if (s = { epk: { x: p, crv: l, kty: m } }, m === "EC" && (s.epk.y = E), u && (s.apu = w(u)), d && (s.apv = w(d)), t === "ECDH-ES") {
|
|
787
|
+
o = X;
|
|
788
788
|
break;
|
|
789
789
|
}
|
|
790
|
-
o = n ||
|
|
791
|
-
const
|
|
792
|
-
a = await z(
|
|
790
|
+
o = n || D(e);
|
|
791
|
+
const Oe = t.slice(-6);
|
|
792
|
+
a = await z(Oe, X, o);
|
|
793
793
|
break;
|
|
794
794
|
}
|
|
795
795
|
case "RSA1_5":
|
|
@@ -797,38 +797,38 @@ async function lt(t, e, r, n, i = {}) {
|
|
|
797
797
|
case "RSA-OAEP-256":
|
|
798
798
|
case "RSA-OAEP-384":
|
|
799
799
|
case "RSA-OAEP-512": {
|
|
800
|
-
o = n ||
|
|
800
|
+
o = n || D(e), a = await Qe(t, r, o);
|
|
801
801
|
break;
|
|
802
802
|
}
|
|
803
803
|
case "PBES2-HS256+A128KW":
|
|
804
804
|
case "PBES2-HS384+A192KW":
|
|
805
805
|
case "PBES2-HS512+A256KW": {
|
|
806
|
-
o = n ||
|
|
806
|
+
o = n || D(e);
|
|
807
807
|
const { p2c: u, p2s: d } = i;
|
|
808
|
-
({ encryptedKey: a, ...s } = await
|
|
808
|
+
({ encryptedKey: a, ...s } = await Xe(t, r, o, u, d));
|
|
809
809
|
break;
|
|
810
810
|
}
|
|
811
811
|
case "A128KW":
|
|
812
812
|
case "A192KW":
|
|
813
813
|
case "A256KW": {
|
|
814
|
-
o = n ||
|
|
814
|
+
o = n || D(e), a = await z(t, r, o);
|
|
815
815
|
break;
|
|
816
816
|
}
|
|
817
817
|
case "A128GCMKW":
|
|
818
818
|
case "A192GCMKW":
|
|
819
819
|
case "A256GCMKW": {
|
|
820
|
-
o = n ||
|
|
820
|
+
o = n || D(e);
|
|
821
821
|
const { iv: u } = i;
|
|
822
|
-
({ encryptedKey: a, ...s } = await
|
|
822
|
+
({ encryptedKey: a, ...s } = await lt(t, r, o, u));
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
825
|
default:
|
|
826
|
-
throw new
|
|
826
|
+
throw new b('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
827
827
|
}
|
|
828
828
|
return { cek: o, encryptedKey: a, parameters: s };
|
|
829
829
|
}
|
|
830
|
-
const
|
|
831
|
-
class
|
|
830
|
+
const pt = Symbol();
|
|
831
|
+
class mt {
|
|
832
832
|
constructor(e) {
|
|
833
833
|
if (!(e instanceof Uint8Array))
|
|
834
834
|
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
@@ -869,40 +869,40 @@ class dt {
|
|
|
869
869
|
}
|
|
870
870
|
async encrypt(e, r) {
|
|
871
871
|
if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader)
|
|
872
|
-
throw new
|
|
873
|
-
if (!
|
|
874
|
-
throw new
|
|
872
|
+
throw new P("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
873
|
+
if (!Ne(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader))
|
|
874
|
+
throw new P("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
875
875
|
const n = {
|
|
876
876
|
...this._protectedHeader,
|
|
877
877
|
...this._unprotectedHeader,
|
|
878
878
|
...this._sharedUnprotectedHeader
|
|
879
879
|
};
|
|
880
|
-
if (
|
|
881
|
-
throw new
|
|
880
|
+
if (ut(P, /* @__PURE__ */ new Map(), r == null ? void 0 : r.crit, this._protectedHeader, n), n.zip !== void 0)
|
|
881
|
+
throw new b('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
882
882
|
const { alg: i, enc: a } = n;
|
|
883
883
|
if (typeof i != "string" || !i)
|
|
884
|
-
throw new
|
|
884
|
+
throw new P('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
885
885
|
if (typeof a != "string" || !a)
|
|
886
|
-
throw new
|
|
886
|
+
throw new P('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
887
887
|
let s;
|
|
888
888
|
if (this._cek && (i === "dir" || i === "ECDH-ES"))
|
|
889
889
|
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${i}`);
|
|
890
890
|
let o;
|
|
891
891
|
{
|
|
892
|
-
let
|
|
893
|
-
({ cek: o, encryptedKey: s, parameters:
|
|
892
|
+
let m;
|
|
893
|
+
({ cek: o, encryptedKey: s, parameters: m } = await ft(i, a, e, this._cek, this._keyManagementParameters)), m && (r && pt in r ? this._unprotectedHeader ? this._unprotectedHeader = { ...this._unprotectedHeader, ...m } : this.setUnprotectedHeader(m) : this._protectedHeader ? this._protectedHeader = { ...this._protectedHeader, ...m } : this.setProtectedHeader(m));
|
|
894
894
|
}
|
|
895
895
|
let c, u, d;
|
|
896
|
-
this._protectedHeader ? u =
|
|
897
|
-
const { ciphertext:
|
|
898
|
-
ciphertext:
|
|
896
|
+
this._protectedHeader ? u = O.encode(w(JSON.stringify(this._protectedHeader))) : u = O.encode(""), this._aad ? (d = w(this._aad), c = M(u, O.encode("."), O.encode(d))) : c = u;
|
|
897
|
+
const { ciphertext: h, tag: p, iv: E } = await be(a, this._plaintext, o, this._iv, c), l = {
|
|
898
|
+
ciphertext: w(h)
|
|
899
899
|
};
|
|
900
|
-
return
|
|
900
|
+
return E && (l.iv = w(E)), p && (l.tag = w(p)), s && (l.encrypted_key = w(s)), d && (l.aad = d), this._protectedHeader && (l.protected = ne.decode(u)), this._sharedUnprotectedHeader && (l.unprotected = this._sharedUnprotectedHeader), this._unprotectedHeader && (l.header = this._unprotectedHeader), l;
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
|
-
class
|
|
903
|
+
class bt {
|
|
904
904
|
constructor(e) {
|
|
905
|
-
this._flattened = new
|
|
905
|
+
this._flattened = new mt(e);
|
|
906
906
|
}
|
|
907
907
|
setContentEncryptionKey(e) {
|
|
908
908
|
return this._flattened.setContentEncryptionKey(e), this;
|
|
@@ -927,13 +927,13 @@ const L = {
|
|
|
927
927
|
backgroundColor: "transparent"
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
|
-
},
|
|
930
|
+
}, yt = "DOM Element was not found";
|
|
931
931
|
var ee;
|
|
932
932
|
(function(t) {
|
|
933
933
|
t.NOT_COMPLETE = "NOT_COMPLETE", t.SCHEME_NOT_SUPPORTED = "SCHEME_NOT_SUPPORTED", t.LUHN_CHECK_FAILED = "LUHN_CHECK_FAILED", t.INVALID_EXPIRY_DATE = "INVALID_EXPIRY_DATE";
|
|
934
934
|
})(ee || (ee = {}));
|
|
935
|
-
const ye = (t) => t != null,
|
|
936
|
-
class
|
|
935
|
+
const ye = (t) => t != null, wt = "v3.9.0";
|
|
936
|
+
class x {
|
|
937
937
|
constructor(e, r) {
|
|
938
938
|
if (Object.defineProperty(this, "options", {
|
|
939
939
|
enumerable: !0,
|
|
@@ -997,14 +997,14 @@ class R {
|
|
|
997
997
|
var n;
|
|
998
998
|
(n = this.iframe) == null || n.remove(), this.iframe = null;
|
|
999
999
|
}
|
|
1000
|
-
}), this.IFRAME_BASE_URL =
|
|
1000
|
+
}), this.IFRAME_BASE_URL = Et(wt), !this.IFRAME_BASE_URL)
|
|
1001
1001
|
throw new Error("IFRAME_BASE_URL not found");
|
|
1002
1002
|
r && F.set(this, { key: r });
|
|
1003
1003
|
}
|
|
1004
1004
|
mount(e) {
|
|
1005
1005
|
const r = typeof e == "string" ? document.querySelector(e) : e;
|
|
1006
1006
|
if (!r)
|
|
1007
|
-
throw new Error(
|
|
1007
|
+
throw new Error(`${yt}: ${e}`);
|
|
1008
1008
|
r.innerHTML = `<iframe width="100%" height="29" src="${this.IFRAME_BASE_URL}?field=${this.type}&origin=${location.origin}"></iframe>`, this.iframe = r.querySelector("iframe");
|
|
1009
1009
|
const n = (i) => {
|
|
1010
1010
|
var a;
|
|
@@ -1044,24 +1044,79 @@ class R {
|
|
|
1044
1044
|
(n = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || n.postMessage(e, this.IFRAME_BASE_URL);
|
|
1045
1045
|
}
|
|
1046
1046
|
}
|
|
1047
|
-
function
|
|
1047
|
+
function Et(t) {
|
|
1048
1048
|
return `https://${window.HG_IFRAME_HOST ?? "sdk.hellgate.io"}/web/${t}/iframe/`;
|
|
1049
1049
|
}
|
|
1050
1050
|
const F = /* @__PURE__ */ new Map();
|
|
1051
|
+
class gt extends x {
|
|
1052
|
+
constructor() {
|
|
1053
|
+
super(...arguments), Object.defineProperty(this, "type", {
|
|
1054
|
+
enumerable: !0,
|
|
1055
|
+
configurable: !0,
|
|
1056
|
+
writable: !0,
|
|
1057
|
+
value: "cardExpirationMonth"
|
|
1058
|
+
}), Object.defineProperty(this, "extractValue", {
|
|
1059
|
+
enumerable: !0,
|
|
1060
|
+
configurable: !0,
|
|
1061
|
+
writable: !0,
|
|
1062
|
+
value: we
|
|
1063
|
+
}), Object.defineProperty(this, "putValue", {
|
|
1064
|
+
enumerable: !0,
|
|
1065
|
+
configurable: !0,
|
|
1066
|
+
writable: !0,
|
|
1067
|
+
value: Ee
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1051
1071
|
function we(t) {
|
|
1052
|
-
|
|
1053
|
-
|
|
1072
|
+
return t ? Number(t) : null;
|
|
1073
|
+
}
|
|
1074
|
+
function Ee(t) {
|
|
1075
|
+
return t ? t < 10 ? `0${t}` : String(t) : null;
|
|
1076
|
+
}
|
|
1077
|
+
class At extends x {
|
|
1078
|
+
constructor() {
|
|
1079
|
+
super(...arguments), Object.defineProperty(this, "type", {
|
|
1080
|
+
enumerable: !0,
|
|
1081
|
+
configurable: !0,
|
|
1082
|
+
writable: !0,
|
|
1083
|
+
value: "cardExpirationYear"
|
|
1084
|
+
}), Object.defineProperty(this, "extractValue", {
|
|
1085
|
+
enumerable: !0,
|
|
1086
|
+
configurable: !0,
|
|
1087
|
+
writable: !0,
|
|
1088
|
+
value: ge
|
|
1089
|
+
}), Object.defineProperty(this, "putValue", {
|
|
1090
|
+
enumerable: !0,
|
|
1091
|
+
configurable: !0,
|
|
1092
|
+
writable: !0,
|
|
1093
|
+
value: Ae
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1054
1096
|
}
|
|
1055
1097
|
function ge(t) {
|
|
1098
|
+
if (!t)
|
|
1099
|
+
return null;
|
|
1100
|
+
const e = Number(t);
|
|
1101
|
+
return e > 10 ? +`20${e}` : null;
|
|
1102
|
+
}
|
|
1103
|
+
function Ae(t) {
|
|
1104
|
+
return t ? t >= 100 ? String(t).slice(-2) : String(t) : null;
|
|
1105
|
+
}
|
|
1106
|
+
function _e(t) {
|
|
1107
|
+
const [e = null, r = null] = (t ?? "").split("/").map((n) => n.trim());
|
|
1108
|
+
return {
|
|
1109
|
+
month: we(e),
|
|
1110
|
+
year: ge(r)
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
function Se(t) {
|
|
1056
1114
|
if (!t)
|
|
1057
1115
|
return null;
|
|
1058
1116
|
const { month: e, year: r } = t;
|
|
1059
|
-
return [
|
|
1060
|
-
e && e < 10 ? `0${e}` : e,
|
|
1061
|
-
r && r >= 100 ? String(r).slice(-2) : r
|
|
1062
|
-
].filter(ye).join(" / ");
|
|
1117
|
+
return [Ee(e), Ae(r)].filter(ye).join(" / ");
|
|
1063
1118
|
}
|
|
1064
|
-
class
|
|
1119
|
+
class _t extends x {
|
|
1065
1120
|
constructor() {
|
|
1066
1121
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1067
1122
|
enumerable: !0,
|
|
@@ -1072,22 +1127,22 @@ class bt extends R {
|
|
|
1072
1127
|
enumerable: !0,
|
|
1073
1128
|
configurable: !0,
|
|
1074
1129
|
writable: !0,
|
|
1075
|
-
value:
|
|
1130
|
+
value: _e
|
|
1076
1131
|
}), Object.defineProperty(this, "putValue", {
|
|
1077
1132
|
enumerable: !0,
|
|
1078
1133
|
configurable: !0,
|
|
1079
1134
|
writable: !0,
|
|
1080
|
-
value:
|
|
1135
|
+
value: Se
|
|
1081
1136
|
});
|
|
1082
1137
|
}
|
|
1083
1138
|
}
|
|
1084
|
-
function
|
|
1139
|
+
function Ce(t) {
|
|
1085
1140
|
return (t == null ? void 0 : t.replaceAll(" ", "")) ?? null;
|
|
1086
1141
|
}
|
|
1087
|
-
function
|
|
1142
|
+
function St(t) {
|
|
1088
1143
|
return t;
|
|
1089
1144
|
}
|
|
1090
|
-
class
|
|
1145
|
+
class Ct extends x {
|
|
1091
1146
|
constructor() {
|
|
1092
1147
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1093
1148
|
enumerable: !0,
|
|
@@ -1098,16 +1153,16 @@ class wt extends R {
|
|
|
1098
1153
|
enumerable: !0,
|
|
1099
1154
|
configurable: !0,
|
|
1100
1155
|
writable: !0,
|
|
1101
|
-
value:
|
|
1156
|
+
value: Ce
|
|
1102
1157
|
}), Object.defineProperty(this, "putValue", {
|
|
1103
1158
|
enumerable: !0,
|
|
1104
1159
|
configurable: !0,
|
|
1105
1160
|
writable: !0,
|
|
1106
|
-
value:
|
|
1161
|
+
value: St
|
|
1107
1162
|
});
|
|
1108
1163
|
}
|
|
1109
1164
|
}
|
|
1110
|
-
class
|
|
1165
|
+
class Pt extends x {
|
|
1111
1166
|
constructor() {
|
|
1112
1167
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1113
1168
|
enumerable: !0,
|
|
@@ -1119,8 +1174,8 @@ class gt extends R {
|
|
|
1119
1174
|
configurable: !0,
|
|
1120
1175
|
writable: !0,
|
|
1121
1176
|
value: (e) => e ? {
|
|
1122
|
-
number: e.cardNumber ?
|
|
1123
|
-
expiry_date: e.cardExpirationDate ?
|
|
1177
|
+
number: e.cardNumber ? Ce(e.cardNumber) : null,
|
|
1178
|
+
expiry_date: e.cardExpirationDate ? _e(e.cardExpirationDate) : null,
|
|
1124
1179
|
cvc: e.cardVerificationCode ?? null
|
|
1125
1180
|
} : null
|
|
1126
1181
|
}), Object.defineProperty(this, "putValue", {
|
|
@@ -1129,13 +1184,13 @@ class gt extends R {
|
|
|
1129
1184
|
writable: !0,
|
|
1130
1185
|
value: (e) => e ? {
|
|
1131
1186
|
cardNumber: e.number ? e.number : null,
|
|
1132
|
-
cardExpirationDate: e.expiry_date ?
|
|
1187
|
+
cardExpirationDate: e.expiry_date ? Se(e.expiry_date) : null,
|
|
1133
1188
|
cardVerificationCode: e.cvc ?? null
|
|
1134
1189
|
} : null
|
|
1135
1190
|
});
|
|
1136
1191
|
}
|
|
1137
1192
|
}
|
|
1138
|
-
class
|
|
1193
|
+
class vt extends x {
|
|
1139
1194
|
constructor() {
|
|
1140
1195
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1141
1196
|
enumerable: !0,
|
|
@@ -1155,7 +1210,7 @@ class Et extends R {
|
|
|
1155
1210
|
});
|
|
1156
1211
|
}
|
|
1157
1212
|
}
|
|
1158
|
-
class
|
|
1213
|
+
class Pe extends x {
|
|
1159
1214
|
constructor() {
|
|
1160
1215
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1161
1216
|
enumerable: !0,
|
|
@@ -1175,23 +1230,27 @@ class Ae extends R {
|
|
|
1175
1230
|
});
|
|
1176
1231
|
}
|
|
1177
1232
|
}
|
|
1178
|
-
function
|
|
1233
|
+
function v(t, e, r) {
|
|
1179
1234
|
switch (t) {
|
|
1180
1235
|
case "card":
|
|
1181
|
-
return new
|
|
1236
|
+
return new Pt(e, r);
|
|
1182
1237
|
case "cardNumber":
|
|
1183
|
-
return new
|
|
1238
|
+
return new Ct(e, r);
|
|
1184
1239
|
case "cardExpirationDate":
|
|
1185
|
-
return new
|
|
1240
|
+
return new _t(e, r);
|
|
1241
|
+
case "cardExpirationMonth":
|
|
1242
|
+
return new gt(e, r);
|
|
1243
|
+
case "cardExpirationYear":
|
|
1244
|
+
return new At(e, r);
|
|
1186
1245
|
case "cardVerificationCode":
|
|
1187
|
-
return new
|
|
1246
|
+
return new vt(e, r);
|
|
1188
1247
|
case "text":
|
|
1189
|
-
return new
|
|
1248
|
+
return new Pe(e, r);
|
|
1190
1249
|
default:
|
|
1191
1250
|
ASSERT_EXHAUSTIVE(t);
|
|
1192
1251
|
}
|
|
1193
1252
|
}
|
|
1194
|
-
function
|
|
1253
|
+
function Ot() {
|
|
1195
1254
|
return Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
1196
1255
|
}
|
|
1197
1256
|
function te(t) {
|
|
@@ -1201,9 +1260,9 @@ function te(t) {
|
|
|
1201
1260
|
t.account_number_last_four
|
|
1202
1261
|
].join(" ");
|
|
1203
1262
|
}
|
|
1204
|
-
class
|
|
1263
|
+
class q {
|
|
1205
1264
|
static async init(e) {
|
|
1206
|
-
return new
|
|
1265
|
+
return new q(e);
|
|
1207
1266
|
}
|
|
1208
1267
|
constructor(e) {
|
|
1209
1268
|
Object.defineProperty(this, "session", {
|
|
@@ -1244,10 +1303,10 @@ class X {
|
|
|
1244
1303
|
var s;
|
|
1245
1304
|
if (this.hasFormElements())
|
|
1246
1305
|
throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
|
|
1247
|
-
const n =
|
|
1306
|
+
const n = K.get(this);
|
|
1248
1307
|
if (!n)
|
|
1249
1308
|
throw new Error("Secure key not found");
|
|
1250
|
-
const i =
|
|
1309
|
+
const i = C({
|
|
1251
1310
|
disabled: !1,
|
|
1252
1311
|
autocomplete: "on",
|
|
1253
1312
|
style: { ...L }
|
|
@@ -1263,85 +1322,26 @@ class X {
|
|
|
1263
1322
|
cvc: null
|
|
1264
1323
|
};
|
|
1265
1324
|
}
|
|
1266
|
-
const a =
|
|
1325
|
+
const a = v("card", i, n);
|
|
1267
1326
|
return this.cardElements.card = {
|
|
1268
1327
|
element: a,
|
|
1269
1328
|
state: this.createFieldDefaultState()
|
|
1270
1329
|
}, this.addElementStateListener("card"), a;
|
|
1271
1330
|
}
|
|
1272
|
-
}), Object.defineProperty(this, "createFormFields", {
|
|
1273
|
-
enumerable: !0,
|
|
1274
|
-
configurable: !0,
|
|
1275
|
-
writable: !0,
|
|
1276
|
-
value: (r = {}) => {
|
|
1277
|
-
var _, S;
|
|
1278
|
-
if (this.hasFormElements())
|
|
1279
|
-
throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
|
|
1280
|
-
const n = H.get(this);
|
|
1281
|
-
if (!n)
|
|
1282
|
-
throw new Error("Secure key not found");
|
|
1283
|
-
const i = {
|
|
1284
|
-
disabled: this.cvcOnlyEnabled,
|
|
1285
|
-
autocomplete: "on",
|
|
1286
|
-
style: { ...L }
|
|
1287
|
-
}, { cardNumber: a = {}, expiryDate: s = {}, securityCode: o = {}, ...c } = r, u = T("cardNumber", {
|
|
1288
|
-
...v(i, {
|
|
1289
|
-
...c,
|
|
1290
|
-
...a,
|
|
1291
|
-
cvcOnly: this.cvcOnlyEnabled,
|
|
1292
|
-
value: this.session.isNextAction("refresh_security_code") && ((_ = this.session.state) != null && _.data) ? te(this.session.state.data) : null
|
|
1293
|
-
})
|
|
1294
|
-
}, n), d = T("cardExpirationDate", {
|
|
1295
|
-
...v(i, {
|
|
1296
|
-
...c,
|
|
1297
|
-
...s,
|
|
1298
|
-
value: this.session.isNextAction("refresh_security_code") && ((S = this.session.state) != null && S.data) ? {
|
|
1299
|
-
month: this.session.state.data.expiry_month,
|
|
1300
|
-
year: this.session.state.data.expiry_year
|
|
1301
|
-
} : null
|
|
1302
|
-
})
|
|
1303
|
-
}, n), l = T("cardVerificationCode", {
|
|
1304
|
-
...v({
|
|
1305
|
-
...i,
|
|
1306
|
-
disabled: !1,
|
|
1307
|
-
autofocus: this.cvcOnlyEnabled
|
|
1308
|
-
}, {
|
|
1309
|
-
...c,
|
|
1310
|
-
...o
|
|
1311
|
-
})
|
|
1312
|
-
}, n);
|
|
1313
|
-
return u.on("change", (p) => {
|
|
1314
|
-
const b = p.cardBrand;
|
|
1315
|
-
l.update({ cardType: b });
|
|
1316
|
-
}), this.cardElements = {
|
|
1317
|
-
cardNumber: {
|
|
1318
|
-
element: u,
|
|
1319
|
-
state: this.createFieldDefaultState()
|
|
1320
|
-
},
|
|
1321
|
-
cardExpirationDate: {
|
|
1322
|
-
element: d,
|
|
1323
|
-
state: this.createFieldDefaultState()
|
|
1324
|
-
},
|
|
1325
|
-
cardVerificationCode: {
|
|
1326
|
-
element: l,
|
|
1327
|
-
state: this.createFieldDefaultState()
|
|
1328
|
-
}
|
|
1329
|
-
}, this.addElementStateListener("cardNumber"), this.addElementStateListener("cardExpirationDate"), this.addElementStateListener("cardVerificationCode"), { cardNumber: u, expiryDate: d, securityCode: l };
|
|
1330
|
-
}
|
|
1331
1331
|
}), Object.defineProperty(this, "createTextField", {
|
|
1332
1332
|
enumerable: !0,
|
|
1333
1333
|
configurable: !0,
|
|
1334
1334
|
writable: !0,
|
|
1335
1335
|
value: (r = {}) => {
|
|
1336
|
-
const n =
|
|
1336
|
+
const n = K.get(this);
|
|
1337
1337
|
if (!n)
|
|
1338
1338
|
throw new Error("Secure key not found");
|
|
1339
1339
|
const i = {
|
|
1340
1340
|
disabled: !1,
|
|
1341
1341
|
autocomplete: "on",
|
|
1342
1342
|
style: { ...L }
|
|
1343
|
-
}, a =
|
|
1344
|
-
...
|
|
1343
|
+
}, a = v("text", {
|
|
1344
|
+
...C(i, { ...r })
|
|
1345
1345
|
}, n);
|
|
1346
1346
|
return this.textElements.push(a), a;
|
|
1347
1347
|
}
|
|
@@ -1420,7 +1420,88 @@ class X {
|
|
|
1420
1420
|
throw this.disableFormElements(!1), n;
|
|
1421
1421
|
}
|
|
1422
1422
|
}
|
|
1423
|
-
}),
|
|
1423
|
+
}), K.set(this, Ot()), this.cvcOnlyEnabled = this.session.isNextAction("refresh_security_code");
|
|
1424
|
+
}
|
|
1425
|
+
createFormFields(e = {}) {
|
|
1426
|
+
var u, d;
|
|
1427
|
+
if (this.hasFormElements())
|
|
1428
|
+
throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
|
|
1429
|
+
const r = K.get(this);
|
|
1430
|
+
if (!r)
|
|
1431
|
+
throw new Error("Secure key not found");
|
|
1432
|
+
const n = {
|
|
1433
|
+
disabled: this.cvcOnlyEnabled,
|
|
1434
|
+
autocomplete: "on",
|
|
1435
|
+
style: { ...L }
|
|
1436
|
+
}, { cardNumber: i = {}, securityCode: a = {}, ...s } = e, o = v("cardNumber", {
|
|
1437
|
+
...C(n, {
|
|
1438
|
+
...s,
|
|
1439
|
+
...i,
|
|
1440
|
+
cvcOnly: this.cvcOnlyEnabled,
|
|
1441
|
+
value: this.session.isNextAction("refresh_security_code") && ((u = this.session.state) != null && u.data) ? te(this.session.state.data) : null
|
|
1442
|
+
})
|
|
1443
|
+
}, r), c = v("cardVerificationCode", {
|
|
1444
|
+
...C({
|
|
1445
|
+
...n,
|
|
1446
|
+
disabled: !1,
|
|
1447
|
+
autofocus: this.cvcOnlyEnabled
|
|
1448
|
+
}, {
|
|
1449
|
+
...s,
|
|
1450
|
+
...a
|
|
1451
|
+
})
|
|
1452
|
+
}, r);
|
|
1453
|
+
if (o.on("change", (h) => {
|
|
1454
|
+
const p = h.cardBrand;
|
|
1455
|
+
c.update({ cardType: p });
|
|
1456
|
+
}), this.cardElements = {
|
|
1457
|
+
cardNumber: {
|
|
1458
|
+
element: o,
|
|
1459
|
+
state: this.createFieldDefaultState()
|
|
1460
|
+
},
|
|
1461
|
+
cardVerificationCode: {
|
|
1462
|
+
element: c,
|
|
1463
|
+
state: this.createFieldDefaultState()
|
|
1464
|
+
}
|
|
1465
|
+
}, this.addElementStateListener("cardNumber"), this.addElementStateListener("cardVerificationCode"), e.expiryDateElement === "separate") {
|
|
1466
|
+
const { expiryMonth: h = {}, expiryYear: p = {} } = e, E = v("cardExpirationMonth", {
|
|
1467
|
+
...C(n, {
|
|
1468
|
+
...s,
|
|
1469
|
+
...h
|
|
1470
|
+
})
|
|
1471
|
+
}, r), l = v("cardExpirationYear", {
|
|
1472
|
+
...C(n, {
|
|
1473
|
+
...s,
|
|
1474
|
+
...p
|
|
1475
|
+
})
|
|
1476
|
+
}, r);
|
|
1477
|
+
return l.on("change", () => {
|
|
1478
|
+
const m = y(this, l);
|
|
1479
|
+
E.update({
|
|
1480
|
+
expiryYear: m ? String(y(this, l)) : void 0
|
|
1481
|
+
});
|
|
1482
|
+
}), this.cardElements.cardExpirationMonth = {
|
|
1483
|
+
element: E,
|
|
1484
|
+
state: this.createFieldDefaultState()
|
|
1485
|
+
}, this.cardElements.cardExpirationYear = {
|
|
1486
|
+
element: l,
|
|
1487
|
+
state: this.createFieldDefaultState()
|
|
1488
|
+
}, this.addElementStateListener("cardExpirationMonth"), this.addElementStateListener("cardExpirationYear"), { cardNumber: o, expiryMonth: E, expiryYear: l, securityCode: c };
|
|
1489
|
+
} else {
|
|
1490
|
+
const { expiryDate: h = {} } = e, p = v("cardExpirationDate", {
|
|
1491
|
+
...C(n, {
|
|
1492
|
+
...s,
|
|
1493
|
+
...h,
|
|
1494
|
+
value: this.session.isNextAction("refresh_security_code") && ((d = this.session.state) != null && d.data) ? {
|
|
1495
|
+
month: this.session.state.data.expiry_month,
|
|
1496
|
+
year: this.session.state.data.expiry_year
|
|
1497
|
+
} : null
|
|
1498
|
+
})
|
|
1499
|
+
}, r);
|
|
1500
|
+
return this.cardElements.cardExpirationDate = {
|
|
1501
|
+
element: p,
|
|
1502
|
+
state: this.createFieldDefaultState()
|
|
1503
|
+
}, this.addElementStateListener("cardExpirationDate"), { cardNumber: o, expiryDate: p, securityCode: c };
|
|
1504
|
+
}
|
|
1424
1505
|
}
|
|
1425
1506
|
async refreshSecurityCode() {
|
|
1426
1507
|
const e = this.getFormValue();
|
|
@@ -1440,24 +1521,33 @@ class X {
|
|
|
1440
1521
|
});
|
|
1441
1522
|
}
|
|
1442
1523
|
getFormValue() {
|
|
1443
|
-
var
|
|
1444
|
-
const { card: e, cardNumber: r, cardExpirationDate: n,
|
|
1445
|
-
let
|
|
1524
|
+
var c, u, d, h, p, E;
|
|
1525
|
+
const { card: e, cardNumber: r, cardExpirationDate: n, cardExpirationMonth: i, cardExpirationYear: a, cardVerificationCode: s } = this.cardElements;
|
|
1526
|
+
let o;
|
|
1446
1527
|
if (e) {
|
|
1447
|
-
const l =
|
|
1448
|
-
|
|
1528
|
+
const l = y(this, e.element);
|
|
1529
|
+
o = {
|
|
1449
1530
|
number: (l == null ? void 0 : l.number) ?? null,
|
|
1450
|
-
expiration_month: ((
|
|
1451
|
-
expiration_year: ((
|
|
1531
|
+
expiration_month: ((c = l == null ? void 0 : l.expiry_date) == null ? void 0 : c.month) ?? null,
|
|
1532
|
+
expiration_year: ((u = l == null ? void 0 : l.expiry_date) == null ? void 0 : u.year) ?? null,
|
|
1452
1533
|
cvc: (l == null ? void 0 : l.cvc) ?? null
|
|
1453
1534
|
};
|
|
1454
1535
|
}
|
|
1455
|
-
|
|
1456
|
-
number: ((
|
|
1457
|
-
expiration_month: ((
|
|
1458
|
-
expiration_year: ((
|
|
1459
|
-
cvc:
|
|
1460
|
-
}), a
|
|
1536
|
+
if (r && s && (n && (o = {
|
|
1537
|
+
number: ((d = y(this, r.element)) == null ? void 0 : d.replaceAll(" ", "")) ?? null,
|
|
1538
|
+
expiration_month: ((h = y(this, n.element)) == null ? void 0 : h.month) ?? null,
|
|
1539
|
+
expiration_year: ((p = y(this, n.element)) == null ? void 0 : p.year) ?? null,
|
|
1540
|
+
cvc: y(this, s.element)
|
|
1541
|
+
}), i && a)) {
|
|
1542
|
+
const l = y(this, i.element), m = y(this, a.element);
|
|
1543
|
+
o = {
|
|
1544
|
+
number: ((E = y(this, r.element)) == null ? void 0 : E.replaceAll(" ", "")) ?? null,
|
|
1545
|
+
expiration_month: l ? Number(l) : null,
|
|
1546
|
+
expiration_year: m ? Number(m) : null,
|
|
1547
|
+
cvc: y(this, s.element)
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
return o;
|
|
1461
1551
|
}
|
|
1462
1552
|
hasFormElements() {
|
|
1463
1553
|
return !!Object.keys(this.cardElements).length;
|
|
@@ -1469,19 +1559,19 @@ class X {
|
|
|
1469
1559
|
}
|
|
1470
1560
|
extractAdditionalData({ cardholder_name: e, billing_address: r = {} }) {
|
|
1471
1561
|
return re({
|
|
1472
|
-
cardholder_name:
|
|
1562
|
+
cardholder_name: H(this, e),
|
|
1473
1563
|
billing_address: {
|
|
1474
|
-
line1:
|
|
1475
|
-
line2:
|
|
1476
|
-
line3:
|
|
1477
|
-
city:
|
|
1478
|
-
postal_code:
|
|
1564
|
+
line1: H(this, r.line1),
|
|
1565
|
+
line2: H(this, r.line2),
|
|
1566
|
+
line3: H(this, r.line3),
|
|
1567
|
+
city: H(this, r.city),
|
|
1568
|
+
postal_code: H(this, r.postal_code)
|
|
1479
1569
|
}
|
|
1480
1570
|
});
|
|
1481
1571
|
}
|
|
1482
1572
|
async encryptCardData(e, r) {
|
|
1483
|
-
const n = await
|
|
1484
|
-
return { enc_payload: await new
|
|
1573
|
+
const n = await nt(r, "RSA-OAEP"), i = JSON.stringify(e), a = new TextEncoder().encode(i);
|
|
1574
|
+
return { enc_payload: await new bt(a).setProtectedHeader({ alg: "RSA-OAEP", enc: "A256GCM" }).encrypt(n) };
|
|
1485
1575
|
}
|
|
1486
1576
|
addElementStateListener(e) {
|
|
1487
1577
|
const r = this.cardElements[e];
|
|
@@ -1511,16 +1601,16 @@ class X {
|
|
|
1511
1601
|
return new Error(`Card data is not valid. ${this.state.error}`);
|
|
1512
1602
|
}
|
|
1513
1603
|
}
|
|
1514
|
-
const
|
|
1515
|
-
function
|
|
1516
|
-
const r =
|
|
1604
|
+
const K = /* @__PURE__ */ new Map();
|
|
1605
|
+
function y(t, e) {
|
|
1606
|
+
const r = K.get(t);
|
|
1517
1607
|
return r ? e.secureValue(r) : null;
|
|
1518
1608
|
}
|
|
1519
|
-
function
|
|
1520
|
-
const r =
|
|
1521
|
-
return e instanceof
|
|
1609
|
+
function H(t, e) {
|
|
1610
|
+
const r = K.get(t);
|
|
1611
|
+
return e instanceof Pe && r ? y(t, e) ?? void 0 : e;
|
|
1522
1612
|
}
|
|
1523
|
-
class
|
|
1613
|
+
class xt {
|
|
1524
1614
|
constructor(e = "https://api.hellgate.io", r = new AbortController()) {
|
|
1525
1615
|
Object.defineProperty(this, "abortCtrl", {
|
|
1526
1616
|
enumerable: !0,
|
|
@@ -1554,8 +1644,8 @@ class _t {
|
|
|
1554
1644
|
this.abortCtrl.abort();
|
|
1555
1645
|
}
|
|
1556
1646
|
}
|
|
1557
|
-
const
|
|
1558
|
-
class
|
|
1647
|
+
const Ht = 2e3;
|
|
1648
|
+
class Kt {
|
|
1559
1649
|
constructor(e, r) {
|
|
1560
1650
|
Object.defineProperty(this, "id", {
|
|
1561
1651
|
enumerable: !0,
|
|
@@ -1623,7 +1713,7 @@ class Ct {
|
|
|
1623
1713
|
const o = this.onStateChange((c) => {
|
|
1624
1714
|
c.next_action !== (i == null ? void 0 : i.next_action) && c.next_action === null && (a(B(c)), o());
|
|
1625
1715
|
});
|
|
1626
|
-
this.api.completeAction(this.id, n).then((c) => this.newStateHandle(c, s)).catch(async (c) => s(await
|
|
1716
|
+
this.api.completeAction(this.id, n).then((c) => this.newStateHandle(c, s)).catch(async (c) => s(await Tt(c)));
|
|
1627
1717
|
});
|
|
1628
1718
|
}
|
|
1629
1719
|
}), Object.defineProperty(this, "completeSession", {
|
|
@@ -1659,24 +1749,24 @@ class Ct {
|
|
|
1659
1749
|
case "wait": {
|
|
1660
1750
|
window.clearTimeout(this.pollingTimer), this.pollingTimer = window.setTimeout(() => this.updateSessionState(r).catch((i) => {
|
|
1661
1751
|
i instanceof Response && i.status === 404 && (r == null || r(new Error(`Session ${this.id} has expired`)));
|
|
1662
|
-
}),
|
|
1752
|
+
}), Ht);
|
|
1663
1753
|
break;
|
|
1664
1754
|
}
|
|
1665
1755
|
}
|
|
1666
1756
|
e.next_action !== ((n = this.state) == null ? void 0 : n.next_action) && this.stateChangeHandlers.forEach((i) => i(e)), e.next_action === null && this.completeSession(B(e)), this.state = e;
|
|
1667
1757
|
}
|
|
1668
1758
|
}
|
|
1669
|
-
async function
|
|
1759
|
+
async function Tt(t) {
|
|
1670
1760
|
return !t.ok && t.status >= 400 && t.status <= 500 ? t.json() : t;
|
|
1671
1761
|
}
|
|
1672
1762
|
function B(t) {
|
|
1673
1763
|
const e = { ...t };
|
|
1674
1764
|
return delete e.next_action, e;
|
|
1675
1765
|
}
|
|
1676
|
-
const
|
|
1766
|
+
const Dt = {
|
|
1677
1767
|
base_url: "https://api.hellgate.io"
|
|
1678
1768
|
};
|
|
1679
|
-
class
|
|
1769
|
+
class ve {
|
|
1680
1770
|
constructor(e, r) {
|
|
1681
1771
|
Object.defineProperty(this, "session", {
|
|
1682
1772
|
enumerable: !0,
|
|
@@ -1709,25 +1799,25 @@ class _e {
|
|
|
1709
1799
|
}
|
|
1710
1800
|
static async init(e, r = {}) {
|
|
1711
1801
|
const { session: n, cardHandler: i, handler3DS: a } = await this.initHandlers(e, r);
|
|
1712
|
-
return new
|
|
1802
|
+
return new ve(n, {
|
|
1713
1803
|
CARD: i,
|
|
1714
1804
|
"3DS": a
|
|
1715
1805
|
});
|
|
1716
1806
|
}
|
|
1717
1807
|
static async initHandlers(e, r) {
|
|
1718
1808
|
const n = {
|
|
1719
|
-
...
|
|
1809
|
+
...Dt,
|
|
1720
1810
|
...r
|
|
1721
|
-
}, i = new
|
|
1811
|
+
}, i = new xt(n.base_url, n.abortCtrl), a = new Kt(e, i);
|
|
1722
1812
|
await a.init();
|
|
1723
1813
|
const s = a.isNextAction("tokenize_card") || a.isNextAction("refresh_security_code") ? await this.createCardHandler(a) : void 0, o = this.create3DSHandler(a, r);
|
|
1724
1814
|
return { session: a, cardHandler: s, handler3DS: o };
|
|
1725
1815
|
}
|
|
1726
1816
|
static createCardHandler(e) {
|
|
1727
|
-
return
|
|
1817
|
+
return q.init(e);
|
|
1728
1818
|
}
|
|
1729
1819
|
static create3DSHandler(e, r) {
|
|
1730
|
-
return new
|
|
1820
|
+
return new He(e, {
|
|
1731
1821
|
domContainer: r.challenge_3ds_container,
|
|
1732
1822
|
labelText: r.challenge_3ds_label_text
|
|
1733
1823
|
});
|
|
@@ -1735,18 +1825,18 @@ class _e {
|
|
|
1735
1825
|
}
|
|
1736
1826
|
globalThis.HellgateSDK && (globalThis.Hellgate = globalThis.HellgateSDK.Hellgate, delete globalThis.HellgateSDK);
|
|
1737
1827
|
export {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1828
|
+
Pt as CardElement,
|
|
1829
|
+
_t as CardExpirationDateElement,
|
|
1830
|
+
Ct as CardNumberElement,
|
|
1831
|
+
vt as CardVerificationCodeElement,
|
|
1832
|
+
ve as Hellgate,
|
|
1833
|
+
He as Hellgate3DSHandler,
|
|
1834
|
+
q as HellgateCardHandler,
|
|
1835
|
+
Pe as TextElement,
|
|
1836
|
+
v as createElement,
|
|
1837
|
+
Ce as extractCardNumberValue,
|
|
1838
|
+
_e as extractExpiryDateValue,
|
|
1839
|
+
St as putCardNumberValue,
|
|
1840
|
+
Se as putExpiryDateValue,
|
|
1841
|
+
Ot as uid
|
|
1752
1842
|
};
|