hanbiro-react16-sdk 1.0.32 → 1.0.33
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/components/ChatAIDraft/helper.js +27 -2
- package/dist/hanbiro-react16-sdk.style.css +2 -2
- package/dist/hanbiro-react16-sdk.umd.js +2663 -701
- package/dist/index.js +2 -2
- package/dist/node_modules/@hanbiro/signer-core/dist/index.js +932 -0
- package/dist/utils/api.d.ts +1 -0
- package/dist/utils/api.js +16 -3
- package/package.json +3 -2
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
var we = Object.defineProperty;
|
|
2
|
+
var X = Object.getOwnPropertySymbols;
|
|
3
|
+
var me = Object.prototype.hasOwnProperty, be = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var z = (t, e, n) => e in t ? we(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n, f = (t, e) => {
|
|
5
|
+
for (var n in e || (e = {})) me.call(e, n) && z(t, n, e[n]);
|
|
6
|
+
if (X) for (var n of X(e)) be.call(e, n) && z(t, n, e[n]);
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
var c = (t, e, n) => new Promise((r, i) => {
|
|
10
|
+
var o = (l) => {
|
|
11
|
+
try {
|
|
12
|
+
a(n.next(l));
|
|
13
|
+
} catch (d) {
|
|
14
|
+
i(d);
|
|
15
|
+
}
|
|
16
|
+
}, s = (l) => {
|
|
17
|
+
try {
|
|
18
|
+
a(n.throw(l));
|
|
19
|
+
} catch (d) {
|
|
20
|
+
i(d);
|
|
21
|
+
}
|
|
22
|
+
}, a = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(o, s);
|
|
23
|
+
a((n = n.apply(t, e)).next());
|
|
24
|
+
});
|
|
25
|
+
var Q = { lsIdKey: "sig_client_uuid", lsPubJwkKey: "sig_pub_jwk", idbName: "mod_sig_keystore_v1", idbStore: "keys", idbPrivKey: "p256_priv", registerUrlTpl: "/sig/register/{id}", gwCookieName: "HANBIRO_GW" };
|
|
26
|
+
function v() {
|
|
27
|
+
let t = [];
|
|
28
|
+
try {
|
|
29
|
+
let n = "__sig_test__";
|
|
30
|
+
localStorage.setItem(n, "1"), localStorage.removeItem(n);
|
|
31
|
+
} catch (n) {
|
|
32
|
+
t.push("localStorage");
|
|
33
|
+
}
|
|
34
|
+
return typeof indexedDB == "undefined" && t.push("IndexedDB"), b() || t.push("WebCrypto (crypto.subtle)"), { supported: t.length === 0, missing: t };
|
|
35
|
+
}
|
|
36
|
+
var Se = { ko: { title: "지원되지 않는 브라우저입니다", description: "이 서비스를 이용하려면 최신 브라우저가 필요합니다.", missingFeatures: "다음 기능이 지원되지 않습니다:", httpsNote: "또한, 보안 연결(HTTPS)을 통해 접속해야 합니다.", browserSuggestion: "Chrome, Firefox, Safari, Edge 등 최신 브라우저를 사용해 주세요." }, en: { title: "Unsupported Browser", description: "A modern browser is required to use this service.", missingFeatures: "The following features are not supported:", httpsNote: "Also, you must access via a secure connection (HTTPS).", browserSuggestion: "Please use a modern browser such as Chrome, Firefox, Safari, or Edge." }, vi: { title: "Trình duyệt không được hỗ trợ", description: "Cần có trình duyệt hiện đại để sử dụng dịch vụ này.", missingFeatures: "Các tính năng sau không được hỗ trợ:", httpsNote: "Ngoài ra, bạn phải truy cập qua kết nối bảo mật (HTTPS).", browserSuggestion: "Vui lòng sử dụng trình duyệt hiện đại như Chrome, Firefox, Safari hoặc Edge." } };
|
|
37
|
+
function P() {
|
|
38
|
+
if (typeof navigator == "undefined") return "en";
|
|
39
|
+
let t = (navigator.language || navigator.userLanguage || "en").toLowerCase();
|
|
40
|
+
return t.startsWith("ko") ? "ko" : t.startsWith("vi") ? "vi" : "en";
|
|
41
|
+
}
|
|
42
|
+
function w(t, e, n) {
|
|
43
|
+
let r = n || P(), i = Se[r], o = `
|
|
44
|
+
<div style="
|
|
45
|
+
position: fixed;
|
|
46
|
+
top: 0;
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
background: #fff;
|
|
51
|
+
z-index: 999999;
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
56
|
+
">
|
|
57
|
+
<div style="
|
|
58
|
+
text-align: center;
|
|
59
|
+
padding: 40px;
|
|
60
|
+
max-width: 500px;
|
|
61
|
+
">
|
|
62
|
+
<div style="font-size: 48px; margin-bottom: 20px;">⚠️</div>
|
|
63
|
+
<h1 style="color: #333; margin-bottom: 16px; font-size: 24px;">
|
|
64
|
+
${i.title}
|
|
65
|
+
</h1>
|
|
66
|
+
<p style="color: #666; margin-bottom: 16px; line-height: 1.6;">
|
|
67
|
+
${i.description}<br>
|
|
68
|
+
${i.missingFeatures}
|
|
69
|
+
</p>
|
|
70
|
+
<ul style="
|
|
71
|
+
text-align: left;
|
|
72
|
+
display: inline-block;
|
|
73
|
+
color: #e53935;
|
|
74
|
+
margin-bottom: 16px;
|
|
75
|
+
">
|
|
76
|
+
${t.map((s) => `<li>${s}</li>`).join("")}
|
|
77
|
+
</ul>
|
|
78
|
+
<p style="color: #ff6f00; margin-bottom: 16px; font-size: 14px; font-weight: 500;">
|
|
79
|
+
🔒 ${i.httpsNote}
|
|
80
|
+
</p>
|
|
81
|
+
<p style="color: #666; font-size: 14px;">
|
|
82
|
+
${i.browserSuggestion}
|
|
83
|
+
</p>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
`;
|
|
87
|
+
if (e) {
|
|
88
|
+
let s = document.getElementById(e);
|
|
89
|
+
if (s) {
|
|
90
|
+
s.innerHTML = o;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
document.body ? document.body.innerHTML = o : document.addEventListener("DOMContentLoaded", () => {
|
|
95
|
+
document.body.innerHTML = o;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function ie(t) {
|
|
99
|
+
let e = f({}, Q);
|
|
100
|
+
if (t) for (let n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
|
|
101
|
+
return e;
|
|
102
|
+
}
|
|
103
|
+
function m() {
|
|
104
|
+
if (typeof window != "undefined") {
|
|
105
|
+
if (window.crypto) return window.crypto;
|
|
106
|
+
if (window.msCrypto) return window.msCrypto;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function b() {
|
|
110
|
+
let t = m();
|
|
111
|
+
if (t) return t.subtle || t.webkitSubtle;
|
|
112
|
+
}
|
|
113
|
+
function _(t) {
|
|
114
|
+
try {
|
|
115
|
+
return localStorage.getItem(t);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function oe(t, e) {
|
|
121
|
+
try {
|
|
122
|
+
localStorage.setItem(t, e);
|
|
123
|
+
} catch (n) {
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function Ce(t) {
|
|
127
|
+
try {
|
|
128
|
+
localStorage.removeItem(t);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function S(t) {
|
|
133
|
+
return _(t.lsIdKey) || "";
|
|
134
|
+
}
|
|
135
|
+
function E(t, e) {
|
|
136
|
+
oe(t.lsIdKey, e);
|
|
137
|
+
}
|
|
138
|
+
function se(t) {
|
|
139
|
+
Ce(t.lsIdKey);
|
|
140
|
+
}
|
|
141
|
+
function j(t) {
|
|
142
|
+
try {
|
|
143
|
+
let e = _(t.lsPubJwkKey);
|
|
144
|
+
return e ? JSON.parse(e) : null;
|
|
145
|
+
} catch (e) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function ae(t, e) {
|
|
150
|
+
try {
|
|
151
|
+
oe(t.lsPubJwkKey, JSON.stringify(e));
|
|
152
|
+
} catch (n) {
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function k(t) {
|
|
156
|
+
let e = t instanceof Uint8Array ? t : new Uint8Array(t), n = "";
|
|
157
|
+
for (let r = 0; r < e.length; r++) n += String.fromCharCode(e[r]);
|
|
158
|
+
return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
159
|
+
}
|
|
160
|
+
function C(t) {
|
|
161
|
+
if (typeof TextEncoder != "undefined") return new TextEncoder().encode(String(t));
|
|
162
|
+
let e = unescape(encodeURIComponent(String(t))), n = new Uint8Array(e.length);
|
|
163
|
+
for (let r = 0; r < e.length; r++) n[r] = e.charCodeAt(r);
|
|
164
|
+
return n;
|
|
165
|
+
}
|
|
166
|
+
function x() {
|
|
167
|
+
let t = m();
|
|
168
|
+
if (!t || !t.getRandomValues) throw new Error("crypto.getRandomValues not supported");
|
|
169
|
+
let e = new Uint8Array(16);
|
|
170
|
+
t.getRandomValues(e), e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
|
|
171
|
+
let n = Array.from(e).map((r) => ("00" + r.toString(16)).slice(-2)).join("");
|
|
172
|
+
return n.slice(0, 8) + "-" + n.slice(8, 12) + "-" + n.slice(12, 16) + "-" + n.slice(16, 20) + "-" + n.slice(20);
|
|
173
|
+
}
|
|
174
|
+
function Y(t) {
|
|
175
|
+
let e = t.slice(0, 16);
|
|
176
|
+
e[6] = e[6] & 15 | 80, e[8] = e[8] & 63 | 128;
|
|
177
|
+
let n = Array.from(e).map((r) => ("00" + r.toString(16)).slice(-2)).join("");
|
|
178
|
+
return n.slice(0, 8) + "-" + n.slice(8, 12) + "-" + n.slice(12, 16) + "-" + n.slice(16, 20) + "-" + n.slice(20);
|
|
179
|
+
}
|
|
180
|
+
function xe(t) {
|
|
181
|
+
let e = 3735928559 ^ t.length, n = 1103547991 ^ t.length, r = 3235826430 ^ t.length, i = 2654435769 ^ t.length;
|
|
182
|
+
for (let s = 0; s < t.length; s++) {
|
|
183
|
+
let a = t.charCodeAt(s);
|
|
184
|
+
e = Math.imul(e ^ a, 2654435761), n = Math.imul(n ^ a, 1597334677), r = Math.imul(r ^ a, 2246822507), i = Math.imul(i ^ a, 3266489909);
|
|
185
|
+
}
|
|
186
|
+
e = Math.imul(e ^ e >>> 16, 2246822507) ^ Math.imul(n ^ n >>> 13, 3266489909), n = Math.imul(n ^ n >>> 16, 2246822507) ^ Math.imul(r ^ r >>> 13, 3266489909), r = Math.imul(r ^ r >>> 16, 2246822507) ^ Math.imul(i ^ i >>> 13, 3266489909), i = Math.imul(i ^ i >>> 16, 2246822507) ^ Math.imul(e ^ e >>> 13, 3266489909);
|
|
187
|
+
let o = new Uint8Array(16);
|
|
188
|
+
return new DataView(o.buffer).setUint32(0, e >>> 0, false), new DataView(o.buffer).setUint32(4, n >>> 0, false), new DataView(o.buffer).setUint32(8, r >>> 0, false), new DataView(o.buffer).setUint32(12, i >>> 0, false), o;
|
|
189
|
+
}
|
|
190
|
+
function Ae(t) {
|
|
191
|
+
return c(this, null, function* () {
|
|
192
|
+
let e = b();
|
|
193
|
+
if (e && typeof e.digest == "function") {
|
|
194
|
+
let n = yield e.digest("SHA-256", C(t));
|
|
195
|
+
return Y(new Uint8Array(n));
|
|
196
|
+
}
|
|
197
|
+
return Y(xe(t));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function V(t, e) {
|
|
201
|
+
if (e == null) return;
|
|
202
|
+
if (Array.isArray(e)) {
|
|
203
|
+
for (let i of e) V(t, i);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (typeof e == "object") {
|
|
207
|
+
for (let i in e) Object.prototype.hasOwnProperty.call(e, i) && V(t, e[i]);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let r = String(e).match(/[0-9a-fA-F]{2}(?:(?:[:-][0-9a-fA-F]{2}){5}|(?:[0-9a-fA-F]{2}){5})/g);
|
|
211
|
+
if (r) for (let i of r) {
|
|
212
|
+
let o = i.replace(/[^0-9a-fA-F]/g, "").toLowerCase();
|
|
213
|
+
o.length === 12 && o !== "000000000000" && t.push(o);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function y(t) {
|
|
217
|
+
let e = [];
|
|
218
|
+
return V(e, t), Array.from(new Set(e)).sort();
|
|
219
|
+
}
|
|
220
|
+
function le(t, e) {
|
|
221
|
+
return c(this, null, function* () {
|
|
222
|
+
let n = t.call(e);
|
|
223
|
+
return n && typeof n.then == "function" ? yield n : n;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function U(t) {
|
|
227
|
+
return typeof t.HanSigGetMacAddresses == "function" || typeof t.HanSigMacAddresses != "undefined";
|
|
228
|
+
}
|
|
229
|
+
function de(t) {
|
|
230
|
+
return c(this, null, function* () {
|
|
231
|
+
return yield new Promise((e) => setTimeout(e, t));
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function Ie(t) {
|
|
235
|
+
return c(this, null, function* () {
|
|
236
|
+
if (U(t)) return true;
|
|
237
|
+
if (!(typeof t.hanChromeExt == "function")) return false;
|
|
238
|
+
let n = 2500, r = 100, i = Date.now() + n;
|
|
239
|
+
for (; Date.now() <= i; ) {
|
|
240
|
+
if (U(t)) return true;
|
|
241
|
+
if (Date.now() + r > i) break;
|
|
242
|
+
yield de(r);
|
|
243
|
+
}
|
|
244
|
+
return U(t);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function Ue(t) {
|
|
248
|
+
return c(this, null, function* () {
|
|
249
|
+
if (!U(t)) return "";
|
|
250
|
+
let e = 8e3, n = 150, r = Date.now() + e, i = "";
|
|
251
|
+
for (; Date.now() <= r; ) {
|
|
252
|
+
let o = [];
|
|
253
|
+
if (typeof t.HanSigMacAddresses != "undefined" && o.push(t.HanSigMacAddresses), typeof t.HanSigGetMacAddresses == "function") try {
|
|
254
|
+
o.push(yield le(t.HanSigGetMacAddresses, t));
|
|
255
|
+
} catch (s) {
|
|
256
|
+
}
|
|
257
|
+
if (i = o, y(o).length > 0) return o;
|
|
258
|
+
if (Date.now() + n > r) break;
|
|
259
|
+
yield de(n);
|
|
260
|
+
}
|
|
261
|
+
return i;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function ve() {
|
|
265
|
+
return c(this, null, function* () {
|
|
266
|
+
if (typeof window == "undefined" || typeof window.hanChromeExt != "function") return "";
|
|
267
|
+
try {
|
|
268
|
+
let t = window.hanChromeExt();
|
|
269
|
+
if (!t) return "";
|
|
270
|
+
let e = () => [t.allMAC || "", t.MAC || "", t.macAddress || "", t.mac || ""], n = (i) => i.some((o) => typeof o == "string" && o.trim().length > 0), r = e();
|
|
271
|
+
return n(r) ? r : typeof t.getData != "function" ? "" : yield new Promise((i) => {
|
|
272
|
+
let o = false, s = (...a) => {
|
|
273
|
+
if (o) return;
|
|
274
|
+
o = true;
|
|
275
|
+
let l = e();
|
|
276
|
+
i([l, a]);
|
|
277
|
+
};
|
|
278
|
+
setTimeout(s, 3e3);
|
|
279
|
+
try {
|
|
280
|
+
t.getData((...a) => s(...a));
|
|
281
|
+
} catch (a) {
|
|
282
|
+
s();
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
} catch (t) {
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function M(t) {
|
|
291
|
+
return c(this, null, function* () {
|
|
292
|
+
let e = [];
|
|
293
|
+
try {
|
|
294
|
+
t != null && t.macAddresses && e.push(t.macAddresses), typeof (t == null ? void 0 : t.getMacAddresses) == "function" && e.push(yield le(t.getMacAddresses, t));
|
|
295
|
+
} catch (n) {
|
|
296
|
+
}
|
|
297
|
+
if (typeof window != "undefined") {
|
|
298
|
+
let n = window, r = yield Ie(n);
|
|
299
|
+
r && e.push(yield Ue(n));
|
|
300
|
+
try {
|
|
301
|
+
n.Hanbiro_UsbAuth && typeof n.Hanbiro_UsbAuth.GetAllMacAddress == "function" && e.push(n.Hanbiro_UsbAuth.GetAllMacAddress());
|
|
302
|
+
} catch (o) {
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
let o = n.plugin0 || typeof document != "undefined" && document.getElementById("plugin0");
|
|
306
|
+
o && typeof o.getAllMacAddress == "function" && e.push(o.getAllMacAddress());
|
|
307
|
+
} catch (o) {
|
|
308
|
+
}
|
|
309
|
+
let i = y(e);
|
|
310
|
+
(!r || i.length === 0) && e.push(yield ve());
|
|
311
|
+
}
|
|
312
|
+
return y(e);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function D(t) {
|
|
316
|
+
return c(this, null, function* () {
|
|
317
|
+
let e = y(t);
|
|
318
|
+
if (e.length === 0) return "";
|
|
319
|
+
let n = "hanbiro:client-id:mac:v1:" + e.join(",");
|
|
320
|
+
return yield Ae(n);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function H() {
|
|
324
|
+
let t = m();
|
|
325
|
+
if (!t || !t.getRandomValues) throw new Error("crypto.getRandomValues not supported");
|
|
326
|
+
return k(t.getRandomValues(new Uint8Array(16)));
|
|
327
|
+
}
|
|
328
|
+
function B(t) {
|
|
329
|
+
if (typeof document == "undefined") return "";
|
|
330
|
+
let e = document.cookie ? document.cookie.split(";") : [];
|
|
331
|
+
for (let n = 0; n < e.length; n++) {
|
|
332
|
+
let r = e[n].trim();
|
|
333
|
+
if (r.indexOf(t + "=") === 0) return r.substring(t.length + 1);
|
|
334
|
+
}
|
|
335
|
+
return "";
|
|
336
|
+
}
|
|
337
|
+
function Pe(t) {
|
|
338
|
+
if (t < 128) return [t];
|
|
339
|
+
let e = [];
|
|
340
|
+
for (; t > 0; ) e.unshift(t & 255), t >>= 8;
|
|
341
|
+
return e.unshift(128 | e.length), e;
|
|
342
|
+
}
|
|
343
|
+
function Z(t) {
|
|
344
|
+
let e = 0;
|
|
345
|
+
for (; e < t.length - 1 && t[e] === 0; ) e++;
|
|
346
|
+
let n = t.slice(e);
|
|
347
|
+
if ((n[0] & 128) !== 0) {
|
|
348
|
+
let r = new Uint8Array(n.length + 1);
|
|
349
|
+
return r[0] = 0, r.set(n, 1), r;
|
|
350
|
+
}
|
|
351
|
+
return n;
|
|
352
|
+
}
|
|
353
|
+
function J(t) {
|
|
354
|
+
if (!t) throw new Error("Invalid signature");
|
|
355
|
+
let e = t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
356
|
+
if (e.length !== 64) return e;
|
|
357
|
+
let n = Z(e.slice(0, 32)), r = Z(e.slice(32, 64)), i = new Uint8Array(2 + n.length);
|
|
358
|
+
i[0] = 2, i[1] = n.length, i.set(n, 2);
|
|
359
|
+
let o = new Uint8Array(2 + r.length);
|
|
360
|
+
o[0] = 2, o[1] = r.length, o.set(r, 2);
|
|
361
|
+
let s = i.length + o.length, a = Pe(s), l = new Uint8Array(1 + a.length + s);
|
|
362
|
+
return l[0] = 48, l.set(a, 1), l.set(i, 1 + a.length), l.set(o, 1 + a.length + i.length), l;
|
|
363
|
+
}
|
|
364
|
+
var ee = "0123456789ABCDEF";
|
|
365
|
+
function te(t) {
|
|
366
|
+
return t >= 48 && t <= 57 ? t - 48 : t >= 65 && t <= 70 ? t - 65 + 10 : t >= 97 && t <= 102 ? t - 97 + 10 : -1;
|
|
367
|
+
}
|
|
368
|
+
function _e(t) {
|
|
369
|
+
return t >= 65 && t <= 90 || t >= 97 && t <= 122 || t >= 48 && t <= 57 || t === 45 || t === 46 || t === 95 || t === 126 || t === 33 || t === 36 || t === 39 || t === 40 || t === 41 || t === 42 || t === 44 || t === 59 || t === 58 || t === 64 || t === 47 || t === 63 || t === 91 || t === 93;
|
|
370
|
+
}
|
|
371
|
+
function ne(t) {
|
|
372
|
+
let e = String(t || ""), n = [], r = 0;
|
|
373
|
+
for (; r < e.length; ) {
|
|
374
|
+
if (e[r] === "%" && r + 2 < e.length) {
|
|
375
|
+
let o = te(e.charCodeAt(r + 1)), s = te(e.charCodeAt(r + 2));
|
|
376
|
+
if (o >= 0 && s >= 0) {
|
|
377
|
+
n.push(o << 4 | s), r += 3;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
let i = e.codePointAt(r) || 0;
|
|
382
|
+
if (i == 43 && (i = 32), i <= 127) n.push(i);
|
|
383
|
+
else {
|
|
384
|
+
let o = C(String.fromCodePoint(i));
|
|
385
|
+
for (let s = 0; s < o.length; s++) n.push(o[s]);
|
|
386
|
+
}
|
|
387
|
+
r += i > 65535 ? 2 : 1;
|
|
388
|
+
}
|
|
389
|
+
return new Uint8Array(n);
|
|
390
|
+
}
|
|
391
|
+
function re(t) {
|
|
392
|
+
let e = [];
|
|
393
|
+
for (let n = 0; n < t.length; n++) {
|
|
394
|
+
let r = t[n];
|
|
395
|
+
_e(r) ? e.push(String.fromCharCode(r)) : e.push("%" + ee[r >> 4 & 15] + ee[r & 15]);
|
|
396
|
+
}
|
|
397
|
+
return e.join("");
|
|
398
|
+
}
|
|
399
|
+
function Ee(t) {
|
|
400
|
+
let e = String(t || "").replace(/^\?/, "");
|
|
401
|
+
if (!e) return "";
|
|
402
|
+
let n = [], r = e.split("&");
|
|
403
|
+
for (let i = 0; i < r.length; i++) {
|
|
404
|
+
let o = r[i];
|
|
405
|
+
if (!o) continue;
|
|
406
|
+
let s = o.indexOf("="), a = s === -1 ? o : o.slice(0, s), l = s === -1 ? "" : o.slice(s + 1), d = ne(a), u = ne(l), p = re(d);
|
|
407
|
+
if (!p) continue;
|
|
408
|
+
let h = re(u), ye = u.length > 0;
|
|
409
|
+
n.push({ k: p, v: h, hasValue: ye, i });
|
|
410
|
+
}
|
|
411
|
+
return n.length === 0 ? "" : (n.sort((i, o) => i.k < o.k ? -1 : i.k > o.k ? 1 : i.v < o.v ? -1 : i.v > o.v ? 1 : i.i - o.i), n.map((i) => i.hasValue ? `${i.k}=${i.v}` : i.k).join("&"));
|
|
412
|
+
}
|
|
413
|
+
function T(t) {
|
|
414
|
+
let e = [String(t.method || "").toUpperCase(), String(t.host || "").toLowerCase(), t.path || "", Ee(t.query || ""), t.id || "", String(t.ts || ""), t.nonce || ""];
|
|
415
|
+
return typeof t.gw == "string" && e.push(t.gw), e.join(".");
|
|
416
|
+
}
|
|
417
|
+
var q = (t) => new Promise((e, n) => {
|
|
418
|
+
if (typeof indexedDB == "undefined") return n(new Error("IndexedDB not supported"));
|
|
419
|
+
let r = indexedDB.open(t.idbName, 1);
|
|
420
|
+
r.onupgradeneeded = () => {
|
|
421
|
+
let i = r.result;
|
|
422
|
+
i.objectStoreNames.contains(t.idbStore) || i.createObjectStore(t.idbStore);
|
|
423
|
+
}, r.onsuccess = () => e(r.result), r.onerror = () => n(r.error || new Error("idb open failed"));
|
|
424
|
+
}), ce = (t, e, n) => new Promise((r) => {
|
|
425
|
+
try {
|
|
426
|
+
let s = t.transaction(e.idbStore, "readonly").objectStore(e.idbStore).get(n);
|
|
427
|
+
s.onsuccess = () => r(s.result || null), s.onerror = () => r(null);
|
|
428
|
+
} catch (i) {
|
|
429
|
+
r(null);
|
|
430
|
+
}
|
|
431
|
+
}), ue = (t, e, n, r) => new Promise((i, o) => {
|
|
432
|
+
try {
|
|
433
|
+
let l = t.transaction(e.idbStore, "readwrite").objectStore(e.idbStore).put(r, n);
|
|
434
|
+
l.onsuccess = () => i(true), l.onerror = () => o(l.error || new Error("idb put failed"));
|
|
435
|
+
} catch (s) {
|
|
436
|
+
o(s);
|
|
437
|
+
}
|
|
438
|
+
}), ge = (t, e, n) => new Promise((r) => {
|
|
439
|
+
try {
|
|
440
|
+
let s = t.transaction(e.idbStore, "readwrite").objectStore(e.idbStore).delete(n);
|
|
441
|
+
s.onsuccess = () => r(true), s.onerror = () => r(false);
|
|
442
|
+
} catch (i) {
|
|
443
|
+
r(false);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
var R = class {
|
|
447
|
+
constructor(e = false) {
|
|
448
|
+
this.prefix = "[HanbiroSigner]";
|
|
449
|
+
this.enabled = e || _("sig_debug") === "true";
|
|
450
|
+
}
|
|
451
|
+
setEnabled(e) {
|
|
452
|
+
this.enabled = e;
|
|
453
|
+
}
|
|
454
|
+
info(e, ...n) {
|
|
455
|
+
this.enabled && console.info(`%c${this.prefix} ℹ️ ${e}`, "color: #3b82f6; font-weight: bold;", ...n);
|
|
456
|
+
}
|
|
457
|
+
debug(e, ...n) {
|
|
458
|
+
this.enabled && console.debug(`%c${this.prefix} 🔧 ${e}`, "color: #8b5cf6;", ...n);
|
|
459
|
+
}
|
|
460
|
+
warn(e, ...n) {
|
|
461
|
+
this.enabled && console.warn(`%c${this.prefix} ⚠️ ${e}`, "color: #f59e0b; font-weight: bold;", ...n);
|
|
462
|
+
}
|
|
463
|
+
error(e, ...n) {
|
|
464
|
+
this.enabled && console.error(`%c${this.prefix} ❌ ${e}`, "color: #ef4444; font-weight: bold;", ...n);
|
|
465
|
+
}
|
|
466
|
+
group(e) {
|
|
467
|
+
this.enabled && console.groupCollapsed(`${this.prefix} ${e}`);
|
|
468
|
+
}
|
|
469
|
+
groupEnd() {
|
|
470
|
+
this.enabled && console.groupEnd();
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
var F = class {
|
|
474
|
+
constructor() {
|
|
475
|
+
this.name = "iOS";
|
|
476
|
+
}
|
|
477
|
+
callNative(e, n) {
|
|
478
|
+
return new Promise((r, i) => {
|
|
479
|
+
var l, d;
|
|
480
|
+
if (!((d = (l = window.webkit) == null ? void 0 : l.messageHandlers) != null && d.observe)) return i(new Error("iOS Bridge (observe) not found"));
|
|
481
|
+
let o = Math.random().toString(36).substring(2, 9), s = e === "getHybridClientId" ? `GetIOSClientIdCallback${o}` : `HanbiroIOSSignCallback${o}`, a = setTimeout(() => {
|
|
482
|
+
window[s] && (delete window[s], i(new Error(`[HanbiroSigner] Calling iOS Timeout Action: ${e} | callBack: ${s} | Time: ${Date.now()}`)));
|
|
483
|
+
}, 5e3);
|
|
484
|
+
window[s] = (u) => {
|
|
485
|
+
clearTimeout(a), delete window[s], u ? r(u) : i(new Error("iOS returned empty result"));
|
|
486
|
+
};
|
|
487
|
+
try {
|
|
488
|
+
let u = e === "getHybridClientId" ? [e, s].join("_____") : [e, s, n || ""].join("_____");
|
|
489
|
+
window.webkit.messageHandlers.observe.postMessage(u);
|
|
490
|
+
} catch (u) {
|
|
491
|
+
clearTimeout(a), delete window[s], i(u);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
getClientId() {
|
|
496
|
+
return this.callNative("getHybridClientId").then((e) => e || null).catch((e) => null);
|
|
497
|
+
}
|
|
498
|
+
signECDSA(e) {
|
|
499
|
+
return this.callNative("hanbiroSignECDSA", e);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
var N = class {
|
|
503
|
+
constructor() {
|
|
504
|
+
this.name = "Flutter";
|
|
505
|
+
}
|
|
506
|
+
callNative(e, n) {
|
|
507
|
+
return new Promise((r, i) => {
|
|
508
|
+
if (!window.FlutterSignatureChannel) return i(new Error("Flutter Bridge not found"));
|
|
509
|
+
let o = Math.random().toString(36).substring(2, 9), s = e === "getHybridClientId" ? `GetFlutterClientIdCallback${o}` : `HanbiroFlutterSignCallback${o}`, a = setTimeout(() => {
|
|
510
|
+
window[s] && (delete window[s], i(new Error(`[HanbiroSigner] Calling Flutter Timeout Action: ${e} | callBack: ${s} | Time: ${Date.now()}`)));
|
|
511
|
+
}, 5e3);
|
|
512
|
+
window[s] = (l) => {
|
|
513
|
+
clearTimeout(a), delete window[s], l ? r(l) : i(new Error("Flutter returned empty result"));
|
|
514
|
+
};
|
|
515
|
+
try {
|
|
516
|
+
let d = JSON.stringify({ action: e, callback_method: s, payload: n || "" });
|
|
517
|
+
window.FlutterSignatureChannel.postMessage(d);
|
|
518
|
+
} catch (l) {
|
|
519
|
+
clearTimeout(a), delete window[s], i(l);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
getClientId() {
|
|
524
|
+
return this.callNative("getHybridClientId").then((e) => e || null).catch((e) => null);
|
|
525
|
+
}
|
|
526
|
+
signECDSA(e) {
|
|
527
|
+
return this.callNative("hanbiroSignECDSA", e);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
var G = class {
|
|
531
|
+
constructor() {
|
|
532
|
+
this.name = "Android";
|
|
533
|
+
}
|
|
534
|
+
getClientId() {
|
|
535
|
+
if (window.JSInterface && typeof window.JSInterface.getHybridClientId == "function") {
|
|
536
|
+
let e = window.JSInterface.getHybridClientId();
|
|
537
|
+
return Promise.resolve(e || null);
|
|
538
|
+
}
|
|
539
|
+
return Promise.resolve(null);
|
|
540
|
+
}
|
|
541
|
+
signECDSA(e) {
|
|
542
|
+
if (window.JSInterface && typeof window.JSInterface.hanbiroSignECDSA == "function") try {
|
|
543
|
+
let n = window.JSInterface.hanbiroSignECDSA(e);
|
|
544
|
+
return Promise.resolve(n);
|
|
545
|
+
} catch (n) {
|
|
546
|
+
return Promise.reject(n);
|
|
547
|
+
}
|
|
548
|
+
return Promise.reject(new Error("Android JSInterface.hanbiroSignECDSA is missing"));
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
var A = "__hanbiroSessionStatusCache", He = "sig_client_uuid", I = null;
|
|
552
|
+
function K(t) {
|
|
553
|
+
if (typeof document == "undefined") return null;
|
|
554
|
+
let e = document.cookie.match(new RegExp(`(?:^|; )${t}=([^;]*)`));
|
|
555
|
+
return e ? decodeURIComponent(e[1]) : null;
|
|
556
|
+
}
|
|
557
|
+
function pe(t, e = "POST") {
|
|
558
|
+
return c(this, null, function* () {
|
|
559
|
+
if (typeof window == "undefined") return {};
|
|
560
|
+
let n = window.HanSigCommon;
|
|
561
|
+
if (!n || typeof n.generateHeaders != "function") return {};
|
|
562
|
+
try {
|
|
563
|
+
let r = yield n.generateHeaders({ method: e, url: t });
|
|
564
|
+
return r && typeof r == "object" ? r : {};
|
|
565
|
+
} catch (r) {
|
|
566
|
+
return {};
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function Be() {
|
|
571
|
+
if (typeof window == "undefined" || typeof localStorage == "undefined") return {};
|
|
572
|
+
try {
|
|
573
|
+
let t = localStorage.getItem(He);
|
|
574
|
+
return t ? { "X-Sig-Id": t } : {};
|
|
575
|
+
} catch (t) {
|
|
576
|
+
return {};
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function g() {
|
|
580
|
+
if (typeof window == "undefined") return { checked: false, logged: false, sessionVersion: null };
|
|
581
|
+
if (window !== window.parent) try {
|
|
582
|
+
if (window.parent && window.parent[A]) return window.parent[A];
|
|
583
|
+
} catch (e) {
|
|
584
|
+
}
|
|
585
|
+
let t = window;
|
|
586
|
+
return t[A] || (t[A] = { checked: false, logged: false, sessionVersion: K("GWV") }), t[A];
|
|
587
|
+
}
|
|
588
|
+
function O(t = "", e) {
|
|
589
|
+
var o, s;
|
|
590
|
+
if (e) {
|
|
591
|
+
let a = e.replace(/\/+$/, "");
|
|
592
|
+
return t ? `${a}/${t}` : a;
|
|
593
|
+
}
|
|
594
|
+
if (typeof window == "undefined") return t;
|
|
595
|
+
let n = window.location, { hostname: r } = n, i = "";
|
|
596
|
+
if (r === "localhost" || r === "127.0.0.1") {
|
|
597
|
+
let a = window;
|
|
598
|
+
i = ((o = a.baseConfig) == null ? void 0 : o.apiFrontUrl) || ((s = a.baseConfig) == null ? void 0 : s.apiUrl), i || (i = window.location.protocol + "//vndev.hanbiro.com/ngw");
|
|
599
|
+
} else {
|
|
600
|
+
if (window.location !== window.parent.location) try {
|
|
601
|
+
n = window.parent.location;
|
|
602
|
+
} catch (u) {
|
|
603
|
+
n = window.location;
|
|
604
|
+
}
|
|
605
|
+
let { hostname: a, protocol: l } = n;
|
|
606
|
+
i = [l, "//", a, "/ngw"].join("");
|
|
607
|
+
}
|
|
608
|
+
if (t !== "") {
|
|
609
|
+
let a = i.replace(/\/+$/, ""), l = t.replace(/^\/+/, "");
|
|
610
|
+
return `${a}/${l}`;
|
|
611
|
+
}
|
|
612
|
+
return i;
|
|
613
|
+
}
|
|
614
|
+
function he(t) {
|
|
615
|
+
let e = g();
|
|
616
|
+
if (typeof window == "undefined" || typeof XMLHttpRequest == "undefined") return false;
|
|
617
|
+
let n = O("sign/session_status", t);
|
|
618
|
+
try {
|
|
619
|
+
let r = new XMLHttpRequest();
|
|
620
|
+
r.open("POST", n, false), r.setRequestHeader("Content-Type", "application/json");
|
|
621
|
+
let i = Be();
|
|
622
|
+
if (Object.keys(i).forEach((o) => {
|
|
623
|
+
r.setRequestHeader(o, i[o]);
|
|
624
|
+
}), r.withCredentials = true, r.send(), r.status === 200) try {
|
|
625
|
+
let o = JSON.parse(r.responseText);
|
|
626
|
+
e.logged = !!(o && o.success);
|
|
627
|
+
} catch (o) {
|
|
628
|
+
e.logged = false;
|
|
629
|
+
}
|
|
630
|
+
else r.status === 404 ? e.logged = true : e.logged = false;
|
|
631
|
+
} catch (r) {
|
|
632
|
+
e.logged = false;
|
|
633
|
+
}
|
|
634
|
+
return e.checked = true, e.logged;
|
|
635
|
+
}
|
|
636
|
+
function Te(t) {
|
|
637
|
+
return c(this, null, function* () {
|
|
638
|
+
let e = g();
|
|
639
|
+
if (typeof window == "undefined" || typeof fetch != "function") return he(t);
|
|
640
|
+
let n = O("sign/session_status", t);
|
|
641
|
+
try {
|
|
642
|
+
let r = yield pe(n, "POST"), i = yield fetch(n, { method: "POST", headers: f({ "Content-Type": "application/json" }, r), credentials: "include" });
|
|
643
|
+
if (i.ok) {
|
|
644
|
+
let o = yield i.json();
|
|
645
|
+
e.logged = !!(o && o.success);
|
|
646
|
+
} else i.status === 404 ? e.logged = true : e.logged = false;
|
|
647
|
+
} catch (r) {
|
|
648
|
+
e.logged = false;
|
|
649
|
+
}
|
|
650
|
+
return e.checked = true, e.logged;
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
var L = { get: (t, e) => c(null, null, function* () {
|
|
654
|
+
let n = g();
|
|
655
|
+
return !t && n.checked && n.logged !== null ? n.logged : (!t && I || (I = Te(e).finally(() => {
|
|
656
|
+
I = null;
|
|
657
|
+
})), I);
|
|
658
|
+
}), getSync: (t, e) => {
|
|
659
|
+
let n = g();
|
|
660
|
+
return t || !n.checked ? he(e) : n.logged;
|
|
661
|
+
}, verifySessionVersion: (t) => c(null, null, function* () {
|
|
662
|
+
let e = K("GWV"), n = g(), r = n.sessionVersion;
|
|
663
|
+
if (e === r) return true;
|
|
664
|
+
if (!r) return n.sessionVersion = e, true;
|
|
665
|
+
try {
|
|
666
|
+
let i = O("sign/check_cookie", t), o = yield pe(i, "POST"), s = yield fetch(i, { method: "POST", headers: f({ "Content-Type": "application/json" }, o), body: JSON.stringify({ v: r }), credentials: "include" });
|
|
667
|
+
if (s.ok) {
|
|
668
|
+
let a = yield s.json();
|
|
669
|
+
return !!(a && a.success);
|
|
670
|
+
}
|
|
671
|
+
return s.status === 404;
|
|
672
|
+
} catch (i) {
|
|
673
|
+
return false;
|
|
674
|
+
} finally {
|
|
675
|
+
n.sessionVersion = K("GWV");
|
|
676
|
+
}
|
|
677
|
+
}), syncSessionVersion: () => {
|
|
678
|
+
let t = g();
|
|
679
|
+
return t.sessionVersion = K("GWV"), t.sessionVersion;
|
|
680
|
+
}, clearSessionVersion: () => {
|
|
681
|
+
let t = g();
|
|
682
|
+
t.sessionVersion = null;
|
|
683
|
+
}, setCache: (t) => {
|
|
684
|
+
let e = g();
|
|
685
|
+
return e.checked = true, e.logged = !!t, e.logged;
|
|
686
|
+
}, clearCache: () => {
|
|
687
|
+
let t = g();
|
|
688
|
+
return t.checked = false, t.logged = false, t.logged;
|
|
689
|
+
}, recheckUnauthorized: (t) => L.getSync(true, t) };
|
|
690
|
+
var $ = class extends Error {
|
|
691
|
+
constructor(n, r) {
|
|
692
|
+
super(r || "Registration conflict: key already registered");
|
|
693
|
+
this.status = 409;
|
|
694
|
+
this.name = "RegistrationConflictError", this.clientId = n;
|
|
695
|
+
}
|
|
696
|
+
}, Re = (t, e, n, r, i) => c(null, null, function* () {
|
|
697
|
+
let o = t.registerUrlTpl.replace("{id}", encodeURIComponent(e));
|
|
698
|
+
if ((location.hostname === "localhost" || location.hostname === "127.0.0.1") && (o = `${new URL(t.baseUrl).origin}${o}`), r.debug("Registering Public Key...", { url: o, id: e, hasRefreshToken: false }), typeof fetch != "function") throw new Error("fetch not supported; provide registerPublicKey override");
|
|
699
|
+
let s = yield fetch(o, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(n), credentials: "include" });
|
|
700
|
+
if (!s.ok) {
|
|
701
|
+
let a = yield s.text().catch(() => "");
|
|
702
|
+
throw r.error("Registration failed response", { status: s.status, body: a }), s.status === 409 ? new $(e, a) : new Error("sig register failed: " + s.status + " " + a);
|
|
703
|
+
}
|
|
704
|
+
return true;
|
|
705
|
+
}), W = class {
|
|
706
|
+
constructor(e) {
|
|
707
|
+
this._identityPromise = null;
|
|
708
|
+
this._registerOncePromise = null;
|
|
709
|
+
this._browserSupported = true;
|
|
710
|
+
this._enabled = true;
|
|
711
|
+
this._useGwCookie = true;
|
|
712
|
+
this.nativeAdapter = null;
|
|
713
|
+
this._createClientId = (e2) => c(this, null, function* () {
|
|
714
|
+
try {
|
|
715
|
+
this.logger.info("[MAC] Creating Client ID. Trying MAC-based UUID first.");
|
|
716
|
+
let r = yield M(e2), i = yield D(r);
|
|
717
|
+
if (i) return this.logger.info("[MAC] Using MAC-based Client ID.", { macAddresses: r, clientId: i }), this.logger.info("Generated MAC-based Client ID."), this.logger.debug("MAC addresses used for Client ID:", r), i;
|
|
718
|
+
} catch (r) {
|
|
719
|
+
this.logger.warn("[MAC] MAC-based Client ID generation failed.", r), this.logger.warn("Failed to generate MAC-based Client ID", r);
|
|
720
|
+
}
|
|
721
|
+
let n = x();
|
|
722
|
+
return this.logger.warn("[MAC] Using random Client ID fallback.", n), n;
|
|
723
|
+
});
|
|
724
|
+
this._ensureStoredClientIdAsync = (e2) => c(this, null, function* () {
|
|
725
|
+
let n = this._merge(e2), r = S(n);
|
|
726
|
+
return r ? this.logger.info("[MAC] Using stored Client ID.", { key: n.lsIdKey, clientId: r }) : (r = yield this._createClientId(n), E(n, r), this.logger.info("[MAC] Stored new Client ID.", { key: n.lsIdKey, clientId: r })), r;
|
|
727
|
+
});
|
|
728
|
+
this._resolveClientIdForHeader = (e2) => c(this, null, function* () {
|
|
729
|
+
let n = this._merge(e2);
|
|
730
|
+
if (this.nativeAdapter || this.detectHybridEnvironment(), this.nativeAdapter) try {
|
|
731
|
+
let r = yield this.nativeAdapter.getClientId();
|
|
732
|
+
if (r) return r;
|
|
733
|
+
} catch (r) {
|
|
734
|
+
this.logger.warn("Failed to get Hybrid Client ID for id-only header", r);
|
|
735
|
+
}
|
|
736
|
+
return this._ensureStoredClientIdAsync(n);
|
|
737
|
+
});
|
|
738
|
+
this.isEnabled = () => this._enabled;
|
|
739
|
+
this.isBrowserSupported = () => this._browserSupported;
|
|
740
|
+
this._merge = (e2) => (typeof (e2 == null ? void 0 : e2.debug) != "undefined" && this.logger.setEnabled(e2.debug), ie(f(f({}, this.defaults), e2)));
|
|
741
|
+
this.getCookieRaw = (e2) => B(e2);
|
|
742
|
+
this.hasIdentitySync = (e2) => {
|
|
743
|
+
let n = this._merge(e2);
|
|
744
|
+
return !!S(n);
|
|
745
|
+
};
|
|
746
|
+
this.clearPrivateKey = (e2) => c(this, null, function* () {
|
|
747
|
+
let n = this._merge(e2);
|
|
748
|
+
this.logger.info("Clearing Private Key..."), this._identityPromise = null;
|
|
749
|
+
try {
|
|
750
|
+
let r = yield q(n);
|
|
751
|
+
try {
|
|
752
|
+
return yield ge(r, n, n.idbPrivKey), true;
|
|
753
|
+
} finally {
|
|
754
|
+
r.close();
|
|
755
|
+
}
|
|
756
|
+
} catch (r) {
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
this.clearStoredClientId = (e2) => {
|
|
761
|
+
se(this._merge(e2));
|
|
762
|
+
};
|
|
763
|
+
this.getOrCreateIdentity = (e2) => {
|
|
764
|
+
if (!this._enabled) return Promise.resolve({ id: "", privateKey: null });
|
|
765
|
+
let n = this._merge(e2);
|
|
766
|
+
return this._identityPromise ? this._identityPromise : (this._identityPromise = c(this, null, function* () {
|
|
767
|
+
this.logger.group("getOrCreateIdentity");
|
|
768
|
+
try {
|
|
769
|
+
if (!this._browserSupported) throw new Error("Browser not supported: missing required features");
|
|
770
|
+
let r = m(), i = b();
|
|
771
|
+
if (!r || !i) throw new Error("WebCrypto(crypto.subtle) not supported");
|
|
772
|
+
if (typeof indexedDB == "undefined") throw new Error("IndexedDB not supported");
|
|
773
|
+
let o = S(n);
|
|
774
|
+
this.logger.debug("Stored Client ID:", o);
|
|
775
|
+
let s = yield q(n);
|
|
776
|
+
try {
|
|
777
|
+
let a = yield ce(s, n, n.idbPrivKey);
|
|
778
|
+
if (o && a) return this.logger.info("Identity found in storage."), { id: o, privateKey: a };
|
|
779
|
+
this.logger.info("Identity missing. Generating new...");
|
|
780
|
+
let l = o;
|
|
781
|
+
l || (l = yield this._createClientId(n), E(n, l), this.logger.debug("Generated new Client ID:", l));
|
|
782
|
+
let d = yield i.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]), u = yield i.exportKey("jwk", d.publicKey), p = yield i.exportKey("jwk", d.privateKey);
|
|
783
|
+
if (!u || !p) throw new Error("Failed to export keys");
|
|
784
|
+
ae(n, u);
|
|
785
|
+
let h = yield i.importKey("jwk", p, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
|
|
786
|
+
return yield ue(s, n, n.idbPrivKey, h), this.logger.info("New identity created and saved."), { id: l, privateKey: h };
|
|
787
|
+
} finally {
|
|
788
|
+
s.close(), this.logger.groupEnd();
|
|
789
|
+
}
|
|
790
|
+
} catch (r) {
|
|
791
|
+
throw this.logger.error("Error in getOrCreateIdentity", r), this.logger.groupEnd(), r;
|
|
792
|
+
}
|
|
793
|
+
}), this._identityPromise);
|
|
794
|
+
};
|
|
795
|
+
this.ensureRegisterOnce = (e2) => {
|
|
796
|
+
if (!this._enabled) return Promise.resolve(true);
|
|
797
|
+
if (this._registerOncePromise) return this._registerOncePromise;
|
|
798
|
+
let n = this._merge(e2);
|
|
799
|
+
return this._registerOncePromise = c(this, null, function* () {
|
|
800
|
+
try {
|
|
801
|
+
if (!this._browserSupported) return this.logger.error("Browser not supported, skipping registration"), false;
|
|
802
|
+
let i = (yield this.getOrCreateIdentity(e2)).id, o = j(n);
|
|
803
|
+
if (o || (this.logger.warn("Repair needed: ID exists but PubKey missing in LS"), yield this.clearPrivateKey(e2), this._identityPromise = null, i = (yield this.getOrCreateIdentity(e2)).id, o = j(n)), i && o) try {
|
|
804
|
+
e2 && typeof e2.registerPublicKey == "function" ? yield e2.registerPublicKey(i, o) : yield Re(n, i, o, this.logger);
|
|
805
|
+
} catch (s) {
|
|
806
|
+
if (s && (s instanceof $ || s.name === "RegistrationConflictError" || s.status === 409)) {
|
|
807
|
+
if (this.logger.warn("Registration conflict (409), redirecting to refresh_key page...", { clientId: i }), typeof window != "undefined") {
|
|
808
|
+
let d = `/ngw/sign/refresh_key?return_url=${encodeURIComponent(window.location.href)}`;
|
|
809
|
+
return this.logger.info("Redirecting to: " + d), window.location.href = d, new Promise(() => {
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
} else this.logger.warn("Re-registration failed (ignoring)", s);
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
return true;
|
|
816
|
+
} catch (r) {
|
|
817
|
+
return this.logger.error("ensureRegisterOnce fatal error", r), true;
|
|
818
|
+
}
|
|
819
|
+
}), this._registerOncePromise;
|
|
820
|
+
};
|
|
821
|
+
this.signCanonical = (e2, n) => c(null, null, function* () {
|
|
822
|
+
let r = b();
|
|
823
|
+
if (!r) throw new Error("WebCrypto subtle not supported");
|
|
824
|
+
let i = yield r.sign({ name: "ECDSA", hash: "SHA-256" }, e2, C(n)), o = J(new Uint8Array(i));
|
|
825
|
+
return k(o);
|
|
826
|
+
});
|
|
827
|
+
this.buildSigHeadersFromParts = (e2, n) => c(this, null, function* () {
|
|
828
|
+
if (!this._enabled) {
|
|
829
|
+
let i = yield this._resolveClientIdForHeader(n);
|
|
830
|
+
return i ? { "X-Sig-Id": i } : {};
|
|
831
|
+
}
|
|
832
|
+
let r = this._merge(n);
|
|
833
|
+
if (this.logger.debug("Building signature headers...", e2), this.nativeAdapter || this.detectHybridEnvironment(), this.nativeAdapter) try {
|
|
834
|
+
this.logger.info(`Running in Hybrid Mode (${this.nativeAdapter.name}).`);
|
|
835
|
+
let i = yield this.nativeAdapter.getClientId();
|
|
836
|
+
if (!i) throw new Error(`Hybrid adapter ${this.nativeAdapter.name} returned null ClientID`);
|
|
837
|
+
this.logger.info("Hybrid Client ID:", i);
|
|
838
|
+
let o = e2.ts || Math.floor(Date.now() / 1e3), s = e2.nonce || H(), a = { method: e2.method, host: e2.host, path: e2.path, query: e2.query, id: i, ts: o, nonce: s };
|
|
839
|
+
this._useGwCookie && (a.gw = typeof e2.gw == "string" ? e2.gw : B(r.gwCookieName));
|
|
840
|
+
let l = T(a);
|
|
841
|
+
this.logger.debug("Canonical String (Hybrid):", l);
|
|
842
|
+
let d = yield this.nativeAdapter.signECDSA(l);
|
|
843
|
+
return this.logger.info("Signature generated by Native App: ", d), { "X-Sig-Id": i, "X-Sig-Ts": String(o), "X-Sig-Nonce": s, "X-Sig-Value": d };
|
|
844
|
+
} catch (i) {
|
|
845
|
+
return this.logger.error("Hybrid signing failed: ", i), {};
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
this.logger.info("Running in Web Mode."), yield this.ensureRegisterOnce(n);
|
|
849
|
+
let i = yield this.getOrCreateIdentity(n), o = e2.ts || Math.floor(Date.now() / 1e3), s = e2.nonce || H(), a = { method: e2.method, host: e2.host, path: e2.path, query: e2.query, id: i.id, ts: o, nonce: s };
|
|
850
|
+
this._useGwCookie && (a.gw = typeof e2.gw == "string" ? e2.gw : B(r.gwCookieName)), this.logger.debug("Canonical parts input: ", a);
|
|
851
|
+
let l = T(a);
|
|
852
|
+
this.logger.debug("Canonical String:", l);
|
|
853
|
+
let d = yield this.signCanonical(i.privateKey, l);
|
|
854
|
+
return this.logger.info("Signature generated successfully"), { "X-Sig-Id": i.id, "X-Sig-Ts": String(o), "X-Sig-Nonce": s, "X-Sig-Value": d };
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
this.createClientIdFromMacAddresses = (e2) => c(this, null, function* () {
|
|
858
|
+
let n = typeof e2 == "undefined" ? yield M(this._merge()) : e2;
|
|
859
|
+
return (yield D(n)) || x();
|
|
860
|
+
});
|
|
861
|
+
this.generateHeaders = (e2, n) => c(this, null, function* () {
|
|
862
|
+
this.logger.debug("generateHeaders called with config:", e2);
|
|
863
|
+
let r = n && typeof n == "object" && !Array.isArray(n) && typeof n.resolvedUrl == "string" ? n.resolvedUrl : "", i = String(e2.method || "GET").toUpperCase(), o = e2.baseURL || window.location.origin, s = r ? new URL(r, window.location.origin) : new URL(String(e2.url || ""), o), a = new URLSearchParams(s.search ? s.search.slice(1) : "");
|
|
864
|
+
!r && e2.params && typeof e2.params == "object" && Object.keys(e2.params).forEach((d) => {
|
|
865
|
+
let u = e2.params[d];
|
|
866
|
+
u != null && (Array.isArray(u) ? u.forEach((p) => {
|
|
867
|
+
let h = d.endsWith("[]") ? d : d + "[]";
|
|
868
|
+
a.append(h, String(p));
|
|
869
|
+
}) : a.set(d, String(u)));
|
|
870
|
+
});
|
|
871
|
+
let l = a.toString();
|
|
872
|
+
return this.buildSigHeadersFromParts({ method: i, host: s.host, path: s.pathname, query: l }, n);
|
|
873
|
+
});
|
|
874
|
+
if (this.logger = new R(!!(e != null && e.debug)), this._enabled = this._checkEnabled(), this._useGwCookie = this._checkUseGwCookie(), typeof window != "undefined") if (this._isLocalStorageSupported()) if (!this._enabled) this.logger.info("Signature verification disabled via GWCONF"), this._browserSupported = true;
|
|
875
|
+
else {
|
|
876
|
+
let r = v();
|
|
877
|
+
this._browserSupported = r.supported, r.supported || (this.logger.error("Browser not supported", r.missing), (e == null ? void 0 : e.showUnsupportedMessage) !== false && w(r.missing, e == null ? void 0 : e.unsupportedContainerId));
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
let r = ["localStorage"];
|
|
881
|
+
this._browserSupported = false, this.logger.error("Browser not supported", r), (e == null ? void 0 : e.showUnsupportedMessage) !== false && w(r, e == null ? void 0 : e.unsupportedContainerId);
|
|
882
|
+
}
|
|
883
|
+
this.detectHybridEnvironment(), e != null && e.debug && this.logger.info("Initialized with options", this.defaults);
|
|
884
|
+
}
|
|
885
|
+
_isLocalStorageSupported() {
|
|
886
|
+
try {
|
|
887
|
+
let e = "__sig_test__";
|
|
888
|
+
return localStorage.setItem(e, "1"), localStorage.removeItem(e), true;
|
|
889
|
+
} catch (e) {
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
_ensureStoredClientId(e) {
|
|
894
|
+
let n = this._merge(e), r = S(n);
|
|
895
|
+
return r || (r = x(), E(n, r)), r;
|
|
896
|
+
}
|
|
897
|
+
_checkEnabled() {
|
|
898
|
+
if (typeof window == "undefined") return false;
|
|
899
|
+
let e = window.GWCONF;
|
|
900
|
+
return !e || typeof e.enableSignatureVerification == "undefined" ? false : !!e.enableSignatureVerification;
|
|
901
|
+
}
|
|
902
|
+
_checkUseGwCookie() {
|
|
903
|
+
if (typeof window == "undefined") return false;
|
|
904
|
+
let e = window.GWCONF;
|
|
905
|
+
return !e || typeof e.useGwCookieInSignature == "undefined" ? false : !!e.useGwCookieInSignature;
|
|
906
|
+
}
|
|
907
|
+
detectHybridEnvironment() {
|
|
908
|
+
if (!this.nativeAdapter) {
|
|
909
|
+
if (window.isSupportSignECDSAiOS && typeof window.webkit != "undefined" && typeof window.webkit.messageHandlers != "undefined" && typeof window.webkit.messageHandlers.observe != "undefined" && typeof window.webkit.messageHandlers.observe.postMessage != "undefined") {
|
|
910
|
+
this.logger.info("Detected iOS hybrid environment"), this.nativeAdapter = new F();
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
if (window.supportECDSAPostMessage) {
|
|
914
|
+
this.logger.info("Detected Flutter hybrid environment"), this.nativeAdapter = new N();
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
if (window.JSInterface && typeof window.JSInterface.getHybridClientId == "function" && typeof window.JSInterface.hanbiroSignECDSA == "function") {
|
|
918
|
+
this.logger.info("Detected Android hybrid environment"), this.nativeAdapter = new G();
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
typeof window != "undefined" && (window.HanSigCommon = new W({ baseUrl: location.origin }), window.HanSigCommon.randomNonce16B64u = H, window.HanSigCommon.b64urlEncodeBytes = k, window.HanSigCommon.utf8Bytes = C, window.HanSigCommon.uuidv4 = x, window.HanSigCommon.collectMacAddresses = M, window.HanSigCommon.normalizeMacAddresses = y, window.HanSigCommon.uuidFromMacAddresses = D, window.HanSigCommon.canonicalString = T, window.HanSigCommon.rawEcdsaP256ToDer = J, window.HanSigUtils = { checkBrowserSupport: v, showUnsupportedBrowserMessage: w, detectLanguage: P, isBrowserSupported: () => {
|
|
925
|
+
var t, e;
|
|
926
|
+
return (e = (t = window.HanSigCommon) == null ? void 0 : t.isBrowserSupported()) != null ? e : false;
|
|
927
|
+
} }, window.hanSessionStatus = L);
|
|
928
|
+
export {
|
|
929
|
+
W as ClientSigner,
|
|
930
|
+
$ as RegistrationConflictError,
|
|
931
|
+
L as hanSessionStatus
|
|
932
|
+
};
|