@starfish-codes/hellgate 3.8.1 → 3.9.1
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/3ds/typings.d.ts +1 -0
- package/dist/__tests__/test-utils.d.ts +11 -0
- package/dist/card/card-handler.d.ts +30 -8
- package/dist/card/coordinator/card-handler-coordinator.d.ts +34 -0
- package/dist/card/coordinator/index.d.ts +2 -0
- package/dist/card/coordinator/typings.d.ts +36 -0
- package/dist/card/typings.d.ts +14 -3
- package/dist/card/ui/elements/base-element.d.ts +3 -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 +5 -2
- package/dist/card/ui/iframe/elements/base-element.d.ts +3 -2
- 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/iframe/elements/text-element.d.ts +1 -0
- package/dist/card/ui/iframe/index.d.ts +1 -0
- package/dist/card/ui/iframe/utils.d.ts +1 -0
- package/dist/card/ui/typings.d.ts +10 -6
- package/dist/coordinator/coordinator.d.ts +38 -0
- package/dist/coordinator/iframe/constants.d.ts +1 -0
- package/dist/coordinator/iframe/iframe-coordinator.d.ts +33 -0
- package/dist/coordinator/iframe/iframe.d.ts +1 -0
- package/dist/coordinator/iframe/index.d.ts +2 -0
- package/dist/coordinator/index.d.ts +3 -0
- package/dist/coordinator/typings.d.ts +39 -0
- package/dist/hellgate-sdk.mjs +515 -1132
- package/dist/hellgate-sdk.umd.js +1 -1
- package/dist/hellgate.d.ts +5 -2
- package/dist/session/session.d.ts +1 -1
- package/dist/utils.d.ts +1 -0
- package/package.json +6 -5
package/dist/hellgate-sdk.mjs
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
function
|
|
2
|
-
return Array.isArray(
|
|
1
|
+
function x(i) {
|
|
2
|
+
return Array.isArray(i) ? i.filter(Boolean) : Object.fromEntries(Object.entries(i).map(([e, t]) => [
|
|
3
3
|
e,
|
|
4
|
-
typeof
|
|
5
|
-
]).filter(([e,
|
|
4
|
+
typeof t == "object" && t && !Array.isArray(t) ? x(t) : t
|
|
5
|
+
]).filter(([e, t]) => typeof t == "object" && t && !Array.isArray(t) ? !!Object.keys(t).length : t != null && t != null));
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
for (const
|
|
10
|
-
const a =
|
|
11
|
-
typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (
|
|
7
|
+
function h(i, e) {
|
|
8
|
+
const t = { ...i, ...e }, r = Object.keys(t);
|
|
9
|
+
for (const n of r) {
|
|
10
|
+
const a = i[n], s = e[n];
|
|
11
|
+
typeof a == "object" && !Array.isArray(a) && a && typeof s == "object" && !Array.isArray(s) && s && (t[n] = h(a, s));
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
function E(i) {
|
|
16
|
+
if (!i.ok)
|
|
17
|
+
throw i;
|
|
18
|
+
return i.json();
|
|
14
19
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
throw t;
|
|
18
|
-
return t.json();
|
|
20
|
+
function C(i) {
|
|
21
|
+
return `https://${window.HG_IFRAME_HOST ?? "sdk.hellgate.io"}/web/${i}/iframe/`;
|
|
19
22
|
}
|
|
20
|
-
const
|
|
21
|
-
class
|
|
22
|
-
constructor(e,
|
|
23
|
+
const N = 2e3;
|
|
24
|
+
class F {
|
|
25
|
+
constructor(e, t) {
|
|
23
26
|
Object.defineProperty(this, "session", {
|
|
24
27
|
enumerable: !0,
|
|
25
28
|
configurable: !0,
|
|
@@ -79,40 +82,40 @@ class Pe {
|
|
|
79
82
|
enumerable: !0,
|
|
80
83
|
configurable: !0,
|
|
81
84
|
writable: !0,
|
|
82
|
-
value: (
|
|
83
|
-
this.decoupledAuthHandlers.push(
|
|
85
|
+
value: (r) => {
|
|
86
|
+
this.decoupledAuthHandlers.push(r);
|
|
84
87
|
}
|
|
85
88
|
}), Object.defineProperty(this, "onStartChallenge", {
|
|
86
89
|
enumerable: !0,
|
|
87
90
|
configurable: !0,
|
|
88
91
|
writable: !0,
|
|
89
|
-
value: (
|
|
90
|
-
this.onStartHandler =
|
|
92
|
+
value: (r) => {
|
|
93
|
+
this.onStartHandler = r;
|
|
91
94
|
}
|
|
92
95
|
}), Object.defineProperty(this, "onChallengeFinished", {
|
|
93
96
|
enumerable: !0,
|
|
94
97
|
configurable: !0,
|
|
95
98
|
writable: !0,
|
|
96
|
-
value: (
|
|
97
|
-
this.onFinishHandler =
|
|
99
|
+
value: (r) => {
|
|
100
|
+
this.onFinishHandler = r;
|
|
98
101
|
}
|
|
99
102
|
}), Object.defineProperty(this, "sessionStateHandle", {
|
|
100
103
|
enumerable: !0,
|
|
101
104
|
configurable: !0,
|
|
102
105
|
writable: !0,
|
|
103
|
-
value: (
|
|
104
|
-
var
|
|
105
|
-
switch (
|
|
106
|
+
value: (r) => {
|
|
107
|
+
var n, a;
|
|
108
|
+
switch (r.next_action) {
|
|
106
109
|
case "3ds_check": {
|
|
107
|
-
this.initCheck3DSIframes(
|
|
110
|
+
this.initCheck3DSIframes(r.data.threeds_server_callback_url, r.data.mon_url);
|
|
108
111
|
break;
|
|
109
112
|
}
|
|
110
113
|
case "3ds_challenge": {
|
|
111
|
-
(
|
|
114
|
+
(n = this.onStartHandler) == null || n.call(this), this.disposeCheck3DSIframe(), this.startChallenge(r.data.challenge_url, r.data.result_mon_url);
|
|
112
115
|
break;
|
|
113
116
|
}
|
|
114
117
|
case "3ds_challenge_decoupled": {
|
|
115
|
-
this.startDecoupledAuth(
|
|
118
|
+
this.startDecoupledAuth(r.data.cardholder_info, r.data.result_mon_url, r.data.transaction_id);
|
|
116
119
|
break;
|
|
117
120
|
}
|
|
118
121
|
case null: {
|
|
@@ -121,820 +124,98 @@ class Pe {
|
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
|
-
}), this.domContainer =
|
|
127
|
+
}), this.domContainer = t.domContainer ?? p(), this.disposers.push(this.session.onStateChange(this.sessionStateHandle)), this.labelText = t.labelText;
|
|
125
128
|
}
|
|
126
129
|
dispose() {
|
|
127
130
|
this.disposers.forEach((e) => e()), this.check3dsIframeDisposers.forEach((e) => e());
|
|
128
131
|
}
|
|
129
|
-
initCheck3DSIframes(e,
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
132
|
+
initCheck3DSIframes(e, t) {
|
|
133
|
+
const r = p();
|
|
134
|
+
r.insertAdjacentHTML("beforeend", `<iframe id="check_3ds_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${e}"></iframe>`);
|
|
135
|
+
const n = r.querySelector(`#check_3ds_${this.iframeId}`);
|
|
136
|
+
if (n) {
|
|
134
137
|
const a = (s) => {
|
|
135
|
-
s.source ===
|
|
138
|
+
s.source === n.contentWindow && this.session.completeAction({ action: "3ds_check", result: s.data });
|
|
136
139
|
};
|
|
137
|
-
window.addEventListener("message", a), this.check3dsIframeDisposers.push(() => window.removeEventListener("message", a), () =>
|
|
140
|
+
window.addEventListener("message", a), this.check3dsIframeDisposers.push(() => window.removeEventListener("message", a), () => n.remove());
|
|
138
141
|
}
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
const a =
|
|
142
|
+
if (t) {
|
|
143
|
+
r.insertAdjacentHTML("beforeend", `<iframe id="mon_${this.iframeId}" width="0" height="0" style="border:0;visibility: hidden;" src="${t}"></iframe>`);
|
|
144
|
+
const a = r.querySelector(`#mon_${this.iframeId}`);
|
|
142
145
|
a && this.disposers.push(() => a.remove());
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
disposeCheck3DSIframe() {
|
|
146
149
|
this.check3dsIframeDisposers.forEach((e) => e()), this.check3dsIframeDisposers = [];
|
|
147
150
|
}
|
|
148
|
-
startChallenge(e,
|
|
149
|
-
const
|
|
150
|
-
this.domContainer.insertAdjacentHTML("beforeend", this.domContainer ===
|
|
151
|
+
startChallenge(e, t) {
|
|
152
|
+
const r = p(), n = `<div style="display: flex; flex-direction: column; gap: 10px; align-items: center; ${this.domContainer === r ? '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>`;
|
|
153
|
+
this.domContainer.insertAdjacentHTML("beforeend", this.domContainer === r ? `<div id="cha_${this.iframeId}_wrap" style="background: #fff; position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 10000;">${n}</div>` : n);
|
|
151
154
|
const a = this.domContainer.querySelector(`#cha_${this.iframeId}`), s = this.domContainer.querySelector(`#cha_${this.iframeId}_wrap`);
|
|
152
155
|
if (!a)
|
|
153
156
|
throw new Error("3DS Challenge Iframe initialization failed");
|
|
154
157
|
this.disposers.push(() => {
|
|
155
158
|
a.remove(), s == null || s.remove();
|
|
156
159
|
});
|
|
157
|
-
const o = new Promise((
|
|
158
|
-
const d = (
|
|
159
|
-
|
|
160
|
+
const o = new Promise((c) => {
|
|
161
|
+
const d = (u) => {
|
|
162
|
+
u.source !== a.contentWindow || u.data.event !== "AuthResultReady" || c({
|
|
163
|
+
...u.data,
|
|
164
|
+
requestor_trans_id: u.data.requestor_trans_id ?? u.data.requestorTransId,
|
|
165
|
+
// TODO: remove this field after the backend is updated
|
|
166
|
+
requestorTransId: void 0,
|
|
167
|
+
param: u.data.param || void 0
|
|
168
|
+
});
|
|
160
169
|
};
|
|
161
170
|
window.addEventListener("message", d), this.disposers.push(() => window.removeEventListener("message", d));
|
|
162
|
-
}),
|
|
163
|
-
const d = this.startAuthResultPolling(
|
|
164
|
-
|
|
165
|
-
requestor_trans_id:
|
|
166
|
-
event:
|
|
171
|
+
}), l = new Promise((c) => {
|
|
172
|
+
const d = this.startAuthResultPolling(t, (u) => {
|
|
173
|
+
u.event === "AuthResultReady" && (d(), c({
|
|
174
|
+
requestor_trans_id: u.threeDSRequestorTransID,
|
|
175
|
+
event: u.event
|
|
167
176
|
}));
|
|
168
177
|
});
|
|
169
178
|
});
|
|
170
|
-
Promise.any([o,
|
|
179
|
+
Promise.any([o, l]).then((c) => {
|
|
171
180
|
this.session.completeAction({
|
|
172
181
|
action: "3ds_challenge",
|
|
173
|
-
result:
|
|
182
|
+
result: c
|
|
174
183
|
});
|
|
175
184
|
});
|
|
176
185
|
}
|
|
177
|
-
startDecoupledAuth(e,
|
|
178
|
-
this.transactionId || (this.transactionId =
|
|
179
|
-
const
|
|
186
|
+
startDecoupledAuth(e, t, r) {
|
|
187
|
+
this.transactionId || (this.transactionId = r), this.decoupledAuthHandlers.forEach((a) => a(e));
|
|
188
|
+
const n = this.startAuthResultPolling(t, (a) => {
|
|
180
189
|
a.event === "AuthResultReady" && (this.session.completeAction({
|
|
181
190
|
action: "3ds_challenge_decoupled",
|
|
182
191
|
result: { ...a, event: a.event }
|
|
183
|
-
}),
|
|
192
|
+
}), n());
|
|
184
193
|
});
|
|
185
194
|
}
|
|
186
|
-
startAuthResultPolling(e,
|
|
187
|
-
return window.clearTimeout(this.resultPollingTimer), this.resultPollingTimer = window.setTimeout(() => fetch(e).then((
|
|
188
|
-
this.startAuthResultPolling(e,
|
|
195
|
+
startAuthResultPolling(e, t) {
|
|
196
|
+
return window.clearTimeout(this.resultPollingTimer), this.resultPollingTimer = window.setTimeout(() => fetch(e).then((r) => E(r)).then((r) => {
|
|
197
|
+
this.startAuthResultPolling(e, t), t(r);
|
|
189
198
|
}).catch(() => {
|
|
190
|
-
}),
|
|
199
|
+
}), N), () => window.clearTimeout(this.resultPollingTimer);
|
|
191
200
|
}
|
|
192
201
|
}
|
|
193
|
-
function
|
|
202
|
+
function p() {
|
|
194
203
|
return document.body;
|
|
195
204
|
}
|
|
196
|
-
const
|
|
197
|
-
const r = `SHA-${t.slice(-3)}`;
|
|
198
|
-
return new Uint8Array(await h.subtle.digest(r, e));
|
|
199
|
-
}, C = new TextEncoder(), ne = new TextDecoder(), I = 2 ** 32;
|
|
200
|
-
function D(...t) {
|
|
201
|
-
const e = t.reduce((i, { length: a }) => i + a, 0), r = new Uint8Array(e);
|
|
202
|
-
let n = 0;
|
|
203
|
-
for (const i of t)
|
|
204
|
-
r.set(i, n), n += i.length;
|
|
205
|
-
return r;
|
|
206
|
-
}
|
|
207
|
-
function Oe(t, e) {
|
|
208
|
-
return D(C.encode(t), new Uint8Array([0]), e);
|
|
209
|
-
}
|
|
210
|
-
function J(t, e, r) {
|
|
211
|
-
if (e < 0 || e >= I)
|
|
212
|
-
throw new RangeError(`value must be >= 0 and <= ${I - 1}. Received ${e}`);
|
|
213
|
-
t.set([e >>> 24, e >>> 16, e >>> 8, e & 255], r);
|
|
214
|
-
}
|
|
215
|
-
function He(t) {
|
|
216
|
-
const e = Math.floor(t / I), r = t % I, n = new Uint8Array(8);
|
|
217
|
-
return J(n, e, 0), J(n, r, 4), n;
|
|
218
|
-
}
|
|
219
|
-
function k(t) {
|
|
220
|
-
const e = new Uint8Array(4);
|
|
221
|
-
return J(e, t), e;
|
|
222
|
-
}
|
|
223
|
-
function U(t) {
|
|
224
|
-
return D(k(t.length), t);
|
|
225
|
-
}
|
|
226
|
-
async function xe(t, e, r) {
|
|
227
|
-
const n = Math.ceil((e >> 3) / 32), i = new Uint8Array(n * 32);
|
|
228
|
-
for (let a = 0; a < n; a++) {
|
|
229
|
-
const s = new Uint8Array(4 + t.length + r.length);
|
|
230
|
-
s.set(k(a + 1)), s.set(t, 4), s.set(r, 4 + t.length), i.set(await ve("sha256", s), a * 32);
|
|
231
|
-
}
|
|
232
|
-
return i.slice(0, e >> 3);
|
|
233
|
-
}
|
|
234
|
-
const Ke = (t) => {
|
|
235
|
-
let e = t;
|
|
236
|
-
typeof e == "string" && (e = C.encode(e));
|
|
237
|
-
const r = 32768, n = [];
|
|
238
|
-
for (let i = 0; i < e.length; i += r)
|
|
239
|
-
n.push(String.fromCharCode.apply(null, e.subarray(i, i + r)));
|
|
240
|
-
return btoa(n.join(""));
|
|
241
|
-
}, m = (t) => Ke(t).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"), Te = (t) => {
|
|
242
|
-
const e = atob(t), r = new Uint8Array(e.length);
|
|
243
|
-
for (let n = 0; n < e.length; n++)
|
|
244
|
-
r[n] = e.charCodeAt(n);
|
|
245
|
-
return r;
|
|
246
|
-
}, ie = (t) => {
|
|
247
|
-
let e = t;
|
|
248
|
-
e instanceof Uint8Array && (e = ne.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
249
|
-
try {
|
|
250
|
-
return Te(e);
|
|
251
|
-
} catch {
|
|
252
|
-
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
class ae extends Error {
|
|
256
|
-
static get code() {
|
|
257
|
-
return "ERR_JOSE_GENERIC";
|
|
258
|
-
}
|
|
259
|
-
constructor(e) {
|
|
260
|
-
var r;
|
|
261
|
-
super(e), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
class f extends ae {
|
|
265
|
-
constructor() {
|
|
266
|
-
super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
267
|
-
}
|
|
268
|
-
static get code() {
|
|
269
|
-
return "ERR_JOSE_NOT_SUPPORTED";
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
class A extends ae {
|
|
273
|
-
constructor() {
|
|
274
|
-
super(...arguments), this.code = "ERR_JWE_INVALID";
|
|
275
|
-
}
|
|
276
|
-
static get code() {
|
|
277
|
-
return "ERR_JWE_INVALID";
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const q = h.getRandomValues.bind(h);
|
|
281
|
-
function se(t) {
|
|
282
|
-
switch (t) {
|
|
283
|
-
case "A128GCM":
|
|
284
|
-
case "A128GCMKW":
|
|
285
|
-
case "A192GCM":
|
|
286
|
-
case "A192GCMKW":
|
|
287
|
-
case "A256GCM":
|
|
288
|
-
case "A256GCMKW":
|
|
289
|
-
return 96;
|
|
290
|
-
case "A128CBC-HS256":
|
|
291
|
-
case "A192CBC-HS384":
|
|
292
|
-
case "A256CBC-HS512":
|
|
293
|
-
return 128;
|
|
294
|
-
default:
|
|
295
|
-
throw new f(`Unsupported JWE Algorithm: ${t}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const De = (t) => q(new Uint8Array(se(t) >> 3)), Re = (t, e) => {
|
|
299
|
-
if (e.length << 3 !== se(t))
|
|
300
|
-
throw new A("Invalid Initialization Vector length");
|
|
301
|
-
}, Z = (t, e) => {
|
|
302
|
-
const r = t.byteLength << 3;
|
|
303
|
-
if (r !== e)
|
|
304
|
-
throw new A(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`);
|
|
305
|
-
};
|
|
306
|
-
function E(t, e = "algorithm.name") {
|
|
307
|
-
return new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);
|
|
308
|
-
}
|
|
309
|
-
function j(t, e) {
|
|
310
|
-
return t.name === e;
|
|
311
|
-
}
|
|
312
|
-
function je(t) {
|
|
313
|
-
return parseInt(t.name.slice(4), 10);
|
|
314
|
-
}
|
|
315
|
-
function Ie(t, e) {
|
|
316
|
-
if (e.length && !e.some((r) => t.usages.includes(r))) {
|
|
317
|
-
let r = "CryptoKey does not support this operation, its usages must include ";
|
|
318
|
-
if (e.length > 2) {
|
|
319
|
-
const n = e.pop();
|
|
320
|
-
r += `one of ${e.join(", ")}, or ${n}.`;
|
|
321
|
-
} else e.length === 2 ? r += `one of ${e[0]} or ${e[1]}.` : r += `${e[0]}.`;
|
|
322
|
-
throw new TypeError(r);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
function x(t, e, ...r) {
|
|
326
|
-
switch (e) {
|
|
327
|
-
case "A128GCM":
|
|
328
|
-
case "A192GCM":
|
|
329
|
-
case "A256GCM": {
|
|
330
|
-
if (!j(t.algorithm, "AES-GCM"))
|
|
331
|
-
throw E("AES-GCM");
|
|
332
|
-
const n = parseInt(e.slice(1, 4), 10);
|
|
333
|
-
if (t.algorithm.length !== n)
|
|
334
|
-
throw E(n, "algorithm.length");
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
case "A128KW":
|
|
338
|
-
case "A192KW":
|
|
339
|
-
case "A256KW": {
|
|
340
|
-
if (!j(t.algorithm, "AES-KW"))
|
|
341
|
-
throw E("AES-KW");
|
|
342
|
-
const n = parseInt(e.slice(1, 4), 10);
|
|
343
|
-
if (t.algorithm.length !== n)
|
|
344
|
-
throw E(n, "algorithm.length");
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case "ECDH": {
|
|
348
|
-
switch (t.algorithm.name) {
|
|
349
|
-
case "ECDH":
|
|
350
|
-
case "X25519":
|
|
351
|
-
case "X448":
|
|
352
|
-
break;
|
|
353
|
-
default:
|
|
354
|
-
throw E("ECDH, X25519, or X448");
|
|
355
|
-
}
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
case "PBES2-HS256+A128KW":
|
|
359
|
-
case "PBES2-HS384+A192KW":
|
|
360
|
-
case "PBES2-HS512+A256KW":
|
|
361
|
-
if (!j(t.algorithm, "PBKDF2"))
|
|
362
|
-
throw E("PBKDF2");
|
|
363
|
-
break;
|
|
364
|
-
case "RSA-OAEP":
|
|
365
|
-
case "RSA-OAEP-256":
|
|
366
|
-
case "RSA-OAEP-384":
|
|
367
|
-
case "RSA-OAEP-512": {
|
|
368
|
-
if (!j(t.algorithm, "RSA-OAEP"))
|
|
369
|
-
throw E("RSA-OAEP");
|
|
370
|
-
const n = parseInt(e.slice(9), 10) || 1;
|
|
371
|
-
if (je(t.algorithm.hash) !== n)
|
|
372
|
-
throw E(`SHA-${n}`, "algorithm.hash");
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
default:
|
|
376
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
377
|
-
}
|
|
378
|
-
Ie(t, r);
|
|
379
|
-
}
|
|
380
|
-
function oe(t, e, ...r) {
|
|
381
|
-
var n;
|
|
382
|
-
if (r.length > 2) {
|
|
383
|
-
const i = r.pop();
|
|
384
|
-
t += `one of type ${r.join(", ")}, or ${i}.`;
|
|
385
|
-
} else r.length === 2 ? t += `one of type ${r[0]} or ${r[1]}.` : t += `of type ${r[0]}.`;
|
|
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
|
-
}
|
|
388
|
-
const g = (t, ...e) => oe("Key must be ", t, ...e);
|
|
389
|
-
function ce(t, e, ...r) {
|
|
390
|
-
return oe(`Key for the ${t} algorithm must be `, e, ...r);
|
|
391
|
-
}
|
|
392
|
-
const le = (t) => w(t) ? !0 : (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", y = ["CryptoKey"], Me = (...t) => {
|
|
393
|
-
const e = t.filter(Boolean);
|
|
394
|
-
if (e.length === 0 || e.length === 1)
|
|
395
|
-
return !0;
|
|
396
|
-
let r;
|
|
397
|
-
for (const n of e) {
|
|
398
|
-
const i = Object.keys(n);
|
|
399
|
-
if (!r || r.size === 0) {
|
|
400
|
-
r = new Set(i);
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
for (const a of i) {
|
|
404
|
-
if (r.has(a))
|
|
405
|
-
return !1;
|
|
406
|
-
r.add(a);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return !0;
|
|
410
|
-
};
|
|
411
|
-
function Ue(t) {
|
|
412
|
-
return typeof t == "object" && t !== null;
|
|
413
|
-
}
|
|
414
|
-
function $e(t) {
|
|
415
|
-
if (!Ue(t) || Object.prototype.toString.call(t) !== "[object Object]")
|
|
416
|
-
return !1;
|
|
417
|
-
if (Object.getPrototypeOf(t) === null)
|
|
418
|
-
return !0;
|
|
419
|
-
let e = t;
|
|
420
|
-
for (; Object.getPrototypeOf(e) !== null; )
|
|
421
|
-
e = Object.getPrototypeOf(e);
|
|
422
|
-
return Object.getPrototypeOf(t) === e;
|
|
423
|
-
}
|
|
424
|
-
const ue = [
|
|
425
|
-
{ hash: "SHA-256", name: "HMAC" },
|
|
426
|
-
!0,
|
|
427
|
-
["sign"]
|
|
428
|
-
];
|
|
429
|
-
function We(t, e) {
|
|
430
|
-
if (t.algorithm.length !== parseInt(e.slice(1, 4), 10))
|
|
431
|
-
throw new TypeError(`Invalid key size for alg: ${e}`);
|
|
432
|
-
}
|
|
433
|
-
function Ne(t, e, r) {
|
|
434
|
-
if (w(t))
|
|
435
|
-
return x(t, e, r), t;
|
|
436
|
-
if (t instanceof Uint8Array)
|
|
437
|
-
return h.subtle.importKey("raw", t, "AES-KW", !0, [r]);
|
|
438
|
-
throw new TypeError(g(t, ...y, "Uint8Array"));
|
|
439
|
-
}
|
|
440
|
-
const z = async (t, e, r) => {
|
|
441
|
-
const n = await Ne(e, t, "wrapKey");
|
|
442
|
-
We(n, t);
|
|
443
|
-
const i = await h.subtle.importKey("raw", r, ...ue);
|
|
444
|
-
return new Uint8Array(await h.subtle.wrapKey("raw", i, n, "AES-KW"));
|
|
445
|
-
};
|
|
446
|
-
async function Le(t, e, r, n, i = new Uint8Array(0), a = new Uint8Array(0)) {
|
|
447
|
-
if (!w(t))
|
|
448
|
-
throw new TypeError(g(t, ...y));
|
|
449
|
-
if (x(t, "ECDH"), !w(e))
|
|
450
|
-
throw new TypeError(g(e, ...y));
|
|
451
|
-
x(e, "ECDH", "deriveBits");
|
|
452
|
-
const s = D(U(C.encode(r)), U(i), U(a), k(n));
|
|
453
|
-
let o;
|
|
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 h.subtle.deriveBits({
|
|
456
|
-
name: t.algorithm.name,
|
|
457
|
-
public: t
|
|
458
|
-
}, e, o));
|
|
459
|
-
return xe(c, n, s);
|
|
460
|
-
}
|
|
461
|
-
async function Fe(t) {
|
|
462
|
-
if (!w(t))
|
|
463
|
-
throw new TypeError(g(t, ...y));
|
|
464
|
-
return h.subtle.generateKey(t.algorithm, !0, ["deriveBits"]);
|
|
465
|
-
}
|
|
466
|
-
function Be(t) {
|
|
467
|
-
if (!w(t))
|
|
468
|
-
throw new TypeError(g(t, ...y));
|
|
469
|
-
return ["P-256", "P-384", "P-521"].includes(t.algorithm.namedCurve) || t.algorithm.name === "X25519" || t.algorithm.name === "X448";
|
|
470
|
-
}
|
|
471
|
-
function Ve(t) {
|
|
472
|
-
if (!(t instanceof Uint8Array) || t.length < 8)
|
|
473
|
-
throw new A("PBES2 Salt Input must be 8 or more octets");
|
|
474
|
-
}
|
|
475
|
-
function Je(t, e) {
|
|
476
|
-
if (t instanceof Uint8Array)
|
|
477
|
-
return h.subtle.importKey("raw", t, "PBKDF2", !1, ["deriveBits"]);
|
|
478
|
-
if (w(t))
|
|
479
|
-
return x(t, e, "deriveBits", "deriveKey"), t;
|
|
480
|
-
throw new TypeError(g(t, ...y, "Uint8Array"));
|
|
481
|
-
}
|
|
482
|
-
async function ze(t, e, r, n) {
|
|
483
|
-
Ve(t);
|
|
484
|
-
const i = Oe(e, t), a = parseInt(e.slice(13, 16), 10), s = {
|
|
485
|
-
hash: `SHA-${e.slice(8, 11)}`,
|
|
486
|
-
iterations: r,
|
|
487
|
-
name: "PBKDF2",
|
|
488
|
-
salt: i
|
|
489
|
-
}, o = {
|
|
490
|
-
length: a,
|
|
491
|
-
name: "AES-KW"
|
|
492
|
-
}, c = await Je(n, e);
|
|
493
|
-
if (c.usages.includes("deriveBits"))
|
|
494
|
-
return new Uint8Array(await h.subtle.deriveBits(s, c, a));
|
|
495
|
-
if (c.usages.includes("deriveKey"))
|
|
496
|
-
return h.subtle.deriveKey(s, c, o, !1, ["wrapKey", "unwrapKey"]);
|
|
497
|
-
throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
|
|
498
|
-
}
|
|
499
|
-
const Ge = async (t, e, r, n = 2048, i = q(new Uint8Array(16))) => {
|
|
500
|
-
const a = await ze(i, t, n, e);
|
|
501
|
-
return { encryptedKey: await z(t.slice(-6), a, r), p2c: n, p2s: m(i) };
|
|
502
|
-
};
|
|
503
|
-
function Q(t) {
|
|
504
|
-
switch (t) {
|
|
505
|
-
case "RSA-OAEP":
|
|
506
|
-
case "RSA-OAEP-256":
|
|
507
|
-
case "RSA-OAEP-384":
|
|
508
|
-
case "RSA-OAEP-512":
|
|
509
|
-
return "RSA-OAEP";
|
|
510
|
-
default:
|
|
511
|
-
throw new f(`alg ${t} is not supported either by JOSE or your javascript runtime`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const ke = (t, e) => {
|
|
515
|
-
if (t.startsWith("RS") || t.startsWith("PS")) {
|
|
516
|
-
const { modulusLength: r } = e.algorithm;
|
|
517
|
-
if (typeof r != "number" || r < 2048)
|
|
518
|
-
throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`);
|
|
519
|
-
}
|
|
520
|
-
}, qe = async (t, e, r) => {
|
|
521
|
-
if (!w(e))
|
|
522
|
-
throw new TypeError(g(e, ...y));
|
|
523
|
-
if (x(e, t, "encrypt", "wrapKey"), ke(t, e), e.usages.includes("encrypt"))
|
|
524
|
-
return new Uint8Array(await h.subtle.encrypt(Q(t), e, r));
|
|
525
|
-
if (e.usages.includes("wrapKey")) {
|
|
526
|
-
const n = await h.subtle.importKey("raw", r, ...ue);
|
|
527
|
-
return new Uint8Array(await h.subtle.wrapKey("raw", n, e, Q(t)));
|
|
528
|
-
}
|
|
529
|
-
throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
|
|
530
|
-
};
|
|
531
|
-
function Xe(t) {
|
|
532
|
-
let e, r;
|
|
533
|
-
switch (t.kty) {
|
|
534
|
-
case "RSA": {
|
|
535
|
-
switch (t.alg) {
|
|
536
|
-
case "PS256":
|
|
537
|
-
case "PS384":
|
|
538
|
-
case "PS512":
|
|
539
|
-
e = { name: "RSA-PSS", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
|
|
540
|
-
break;
|
|
541
|
-
case "RS256":
|
|
542
|
-
case "RS384":
|
|
543
|
-
case "RS512":
|
|
544
|
-
e = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
|
|
545
|
-
break;
|
|
546
|
-
case "RSA-OAEP":
|
|
547
|
-
case "RSA-OAEP-256":
|
|
548
|
-
case "RSA-OAEP-384":
|
|
549
|
-
case "RSA-OAEP-512":
|
|
550
|
-
e = {
|
|
551
|
-
name: "RSA-OAEP",
|
|
552
|
-
hash: `SHA-${parseInt(t.alg.slice(-3), 10) || 1}`
|
|
553
|
-
}, r = t.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
554
|
-
break;
|
|
555
|
-
default:
|
|
556
|
-
throw new f('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
557
|
-
}
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
case "EC": {
|
|
561
|
-
switch (t.alg) {
|
|
562
|
-
case "ES256":
|
|
563
|
-
e = { name: "ECDSA", namedCurve: "P-256" }, r = t.d ? ["sign"] : ["verify"];
|
|
564
|
-
break;
|
|
565
|
-
case "ES384":
|
|
566
|
-
e = { name: "ECDSA", namedCurve: "P-384" }, r = t.d ? ["sign"] : ["verify"];
|
|
567
|
-
break;
|
|
568
|
-
case "ES512":
|
|
569
|
-
e = { name: "ECDSA", namedCurve: "P-521" }, r = t.d ? ["sign"] : ["verify"];
|
|
570
|
-
break;
|
|
571
|
-
case "ECDH-ES":
|
|
572
|
-
case "ECDH-ES+A128KW":
|
|
573
|
-
case "ECDH-ES+A192KW":
|
|
574
|
-
case "ECDH-ES+A256KW":
|
|
575
|
-
e = { name: "ECDH", namedCurve: t.crv }, r = t.d ? ["deriveBits"] : [];
|
|
576
|
-
break;
|
|
577
|
-
default:
|
|
578
|
-
throw new f('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
579
|
-
}
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
case "OKP": {
|
|
583
|
-
switch (t.alg) {
|
|
584
|
-
case "EdDSA":
|
|
585
|
-
e = { name: t.crv }, r = t.d ? ["sign"] : ["verify"];
|
|
586
|
-
break;
|
|
587
|
-
case "ECDH-ES":
|
|
588
|
-
case "ECDH-ES+A128KW":
|
|
589
|
-
case "ECDH-ES+A192KW":
|
|
590
|
-
case "ECDH-ES+A256KW":
|
|
591
|
-
e = { name: t.crv }, r = t.d ? ["deriveBits"] : [];
|
|
592
|
-
break;
|
|
593
|
-
default:
|
|
594
|
-
throw new f('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
595
|
-
}
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
default:
|
|
599
|
-
throw new f('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
600
|
-
}
|
|
601
|
-
return { algorithm: e, keyUsages: r };
|
|
602
|
-
}
|
|
603
|
-
const de = async (t) => {
|
|
604
|
-
if (!t.alg)
|
|
605
|
-
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
606
|
-
const { algorithm: e, keyUsages: r } = Xe(t), n = [
|
|
607
|
-
e,
|
|
608
|
-
t.ext ?? !1,
|
|
609
|
-
t.key_ops ?? r
|
|
610
|
-
], i = { ...t };
|
|
611
|
-
return delete i.alg, delete i.use, h.subtle.importKey("jwk", i, ...n);
|
|
612
|
-
}, he = (t) => ie(t);
|
|
613
|
-
let $, W;
|
|
614
|
-
const fe = (t) => (t == null ? void 0 : t[Symbol.toStringTag]) === "KeyObject", pe = async (t, e, r, n) => {
|
|
615
|
-
let i = t.get(e);
|
|
616
|
-
if (i != null && i[n])
|
|
617
|
-
return i[n];
|
|
618
|
-
const a = await de({ ...r, alg: n });
|
|
619
|
-
return i ? i[n] = a : t.set(e, { [n]: a }), a;
|
|
620
|
-
}, Ye = (t, e) => {
|
|
621
|
-
if (fe(t)) {
|
|
622
|
-
let r = t.export({ format: "jwk" });
|
|
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
|
-
}
|
|
625
|
-
return t;
|
|
626
|
-
}, Ze = (t, e) => {
|
|
627
|
-
if (fe(t)) {
|
|
628
|
-
let r = t.export({ format: "jwk" });
|
|
629
|
-
return r.k ? he(r.k) : ($ || ($ = /* @__PURE__ */ new WeakMap()), pe($, t, r, e));
|
|
630
|
-
}
|
|
631
|
-
return t;
|
|
632
|
-
}, N = { normalizePublicKey: Ye, normalizePrivateKey: Ze };
|
|
633
|
-
function me(t) {
|
|
634
|
-
switch (t) {
|
|
635
|
-
case "A128GCM":
|
|
636
|
-
return 128;
|
|
637
|
-
case "A192GCM":
|
|
638
|
-
return 192;
|
|
639
|
-
case "A256GCM":
|
|
640
|
-
case "A128CBC-HS256":
|
|
641
|
-
return 256;
|
|
642
|
-
case "A192CBC-HS384":
|
|
643
|
-
return 384;
|
|
644
|
-
case "A256CBC-HS512":
|
|
645
|
-
return 512;
|
|
646
|
-
default:
|
|
647
|
-
throw new f(`Unsupported JWE Algorithm: ${t}`);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
const K = (t) => q(new Uint8Array(me(t) >> 3));
|
|
651
|
-
async function Qe(t, e) {
|
|
652
|
-
if (!$e(t))
|
|
653
|
-
throw new TypeError("JWK must be an object");
|
|
654
|
-
switch (t.kty) {
|
|
655
|
-
case "oct":
|
|
656
|
-
if (typeof t.k != "string" || !t.k)
|
|
657
|
-
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
658
|
-
return ie(t.k);
|
|
659
|
-
case "RSA":
|
|
660
|
-
if (t.oth !== void 0)
|
|
661
|
-
throw new f('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
662
|
-
case "EC":
|
|
663
|
-
case "OKP":
|
|
664
|
-
return de({ ...t, alg: e });
|
|
665
|
-
default:
|
|
666
|
-
throw new f('Unsupported "kty" (Key Type) Parameter value');
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
const G = (t) => t == null ? void 0 : t[Symbol.toStringTag], et = (t, e) => {
|
|
670
|
-
if (!(e instanceof Uint8Array)) {
|
|
671
|
-
if (!le(e))
|
|
672
|
-
throw new TypeError(ce(t, e, ...y, "Uint8Array"));
|
|
673
|
-
if (e.type !== "secret")
|
|
674
|
-
throw new TypeError(`${G(e)} instances for symmetric algorithms must be of type "secret"`);
|
|
675
|
-
}
|
|
676
|
-
}, tt = (t, e, r) => {
|
|
677
|
-
if (!le(e))
|
|
678
|
-
throw new TypeError(ce(t, e, ...y));
|
|
679
|
-
if (e.type === "secret")
|
|
680
|
-
throw new TypeError(`${G(e)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
681
|
-
if (e.algorithm, e.algorithm && r === "encrypt" && e.type === "private")
|
|
682
|
-
throw new TypeError(`${G(e)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
683
|
-
}, rt = (t, e, r) => {
|
|
684
|
-
t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? et(t, e) : tt(t, e, r);
|
|
685
|
-
};
|
|
686
|
-
async function nt(t, e, r, n, i) {
|
|
687
|
-
if (!(r instanceof Uint8Array))
|
|
688
|
-
throw new TypeError(g(r, "Uint8Array"));
|
|
689
|
-
const a = parseInt(t.slice(1, 4), 10), s = await h.subtle.importKey("raw", r.subarray(a >> 3), "AES-CBC", !1, ["encrypt"]), o = await h.subtle.importKey("raw", r.subarray(0, a >> 3), {
|
|
690
|
-
hash: `SHA-${a << 1}`,
|
|
691
|
-
name: "HMAC"
|
|
692
|
-
}, !1, ["sign"]), c = new Uint8Array(await h.subtle.encrypt({
|
|
693
|
-
iv: n,
|
|
694
|
-
name: "AES-CBC"
|
|
695
|
-
}, s, e)), u = D(i, n, c, He(i.length << 3)), d = new Uint8Array((await h.subtle.sign("HMAC", o, u)).slice(0, a >> 3));
|
|
696
|
-
return { ciphertext: c, tag: d, iv: n };
|
|
697
|
-
}
|
|
698
|
-
async function it(t, e, r, n, i) {
|
|
699
|
-
let a;
|
|
700
|
-
r instanceof Uint8Array ? a = await h.subtle.importKey("raw", r, "AES-GCM", !1, ["encrypt"]) : (x(r, t, "encrypt"), a = r);
|
|
701
|
-
const s = new Uint8Array(await h.subtle.encrypt({
|
|
702
|
-
additionalData: i,
|
|
703
|
-
iv: n,
|
|
704
|
-
name: "AES-GCM",
|
|
705
|
-
tagLength: 128
|
|
706
|
-
}, a, e)), o = s.slice(-16);
|
|
707
|
-
return { ciphertext: s.slice(0, -16), tag: o, iv: n };
|
|
708
|
-
}
|
|
709
|
-
const be = async (t, e, r, n, i) => {
|
|
710
|
-
if (!w(r) && !(r instanceof Uint8Array))
|
|
711
|
-
throw new TypeError(g(r, ...y, "Uint8Array"));
|
|
712
|
-
switch (n ? Re(t, n) : n = De(t), t) {
|
|
713
|
-
case "A128CBC-HS256":
|
|
714
|
-
case "A192CBC-HS384":
|
|
715
|
-
case "A256CBC-HS512":
|
|
716
|
-
return r instanceof Uint8Array && Z(r, parseInt(t.slice(-3), 10)), nt(t, e, r, n, i);
|
|
717
|
-
case "A128GCM":
|
|
718
|
-
case "A192GCM":
|
|
719
|
-
case "A256GCM":
|
|
720
|
-
return r instanceof Uint8Array && Z(r, parseInt(t.slice(1, 4), 10)), it(t, e, r, n, i);
|
|
721
|
-
default:
|
|
722
|
-
throw new f("Unsupported JWE Content Encryption Algorithm");
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
async function at(t, e, r, n) {
|
|
726
|
-
const i = t.slice(0, 7), a = await be(i, r, e, n, new Uint8Array(0));
|
|
727
|
-
return {
|
|
728
|
-
encryptedKey: a.ciphertext,
|
|
729
|
-
iv: m(a.iv),
|
|
730
|
-
tag: m(a.tag)
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
function st(t, e, r, n, i) {
|
|
734
|
-
if (i.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
|
|
735
|
-
throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
736
|
-
if (!n || n.crit === void 0)
|
|
737
|
-
return /* @__PURE__ */ new Set();
|
|
738
|
-
if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((s) => typeof s != "string" || s.length === 0))
|
|
739
|
-
throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
740
|
-
let a;
|
|
741
|
-
r !== void 0 ? a = new Map([...Object.entries(r), ...e.entries()]) : a = e;
|
|
742
|
-
for (const s of n.crit) {
|
|
743
|
-
if (!a.has(s))
|
|
744
|
-
throw new f(`Extension Header Parameter "${s}" is not recognized`);
|
|
745
|
-
if (i[s] === void 0)
|
|
746
|
-
throw new t(`Extension Header Parameter "${s}" is missing`);
|
|
747
|
-
if (a.get(s) && n[s] === void 0)
|
|
748
|
-
throw new t(`Extension Header Parameter "${s}" MUST be integrity protected`);
|
|
749
|
-
}
|
|
750
|
-
return new Set(n.crit);
|
|
751
|
-
}
|
|
752
|
-
const ot = async (t) => {
|
|
753
|
-
if (t instanceof Uint8Array)
|
|
754
|
-
return {
|
|
755
|
-
kty: "oct",
|
|
756
|
-
k: m(t)
|
|
757
|
-
};
|
|
758
|
-
if (!w(t))
|
|
759
|
-
throw new TypeError(g(t, ...y, "Uint8Array"));
|
|
760
|
-
if (!t.extractable)
|
|
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 h.subtle.exportKey("jwk", t);
|
|
763
|
-
return a;
|
|
764
|
-
};
|
|
765
|
-
async function ct(t) {
|
|
766
|
-
return ot(t);
|
|
767
|
-
}
|
|
768
|
-
async function lt(t, e, r, n, i = {}) {
|
|
769
|
-
var c;
|
|
770
|
-
let a, s, o;
|
|
771
|
-
switch (rt(t, r, "encrypt"), r = await ((c = N.normalizePublicKey) == null ? void 0 : c.call(N, r, t)) || r, t) {
|
|
772
|
-
case "dir": {
|
|
773
|
-
o = r;
|
|
774
|
-
break;
|
|
775
|
-
}
|
|
776
|
-
case "ECDH-ES":
|
|
777
|
-
case "ECDH-ES+A128KW":
|
|
778
|
-
case "ECDH-ES+A192KW":
|
|
779
|
-
case "ECDH-ES+A256KW": {
|
|
780
|
-
if (!Be(r))
|
|
781
|
-
throw new f("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
782
|
-
const { apu: u, apv: d } = i;
|
|
783
|
-
let { epk: l } = i;
|
|
784
|
-
l || (l = (await Fe(r)).privateKey);
|
|
785
|
-
const { x: _, y: S, crv: p, kty: b } = await ct(l), Y = await Le(r, l, t === "ECDH-ES" ? e : t, t === "ECDH-ES" ? me(e) : parseInt(t.slice(-5, -2), 10), u, d);
|
|
786
|
-
if (s = { epk: { x: _, crv: p, kty: b } }, b === "EC" && (s.epk.y = S), u && (s.apu = m(u)), d && (s.apv = m(d)), t === "ECDH-ES") {
|
|
787
|
-
o = Y;
|
|
788
|
-
break;
|
|
789
|
-
}
|
|
790
|
-
o = n || K(e);
|
|
791
|
-
const Se = t.slice(-6);
|
|
792
|
-
a = await z(Se, Y, o);
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
case "RSA1_5":
|
|
796
|
-
case "RSA-OAEP":
|
|
797
|
-
case "RSA-OAEP-256":
|
|
798
|
-
case "RSA-OAEP-384":
|
|
799
|
-
case "RSA-OAEP-512": {
|
|
800
|
-
o = n || K(e), a = await qe(t, r, o);
|
|
801
|
-
break;
|
|
802
|
-
}
|
|
803
|
-
case "PBES2-HS256+A128KW":
|
|
804
|
-
case "PBES2-HS384+A192KW":
|
|
805
|
-
case "PBES2-HS512+A256KW": {
|
|
806
|
-
o = n || K(e);
|
|
807
|
-
const { p2c: u, p2s: d } = i;
|
|
808
|
-
({ encryptedKey: a, ...s } = await Ge(t, r, o, u, d));
|
|
809
|
-
break;
|
|
810
|
-
}
|
|
811
|
-
case "A128KW":
|
|
812
|
-
case "A192KW":
|
|
813
|
-
case "A256KW": {
|
|
814
|
-
o = n || K(e), a = await z(t, r, o);
|
|
815
|
-
break;
|
|
816
|
-
}
|
|
817
|
-
case "A128GCMKW":
|
|
818
|
-
case "A192GCMKW":
|
|
819
|
-
case "A256GCMKW": {
|
|
820
|
-
o = n || K(e);
|
|
821
|
-
const { iv: u } = i;
|
|
822
|
-
({ encryptedKey: a, ...s } = await at(t, r, o, u));
|
|
823
|
-
break;
|
|
824
|
-
}
|
|
825
|
-
default:
|
|
826
|
-
throw new f('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
827
|
-
}
|
|
828
|
-
return { cek: o, encryptedKey: a, parameters: s };
|
|
829
|
-
}
|
|
830
|
-
const ut = Symbol();
|
|
831
|
-
class dt {
|
|
832
|
-
constructor(e) {
|
|
833
|
-
if (!(e instanceof Uint8Array))
|
|
834
|
-
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
835
|
-
this._plaintext = e;
|
|
836
|
-
}
|
|
837
|
-
setKeyManagementParameters(e) {
|
|
838
|
-
if (this._keyManagementParameters)
|
|
839
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
840
|
-
return this._keyManagementParameters = e, this;
|
|
841
|
-
}
|
|
842
|
-
setProtectedHeader(e) {
|
|
843
|
-
if (this._protectedHeader)
|
|
844
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
845
|
-
return this._protectedHeader = e, this;
|
|
846
|
-
}
|
|
847
|
-
setSharedUnprotectedHeader(e) {
|
|
848
|
-
if (this._sharedUnprotectedHeader)
|
|
849
|
-
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
850
|
-
return this._sharedUnprotectedHeader = e, this;
|
|
851
|
-
}
|
|
852
|
-
setUnprotectedHeader(e) {
|
|
853
|
-
if (this._unprotectedHeader)
|
|
854
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
855
|
-
return this._unprotectedHeader = e, this;
|
|
856
|
-
}
|
|
857
|
-
setAdditionalAuthenticatedData(e) {
|
|
858
|
-
return this._aad = e, this;
|
|
859
|
-
}
|
|
860
|
-
setContentEncryptionKey(e) {
|
|
861
|
-
if (this._cek)
|
|
862
|
-
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
863
|
-
return this._cek = e, this;
|
|
864
|
-
}
|
|
865
|
-
setInitializationVector(e) {
|
|
866
|
-
if (this._iv)
|
|
867
|
-
throw new TypeError("setInitializationVector can only be called once");
|
|
868
|
-
return this._iv = e, this;
|
|
869
|
-
}
|
|
870
|
-
async encrypt(e, r) {
|
|
871
|
-
if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader)
|
|
872
|
-
throw new A("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
873
|
-
if (!Me(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader))
|
|
874
|
-
throw new A("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
875
|
-
const n = {
|
|
876
|
-
...this._protectedHeader,
|
|
877
|
-
...this._unprotectedHeader,
|
|
878
|
-
...this._sharedUnprotectedHeader
|
|
879
|
-
};
|
|
880
|
-
if (st(A, /* @__PURE__ */ new Map(), r == null ? void 0 : r.crit, this._protectedHeader, n), n.zip !== void 0)
|
|
881
|
-
throw new f('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
882
|
-
const { alg: i, enc: a } = n;
|
|
883
|
-
if (typeof i != "string" || !i)
|
|
884
|
-
throw new A('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
885
|
-
if (typeof a != "string" || !a)
|
|
886
|
-
throw new A('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
887
|
-
let s;
|
|
888
|
-
if (this._cek && (i === "dir" || i === "ECDH-ES"))
|
|
889
|
-
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${i}`);
|
|
890
|
-
let o;
|
|
891
|
-
{
|
|
892
|
-
let b;
|
|
893
|
-
({ cek: o, encryptedKey: s, parameters: b } = await lt(i, a, e, this._cek, this._keyManagementParameters)), b && (r && ut in r ? this._unprotectedHeader ? this._unprotectedHeader = { ...this._unprotectedHeader, ...b } : this.setUnprotectedHeader(b) : this._protectedHeader ? this._protectedHeader = { ...this._protectedHeader, ...b } : this.setProtectedHeader(b));
|
|
894
|
-
}
|
|
895
|
-
let c, u, d;
|
|
896
|
-
this._protectedHeader ? u = C.encode(m(JSON.stringify(this._protectedHeader))) : u = C.encode(""), this._aad ? (d = m(this._aad), c = D(u, C.encode("."), C.encode(d))) : c = u;
|
|
897
|
-
const { ciphertext: l, tag: _, iv: S } = await be(a, this._plaintext, o, this._iv, c), p = {
|
|
898
|
-
ciphertext: m(l)
|
|
899
|
-
};
|
|
900
|
-
return S && (p.iv = m(S)), _ && (p.tag = m(_)), s && (p.encrypted_key = m(s)), d && (p.aad = d), this._protectedHeader && (p.protected = ne.decode(u)), this._sharedUnprotectedHeader && (p.unprotected = this._sharedUnprotectedHeader), this._unprotectedHeader && (p.header = this._unprotectedHeader), p;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
class ht {
|
|
904
|
-
constructor(e) {
|
|
905
|
-
this._flattened = new dt(e);
|
|
906
|
-
}
|
|
907
|
-
setContentEncryptionKey(e) {
|
|
908
|
-
return this._flattened.setContentEncryptionKey(e), this;
|
|
909
|
-
}
|
|
910
|
-
setInitializationVector(e) {
|
|
911
|
-
return this._flattened.setInitializationVector(e), this;
|
|
912
|
-
}
|
|
913
|
-
setProtectedHeader(e) {
|
|
914
|
-
return this._flattened.setProtectedHeader(e), this;
|
|
915
|
-
}
|
|
916
|
-
setKeyManagementParameters(e) {
|
|
917
|
-
return this._flattened.setKeyManagementParameters(e), this;
|
|
918
|
-
}
|
|
919
|
-
async encrypt(e, r) {
|
|
920
|
-
const n = await this._flattened.encrypt(e, r);
|
|
921
|
-
return [n.protected, n.encrypted_key, n.iv, n.ciphertext, n.tag].join(".");
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
const L = {
|
|
205
|
+
const y = {
|
|
925
206
|
base: {
|
|
926
207
|
":disabled": {
|
|
927
208
|
backgroundColor: "transparent"
|
|
928
209
|
}
|
|
929
210
|
}
|
|
930
|
-
},
|
|
931
|
-
var
|
|
932
|
-
(function(
|
|
933
|
-
|
|
934
|
-
})(
|
|
935
|
-
const
|
|
936
|
-
class
|
|
937
|
-
constructor(e
|
|
211
|
+
}, k = "DOM Element was not found";
|
|
212
|
+
var O;
|
|
213
|
+
(function(i) {
|
|
214
|
+
i.NOT_COMPLETE = "NOT_COMPLETE", i.SCHEME_NOT_SUPPORTED = "SCHEME_NOT_SUPPORTED", i.LUHN_CHECK_FAILED = "LUHN_CHECK_FAILED", i.INVALID_EXPIRY_DATE = "INVALID_EXPIRY_DATE";
|
|
215
|
+
})(O || (O = {}));
|
|
216
|
+
const S = (i) => i != null, R = "v3.9.1";
|
|
217
|
+
class f {
|
|
218
|
+
constructor(e) {
|
|
938
219
|
if (Object.defineProperty(this, "options", {
|
|
939
220
|
enumerable: !0,
|
|
940
221
|
configurable: !0,
|
|
@@ -955,16 +236,21 @@ class R {
|
|
|
955
236
|
configurable: !0,
|
|
956
237
|
writable: !0,
|
|
957
238
|
value: { ready: [], blur: [], focus: [], keydown: [], change: [] }
|
|
239
|
+
}), Object.defineProperty(this, "key", {
|
|
240
|
+
enumerable: !0,
|
|
241
|
+
configurable: !0,
|
|
242
|
+
writable: !0,
|
|
243
|
+
value: ""
|
|
958
244
|
}), Object.defineProperty(this, "update", {
|
|
959
245
|
enumerable: !0,
|
|
960
246
|
configurable: !0,
|
|
961
247
|
writable: !0,
|
|
962
|
-
value: async ({ ...
|
|
963
|
-
this.iframe &&
|
|
248
|
+
value: async ({ ...t }) => {
|
|
249
|
+
this.iframe && S(t.height) && (this.iframe.height = t.height), this.iframePostMessage({
|
|
964
250
|
type: "update",
|
|
965
251
|
data: {
|
|
966
|
-
...
|
|
967
|
-
value:
|
|
252
|
+
...t,
|
|
253
|
+
value: t.value ? this.putValue(t.value) ?? void 0 : void 0
|
|
968
254
|
}
|
|
969
255
|
});
|
|
970
256
|
}
|
|
@@ -994,74 +280,110 @@ class R {
|
|
|
994
280
|
configurable: !0,
|
|
995
281
|
writable: !0,
|
|
996
282
|
value: () => {
|
|
997
|
-
var
|
|
998
|
-
(
|
|
283
|
+
var t;
|
|
284
|
+
(t = this.iframe) == null || t.remove(), this.iframe = null;
|
|
999
285
|
}
|
|
1000
|
-
}), this.IFRAME_BASE_URL =
|
|
286
|
+
}), this.IFRAME_BASE_URL = C(R), !this.IFRAME_BASE_URL)
|
|
1001
287
|
throw new Error("IFRAME_BASE_URL not found");
|
|
1002
|
-
r && F.set(this, { key: r });
|
|
1003
288
|
}
|
|
1004
289
|
mount(e) {
|
|
1005
|
-
const
|
|
1006
|
-
if (!
|
|
1007
|
-
throw new Error(
|
|
1008
|
-
|
|
1009
|
-
const
|
|
290
|
+
const t = typeof e == "string" ? document.querySelector(e) : e;
|
|
291
|
+
if (!t)
|
|
292
|
+
throw new Error(`${k}: ${e}`);
|
|
293
|
+
t.innerHTML = `<iframe width="100%" height="29" src="${this.IFRAME_BASE_URL}?field=${this.type}&origin=${location.origin}"></iframe>`, this.iframe = t.querySelector("iframe");
|
|
294
|
+
const r = (n) => {
|
|
1010
295
|
var a;
|
|
1011
|
-
|
|
1012
|
-
if (i.data.type === "change") {
|
|
1013
|
-
const s = this.extractValue(i.data.data.value), o = { ...i.data.data };
|
|
1014
|
-
delete o.value;
|
|
1015
|
-
const c = F.get(this);
|
|
1016
|
-
c && (c.value = s), this.emitEvent({
|
|
1017
|
-
...i.data,
|
|
1018
|
-
data: o
|
|
1019
|
-
});
|
|
1020
|
-
} else
|
|
1021
|
-
this.emitEvent(i.data);
|
|
296
|
+
n.source !== ((a = this.iframe) == null ? void 0 : a.contentWindow) || n.data.element !== this.type || this.emitEvent(n.data);
|
|
1022
297
|
};
|
|
1023
|
-
return window.addEventListener("message",
|
|
1024
|
-
this.on("ready", () => {
|
|
1025
|
-
this.update(this.options),
|
|
298
|
+
return window.addEventListener("message", r), new Promise((n) => {
|
|
299
|
+
this.on("ready", (a) => {
|
|
300
|
+
this.key = a.key, this.update(this.options), n();
|
|
1026
301
|
});
|
|
1027
302
|
});
|
|
1028
303
|
}
|
|
1029
|
-
on(e,
|
|
1030
|
-
return this.subscriptions[e].push(
|
|
1031
|
-
unsubscribe: () => this.subscriptions[e].splice(this.subscriptions[e].indexOf(
|
|
304
|
+
on(e, t) {
|
|
305
|
+
return this.subscriptions[e].push(t), {
|
|
306
|
+
unsubscribe: () => this.subscriptions[e].splice(this.subscriptions[e].indexOf(t), 1)
|
|
1032
307
|
};
|
|
1033
308
|
}
|
|
1034
|
-
secureValue(e) {
|
|
1035
|
-
const r = F.get(this);
|
|
1036
|
-
return (r == null ? void 0 : r.key) !== e ? null : (r == null ? void 0 : r.value) ?? null;
|
|
1037
|
-
}
|
|
1038
309
|
emitEvent(e) {
|
|
1039
|
-
var
|
|
1040
|
-
(
|
|
310
|
+
var t;
|
|
311
|
+
(t = this.subscriptions[e.type]) == null || t.forEach((r) => r(e.data));
|
|
1041
312
|
}
|
|
1042
313
|
iframePostMessage(e) {
|
|
1043
|
-
var
|
|
1044
|
-
(
|
|
314
|
+
var t, r;
|
|
315
|
+
(r = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || r.postMessage(e, this.IFRAME_BASE_URL);
|
|
1045
316
|
}
|
|
1046
317
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
318
|
+
class $ extends f {
|
|
319
|
+
constructor() {
|
|
320
|
+
super(...arguments), Object.defineProperty(this, "type", {
|
|
321
|
+
enumerable: !0,
|
|
322
|
+
configurable: !0,
|
|
323
|
+
writable: !0,
|
|
324
|
+
value: "cardExpirationMonth"
|
|
325
|
+
}), Object.defineProperty(this, "extractValue", {
|
|
326
|
+
enumerable: !0,
|
|
327
|
+
configurable: !0,
|
|
328
|
+
writable: !0,
|
|
329
|
+
value: j
|
|
330
|
+
}), Object.defineProperty(this, "putValue", {
|
|
331
|
+
enumerable: !0,
|
|
332
|
+
configurable: !0,
|
|
333
|
+
writable: !0,
|
|
334
|
+
value: A
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function j(i) {
|
|
339
|
+
return i ? Number(i) : null;
|
|
1049
340
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const [e = null, r = null] = (t ?? "").split("/").map((n) => Number(n.trim()));
|
|
1053
|
-
return { month: e, year: r && r > 10 ? +`20${r}` : null };
|
|
341
|
+
function A(i) {
|
|
342
|
+
return i ? i < 10 ? `0${i}` : String(i) : null;
|
|
1054
343
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
344
|
+
class U extends f {
|
|
345
|
+
constructor() {
|
|
346
|
+
super(...arguments), Object.defineProperty(this, "type", {
|
|
347
|
+
enumerable: !0,
|
|
348
|
+
configurable: !0,
|
|
349
|
+
writable: !0,
|
|
350
|
+
value: "cardExpirationYear"
|
|
351
|
+
}), Object.defineProperty(this, "extractValue", {
|
|
352
|
+
enumerable: !0,
|
|
353
|
+
configurable: !0,
|
|
354
|
+
writable: !0,
|
|
355
|
+
value: H
|
|
356
|
+
}), Object.defineProperty(this, "putValue", {
|
|
357
|
+
enumerable: !0,
|
|
358
|
+
configurable: !0,
|
|
359
|
+
writable: !0,
|
|
360
|
+
value: D
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function H(i) {
|
|
365
|
+
if (!i)
|
|
1057
366
|
return null;
|
|
1058
|
-
const
|
|
1059
|
-
return
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
367
|
+
const e = Number(i);
|
|
368
|
+
return e > 10 ? +`20${e}` : null;
|
|
369
|
+
}
|
|
370
|
+
function D(i) {
|
|
371
|
+
return i ? i >= 100 ? String(i).slice(-2) : String(i) : null;
|
|
372
|
+
}
|
|
373
|
+
function T(i) {
|
|
374
|
+
const [e = null, t = null] = (i ?? "").split("/").map((r) => r.trim());
|
|
375
|
+
return {
|
|
376
|
+
month: j(e),
|
|
377
|
+
year: H(t)
|
|
378
|
+
};
|
|
1063
379
|
}
|
|
1064
|
-
|
|
380
|
+
function M(i) {
|
|
381
|
+
if (!i)
|
|
382
|
+
return null;
|
|
383
|
+
const { month: e, year: t } = i;
|
|
384
|
+
return [A(e), D(t)].filter(S).join(" / ");
|
|
385
|
+
}
|
|
386
|
+
class V extends f {
|
|
1065
387
|
constructor() {
|
|
1066
388
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1067
389
|
enumerable: !0,
|
|
@@ -1072,22 +394,22 @@ class bt extends R {
|
|
|
1072
394
|
enumerable: !0,
|
|
1073
395
|
configurable: !0,
|
|
1074
396
|
writable: !0,
|
|
1075
|
-
value:
|
|
397
|
+
value: T
|
|
1076
398
|
}), Object.defineProperty(this, "putValue", {
|
|
1077
399
|
enumerable: !0,
|
|
1078
400
|
configurable: !0,
|
|
1079
401
|
writable: !0,
|
|
1080
|
-
value:
|
|
402
|
+
value: M
|
|
1081
403
|
});
|
|
1082
404
|
}
|
|
1083
405
|
}
|
|
1084
|
-
function
|
|
1085
|
-
return (
|
|
406
|
+
function I(i) {
|
|
407
|
+
return (i == null ? void 0 : i.replaceAll(" ", "")) ?? null;
|
|
1086
408
|
}
|
|
1087
|
-
function
|
|
1088
|
-
return
|
|
409
|
+
function z(i) {
|
|
410
|
+
return i;
|
|
1089
411
|
}
|
|
1090
|
-
class
|
|
412
|
+
class B extends f {
|
|
1091
413
|
constructor() {
|
|
1092
414
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1093
415
|
enumerable: !0,
|
|
@@ -1098,16 +420,16 @@ class wt extends R {
|
|
|
1098
420
|
enumerable: !0,
|
|
1099
421
|
configurable: !0,
|
|
1100
422
|
writable: !0,
|
|
1101
|
-
value:
|
|
423
|
+
value: I
|
|
1102
424
|
}), Object.defineProperty(this, "putValue", {
|
|
1103
425
|
enumerable: !0,
|
|
1104
426
|
configurable: !0,
|
|
1105
427
|
writable: !0,
|
|
1106
|
-
value:
|
|
428
|
+
value: z
|
|
1107
429
|
});
|
|
1108
430
|
}
|
|
1109
431
|
}
|
|
1110
|
-
class
|
|
432
|
+
class Y extends f {
|
|
1111
433
|
constructor() {
|
|
1112
434
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1113
435
|
enumerable: !0,
|
|
@@ -1119,8 +441,8 @@ class gt extends R {
|
|
|
1119
441
|
configurable: !0,
|
|
1120
442
|
writable: !0,
|
|
1121
443
|
value: (e) => e ? {
|
|
1122
|
-
number: e.cardNumber ?
|
|
1123
|
-
expiry_date: e.cardExpirationDate ?
|
|
444
|
+
number: e.cardNumber ? I(e.cardNumber) : null,
|
|
445
|
+
expiry_date: e.cardExpirationDate ? T(e.cardExpirationDate) : null,
|
|
1124
446
|
cvc: e.cardVerificationCode ?? null
|
|
1125
447
|
} : null
|
|
1126
448
|
}), Object.defineProperty(this, "putValue", {
|
|
@@ -1129,13 +451,13 @@ class gt extends R {
|
|
|
1129
451
|
writable: !0,
|
|
1130
452
|
value: (e) => e ? {
|
|
1131
453
|
cardNumber: e.number ? e.number : null,
|
|
1132
|
-
cardExpirationDate: e.expiry_date ?
|
|
454
|
+
cardExpirationDate: e.expiry_date ? M(e.expiry_date) : null,
|
|
1133
455
|
cardVerificationCode: e.cvc ?? null
|
|
1134
456
|
} : null
|
|
1135
457
|
});
|
|
1136
458
|
}
|
|
1137
459
|
}
|
|
1138
|
-
class
|
|
460
|
+
class q extends f {
|
|
1139
461
|
constructor() {
|
|
1140
462
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1141
463
|
enumerable: !0,
|
|
@@ -1155,7 +477,7 @@ class Et extends R {
|
|
|
1155
477
|
});
|
|
1156
478
|
}
|
|
1157
479
|
}
|
|
1158
|
-
class
|
|
480
|
+
class K extends f {
|
|
1159
481
|
constructor() {
|
|
1160
482
|
super(...arguments), Object.defineProperty(this, "type", {
|
|
1161
483
|
enumerable: !0,
|
|
@@ -1175,42 +497,48 @@ class Ae extends R {
|
|
|
1175
497
|
});
|
|
1176
498
|
}
|
|
1177
499
|
}
|
|
1178
|
-
function
|
|
1179
|
-
switch (
|
|
500
|
+
function b(i, e) {
|
|
501
|
+
switch (i) {
|
|
1180
502
|
case "card":
|
|
1181
|
-
return new
|
|
503
|
+
return new Y(e);
|
|
1182
504
|
case "cardNumber":
|
|
1183
|
-
return new
|
|
505
|
+
return new B(e);
|
|
1184
506
|
case "cardExpirationDate":
|
|
1185
|
-
return new
|
|
507
|
+
return new V(e);
|
|
508
|
+
case "cardExpirationMonth":
|
|
509
|
+
return new $(e);
|
|
510
|
+
case "cardExpirationYear":
|
|
511
|
+
return new U(e);
|
|
1186
512
|
case "cardVerificationCode":
|
|
1187
|
-
return new
|
|
513
|
+
return new q(e);
|
|
1188
514
|
case "text":
|
|
1189
|
-
return new
|
|
515
|
+
return new K(e);
|
|
1190
516
|
default:
|
|
1191
|
-
ASSERT_EXHAUSTIVE(
|
|
517
|
+
ASSERT_EXHAUSTIVE(i);
|
|
1192
518
|
}
|
|
1193
519
|
}
|
|
1194
|
-
function
|
|
1195
|
-
return Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
1196
|
-
}
|
|
1197
|
-
function te(t) {
|
|
520
|
+
function P(i) {
|
|
1198
521
|
return [
|
|
1199
|
-
|
|
1200
|
-
"".padEnd(
|
|
1201
|
-
|
|
522
|
+
i.issuer_identification_number,
|
|
523
|
+
"".padEnd(i.account_number_length - i.issuer_identification_number.length - i.account_number_last_four.length, "*"),
|
|
524
|
+
i.account_number_last_four
|
|
1202
525
|
].join(" ");
|
|
1203
526
|
}
|
|
1204
|
-
class
|
|
1205
|
-
static async init(e) {
|
|
1206
|
-
return new
|
|
527
|
+
class w {
|
|
528
|
+
static async init(e, t) {
|
|
529
|
+
return new w(e, t);
|
|
1207
530
|
}
|
|
1208
|
-
constructor(e) {
|
|
531
|
+
constructor(e, t) {
|
|
1209
532
|
Object.defineProperty(this, "session", {
|
|
1210
533
|
enumerable: !0,
|
|
1211
534
|
configurable: !0,
|
|
1212
535
|
writable: !0,
|
|
1213
536
|
value: e
|
|
537
|
+
}), Object.defineProperty(this, "coordinator", {
|
|
538
|
+
enumerable: !0,
|
|
539
|
+
configurable: !0,
|
|
540
|
+
writable: !0,
|
|
541
|
+
value: t
|
|
1214
542
|
}), Object.defineProperty(this, "state", {
|
|
1215
543
|
enumerable: !0,
|
|
1216
544
|
configurable: !0,
|
|
@@ -1244,18 +572,15 @@ class X {
|
|
|
1244
572
|
var s;
|
|
1245
573
|
if (this.hasFormElements())
|
|
1246
574
|
throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
|
|
1247
|
-
const n =
|
|
1248
|
-
if (!n)
|
|
1249
|
-
throw new Error("Secure key not found");
|
|
1250
|
-
const i = v({
|
|
575
|
+
const n = h({
|
|
1251
576
|
disabled: !1,
|
|
1252
577
|
autocomplete: "on",
|
|
1253
|
-
style: { ...
|
|
578
|
+
style: { ...y }
|
|
1254
579
|
}, r);
|
|
1255
580
|
if (this.session.isNextAction("refresh_security_code") && ((s = this.session.state) != null && s.data)) {
|
|
1256
581
|
const o = this.session.state.data;
|
|
1257
|
-
|
|
1258
|
-
number:
|
|
582
|
+
n.cvcOnly = !0, n.value = {
|
|
583
|
+
number: P(o),
|
|
1259
584
|
expiry_date: {
|
|
1260
585
|
month: (o == null ? void 0 : o.expiry_month) ?? null,
|
|
1261
586
|
year: (o == null ? void 0 : o.expiry_year) ?? null
|
|
@@ -1263,86 +588,24 @@ class X {
|
|
|
1263
588
|
cvc: null
|
|
1264
589
|
};
|
|
1265
590
|
}
|
|
1266
|
-
const a =
|
|
591
|
+
const a = b("card", n);
|
|
1267
592
|
return this.cardElements.card = {
|
|
1268
593
|
element: a,
|
|
1269
594
|
state: this.createFieldDefaultState()
|
|
1270
595
|
}, this.addElementStateListener("card"), a;
|
|
1271
596
|
}
|
|
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
597
|
}), Object.defineProperty(this, "createTextField", {
|
|
1332
598
|
enumerable: !0,
|
|
1333
599
|
configurable: !0,
|
|
1334
600
|
writable: !0,
|
|
1335
601
|
value: (r = {}) => {
|
|
1336
|
-
const n =
|
|
1337
|
-
if (!n)
|
|
1338
|
-
throw new Error("Secure key not found");
|
|
1339
|
-
const i = {
|
|
602
|
+
const n = {
|
|
1340
603
|
disabled: !1,
|
|
1341
604
|
autocomplete: "on",
|
|
1342
|
-
style: { ...
|
|
1343
|
-
}, a =
|
|
1344
|
-
...
|
|
1345
|
-
}
|
|
605
|
+
style: { ...y }
|
|
606
|
+
}, a = b("text", {
|
|
607
|
+
...h(n, { ...r })
|
|
608
|
+
});
|
|
1346
609
|
return this.textElements.push(a), a;
|
|
1347
610
|
}
|
|
1348
611
|
}), Object.defineProperty(this, "tokenize", {
|
|
@@ -1350,25 +613,20 @@ class X {
|
|
|
1350
613
|
configurable: !0,
|
|
1351
614
|
writable: !0,
|
|
1352
615
|
value: async (r) => {
|
|
1353
|
-
var
|
|
1354
|
-
if (((
|
|
1355
|
-
throw new Error(`The session's next_action='${(
|
|
1356
|
-
const n = this.
|
|
1357
|
-
if (
|
|
1358
|
-
throw
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
expiry_month: n.expiration_month,
|
|
1368
|
-
expiry_year: n.expiration_year,
|
|
1369
|
-
security_code: n.cvc,
|
|
1370
|
-
additional_data: i
|
|
1371
|
-
}, s.jwk);
|
|
616
|
+
var a, s;
|
|
617
|
+
if (((a = this.session.state) == null ? void 0 : a.next_action) !== "tokenize_card")
|
|
618
|
+
throw new Error(`The session's next_action='${(s = this.session.state) == null ? void 0 : s.next_action}'. tokenize() is available only if next_action='tokenize_card'`);
|
|
619
|
+
const n = this.getCardDataValidationError();
|
|
620
|
+
if (n)
|
|
621
|
+
throw n;
|
|
622
|
+
return this.coordinator.postMessage({
|
|
623
|
+
type: "card:tokenize",
|
|
624
|
+
additionalData: this.serializeAdditionalData(r)
|
|
625
|
+
}), new Promise((o) => {
|
|
626
|
+
this.coordinator.onMessage("card:tokenize:response", (l) => {
|
|
627
|
+
o(l.success ? l.result : null);
|
|
628
|
+
});
|
|
629
|
+
});
|
|
1372
630
|
}
|
|
1373
631
|
}), Object.defineProperty(this, "onStateChange", {
|
|
1374
632
|
enumerable: !0,
|
|
@@ -1389,7 +647,7 @@ class X {
|
|
|
1389
647
|
configurable: !0,
|
|
1390
648
|
writable: !0,
|
|
1391
649
|
value: () => {
|
|
1392
|
-
Object.values(this.cardElements).forEach((r) => r == null ? void 0 : r.element.unmount()), this.textElements.forEach((r) => r == null ? void 0 : r.unmount()), this.cardElements = {}, this.textElements = [];
|
|
650
|
+
Object.values(this.cardElements).forEach((r) => r == null ? void 0 : r.element.unmount()), this.textElements.forEach((r) => r == null ? void 0 : r.unmount()), this.cardElements = {}, this.textElements = [], this.state = this.createFieldDefaultState();
|
|
1393
651
|
}
|
|
1394
652
|
}), Object.defineProperty(this, "dispose", {
|
|
1395
653
|
enumerable: !0,
|
|
@@ -1405,97 +663,130 @@ class X {
|
|
|
1405
663
|
value: async (r = {}) => {
|
|
1406
664
|
if (!this.hasFormElements())
|
|
1407
665
|
throw new Error("Card form must be initialized and completed before processing");
|
|
666
|
+
const n = this.getCardDataValidationError();
|
|
667
|
+
if (n)
|
|
668
|
+
throw n;
|
|
1408
669
|
if (this.session.isNextAction("refresh_security_code"))
|
|
1409
670
|
return this.refreshSecurityCode();
|
|
1410
671
|
this.disableFormElements(!0);
|
|
1411
672
|
try {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
673
|
+
return this.coordinator.postMessage({
|
|
674
|
+
type: "card:process",
|
|
675
|
+
additionalData: this.serializeAdditionalData(r)
|
|
676
|
+
}), new Promise((a, s) => {
|
|
677
|
+
this.coordinator.onMessage("card:process:response", (o) => {
|
|
678
|
+
o.result && o.success ? a(o.result) : s(new Error(o.error));
|
|
679
|
+
});
|
|
1418
680
|
});
|
|
1419
|
-
} catch (
|
|
1420
|
-
throw this.disableFormElements(!1),
|
|
681
|
+
} catch (a) {
|
|
682
|
+
throw this.disableFormElements(!1), a;
|
|
1421
683
|
}
|
|
1422
684
|
}
|
|
1423
|
-
}),
|
|
685
|
+
}), this.cvcOnlyEnabled = this.session.isNextAction("refresh_security_code");
|
|
686
|
+
}
|
|
687
|
+
createFormFields(e = {}) {
|
|
688
|
+
var l, c;
|
|
689
|
+
if (this.hasFormElements())
|
|
690
|
+
throw new Error("Form elements can't be initialized twice. You can call `reset()` method or create new Hellgate client.");
|
|
691
|
+
const t = {
|
|
692
|
+
disabled: this.cvcOnlyEnabled,
|
|
693
|
+
autocomplete: "on",
|
|
694
|
+
style: { ...y }
|
|
695
|
+
}, { cardNumber: r = {}, securityCode: n = {}, ...a } = e, s = b("cardNumber", {
|
|
696
|
+
...h(t, {
|
|
697
|
+
...a,
|
|
698
|
+
...r,
|
|
699
|
+
cvcOnly: this.cvcOnlyEnabled,
|
|
700
|
+
value: this.session.isNextAction("refresh_security_code") && ((l = this.session.state) != null && l.data) ? P(this.session.state.data) : null
|
|
701
|
+
})
|
|
702
|
+
}), o = b("cardVerificationCode", {
|
|
703
|
+
...h({
|
|
704
|
+
...t,
|
|
705
|
+
disabled: !1,
|
|
706
|
+
autofocus: this.cvcOnlyEnabled
|
|
707
|
+
}, {
|
|
708
|
+
...a,
|
|
709
|
+
...n
|
|
710
|
+
})
|
|
711
|
+
});
|
|
712
|
+
if (s.on("change", (d) => {
|
|
713
|
+
const u = d.cardBrand;
|
|
714
|
+
o.update({ cardType: u });
|
|
715
|
+
}), this.cardElements = {
|
|
716
|
+
cardNumber: {
|
|
717
|
+
element: s,
|
|
718
|
+
state: this.createFieldDefaultState()
|
|
719
|
+
},
|
|
720
|
+
cardVerificationCode: {
|
|
721
|
+
element: o,
|
|
722
|
+
state: this.createFieldDefaultState()
|
|
723
|
+
}
|
|
724
|
+
}, this.addElementStateListener("cardNumber"), this.addElementStateListener("cardVerificationCode"), e.expiryDateElement === "separate") {
|
|
725
|
+
const { expiryMonth: d = {}, expiryYear: u = {} } = e, _ = b("cardExpirationMonth", {
|
|
726
|
+
...h(t, {
|
|
727
|
+
...a,
|
|
728
|
+
...d
|
|
729
|
+
})
|
|
730
|
+
}), v = b("cardExpirationYear", {
|
|
731
|
+
...h(t, {
|
|
732
|
+
...a,
|
|
733
|
+
...u
|
|
734
|
+
})
|
|
735
|
+
});
|
|
736
|
+
return this.cardElements.cardExpirationMonth = {
|
|
737
|
+
element: _,
|
|
738
|
+
state: this.createFieldDefaultState()
|
|
739
|
+
}, this.cardElements.cardExpirationYear = {
|
|
740
|
+
element: v,
|
|
741
|
+
state: this.createFieldDefaultState()
|
|
742
|
+
}, this.addElementStateListener("cardExpirationMonth"), this.addElementStateListener("cardExpirationYear"), { cardNumber: s, expiryMonth: _, expiryYear: v, securityCode: o };
|
|
743
|
+
} else {
|
|
744
|
+
const { expiryDate: d = {} } = e, u = b("cardExpirationDate", {
|
|
745
|
+
...h(t, {
|
|
746
|
+
...a,
|
|
747
|
+
...d,
|
|
748
|
+
value: this.session.isNextAction("refresh_security_code") && ((c = this.session.state) != null && c.data) ? {
|
|
749
|
+
month: this.session.state.data.expiry_month,
|
|
750
|
+
year: this.session.state.data.expiry_year
|
|
751
|
+
} : null
|
|
752
|
+
})
|
|
753
|
+
});
|
|
754
|
+
return this.cardElements.cardExpirationDate = {
|
|
755
|
+
element: u,
|
|
756
|
+
state: this.createFieldDefaultState()
|
|
757
|
+
}, this.addElementStateListener("cardExpirationDate"), { cardNumber: s, expiryDate: u, securityCode: o };
|
|
758
|
+
}
|
|
1424
759
|
}
|
|
1425
760
|
async refreshSecurityCode() {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
const r = await this.encryptCardData({ security_code: e.cvc }, this.session.state.data.jwk);
|
|
1433
|
-
return this.session.completeAction({
|
|
1434
|
-
action: "refresh_security_code",
|
|
1435
|
-
result: { ...r }
|
|
1436
|
-
}).catch((n) => {
|
|
1437
|
-
if (this.disableFormElements(!1), n instanceof Error)
|
|
1438
|
-
throw n;
|
|
1439
|
-
return { status: "failure", data: n };
|
|
761
|
+
return this.coordinator.postMessage({
|
|
762
|
+
type: "card:refresh_security_code"
|
|
763
|
+
}), new Promise((e, t) => {
|
|
764
|
+
this.coordinator.onMessage("card:refresh_security_code:response", (r) => {
|
|
765
|
+
r.result ? e(r.result) : t(new Error(r.error));
|
|
766
|
+
});
|
|
1440
767
|
});
|
|
1441
768
|
}
|
|
1442
|
-
getFormValue() {
|
|
1443
|
-
var s, o, c, u, d;
|
|
1444
|
-
const { card: e, cardNumber: r, cardExpirationDate: n, cardVerificationCode: i } = this.cardElements;
|
|
1445
|
-
let a;
|
|
1446
|
-
if (e) {
|
|
1447
|
-
const l = O(this, e.element);
|
|
1448
|
-
a = {
|
|
1449
|
-
number: (l == null ? void 0 : l.number) ?? null,
|
|
1450
|
-
expiration_month: ((s = l == null ? void 0 : l.expiry_date) == null ? void 0 : s.month) ?? null,
|
|
1451
|
-
expiration_year: ((o = l == null ? void 0 : l.expiry_date) == null ? void 0 : o.year) ?? null,
|
|
1452
|
-
cvc: (l == null ? void 0 : l.cvc) ?? null
|
|
1453
|
-
};
|
|
1454
|
-
}
|
|
1455
|
-
return r && n && i && (a = {
|
|
1456
|
-
number: ((c = O(this, r.element)) == null ? void 0 : c.replaceAll(" ", "")) ?? null,
|
|
1457
|
-
expiration_month: ((u = O(this, n.element)) == null ? void 0 : u.month) ?? null,
|
|
1458
|
-
expiration_year: ((d = O(this, n.element)) == null ? void 0 : d.year) ?? null,
|
|
1459
|
-
cvc: O(this, i.element)
|
|
1460
|
-
}), a;
|
|
1461
|
-
}
|
|
1462
769
|
hasFormElements() {
|
|
1463
770
|
return !!Object.keys(this.cardElements).length;
|
|
1464
771
|
}
|
|
1465
772
|
disableFormElements(e) {
|
|
1466
|
-
Object.values(this.cardElements).forEach(({ element:
|
|
1467
|
-
|
|
1468
|
-
});
|
|
1469
|
-
}
|
|
1470
|
-
extractAdditionalData({ cardholder_name: e, billing_address: r = {} }) {
|
|
1471
|
-
return re({
|
|
1472
|
-
cardholder_name: P(this, e),
|
|
1473
|
-
billing_address: {
|
|
1474
|
-
line1: P(this, r.line1),
|
|
1475
|
-
line2: P(this, r.line2),
|
|
1476
|
-
line3: P(this, r.line3),
|
|
1477
|
-
city: P(this, r.city),
|
|
1478
|
-
postal_code: P(this, r.postal_code)
|
|
1479
|
-
}
|
|
773
|
+
Object.values(this.cardElements).forEach(({ element: t }) => {
|
|
774
|
+
t.update({ disabled: e });
|
|
1480
775
|
});
|
|
1481
776
|
}
|
|
1482
|
-
async encryptCardData(e, r) {
|
|
1483
|
-
const n = await Qe(r, "RSA-OAEP"), i = JSON.stringify(e), a = new TextEncoder().encode(i);
|
|
1484
|
-
return { enc_payload: await new ht(a).setProtectedHeader({ alg: "RSA-OAEP", enc: "A256GCM" }).encrypt(n) };
|
|
1485
|
-
}
|
|
1486
777
|
addElementStateListener(e) {
|
|
1487
|
-
const
|
|
1488
|
-
|
|
1489
|
-
|
|
778
|
+
const t = this.cardElements[e];
|
|
779
|
+
t && t.element.on("change", (r) => {
|
|
780
|
+
t.state = r, this.updateFormState();
|
|
1490
781
|
});
|
|
1491
782
|
}
|
|
1492
783
|
updateFormState() {
|
|
1493
784
|
const e = this.cvcOnlyEnabled && this.cardElements.cardVerificationCode ? [this.cardElements.cardVerificationCode] : Object.values(this.cardElements);
|
|
1494
|
-
e.length ? this.state = e.reduce((
|
|
785
|
+
e.length ? this.state = e.reduce((t, { state: r }) => (t.valid = !!t.valid && !!r.valid, t.complete = !!t.complete && !!r.complete, t.empty = !!t.empty && !!r.empty, t.error = t.error || r.error, t.errorCode = t.errorCode || r.errorCode, t), {
|
|
1495
786
|
valid: !0,
|
|
1496
787
|
complete: !0,
|
|
1497
788
|
empty: !0
|
|
1498
|
-
}) : this.state = this.createFieldDefaultState(), this.stateChangeHandlers.forEach((
|
|
789
|
+
}) : this.state = this.createFieldDefaultState(), this.stateChangeHandlers.forEach((t) => t(this.state));
|
|
1499
790
|
}
|
|
1500
791
|
createFieldDefaultState() {
|
|
1501
792
|
return {
|
|
@@ -1504,6 +795,18 @@ class X {
|
|
|
1504
795
|
valid: !1
|
|
1505
796
|
};
|
|
1506
797
|
}
|
|
798
|
+
serializeAdditionalData({ cardholder_name: e, billing_address: t = {} }) {
|
|
799
|
+
return x({
|
|
800
|
+
cardholder_name: m(e),
|
|
801
|
+
billing_address: {
|
|
802
|
+
line1: m(t.line1),
|
|
803
|
+
line2: m(t.line2),
|
|
804
|
+
line3: m(t.line3),
|
|
805
|
+
city: m(t.city),
|
|
806
|
+
postal_code: m(t.postal_code)
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
}
|
|
1507
810
|
getCardDataValidationError() {
|
|
1508
811
|
if (!this.state.complete)
|
|
1509
812
|
return new Error(this.state.error ?? "Card data is not complete");
|
|
@@ -1511,22 +814,96 @@ class X {
|
|
|
1511
814
|
return new Error(`Card data is not valid. ${this.state.error}`);
|
|
1512
815
|
}
|
|
1513
816
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
817
|
+
function m(i) {
|
|
818
|
+
if (typeof i == "string")
|
|
819
|
+
return i;
|
|
820
|
+
if (i != null && i.key)
|
|
821
|
+
return { key: i.key };
|
|
1518
822
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
823
|
+
const W = "v3.9.1";
|
|
824
|
+
class G {
|
|
825
|
+
constructor() {
|
|
826
|
+
if (Object.defineProperty(this, "iframe", {
|
|
827
|
+
enumerable: !0,
|
|
828
|
+
configurable: !0,
|
|
829
|
+
writable: !0,
|
|
830
|
+
value: null
|
|
831
|
+
}), Object.defineProperty(this, "iframeBaseUrl", {
|
|
832
|
+
enumerable: !0,
|
|
833
|
+
configurable: !0,
|
|
834
|
+
writable: !0,
|
|
835
|
+
value: void 0
|
|
836
|
+
}), Object.defineProperty(this, "messageHandler", {
|
|
837
|
+
enumerable: !0,
|
|
838
|
+
configurable: !0,
|
|
839
|
+
writable: !0,
|
|
840
|
+
value: null
|
|
841
|
+
}), Object.defineProperty(this, "init", {
|
|
842
|
+
enumerable: !0,
|
|
843
|
+
configurable: !0,
|
|
844
|
+
writable: !0,
|
|
845
|
+
value: async (e, t, r) => (window.fetchMocker = { a: 1 }, new Promise((n, a) => {
|
|
846
|
+
r == null || r.signal.addEventListener("abort", () => {
|
|
847
|
+
const l = new Error("Coordinator init aborted");
|
|
848
|
+
l.name = "AbortError", a(l), this.dispose();
|
|
849
|
+
});
|
|
850
|
+
const s = document.createElement("div");
|
|
851
|
+
s.setAttribute("style", "position:absolute;width:0;height:0;overflow:hidden;"), s.setAttribute("data-hg-coordinator", ""), document.body.appendChild(s);
|
|
852
|
+
const o = `${this.iframeBaseUrl}?type=coordinator&sessionId=${e}&apiBaseUrl=${t}&origin=${encodeURIComponent(location.origin)}`;
|
|
853
|
+
if (s.innerHTML = `<iframe src="${o}" width="0" height="0" style="border:none;" tabindex="-1" aria-hidden="true"></iframe>`, this.iframe = s.querySelector("iframe"), !this.iframe) {
|
|
854
|
+
a(new Error("Failed to create coordinator iframe"));
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
this.messageHandler = (l) => {
|
|
858
|
+
var c, d, u;
|
|
859
|
+
if (l.source === ((c = this.iframe) == null ? void 0 : c.contentWindow)) {
|
|
860
|
+
if (((d = l.data) == null ? void 0 : d.type) === "coordinator:ready") {
|
|
861
|
+
n();
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (((u = l.data) == null ? void 0 : u.type) === "coordinator:error") {
|
|
865
|
+
a(l.data.error);
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}, window.addEventListener("message", this.messageHandler), this.iframe.addEventListener("error", () => {
|
|
870
|
+
a(new Error("Coordinator iframe failed to load"));
|
|
871
|
+
});
|
|
872
|
+
}))
|
|
873
|
+
}), this.iframeBaseUrl = C(W), !this.iframeBaseUrl)
|
|
874
|
+
throw new Error("IFRAME_BASE_URL not found");
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Send a command to the coordinator iframe.
|
|
878
|
+
* Only commands and configuration — never card data.
|
|
879
|
+
*/
|
|
880
|
+
postMessage(e) {
|
|
881
|
+
var t, r;
|
|
882
|
+
(r = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || r.postMessage(e, this.iframeBaseUrl);
|
|
883
|
+
}
|
|
884
|
+
onMessage(e, t) {
|
|
885
|
+
window.addEventListener("message", (r) => {
|
|
886
|
+
var n, a;
|
|
887
|
+
r.source === ((n = this.iframe) == null ? void 0 : n.contentWindow) && ((a = r.data) == null ? void 0 : a.type) === e && t(r.data);
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Clean up the coordinator iframe and all associated resources.
|
|
892
|
+
*/
|
|
893
|
+
dispose() {
|
|
894
|
+
var t;
|
|
895
|
+
this.postMessage({ type: "coordinator:dispose" }), this.messageHandler && (window.removeEventListener("message", this.messageHandler), this.messageHandler = null);
|
|
896
|
+
const e = (t = this.iframe) == null ? void 0 : t.parentElement;
|
|
897
|
+
this.iframe = null, e == null || e.remove();
|
|
898
|
+
}
|
|
1522
899
|
}
|
|
1523
|
-
class
|
|
1524
|
-
constructor(e = "https://api.hellgate.io",
|
|
900
|
+
class X {
|
|
901
|
+
constructor(e = "https://api.hellgate.io", t = new AbortController()) {
|
|
1525
902
|
Object.defineProperty(this, "abortCtrl", {
|
|
1526
903
|
enumerable: !0,
|
|
1527
904
|
configurable: !0,
|
|
1528
905
|
writable: !0,
|
|
1529
|
-
value:
|
|
906
|
+
value: t
|
|
1530
907
|
}), Object.defineProperty(this, "baseUrl", {
|
|
1531
908
|
enumerable: !0,
|
|
1532
909
|
configurable: !0,
|
|
@@ -1537,26 +914,26 @@ class _t {
|
|
|
1537
914
|
getSession(e) {
|
|
1538
915
|
return fetch(`${this.baseUrl}/sessions/${e}`, {
|
|
1539
916
|
signal: this.abortCtrl.signal
|
|
1540
|
-
}).then((
|
|
917
|
+
}).then((t) => E(t));
|
|
1541
918
|
}
|
|
1542
|
-
completeAction(e,
|
|
919
|
+
completeAction(e, t) {
|
|
1543
920
|
return fetch(`${this.baseUrl}/sessions/${e}/complete-action`, {
|
|
1544
921
|
method: "POST",
|
|
1545
922
|
headers: {
|
|
1546
923
|
"Content-Type": "application/json"
|
|
1547
924
|
},
|
|
1548
925
|
mode: "cors",
|
|
1549
|
-
body: JSON.stringify(
|
|
926
|
+
body: JSON.stringify(t),
|
|
1550
927
|
signal: this.abortCtrl.signal
|
|
1551
|
-
}).then((
|
|
928
|
+
}).then((r) => E(r));
|
|
1552
929
|
}
|
|
1553
930
|
cancelAll() {
|
|
1554
931
|
this.abortCtrl.abort();
|
|
1555
932
|
}
|
|
1556
933
|
}
|
|
1557
|
-
const
|
|
1558
|
-
class
|
|
1559
|
-
constructor(e,
|
|
934
|
+
const J = 2e3;
|
|
935
|
+
class Q {
|
|
936
|
+
constructor(e, t) {
|
|
1560
937
|
Object.defineProperty(this, "id", {
|
|
1561
938
|
enumerable: !0,
|
|
1562
939
|
configurable: !0,
|
|
@@ -1566,7 +943,7 @@ class Ct {
|
|
|
1566
943
|
enumerable: !0,
|
|
1567
944
|
configurable: !0,
|
|
1568
945
|
writable: !0,
|
|
1569
|
-
value:
|
|
946
|
+
value: t
|
|
1570
947
|
}), Object.defineProperty(this, "state", {
|
|
1571
948
|
enumerable: !0,
|
|
1572
949
|
configurable: !0,
|
|
@@ -1591,47 +968,47 @@ class Ct {
|
|
|
1591
968
|
enumerable: !0,
|
|
1592
969
|
configurable: !0,
|
|
1593
970
|
writable: !0,
|
|
1594
|
-
value: async () => new Promise((
|
|
971
|
+
value: async () => new Promise((r, n) => {
|
|
1595
972
|
const a = this.onStateChange((s) => {
|
|
1596
|
-
s.next_action !== "wait" && (
|
|
973
|
+
s.next_action !== "wait" && (r(s), a());
|
|
1597
974
|
});
|
|
1598
975
|
this.updateSessionState().catch((s) => {
|
|
1599
|
-
s instanceof Response && s.status === 404 &&
|
|
976
|
+
s instanceof Response && s.status === 404 && n(new Error(`Session ${this.id} doesn't exist or has expired`)), n(s);
|
|
1600
977
|
});
|
|
1601
978
|
})
|
|
1602
979
|
}), Object.defineProperty(this, "onStateChange", {
|
|
1603
980
|
enumerable: !0,
|
|
1604
981
|
configurable: !0,
|
|
1605
982
|
writable: !0,
|
|
1606
|
-
value: (
|
|
983
|
+
value: (r) => (this.stateChangeHandlers.push(r), this.state && r(this.state), () => this.stateChangeHandlers = this.stateChangeHandlers.filter((n) => n !== r))
|
|
1607
984
|
}), Object.defineProperty(this, "onClose", {
|
|
1608
985
|
enumerable: !0,
|
|
1609
986
|
configurable: !0,
|
|
1610
987
|
writable: !0,
|
|
1611
|
-
value: (
|
|
1612
|
-
var
|
|
1613
|
-
return ((
|
|
1614
|
-
}) : (this.onCloseHandlers.push(
|
|
988
|
+
value: (r) => {
|
|
989
|
+
var n;
|
|
990
|
+
return ((n = this.state) == null ? void 0 : n.next_action) === null ? (r(g(this.state)), () => {
|
|
991
|
+
}) : (this.onCloseHandlers.push(r), () => this.onCloseHandlers = this.onCloseHandlers.filter((a) => a !== r));
|
|
1615
992
|
}
|
|
1616
993
|
}), Object.defineProperty(this, "completeAction", {
|
|
1617
994
|
enumerable: !0,
|
|
1618
995
|
configurable: !0,
|
|
1619
996
|
writable: !0,
|
|
1620
|
-
value: async (
|
|
1621
|
-
const
|
|
997
|
+
value: async (r) => {
|
|
998
|
+
const n = this.state;
|
|
1622
999
|
return new Promise((a, s) => {
|
|
1623
|
-
const o = this.onStateChange((
|
|
1624
|
-
|
|
1000
|
+
const o = this.onStateChange((l) => {
|
|
1001
|
+
l.next_action !== (n == null ? void 0 : n.next_action) && l.next_action === null && (a(g(l)), o());
|
|
1625
1002
|
});
|
|
1626
|
-
this.api.completeAction(this.id,
|
|
1003
|
+
this.api.completeAction(this.id, r).then((l) => this.newStateHandle(l, s)).catch(async (l) => s(await Z(l)));
|
|
1627
1004
|
});
|
|
1628
1005
|
}
|
|
1629
1006
|
}), Object.defineProperty(this, "completeSession", {
|
|
1630
1007
|
enumerable: !0,
|
|
1631
1008
|
configurable: !0,
|
|
1632
1009
|
writable: !0,
|
|
1633
|
-
value: (
|
|
1634
|
-
this.onCloseHandlers.forEach((
|
|
1010
|
+
value: (r) => {
|
|
1011
|
+
this.onCloseHandlers.forEach((n) => n(r)), this.stop();
|
|
1635
1012
|
}
|
|
1636
1013
|
}), Object.defineProperty(this, "dispose", {
|
|
1637
1014
|
enumerable: !0,
|
|
@@ -1643,46 +1020,51 @@ class Ct {
|
|
|
1643
1020
|
});
|
|
1644
1021
|
}
|
|
1645
1022
|
isNextAction(e) {
|
|
1646
|
-
var
|
|
1647
|
-
return ((
|
|
1023
|
+
var t;
|
|
1024
|
+
return ((t = this.state) == null ? void 0 : t.next_action) === e;
|
|
1648
1025
|
}
|
|
1649
1026
|
stop() {
|
|
1650
1027
|
window.clearTimeout(this.pollingTimer), this.stateChangeHandlers = [], this.onCloseHandlers = [];
|
|
1651
1028
|
}
|
|
1652
1029
|
async updateSessionState(e) {
|
|
1653
|
-
const
|
|
1654
|
-
this.newStateHandle(
|
|
1030
|
+
const t = await this.api.getSession(this.id);
|
|
1031
|
+
this.newStateHandle(t, e);
|
|
1655
1032
|
}
|
|
1656
|
-
newStateHandle(e,
|
|
1657
|
-
var
|
|
1033
|
+
newStateHandle(e, t) {
|
|
1034
|
+
var r;
|
|
1658
1035
|
switch (!e.next_action && e.status && (e.next_action = null), e.next_action) {
|
|
1659
1036
|
case "wait": {
|
|
1660
|
-
window.clearTimeout(this.pollingTimer), this.pollingTimer = window.setTimeout(() => this.updateSessionState(
|
|
1661
|
-
|
|
1662
|
-
}),
|
|
1037
|
+
window.clearTimeout(this.pollingTimer), this.pollingTimer = window.setTimeout(() => this.updateSessionState(t).catch((n) => {
|
|
1038
|
+
n instanceof Response && n.status === 404 && (t == null || t(new Error(`Session ${this.id} has expired`)));
|
|
1039
|
+
}), J);
|
|
1663
1040
|
break;
|
|
1664
1041
|
}
|
|
1665
1042
|
}
|
|
1666
|
-
e.next_action !== ((
|
|
1043
|
+
e.next_action !== ((r = this.state) == null ? void 0 : r.next_action) && this.stateChangeHandlers.forEach((n) => n(e)), e.next_action === null && this.completeSession(g(e)), this.state = e;
|
|
1667
1044
|
}
|
|
1668
1045
|
}
|
|
1669
|
-
async function
|
|
1670
|
-
return !
|
|
1046
|
+
async function Z(i) {
|
|
1047
|
+
return !i.ok && i.status >= 400 && i.status <= 500 ? i.json() : i;
|
|
1671
1048
|
}
|
|
1672
|
-
function
|
|
1673
|
-
const e = { ...
|
|
1049
|
+
function g(i) {
|
|
1050
|
+
const e = { ...i };
|
|
1674
1051
|
return delete e.next_action, e;
|
|
1675
1052
|
}
|
|
1676
|
-
const
|
|
1053
|
+
const ee = {
|
|
1677
1054
|
base_url: "https://api.hellgate.io"
|
|
1678
1055
|
};
|
|
1679
|
-
class
|
|
1680
|
-
constructor(e, r) {
|
|
1056
|
+
class L {
|
|
1057
|
+
constructor(e, t, r) {
|
|
1681
1058
|
Object.defineProperty(this, "session", {
|
|
1682
1059
|
enumerable: !0,
|
|
1683
1060
|
configurable: !0,
|
|
1684
1061
|
writable: !0,
|
|
1685
1062
|
value: e
|
|
1063
|
+
}), Object.defineProperty(this, "coordinator", {
|
|
1064
|
+
enumerable: !0,
|
|
1065
|
+
configurable: !0,
|
|
1066
|
+
writable: !0,
|
|
1067
|
+
value: t
|
|
1686
1068
|
}), Object.defineProperty(this, "paymentFlowHandlers", {
|
|
1687
1069
|
enumerable: !0,
|
|
1688
1070
|
configurable: !0,
|
|
@@ -1693,7 +1075,7 @@ class _e {
|
|
|
1693
1075
|
configurable: !0,
|
|
1694
1076
|
writable: !0,
|
|
1695
1077
|
value: () => {
|
|
1696
|
-
this.session.dispose(), Object.values(this.paymentFlowHandlers).forEach((n) => n == null ? void 0 : n.dispose());
|
|
1078
|
+
this.session.dispose(), this.coordinator.dispose(), Object.values(this.paymentFlowHandlers).forEach((n) => n == null ? void 0 : n.dispose());
|
|
1697
1079
|
}
|
|
1698
1080
|
}), Object.defineProperty(this, "onSessionComplete", {
|
|
1699
1081
|
enumerable: !0,
|
|
@@ -1707,46 +1089,47 @@ class _e {
|
|
|
1707
1089
|
use(e) {
|
|
1708
1090
|
return this.paymentFlowHandlers[e];
|
|
1709
1091
|
}
|
|
1710
|
-
static async init(e,
|
|
1711
|
-
const { session: n, cardHandler:
|
|
1712
|
-
return new
|
|
1713
|
-
CARD:
|
|
1714
|
-
"3DS":
|
|
1092
|
+
static async init(e, t = {}) {
|
|
1093
|
+
const { session: r, coordinator: n, cardHandler: a, handler3DS: s } = await this.initHandlers(e, t);
|
|
1094
|
+
return new L(r, n, {
|
|
1095
|
+
CARD: a,
|
|
1096
|
+
"3DS": s
|
|
1715
1097
|
});
|
|
1716
1098
|
}
|
|
1717
|
-
static async initHandlers(e,
|
|
1718
|
-
const
|
|
1719
|
-
...
|
|
1720
|
-
...
|
|
1721
|
-
},
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1099
|
+
static async initHandlers(e, t) {
|
|
1100
|
+
const r = {
|
|
1101
|
+
...ee,
|
|
1102
|
+
...t
|
|
1103
|
+
}, n = new X(r.base_url, r.abortCtrl), a = new Q(e, n), s = new G();
|
|
1104
|
+
s.onMessage("coordinator:session_state_change", (c) => {
|
|
1105
|
+
c.state.next_action !== "wait" && a.newStateHandle(c.state);
|
|
1106
|
+
}), await s.init(e, r.base_url, r.abortCtrl);
|
|
1107
|
+
const o = a.isNextAction("tokenize_card") || a.isNextAction("refresh_security_code") ? await this.createCardHandler(a, s) : void 0, l = this.create3DSHandler(a, t);
|
|
1108
|
+
return { session: a, coordinator: s, cardHandler: o, handler3DS: l };
|
|
1109
|
+
}
|
|
1110
|
+
static createCardHandler(e, t) {
|
|
1111
|
+
return w.init(e, t);
|
|
1112
|
+
}
|
|
1113
|
+
static create3DSHandler(e, t) {
|
|
1114
|
+
return new F(e, {
|
|
1115
|
+
domContainer: t.challenge_3ds_container,
|
|
1116
|
+
labelText: t.challenge_3ds_label_text
|
|
1733
1117
|
});
|
|
1734
1118
|
}
|
|
1735
1119
|
}
|
|
1736
1120
|
globalThis.HellgateSDK && (globalThis.Hellgate = globalThis.HellgateSDK.Hellgate, delete globalThis.HellgateSDK);
|
|
1737
1121
|
export {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
At as uid
|
|
1122
|
+
Y as CardElement,
|
|
1123
|
+
V as CardExpirationDateElement,
|
|
1124
|
+
B as CardNumberElement,
|
|
1125
|
+
q as CardVerificationCodeElement,
|
|
1126
|
+
L as Hellgate,
|
|
1127
|
+
F as Hellgate3DSHandler,
|
|
1128
|
+
w as HellgateCardHandler,
|
|
1129
|
+
K as TextElement,
|
|
1130
|
+
b as createElement,
|
|
1131
|
+
I as extractCardNumberValue,
|
|
1132
|
+
T as extractExpiryDateValue,
|
|
1133
|
+
z as putCardNumberValue,
|
|
1134
|
+
M as putExpiryDateValue
|
|
1752
1135
|
};
|