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