@nexus-cross/crossx-sdk-core 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var Ps = Object.defineProperty;
2
2
  var Os = (r, e, s) => e in r ? Ps(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s;
3
3
  var S = (r, e, s) => Os(r, typeof e != "symbol" ? e + "" : e, s);
4
4
  import { decodeJwt as Ns } from "jose";
5
- var x = /* @__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.ALREADY_AUTHENTICATED = "ALREADY_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.MIGRATION_PIN_LOCKED = "MIGRATION_PIN_LOCKED", 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.PASSWORD_NOT_SET = "PASSWORD_NOT_SET", r.PASSWORD_WRONG = "PASSWORD_WRONG", r.PASSWORD_COMPLEXITY = "PASSWORD_COMPLEXITY", r.PASSWORD_CANCELLED = "PASSWORD_CANCELLED", r.INVALID_CONFIG = "INVALID_CONFIG", r.UNKNOWN_ERROR = "UNKNOWN_ERROR", r))(x || {});
5
+ var g = /* @__PURE__ */ ((r) => (r.AUTH_NOT_INITIALIZED = "AUTH_NOT_INITIALIZED", r.AUTH_FAILED = "AUTH_FAILED", r.AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID", r.AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED", r.AUTH_NOT_AUTHENTICATED = "AUTH_NOT_AUTHENTICATED", r.ALREADY_AUTHENTICATED = "ALREADY_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.MIGRATION_PIN_LOCKED = "MIGRATION_PIN_LOCKED", r.GATEWAY_INTERNAL_ERROR = "GATEWAY_INTERNAL_ERROR", r.GATEWAY_LOCK_CONFLICT = "GATEWAY_LOCK_CONFLICT", r.WALLET_INCONSISTENT_STATE = "WALLET_INCONSISTENT_STATE", 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.PASSWORD_NOT_SET = "PASSWORD_NOT_SET", r.PASSWORD_WRONG = "PASSWORD_WRONG", r.PASSWORD_COMPLEXITY = "PASSWORD_COMPLEXITY", r.PASSWORD_CANCELLED = "PASSWORD_CANCELLED", r.INVALID_CONFIG = "INVALID_CONFIG", r.UNKNOWN_ERROR = "UNKNOWN_ERROR", r))(g || {});
6
6
  class m extends Error {
7
7
  constructor(e, s, t) {
8
8
  super(s), this.code = e, this.details = t, this.name = "CROSSxError", Object.setPrototypeOf(this, m.prototype);
@@ -85,6 +85,7 @@ class Ds {
85
85
  // ──────────────────────────────────────────────
86
86
  // EIP-1193 request
87
87
  // ──────────────────────────────────────────────
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
89
  async request({ method: e, params: s = [] }) {
89
90
  switch (e) {
90
91
  case "eth_accounts":
@@ -107,7 +108,7 @@ class Ds {
107
108
  case "personal_sign":
108
109
  case "eth_sign":
109
110
  throw new m(
110
- x.NOT_IMPLEMENTED,
111
+ g.NOT_IMPLEMENTED,
111
112
  `${e}은(는) 아직 지원되지 않습니다. sdk.signMessage()를 직접 사용하세요.`
112
113
  );
113
114
  case "eth_signTypedData":
@@ -115,7 +116,7 @@ class Ds {
115
116
  case "eth_signTypedData_v3":
116
117
  case "eth_signTypedData_v4":
117
118
  throw new m(
118
- x.NOT_IMPLEMENTED,
119
+ g.NOT_IMPLEMENTED,
119
120
  `${e}은(는) 아직 지원되지 않습니다. sdk.signTypedData() 또는 sdk.signTypedDataOffchain()을 직접 사용하세요.`
120
121
  );
121
122
  default:
@@ -133,6 +134,7 @@ class Ds {
133
134
  return (t = this._listeners.get(e)) == null || t.delete(s), this;
134
135
  }
135
136
  /** 내부적으로 이벤트를 발행 (accountsChanged, chainChanged 등) */
137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
138
  emit(e, ...s) {
137
139
  var t;
138
140
  (t = this._listeners.get(e)) == null || t.forEach((o) => o(...s));
@@ -149,6 +151,7 @@ class Ds {
149
151
  * EIP-1193 tx 파라미터를 SDK UnsignedTransaction 형식으로 변환.
150
152
  * EIP-1193에서는 gasLimit 대신 gas 를 사용하는 경우가 있으므로 정규화.
151
153
  */
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
155
  _normalizeEIP1193Tx(e) {
153
156
  return {
154
157
  from: e.from,
@@ -338,7 +341,7 @@ class Us {
338
341
  checkResponseError(e, s) {
339
342
  if (e != null && e.code && e.code !== 200 && e.code > 0)
340
343
  throw new m(
341
- x.AUTH_FAILED,
344
+ g.AUTH_FAILED,
342
345
  `${s} 실패 (코드 ${e.code}): ${e.message}`
343
346
  );
344
347
  const t = e == null ? void 0 : e.data;
@@ -346,7 +349,7 @@ class Us {
346
349
  const o = t;
347
350
  if (o.code && o.code !== 200 && o.code > 0)
348
351
  throw new m(
349
- x.AUTH_FAILED,
352
+ g.AUTH_FAILED,
350
353
  `${s} 실패 (코드 ${o.code}): ${o.message}`
351
354
  );
352
355
  }
@@ -359,7 +362,7 @@ class Us {
359
362
  let l = "/login";
360
363
  c === "google" ? l = "/google" : c === "apple" && (l = "/apple");
361
364
  const { oauthServiceUrl: d, authApiUrl: u } = this.config, _ = `${d}${l}`;
362
- h.log(`[CROSSx] OAuth 팝업 열기 (${c || "일반"} 로그인):`, _);
365
+ h.log(`[CROSSx] OAuth 팝업 열기 (${c || "일반"} 로그인)`);
363
366
  const f = await this.oauth.openAuth({
364
367
  authUrl: _,
365
368
  expectedOrigin: new URL(d).origin
@@ -415,7 +418,7 @@ class Us {
415
418
  */
416
419
  async exchangeFirebaseToken(e, s) {
417
420
  const t = this.useCookieAuth, o = t ? `${s}/cross-auth/social/login/cookie` : `${s}/cross-auth/social/login`;
418
- h.log("[CROSSx] Firebase 토큰 교환 요청:", o);
421
+ h.log("[CROSSx] Firebase 토큰 교환 요청");
419
422
  const n = await this.transport.request({
420
423
  url: o,
421
424
  method: "POST",
@@ -431,7 +434,7 @@ class Us {
431
434
  return h.log("[CROSSx] Cookie 모드 — 로그인 성공 (JWT는 HttpOnly 쿠키)"), {};
432
435
  if (!a)
433
436
  throw new m(
434
- x.AUTH_FAILED,
437
+ g.AUTH_FAILED,
435
438
  "토큰 교환 응답에서 access_token을 찾을 수 없습니다"
436
439
  );
437
440
  h.log("[CROSSx] access_token 교환 성공");
@@ -562,7 +565,7 @@ class Us {
562
565
  return;
563
566
  }
564
567
  if (!c)
565
- throw new m(x.AUTH_FAILED, "토큰 자동 갱신 실패: 응답에 토큰이 없습니다");
568
+ throw new m(g.AUTH_FAILED, "토큰 자동 갱신 실패: 응답에 토큰이 없습니다");
566
569
  if (this.tokenStore.set(c), !t) {
567
570
  await this.storage.set(Je, c);
568
571
  const l = this.extractRefreshToken(a);
@@ -588,10 +591,10 @@ class Us {
588
591
  } else
589
592
  h.log("[CROSSx] getOrCreateWallet 직접 호출 (폴백)"), t = (await this.walletProvider.getOrCreateWallet(e.id)).address, h.log("[CROSSx] 지갑 로드 완료 — address:", t);
590
593
  } catch (n) {
591
- if (n instanceof m && n.code === x.MIGRATION_BACKUP_EXISTS)
594
+ if (n instanceof m && n.code === g.MIGRATION_BACKUP_EXISTS)
592
595
  h.log("[CROSSx] MIGRATION_BACKUP_EXISTS 감지 → needsMigration = true"), o = !0;
593
596
  else {
594
- if (n instanceof m && (n.code === x.PROJECT_NOT_REGISTERED || n.code === x.PROJECT_ID_MISSING || n.code === x.ORIGIN_NOT_ALLOWED))
597
+ if (n instanceof m && (n.code === g.PROJECT_NOT_REGISTERED || n.code === g.PROJECT_ID_MISSING || n.code === g.ORIGIN_NOT_ALLOWED))
595
598
  throw h.error("[CROSSx] 프로젝트 설정 에러:", n.message), n;
596
599
  h.warn("[CROSSx] 지갑 상태 확인 실패 (로그인은 유지):", n);
597
600
  }
@@ -600,7 +603,7 @@ class Us {
600
603
  }
601
604
  }
602
605
  const Hs = "crossx_access_token", Fs = "crossx_refresh_token", Gs = "crossx_user_info";
603
- class qs {
606
+ class Ws {
604
607
  constructor(e, s, t) {
605
608
  this.config = e, this.storage = s, this.tokenStore = t;
606
609
  }
@@ -608,14 +611,14 @@ class qs {
608
611
  this.tokenStore.clear(), this.config.authMode !== "cookie" && (await this.storage.remove(Hs), await this.storage.remove(Fs)), await this.storage.remove(Gs);
609
612
  }
610
613
  }
611
- class Ws {
614
+ class qs {
612
615
  constructor(e, s) {
613
616
  this.storage = e, this.walletProvider = s;
614
617
  }
615
618
  async execute(e, s) {
616
619
  if (!this.walletProvider.migrateWallet)
617
620
  throw new m(
618
- x.NOT_IMPLEMENTED,
621
+ g.NOT_IMPLEMENTED,
619
622
  "현재 환경에서는 마이그레이션이 지원되지 않습니다"
620
623
  );
621
624
  h.log("[CROSSx][Migration Phase 4] MigrateWalletUseCase.execute() — pin 길이:", e.length, "sub:", s);
@@ -692,7 +695,7 @@ class Vs {
692
695
  })).data;
693
696
  if (a != null && a.error)
694
697
  throw new m(
695
- x.UNKNOWN_ERROR,
698
+ g.UNKNOWN_ERROR,
696
699
  `RPC 오류 [${e}] (${t}): ${a.error.message} (코드: ${a.error.code})`
697
700
  );
698
701
  return a == null ? void 0 : a.result;
@@ -758,9 +761,9 @@ function js() {
758
761
  }
759
762
  return Fe.production;
760
763
  }
761
- const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA00", Tt = 130, kt = 6, Ct = 18, Qs = 0, er = 30 * 1e3, Q = class Q extends Ks {
764
+ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA00", Tt = 130, Ct = 6, kt = 18, Qs = 0, er = 30 * 1e3, Q = class Q extends Ks {
762
765
  constructor(e, s, t, o, n, i, a, c, l, d, u) {
763
- super(), this.storage = t, this.crypto = o, this.transport = n, 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._verifyPasswordMutex = null, this._config = Object.freeze({ ...e }), this.internalConfig = e, this.adapterConfig = s, e.logger && St(e.logger), this.confirmation = l, this.passwordStore = u ?? new Jt(), this.chainRegistry = d, this.jsonRpc = new Vs(d, n), this.signInUseCase = new Us(
766
+ super(), this.storage = t, this.crypto = o, this.transport = n, this.oauth = i, this.walletProvider = a, this.tokenStore = c, this.initialized = !1, this._initPromise = null, this.authenticated = !1, this.userId = null, this.address = null, this.activeWalletIndex = 0, this.userEmail = null, this.loginType = null, this.providerSub = null, this.tokenSignatureVerified = !1, this._verifyPasswordMutex = null, this._config = Object.freeze({ ...e }), this.internalConfig = e, this.adapterConfig = s, e.logger && St(e.logger), this.confirmation = l, this.passwordStore = u ?? new Jt(), this.chainRegistry = d, this.jsonRpc = new Vs(d, n), this.signInUseCase = new Us(
764
767
  this.internalConfig,
765
768
  t,
766
769
  o,
@@ -768,7 +771,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
768
771
  n,
769
772
  a,
770
773
  c
771
- ), this.signOutUseCase = new qs(this.internalConfig, t, c), this.migrateWalletUseCase = new Ws(t, a);
774
+ ), this.signOutUseCase = new Ws(this.internalConfig, t, c), this.migrateWalletUseCase = new qs(t, a);
772
775
  }
773
776
  get config() {
774
777
  return this._config;
@@ -787,32 +790,36 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
787
790
  * console.log('자동 로그인:', session.address);
788
791
  * }
789
792
  */
790
- async initialize() {
791
- if (this.initialized) return this.authenticated ? { success: !0, address: this.address ?? void 0 } : null;
793
+ async initialize(e) {
794
+ return this.initialized ? this.authenticated ? { success: !0, address: this.address ?? void 0 } : null : this._initPromise ? this._initPromise : (this._initPromise = this._doInitialize(e).finally(() => {
795
+ this._initPromise = null;
796
+ }), this._initPromise);
797
+ }
798
+ async _doInitialize(e) {
792
799
  console.log("[CROSSx SDK] v1.1.0 초기화 중..."), this.confirmation.setMessages(Et(this._config.locale));
793
800
  try {
794
- const e = js();
795
- this.internalConfig.oauthServiceUrl = e.oauthServiceUrl, this.internalConfig.authApiUrl = e.authApiUrl, this.internalConfig.walletGatewayUrl = e.walletGatewayUrl, this.adapterConfig.gatewayUrl = e.walletGatewayUrl;
796
- const s = await this.signInUseCase.restoreSession();
797
- if (s != null && s.success) {
798
- this.applyAuthResult(s);
801
+ const s = js();
802
+ this.internalConfig.oauthServiceUrl = s.oauthServiceUrl, this.internalConfig.authApiUrl = s.authApiUrl, this.internalConfig.walletGatewayUrl = s.walletGatewayUrl, this.adapterConfig.gatewayUrl = s.walletGatewayUrl;
803
+ const t = await this.signInUseCase.restoreSession();
804
+ if (t != null && t.success) {
805
+ this.applyAuthResult(t);
799
806
  try {
800
- await this.loadWalletAfterAuth();
801
- } catch (t) {
802
- if (!(t instanceof m && t.code === x.PASSWORD_CANCELLED))
803
- throw t;
807
+ await this.loadWalletAfterAuth(e == null ? void 0 : e.preferredWalletIndex);
808
+ } catch (o) {
809
+ if (!(o instanceof m && o.code === g.PASSWORD_CANCELLED))
810
+ throw o;
804
811
  h.log("[CROSSx] initialize: 비밀번호 입력 취소 — 지갑 미로드 상태로 계속");
805
812
  }
806
813
  }
807
- return this.initialized = !0, this.emit("initialized", { restored: !!(s != null && s.success) }), s ?? null;
808
- } catch (e) {
809
- throw new m(x.AUTH_NOT_INITIALIZED, "SDK 초기화에 실패했습니다", e);
814
+ return this.initialized = !0, this.emit("initialized", { restored: !!(t != null && t.success) }), t ?? null;
815
+ } catch (s) {
816
+ throw new m(g.AUTH_NOT_INITIALIZED, "SDK 초기화에 실패했습니다", s);
810
817
  }
811
818
  }
812
819
  async signIn(e) {
813
820
  if (this.ensureInitialized(), this.authenticated)
814
821
  throw new m(
815
- x.ALREADY_AUTHENTICATED,
822
+ g.ALREADY_AUTHENTICATED,
816
823
  "이미 로그인된 상태입니다. signOut()을 먼저 호출하세요."
817
824
  );
818
825
  let s = e;
@@ -826,7 +833,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
826
833
  const t = await this.signInUseCase.execute(s);
827
834
  return t.success && this.applyAuthResult(t), t;
828
835
  } catch (t) {
829
- throw new m(x.AUTH_FAILED, "로그인에 실패했습니다", t);
836
+ throw new m(g.AUTH_FAILED, "로그인에 실패했습니다", t);
830
837
  }
831
838
  }
832
839
  /**
@@ -857,7 +864,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
857
864
  const t = await this.getAddresses(), o = await this.selectWalletIfMultiple(t);
858
865
  return { ...s, address: (o == null ? void 0 : o.address) ?? s.address, addresses: t };
859
866
  } catch (t) {
860
- throw t instanceof m && t.code === x.PASSWORD_CANCELLED && (h.log("[CROSSx] signInWithCreate: 비밀번호 설정 취소 — 자동 로그아웃 진행"), await this.signOut().catch(
867
+ throw t instanceof m && t.code === g.PASSWORD_CANCELLED && (h.log("[CROSSx] signInWithCreate: 비밀번호 설정 취소 — 자동 로그아웃 진행"), await this.signOut().catch(
861
868
  (o) => h.warn("[CROSSx] signInWithCreate: 자동 로그아웃 실패", o)
862
869
  )), t;
863
870
  }
@@ -867,7 +874,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
867
874
  try {
868
875
  await this.signOutUseCase.execute(), this.clearAuthState();
869
876
  } catch (e) {
870
- throw new m(x.UNKNOWN_ERROR, "로그아웃에 실패했습니다", e);
877
+ throw new m(g.UNKNOWN_ERROR, "로그아웃에 실패했습니다", e);
871
878
  }
872
879
  }
873
880
  isAuthenticated() {
@@ -912,7 +919,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
912
919
  try {
913
920
  await this.loadWalletAfterAuth();
914
921
  } catch (s) {
915
- s instanceof m && s.code === x.PASSWORD_CANCELLED || h.warn("[CROSSx] ensureLoggedIn: loadWalletAfterAuth 실패:", s);
922
+ s instanceof m && s.code === g.PASSWORD_CANCELLED || h.warn("[CROSSx] ensureLoggedIn: loadWalletAfterAuth 실패:", s);
916
923
  }
917
924
  return !0;
918
925
  }
@@ -952,13 +959,13 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
952
959
  */
953
960
  async migrateWallet(e) {
954
961
  if (this.ensureAuthenticated(), !this.userId)
955
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
962
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
956
963
  try {
957
964
  const s = await this.migrateWalletUseCase.execute(e, this.userId);
958
- return this.address = s.address, this.emit("addressChanged", { address: s.address, index: 0 }), h.log("[CROSSx] migrateWallet 완료 — address:", s.address), s;
965
+ return this.address = s.address, this.activeWalletIndex = 0, this.emit("addressChanged", { address: s.address, index: 0 }), h.log("[CROSSx] migrateWallet 완료 — address:", s.address), s;
959
966
  } catch (s) {
960
967
  throw s instanceof m ? s : new m(
961
- x.MIGRATION_FAILED,
968
+ g.MIGRATION_FAILED,
962
969
  "지갑 마이그레이션에 실패했습니다",
963
970
  s
964
971
  );
@@ -979,10 +986,10 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
979
986
  async getAddress(e) {
980
987
  if (e !== void 0) {
981
988
  if (this.ensureAuthenticated(), !this.userId)
982
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
989
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
983
990
  return { address: (await this.walletProvider.getAddress(this.userId, e)).address, index: e };
984
991
  }
985
- return !this.authenticated || !this.address ? null : { address: this.address, index: 0 };
992
+ return !this.authenticated || !this.address ? null : { address: this.address, index: this.activeWalletIndex };
986
993
  }
987
994
  /**
988
995
  * 사용자의 지갑 주소 목록 반환
@@ -1019,7 +1026,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1019
1026
  */
1020
1027
  async selectWallet(e) {
1021
1028
  if (this.ensureAuthenticated(), !this.userId)
1022
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1029
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1023
1030
  let s = await this.walletProvider.getAddresses(this.userId);
1024
1031
  s.length === 0 && this.address && (s = [{ address: this.address, index: 0 }]);
1025
1032
  const t = await this.confirmation.showWalletSelector(
@@ -1031,7 +1038,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1031
1038
  },
1032
1039
  e
1033
1040
  );
1034
- return t && (this.address = t.address, this.emit("addressChanged", { address: t.address, index: t.index })), t;
1041
+ return t && (this.address = t.address, this.activeWalletIndex = t.index, this.emit("addressChanged", { address: t.address, index: t.index })), t;
1035
1042
  }
1036
1043
  /**
1037
1044
  * 지갑이 2개 이상이면 selectWallet()을 호출합니다.
@@ -1061,7 +1068,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1061
1068
  try {
1062
1069
  return await this.chainRegistry.getChains();
1063
1070
  } catch (e) {
1064
- throw e instanceof m ? e : new m(x.UNKNOWN_ERROR, "체인 목록 조회에 실패했습니다", e);
1071
+ throw e instanceof m ? e : new m(g.UNKNOWN_ERROR, "체인 목록 조회에 실패했습니다", e);
1065
1072
  }
1066
1073
  }
1067
1074
  /**
@@ -1080,7 +1087,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1080
1087
  try {
1081
1088
  return await this.chainRegistry.getChain(e);
1082
1089
  } catch (s) {
1083
- throw s instanceof m ? s : new m(x.CHAIN_NOT_SUPPORTED, `체인 조회에 실패했습니다: ${e}`, s);
1090
+ throw s instanceof m ? s : new m(g.CHAIN_NOT_SUPPORTED, `체인 조회에 실패했습니다: ${e}`, s);
1084
1091
  }
1085
1092
  }
1086
1093
  // ============================================================================
@@ -1121,7 +1128,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1121
1128
  */
1122
1129
  async createWallet() {
1123
1130
  if (this.ensureAuthenticated(), !this.userId)
1124
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1131
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1125
1132
  h.log("[CROSSx] createWallet 시작");
1126
1133
  const e = await this.fetchWalletStatus();
1127
1134
  if (h.log("[CROSSx] 지갑 상태:", e), e === "migration_required") {
@@ -1129,25 +1136,25 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1129
1136
  h.log("[CROSSx] migration_required → 마이그레이션 UI 시작 — sub:", s);
1130
1137
  const t = await this.handleMigrationFlow(s);
1131
1138
  if (t)
1132
- return this.address = t.address, this.emit("addressChanged", { address: t.address, index: 0 }), { address: t.address };
1139
+ return this.address = t.address, this.activeWalletIndex = 0, this.emit("addressChanged", { address: t.address, index: 0 }), { address: t.address };
1133
1140
  throw new m(
1134
- x.MIGRATION_FAILED,
1141
+ g.MIGRATION_FAILED,
1135
1142
  "사용자가 마이그레이션을 건너뛰었습니다"
1136
1143
  );
1137
1144
  }
1138
1145
  e === "exists" ? await this.ensureVerifiedPassword() : await this.ensurePasswordSetup();
1139
1146
  try {
1140
1147
  const s = await this.walletProvider.getOrCreateWallet(this.userId);
1141
- return this.address = s.address, this.emit("addressChanged", { address: s.address, index: 0 }), h.log("[CROSSx] 지갑 준비 완료:", s.address), { address: s.address };
1148
+ return this.address = s.address, this.activeWalletIndex = 0, this.emit("addressChanged", { address: s.address, index: 0 }), h.log("[CROSSx] 지갑 준비 완료:", s.address), { address: s.address };
1142
1149
  } catch (s) {
1143
- if (s instanceof m && s.code === x.MIGRATION_BACKUP_EXISTS) {
1150
+ if (s instanceof m && s.code === g.MIGRATION_BACKUP_EXISTS) {
1144
1151
  const t = this.providerSub ?? this.userId;
1145
1152
  h.log("[CROSSx] MIGRATION_BACKUP_EXISTS (폴백) → 마이그레이션 UI 시작");
1146
1153
  const o = await this.handleMigrationFlow(t);
1147
1154
  if (o)
1148
- return this.address = o.address, this.emit("addressChanged", { address: o.address, index: 0 }), { address: o.address };
1155
+ return this.address = o.address, this.activeWalletIndex = 0, this.emit("addressChanged", { address: o.address, index: 0 }), { address: o.address };
1149
1156
  throw new m(
1150
- x.MIGRATION_FAILED,
1157
+ g.MIGRATION_FAILED,
1151
1158
  "사용자가 마이그레이션을 건너뛰었습니다"
1152
1159
  );
1153
1160
  }
@@ -1176,7 +1183,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1176
1183
  */
1177
1184
  async signMessage(e, s, t) {
1178
1185
  if (this.ensureAuthenticated(), !this.userId)
1179
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1186
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1180
1187
  await this.ensurePasswordForSigning();
1181
1188
  const o = t == null ? void 0 : t.index, n = await this.walletProvider.getAddress(this.userId, o ?? 0);
1182
1189
  let i;
@@ -1188,7 +1195,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1188
1195
  dappName: t == null ? void 0 : t.dappName,
1189
1196
  accountName: t == null ? void 0 : t.accountName
1190
1197
  }))
1191
- throw new m(x.USER_REJECTED, "사용자가 메시지 서명을 거부했습니다");
1198
+ throw new m(g.USER_REJECTED, "사용자가 메시지 서명을 거부했습니다");
1192
1199
  try {
1193
1200
  const c = await this.withPasswordRetry(
1194
1201
  () => this.walletProvider.signMessage(
@@ -1207,7 +1214,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1207
1214
  address: n.address
1208
1215
  };
1209
1216
  } catch (c) {
1210
- throw c instanceof m ? c : new m(x.SIGNATURE_FAILED, `메시지 서명에 실패했습니다 (${e})`, c);
1217
+ throw c instanceof m ? c : new m(g.SIGNATURE_FAILED, `메시지 서명에 실패했습니다 (${e})`, c);
1211
1218
  }
1212
1219
  }
1213
1220
  /**
@@ -1233,9 +1240,9 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1233
1240
  */
1234
1241
  async signTypedData(e, s, t) {
1235
1242
  if (this.ensureAuthenticated(), !this.userId)
1236
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1243
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1237
1244
  if (!this.walletProvider.signTypedData)
1238
- throw new m(x.NOT_IMPLEMENTED, "signTypedData가 구현되어 있지 않습니다");
1245
+ throw new m(g.NOT_IMPLEMENTED, "signTypedData가 구현되어 있지 않습니다");
1239
1246
  await this.ensurePasswordForSigning(), Q.validateTypedDataChainId(e, s);
1240
1247
  const o = await this.walletProvider.getAddress(this.userId, (t == null ? void 0 : t.index) ?? 0);
1241
1248
  let n;
@@ -1247,7 +1254,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1247
1254
  dappName: t == null ? void 0 : t.dappName,
1248
1255
  accountName: t == null ? void 0 : t.accountName
1249
1256
  }))
1250
- throw new m(x.USER_REJECTED, "사용자가 타입 데이터 서명을 거부했습니다");
1257
+ throw new m(g.USER_REJECTED, "사용자가 타입 데이터 서명을 거부했습니다");
1251
1258
  try {
1252
1259
  const a = await this.withPasswordRetry(
1253
1260
  () => this.walletProvider.signTypedData(
@@ -1265,7 +1272,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1265
1272
  address: o.address
1266
1273
  };
1267
1274
  } catch (a) {
1268
- throw a instanceof m ? a : new m(x.SIGNATURE_FAILED, `타입 데이터 서명에 실패했습니다 (${e})`, a);
1275
+ throw a instanceof m ? a : new m(g.SIGNATURE_FAILED, `타입 데이터 서명에 실패했습니다 (${e})`, a);
1269
1276
  }
1270
1277
  }
1271
1278
  /**
@@ -1301,7 +1308,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1301
1308
  */
1302
1309
  async signTransaction(e, s, t) {
1303
1310
  if (this.ensureAuthenticated(), !this.userId)
1304
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1311
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1305
1312
  await this.ensurePasswordForSigning();
1306
1313
  const o = await this.withResolvedGasAndFee(s, e);
1307
1314
  let n;
@@ -1323,7 +1330,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1323
1330
  dappName: t == null ? void 0 : t.dappName,
1324
1331
  accountName: t == null ? void 0 : t.accountName
1325
1332
  }))
1326
- throw new m(x.USER_REJECTED, "사용자가 트랜잭션 서명을 거부했습니다");
1333
+ throw new m(g.USER_REJECTED, "사용자가 트랜잭션 서명을 거부했습니다");
1327
1334
  try {
1328
1335
  const c = await this.withPasswordRetry(
1329
1336
  () => this.walletProvider.signTransaction(
@@ -1343,7 +1350,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1343
1350
  if (c instanceof m) throw c;
1344
1351
  const l = c instanceof Error ? c.message : String(c);
1345
1352
  throw new m(
1346
- x.SIGNATURE_FAILED,
1353
+ g.SIGNATURE_FAILED,
1347
1354
  `트랜잭션 서명에 실패했습니다 (${e}): ${l}`,
1348
1355
  c
1349
1356
  );
@@ -1357,7 +1364,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1357
1364
  */
1358
1365
  async sendTransaction(e, s, t) {
1359
1366
  if (this.ensureAuthenticated(), !this.userId)
1360
- throw new m(x.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1367
+ throw new m(g.AUTH_NOT_AUTHENTICATED, "사용자 ID를 찾을 수 없습니다");
1361
1368
  await this.ensurePasswordForSigning();
1362
1369
  const o = await this.withResolvedGasAndFee(s, e);
1363
1370
  let n;
@@ -1379,7 +1386,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1379
1386
  dappName: t == null ? void 0 : t.dappName,
1380
1387
  accountName: t == null ? void 0 : t.accountName
1381
1388
  }))
1382
- throw new m(x.USER_REJECTED, "사용자가 트랜잭션을 거부했습니다");
1389
+ throw new m(g.USER_REJECTED, "사용자가 트랜잭션을 거부했습니다");
1383
1390
  try {
1384
1391
  const c = await this.withPasswordRetry(async () => {
1385
1392
  if (this.walletProvider.sendTransaction)
@@ -1403,7 +1410,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1403
1410
  if (c instanceof m) throw c;
1404
1411
  const l = c instanceof Error ? c.message : String(c);
1405
1412
  throw new m(
1406
- x.TRANSACTION_FAILED,
1413
+ g.TRANSACTION_FAILED,
1407
1414
  `트랜잭션 전송에 실패했습니다 (${e}): ${l}`,
1408
1415
  c
1409
1416
  );
@@ -1436,7 +1443,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1436
1443
  await new Promise((d) => setTimeout(d, c)), c = Math.min(c * 2, n);
1437
1444
  }
1438
1445
  throw new m(
1439
- x.UNKNOWN_ERROR,
1446
+ g.UNKNOWN_ERROR,
1440
1447
  `트랜잭션 영수증 조회 시간이 초과되었습니다 (${e})`
1441
1448
  );
1442
1449
  }
@@ -1534,12 +1541,12 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1534
1541
  this.ensureAuthenticated();
1535
1542
  const t = this.walletProvider;
1536
1543
  if (typeof t.changePassword != "function")
1537
- throw new m(x.NOT_IMPLEMENTED, "changePassword가 구현되어 있지 않습니다");
1544
+ throw new m(g.NOT_IMPLEMENTED, "changePassword가 구현되어 있지 않습니다");
1538
1545
  this.passwordStore.set(e);
1539
1546
  try {
1540
1547
  await t.changePassword(e, s), this.passwordStore.set(s), h.log("[CROSSx] 비밀번호 변경 완료");
1541
1548
  } catch (o) {
1542
- throw o instanceof m ? o : new m(x.UNKNOWN_ERROR, "비밀번호 변경에 실패했습니다", o);
1549
+ throw o instanceof m ? o : new m(g.UNKNOWN_ERROR, "비밀번호 변경에 실패했습니다", o);
1543
1550
  }
1544
1551
  }
1545
1552
  // ============================================================================
@@ -1560,7 +1567,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1560
1567
  return await this.walletRpc("eth_gasPrice", [], e);
1561
1568
  } catch (s) {
1562
1569
  const t = s instanceof Error ? s.message : String(s);
1563
- throw new m(x.GAS_ESTIMATION_FAILED, `가스 가격 조회에 실패했습니다 (${e}): ${t}`, s);
1570
+ throw new m(g.GAS_ESTIMATION_FAILED, `가스 가격 조회에 실패했습니다 (${e}): ${t}`, s);
1564
1571
  }
1565
1572
  }
1566
1573
  /**
@@ -1581,7 +1588,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1581
1588
  return await this.walletRpc("eth_estimateGas", [t], s);
1582
1589
  } catch (o) {
1583
1590
  const n = o instanceof Error ? o.message : String(o);
1584
- throw new m(x.GAS_ESTIMATION_FAILED, `가스 추정에 실패했습니다 (${s}): ${n}`, o);
1591
+ throw new m(g.GAS_ESTIMATION_FAILED, `가스 추정에 실패했습니다 (${s}): ${n}`, o);
1585
1592
  }
1586
1593
  }
1587
1594
  /**
@@ -1602,7 +1609,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1602
1609
  return (s == null ? void 0 : s.baseFeePerGas) ?? null;
1603
1610
  } catch (s) {
1604
1611
  const t = s instanceof Error ? s.message : String(s);
1605
- throw new m(x.GAS_ESTIMATION_FAILED, `baseFeePerGas 조회에 실패했습니다 (${e}): ${t}`, s);
1612
+ throw new m(g.GAS_ESTIMATION_FAILED, `baseFeePerGas 조회에 실패했습니다 (${e}): ${t}`, s);
1606
1613
  }
1607
1614
  }
1608
1615
  /**
@@ -1621,7 +1628,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1621
1628
  return await this.walletRpc("eth_maxPriorityFeePerGas", [], e);
1622
1629
  } catch (s) {
1623
1630
  const t = s instanceof Error ? s.message : String(s);
1624
- throw new m(x.GAS_ESTIMATION_FAILED, `maxPriorityFeePerGas 조회에 실패했습니다 (${e}): ${t}`, s);
1631
+ throw new m(g.GAS_ESTIMATION_FAILED, `maxPriorityFeePerGas 조회에 실패했습니다 (${e}): ${t}`, s);
1625
1632
  }
1626
1633
  }
1627
1634
  // ============================================================================
@@ -1641,7 +1648,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1641
1648
  } catch (t) {
1642
1649
  if (t instanceof m) throw t;
1643
1650
  const o = t instanceof Error ? t.message : String(t);
1644
- throw new m(x.UNKNOWN_ERROR, `Nonce 조회에 실패했습니다: ${o}`, t);
1651
+ throw new m(g.UNKNOWN_ERROR, `Nonce 조회에 실패했습니다: ${o}`, t);
1645
1652
  }
1646
1653
  }
1647
1654
  /**
@@ -1660,7 +1667,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1660
1667
  } catch (t) {
1661
1668
  if (t instanceof m) throw t;
1662
1669
  const o = t instanceof Error ? t.message : String(t);
1663
- throw new m(x.UNKNOWN_ERROR, `잔액 조회에 실패했습니다 (${e}): ${o}`, t);
1670
+ throw new m(g.UNKNOWN_ERROR, `잔액 조회에 실패했습니다 (${e}): ${o}`, t);
1664
1671
  }
1665
1672
  }
1666
1673
  static formatWei(e) {
@@ -1668,7 +1675,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1668
1675
  try {
1669
1676
  const s = BigInt(e);
1670
1677
  if (s === 0n) return "0";
1671
- const t = 10n ** BigInt(Ct), o = s / t, i = (s % t).toString().padStart(Ct, "0").replace(/0+$/, "").slice(0, kt);
1678
+ const t = 10n ** BigInt(kt), o = s / t, i = (s % t).toString().padStart(kt, "0").replace(/0+$/, "").slice(0, Ct);
1672
1679
  return i ? `${o}.${i}` : `${o}`;
1673
1680
  } catch {
1674
1681
  return "?";
@@ -1704,6 +1711,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1704
1711
  * @example
1705
1712
  * const result = await sdk.walletRpc('eth_call', [{ to, data }, 'latest'], 'eip155:612044');
1706
1713
  */
1714
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1707
1715
  async walletRpc(e, s, t) {
1708
1716
  this.ensureAuthenticated();
1709
1717
  try {
@@ -1711,7 +1719,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1711
1719
  } catch (o) {
1712
1720
  if (o instanceof m) throw o;
1713
1721
  const n = o instanceof Error ? o.message : String(o);
1714
- throw new m(x.UNKNOWN_ERROR, `walletRpc 호출에 실패했습니다 [${e}] (${t}): ${n}`, o);
1722
+ throw new m(g.UNKNOWN_ERROR, `walletRpc 호출에 실패했습니다 [${e}] (${t}): ${n}`, o);
1715
1723
  }
1716
1724
  }
1717
1725
  // ============================================================================
@@ -1726,7 +1734,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1726
1734
  try {
1727
1735
  const o = BigInt(e);
1728
1736
  if (o === 0n) return;
1729
- const n = 10n ** BigInt(t), i = o / n, c = (o % n).toString().padStart(t, "0").slice(0, kt).replace(/0+$/, "");
1737
+ const n = 10n ** BigInt(t), i = o / n, c = (o % n).toString().padStart(t, "0").slice(0, Ct).replace(/0+$/, "");
1730
1738
  return `${c ? `${i}.${c}` : `${i}`} ${s}`;
1731
1739
  } catch {
1732
1740
  return;
@@ -1777,7 +1785,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1777
1785
  h.warn(`[CROSSx][Migration Phase 4] PIN 불일치 (시도 ${o}/${n})`), t = "Incorrect PIN.";
1778
1786
  } catch (d) {
1779
1787
  if (!(d instanceof m)) throw d;
1780
- if (d.code === x.MIGRATION_PIN_LOCKED) {
1788
+ if (d.code === g.MIGRATION_PIN_LOCKED) {
1781
1789
  const u = d.details;
1782
1790
  if (n = (u == null ? void 0 : u.maxAttempts) ?? 5, (u == null ? void 0 : u.permanent) === !0)
1783
1791
  return h.warn("[CROSSx][Migration Phase 4] PIN 영구 잠금 (verify-pin)"), await this.confirmation.showPinLockedPrompt(0, "Your account has been permanently locked due to too many failed attempts."), null;
@@ -1793,7 +1801,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1793
1801
  const l = await this.migrateWalletUseCase.execute(i, e);
1794
1802
  return h.log("[CROSSx][Migration Phase 5] 마이그레이션 성공 — address:", l.address), l;
1795
1803
  } catch (l) {
1796
- if (l instanceof m && l.code === x.MIGRATION_FAILED)
1804
+ if (l instanceof m && l.code === g.MIGRATION_FAILED)
1797
1805
  return h.warn("[CROSSx][Migration Phase 5] migrate PIN 불일치 (경합) — 처음부터 재시도"), this.handleMigrationFlow(e);
1798
1806
  throw h.error("[CROSSx][Migration Phase 5] 마이그레이션 실패 (복구 불가):", l), l;
1799
1807
  }
@@ -1844,7 +1852,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1844
1852
  if (e === "0") {
1845
1853
  if (t !== void 0 && t !== 0)
1846
1854
  throw new m(
1847
- x.TYPED_DATA_CHAIN_ID_MISMATCH,
1855
+ g.TYPED_DATA_CHAIN_ID_MISMATCH,
1848
1856
  `오프체인 서명(chainId=0)에서는 typedData.domain.chainId가 없거나 0이어야 합니다. 현재 값: ${t}`
1849
1857
  );
1850
1858
  return;
@@ -1854,12 +1862,12 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1854
1862
  const n = Number(o[1]);
1855
1863
  if (t === void 0)
1856
1864
  throw new m(
1857
- x.TYPED_DATA_CHAIN_ID_MISMATCH,
1865
+ g.TYPED_DATA_CHAIN_ID_MISMATCH,
1858
1866
  `온체인 서명(${e})에서는 typedData.domain.chainId가 반드시 있어야 합니다`
1859
1867
  );
1860
1868
  if (t !== n)
1861
1869
  throw new m(
1862
- x.TYPED_DATA_CHAIN_ID_MISMATCH,
1870
+ g.TYPED_DATA_CHAIN_ID_MISMATCH,
1863
1871
  `typedData.domain.chainId (${t})가 chainId (${e}, 예상값: ${n})와 일치하지 않습니다`
1864
1872
  );
1865
1873
  }
@@ -1877,10 +1885,10 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1877
1885
  static validateSignatureFormat(e) {
1878
1886
  const s = e.startsWith("0x") ? e.slice(2) : e;
1879
1887
  if (!/^[0-9a-fA-F]+$/.test(s))
1880
- throw new m(x.SIGNATURE_FAILED, "유효하지 않은 서명: 올바른 hex 문자열이 아닙니다");
1888
+ throw new m(g.SIGNATURE_FAILED, "유효하지 않은 서명: 올바른 hex 문자열이 아닙니다");
1881
1889
  if (s.length !== Tt)
1882
1890
  throw new m(
1883
- x.SIGNATURE_FAILED,
1891
+ g.SIGNATURE_FAILED,
1884
1892
  `서명 길이가 유효하지 않습니다: ${Tt} hex 문자(65 바이트) 예상, 현재 ${s.length}`
1885
1893
  );
1886
1894
  }
@@ -1888,9 +1896,9 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1888
1896
  static validateSignedTxFormat(e) {
1889
1897
  const s = e.startsWith("0x") ? e.slice(2) : e;
1890
1898
  if (!/^[0-9a-fA-F]+$/.test(s))
1891
- throw new m(x.SIGNATURE_FAILED, "유효하지 않은 서명된 트랜잭션: 올바른 hex 문자열이 아닙니다");
1899
+ throw new m(g.SIGNATURE_FAILED, "유효하지 않은 서명된 트랜잭션: 올바른 hex 문자열이 아닙니다");
1892
1900
  if (s.length < 2)
1893
- throw new m(x.SIGNATURE_FAILED, "유효하지 않은 서명된 트랜잭션: 너무 짧습니다");
1901
+ throw new m(g.SIGNATURE_FAILED, "유효하지 않은 서명된 트랜잭션: 너무 짧습니다");
1894
1902
  }
1895
1903
  /**
1896
1904
  * Gateway 서명 응답의 ecrecover 검증 (XF-036)
@@ -1907,7 +1915,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1907
1915
  expected: t,
1908
1916
  recovered: o
1909
1917
  }), new m(
1910
- x.SIGNATURE_SIGNER_MISMATCH,
1918
+ g.SIGNATURE_SIGNER_MISMATCH,
1911
1919
  `서명자 주소가 일치하지 않습니다: 예상 ${t}, 복원된 주소 ${o}`
1912
1920
  );
1913
1921
  h.log("[CROSSx] 서명 ecrecover 검증 성공");
@@ -1919,7 +1927,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1919
1927
  /** AuthResult를 내부 상태에 반영합니다. */
1920
1928
  applyAuthResult(e) {
1921
1929
  var s, t, o, n;
1922
- this.authenticated = e.success, this.userId = ((s = e.user) == null ? void 0 : s.id) ?? null, this.address = e.address ?? null, this.userEmail = ((t = e.user) == null ? void 0 : t.email) ?? null, this.providerSub = ((o = e.user) == null ? void 0 : o.providerSub) ?? null, this.loginType = Q.normalizeLoginType((n = e.user) == null ? void 0 : n.signInProvider), this.tokenSignatureVerified = e.tokenSignatureVerified ?? !1, this.emit("authChanged", {
1930
+ this.authenticated = e.success, this.userId = ((s = e.user) == null ? void 0 : s.id) ?? null, this.address = e.address ?? null, this.activeWalletIndex = 0, this.userEmail = ((t = e.user) == null ? void 0 : t.email) ?? null, this.providerSub = ((o = e.user) == null ? void 0 : o.providerSub) ?? null, this.loginType = Q.normalizeLoginType((n = e.user) == null ? void 0 : n.signInProvider), this.tokenSignatureVerified = e.tokenSignatureVerified ?? !1, this.emit("authChanged", {
1923
1931
  isAuthenticated: this.authenticated,
1924
1932
  address: this.address,
1925
1933
  userId: this.userId
@@ -1927,7 +1935,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1927
1935
  }
1928
1936
  /** 인증 상태를 초기화합니다. */
1929
1937
  clearAuthState() {
1930
- this.authenticated = !1, this.userId = null, this.address = null, this.userEmail = null, this.providerSub = null, this.loginType = null, this.tokenSignatureVerified = !1, this.passwordStore.clear(), this.emit("authChanged", {
1938
+ this.authenticated = !1, this.userId = null, this.address = null, this.activeWalletIndex = 0, this.userEmail = null, this.providerSub = null, this.loginType = null, this.tokenSignatureVerified = !1, this.passwordStore.clear(), this.emit("authChanged", {
1931
1939
  isAuthenticated: !1,
1932
1940
  address: null,
1933
1941
  userId: null
@@ -1949,7 +1957,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1949
1957
  if (this.passwordStore.has()) return;
1950
1958
  const e = await this.confirmation.showPasswordSetupPrompt();
1951
1959
  if (!e)
1952
- throw new m(x.PASSWORD_CANCELLED, "사용자가 비밀번호 설정을 취소했습니다");
1960
+ throw new m(g.PASSWORD_CANCELLED, "사용자가 비밀번호 설정을 취소했습니다");
1953
1961
  this.passwordStore.set(e), h.log("[CROSSx] 비밀번호 설정 완료 (메모리 캐시)");
1954
1962
  }
1955
1963
  /**
@@ -1963,7 +1971,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1963
1971
  e && this.passwordStore.clear();
1964
1972
  const s = await this.confirmation.showPasswordInputPrompt({ errorMessage: e });
1965
1973
  if (!s)
1966
- throw new m(x.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
1974
+ throw new m(g.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
1967
1975
  this.passwordStore.set(s), h.log("[CROSSx] 비밀번호 입력 완료 (메모리 캐시)");
1968
1976
  }
1969
1977
  /**
@@ -1998,7 +2006,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
1998
2006
  errorMessage: e
1999
2007
  });
2000
2008
  if (!n)
2001
- throw new m(x.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
2009
+ throw new m(g.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
2002
2010
  this.passwordStore.set(n), h.log("[CROSSx] 비밀번호 캐시 완료 (verifyPassword 미지원, 로컬 전용)"), s();
2003
2011
  return;
2004
2012
  }
@@ -2010,13 +2018,13 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
2010
2018
  try {
2011
2019
  return await this.walletProvider.verifyPassword(n) ? (h.log("[CROSSx] 비밀번호 서버 검증 완료 (verify-password)"), { ok: !0 }) : (this.passwordStore.clear(), { ok: !1, error: "Incorrect password. Please try again." });
2012
2020
  } catch (i) {
2013
- if (this.passwordStore.clear(), i instanceof m && i.code === x.PASSWORD_WRONG)
2021
+ if (this.passwordStore.clear(), i instanceof m && i.code === g.PASSWORD_WRONG)
2014
2022
  return { ok: !1, error: "Incorrect password. Please try again." };
2015
2023
  throw i;
2016
2024
  }
2017
2025
  }
2018
2026
  }))
2019
- throw new m(x.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
2027
+ throw new m(g.PASSWORD_CANCELLED, "사용자가 비밀번호 입력을 취소했습니다");
2020
2028
  s();
2021
2029
  } catch (o) {
2022
2030
  throw t(o), o;
@@ -2031,18 +2039,19 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
2031
2039
  * 2. GET /mnemonic/addresses (비밀번호 불필요) → 캐시된 주소가 있으면 바로 사용
2032
2040
  * 3. 빈 배열인 경우 → 비밀번호 확인(메모리 없으면 모달) → POST /mnemonic/address(0)
2033
2041
  */
2034
- async loadWalletAfterAuth() {
2042
+ async loadWalletAfterAuth(e) {
2035
2043
  if (!this.userId) return;
2036
- const e = await this.fetchWalletStatus();
2037
- if (h.log("[CROSSx] loadWalletAfterAuth 지갑 상태:", e), e !== "exists") return;
2038
- const s = await this.walletProvider.getAddresses(this.userId);
2039
- if (s.length > 0) {
2040
- this.address = s[0].address, this.emit("addressChanged", { address: s[0].address, index: s[0].index }), h.log("[CROSSx] 캐시된 주소 로드 완료 (비밀번호 불필요):", this.address);
2044
+ const s = await this.fetchWalletStatus();
2045
+ if (h.log("[CROSSx] loadWalletAfterAuth 지갑 상태:", s), s !== "exists") return;
2046
+ const t = await this.walletProvider.getAddresses(this.userId);
2047
+ if (t.length > 0) {
2048
+ const n = e !== void 0 ? t.find((i) => i.index === e) ?? t[0] : t[0];
2049
+ this.address = n.address, this.activeWalletIndex = n.index, h.log("[CROSSx] 캐시된 주소 로드 완료 (비밀번호 불필요):", this.address), this.emit("addressChanged", { address: n.address, index: n.index });
2041
2050
  return;
2042
2051
  }
2043
2052
  h.log("[CROSSx] 주소 캐시 없음 — 비밀번호 확인 후 address(0) 조회"), await this.ensureVerifiedPassword();
2044
- const t = await this.walletProvider.getAddress(this.userId, 0);
2045
- this.address = t.address, this.emit("addressChanged", { address: t.address, index: 0 }), h.log("[CROSSx] 세션 복원 후 지갑 주소 로드 완료:", this.address);
2053
+ const o = await this.walletProvider.getAddress(this.userId, 0);
2054
+ this.address = o.address, this.activeWalletIndex = 0, h.log("[CROSSx] 세션 복원 후 지갑 주소 로드 완료:", this.address), this.emit("addressChanged", { address: o.address, index: 0 });
2046
2055
  }
2047
2056
  /**
2048
2057
  * PASSWORD_WRONG 에러 시 서버 검증 포함 비밀번호 재입력 모달을 표시하고 재시도합니다.
@@ -2058,7 +2067,7 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
2058
2067
  try {
2059
2068
  return await e();
2060
2069
  } catch (s) {
2061
- if (s instanceof m && s.code === x.PASSWORD_WRONG)
2070
+ if (s instanceof m && s.code === g.PASSWORD_WRONG)
2062
2071
  return h.warn("[CROSSx] 비밀번호 불일치 — 서버 검증 후 재시도"), await this.ensureVerifiedPassword("Incorrect password. Please enter your current password."), await e();
2063
2072
  throw s;
2064
2073
  }
@@ -2066,14 +2075,14 @@ const Ys = 2e3, It = 6e4, Zs = 1e3, Xs = 1e4, Js = "0x77359400", At = "0x3B9ACA0
2066
2075
  ensureInitialized() {
2067
2076
  if (!this.initialized)
2068
2077
  throw new m(
2069
- x.AUTH_NOT_INITIALIZED,
2078
+ g.AUTH_NOT_INITIALIZED,
2070
2079
  "SDK가 초기화되지 않았습니다. initialize()를 먼저 호출하세요."
2071
2080
  );
2072
2081
  }
2073
2082
  ensureAuthenticated() {
2074
2083
  if (this.ensureInitialized(), !this.authenticated)
2075
2084
  throw new m(
2076
- x.AUTH_NOT_AUTHENTICATED,
2085
+ g.AUTH_NOT_AUTHENTICATED,
2077
2086
  "인증되지 않은 상태입니다. signIn()을 먼저 호출하세요."
2078
2087
  );
2079
2088
  }
@@ -2569,7 +2578,7 @@ const Sr = /* @__PURE__ */ ss(
2569
2578
  );
2570
2579
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2571
2580
  const ut = /* @__PURE__ */ BigInt(0), it = /* @__PURE__ */ BigInt(1);
2572
- function qe(r, e = "") {
2581
+ function We(r, e = "") {
2573
2582
  if (typeof r != "boolean") {
2574
2583
  const s = e && `"${e}" `;
2575
2584
  throw new Error(s + "expected boolean, got type=" + typeof r);
@@ -2627,7 +2636,7 @@ function Tr(r) {
2627
2636
  return e;
2628
2637
  }
2629
2638
  const pt = (r) => (it << BigInt(r)) - it;
2630
- function kr(r, e, s) {
2639
+ function Cr(r, e, s) {
2631
2640
  if (pe(r, "hashLen"), pe(e, "qByteLen"), typeof s != "function")
2632
2641
  throw new Error("hmacFn must be a function");
2633
2642
  const t = (y) => new Uint8Array(y), o = Uint8Array.of(), n = Uint8Array.of(0), i = Uint8Array.of(1), a = 1e3;
@@ -2681,7 +2690,7 @@ function Mt(r) {
2681
2690
  };
2682
2691
  }
2683
2692
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2684
- const ee = /* @__PURE__ */ BigInt(0), Z = /* @__PURE__ */ BigInt(1), be = /* @__PURE__ */ BigInt(2), cs = /* @__PURE__ */ BigInt(3), ls = /* @__PURE__ */ BigInt(4), ds = /* @__PURE__ */ BigInt(5), Cr = /* @__PURE__ */ BigInt(7), us = /* @__PURE__ */ BigInt(8), Rr = /* @__PURE__ */ BigInt(9), hs = /* @__PURE__ */ BigInt(16);
2693
+ const ee = /* @__PURE__ */ BigInt(0), Z = /* @__PURE__ */ BigInt(1), be = /* @__PURE__ */ BigInt(2), cs = /* @__PURE__ */ BigInt(3), ls = /* @__PURE__ */ BigInt(4), ds = /* @__PURE__ */ BigInt(5), kr = /* @__PURE__ */ BigInt(7), us = /* @__PURE__ */ BigInt(8), Rr = /* @__PURE__ */ BigInt(9), hs = /* @__PURE__ */ BigInt(16);
2685
2694
  function ne(r, e) {
2686
2695
  const s = r % e;
2687
2696
  return s >= ee ? s : e + s;
@@ -2719,7 +2728,7 @@ function Pr(r, e) {
2719
2728
  return _t(r, a, e), a;
2720
2729
  }
2721
2730
  function Or(r) {
2722
- const e = Ye(r), s = fs(r), t = s(e, e.neg(e.ONE)), o = s(e, t), n = s(e, e.neg(t)), i = (r + Cr) / hs;
2731
+ const e = Ye(r), s = fs(r), t = s(e, e.neg(e.ONE)), o = s(e, t), n = s(e, e.neg(t)), i = (r + kr) / hs;
2723
2732
  return (a, c) => {
2724
2733
  let l = a.pow(c, i), d = a.mul(l, t);
2725
2734
  const u = a.mul(l, o), _ = a.mul(l, n), f = a.eql(a.sqr(d), c), p = a.eql(a.sqr(u), c);
@@ -2953,8 +2962,8 @@ function Ur(r, e, s = !1) {
2953
2962
  return s ? as(a, o) : ht(a, o);
2954
2963
  }
2955
2964
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
2956
- const ke = /* @__PURE__ */ BigInt(0), ve = /* @__PURE__ */ BigInt(1);
2957
- function We(r, e) {
2965
+ const Ce = /* @__PURE__ */ BigInt(0), ve = /* @__PURE__ */ BigInt(1);
2966
+ function qe(r, e) {
2958
2967
  const s = e.negate();
2959
2968
  return r ? s : e;
2960
2969
  }
@@ -2983,7 +2992,7 @@ function st(r) {
2983
2992
  return ms.get(r) || 1;
2984
2993
  }
2985
2994
  function Ht(r) {
2986
- if (r !== ke)
2995
+ if (r !== Ce)
2987
2996
  throw new Error("invalid wNAF");
2988
2997
  }
2989
2998
  class Hr {
@@ -2998,7 +3007,7 @@ class Hr {
2998
3007
  // non-const time multiplication ladder
2999
3008
  _unsafeLadder(e, s, t = this.ZERO) {
3000
3009
  let o = e;
3001
- for (; s > ke; )
3010
+ for (; s > Ce; )
3002
3011
  s & ve && (t = t.add(o)), o = o.double(), s >>= ve;
3003
3012
  return t;
3004
3013
  }
@@ -3038,7 +3047,7 @@ class Hr {
3038
3047
  const i = et(e, this.bits);
3039
3048
  for (let a = 0; a < i.windows; a++) {
3040
3049
  const { nextN: c, offset: l, isZero: d, isNeg: u, isNegF: _, offsetF: f } = Ut(t, a, i);
3041
- t = c, d ? n = n.add(We(_, s[f])) : o = o.add(We(u, s[l]));
3050
+ t = c, d ? n = n.add(qe(_, s[f])) : o = o.add(qe(u, s[l]));
3042
3051
  }
3043
3052
  return Ht(t), { p: o, f: n };
3044
3053
  }
@@ -3049,7 +3058,7 @@ class Hr {
3049
3058
  */
3050
3059
  wNAFUnsafe(e, s, t, o = this.ZERO) {
3051
3060
  const n = et(e, this.bits);
3052
- for (let i = 0; i < n.windows && t !== ke; i++) {
3061
+ for (let i = 0; i < n.windows && t !== Ce; i++) {
3053
3062
  const { nextN: a, offset: c, isZero: l, isNeg: d } = Ut(t, i, n);
3054
3063
  if (t = a, !l) {
3055
3064
  const u = s[c];
@@ -3082,7 +3091,7 @@ class Hr {
3082
3091
  }
3083
3092
  function Fr(r, e, s, t) {
3084
3093
  let o = e, n = r.ZERO, i = r.ZERO;
3085
- for (; s > ke || t > ke; )
3094
+ for (; s > Ce || t > Ce; )
3086
3095
  s & ve && (n = n.add(o)), t & ve && (i = i.add(o)), o = o.double(), s >>= ve, t >>= ve;
3087
3096
  return { p1: n, p2: i };
3088
3097
  }
@@ -3099,7 +3108,7 @@ function Gr(r, e, s = {}, t) {
3099
3108
  throw new Error(`expected valid ${r} CURVE object`);
3100
3109
  for (const c of ["p", "n", "h"]) {
3101
3110
  const l = e[c];
3102
- if (!(typeof l == "bigint" && l > ke))
3111
+ if (!(typeof l == "bigint" && l > Ce))
3103
3112
  throw new Error(`CURVE.${c} must be positive bigint`);
3104
3113
  }
3105
3114
  const o = Ft(e.p, s.Fp, t), n = Ft(e.n, s.Fn, t), a = ["Gx", "Gy", "a", "b"];
@@ -3108,7 +3117,7 @@ function Gr(r, e, s = {}, t) {
3108
3117
  throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
3109
3118
  return e = Object.freeze(Object.assign({}, e)), { CURVE: e, Fp: o, Fn: n };
3110
3119
  }
3111
- function qr(r, e) {
3120
+ function Wr(r, e) {
3112
3121
  return function(t) {
3113
3122
  const o = r(t);
3114
3123
  return { secretKey: o, publicKey: e(o) };
@@ -3160,7 +3169,7 @@ const bs = (r, e, s) => new ys(r, e).update(s).digest();
3160
3169
  bs.create = (r, e) => new ys(r, e);
3161
3170
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3162
3171
  const Gt = (r, e) => (r + (r >= 0 ? e : -e) / vs) / e;
3163
- function Wr(r, e, s) {
3172
+ function qr(r, e, s) {
3164
3173
  const [[t, o], [n, i]] = e, a = Gt(i * r, s), c = Gt(-o * r, s);
3165
3174
  let l = r - a * t - c * n, d = -a * o - c * i;
3166
3175
  const u = l < ue, _ = d < ue;
@@ -3179,7 +3188,7 @@ function rt(r, e) {
3179
3188
  const s = {};
3180
3189
  for (let t of Object.keys(e))
3181
3190
  s[t] = r[t] === void 0 ? e[t] : r[t];
3182
- return qe(s.lowS, "lowS"), qe(s.prehash, "prehash"), s.format !== void 0 && at(s.format), s;
3191
+ return We(s.lowS, "lowS"), We(s.prehash, "prehash"), s.format !== void 0 && at(s.format), s;
3183
3192
  }
3184
3193
  class Vr extends Error {
3185
3194
  constructor(e = "") {
@@ -3294,48 +3303,48 @@ function zr(r, e = {}) {
3294
3303
  if (!t.isOdd)
3295
3304
  throw new Error("compression is not supported: Field does not have .isOdd()");
3296
3305
  }
3297
- function u(L, g, w) {
3298
- const { x: v, y: A } = g.toAffine(), C = t.toBytes(v);
3299
- if (qe(w, "isCompressed"), w) {
3306
+ function u(L, x, w) {
3307
+ const { x: v, y: A } = x.toAffine(), k = t.toBytes(v);
3308
+ if (We(w, "isCompressed"), w) {
3300
3309
  d();
3301
- const k = !t.isOdd(A);
3302
- return we(Ss(k), C);
3310
+ const C = !t.isOdd(A);
3311
+ return we(Ss(C), k);
3303
3312
  } else
3304
- return we(Uint8Array.of(4), C, t.toBytes(A));
3313
+ return we(Uint8Array.of(4), k, t.toBytes(A));
3305
3314
  }
3306
3315
  function _(L) {
3307
3316
  F(L, void 0, "Point");
3308
- const { publicKey: g, publicKeyUncompressed: w } = l, v = L.length, A = L[0], C = L.subarray(1);
3309
- if (v === g && (A === 2 || A === 3)) {
3310
- const k = t.fromBytes(C);
3311
- if (!t.isValid(k))
3317
+ const { publicKey: x, publicKeyUncompressed: w } = l, v = L.length, A = L[0], k = L.subarray(1);
3318
+ if (v === x && (A === 2 || A === 3)) {
3319
+ const C = t.fromBytes(k);
3320
+ if (!t.isValid(C))
3312
3321
  throw new Error("bad point: is not on curve, wrong x");
3313
- const R = b(k);
3322
+ const R = b(C);
3314
3323
  let I;
3315
3324
  try {
3316
3325
  I = t.sqrt(R);
3317
- } catch (W) {
3318
- const H = W instanceof Error ? ": " + W.message : "";
3326
+ } catch (q) {
3327
+ const H = q instanceof Error ? ": " + q.message : "";
3319
3328
  throw new Error("bad point: is not on curve, sqrt error" + H);
3320
3329
  }
3321
3330
  d();
3322
3331
  const P = t.isOdd(I);
3323
- return (A & 1) === 1 !== P && (I = t.neg(I)), { x: k, y: I };
3332
+ return (A & 1) === 1 !== P && (I = t.neg(I)), { x: C, y: I };
3324
3333
  } else if (v === w && A === 4) {
3325
- const k = t.BYTES, R = t.fromBytes(C.subarray(0, k)), I = t.fromBytes(C.subarray(k, k * 2));
3334
+ const C = t.BYTES, R = t.fromBytes(k.subarray(0, C)), I = t.fromBytes(k.subarray(C, C * 2));
3326
3335
  if (!y(R, I))
3327
3336
  throw new Error("bad point: is not on curve");
3328
3337
  return { x: R, y: I };
3329
3338
  } else
3330
- throw new Error(`bad point: got length ${v}, expected compressed=${g} or uncompressed=${w}`);
3339
+ throw new Error(`bad point: got length ${v}, expected compressed=${x} or uncompressed=${w}`);
3331
3340
  }
3332
3341
  const f = e.toBytes || u, p = e.fromBytes || _;
3333
3342
  function b(L) {
3334
- const g = t.sqr(L), w = t.mul(g, L);
3343
+ const x = t.sqr(L), w = t.mul(x, L);
3335
3344
  return t.add(t.add(w, t.mul(L, n.a)), n.b);
3336
3345
  }
3337
- function y(L, g) {
3338
- const w = t.sqr(g), v = b(L);
3346
+ function y(L, x) {
3347
+ const w = t.sqr(x), v = b(L);
3339
3348
  return t.eql(w, v);
3340
3349
  }
3341
3350
  if (!y(n.Gx, n.Gy))
@@ -3343,10 +3352,10 @@ function zr(r, e = {}) {
3343
3352
  const E = t.mul(t.pow(n.a, Be), Kr), M = t.mul(t.sqr(n.b), BigInt(27));
3344
3353
  if (t.is0(t.add(E, M)))
3345
3354
  throw new Error("bad curve params: a or b");
3346
- function U(L, g, w = !1) {
3347
- if (!t.isValid(g) || w && t.is0(g))
3355
+ function U(L, x, w = !1) {
3356
+ if (!t.isValid(x) || w && t.is0(x))
3348
3357
  throw new Error(`bad point coordinate ${L}`);
3349
- return g;
3358
+ return x;
3350
3359
  }
3351
3360
  function D(L) {
3352
3361
  if (!(L instanceof J))
@@ -3355,64 +3364,64 @@ function zr(r, e = {}) {
3355
3364
  function B(L) {
3356
3365
  if (!c || !c.basises)
3357
3366
  throw new Error("no endo");
3358
- return Wr(L, c.basises, o.ORDER);
3367
+ return qr(L, c.basises, o.ORDER);
3359
3368
  }
3360
- const K = Mt((L, g) => {
3369
+ const K = Mt((L, x) => {
3361
3370
  const { X: w, Y: v, Z: A } = L;
3362
3371
  if (t.eql(A, t.ONE))
3363
3372
  return { x: w, y: v };
3364
- const C = L.is0();
3365
- g == null && (g = C ? t.ONE : t.inv(A));
3366
- const k = t.mul(w, g), R = t.mul(v, g), I = t.mul(A, g);
3367
- if (C)
3373
+ const k = L.is0();
3374
+ x == null && (x = k ? t.ONE : t.inv(A));
3375
+ const C = t.mul(w, x), R = t.mul(v, x), I = t.mul(A, x);
3376
+ if (k)
3368
3377
  return { x: t.ZERO, y: t.ZERO };
3369
3378
  if (!t.eql(I, t.ONE))
3370
3379
  throw new Error("invZ was invalid");
3371
- return { x: k, y: R };
3380
+ return { x: C, y: R };
3372
3381
  }), le = Mt((L) => {
3373
3382
  if (L.is0()) {
3374
3383
  if (e.allowInfinityPoint && !t.is0(L.Y))
3375
3384
  return;
3376
3385
  throw new Error("bad point: ZERO");
3377
3386
  }
3378
- const { x: g, y: w } = L.toAffine();
3379
- if (!t.isValid(g) || !t.isValid(w))
3387
+ const { x, y: w } = L.toAffine();
3388
+ if (!t.isValid(x) || !t.isValid(w))
3380
3389
  throw new Error("bad point: x or y not field elements");
3381
- if (!y(g, w))
3390
+ if (!y(x, w))
3382
3391
  throw new Error("bad point: equation left != right");
3383
3392
  if (!L.isTorsionFree())
3384
3393
  throw new Error("bad point: not in prime-order subgroup");
3385
3394
  return !0;
3386
3395
  });
3387
- function fe(L, g, w, v, A) {
3388
- return w = new J(t.mul(w.X, L), w.Y, w.Z), g = We(v, g), w = We(A, w), g.add(w);
3396
+ function fe(L, x, w, v, A) {
3397
+ return w = new J(t.mul(w.X, L), w.Y, w.Z), x = qe(v, x), w = qe(A, w), x.add(w);
3389
3398
  }
3390
3399
  const $ = class $ {
3391
3400
  /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
3392
- constructor(g, w, v) {
3401
+ constructor(x, w, v) {
3393
3402
  S(this, "X");
3394
3403
  S(this, "Y");
3395
3404
  S(this, "Z");
3396
- this.X = U("x", g), this.Y = U("y", w, !0), this.Z = U("z", v), Object.freeze(this);
3405
+ this.X = U("x", x), this.Y = U("y", w, !0), this.Z = U("z", v), Object.freeze(this);
3397
3406
  }
3398
3407
  static CURVE() {
3399
3408
  return n;
3400
3409
  }
3401
3410
  /** Does NOT validate if the point is valid. Use `.assertValidity()`. */
3402
- static fromAffine(g) {
3403
- const { x: w, y: v } = g || {};
3404
- if (!g || !t.isValid(w) || !t.isValid(v))
3411
+ static fromAffine(x) {
3412
+ const { x: w, y: v } = x || {};
3413
+ if (!x || !t.isValid(w) || !t.isValid(v))
3405
3414
  throw new Error("invalid affine point");
3406
- if (g instanceof $)
3415
+ if (x instanceof $)
3407
3416
  throw new Error("projective point not allowed");
3408
3417
  return t.is0(w) && t.is0(v) ? $.ZERO : new $(w, v, t.ONE);
3409
3418
  }
3410
- static fromBytes(g) {
3411
- const w = $.fromAffine(p(F(g, void 0, "point")));
3419
+ static fromBytes(x) {
3420
+ const w = $.fromAffine(p(F(x, void 0, "point")));
3412
3421
  return w.assertValidity(), w;
3413
3422
  }
3414
- static fromHex(g) {
3415
- return $.fromBytes(Ge(g));
3423
+ static fromHex(x) {
3424
+ return $.fromBytes(Ge(x));
3416
3425
  }
3417
3426
  get x() {
3418
3427
  return this.toAffine().x;
@@ -3426,8 +3435,8 @@ function zr(r, e = {}) {
3426
3435
  * @param isLazy true will defer table computation until the first multiplication
3427
3436
  * @returns
3428
3437
  */
3429
- precompute(g = 8, w = !0) {
3430
- return ie.createCache(this, g), w || this.multiply(Be), this;
3438
+ precompute(x = 8, w = !0) {
3439
+ return ie.createCache(this, x), w || this.multiply(Be), this;
3431
3440
  }
3432
3441
  // TODO: return `this`
3433
3442
  /** A point on curve is valid if it conforms to equation. */
@@ -3435,15 +3444,15 @@ function zr(r, e = {}) {
3435
3444
  le(this);
3436
3445
  }
3437
3446
  hasEvenY() {
3438
- const { y: g } = this.toAffine();
3447
+ const { y: x } = this.toAffine();
3439
3448
  if (!t.isOdd)
3440
3449
  throw new Error("Field doesn't support isOdd");
3441
- return !t.isOdd(g);
3450
+ return !t.isOdd(x);
3442
3451
  }
3443
3452
  /** Compare one point to another. */
3444
- equals(g) {
3445
- D(g);
3446
- const { X: w, Y: v, Z: A } = this, { X: C, Y: k, Z: R } = g, I = t.eql(t.mul(w, R), t.mul(C, A)), P = t.eql(t.mul(v, R), t.mul(k, A));
3453
+ equals(x) {
3454
+ D(x);
3455
+ const { X: w, Y: v, Z: A } = this, { X: k, Y: C, Z: R } = x, I = t.eql(t.mul(w, R), t.mul(k, A)), P = t.eql(t.mul(v, R), t.mul(C, A));
3447
3456
  return I && P;
3448
3457
  }
3449
3458
  /** Flips point to one corresponding to (x, -y) in Affine coordinates. */
@@ -3455,26 +3464,26 @@ function zr(r, e = {}) {
3455
3464
  // https://eprint.iacr.org/2015/1060, algorithm 3
3456
3465
  // Cost: 8M + 3S + 3*a + 2*b3 + 15add.
3457
3466
  double() {
3458
- const { a: g, b: w } = n, v = t.mul(w, Be), { X: A, Y: C, Z: k } = this;
3459
- let R = t.ZERO, I = t.ZERO, P = t.ZERO, N = t.mul(A, A), W = t.mul(C, C), H = t.mul(k, k), O = t.mul(A, C);
3460
- return O = t.add(O, O), P = t.mul(A, k), P = t.add(P, P), R = t.mul(g, P), I = t.mul(v, H), I = t.add(R, I), R = t.sub(W, I), I = t.add(W, I), I = t.mul(R, I), R = t.mul(O, R), P = t.mul(v, P), H = t.mul(g, H), O = t.sub(N, H), O = t.mul(g, O), O = t.add(O, P), P = t.add(N, N), N = t.add(P, N), N = t.add(N, H), N = t.mul(N, O), I = t.add(I, N), H = t.mul(C, k), H = t.add(H, H), N = t.mul(H, O), R = t.sub(R, N), P = t.mul(H, W), P = t.add(P, P), P = t.add(P, P), new $(R, I, P);
3467
+ const { a: x, b: w } = n, v = t.mul(w, Be), { X: A, Y: k, Z: C } = this;
3468
+ let R = t.ZERO, I = t.ZERO, P = t.ZERO, N = t.mul(A, A), q = t.mul(k, k), H = t.mul(C, C), O = t.mul(A, k);
3469
+ return O = t.add(O, O), P = t.mul(A, C), P = t.add(P, P), R = t.mul(x, P), I = t.mul(v, H), I = t.add(R, I), R = t.sub(q, I), I = t.add(q, I), I = t.mul(R, I), R = t.mul(O, R), P = t.mul(v, P), H = t.mul(x, H), O = t.sub(N, H), O = t.mul(x, O), O = t.add(O, P), P = t.add(N, N), N = t.add(P, N), N = t.add(N, H), N = t.mul(N, O), I = t.add(I, N), H = t.mul(k, C), H = t.add(H, H), N = t.mul(H, O), R = t.sub(R, N), P = t.mul(H, q), P = t.add(P, P), P = t.add(P, P), new $(R, I, P);
3461
3470
  }
3462
3471
  // Renes-Costello-Batina exception-free addition formula.
3463
3472
  // There is 30% faster Jacobian formula, but it is not complete.
3464
3473
  // https://eprint.iacr.org/2015/1060, algorithm 1
3465
3474
  // Cost: 12M + 0S + 3*a + 3*b3 + 23add.
3466
- add(g) {
3467
- D(g);
3468
- const { X: w, Y: v, Z: A } = this, { X: C, Y: k, Z: R } = g;
3475
+ add(x) {
3476
+ D(x);
3477
+ const { X: w, Y: v, Z: A } = this, { X: k, Y: C, Z: R } = x;
3469
3478
  let I = t.ZERO, P = t.ZERO, N = t.ZERO;
3470
- const W = n.a, H = t.mul(n.b, Be);
3471
- let O = t.mul(w, C), V = t.mul(v, k), j = t.mul(A, R), se = t.add(w, v), G = t.add(C, k);
3479
+ const q = n.a, H = t.mul(n.b, Be);
3480
+ let O = t.mul(w, k), V = t.mul(v, C), j = t.mul(A, R), se = t.add(w, v), G = t.add(k, C);
3472
3481
  se = t.mul(se, G), G = t.add(O, V), se = t.sub(se, G), G = t.add(w, A);
3473
- let Y = t.add(C, R);
3474
- return G = t.mul(G, Y), Y = t.add(O, j), G = t.sub(G, Y), Y = t.add(v, A), I = t.add(k, R), Y = t.mul(Y, I), I = t.add(V, j), Y = t.sub(Y, I), N = t.mul(W, G), I = t.mul(H, j), N = t.add(I, N), I = t.sub(V, N), N = t.add(V, N), P = t.mul(I, N), V = t.add(O, O), V = t.add(V, O), j = t.mul(W, j), G = t.mul(H, G), V = t.add(V, j), j = t.sub(O, j), j = t.mul(W, j), G = t.add(G, j), O = t.mul(V, G), P = t.add(P, O), O = t.mul(Y, G), I = t.mul(se, I), I = t.sub(I, O), O = t.mul(se, V), N = t.mul(Y, N), N = t.add(N, O), new $(I, P, N);
3482
+ let Y = t.add(k, R);
3483
+ return G = t.mul(G, Y), Y = t.add(O, j), G = t.sub(G, Y), Y = t.add(v, A), I = t.add(C, R), Y = t.mul(Y, I), I = t.add(V, j), Y = t.sub(Y, I), N = t.mul(q, G), I = t.mul(H, j), N = t.add(I, N), I = t.sub(V, N), N = t.add(V, N), P = t.mul(I, N), V = t.add(O, O), V = t.add(V, O), j = t.mul(q, j), G = t.mul(H, G), V = t.add(V, j), j = t.sub(O, j), j = t.mul(q, j), G = t.add(G, j), O = t.mul(V, G), P = t.add(P, O), O = t.mul(Y, G), I = t.mul(se, I), I = t.sub(I, O), O = t.mul(se, V), N = t.mul(Y, N), N = t.add(N, O), new $(I, P, N);
3475
3484
  }
3476
- subtract(g) {
3477
- return this.add(g.negate());
3485
+ subtract(x) {
3486
+ return this.add(x.negate());
3478
3487
  }
3479
3488
  is0() {
3480
3489
  return this.equals($.ZERO);
@@ -3488,18 +3497,18 @@ function zr(r, e = {}) {
3488
3497
  * @param scalar by which the point would be multiplied
3489
3498
  * @returns New point
3490
3499
  */
3491
- multiply(g) {
3500
+ multiply(x) {
3492
3501
  const { endo: w } = e;
3493
- if (!o.isValidNot0(g))
3502
+ if (!o.isValidNot0(x))
3494
3503
  throw new Error("invalid scalar: out of range");
3495
3504
  let v, A;
3496
- const C = (k) => ie.cached(this, k, (R) => Bt($, R));
3505
+ const k = (C) => ie.cached(this, C, (R) => Bt($, R));
3497
3506
  if (w) {
3498
- const { k1neg: k, k1: R, k2neg: I, k2: P } = B(g), { p: N, f: W } = C(R), { p: H, f: O } = C(P);
3499
- A = W.add(O), v = fe(w.beta, N, H, k, I);
3507
+ const { k1neg: C, k1: R, k2neg: I, k2: P } = B(x), { p: N, f: q } = k(R), { p: H, f: O } = k(P);
3508
+ A = q.add(O), v = fe(w.beta, N, H, C, I);
3500
3509
  } else {
3501
- const { p: k, f: R } = C(g);
3502
- v = k, A = R;
3510
+ const { p: C, f: R } = k(x);
3511
+ v = C, A = R;
3503
3512
  }
3504
3513
  return Bt($, [v, A])[0];
3505
3514
  }
@@ -3508,49 +3517,49 @@ function zr(r, e = {}) {
3508
3517
  * It's faster, but should only be used when you don't care about
3509
3518
  * an exposed secret key e.g. sig verification, which works over *public* keys.
3510
3519
  */
3511
- multiplyUnsafe(g) {
3520
+ multiplyUnsafe(x) {
3512
3521
  const { endo: w } = e, v = this;
3513
- if (!o.isValid(g))
3522
+ if (!o.isValid(x))
3514
3523
  throw new Error("invalid scalar: out of range");
3515
- if (g === ue || v.is0())
3524
+ if (x === ue || v.is0())
3516
3525
  return $.ZERO;
3517
- if (g === Ie)
3526
+ if (x === Ie)
3518
3527
  return v;
3519
3528
  if (ie.hasCache(this))
3520
- return this.multiply(g);
3529
+ return this.multiply(x);
3521
3530
  if (w) {
3522
- const { k1neg: A, k1: C, k2neg: k, k2: R } = B(g), { p1: I, p2: P } = Fr($, v, C, R);
3523
- return fe(w.beta, I, P, A, k);
3531
+ const { k1neg: A, k1: k, k2neg: C, k2: R } = B(x), { p1: I, p2: P } = Fr($, v, k, R);
3532
+ return fe(w.beta, I, P, A, C);
3524
3533
  } else
3525
- return ie.unsafe(v, g);
3534
+ return ie.unsafe(v, x);
3526
3535
  }
3527
3536
  /**
3528
3537
  * Converts Projective point to affine (x, y) coordinates.
3529
3538
  * @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
3530
3539
  */
3531
- toAffine(g) {
3532
- return K(this, g);
3540
+ toAffine(x) {
3541
+ return K(this, x);
3533
3542
  }
3534
3543
  /**
3535
3544
  * Checks whether Point is free of torsion elements (is in prime subgroup).
3536
3545
  * Always torsion-free for cofactor=1 curves.
3537
3546
  */
3538
3547
  isTorsionFree() {
3539
- const { isTorsionFree: g } = e;
3540
- return i === Ie ? !0 : g ? g($, this) : ie.unsafe(this, a).is0();
3548
+ const { isTorsionFree: x } = e;
3549
+ return i === Ie ? !0 : x ? x($, this) : ie.unsafe(this, a).is0();
3541
3550
  }
3542
3551
  clearCofactor() {
3543
- const { clearCofactor: g } = e;
3544
- return i === Ie ? this : g ? g($, this) : this.multiplyUnsafe(i);
3552
+ const { clearCofactor: x } = e;
3553
+ return i === Ie ? this : x ? x($, this) : this.multiplyUnsafe(i);
3545
3554
  }
3546
3555
  isSmallOrder() {
3547
3556
  return this.multiplyUnsafe(i).is0();
3548
3557
  }
3549
- toBytes(g = !0) {
3550
- return qe(g, "isCompressed"), this.assertValidity(), f($, this, g);
3558
+ toBytes(x = !0) {
3559
+ return We(x, "isCompressed"), this.assertValidity(), f($, this, x);
3551
3560
  }
3552
- toHex(g = !0) {
3553
- return Oe(this.toBytes(g));
3561
+ toHex(x = !0) {
3562
+ return Oe(this.toBytes(x));
3554
3563
  }
3555
3564
  toString() {
3556
3565
  return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
@@ -3622,7 +3631,7 @@ function jr(r, e = {}) {
3622
3631
  isValidSecretKey: n,
3623
3632
  isValidPublicKey: i,
3624
3633
  randomSecretKey: a
3625
- }, _ = qr(a, c);
3634
+ }, _ = Wr(a, c);
3626
3635
  return Object.freeze({ getPublicKey: c, getSharedSecret: d, keygen: _, Point: r, utils: u, lengths: o });
3627
3636
  }
3628
3637
  function Yr(r, e, s = {}) {
@@ -3633,29 +3642,29 @@ function Yr(r, e, s = {}) {
3633
3642
  bits2int: "function",
3634
3643
  bits2int_modN: "function"
3635
3644
  }), s = Object.assign({}, s);
3636
- const t = s.randomBytes || rs, o = s.hmac || ((g, w) => bs(e, g, w)), { Fp: n, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret: u, utils: _, lengths: f } = jr(r, s), p = {
3645
+ const t = s.randomBytes || rs, o = s.hmac || ((x, w) => bs(e, x, w)), { Fp: n, Fn: i } = r, { ORDER: a, BITS: c } = i, { keygen: l, getPublicKey: d, getSharedSecret: u, utils: _, lengths: f } = jr(r, s), p = {
3637
3646
  prehash: !0,
3638
3647
  lowS: typeof s.lowS == "boolean" ? s.lowS : !0,
3639
3648
  format: "compact",
3640
3649
  extraEntropy: !1
3641
3650
  }, b = a * vs < n.ORDER;
3642
- function y(g) {
3651
+ function y(x) {
3643
3652
  const w = a >> Ie;
3644
- return g > w;
3653
+ return x > w;
3645
3654
  }
3646
- function E(g, w) {
3655
+ function E(x, w) {
3647
3656
  if (!i.isValidNot0(w))
3648
- throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);
3657
+ throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);
3649
3658
  return w;
3650
3659
  }
3651
3660
  function M() {
3652
3661
  if (b)
3653
3662
  throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
3654
3663
  }
3655
- function U(g, w) {
3664
+ function U(x, w) {
3656
3665
  at(w);
3657
3666
  const v = f.signature, A = w === "compact" ? v : w === "recovered" ? v + 1 : void 0;
3658
- return F(g, A);
3667
+ return F(x, A);
3659
3668
  }
3660
3669
  class D {
3661
3670
  constructor(w, v, A) {
@@ -3677,8 +3686,8 @@ function Yr(r, e, s = {}) {
3677
3686
  return new D(I, P);
3678
3687
  }
3679
3688
  v === "recovered" && (A = w[0], v = "compact", w = w.subarray(1));
3680
- const C = f.signature / 2, k = w.subarray(0, C), R = w.subarray(C, C * 2);
3681
- return new D(i.fromBytes(k), i.fromBytes(R), A);
3689
+ const k = f.signature / 2, C = w.subarray(0, k), R = w.subarray(k, k * 2);
3690
+ return new D(i.fromBytes(C), i.fromBytes(R), A);
3682
3691
  }
3683
3692
  static fromHex(w, v) {
3684
3693
  return this.fromBytes(Ge(w), v);
@@ -3693,10 +3702,10 @@ function Yr(r, e, s = {}) {
3693
3702
  return new D(this.r, this.s, w);
3694
3703
  }
3695
3704
  recoverPublicKey(w) {
3696
- const { r: v, s: A } = this, C = this.assertRecovery(), k = C === 2 || C === 3 ? v + a : v;
3697
- if (!n.isValid(k))
3705
+ const { r: v, s: A } = this, k = this.assertRecovery(), C = k === 2 || k === 3 ? v + a : v;
3706
+ if (!n.isValid(C))
3698
3707
  throw new Error("invalid recovery id: sig.r+curve.n != R.x");
3699
- const R = n.toBytes(k), I = r.fromBytes(we(Ss((C & 1) === 0), R)), P = i.inv(k), N = K(F(w, void 0, "msgHash")), W = i.create(-N * P), H = i.create(A * P), O = r.BASE.multiplyUnsafe(W).add(I.multiplyUnsafe(H));
3708
+ const R = n.toBytes(C), I = r.fromBytes(we(Ss((k & 1) === 0), R)), P = i.inv(C), N = K(F(w, void 0, "msgHash")), q = i.create(-N * P), H = i.create(A * P), O = r.BASE.multiplyUnsafe(q).add(I.multiplyUnsafe(H));
3700
3709
  if (O.is0())
3701
3710
  throw new Error("invalid recovery: point at infinify");
3702
3711
  return O.assertValidity(), O;
@@ -3708,8 +3717,8 @@ function Yr(r, e, s = {}) {
3708
3717
  toBytes(w = p.format) {
3709
3718
  if (at(w), w === "der")
3710
3719
  return Ge(xe.hexFromSig(this));
3711
- const { r: v, s: A } = this, C = i.toBytes(v), k = i.toBytes(A);
3712
- return w === "recovered" ? (M(), we(Uint8Array.of(this.assertRecovery()), C, k)) : we(C, k);
3720
+ const { r: v, s: A } = this, k = i.toBytes(v), C = i.toBytes(A);
3721
+ return w === "recovered" ? (M(), we(Uint8Array.of(this.assertRecovery()), k, C)) : we(k, C);
3713
3722
  }
3714
3723
  toHex(w) {
3715
3724
  return Oe(this.toBytes(w));
@@ -3723,24 +3732,24 @@ function Yr(r, e, s = {}) {
3723
3732
  }, K = s.bits2int_modN || function(w) {
3724
3733
  return i.create(B(w));
3725
3734
  }, le = pt(c);
3726
- function fe(g) {
3727
- return Ar("num < 2^" + c, g, ue, le), i.toBytes(g);
3735
+ function fe(x) {
3736
+ return Ar("num < 2^" + c, x, ue, le), i.toBytes(x);
3728
3737
  }
3729
- function J(g, w) {
3730
- return F(g, void 0, "message"), w ? F(e(g), void 0, "prehashed message") : g;
3738
+ function J(x, w) {
3739
+ return F(x, void 0, "message"), w ? F(e(x), void 0, "prehashed message") : x;
3731
3740
  }
3732
- function me(g, w, v) {
3733
- const { lowS: A, prehash: C, extraEntropy: k } = rt(v, p);
3734
- g = J(g, C);
3735
- const R = K(g), I = i.fromBytes(w);
3741
+ function me(x, w, v) {
3742
+ const { lowS: A, prehash: k, extraEntropy: C } = rt(v, p);
3743
+ x = J(x, k);
3744
+ const R = K(x), I = i.fromBytes(w);
3736
3745
  if (!i.isValidNot0(I))
3737
3746
  throw new Error("invalid private key");
3738
3747
  const P = [fe(I), fe(R)];
3739
- if (k != null && k !== !1) {
3740
- const O = k === !0 ? t(f.secretKey) : k;
3748
+ if (C != null && C !== !1) {
3749
+ const O = C === !0 ? t(f.secretKey) : C;
3741
3750
  P.push(F(O, void 0, "extraEntropy"));
3742
3751
  }
3743
- const N = we(...P), W = R;
3752
+ const N = we(...P), q = R;
3744
3753
  function H(O) {
3745
3754
  const V = B(O);
3746
3755
  if (!i.isValidNot0(V))
@@ -3748,7 +3757,7 @@ function Yr(r, e, s = {}) {
3748
3757
  const j = i.inv(V), se = r.BASE.multiply(V).toAffine(), G = i.create(se.x);
3749
3758
  if (G === ue)
3750
3759
  return;
3751
- const Y = i.create(j * i.create(W + G * I));
3760
+ const Y = i.create(j * i.create(q + G * I));
3752
3761
  if (Y === ue)
3753
3762
  return;
3754
3763
  let bt = (se.x === G ? 0 : 2) | Number(se.y & Ie), vt = Y;
@@ -3756,30 +3765,30 @@ function Yr(r, e, s = {}) {
3756
3765
  }
3757
3766
  return { seed: N, k2sig: H };
3758
3767
  }
3759
- function ie(g, w, v = {}) {
3760
- const { seed: A, k2sig: C } = me(g, w, v);
3761
- return kr(e.outputLen, i.BYTES, o)(A, C).toBytes(v.format);
3768
+ function ie(x, w, v = {}) {
3769
+ const { seed: A, k2sig: k } = me(x, w, v);
3770
+ return Cr(e.outputLen, i.BYTES, o)(A, k).toBytes(v.format);
3762
3771
  }
3763
- function $(g, w, v, A = {}) {
3764
- const { lowS: C, prehash: k, format: R } = rt(A, p);
3765
- if (v = F(v, void 0, "publicKey"), w = J(w, k), !dt(g)) {
3766
- const I = g instanceof D ? ", use sig.toBytes()" : "";
3772
+ function $(x, w, v, A = {}) {
3773
+ const { lowS: k, prehash: C, format: R } = rt(A, p);
3774
+ if (v = F(v, void 0, "publicKey"), w = J(w, C), !dt(x)) {
3775
+ const I = x instanceof D ? ", use sig.toBytes()" : "";
3767
3776
  throw new Error("verify expects Uint8Array signature" + I);
3768
3777
  }
3769
- U(g, R);
3778
+ U(x, R);
3770
3779
  try {
3771
- const I = D.fromBytes(g, R), P = r.fromBytes(v);
3772
- if (C && I.hasHighS())
3780
+ const I = D.fromBytes(x, R), P = r.fromBytes(v);
3781
+ if (k && I.hasHighS())
3773
3782
  return !1;
3774
- const { r: N, s: W } = I, H = K(w), O = i.inv(W), V = i.create(H * O), j = i.create(N * O), se = r.BASE.multiplyUnsafe(V).add(P.multiplyUnsafe(j));
3783
+ const { r: N, s: q } = I, H = K(w), O = i.inv(q), V = i.create(H * O), j = i.create(N * O), se = r.BASE.multiplyUnsafe(V).add(P.multiplyUnsafe(j));
3775
3784
  return se.is0() ? !1 : i.create(se.x) === N;
3776
3785
  } catch {
3777
3786
  return !1;
3778
3787
  }
3779
3788
  }
3780
- function L(g, w, v = {}) {
3789
+ function L(x, w, v = {}) {
3781
3790
  const { prehash: A } = rt(v, p);
3782
- return w = J(w, A), D.fromBytes(g, "recovered").recoverPublicKey(w).toBytes();
3791
+ return w = J(w, A), D.fromBytes(x, "recovered").recoverPublicKey(w).toBytes();
3783
3792
  }
3784
3793
  return Object.freeze({
3785
3794
  keygen: l,
@@ -3810,9 +3819,9 @@ const gt = {
3810
3819
  [BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
3811
3820
  [BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
3812
3821
  ]
3813
- }, qt = /* @__PURE__ */ BigInt(2);
3822
+ }, Wt = /* @__PURE__ */ BigInt(2);
3814
3823
  function Xr(r) {
3815
- const e = gt.p, s = BigInt(3), t = BigInt(6), o = BigInt(11), n = BigInt(22), i = BigInt(23), a = BigInt(44), c = BigInt(88), l = r * r * r % e, d = l * l * r % e, u = oe(d, s, e) * d % e, _ = oe(u, s, e) * d % e, f = oe(_, qt, e) * l % e, p = oe(f, o, e) * f % e, b = oe(p, n, e) * p % e, y = oe(b, a, e) * b % e, E = oe(y, c, e) * y % e, M = oe(E, a, e) * b % e, U = oe(M, s, e) * d % e, D = oe(U, i, e) * p % e, B = oe(D, t, e) * l % e, K = oe(B, qt, e);
3824
+ const e = gt.p, s = BigInt(3), t = BigInt(6), o = BigInt(11), n = BigInt(22), i = BigInt(23), a = BigInt(44), c = BigInt(88), l = r * r * r % e, d = l * l * r % e, u = oe(d, s, e) * d % e, _ = oe(u, s, e) * d % e, f = oe(_, Wt, e) * l % e, p = oe(f, o, e) * f % e, b = oe(p, n, e) * p % e, y = oe(b, a, e) * b % e, E = oe(y, c, e) * y % e, M = oe(E, a, e) * b % e, U = oe(M, s, e) * d % e, D = oe(U, i, e) * p % e, B = oe(D, t, e) * l % e, K = oe(B, Wt, e);
3816
3825
  if (!ct.eql(ct.sqr(K), r))
3817
3826
  throw new Error("Cannot find square root");
3818
3827
  return K;
@@ -3820,28 +3829,28 @@ function Xr(r) {
3820
3829
  const ct = Ye(gt.p, { sqrt: Xr }), Jr = /* @__PURE__ */ zr(gt, {
3821
3830
  Fp: ct,
3822
3831
  endo: Zr
3823
- }), Qr = /* @__PURE__ */ Yr(Jr, Sr), eo = BigInt(0), Ce = BigInt(1), to = BigInt(2), so = BigInt(7), ro = BigInt(256), oo = BigInt(113), Is = [], As = [], Ts = [];
3824
- for (let r = 0, e = Ce, s = 1, t = 0; r < 24; r++) {
3832
+ }), Qr = /* @__PURE__ */ Yr(Jr, Sr), eo = BigInt(0), ke = BigInt(1), to = BigInt(2), so = BigInt(7), ro = BigInt(256), oo = BigInt(113), Is = [], As = [], Ts = [];
3833
+ for (let r = 0, e = ke, s = 1, t = 0; r < 24; r++) {
3825
3834
  [s, t] = [t, (2 * s + 3 * t) % 5], Is.push(2 * (5 * t + s)), As.push((r + 1) * (r + 2) / 2 % 64);
3826
3835
  let o = eo;
3827
3836
  for (let n = 0; n < 7; n++)
3828
- e = (e << Ce ^ (e >> so) * oo) % ro, e & to && (o ^= Ce << (Ce << BigInt(n)) - Ce);
3837
+ e = (e << ke ^ (e >> so) * oo) % ro, e & to && (o ^= ke << (ke << BigInt(n)) - ke);
3829
3838
  Ts.push(o);
3830
3839
  }
3831
- const ks = _r(Ts, !0), no = ks[0], io = ks[1], Wt = (r, e, s) => s > 32 ? wr(r, e, s) : gr(r, e, s), Vt = (r, e, s) => s > 32 ? mr(r, e, s) : xr(r, e, s);
3840
+ const Cs = _r(Ts, !0), no = Cs[0], io = Cs[1], qt = (r, e, s) => s > 32 ? wr(r, e, s) : gr(r, e, s), Vt = (r, e, s) => s > 32 ? mr(r, e, s) : xr(r, e, s);
3832
3841
  function ao(r, e = 24) {
3833
3842
  const s = new Uint32Array(10);
3834
3843
  for (let t = 24 - e; t < 24; t++) {
3835
3844
  for (let i = 0; i < 10; i++)
3836
3845
  s[i] = r[i] ^ r[i + 10] ^ r[i + 20] ^ r[i + 30] ^ r[i + 40];
3837
3846
  for (let i = 0; i < 10; i += 2) {
3838
- const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1], u = Wt(l, d, 1) ^ s[a], _ = Vt(l, d, 1) ^ s[a + 1];
3847
+ const a = (i + 8) % 10, c = (i + 2) % 10, l = s[c], d = s[c + 1], u = qt(l, d, 1) ^ s[a], _ = Vt(l, d, 1) ^ s[a + 1];
3839
3848
  for (let f = 0; f < 50; f += 10)
3840
3849
  r[i + f] ^= u, r[i + f + 1] ^= _;
3841
3850
  }
3842
3851
  let o = r[2], n = r[3];
3843
3852
  for (let i = 0; i < 24; i++) {
3844
- const a = As[i], c = Wt(o, n, a), l = Vt(o, n, a), d = Is[i];
3853
+ const a = As[i], c = qt(o, n, a), l = Vt(o, n, a), d = Is[i];
3845
3854
  o = r[d], n = r[d + 1], r[d] = c, r[d + 1] = l;
3846
3855
  }
3847
3856
  for (let i = 0; i < 50; i += 10) {
@@ -3990,6 +3999,7 @@ function zt(r) {
3990
3999
  }
3991
4000
  const ho = 3e4;
3992
4001
  class po {
4002
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3993
4003
  async request(e) {
3994
4004
  const s = new AbortController(), t = setTimeout(
3995
4005
  () => s.abort(),
@@ -4065,11 +4075,11 @@ class wt {
4065
4075
  return;
4066
4076
  }
4067
4077
  if (B.data.status === "success") {
4068
- const g = ((fe = B.data.data) == null ? void 0 : fe.accessToken) || ((J = B.data.data) == null ? void 0 : J.idToken);
4078
+ const x = ((fe = B.data.data) == null ? void 0 : fe.accessToken) || ((J = B.data.data) == null ? void 0 : J.idToken);
4069
4079
  h.log("[CROSSx] OAuth 토큰 수신:", {
4070
4080
  hasAccessToken: !!((me = B.data.data) != null && me.accessToken),
4071
4081
  hasIdToken: !!((ie = B.data.data) != null && ie.idToken)
4072
- }), g ? s(g) : (h.error("[CROSSx] 토큰을 찾을 수 없음:", B.data), t(new Error("Token not found in response")));
4082
+ }), x ? s(x) : (h.error("[CROSSx] 토큰을 찾을 수 없음:", B.data), t(new Error("Token not found in response")));
4073
4083
  } else
4074
4084
  h.error("[CROSSx] OAuth 실패:", ($ = B.data.data) == null ? void 0 : $.error), t(new Error(((L = B.data.data) == null ? void 0 : L.error) || "Authentication failed"));
4075
4085
  };
@@ -4109,7 +4119,7 @@ class fo {
4109
4119
  const n = (s = this.passwordStore) == null ? void 0 : s.get();
4110
4120
  return n && (await this.storage.set(Ee, n), h.log("[Mock] 지갑 생성 — 비밀번호 저장됨")), o;
4111
4121
  } catch (t) {
4112
- throw new m(x.WALLET_CREATION_FAILED, "지갑 생성에 실패했습니다", t);
4122
+ throw new m(g.WALLET_CREATION_FAILED, "지갑 생성에 실패했습니다", t);
4113
4123
  }
4114
4124
  }
4115
4125
  /** GET /mnemonic/addresses 모킹 — 비밀번호 불필요, 캐시된 주소 반환 */
@@ -4159,16 +4169,16 @@ class fo {
4159
4169
  async changePassword(e, s) {
4160
4170
  var n;
4161
4171
  if (h.log("[Mock] changePassword"), this.passwordScenario === "wrong")
4162
- throw new m(x.PASSWORD_WRONG, "Incorrect password.");
4172
+ throw new m(g.PASSWORD_WRONG, "Incorrect password.");
4163
4173
  const t = (n = this.passwordStore) == null ? void 0 : n.get(), o = await this.storage.get(Ee);
4164
4174
  if (o && t && o !== t)
4165
- throw new m(x.PASSWORD_WRONG, "Incorrect password.");
4175
+ throw new m(g.PASSWORD_WRONG, "Incorrect password.");
4166
4176
  await this.storage.set(Ee, s), h.log("[Mock] changePassword 완료");
4167
4177
  }
4168
4178
  async migrateWallet(e, s) {
4169
4179
  var n;
4170
4180
  if (h.log(`[Mock] migrateWallet pin=${e} sub=${s}`), this.migrateScenario === "wrong_pin")
4171
- throw new m(x.MIGRATION_FAILED, "Incorrect PIN.", {
4181
+ throw new m(g.MIGRATION_FAILED, "Incorrect PIN.", {
4172
4182
  permanent: !1,
4173
4183
  lockExpiresAt: 0,
4174
4184
  remainingAttempts: 4,
@@ -4183,7 +4193,7 @@ class fo {
4183
4193
  ...this.migrateScenario.locked
4184
4194
  };
4185
4195
  throw new m(
4186
- x.MIGRATION_PIN_LOCKED,
4196
+ g.MIGRATION_PIN_LOCKED,
4187
4197
  "Too many incorrect PIN attempts. Your account has been temporarily locked.",
4188
4198
  a
4189
4199
  );
@@ -4238,7 +4248,7 @@ class Ve {
4238
4248
  const e = this.tokenStore.get();
4239
4249
  if (!e)
4240
4250
  throw new m(
4241
- x.AUTH_NOT_AUTHENTICATED,
4251
+ g.AUTH_NOT_AUTHENTICATED,
4242
4252
  "인증 토큰을 찾을 수 없습니다. 먼저 로그인해 주세요."
4243
4253
  );
4244
4254
  return e;
@@ -4284,7 +4294,7 @@ class Ve {
4284
4294
  method: e,
4285
4295
  status: (c = l.response) == null ? void 0 : c.status
4286
4296
  }), new m(
4287
- x.UNKNOWN_ERROR,
4297
+ g.UNKNOWN_ERROR,
4288
4298
  `Wallet Gateway 오류 (${_}): ${u}`
4289
4299
  );
4290
4300
  }
@@ -4311,7 +4321,7 @@ class Ve {
4311
4321
  let s;
4312
4322
  if (this._walletStatusCache !== null ? (s = this._walletStatusCache, this._walletStatusCache = null, h.log("[CROSSx] getOrCreateWallet — 캐시된 상태 사용:", s)) : (h.log("[CROSSx] GET /mnemonic/check — 지갑 상태 확인"), s = await this.checkWallet(), this._walletStatusCache = null), s === "migration_required")
4313
4323
  throw h.log("[CROSSx] migration_required → MIGRATION_BACKUP_EXISTS throw"), new m(
4314
- x.MIGRATION_BACKUP_EXISTS,
4324
+ g.MIGRATION_BACKUP_EXISTS,
4315
4325
  "CROSSx 백업이 존재합니다. 마이그레이션을 진행해 주세요."
4316
4326
  );
4317
4327
  if (s === "exists") {
@@ -4353,15 +4363,15 @@ class Ve {
4353
4363
  switch (e) {
4354
4364
  case "sign":
4355
4365
  case "send":
4356
- if (!s.tx) throw new m(x.TX_INVALID_PARAMS, "prepare: tx가 필요합니다");
4366
+ if (!s.tx) throw new m(g.TX_INVALID_PARAMS, "prepare: tx가 필요합니다");
4357
4367
  t = { unsignedTx: this.buildUnsignedTx(s.tx) };
4358
4368
  break;
4359
4369
  case "sign-message":
4360
- if (!s.message) throw new m(x.TX_INVALID_PARAMS, "prepare: message가 필요합니다");
4370
+ if (!s.message) throw new m(g.TX_INVALID_PARAMS, "prepare: message가 필요합니다");
4361
4371
  t = { message: s.message }, s.from && (t.from = s.from);
4362
4372
  break;
4363
4373
  case "sign-typed-data":
4364
- if (!s.typedData) throw new m(x.TX_INVALID_PARAMS, "prepare: typedData가 필요합니다");
4374
+ if (!s.typedData) throw new m(g.TX_INVALID_PARAMS, "prepare: typedData가 필요합니다");
4365
4375
  t = { typedData: s.typedData }, s.from && (t.from = s.from);
4366
4376
  break;
4367
4377
  }
@@ -4369,24 +4379,20 @@ class Ve {
4369
4379
  return { uuid: n.uuid, expiresAt: n.expiresAt };
4370
4380
  }
4371
4381
  async signMessage(e, s, t, o, n, i) {
4372
- const a = { message: t };
4382
+ const a = { message: t, password: this.requirePassword() };
4373
4383
  n && (a.uuid = n), i && (a.from = i);
4374
- const c = this.getPassword();
4375
- c && (a.password = c);
4376
- const l = await this.request("POST", "/mnemonic/sign-message", a);
4377
- return { chainId: s, signature: l.signature, format: "hex" };
4384
+ const c = await this.request("POST", "/mnemonic/sign-message", a);
4385
+ return { chainId: s, signature: c.signature, format: "hex" };
4378
4386
  }
4379
4387
  async signTypedData(e, s, t, o, n, i) {
4380
- const a = { typedData: t };
4388
+ const a = { typedData: t, password: this.requirePassword() };
4381
4389
  n && (a.uuid = n), i && (a.from = i);
4382
- const c = this.getPassword();
4383
- c && (a.password = c);
4384
- const l = await this.request(
4390
+ const c = await this.request(
4385
4391
  "POST",
4386
4392
  `/mnemonic/sign-typed-data/${encodeURIComponent(s)}`,
4387
4393
  a
4388
4394
  );
4389
- return { chainId: s, signature: l.signature, format: "hex" };
4395
+ return { chainId: s, signature: c.signature, format: "hex" };
4390
4396
  }
4391
4397
  buildUnsignedTx(e) {
4392
4398
  return {
@@ -4403,24 +4409,21 @@ class Ve {
4403
4409
  };
4404
4410
  }
4405
4411
  async signTransaction(e, s, t, o, n) {
4406
- const i = { unsignedTx: this.buildUnsignedTx(t) };
4412
+ const i = { unsignedTx: this.buildUnsignedTx(t), password: this.requirePassword() };
4407
4413
  n && (i.uuid = n);
4408
- const a = this.getPassword();
4409
- a && (i.password = a);
4410
- const c = await this.request(
4414
+ const a = await this.request(
4411
4415
  "POST",
4412
4416
  `/mnemonic/sign/${encodeURIComponent(s)}`,
4413
4417
  i
4414
4418
  );
4415
- return { chainId: s, signature: c.signedTx, txHash: c.txHash, format: "hex" };
4419
+ return { chainId: s, signature: a.signedTx, txHash: a.txHash, format: "hex" };
4416
4420
  }
4417
4421
  async sendTransaction(e, s, t, o) {
4418
4422
  const n = {
4419
- unsignedTx: this.buildUnsignedTx(t)
4423
+ unsignedTx: this.buildUnsignedTx(t),
4424
+ password: this.requirePassword()
4420
4425
  };
4421
- o && (n.uuid = o);
4422
- const i = this.getPassword();
4423
- return i && (n.password = i), { txHash: (await this.request(
4426
+ return o && (n.uuid = o), { txHash: (await this.request(
4424
4427
  "POST",
4425
4428
  `/mnemonic/send/${encodeURIComponent(s)}`,
4426
4429
  n
@@ -4428,7 +4431,7 @@ class Ve {
4428
4431
  }
4429
4432
  async migrateWallet(e, s) {
4430
4433
  h.log("[CROSSx][Migration Phase 4] POST /mnemonic/migrate 호출 — sub:", s);
4431
- const t = { pin: e, sub: s, password: this.requirePassword() }, o = await this.request(
4434
+ const t = { recoveryPin: e, sub: s, password: this.requirePassword() }, o = await this.request(
4432
4435
  "POST",
4433
4436
  "/mnemonic/migrate",
4434
4437
  t
@@ -4477,59 +4480,62 @@ class Ve {
4477
4480
  * 마이그레이션 전 PIN 유효성 및 잠금 상태 확인에 사용합니다.
4478
4481
  */
4479
4482
  async verifyPin(e, s) {
4480
- const t = { pin: e, sub: s };
4481
- return this.request("POST", "/mnemonic/verify-pin", t);
4483
+ const t = { recoveryPin: e, sub: s };
4484
+ return this.request("POST", "/mnemonic/verify-recovery-pin", t);
4482
4485
  }
4483
4486
  /** passwordStore에서 비밀번호를 가져오거나 PASSWORD_NOT_SET 에러를 throw */
4484
4487
  requirePassword() {
4485
4488
  const e = this.getPassword();
4486
4489
  if (!e)
4487
4490
  throw new m(
4488
- x.PASSWORD_NOT_SET,
4491
+ g.PASSWORD_NOT_SET,
4489
4492
  "비밀번호가 설정되지 않았습니다. 비밀번호를 입력해 주세요."
4490
4493
  );
4491
4494
  return e;
4492
4495
  }
4496
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4493
4497
  static mapGatewayError(e, s) {
4494
4498
  switch (e) {
4495
4499
  case -10002:
4496
- return x.AUTH_NOT_AUTHENTICATED;
4500
+ return g.AUTH_NOT_AUTHENTICATED;
4497
4501
  case -10001:
4498
4502
  case -10009:
4499
- return x.UNKNOWN_ERROR;
4503
+ return g.UNKNOWN_ERROR;
4500
4504
  case -10006:
4501
- return x.GATEWAY_INTERNAL_ERROR;
4505
+ return g.GATEWAY_INTERNAL_ERROR;
4502
4506
  case -10008:
4503
- return x.GATEWAY_LOCK_CONFLICT;
4507
+ return g.GATEWAY_LOCK_CONFLICT;
4504
4508
  case -10010:
4505
- return x.MIGRATION_FAILED;
4509
+ return g.MIGRATION_FAILED;
4506
4510
  case -10012:
4507
- return x.MIGRATION_BACKUP_EXISTS;
4511
+ return g.MIGRATION_BACKUP_EXISTS;
4508
4512
  case -10027:
4509
- return x.MIGRATION_PIN_LOCKED;
4513
+ return g.MIGRATION_PIN_LOCKED;
4510
4514
  case -10022:
4511
- return x.PROJECT_NOT_REGISTERED;
4515
+ return g.PROJECT_NOT_REGISTERED;
4512
4516
  case -10023:
4513
- return x.PROJECT_ID_MISSING;
4517
+ return g.PROJECT_ID_MISSING;
4514
4518
  case -10024:
4515
- return x.ORIGIN_NOT_ALLOWED;
4519
+ return g.ORIGIN_NOT_ALLOWED;
4516
4520
  case -10028:
4517
- return x.PASSWORD_WRONG;
4521
+ return g.PASSWORD_WRONG;
4518
4522
  case -10029:
4519
- return x.PASSWORD_COMPLEXITY;
4523
+ return g.PASSWORD_COMPLEXITY;
4524
+ case -10030:
4525
+ return g.WALLET_INCONSISTENT_STATE;
4520
4526
  case -10026:
4521
- return x.TYPED_DATA_CHAIN_ID_MISMATCH;
4527
+ return g.TYPED_DATA_CHAIN_ID_MISMATCH;
4522
4528
  case -10014:
4523
4529
  case -10015:
4524
4530
  case -10019:
4525
- return x.PREPARE_FAILED;
4531
+ return g.PREPARE_FAILED;
4526
4532
  case -10016:
4527
- return x.PREPARE_EXPIRED;
4533
+ return g.PREPARE_EXPIRED;
4528
4534
  case -10017:
4529
4535
  case -10018:
4530
- return x.PREPARE_MISMATCH;
4536
+ return g.PREPARE_MISMATCH;
4531
4537
  default:
4532
- return x.UNKNOWN_ERROR;
4538
+ return g.UNKNOWN_ERROR;
4533
4539
  }
4534
4540
  }
4535
4541
  static getGatewayErrorMessage(e, s) {
@@ -4554,6 +4560,8 @@ class Ve {
4554
4560
  return "Password does not meet complexity requirements. Please use a stronger password.";
4555
4561
  case -10027:
4556
4562
  return "Too many incorrect PIN attempts. Your account has been temporarily locked.";
4563
+ case -10030:
4564
+ return "Wallet is in an inconsistent state. Please contact support.";
4557
4565
  default:
4558
4566
  return `Request failed (${e}): ${s}`;
4559
4567
  }
@@ -4624,7 +4632,7 @@ class Pe {
4624
4632
  );
4625
4633
  if (s) return s;
4626
4634
  throw new m(
4627
- x.CHAIN_NOT_SUPPORTED,
4635
+ g.CHAIN_NOT_SUPPORTED,
4628
4636
  `지원하지 않는 체인: ${e}`
4629
4637
  );
4630
4638
  }
@@ -4637,19 +4645,19 @@ class Pe {
4637
4645
  static mapErrorCode(e) {
4638
4646
  switch (e) {
4639
4647
  case -10020:
4640
- return x.CHAIN_NOT_SUPPORTED;
4648
+ return g.CHAIN_NOT_SUPPORTED;
4641
4649
  case -10021:
4642
- return x.INVALID_CHAIN;
4650
+ return g.INVALID_CHAIN;
4643
4651
  case -10022:
4644
- return x.PROJECT_NOT_REGISTERED;
4652
+ return g.PROJECT_NOT_REGISTERED;
4645
4653
  case -10023:
4646
- return x.PROJECT_ID_MISSING;
4654
+ return g.PROJECT_ID_MISSING;
4647
4655
  case -10024:
4648
- return x.APP_IDENTIFIER_MISSING;
4656
+ return g.APP_IDENTIFIER_MISSING;
4649
4657
  case -10025:
4650
- return x.INVALID_APP_TYPE;
4658
+ return g.INVALID_APP_TYPE;
4651
4659
  default:
4652
- return x.UNKNOWN_ERROR;
4660
+ return g.UNKNOWN_ERROR;
4653
4661
  }
4654
4662
  }
4655
4663
  }
@@ -6142,7 +6150,7 @@ const Zt = {
6142
6150
  612044: "CROSS Testnet",
6143
6151
  612055: "CROSS Mainnet"
6144
6152
  };
6145
- function Cs(r) {
6153
+ function ks(r) {
6146
6154
  const e = parseInt(r.split(":")[1] ?? "", 10);
6147
6155
  return !isNaN(e) && Zt[e] ? Zt[e] : r;
6148
6156
  }
@@ -6197,9 +6205,9 @@ function mo(r) {
6197
6205
  }
6198
6206
  function Rs(r) {
6199
6207
  const e = mo(r);
6200
- if (!e) return q("Estimated fee", "<span>—</span>");
6201
- let s = q("Est. Tx Fee", `<span>${e.estTxFee}</span>`);
6202
- return e.isDynamic ? (e.maxPriorityFeeGwei !== void 0 && (s += q("Max Priority Fee", `<span>${e.maxPriorityFeeGwei} Gwei</span>`)), e.maxFeeGwei !== void 0 && (s += q("Max Gas Fee", `<span>${e.maxFeeGwei} Gwei</span>`))) : e.gasPriceGwei !== void 0 && (s += q("Gas Price", `<span>${e.gasPriceGwei} Gwei</span>`)), e.gasLimitFormatted && (s += q("Gas Limit", `<span>${e.gasLimitFormatted}</span>`)), s;
6208
+ if (!e) return W("Estimated fee", "<span>—</span>");
6209
+ let s = W("Est. Tx Fee", `<span>${e.estTxFee}</span>`);
6210
+ return e.isDynamic ? (e.maxPriorityFeeGwei !== void 0 && (s += W("Max Priority Fee", `<span>${e.maxPriorityFeeGwei} Gwei</span>`)), e.maxFeeGwei !== void 0 && (s += W("Max Gas Fee", `<span>${e.maxFeeGwei} Gwei</span>`))) : e.gasPriceGwei !== void 0 && (s += W("Gas Price", `<span>${e.gasPriceGwei} Gwei</span>`)), e.gasLimitFormatted && (s += W("Gas Limit", `<span>${e.gasLimitFormatted}</span>`)), s;
6203
6211
  }
6204
6212
  const he = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
6205
6213
  <rect x="9" y="9" width="13" height="13" rx="2"/>
@@ -6251,7 +6259,7 @@ function re(r) {
6251
6259
  `--cx-on-primary:${r.onPrimary}`
6252
6260
  ].join(";");
6253
6261
  }
6254
- function q(r, e) {
6262
+ function W(r, e) {
6255
6263
  return `
6256
6264
  <div class="__crossx-row">
6257
6265
  <span class="__crossx-row-label">${r}</span>
@@ -6281,8 +6289,8 @@ function So(r, e) {
6281
6289
  <p class="__crossx-warning">After you sign, changes or cancellations are not possible.</p>
6282
6290
  <hr class="__crossx-divider">
6283
6291
  <div class="__crossx-rows">
6284
- ${q("To", o)}
6285
- ${q("Network", `<span>${Cs(r.chainId)}</span>`)}
6292
+ ${W("To", o)}
6293
+ ${W("Network", `<span>${ks(r.chainId)}</span>`)}
6286
6294
  ${n}
6287
6295
  </div>
6288
6296
  </div>
@@ -6312,8 +6320,8 @@ function Eo(r, e) {
6312
6320
  </p>
6313
6321
  <div class="__crossx-body-cols">
6314
6322
  <div class="__crossx-rows">
6315
- ${q("To", i)}
6316
- ${q("Network", `<span>${Cs(r.chainId)}</span>`)}
6323
+ ${W("To", i)}
6324
+ ${W("Network", `<span>${ks(r.chainId)}</span>`)}
6317
6325
  ${a}
6318
6326
  </div>
6319
6327
  <div class="__crossx-pill">
@@ -6350,12 +6358,12 @@ function Ao(r) {
6350
6358
  }
6351
6359
  }
6352
6360
  function To(r, e) {
6353
- const s = q(
6361
+ const s = W(
6354
6362
  "From",
6355
6363
  `<span class="__crossx-addr-text">${X(r.from)}</span>
6356
6364
  <button class="__crossx-copy-btn" data-copy="${T(r.from)}" title="Copy address">${he}</button>`
6357
- ), t = r.to ? q("To", `<span class="__crossx-addr-text">${X(r.to)}</span>
6358
- <button class="__crossx-copy-btn" data-copy="${T(r.to)}" title="Copy address">${he}</button>`) : "", o = r.amount ? q("Transfer", `<span>${T(r.amount)}</span>`) : "", n = r.fees ? q("Tx Fee", `<span>${T(r.fees)}</span>`) : "", i = r.txHash ? q("Tx Hash", `<span class="__crossx-addr-text">${X(r.txHash)}</span>
6365
+ ), t = r.to ? W("To", `<span class="__crossx-addr-text">${X(r.to)}</span>
6366
+ <button class="__crossx-copy-btn" data-copy="${T(r.to)}" title="Copy address">${he}</button>`) : "", o = r.amount ? W("Transfer", `<span>${T(r.amount)}</span>`) : "", n = r.fees ? W("Tx Fee", `<span>${T(r.fees)}</span>`) : "", i = r.txHash ? W("Tx Hash", `<span class="__crossx-addr-text">${X(r.txHash)}</span>
6359
6367
  <button class="__crossx-copy-btn" data-copy="${T(r.txHash)}" title="Copy hash">${he}</button>`) : "", a = r.total ? `<div class="__crossx-total-pill">
6360
6368
  <span class="__crossx-total-label">Total<br>(including fees)</span>
6361
6369
  <span class="__crossx-total-amount">${T(r.total)}</span>
@@ -6381,7 +6389,7 @@ function To(r, e) {
6381
6389
  </div>
6382
6390
  `, c;
6383
6391
  }
6384
- function ko(r, e) {
6392
+ function Co(r, e) {
6385
6393
  const s = document.createElement("div");
6386
6394
  return s.id = z, s.innerHTML = `
6387
6395
  <div class="__crossx-card __crossx-card--migration" style="${re(e)}" role="dialog" aria-modal="true" aria-labelledby="__crossx-ttl">
@@ -6398,7 +6406,7 @@ function ko(r, e) {
6398
6406
  </div>
6399
6407
  `, s;
6400
6408
  }
6401
- function Co(r, e, s) {
6409
+ function ko(r, e, s) {
6402
6410
  const t = e.status !== "reverted" && e.status !== "timeout", o = e.status === "timeout", n = r.querySelector("#__crossx-ttl"), i = r.querySelector(".__crossx-header");
6403
6411
  if (n) {
6404
6412
  const p = o ? vo : t ? "" : bo, b = o ? "Transaction timeout" : t ? "Transaction complete" : "Transaction failed";
@@ -6410,9 +6418,9 @@ function Co(r, e, s) {
6410
6418
  }
6411
6419
  const a = r.querySelector("#__crossx-progress-body");
6412
6420
  if (!a) return;
6413
- const c = e.from ? q("From", `<span class="__crossx-addr-text">${X(e.from)}</span>
6414
- <button class="__crossx-copy-btn" data-copy="${T(e.from)}" title="Copy address">${he}</button>`) : "", l = e.to ? q("To", `<span class="__crossx-addr-text">${X(e.to)}</span>
6415
- <button class="__crossx-copy-btn" data-copy="${T(e.to)}" title="Copy address">${he}</button>`) : "", d = e.amount ? q("Transfer", `<span>${T(e.amount)}</span>`) : "", u = e.fees ? q("Tx Fee", `<span>${T(e.fees)}</span>`) : "", _ = e.txHash ? q("Tx Hash", `<span class="__crossx-addr-text">${X(e.txHash)}</span>
6421
+ const c = e.from ? W("From", `<span class="__crossx-addr-text">${X(e.from)}</span>
6422
+ <button class="__crossx-copy-btn" data-copy="${T(e.from)}" title="Copy address">${he}</button>`) : "", l = e.to ? W("To", `<span class="__crossx-addr-text">${X(e.to)}</span>
6423
+ <button class="__crossx-copy-btn" data-copy="${T(e.to)}" title="Copy address">${he}</button>`) : "", d = e.amount ? W("Transfer", `<span>${T(e.amount)}</span>`) : "", u = e.fees ? W("Tx Fee", `<span>${T(e.fees)}</span>`) : "", _ = e.txHash ? W("Tx Hash", `<span class="__crossx-addr-text">${X(e.txHash)}</span>
6416
6424
  <button class="__crossx-copy-btn" data-copy="${T(e.txHash)}" title="Copy hash">${he}</button>`) : "", f = e.total ? `<div class="__crossx-total-pill">
6417
6425
  <span class="__crossx-total-label">Total<br>(including fees)</span>
6418
6426
  <span class="__crossx-total-amount">${T(e.total)}</span>
@@ -6703,10 +6711,10 @@ const Ke = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="h
6703
6711
  <path d="M1 3.5L3.5 6L8 1" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
6704
6712
  </svg>`, Go = `<svg width="11" height="9" viewBox="0 0 11 9" fill="none" xmlns="http://www.w3.org/2000/svg">
6705
6713
  <path d="M1 4.5L4 7.5L10 1" stroke="white" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
6706
- </svg>`, qo = `<svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
6714
+ </svg>`, Wo = `<svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
6707
6715
  <path d="M12 0C18.6274 0 24 5.37258 24 12C23.9999 18.6273 18.6274 24 12 24C5.37264 24 9.89594e-05 18.6273 0 12C0 5.37258 5.37258 0 12 0ZM10.875 15.127V17.377H13.125V15.127H10.875ZM10.875 6.62207V13.627H13.125V6.62207H10.875Z" fill="currentColor"/>
6708
6716
  </svg>`;
6709
- function Wo(r) {
6717
+ function qo(r) {
6710
6718
  return {
6711
6719
  minLength: r.length >= 8,
6712
6720
  uppercase: /[A-Z]/.test(r),
@@ -6735,7 +6743,7 @@ function Ko(r) {
6735
6743
  <div class="__crossx-pw-fields __crossx-pw-fields--notice">
6736
6744
  <div class="__crossx-pw-notice-header">
6737
6745
  <div class="__crossx-pw-notice-title-row">
6738
- <span class="__crossx-pw-notice-icon">${qo}</span>
6746
+ <span class="__crossx-pw-notice-icon">${Wo}</span>
6739
6747
  <p class="__crossx-pw-notice-title">${T(r.noticeTitle)}</p>
6740
6748
  </div>
6741
6749
  <p class="__crossx-pw-notice-desc">${T(r.noticeDesc)}</p>
@@ -6858,7 +6866,7 @@ function Zo(r, e, s, t) {
6858
6866
  number: r.querySelector("#__crossx-rule-number"),
6859
6867
  special: r.querySelector("#__crossx-rule-special")
6860
6868
  }, _ = () => {
6861
- const b = o.value, y = n.value, E = Wo(b), M = Vo(E);
6869
+ const b = o.value, y = n.value, E = qo(b), M = Vo(E);
6862
6870
  Object.keys(E).forEach((le) => {
6863
6871
  u[le].classList.toggle("--met", E[le]);
6864
6872
  });
@@ -7244,7 +7252,7 @@ class en {
7244
7252
  showTransactionProgress(e, s) {
7245
7253
  return new Promise((t) => {
7246
7254
  ce();
7247
- const o = ko(e, this.tokens);
7255
+ const o = Co(e, this.tokens);
7248
7256
  document.body.appendChild(o);
7249
7257
  const n = () => o.remove();
7250
7258
  let i = !1;
@@ -7261,7 +7269,7 @@ class en {
7261
7269
  document.addEventListener("keydown", l);
7262
7270
  };
7263
7271
  s.then((l) => {
7264
- i || (Co(o, l, this.tokens), c());
7272
+ i || (ko(o, l, this.tokens), c());
7265
7273
  });
7266
7274
  });
7267
7275
  }
@@ -7350,6 +7358,6 @@ export {
7350
7358
  Ds as CROSSxEthereumProvider,
7351
7359
  nt as CROSSxSDK,
7352
7360
  on as ChainId,
7353
- x as ErrorCode,
7361
+ g as ErrorCode,
7354
7362
  nn as createCROSSxSDK
7355
7363
  };