@nexus-cross/crossx-sdk-wagmi 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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;IAC/C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;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;IAC/C;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAS9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAyNpE"}
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;IAC/C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;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;IAC/C;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAS9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAqPpE"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("wagmi"),P=require("viem"),f=require("@nexus-cross/crossx-sdk-core");function N(i){return parseInt(i.split(":")[1]??"1",10)}function y(i){return`eip155:${i}`}function W(i){return"0x"+i.toString(16)}function R(i){const t=i.startsWith("0x")?i.slice(2):i,s=new Uint8Array(t.length/2);for(let n=0;n<s.length;n++)s[n]=parseInt(t.substring(n*2,n*2+2),16);return new TextDecoder().decode(s)}class b{constructor(t,s=f.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof s=="number"?s:N(s),this.sdk.on("addressChanged",({address:n,index:o})=>{this.setWalletIndex(o),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(t){this.walletIndexChangeCallback=t}async request({method:t,params:s}){try{return await this._handleRequest(t,s)}catch(n){throw n instanceof f.CROSSxError&&n.code===f.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(t,s){var o;const n=s??[];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 W(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n,r=e.startsWith("0x")?R(e):e;return(await this.sdk.signMessage(y(this.chainId),r,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n,r=e.startsWith("0x")?R(e):e;return(await this.sdk.signMessage(y(this.chainId),r,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=n,r=typeof e=="string"?JSON.parse(e):e,d=(o=r==null?void 0:r.domain)==null?void 0:o.chainId,w=d==null||d===0,m=w?0:Number(d),l={index:this.walletIndex};return(w?await this.sdk.signTypedDataOffchain(r,l):await this.sdk.signTypedData(y(m),r,l)).signature}case"eth_sendTransaction":{const[e]=n,r=y(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}]=n,r=parseInt(e,16);return r!==this.chainId&&(this.chainId=r,this.emit("chainChanged",W(r))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,y(this.chainId))}}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),this}removeListener(t,s){var n;return(n=this.listeners.get(t))==null||n.delete(s),this}emit(t,...s){var n;(n=this.listeners.get(t))==null||n.forEach(o=>o(...s))}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",W(t)))}setWalletIndex(t){var s;this.walletIndex=t,(s=this.walletIndexChangeCallback)==null||s.call(this,t)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function L(i){return typeof i=="number"?i:parseInt(i.split(":")[1]??"1",10)}const O="crossx-wallet-index";function q(){try{const i=typeof window<"u"?localStorage.getItem(O):null;return i&&Number(i)||0}catch{return 0}}function G(i){try{typeof window<"u"&&localStorage.setItem(O,String(i))}catch{}}function M(){try{typeof window<"u"&&localStorage.removeItem(O)}catch{}}function U(i){const{defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:o,...e}=i;o&&(e.showConnectOtherWallets=!0);const r=f.createCROSSxSDK(e);return k({sdk:r,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:o})}function k(i){const{sdk:t,defaultChainId:s=f.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=q,onWalletIndexChanged:o=G,openConnectOtherWallet:e}=i,r=L(s);let d=null,w=!1,m=!1;function l(){return d||(d=new b(t,r),d._setWalletIndexChangeCallback(o)),d}return D.createConnector(u=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!w){const g=n();await t.initialize({preferredWalletIndex:g}),w=!0,t.on("addressChanged",({address:c,index:C})=>{if(m)return;const p=l();p.setWalletIndex(C),c&&p.notifyAccountsChanged([c])}),e&&t.on("connectExternalWallet",e)}const a=l();a.on("accountsChanged",this.onAccountsChanged.bind(this)),a.on("chainChanged",this.onChainChanged.bind(this)),a.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:a,isReconnecting:g}={}){var p;const c=l(),C=a??r;m=!0;try{if(g||t.isAuthenticated()){const h=n();if(t.isAuthenticated()){try{const A=await t.getAddresses();if(A.length>0){const E=A.find(v=>v.index===h)??A[0];return c.setWalletIndex(E.index),c.notifyAccountsChanged([E.address]),{accounts:[E.address],chainId:C}}}catch{}await t.signOut().catch(()=>{}),c.notifyDisconnect()}}let I;try{I=await t.signInWithCreate()}catch(h){throw h instanceof f.CROSSxError&&h.code===f.ErrorCode.EXTERNAL_WALLET_REQUESTED?(c.notifyDisconnect(),new P.UserRejectedRequestError(h)):(t.isAuthenticated()||(c.notifyDisconnect(),u.emitter.emit("disconnect")),h)}if(!I.success)throw new Error(I.error??"CROSSx sign-in failed");const x=I.address,_=I.addresses.map(h=>h.address).filter(h=>!x||h.toLowerCase()!==x.toLowerCase()),S=x?[x,..._]:_;if(S.length===0)throw new Error("No address found after sign-in");const T=((p=I.addresses.find(h=>x&&h.address.toLowerCase()===x.toLowerCase()))==null?void 0:p.index)??0;return c.setWalletIndex(T),c.notifyAccountsChanged(S),{accounts:S,chainId:C}}finally{m=!1}},async disconnect(){const a=l();await t.signOut(),a.notifyDisconnect(),M(),o(0),u.emitter.emit("disconnect")},async getAccounts(){const g=l().getCurrentAccounts();if(g.length>0)return g;const c=await t.getAddress();return c?[c.address]:[]},async getChainId(){return l().getCurrentChainId()},async getProvider({chainId:a}={}){return l()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:a}){l().setChainId(a),u.emitter.emit("change",{chainId:a});const c=u.chains.find(C=>C.id===a);if(!c)throw new Error(`Chain ${a} is not configured`);return c},onAccountsChanged(a){a.length===0?u.emitter.emit("disconnect"):u.emitter.emit("change",{accounts:a})},onChainChanged(a){u.emitter.emit("change",{chainId:Number(a)})},onDisconnect(){u.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=b;exports.createCROSSxConnector=k;exports.crossxConnector=U;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("wagmi"),L=require("viem"),C=require("@nexus-cross/crossx-sdk-core");function q(i){return parseInt(i.split(":")[1]??"1",10)}function S(i){return`eip155:${i}`}function O(i){return"0x"+i.toString(16)}function b(i){const t=i.startsWith("0x")?i.slice(2):i,s=new Uint8Array(t.length/2);for(let n=0;n<s.length;n++)s[n]=parseInt(t.substring(n*2,n*2+2),16);return new TextDecoder().decode(s)}class D{constructor(t,s=C.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof s=="number"?s:q(s),this.sdk.on("addressChanged",({address:n,index:o})=>{this.setWalletIndex(o),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(t){this.walletIndexChangeCallback=t}async request({method:t,params:s}){try{return await this._handleRequest(t,s)}catch(n){throw n instanceof C.CROSSxError&&n.code===C.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(t,s){var o;const n=s??[];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 O(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n,a=e.startsWith("0x")?b(e):e;return(await this.sdk.signMessage(S(this.chainId),a,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n,a=e.startsWith("0x")?b(e):e;return(await this.sdk.signMessage(S(this.chainId),a,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=n,a=typeof e=="string"?JSON.parse(e):e,d=(o=a==null?void 0:a.domain)==null?void 0:o.chainId,y=d==null||d===0,I=y?0:Number(d),x={index:this.walletIndex};return(y?await this.sdk.signTypedDataOffchain(a,x):await this.sdk.signTypedData(S(I),a,x)).signature}case"eth_sendTransaction":{const[e]=n,a=S(this.chainId);return(await this.sdk.sendTransaction(a,{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}]=n,a=parseInt(e,16);return a!==this.chainId&&(this.chainId=a,this.emit("chainChanged",O(a))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,S(this.chainId))}}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),this}removeListener(t,s){var n;return(n=this.listeners.get(t))==null||n.delete(s),this}emit(t,...s){var n;(n=this.listeners.get(t))==null||n.forEach(o=>o(...s))}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",O(t)))}setWalletIndex(t){var s;this.walletIndex=t,(s=this.walletIndexChangeCallback)==null||s.call(this,t)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function G(i){return typeof i=="number"?i:parseInt(i.split(":")[1]??"1",10)}const _="crossx-wallet-index";function M(){try{const i=typeof window<"u"?localStorage.getItem(_):null;return i&&Number(i)||0}catch{return 0}}function U(i){try{typeof window<"u"&&localStorage.setItem(_,String(i))}catch{}}function k(){try{typeof window<"u"&&localStorage.removeItem(_)}catch{}}function j(i){const{defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:o,...e}=i;o&&(e.showConnectOtherWallets=!0);const a=C.createCROSSxSDK(e);return T({sdk:a,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,openConnectOtherWallet:o})}function T(i){const{sdk:t,defaultChainId:s=C.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=M,onWalletIndexChanged:o=U,openConnectOtherWallet:e}=i,a=G(s);let d=null,y=!1,I=!1,x=!1;function l(){return d||(d=new D(t,a),d._setWalletIndexChangeCallback(o)),d}return N.createConnector(u=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!y){const f=n();await t.initialize({preferredWalletIndex:f}),y=!0,t.on("addressChanged",({address:r,index:g})=>{if(I)return;const p=l();p.setWalletIndex(g),r&&p.notifyAccountsChanged([r])}),t.on("authChanged",r=>{if(!(I||x))if(r.isAuthenticated&&r.address){const g=l();g.notifyAccountsChanged([r.address]),u.emitter.emit("connect",{accounts:[r.address],chainId:g.getCurrentChainId()})}else r.isAuthenticated||(l().notifyDisconnect(),k(),o(0),u.emitter.emit("disconnect"))}),e&&t.on("connectExternalWallet",e)}const c=l();c.on("accountsChanged",this.onAccountsChanged.bind(this)),c.on("chainChanged",this.onChainChanged.bind(this)),c.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:c,isReconnecting:f}={}){var p;const r=l(),g=c??a;I=!0;try{if(f||t.isAuthenticated()){const h=n();if(t.isAuthenticated()){try{const E=await t.getAddresses();if(E.length>0){const W=E.find(v=>v.index===h)??E[0];return r.setWalletIndex(W.index),r.notifyAccountsChanged([W.address]),{accounts:[W.address],chainId:g}}}catch{}await t.signOut().catch(()=>{}),r.notifyDisconnect()}}let w;try{w=await t.signInWithCreate()}catch(h){throw h instanceof C.CROSSxError&&h.code===C.ErrorCode.EXTERNAL_WALLET_REQUESTED?(r.notifyDisconnect(),new L.UserRejectedRequestError(h)):(t.isAuthenticated()||(r.notifyDisconnect(),u.emitter.emit("disconnect")),h)}if(!w.success)throw new Error(w.error??"CROSSx sign-in failed");const m=w.address,R=w.addresses.map(h=>h.address).filter(h=>!m||h.toLowerCase()!==m.toLowerCase()),A=m?[m,...R]:R;if(A.length===0)throw new Error("No address found after sign-in");const P=((p=w.addresses.find(h=>m&&h.address.toLowerCase()===m.toLowerCase()))==null?void 0:p.index)??0;return r.setWalletIndex(P),r.notifyAccountsChanged(A),{accounts:A,chainId:g}}finally{I=!1}},async disconnect(){x=!0;try{const c=l();await t.signOut(),c.notifyDisconnect(),k(),o(0),u.emitter.emit("disconnect")}finally{x=!1}},async getAccounts(){const f=l().getCurrentAccounts();if(f.length>0)return f;const r=await t.getAddress();return r?[r.address]:[]},async getChainId(){return l().getCurrentChainId()},async getProvider({chainId:c}={}){return l()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:c}){l().setChainId(c),u.emitter.emit("change",{chainId:c});const r=u.chains.find(g=>g.id===c);if(!r)throw new Error(`Chain ${c} is not configured`);return r},onAccountsChanged(c){c.length===0?u.emitter.emit("disconnect"):u.emitter.emit("change",{accounts:c})},onChainChanged(c){u.emitter.emit("change",{chainId:Number(c)})},onDisconnect(){u.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=D;exports.createCROSSxConnector=T;exports.crossxConnector=j;
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
1
  import { createConnector as v } from "wagmi";
2
- import { UserRejectedRequestError as P } from "viem";
3
- import { ChainId as b, CROSSxError as R, ErrorCode as k, createCROSSxSDK as N } from "@nexus-cross/crossx-sdk-core";
4
- function L(i) {
2
+ import { UserRejectedRequestError as L } from "viem";
3
+ import { ChainId as R, CROSSxError as k, ErrorCode as T, createCROSSxSDK as q } from "@nexus-cross/crossx-sdk-core";
4
+ function G(i) {
5
5
  return parseInt(i.split(":")[1] ?? "1", 10);
6
6
  }
7
- function p(i) {
7
+ function y(i) {
8
8
  return `eip155:${i}`;
9
9
  }
10
- function E(i) {
10
+ function W(i) {
11
11
  return "0x" + i.toString(16);
12
12
  }
13
- function O(i) {
13
+ function b(i) {
14
14
  const t = i.startsWith("0x") ? i.slice(2) : i, s = new Uint8Array(t.length / 2);
15
15
  for (let n = 0; n < s.length; n++)
16
16
  s[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
17
17
  return new TextDecoder().decode(s);
18
18
  }
19
- class q {
20
- constructor(t, s = b.CROSS_MAINNET) {
21
- this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof s == "number" ? s : L(s), this.sdk.on("addressChanged", ({ address: n, index: o }) => {
19
+ class U {
20
+ constructor(t, s = R.CROSS_MAINNET) {
21
+ this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof s == "number" ? s : G(s), this.sdk.on("addressChanged", ({ address: n, index: o }) => {
22
22
  this.setWalletIndex(o), this.notifyAccountsChanged([n]);
23
23
  });
24
24
  }
@@ -31,7 +31,7 @@ class q {
31
31
  try {
32
32
  return await this._handleRequest(t, s);
33
33
  } catch (n) {
34
- throw n instanceof R && n.code === k.USER_REJECTED ? Object.assign(
34
+ throw n instanceof k && n.code === T.USER_REJECTED ? Object.assign(
35
35
  new Error("User rejected the request"),
36
36
  { code: 4001, data: n.details }
37
37
  ) : n;
@@ -49,21 +49,21 @@ class q {
49
49
  return e ? [e.address] : [];
50
50
  }
51
51
  case "eth_chainId":
52
- return E(this.chainId);
52
+ return W(this.chainId);
53
53
  case "net_version":
54
54
  return String(this.chainId);
55
55
  case "personal_sign": {
56
- const [e] = n, r = e.startsWith("0x") ? O(e) : e;
56
+ const [e] = n, r = e.startsWith("0x") ? b(e) : e;
57
57
  return (await this.sdk.signMessage(
58
- p(this.chainId),
58
+ y(this.chainId),
59
59
  r,
60
60
  { index: this.walletIndex }
61
61
  )).signature;
62
62
  }
63
63
  case "eth_sign": {
64
- const [, e] = n, r = e.startsWith("0x") ? O(e) : e;
64
+ const [, e] = n, r = e.startsWith("0x") ? b(e) : e;
65
65
  return (await this.sdk.signMessage(
66
- p(this.chainId),
66
+ y(this.chainId),
67
67
  r,
68
68
  { index: this.walletIndex }
69
69
  )).signature;
@@ -71,11 +71,11 @@ class q {
71
71
  case "eth_signTypedData":
72
72
  case "eth_signTypedData_v3":
73
73
  case "eth_signTypedData_v4": {
74
- const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e, d = (o = r == null ? void 0 : r.domain) == null ? void 0 : o.chainId, x = d == null || d === 0, w = x ? 0 : Number(d), l = { index: this.walletIndex };
75
- return (x ? await this.sdk.signTypedDataOffchain(r, l) : await this.sdk.signTypedData(p(w), r, l)).signature;
74
+ const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e, d = (o = r == null ? void 0 : r.domain) == null ? void 0 : o.chainId, w = d == null || d === 0, I = w ? 0 : Number(d), C = { index: this.walletIndex };
75
+ return (w ? await this.sdk.signTypedDataOffchain(r, C) : await this.sdk.signTypedData(y(I), r, C)).signature;
76
76
  }
77
77
  case "eth_sendTransaction": {
78
- const [e] = n, r = p(this.chainId);
78
+ const [e] = n, r = y(this.chainId);
79
79
  return (await this.sdk.sendTransaction(r, {
80
80
  from: e.from,
81
81
  to: e.to,
@@ -91,12 +91,12 @@ class q {
91
91
  }
92
92
  case "wallet_switchEthereumChain": {
93
93
  const [{ chainId: e }] = n, r = parseInt(e, 16);
94
- return r !== this.chainId && (this.chainId = r, this.emit("chainChanged", E(r))), null;
94
+ return r !== this.chainId && (this.chainId = r, this.emit("chainChanged", W(r))), null;
95
95
  }
96
96
  case "wallet_addEthereumChain":
97
97
  return null;
98
98
  default:
99
- return this.sdk.walletRpc(t, n, p(this.chainId));
99
+ return this.sdk.walletRpc(t, n, y(this.chainId));
100
100
  }
101
101
  }
102
102
  // ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
@@ -122,7 +122,7 @@ class q {
122
122
  return this.chainId;
123
123
  }
124
124
  setChainId(t) {
125
- t !== this.chainId && (this.chainId = t, this.emit("chainChanged", E(t)));
125
+ t !== this.chainId && (this.chainId = t, this.emit("chainChanged", W(t)));
126
126
  }
127
127
  /**
128
128
  * 활성 지갑 인덱스 설정.
@@ -139,69 +139,78 @@ class q {
139
139
  return [...this.currentAccounts];
140
140
  }
141
141
  }
142
- function G(i) {
142
+ function M(i) {
143
143
  return typeof i == "number" ? i : parseInt(i.split(":")[1] ?? "1", 10);
144
144
  }
145
- const W = "crossx-wallet-index";
146
- function U() {
145
+ const _ = "crossx-wallet-index";
146
+ function F() {
147
147
  try {
148
- const i = typeof window < "u" ? localStorage.getItem(W) : null;
148
+ const i = typeof window < "u" ? localStorage.getItem(_) : null;
149
149
  return i && Number(i) || 0;
150
150
  } catch {
151
151
  return 0;
152
152
  }
153
153
  }
154
- function M(i) {
154
+ function j(i) {
155
155
  try {
156
- typeof window < "u" && localStorage.setItem(W, String(i));
156
+ typeof window < "u" && localStorage.setItem(_, String(i));
157
157
  } catch {
158
158
  }
159
159
  }
160
- function F() {
160
+ function D() {
161
161
  try {
162
- typeof window < "u" && localStorage.removeItem(W);
162
+ typeof window < "u" && localStorage.removeItem(_);
163
163
  } catch {
164
164
  }
165
165
  }
166
- function K(i) {
166
+ function $(i) {
167
167
  const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: o, ...e } = i;
168
168
  o && (e.showConnectOtherWallets = !0);
169
- const r = N(e);
170
- return j({ sdk: r, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: o });
169
+ const r = q(e);
170
+ return z({ sdk: r, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: o });
171
171
  }
172
- function j(i) {
172
+ function z(i) {
173
173
  const {
174
174
  sdk: t,
175
- defaultChainId: s = b.CROSS_MAINNET,
176
- getStoredWalletIndex: n = U,
177
- onWalletIndexChanged: o = M,
175
+ defaultChainId: s = R.CROSS_MAINNET,
176
+ getStoredWalletIndex: n = F,
177
+ onWalletIndexChanged: o = j,
178
178
  openConnectOtherWallet: e
179
- } = i, r = G(s);
180
- let d = null, x = !1, w = !1;
179
+ } = i, r = M(s);
180
+ let d = null, w = !1, I = !1, C = !1;
181
181
  function l() {
182
- return d || (d = new q(t, r), d._setWalletIndexChangeCallback(o)), d;
182
+ return d || (d = new U(t, r), d._setWalletIndexChangeCallback(o)), d;
183
183
  }
184
184
  return v((u) => ({
185
185
  id: "crossx",
186
186
  name: "CROSSx Wallet",
187
187
  type: "crossx",
188
188
  async setup() {
189
- if (!x) {
189
+ if (!w) {
190
190
  const g = n();
191
- await t.initialize({ preferredWalletIndex: g }), x = !0, t.on("addressChanged", ({ address: c, index: f }) => {
192
- if (w) return;
193
- const m = l();
194
- m.setWalletIndex(f), c && m.notifyAccountsChanged([c]);
191
+ await t.initialize({ preferredWalletIndex: g }), w = !0, t.on("addressChanged", ({ address: a, index: f }) => {
192
+ if (I) return;
193
+ const p = l();
194
+ p.setWalletIndex(f), a && p.notifyAccountsChanged([a]);
195
+ }), t.on("authChanged", (a) => {
196
+ if (!(I || C))
197
+ if (a.isAuthenticated && a.address) {
198
+ const f = l();
199
+ f.notifyAccountsChanged([a.address]), u.emitter.emit("connect", {
200
+ accounts: [a.address],
201
+ chainId: f.getCurrentChainId()
202
+ });
203
+ } else a.isAuthenticated || (l().notifyDisconnect(), D(), o(0), u.emitter.emit("disconnect"));
195
204
  }), e && t.on("connectExternalWallet", e);
196
205
  }
197
- const a = l();
198
- a.on("accountsChanged", this.onAccountsChanged.bind(this)), a.on("chainChanged", this.onChainChanged.bind(this)), a.on("disconnect", this.onDisconnect.bind(this));
206
+ const c = l();
207
+ c.on("accountsChanged", this.onAccountsChanged.bind(this)), c.on("chainChanged", this.onChainChanged.bind(this)), c.on("disconnect", this.onDisconnect.bind(this));
199
208
  },
200
209
  // ── connect ─────────────────────────────────────────────────────────────
201
- async connect({ chainId: a, isReconnecting: g } = {}) {
202
- var m;
203
- const c = l(), f = a ?? r;
204
- w = !0;
210
+ async connect({ chainId: c, isReconnecting: g } = {}) {
211
+ var p;
212
+ const a = l(), f = c ?? r;
213
+ I = !0;
205
214
  try {
206
215
  if (g || t.isAuthenticated()) {
207
216
  const h = n();
@@ -209,9 +218,9 @@ function j(i) {
209
218
  try {
210
219
  const S = await t.getAddresses();
211
220
  if (S.length > 0) {
212
- const A = S.find((D) => D.index === h) ?? S[0];
213
- return c.setWalletIndex(A.index), c.notifyAccountsChanged([A.address]), {
214
- accounts: [A.address],
221
+ const E = S.find((N) => N.index === h) ?? S[0];
222
+ return a.setWalletIndex(E.index), a.notifyAccountsChanged([E.address]), {
223
+ accounts: [E.address],
215
224
  chainId: f
216
225
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
217
226
  };
@@ -219,50 +228,55 @@ function j(i) {
219
228
  } catch {
220
229
  }
221
230
  await t.signOut().catch(() => {
222
- }), c.notifyDisconnect();
231
+ }), a.notifyDisconnect();
223
232
  }
224
233
  }
225
- let I;
234
+ let m;
226
235
  try {
227
- I = await t.signInWithCreate();
236
+ m = await t.signInWithCreate();
228
237
  } catch (h) {
229
- throw h instanceof R && h.code === k.EXTERNAL_WALLET_REQUESTED ? (c.notifyDisconnect(), new P(h)) : (t.isAuthenticated() || (c.notifyDisconnect(), u.emitter.emit("disconnect")), h);
238
+ throw h instanceof k && h.code === T.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new L(h)) : (t.isAuthenticated() || (a.notifyDisconnect(), u.emitter.emit("disconnect")), h);
230
239
  }
231
- if (!I.success)
232
- throw new Error(I.error ?? "CROSSx sign-in failed");
233
- const C = I.address, _ = I.addresses.map((h) => h.address).filter((h) => !C || h.toLowerCase() !== C.toLowerCase()), y = C ? [C, ..._] : _;
234
- if (y.length === 0)
240
+ if (!m.success)
241
+ throw new Error(m.error ?? "CROSSx sign-in failed");
242
+ const x = m.address, O = m.addresses.map((h) => h.address).filter((h) => !x || h.toLowerCase() !== x.toLowerCase()), A = x ? [x, ...O] : O;
243
+ if (A.length === 0)
235
244
  throw new Error("No address found after sign-in");
236
- const T = ((m = I.addresses.find(
237
- (h) => C && h.address.toLowerCase() === C.toLowerCase()
238
- )) == null ? void 0 : m.index) ?? 0;
239
- return c.setWalletIndex(T), c.notifyAccountsChanged(y), {
240
- accounts: y,
245
+ const P = ((p = m.addresses.find(
246
+ (h) => x && h.address.toLowerCase() === x.toLowerCase()
247
+ )) == null ? void 0 : p.index) ?? 0;
248
+ return a.setWalletIndex(P), a.notifyAccountsChanged(A), {
249
+ accounts: A,
241
250
  chainId: f
242
251
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
252
  };
244
253
  } finally {
245
- w = !1;
254
+ I = !1;
246
255
  }
247
256
  },
248
257
  // ── disconnect ──────────────────────────────────────────────────────────
249
258
  async disconnect() {
250
- const a = l();
251
- await t.signOut(), a.notifyDisconnect(), F(), o(0), u.emitter.emit("disconnect");
259
+ C = !0;
260
+ try {
261
+ const c = l();
262
+ await t.signOut(), c.notifyDisconnect(), D(), o(0), u.emitter.emit("disconnect");
263
+ } finally {
264
+ C = !1;
265
+ }
252
266
  },
253
267
  // ── getAccounts ─────────────────────────────────────────────────────────
254
268
  async getAccounts() {
255
269
  const g = l().getCurrentAccounts();
256
270
  if (g.length > 0) return g;
257
- const c = await t.getAddress();
258
- return c ? [c.address] : [];
271
+ const a = await t.getAddress();
272
+ return a ? [a.address] : [];
259
273
  },
260
274
  // ── getChainId ──────────────────────────────────────────────────────────
261
275
  async getChainId() {
262
276
  return l().getCurrentChainId();
263
277
  },
264
278
  // ── getProvider ─────────────────────────────────────────────────────────
265
- async getProvider({ chainId: a } = {}) {
279
+ async getProvider({ chainId: c } = {}) {
266
280
  return l();
267
281
  },
268
282
  // ── isAuthorized ────────────────────────────────────────────────────────
@@ -270,22 +284,22 @@ function j(i) {
270
284
  return await t.whenReady(), t.isAuthenticated();
271
285
  },
272
286
  // ── switchChain ─────────────────────────────────────────────────────────
273
- async switchChain({ chainId: a }) {
274
- l().setChainId(a), u.emitter.emit("change", { chainId: a });
275
- const c = u.chains.find((f) => f.id === a);
276
- if (!c)
277
- throw new Error(`Chain ${a} is not configured`);
278
- return c;
287
+ async switchChain({ chainId: c }) {
288
+ l().setChainId(c), u.emitter.emit("change", { chainId: c });
289
+ const a = u.chains.find((f) => f.id === c);
290
+ if (!a)
291
+ throw new Error(`Chain ${c} is not configured`);
292
+ return a;
279
293
  },
280
294
  // ── 이벤트 핸들러 ───────────────────────────────────────────────────────
281
- onAccountsChanged(a) {
282
- a.length === 0 ? u.emitter.emit("disconnect") : u.emitter.emit("change", {
283
- accounts: a
295
+ onAccountsChanged(c) {
296
+ c.length === 0 ? u.emitter.emit("disconnect") : u.emitter.emit("change", {
297
+ accounts: c
284
298
  });
285
299
  },
286
- onChainChanged(a) {
300
+ onChainChanged(c) {
287
301
  u.emitter.emit("change", {
288
- chainId: Number(a)
302
+ chainId: Number(c)
289
303
  });
290
304
  },
291
305
  onDisconnect() {
@@ -294,7 +308,7 @@ function j(i) {
294
308
  }));
295
309
  }
296
310
  export {
297
- q as CROSSxEIP1193Provider,
298
- j as createCROSSxConnector,
299
- K as crossxConnector
311
+ U as CROSSxEIP1193Provider,
312
+ z as createCROSSxConnector,
313
+ $ as crossxConnector
300
314
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/crossx-sdk-wagmi",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
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.3.5"
20
+ "@nexus-cross/crossx-sdk-core": "1.3.7"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": ">=2.0.0",