@nexus-cross/crossx-sdk-wagmi 1.0.9 → 1.1.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,SAAS,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GA2KpE"}
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAInD,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,SAAS,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,MAAM,CAAC;IACpC,wDAAwD;IACxD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAgNpE"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("wagmi"),p=require("@nexus-cross/crossx-sdk-core");function k(s){return parseInt(s.split(":")[1]??"1",10)}function x(s){return`eip155:${s}`}function w(s){return"0x"+s.toString(16)}class b{constructor(e,i=p.ChainId.CROSS_MAINNET){this.sdk=e,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof i=="number"?i:k(i),this.sdk.on("addressChanged",({address:c,index:o})=>{this.setWalletIndex(o),this.notifyAccountsChanged([c])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:i}){var o;const c=i??[];switch(e){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return console.log("[CROSSx-debug] provider.eth_accounts → currentAccounts:",this.currentAccounts[0],"walletIndex:",this.walletIndex),[...this.currentAccounts];const t=await this.sdk.getAddress();return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():",t==null?void 0:t.address),t?[t.address]:[]}case"eth_chainId":return w(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=c;return(await this.sdk.signMessage(x(this.chainId),t,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=c;return(await this.sdk.signMessage(x(this.chainId),t,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=c,a=typeof t=="string"?JSON.parse(t):t,g=(o=a==null?void 0:a.domain)==null?void 0:o.chainId,d=g==null||g===0,h=d?0:Number(g),n={index:this.walletIndex};return(d?await this.sdk.signTypedDataOffchain(a,n):await this.sdk.signTypedData(x(h),a,n)).signature}case"eth_sendTransaction":{const[t]=c,a=x(this.chainId);return(await this.sdk.sendTransaction(a,{from:t.from,to:t.to,value:t.value,data:t.data,gasLimit:t.gasLimit??t.gas,gasPrice:t.gasPrice,maxFeePerGas:t.maxFeePerGas,maxPriorityFeePerGas:t.maxPriorityFeePerGas,nonce:t.nonce!==void 0?parseInt(String(t.nonce),16):void 0,chainId:this.chainId},{index:this.walletIndex})).txHash}case"wallet_switchEthereumChain":{const[{chainId:t}]=c,a=parseInt(t,16);return a!==this.chainId&&(this.chainId=a,this.emit("chainChanged",w(a))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,c,x(this.chainId))}}on(e,i){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(i),this}removeListener(e,i){var c;return(c=this.listeners.get(e))==null||c.delete(i),this}emit(e,...i){var c;(c=this.listeners.get(e))==null||c.forEach(o=>o(...i))}notifyAccountsChanged(e){console.log("[CROSSx-debug] provider.notifyAccountsChanged:",e[0],"walletIndex:",this.walletIndex),this.currentAccounts=e,this.emit("accountsChanged",e)}notifyDisconnect(e){this.currentAccounts=[],this.walletIndex=0,this.emit("disconnect",e)}getCurrentChainId(){return this.chainId}setChainId(e){e!==this.chainId&&(this.chainId=e,this.emit("chainChanged",w(e)))}setWalletIndex(e){var i;console.log("[CROSSx-debug] provider.setWalletIndex:",e),this.walletIndex=e,(i=this.walletIndexChangeCallback)==null||i.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function v(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const A="crossx-wallet-index";function _(){try{const s=typeof window<"u"?localStorage.getItem(A):null;return s&&Number(s)||0}catch{return 0}}function W(s){try{typeof window<"u"&&localStorage.setItem(A,String(s))}catch{}}function P(){try{typeof window<"u"&&localStorage.removeItem(A)}catch{}}function T(s){const{defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:c,...o}=s,t=p.createCROSSxSDK(o);return O({sdk:t,defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:c})}function O(s){const{sdk:e,defaultChainId:i=p.ChainId.CROSS_MAINNET,getStoredWalletIndex:c=_,onWalletIndexChanged:o=W}=s,t=v(i);let a=null,g=!1;function d(){return a||(a=new b(e,t),a._setWalletIndexChangeCallback(o)),a}return R.createConnector(h=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){console.log("[CROSSx-debug] connector.setup() 시작"),g||(await e.initialize(),g=!0),console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:",e.isAuthenticated());const n=d();n.on("accountsChanged",this.onAccountsChanged.bind(this)),n.on("chainChanged",this.onChainChanged.bind(this)),n.on("disconnect",this.onDisconnect.bind(this)),console.log("[CROSSx-debug] connector.setup() 완료, 이벤트 리스너 등록됨")},async connect({chainId:n,isReconnecting:u}={}){console.log("[CROSSx-debug] connector.connect() 호출",{isReconnecting:u,targetChainId:n});const r=d(),S=n??t;if(u||e.isAuthenticated()){const C=c();console.log("[CROSSx-debug] connector.connect() 재연결 경로",{storedIndex:C,isAuth:e.isAuthenticated()});const l=await e.getAddress(C||void 0);if(console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과",{address:l==null?void 0:l.address,index:l==null?void 0:l.index,requestedIndex:C||void 0}),l)return r.setWalletIndex(C),r.notifyAccountsChanged([l.address]),console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:",l.address),{accounts:[l.address],chainId:S};console.log("[CROSSx-debug] connector.connect() 재연결 경로info null, 신규 로그인으로 진행")}const f=await e.signInWithCreate();if(!f.success)throw new Error(f.error??"CROSSx sign-in failed");const I=f.address,y=f.addresses.map(C=>C.address).filter(C=>!I||C.toLowerCase()!==I.toLowerCase()),m=I?[I,...y]:y;if(m.length===0)throw new Error("No address found after sign-in");return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:",I),r.notifyAccountsChanged(m),{accounts:m,chainId:S}},async disconnect(){const n=d();await e.signOut(),n.notifyDisconnect(),P(),o(0),h.emitter.emit("disconnect")},async getAccounts(){const n=d(),u=n.getCurrentAccounts();if(console.log("[CROSSx-debug] connector.getAccounts()",{trackedLen:u.length,tracked:u[0],walletIndex:n.getWalletIndex()}),u.length>0)return u;const r=await e.getAddress();return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():",r==null?void 0:r.address),r?[r.address]:[]},async getChainId(){return d().getCurrentChainId()},async getProvider({chainId:n}={}){return d()},async isAuthorized(){const n=e.isAuthenticated();return console.log("[CROSSx-debug] connector.isAuthorized():",n),n},async switchChain({chainId:n}){d().setChainId(n),h.emitter.emit("change",{chainId:n});const r=h.chains.find(S=>S.id===n);if(!r)throw new Error(`Chain ${n} is not configured`);return r},onAccountsChanged(n){console.log("[CROSSx-debug] connector.onAccountsChanged:",n),n.length===0?h.emitter.emit("disconnect"):h.emitter.emit("change",{accounts:n})},onChainChanged(n){h.emitter.emit("change",{chainId:Number(n)})},onDisconnect(){h.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=b;exports.createCROSSxConnector=O;exports.crossxConnector=T;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("wagmi"),y=require("@nexus-cross/crossx-sdk-core");function W(s){return parseInt(s.split(":")[1]??"1",10)}function w(s){return`eip155:${s}`}function A(s){return"0x"+s.toString(16)}class R{constructor(e,c=y.ChainId.CROSS_MAINNET){this.sdk=e,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof c=="number"?c:W(c),this.sdk.on("addressChanged",({address:i,index:a})=>{this.setWalletIndex(a),this.notifyAccountsChanged([i])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:c}){var a;const i=c??[];switch(e){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return console.log("[CROSSx-debug] provider.eth_accounts → currentAccounts:",this.currentAccounts[0],"walletIndex:",this.walletIndex),[...this.currentAccounts];const t=await this.sdk.getAddress();return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():",t==null?void 0:t.address),t?[t.address]:[]}case"eth_chainId":return A(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=i;return(await this.sdk.signMessage(w(this.chainId),t,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=i;return(await this.sdk.signMessage(w(this.chainId),t,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=i,o=typeof t=="string"?JSON.parse(t):t,C=(a=o==null?void 0:o.domain)==null?void 0:a.chainId,l=C==null||C===0,h=l?0:Number(C),n={index:this.walletIndex};return(l?await this.sdk.signTypedDataOffchain(o,n):await this.sdk.signTypedData(w(h),o,n)).signature}case"eth_sendTransaction":{const[t]=i,o=w(this.chainId);return(await this.sdk.sendTransaction(o,{from:t.from,to:t.to,value:t.value,data:t.data,gasLimit:t.gasLimit??t.gas,gasPrice:t.gasPrice,maxFeePerGas:t.maxFeePerGas,maxPriorityFeePerGas:t.maxPriorityFeePerGas,nonce:t.nonce!==void 0?parseInt(String(t.nonce),16):void 0,chainId:this.chainId},{index:this.walletIndex})).txHash}case"wallet_switchEthereumChain":{const[{chainId:t}]=i,o=parseInt(t,16);return o!==this.chainId&&(this.chainId=o,this.emit("chainChanged",A(o))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,i,w(this.chainId))}}on(e,c){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(c),this}removeListener(e,c){var i;return(i=this.listeners.get(e))==null||i.delete(c),this}emit(e,...c){var i;(i=this.listeners.get(e))==null||i.forEach(a=>a(...c))}notifyAccountsChanged(e){console.log("[CROSSx-debug] provider.notifyAccountsChanged:",e[0],"walletIndex:",this.walletIndex),this.currentAccounts=e,this.emit("accountsChanged",e)}notifyDisconnect(e){this.currentAccounts=[],this.walletIndex=0,this.emit("disconnect",e)}getCurrentChainId(){return this.chainId}setChainId(e){e!==this.chainId&&(this.chainId=e,this.emit("chainChanged",A(e)))}setWalletIndex(e){var c;console.log("[CROSSx-debug] provider.setWalletIndex:",e),this.walletIndex=e,(c=this.walletIndexChangeCallback)==null||c.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function P(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const b="crossx-wallet-index";function D(){try{const s=typeof window<"u"?localStorage.getItem(b):null;return s&&Number(s)||0}catch{return 0}}function T(s){try{typeof window<"u"&&localStorage.setItem(b,String(s))}catch{}}function E(){try{typeof window<"u"&&localStorage.removeItem(b)}catch{}}function N(s){const{defaultChainId:e,getStoredWalletIndex:c,onWalletIndexChanged:i,...a}=s,t=y.createCROSSxSDK(a);return k({sdk:t,defaultChainId:e,getStoredWalletIndex:c,onWalletIndexChanged:i})}function k(s){const{sdk:e,defaultChainId:c=y.ChainId.CROSS_MAINNET,getStoredWalletIndex:i=D,onWalletIndexChanged:a=T}=s,t=P(c);let o=null,C=!1;function l(){return o||(o=new R(e,t),o._setWalletIndexChangeCallback(a)),o}return _.createConnector(h=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){console.log("[CROSSx-debug] connector.setup() 시작"),C||(await e.initialize(),C=!0),console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:",e.isAuthenticated());const n=l();n.on("accountsChanged",this.onAccountsChanged.bind(this)),n.on("chainChanged",this.onChainChanged.bind(this)),n.on("disconnect",this.onDisconnect.bind(this)),console.log("[CROSSx-debug] connector.setup() 완료, 이벤트 리스너 등록됨")},async connect({chainId:n,isReconnecting:g}={}){console.log("[CROSSx-debug] connector.connect() 호출",{isReconnecting:g,targetChainId:n});const r=l(),x=n??t;if(g||e.isAuthenticated()){const d=i();console.log("[CROSSx-debug] connector.connect() 재연결 경로",{storedIndex:d,isAuth:e.isAuthenticated()});const u=await e.getAddress(d||void 0);if(console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과",{address:u==null?void 0:u.address,index:u==null?void 0:u.index,requestedIndex:d||void 0}),u)return r.setWalletIndex(d),r.notifyAccountsChanged([u.address]),console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:",u.address),{accounts:[u.address],chainId:x};if(e.isAuthenticated()){console.log("[CROSSx-debug] connector.connect() 캐시 없음getAddresses() 재시도");try{const f=await e.getAddresses();if(f.length>0){const m=f.find(v=>v.index===d)??f[0];return r.setWalletIndex(m.index),r.notifyAccountsChanged([m.address]),console.log("[CROSSx-debug] connector.connect() getAddresses 재시도 성공 →",m.address),{accounts:[m.address],chainId:x}}}catch(f){console.warn("[CROSSx-debug] connector.connect() getAddresses 실패:",f)}console.log("[CROSSx-debug] connector.connect() 지갑 없음 — 로그아웃 후 신규 로그인"),await e.signOut().catch(()=>{}),r.notifyDisconnect()}console.log("[CROSSx-debug] connector.connect() 신규 로그인으로 진행")}let I;try{I=await e.signInWithCreate()}catch(d){throw e.isAuthenticated()||(r.notifyDisconnect(),h.emitter.emit("disconnect")),d}if(!I.success)throw new Error(I.error??"CROSSx sign-in failed");const S=I.address,O=I.addresses.map(d=>d.address).filter(d=>!S||d.toLowerCase()!==S.toLowerCase()),p=S?[S,...O]:O;if(p.length===0)throw new Error("No address found after sign-in");return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:",S),r.notifyAccountsChanged(p),{accounts:p,chainId:x}},async disconnect(){const n=l();await e.signOut(),n.notifyDisconnect(),E(),a(0),h.emitter.emit("disconnect")},async getAccounts(){const n=l(),g=n.getCurrentAccounts();if(console.log("[CROSSx-debug] connector.getAccounts()",{trackedLen:g.length,tracked:g[0],walletIndex:n.getWalletIndex()}),g.length>0)return g;const r=await e.getAddress();return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():",r==null?void 0:r.address),r?[r.address]:[]},async getChainId(){return l().getCurrentChainId()},async getProvider({chainId:n}={}){return l()},async isAuthorized(){const n=e.isAuthenticated();return console.log("[CROSSx-debug] connector.isAuthorized():",n),n},async switchChain({chainId:n}){l().setChainId(n),h.emitter.emit("change",{chainId:n});const r=h.chains.find(x=>x.id===n);if(!r)throw new Error(`Chain ${n} is not configured`);return r},onAccountsChanged(n){console.log("[CROSSx-debug] connector.onAccountsChanged:",n),n.length===0?h.emitter.emit("disconnect"):h.emitter.emit("change",{accounts:n})},onChainChanged(n){h.emitter.emit("change",{chainId:Number(n)})},onDisconnect(){h.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=R;exports.createCROSSxConnector=k;exports.crossxConnector=N;
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
- import { createConnector as b } from "wagmi";
2
- import { ChainId as y, createCROSSxSDK as O } from "@nexus-cross/crossx-sdk-core";
3
- function k(s) {
1
+ import { createConnector as k } from "wagmi";
2
+ import { ChainId as O, createCROSSxSDK as _ } from "@nexus-cross/crossx-sdk-core";
3
+ function v(s) {
4
4
  return parseInt(s.split(":")[1] ?? "1", 10);
5
5
  }
6
- function x(s) {
6
+ function m(s) {
7
7
  return `eip155:${s}`;
8
8
  }
9
- function p(s) {
9
+ function A(s) {
10
10
  return "0x" + s.toString(16);
11
11
  }
12
- class R {
13
- constructor(e, i = y.CROSS_MAINNET) {
14
- this.sdk = e, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof i == "number" ? i : k(i), this.sdk.on("addressChanged", ({ address: c, index: o }) => {
15
- this.setWalletIndex(o), this.notifyAccountsChanged([c]);
12
+ class W {
13
+ constructor(e, c = O.CROSS_MAINNET) {
14
+ this.sdk = e, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof c == "number" ? c : v(c), this.sdk.on("addressChanged", ({ address: i, index: r }) => {
15
+ this.setWalletIndex(r), this.notifyAccountsChanged([i]);
16
16
  });
17
17
  }
18
18
  /** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
@@ -20,9 +20,9 @@ class R {
20
20
  this.walletIndexChangeCallback = e;
21
21
  }
22
22
  // ── EIP-1193 request ──────────────────────────────────────────────────────
23
- async request({ method: e, params: i }) {
24
- var o;
25
- const c = i ?? [];
23
+ async request({ method: e, params: c }) {
24
+ var r;
25
+ const i = c ?? [];
26
26
  switch (e) {
27
27
  case "eth_requestAccounts":
28
28
  case "eth_accounts": {
@@ -32,21 +32,21 @@ class R {
32
32
  return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():", t == null ? void 0 : t.address), t ? [t.address] : [];
33
33
  }
34
34
  case "eth_chainId":
35
- return p(this.chainId);
35
+ return A(this.chainId);
36
36
  case "net_version":
37
37
  return String(this.chainId);
38
38
  case "personal_sign": {
39
- const [t] = c;
39
+ const [t] = i;
40
40
  return (await this.sdk.signMessage(
41
- x(this.chainId),
41
+ m(this.chainId),
42
42
  t,
43
43
  { index: this.walletIndex }
44
44
  )).signature;
45
45
  }
46
46
  case "eth_sign": {
47
- const [, t] = c;
47
+ const [, t] = i;
48
48
  return (await this.sdk.signMessage(
49
- x(this.chainId),
49
+ m(this.chainId),
50
50
  t,
51
51
  { index: this.walletIndex }
52
52
  )).signature;
@@ -54,11 +54,11 @@ class R {
54
54
  case "eth_signTypedData":
55
55
  case "eth_signTypedData_v3":
56
56
  case "eth_signTypedData_v4": {
57
- const [, t] = c, a = typeof t == "string" ? JSON.parse(t) : t, g = (o = a == null ? void 0 : a.domain) == null ? void 0 : o.chainId, d = g == null || g === 0, h = d ? 0 : Number(g), n = { index: this.walletIndex };
58
- return (d ? await this.sdk.signTypedDataOffchain(a, n) : await this.sdk.signTypedData(x(h), a, n)).signature;
57
+ const [, t] = i, a = typeof t == "string" ? JSON.parse(t) : t, C = (r = a == null ? void 0 : a.domain) == null ? void 0 : r.chainId, l = C == null || C === 0, h = l ? 0 : Number(C), n = { index: this.walletIndex };
58
+ return (l ? await this.sdk.signTypedDataOffchain(a, n) : await this.sdk.signTypedData(m(h), a, n)).signature;
59
59
  }
60
60
  case "eth_sendTransaction": {
61
- const [t] = c, a = x(this.chainId);
61
+ const [t] = i, a = m(this.chainId);
62
62
  return (await this.sdk.sendTransaction(a, {
63
63
  from: t.from,
64
64
  to: t.to,
@@ -73,26 +73,26 @@ class R {
73
73
  }, { index: this.walletIndex })).txHash;
74
74
  }
75
75
  case "wallet_switchEthereumChain": {
76
- const [{ chainId: t }] = c, a = parseInt(t, 16);
77
- return a !== this.chainId && (this.chainId = a, this.emit("chainChanged", p(a))), null;
76
+ const [{ chainId: t }] = i, a = parseInt(t, 16);
77
+ return a !== this.chainId && (this.chainId = a, this.emit("chainChanged", A(a))), null;
78
78
  }
79
79
  case "wallet_addEthereumChain":
80
80
  return null;
81
81
  default:
82
- return this.sdk.walletRpc(e, c, x(this.chainId));
82
+ return this.sdk.walletRpc(e, i, m(this.chainId));
83
83
  }
84
84
  }
85
85
  // ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
86
- on(e, i) {
87
- return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(i), this;
86
+ on(e, c) {
87
+ return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(c), this;
88
88
  }
89
- removeListener(e, i) {
90
- var c;
91
- return (c = this.listeners.get(e)) == null || c.delete(i), this;
89
+ removeListener(e, c) {
90
+ var i;
91
+ return (i = this.listeners.get(e)) == null || i.delete(c), this;
92
92
  }
93
- emit(e, ...i) {
94
- var c;
95
- (c = this.listeners.get(e)) == null || c.forEach((o) => o(...i));
93
+ emit(e, ...c) {
94
+ var i;
95
+ (i = this.listeners.get(e)) == null || i.forEach((r) => r(...c));
96
96
  }
97
97
  // ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
98
98
  notifyAccountsChanged(e) {
@@ -105,15 +105,15 @@ class R {
105
105
  return this.chainId;
106
106
  }
107
107
  setChainId(e) {
108
- e !== this.chainId && (this.chainId = e, this.emit("chainChanged", p(e)));
108
+ e !== this.chainId && (this.chainId = e, this.emit("chainChanged", A(e)));
109
109
  }
110
110
  /**
111
111
  * 활성 지갑 인덱스 설정.
112
112
  * Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
113
113
  */
114
114
  setWalletIndex(e) {
115
- var i;
116
- console.log("[CROSSx-debug] provider.setWalletIndex:", e), this.walletIndex = e, (i = this.walletIndexChangeCallback) == null || i.call(this, e);
115
+ var c;
116
+ console.log("[CROSSx-debug] provider.setWalletIndex:", e), this.walletIndex = e, (c = this.walletIndexChangeCallback) == null || c.call(this, e);
117
117
  }
118
118
  getWalletIndex() {
119
119
  return this.walletIndex;
@@ -122,99 +122,121 @@ class R {
122
122
  return [...this.currentAccounts];
123
123
  }
124
124
  }
125
- function _(s) {
125
+ function D(s) {
126
126
  return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
127
127
  }
128
- const w = "crossx-wallet-index";
129
- function v() {
128
+ const y = "crossx-wallet-index";
129
+ function P() {
130
130
  try {
131
- const s = typeof window < "u" ? localStorage.getItem(w) : null;
131
+ const s = typeof window < "u" ? localStorage.getItem(y) : null;
132
132
  return s && Number(s) || 0;
133
133
  } catch {
134
134
  return 0;
135
135
  }
136
136
  }
137
- function W(s) {
137
+ function T(s) {
138
138
  try {
139
- typeof window < "u" && localStorage.setItem(w, String(s));
139
+ typeof window < "u" && localStorage.setItem(y, String(s));
140
140
  } catch {
141
141
  }
142
142
  }
143
- function P() {
143
+ function E() {
144
144
  try {
145
- typeof window < "u" && localStorage.removeItem(w);
145
+ typeof window < "u" && localStorage.removeItem(y);
146
146
  } catch {
147
147
  }
148
148
  }
149
- function N(s) {
150
- const { defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: c, ...o } = s, t = O(o);
151
- return D({ sdk: t, defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: c });
149
+ function z(s) {
150
+ const { defaultChainId: e, getStoredWalletIndex: c, onWalletIndexChanged: i, ...r } = s, t = _(r);
151
+ return N({ sdk: t, defaultChainId: e, getStoredWalletIndex: c, onWalletIndexChanged: i });
152
152
  }
153
- function D(s) {
153
+ function N(s) {
154
154
  const {
155
155
  sdk: e,
156
- defaultChainId: i = y.CROSS_MAINNET,
157
- getStoredWalletIndex: c = v,
158
- onWalletIndexChanged: o = W
159
- } = s, t = _(i);
160
- let a = null, g = !1;
161
- function d() {
162
- return a || (a = new R(e, t), a._setWalletIndexChangeCallback(o)), a;
163
- }
164
- return b((h) => ({
156
+ defaultChainId: c = O.CROSS_MAINNET,
157
+ getStoredWalletIndex: i = P,
158
+ onWalletIndexChanged: r = T
159
+ } = s, t = D(c);
160
+ let a = null, C = !1;
161
+ function l() {
162
+ return a || (a = new W(e, t), a._setWalletIndexChangeCallback(r)), a;
163
+ }
164
+ return k((h) => ({
165
165
  id: "crossx",
166
166
  name: "CROSSx Wallet",
167
167
  type: "crossx",
168
168
  async setup() {
169
- console.log("[CROSSx-debug] connector.setup() 시작"), g || (await e.initialize(), g = !0), console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:", e.isAuthenticated());
170
- const n = d();
169
+ console.log("[CROSSx-debug] connector.setup() 시작"), C || (await e.initialize(), C = !0), console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:", e.isAuthenticated());
170
+ const n = l();
171
171
  n.on("accountsChanged", this.onAccountsChanged.bind(this)), n.on("chainChanged", this.onChainChanged.bind(this)), n.on("disconnect", this.onDisconnect.bind(this)), console.log("[CROSSx-debug] connector.setup() 완료, 이벤트 리스너 등록됨");
172
172
  },
173
173
  // ── connect ─────────────────────────────────────────────────────────────
174
- async connect({ chainId: n, isReconnecting: u } = {}) {
175
- console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting: u, targetChainId: n });
176
- const r = d(), S = n ?? t;
177
- if (u || e.isAuthenticated()) {
178
- const C = c();
179
- console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex: C, isAuth: e.isAuthenticated() });
180
- const l = await e.getAddress(C || void 0);
181
- if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address: l == null ? void 0 : l.address, index: l == null ? void 0 : l.index, requestedIndex: C || void 0 }), l)
182
- return r.setWalletIndex(C), r.notifyAccountsChanged([l.address]), console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:", l.address), {
183
- accounts: [l.address],
184
- chainId: S
174
+ async connect({ chainId: n, isReconnecting: g } = {}) {
175
+ console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting: g, targetChainId: n });
176
+ const o = l(), x = n ?? t;
177
+ if (g || e.isAuthenticated()) {
178
+ const d = i();
179
+ console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex: d, isAuth: e.isAuthenticated() });
180
+ const u = await e.getAddress(d || void 0);
181
+ if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address: u == null ? void 0 : u.address, index: u == null ? void 0 : u.index, requestedIndex: d || void 0 }), u)
182
+ return o.setWalletIndex(d), o.notifyAccountsChanged([u.address]), console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:", u.address), {
183
+ accounts: [u.address],
184
+ chainId: x
185
185
  };
186
- console.log("[CROSSx-debug] connector.connect() 재연결 경로 — info null, 신규 로그인으로 진행");
186
+ if (e.isAuthenticated()) {
187
+ console.log("[CROSSx-debug] connector.connect() 캐시 없음 — getAddresses() 재시도");
188
+ try {
189
+ const f = await e.getAddresses();
190
+ if (f.length > 0) {
191
+ const w = f.find((R) => R.index === d) ?? f[0];
192
+ return o.setWalletIndex(w.index), o.notifyAccountsChanged([w.address]), console.log("[CROSSx-debug] connector.connect() getAddresses 재시도 성공 →", w.address), {
193
+ accounts: [w.address],
194
+ chainId: x
195
+ };
196
+ }
197
+ } catch (f) {
198
+ console.warn("[CROSSx-debug] connector.connect() getAddresses 실패:", f);
199
+ }
200
+ console.log("[CROSSx-debug] connector.connect() 지갑 없음 — 로그아웃 후 신규 로그인"), await e.signOut().catch(() => {
201
+ }), o.notifyDisconnect();
202
+ }
203
+ console.log("[CROSSx-debug] connector.connect() 신규 로그인으로 진행");
204
+ }
205
+ let I;
206
+ try {
207
+ I = await e.signInWithCreate();
208
+ } catch (d) {
209
+ throw e.isAuthenticated() || (o.notifyDisconnect(), h.emitter.emit("disconnect")), d;
187
210
  }
188
- const f = await e.signInWithCreate();
189
- if (!f.success)
190
- throw new Error(f.error ?? "CROSSx sign-in failed");
191
- const I = f.address, A = f.addresses.map((C) => C.address).filter((C) => !I || C.toLowerCase() !== I.toLowerCase()), m = I ? [I, ...A] : A;
192
- if (m.length === 0)
211
+ if (!I.success)
212
+ throw new Error(I.error ?? "CROSSx sign-in failed");
213
+ const S = I.address, b = I.addresses.map((d) => d.address).filter((d) => !S || d.toLowerCase() !== S.toLowerCase()), p = S ? [S, ...b] : b;
214
+ if (p.length === 0)
193
215
  throw new Error("No address found after sign-in");
194
- return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:", I), r.notifyAccountsChanged(m), {
195
- accounts: m,
196
- chainId: S
216
+ return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:", S), o.notifyAccountsChanged(p), {
217
+ accounts: p,
218
+ chainId: x
197
219
  };
198
220
  },
199
221
  // ── disconnect ──────────────────────────────────────────────────────────
200
222
  async disconnect() {
201
- const n = d();
202
- await e.signOut(), n.notifyDisconnect(), P(), o(0), h.emitter.emit("disconnect");
223
+ const n = l();
224
+ await e.signOut(), n.notifyDisconnect(), E(), r(0), h.emitter.emit("disconnect");
203
225
  },
204
226
  // ── getAccounts ─────────────────────────────────────────────────────────
205
227
  async getAccounts() {
206
- const n = d(), u = n.getCurrentAccounts();
207
- if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen: u.length, tracked: u[0], walletIndex: n.getWalletIndex() }), u.length > 0) return u;
208
- const r = await e.getAddress();
209
- return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():", r == null ? void 0 : r.address), r ? [r.address] : [];
228
+ const n = l(), g = n.getCurrentAccounts();
229
+ if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen: g.length, tracked: g[0], walletIndex: n.getWalletIndex() }), g.length > 0) return g;
230
+ const o = await e.getAddress();
231
+ return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():", o == null ? void 0 : o.address), o ? [o.address] : [];
210
232
  },
211
233
  // ── getChainId ──────────────────────────────────────────────────────────
212
234
  async getChainId() {
213
- return d().getCurrentChainId();
235
+ return l().getCurrentChainId();
214
236
  },
215
237
  // ── getProvider ─────────────────────────────────────────────────────────
216
238
  async getProvider({ chainId: n } = {}) {
217
- return d();
239
+ return l();
218
240
  },
219
241
  // ── isAuthorized ────────────────────────────────────────────────────────
220
242
  async isAuthorized() {
@@ -223,11 +245,11 @@ function D(s) {
223
245
  },
224
246
  // ── switchChain ─────────────────────────────────────────────────────────
225
247
  async switchChain({ chainId: n }) {
226
- d().setChainId(n), h.emitter.emit("change", { chainId: n });
227
- const r = h.chains.find((S) => S.id === n);
228
- if (!r)
248
+ l().setChainId(n), h.emitter.emit("change", { chainId: n });
249
+ const o = h.chains.find((x) => x.id === n);
250
+ if (!o)
229
251
  throw new Error(`Chain ${n} is not configured`);
230
- return r;
252
+ return o;
231
253
  },
232
254
  // ── 이벤트 핸들러 ───────────────────────────────────────────────────────
233
255
  onAccountsChanged(n) {
@@ -246,7 +268,7 @@ function D(s) {
246
268
  }));
247
269
  }
248
270
  export {
249
- R as CROSSxEIP1193Provider,
250
- D as createCROSSxConnector,
251
- N as crossxConnector
271
+ W as CROSSxEIP1193Provider,
272
+ N as createCROSSxConnector,
273
+ z as crossxConnector
252
274
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/crossx-sdk-wagmi",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@nexus-cross/crossx-sdk-core": "1.0.9"
20
+ "@nexus-cross/crossx-sdk-core": "1.1.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": ">=2.0.0",