@nexus-cross/crossx-sdk-wagmi 2.3.0-beta.2 → 2.3.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +65 -59
- package/package.json +2 -2
package/dist/connector.d.ts.map
CHANGED
|
@@ -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,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;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,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAoDF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAc9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,
|
|
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,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;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,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAoDF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAc9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAgTpE"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("wagmi"),z=require("viem"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("wagmi"),z=require("viem"),y=require("@nexus-cross/crossx-sdk-core");function F(s){return parseInt(s.split(":")[1]??"1",10)}function A(s){return`eip155:${s}`}function b(s){return"0x"+s.toString(16)}function N(s){const e=s.startsWith("0x")?s.slice(2):s,r=new Uint8Array(e.length/2);for(let n=0;n<r.length;n++)r[n]=parseInt(e.substring(n*2,n*2+2),16);return new TextDecoder().decode(r)}class G{constructor(e,r=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 r=="number"?r:F(r),this.sdk.on("addressChanged",({address:n,index:d})=>{this.setWalletIndex(d),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:r}){try{return await this._handleRequest(e,r)}catch(n){throw n instanceof y.CROSSxError&&n.code===y.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(e,r){var d;const n=r??[];switch(e){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return[...this.currentAccounts];const t=await this.sdk.getAddress();return t?[t.address]:[]}case"eth_chainId":return b(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=n,c=t.startsWith("0x")?N(t):t;return(await this.sdk.signMessage(A(this.chainId),c,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=n,c=t.startsWith("0x")?N(t):t;return(await this.sdk.signMessage(A(this.chainId),c,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=n,c=typeof t=="string"?JSON.parse(t):t,l=(d=c==null?void 0:c.domain)==null?void 0:d.chainId,u=l==null||l===0,m=u?0:Number(l),f={index:this.walletIndex};return(u?await this.sdk.signTypedDataOffchain(c,f):await this.sdk.signTypedData(A(m),c,f)).signature}case"eth_sendTransaction":{const[t]=n,c=A(this.chainId);return(await this.sdk.sendTransaction(c,{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}]=n,c=parseInt(t,16);return c!==this.chainId&&(this.chainId=c,this.emit("chainChanged",b(c))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,n,A(this.chainId))}}on(e,r){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(r),this}removeListener(e,r){var n;return(n=this.listeners.get(e))==null||n.delete(r),this}emit(e,...r){var n;(n=this.listeners.get(e))==null||n.forEach(d=>d(...r))}notifyAccountsChanged(e){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",b(e)))}setWalletIndex(e){var r;this.walletIndex=e,(r=this.walletIndexChangeCallback)==null||r.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function K(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const k="crossx-wallet-index";function H(){try{const s=typeof window<"u"?localStorage.getItem(k):null;return s&&Number(s)||0}catch{return 0}}function J(s){try{typeof window<"u"&&localStorage.setItem(k,String(s))}catch{}}function q(){try{typeof window<"u"&&localStorage.removeItem(k)}catch{}}const D="crossx-wallet-address";function Y(){try{return typeof window<"u"?localStorage.getItem(D):null}catch{return null}}function $(s){try{typeof window<"u"&&localStorage.setItem(D,s)}catch{}}function Q(){try{typeof window<"u"&&localStorage.removeItem(D)}catch{}}function X(s){const{defaultChainId:e,getStoredWalletIndex:r,onWalletIndexChanged:n,getStoredWalletAddress:d,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:l,...u}=s;if(l){const f=u.connectOtherWallets,S=Array.isArray(f)&&f.length>0,x=u.showConnectOtherWallets===!0;!S&&!x&&(u.showConnectOtherWallets=!0)}const m=y.createCROSSxSDK(u);return M({sdk:m,defaultChainId:e,getStoredWalletIndex:r,onWalletIndexChanged:n,getStoredWalletAddress:d,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:l})}function M(s){const{sdk:e,defaultChainId:r=y.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=H,onWalletIndexChanged:d=J,getStoredWalletAddress:t=Y,onWalletAddressChanged:c=$,clearStoredWalletAddress:l=Q,openConnectOtherWallet:u}=s,m=K(r);let f=null,S=!1,x=null,T=!1,E=!1,O=!1;function g(){return f||(f=new G(e,m),f._setWalletIndexChangeCallback(d)),f}return j.createConnector(C=>{function P(a){if(T)return;const h=g();h.on("accountsChanged",a.onAccountsChanged.bind(a)),h.on("chainChanged",a.onChainChanged.bind(a)),h.on("disconnect",a.onDisconnect.bind(a)),T=!0}async function _(){if(!S)return x||(x=(async()=>{const a=n(),h=t()??void 0;await e.initialize({preferredWalletIndex:a,preferredWalletAddress:h}),e.on("addressChanged",({address:i,index:I})=>{if(E)return;const W=g();W.setWalletIndex(I),i&&(W.notifyAccountsChanged([i]),c(i))}),e.on("authChanged",i=>{if(!(E||O))if(i.isAuthenticated&&i.address){const I=g();I.notifyAccountsChanged([i.address]),C.emitter.emit("connect",{accounts:[i.address],chainId:I.getCurrentChainId()})}else i.isAuthenticated||(g().notifyDisconnect(),q(),l(),d(0),C.emitter.emit("disconnect"))}),u&&e.on("connectExternalWallet",u),S=!0})().finally(()=>{x=null}),x)}return{id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){await _(),P(this)},async connect({chainId:a,isReconnecting:h}={}){await _(),P(this);const i=g(),I=a??m;E=!0;try{if(e.isAuthenticated()){const o=await e.getAddress();if(o)return i.setWalletIndex(o.index),i.notifyAccountsChanged([o.address]),{accounts:[o.address],chainId:I};if(h)throw new Error("CROSSx reconnect: authenticated session has no active wallet address");await e.signOut().catch(()=>{}),i.notifyDisconnect()}if(h)throw new Error("CROSSx reconnect: no authenticated session to restore");const W=t();let p;try{p=await e.signInWithCreate({preferredWalletAddress:W??void 0})}catch(o){throw o instanceof y.CROSSxError&&o.code===y.ErrorCode.EXTERNAL_WALLET_REQUESTED?(i.notifyDisconnect(),new z.UserRejectedRequestError(o)):(e.isAuthenticated()||(i.notifyDisconnect(),C.emitter.emit("disconnect")),o)}if(!p.success)throw new Error(p.error??"CROSSx sign-in failed");const w=p.address,L=p.addresses.map(o=>o.address).filter(o=>!w||o.toLowerCase()!==w.toLowerCase()),R=w?[w,...L]:L;if(R.length===0)throw new Error("No address found after sign-in");const v=p.addresses.find(o=>w&&o.address.toLowerCase()===w.toLowerCase()),U=(v==null?void 0:v.index)??0;return i.setWalletIndex(U),i.notifyAccountsChanged(R),w&&c(w),{accounts:R,chainId:I}}finally{E=!1}},async disconnect(){O=!0;try{const a=g();await e.signOut(),a.notifyDisconnect(),q(),l(),d(0),C.emitter.emit("disconnect")}finally{O=!1}},async getAccounts(){const h=g().getCurrentAccounts();if(h.length>0)return h;const i=await e.getAddress();return i?[i.address]:[]},async getChainId(){return g().getCurrentChainId()},async getProvider({chainId:a}={}){return g()},async isAuthorized(){return await _(),e.isAuthenticated()},async switchChain({chainId:a}){g().setChainId(a),C.emitter.emit("change",{chainId:a});const i=C.chains.find(I=>I.id===a);if(!i)throw new Error(`Chain ${a} is not configured`);return i},onAccountsChanged(a){a.length===0?C.emitter.emit("disconnect"):C.emitter.emit("change",{accounts:a})},onChainChanged(a){C.emitter.emit("change",{chainId:Number(a)})},onDisconnect(){C.emitter.emit("disconnect")}}})}exports.CROSSxEIP1193Provider=G;exports.createCROSSxConnector=M;exports.crossxConnector=X;
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import { ChainId as G, CROSSxError as q, ErrorCode as U, createCROSSxSDK as j }
|
|
|
4
4
|
function K(s) {
|
|
5
5
|
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function S(s) {
|
|
8
8
|
return `eip155:${s}`;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function R(s) {
|
|
11
11
|
return "0x" + s.toString(16);
|
|
12
12
|
}
|
|
13
13
|
function L(s) {
|
|
@@ -18,8 +18,8 @@ function L(s) {
|
|
|
18
18
|
}
|
|
19
19
|
class H {
|
|
20
20
|
constructor(t, r = G.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 r == "number" ? r : K(r), this.sdk.on("addressChanged", ({ address: n, index:
|
|
22
|
-
this.setWalletIndex(
|
|
21
|
+
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof r == "number" ? r : K(r), this.sdk.on("addressChanged", ({ address: n, index: d }) => {
|
|
22
|
+
this.setWalletIndex(d), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -38,7 +38,7 @@ class H {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
async _handleRequest(t, r) {
|
|
41
|
-
var
|
|
41
|
+
var d;
|
|
42
42
|
const n = r ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
@@ -49,13 +49,13 @@ class H {
|
|
|
49
49
|
return e ? [e.address] : [];
|
|
50
50
|
}
|
|
51
51
|
case "eth_chainId":
|
|
52
|
-
return
|
|
52
|
+
return R(this.chainId);
|
|
53
53
|
case "net_version":
|
|
54
54
|
return String(this.chainId);
|
|
55
55
|
case "personal_sign": {
|
|
56
56
|
const [e] = n, c = e.startsWith("0x") ? L(e) : e;
|
|
57
57
|
return (await this.sdk.signMessage(
|
|
58
|
-
|
|
58
|
+
S(this.chainId),
|
|
59
59
|
c,
|
|
60
60
|
{ index: this.walletIndex }
|
|
61
61
|
)).signature;
|
|
@@ -63,7 +63,7 @@ class H {
|
|
|
63
63
|
case "eth_sign": {
|
|
64
64
|
const [, e] = n, c = e.startsWith("0x") ? L(e) : e;
|
|
65
65
|
return (await this.sdk.signMessage(
|
|
66
|
-
|
|
66
|
+
S(this.chainId),
|
|
67
67
|
c,
|
|
68
68
|
{ index: this.walletIndex }
|
|
69
69
|
)).signature;
|
|
@@ -71,11 +71,11 @@ class H {
|
|
|
71
71
|
case "eth_signTypedData":
|
|
72
72
|
case "eth_signTypedData_v3":
|
|
73
73
|
case "eth_signTypedData_v4": {
|
|
74
|
-
const [, e] = n, c = typeof e == "string" ? JSON.parse(e) : e, l = (
|
|
75
|
-
return (u ? await this.sdk.signTypedDataOffchain(c, f) : await this.sdk.signTypedData(
|
|
74
|
+
const [, e] = n, c = typeof e == "string" ? JSON.parse(e) : e, l = (d = c == null ? void 0 : c.domain) == null ? void 0 : d.chainId, u = l == null || l === 0, p = u ? 0 : Number(l), f = { index: this.walletIndex };
|
|
75
|
+
return (u ? await this.sdk.signTypedDataOffchain(c, f) : await this.sdk.signTypedData(S(p), c, f)).signature;
|
|
76
76
|
}
|
|
77
77
|
case "eth_sendTransaction": {
|
|
78
|
-
const [e] = n, c =
|
|
78
|
+
const [e] = n, c = S(this.chainId);
|
|
79
79
|
return (await this.sdk.sendTransaction(c, {
|
|
80
80
|
from: e.from,
|
|
81
81
|
to: e.to,
|
|
@@ -91,12 +91,12 @@ class H {
|
|
|
91
91
|
}
|
|
92
92
|
case "wallet_switchEthereumChain": {
|
|
93
93
|
const [{ chainId: e }] = n, c = parseInt(e, 16);
|
|
94
|
-
return c !== this.chainId && (this.chainId = c, this.emit("chainChanged",
|
|
94
|
+
return c !== this.chainId && (this.chainId = c, this.emit("chainChanged", R(c))), null;
|
|
95
95
|
}
|
|
96
96
|
case "wallet_addEthereumChain":
|
|
97
97
|
return null;
|
|
98
98
|
default:
|
|
99
|
-
return this.sdk.walletRpc(t, n,
|
|
99
|
+
return this.sdk.walletRpc(t, n, S(this.chainId));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
@@ -109,7 +109,7 @@ class H {
|
|
|
109
109
|
}
|
|
110
110
|
emit(t, ...r) {
|
|
111
111
|
var n;
|
|
112
|
-
(n = this.listeners.get(t)) == null || n.forEach((
|
|
112
|
+
(n = this.listeners.get(t)) == null || n.forEach((d) => d(...r));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -122,7 +122,7 @@ class H {
|
|
|
122
122
|
return this.chainId;
|
|
123
123
|
}
|
|
124
124
|
setChainId(t) {
|
|
125
|
-
t !== this.chainId && (this.chainId = t, this.emit("chainChanged",
|
|
125
|
+
t !== this.chainId && (this.chainId = t, this.emit("chainChanged", R(t)));
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* 활성 지갑 인덱스 설정.
|
|
@@ -142,10 +142,10 @@ class H {
|
|
|
142
142
|
function J(s) {
|
|
143
143
|
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
144
144
|
}
|
|
145
|
-
const
|
|
145
|
+
const k = "crossx-wallet-index";
|
|
146
146
|
function Y() {
|
|
147
147
|
try {
|
|
148
|
-
const s = typeof window < "u" ? localStorage.getItem(
|
|
148
|
+
const s = typeof window < "u" ? localStorage.getItem(k) : null;
|
|
149
149
|
return s && Number(s) || 0;
|
|
150
150
|
} catch {
|
|
151
151
|
return 0;
|
|
@@ -153,84 +153,84 @@ function Y() {
|
|
|
153
153
|
}
|
|
154
154
|
function $(s) {
|
|
155
155
|
try {
|
|
156
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(k, String(s));
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
function N() {
|
|
161
161
|
try {
|
|
162
|
-
typeof window < "u" && localStorage.removeItem(
|
|
162
|
+
typeof window < "u" && localStorage.removeItem(k);
|
|
163
163
|
} catch {
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
166
|
+
const b = "crossx-wallet-address";
|
|
167
167
|
function Q() {
|
|
168
168
|
try {
|
|
169
|
-
return typeof window < "u" ? localStorage.getItem(
|
|
169
|
+
return typeof window < "u" ? localStorage.getItem(b) : null;
|
|
170
170
|
} catch {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
function X(s) {
|
|
175
175
|
try {
|
|
176
|
-
typeof window < "u" && localStorage.setItem(
|
|
176
|
+
typeof window < "u" && localStorage.setItem(b, s);
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
function B() {
|
|
181
181
|
try {
|
|
182
|
-
typeof window < "u" && localStorage.removeItem(
|
|
182
|
+
typeof window < "u" && localStorage.removeItem(b);
|
|
183
183
|
} catch {
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
function nt(s) {
|
|
187
|
-
const { defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress:
|
|
187
|
+
const { defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress: d, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l, ...u } = s;
|
|
188
188
|
if (l) {
|
|
189
|
-
const f = u.connectOtherWallets,
|
|
190
|
-
!
|
|
189
|
+
const f = u.connectOtherWallets, y = Array.isArray(f) && f.length > 0, m = u.showConnectOtherWallets === !0;
|
|
190
|
+
!y && !m && (u.showConnectOtherWallets = !0);
|
|
191
191
|
}
|
|
192
192
|
const p = j(u);
|
|
193
|
-
return V({ sdk: p, defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress:
|
|
193
|
+
return V({ sdk: p, defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress: d, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l });
|
|
194
194
|
}
|
|
195
195
|
function V(s) {
|
|
196
196
|
const {
|
|
197
197
|
sdk: t,
|
|
198
198
|
defaultChainId: r = G.CROSS_MAINNET,
|
|
199
199
|
getStoredWalletIndex: n = Y,
|
|
200
|
-
onWalletIndexChanged:
|
|
200
|
+
onWalletIndexChanged: d = $,
|
|
201
201
|
getStoredWalletAddress: e = Q,
|
|
202
202
|
onWalletAddressChanged: c = X,
|
|
203
203
|
clearStoredWalletAddress: l = B,
|
|
204
204
|
openConnectOtherWallet: u
|
|
205
205
|
} = s, p = J(r);
|
|
206
|
-
let f = null,
|
|
206
|
+
let f = null, y = !1, m = null, v = !1, A = !1, E = !1;
|
|
207
207
|
function g() {
|
|
208
|
-
return f || (f = new H(t, p), f._setWalletIndexChangeCallback(
|
|
208
|
+
return f || (f = new H(t, p), f._setWalletIndexChangeCallback(d)), f;
|
|
209
209
|
}
|
|
210
210
|
return z((C) => {
|
|
211
211
|
function T(a) {
|
|
212
|
-
if (
|
|
212
|
+
if (v) return;
|
|
213
213
|
const h = g();
|
|
214
|
-
h.on("accountsChanged", a.onAccountsChanged.bind(a)), h.on("chainChanged", a.onChainChanged.bind(a)), h.on("disconnect", a.onDisconnect.bind(a)),
|
|
214
|
+
h.on("accountsChanged", a.onAccountsChanged.bind(a)), h.on("chainChanged", a.onChainChanged.bind(a)), h.on("disconnect", a.onDisconnect.bind(a)), v = !0;
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
217
|
-
if (!
|
|
216
|
+
async function O() {
|
|
217
|
+
if (!y)
|
|
218
218
|
return m || (m = (async () => {
|
|
219
219
|
const a = n(), h = e() ?? void 0;
|
|
220
220
|
await t.initialize({ preferredWalletIndex: a, preferredWalletAddress: h }), t.on("addressChanged", ({ address: i, index: I }) => {
|
|
221
|
-
if (
|
|
221
|
+
if (A) return;
|
|
222
222
|
const W = g();
|
|
223
223
|
W.setWalletIndex(I), i && (W.notifyAccountsChanged([i]), c(i));
|
|
224
224
|
}), t.on("authChanged", (i) => {
|
|
225
|
-
if (!(
|
|
225
|
+
if (!(A || E))
|
|
226
226
|
if (i.isAuthenticated && i.address) {
|
|
227
227
|
const I = g();
|
|
228
228
|
I.notifyAccountsChanged([i.address]), C.emitter.emit("connect", {
|
|
229
229
|
accounts: [i.address],
|
|
230
230
|
chainId: I.getCurrentChainId()
|
|
231
231
|
});
|
|
232
|
-
} else i.isAuthenticated || (g().notifyDisconnect(), N(), l(),
|
|
233
|
-
}), u && t.on("connectExternalWallet", u),
|
|
232
|
+
} else i.isAuthenticated || (g().notifyDisconnect(), N(), l(), d(0), C.emitter.emit("disconnect"));
|
|
233
|
+
}), u && t.on("connectExternalWallet", u), y = !0;
|
|
234
234
|
})().finally(() => {
|
|
235
235
|
m = null;
|
|
236
236
|
}), m);
|
|
@@ -240,49 +240,55 @@ function V(s) {
|
|
|
240
240
|
name: "CROSSx Wallet",
|
|
241
241
|
type: "crossx",
|
|
242
242
|
async setup() {
|
|
243
|
-
await
|
|
243
|
+
await O(), T(this);
|
|
244
244
|
},
|
|
245
245
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
246
246
|
async connect({ chainId: a, isReconnecting: h } = {}) {
|
|
247
|
-
await
|
|
247
|
+
await O(), T(this);
|
|
248
248
|
const i = g(), I = a ?? p;
|
|
249
|
-
|
|
249
|
+
A = !0;
|
|
250
250
|
try {
|
|
251
|
-
if (
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
return i.setWalletIndex(
|
|
255
|
-
accounts: [
|
|
251
|
+
if (t.isAuthenticated()) {
|
|
252
|
+
const o = await t.getAddress();
|
|
253
|
+
if (o)
|
|
254
|
+
return i.setWalletIndex(o.index), i.notifyAccountsChanged([o.address]), {
|
|
255
|
+
accounts: [o.address],
|
|
256
256
|
chainId: I
|
|
257
257
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
258
|
};
|
|
259
|
+
if (h)
|
|
260
|
+
throw new Error(
|
|
261
|
+
"CROSSx reconnect: authenticated session has no active wallet address"
|
|
262
|
+
);
|
|
259
263
|
await t.signOut().catch(() => {
|
|
260
264
|
}), i.notifyDisconnect();
|
|
261
265
|
}
|
|
266
|
+
if (h)
|
|
267
|
+
throw new Error("CROSSx reconnect: no authenticated session to restore");
|
|
262
268
|
const W = e();
|
|
263
|
-
let
|
|
269
|
+
let x;
|
|
264
270
|
try {
|
|
265
|
-
|
|
271
|
+
x = await t.signInWithCreate({
|
|
266
272
|
preferredWalletAddress: W ?? void 0
|
|
267
273
|
});
|
|
268
|
-
} catch (
|
|
269
|
-
throw
|
|
274
|
+
} catch (o) {
|
|
275
|
+
throw o instanceof q && o.code === U.EXTERNAL_WALLET_REQUESTED ? (i.notifyDisconnect(), new F(o)) : (t.isAuthenticated() || (i.notifyDisconnect(), C.emitter.emit("disconnect")), o);
|
|
270
276
|
}
|
|
271
|
-
if (!
|
|
272
|
-
throw new Error(
|
|
273
|
-
const w =
|
|
277
|
+
if (!x.success)
|
|
278
|
+
throw new Error(x.error ?? "CROSSx sign-in failed");
|
|
279
|
+
const w = x.address, P = x.addresses.map((o) => o.address).filter((o) => !w || o.toLowerCase() !== w.toLowerCase()), _ = w ? [w, ...P] : P;
|
|
274
280
|
if (_.length === 0)
|
|
275
281
|
throw new Error("No address found after sign-in");
|
|
276
|
-
const
|
|
277
|
-
(
|
|
278
|
-
), M = (
|
|
282
|
+
const D = x.addresses.find(
|
|
283
|
+
(o) => w && o.address.toLowerCase() === w.toLowerCase()
|
|
284
|
+
), M = (D == null ? void 0 : D.index) ?? 0;
|
|
279
285
|
return i.setWalletIndex(M), i.notifyAccountsChanged(_), w && c(w), {
|
|
280
286
|
accounts: _,
|
|
281
287
|
chainId: I
|
|
282
288
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
289
|
};
|
|
284
290
|
} finally {
|
|
285
|
-
|
|
291
|
+
A = !1;
|
|
286
292
|
}
|
|
287
293
|
},
|
|
288
294
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
@@ -290,7 +296,7 @@ function V(s) {
|
|
|
290
296
|
E = !0;
|
|
291
297
|
try {
|
|
292
298
|
const a = g();
|
|
293
|
-
await t.signOut(), a.notifyDisconnect(), N(), l(),
|
|
299
|
+
await t.signOut(), a.notifyDisconnect(), N(), l(), d(0), C.emitter.emit("disconnect");
|
|
294
300
|
} finally {
|
|
295
301
|
E = !1;
|
|
296
302
|
}
|
|
@@ -312,7 +318,7 @@ function V(s) {
|
|
|
312
318
|
},
|
|
313
319
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
314
320
|
async isAuthorized() {
|
|
315
|
-
return await
|
|
321
|
+
return await O(), t.isAuthenticated();
|
|
316
322
|
},
|
|
317
323
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
318
324
|
async switchChain({ chainId: a }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.3.0-beta.
|
|
3
|
+
"version": "2.3.0-beta.3",
|
|
4
4
|
"description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@nexus-cross/crossx-sdk-core": "^2.3.0-beta.
|
|
21
|
+
"@nexus-cross/crossx-sdk-core": "^2.3.0-beta.3"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|