@nexus-cross/crossx-sdk-core 1.0.5 → 1.0.7
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/adapters/confirmation/BrowserConfirmationAdapter.d.ts +1 -1
- package/dist/adapters/confirmation/BrowserConfirmationAdapter.d.ts.map +1 -1
- package/dist/core/ports/ConfirmationPort.d.ts +2 -1
- package/dist/core/ports/ConfirmationPort.d.ts.map +1 -1
- package/dist/index.cjs +52 -40
- package/dist/index.js +644 -630
- package/dist/sdk/CROSSxSDK.d.ts +5 -3
- package/dist/sdk/CROSSxSDK.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var Ts = (r, e, s) => e in r ? Is(r, e, { enumerable: !0, configurable: !0, writ
|
|
|
3
3
|
var v = (r, e, s) => Ts(r, typeof e != "symbol" ? e + "" : e, s);
|
|
4
4
|
import { decodeJwt as As } from "jose";
|
|
5
5
|
var g = /* @__PURE__ */ ((r) => (r.AUTH_NOT_INITIALIZED = "AUTH_NOT_INITIALIZED", r.AUTH_FAILED = "AUTH_FAILED", r.AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID", r.AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED", r.AUTH_NOT_AUTHENTICATED = "AUTH_NOT_AUTHENTICATED", r.WALLET_NOT_FOUND = "WALLET_NOT_FOUND", r.WALLET_CREATION_FAILED = "WALLET_CREATION_FAILED", r.SIGN_FAILED = "SIGN_FAILED", r.SIGN_REJECTED = "SIGN_REJECTED", r.TX_FAILED = "TX_FAILED", r.TX_REJECTED = "TX_REJECTED", r.USER_REJECTED = "USER_REJECTED", r.TX_INVALID_PARAMS = "TX_INVALID_PARAMS", r.NETWORK_ERROR = "NETWORK_ERROR", r.NETWORK_NOT_CONFIGURED = "NETWORK_NOT_CONFIGURED", r.INVALID_CHAIN = "INVALID_CHAIN", r.CHAIN_NOT_SUPPORTED = "CHAIN_NOT_SUPPORTED", r.CHAIN_ADAPTER_NOT_FOUND = "CHAIN_ADAPTER_NOT_FOUND", r.NOT_IMPLEMENTED = "NOT_IMPLEMENTED", r.SIGNATURE_FAILED = "SIGNATURE_FAILED", r.TRANSACTION_FAILED = "TRANSACTION_FAILED", r.PREPARE_FAILED = "PREPARE_FAILED", r.PREPARE_EXPIRED = "PREPARE_EXPIRED", r.PREPARE_MISMATCH = "PREPARE_MISMATCH", r.MIGRATION_FAILED = "MIGRATION_FAILED", r.MIGRATION_BACKUP_EXISTS = "MIGRATION_BACKUP_EXISTS", r.GATEWAY_INTERNAL_ERROR = "GATEWAY_INTERNAL_ERROR", r.GATEWAY_LOCK_CONFLICT = "GATEWAY_LOCK_CONFLICT", r.PROJECT_ID_MISSING = "PROJECT_ID_MISSING", r.ORIGIN_NOT_ALLOWED = "ORIGIN_NOT_ALLOWED", r.APP_IDENTIFIER_MISSING = "APP_IDENTIFIER_MISSING", r.INVALID_APP_TYPE = "INVALID_APP_TYPE", r.PROJECT_NOT_REGISTERED = "PROJECT_NOT_REGISTERED", r.SIGNATURE_SIGNER_MISMATCH = "SIGNATURE_SIGNER_MISMATCH", r.GAS_ESTIMATION_FAILED = "GAS_ESTIMATION_FAILED", r.TYPED_DATA_CHAIN_ID_MISMATCH = "TYPED_DATA_CHAIN_ID_MISMATCH", r.INVALID_CONFIG = "INVALID_CONFIG", r.UNKNOWN_ERROR = "UNKNOWN_ERROR", r))(g || {});
|
|
6
|
-
class
|
|
6
|
+
class x extends Error {
|
|
7
7
|
constructor(e, s, t) {
|
|
8
|
-
super(s), this.code = e, this.details = t, this.name = "CROSSxError", Object.setPrototypeOf(this,
|
|
8
|
+
super(s), this.code = e, this.details = t, this.name = "CROSSxError", Object.setPrototypeOf(this, x.prototype);
|
|
9
9
|
}
|
|
10
10
|
toJSON() {
|
|
11
11
|
return {
|
|
@@ -106,7 +106,7 @@ class Cs {
|
|
|
106
106
|
}
|
|
107
107
|
case "personal_sign":
|
|
108
108
|
case "eth_sign":
|
|
109
|
-
throw new
|
|
109
|
+
throw new x(
|
|
110
110
|
g.NOT_IMPLEMENTED,
|
|
111
111
|
`${e} is not yet supported. Use sdk.signMessage() directly.`
|
|
112
112
|
);
|
|
@@ -114,7 +114,7 @@ class Cs {
|
|
|
114
114
|
case "eth_signTypedData_v1":
|
|
115
115
|
case "eth_signTypedData_v3":
|
|
116
116
|
case "eth_signTypedData_v4":
|
|
117
|
-
throw new
|
|
117
|
+
throw new x(
|
|
118
118
|
g.NOT_IMPLEMENTED,
|
|
119
119
|
`${e} is not yet supported. Use sdk.signTypedData() or sdk.signTypedDataOffchain() directly.`
|
|
120
120
|
);
|
|
@@ -168,7 +168,7 @@ let we = null;
|
|
|
168
168
|
function wt(r) {
|
|
169
169
|
we = r;
|
|
170
170
|
}
|
|
171
|
-
const
|
|
171
|
+
const p = {
|
|
172
172
|
log(...r) {
|
|
173
173
|
if (we) {
|
|
174
174
|
we.log(...r);
|
|
@@ -202,7 +202,7 @@ class ks {
|
|
|
202
202
|
*/
|
|
203
203
|
checkResponseError(e, s) {
|
|
204
204
|
if (e != null && e.code && e.code !== 200 && e.code > 0)
|
|
205
|
-
throw new
|
|
205
|
+
throw new x(
|
|
206
206
|
g.AUTH_FAILED,
|
|
207
207
|
`${s} failed (code ${e.code}): ${e.message}`
|
|
208
208
|
);
|
|
@@ -210,7 +210,7 @@ class ks {
|
|
|
210
210
|
if (typeof t == "object" && t !== null && "code" in t) {
|
|
211
211
|
const n = t;
|
|
212
212
|
if (n.code && n.code !== 200 && n.code > 0)
|
|
213
|
-
throw new
|
|
213
|
+
throw new x(
|
|
214
214
|
g.AUTH_FAILED,
|
|
215
215
|
`${s} failed (code ${n.code}): ${n.message}`
|
|
216
216
|
);
|
|
@@ -223,55 +223,55 @@ class ks {
|
|
|
223
223
|
const c = e == null ? void 0 : e.provider;
|
|
224
224
|
let l = "/login";
|
|
225
225
|
c === "google" ? l = "/google" : c === "apple" && (l = "/apple");
|
|
226
|
-
const { oauthServiceUrl: d, authApiUrl:
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
authUrl:
|
|
226
|
+
const { oauthServiceUrl: d, authApiUrl: f } = this.config, w = `${d}${l}`;
|
|
227
|
+
p.log(`[CROSSx] OAuth 팝업 열기 (${c || "일반"} 로그인):`, w);
|
|
228
|
+
const _ = await this.oauth.openAuth({
|
|
229
|
+
authUrl: w,
|
|
230
230
|
expectedOrigin: new URL(d).origin
|
|
231
231
|
});
|
|
232
|
-
|
|
233
|
-
const { accessToken:
|
|
234
|
-
let
|
|
232
|
+
p.log("[CROSSx] OAuth Firebase 토큰 받음 (length:", _.length, ")");
|
|
233
|
+
const { accessToken: m, refreshToken: A } = await this.exchangeFirebaseToken(_, f);
|
|
234
|
+
let y, I;
|
|
235
235
|
try {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
236
|
+
const U = this.crypto.decodeJWT(_);
|
|
237
|
+
I = (n = U.firebase) == null ? void 0 : n.sign_in_provider;
|
|
238
|
+
const $ = ((o = U.firebase) == null ? void 0 : o.identities) ?? {};
|
|
239
|
+
I === "google.com" ? y = (i = $["google.com"]) == null ? void 0 : i[0] : I === "apple.com" && (y = (a = $["apple.com"]) == null ? void 0 : a[0]), p.log("[CROSSx] OAuth provider sub 추출 — provider:", I, "hasProviderSub:", !!y);
|
|
240
240
|
} catch {
|
|
241
|
-
|
|
241
|
+
p.warn("[CROSSx] firebaseToken에서 providerSub 추출 실패");
|
|
242
242
|
}
|
|
243
|
-
if (
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
if (t =
|
|
248
|
-
throw
|
|
249
|
-
const
|
|
250
|
-
s = {
|
|
251
|
-
id: M.sub,
|
|
252
|
-
email: M.email,
|
|
253
|
-
signInProvider: E,
|
|
254
|
-
providerSub: S
|
|
255
|
-
}, this.tokenStore.set(w), this.useCookieAuth || (await this.storage.set(Ye, w), b && await this.storage.set(Ne, b));
|
|
256
|
-
} else {
|
|
257
|
-
const B = this.crypto.decodeJWT(x);
|
|
243
|
+
if (m) {
|
|
244
|
+
const U = this.crypto.decodeJWT(m);
|
|
245
|
+
p.log("[CROSSx] access_token 디코딩 — sub:", U.sub, "exp:", U.exp);
|
|
246
|
+
const $ = await this.crypto.verifyJWT(m);
|
|
247
|
+
if (t = $.signatureVerified ?? !1, !$.valid)
|
|
248
|
+
throw p.error("[CROSSx] access_token 검증 실패"), new Error("Invalid access token");
|
|
249
|
+
const B = $.payload;
|
|
258
250
|
s = {
|
|
259
251
|
id: B.sub,
|
|
260
252
|
email: B.email,
|
|
261
|
-
signInProvider:
|
|
262
|
-
providerSub:
|
|
263
|
-
},
|
|
253
|
+
signInProvider: I,
|
|
254
|
+
providerSub: y
|
|
255
|
+
}, this.tokenStore.set(m), this.useCookieAuth || (await this.storage.set(Ye, m), A && await this.storage.set(Ne, A));
|
|
256
|
+
} else {
|
|
257
|
+
const U = this.crypto.decodeJWT(_);
|
|
258
|
+
s = {
|
|
259
|
+
id: U.sub,
|
|
260
|
+
email: U.email,
|
|
261
|
+
signInProvider: I,
|
|
262
|
+
providerSub: y
|
|
263
|
+
}, p.log("[CROSSx] Cookie 모드 — Firebase 토큰에서 사용자 정보 추출 — id:", s.id);
|
|
264
264
|
}
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
await this.storage.set(Pe,
|
|
265
|
+
p.log("[CROSSx] 사용자 정보 — id:", s.id);
|
|
266
|
+
const L = this.useCookieAuth ? { id: s.id, signInProvider: s.signInProvider, providerSub: s.providerSub } : s;
|
|
267
|
+
await this.storage.set(Pe, L), p.log("[CROSSx] 사용자 정보 저장 완료 (authMode:", this.useCookieAuth ? "cookie" : "token", ")");
|
|
268
268
|
} catch (c) {
|
|
269
|
-
return
|
|
269
|
+
return p.error("[CROSSx] SignIn 에러 (OAuth/토큰 교환 단계):", c), {
|
|
270
270
|
success: !1,
|
|
271
271
|
error: c instanceof Error ? c.message : "Sign in failed"
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
-
return
|
|
274
|
+
return p.log("[CROSSx][Migration Phase 1] OAuth 로그인 완료, 지갑 로드 시작 — userId:", s.id), this.loadWallet(s, t);
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
277
277
|
* Firebase 토큰 → CROSSx 인증 교환
|
|
@@ -280,7 +280,7 @@ class ks {
|
|
|
280
280
|
*/
|
|
281
281
|
async exchangeFirebaseToken(e, s) {
|
|
282
282
|
const t = this.useCookieAuth, n = t ? `${s}/cross-auth/social/login/cookie` : `${s}/cross-auth/social/login`;
|
|
283
|
-
|
|
283
|
+
p.log("[CROSSx] Firebase 토큰 교환 요청:", n);
|
|
284
284
|
const o = await this.transport.request({
|
|
285
285
|
url: n,
|
|
286
286
|
method: "POST",
|
|
@@ -288,18 +288,18 @@ class ks {
|
|
|
288
288
|
body: { auth_code: e, login_type: "firebase" },
|
|
289
289
|
...t ? { credentials: "include" } : {}
|
|
290
290
|
});
|
|
291
|
-
|
|
291
|
+
p.log("[CROSSx] 토큰 교환 응답 — status:", o.status);
|
|
292
292
|
const i = o.data;
|
|
293
293
|
this.checkResponseError(i, "Token exchange");
|
|
294
294
|
const a = this.extractAccessToken(i);
|
|
295
295
|
if (t && !a)
|
|
296
|
-
return
|
|
296
|
+
return p.log("[CROSSx] Cookie 모드 — 로그인 성공 (JWT는 HttpOnly 쿠키)"), {};
|
|
297
297
|
if (!a)
|
|
298
|
-
throw new
|
|
298
|
+
throw new x(
|
|
299
299
|
g.AUTH_FAILED,
|
|
300
300
|
"access_token not found in exchange response"
|
|
301
301
|
);
|
|
302
|
-
|
|
302
|
+
p.log("[CROSSx] access_token 교환 성공");
|
|
303
303
|
let c;
|
|
304
304
|
return t || (c = this.extractRefreshToken(i)), { accessToken: a, refreshToken: c };
|
|
305
305
|
}
|
|
@@ -361,38 +361,38 @@ class ks {
|
|
|
361
361
|
if (t.valid) {
|
|
362
362
|
const n = await this.storage.get(Pe);
|
|
363
363
|
if (n)
|
|
364
|
-
return
|
|
364
|
+
return p.log("[CROSSx] restoreSession — 메모리 토큰 유효, 세션 복원"), this.loadWallet(n, t.signatureVerified);
|
|
365
365
|
}
|
|
366
366
|
this.tokenStore.clear();
|
|
367
367
|
}
|
|
368
368
|
if (this.useCookieAuth) {
|
|
369
|
-
|
|
369
|
+
p.log("[CROSSx] restoreSession — 쿠키 기반 silentRefresh 시도");
|
|
370
370
|
const t = await this.silentRefresh();
|
|
371
371
|
t && this.tokenStore.set(t);
|
|
372
372
|
} else {
|
|
373
373
|
const t = await this.storage.get(Ye), n = await this.storage.get(Ne);
|
|
374
|
-
if (
|
|
374
|
+
if (p.log(
|
|
375
375
|
"[CROSSx] restoreSession — access_token:",
|
|
376
376
|
t ? "있음" : "없음",
|
|
377
377
|
"refresh_token:",
|
|
378
378
|
n ? "있음" : "없음"
|
|
379
379
|
), !n)
|
|
380
|
-
return
|
|
380
|
+
return p.log("[CROSSx] restoreSession — refresh_token 없음, 세션 복원 생략"), null;
|
|
381
381
|
t && this.tokenStore.set(t);
|
|
382
382
|
const o = await this.silentRefresh(n);
|
|
383
|
-
|
|
383
|
+
p.log("[CROSSx] restoreSession — silentRefresh 결과:", o ? "토큰 발급 성공" : "토큰 없음"), o && this.tokenStore.set(o);
|
|
384
384
|
}
|
|
385
385
|
const s = await this.storage.get(Pe);
|
|
386
|
-
if (
|
|
386
|
+
if (p.log("[CROSSx] restoreSession — userInfo 조회:", s ? `있음 (id: ${s.id})` : "없음"), !s)
|
|
387
387
|
return null;
|
|
388
|
-
|
|
388
|
+
p.log("[CROSSx] restoreSession — silentRefresh 성공, 세션 복원 — userId:", s.id);
|
|
389
389
|
try {
|
|
390
390
|
return await this.loadWallet(s, !1);
|
|
391
391
|
} catch (t) {
|
|
392
|
-
return
|
|
392
|
+
return p.warn("[CROSSx] restoreSession — 지갑 로드 실패 (세션은 유지):", t), { success: !0, user: s, tokenSignatureVerified: !1 };
|
|
393
393
|
}
|
|
394
394
|
} catch (e) {
|
|
395
|
-
return
|
|
395
|
+
return p.log("[CROSSx] restoreSession — 세션 복원 실패, 스토리지 정리:", e), this.tokenStore.clear(), this.useCookieAuth || await this.storage.remove(Ne), await this.storage.remove(Pe), null;
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
/**
|
|
@@ -418,37 +418,37 @@ class ks {
|
|
|
418
418
|
body: o,
|
|
419
419
|
...t ? { credentials: "include" } : {}
|
|
420
420
|
});
|
|
421
|
-
|
|
421
|
+
p.log("[CROSSx] silentRefresh 응답 — status:", i.status);
|
|
422
422
|
const a = i.data;
|
|
423
423
|
this.checkResponseError(a, "Silent refresh");
|
|
424
424
|
const c = this.extractAccessToken(a);
|
|
425
425
|
if (t && !c) {
|
|
426
|
-
|
|
426
|
+
p.log("[CROSSx] silentRefresh 성공 (cookie 갱신)");
|
|
427
427
|
return;
|
|
428
428
|
}
|
|
429
429
|
if (!c)
|
|
430
|
-
throw new
|
|
430
|
+
throw new x(g.AUTH_FAILED, "Silent refresh failed: no token in response");
|
|
431
431
|
if (this.tokenStore.set(c), !t) {
|
|
432
432
|
await this.storage.set(Ye, c);
|
|
433
433
|
const l = this.extractRefreshToken(a);
|
|
434
434
|
l && await this.storage.set(Ne, l);
|
|
435
435
|
}
|
|
436
|
-
return
|
|
436
|
+
return p.log("[CROSSx] silentRefresh 성공"), c;
|
|
437
437
|
}
|
|
438
438
|
async loadWallet(e, s) {
|
|
439
439
|
let t, n = !1;
|
|
440
440
|
try {
|
|
441
|
-
|
|
441
|
+
p.log("[CROSSx][Migration Phase 2] POST /mnemonic/create 호출 — userId:", e.id), t = (await this.walletProvider.getOrCreateWallet(e.id)).address, p.log("[CROSSx][Migration Phase 2] 지갑 로드 완료 (기존 백업 없음) — address:", t);
|
|
442
442
|
} catch (o) {
|
|
443
|
-
if (o instanceof
|
|
444
|
-
|
|
443
|
+
if (o instanceof x && o.code === g.MIGRATION_BACKUP_EXISTS)
|
|
444
|
+
p.log("[CROSSx][Migration Phase 2] Gateway -10012 감지 → needsMigration = true"), n = !0;
|
|
445
445
|
else {
|
|
446
|
-
if (o instanceof
|
|
447
|
-
throw
|
|
448
|
-
|
|
446
|
+
if (o instanceof x && (o.code === g.PROJECT_NOT_REGISTERED || o.code === g.PROJECT_ID_MISSING || o.code === g.ORIGIN_NOT_ALLOWED))
|
|
447
|
+
throw p.error("[CROSSx][Migration Phase 2] 프로젝트 설정 에러:", o.message), o;
|
|
448
|
+
p.warn("[CROSSx][Migration Phase 2] 지갑 로드 실패 (로그인은 유지):", o);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
return
|
|
451
|
+
return p.log("[CROSSx][Migration Phase 2] loadWallet 결과 — address:", t, "needsMigration:", n), { success: !0, address: t, user: e, needsMigration: n, tokenSignatureVerified: s };
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
const Ns = "crossx_access_token", Ps = "crossx_refresh_token", Ls = "crossx_user_info";
|
|
@@ -466,13 +466,13 @@ class $s {
|
|
|
466
466
|
}
|
|
467
467
|
async execute(e, s) {
|
|
468
468
|
if (!this.walletProvider.migrateWallet)
|
|
469
|
-
throw new
|
|
469
|
+
throw new x(
|
|
470
470
|
g.NOT_IMPLEMENTED,
|
|
471
471
|
"Migration is not supported in the current environment"
|
|
472
472
|
);
|
|
473
|
-
|
|
473
|
+
p.log("[CROSSx][Migration Phase 4] MigrateWalletUseCase.execute() — pin 길이:", e.length, "sub:", s);
|
|
474
474
|
const t = await this.walletProvider.migrateWallet(e, s);
|
|
475
|
-
return
|
|
475
|
+
return p.log("[CROSSx][Migration Phase 5] MigrateWalletUseCase 완료 — address:", t.address), {
|
|
476
476
|
address: t.address
|
|
477
477
|
};
|
|
478
478
|
}
|
|
@@ -502,7 +502,7 @@ class Ms {
|
|
|
502
502
|
body: o
|
|
503
503
|
})).data;
|
|
504
504
|
if (a != null && a.error)
|
|
505
|
-
throw new
|
|
505
|
+
throw new x(
|
|
506
506
|
g.UNKNOWN_ERROR,
|
|
507
507
|
`RPC error [${e}] (${t}): ${a.error.message} (code: ${a.error.code})`
|
|
508
508
|
);
|
|
@@ -602,14 +602,14 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
602
602
|
*/
|
|
603
603
|
async initialize() {
|
|
604
604
|
if (this.initialized) return this.authenticated ? { success: !0, address: this.address ?? void 0 } : null;
|
|
605
|
-
console.log("[CROSSx SDK] v1.0.
|
|
605
|
+
console.log("[CROSSx SDK] v1.0.7 initializing...");
|
|
606
606
|
try {
|
|
607
607
|
const e = await Fs();
|
|
608
608
|
this.internalConfig.oauthServiceUrl = e.oauthServiceUrl, this.internalConfig.authApiUrl = e.authApiUrl, this.internalConfig.walletGatewayUrl = e.walletGatewayUrl, this.adapterConfig.gatewayUrl = e.walletGatewayUrl;
|
|
609
609
|
const s = await this.signInUseCase.restoreSession();
|
|
610
610
|
return s != null && s.success && this.applyAuthResult(s), this.initialized = !0, this.emit("initialized", { restored: !!(s != null && s.success) }), s ?? null;
|
|
611
611
|
} catch (e) {
|
|
612
|
-
throw new
|
|
612
|
+
throw new x(g.AUTH_NOT_INITIALIZED, "SDK initialization failed", e);
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
async signIn(e) {
|
|
@@ -625,7 +625,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
625
625
|
const t = await this.signInUseCase.execute(s);
|
|
626
626
|
return t.success && this.applyAuthResult(t), t;
|
|
627
627
|
} catch (t) {
|
|
628
|
-
throw new
|
|
628
|
+
throw new x(g.AUTH_FAILED, "Sign in failed", t);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
631
|
/**
|
|
@@ -660,7 +660,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
660
660
|
try {
|
|
661
661
|
await this.signOutUseCase.execute(), this.clearAuthState();
|
|
662
662
|
} catch (e) {
|
|
663
|
-
throw new
|
|
663
|
+
throw new x(g.UNKNOWN_ERROR, "Sign out failed", e);
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
isAuthenticated() {
|
|
@@ -736,12 +736,12 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
736
736
|
*/
|
|
737
737
|
async migrateWallet(e) {
|
|
738
738
|
if (this.ensureAuthenticated(), !this.userId)
|
|
739
|
-
throw new
|
|
739
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
740
740
|
try {
|
|
741
741
|
const s = await this.migrateWalletUseCase.execute(e, this.userId);
|
|
742
|
-
return this.address = s.address, this.emit("addressChanged", { address: s.address, index: 0 }),
|
|
742
|
+
return this.address = s.address, this.emit("addressChanged", { address: s.address, index: 0 }), p.log("[CROSSx] migrateWallet 완료 — address:", s.address), s;
|
|
743
743
|
} catch (s) {
|
|
744
|
-
throw s instanceof
|
|
744
|
+
throw s instanceof x ? s : new x(
|
|
745
745
|
g.MIGRATION_FAILED,
|
|
746
746
|
"Wallet migration failed",
|
|
747
747
|
s
|
|
@@ -763,7 +763,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
763
763
|
async getAddress(e) {
|
|
764
764
|
if (e !== void 0) {
|
|
765
765
|
if (this.ensureAuthenticated(), !this.userId)
|
|
766
|
-
throw new
|
|
766
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
767
767
|
return { address: (await this.walletProvider.getAddress(this.userId, e)).address, index: e };
|
|
768
768
|
}
|
|
769
769
|
return !this.authenticated || !this.address ? null : { address: this.address, index: 0 };
|
|
@@ -787,34 +787,35 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
787
787
|
* SDK 내부에 "활성 지갑" 상태를 저장하지 않습니다.
|
|
788
788
|
* 반환된 index를 서명/전송 시 opts.index로 전달하세요.
|
|
789
789
|
*
|
|
790
|
+
* @param currentAddress 현재 활성 지갑 주소 (선택 UI에 "selected" 표시, 미전달 시 표시 없음)
|
|
790
791
|
* @returns 선택된 지갑 `{ address, index }` 또는 닫기 시 `null`
|
|
791
792
|
*
|
|
792
793
|
* @example
|
|
793
|
-
* const wallet = await sdk.selectWallet();
|
|
794
|
+
* const wallet = await sdk.selectWallet(currentAddress);
|
|
794
795
|
* if (wallet) {
|
|
795
796
|
* await sdk.signMessage(chainId, message, { index: wallet.index });
|
|
796
797
|
* }
|
|
797
798
|
*/
|
|
798
|
-
async selectWallet() {
|
|
799
|
+
async selectWallet(e) {
|
|
799
800
|
if (this.ensureAuthenticated(), !this.userId)
|
|
800
|
-
throw new
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
e,
|
|
801
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
802
|
+
const s = await this.walletProvider.getAddresses(this.userId), t = await this.confirmation.showWalletSelector(
|
|
803
|
+
s,
|
|
804
804
|
async () => {
|
|
805
|
-
const
|
|
806
|
-
return
|
|
807
|
-
}
|
|
805
|
+
const n = s.length, i = { address: (await this.walletProvider.getAddress(this.userId, n)).address, index: n };
|
|
806
|
+
return s.push(i), i;
|
|
807
|
+
},
|
|
808
|
+
e
|
|
808
809
|
);
|
|
810
|
+
return t && (this.address = t.address, this.emit("addressChanged", { address: t.address, index: t.index })), t;
|
|
809
811
|
}
|
|
810
812
|
/**
|
|
811
|
-
* 지갑이 2개 이상이면 selectWallet()을
|
|
813
|
+
* 지갑이 2개 이상이면 selectWallet()을 호출합니다.
|
|
814
|
+
* selectWallet() 내부에서 this.address 설정 및 addressChanged 이벤트를 처리합니다.
|
|
812
815
|
* 지갑이 1개 이하이거나 사용자가 취소하면 null을 반환합니다.
|
|
813
816
|
*/
|
|
814
817
|
async selectWalletIfMultiple(e) {
|
|
815
|
-
|
|
816
|
-
const s = await this.selectWallet();
|
|
817
|
-
return s && (this.address = s.address, this.emit("addressChanged", { address: s.address, index: s.index })), s;
|
|
818
|
+
return e.length < 2 ? null : this.selectWallet();
|
|
818
819
|
}
|
|
819
820
|
// ============================================================================
|
|
820
821
|
// 체인 조회
|
|
@@ -836,7 +837,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
836
837
|
try {
|
|
837
838
|
return await this.chainRegistry.getChains();
|
|
838
839
|
} catch (e) {
|
|
839
|
-
throw e instanceof
|
|
840
|
+
throw e instanceof x ? e : new x(g.UNKNOWN_ERROR, "Failed to fetch chains", e);
|
|
840
841
|
}
|
|
841
842
|
}
|
|
842
843
|
/**
|
|
@@ -855,7 +856,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
855
856
|
try {
|
|
856
857
|
return await this.chainRegistry.getChain(e);
|
|
857
858
|
} catch (s) {
|
|
858
|
-
throw s instanceof
|
|
859
|
+
throw s instanceof x ? s : new x(g.CHAIN_NOT_SUPPORTED, `Failed to fetch chain: ${e}`, s);
|
|
859
860
|
}
|
|
860
861
|
}
|
|
861
862
|
// ============================================================================
|
|
@@ -881,19 +882,19 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
881
882
|
*/
|
|
882
883
|
async createWallet() {
|
|
883
884
|
if (this.ensureAuthenticated(), !this.userId)
|
|
884
|
-
throw new
|
|
885
|
-
|
|
885
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
886
|
+
p.log("[CROSSx] 지갑 생성 시작");
|
|
886
887
|
try {
|
|
887
888
|
const e = await this.walletProvider.getOrCreateWallet(this.userId);
|
|
888
|
-
return this.address = e.address, this.emit("addressChanged", { address: e.address, index: 0 }),
|
|
889
|
+
return this.address = e.address, this.emit("addressChanged", { address: e.address, index: 0 }), p.log("[CROSSx] 지갑 생성 완료:", e.address), { address: e.address };
|
|
889
890
|
} catch (e) {
|
|
890
|
-
if (e instanceof
|
|
891
|
+
if (e instanceof x && e.code === g.MIGRATION_BACKUP_EXISTS) {
|
|
891
892
|
const s = this.providerSub ?? this.userId;
|
|
892
|
-
|
|
893
|
+
p.log("[CROSSx][Migration Phase 3] createWallet() — Gateway -10012 감지, 마이그레이션 UI 시작 — migrationSub:", s);
|
|
893
894
|
const t = await this.handleMigrationFlow(s);
|
|
894
895
|
if (t)
|
|
895
896
|
return this.address = t.address, this.emit("addressChanged", { address: t.address, index: 0 }), { address: t.address };
|
|
896
|
-
throw new
|
|
897
|
+
throw new x(
|
|
897
898
|
g.MIGRATION_FAILED,
|
|
898
899
|
"Migration skipped by user"
|
|
899
900
|
);
|
|
@@ -913,7 +914,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
913
914
|
*/
|
|
914
915
|
async signMessage(e, s, t) {
|
|
915
916
|
if (this.ensureAuthenticated(), !this.userId)
|
|
916
|
-
throw new
|
|
917
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
917
918
|
const n = t == null ? void 0 : t.index, o = await this.walletProvider.getAddress(this.userId, n ?? 0);
|
|
918
919
|
let i;
|
|
919
920
|
if (this.walletProvider.prepare && (i = (await this.walletProvider.prepare("sign-message", { message: s, from: o.address })).uuid), !await this.confirmation.requestConfirmation({
|
|
@@ -924,7 +925,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
924
925
|
dappName: t == null ? void 0 : t.dappName,
|
|
925
926
|
accountName: t == null ? void 0 : t.accountName
|
|
926
927
|
}))
|
|
927
|
-
throw new
|
|
928
|
+
throw new x(g.USER_REJECTED, "User rejected message signing");
|
|
928
929
|
try {
|
|
929
930
|
const c = await this.walletProvider.signMessage(
|
|
930
931
|
this.userId,
|
|
@@ -941,7 +942,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
941
942
|
address: o.address
|
|
942
943
|
};
|
|
943
944
|
} catch (c) {
|
|
944
|
-
throw c instanceof
|
|
945
|
+
throw c instanceof x ? c : new x(g.SIGNATURE_FAILED, `Message signing failed (${e})`, c);
|
|
945
946
|
}
|
|
946
947
|
}
|
|
947
948
|
/**
|
|
@@ -967,9 +968,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
967
968
|
*/
|
|
968
969
|
async signTypedData(e, s, t) {
|
|
969
970
|
if (this.ensureAuthenticated(), !this.userId)
|
|
970
|
-
throw new
|
|
971
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
971
972
|
if (!this.walletProvider.signTypedData)
|
|
972
|
-
throw new
|
|
973
|
+
throw new x(g.NOT_IMPLEMENTED, "signTypedData is not implemented");
|
|
973
974
|
X.validateTypedDataChainId(e, s);
|
|
974
975
|
const n = await this.walletProvider.getAddress(this.userId, (t == null ? void 0 : t.index) ?? 0);
|
|
975
976
|
let o;
|
|
@@ -981,7 +982,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
981
982
|
dappName: t == null ? void 0 : t.dappName,
|
|
982
983
|
accountName: t == null ? void 0 : t.accountName
|
|
983
984
|
}))
|
|
984
|
-
throw new
|
|
985
|
+
throw new x(g.USER_REJECTED, "User rejected typed data signing");
|
|
985
986
|
try {
|
|
986
987
|
const a = await this.walletProvider.signTypedData(
|
|
987
988
|
this.userId,
|
|
@@ -997,7 +998,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
997
998
|
address: n.address
|
|
998
999
|
};
|
|
999
1000
|
} catch (a) {
|
|
1000
|
-
throw a instanceof
|
|
1001
|
+
throw a instanceof x ? a : new x(g.SIGNATURE_FAILED, `Typed data signing failed (${e})`, a);
|
|
1001
1002
|
}
|
|
1002
1003
|
}
|
|
1003
1004
|
/**
|
|
@@ -1033,7 +1034,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1033
1034
|
*/
|
|
1034
1035
|
async signTransaction(e, s, t) {
|
|
1035
1036
|
if (this.ensureAuthenticated(), !this.userId)
|
|
1036
|
-
throw new
|
|
1037
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
1037
1038
|
const n = await this.withResolvedGasAndFee(s, e);
|
|
1038
1039
|
let o;
|
|
1039
1040
|
this.walletProvider.prepare && (o = (await this.walletProvider.prepare("sign", { tx: n })).uuid);
|
|
@@ -1054,7 +1055,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1054
1055
|
dappName: t == null ? void 0 : t.dappName,
|
|
1055
1056
|
accountName: t == null ? void 0 : t.accountName
|
|
1056
1057
|
}))
|
|
1057
|
-
throw new
|
|
1058
|
+
throw new x(g.USER_REJECTED, "User rejected transaction signing");
|
|
1058
1059
|
try {
|
|
1059
1060
|
const c = await this.walletProvider.signTransaction(
|
|
1060
1061
|
this.userId,
|
|
@@ -1069,9 +1070,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1069
1070
|
txHash: c.txHash ?? ""
|
|
1070
1071
|
};
|
|
1071
1072
|
} catch (c) {
|
|
1072
|
-
if (c instanceof
|
|
1073
|
+
if (c instanceof x) throw c;
|
|
1073
1074
|
const l = c instanceof Error ? c.message : String(c);
|
|
1074
|
-
throw new
|
|
1075
|
+
throw new x(
|
|
1075
1076
|
g.SIGNATURE_FAILED,
|
|
1076
1077
|
`Transaction signing failed (${e}): ${l}`,
|
|
1077
1078
|
c
|
|
@@ -1086,7 +1087,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1086
1087
|
*/
|
|
1087
1088
|
async sendTransaction(e, s, t) {
|
|
1088
1089
|
if (this.ensureAuthenticated(), !this.userId)
|
|
1089
|
-
throw new
|
|
1090
|
+
throw new x(g.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
1090
1091
|
const n = await this.withResolvedGasAndFee(s, e);
|
|
1091
1092
|
let o;
|
|
1092
1093
|
this.walletProvider.prepare && (o = (await this.walletProvider.prepare("send", { tx: n })).uuid);
|
|
@@ -1107,7 +1108,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1107
1108
|
dappName: t == null ? void 0 : t.dappName,
|
|
1108
1109
|
accountName: t == null ? void 0 : t.accountName
|
|
1109
1110
|
}))
|
|
1110
|
-
throw new
|
|
1111
|
+
throw new x(g.USER_REJECTED, "User rejected transaction");
|
|
1111
1112
|
try {
|
|
1112
1113
|
let c;
|
|
1113
1114
|
if (this.walletProvider.sendTransaction)
|
|
@@ -1130,7 +1131,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1130
1131
|
return { chainId: e, txHash: c, status: "pending" };
|
|
1131
1132
|
} catch (c) {
|
|
1132
1133
|
const l = c instanceof Error ? c.message : String(c);
|
|
1133
|
-
throw new
|
|
1134
|
+
throw new x(
|
|
1134
1135
|
g.TRANSACTION_FAILED,
|
|
1135
1136
|
`Transaction failed (${e}): ${l}`,
|
|
1136
1137
|
c
|
|
@@ -1163,7 +1164,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1163
1164
|
if (l) return l;
|
|
1164
1165
|
await new Promise((d) => setTimeout(d, c)), c = Math.min(c * 2, o);
|
|
1165
1166
|
}
|
|
1166
|
-
throw new
|
|
1167
|
+
throw new x(
|
|
1167
1168
|
g.UNKNOWN_ERROR,
|
|
1168
1169
|
`Transaction receipt timeout (${e})`
|
|
1169
1170
|
);
|
|
@@ -1184,37 +1185,37 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1184
1185
|
* logger.log(receipt.status); // '0x1' | '0x0'
|
|
1185
1186
|
*/
|
|
1186
1187
|
async sendTransactionWithWaitForReceipt(e, s, t = {}) {
|
|
1187
|
-
var
|
|
1188
|
-
const { intervalMs: n, timeoutMs: o, ...i } = t, { txHash: a } = await this.sendTransaction(e, s, i), c = n ?? ((
|
|
1189
|
-
let
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
const
|
|
1188
|
+
var A, y;
|
|
1189
|
+
const { intervalMs: n, timeoutMs: o, ...i } = t, { txHash: a } = await this.sendTransaction(e, s, i), c = n ?? ((A = this._config.receiptPolling) == null ? void 0 : A.intervalMs) ?? Hs, l = o ?? ((y = this._config.receiptPolling) == null ? void 0 : y.timeoutMs) ?? bt, d = ze(e), f = s.from ?? "";
|
|
1190
|
+
let w, _;
|
|
1191
|
+
const m = this.waitForTxAndGetReceipt(a, e, { intervalMs: c, timeoutMs: l }).then((I) => {
|
|
1192
|
+
w = I;
|
|
1193
|
+
const L = BigInt(I.gasUsed) * BigInt(I.effectiveGasPrice), U = s.value ? BigInt(s.value) : 0n, $ = X.formatTxAmount(s.value, d.symbol, d.decimals), B = X.formatTxAmount("0x" + L.toString(16), d.symbol, d.decimals), Q = X.formatTxAmount("0x" + (U + L).toString(16), d.symbol, d.decimals);
|
|
1193
1194
|
return {
|
|
1194
1195
|
chainId: e,
|
|
1195
1196
|
txHash: a,
|
|
1196
|
-
from:
|
|
1197
|
-
to:
|
|
1198
|
-
amount:
|
|
1199
|
-
fees:
|
|
1197
|
+
from: I.from,
|
|
1198
|
+
to: I.to ?? s.to,
|
|
1199
|
+
amount: $,
|
|
1200
|
+
fees: B,
|
|
1200
1201
|
total: Q,
|
|
1201
1202
|
nativeSymbol: d.symbol,
|
|
1202
|
-
status:
|
|
1203
|
+
status: I.status === "0x1" ? "success" : "reverted"
|
|
1203
1204
|
};
|
|
1204
|
-
}).catch((
|
|
1205
|
+
}).catch((I) => (_ = I instanceof Error ? I : new Error(String(I)), {
|
|
1205
1206
|
chainId: e,
|
|
1206
1207
|
txHash: a,
|
|
1207
|
-
from:
|
|
1208
|
+
from: f,
|
|
1208
1209
|
to: s.to,
|
|
1209
1210
|
amount: X.formatTxAmount(s.value, d.symbol, d.decimals),
|
|
1210
1211
|
nativeSymbol: d.symbol,
|
|
1211
1212
|
status: "timeout"
|
|
1212
1213
|
}));
|
|
1213
1214
|
if (await this.confirmation.showTransactionProgress(
|
|
1214
|
-
{ chainId: e, txHash: a, from:
|
|
1215
|
-
|
|
1216
|
-
),
|
|
1217
|
-
return { chainId: e, txHash: a, receipt:
|
|
1215
|
+
{ chainId: e, txHash: a, from: f, to: s.to },
|
|
1216
|
+
m
|
|
1217
|
+
), _) throw _;
|
|
1218
|
+
return { chainId: e, txHash: a, receipt: w };
|
|
1218
1219
|
}
|
|
1219
1220
|
// ============================================================================
|
|
1220
1221
|
// Gas 조회
|
|
@@ -1234,7 +1235,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1234
1235
|
return await this.walletRpc("eth_gasPrice", [], e);
|
|
1235
1236
|
} catch (s) {
|
|
1236
1237
|
const t = s instanceof Error ? s.message : String(s);
|
|
1237
|
-
throw new
|
|
1238
|
+
throw new x(g.GAS_ESTIMATION_FAILED, `Failed to get gas price (${e}): ${t}`, s);
|
|
1238
1239
|
}
|
|
1239
1240
|
}
|
|
1240
1241
|
/**
|
|
@@ -1255,7 +1256,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1255
1256
|
return await this.walletRpc("eth_estimateGas", [t], s);
|
|
1256
1257
|
} catch (n) {
|
|
1257
1258
|
const o = n instanceof Error ? n.message : String(n);
|
|
1258
|
-
throw new
|
|
1259
|
+
throw new x(g.GAS_ESTIMATION_FAILED, `Failed to estimate gas (${s}): ${o}`, n);
|
|
1259
1260
|
}
|
|
1260
1261
|
}
|
|
1261
1262
|
/**
|
|
@@ -1276,7 +1277,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1276
1277
|
return (s == null ? void 0 : s.baseFeePerGas) ?? null;
|
|
1277
1278
|
} catch (s) {
|
|
1278
1279
|
const t = s instanceof Error ? s.message : String(s);
|
|
1279
|
-
throw new
|
|
1280
|
+
throw new x(g.GAS_ESTIMATION_FAILED, `Failed to get baseFeePerGas (${e}): ${t}`, s);
|
|
1280
1281
|
}
|
|
1281
1282
|
}
|
|
1282
1283
|
/**
|
|
@@ -1295,7 +1296,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1295
1296
|
return await this.walletRpc("eth_maxPriorityFeePerGas", [], e);
|
|
1296
1297
|
} catch (s) {
|
|
1297
1298
|
const t = s instanceof Error ? s.message : String(s);
|
|
1298
|
-
throw new
|
|
1299
|
+
throw new x(g.GAS_ESTIMATION_FAILED, `Failed to get maxPriorityFeePerGas (${e}): ${t}`, s);
|
|
1299
1300
|
}
|
|
1300
1301
|
}
|
|
1301
1302
|
// ============================================================================
|
|
@@ -1313,9 +1314,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1313
1314
|
const t = await this.jsonRpc.call("eth_getTransactionCount", [s, "pending"], e);
|
|
1314
1315
|
return parseInt(t ?? "0x0", 16);
|
|
1315
1316
|
} catch (t) {
|
|
1316
|
-
if (t instanceof
|
|
1317
|
+
if (t instanceof x) throw t;
|
|
1317
1318
|
const n = t instanceof Error ? t.message : String(t);
|
|
1318
|
-
throw new
|
|
1319
|
+
throw new x(g.UNKNOWN_ERROR, `Failed to get nonce: ${n}`, t);
|
|
1319
1320
|
}
|
|
1320
1321
|
}
|
|
1321
1322
|
/**
|
|
@@ -1332,9 +1333,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1332
1333
|
const n = await this.jsonRpc.call("eth_getBalance", [s, "latest"], e) ?? "0x0";
|
|
1333
1334
|
return { wei: n, formatted: X.formatWei(n), chainId: e };
|
|
1334
1335
|
} catch (t) {
|
|
1335
|
-
if (t instanceof
|
|
1336
|
+
if (t instanceof x) throw t;
|
|
1336
1337
|
const n = t instanceof Error ? t.message : String(t);
|
|
1337
|
-
throw new
|
|
1338
|
+
throw new x(g.UNKNOWN_ERROR, `Failed to get balance (${e}): ${n}`, t);
|
|
1338
1339
|
}
|
|
1339
1340
|
}
|
|
1340
1341
|
static formatWei(e) {
|
|
@@ -1383,9 +1384,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1383
1384
|
try {
|
|
1384
1385
|
return await this.jsonRpc.call(e, s, t);
|
|
1385
1386
|
} catch (n) {
|
|
1386
|
-
if (n instanceof
|
|
1387
|
+
if (n instanceof x) throw n;
|
|
1387
1388
|
const o = n instanceof Error ? n.message : String(n);
|
|
1388
|
-
throw new
|
|
1389
|
+
throw new x(g.UNKNOWN_ERROR, `walletRpc failed [${e}] (${t}): ${o}`, n);
|
|
1389
1390
|
}
|
|
1390
1391
|
}
|
|
1391
1392
|
// ============================================================================
|
|
@@ -1413,26 +1414,26 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1413
1414
|
* 3) migrateWallet API 호출
|
|
1414
1415
|
*/
|
|
1415
1416
|
async handleMigrationFlow(e) {
|
|
1416
|
-
|
|
1417
|
+
p.log('[CROSSx][Migration Phase 3] "Wallet Found" 팝업 표시');
|
|
1417
1418
|
const s = await this.confirmation.showMigrationFoundPrompt();
|
|
1418
|
-
if (
|
|
1419
|
-
return
|
|
1419
|
+
if (p.log("[CROSSx][Migration Phase 3] 사용자 선택:", s), s === "skip")
|
|
1420
|
+
return p.log("[CROSSx][Migration Phase 3] 사용자가 마이그레이션을 건너뜀 → 종료"), null;
|
|
1420
1421
|
let t, n = 0;
|
|
1421
1422
|
for (; ; ) {
|
|
1422
|
-
n++,
|
|
1423
|
+
n++, p.log(`[CROSSx][Migration Phase 4] PIN 입력 팝업 표시 (시도 #${n})`, t ? `— 이전 에러: ${t}` : "");
|
|
1423
1424
|
const o = await this.confirmation.showPinInputPrompt(t);
|
|
1424
1425
|
if (o === null)
|
|
1425
|
-
return
|
|
1426
|
-
|
|
1426
|
+
return p.log("[CROSSx][Migration Phase 4] 사용자가 PIN 입력을 취소함 → 종료"), null;
|
|
1427
|
+
p.log(`[CROSSx][Migration Phase 4] PIN 입력 완료 (${o.length}자리), Gateway 마이그레이션 API 호출`);
|
|
1427
1428
|
try {
|
|
1428
1429
|
const i = await this.migrateWalletUseCase.execute(o, e);
|
|
1429
|
-
return
|
|
1430
|
+
return p.log("[CROSSx][Migration Phase 5] 마이그레이션 성공 — address:", i.address), i;
|
|
1430
1431
|
} catch (i) {
|
|
1431
|
-
if (i instanceof
|
|
1432
|
-
|
|
1432
|
+
if (i instanceof x && i.code === g.MIGRATION_FAILED) {
|
|
1433
|
+
p.warn(`[CROSSx][Migration Phase 4] PIN 불일치 (시도 #${n}) — 재시도 요청`), t = "Incorrect PIN. Please try again.";
|
|
1433
1434
|
continue;
|
|
1434
1435
|
}
|
|
1435
|
-
throw
|
|
1436
|
+
throw p.error("[CROSSx][Migration Phase 4] 마이그레이션 실패 (복구 불가):", i), i;
|
|
1436
1437
|
}
|
|
1437
1438
|
}
|
|
1438
1439
|
}
|
|
@@ -1455,21 +1456,21 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1455
1456
|
if (n) {
|
|
1456
1457
|
const l = c.from ?? this.address;
|
|
1457
1458
|
if (l) {
|
|
1458
|
-
|
|
1459
|
+
p.log("[CROSSx] nonce 비어있음 → eth_getTransactionCount 호출 (from:", l, ")");
|
|
1459
1460
|
const d = await this.jsonRpc.call("eth_getTransactionCount", [l, "pending"], s);
|
|
1460
|
-
c.nonce = parseInt(d ?? "0x0", 16),
|
|
1461
|
+
c.nonce = parseInt(d ?? "0x0", 16), p.log("[CROSSx] nonce 결과:", c.nonce);
|
|
1461
1462
|
}
|
|
1462
1463
|
}
|
|
1463
|
-
if (o && (
|
|
1464
|
-
|
|
1464
|
+
if (o && (p.log("[CROSSx] gasLimit 비어있음 → eth_estimateGas 호출"), c.gasLimit = await this.estimateGas(e, s), p.log("[CROSSx] estimateGas 결과:", c.gasLimit)), i) {
|
|
1465
|
+
p.log("[CROSSx] gasPrice & maxFeePerGas 비어있음 → baseFee 조회로 Dynamic/Legacy 판별");
|
|
1465
1466
|
const l = await this.getBaseFeePerGas(s);
|
|
1466
1467
|
if (l) {
|
|
1467
1468
|
const d = vt;
|
|
1468
|
-
c.maxFeePerGas = "0x" + (BigInt(l) + BigInt(d)).toString(16), c.maxPriorityFeePerGas = d,
|
|
1469
|
+
c.maxFeePerGas = "0x" + (BigInt(l) + BigInt(d)).toString(16), c.maxPriorityFeePerGas = d, p.log("[CROSSx] Dynamic 체인 감지 — baseFee:", l, "maxFeePerGas:", c.maxFeePerGas, "maxPriorityFeePerGas: 1 Gwei");
|
|
1469
1470
|
} else
|
|
1470
|
-
c.gasPrice = Ws,
|
|
1471
|
+
c.gasPrice = Ws, p.log("[CROSSx] Legacy 체인 감지 — gasPrice: 2 Gwei");
|
|
1471
1472
|
}
|
|
1472
|
-
return !i && a && (c.maxPriorityFeePerGas = vt,
|
|
1473
|
+
return !i && a && (c.maxPriorityFeePerGas = vt, p.log("[CROSSx] maxPriorityFeePerGas 비어있음 → 1 Gwei 기본값 적용")), c;
|
|
1473
1474
|
}
|
|
1474
1475
|
/**
|
|
1475
1476
|
* EIP-712 signTypedData 호출 시 chainId와 typedData.domain.chainId 정합성 검증.
|
|
@@ -1481,7 +1482,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1481
1482
|
const t = X.extractDomainChainId(s);
|
|
1482
1483
|
if (e === "0") {
|
|
1483
1484
|
if (t !== void 0 && t !== 0)
|
|
1484
|
-
throw new
|
|
1485
|
+
throw new x(
|
|
1485
1486
|
g.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1486
1487
|
`Off-chain signing (chainId=0) requires typedData.domain.chainId to be absent or 0, got ${t}`
|
|
1487
1488
|
);
|
|
@@ -1491,12 +1492,12 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1491
1492
|
if (n) {
|
|
1492
1493
|
const o = Number(n[1]);
|
|
1493
1494
|
if (t === void 0)
|
|
1494
|
-
throw new
|
|
1495
|
+
throw new x(
|
|
1495
1496
|
g.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1496
1497
|
`On-chain signing (${e}) requires typedData.domain.chainId to be present`
|
|
1497
1498
|
);
|
|
1498
1499
|
if (t !== o)
|
|
1499
|
-
throw new
|
|
1500
|
+
throw new x(
|
|
1500
1501
|
g.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1501
1502
|
`typedData.domain.chainId (${t}) does not match chainId (${e}, expected ${o})`
|
|
1502
1503
|
);
|
|
@@ -1515,9 +1516,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1515
1516
|
static validateSignatureFormat(e) {
|
|
1516
1517
|
const s = e.startsWith("0x") ? e.slice(2) : e;
|
|
1517
1518
|
if (!/^[0-9a-fA-F]+$/.test(s))
|
|
1518
|
-
throw new
|
|
1519
|
+
throw new x(g.SIGNATURE_FAILED, "Invalid signature: not a valid hex string");
|
|
1519
1520
|
if (s.length !== St)
|
|
1520
|
-
throw new
|
|
1521
|
+
throw new x(
|
|
1521
1522
|
g.SIGNATURE_FAILED,
|
|
1522
1523
|
`Invalid signature length: expected ${St} hex chars (65 bytes), got ${s.length}`
|
|
1523
1524
|
);
|
|
@@ -1526,9 +1527,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1526
1527
|
static validateSignedTxFormat(e) {
|
|
1527
1528
|
const s = e.startsWith("0x") ? e.slice(2) : e;
|
|
1528
1529
|
if (!/^[0-9a-fA-F]+$/.test(s))
|
|
1529
|
-
throw new
|
|
1530
|
+
throw new x(g.SIGNATURE_FAILED, "Invalid signedTx: not a valid hex string");
|
|
1530
1531
|
if (s.length < 2)
|
|
1531
|
-
throw new
|
|
1532
|
+
throw new x(g.SIGNATURE_FAILED, "Invalid signedTx: too short");
|
|
1532
1533
|
}
|
|
1533
1534
|
/**
|
|
1534
1535
|
* Gateway 서명 응답의 ecrecover 검증 (XF-036)
|
|
@@ -1541,17 +1542,17 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1541
1542
|
try {
|
|
1542
1543
|
const n = this.crypto.recoverPersonalSignSigner(e, s);
|
|
1543
1544
|
if (n.toLowerCase() !== t.toLowerCase())
|
|
1544
|
-
throw
|
|
1545
|
+
throw p.error("[CROSSx] 서명 검증 실패: 서명자 주소 불일치", {
|
|
1545
1546
|
expected: t,
|
|
1546
1547
|
recovered: n
|
|
1547
|
-
}), new
|
|
1548
|
+
}), new x(
|
|
1548
1549
|
g.SIGNATURE_SIGNER_MISMATCH,
|
|
1549
1550
|
`Signature signer mismatch: expected ${t}, recovered ${n}`
|
|
1550
1551
|
);
|
|
1551
|
-
|
|
1552
|
+
p.log("[CROSSx] 서명 ecrecover 검증 성공");
|
|
1552
1553
|
} catch (n) {
|
|
1553
|
-
if (n instanceof
|
|
1554
|
-
|
|
1554
|
+
if (n instanceof x) throw n;
|
|
1555
|
+
p.warn("[CROSSx] ecrecover 검증 중 예외 (무시):", n);
|
|
1555
1556
|
}
|
|
1556
1557
|
}
|
|
1557
1558
|
/** AuthResult를 내부 상태에 반영합니다. */
|
|
@@ -1580,14 +1581,14 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1580
1581
|
}
|
|
1581
1582
|
ensureInitialized() {
|
|
1582
1583
|
if (!this.initialized)
|
|
1583
|
-
throw new
|
|
1584
|
+
throw new x(
|
|
1584
1585
|
g.AUTH_NOT_INITIALIZED,
|
|
1585
1586
|
"SDK is not initialized. Call initialize() first."
|
|
1586
1587
|
);
|
|
1587
1588
|
}
|
|
1588
1589
|
ensureAuthenticated() {
|
|
1589
1590
|
if (this.ensureInitialized(), !this.authenticated)
|
|
1590
|
-
throw new
|
|
1591
|
+
throw new x(
|
|
1591
1592
|
g.AUTH_NOT_AUTHENTICATED,
|
|
1592
1593
|
"Not authenticated. Call signIn() first."
|
|
1593
1594
|
);
|
|
@@ -1613,7 +1614,7 @@ class Ks {
|
|
|
1613
1614
|
const t = JSON.stringify(s);
|
|
1614
1615
|
localStorage.setItem(this.prefix + e, t);
|
|
1615
1616
|
} catch (t) {
|
|
1616
|
-
throw
|
|
1617
|
+
throw p.error("Storage set error:", t), t;
|
|
1617
1618
|
}
|
|
1618
1619
|
}
|
|
1619
1620
|
async get(e) {
|
|
@@ -1621,14 +1622,14 @@ class Ks {
|
|
|
1621
1622
|
const s = localStorage.getItem(this.prefix + e);
|
|
1622
1623
|
return s ? JSON.parse(s) : null;
|
|
1623
1624
|
} catch (s) {
|
|
1624
|
-
return
|
|
1625
|
+
return p.error("Storage get error:", s), null;
|
|
1625
1626
|
}
|
|
1626
1627
|
}
|
|
1627
1628
|
async remove(e) {
|
|
1628
1629
|
try {
|
|
1629
1630
|
localStorage.removeItem(this.prefix + e);
|
|
1630
1631
|
} catch (s) {
|
|
1631
|
-
throw
|
|
1632
|
+
throw p.error("Storage remove error:", s), s;
|
|
1632
1633
|
}
|
|
1633
1634
|
}
|
|
1634
1635
|
async clear() {
|
|
@@ -1637,7 +1638,7 @@ class Ks {
|
|
|
1637
1638
|
s.startsWith(this.prefix) && localStorage.removeItem(s);
|
|
1638
1639
|
});
|
|
1639
1640
|
} catch (e) {
|
|
1640
|
-
throw
|
|
1641
|
+
throw p.error("Storage clear error:", e), e;
|
|
1641
1642
|
}
|
|
1642
1643
|
}
|
|
1643
1644
|
}
|
|
@@ -1719,7 +1720,7 @@ class At {
|
|
|
1719
1720
|
const t = JSON.stringify(s), n = await this.encrypt(t);
|
|
1720
1721
|
await this.idbPut(Se, e, n);
|
|
1721
1722
|
} catch (t) {
|
|
1722
|
-
throw
|
|
1723
|
+
throw p.error("[CROSSx] IndexedDB set error:", t), t;
|
|
1723
1724
|
}
|
|
1724
1725
|
}
|
|
1725
1726
|
async get(e) {
|
|
@@ -1730,21 +1731,21 @@ class At {
|
|
|
1730
1731
|
const t = await this.decrypt(s);
|
|
1731
1732
|
return JSON.parse(t);
|
|
1732
1733
|
} catch (s) {
|
|
1733
|
-
return
|
|
1734
|
+
return p.error("[CROSSx] IndexedDB get error:", s), null;
|
|
1734
1735
|
}
|
|
1735
1736
|
}
|
|
1736
1737
|
async remove(e) {
|
|
1737
1738
|
try {
|
|
1738
1739
|
await this.ensureReady(), await this.idbDelete(Se, e);
|
|
1739
1740
|
} catch (s) {
|
|
1740
|
-
throw
|
|
1741
|
+
throw p.error("[CROSSx] IndexedDB remove error:", s), s;
|
|
1741
1742
|
}
|
|
1742
1743
|
}
|
|
1743
1744
|
async clear() {
|
|
1744
1745
|
try {
|
|
1745
1746
|
await this.ensureReady(), await this.idbClear(Se);
|
|
1746
1747
|
} catch (e) {
|
|
1747
|
-
throw
|
|
1748
|
+
throw p.error("[CROSSx] IndexedDB clear error:", e), e;
|
|
1748
1749
|
}
|
|
1749
1750
|
}
|
|
1750
1751
|
/**
|
|
@@ -1764,7 +1765,7 @@ function ue(r, e = "") {
|
|
|
1764
1765
|
throw new Error(`${s}expected integer >= 0, got ${r}`);
|
|
1765
1766
|
}
|
|
1766
1767
|
}
|
|
1767
|
-
function
|
|
1768
|
+
function H(r, e, s = "") {
|
|
1768
1769
|
const t = at(r), n = r == null ? void 0 : r.length, o = e !== void 0;
|
|
1769
1770
|
if (!t || o && n !== e) {
|
|
1770
1771
|
const i = s && `"${s}" `, a = o ? ` of length ${e}` : "", c = t ? `length=${n}` : `type=${typeof r}`;
|
|
@@ -1784,7 +1785,7 @@ function Ie(r, e = !0) {
|
|
|
1784
1785
|
throw new Error("Hash#digest() has already been called");
|
|
1785
1786
|
}
|
|
1786
1787
|
function zt(r, e) {
|
|
1787
|
-
|
|
1788
|
+
H(r, void 0, "digestInto() output");
|
|
1788
1789
|
const s = e.outputLen;
|
|
1789
1790
|
if (r.length < s)
|
|
1790
1791
|
throw new Error('"digestInto() output" expected to be of length >=' + s);
|
|
@@ -1813,7 +1814,7 @@ function er(r) {
|
|
|
1813
1814
|
}
|
|
1814
1815
|
const Rt = Js ? (r) => r : er, Yt = /* @ts-ignore */ typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", tr = /* @__PURE__ */ Array.from({ length: 256 }, (r, e) => e.toString(16).padStart(2, "0"));
|
|
1815
1816
|
function ke(r) {
|
|
1816
|
-
if (
|
|
1817
|
+
if (H(r), Yt)
|
|
1817
1818
|
return r.toHex();
|
|
1818
1819
|
let e = "";
|
|
1819
1820
|
for (let s = 0; s < r.length; s++)
|
|
@@ -1852,7 +1853,7 @@ function _e(...r) {
|
|
|
1852
1853
|
let e = 0;
|
|
1853
1854
|
for (let t = 0; t < r.length; t++) {
|
|
1854
1855
|
const n = r[t];
|
|
1855
|
-
|
|
1856
|
+
H(n), e += n.length;
|
|
1856
1857
|
}
|
|
1857
1858
|
const s = new Uint8Array(e);
|
|
1858
1859
|
for (let t = 0, n = 0; t < r.length; t++) {
|
|
@@ -1896,7 +1897,7 @@ class or {
|
|
|
1896
1897
|
this.blockLen = e, this.outputLen = s, this.padOffset = t, this.isLE = n, this.buffer = new Uint8Array(e), this.view = Ze(this.buffer);
|
|
1897
1898
|
}
|
|
1898
1899
|
update(e) {
|
|
1899
|
-
Ie(this),
|
|
1900
|
+
Ie(this), H(e);
|
|
1900
1901
|
const { view: s, buffer: t, blockLen: n } = this, o = e.length;
|
|
1901
1902
|
for (let i = 0; i < o; ) {
|
|
1902
1903
|
const a = Math.min(n - this.pos, o - i);
|
|
@@ -1915,8 +1916,8 @@ class or {
|
|
|
1915
1916
|
const { buffer: s, view: t, blockLen: n, isLE: o } = this;
|
|
1916
1917
|
let { pos: i } = this;
|
|
1917
1918
|
s[i++] = 128, Te(this.buffer.subarray(i)), this.padOffset > n - i && (this.process(t, 0), i = 0);
|
|
1918
|
-
for (let
|
|
1919
|
-
s[
|
|
1919
|
+
for (let f = i; f < n; f++)
|
|
1920
|
+
s[f] = 0;
|
|
1920
1921
|
t.setBigUint64(n - 8, BigInt(this.length * 8), o), this.process(t, 0);
|
|
1921
1922
|
const a = Ze(e), c = this.outputLen;
|
|
1922
1923
|
if (c % 4)
|
|
@@ -1924,8 +1925,8 @@ class or {
|
|
|
1924
1925
|
const l = c / 4, d = this.get();
|
|
1925
1926
|
if (l > d.length)
|
|
1926
1927
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1927
|
-
for (let
|
|
1928
|
-
a.setUint32(4 *
|
|
1928
|
+
for (let f = 0; f < l; f++)
|
|
1929
|
+
a.setUint32(4 * f, d[f], o);
|
|
1929
1930
|
}
|
|
1930
1931
|
digest() {
|
|
1931
1932
|
const { buffer: e, outputLen: s } = this;
|
|
@@ -2043,16 +2044,16 @@ class fr extends or {
|
|
|
2043
2044
|
this.A = e | 0, this.B = s | 0, this.C = t | 0, this.D = n | 0, this.E = o | 0, this.F = i | 0, this.G = a | 0, this.H = c | 0;
|
|
2044
2045
|
}
|
|
2045
2046
|
process(e, s) {
|
|
2046
|
-
for (let
|
|
2047
|
-
pe[
|
|
2048
|
-
for (let
|
|
2049
|
-
const
|
|
2050
|
-
pe[
|
|
2047
|
+
for (let f = 0; f < 16; f++, s += 4)
|
|
2048
|
+
pe[f] = e.getUint32(s, !1);
|
|
2049
|
+
for (let f = 16; f < 64; f++) {
|
|
2050
|
+
const w = pe[f - 15], _ = pe[f - 2], m = oe(w, 7) ^ oe(w, 18) ^ w >>> 3, A = oe(_, 17) ^ oe(_, 19) ^ _ >>> 10;
|
|
2051
|
+
pe[f] = A + pe[f - 7] + m + pe[f - 16] | 0;
|
|
2051
2052
|
}
|
|
2052
2053
|
let { A: t, B: n, C: o, D: i, E: a, F: c, G: l, H: d } = this;
|
|
2053
|
-
for (let
|
|
2054
|
-
const
|
|
2055
|
-
d = l, l = c, c = a, a = i +
|
|
2054
|
+
for (let f = 0; f < 64; f++) {
|
|
2055
|
+
const w = oe(a, 6) ^ oe(a, 11) ^ oe(a, 25), _ = d + w + rr(a, c, l) + hr[f] + pe[f] | 0, A = (oe(t, 2) ^ oe(t, 13) ^ oe(t, 22)) + nr(t, n, o) | 0;
|
|
2056
|
+
d = l, l = c, c = a, a = i + _ | 0, i = o, o = n, n = t, t = _ + A | 0;
|
|
2056
2057
|
}
|
|
2057
2058
|
t = t + this.A | 0, n = n + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, l = l + this.G | 0, d = d + this.H | 0, this.set(t, n, o, i, a, c, l, d);
|
|
2058
2059
|
}
|
|
@@ -2112,7 +2113,7 @@ function je(r) {
|
|
|
2112
2113
|
return Qt(ke(r));
|
|
2113
2114
|
}
|
|
2114
2115
|
function es(r) {
|
|
2115
|
-
return Qt(ke(_r(
|
|
2116
|
+
return Qt(ke(_r(H(r)).reverse()));
|
|
2116
2117
|
}
|
|
2117
2118
|
function lt(r, e) {
|
|
2118
2119
|
ue(e), r = Jt(r);
|
|
@@ -2145,30 +2146,30 @@ const dt = (r) => (rt << BigInt(r)) - rt;
|
|
|
2145
2146
|
function yr(r, e, s) {
|
|
2146
2147
|
if (ue(r, "hashLen"), ue(e, "qByteLen"), typeof s != "function")
|
|
2147
2148
|
throw new Error("hmacFn must be a function");
|
|
2148
|
-
const t = (
|
|
2149
|
+
const t = (y) => new Uint8Array(y), n = Uint8Array.of(), o = Uint8Array.of(0), i = Uint8Array.of(1), a = 1e3;
|
|
2149
2150
|
let c = t(r), l = t(r), d = 0;
|
|
2150
|
-
const
|
|
2151
|
+
const f = () => {
|
|
2151
2152
|
c.fill(1), l.fill(0), d = 0;
|
|
2152
|
-
},
|
|
2153
|
-
l =
|
|
2154
|
-
},
|
|
2153
|
+
}, w = (...y) => s(l, _e(c, ...y)), _ = (y = n) => {
|
|
2154
|
+
l = w(o, y), c = w(), y.length !== 0 && (l = w(i, y), c = w());
|
|
2155
|
+
}, m = () => {
|
|
2155
2156
|
if (d++ >= a)
|
|
2156
2157
|
throw new Error("drbg: tried max amount of iterations");
|
|
2157
|
-
let
|
|
2158
|
-
const
|
|
2159
|
-
for (;
|
|
2160
|
-
c =
|
|
2161
|
-
const
|
|
2162
|
-
|
|
2163
|
-
}
|
|
2164
|
-
return _e(...
|
|
2158
|
+
let y = 0;
|
|
2159
|
+
const I = [];
|
|
2160
|
+
for (; y < e; ) {
|
|
2161
|
+
c = w();
|
|
2162
|
+
const L = c.slice();
|
|
2163
|
+
I.push(L), y += c.length;
|
|
2164
|
+
}
|
|
2165
|
+
return _e(...I);
|
|
2165
2166
|
};
|
|
2166
|
-
return (
|
|
2167
|
-
|
|
2168
|
-
let
|
|
2169
|
-
for (; !(
|
|
2170
|
-
|
|
2171
|
-
return
|
|
2167
|
+
return (y, I) => {
|
|
2168
|
+
f(), _(y);
|
|
2169
|
+
let L;
|
|
2170
|
+
for (; !(L = I(m())); )
|
|
2171
|
+
_();
|
|
2172
|
+
return f(), L;
|
|
2172
2173
|
};
|
|
2173
2174
|
}
|
|
2174
2175
|
function ut(r, e = {}, s = {}) {
|
|
@@ -2237,10 +2238,10 @@ function Er(r) {
|
|
|
2237
2238
|
const e = Ve(r), s = cs(r), t = s(e, e.neg(e.ONE)), n = s(e, t), o = s(e, e.neg(t)), i = (r + br) / is;
|
|
2238
2239
|
return (a, c) => {
|
|
2239
2240
|
let l = a.pow(c, i), d = a.mul(l, t);
|
|
2240
|
-
const
|
|
2241
|
-
l = a.cmov(l, d,
|
|
2242
|
-
const
|
|
2243
|
-
return ht(a,
|
|
2241
|
+
const f = a.mul(l, n), w = a.mul(l, o), _ = a.eql(a.sqr(d), c), m = a.eql(a.sqr(f), c);
|
|
2242
|
+
l = a.cmov(l, d, _), d = a.cmov(w, f, m);
|
|
2243
|
+
const A = a.eql(a.sqr(d), c), y = a.cmov(l, d, A);
|
|
2244
|
+
return ht(a, y, c), y;
|
|
2244
2245
|
};
|
|
2245
2246
|
}
|
|
2246
2247
|
function cs(r) {
|
|
@@ -2263,18 +2264,18 @@ function cs(r) {
|
|
|
2263
2264
|
return l;
|
|
2264
2265
|
if (Pt(c, l) !== 1)
|
|
2265
2266
|
throw new Error("Cannot find square root");
|
|
2266
|
-
let d = s,
|
|
2267
|
-
for (; !c.eql(
|
|
2268
|
-
if (c.is0(
|
|
2267
|
+
let d = s, f = c.mul(c.ONE, o), w = c.pow(l, e), _ = c.pow(l, i);
|
|
2268
|
+
for (; !c.eql(w, c.ONE); ) {
|
|
2269
|
+
if (c.is0(w))
|
|
2269
2270
|
return c.ZERO;
|
|
2270
|
-
let
|
|
2271
|
-
for (; !c.eql(
|
|
2272
|
-
if (
|
|
2271
|
+
let m = 1, A = c.sqr(w);
|
|
2272
|
+
for (; !c.eql(A, c.ONE); )
|
|
2273
|
+
if (m++, A = c.sqr(A), m === d)
|
|
2273
2274
|
throw new Error("Cannot find square root");
|
|
2274
|
-
const
|
|
2275
|
-
d =
|
|
2275
|
+
const y = z << BigInt(d - m - 1), I = c.pow(f, y);
|
|
2276
|
+
d = m, f = c.sqr(I), w = c.mul(w, f), _ = c.mul(_, I);
|
|
2276
2277
|
}
|
|
2277
|
-
return
|
|
2278
|
+
return _;
|
|
2278
2279
|
};
|
|
2279
2280
|
}
|
|
2280
2281
|
function Ir(r) {
|
|
@@ -2421,7 +2422,7 @@ class Cr {
|
|
|
2421
2422
|
return this.isLE ? ts(e, this.BYTES) : lt(e, this.BYTES);
|
|
2422
2423
|
}
|
|
2423
2424
|
fromBytes(e, s = !1) {
|
|
2424
|
-
|
|
2425
|
+
H(e);
|
|
2425
2426
|
const { _lengths: t, BYTES: n, isLE: o, ORDER: i, _mod: a } = this;
|
|
2426
2427
|
if (t) {
|
|
2427
2428
|
if (!t.includes(e.length) || e.length > n)
|
|
@@ -2460,7 +2461,7 @@ function us(r) {
|
|
|
2460
2461
|
return e + Math.ceil(e / 2);
|
|
2461
2462
|
}
|
|
2462
2463
|
function kr(r, e, s = !1) {
|
|
2463
|
-
|
|
2464
|
+
H(r);
|
|
2464
2465
|
const t = r.length, n = ds(e), o = us(e);
|
|
2465
2466
|
if (t < 16 || t < o || t > 1024)
|
|
2466
2467
|
throw new Error("expected " + o + "-1024 bytes of input, got " + t);
|
|
@@ -2490,8 +2491,8 @@ function Dt(r, e, s) {
|
|
|
2490
2491
|
const { windowSize: t, mask: n, maxNumber: o, shiftBy: i } = s;
|
|
2491
2492
|
let a = Number(r & n), c = r >> i;
|
|
2492
2493
|
a > t && (a -= o, c += be);
|
|
2493
|
-
const l = e * t, d = l + Math.abs(a) - 1,
|
|
2494
|
-
return { nextN: c, offset: d, isZero:
|
|
2494
|
+
const l = e * t, d = l + Math.abs(a) - 1, f = a === 0, w = a < 0, _ = e % 2 !== 0;
|
|
2495
|
+
return { nextN: c, offset: d, isZero: f, isNeg: w, isNegF: _, offsetF: l };
|
|
2495
2496
|
}
|
|
2496
2497
|
const Je = /* @__PURE__ */ new WeakMap(), fs = /* @__PURE__ */ new WeakMap();
|
|
2497
2498
|
function Qe(r) {
|
|
@@ -2552,8 +2553,8 @@ class Nr {
|
|
|
2552
2553
|
let n = this.ZERO, o = this.BASE;
|
|
2553
2554
|
const i = Xe(e, this.bits);
|
|
2554
2555
|
for (let a = 0; a < i.windows; a++) {
|
|
2555
|
-
const { nextN: c, offset: l, isZero: d, isNeg:
|
|
2556
|
-
t = c, d ? o = o.add(Ge(
|
|
2556
|
+
const { nextN: c, offset: l, isZero: d, isNeg: f, isNegF: w, offsetF: _ } = Dt(t, a, i);
|
|
2557
|
+
t = c, d ? o = o.add(Ge(w, s[_])) : n = n.add(Ge(f, s[l]));
|
|
2557
2558
|
}
|
|
2558
2559
|
return $t(t), { p: n, f: o };
|
|
2559
2560
|
}
|
|
@@ -2567,8 +2568,8 @@ class Nr {
|
|
|
2567
2568
|
for (let i = 0; i < o.windows && t !== Ae; i++) {
|
|
2568
2569
|
const { nextN: a, offset: c, isZero: l, isNeg: d } = Dt(t, i, o);
|
|
2569
2570
|
if (t = a, !l) {
|
|
2570
|
-
const
|
|
2571
|
-
n = n.add(d ?
|
|
2571
|
+
const f = s[c];
|
|
2572
|
+
n = n.add(d ? f.negate() : f);
|
|
2572
2573
|
}
|
|
2573
2574
|
}
|
|
2574
2575
|
return $t(t), n;
|
|
@@ -2637,7 +2638,7 @@ class ps {
|
|
|
2637
2638
|
v(this, "outputLen");
|
|
2638
2639
|
v(this, "finished", !1);
|
|
2639
2640
|
v(this, "destroyed", !1);
|
|
2640
|
-
if (Kt(e),
|
|
2641
|
+
if (Kt(e), H(s, void 0, "key"), this.iHash = e.create(), typeof this.iHash.update != "function")
|
|
2641
2642
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
2642
2643
|
this.blockLen = this.iHash.blockLen, this.outputLen = this.iHash.outputLen;
|
|
2643
2644
|
const t = this.blockLen, n = new Uint8Array(t);
|
|
@@ -2653,7 +2654,7 @@ class ps {
|
|
|
2653
2654
|
return Ie(this), this.iHash.update(e), this;
|
|
2654
2655
|
}
|
|
2655
2656
|
digestInto(e) {
|
|
2656
|
-
Ie(this),
|
|
2657
|
+
Ie(this), H(e, this.outputLen, "output"), this.finished = !0, this.iHash.digestInto(e), this.oHash.update(e), this.oHash.digestInto(e), this.destroy();
|
|
2657
2658
|
}
|
|
2658
2659
|
digest() {
|
|
2659
2660
|
const e = new Uint8Array(this.oHash.outputLen);
|
|
@@ -2678,12 +2679,12 @@ const Bt = (r, e) => (r + (r >= 0 ? e : -e) / _s) / e;
|
|
|
2678
2679
|
function $r(r, e, s) {
|
|
2679
2680
|
const [[t, n], [o, i]] = e, a = Bt(i * r, s), c = Bt(-n * r, s);
|
|
2680
2681
|
let l = r - a * t - c * o, d = -a * n - c * i;
|
|
2681
|
-
const
|
|
2682
|
-
|
|
2683
|
-
const
|
|
2684
|
-
if (l < le || l >=
|
|
2682
|
+
const f = l < le, w = d < le;
|
|
2683
|
+
f && (l = -l), w && (d = -d);
|
|
2684
|
+
const _ = dt(Math.ceil(wr(s) / 2)) + Ee;
|
|
2685
|
+
if (l < le || l >= _ || d < le || d >= _)
|
|
2685
2686
|
throw new Error("splitScalar (endomorphism): failed, k=" + r);
|
|
2686
|
-
return { k1neg:
|
|
2687
|
+
return { k1neg: f, k1: l, k2neg: w, k2: d };
|
|
2687
2688
|
}
|
|
2688
2689
|
function nt(r) {
|
|
2689
2690
|
if (!["compact", "recovered", "der"].includes(r))
|
|
@@ -2776,7 +2777,7 @@ const ge = {
|
|
|
2776
2777
|
}
|
|
2777
2778
|
},
|
|
2778
2779
|
toSig(r) {
|
|
2779
|
-
const { Err: e, _int: s, _tlv: t } = ge, n =
|
|
2780
|
+
const { Err: e, _int: s, _tlv: t } = ge, n = H(r, void 0, "signature"), { v: o, l: i } = t.decode(48, n);
|
|
2780
2781
|
if (i.length)
|
|
2781
2782
|
throw new e("invalid signature: left bytes after parsing");
|
|
2782
2783
|
const { v: a, l: c } = t.decode(2, o), { v: l, l: d } = t.decode(2, c);
|
|
@@ -2809,81 +2810,81 @@ function Ur(r, e = {}) {
|
|
|
2809
2810
|
if (!t.isOdd)
|
|
2810
2811
|
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2811
2812
|
}
|
|
2812
|
-
function
|
|
2813
|
-
const { x:
|
|
2813
|
+
function f(P, u, h) {
|
|
2814
|
+
const { x: b, y: E } = u.toAffine(), R = t.toBytes(b);
|
|
2814
2815
|
if (He(h, "isCompressed"), h) {
|
|
2815
2816
|
d();
|
|
2816
|
-
const
|
|
2817
|
-
return _e(xs(
|
|
2817
|
+
const T = !t.isOdd(E);
|
|
2818
|
+
return _e(xs(T), R);
|
|
2818
2819
|
} else
|
|
2819
|
-
return _e(Uint8Array.of(4), R, t.toBytes(
|
|
2820
|
-
}
|
|
2821
|
-
function
|
|
2822
|
-
|
|
2823
|
-
const { publicKey: u, publicKeyUncompressed: h } = l,
|
|
2824
|
-
if (
|
|
2825
|
-
const
|
|
2826
|
-
if (!t.isValid(
|
|
2820
|
+
return _e(Uint8Array.of(4), R, t.toBytes(E));
|
|
2821
|
+
}
|
|
2822
|
+
function w(P) {
|
|
2823
|
+
H(P, void 0, "Point");
|
|
2824
|
+
const { publicKey: u, publicKeyUncompressed: h } = l, b = P.length, E = P[0], R = P.subarray(1);
|
|
2825
|
+
if (b === u && (E === 2 || E === 3)) {
|
|
2826
|
+
const T = t.fromBytes(R);
|
|
2827
|
+
if (!t.isValid(T))
|
|
2827
2828
|
throw new Error("bad point: is not on curve, wrong x");
|
|
2828
|
-
const O =
|
|
2829
|
-
let
|
|
2829
|
+
const O = A(T);
|
|
2830
|
+
let S;
|
|
2830
2831
|
try {
|
|
2831
|
-
|
|
2832
|
+
S = t.sqrt(O);
|
|
2832
2833
|
} catch (W) {
|
|
2833
|
-
const
|
|
2834
|
-
throw new Error("bad point: is not on curve, sqrt error" +
|
|
2834
|
+
const F = W instanceof Error ? ": " + W.message : "";
|
|
2835
|
+
throw new Error("bad point: is not on curve, sqrt error" + F);
|
|
2835
2836
|
}
|
|
2836
2837
|
d();
|
|
2837
|
-
const C = t.isOdd(
|
|
2838
|
-
return (
|
|
2839
|
-
} else if (
|
|
2840
|
-
const
|
|
2841
|
-
if (!
|
|
2838
|
+
const C = t.isOdd(S);
|
|
2839
|
+
return (E & 1) === 1 !== C && (S = t.neg(S)), { x: T, y: S };
|
|
2840
|
+
} else if (b === h && E === 4) {
|
|
2841
|
+
const T = t.BYTES, O = t.fromBytes(R.subarray(0, T)), S = t.fromBytes(R.subarray(T, T * 2));
|
|
2842
|
+
if (!y(O, S))
|
|
2842
2843
|
throw new Error("bad point: is not on curve");
|
|
2843
|
-
return { x: O, y:
|
|
2844
|
+
return { x: O, y: S };
|
|
2844
2845
|
} else
|
|
2845
|
-
throw new Error(`bad point: got length ${
|
|
2846
|
+
throw new Error(`bad point: got length ${b}, expected compressed=${u} or uncompressed=${h}`);
|
|
2846
2847
|
}
|
|
2847
|
-
const
|
|
2848
|
-
function
|
|
2848
|
+
const _ = e.toBytes || f, m = e.fromBytes || w;
|
|
2849
|
+
function A(P) {
|
|
2849
2850
|
const u = t.sqr(P), h = t.mul(u, P);
|
|
2850
2851
|
return t.add(t.add(h, t.mul(P, o.a)), o.b);
|
|
2851
2852
|
}
|
|
2852
|
-
function
|
|
2853
|
-
const h = t.sqr(u),
|
|
2854
|
-
return t.eql(h,
|
|
2853
|
+
function y(P, u) {
|
|
2854
|
+
const h = t.sqr(u), b = A(P);
|
|
2855
|
+
return t.eql(h, b);
|
|
2855
2856
|
}
|
|
2856
|
-
if (!
|
|
2857
|
+
if (!y(o.Gx, o.Gy))
|
|
2857
2858
|
throw new Error("bad curve params: generator point");
|
|
2858
|
-
const
|
|
2859
|
-
if (t.is0(t.add(
|
|
2859
|
+
const I = t.mul(t.pow(o.a, Me), Br), L = t.mul(t.sqr(o.b), BigInt(27));
|
|
2860
|
+
if (t.is0(t.add(I, L)))
|
|
2860
2861
|
throw new Error("bad curve params: a or b");
|
|
2861
|
-
function
|
|
2862
|
+
function U(P, u, h = !1) {
|
|
2862
2863
|
if (!t.isValid(u) || h && t.is0(u))
|
|
2863
2864
|
throw new Error(`bad point coordinate ${P}`);
|
|
2864
2865
|
return u;
|
|
2865
2866
|
}
|
|
2866
|
-
function
|
|
2867
|
+
function $(P) {
|
|
2867
2868
|
if (!(P instanceof Z))
|
|
2868
2869
|
throw new Error("Weierstrass Point expected");
|
|
2869
2870
|
}
|
|
2870
|
-
function
|
|
2871
|
+
function B(P) {
|
|
2871
2872
|
if (!c || !c.basises)
|
|
2872
2873
|
throw new Error("no endo");
|
|
2873
2874
|
return $r(P, c.basises, n.ORDER);
|
|
2874
2875
|
}
|
|
2875
2876
|
const Q = kt((P, u) => {
|
|
2876
|
-
const { X: h, Y:
|
|
2877
|
-
if (t.eql(
|
|
2878
|
-
return { x: h, y };
|
|
2877
|
+
const { X: h, Y: b, Z: E } = P;
|
|
2878
|
+
if (t.eql(E, t.ONE))
|
|
2879
|
+
return { x: h, y: b };
|
|
2879
2880
|
const R = P.is0();
|
|
2880
|
-
u == null && (u = R ? t.ONE : t.inv(
|
|
2881
|
-
const
|
|
2881
|
+
u == null && (u = R ? t.ONE : t.inv(E));
|
|
2882
|
+
const T = t.mul(h, u), O = t.mul(b, u), S = t.mul(E, u);
|
|
2882
2883
|
if (R)
|
|
2883
2884
|
return { x: t.ZERO, y: t.ZERO };
|
|
2884
|
-
if (!t.eql(
|
|
2885
|
+
if (!t.eql(S, t.ONE))
|
|
2885
2886
|
throw new Error("invZ was invalid");
|
|
2886
|
-
return { x:
|
|
2887
|
+
return { x: T, y: O };
|
|
2887
2888
|
}), ve = kt((P) => {
|
|
2888
2889
|
if (P.is0()) {
|
|
2889
2890
|
if (e.allowInfinityPoint && !t.is0(P.Y))
|
|
@@ -2893,41 +2894,41 @@ function Ur(r, e = {}) {
|
|
|
2893
2894
|
const { x: u, y: h } = P.toAffine();
|
|
2894
2895
|
if (!t.isValid(u) || !t.isValid(h))
|
|
2895
2896
|
throw new Error("bad point: x or y not field elements");
|
|
2896
|
-
if (!
|
|
2897
|
+
if (!y(u, h))
|
|
2897
2898
|
throw new Error("bad point: equation left != right");
|
|
2898
2899
|
if (!P.isTorsionFree())
|
|
2899
2900
|
throw new Error("bad point: not in prime-order subgroup");
|
|
2900
2901
|
return !0;
|
|
2901
2902
|
});
|
|
2902
|
-
function he(P, u, h,
|
|
2903
|
-
return h = new Z(t.mul(h.X, P), h.Y, h.Z), u = Ge(
|
|
2903
|
+
function he(P, u, h, b, E) {
|
|
2904
|
+
return h = new Z(t.mul(h.X, P), h.Y, h.Z), u = Ge(b, u), h = Ge(E, h), u.add(h);
|
|
2904
2905
|
}
|
|
2905
|
-
const
|
|
2906
|
+
const D = class D {
|
|
2906
2907
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2907
|
-
constructor(u, h,
|
|
2908
|
+
constructor(u, h, b) {
|
|
2908
2909
|
v(this, "X");
|
|
2909
2910
|
v(this, "Y");
|
|
2910
2911
|
v(this, "Z");
|
|
2911
|
-
this.X =
|
|
2912
|
+
this.X = U("x", u), this.Y = U("y", h, !0), this.Z = U("z", b), Object.freeze(this);
|
|
2912
2913
|
}
|
|
2913
2914
|
static CURVE() {
|
|
2914
2915
|
return o;
|
|
2915
2916
|
}
|
|
2916
2917
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2917
2918
|
static fromAffine(u) {
|
|
2918
|
-
const { x: h, y } = u || {};
|
|
2919
|
-
if (!u || !t.isValid(h) || !t.isValid(
|
|
2919
|
+
const { x: h, y: b } = u || {};
|
|
2920
|
+
if (!u || !t.isValid(h) || !t.isValid(b))
|
|
2920
2921
|
throw new Error("invalid affine point");
|
|
2921
|
-
if (u instanceof
|
|
2922
|
+
if (u instanceof D)
|
|
2922
2923
|
throw new Error("projective point not allowed");
|
|
2923
|
-
return t.is0(h) && t.is0(
|
|
2924
|
+
return t.is0(h) && t.is0(b) ? D.ZERO : new D(h, b, t.ONE);
|
|
2924
2925
|
}
|
|
2925
2926
|
static fromBytes(u) {
|
|
2926
|
-
const h =
|
|
2927
|
+
const h = D.fromAffine(m(H(u, void 0, "point")));
|
|
2927
2928
|
return h.assertValidity(), h;
|
|
2928
2929
|
}
|
|
2929
2930
|
static fromHex(u) {
|
|
2930
|
-
return
|
|
2931
|
+
return D.fromBytes(Fe(u));
|
|
2931
2932
|
}
|
|
2932
2933
|
get x() {
|
|
2933
2934
|
return this.toAffine().x;
|
|
@@ -2957,42 +2958,42 @@ function Ur(r, e = {}) {
|
|
|
2957
2958
|
}
|
|
2958
2959
|
/** Compare one point to another. */
|
|
2959
2960
|
equals(u) {
|
|
2960
|
-
|
|
2961
|
-
const { X: h, Y:
|
|
2962
|
-
return
|
|
2961
|
+
$(u);
|
|
2962
|
+
const { X: h, Y: b, Z: E } = this, { X: R, Y: T, Z: O } = u, S = t.eql(t.mul(h, O), t.mul(R, E)), C = t.eql(t.mul(b, O), t.mul(T, E));
|
|
2963
|
+
return S && C;
|
|
2963
2964
|
}
|
|
2964
2965
|
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2965
2966
|
negate() {
|
|
2966
|
-
return new
|
|
2967
|
+
return new D(this.X, t.neg(this.Y), this.Z);
|
|
2967
2968
|
}
|
|
2968
2969
|
// Renes-Costello-Batina exception-free doubling formula.
|
|
2969
2970
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2970
2971
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2971
2972
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2972
2973
|
double() {
|
|
2973
|
-
const { a: u, b: h } = o,
|
|
2974
|
-
let O = t.ZERO,
|
|
2975
|
-
return k = t.add(k, k), C = t.mul(
|
|
2974
|
+
const { a: u, b: h } = o, b = t.mul(h, Me), { X: E, Y: R, Z: T } = this;
|
|
2975
|
+
let O = t.ZERO, S = t.ZERO, C = t.ZERO, N = t.mul(E, E), W = t.mul(R, R), F = t.mul(T, T), k = t.mul(E, R);
|
|
2976
|
+
return k = t.add(k, k), C = t.mul(E, T), C = t.add(C, C), O = t.mul(u, C), S = t.mul(b, F), S = t.add(O, S), O = t.sub(W, S), S = t.add(W, S), S = t.mul(O, S), O = t.mul(k, O), C = t.mul(b, C), F = t.mul(u, F), k = t.sub(N, F), k = t.mul(u, k), k = t.add(k, C), C = t.add(N, N), N = t.add(C, N), N = t.add(N, F), N = t.mul(N, k), S = t.add(S, N), F = t.mul(R, T), F = t.add(F, F), N = t.mul(F, k), O = t.sub(O, N), C = t.mul(F, W), C = t.add(C, C), C = t.add(C, C), new D(O, S, C);
|
|
2976
2977
|
}
|
|
2977
2978
|
// Renes-Costello-Batina exception-free addition formula.
|
|
2978
2979
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2979
2980
|
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2980
2981
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2981
2982
|
add(u) {
|
|
2982
|
-
|
|
2983
|
-
const { X: h, Y:
|
|
2984
|
-
let
|
|
2985
|
-
const W = o.a,
|
|
2986
|
-
let k = t.mul(h, R), j = t.mul(
|
|
2987
|
-
ee = t.mul(ee,
|
|
2983
|
+
$(u);
|
|
2984
|
+
const { X: h, Y: b, Z: E } = this, { X: R, Y: T, Z: O } = u;
|
|
2985
|
+
let S = t.ZERO, C = t.ZERO, N = t.ZERO;
|
|
2986
|
+
const W = o.a, F = t.mul(o.b, Me);
|
|
2987
|
+
let k = t.mul(h, R), j = t.mul(b, T), V = t.mul(E, O), ee = t.add(h, b), G = t.add(R, T);
|
|
2988
|
+
ee = t.mul(ee, G), G = t.add(k, j), ee = t.sub(ee, G), G = t.add(h, E);
|
|
2988
2989
|
let K = t.add(R, O);
|
|
2989
|
-
return
|
|
2990
|
+
return G = t.mul(G, K), K = t.add(k, V), G = t.sub(G, K), K = t.add(b, E), S = t.add(T, O), K = t.mul(K, S), S = t.add(j, V), K = t.sub(K, S), N = t.mul(W, G), S = t.mul(F, V), N = t.add(S, N), S = t.sub(j, N), N = t.add(j, N), C = t.mul(S, N), j = t.add(k, k), j = t.add(j, k), V = t.mul(W, V), G = t.mul(F, G), j = t.add(j, V), V = t.sub(k, V), V = t.mul(W, V), G = t.add(G, V), k = t.mul(j, G), C = t.add(C, k), k = t.mul(K, G), S = t.mul(ee, S), S = t.sub(S, k), k = t.mul(ee, j), N = t.mul(K, N), N = t.add(N, k), new D(S, C, N);
|
|
2990
2991
|
}
|
|
2991
2992
|
subtract(u) {
|
|
2992
2993
|
return this.add(u.negate());
|
|
2993
2994
|
}
|
|
2994
2995
|
is0() {
|
|
2995
|
-
return this.equals(
|
|
2996
|
+
return this.equals(D.ZERO);
|
|
2996
2997
|
}
|
|
2997
2998
|
/**
|
|
2998
2999
|
* Constant time multiplication.
|
|
@@ -3007,16 +3008,16 @@ function Ur(r, e = {}) {
|
|
|
3007
3008
|
const { endo: h } = e;
|
|
3008
3009
|
if (!n.isValidNot0(u))
|
|
3009
3010
|
throw new Error("invalid scalar: out of range");
|
|
3010
|
-
let
|
|
3011
|
-
const R = (
|
|
3011
|
+
let b, E;
|
|
3012
|
+
const R = (T) => ne.cached(this, T, (O) => Lt(D, O));
|
|
3012
3013
|
if (h) {
|
|
3013
|
-
const { k1neg:
|
|
3014
|
-
|
|
3014
|
+
const { k1neg: T, k1: O, k2neg: S, k2: C } = B(u), { p: N, f: W } = R(O), { p: F, f: k } = R(C);
|
|
3015
|
+
E = W.add(k), b = he(h.beta, N, F, T, S);
|
|
3015
3016
|
} else {
|
|
3016
|
-
const { p:
|
|
3017
|
-
|
|
3017
|
+
const { p: T, f: O } = R(u);
|
|
3018
|
+
b = T, E = O;
|
|
3018
3019
|
}
|
|
3019
|
-
return Lt(
|
|
3020
|
+
return Lt(D, [b, E])[0];
|
|
3020
3021
|
}
|
|
3021
3022
|
/**
|
|
3022
3023
|
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
@@ -3024,20 +3025,20 @@ function Ur(r, e = {}) {
|
|
|
3024
3025
|
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
3025
3026
|
*/
|
|
3026
3027
|
multiplyUnsafe(u) {
|
|
3027
|
-
const { endo: h } = e,
|
|
3028
|
+
const { endo: h } = e, b = this;
|
|
3028
3029
|
if (!n.isValid(u))
|
|
3029
3030
|
throw new Error("invalid scalar: out of range");
|
|
3030
|
-
if (u === le ||
|
|
3031
|
-
return
|
|
3031
|
+
if (u === le || b.is0())
|
|
3032
|
+
return D.ZERO;
|
|
3032
3033
|
if (u === Ee)
|
|
3033
|
-
return
|
|
3034
|
+
return b;
|
|
3034
3035
|
if (ne.hasCache(this))
|
|
3035
3036
|
return this.multiply(u);
|
|
3036
3037
|
if (h) {
|
|
3037
|
-
const { k1neg:
|
|
3038
|
-
return he(h.beta,
|
|
3038
|
+
const { k1neg: E, k1: R, k2neg: T, k2: O } = B(u), { p1: S, p2: C } = Pr(D, b, R, O);
|
|
3039
|
+
return he(h.beta, S, C, E, T);
|
|
3039
3040
|
} else
|
|
3040
|
-
return ne.unsafe(
|
|
3041
|
+
return ne.unsafe(b, u);
|
|
3041
3042
|
}
|
|
3042
3043
|
/**
|
|
3043
3044
|
* Converts Projective point to affine (x, y) coordinates.
|
|
@@ -3052,17 +3053,17 @@ function Ur(r, e = {}) {
|
|
|
3052
3053
|
*/
|
|
3053
3054
|
isTorsionFree() {
|
|
3054
3055
|
const { isTorsionFree: u } = e;
|
|
3055
|
-
return i === Ee ? !0 : u ? u(
|
|
3056
|
+
return i === Ee ? !0 : u ? u(D, this) : ne.unsafe(this, a).is0();
|
|
3056
3057
|
}
|
|
3057
3058
|
clearCofactor() {
|
|
3058
3059
|
const { clearCofactor: u } = e;
|
|
3059
|
-
return i === Ee ? this : u ? u(
|
|
3060
|
+
return i === Ee ? this : u ? u(D, this) : this.multiplyUnsafe(i);
|
|
3060
3061
|
}
|
|
3061
3062
|
isSmallOrder() {
|
|
3062
3063
|
return this.multiplyUnsafe(i).is0();
|
|
3063
3064
|
}
|
|
3064
3065
|
toBytes(u = !0) {
|
|
3065
|
-
return He(u, "isCompressed"), this.assertValidity(),
|
|
3066
|
+
return He(u, "isCompressed"), this.assertValidity(), _(D, this, u);
|
|
3066
3067
|
}
|
|
3067
3068
|
toHex(u = !0) {
|
|
3068
3069
|
return ke(this.toBytes(u));
|
|
@@ -3072,12 +3073,12 @@ function Ur(r, e = {}) {
|
|
|
3072
3073
|
}
|
|
3073
3074
|
};
|
|
3074
3075
|
// base / generator point
|
|
3075
|
-
v(
|
|
3076
|
-
v(
|
|
3076
|
+
v(D, "BASE", new D(o.Gx, o.Gy, t.ONE)), // zero / infinity / identity point
|
|
3077
|
+
v(D, "ZERO", new D(t.ZERO, t.ONE, t.ZERO)), // 0, 1, 0
|
|
3077
3078
|
// math field
|
|
3078
|
-
v(
|
|
3079
|
-
v(
|
|
3080
|
-
let Z =
|
|
3079
|
+
v(D, "Fp", t), // scalar field
|
|
3080
|
+
v(D, "Fn", n);
|
|
3081
|
+
let Z = D;
|
|
3081
3082
|
const xe = n.BITS, ne = new Nr(Z, e.endo ? Math.ceil(xe / 2) : xe);
|
|
3082
3083
|
return Z.BASE.precompute(8), Z;
|
|
3083
3084
|
}
|
|
@@ -3095,50 +3096,50 @@ function ms(r, e) {
|
|
|
3095
3096
|
}
|
|
3096
3097
|
function Fr(r, e = {}) {
|
|
3097
3098
|
const { Fn: s } = r, t = e.randomBytes || Xt, n = Object.assign(ms(r.Fp, s), { seed: us(s.ORDER) });
|
|
3098
|
-
function o(
|
|
3099
|
+
function o(_) {
|
|
3099
3100
|
try {
|
|
3100
|
-
const
|
|
3101
|
-
return s.isValidNot0(
|
|
3101
|
+
const m = s.fromBytes(_);
|
|
3102
|
+
return s.isValidNot0(m);
|
|
3102
3103
|
} catch {
|
|
3103
3104
|
return !1;
|
|
3104
3105
|
}
|
|
3105
3106
|
}
|
|
3106
|
-
function i(
|
|
3107
|
-
const { publicKey:
|
|
3107
|
+
function i(_, m) {
|
|
3108
|
+
const { publicKey: A, publicKeyUncompressed: y } = n;
|
|
3108
3109
|
try {
|
|
3109
|
-
const
|
|
3110
|
-
return
|
|
3110
|
+
const I = _.length;
|
|
3111
|
+
return m === !0 && I !== A || m === !1 && I !== y ? !1 : !!r.fromBytes(_);
|
|
3111
3112
|
} catch {
|
|
3112
3113
|
return !1;
|
|
3113
3114
|
}
|
|
3114
3115
|
}
|
|
3115
|
-
function a(
|
|
3116
|
-
return kr(
|
|
3116
|
+
function a(_ = t(n.seed)) {
|
|
3117
|
+
return kr(H(_, n.seed, "seed"), s.ORDER);
|
|
3117
3118
|
}
|
|
3118
|
-
function c(
|
|
3119
|
-
return r.BASE.multiply(s.fromBytes(
|
|
3119
|
+
function c(_, m = !0) {
|
|
3120
|
+
return r.BASE.multiply(s.fromBytes(_)).toBytes(m);
|
|
3120
3121
|
}
|
|
3121
|
-
function l(
|
|
3122
|
-
const { secretKey:
|
|
3123
|
-
if (!at(
|
|
3122
|
+
function l(_) {
|
|
3123
|
+
const { secretKey: m, publicKey: A, publicKeyUncompressed: y } = n;
|
|
3124
|
+
if (!at(_) || "_lengths" in s && s._lengths || m === A)
|
|
3124
3125
|
return;
|
|
3125
|
-
const
|
|
3126
|
-
return
|
|
3126
|
+
const I = H(_, void 0, "key").length;
|
|
3127
|
+
return I === A || I === y;
|
|
3127
3128
|
}
|
|
3128
|
-
function d(
|
|
3129
|
-
if (l(
|
|
3129
|
+
function d(_, m, A = !0) {
|
|
3130
|
+
if (l(_) === !0)
|
|
3130
3131
|
throw new Error("first arg must be private key");
|
|
3131
|
-
if (l(
|
|
3132
|
+
if (l(m) === !1)
|
|
3132
3133
|
throw new Error("second arg must be public key");
|
|
3133
|
-
const
|
|
3134
|
-
return r.fromBytes(
|
|
3134
|
+
const y = s.fromBytes(_);
|
|
3135
|
+
return r.fromBytes(m).multiply(y).toBytes(A);
|
|
3135
3136
|
}
|
|
3136
|
-
const
|
|
3137
|
+
const f = {
|
|
3137
3138
|
isValidSecretKey: o,
|
|
3138
3139
|
isValidPublicKey: i,
|
|
3139
3140
|
randomSecretKey: a
|
|
3140
|
-
},
|
|
3141
|
-
return Object.freeze({ getPublicKey: c, getSharedSecret: d, keygen:
|
|
3141
|
+
}, w = Dr(a, c);
|
|
3142
|
+
return Object.freeze({ getPublicKey: c, getSharedSecret: d, keygen: w, Point: r, utils: f, lengths: n });
|
|
3142
3143
|
}
|
|
3143
3144
|
function Hr(r, e, s = {}) {
|
|
3144
3145
|
Kt(e), ut(s, {}, {
|
|
@@ -3148,55 +3149,55 @@ function Hr(r, e, s = {}) {
|
|
|
3148
3149
|
bits2int: "function",
|
|
3149
3150
|
bits2int_modN: "function"
|
|
3150
3151
|
}), s = Object.assign({}, s);
|
|
3151
|
-
const t = s.randomBytes || Xt, n = s.hmac || ((u, h) => gs(e, u, h)), { Fp: o, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret:
|
|
3152
|
+
const t = s.randomBytes || Xt, n = s.hmac || ((u, h) => gs(e, u, h)), { Fp: o, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret: f, utils: w, lengths: _ } = Fr(r, s), m = {
|
|
3152
3153
|
prehash: !0,
|
|
3153
3154
|
lowS: typeof s.lowS == "boolean" ? s.lowS : !0,
|
|
3154
3155
|
format: "compact",
|
|
3155
3156
|
extraEntropy: !1
|
|
3156
|
-
},
|
|
3157
|
-
function
|
|
3157
|
+
}, A = a * _s < o.ORDER;
|
|
3158
|
+
function y(u) {
|
|
3158
3159
|
const h = a >> Ee;
|
|
3159
3160
|
return u > h;
|
|
3160
3161
|
}
|
|
3161
|
-
function
|
|
3162
|
+
function I(u, h) {
|
|
3162
3163
|
if (!i.isValidNot0(h))
|
|
3163
3164
|
throw new Error(`invalid signature ${u}: out of range 1..Point.Fn.ORDER`);
|
|
3164
3165
|
return h;
|
|
3165
3166
|
}
|
|
3166
|
-
function
|
|
3167
|
-
if (
|
|
3167
|
+
function L() {
|
|
3168
|
+
if (A)
|
|
3168
3169
|
throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
3169
3170
|
}
|
|
3170
|
-
function
|
|
3171
|
+
function U(u, h) {
|
|
3171
3172
|
nt(h);
|
|
3172
|
-
const
|
|
3173
|
-
return
|
|
3173
|
+
const b = _.signature, E = h === "compact" ? b : h === "recovered" ? b + 1 : void 0;
|
|
3174
|
+
return H(u, E);
|
|
3174
3175
|
}
|
|
3175
|
-
class
|
|
3176
|
-
constructor(h,
|
|
3176
|
+
class $ {
|
|
3177
|
+
constructor(h, b, E) {
|
|
3177
3178
|
v(this, "r");
|
|
3178
3179
|
v(this, "s");
|
|
3179
3180
|
v(this, "recovery");
|
|
3180
|
-
if (this.r =
|
|
3181
|
-
if (
|
|
3181
|
+
if (this.r = I("r", h), this.s = I("s", b), E != null) {
|
|
3182
|
+
if (L(), ![0, 1, 2, 3].includes(E))
|
|
3182
3183
|
throw new Error("invalid recovery id");
|
|
3183
|
-
this.recovery =
|
|
3184
|
+
this.recovery = E;
|
|
3184
3185
|
}
|
|
3185
3186
|
Object.freeze(this);
|
|
3186
3187
|
}
|
|
3187
|
-
static fromBytes(h,
|
|
3188
|
-
|
|
3189
|
-
let
|
|
3190
|
-
if (
|
|
3191
|
-
const { r:
|
|
3192
|
-
return new
|
|
3188
|
+
static fromBytes(h, b = m.format) {
|
|
3189
|
+
U(h, b);
|
|
3190
|
+
let E;
|
|
3191
|
+
if (b === "der") {
|
|
3192
|
+
const { r: S, s: C } = ge.toSig(H(h));
|
|
3193
|
+
return new $(S, C);
|
|
3193
3194
|
}
|
|
3194
|
-
|
|
3195
|
-
const R =
|
|
3196
|
-
return new
|
|
3195
|
+
b === "recovered" && (E = h[0], b = "compact", h = h.subarray(1));
|
|
3196
|
+
const R = _.signature / 2, T = h.subarray(0, R), O = h.subarray(R, R * 2);
|
|
3197
|
+
return new $(i.fromBytes(T), i.fromBytes(O), E);
|
|
3197
3198
|
}
|
|
3198
|
-
static fromHex(h,
|
|
3199
|
-
return this.fromBytes(Fe(h),
|
|
3199
|
+
static fromHex(h, b) {
|
|
3200
|
+
return this.fromBytes(Fe(h), b);
|
|
3200
3201
|
}
|
|
3201
3202
|
assertRecovery() {
|
|
3202
3203
|
const { recovery: h } = this;
|
|
@@ -3205,108 +3206,108 @@ function Hr(r, e, s = {}) {
|
|
|
3205
3206
|
return h;
|
|
3206
3207
|
}
|
|
3207
3208
|
addRecoveryBit(h) {
|
|
3208
|
-
return new
|
|
3209
|
+
return new $(this.r, this.s, h);
|
|
3209
3210
|
}
|
|
3210
3211
|
recoverPublicKey(h) {
|
|
3211
|
-
const { r:
|
|
3212
|
-
if (!o.isValid(
|
|
3212
|
+
const { r: b, s: E } = this, R = this.assertRecovery(), T = R === 2 || R === 3 ? b + a : b;
|
|
3213
|
+
if (!o.isValid(T))
|
|
3213
3214
|
throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
3214
|
-
const O = o.toBytes(
|
|
3215
|
+
const O = o.toBytes(T), S = r.fromBytes(_e(xs((R & 1) === 0), O)), C = i.inv(T), N = Q(H(h, void 0, "msgHash")), W = i.create(-N * C), F = i.create(E * C), k = r.BASE.multiplyUnsafe(W).add(S.multiplyUnsafe(F));
|
|
3215
3216
|
if (k.is0())
|
|
3216
3217
|
throw new Error("invalid recovery: point at infinify");
|
|
3217
3218
|
return k.assertValidity(), k;
|
|
3218
3219
|
}
|
|
3219
3220
|
// Signatures should be low-s, to prevent malleability.
|
|
3220
3221
|
hasHighS() {
|
|
3221
|
-
return
|
|
3222
|
+
return y(this.s);
|
|
3222
3223
|
}
|
|
3223
|
-
toBytes(h =
|
|
3224
|
+
toBytes(h = m.format) {
|
|
3224
3225
|
if (nt(h), h === "der")
|
|
3225
3226
|
return Fe(ge.hexFromSig(this));
|
|
3226
|
-
const { r:
|
|
3227
|
-
return h === "recovered" ? (
|
|
3227
|
+
const { r: b, s: E } = this, R = i.toBytes(b), T = i.toBytes(E);
|
|
3228
|
+
return h === "recovered" ? (L(), _e(Uint8Array.of(this.assertRecovery()), R, T)) : _e(R, T);
|
|
3228
3229
|
}
|
|
3229
3230
|
toHex(h) {
|
|
3230
3231
|
return ke(this.toBytes(h));
|
|
3231
3232
|
}
|
|
3232
3233
|
}
|
|
3233
|
-
const
|
|
3234
|
+
const B = s.bits2int || function(h) {
|
|
3234
3235
|
if (h.length > 8192)
|
|
3235
3236
|
throw new Error("input is too large");
|
|
3236
|
-
const
|
|
3237
|
-
return
|
|
3237
|
+
const b = je(h), E = h.length * 8 - c;
|
|
3238
|
+
return E > 0 ? b >> BigInt(E) : b;
|
|
3238
3239
|
}, Q = s.bits2int_modN || function(h) {
|
|
3239
|
-
return i.create(
|
|
3240
|
+
return i.create(B(h));
|
|
3240
3241
|
}, ve = dt(c);
|
|
3241
3242
|
function he(u) {
|
|
3242
3243
|
return mr("num < 2^" + c, u, le, ve), i.toBytes(u);
|
|
3243
3244
|
}
|
|
3244
3245
|
function Z(u, h) {
|
|
3245
|
-
return
|
|
3246
|
+
return H(u, void 0, "message"), h ? H(e(u), void 0, "prehashed message") : u;
|
|
3246
3247
|
}
|
|
3247
|
-
function xe(u, h,
|
|
3248
|
-
const { lowS:
|
|
3248
|
+
function xe(u, h, b) {
|
|
3249
|
+
const { lowS: E, prehash: R, extraEntropy: T } = et(b, m);
|
|
3249
3250
|
u = Z(u, R);
|
|
3250
|
-
const O = Q(u),
|
|
3251
|
-
if (!i.isValidNot0(
|
|
3251
|
+
const O = Q(u), S = i.fromBytes(h);
|
|
3252
|
+
if (!i.isValidNot0(S))
|
|
3252
3253
|
throw new Error("invalid private key");
|
|
3253
|
-
const C = [he(
|
|
3254
|
-
if (
|
|
3255
|
-
const k =
|
|
3256
|
-
C.push(
|
|
3254
|
+
const C = [he(S), he(O)];
|
|
3255
|
+
if (T != null && T !== !1) {
|
|
3256
|
+
const k = T === !0 ? t(_.secretKey) : T;
|
|
3257
|
+
C.push(H(k, void 0, "extraEntropy"));
|
|
3257
3258
|
}
|
|
3258
3259
|
const N = _e(...C), W = O;
|
|
3259
|
-
function
|
|
3260
|
-
const j =
|
|
3260
|
+
function F(k) {
|
|
3261
|
+
const j = B(k);
|
|
3261
3262
|
if (!i.isValidNot0(j))
|
|
3262
3263
|
return;
|
|
3263
|
-
const V = i.inv(j), ee = r.BASE.multiply(j).toAffine(),
|
|
3264
|
-
if (
|
|
3264
|
+
const V = i.inv(j), ee = r.BASE.multiply(j).toAffine(), G = i.create(ee.x);
|
|
3265
|
+
if (G === le)
|
|
3265
3266
|
return;
|
|
3266
|
-
const K = i.create(V * i.create(W +
|
|
3267
|
+
const K = i.create(V * i.create(W + G * S));
|
|
3267
3268
|
if (K === le)
|
|
3268
3269
|
return;
|
|
3269
|
-
let xt = (ee.x ===
|
|
3270
|
-
return
|
|
3270
|
+
let xt = (ee.x === G ? 0 : 2) | Number(ee.y & Ee), mt = K;
|
|
3271
|
+
return E && y(K) && (mt = i.neg(K), xt ^= 1), new $(G, mt, A ? void 0 : xt);
|
|
3271
3272
|
}
|
|
3272
|
-
return { seed: N, k2sig:
|
|
3273
|
+
return { seed: N, k2sig: F };
|
|
3273
3274
|
}
|
|
3274
|
-
function ne(u, h,
|
|
3275
|
-
const { seed:
|
|
3276
|
-
return yr(e.outputLen, i.BYTES, n)(
|
|
3275
|
+
function ne(u, h, b = {}) {
|
|
3276
|
+
const { seed: E, k2sig: R } = xe(u, h, b);
|
|
3277
|
+
return yr(e.outputLen, i.BYTES, n)(E, R).toBytes(b.format);
|
|
3277
3278
|
}
|
|
3278
|
-
function
|
|
3279
|
-
const { lowS: R, prehash:
|
|
3280
|
-
if (
|
|
3281
|
-
const
|
|
3282
|
-
throw new Error("verify expects Uint8Array signature" +
|
|
3279
|
+
function D(u, h, b, E = {}) {
|
|
3280
|
+
const { lowS: R, prehash: T, format: O } = et(E, m);
|
|
3281
|
+
if (b = H(b, void 0, "publicKey"), h = Z(h, T), !at(u)) {
|
|
3282
|
+
const S = u instanceof $ ? ", use sig.toBytes()" : "";
|
|
3283
|
+
throw new Error("verify expects Uint8Array signature" + S);
|
|
3283
3284
|
}
|
|
3284
|
-
|
|
3285
|
+
U(u, O);
|
|
3285
3286
|
try {
|
|
3286
|
-
const
|
|
3287
|
-
if (R &&
|
|
3287
|
+
const S = $.fromBytes(u, O), C = r.fromBytes(b);
|
|
3288
|
+
if (R && S.hasHighS())
|
|
3288
3289
|
return !1;
|
|
3289
|
-
const { r: N, s: W } =
|
|
3290
|
+
const { r: N, s: W } = S, F = Q(h), k = i.inv(W), j = i.create(F * k), V = i.create(N * k), ee = r.BASE.multiplyUnsafe(j).add(C.multiplyUnsafe(V));
|
|
3290
3291
|
return ee.is0() ? !1 : i.create(ee.x) === N;
|
|
3291
3292
|
} catch {
|
|
3292
3293
|
return !1;
|
|
3293
3294
|
}
|
|
3294
3295
|
}
|
|
3295
|
-
function P(u, h,
|
|
3296
|
-
const { prehash:
|
|
3297
|
-
return h = Z(h,
|
|
3296
|
+
function P(u, h, b = {}) {
|
|
3297
|
+
const { prehash: E } = et(b, m);
|
|
3298
|
+
return h = Z(h, E), $.fromBytes(u, "recovered").recoverPublicKey(h).toBytes();
|
|
3298
3299
|
}
|
|
3299
3300
|
return Object.freeze({
|
|
3300
3301
|
keygen: l,
|
|
3301
3302
|
getPublicKey: d,
|
|
3302
|
-
getSharedSecret:
|
|
3303
|
-
utils:
|
|
3304
|
-
lengths:
|
|
3303
|
+
getSharedSecret: f,
|
|
3304
|
+
utils: w,
|
|
3305
|
+
lengths: _,
|
|
3305
3306
|
Point: r,
|
|
3306
3307
|
sign: ne,
|
|
3307
|
-
verify:
|
|
3308
|
+
verify: D,
|
|
3308
3309
|
recoverPublicKey: P,
|
|
3309
|
-
Signature:
|
|
3310
|
+
Signature: $,
|
|
3310
3311
|
hash: e
|
|
3311
3312
|
});
|
|
3312
3313
|
}
|
|
@@ -3327,7 +3328,7 @@ const ft = {
|
|
|
3327
3328
|
]
|
|
3328
3329
|
}, Ut = /* @__PURE__ */ BigInt(2);
|
|
3329
3330
|
function qr(r) {
|
|
3330
|
-
const e = ft.p, s = BigInt(3), t = BigInt(6), n = BigInt(11), o = BigInt(22), i = BigInt(23), a = BigInt(44), c = BigInt(88), l = r * r * r % e, d = l * l * r % e,
|
|
3331
|
+
const e = ft.p, s = BigInt(3), t = BigInt(6), n = BigInt(11), o = BigInt(22), i = BigInt(23), a = BigInt(44), c = BigInt(88), l = r * r * r % e, d = l * l * r % e, f = se(d, s, e) * d % e, w = se(f, s, e) * d % e, _ = se(w, Ut, e) * l % e, m = se(_, n, e) * _ % e, A = se(m, o, e) * m % e, y = se(A, a, e) * A % e, I = se(y, c, e) * y % e, L = se(I, a, e) * A % e, U = se(L, s, e) * d % e, $ = se(U, i, e) * m % e, B = se($, t, e) * l % e, Q = se(B, Ut, e);
|
|
3331
3332
|
if (!ot.eql(ot.sqr(Q), r))
|
|
3332
3333
|
throw new Error("Cannot find square root");
|
|
3333
3334
|
return Q;
|
|
@@ -3350,9 +3351,9 @@ function Qr(r, e = 24) {
|
|
|
3350
3351
|
for (let i = 0; i < 10; i++)
|
|
3351
3352
|
s[i] = r[i] ^ r[i + 10] ^ r[i + 20] ^ r[i + 30] ^ r[i + 40];
|
|
3352
3353
|
for (let i = 0; i < 10; i += 2) {
|
|
3353
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1],
|
|
3354
|
-
for (let
|
|
3355
|
-
r[i +
|
|
3354
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1], f = Ft(l, d, 1) ^ s[a], w = Ht(l, d, 1) ^ s[a + 1];
|
|
3355
|
+
for (let _ = 0; _ < 50; _ += 10)
|
|
3356
|
+
r[i + _] ^= f, r[i + _ + 1] ^= w;
|
|
3356
3357
|
}
|
|
3357
3358
|
let n = r[2], o = r[3];
|
|
3358
3359
|
for (let i = 0; i < 24; i++) {
|
|
@@ -3394,7 +3395,7 @@ class pt {
|
|
|
3394
3395
|
Rt(this.state32), Qr(this.state32, this.rounds), Rt(this.state32), this.posOut = 0, this.pos = 0;
|
|
3395
3396
|
}
|
|
3396
3397
|
update(e) {
|
|
3397
|
-
Ie(this),
|
|
3398
|
+
Ie(this), H(e);
|
|
3398
3399
|
const { blockLen: s, state: t } = this, n = e.length;
|
|
3399
3400
|
for (let o = 0; o < n; ) {
|
|
3400
3401
|
const i = Math.min(s - this.pos, n - o);
|
|
@@ -3412,7 +3413,7 @@ class pt {
|
|
|
3412
3413
|
e[t] ^= s, s & 128 && t === n - 1 && this.keccak(), e[n - 1] ^= 128, this.keccak();
|
|
3413
3414
|
}
|
|
3414
3415
|
writeInto(e) {
|
|
3415
|
-
Ie(this, !1),
|
|
3416
|
+
Ie(this, !1), H(e), this.finish();
|
|
3416
3417
|
const s = this.state, { blockLen: t } = this;
|
|
3417
3418
|
for (let n = 0, o = e.length; n < o; ) {
|
|
3418
3419
|
this.posOut >= t && this.keccak();
|
|
@@ -3450,20 +3451,20 @@ class tn {
|
|
|
3450
3451
|
async verifyJWT(e, s) {
|
|
3451
3452
|
try {
|
|
3452
3453
|
const t = this.decodeJWT(e);
|
|
3453
|
-
|
|
3454
|
+
p.log("[CROSSx] JWT 디코딩 성공:", {
|
|
3454
3455
|
sub: t.sub,
|
|
3455
3456
|
exp: t.exp,
|
|
3456
3457
|
iat: t.iat,
|
|
3457
3458
|
"현재 시간": Math.floor(Date.now() / 1e3)
|
|
3458
3459
|
});
|
|
3459
3460
|
const n = Math.floor(Date.now() / 1e3);
|
|
3460
|
-
return t.exp && t.exp < n ? (
|
|
3461
|
+
return t.exp && t.exp < n ? (p.warn("[CROSSx] 토큰 만료:", {
|
|
3461
3462
|
exp: t.exp,
|
|
3462
3463
|
now: n,
|
|
3463
3464
|
만료시간: new Date(t.exp * 1e3).toISOString()
|
|
3464
|
-
}), { payload: t, valid: !1, signatureVerified: !1 }) : t.sub ? (
|
|
3465
|
+
}), { payload: t, valid: !1, signatureVerified: !1 }) : t.sub ? (p.log("[CROSSx] JWT 검증 성공 (서명 미검증 — JWKS 미구현)"), { payload: t, valid: !0, signatureVerified: !1 }) : (p.warn("[CROSSx] JWT에 sub(사용자ID) 없음"), { payload: t, valid: !1, signatureVerified: !1 });
|
|
3465
3466
|
} catch (t) {
|
|
3466
|
-
throw
|
|
3467
|
+
throw p.error("[CROSSx] JWT 검증 중 에러:", t), t;
|
|
3467
3468
|
}
|
|
3468
3469
|
}
|
|
3469
3470
|
decodeJWT(e) {
|
|
@@ -3485,11 +3486,11 @@ ${t.length}`
|
|
|
3485
3486
|
const i = Gt(o), a = s.startsWith("0x") ? s.slice(2) : s;
|
|
3486
3487
|
if (a.length !== 130)
|
|
3487
3488
|
throw new Error(`Invalid signature length: expected 130 hex chars, got ${a.length}`);
|
|
3488
|
-
const c = sn(a), l = c.slice(0, 32), d = c.slice(32, 64),
|
|
3489
|
+
const c = sn(a), l = c.slice(0, 32), d = c.slice(32, 64), f = c[64], w = f >= 27 ? f - 27 : f, A = new jr.Signature(
|
|
3489
3490
|
qt(l),
|
|
3490
3491
|
qt(d)
|
|
3491
|
-
).addRecoveryBit(
|
|
3492
|
-
return "0x" + ke(
|
|
3492
|
+
).addRecoveryBit(w).recoverPublicKey(i).toBytes(!1).slice(1), y = Gt(A);
|
|
3493
|
+
return "0x" + ke(y.slice(12));
|
|
3493
3494
|
}
|
|
3494
3495
|
}
|
|
3495
3496
|
function sn(r) {
|
|
@@ -3542,53 +3543,53 @@ class gt {
|
|
|
3542
3543
|
}
|
|
3543
3544
|
openAuth(e) {
|
|
3544
3545
|
return new Promise((s, t) => {
|
|
3545
|
-
const n = e.width ?? 500, o = e.height ?? 600, i = window.screenX + (window.outerWidth - n) / 2, a = window.screenY + (window.outerHeight - o) / 2, c = gt.generateState(), l = e.authUrl.includes("?") ? "&" : "?", d = `${e.authUrl}${l}state=${c}`,
|
|
3546
|
+
const n = e.width ?? 500, o = e.height ?? 600, i = window.screenX + (window.outerWidth - n) / 2, a = window.screenY + (window.outerHeight - o) / 2, c = gt.generateState(), l = e.authUrl.includes("?") ? "&" : "?", d = `${e.authUrl}${l}state=${c}`, f = window.open(
|
|
3546
3547
|
d,
|
|
3547
3548
|
"CROSSx OAuth",
|
|
3548
3549
|
`width=${n},height=${o},left=${i},top=${a}`
|
|
3549
3550
|
);
|
|
3550
|
-
if (!
|
|
3551
|
+
if (!f) {
|
|
3551
3552
|
t(new Error("팝업 창을 열 수 없습니다. 팝업 차단을 해제해 주세요."));
|
|
3552
3553
|
return;
|
|
3553
3554
|
}
|
|
3554
|
-
const
|
|
3555
|
-
|
|
3556
|
-
}, 5 * 60 * 1e3),
|
|
3557
|
-
let
|
|
3558
|
-
const
|
|
3559
|
-
clearInterval(
|
|
3560
|
-
|
|
3555
|
+
const w = setTimeout(() => {
|
|
3556
|
+
p.warn("[CROSSx] OAuth 타임아웃 (5분) — postMessage를 수신하지 못했습니다"), U(), t(new Error("Authentication timeout"));
|
|
3557
|
+
}, 5 * 60 * 1e3), _ = 10, m = 30;
|
|
3558
|
+
let A = 0, y = null;
|
|
3559
|
+
const I = () => {
|
|
3560
|
+
clearInterval(L), p.warn("[CROSSx] COOP 감지 — OAuth 서버 응답을 " + m + "초간 대기합니다"), y = setTimeout(() => {
|
|
3561
|
+
U(), t(new Error(
|
|
3561
3562
|
"OAuth 서버로부터 응답을 받지 못했습니다. 브라우저 보안 정책(COOP)으로 인해 팝업 통신이 차단되었을 수 있습니다. 다시 시도해 주세요."
|
|
3562
3563
|
));
|
|
3563
|
-
},
|
|
3564
|
-
},
|
|
3565
|
-
|
|
3564
|
+
}, m * 1e3);
|
|
3565
|
+
}, L = setInterval(() => {
|
|
3566
|
+
A++;
|
|
3566
3567
|
try {
|
|
3567
|
-
|
|
3568
|
+
f.closed && (A <= _ ? I() : (U(), t(new Error("로그인이 취소되었습니다"))));
|
|
3568
3569
|
} catch {
|
|
3569
|
-
|
|
3570
|
+
I();
|
|
3570
3571
|
}
|
|
3571
|
-
}, 1e3),
|
|
3572
|
-
clearTimeout(
|
|
3573
|
-
},
|
|
3574
|
-
var ve, he, Z, xe, ne,
|
|
3575
|
-
if (
|
|
3576
|
-
|
|
3577
|
-
const Q =
|
|
3572
|
+
}, 1e3), U = () => {
|
|
3573
|
+
clearTimeout(w), clearInterval(L), y && clearTimeout(y), window.removeEventListener("message", $);
|
|
3574
|
+
}, $ = (B) => {
|
|
3575
|
+
var ve, he, Z, xe, ne, D, P;
|
|
3576
|
+
if (B.origin !== e.expectedOrigin) return;
|
|
3577
|
+
U(), p.log("[CROSSx] OAuth postMessage 수신 — status:", B.data.status);
|
|
3578
|
+
const Q = B.data.state ?? ((ve = B.data.data) == null ? void 0 : ve.state);
|
|
3578
3579
|
if (!Q || Q !== c) {
|
|
3579
3580
|
t(new Error("OAuth state mismatch — possible CSRF attack"));
|
|
3580
3581
|
return;
|
|
3581
3582
|
}
|
|
3582
|
-
if (
|
|
3583
|
-
const u = ((he =
|
|
3584
|
-
|
|
3585
|
-
hasAccessToken: !!((xe =
|
|
3586
|
-
hasIdToken: !!((ne =
|
|
3587
|
-
}), u ? s(u) : (
|
|
3583
|
+
if (B.data.status === "success") {
|
|
3584
|
+
const u = ((he = B.data.data) == null ? void 0 : he.accessToken) || ((Z = B.data.data) == null ? void 0 : Z.idToken);
|
|
3585
|
+
p.log("[CROSSx] OAuth 토큰 수신:", {
|
|
3586
|
+
hasAccessToken: !!((xe = B.data.data) != null && xe.accessToken),
|
|
3587
|
+
hasIdToken: !!((ne = B.data.data) != null && ne.idToken)
|
|
3588
|
+
}), u ? s(u) : (p.error("[CROSSx] 토큰을 찾을 수 없음:", B.data), t(new Error("Token not found in response")));
|
|
3588
3589
|
} else
|
|
3589
|
-
|
|
3590
|
+
p.error("[CROSSx] OAuth 실패:", (D = B.data.data) == null ? void 0 : D.error), t(new Error(((P = B.data.data) == null ? void 0 : P.error) || "Authentication failed"));
|
|
3590
3591
|
};
|
|
3591
|
-
window.addEventListener("message",
|
|
3592
|
+
window.addEventListener("message", $);
|
|
3592
3593
|
});
|
|
3593
3594
|
}
|
|
3594
3595
|
}
|
|
@@ -3609,7 +3610,7 @@ class on {
|
|
|
3609
3610
|
};
|
|
3610
3611
|
return await this.storage.set(Oe, t), t;
|
|
3611
3612
|
} catch (s) {
|
|
3612
|
-
throw new
|
|
3613
|
+
throw new x(g.WALLET_CREATION_FAILED, "Wallet creation failed", s);
|
|
3613
3614
|
}
|
|
3614
3615
|
}
|
|
3615
3616
|
async getAddresses(e) {
|
|
@@ -3624,24 +3625,24 @@ class on {
|
|
|
3624
3625
|
}
|
|
3625
3626
|
async prepare(e, s) {
|
|
3626
3627
|
const t = "mock-" + crypto.randomUUID();
|
|
3627
|
-
return
|
|
3628
|
+
return p.log(`[Mock] prepare action=${e} → uuid=${t}`), { uuid: t, expiresAt: new Date(Date.now() + 5 * 6e4).toISOString() };
|
|
3628
3629
|
}
|
|
3629
3630
|
async signMessage(e, s, t, n = 0, o, i) {
|
|
3630
|
-
return
|
|
3631
|
+
return p.log(`[Mock] signMessage chainId=${s} index=${n} uuid=${o} from=${i}: "${t}"`), { chainId: s, signature: this.generateMockSignature(), format: "hex" };
|
|
3631
3632
|
}
|
|
3632
3633
|
async signTypedData(e, s, t, n = 0, o, i) {
|
|
3633
|
-
return
|
|
3634
|
+
return p.log(`[Mock] signTypedData chainId=${s} index=${n} uuid=${o} from=${i}`), { chainId: s, signature: this.generateMockSignature(), format: "hex" };
|
|
3634
3635
|
}
|
|
3635
3636
|
async signTransaction(e, s, t, n = 0, o) {
|
|
3636
|
-
|
|
3637
|
+
p.log(`[Mock] signTransaction chainId=${s} index=${n} uuid=${o}:`, t);
|
|
3637
3638
|
const i = "0x" + Array(64).fill(0).map(() => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
3638
3639
|
return { chainId: s, signature: this.generateMockSignature(), txHash: i, format: "hex" };
|
|
3639
3640
|
}
|
|
3640
3641
|
async sendTransaction(e, s, t, n) {
|
|
3641
|
-
return
|
|
3642
|
+
return p.log(`[Mock] sendTransaction chainId=${s} uuid=${n}:`, t), { txHash: "0x" + Array(64).fill(0).map(() => Math.floor(Math.random() * 16).toString(16)).join("") };
|
|
3642
3643
|
}
|
|
3643
3644
|
async recoverWallet(e, s) {
|
|
3644
|
-
|
|
3645
|
+
p.log("[Mock] recoverWallet");
|
|
3645
3646
|
const t = {
|
|
3646
3647
|
id: e,
|
|
3647
3648
|
address: this.generateMockEvmAddress(),
|
|
@@ -3651,7 +3652,7 @@ class on {
|
|
|
3651
3652
|
return await this.storage.set(Oe, t), t;
|
|
3652
3653
|
}
|
|
3653
3654
|
async migrateWallet(e, s) {
|
|
3654
|
-
|
|
3655
|
+
p.log(`[Mock] migrateWallet pin=${e} sub=${s}`);
|
|
3655
3656
|
const t = {
|
|
3656
3657
|
id: s,
|
|
3657
3658
|
address: this.generateMockEvmAddress(),
|
|
@@ -3681,7 +3682,7 @@ class qe {
|
|
|
3681
3682
|
getAuthToken() {
|
|
3682
3683
|
const e = this.tokenStore.get();
|
|
3683
3684
|
if (!e)
|
|
3684
|
-
throw new
|
|
3685
|
+
throw new x(
|
|
3685
3686
|
g.AUTH_NOT_AUTHENTICATED,
|
|
3686
3687
|
"No auth token found. Please sign in first."
|
|
3687
3688
|
);
|
|
@@ -3703,33 +3704,33 @@ class qe {
|
|
|
3703
3704
|
})).data;
|
|
3704
3705
|
if (d && typeof d.code == "number") {
|
|
3705
3706
|
if (d.code < 0 || d.code >= 400) {
|
|
3706
|
-
const
|
|
3707
|
-
|
|
3707
|
+
const f = d.message || d.data || "API request failed";
|
|
3708
|
+
p.error("[CROSSx] Wallet Gateway API 에러 (HTTP 200):", {
|
|
3708
3709
|
code: d.code,
|
|
3709
|
-
message:
|
|
3710
|
+
message: f,
|
|
3710
3711
|
url: o,
|
|
3711
3712
|
method: e,
|
|
3712
3713
|
fullResponse: d
|
|
3713
3714
|
});
|
|
3714
|
-
const
|
|
3715
|
-
throw
|
|
3715
|
+
const w = qe.mapGatewayError(d.code), _ = qe.getGatewayErrorMessage(d.code, f), m = new x(w, _);
|
|
3716
|
+
throw m.gatewayCode = d.code, m.gatewayMessage = f, m;
|
|
3716
3717
|
}
|
|
3717
|
-
return
|
|
3718
|
+
return p.log("[CROSSx] Wallet Gateway API 성공:", { code: d.code, url: o, method: e }), d.data ?? d;
|
|
3718
3719
|
}
|
|
3719
3720
|
return d;
|
|
3720
3721
|
} catch (l) {
|
|
3721
|
-
if (l instanceof
|
|
3722
|
+
if (l instanceof x) throw l;
|
|
3722
3723
|
if ((a = l.response) != null && a.data) {
|
|
3723
|
-
const d = l.response.data,
|
|
3724
|
-
throw
|
|
3725
|
-
code:
|
|
3726
|
-
message:
|
|
3724
|
+
const d = l.response.data, f = d.message || d.data || "API request failed", w = d.code || "UNKNOWN";
|
|
3725
|
+
throw p.error("[CROSSx] Wallet Gateway API 에러 (HTTP 에러):", {
|
|
3726
|
+
code: w,
|
|
3727
|
+
message: f,
|
|
3727
3728
|
url: o,
|
|
3728
3729
|
method: e,
|
|
3729
3730
|
status: (c = l.response) == null ? void 0 : c.status
|
|
3730
|
-
}), new
|
|
3731
|
+
}), new x(
|
|
3731
3732
|
g.UNKNOWN_ERROR,
|
|
3732
|
-
`Wallet Gateway error (${
|
|
3733
|
+
`Wallet Gateway error (${w}): ${f}`
|
|
3733
3734
|
);
|
|
3734
3735
|
}
|
|
3735
3736
|
throw l;
|
|
@@ -3737,12 +3738,12 @@ class qe {
|
|
|
3737
3738
|
}
|
|
3738
3739
|
async getOrCreateWallet(e) {
|
|
3739
3740
|
var s;
|
|
3740
|
-
|
|
3741
|
+
p.log("[CROSSx][Migration Phase 2] GET /mnemonic/addresses — 기존 지갑 조회");
|
|
3741
3742
|
try {
|
|
3742
3743
|
const t = await this.request("GET", "/mnemonic/addresses");
|
|
3743
3744
|
if (t.addresses && t.addresses.length > 0) {
|
|
3744
3745
|
const { address: n } = t.addresses[0];
|
|
3745
|
-
return
|
|
3746
|
+
return p.log("[CROSSx][Migration Phase 2] 기존 지갑 발견 — address:", n), {
|
|
3746
3747
|
id: e,
|
|
3747
3748
|
address: n,
|
|
3748
3749
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -3750,12 +3751,12 @@ class qe {
|
|
|
3750
3751
|
};
|
|
3751
3752
|
}
|
|
3752
3753
|
} catch {
|
|
3753
|
-
|
|
3754
|
+
p.log("[CROSSx][Migration Phase 2] 기존 지갑 없음, POST /mnemonic/create 진행");
|
|
3754
3755
|
}
|
|
3755
|
-
|
|
3756
|
+
p.log("[CROSSx][Migration Phase 2] POST /mnemonic/create — ignoreBackup: false");
|
|
3756
3757
|
try {
|
|
3757
3758
|
const t = { ignoreBackup: !1 }, n = await this.request("POST", "/mnemonic/create", t);
|
|
3758
|
-
return
|
|
3759
|
+
return p.log("[CROSSx][Migration Phase 2] /mnemonic/create 성공 — address:", n.address), {
|
|
3759
3760
|
id: e,
|
|
3760
3761
|
address: n.address,
|
|
3761
3762
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -3763,7 +3764,7 @@ class qe {
|
|
|
3763
3764
|
};
|
|
3764
3765
|
} catch (t) {
|
|
3765
3766
|
if ((t == null ? void 0 : t.gatewayCode) === -10004 || (s = t == null ? void 0 : t.message) != null && s.includes("-10004")) {
|
|
3766
|
-
|
|
3767
|
+
p.log("[CROSSx][Migration Phase 2] 지갑 이미 존재 (-10004), 주소 재조회");
|
|
3767
3768
|
const n = await this.request("GET", "/mnemonic/addresses");
|
|
3768
3769
|
if (n.addresses && n.addresses.length > 0)
|
|
3769
3770
|
return {
|
|
@@ -3773,7 +3774,7 @@ class qe {
|
|
|
3773
3774
|
createdAt: Date.now()
|
|
3774
3775
|
};
|
|
3775
3776
|
}
|
|
3776
|
-
throw (t == null ? void 0 : t.gatewayCode) === -10012 &&
|
|
3777
|
+
throw (t == null ? void 0 : t.gatewayCode) === -10012 && p.log("[CROSSx][Migration Phase 2] Gateway -10012 수신 → MIGRATION_BACKUP_EXISTS throw"), t;
|
|
3777
3778
|
}
|
|
3778
3779
|
}
|
|
3779
3780
|
async getAddresses(e) {
|
|
@@ -3786,8 +3787,8 @@ class qe {
|
|
|
3786
3787
|
`/mnemonic/address?index=${s}`
|
|
3787
3788
|
)).address, derivationPath: `m/44'/60'/0'/0/${s}` };
|
|
3788
3789
|
} catch (t) {
|
|
3789
|
-
if (t instanceof
|
|
3790
|
-
return
|
|
3790
|
+
if (t instanceof x && this.isAddressNotFoundError(t))
|
|
3791
|
+
return p.log(`[CROSSx] index ${s} 주소 없음, 파생 중...`), { address: (await this.request(
|
|
3791
3792
|
"GET",
|
|
3792
3793
|
`/mnemonic/address?index=${s}&derive=true`
|
|
3793
3794
|
)).address, derivationPath: `m/44'/60'/0'/0/${s}` };
|
|
@@ -3803,15 +3804,15 @@ class qe {
|
|
|
3803
3804
|
switch (e) {
|
|
3804
3805
|
case "sign":
|
|
3805
3806
|
case "send":
|
|
3806
|
-
if (!s.tx) throw new
|
|
3807
|
+
if (!s.tx) throw new x(g.TX_INVALID_PARAMS, "prepare: tx is required");
|
|
3807
3808
|
t = { unsignedTx: this.buildUnsignedTx(s.tx) };
|
|
3808
3809
|
break;
|
|
3809
3810
|
case "sign-message":
|
|
3810
|
-
if (!s.message) throw new
|
|
3811
|
+
if (!s.message) throw new x(g.TX_INVALID_PARAMS, "prepare: message is required");
|
|
3811
3812
|
t = { message: s.message }, s.from && (t.from = s.from);
|
|
3812
3813
|
break;
|
|
3813
3814
|
case "sign-typed-data":
|
|
3814
|
-
if (!s.typedData) throw new
|
|
3815
|
+
if (!s.typedData) throw new x(g.TX_INVALID_PARAMS, "prepare: typedData is required");
|
|
3815
3816
|
t = { typedData: s.typedData }, s.from && (t.from = s.from);
|
|
3816
3817
|
break;
|
|
3817
3818
|
}
|
|
@@ -3883,13 +3884,13 @@ class qe {
|
|
|
3883
3884
|
};
|
|
3884
3885
|
}
|
|
3885
3886
|
async migrateWallet(e, s) {
|
|
3886
|
-
|
|
3887
|
+
p.log("[CROSSx][Migration Phase 4] POST /mnemonic/migrate 호출 — sub:", s);
|
|
3887
3888
|
const t = { pin: e, sub: s }, n = await this.request(
|
|
3888
3889
|
"POST",
|
|
3889
3890
|
"/mnemonic/migrate",
|
|
3890
3891
|
t
|
|
3891
3892
|
);
|
|
3892
|
-
return
|
|
3893
|
+
return p.log("[CROSSx][Migration Phase 4] /mnemonic/migrate 완료 — address:", n.address), {
|
|
3893
3894
|
id: s,
|
|
3894
3895
|
address: n.address,
|
|
3895
3896
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -4006,7 +4007,7 @@ class Ce {
|
|
|
4006
4007
|
handleEnvelopeError(e) {
|
|
4007
4008
|
if (e.code < 0) {
|
|
4008
4009
|
const s = typeof e.data == "string" ? e.data : e.message ?? "Chain registry request failed";
|
|
4009
|
-
throw new
|
|
4010
|
+
throw new x(
|
|
4010
4011
|
Ce.mapErrorCode(e.code),
|
|
4011
4012
|
s
|
|
4012
4013
|
);
|
|
@@ -4017,7 +4018,7 @@ class Ce {
|
|
|
4017
4018
|
(t) => t.chainId === e
|
|
4018
4019
|
);
|
|
4019
4020
|
if (s) return s;
|
|
4020
|
-
throw new
|
|
4021
|
+
throw new x(
|
|
4021
4022
|
g.CHAIN_NOT_SUPPORTED,
|
|
4022
4023
|
`Unsupported chain: ${e}`
|
|
4023
4024
|
);
|
|
@@ -4852,6 +4853,18 @@ const cn = `
|
|
|
4852
4853
|
color: var(--cx-value);
|
|
4853
4854
|
white-space: nowrap;
|
|
4854
4855
|
}
|
|
4856
|
+
.__crossx-wallet-selected {
|
|
4857
|
+
font-size: 11px;
|
|
4858
|
+
font-weight: 600;
|
|
4859
|
+
line-height: 1;
|
|
4860
|
+
color: var(--cx-primary);
|
|
4861
|
+
border: 1.5px solid var(--cx-primary);
|
|
4862
|
+
border-radius: 6px;
|
|
4863
|
+
padding: 4px 8px;
|
|
4864
|
+
margin-left: auto;
|
|
4865
|
+
flex-shrink: 0;
|
|
4866
|
+
white-space: nowrap;
|
|
4867
|
+
}
|
|
4855
4868
|
.__crossx-wallet-add {
|
|
4856
4869
|
display: flex;
|
|
4857
4870
|
align-items: center;
|
|
@@ -5123,9 +5136,9 @@ function un(r) {
|
|
|
5123
5136
|
}
|
|
5124
5137
|
function Es(r) {
|
|
5125
5138
|
const e = un(r);
|
|
5126
|
-
if (!e) return
|
|
5127
|
-
let s =
|
|
5128
|
-
return e.isDynamic ? (e.maxPriorityFeeGwei !== void 0 && (s +=
|
|
5139
|
+
if (!e) return q("Estimated fee", "<span>—</span>");
|
|
5140
|
+
let s = q("Est. Tx Fee", `<span>${e.estTxFee}</span>`);
|
|
5141
|
+
return e.isDynamic ? (e.maxPriorityFeeGwei !== void 0 && (s += q("Max Priority Fee", `<span>${e.maxPriorityFeeGwei} Gwei</span>`)), e.maxFeeGwei !== void 0 && (s += q("Max Gas Fee", `<span>${e.maxFeeGwei} Gwei</span>`))) : e.gasPriceGwei !== void 0 && (s += q("Gas Price", `<span>${e.gasPriceGwei} Gwei</span>`)), e.gasLimitFormatted && (s += q("Gas Limit", `<span>${e.gasLimitFormatted}</span>`)), s;
|
|
5129
5142
|
}
|
|
5130
5143
|
const de = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
5131
5144
|
<rect x="9" y="9" width="13" height="13" rx="2"/>
|
|
@@ -5175,7 +5188,7 @@ function ae(r) {
|
|
|
5175
5188
|
`--cx-on-primary:${r.onPrimary}`
|
|
5176
5189
|
].join(";");
|
|
5177
5190
|
}
|
|
5178
|
-
function
|
|
5191
|
+
function q(r, e) {
|
|
5179
5192
|
return `
|
|
5180
5193
|
<div class="__crossx-row">
|
|
5181
5194
|
<span class="__crossx-row-label">${r}</span>
|
|
@@ -5184,7 +5197,7 @@ function G(r, e) {
|
|
|
5184
5197
|
}
|
|
5185
5198
|
function gn(r, e) {
|
|
5186
5199
|
const s = e, t = Ke(), n = r.to ? `<span class="__crossx-addr-text">${Y(r.to)}</span>
|
|
5187
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5200
|
+
<button class="__crossx-copy-btn" data-copy="${M(r.to)}" title="Copy address">${de}</button>` : "<span>—</span>", o = Es(r), i = r.data && r.data !== "0x" ? r.data : "0x", a = document.createElement("div");
|
|
5188
5201
|
return a.id = te, a.innerHTML = `
|
|
5189
5202
|
<div class="__crossx-card __crossx-card--migration __crossx-card--sign-tx" style="${ae(s)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
|
|
5190
5203
|
<div class="__crossx-header">
|
|
@@ -5196,7 +5209,7 @@ function gn(r, e) {
|
|
|
5196
5209
|
<div class="__crossx-body-cols">
|
|
5197
5210
|
<div class="__crossx-col-left">
|
|
5198
5211
|
<p class="__crossx-sig-subtitle">
|
|
5199
|
-
<span class="__crossx-sig-origin">${
|
|
5212
|
+
<span class="__crossx-sig-origin">${M(t)} </span>is requesting a Signature
|
|
5200
5213
|
</p>
|
|
5201
5214
|
<div class="__crossx-addr-pill">
|
|
5202
5215
|
${_t}
|
|
@@ -5205,12 +5218,12 @@ function gn(r, e) {
|
|
|
5205
5218
|
<p class="__crossx-warning">After you sign, changes or cancellations are not possible.</p>
|
|
5206
5219
|
<hr class="__crossx-divider">
|
|
5207
5220
|
<div class="__crossx-rows">
|
|
5208
|
-
${
|
|
5209
|
-
${
|
|
5221
|
+
${q("To", n)}
|
|
5222
|
+
${q("Network", `<span>${Ss(r.chainId)}</span>`)}
|
|
5210
5223
|
${o}
|
|
5211
5224
|
</div>
|
|
5212
5225
|
</div>
|
|
5213
|
-
<pre class="__crossx-raw-tx">${
|
|
5226
|
+
<pre class="__crossx-raw-tx">${M(i)}</pre>
|
|
5214
5227
|
</div>
|
|
5215
5228
|
<div class="__crossx-btn-row">
|
|
5216
5229
|
<button class="__crossx-cancel-btn" id="__crossx-cancel-btn">Cancel</button>
|
|
@@ -5222,7 +5235,7 @@ function gn(r, e) {
|
|
|
5222
5235
|
}
|
|
5223
5236
|
function _n(r, e) {
|
|
5224
5237
|
const s = e, t = r.nativeSymbol ?? "ETH", n = r.nativeDecimals ?? 18, o = Ke(), i = r.to ? `<span class="__crossx-addr-text">${Y(r.to)}</span>
|
|
5225
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5238
|
+
<button class="__crossx-copy-btn" data-copy="${M(r.to)}" title="Copy address">${de}</button>` : "<span>—</span>", a = Es(r), l = ln(r.value, t, n) ?? "—", d = document.createElement("div");
|
|
5226
5239
|
return d.id = te, d.innerHTML = `
|
|
5227
5240
|
<div class="__crossx-card __crossx-card--migration __crossx-card--send-tx" style="${ae(s)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
|
|
5228
5241
|
<div class="__crossx-header">
|
|
@@ -5232,12 +5245,12 @@ function _n(r, e) {
|
|
|
5232
5245
|
<hr class="__crossx-divider">
|
|
5233
5246
|
<div class="__crossx-body">
|
|
5234
5247
|
<p class="__crossx-tx-subtitle">
|
|
5235
|
-
<span class="__crossx-sig-origin">${
|
|
5248
|
+
<span class="__crossx-sig-origin">${M(o)}</span> wants your permission to approve the following transaction.
|
|
5236
5249
|
</p>
|
|
5237
5250
|
<div class="__crossx-body-cols">
|
|
5238
5251
|
<div class="__crossx-rows">
|
|
5239
|
-
${
|
|
5240
|
-
${
|
|
5252
|
+
${q("To", i)}
|
|
5253
|
+
${q("Network", `<span>${Ss(r.chainId)}</span>`)}
|
|
5241
5254
|
${a}
|
|
5242
5255
|
</div>
|
|
5243
5256
|
<div class="__crossx-pill">
|
|
@@ -5258,31 +5271,31 @@ function Ke() {
|
|
|
5258
5271
|
return "This site";
|
|
5259
5272
|
}
|
|
5260
5273
|
}
|
|
5261
|
-
function
|
|
5274
|
+
function M(r) {
|
|
5262
5275
|
return r.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
5263
5276
|
}
|
|
5264
5277
|
function xn(r) {
|
|
5265
5278
|
return typeof r == "string" && /^0x[0-9a-fA-F]{40}$/i.test(r);
|
|
5266
5279
|
}
|
|
5267
5280
|
function mn(r) {
|
|
5268
|
-
if (typeof r == "string") return
|
|
5281
|
+
if (typeof r == "string") return M(r);
|
|
5269
5282
|
if (typeof r == "number" || typeof r == "bigint" || typeof r == "boolean") return String(r);
|
|
5270
5283
|
try {
|
|
5271
|
-
return
|
|
5284
|
+
return M(JSON.stringify(r));
|
|
5272
5285
|
} catch {
|
|
5273
5286
|
return String(r);
|
|
5274
5287
|
}
|
|
5275
5288
|
}
|
|
5276
5289
|
function wn(r, e) {
|
|
5277
|
-
const s =
|
|
5290
|
+
const s = q(
|
|
5278
5291
|
"From",
|
|
5279
5292
|
`<span class="__crossx-addr-text">${Y(r.from)}</span>
|
|
5280
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5281
|
-
), t = r.to ?
|
|
5282
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5283
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5293
|
+
<button class="__crossx-copy-btn" data-copy="${M(r.from)}" title="Copy address">${de}</button>`
|
|
5294
|
+
), t = r.to ? q("To", `<span class="__crossx-addr-text">${Y(r.to)}</span>
|
|
5295
|
+
<button class="__crossx-copy-btn" data-copy="${M(r.to)}" title="Copy address">${de}</button>`) : "", n = r.amount ? q("Transfer", `<span>${M(r.amount)}</span>`) : "", o = r.fees ? q("Tx Fee", `<span>${M(r.fees)}</span>`) : "", i = r.txHash ? q("Tx Hash", `<span class="__crossx-addr-text">${Y(r.txHash)}</span>
|
|
5296
|
+
<button class="__crossx-copy-btn" data-copy="${M(r.txHash)}" title="Copy hash">${de}</button>`) : "", a = r.total ? `<div class="__crossx-total-pill">
|
|
5284
5297
|
<span class="__crossx-total-label">Total<br>(including fees)</span>
|
|
5285
|
-
<span class="__crossx-total-amount">${
|
|
5298
|
+
<span class="__crossx-total-amount">${M(r.total)}</span>
|
|
5286
5299
|
</div>` : "", c = document.createElement("div");
|
|
5287
5300
|
return c.id = te, c.innerHTML = `
|
|
5288
5301
|
<div class="__crossx-card __crossx-card--migration" style="${ae(e)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
|
|
@@ -5325,44 +5338,44 @@ function yn(r, e) {
|
|
|
5325
5338
|
function bn(r, e, s) {
|
|
5326
5339
|
const t = e.status !== "reverted" && e.status !== "timeout", n = e.status === "timeout", o = r.querySelector("#__crossx-ttl"), i = r.querySelector(".__crossx-header");
|
|
5327
5340
|
if (o) {
|
|
5328
|
-
const
|
|
5329
|
-
|
|
5341
|
+
const m = n ? pn : t ? "" : fn, A = n ? "Transaction timeout" : t ? "Transaction complete" : "Transaction failed";
|
|
5342
|
+
m ? (o.style.display = "flex", o.style.alignItems = "center", o.style.gap = "8px", o.innerHTML = `${m}<span>${A}</span>`) : o.textContent = A;
|
|
5330
5343
|
}
|
|
5331
5344
|
if (i && !r.querySelector("#__crossx-close-btn")) {
|
|
5332
|
-
const
|
|
5333
|
-
|
|
5345
|
+
const m = document.createElement("button");
|
|
5346
|
+
m.className = "__crossx-close", m.id = "__crossx-close-btn", m.setAttribute("aria-label", "Close"), m.innerHTML = ie, i.appendChild(m);
|
|
5334
5347
|
}
|
|
5335
5348
|
const a = r.querySelector("#__crossx-progress-body");
|
|
5336
5349
|
if (!a) return;
|
|
5337
|
-
const c = e.from ?
|
|
5338
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5339
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5340
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5350
|
+
const c = e.from ? q("From", `<span class="__crossx-addr-text">${Y(e.from)}</span>
|
|
5351
|
+
<button class="__crossx-copy-btn" data-copy="${M(e.from)}" title="Copy address">${de}</button>`) : "", l = e.to ? q("To", `<span class="__crossx-addr-text">${Y(e.to)}</span>
|
|
5352
|
+
<button class="__crossx-copy-btn" data-copy="${M(e.to)}" title="Copy address">${de}</button>`) : "", d = e.amount ? q("Transfer", `<span>${M(e.amount)}</span>`) : "", f = e.fees ? q("Tx Fee", `<span>${M(e.fees)}</span>`) : "", w = e.txHash ? q("Tx Hash", `<span class="__crossx-addr-text">${Y(e.txHash)}</span>
|
|
5353
|
+
<button class="__crossx-copy-btn" data-copy="${M(e.txHash)}" title="Copy hash">${de}</button>`) : "", _ = e.total ? `<div class="__crossx-total-pill">
|
|
5341
5354
|
<span class="__crossx-total-label">Total<br>(including fees)</span>
|
|
5342
|
-
<span class="__crossx-total-amount">${
|
|
5355
|
+
<span class="__crossx-total-amount">${M(e.total)}</span>
|
|
5343
5356
|
</div>` : "";
|
|
5344
5357
|
a.innerHTML = `
|
|
5345
5358
|
<div class="__crossx-rows">
|
|
5346
5359
|
${c}
|
|
5347
5360
|
${l}
|
|
5348
5361
|
${d}
|
|
5349
|
-
${
|
|
5350
|
-
${
|
|
5362
|
+
${f}
|
|
5363
|
+
${w}
|
|
5351
5364
|
</div>
|
|
5352
|
-
${
|
|
5365
|
+
${_}
|
|
5353
5366
|
<button class="__crossx-approve-btn" id="__crossx-done-btn">${t ? "All Done" : "Done"}</button>
|
|
5354
|
-
`, a.querySelectorAll(".__crossx-copy-btn").forEach((
|
|
5355
|
-
|
|
5356
|
-
var
|
|
5357
|
-
|
|
5358
|
-
const
|
|
5359
|
-
|
|
5367
|
+
`, a.querySelectorAll(".__crossx-copy-btn").forEach((m) => {
|
|
5368
|
+
m.addEventListener("click", (A) => {
|
|
5369
|
+
var I;
|
|
5370
|
+
A.stopPropagation();
|
|
5371
|
+
const y = m.dataset.copy;
|
|
5372
|
+
y && ((I = navigator.clipboard) == null || I.writeText(y).catch(() => {
|
|
5360
5373
|
}));
|
|
5361
5374
|
});
|
|
5362
5375
|
});
|
|
5363
5376
|
}
|
|
5364
5377
|
function vn(r, e) {
|
|
5365
|
-
const s = e, t = Ke(), n =
|
|
5378
|
+
const s = e, t = Ke(), n = M(r.message), o = document.createElement("div");
|
|
5366
5379
|
return o.id = te, o.innerHTML = `
|
|
5367
5380
|
<div class="__crossx-card __crossx-card--migration __crossx-card--sign-msg" style="${ae(s)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
|
|
5368
5381
|
<div class="__crossx-header">
|
|
@@ -5374,7 +5387,7 @@ function vn(r, e) {
|
|
|
5374
5387
|
<div class="__crossx-body-cols">
|
|
5375
5388
|
<div class="__crossx-col-left">
|
|
5376
5389
|
<p class="__crossx-sig-subtitle">
|
|
5377
|
-
<span class="__crossx-sig-origin">${
|
|
5390
|
+
<span class="__crossx-sig-origin">${M(t)} </span>is requesting a Signature
|
|
5378
5391
|
</p>
|
|
5379
5392
|
<div class="__crossx-addr-pill">
|
|
5380
5393
|
${_t}
|
|
@@ -5406,15 +5419,15 @@ function Sn(r, e) {
|
|
|
5406
5419
|
let a = `
|
|
5407
5420
|
<div class="__crossx-td-row">
|
|
5408
5421
|
<span class="__crossx-td-label">Primary Type</span>
|
|
5409
|
-
<span class="__crossx-td-value">${
|
|
5422
|
+
<span class="__crossx-td-value">${M(o)}</span>
|
|
5410
5423
|
</div>`;
|
|
5411
5424
|
for (const [l, d] of Object.entries(i)) {
|
|
5412
|
-
const
|
|
5413
|
-
<button class="__crossx-copy-btn" data-copy="${
|
|
5425
|
+
const f = mn(d), _ = xn(d) ? `<span class="__crossx-addr-text">${Y(d)}</span>
|
|
5426
|
+
<button class="__crossx-copy-btn" data-copy="${M(String(d))}" title="Copy">${de}</button>` : `<span>${f}</span>`;
|
|
5414
5427
|
a += `
|
|
5415
5428
|
<div class="__crossx-td-row">
|
|
5416
|
-
<span class="__crossx-td-label">${
|
|
5417
|
-
<div class="__crossx-td-value">${
|
|
5429
|
+
<span class="__crossx-td-label">${M(l)}</span>
|
|
5430
|
+
<div class="__crossx-td-value">${_}</div>
|
|
5418
5431
|
</div>`;
|
|
5419
5432
|
}
|
|
5420
5433
|
const c = document.createElement("div");
|
|
@@ -5429,7 +5442,7 @@ function Sn(r, e) {
|
|
|
5429
5442
|
<div class="__crossx-body-cols">
|
|
5430
5443
|
<div class="__crossx-col-left">
|
|
5431
5444
|
<p class="__crossx-sig-subtitle">
|
|
5432
|
-
<span class="__crossx-sig-origin">${
|
|
5445
|
+
<span class="__crossx-sig-origin">${M(t)} </span>is requesting a Signature
|
|
5433
5446
|
</p>
|
|
5434
5447
|
<div class="__crossx-addr-pill">
|
|
5435
5448
|
${_t}
|
|
@@ -5452,13 +5465,14 @@ const En = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="
|
|
|
5452
5465
|
<line x1="12" y1="5" x2="12" y2="19"/>
|
|
5453
5466
|
<line x1="5" y1="12" x2="19" y2="12"/>
|
|
5454
5467
|
</svg>`;
|
|
5455
|
-
function In(r, e) {
|
|
5456
|
-
const s = r.map(
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5468
|
+
function In(r, e, s) {
|
|
5469
|
+
const t = s == null ? void 0 : s.toLowerCase(), n = r.map((i) => {
|
|
5470
|
+
const a = t && i.address.toLowerCase() === t;
|
|
5471
|
+
return `<button class="__crossx-wallet-item" data-wallet-index="${i.index}" data-wallet-address="${M(i.address)}">
|
|
5472
|
+
<span class="__crossx-wallet-addr">${Y(i.address)}</span>${a ? '<span class="__crossx-wallet-selected">selected</span>' : ""}
|
|
5473
|
+
</button>`;
|
|
5474
|
+
}).join(""), o = document.createElement("div");
|
|
5475
|
+
return o.id = te, o.innerHTML = `
|
|
5462
5476
|
<div class="__crossx-card __crossx-card--migration __crossx-card--wallet-selector" style="${ae(e)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
|
|
5463
5477
|
<div class="__crossx-header">
|
|
5464
5478
|
<div style="display:flex;flex-direction:column;gap:4px;padding-right:36px;">
|
|
@@ -5479,7 +5493,7 @@ function In(r, e) {
|
|
|
5479
5493
|
<hr class="__crossx-divider __crossx-divider--cols">
|
|
5480
5494
|
<div class="__crossx-col-right-ws">
|
|
5481
5495
|
<div class="__crossx-wallet-list" id="__crossx-wallet-list">
|
|
5482
|
-
${
|
|
5496
|
+
${n}
|
|
5483
5497
|
</div>
|
|
5484
5498
|
<button class="__crossx-wallet-add" id="__crossx-add-wallet-btn" type="button">
|
|
5485
5499
|
<span class="__crossx-wallet-add-icon">${En}</span>
|
|
@@ -5489,7 +5503,7 @@ function In(r, e) {
|
|
|
5489
5503
|
</div>
|
|
5490
5504
|
</div>
|
|
5491
5505
|
</div>
|
|
5492
|
-
`,
|
|
5506
|
+
`, o;
|
|
5493
5507
|
}
|
|
5494
5508
|
const Tn = `<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5495
5509
|
<path d="M26.693 21.193c-.028-3.168 2.587-4.712 2.706-4.786-1.477-2.16-3.77-2.454-4.58-2.484-1.944-.197-3.804 1.148-4.793 1.148-.992 0-2.52-1.12-4.147-1.09-2.13.032-4.1 1.239-5.198 3.133-2.222 3.855-.569 9.562 1.593 12.69 1.061 1.535 2.318 3.258 3.975 3.196 1.6-.064 2.2-1.03 4.133-1.03 1.928 0 2.48 1.03 4.172.997 1.72-.03 2.806-1.56 3.862-3.1 1.211-1.779 1.713-3.495 1.74-3.583-.037-.017-3.427-1.316-3.463-5.09z" fill="currentColor"/>
|
|
@@ -5595,8 +5609,8 @@ function kn(r, e, s) {
|
|
|
5595
5609
|
a.preventDefault();
|
|
5596
5610
|
const c = (((d = a.clipboardData) == null ? void 0 : d.getData("text")) ?? "").replace(/\D/g, "").slice(0, 4);
|
|
5597
5611
|
if (!c) return;
|
|
5598
|
-
c.split("").forEach((
|
|
5599
|
-
t[
|
|
5612
|
+
c.split("").forEach((f, w) => {
|
|
5613
|
+
t[w] && (t[w].value = f);
|
|
5600
5614
|
});
|
|
5601
5615
|
const l = Math.min(c.length, 3);
|
|
5602
5616
|
t[l].focus(), c.length === 4 && setTimeout(() => e(c), 200);
|
|
@@ -5618,50 +5632,50 @@ class Nn {
|
|
|
5618
5632
|
* 지갑 목록을 표시하고, 사용자가 선택하거나 새 지갑을 추가할 수 있습니다.
|
|
5619
5633
|
* 모달은 지갑을 선택하거나 X를 누를 때까지 유지됩니다.
|
|
5620
5634
|
*/
|
|
5621
|
-
showWalletSelector(e, s) {
|
|
5622
|
-
return new Promise((
|
|
5623
|
-
var
|
|
5635
|
+
showWalletSelector(e, s, t) {
|
|
5636
|
+
return new Promise((n) => {
|
|
5637
|
+
var A;
|
|
5624
5638
|
me();
|
|
5625
|
-
const
|
|
5626
|
-
document.body.style.overflow = "hidden", document.body.appendChild(
|
|
5627
|
-
let
|
|
5628
|
-
const
|
|
5629
|
-
|
|
5630
|
-
},
|
|
5631
|
-
|
|
5632
|
-
},
|
|
5633
|
-
|
|
5639
|
+
const o = [...e], i = In(o, this.tokens, t), a = document.body.style.overflow;
|
|
5640
|
+
document.body.style.overflow = "hidden", document.body.appendChild(i);
|
|
5641
|
+
let c = !1;
|
|
5642
|
+
const l = () => {
|
|
5643
|
+
c || (c = !0, i.remove(), document.body.style.overflow = a);
|
|
5644
|
+
}, d = (y) => {
|
|
5645
|
+
l(), n(y);
|
|
5646
|
+
}, f = () => {
|
|
5647
|
+
l(), n(null);
|
|
5634
5648
|
};
|
|
5635
5649
|
(() => {
|
|
5636
|
-
|
|
5637
|
-
|
|
5638
|
-
const
|
|
5639
|
-
|
|
5650
|
+
i.querySelectorAll(".__crossx-wallet-item").forEach((y) => {
|
|
5651
|
+
y.addEventListener("click", () => {
|
|
5652
|
+
const I = y.dataset.walletAddress ?? "", L = parseInt(y.dataset.walletIndex ?? "0", 10);
|
|
5653
|
+
d({ address: I, index: L });
|
|
5640
5654
|
});
|
|
5641
5655
|
});
|
|
5642
5656
|
})();
|
|
5643
|
-
const
|
|
5644
|
-
|
|
5645
|
-
|
|
5657
|
+
const _ = i.querySelector("#__crossx-add-wallet-btn");
|
|
5658
|
+
_ && _.addEventListener("click", async () => {
|
|
5659
|
+
_.disabled = !0;
|
|
5646
5660
|
try {
|
|
5647
|
-
const
|
|
5648
|
-
|
|
5649
|
-
const
|
|
5650
|
-
if (
|
|
5651
|
-
const
|
|
5652
|
-
|
|
5661
|
+
const y = await s();
|
|
5662
|
+
o.push(y);
|
|
5663
|
+
const I = i.querySelector("#__crossx-wallet-list");
|
|
5664
|
+
if (I) {
|
|
5665
|
+
const L = document.createElement("button");
|
|
5666
|
+
L.className = "__crossx-wallet-item", L.dataset.walletIndex = String(y.index), L.dataset.walletAddress = y.address, L.innerHTML = `<span class="__crossx-wallet-addr">${Y(y.address)}</span>`, L.addEventListener("click", () => d(y)), I.appendChild(L), L.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
5653
5667
|
}
|
|
5654
5668
|
} catch {
|
|
5655
5669
|
} finally {
|
|
5656
|
-
|
|
5670
|
+
_.disabled = !1;
|
|
5657
5671
|
}
|
|
5658
|
-
}), (
|
|
5659
|
-
|
|
5672
|
+
}), (A = i.querySelector("#__crossx-close-btn")) == null || A.addEventListener("click", f), i.addEventListener("click", (y) => {
|
|
5673
|
+
y.target === i && f();
|
|
5660
5674
|
});
|
|
5661
|
-
const
|
|
5662
|
-
|
|
5675
|
+
const m = (y) => {
|
|
5676
|
+
y.key === "Escape" && (document.removeEventListener("keydown", m), f());
|
|
5663
5677
|
};
|
|
5664
|
-
document.addEventListener("keydown",
|
|
5678
|
+
document.addEventListener("keydown", m);
|
|
5665
5679
|
});
|
|
5666
5680
|
}
|
|
5667
5681
|
/**
|
|
@@ -5683,7 +5697,7 @@ class Nn {
|
|
|
5683
5697
|
(a = s.querySelector("#__crossx-apple-btn")) == null || a.addEventListener("click", () => n("apple")), (c = s.querySelector("#__crossx-google-btn")) == null || c.addEventListener("click", () => n("google")), (l = s.querySelector("#__crossx-close-btn")) == null || l.addEventListener("click", o), s.addEventListener("click", (d) => {
|
|
5684
5698
|
d.target === s && o();
|
|
5685
5699
|
}), s.querySelectorAll(".__crossx-login-terms-link").forEach((d) => {
|
|
5686
|
-
d.addEventListener("click", (
|
|
5700
|
+
d.addEventListener("click", (f) => f.stopPropagation());
|
|
5687
5701
|
});
|
|
5688
5702
|
const i = (d) => {
|
|
5689
5703
|
d.key === "Escape" && (document.removeEventListener("keydown", i), o());
|
|
@@ -5751,10 +5765,10 @@ class Nn {
|
|
|
5751
5765
|
};
|
|
5752
5766
|
(a = t.querySelector("#__crossx-done-btn")) == null || a.addEventListener("click", o), (c = t.querySelector("#__crossx-close-btn")) == null || c.addEventListener("click", o), t.querySelectorAll(".__crossx-copy-btn").forEach((l) => {
|
|
5753
5767
|
l.addEventListener("click", (d) => {
|
|
5754
|
-
var
|
|
5768
|
+
var w;
|
|
5755
5769
|
d.stopPropagation();
|
|
5756
|
-
const
|
|
5757
|
-
|
|
5770
|
+
const f = l.dataset.copy;
|
|
5771
|
+
f && ((w = navigator.clipboard) == null || w.writeText(f).catch(() => {
|
|
5758
5772
|
}));
|
|
5759
5773
|
});
|
|
5760
5774
|
}), t.addEventListener("click", (l) => {
|
|
@@ -5780,12 +5794,12 @@ class Nn {
|
|
|
5780
5794
|
const a = () => {
|
|
5781
5795
|
i || (i = !0, o(), t());
|
|
5782
5796
|
}, c = () => {
|
|
5783
|
-
var d,
|
|
5784
|
-
(d = n.querySelector("#__crossx-done-btn")) == null || d.addEventListener("click", a), (
|
|
5785
|
-
|
|
5797
|
+
var d, f;
|
|
5798
|
+
(d = n.querySelector("#__crossx-done-btn")) == null || d.addEventListener("click", a), (f = n.querySelector("#__crossx-close-btn")) == null || f.addEventListener("click", a), n.addEventListener("click", (w) => {
|
|
5799
|
+
w.target === n && a();
|
|
5786
5800
|
});
|
|
5787
|
-
const l = (
|
|
5788
|
-
|
|
5801
|
+
const l = (w) => {
|
|
5802
|
+
w.key === "Escape" && (document.removeEventListener("keydown", l), a());
|
|
5789
5803
|
};
|
|
5790
5804
|
document.addEventListener("keydown", l);
|
|
5791
5805
|
};
|
|
@@ -5805,19 +5819,19 @@ class Nn {
|
|
|
5805
5819
|
}, i = () => {
|
|
5806
5820
|
n(), s(!1);
|
|
5807
5821
|
};
|
|
5808
|
-
(c = t.querySelector("#__crossx-confirm-btn")) == null || c.addEventListener("click", o), (l = t.querySelector("#__crossx-cancel-btn")) == null || l.addEventListener("click", i), (d = t.querySelector("#__crossx-close-btn")) == null || d.addEventListener("click", i), t.querySelectorAll(".__crossx-copy-btn").forEach((
|
|
5809
|
-
|
|
5810
|
-
var
|
|
5811
|
-
|
|
5812
|
-
const
|
|
5813
|
-
|
|
5822
|
+
(c = t.querySelector("#__crossx-confirm-btn")) == null || c.addEventListener("click", o), (l = t.querySelector("#__crossx-cancel-btn")) == null || l.addEventListener("click", i), (d = t.querySelector("#__crossx-close-btn")) == null || d.addEventListener("click", i), t.querySelectorAll(".__crossx-copy-btn").forEach((f) => {
|
|
5823
|
+
f.addEventListener("click", (w) => {
|
|
5824
|
+
var m;
|
|
5825
|
+
w.stopPropagation();
|
|
5826
|
+
const _ = f.dataset.copy;
|
|
5827
|
+
_ && ((m = navigator.clipboard) == null || m.writeText(_).catch(() => {
|
|
5814
5828
|
}));
|
|
5815
5829
|
});
|
|
5816
|
-
}), t.addEventListener("click", (
|
|
5817
|
-
|
|
5830
|
+
}), t.addEventListener("click", (f) => {
|
|
5831
|
+
f.target === t && i();
|
|
5818
5832
|
});
|
|
5819
|
-
const a = (
|
|
5820
|
-
|
|
5833
|
+
const a = (f) => {
|
|
5834
|
+
f.key === "Escape" && (document.removeEventListener("keydown", a), i());
|
|
5821
5835
|
};
|
|
5822
5836
|
document.addEventListener("keydown", a);
|
|
5823
5837
|
});
|
|
@@ -5852,13 +5866,13 @@ function Mn(r) {
|
|
|
5852
5866
|
projectId: r.projectId
|
|
5853
5867
|
}, o = s.authMode !== "cookie" && At.isAvailable() ? new At() : new Ks(), i = new tn(), a = new nn(), c = new gt(), l = new Pn();
|
|
5854
5868
|
let d;
|
|
5855
|
-
r.useMockWallet ? (
|
|
5869
|
+
r.useMockWallet ? (p.log("[CROSSx] Mock Wallet Provider 사용"), d = new on(o)) : (p.log("[CROSSx] Remote Wallet Provider 사용"), d = new qe(
|
|
5856
5870
|
t,
|
|
5857
5871
|
o,
|
|
5858
5872
|
a,
|
|
5859
5873
|
l
|
|
5860
5874
|
));
|
|
5861
|
-
const
|
|
5875
|
+
const f = new Ce(t, a), w = new Nn(r.theme ?? "light", r.themeTokens);
|
|
5862
5876
|
return new st(
|
|
5863
5877
|
s,
|
|
5864
5878
|
t,
|
|
@@ -5868,12 +5882,12 @@ function Mn(r) {
|
|
|
5868
5882
|
c,
|
|
5869
5883
|
d,
|
|
5870
5884
|
l,
|
|
5871
|
-
|
|
5872
|
-
|
|
5885
|
+
w,
|
|
5886
|
+
f
|
|
5873
5887
|
);
|
|
5874
5888
|
}
|
|
5875
5889
|
export {
|
|
5876
|
-
|
|
5890
|
+
x as CROSSxError,
|
|
5877
5891
|
Cs as CROSSxEthereumProvider,
|
|
5878
5892
|
st as CROSSxSDK,
|
|
5879
5893
|
$n as ChainId,
|