@nexus-cross/crossx-sdk-core 1.0.1 → 1.0.2
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.map +1 -1
- package/dist/core/types/index.d.ts +12 -0
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/index.cjs +46 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +582 -525
- package/dist/sdk/CROSSxSDK.d.ts +19 -1
- package/dist/sdk/CROSSxSDK.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,9 +3,9 @@ var Is = (r, e, s) => e in r ? Ts(r, e, { enumerable: !0, configurable: !0, writ
|
|
|
3
3
|
var v = (r, e, s) => Is(r, typeof e != "symbol" ? e + "" : e, s);
|
|
4
4
|
import { decodeJwt as As } from "jose";
|
|
5
5
|
var p = /* @__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))(p || {});
|
|
6
|
-
class
|
|
6
|
+
class _ 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, _.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 _(
|
|
110
110
|
p.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 _(
|
|
118
118
|
p.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 f = {
|
|
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 _(
|
|
206
206
|
p.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 _(
|
|
214
214
|
p.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: g } = this.config, m = `${d}${l}`;
|
|
227
|
+
f.log(`[CROSSx] OAuth 팝업 열기 (${c || "일반"} 로그인):`, m);
|
|
228
|
+
const x = await this.oauth.openAuth({
|
|
229
|
+
authUrl: m,
|
|
230
230
|
expectedOrigin: new URL(d).origin
|
|
231
231
|
});
|
|
232
|
-
|
|
233
|
-
const { accessToken:
|
|
234
|
-
let
|
|
232
|
+
f.log("[CROSSx] OAuth Firebase 토큰 받음 (length:", x.length, ")");
|
|
233
|
+
const { accessToken: w, refreshToken: b } = await this.exchangeFirebaseToken(x, g);
|
|
234
|
+
let S, E;
|
|
235
235
|
try {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
const D = ((o =
|
|
239
|
-
|
|
236
|
+
const B = this.crypto.decodeJWT(x);
|
|
237
|
+
E = (n = B.firebase) == null ? void 0 : n.sign_in_provider;
|
|
238
|
+
const D = ((o = B.firebase) == null ? void 0 : o.identities) ?? {};
|
|
239
|
+
E === "google.com" ? S = (i = D["google.com"]) == null ? void 0 : i[0] : E === "apple.com" && (S = (a = D["apple.com"]) == null ? void 0 : a[0]), f.log("[CROSSx] OAuth provider sub 추출 — provider:", E, "hasProviderSub:", !!S);
|
|
240
240
|
} catch {
|
|
241
|
-
|
|
241
|
+
f.warn("[CROSSx] firebaseToken에서 providerSub 추출 실패");
|
|
242
242
|
}
|
|
243
|
-
if (
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const D = await this.crypto.verifyJWT(
|
|
243
|
+
if (w) {
|
|
244
|
+
const B = this.crypto.decodeJWT(w);
|
|
245
|
+
f.log("[CROSSx] access_token 디코딩 — sub:", B.sub, "exp:", B.exp);
|
|
246
|
+
const D = await this.crypto.verifyJWT(w);
|
|
247
247
|
if (t = D.signatureVerified ?? !1, !D.valid)
|
|
248
|
-
throw
|
|
249
|
-
const
|
|
250
|
-
s = {
|
|
251
|
-
id: B.sub,
|
|
252
|
-
email: B.email,
|
|
253
|
-
signInProvider: A,
|
|
254
|
-
providerSub: b
|
|
255
|
-
}, this.tokenStore.set(_), this.useCookieAuth || (await this.storage.set(Ye, _), T && await this.storage.set(Ne, T));
|
|
256
|
-
} else {
|
|
257
|
-
const M = this.crypto.decodeJWT(m);
|
|
248
|
+
throw f.error("[CROSSx] access_token 검증 실패"), new Error("Invalid access token");
|
|
249
|
+
const M = D.payload;
|
|
258
250
|
s = {
|
|
259
251
|
id: M.sub,
|
|
260
252
|
email: M.email,
|
|
261
|
-
signInProvider:
|
|
262
|
-
providerSub:
|
|
263
|
-
},
|
|
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);
|
|
258
|
+
s = {
|
|
259
|
+
id: B.sub,
|
|
260
|
+
email: B.email,
|
|
261
|
+
signInProvider: E,
|
|
262
|
+
providerSub: S
|
|
263
|
+
}, f.log("[CROSSx] Cookie 모드 — Firebase 토큰에서 사용자 정보 추출 — id:", s.id);
|
|
264
264
|
}
|
|
265
|
-
|
|
265
|
+
f.log("[CROSSx] 사용자 정보 — id:", s.id);
|
|
266
266
|
const q = this.useCookieAuth ? { id: s.id, signInProvider: s.signInProvider, providerSub: s.providerSub } : s;
|
|
267
|
-
await this.storage.set(Pe, q),
|
|
267
|
+
await this.storage.set(Pe, q), f.log("[CROSSx] 사용자 정보 저장 완료 (authMode:", this.useCookieAuth ? "cookie" : "token", ")");
|
|
268
268
|
} catch (c) {
|
|
269
|
-
return
|
|
269
|
+
return f.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 f.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
|
+
f.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
|
+
f.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 f.log("[CROSSx] Cookie 모드 — 로그인 성공 (JWT는 HttpOnly 쿠키)"), {};
|
|
297
297
|
if (!a)
|
|
298
|
-
throw new
|
|
298
|
+
throw new _(
|
|
299
299
|
p.AUTH_FAILED,
|
|
300
300
|
"access_token not found in exchange response"
|
|
301
301
|
);
|
|
302
|
-
|
|
302
|
+
f.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 f.log("[CROSSx] restoreSession — 메모리 토큰 유효, 세션 복원"), this.loadWallet(n, t.signatureVerified);
|
|
365
365
|
}
|
|
366
366
|
this.tokenStore.clear();
|
|
367
367
|
}
|
|
368
368
|
if (this.useCookieAuth) {
|
|
369
|
-
|
|
369
|
+
f.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 (f.log(
|
|
375
375
|
"[CROSSx] restoreSession — access_token:",
|
|
376
376
|
t ? "있음" : "없음",
|
|
377
377
|
"refresh_token:",
|
|
378
378
|
n ? "있음" : "없음"
|
|
379
379
|
), !n)
|
|
380
|
-
return
|
|
380
|
+
return f.log("[CROSSx] restoreSession — refresh_token 없음, 세션 복원 생략"), null;
|
|
381
381
|
t && this.tokenStore.set(t);
|
|
382
382
|
const o = await this.silentRefresh(n);
|
|
383
|
-
|
|
383
|
+
f.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 (f.log("[CROSSx] restoreSession — userInfo 조회:", s ? `있음 (id: ${s.id})` : "없음"), !s)
|
|
387
387
|
return null;
|
|
388
|
-
|
|
388
|
+
f.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 f.warn("[CROSSx] restoreSession — 지갑 로드 실패 (세션은 유지):", t), { success: !0, user: s, tokenSignatureVerified: !1 };
|
|
393
393
|
}
|
|
394
394
|
} catch (e) {
|
|
395
|
-
return
|
|
395
|
+
return f.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
|
+
f.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
|
+
f.log("[CROSSx] silentRefresh 성공 (cookie 갱신)");
|
|
427
427
|
return;
|
|
428
428
|
}
|
|
429
429
|
if (!c)
|
|
430
|
-
throw new
|
|
430
|
+
throw new _(p.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 f.log("[CROSSx] silentRefresh 성공"), c;
|
|
437
437
|
}
|
|
438
438
|
async loadWallet(e, s) {
|
|
439
439
|
let t, n = !1;
|
|
440
440
|
try {
|
|
441
|
-
|
|
441
|
+
f.log("[CROSSx][Migration Phase 2] POST /mnemonic/create 호출 — userId:", e.id), t = (await this.walletProvider.getOrCreateWallet(e.id)).address, f.log("[CROSSx][Migration Phase 2] 지갑 로드 완료 (기존 백업 없음) — address:", t);
|
|
442
442
|
} catch (o) {
|
|
443
|
-
if (o instanceof
|
|
444
|
-
|
|
443
|
+
if (o instanceof _ && o.code === p.MIGRATION_BACKUP_EXISTS)
|
|
444
|
+
f.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 _ && (o.code === p.PROJECT_NOT_REGISTERED || o.code === p.PROJECT_ID_MISSING || o.code === p.ORIGIN_NOT_ALLOWED))
|
|
447
|
+
throw f.error("[CROSSx][Migration Phase 2] 프로젝트 설정 에러:", o.message), o;
|
|
448
|
+
f.warn("[CROSSx][Migration Phase 2] 지갑 로드 실패 (로그인은 유지):", o);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
return
|
|
451
|
+
return f.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,18 +466,18 @@ class $s {
|
|
|
466
466
|
}
|
|
467
467
|
async execute(e, s) {
|
|
468
468
|
if (!this.walletProvider.migrateWallet)
|
|
469
|
-
throw new
|
|
469
|
+
throw new _(
|
|
470
470
|
p.NOT_IMPLEMENTED,
|
|
471
471
|
"Migration is not supported in the current environment"
|
|
472
472
|
);
|
|
473
|
-
|
|
473
|
+
f.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 f.log("[CROSSx][Migration Phase 5] MigrateWalletUseCase 완료 — address:", t.address), {
|
|
476
476
|
address: t.address
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
|
-
class
|
|
480
|
+
class Ms {
|
|
481
481
|
constructor(e, s) {
|
|
482
482
|
this.chainRegistry = e, this.transport = s;
|
|
483
483
|
}
|
|
@@ -502,14 +502,14 @@ class Bs {
|
|
|
502
502
|
body: o
|
|
503
503
|
})).data;
|
|
504
504
|
if (a != null && a.error)
|
|
505
|
-
throw new
|
|
505
|
+
throw new _(
|
|
506
506
|
p.UNKNOWN_ERROR,
|
|
507
507
|
`RPC error [${e}] (${t}): ${a.error.message} (code: ${a.error.code})`
|
|
508
508
|
);
|
|
509
509
|
return a == null ? void 0 : a.result;
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
-
class
|
|
512
|
+
class Bs {
|
|
513
513
|
constructor() {
|
|
514
514
|
this.listeners = /* @__PURE__ */ new Map();
|
|
515
515
|
}
|
|
@@ -571,9 +571,9 @@ async function Fs() {
|
|
|
571
571
|
}
|
|
572
572
|
return Ue.production;
|
|
573
573
|
}
|
|
574
|
-
const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA00", St = 130, Et = 6, Tt = 18, js = 0, Vs = 30 * 1e3, X = class X extends
|
|
574
|
+
const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA00", St = 130, Et = 6, Tt = 18, js = 0, Vs = 30 * 1e3, X = class X extends Bs {
|
|
575
575
|
constructor(e, s, t, n, o, i, a, c, l, d) {
|
|
576
|
-
super(), this.storage = t, this.crypto = n, this.transport = o, this.oauth = i, this.walletProvider = a, this.tokenStore = c, this.initialized = !1, this.authenticated = !1, this.userId = null, this.address = null, this.userEmail = null, this.loginType = null, this.providerSub = null, this.tokenSignatureVerified = !1, this._config = Object.freeze({ ...e }), this.internalConfig = e, this.adapterConfig = s, e.logger && wt(e.logger), this.confirmation = l, this.chainRegistry = d, this.jsonRpc = new
|
|
576
|
+
super(), this.storage = t, this.crypto = n, this.transport = o, this.oauth = i, this.walletProvider = a, this.tokenStore = c, this.initialized = !1, this.authenticated = !1, this.userId = null, this.address = null, this.userEmail = null, this.loginType = null, this.providerSub = null, this.tokenSignatureVerified = !1, this._config = Object.freeze({ ...e }), this.internalConfig = e, this.adapterConfig = s, e.logger && wt(e.logger), this.confirmation = l, this.chainRegistry = d, this.jsonRpc = new Ms(d, o), this.signInUseCase = new ks(
|
|
577
577
|
this.internalConfig,
|
|
578
578
|
t,
|
|
579
579
|
n,
|
|
@@ -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.2 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 _(p.AUTH_NOT_INITIALIZED, "SDK initialization failed", e);
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
615
|
async signIn(e) {
|
|
@@ -625,15 +625,42 @@ 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 _(p.AUTH_FAILED, "Sign in failed", t);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* 로그인 + 지갑 생성 + 마이그레이션을 단일 호출로 완료합니다.
|
|
633
|
+
*
|
|
634
|
+
* 내부적으로 {@link signIn}을 수행한 뒤, 지갑이 아직 없거나
|
|
635
|
+
* 기존 CROSSx 백업 마이그레이션이 필요한 경우 {@link createWallet}을
|
|
636
|
+
* 자동 호출하여 지갑 생성·마이그레이션까지 완료합니다.
|
|
637
|
+
* 성공 시 사용자의 전체 지갑 주소 목록(`addresses`)도 함께 반환합니다.
|
|
638
|
+
*
|
|
639
|
+
* @param options 로그인 옵션 (provider 지정 가능)
|
|
640
|
+
* @returns `AuthResult` + `addresses` (지갑 주소 목록)
|
|
641
|
+
* @throws 마이그레이션을 사용자가 취소하면 `CROSSxError(MIGRATION_FAILED)`
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* const result = await sdk.signInWithCreate();
|
|
645
|
+
* console.log(result.address); // '0x...'
|
|
646
|
+
* console.log(result.addresses); // [{ address: '0x...', index: 0 }]
|
|
647
|
+
*/
|
|
648
|
+
async signInWithCreate(e) {
|
|
649
|
+
const s = await this.signIn(e);
|
|
650
|
+
if (!s.success) return { ...s, addresses: [] };
|
|
651
|
+
if (s.needsMigration || !s.address) {
|
|
652
|
+
const { address: n } = await this.createWallet(), o = await this.getAddresses();
|
|
653
|
+
return { ...s, address: n, needsMigration: !1, addresses: o };
|
|
654
|
+
}
|
|
655
|
+
const t = await this.getAddresses();
|
|
656
|
+
return { ...s, addresses: t };
|
|
657
|
+
}
|
|
631
658
|
async signOut() {
|
|
632
659
|
this.ensureInitialized();
|
|
633
660
|
try {
|
|
634
661
|
await this.signOutUseCase.execute(), this.clearAuthState();
|
|
635
662
|
} catch (e) {
|
|
636
|
-
throw new
|
|
663
|
+
throw new _(p.UNKNOWN_ERROR, "Sign out failed", e);
|
|
637
664
|
}
|
|
638
665
|
}
|
|
639
666
|
isAuthenticated() {
|
|
@@ -709,12 +736,12 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
709
736
|
*/
|
|
710
737
|
async migrateWallet(e) {
|
|
711
738
|
if (this.ensureAuthenticated(), !this.userId)
|
|
712
|
-
throw new
|
|
739
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
713
740
|
try {
|
|
714
741
|
const s = await this.migrateWalletUseCase.execute(e, this.userId);
|
|
715
|
-
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 }), f.log("[CROSSx] migrateWallet 완료 — address:", s.address), s;
|
|
716
743
|
} catch (s) {
|
|
717
|
-
throw s instanceof
|
|
744
|
+
throw s instanceof _ ? s : new _(
|
|
718
745
|
p.MIGRATION_FAILED,
|
|
719
746
|
"Wallet migration failed",
|
|
720
747
|
s
|
|
@@ -736,7 +763,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
736
763
|
async getAddress(e) {
|
|
737
764
|
if (e !== void 0) {
|
|
738
765
|
if (this.ensureAuthenticated(), !this.userId)
|
|
739
|
-
throw new
|
|
766
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
740
767
|
return { address: (await this.walletProvider.getAddress(this.userId, e)).address, index: e };
|
|
741
768
|
}
|
|
742
769
|
return !this.authenticated || !this.address ? null : { address: this.address, index: 0 };
|
|
@@ -770,7 +797,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
770
797
|
*/
|
|
771
798
|
async selectWallet() {
|
|
772
799
|
if (this.ensureAuthenticated(), !this.userId)
|
|
773
|
-
throw new
|
|
800
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
774
801
|
const e = await this.walletProvider.getAddresses(this.userId);
|
|
775
802
|
return this.confirmation.showWalletSelector(
|
|
776
803
|
e,
|
|
@@ -800,7 +827,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
800
827
|
try {
|
|
801
828
|
return await this.chainRegistry.getChains();
|
|
802
829
|
} catch (e) {
|
|
803
|
-
throw e instanceof
|
|
830
|
+
throw e instanceof _ ? e : new _(p.UNKNOWN_ERROR, "Failed to fetch chains", e);
|
|
804
831
|
}
|
|
805
832
|
}
|
|
806
833
|
/**
|
|
@@ -819,7 +846,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
819
846
|
try {
|
|
820
847
|
return await this.chainRegistry.getChain(e);
|
|
821
848
|
} catch (s) {
|
|
822
|
-
throw s instanceof
|
|
849
|
+
throw s instanceof _ ? s : new _(p.CHAIN_NOT_SUPPORTED, `Failed to fetch chain: ${e}`, s);
|
|
823
850
|
}
|
|
824
851
|
}
|
|
825
852
|
// ============================================================================
|
|
@@ -845,19 +872,19 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
845
872
|
*/
|
|
846
873
|
async createWallet() {
|
|
847
874
|
if (this.ensureAuthenticated(), !this.userId)
|
|
848
|
-
throw new
|
|
849
|
-
|
|
875
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
876
|
+
f.log("[CROSSx] 지갑 생성 시작");
|
|
850
877
|
try {
|
|
851
878
|
const e = await this.walletProvider.getOrCreateWallet(this.userId);
|
|
852
|
-
return this.address = e.address, this.emit("addressChanged", { address: e.address, index: 0 }),
|
|
879
|
+
return this.address = e.address, this.emit("addressChanged", { address: e.address, index: 0 }), f.log("[CROSSx] 지갑 생성 완료:", e.address), { address: e.address };
|
|
853
880
|
} catch (e) {
|
|
854
|
-
if (e instanceof
|
|
881
|
+
if (e instanceof _ && e.code === p.MIGRATION_BACKUP_EXISTS) {
|
|
855
882
|
const s = this.providerSub ?? this.userId;
|
|
856
|
-
|
|
883
|
+
f.log("[CROSSx][Migration Phase 3] createWallet() — Gateway -10012 감지, 마이그레이션 UI 시작 — migrationSub:", s);
|
|
857
884
|
const t = await this.handleMigrationFlow(s);
|
|
858
885
|
if (t)
|
|
859
886
|
return this.address = t.address, this.emit("addressChanged", { address: t.address, index: 0 }), { address: t.address };
|
|
860
|
-
throw new
|
|
887
|
+
throw new _(
|
|
861
888
|
p.MIGRATION_FAILED,
|
|
862
889
|
"Migration skipped by user"
|
|
863
890
|
);
|
|
@@ -877,7 +904,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
877
904
|
*/
|
|
878
905
|
async signMessage(e, s, t) {
|
|
879
906
|
if (this.ensureAuthenticated(), !this.userId)
|
|
880
|
-
throw new
|
|
907
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
881
908
|
const n = t == null ? void 0 : t.index, o = await this.walletProvider.getAddress(this.userId, n ?? 0);
|
|
882
909
|
let i;
|
|
883
910
|
if (this.walletProvider.prepare && (i = (await this.walletProvider.prepare("sign-message", { message: s, from: o.address })).uuid), !await this.confirmation.requestConfirmation({
|
|
@@ -888,7 +915,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
888
915
|
dappName: t == null ? void 0 : t.dappName,
|
|
889
916
|
accountName: t == null ? void 0 : t.accountName
|
|
890
917
|
}))
|
|
891
|
-
throw new
|
|
918
|
+
throw new _(p.USER_REJECTED, "User rejected message signing");
|
|
892
919
|
try {
|
|
893
920
|
const c = await this.walletProvider.signMessage(
|
|
894
921
|
this.userId,
|
|
@@ -905,7 +932,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
905
932
|
address: o.address
|
|
906
933
|
};
|
|
907
934
|
} catch (c) {
|
|
908
|
-
throw c instanceof
|
|
935
|
+
throw c instanceof _ ? c : new _(p.SIGNATURE_FAILED, `Message signing failed (${e})`, c);
|
|
909
936
|
}
|
|
910
937
|
}
|
|
911
938
|
/**
|
|
@@ -931,9 +958,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
931
958
|
*/
|
|
932
959
|
async signTypedData(e, s, t) {
|
|
933
960
|
if (this.ensureAuthenticated(), !this.userId)
|
|
934
|
-
throw new
|
|
961
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
935
962
|
if (!this.walletProvider.signTypedData)
|
|
936
|
-
throw new
|
|
963
|
+
throw new _(p.NOT_IMPLEMENTED, "signTypedData is not implemented");
|
|
937
964
|
X.validateTypedDataChainId(e, s);
|
|
938
965
|
const n = await this.walletProvider.getAddress(this.userId, (t == null ? void 0 : t.index) ?? 0);
|
|
939
966
|
let o;
|
|
@@ -945,7 +972,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
945
972
|
dappName: t == null ? void 0 : t.dappName,
|
|
946
973
|
accountName: t == null ? void 0 : t.accountName
|
|
947
974
|
}))
|
|
948
|
-
throw new
|
|
975
|
+
throw new _(p.USER_REJECTED, "User rejected typed data signing");
|
|
949
976
|
try {
|
|
950
977
|
const a = await this.walletProvider.signTypedData(
|
|
951
978
|
this.userId,
|
|
@@ -961,7 +988,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
961
988
|
address: n.address
|
|
962
989
|
};
|
|
963
990
|
} catch (a) {
|
|
964
|
-
throw a instanceof
|
|
991
|
+
throw a instanceof _ ? a : new _(p.SIGNATURE_FAILED, `Typed data signing failed (${e})`, a);
|
|
965
992
|
}
|
|
966
993
|
}
|
|
967
994
|
/**
|
|
@@ -997,7 +1024,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
997
1024
|
*/
|
|
998
1025
|
async signTransaction(e, s, t) {
|
|
999
1026
|
if (this.ensureAuthenticated(), !this.userId)
|
|
1000
|
-
throw new
|
|
1027
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
1001
1028
|
const n = await this.withResolvedGasAndFee(s, e);
|
|
1002
1029
|
let o;
|
|
1003
1030
|
this.walletProvider.prepare && (o = (await this.walletProvider.prepare("sign", { tx: n })).uuid);
|
|
@@ -1018,7 +1045,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1018
1045
|
dappName: t == null ? void 0 : t.dappName,
|
|
1019
1046
|
accountName: t == null ? void 0 : t.accountName
|
|
1020
1047
|
}))
|
|
1021
|
-
throw new
|
|
1048
|
+
throw new _(p.USER_REJECTED, "User rejected transaction signing");
|
|
1022
1049
|
try {
|
|
1023
1050
|
const c = await this.walletProvider.signTransaction(
|
|
1024
1051
|
this.userId,
|
|
@@ -1033,9 +1060,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1033
1060
|
txHash: c.txHash ?? ""
|
|
1034
1061
|
};
|
|
1035
1062
|
} catch (c) {
|
|
1036
|
-
if (c instanceof
|
|
1063
|
+
if (c instanceof _) throw c;
|
|
1037
1064
|
const l = c instanceof Error ? c.message : String(c);
|
|
1038
|
-
throw new
|
|
1065
|
+
throw new _(
|
|
1039
1066
|
p.SIGNATURE_FAILED,
|
|
1040
1067
|
`Transaction signing failed (${e}): ${l}`,
|
|
1041
1068
|
c
|
|
@@ -1050,7 +1077,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1050
1077
|
*/
|
|
1051
1078
|
async sendTransaction(e, s, t) {
|
|
1052
1079
|
if (this.ensureAuthenticated(), !this.userId)
|
|
1053
|
-
throw new
|
|
1080
|
+
throw new _(p.AUTH_NOT_AUTHENTICATED, "User ID not found");
|
|
1054
1081
|
const n = await this.withResolvedGasAndFee(s, e);
|
|
1055
1082
|
let o;
|
|
1056
1083
|
this.walletProvider.prepare && (o = (await this.walletProvider.prepare("send", { tx: n })).uuid);
|
|
@@ -1071,7 +1098,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1071
1098
|
dappName: t == null ? void 0 : t.dappName,
|
|
1072
1099
|
accountName: t == null ? void 0 : t.accountName
|
|
1073
1100
|
}))
|
|
1074
|
-
throw new
|
|
1101
|
+
throw new _(p.USER_REJECTED, "User rejected transaction");
|
|
1075
1102
|
try {
|
|
1076
1103
|
let c;
|
|
1077
1104
|
if (this.walletProvider.sendTransaction)
|
|
@@ -1094,7 +1121,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1094
1121
|
return { chainId: e, txHash: c, status: "pending" };
|
|
1095
1122
|
} catch (c) {
|
|
1096
1123
|
const l = c instanceof Error ? c.message : String(c);
|
|
1097
|
-
throw new
|
|
1124
|
+
throw new _(
|
|
1098
1125
|
p.TRANSACTION_FAILED,
|
|
1099
1126
|
`Transaction failed (${e}): ${l}`,
|
|
1100
1127
|
c
|
|
@@ -1127,7 +1154,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1127
1154
|
if (l) return l;
|
|
1128
1155
|
await new Promise((d) => setTimeout(d, c)), c = Math.min(c * 2, o);
|
|
1129
1156
|
}
|
|
1130
|
-
throw new
|
|
1157
|
+
throw new _(
|
|
1131
1158
|
p.UNKNOWN_ERROR,
|
|
1132
1159
|
`Transaction receipt timeout (${e})`
|
|
1133
1160
|
);
|
|
@@ -1148,37 +1175,37 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1148
1175
|
* logger.log(receipt.status); // '0x1' | '0x0'
|
|
1149
1176
|
*/
|
|
1150
1177
|
async sendTransactionWithWaitForReceipt(e, s, t = {}) {
|
|
1151
|
-
var
|
|
1152
|
-
const { intervalMs: n, timeoutMs: o, ...i } = t, { txHash: a } = await this.sendTransaction(e, s, i), c = n ?? ((
|
|
1153
|
-
let
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1156
|
-
const q = BigInt(
|
|
1178
|
+
var b, S;
|
|
1179
|
+
const { intervalMs: n, timeoutMs: o, ...i } = t, { txHash: a } = await this.sendTransaction(e, s, i), c = n ?? ((b = this._config.receiptPolling) == null ? void 0 : b.intervalMs) ?? Hs, l = o ?? ((S = this._config.receiptPolling) == null ? void 0 : S.timeoutMs) ?? bt, d = ze(e), g = s.from ?? "";
|
|
1180
|
+
let m, x;
|
|
1181
|
+
const w = this.waitForTxAndGetReceipt(a, e, { intervalMs: c, timeoutMs: l }).then((E) => {
|
|
1182
|
+
m = E;
|
|
1183
|
+
const q = BigInt(E.gasUsed) * BigInt(E.effectiveGasPrice), B = s.value ? BigInt(s.value) : 0n, D = X.formatTxAmount(s.value, d.symbol, d.decimals), M = X.formatTxAmount("0x" + q.toString(16), d.symbol, d.decimals), Q = X.formatTxAmount("0x" + (B + q).toString(16), d.symbol, d.decimals);
|
|
1157
1184
|
return {
|
|
1158
1185
|
chainId: e,
|
|
1159
1186
|
txHash: a,
|
|
1160
|
-
from:
|
|
1161
|
-
to:
|
|
1187
|
+
from: E.from,
|
|
1188
|
+
to: E.to ?? s.to,
|
|
1162
1189
|
amount: D,
|
|
1163
|
-
fees:
|
|
1190
|
+
fees: M,
|
|
1164
1191
|
total: Q,
|
|
1165
1192
|
nativeSymbol: d.symbol,
|
|
1166
|
-
status:
|
|
1193
|
+
status: E.status === "0x1" ? "success" : "reverted"
|
|
1167
1194
|
};
|
|
1168
|
-
}).catch((
|
|
1195
|
+
}).catch((E) => (x = E instanceof Error ? E : new Error(String(E)), {
|
|
1169
1196
|
chainId: e,
|
|
1170
1197
|
txHash: a,
|
|
1171
|
-
from:
|
|
1198
|
+
from: g,
|
|
1172
1199
|
to: s.to,
|
|
1173
1200
|
amount: X.formatTxAmount(s.value, d.symbol, d.decimals),
|
|
1174
1201
|
nativeSymbol: d.symbol,
|
|
1175
1202
|
status: "timeout"
|
|
1176
1203
|
}));
|
|
1177
1204
|
if (await this.confirmation.showTransactionProgress(
|
|
1178
|
-
{ chainId: e, txHash: a, from:
|
|
1179
|
-
|
|
1180
|
-
),
|
|
1181
|
-
return { chainId: e, txHash: a, receipt:
|
|
1205
|
+
{ chainId: e, txHash: a, from: g, to: s.to },
|
|
1206
|
+
w
|
|
1207
|
+
), x) throw x;
|
|
1208
|
+
return { chainId: e, txHash: a, receipt: m };
|
|
1182
1209
|
}
|
|
1183
1210
|
// ============================================================================
|
|
1184
1211
|
// Gas 조회
|
|
@@ -1198,7 +1225,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1198
1225
|
return await this.walletRpc("eth_gasPrice", [], e);
|
|
1199
1226
|
} catch (s) {
|
|
1200
1227
|
const t = s instanceof Error ? s.message : String(s);
|
|
1201
|
-
throw new
|
|
1228
|
+
throw new _(p.GAS_ESTIMATION_FAILED, `Failed to get gas price (${e}): ${t}`, s);
|
|
1202
1229
|
}
|
|
1203
1230
|
}
|
|
1204
1231
|
/**
|
|
@@ -1219,7 +1246,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1219
1246
|
return await this.walletRpc("eth_estimateGas", [t], s);
|
|
1220
1247
|
} catch (n) {
|
|
1221
1248
|
const o = n instanceof Error ? n.message : String(n);
|
|
1222
|
-
throw new
|
|
1249
|
+
throw new _(p.GAS_ESTIMATION_FAILED, `Failed to estimate gas (${s}): ${o}`, n);
|
|
1223
1250
|
}
|
|
1224
1251
|
}
|
|
1225
1252
|
/**
|
|
@@ -1240,7 +1267,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1240
1267
|
return (s == null ? void 0 : s.baseFeePerGas) ?? null;
|
|
1241
1268
|
} catch (s) {
|
|
1242
1269
|
const t = s instanceof Error ? s.message : String(s);
|
|
1243
|
-
throw new
|
|
1270
|
+
throw new _(p.GAS_ESTIMATION_FAILED, `Failed to get baseFeePerGas (${e}): ${t}`, s);
|
|
1244
1271
|
}
|
|
1245
1272
|
}
|
|
1246
1273
|
/**
|
|
@@ -1259,7 +1286,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1259
1286
|
return await this.walletRpc("eth_maxPriorityFeePerGas", [], e);
|
|
1260
1287
|
} catch (s) {
|
|
1261
1288
|
const t = s instanceof Error ? s.message : String(s);
|
|
1262
|
-
throw new
|
|
1289
|
+
throw new _(p.GAS_ESTIMATION_FAILED, `Failed to get maxPriorityFeePerGas (${e}): ${t}`, s);
|
|
1263
1290
|
}
|
|
1264
1291
|
}
|
|
1265
1292
|
// ============================================================================
|
|
@@ -1277,9 +1304,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1277
1304
|
const t = await this.jsonRpc.call("eth_getTransactionCount", [s, "pending"], e);
|
|
1278
1305
|
return parseInt(t ?? "0x0", 16);
|
|
1279
1306
|
} catch (t) {
|
|
1280
|
-
if (t instanceof
|
|
1307
|
+
if (t instanceof _) throw t;
|
|
1281
1308
|
const n = t instanceof Error ? t.message : String(t);
|
|
1282
|
-
throw new
|
|
1309
|
+
throw new _(p.UNKNOWN_ERROR, `Failed to get nonce: ${n}`, t);
|
|
1283
1310
|
}
|
|
1284
1311
|
}
|
|
1285
1312
|
/**
|
|
@@ -1296,9 +1323,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1296
1323
|
const n = await this.jsonRpc.call("eth_getBalance", [s, "latest"], e) ?? "0x0";
|
|
1297
1324
|
return { wei: n, formatted: X.formatWei(n), chainId: e };
|
|
1298
1325
|
} catch (t) {
|
|
1299
|
-
if (t instanceof
|
|
1326
|
+
if (t instanceof _) throw t;
|
|
1300
1327
|
const n = t instanceof Error ? t.message : String(t);
|
|
1301
|
-
throw new
|
|
1328
|
+
throw new _(p.UNKNOWN_ERROR, `Failed to get balance (${e}): ${n}`, t);
|
|
1302
1329
|
}
|
|
1303
1330
|
}
|
|
1304
1331
|
static formatWei(e) {
|
|
@@ -1347,9 +1374,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1347
1374
|
try {
|
|
1348
1375
|
return await this.jsonRpc.call(e, s, t);
|
|
1349
1376
|
} catch (n) {
|
|
1350
|
-
if (n instanceof
|
|
1377
|
+
if (n instanceof _) throw n;
|
|
1351
1378
|
const o = n instanceof Error ? n.message : String(n);
|
|
1352
|
-
throw new
|
|
1379
|
+
throw new _(p.UNKNOWN_ERROR, `walletRpc failed [${e}] (${t}): ${o}`, n);
|
|
1353
1380
|
}
|
|
1354
1381
|
}
|
|
1355
1382
|
// ============================================================================
|
|
@@ -1377,26 +1404,26 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1377
1404
|
* 3) migrateWallet API 호출
|
|
1378
1405
|
*/
|
|
1379
1406
|
async handleMigrationFlow(e) {
|
|
1380
|
-
|
|
1407
|
+
f.log('[CROSSx][Migration Phase 3] "Wallet Found" 팝업 표시');
|
|
1381
1408
|
const s = await this.confirmation.showMigrationFoundPrompt();
|
|
1382
|
-
if (
|
|
1383
|
-
return
|
|
1409
|
+
if (f.log("[CROSSx][Migration Phase 3] 사용자 선택:", s), s === "skip")
|
|
1410
|
+
return f.log("[CROSSx][Migration Phase 3] 사용자가 마이그레이션을 건너뜀 → 종료"), null;
|
|
1384
1411
|
let t, n = 0;
|
|
1385
1412
|
for (; ; ) {
|
|
1386
|
-
n++,
|
|
1413
|
+
n++, f.log(`[CROSSx][Migration Phase 4] PIN 입력 팝업 표시 (시도 #${n})`, t ? `— 이전 에러: ${t}` : "");
|
|
1387
1414
|
const o = await this.confirmation.showPinInputPrompt(t);
|
|
1388
1415
|
if (o === null)
|
|
1389
|
-
return
|
|
1390
|
-
|
|
1416
|
+
return f.log("[CROSSx][Migration Phase 4] 사용자가 PIN 입력을 취소함 → 종료"), null;
|
|
1417
|
+
f.log(`[CROSSx][Migration Phase 4] PIN 입력 완료 (${o.length}자리), Gateway 마이그레이션 API 호출`);
|
|
1391
1418
|
try {
|
|
1392
1419
|
const i = await this.migrateWalletUseCase.execute(o, e);
|
|
1393
|
-
return
|
|
1420
|
+
return f.log("[CROSSx][Migration Phase 5] 마이그레이션 성공 — address:", i.address), i;
|
|
1394
1421
|
} catch (i) {
|
|
1395
|
-
if (i instanceof
|
|
1396
|
-
|
|
1422
|
+
if (i instanceof _ && i.code === p.MIGRATION_FAILED) {
|
|
1423
|
+
f.warn(`[CROSSx][Migration Phase 4] PIN 불일치 (시도 #${n}) — 재시도 요청`), t = "Incorrect PIN. Please try again.";
|
|
1397
1424
|
continue;
|
|
1398
1425
|
}
|
|
1399
|
-
throw
|
|
1426
|
+
throw f.error("[CROSSx][Migration Phase 4] 마이그레이션 실패 (복구 불가):", i), i;
|
|
1400
1427
|
}
|
|
1401
1428
|
}
|
|
1402
1429
|
}
|
|
@@ -1416,16 +1443,16 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1416
1443
|
const t = (l) => !(l != null && l.trim()), n = e.nonce === void 0 || e.nonce === null, o = t(e.gasLimit), i = t(e.gasPrice) && t(e.maxFeePerGas), a = !t(e.maxFeePerGas) && t(e.maxPriorityFeePerGas);
|
|
1417
1444
|
if (!n && !o && !i && !a) return e;
|
|
1418
1445
|
const c = { ...e };
|
|
1419
|
-
if (n && (
|
|
1420
|
-
|
|
1446
|
+
if (n && (f.log("[CROSSx] nonce 비어있음 → eth_getTransactionCount 호출"), c.nonce = await this.getNonce(s), f.log("[CROSSx] nonce 결과:", c.nonce)), o && (f.log("[CROSSx] gasLimit 비어있음 → eth_estimateGas 호출"), c.gasLimit = await this.estimateGas(e, s), f.log("[CROSSx] estimateGas 결과:", c.gasLimit)), i) {
|
|
1447
|
+
f.log("[CROSSx] gasPrice & maxFeePerGas 비어있음 → baseFee 조회로 Dynamic/Legacy 판별");
|
|
1421
1448
|
const l = await this.getBaseFeePerGas(s);
|
|
1422
1449
|
if (l) {
|
|
1423
1450
|
const d = vt;
|
|
1424
|
-
c.maxFeePerGas = "0x" + (BigInt(l) + BigInt(d)).toString(16), c.maxPriorityFeePerGas = d,
|
|
1451
|
+
c.maxFeePerGas = "0x" + (BigInt(l) + BigInt(d)).toString(16), c.maxPriorityFeePerGas = d, f.log("[CROSSx] Dynamic 체인 감지 — baseFee:", l, "maxFeePerGas:", c.maxFeePerGas, "maxPriorityFeePerGas: 1 Gwei");
|
|
1425
1452
|
} else
|
|
1426
|
-
c.gasPrice = Ws,
|
|
1453
|
+
c.gasPrice = Ws, f.log("[CROSSx] Legacy 체인 감지 — gasPrice: 2 Gwei");
|
|
1427
1454
|
}
|
|
1428
|
-
return !i && a && (c.maxPriorityFeePerGas = vt,
|
|
1455
|
+
return !i && a && (c.maxPriorityFeePerGas = vt, f.log("[CROSSx] maxPriorityFeePerGas 비어있음 → 1 Gwei 기본값 적용")), c;
|
|
1429
1456
|
}
|
|
1430
1457
|
/**
|
|
1431
1458
|
* EIP-712 signTypedData 호출 시 chainId와 typedData.domain.chainId 정합성 검증.
|
|
@@ -1437,7 +1464,7 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1437
1464
|
const t = X.extractDomainChainId(s);
|
|
1438
1465
|
if (e === "0") {
|
|
1439
1466
|
if (t !== void 0 && t !== 0)
|
|
1440
|
-
throw new
|
|
1467
|
+
throw new _(
|
|
1441
1468
|
p.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1442
1469
|
`Off-chain signing (chainId=0) requires typedData.domain.chainId to be absent or 0, got ${t}`
|
|
1443
1470
|
);
|
|
@@ -1447,12 +1474,12 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1447
1474
|
if (n) {
|
|
1448
1475
|
const o = Number(n[1]);
|
|
1449
1476
|
if (t === void 0)
|
|
1450
|
-
throw new
|
|
1477
|
+
throw new _(
|
|
1451
1478
|
p.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1452
1479
|
`On-chain signing (${e}) requires typedData.domain.chainId to be present`
|
|
1453
1480
|
);
|
|
1454
1481
|
if (t !== o)
|
|
1455
|
-
throw new
|
|
1482
|
+
throw new _(
|
|
1456
1483
|
p.TYPED_DATA_CHAIN_ID_MISMATCH,
|
|
1457
1484
|
`typedData.domain.chainId (${t}) does not match chainId (${e}, expected ${o})`
|
|
1458
1485
|
);
|
|
@@ -1471,9 +1498,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1471
1498
|
static validateSignatureFormat(e) {
|
|
1472
1499
|
const s = e.startsWith("0x") ? e.slice(2) : e;
|
|
1473
1500
|
if (!/^[0-9a-fA-F]+$/.test(s))
|
|
1474
|
-
throw new
|
|
1501
|
+
throw new _(p.SIGNATURE_FAILED, "Invalid signature: not a valid hex string");
|
|
1475
1502
|
if (s.length !== St)
|
|
1476
|
-
throw new
|
|
1503
|
+
throw new _(
|
|
1477
1504
|
p.SIGNATURE_FAILED,
|
|
1478
1505
|
`Invalid signature length: expected ${St} hex chars (65 bytes), got ${s.length}`
|
|
1479
1506
|
);
|
|
@@ -1482,9 +1509,9 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1482
1509
|
static validateSignedTxFormat(e) {
|
|
1483
1510
|
const s = e.startsWith("0x") ? e.slice(2) : e;
|
|
1484
1511
|
if (!/^[0-9a-fA-F]+$/.test(s))
|
|
1485
|
-
throw new
|
|
1512
|
+
throw new _(p.SIGNATURE_FAILED, "Invalid signedTx: not a valid hex string");
|
|
1486
1513
|
if (s.length < 2)
|
|
1487
|
-
throw new
|
|
1514
|
+
throw new _(p.SIGNATURE_FAILED, "Invalid signedTx: too short");
|
|
1488
1515
|
}
|
|
1489
1516
|
/**
|
|
1490
1517
|
* Gateway 서명 응답의 ecrecover 검증 (XF-036)
|
|
@@ -1497,17 +1524,17 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1497
1524
|
try {
|
|
1498
1525
|
const n = this.crypto.recoverPersonalSignSigner(e, s);
|
|
1499
1526
|
if (n.toLowerCase() !== t.toLowerCase())
|
|
1500
|
-
throw
|
|
1527
|
+
throw f.error("[CROSSx] 서명 검증 실패: 서명자 주소 불일치", {
|
|
1501
1528
|
expected: t,
|
|
1502
1529
|
recovered: n
|
|
1503
|
-
}), new
|
|
1530
|
+
}), new _(
|
|
1504
1531
|
p.SIGNATURE_SIGNER_MISMATCH,
|
|
1505
1532
|
`Signature signer mismatch: expected ${t}, recovered ${n}`
|
|
1506
1533
|
);
|
|
1507
|
-
|
|
1534
|
+
f.log("[CROSSx] 서명 ecrecover 검증 성공");
|
|
1508
1535
|
} catch (n) {
|
|
1509
|
-
if (n instanceof
|
|
1510
|
-
|
|
1536
|
+
if (n instanceof _) throw n;
|
|
1537
|
+
f.warn("[CROSSx] ecrecover 검증 중 예외 (무시):", n);
|
|
1511
1538
|
}
|
|
1512
1539
|
}
|
|
1513
1540
|
/** AuthResult를 내부 상태에 반영합니다. */
|
|
@@ -1536,14 +1563,14 @@ const Hs = 2e3, bt = 6e4, Gs = 1e3, qs = 1e4, Ws = "0x77359400", vt = "0x3B9ACA0
|
|
|
1536
1563
|
}
|
|
1537
1564
|
ensureInitialized() {
|
|
1538
1565
|
if (!this.initialized)
|
|
1539
|
-
throw new
|
|
1566
|
+
throw new _(
|
|
1540
1567
|
p.AUTH_NOT_INITIALIZED,
|
|
1541
1568
|
"SDK is not initialized. Call initialize() first."
|
|
1542
1569
|
);
|
|
1543
1570
|
}
|
|
1544
1571
|
ensureAuthenticated() {
|
|
1545
1572
|
if (this.ensureInitialized(), !this.authenticated)
|
|
1546
|
-
throw new
|
|
1573
|
+
throw new _(
|
|
1547
1574
|
p.AUTH_NOT_AUTHENTICATED,
|
|
1548
1575
|
"Not authenticated. Call signIn() first."
|
|
1549
1576
|
);
|
|
@@ -1569,7 +1596,7 @@ class Ks {
|
|
|
1569
1596
|
const t = JSON.stringify(s);
|
|
1570
1597
|
localStorage.setItem(this.prefix + e, t);
|
|
1571
1598
|
} catch (t) {
|
|
1572
|
-
throw
|
|
1599
|
+
throw f.error("Storage set error:", t), t;
|
|
1573
1600
|
}
|
|
1574
1601
|
}
|
|
1575
1602
|
async get(e) {
|
|
@@ -1577,14 +1604,14 @@ class Ks {
|
|
|
1577
1604
|
const s = localStorage.getItem(this.prefix + e);
|
|
1578
1605
|
return s ? JSON.parse(s) : null;
|
|
1579
1606
|
} catch (s) {
|
|
1580
|
-
return
|
|
1607
|
+
return f.error("Storage get error:", s), null;
|
|
1581
1608
|
}
|
|
1582
1609
|
}
|
|
1583
1610
|
async remove(e) {
|
|
1584
1611
|
try {
|
|
1585
1612
|
localStorage.removeItem(this.prefix + e);
|
|
1586
1613
|
} catch (s) {
|
|
1587
|
-
throw
|
|
1614
|
+
throw f.error("Storage remove error:", s), s;
|
|
1588
1615
|
}
|
|
1589
1616
|
}
|
|
1590
1617
|
async clear() {
|
|
@@ -1593,7 +1620,7 @@ class Ks {
|
|
|
1593
1620
|
s.startsWith(this.prefix) && localStorage.removeItem(s);
|
|
1594
1621
|
});
|
|
1595
1622
|
} catch (e) {
|
|
1596
|
-
throw
|
|
1623
|
+
throw f.error("Storage clear error:", e), e;
|
|
1597
1624
|
}
|
|
1598
1625
|
}
|
|
1599
1626
|
}
|
|
@@ -1675,7 +1702,7 @@ class At {
|
|
|
1675
1702
|
const t = JSON.stringify(s), n = await this.encrypt(t);
|
|
1676
1703
|
await this.idbPut(Se, e, n);
|
|
1677
1704
|
} catch (t) {
|
|
1678
|
-
throw
|
|
1705
|
+
throw f.error("[CROSSx] IndexedDB set error:", t), t;
|
|
1679
1706
|
}
|
|
1680
1707
|
}
|
|
1681
1708
|
async get(e) {
|
|
@@ -1686,21 +1713,21 @@ class At {
|
|
|
1686
1713
|
const t = await this.decrypt(s);
|
|
1687
1714
|
return JSON.parse(t);
|
|
1688
1715
|
} catch (s) {
|
|
1689
|
-
return
|
|
1716
|
+
return f.error("[CROSSx] IndexedDB get error:", s), null;
|
|
1690
1717
|
}
|
|
1691
1718
|
}
|
|
1692
1719
|
async remove(e) {
|
|
1693
1720
|
try {
|
|
1694
1721
|
await this.ensureReady(), await this.idbDelete(Se, e);
|
|
1695
1722
|
} catch (s) {
|
|
1696
|
-
throw
|
|
1723
|
+
throw f.error("[CROSSx] IndexedDB remove error:", s), s;
|
|
1697
1724
|
}
|
|
1698
1725
|
}
|
|
1699
1726
|
async clear() {
|
|
1700
1727
|
try {
|
|
1701
1728
|
await this.ensureReady(), await this.idbClear(Se);
|
|
1702
1729
|
} catch (e) {
|
|
1703
|
-
throw
|
|
1730
|
+
throw f.error("[CROSSx] IndexedDB clear error:", e), e;
|
|
1704
1731
|
}
|
|
1705
1732
|
}
|
|
1706
1733
|
/**
|
|
@@ -1871,8 +1898,8 @@ class or {
|
|
|
1871
1898
|
const { buffer: s, view: t, blockLen: n, isLE: o } = this;
|
|
1872
1899
|
let { pos: i } = this;
|
|
1873
1900
|
s[i++] = 128, Ie(this.buffer.subarray(i)), this.padOffset > n - i && (this.process(t, 0), i = 0);
|
|
1874
|
-
for (let
|
|
1875
|
-
s[
|
|
1901
|
+
for (let g = i; g < n; g++)
|
|
1902
|
+
s[g] = 0;
|
|
1876
1903
|
t.setBigUint64(n - 8, BigInt(this.length * 8), o), this.process(t, 0);
|
|
1877
1904
|
const a = Ze(e), c = this.outputLen;
|
|
1878
1905
|
if (c % 4)
|
|
@@ -1880,8 +1907,8 @@ class or {
|
|
|
1880
1907
|
const l = c / 4, d = this.get();
|
|
1881
1908
|
if (l > d.length)
|
|
1882
1909
|
throw new Error("_sha2: outputLen bigger than state");
|
|
1883
|
-
for (let
|
|
1884
|
-
a.setUint32(4 *
|
|
1910
|
+
for (let g = 0; g < l; g++)
|
|
1911
|
+
a.setUint32(4 * g, d[g], o);
|
|
1885
1912
|
}
|
|
1886
1913
|
digest() {
|
|
1887
1914
|
const { buffer: e, outputLen: s } = this;
|
|
@@ -1999,16 +2026,16 @@ class fr extends or {
|
|
|
1999
2026
|
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;
|
|
2000
2027
|
}
|
|
2001
2028
|
process(e, s) {
|
|
2002
|
-
for (let
|
|
2003
|
-
ge[
|
|
2004
|
-
for (let
|
|
2005
|
-
const
|
|
2006
|
-
ge[
|
|
2029
|
+
for (let g = 0; g < 16; g++, s += 4)
|
|
2030
|
+
ge[g] = e.getUint32(s, !1);
|
|
2031
|
+
for (let g = 16; g < 64; g++) {
|
|
2032
|
+
const m = ge[g - 15], x = ge[g - 2], w = oe(m, 7) ^ oe(m, 18) ^ m >>> 3, b = oe(x, 17) ^ oe(x, 19) ^ x >>> 10;
|
|
2033
|
+
ge[g] = b + ge[g - 7] + w + ge[g - 16] | 0;
|
|
2007
2034
|
}
|
|
2008
2035
|
let { A: t, B: n, C: o, D: i, E: a, F: c, G: l, H: d } = this;
|
|
2009
|
-
for (let
|
|
2010
|
-
const
|
|
2011
|
-
d = l, l = c, c = a, a = i +
|
|
2036
|
+
for (let g = 0; g < 64; g++) {
|
|
2037
|
+
const m = oe(a, 6) ^ oe(a, 11) ^ oe(a, 25), x = d + m + rr(a, c, l) + hr[g] + ge[g] | 0, b = (oe(t, 2) ^ oe(t, 13) ^ oe(t, 22)) + nr(t, n, o) | 0;
|
|
2038
|
+
d = l, l = c, c = a, a = i + x | 0, i = o, o = n, n = t, t = x + b | 0;
|
|
2012
2039
|
}
|
|
2013
2040
|
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);
|
|
2014
2041
|
}
|
|
@@ -2049,7 +2076,7 @@ function He(r, e = "") {
|
|
|
2049
2076
|
}
|
|
2050
2077
|
function Jt(r) {
|
|
2051
2078
|
if (typeof r == "bigint") {
|
|
2052
|
-
if (!
|
|
2079
|
+
if (!Be(r))
|
|
2053
2080
|
throw new Error("positive bigint expected, got " + r);
|
|
2054
2081
|
} else
|
|
2055
2082
|
ue(r);
|
|
@@ -2083,9 +2110,9 @@ function ts(r, e) {
|
|
|
2083
2110
|
function _r(r) {
|
|
2084
2111
|
return Uint8Array.from(r);
|
|
2085
2112
|
}
|
|
2086
|
-
const
|
|
2113
|
+
const Be = (r) => typeof r == "bigint" && ct <= r;
|
|
2087
2114
|
function xr(r, e, s) {
|
|
2088
|
-
return
|
|
2115
|
+
return Be(r) && Be(e) && Be(s) && e <= r && r < s;
|
|
2089
2116
|
}
|
|
2090
2117
|
function mr(r, e, s, t) {
|
|
2091
2118
|
if (!xr(e, s, t))
|
|
@@ -2101,30 +2128,30 @@ const dt = (r) => (rt << BigInt(r)) - rt;
|
|
|
2101
2128
|
function yr(r, e, s) {
|
|
2102
2129
|
if (ue(r, "hashLen"), ue(e, "qByteLen"), typeof s != "function")
|
|
2103
2130
|
throw new Error("hmacFn must be a function");
|
|
2104
|
-
const t = (
|
|
2131
|
+
const t = (S) => new Uint8Array(S), n = Uint8Array.of(), o = Uint8Array.of(0), i = Uint8Array.of(1), a = 1e3;
|
|
2105
2132
|
let c = t(r), l = t(r), d = 0;
|
|
2106
|
-
const
|
|
2133
|
+
const g = () => {
|
|
2107
2134
|
c.fill(1), l.fill(0), d = 0;
|
|
2108
|
-
},
|
|
2109
|
-
l =
|
|
2110
|
-
},
|
|
2135
|
+
}, m = (...S) => s(l, _e(c, ...S)), x = (S = n) => {
|
|
2136
|
+
l = m(o, S), c = m(), S.length !== 0 && (l = m(i, S), c = m());
|
|
2137
|
+
}, w = () => {
|
|
2111
2138
|
if (d++ >= a)
|
|
2112
2139
|
throw new Error("drbg: tried max amount of iterations");
|
|
2113
|
-
let
|
|
2114
|
-
const
|
|
2115
|
-
for (;
|
|
2116
|
-
c =
|
|
2140
|
+
let S = 0;
|
|
2141
|
+
const E = [];
|
|
2142
|
+
for (; S < e; ) {
|
|
2143
|
+
c = m();
|
|
2117
2144
|
const q = c.slice();
|
|
2118
|
-
|
|
2145
|
+
E.push(q), S += c.length;
|
|
2119
2146
|
}
|
|
2120
|
-
return _e(...
|
|
2147
|
+
return _e(...E);
|
|
2121
2148
|
};
|
|
2122
|
-
return (
|
|
2123
|
-
|
|
2149
|
+
return (S, E) => {
|
|
2150
|
+
g(), x(S);
|
|
2124
2151
|
let q;
|
|
2125
|
-
for (; !(q =
|
|
2126
|
-
|
|
2127
|
-
return
|
|
2152
|
+
for (; !(q = E(w())); )
|
|
2153
|
+
x();
|
|
2154
|
+
return g(), q;
|
|
2128
2155
|
};
|
|
2129
2156
|
}
|
|
2130
2157
|
function ut(r, e = {}, s = {}) {
|
|
@@ -2193,10 +2220,10 @@ function Er(r) {
|
|
|
2193
2220
|
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;
|
|
2194
2221
|
return (a, c) => {
|
|
2195
2222
|
let l = a.pow(c, i), d = a.mul(l, t);
|
|
2196
|
-
const
|
|
2197
|
-
l = a.cmov(l, d,
|
|
2198
|
-
const
|
|
2199
|
-
return ht(a,
|
|
2223
|
+
const g = a.mul(l, n), m = a.mul(l, o), x = a.eql(a.sqr(d), c), w = a.eql(a.sqr(g), c);
|
|
2224
|
+
l = a.cmov(l, d, x), d = a.cmov(m, g, w);
|
|
2225
|
+
const b = a.eql(a.sqr(d), c), S = a.cmov(l, d, b);
|
|
2226
|
+
return ht(a, S, c), S;
|
|
2200
2227
|
};
|
|
2201
2228
|
}
|
|
2202
2229
|
function cs(r) {
|
|
@@ -2219,18 +2246,18 @@ function cs(r) {
|
|
|
2219
2246
|
return l;
|
|
2220
2247
|
if (Pt(c, l) !== 1)
|
|
2221
2248
|
throw new Error("Cannot find square root");
|
|
2222
|
-
let d = s,
|
|
2223
|
-
for (; !c.eql(
|
|
2224
|
-
if (c.is0(
|
|
2249
|
+
let d = s, g = c.mul(c.ONE, o), m = c.pow(l, e), x = c.pow(l, i);
|
|
2250
|
+
for (; !c.eql(m, c.ONE); ) {
|
|
2251
|
+
if (c.is0(m))
|
|
2225
2252
|
return c.ZERO;
|
|
2226
|
-
let
|
|
2227
|
-
for (; !c.eql(
|
|
2228
|
-
if (
|
|
2253
|
+
let w = 1, b = c.sqr(m);
|
|
2254
|
+
for (; !c.eql(b, c.ONE); )
|
|
2255
|
+
if (w++, b = c.sqr(b), w === d)
|
|
2229
2256
|
throw new Error("Cannot find square root");
|
|
2230
|
-
const
|
|
2231
|
-
d =
|
|
2257
|
+
const S = z << BigInt(d - w - 1), E = c.pow(g, S);
|
|
2258
|
+
d = w, g = c.sqr(E), m = c.mul(m, g), x = c.mul(x, E);
|
|
2232
2259
|
}
|
|
2233
|
-
return
|
|
2260
|
+
return x;
|
|
2234
2261
|
};
|
|
2235
2262
|
}
|
|
2236
2263
|
function Tr(r) {
|
|
@@ -2446,8 +2473,8 @@ function Dt(r, e, s) {
|
|
|
2446
2473
|
const { windowSize: t, mask: n, maxNumber: o, shiftBy: i } = s;
|
|
2447
2474
|
let a = Number(r & n), c = r >> i;
|
|
2448
2475
|
a > t && (a -= o, c += be);
|
|
2449
|
-
const l = e * t, d = l + Math.abs(a) - 1,
|
|
2450
|
-
return { nextN: c, offset: d, isZero:
|
|
2476
|
+
const l = e * t, d = l + Math.abs(a) - 1, g = a === 0, m = a < 0, x = e % 2 !== 0;
|
|
2477
|
+
return { nextN: c, offset: d, isZero: g, isNeg: m, isNegF: x, offsetF: l };
|
|
2451
2478
|
}
|
|
2452
2479
|
const Je = /* @__PURE__ */ new WeakMap(), fs = /* @__PURE__ */ new WeakMap();
|
|
2453
2480
|
function Qe(r) {
|
|
@@ -2508,8 +2535,8 @@ class Nr {
|
|
|
2508
2535
|
let n = this.ZERO, o = this.BASE;
|
|
2509
2536
|
const i = Xe(e, this.bits);
|
|
2510
2537
|
for (let a = 0; a < i.windows; a++) {
|
|
2511
|
-
const { nextN: c, offset: l, isZero: d, isNeg:
|
|
2512
|
-
t = c, d ? o = o.add(Ge(
|
|
2538
|
+
const { nextN: c, offset: l, isZero: d, isNeg: g, isNegF: m, offsetF: x } = Dt(t, a, i);
|
|
2539
|
+
t = c, d ? o = o.add(Ge(m, s[x])) : n = n.add(Ge(g, s[l]));
|
|
2513
2540
|
}
|
|
2514
2541
|
return $t(t), { p: n, f: o };
|
|
2515
2542
|
}
|
|
@@ -2523,8 +2550,8 @@ class Nr {
|
|
|
2523
2550
|
for (let i = 0; i < o.windows && t !== Ae; i++) {
|
|
2524
2551
|
const { nextN: a, offset: c, isZero: l, isNeg: d } = Dt(t, i, o);
|
|
2525
2552
|
if (t = a, !l) {
|
|
2526
|
-
const
|
|
2527
|
-
n = n.add(d ?
|
|
2553
|
+
const g = s[c];
|
|
2554
|
+
n = n.add(d ? g.negate() : g);
|
|
2528
2555
|
}
|
|
2529
2556
|
}
|
|
2530
2557
|
return $t(t), n;
|
|
@@ -2557,7 +2584,7 @@ function Pr(r, e, s, t) {
|
|
|
2557
2584
|
s & be && (o = o.add(n)), t & be && (i = i.add(n)), n = n.double(), s >>= be, t >>= be;
|
|
2558
2585
|
return { p1: o, p2: i };
|
|
2559
2586
|
}
|
|
2560
|
-
function
|
|
2587
|
+
function Mt(r, e, s) {
|
|
2561
2588
|
if (e) {
|
|
2562
2589
|
if (e.ORDER !== r)
|
|
2563
2590
|
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
@@ -2573,7 +2600,7 @@ function Lr(r, e, s = {}, t) {
|
|
|
2573
2600
|
if (!(typeof l == "bigint" && l > Ae))
|
|
2574
2601
|
throw new Error(`CURVE.${c} must be positive bigint`);
|
|
2575
2602
|
}
|
|
2576
|
-
const n =
|
|
2603
|
+
const n = Mt(e.p, s.Fp, t), o = Mt(e.n, s.Fn, t), a = ["Gx", "Gy", "a", "b"];
|
|
2577
2604
|
for (const c of a)
|
|
2578
2605
|
if (!n.isValid(e[c]))
|
|
2579
2606
|
throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
|
|
@@ -2630,16 +2657,16 @@ class gs {
|
|
|
2630
2657
|
const ps = (r, e, s) => new gs(r, e).update(s).digest();
|
|
2631
2658
|
ps.create = (r, e) => new gs(r, e);
|
|
2632
2659
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2633
|
-
const
|
|
2660
|
+
const Bt = (r, e) => (r + (r >= 0 ? e : -e) / _s) / e;
|
|
2634
2661
|
function $r(r, e, s) {
|
|
2635
|
-
const [[t, n], [o, i]] = e, a =
|
|
2662
|
+
const [[t, n], [o, i]] = e, a = Bt(i * r, s), c = Bt(-n * r, s);
|
|
2636
2663
|
let l = r - a * t - c * o, d = -a * n - c * i;
|
|
2637
|
-
const
|
|
2638
|
-
|
|
2639
|
-
const
|
|
2640
|
-
if (l < le || l >=
|
|
2664
|
+
const g = l < le, m = d < le;
|
|
2665
|
+
g && (l = -l), m && (d = -d);
|
|
2666
|
+
const x = dt(Math.ceil(wr(s) / 2)) + Ee;
|
|
2667
|
+
if (l < le || l >= x || d < le || d >= x)
|
|
2641
2668
|
throw new Error("splitScalar (endomorphism): failed, k=" + r);
|
|
2642
|
-
return { k1neg:
|
|
2669
|
+
return { k1neg: g, k1: l, k2neg: m, k2: d };
|
|
2643
2670
|
}
|
|
2644
2671
|
function nt(r) {
|
|
2645
2672
|
if (!["compact", "recovered", "der"].includes(r))
|
|
@@ -2652,14 +2679,14 @@ function et(r, e) {
|
|
|
2652
2679
|
s[t] = r[t] === void 0 ? e[t] : r[t];
|
|
2653
2680
|
return He(s.lowS, "lowS"), He(s.prehash, "prehash"), s.format !== void 0 && nt(s.format), s;
|
|
2654
2681
|
}
|
|
2655
|
-
class
|
|
2682
|
+
class Mr extends Error {
|
|
2656
2683
|
constructor(e = "") {
|
|
2657
2684
|
super(e);
|
|
2658
2685
|
}
|
|
2659
2686
|
}
|
|
2660
2687
|
const pe = {
|
|
2661
2688
|
// asn.1 DER encoding utils
|
|
2662
|
-
Err:
|
|
2689
|
+
Err: Mr,
|
|
2663
2690
|
// Basic building block is TLV (Tag-Length-Value)
|
|
2664
2691
|
_tlv: {
|
|
2665
2692
|
encode: (r, e) => {
|
|
@@ -2744,7 +2771,7 @@ const pe = {
|
|
|
2744
2771
|
const { _tlv: e, _int: s } = pe, t = e.encode(2, s.encode(r.r)), n = e.encode(2, s.encode(r.s)), o = t + n;
|
|
2745
2772
|
return e.encode(48, o);
|
|
2746
2773
|
}
|
|
2747
|
-
}, le = BigInt(0), Ee = BigInt(1), _s = BigInt(2),
|
|
2774
|
+
}, le = BigInt(0), Ee = BigInt(1), _s = BigInt(2), Me = BigInt(3), Br = BigInt(4);
|
|
2748
2775
|
function Ur(r, e = {}) {
|
|
2749
2776
|
const s = Lr("weierstrass", r, e), { Fp: t, Fn: n } = s;
|
|
2750
2777
|
let o = s.CURVE;
|
|
@@ -2765,56 +2792,56 @@ function Ur(r, e = {}) {
|
|
|
2765
2792
|
if (!t.isOdd)
|
|
2766
2793
|
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2767
2794
|
}
|
|
2768
|
-
function
|
|
2769
|
-
const { x: y, y:
|
|
2795
|
+
function g(P, u, h) {
|
|
2796
|
+
const { x: y, y: I } = u.toAffine(), R = t.toBytes(y);
|
|
2770
2797
|
if (He(h, "isCompressed"), h) {
|
|
2771
2798
|
d();
|
|
2772
|
-
const
|
|
2773
|
-
return _e(xs(
|
|
2799
|
+
const A = !t.isOdd(I);
|
|
2800
|
+
return _e(xs(A), R);
|
|
2774
2801
|
} else
|
|
2775
|
-
return _e(Uint8Array.of(4), R, t.toBytes(
|
|
2802
|
+
return _e(Uint8Array.of(4), R, t.toBytes(I));
|
|
2776
2803
|
}
|
|
2777
|
-
function
|
|
2804
|
+
function m(P) {
|
|
2778
2805
|
F(P, void 0, "Point");
|
|
2779
|
-
const { publicKey: u, publicKeyUncompressed: h } = l, y = P.length,
|
|
2780
|
-
if (y === u && (
|
|
2781
|
-
const
|
|
2782
|
-
if (!t.isValid(
|
|
2806
|
+
const { publicKey: u, publicKeyUncompressed: h } = l, y = P.length, I = P[0], R = P.subarray(1);
|
|
2807
|
+
if (y === u && (I === 2 || I === 3)) {
|
|
2808
|
+
const A = t.fromBytes(R);
|
|
2809
|
+
if (!t.isValid(A))
|
|
2783
2810
|
throw new Error("bad point: is not on curve, wrong x");
|
|
2784
|
-
const O =
|
|
2785
|
-
let
|
|
2811
|
+
const O = b(A);
|
|
2812
|
+
let T;
|
|
2786
2813
|
try {
|
|
2787
|
-
|
|
2814
|
+
T = t.sqrt(O);
|
|
2788
2815
|
} catch (W) {
|
|
2789
2816
|
const U = W instanceof Error ? ": " + W.message : "";
|
|
2790
2817
|
throw new Error("bad point: is not on curve, sqrt error" + U);
|
|
2791
2818
|
}
|
|
2792
2819
|
d();
|
|
2793
|
-
const C = t.isOdd(
|
|
2794
|
-
return (
|
|
2795
|
-
} else if (y === h &&
|
|
2796
|
-
const
|
|
2797
|
-
if (!
|
|
2820
|
+
const C = t.isOdd(T);
|
|
2821
|
+
return (I & 1) === 1 !== C && (T = t.neg(T)), { x: A, y: T };
|
|
2822
|
+
} else if (y === h && I === 4) {
|
|
2823
|
+
const A = t.BYTES, O = t.fromBytes(R.subarray(0, A)), T = t.fromBytes(R.subarray(A, A * 2));
|
|
2824
|
+
if (!S(O, T))
|
|
2798
2825
|
throw new Error("bad point: is not on curve");
|
|
2799
|
-
return { x: O, y:
|
|
2826
|
+
return { x: O, y: T };
|
|
2800
2827
|
} else
|
|
2801
2828
|
throw new Error(`bad point: got length ${y}, expected compressed=${u} or uncompressed=${h}`);
|
|
2802
2829
|
}
|
|
2803
|
-
const
|
|
2804
|
-
function
|
|
2830
|
+
const x = e.toBytes || g, w = e.fromBytes || m;
|
|
2831
|
+
function b(P) {
|
|
2805
2832
|
const u = t.sqr(P), h = t.mul(u, P);
|
|
2806
2833
|
return t.add(t.add(h, t.mul(P, o.a)), o.b);
|
|
2807
2834
|
}
|
|
2808
|
-
function
|
|
2809
|
-
const h = t.sqr(u), y =
|
|
2835
|
+
function S(P, u) {
|
|
2836
|
+
const h = t.sqr(u), y = b(P);
|
|
2810
2837
|
return t.eql(h, y);
|
|
2811
2838
|
}
|
|
2812
|
-
if (!
|
|
2839
|
+
if (!S(o.Gx, o.Gy))
|
|
2813
2840
|
throw new Error("bad curve params: generator point");
|
|
2814
|
-
const
|
|
2815
|
-
if (t.is0(t.add(
|
|
2841
|
+
const E = t.mul(t.pow(o.a, Me), Br), q = t.mul(t.sqr(o.b), BigInt(27));
|
|
2842
|
+
if (t.is0(t.add(E, q)))
|
|
2816
2843
|
throw new Error("bad curve params: a or b");
|
|
2817
|
-
function
|
|
2844
|
+
function B(P, u, h = !1) {
|
|
2818
2845
|
if (!t.isValid(u) || h && t.is0(u))
|
|
2819
2846
|
throw new Error(`bad point coordinate ${P}`);
|
|
2820
2847
|
return u;
|
|
@@ -2823,23 +2850,23 @@ function Ur(r, e = {}) {
|
|
|
2823
2850
|
if (!(P instanceof Z))
|
|
2824
2851
|
throw new Error("Weierstrass Point expected");
|
|
2825
2852
|
}
|
|
2826
|
-
function
|
|
2853
|
+
function M(P) {
|
|
2827
2854
|
if (!c || !c.basises)
|
|
2828
2855
|
throw new Error("no endo");
|
|
2829
2856
|
return $r(P, c.basises, n.ORDER);
|
|
2830
2857
|
}
|
|
2831
2858
|
const Q = kt((P, u) => {
|
|
2832
|
-
const { X: h, Y: y, Z:
|
|
2833
|
-
if (t.eql(
|
|
2859
|
+
const { X: h, Y: y, Z: I } = P;
|
|
2860
|
+
if (t.eql(I, t.ONE))
|
|
2834
2861
|
return { x: h, y };
|
|
2835
2862
|
const R = P.is0();
|
|
2836
|
-
u == null && (u = R ? t.ONE : t.inv(
|
|
2837
|
-
const
|
|
2863
|
+
u == null && (u = R ? t.ONE : t.inv(I));
|
|
2864
|
+
const A = t.mul(h, u), O = t.mul(y, u), T = t.mul(I, u);
|
|
2838
2865
|
if (R)
|
|
2839
2866
|
return { x: t.ZERO, y: t.ZERO };
|
|
2840
|
-
if (!t.eql(
|
|
2867
|
+
if (!t.eql(T, t.ONE))
|
|
2841
2868
|
throw new Error("invZ was invalid");
|
|
2842
|
-
return { x:
|
|
2869
|
+
return { x: A, y: O };
|
|
2843
2870
|
}), ve = kt((P) => {
|
|
2844
2871
|
if (P.is0()) {
|
|
2845
2872
|
if (e.allowInfinityPoint && !t.is0(P.Y))
|
|
@@ -2849,14 +2876,14 @@ function Ur(r, e = {}) {
|
|
|
2849
2876
|
const { x: u, y: h } = P.toAffine();
|
|
2850
2877
|
if (!t.isValid(u) || !t.isValid(h))
|
|
2851
2878
|
throw new Error("bad point: x or y not field elements");
|
|
2852
|
-
if (!
|
|
2879
|
+
if (!S(u, h))
|
|
2853
2880
|
throw new Error("bad point: equation left != right");
|
|
2854
2881
|
if (!P.isTorsionFree())
|
|
2855
2882
|
throw new Error("bad point: not in prime-order subgroup");
|
|
2856
2883
|
return !0;
|
|
2857
2884
|
});
|
|
2858
|
-
function he(P, u, h, y,
|
|
2859
|
-
return h = new Z(t.mul(h.X, P), h.Y, h.Z), u = Ge(y, u), h = Ge(
|
|
2885
|
+
function he(P, u, h, y, I) {
|
|
2886
|
+
return h = new Z(t.mul(h.X, P), h.Y, h.Z), u = Ge(y, u), h = Ge(I, h), u.add(h);
|
|
2860
2887
|
}
|
|
2861
2888
|
const L = class L {
|
|
2862
2889
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
@@ -2864,7 +2891,7 @@ function Ur(r, e = {}) {
|
|
|
2864
2891
|
v(this, "X");
|
|
2865
2892
|
v(this, "Y");
|
|
2866
2893
|
v(this, "Z");
|
|
2867
|
-
this.X =
|
|
2894
|
+
this.X = B("x", u), this.Y = B("y", h, !0), this.Z = B("z", y), Object.freeze(this);
|
|
2868
2895
|
}
|
|
2869
2896
|
static CURVE() {
|
|
2870
2897
|
return o;
|
|
@@ -2879,7 +2906,7 @@ function Ur(r, e = {}) {
|
|
|
2879
2906
|
return t.is0(h) && t.is0(y) ? L.ZERO : new L(h, y, t.ONE);
|
|
2880
2907
|
}
|
|
2881
2908
|
static fromBytes(u) {
|
|
2882
|
-
const h = L.fromAffine(
|
|
2909
|
+
const h = L.fromAffine(w(F(u, void 0, "point")));
|
|
2883
2910
|
return h.assertValidity(), h;
|
|
2884
2911
|
}
|
|
2885
2912
|
static fromHex(u) {
|
|
@@ -2898,7 +2925,7 @@ function Ur(r, e = {}) {
|
|
|
2898
2925
|
* @returns
|
|
2899
2926
|
*/
|
|
2900
2927
|
precompute(u = 8, h = !0) {
|
|
2901
|
-
return ne.createCache(this, u), h || this.multiply(
|
|
2928
|
+
return ne.createCache(this, u), h || this.multiply(Me), this;
|
|
2902
2929
|
}
|
|
2903
2930
|
// TODO: return `this`
|
|
2904
2931
|
/** A point on curve is valid if it conforms to equation. */
|
|
@@ -2914,8 +2941,8 @@ function Ur(r, e = {}) {
|
|
|
2914
2941
|
/** Compare one point to another. */
|
|
2915
2942
|
equals(u) {
|
|
2916
2943
|
D(u);
|
|
2917
|
-
const { X: h, Y: y, Z:
|
|
2918
|
-
return
|
|
2944
|
+
const { X: h, Y: y, Z: I } = this, { X: R, Y: A, Z: O } = u, T = t.eql(t.mul(h, O), t.mul(R, I)), C = t.eql(t.mul(y, O), t.mul(A, I));
|
|
2945
|
+
return T && C;
|
|
2919
2946
|
}
|
|
2920
2947
|
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2921
2948
|
negate() {
|
|
@@ -2926,9 +2953,9 @@ function Ur(r, e = {}) {
|
|
|
2926
2953
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2927
2954
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2928
2955
|
double() {
|
|
2929
|
-
const { a: u, b: h } = o, y = t.mul(h,
|
|
2930
|
-
let O = t.ZERO,
|
|
2931
|
-
return k = t.add(k, k), C = t.mul(
|
|
2956
|
+
const { a: u, b: h } = o, y = t.mul(h, Me), { X: I, Y: R, Z: A } = this;
|
|
2957
|
+
let O = t.ZERO, T = t.ZERO, C = t.ZERO, N = t.mul(I, I), W = t.mul(R, R), U = t.mul(A, A), k = t.mul(I, R);
|
|
2958
|
+
return k = t.add(k, k), C = t.mul(I, A), C = t.add(C, C), O = t.mul(u, C), T = t.mul(y, U), T = t.add(O, T), O = t.sub(W, T), T = t.add(W, T), T = t.mul(O, T), O = t.mul(k, O), C = t.mul(y, C), U = t.mul(u, U), k = t.sub(N, U), k = t.mul(u, k), k = t.add(k, C), C = t.add(N, N), N = t.add(C, N), N = t.add(N, U), N = t.mul(N, k), T = t.add(T, N), U = t.mul(R, A), U = t.add(U, U), N = t.mul(U, k), O = t.sub(O, N), C = t.mul(U, W), C = t.add(C, C), C = t.add(C, C), new L(O, T, C);
|
|
2932
2959
|
}
|
|
2933
2960
|
// Renes-Costello-Batina exception-free addition formula.
|
|
2934
2961
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -2936,13 +2963,13 @@ function Ur(r, e = {}) {
|
|
|
2936
2963
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2937
2964
|
add(u) {
|
|
2938
2965
|
D(u);
|
|
2939
|
-
const { X: h, Y: y, Z:
|
|
2940
|
-
let
|
|
2941
|
-
const W = o.a, U = t.mul(o.b,
|
|
2942
|
-
let k = t.mul(h, R), j = t.mul(y,
|
|
2943
|
-
ee = t.mul(ee, H), H = t.add(k, j), ee = t.sub(ee, H), H = t.add(h,
|
|
2966
|
+
const { X: h, Y: y, Z: I } = this, { X: R, Y: A, Z: O } = u;
|
|
2967
|
+
let T = t.ZERO, C = t.ZERO, N = t.ZERO;
|
|
2968
|
+
const W = o.a, U = t.mul(o.b, Me);
|
|
2969
|
+
let k = t.mul(h, R), j = t.mul(y, A), V = t.mul(I, O), ee = t.add(h, y), H = t.add(R, A);
|
|
2970
|
+
ee = t.mul(ee, H), H = t.add(k, j), ee = t.sub(ee, H), H = t.add(h, I);
|
|
2944
2971
|
let K = t.add(R, O);
|
|
2945
|
-
return H = t.mul(H, K), K = t.add(k, V), H = t.sub(H, K), K = t.add(y,
|
|
2972
|
+
return H = t.mul(H, K), K = t.add(k, V), H = t.sub(H, K), K = t.add(y, I), T = t.add(A, O), K = t.mul(K, T), T = t.add(j, V), K = t.sub(K, T), N = t.mul(W, H), T = t.mul(U, V), N = t.add(T, N), T = t.sub(j, N), N = t.add(j, N), C = t.mul(T, N), j = t.add(k, k), j = t.add(j, k), V = t.mul(W, V), H = t.mul(U, H), j = t.add(j, V), V = t.sub(k, V), V = t.mul(W, V), H = t.add(H, V), k = t.mul(j, H), C = t.add(C, k), k = t.mul(K, H), T = t.mul(ee, T), T = t.sub(T, k), k = t.mul(ee, j), N = t.mul(K, N), N = t.add(N, k), new L(T, C, N);
|
|
2946
2973
|
}
|
|
2947
2974
|
subtract(u) {
|
|
2948
2975
|
return this.add(u.negate());
|
|
@@ -2963,16 +2990,16 @@ function Ur(r, e = {}) {
|
|
|
2963
2990
|
const { endo: h } = e;
|
|
2964
2991
|
if (!n.isValidNot0(u))
|
|
2965
2992
|
throw new Error("invalid scalar: out of range");
|
|
2966
|
-
let y,
|
|
2967
|
-
const R = (
|
|
2993
|
+
let y, I;
|
|
2994
|
+
const R = (A) => ne.cached(this, A, (O) => Lt(L, O));
|
|
2968
2995
|
if (h) {
|
|
2969
|
-
const { k1neg:
|
|
2970
|
-
|
|
2996
|
+
const { k1neg: A, k1: O, k2neg: T, k2: C } = M(u), { p: N, f: W } = R(O), { p: U, f: k } = R(C);
|
|
2997
|
+
I = W.add(k), y = he(h.beta, N, U, A, T);
|
|
2971
2998
|
} else {
|
|
2972
|
-
const { p:
|
|
2973
|
-
y =
|
|
2999
|
+
const { p: A, f: O } = R(u);
|
|
3000
|
+
y = A, I = O;
|
|
2974
3001
|
}
|
|
2975
|
-
return Lt(L, [y,
|
|
3002
|
+
return Lt(L, [y, I])[0];
|
|
2976
3003
|
}
|
|
2977
3004
|
/**
|
|
2978
3005
|
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
@@ -2990,8 +3017,8 @@ function Ur(r, e = {}) {
|
|
|
2990
3017
|
if (ne.hasCache(this))
|
|
2991
3018
|
return this.multiply(u);
|
|
2992
3019
|
if (h) {
|
|
2993
|
-
const { k1neg:
|
|
2994
|
-
return he(h.beta,
|
|
3020
|
+
const { k1neg: I, k1: R, k2neg: A, k2: O } = M(u), { p1: T, p2: C } = Pr(L, y, R, O);
|
|
3021
|
+
return he(h.beta, T, C, I, A);
|
|
2995
3022
|
} else
|
|
2996
3023
|
return ne.unsafe(y, u);
|
|
2997
3024
|
}
|
|
@@ -3018,7 +3045,7 @@ function Ur(r, e = {}) {
|
|
|
3018
3045
|
return this.multiplyUnsafe(i).is0();
|
|
3019
3046
|
}
|
|
3020
3047
|
toBytes(u = !0) {
|
|
3021
|
-
return He(u, "isCompressed"), this.assertValidity(),
|
|
3048
|
+
return He(u, "isCompressed"), this.assertValidity(), x(L, this, u);
|
|
3022
3049
|
}
|
|
3023
3050
|
toHex(u = !0) {
|
|
3024
3051
|
return ke(this.toBytes(u));
|
|
@@ -3051,50 +3078,50 @@ function ms(r, e) {
|
|
|
3051
3078
|
}
|
|
3052
3079
|
function Fr(r, e = {}) {
|
|
3053
3080
|
const { Fn: s } = r, t = e.randomBytes || Xt, n = Object.assign(ms(r.Fp, s), { seed: us(s.ORDER) });
|
|
3054
|
-
function o(
|
|
3081
|
+
function o(x) {
|
|
3055
3082
|
try {
|
|
3056
|
-
const
|
|
3057
|
-
return s.isValidNot0(
|
|
3083
|
+
const w = s.fromBytes(x);
|
|
3084
|
+
return s.isValidNot0(w);
|
|
3058
3085
|
} catch {
|
|
3059
3086
|
return !1;
|
|
3060
3087
|
}
|
|
3061
3088
|
}
|
|
3062
|
-
function i(
|
|
3063
|
-
const { publicKey:
|
|
3089
|
+
function i(x, w) {
|
|
3090
|
+
const { publicKey: b, publicKeyUncompressed: S } = n;
|
|
3064
3091
|
try {
|
|
3065
|
-
const
|
|
3066
|
-
return
|
|
3092
|
+
const E = x.length;
|
|
3093
|
+
return w === !0 && E !== b || w === !1 && E !== S ? !1 : !!r.fromBytes(x);
|
|
3067
3094
|
} catch {
|
|
3068
3095
|
return !1;
|
|
3069
3096
|
}
|
|
3070
3097
|
}
|
|
3071
|
-
function a(
|
|
3072
|
-
return kr(F(
|
|
3098
|
+
function a(x = t(n.seed)) {
|
|
3099
|
+
return kr(F(x, n.seed, "seed"), s.ORDER);
|
|
3073
3100
|
}
|
|
3074
|
-
function c(
|
|
3075
|
-
return r.BASE.multiply(s.fromBytes(
|
|
3101
|
+
function c(x, w = !0) {
|
|
3102
|
+
return r.BASE.multiply(s.fromBytes(x)).toBytes(w);
|
|
3076
3103
|
}
|
|
3077
|
-
function l(
|
|
3078
|
-
const { secretKey:
|
|
3079
|
-
if (!at(
|
|
3104
|
+
function l(x) {
|
|
3105
|
+
const { secretKey: w, publicKey: b, publicKeyUncompressed: S } = n;
|
|
3106
|
+
if (!at(x) || "_lengths" in s && s._lengths || w === b)
|
|
3080
3107
|
return;
|
|
3081
|
-
const
|
|
3082
|
-
return
|
|
3108
|
+
const E = F(x, void 0, "key").length;
|
|
3109
|
+
return E === b || E === S;
|
|
3083
3110
|
}
|
|
3084
|
-
function d(
|
|
3085
|
-
if (l(
|
|
3111
|
+
function d(x, w, b = !0) {
|
|
3112
|
+
if (l(x) === !0)
|
|
3086
3113
|
throw new Error("first arg must be private key");
|
|
3087
|
-
if (l(
|
|
3114
|
+
if (l(w) === !1)
|
|
3088
3115
|
throw new Error("second arg must be public key");
|
|
3089
|
-
const
|
|
3090
|
-
return r.fromBytes(
|
|
3116
|
+
const S = s.fromBytes(x);
|
|
3117
|
+
return r.fromBytes(w).multiply(S).toBytes(b);
|
|
3091
3118
|
}
|
|
3092
|
-
const
|
|
3119
|
+
const g = {
|
|
3093
3120
|
isValidSecretKey: o,
|
|
3094
3121
|
isValidPublicKey: i,
|
|
3095
3122
|
randomSecretKey: a
|
|
3096
|
-
},
|
|
3097
|
-
return Object.freeze({ getPublicKey: c, getSharedSecret: d, keygen:
|
|
3123
|
+
}, m = Dr(a, c);
|
|
3124
|
+
return Object.freeze({ getPublicKey: c, getSharedSecret: d, keygen: m, Point: r, utils: g, lengths: n });
|
|
3098
3125
|
}
|
|
3099
3126
|
function Hr(r, e, s = {}) {
|
|
3100
3127
|
Kt(e), ut(s, {}, {
|
|
@@ -3104,52 +3131,52 @@ function Hr(r, e, s = {}) {
|
|
|
3104
3131
|
bits2int: "function",
|
|
3105
3132
|
bits2int_modN: "function"
|
|
3106
3133
|
}), s = Object.assign({}, s);
|
|
3107
|
-
const t = s.randomBytes || Xt, n = s.hmac || ((u, h) => ps(e, u, h)), { Fp: o, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret:
|
|
3134
|
+
const t = s.randomBytes || Xt, n = s.hmac || ((u, h) => ps(e, u, h)), { Fp: o, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret: g, utils: m, lengths: x } = Fr(r, s), w = {
|
|
3108
3135
|
prehash: !0,
|
|
3109
3136
|
lowS: typeof s.lowS == "boolean" ? s.lowS : !0,
|
|
3110
3137
|
format: "compact",
|
|
3111
3138
|
extraEntropy: !1
|
|
3112
|
-
},
|
|
3113
|
-
function
|
|
3139
|
+
}, b = a * _s < o.ORDER;
|
|
3140
|
+
function S(u) {
|
|
3114
3141
|
const h = a >> Ee;
|
|
3115
3142
|
return u > h;
|
|
3116
3143
|
}
|
|
3117
|
-
function
|
|
3144
|
+
function E(u, h) {
|
|
3118
3145
|
if (!i.isValidNot0(h))
|
|
3119
3146
|
throw new Error(`invalid signature ${u}: out of range 1..Point.Fn.ORDER`);
|
|
3120
3147
|
return h;
|
|
3121
3148
|
}
|
|
3122
3149
|
function q() {
|
|
3123
|
-
if (
|
|
3150
|
+
if (b)
|
|
3124
3151
|
throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
3125
3152
|
}
|
|
3126
|
-
function
|
|
3153
|
+
function B(u, h) {
|
|
3127
3154
|
nt(h);
|
|
3128
|
-
const y =
|
|
3129
|
-
return F(u,
|
|
3155
|
+
const y = x.signature, I = h === "compact" ? y : h === "recovered" ? y + 1 : void 0;
|
|
3156
|
+
return F(u, I);
|
|
3130
3157
|
}
|
|
3131
3158
|
class D {
|
|
3132
|
-
constructor(h, y,
|
|
3159
|
+
constructor(h, y, I) {
|
|
3133
3160
|
v(this, "r");
|
|
3134
3161
|
v(this, "s");
|
|
3135
3162
|
v(this, "recovery");
|
|
3136
|
-
if (this.r =
|
|
3137
|
-
if (q(), ![0, 1, 2, 3].includes(
|
|
3163
|
+
if (this.r = E("r", h), this.s = E("s", y), I != null) {
|
|
3164
|
+
if (q(), ![0, 1, 2, 3].includes(I))
|
|
3138
3165
|
throw new Error("invalid recovery id");
|
|
3139
|
-
this.recovery =
|
|
3166
|
+
this.recovery = I;
|
|
3140
3167
|
}
|
|
3141
3168
|
Object.freeze(this);
|
|
3142
3169
|
}
|
|
3143
|
-
static fromBytes(h, y =
|
|
3144
|
-
|
|
3145
|
-
let
|
|
3170
|
+
static fromBytes(h, y = w.format) {
|
|
3171
|
+
B(h, y);
|
|
3172
|
+
let I;
|
|
3146
3173
|
if (y === "der") {
|
|
3147
|
-
const { r:
|
|
3148
|
-
return new D(
|
|
3174
|
+
const { r: T, s: C } = pe.toSig(F(h));
|
|
3175
|
+
return new D(T, C);
|
|
3149
3176
|
}
|
|
3150
|
-
y === "recovered" && (
|
|
3151
|
-
const R =
|
|
3152
|
-
return new D(i.fromBytes(
|
|
3177
|
+
y === "recovered" && (I = h[0], y = "compact", h = h.subarray(1));
|
|
3178
|
+
const R = x.signature / 2, A = h.subarray(0, R), O = h.subarray(R, R * 2);
|
|
3179
|
+
return new D(i.fromBytes(A), i.fromBytes(O), I);
|
|
3153
3180
|
}
|
|
3154
3181
|
static fromHex(h, y) {
|
|
3155
3182
|
return this.fromBytes(Fe(h), y);
|
|
@@ -3164,35 +3191,35 @@ function Hr(r, e, s = {}) {
|
|
|
3164
3191
|
return new D(this.r, this.s, h);
|
|
3165
3192
|
}
|
|
3166
3193
|
recoverPublicKey(h) {
|
|
3167
|
-
const { r: y, s:
|
|
3168
|
-
if (!o.isValid(
|
|
3194
|
+
const { r: y, s: I } = this, R = this.assertRecovery(), A = R === 2 || R === 3 ? y + a : y;
|
|
3195
|
+
if (!o.isValid(A))
|
|
3169
3196
|
throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
3170
|
-
const O = o.toBytes(
|
|
3197
|
+
const O = o.toBytes(A), T = r.fromBytes(_e(xs((R & 1) === 0), O)), C = i.inv(A), N = Q(F(h, void 0, "msgHash")), W = i.create(-N * C), U = i.create(I * C), k = r.BASE.multiplyUnsafe(W).add(T.multiplyUnsafe(U));
|
|
3171
3198
|
if (k.is0())
|
|
3172
3199
|
throw new Error("invalid recovery: point at infinify");
|
|
3173
3200
|
return k.assertValidity(), k;
|
|
3174
3201
|
}
|
|
3175
3202
|
// Signatures should be low-s, to prevent malleability.
|
|
3176
3203
|
hasHighS() {
|
|
3177
|
-
return
|
|
3204
|
+
return S(this.s);
|
|
3178
3205
|
}
|
|
3179
|
-
toBytes(h =
|
|
3206
|
+
toBytes(h = w.format) {
|
|
3180
3207
|
if (nt(h), h === "der")
|
|
3181
3208
|
return Fe(pe.hexFromSig(this));
|
|
3182
|
-
const { r: y, s:
|
|
3183
|
-
return h === "recovered" ? (q(), _e(Uint8Array.of(this.assertRecovery()), R,
|
|
3209
|
+
const { r: y, s: I } = this, R = i.toBytes(y), A = i.toBytes(I);
|
|
3210
|
+
return h === "recovered" ? (q(), _e(Uint8Array.of(this.assertRecovery()), R, A)) : _e(R, A);
|
|
3184
3211
|
}
|
|
3185
3212
|
toHex(h) {
|
|
3186
3213
|
return ke(this.toBytes(h));
|
|
3187
3214
|
}
|
|
3188
3215
|
}
|
|
3189
|
-
const
|
|
3216
|
+
const M = s.bits2int || function(h) {
|
|
3190
3217
|
if (h.length > 8192)
|
|
3191
3218
|
throw new Error("input is too large");
|
|
3192
|
-
const y = je(h),
|
|
3193
|
-
return
|
|
3219
|
+
const y = je(h), I = h.length * 8 - c;
|
|
3220
|
+
return I > 0 ? y >> BigInt(I) : y;
|
|
3194
3221
|
}, Q = s.bits2int_modN || function(h) {
|
|
3195
|
-
return i.create(
|
|
3222
|
+
return i.create(M(h));
|
|
3196
3223
|
}, ve = dt(c);
|
|
3197
3224
|
function he(u) {
|
|
3198
3225
|
return mr("num < 2^" + c, u, le, ve), i.toBytes(u);
|
|
@@ -3201,63 +3228,63 @@ function Hr(r, e, s = {}) {
|
|
|
3201
3228
|
return F(u, void 0, "message"), h ? F(e(u), void 0, "prehashed message") : u;
|
|
3202
3229
|
}
|
|
3203
3230
|
function xe(u, h, y) {
|
|
3204
|
-
const { lowS:
|
|
3231
|
+
const { lowS: I, prehash: R, extraEntropy: A } = et(y, w);
|
|
3205
3232
|
u = Z(u, R);
|
|
3206
|
-
const O = Q(u),
|
|
3207
|
-
if (!i.isValidNot0(
|
|
3233
|
+
const O = Q(u), T = i.fromBytes(h);
|
|
3234
|
+
if (!i.isValidNot0(T))
|
|
3208
3235
|
throw new Error("invalid private key");
|
|
3209
|
-
const C = [he(
|
|
3210
|
-
if (
|
|
3211
|
-
const k =
|
|
3236
|
+
const C = [he(T), he(O)];
|
|
3237
|
+
if (A != null && A !== !1) {
|
|
3238
|
+
const k = A === !0 ? t(x.secretKey) : A;
|
|
3212
3239
|
C.push(F(k, void 0, "extraEntropy"));
|
|
3213
3240
|
}
|
|
3214
3241
|
const N = _e(...C), W = O;
|
|
3215
3242
|
function U(k) {
|
|
3216
|
-
const j =
|
|
3243
|
+
const j = M(k);
|
|
3217
3244
|
if (!i.isValidNot0(j))
|
|
3218
3245
|
return;
|
|
3219
3246
|
const V = i.inv(j), ee = r.BASE.multiply(j).toAffine(), H = i.create(ee.x);
|
|
3220
3247
|
if (H === le)
|
|
3221
3248
|
return;
|
|
3222
|
-
const K = i.create(V * i.create(W + H *
|
|
3249
|
+
const K = i.create(V * i.create(W + H * T));
|
|
3223
3250
|
if (K === le)
|
|
3224
3251
|
return;
|
|
3225
3252
|
let xt = (ee.x === H ? 0 : 2) | Number(ee.y & Ee), mt = K;
|
|
3226
|
-
return
|
|
3253
|
+
return I && S(K) && (mt = i.neg(K), xt ^= 1), new D(H, mt, b ? void 0 : xt);
|
|
3227
3254
|
}
|
|
3228
3255
|
return { seed: N, k2sig: U };
|
|
3229
3256
|
}
|
|
3230
3257
|
function ne(u, h, y = {}) {
|
|
3231
|
-
const { seed:
|
|
3232
|
-
return yr(e.outputLen, i.BYTES, n)(
|
|
3233
|
-
}
|
|
3234
|
-
function L(u, h, y,
|
|
3235
|
-
const { lowS: R, prehash:
|
|
3236
|
-
if (y = F(y, void 0, "publicKey"), h = Z(h,
|
|
3237
|
-
const
|
|
3238
|
-
throw new Error("verify expects Uint8Array signature" +
|
|
3258
|
+
const { seed: I, k2sig: R } = xe(u, h, y);
|
|
3259
|
+
return yr(e.outputLen, i.BYTES, n)(I, R).toBytes(y.format);
|
|
3260
|
+
}
|
|
3261
|
+
function L(u, h, y, I = {}) {
|
|
3262
|
+
const { lowS: R, prehash: A, format: O } = et(I, w);
|
|
3263
|
+
if (y = F(y, void 0, "publicKey"), h = Z(h, A), !at(u)) {
|
|
3264
|
+
const T = u instanceof D ? ", use sig.toBytes()" : "";
|
|
3265
|
+
throw new Error("verify expects Uint8Array signature" + T);
|
|
3239
3266
|
}
|
|
3240
|
-
|
|
3267
|
+
B(u, O);
|
|
3241
3268
|
try {
|
|
3242
|
-
const
|
|
3243
|
-
if (R &&
|
|
3269
|
+
const T = D.fromBytes(u, O), C = r.fromBytes(y);
|
|
3270
|
+
if (R && T.hasHighS())
|
|
3244
3271
|
return !1;
|
|
3245
|
-
const { r: N, s: W } =
|
|
3272
|
+
const { r: N, s: W } = T, U = Q(h), k = i.inv(W), j = i.create(U * k), V = i.create(N * k), ee = r.BASE.multiplyUnsafe(j).add(C.multiplyUnsafe(V));
|
|
3246
3273
|
return ee.is0() ? !1 : i.create(ee.x) === N;
|
|
3247
3274
|
} catch {
|
|
3248
3275
|
return !1;
|
|
3249
3276
|
}
|
|
3250
3277
|
}
|
|
3251
3278
|
function P(u, h, y = {}) {
|
|
3252
|
-
const { prehash:
|
|
3253
|
-
return h = Z(h,
|
|
3279
|
+
const { prehash: I } = et(y, w);
|
|
3280
|
+
return h = Z(h, I), D.fromBytes(u, "recovered").recoverPublicKey(h).toBytes();
|
|
3254
3281
|
}
|
|
3255
3282
|
return Object.freeze({
|
|
3256
3283
|
keygen: l,
|
|
3257
3284
|
getPublicKey: d,
|
|
3258
|
-
getSharedSecret:
|
|
3259
|
-
utils:
|
|
3260
|
-
lengths:
|
|
3285
|
+
getSharedSecret: g,
|
|
3286
|
+
utils: m,
|
|
3287
|
+
lengths: x,
|
|
3261
3288
|
Point: r,
|
|
3262
3289
|
sign: ne,
|
|
3263
3290
|
verify: L,
|
|
@@ -3283,7 +3310,7 @@ const ft = {
|
|
|
3283
3310
|
]
|
|
3284
3311
|
}, Ut = /* @__PURE__ */ BigInt(2);
|
|
3285
3312
|
function qr(r) {
|
|
3286
|
-
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,
|
|
3313
|
+
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, g = se(d, s, e) * d % e, m = se(g, s, e) * d % e, x = se(m, Ut, e) * l % e, w = se(x, n, e) * x % e, b = se(w, o, e) * w % e, S = se(b, a, e) * b % e, E = se(S, c, e) * S % e, q = se(E, a, e) * b % e, B = se(q, s, e) * d % e, D = se(B, i, e) * w % e, M = se(D, t, e) * l % e, Q = se(M, Ut, e);
|
|
3287
3314
|
if (!ot.eql(ot.sqr(Q), r))
|
|
3288
3315
|
throw new Error("Cannot find square root");
|
|
3289
3316
|
return Q;
|
|
@@ -3306,9 +3333,9 @@ function Qr(r, e = 24) {
|
|
|
3306
3333
|
for (let i = 0; i < 10; i++)
|
|
3307
3334
|
s[i] = r[i] ^ r[i + 10] ^ r[i + 20] ^ r[i + 30] ^ r[i + 40];
|
|
3308
3335
|
for (let i = 0; i < 10; i += 2) {
|
|
3309
|
-
const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1],
|
|
3310
|
-
for (let
|
|
3311
|
-
r[i +
|
|
3336
|
+
const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1], g = Ft(l, d, 1) ^ s[a], m = Ht(l, d, 1) ^ s[a + 1];
|
|
3337
|
+
for (let x = 0; x < 50; x += 10)
|
|
3338
|
+
r[i + x] ^= g, r[i + x + 1] ^= m;
|
|
3312
3339
|
}
|
|
3313
3340
|
let n = r[2], o = r[3];
|
|
3314
3341
|
for (let i = 0; i < 24; i++) {
|
|
@@ -3406,20 +3433,20 @@ class tn {
|
|
|
3406
3433
|
async verifyJWT(e, s) {
|
|
3407
3434
|
try {
|
|
3408
3435
|
const t = this.decodeJWT(e);
|
|
3409
|
-
|
|
3436
|
+
f.log("[CROSSx] JWT 디코딩 성공:", {
|
|
3410
3437
|
sub: t.sub,
|
|
3411
3438
|
exp: t.exp,
|
|
3412
3439
|
iat: t.iat,
|
|
3413
3440
|
"현재 시간": Math.floor(Date.now() / 1e3)
|
|
3414
3441
|
});
|
|
3415
3442
|
const n = Math.floor(Date.now() / 1e3);
|
|
3416
|
-
return t.exp && t.exp < n ? (
|
|
3443
|
+
return t.exp && t.exp < n ? (f.warn("[CROSSx] 토큰 만료:", {
|
|
3417
3444
|
exp: t.exp,
|
|
3418
3445
|
now: n,
|
|
3419
3446
|
만료시간: new Date(t.exp * 1e3).toISOString()
|
|
3420
|
-
}), { payload: t, valid: !1, signatureVerified: !1 }) : t.sub ? (
|
|
3447
|
+
}), { payload: t, valid: !1, signatureVerified: !1 }) : t.sub ? (f.log("[CROSSx] JWT 검증 성공 (서명 미검증 — JWKS 미구현)"), { payload: t, valid: !0, signatureVerified: !1 }) : (f.warn("[CROSSx] JWT에 sub(사용자ID) 없음"), { payload: t, valid: !1, signatureVerified: !1 });
|
|
3421
3448
|
} catch (t) {
|
|
3422
|
-
throw
|
|
3449
|
+
throw f.error("[CROSSx] JWT 검증 중 에러:", t), t;
|
|
3423
3450
|
}
|
|
3424
3451
|
}
|
|
3425
3452
|
decodeJWT(e) {
|
|
@@ -3441,11 +3468,11 @@ ${t.length}`
|
|
|
3441
3468
|
const i = Gt(o), a = s.startsWith("0x") ? s.slice(2) : s;
|
|
3442
3469
|
if (a.length !== 130)
|
|
3443
3470
|
throw new Error(`Invalid signature length: expected 130 hex chars, got ${a.length}`);
|
|
3444
|
-
const c = sn(a), l = c.slice(0, 32), d = c.slice(32, 64),
|
|
3471
|
+
const c = sn(a), l = c.slice(0, 32), d = c.slice(32, 64), g = c[64], m = g >= 27 ? g - 27 : g, b = new jr.Signature(
|
|
3445
3472
|
qt(l),
|
|
3446
3473
|
qt(d)
|
|
3447
|
-
).addRecoveryBit(
|
|
3448
|
-
return "0x" + ke(
|
|
3474
|
+
).addRecoveryBit(m).recoverPublicKey(i).toBytes(!1).slice(1), S = Gt(b);
|
|
3475
|
+
return "0x" + ke(S.slice(12));
|
|
3449
3476
|
}
|
|
3450
3477
|
}
|
|
3451
3478
|
function sn(r) {
|
|
@@ -3498,51 +3525,51 @@ class pt {
|
|
|
3498
3525
|
}
|
|
3499
3526
|
openAuth(e) {
|
|
3500
3527
|
return new Promise((s, t) => {
|
|
3501
|
-
const n = e.width ?? 500, o = e.height ?? 600, i = window.screenX + (window.outerWidth - n) / 2, a = window.screenY + (window.outerHeight - o) / 2, c = pt.generateState(), l = e.authUrl.includes("?") ? "&" : "?", d = `${e.authUrl}${l}state=${c}`,
|
|
3528
|
+
const n = e.width ?? 500, o = e.height ?? 600, i = window.screenX + (window.outerWidth - n) / 2, a = window.screenY + (window.outerHeight - o) / 2, c = pt.generateState(), l = e.authUrl.includes("?") ? "&" : "?", d = `${e.authUrl}${l}state=${c}`, g = window.open(
|
|
3502
3529
|
d,
|
|
3503
3530
|
"CROSSx OAuth",
|
|
3504
3531
|
`width=${n},height=${o},left=${i},top=${a}`
|
|
3505
3532
|
);
|
|
3506
|
-
if (!
|
|
3533
|
+
if (!g) {
|
|
3507
3534
|
t(new Error("팝업 창을 열 수 없습니다. 팝업 차단을 해제해 주세요."));
|
|
3508
3535
|
return;
|
|
3509
3536
|
}
|
|
3510
|
-
const
|
|
3511
|
-
|
|
3512
|
-
}, 5 * 60 * 1e3),
|
|
3513
|
-
let
|
|
3514
|
-
const
|
|
3515
|
-
clearInterval(q),
|
|
3516
|
-
|
|
3537
|
+
const m = setTimeout(() => {
|
|
3538
|
+
f.warn("[CROSSx] OAuth 타임아웃 (5분) — postMessage를 수신하지 못했습니다"), B(), t(new Error("Authentication timeout"));
|
|
3539
|
+
}, 5 * 60 * 1e3), x = 10, w = 30;
|
|
3540
|
+
let b = 0, S = null;
|
|
3541
|
+
const E = () => {
|
|
3542
|
+
clearInterval(q), f.warn("[CROSSx] COOP 감지 — OAuth 서버 응답을 " + w + "초간 대기합니다"), S = setTimeout(() => {
|
|
3543
|
+
B(), t(new Error(
|
|
3517
3544
|
"OAuth 서버로부터 응답을 받지 못했습니다. 브라우저 보안 정책(COOP)으로 인해 팝업 통신이 차단되었을 수 있습니다. 다시 시도해 주세요."
|
|
3518
3545
|
));
|
|
3519
|
-
},
|
|
3546
|
+
}, w * 1e3);
|
|
3520
3547
|
}, q = setInterval(() => {
|
|
3521
|
-
|
|
3548
|
+
b++;
|
|
3522
3549
|
try {
|
|
3523
|
-
|
|
3550
|
+
g.closed && (b <= x ? E() : (B(), t(new Error("로그인이 취소되었습니다"))));
|
|
3524
3551
|
} catch {
|
|
3525
|
-
|
|
3552
|
+
E();
|
|
3526
3553
|
}
|
|
3527
|
-
}, 1e3),
|
|
3528
|
-
clearTimeout(
|
|
3529
|
-
}, D = (
|
|
3554
|
+
}, 1e3), B = () => {
|
|
3555
|
+
clearTimeout(m), clearInterval(q), S && clearTimeout(S), window.removeEventListener("message", D);
|
|
3556
|
+
}, D = (M) => {
|
|
3530
3557
|
var ve, he, Z, xe, ne, L, P;
|
|
3531
|
-
if (
|
|
3532
|
-
|
|
3533
|
-
const Q =
|
|
3558
|
+
if (M.origin !== e.expectedOrigin) return;
|
|
3559
|
+
B(), f.log("[CROSSx] OAuth postMessage 수신 — status:", M.data.status);
|
|
3560
|
+
const Q = M.data.state ?? ((ve = M.data.data) == null ? void 0 : ve.state);
|
|
3534
3561
|
if (!Q || Q !== c) {
|
|
3535
3562
|
t(new Error("OAuth state mismatch — possible CSRF attack"));
|
|
3536
3563
|
return;
|
|
3537
3564
|
}
|
|
3538
|
-
if (
|
|
3539
|
-
const u = ((he =
|
|
3540
|
-
|
|
3541
|
-
hasAccessToken: !!((xe =
|
|
3542
|
-
hasIdToken: !!((ne =
|
|
3543
|
-
}), u ? s(u) : (
|
|
3565
|
+
if (M.data.status === "success") {
|
|
3566
|
+
const u = ((he = M.data.data) == null ? void 0 : he.accessToken) || ((Z = M.data.data) == null ? void 0 : Z.idToken);
|
|
3567
|
+
f.log("[CROSSx] OAuth 토큰 수신:", {
|
|
3568
|
+
hasAccessToken: !!((xe = M.data.data) != null && xe.accessToken),
|
|
3569
|
+
hasIdToken: !!((ne = M.data.data) != null && ne.idToken)
|
|
3570
|
+
}), u ? s(u) : (f.error("[CROSSx] 토큰을 찾을 수 없음:", M.data), t(new Error("Token not found in response")));
|
|
3544
3571
|
} else
|
|
3545
|
-
|
|
3572
|
+
f.error("[CROSSx] OAuth 실패:", (L = M.data.data) == null ? void 0 : L.error), t(new Error(((P = M.data.data) == null ? void 0 : P.error) || "Authentication failed"));
|
|
3546
3573
|
};
|
|
3547
3574
|
window.addEventListener("message", D);
|
|
3548
3575
|
});
|
|
@@ -3565,7 +3592,7 @@ class on {
|
|
|
3565
3592
|
};
|
|
3566
3593
|
return await this.storage.set(Oe, t), t;
|
|
3567
3594
|
} catch (s) {
|
|
3568
|
-
throw new
|
|
3595
|
+
throw new _(p.WALLET_CREATION_FAILED, "Wallet creation failed", s);
|
|
3569
3596
|
}
|
|
3570
3597
|
}
|
|
3571
3598
|
async getAddresses(e) {
|
|
@@ -3580,24 +3607,24 @@ class on {
|
|
|
3580
3607
|
}
|
|
3581
3608
|
async prepare(e, s) {
|
|
3582
3609
|
const t = "mock-" + crypto.randomUUID();
|
|
3583
|
-
return
|
|
3610
|
+
return f.log(`[Mock] prepare action=${e} → uuid=${t}`), { uuid: t, expiresAt: new Date(Date.now() + 5 * 6e4).toISOString() };
|
|
3584
3611
|
}
|
|
3585
3612
|
async signMessage(e, s, t, n = 0, o, i) {
|
|
3586
|
-
return
|
|
3613
|
+
return f.log(`[Mock] signMessage chainId=${s} index=${n} uuid=${o} from=${i}: "${t}"`), { chainId: s, signature: this.generateMockSignature(), format: "hex" };
|
|
3587
3614
|
}
|
|
3588
3615
|
async signTypedData(e, s, t, n = 0, o, i) {
|
|
3589
|
-
return
|
|
3616
|
+
return f.log(`[Mock] signTypedData chainId=${s} index=${n} uuid=${o} from=${i}`), { chainId: s, signature: this.generateMockSignature(), format: "hex" };
|
|
3590
3617
|
}
|
|
3591
3618
|
async signTransaction(e, s, t, n = 0, o) {
|
|
3592
|
-
|
|
3619
|
+
f.log(`[Mock] signTransaction chainId=${s} index=${n} uuid=${o}:`, t);
|
|
3593
3620
|
const i = "0x" + Array(64).fill(0).map(() => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
3594
3621
|
return { chainId: s, signature: this.generateMockSignature(), txHash: i, format: "hex" };
|
|
3595
3622
|
}
|
|
3596
3623
|
async sendTransaction(e, s, t, n) {
|
|
3597
|
-
return
|
|
3624
|
+
return f.log(`[Mock] sendTransaction chainId=${s} uuid=${n}:`, t), { txHash: "0x" + Array(64).fill(0).map(() => Math.floor(Math.random() * 16).toString(16)).join("") };
|
|
3598
3625
|
}
|
|
3599
3626
|
async recoverWallet(e, s) {
|
|
3600
|
-
|
|
3627
|
+
f.log("[Mock] recoverWallet");
|
|
3601
3628
|
const t = {
|
|
3602
3629
|
id: e,
|
|
3603
3630
|
address: this.generateMockEvmAddress(),
|
|
@@ -3607,7 +3634,7 @@ class on {
|
|
|
3607
3634
|
return await this.storage.set(Oe, t), t;
|
|
3608
3635
|
}
|
|
3609
3636
|
async migrateWallet(e, s) {
|
|
3610
|
-
|
|
3637
|
+
f.log(`[Mock] migrateWallet pin=${e} sub=${s}`);
|
|
3611
3638
|
const t = {
|
|
3612
3639
|
id: s,
|
|
3613
3640
|
address: this.generateMockEvmAddress(),
|
|
@@ -3637,7 +3664,7 @@ class qe {
|
|
|
3637
3664
|
getAuthToken() {
|
|
3638
3665
|
const e = this.tokenStore.get();
|
|
3639
3666
|
if (!e)
|
|
3640
|
-
throw new
|
|
3667
|
+
throw new _(
|
|
3641
3668
|
p.AUTH_NOT_AUTHENTICATED,
|
|
3642
3669
|
"No auth token found. Please sign in first."
|
|
3643
3670
|
);
|
|
@@ -3659,33 +3686,33 @@ class qe {
|
|
|
3659
3686
|
})).data;
|
|
3660
3687
|
if (d && typeof d.code == "number") {
|
|
3661
3688
|
if (d.code < 0 || d.code >= 400) {
|
|
3662
|
-
const
|
|
3663
|
-
|
|
3689
|
+
const g = d.message || d.data || "API request failed";
|
|
3690
|
+
f.error("[CROSSx] Wallet Gateway API 에러 (HTTP 200):", {
|
|
3664
3691
|
code: d.code,
|
|
3665
|
-
message:
|
|
3692
|
+
message: g,
|
|
3666
3693
|
url: o,
|
|
3667
3694
|
method: e,
|
|
3668
3695
|
fullResponse: d
|
|
3669
3696
|
});
|
|
3670
|
-
const
|
|
3671
|
-
throw
|
|
3697
|
+
const m = qe.mapGatewayError(d.code), x = qe.getGatewayErrorMessage(d.code, g), w = new _(m, x);
|
|
3698
|
+
throw w.gatewayCode = d.code, w.gatewayMessage = g, w;
|
|
3672
3699
|
}
|
|
3673
|
-
return
|
|
3700
|
+
return f.log("[CROSSx] Wallet Gateway API 성공:", { code: d.code, url: o, method: e }), d.data ?? d;
|
|
3674
3701
|
}
|
|
3675
3702
|
return d;
|
|
3676
3703
|
} catch (l) {
|
|
3677
|
-
if (l instanceof
|
|
3704
|
+
if (l instanceof _) throw l;
|
|
3678
3705
|
if ((a = l.response) != null && a.data) {
|
|
3679
|
-
const d = l.response.data,
|
|
3680
|
-
throw
|
|
3681
|
-
code:
|
|
3682
|
-
message:
|
|
3706
|
+
const d = l.response.data, g = d.message || d.data || "API request failed", m = d.code || "UNKNOWN";
|
|
3707
|
+
throw f.error("[CROSSx] Wallet Gateway API 에러 (HTTP 에러):", {
|
|
3708
|
+
code: m,
|
|
3709
|
+
message: g,
|
|
3683
3710
|
url: o,
|
|
3684
3711
|
method: e,
|
|
3685
3712
|
status: (c = l.response) == null ? void 0 : c.status
|
|
3686
|
-
}), new
|
|
3713
|
+
}), new _(
|
|
3687
3714
|
p.UNKNOWN_ERROR,
|
|
3688
|
-
`Wallet Gateway error (${
|
|
3715
|
+
`Wallet Gateway error (${m}): ${g}`
|
|
3689
3716
|
);
|
|
3690
3717
|
}
|
|
3691
3718
|
throw l;
|
|
@@ -3693,12 +3720,12 @@ class qe {
|
|
|
3693
3720
|
}
|
|
3694
3721
|
async getOrCreateWallet(e) {
|
|
3695
3722
|
var s;
|
|
3696
|
-
|
|
3723
|
+
f.log("[CROSSx][Migration Phase 2] GET /mnemonic/addresses — 기존 지갑 조회");
|
|
3697
3724
|
try {
|
|
3698
3725
|
const t = await this.request("GET", "/mnemonic/addresses");
|
|
3699
3726
|
if (t.addresses && t.addresses.length > 0) {
|
|
3700
3727
|
const { address: n } = t.addresses[0];
|
|
3701
|
-
return
|
|
3728
|
+
return f.log("[CROSSx][Migration Phase 2] 기존 지갑 발견 — address:", n), {
|
|
3702
3729
|
id: e,
|
|
3703
3730
|
address: n,
|
|
3704
3731
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -3706,12 +3733,12 @@ class qe {
|
|
|
3706
3733
|
};
|
|
3707
3734
|
}
|
|
3708
3735
|
} catch {
|
|
3709
|
-
|
|
3736
|
+
f.log("[CROSSx][Migration Phase 2] 기존 지갑 없음, POST /mnemonic/create 진행");
|
|
3710
3737
|
}
|
|
3711
|
-
|
|
3738
|
+
f.log("[CROSSx][Migration Phase 2] POST /mnemonic/create — ignoreBackup: false");
|
|
3712
3739
|
try {
|
|
3713
3740
|
const t = { ignoreBackup: !1 }, n = await this.request("POST", "/mnemonic/create", t);
|
|
3714
|
-
return
|
|
3741
|
+
return f.log("[CROSSx][Migration Phase 2] /mnemonic/create 성공 — address:", n.address), {
|
|
3715
3742
|
id: e,
|
|
3716
3743
|
address: n.address,
|
|
3717
3744
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -3719,7 +3746,7 @@ class qe {
|
|
|
3719
3746
|
};
|
|
3720
3747
|
} catch (t) {
|
|
3721
3748
|
if ((t == null ? void 0 : t.gatewayCode) === -10004 || (s = t == null ? void 0 : t.message) != null && s.includes("-10004")) {
|
|
3722
|
-
|
|
3749
|
+
f.log("[CROSSx][Migration Phase 2] 지갑 이미 존재 (-10004), 주소 재조회");
|
|
3723
3750
|
const n = await this.request("GET", "/mnemonic/addresses");
|
|
3724
3751
|
if (n.addresses && n.addresses.length > 0)
|
|
3725
3752
|
return {
|
|
@@ -3729,7 +3756,7 @@ class qe {
|
|
|
3729
3756
|
createdAt: Date.now()
|
|
3730
3757
|
};
|
|
3731
3758
|
}
|
|
3732
|
-
throw (t == null ? void 0 : t.gatewayCode) === -10012 &&
|
|
3759
|
+
throw (t == null ? void 0 : t.gatewayCode) === -10012 && f.log("[CROSSx][Migration Phase 2] Gateway -10012 수신 → MIGRATION_BACKUP_EXISTS throw"), t;
|
|
3733
3760
|
}
|
|
3734
3761
|
}
|
|
3735
3762
|
async getAddresses(e) {
|
|
@@ -3742,8 +3769,8 @@ class qe {
|
|
|
3742
3769
|
`/mnemonic/address?index=${s}`
|
|
3743
3770
|
)).address, derivationPath: `m/44'/60'/0'/0/${s}` };
|
|
3744
3771
|
} catch (t) {
|
|
3745
|
-
if (t instanceof
|
|
3746
|
-
return
|
|
3772
|
+
if (t instanceof _ && this.isAddressNotFoundError(t))
|
|
3773
|
+
return f.log(`[CROSSx] index ${s} 주소 없음, 파생 중...`), { address: (await this.request(
|
|
3747
3774
|
"GET",
|
|
3748
3775
|
`/mnemonic/address?index=${s}&derive=true`
|
|
3749
3776
|
)).address, derivationPath: `m/44'/60'/0'/0/${s}` };
|
|
@@ -3759,15 +3786,15 @@ class qe {
|
|
|
3759
3786
|
switch (e) {
|
|
3760
3787
|
case "sign":
|
|
3761
3788
|
case "send":
|
|
3762
|
-
if (!s.tx) throw new
|
|
3789
|
+
if (!s.tx) throw new _(p.TX_INVALID_PARAMS, "prepare: tx is required");
|
|
3763
3790
|
t = { unsignedTx: this.buildUnsignedTx(s.tx) };
|
|
3764
3791
|
break;
|
|
3765
3792
|
case "sign-message":
|
|
3766
|
-
if (!s.message) throw new
|
|
3793
|
+
if (!s.message) throw new _(p.TX_INVALID_PARAMS, "prepare: message is required");
|
|
3767
3794
|
t = { message: s.message }, s.from && (t.from = s.from);
|
|
3768
3795
|
break;
|
|
3769
3796
|
case "sign-typed-data":
|
|
3770
|
-
if (!s.typedData) throw new
|
|
3797
|
+
if (!s.typedData) throw new _(p.TX_INVALID_PARAMS, "prepare: typedData is required");
|
|
3771
3798
|
t = { typedData: s.typedData }, s.from && (t.from = s.from);
|
|
3772
3799
|
break;
|
|
3773
3800
|
}
|
|
@@ -3839,13 +3866,13 @@ class qe {
|
|
|
3839
3866
|
};
|
|
3840
3867
|
}
|
|
3841
3868
|
async migrateWallet(e, s) {
|
|
3842
|
-
|
|
3869
|
+
f.log("[CROSSx][Migration Phase 4] POST /mnemonic/migrate 호출 — sub:", s);
|
|
3843
3870
|
const t = { pin: e, sub: s }, n = await this.request(
|
|
3844
3871
|
"POST",
|
|
3845
3872
|
"/mnemonic/migrate",
|
|
3846
3873
|
t
|
|
3847
3874
|
);
|
|
3848
|
-
return
|
|
3875
|
+
return f.log("[CROSSx][Migration Phase 4] /mnemonic/migrate 완료 — address:", n.address), {
|
|
3849
3876
|
id: s,
|
|
3850
3877
|
address: n.address,
|
|
3851
3878
|
derivationPath: "m/44'/60'/0'/0/0",
|
|
@@ -3962,7 +3989,7 @@ class Ce {
|
|
|
3962
3989
|
handleEnvelopeError(e) {
|
|
3963
3990
|
if (e.code < 0) {
|
|
3964
3991
|
const s = typeof e.data == "string" ? e.data : e.message ?? "Chain registry request failed";
|
|
3965
|
-
throw new
|
|
3992
|
+
throw new _(
|
|
3966
3993
|
Ce.mapErrorCode(e.code),
|
|
3967
3994
|
s
|
|
3968
3995
|
);
|
|
@@ -3973,7 +4000,7 @@ class Ce {
|
|
|
3973
4000
|
(t) => t.chainId === e
|
|
3974
4001
|
);
|
|
3975
4002
|
if (s) return s;
|
|
3976
|
-
throw new
|
|
4003
|
+
throw new _(
|
|
3977
4004
|
p.CHAIN_NOT_SUPPORTED,
|
|
3978
4005
|
`Unsupported chain: ${e}`
|
|
3979
4006
|
);
|
|
@@ -4805,6 +4832,10 @@ const cn = `
|
|
|
4805
4832
|
overflow-y: auto;
|
|
4806
4833
|
animation: __crossx-slide-up-mobile 0.25s ease;
|
|
4807
4834
|
}
|
|
4835
|
+
.__crossx-card--wallet-selector {
|
|
4836
|
+
overflow: hidden !important;
|
|
4837
|
+
}
|
|
4838
|
+
.__crossx-card--wallet-selector .__crossx-wallet-list { max-height: 203px; }
|
|
4808
4839
|
.__crossx-login-btn-row {
|
|
4809
4840
|
flex-direction: column;
|
|
4810
4841
|
}
|
|
@@ -4838,7 +4869,7 @@ const cn = `
|
|
|
4838
4869
|
|
|
4839
4870
|
/* ── Landscape for signing/transaction modals ──────────── */
|
|
4840
4871
|
@media (orientation: landscape) and (max-height: 500px) {
|
|
4841
|
-
#${te} { align-items: center !important; }
|
|
4872
|
+
#${te} { align-items: center !important; overflow: hidden; }
|
|
4842
4873
|
.__crossx-card--send-tx,
|
|
4843
4874
|
.__crossx-card--sign-tx,
|
|
4844
4875
|
.__crossx-card--sign-msg,
|
|
@@ -4888,12 +4919,38 @@ const cn = `
|
|
|
4888
4919
|
.__crossx-card--sign-msg .__crossx-msg-box { max-height: 130px; }
|
|
4889
4920
|
.__crossx-card--sign-typed .__crossx-td-rows { max-height: 130px; overflow-y: auto; }
|
|
4890
4921
|
.__crossx-col-left > .__crossx-divider { display: none; }
|
|
4891
|
-
.__crossx-
|
|
4922
|
+
.__crossx-card--wallet-selector {
|
|
4923
|
+
overflow: hidden !important;
|
|
4924
|
+
display: flex !important;
|
|
4925
|
+
flex-direction: column !important;
|
|
4926
|
+
}
|
|
4927
|
+
.__crossx-card--wallet-selector .__crossx-header { flex-shrink: 0; }
|
|
4928
|
+
.__crossx-card--wallet-selector > .__crossx-divider { flex-shrink: 0; }
|
|
4929
|
+
.__crossx-card--wallet-selector .__crossx-body {
|
|
4930
|
+
flex: 1;
|
|
4931
|
+
min-height: 0;
|
|
4932
|
+
overflow: hidden;
|
|
4933
|
+
display: flex;
|
|
4934
|
+
flex-direction: column;
|
|
4935
|
+
}
|
|
4936
|
+
.__crossx-card--wallet-selector .__crossx-body-cols {
|
|
4937
|
+
flex: 1;
|
|
4938
|
+
min-height: 0;
|
|
4939
|
+
align-items: stretch !important;
|
|
4940
|
+
}
|
|
4941
|
+
.__crossx-card--wallet-selector .__crossx-col-right-ws {
|
|
4892
4942
|
display: flex;
|
|
4893
4943
|
flex-direction: column;
|
|
4894
4944
|
gap: 8px;
|
|
4945
|
+
min-height: 0;
|
|
4946
|
+
overflow: hidden;
|
|
4947
|
+
}
|
|
4948
|
+
.__crossx-card--wallet-selector .__crossx-wallet-list {
|
|
4949
|
+
max-height: none;
|
|
4950
|
+
flex: 1;
|
|
4951
|
+
min-height: 0;
|
|
4895
4952
|
}
|
|
4896
|
-
.__crossx-card--wallet-selector .__crossx-wallet-
|
|
4953
|
+
.__crossx-card--wallet-selector .__crossx-wallet-add { flex-shrink: 0; }
|
|
4897
4954
|
}
|
|
4898
4955
|
`;
|
|
4899
4956
|
function me() {
|
|
@@ -5194,19 +5251,19 @@ function yn(r, e) {
|
|
|
5194
5251
|
function bn(r, e, s) {
|
|
5195
5252
|
const t = e.status !== "reverted" && e.status !== "timeout", n = e.status === "timeout", o = r.querySelector("#__crossx-ttl"), i = r.querySelector(".__crossx-header");
|
|
5196
5253
|
if (o) {
|
|
5197
|
-
const
|
|
5198
|
-
|
|
5254
|
+
const w = n ? gn : t ? "" : fn, b = n ? "Transaction timeout" : t ? "Transaction complete" : "Transaction failed";
|
|
5255
|
+
w ? (o.style.display = "flex", o.style.alignItems = "center", o.style.gap = "8px", o.innerHTML = `${w}<span>${b}</span>`) : o.textContent = b;
|
|
5199
5256
|
}
|
|
5200
5257
|
if (i && !r.querySelector("#__crossx-close-btn")) {
|
|
5201
|
-
const
|
|
5202
|
-
|
|
5258
|
+
const w = document.createElement("button");
|
|
5259
|
+
w.className = "__crossx-close", w.id = "__crossx-close-btn", w.setAttribute("aria-label", "Close"), w.innerHTML = ie, i.appendChild(w);
|
|
5203
5260
|
}
|
|
5204
5261
|
const a = r.querySelector("#__crossx-progress-body");
|
|
5205
5262
|
if (!a) return;
|
|
5206
5263
|
const c = e.from ? G("From", `<span class="__crossx-addr-text">${Y(e.from)}</span>
|
|
5207
5264
|
<button class="__crossx-copy-btn" data-copy="${$(e.from)}" title="Copy address">${de}</button>`) : "", l = e.to ? G("To", `<span class="__crossx-addr-text">${Y(e.to)}</span>
|
|
5208
|
-
<button class="__crossx-copy-btn" data-copy="${$(e.to)}" title="Copy address">${de}</button>`) : "", d = e.amount ? G("Transfer", `<span>${$(e.amount)}</span>`) : "",
|
|
5209
|
-
<button class="__crossx-copy-btn" data-copy="${$(e.txHash)}" title="Copy hash">${de}</button>`) : "",
|
|
5265
|
+
<button class="__crossx-copy-btn" data-copy="${$(e.to)}" title="Copy address">${de}</button>`) : "", d = e.amount ? G("Transfer", `<span>${$(e.amount)}</span>`) : "", g = e.fees ? G("Tx Fee", `<span>${$(e.fees)}</span>`) : "", m = e.txHash ? G("Tx Hash", `<span class="__crossx-addr-text">${Y(e.txHash)}</span>
|
|
5266
|
+
<button class="__crossx-copy-btn" data-copy="${$(e.txHash)}" title="Copy hash">${de}</button>`) : "", x = e.total ? `<div class="__crossx-total-pill">
|
|
5210
5267
|
<span class="__crossx-total-label">Total<br>(including fees)</span>
|
|
5211
5268
|
<span class="__crossx-total-amount">${$(e.total)}</span>
|
|
5212
5269
|
</div>` : "";
|
|
@@ -5215,17 +5272,17 @@ function bn(r, e, s) {
|
|
|
5215
5272
|
${c}
|
|
5216
5273
|
${l}
|
|
5217
5274
|
${d}
|
|
5218
|
-
${
|
|
5219
|
-
${
|
|
5275
|
+
${g}
|
|
5276
|
+
${m}
|
|
5220
5277
|
</div>
|
|
5221
|
-
${
|
|
5278
|
+
${x}
|
|
5222
5279
|
<button class="__crossx-approve-btn" id="__crossx-done-btn">${t ? "All Done" : "Done"}</button>
|
|
5223
|
-
`, a.querySelectorAll(".__crossx-copy-btn").forEach((
|
|
5224
|
-
|
|
5225
|
-
var
|
|
5226
|
-
|
|
5227
|
-
const
|
|
5228
|
-
|
|
5280
|
+
`, a.querySelectorAll(".__crossx-copy-btn").forEach((w) => {
|
|
5281
|
+
w.addEventListener("click", (b) => {
|
|
5282
|
+
var E;
|
|
5283
|
+
b.stopPropagation();
|
|
5284
|
+
const S = w.dataset.copy;
|
|
5285
|
+
S && ((E = navigator.clipboard) == null || E.writeText(S).catch(() => {
|
|
5229
5286
|
}));
|
|
5230
5287
|
});
|
|
5231
5288
|
});
|
|
@@ -5278,12 +5335,12 @@ function Sn(r, e) {
|
|
|
5278
5335
|
<span class="__crossx-td-value">${$(o)}</span>
|
|
5279
5336
|
</div>`;
|
|
5280
5337
|
for (const [l, d] of Object.entries(i)) {
|
|
5281
|
-
const
|
|
5282
|
-
<button class="__crossx-copy-btn" data-copy="${$(String(d))}" title="Copy">${de}</button>` : `<span>${
|
|
5338
|
+
const g = mn(d), x = xn(d) ? `<span class="__crossx-addr-text">${Y(d)}</span>
|
|
5339
|
+
<button class="__crossx-copy-btn" data-copy="${$(String(d))}" title="Copy">${de}</button>` : `<span>${g}</span>`;
|
|
5283
5340
|
a += `
|
|
5284
5341
|
<div class="__crossx-td-row">
|
|
5285
5342
|
<span class="__crossx-td-label">${$(l)}</span>
|
|
5286
|
-
<div class="__crossx-td-value">${
|
|
5343
|
+
<div class="__crossx-td-value">${x}</div>
|
|
5287
5344
|
</div>`;
|
|
5288
5345
|
}
|
|
5289
5346
|
const c = document.createElement("div");
|
|
@@ -5464,8 +5521,8 @@ function kn(r, e, s) {
|
|
|
5464
5521
|
a.preventDefault();
|
|
5465
5522
|
const c = (((d = a.clipboardData) == null ? void 0 : d.getData("text")) ?? "").replace(/\D/g, "").slice(0, 4);
|
|
5466
5523
|
if (!c) return;
|
|
5467
|
-
c.split("").forEach((
|
|
5468
|
-
t[
|
|
5524
|
+
c.split("").forEach((g, m) => {
|
|
5525
|
+
t[m] && (t[m].value = g);
|
|
5469
5526
|
});
|
|
5470
5527
|
const l = Math.min(c.length, 3);
|
|
5471
5528
|
t[l].focus(), c.length === 4 && setTimeout(() => e(c), 200);
|
|
@@ -5489,48 +5546,48 @@ class Nn {
|
|
|
5489
5546
|
*/
|
|
5490
5547
|
showWalletSelector(e, s) {
|
|
5491
5548
|
return new Promise((t) => {
|
|
5492
|
-
var
|
|
5549
|
+
var w;
|
|
5493
5550
|
me();
|
|
5494
|
-
const n = [...e], o = Tn(n, this.tokens);
|
|
5495
|
-
document.body.appendChild(o);
|
|
5496
|
-
let
|
|
5497
|
-
const
|
|
5498
|
-
|
|
5499
|
-
},
|
|
5500
|
-
|
|
5501
|
-
},
|
|
5502
|
-
|
|
5551
|
+
const n = [...e], o = Tn(n, this.tokens), i = document.body.style.overflow;
|
|
5552
|
+
document.body.style.overflow = "hidden", document.body.appendChild(o);
|
|
5553
|
+
let a = !1;
|
|
5554
|
+
const c = () => {
|
|
5555
|
+
a || (a = !0, o.remove(), document.body.style.overflow = i);
|
|
5556
|
+
}, l = (b) => {
|
|
5557
|
+
c(), t(b);
|
|
5558
|
+
}, d = () => {
|
|
5559
|
+
c(), t(null);
|
|
5503
5560
|
};
|
|
5504
5561
|
(() => {
|
|
5505
|
-
o.querySelectorAll(".__crossx-wallet-item").forEach((
|
|
5506
|
-
|
|
5507
|
-
const
|
|
5508
|
-
|
|
5562
|
+
o.querySelectorAll(".__crossx-wallet-item").forEach((b) => {
|
|
5563
|
+
b.addEventListener("click", () => {
|
|
5564
|
+
const S = b.dataset.walletAddress ?? "", E = parseInt(b.dataset.walletIndex ?? "0", 10);
|
|
5565
|
+
l({ address: S, index: E });
|
|
5509
5566
|
});
|
|
5510
5567
|
});
|
|
5511
5568
|
})();
|
|
5512
|
-
const
|
|
5513
|
-
|
|
5514
|
-
|
|
5569
|
+
const m = o.querySelector("#__crossx-add-wallet-btn");
|
|
5570
|
+
m && m.addEventListener("click", async () => {
|
|
5571
|
+
m.disabled = !0;
|
|
5515
5572
|
try {
|
|
5516
|
-
const
|
|
5517
|
-
n.push(
|
|
5518
|
-
const
|
|
5519
|
-
if (
|
|
5520
|
-
const
|
|
5521
|
-
|
|
5573
|
+
const b = await s();
|
|
5574
|
+
n.push(b);
|
|
5575
|
+
const S = o.querySelector("#__crossx-wallet-list");
|
|
5576
|
+
if (S) {
|
|
5577
|
+
const E = document.createElement("button");
|
|
5578
|
+
E.className = "__crossx-wallet-item", E.dataset.walletIndex = String(b.index), E.dataset.walletAddress = b.address, E.innerHTML = `<span class="__crossx-wallet-addr">${Y(b.address)}</span>`, E.addEventListener("click", () => l(b)), S.appendChild(E), E.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
5522
5579
|
}
|
|
5523
5580
|
} catch {
|
|
5524
5581
|
} finally {
|
|
5525
|
-
|
|
5582
|
+
m.disabled = !1;
|
|
5526
5583
|
}
|
|
5527
|
-
}), (
|
|
5528
|
-
|
|
5584
|
+
}), (w = o.querySelector("#__crossx-close-btn")) == null || w.addEventListener("click", d), o.addEventListener("click", (b) => {
|
|
5585
|
+
b.target === o && d();
|
|
5529
5586
|
});
|
|
5530
|
-
const
|
|
5531
|
-
|
|
5587
|
+
const x = (b) => {
|
|
5588
|
+
b.key === "Escape" && (document.removeEventListener("keydown", x), d());
|
|
5532
5589
|
};
|
|
5533
|
-
document.addEventListener("keydown",
|
|
5590
|
+
document.addEventListener("keydown", x);
|
|
5534
5591
|
});
|
|
5535
5592
|
}
|
|
5536
5593
|
/**
|
|
@@ -5552,7 +5609,7 @@ class Nn {
|
|
|
5552
5609
|
(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) => {
|
|
5553
5610
|
d.target === s && o();
|
|
5554
5611
|
}), s.querySelectorAll(".__crossx-login-terms-link").forEach((d) => {
|
|
5555
|
-
d.addEventListener("click", (
|
|
5612
|
+
d.addEventListener("click", (g) => g.stopPropagation());
|
|
5556
5613
|
});
|
|
5557
5614
|
const i = (d) => {
|
|
5558
5615
|
d.key === "Escape" && (document.removeEventListener("keydown", i), o());
|
|
@@ -5620,10 +5677,10 @@ class Nn {
|
|
|
5620
5677
|
};
|
|
5621
5678
|
(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) => {
|
|
5622
5679
|
l.addEventListener("click", (d) => {
|
|
5623
|
-
var
|
|
5680
|
+
var m;
|
|
5624
5681
|
d.stopPropagation();
|
|
5625
|
-
const
|
|
5626
|
-
|
|
5682
|
+
const g = l.dataset.copy;
|
|
5683
|
+
g && ((m = navigator.clipboard) == null || m.writeText(g).catch(() => {
|
|
5627
5684
|
}));
|
|
5628
5685
|
});
|
|
5629
5686
|
}), t.addEventListener("click", (l) => {
|
|
@@ -5649,12 +5706,12 @@ class Nn {
|
|
|
5649
5706
|
const a = () => {
|
|
5650
5707
|
i || (i = !0, o(), t());
|
|
5651
5708
|
}, c = () => {
|
|
5652
|
-
var d,
|
|
5653
|
-
(d = n.querySelector("#__crossx-done-btn")) == null || d.addEventListener("click", a), (
|
|
5654
|
-
|
|
5709
|
+
var d, g;
|
|
5710
|
+
(d = n.querySelector("#__crossx-done-btn")) == null || d.addEventListener("click", a), (g = n.querySelector("#__crossx-close-btn")) == null || g.addEventListener("click", a), n.addEventListener("click", (m) => {
|
|
5711
|
+
m.target === n && a();
|
|
5655
5712
|
});
|
|
5656
|
-
const l = (
|
|
5657
|
-
|
|
5713
|
+
const l = (m) => {
|
|
5714
|
+
m.key === "Escape" && (document.removeEventListener("keydown", l), a());
|
|
5658
5715
|
};
|
|
5659
5716
|
document.addEventListener("keydown", l);
|
|
5660
5717
|
};
|
|
@@ -5674,19 +5731,19 @@ class Nn {
|
|
|
5674
5731
|
}, i = () => {
|
|
5675
5732
|
n(), s(!1);
|
|
5676
5733
|
};
|
|
5677
|
-
(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((
|
|
5678
|
-
|
|
5679
|
-
var
|
|
5680
|
-
|
|
5681
|
-
const
|
|
5682
|
-
|
|
5734
|
+
(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((g) => {
|
|
5735
|
+
g.addEventListener("click", (m) => {
|
|
5736
|
+
var w;
|
|
5737
|
+
m.stopPropagation();
|
|
5738
|
+
const x = g.dataset.copy;
|
|
5739
|
+
x && ((w = navigator.clipboard) == null || w.writeText(x).catch(() => {
|
|
5683
5740
|
}));
|
|
5684
5741
|
});
|
|
5685
|
-
}), t.addEventListener("click", (
|
|
5686
|
-
|
|
5742
|
+
}), t.addEventListener("click", (g) => {
|
|
5743
|
+
g.target === t && i();
|
|
5687
5744
|
});
|
|
5688
|
-
const a = (
|
|
5689
|
-
|
|
5745
|
+
const a = (g) => {
|
|
5746
|
+
g.key === "Escape" && (document.removeEventListener("keydown", a), i());
|
|
5690
5747
|
};
|
|
5691
5748
|
document.addEventListener("keydown", a);
|
|
5692
5749
|
});
|
|
@@ -5709,7 +5766,7 @@ class Pn {
|
|
|
5709
5766
|
return this._accessToken !== null;
|
|
5710
5767
|
}
|
|
5711
5768
|
}
|
|
5712
|
-
function
|
|
5769
|
+
function Mn(r) {
|
|
5713
5770
|
r.debug;
|
|
5714
5771
|
const e = Ue.production, s = {
|
|
5715
5772
|
...r,
|
|
@@ -5721,13 +5778,13 @@ function Bn(r) {
|
|
|
5721
5778
|
projectId: r.projectId
|
|
5722
5779
|
}, o = s.authMode !== "cookie" && At.isAvailable() ? new At() : new Ks(), i = new tn(), a = new nn(), c = new pt(), l = new Pn();
|
|
5723
5780
|
let d;
|
|
5724
|
-
r.useMockWallet ? (
|
|
5781
|
+
r.useMockWallet ? (f.log("[CROSSx] Mock Wallet Provider 사용"), d = new on(o)) : (f.log("[CROSSx] Remote Wallet Provider 사용"), d = new qe(
|
|
5725
5782
|
t,
|
|
5726
5783
|
o,
|
|
5727
5784
|
a,
|
|
5728
5785
|
l
|
|
5729
5786
|
));
|
|
5730
|
-
const
|
|
5787
|
+
const g = new Ce(t, a), m = new Nn(r.theme ?? "light", r.themeTokens);
|
|
5731
5788
|
return new st(
|
|
5732
5789
|
s,
|
|
5733
5790
|
t,
|
|
@@ -5737,15 +5794,15 @@ function Bn(r) {
|
|
|
5737
5794
|
c,
|
|
5738
5795
|
d,
|
|
5739
5796
|
l,
|
|
5740
|
-
|
|
5741
|
-
|
|
5797
|
+
m,
|
|
5798
|
+
g
|
|
5742
5799
|
);
|
|
5743
5800
|
}
|
|
5744
5801
|
export {
|
|
5745
|
-
|
|
5802
|
+
_ as CROSSxError,
|
|
5746
5803
|
Cs as CROSSxEthereumProvider,
|
|
5747
5804
|
st as CROSSxSDK,
|
|
5748
5805
|
$n as ChainId,
|
|
5749
5806
|
p as ErrorCode,
|
|
5750
|
-
|
|
5807
|
+
Mn as createCROSSxSDK
|
|
5751
5808
|
};
|