@nexus-cross/crossx-sdk-wagmi 2.3.8 → 2.3.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +89 -81
- 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,8GA+TpE"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("wagmi"),j=require("viem"),x=require("@nexus-cross/crossx-sdk-core");function F(r){return parseInt(r.split(":")[1]??"1",10)}function A(r){return`eip155:${r}`}function v(r){return"0x"+r.toString(16)}function L(r){const e=r.startsWith("0x")?r.slice(2):r,a=new Uint8Array(e.length/2);for(let n=0;n<a.length;n++)a[n]=parseInt(e.substring(n*2,n*2+2),16);return new TextDecoder().decode(a)}class G{constructor(e,a=x.ChainId.ONE_MAINNET){this.sdk=e,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof a=="number"?a:F(a),this.sdk.on("addressChanged",({address:n,index:d})=>{this.setWalletIndex(d),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:a}){try{return await this._handleRequest(e,a)}catch(n){throw n instanceof x.CROSSxError&&n.code===x.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(e,a){var d;const n=a??[];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 v(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=n,c=t.startsWith("0x")?L(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")?L(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",v(c))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,n,A(this.chainId))}}on(e,a){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(a),this}removeListener(e,a){var n;return(n=this.listeners.get(e))==null||n.delete(a),this}emit(e,...a){var n;(n=this.listeners.get(e))==null||n.forEach(d=>d(...a))}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",v(e)))}setWalletIndex(e){var a;this.walletIndex=e,(a=this.walletIndexChangeCallback)==null||a.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function K(r){return typeof r=="number"?r:parseInt(r.split(":")[1]??"1",10)}const b="crossx-wallet-index";function H(){try{const r=typeof window<"u"?localStorage.getItem(b):null;return r&&Number(r)||0}catch{return 0}}function J(r){try{typeof window<"u"&&localStorage.setItem(b,String(r))}catch{}}function q(){try{typeof window<"u"&&localStorage.removeItem(b)}catch{}}const k="crossx-wallet-address";function Y(){try{return typeof window<"u"?localStorage.getItem(k):null}catch{return null}}function $(r){try{typeof window<"u"&&localStorage.setItem(k,r)}catch{}}function B(){try{typeof window<"u"&&localStorage.removeItem(k)}catch{}}function Q(r){const{defaultChainId:e,getStoredWalletIndex:a,onWalletIndexChanged:n,getStoredWalletAddress:d,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:l,...u}=r;if(l){const f=u.connectOtherWallets,S=Array.isArray(f)&&f.length>0,y=u.showConnectOtherWallets===!0;!S&&!y&&(u.showConnectOtherWallets=!0)}const m=x.createCROSSxSDK(u);return M({sdk:m,defaultChainId:e,getStoredWalletIndex:a,onWalletIndexChanged:n,getStoredWalletAddress:d,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:l})}function M(r){const{sdk:e,defaultChainId:a=x.ChainId.ONE_MAINNET,getStoredWalletIndex:n=H,onWalletIndexChanged:d=J,getStoredWalletAddress:t=Y,onWalletAddressChanged:c=$,clearStoredWalletAddress:l=B,openConnectOtherWallet:u}=r,m=K(a);let f=null,S=!1,y=null,T=!1,E=!1,O=!1;function g(){return f||(f=new G(e,m),f._setWalletIndexChangeCallback(d)),f}return z.createConnector(C=>{function P(s){if(T)return;const h=g();h.on("accountsChanged",s.onAccountsChanged.bind(s)),h.on("chainChanged",s.onChainChanged.bind(s)),h.on("disconnect",s.onDisconnect.bind(s)),T=!0}async function _(){if(!S)return y||(y=(async()=>{const s=n(),h=t()??void 0;await e.initialize({preferredWalletIndex:s,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(()=>{y=null}),y)}return{id:"crossx",name:x.WALLET_BRAND_NAME,type:"crossx",async setup(){await _(),P(this)},async connect({chainId:s,isReconnecting:h}={}){await _(),P(this);const i=g(),I=s??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 x.CROSSxError&&o.code===x.ErrorCode.EXTERNAL_WALLET_REQUESTED?(i.notifyDisconnect(),new j.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,N=p.addresses.map(o=>o.address).filter(o=>!w||o.toLowerCase()!==w.toLowerCase()),D=w?[w,...N]:N;if(D.length===0)throw new Error("No address found after sign-in");const R=p.addresses.find(o=>w&&o.address.toLowerCase()===w.toLowerCase()),U=(R==null?void 0:R.index)??0;return i.setWalletIndex(U),i.notifyAccountsChanged(D),w&&c(w),{accounts:D,chainId:I}}finally{E=!1}},async disconnect(){O=!0;try{const s=g();await e.signOut(),s.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:s}={}){return g()},async isAuthorized(){try{await _()}catch(s){return console.warn("[CROSSx] isAuthorized: SDK 초기화 실패 — 미인증으로 처리",s),!1}return e.isAuthenticated()},async switchChain({chainId:s}){g().setChainId(s),C.emitter.emit("change",{chainId:s});const i=C.chains.find(I=>I.id===s);if(!i)throw new Error(`Chain ${s} is not configured`);return i},onAccountsChanged(s){s.length===0?C.emitter.emit("disconnect"):C.emitter.emit("change",{accounts:s})},onChainChanged(s){C.emitter.emit("change",{chainId:Number(s)})},onDisconnect(){C.emitter.emit("disconnect")}}})}exports.CROSSxEIP1193Provider=G;exports.createCROSSxConnector=M;exports.crossxConnector=Q;
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { createConnector as z } from "wagmi";
|
|
2
2
|
import { UserRejectedRequestError as F } from "viem";
|
|
3
|
-
import { ChainId as G, CROSSxError as q, ErrorCode as M, WALLET_BRAND_NAME as
|
|
4
|
-
function H(
|
|
5
|
-
return parseInt(
|
|
3
|
+
import { ChainId as G, CROSSxError as q, ErrorCode as M, WALLET_BRAND_NAME as K, createCROSSxSDK as j } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function H(r) {
|
|
5
|
+
return parseInt(r.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
|
-
function A(
|
|
8
|
-
return `eip155:${
|
|
7
|
+
function A(r) {
|
|
8
|
+
return `eip155:${r}`;
|
|
9
9
|
}
|
|
10
|
-
function k(
|
|
11
|
-
return "0x" +
|
|
10
|
+
function k(r) {
|
|
11
|
+
return "0x" + r.toString(16);
|
|
12
12
|
}
|
|
13
|
-
function P(
|
|
14
|
-
const t =
|
|
15
|
-
for (let n = 0; n <
|
|
16
|
-
|
|
17
|
-
return new TextDecoder().decode(
|
|
13
|
+
function P(r) {
|
|
14
|
+
const t = r.startsWith("0x") ? r.slice(2) : r, a = new Uint8Array(t.length / 2);
|
|
15
|
+
for (let n = 0; n < a.length; n++)
|
|
16
|
+
a[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
|
+
return new TextDecoder().decode(a);
|
|
18
18
|
}
|
|
19
19
|
class J {
|
|
20
|
-
constructor(t,
|
|
21
|
-
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof
|
|
20
|
+
constructor(t, a = G.ONE_MAINNET) {
|
|
21
|
+
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 : H(a), this.sdk.on("addressChanged", ({ address: n, index: d }) => {
|
|
22
22
|
this.setWalletIndex(d), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -27,9 +27,9 @@ class J {
|
|
|
27
27
|
this.walletIndexChangeCallback = t;
|
|
28
28
|
}
|
|
29
29
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
30
|
-
async request({ method: t, params:
|
|
30
|
+
async request({ method: t, params: a }) {
|
|
31
31
|
try {
|
|
32
|
-
return await this._handleRequest(t,
|
|
32
|
+
return await this._handleRequest(t, a);
|
|
33
33
|
} catch (n) {
|
|
34
34
|
throw n instanceof q && n.code === M.USER_REJECTED ? Object.assign(
|
|
35
35
|
new Error("User rejected the request"),
|
|
@@ -37,9 +37,9 @@ class J {
|
|
|
37
37
|
) : n;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
async _handleRequest(t,
|
|
40
|
+
async _handleRequest(t, a) {
|
|
41
41
|
var d;
|
|
42
|
-
const n =
|
|
42
|
+
const n = a ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
45
45
|
case "eth_accounts": {
|
|
@@ -100,16 +100,16 @@ class J {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
103
|
-
on(t,
|
|
104
|
-
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(
|
|
103
|
+
on(t, a) {
|
|
104
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(a), this;
|
|
105
105
|
}
|
|
106
|
-
removeListener(t,
|
|
106
|
+
removeListener(t, a) {
|
|
107
107
|
var n;
|
|
108
|
-
return (n = this.listeners.get(t)) == null || n.delete(
|
|
108
|
+
return (n = this.listeners.get(t)) == null || n.delete(a), this;
|
|
109
109
|
}
|
|
110
|
-
emit(t, ...
|
|
110
|
+
emit(t, ...a) {
|
|
111
111
|
var n;
|
|
112
|
-
(n = this.listeners.get(t)) == null || n.forEach((d) => d(...
|
|
112
|
+
(n = this.listeners.get(t)) == null || n.forEach((d) => d(...a));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -129,8 +129,8 @@ class J {
|
|
|
129
129
|
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
130
130
|
*/
|
|
131
131
|
setWalletIndex(t) {
|
|
132
|
-
var
|
|
133
|
-
this.walletIndex = t, (
|
|
132
|
+
var a;
|
|
133
|
+
this.walletIndex = t, (a = this.walletIndexChangeCallback) == null || a.call(this, t);
|
|
134
134
|
}
|
|
135
135
|
getWalletIndex() {
|
|
136
136
|
return this.walletIndex;
|
|
@@ -139,97 +139,97 @@ class J {
|
|
|
139
139
|
return [...this.currentAccounts];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function Y(
|
|
143
|
-
return typeof
|
|
142
|
+
function Y(r) {
|
|
143
|
+
return typeof r == "number" ? r : parseInt(r.split(":")[1] ?? "1", 10);
|
|
144
144
|
}
|
|
145
|
-
const
|
|
145
|
+
const R = "crossx-wallet-index";
|
|
146
146
|
function $() {
|
|
147
147
|
try {
|
|
148
|
-
const
|
|
149
|
-
return
|
|
148
|
+
const r = typeof window < "u" ? localStorage.getItem(R) : null;
|
|
149
|
+
return r && Number(r) || 0;
|
|
150
150
|
} catch {
|
|
151
151
|
return 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function B(
|
|
154
|
+
function B(r) {
|
|
155
155
|
try {
|
|
156
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(R, String(r));
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
function L() {
|
|
161
161
|
try {
|
|
162
|
-
typeof window < "u" && localStorage.removeItem(
|
|
162
|
+
typeof window < "u" && localStorage.removeItem(R);
|
|
163
163
|
} catch {
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
166
|
+
const T = "crossx-wallet-address";
|
|
167
167
|
function Q() {
|
|
168
168
|
try {
|
|
169
|
-
return typeof window < "u" ? localStorage.getItem(
|
|
169
|
+
return typeof window < "u" ? localStorage.getItem(T) : null;
|
|
170
170
|
} catch {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function X(
|
|
174
|
+
function X(r) {
|
|
175
175
|
try {
|
|
176
|
-
typeof window < "u" && localStorage.setItem(
|
|
176
|
+
typeof window < "u" && localStorage.setItem(T, r);
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
function V() {
|
|
181
181
|
try {
|
|
182
|
-
typeof window < "u" && localStorage.removeItem(
|
|
182
|
+
typeof window < "u" && localStorage.removeItem(T);
|
|
183
183
|
} catch {
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
function st(
|
|
187
|
-
const { defaultChainId: t, getStoredWalletIndex:
|
|
186
|
+
function st(r) {
|
|
187
|
+
const { defaultChainId: t, getStoredWalletIndex: a, onWalletIndexChanged: n, getStoredWalletAddress: d, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l, ...u } = r;
|
|
188
188
|
if (l) {
|
|
189
189
|
const f = u.connectOtherWallets, x = Array.isArray(f) && f.length > 0, m = u.showConnectOtherWallets === !0;
|
|
190
190
|
!x && !m && (u.showConnectOtherWallets = !0);
|
|
191
191
|
}
|
|
192
|
-
const p =
|
|
193
|
-
return Z({ sdk: p, defaultChainId: t, getStoredWalletIndex:
|
|
192
|
+
const p = j(u);
|
|
193
|
+
return Z({ sdk: p, defaultChainId: t, getStoredWalletIndex: a, onWalletIndexChanged: n, getStoredWalletAddress: d, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l });
|
|
194
194
|
}
|
|
195
|
-
function Z(
|
|
195
|
+
function Z(r) {
|
|
196
196
|
const {
|
|
197
197
|
sdk: t,
|
|
198
|
-
defaultChainId:
|
|
198
|
+
defaultChainId: a = G.ONE_MAINNET,
|
|
199
199
|
getStoredWalletIndex: n = $,
|
|
200
200
|
onWalletIndexChanged: d = B,
|
|
201
201
|
getStoredWalletAddress: e = Q,
|
|
202
202
|
onWalletAddressChanged: c = X,
|
|
203
203
|
clearStoredWalletAddress: l = V,
|
|
204
204
|
openConnectOtherWallet: u
|
|
205
|
-
} =
|
|
206
|
-
let f = null, x = !1, m = null,
|
|
205
|
+
} = r, p = Y(a);
|
|
206
|
+
let f = null, x = !1, m = null, b = !1, S = !1, W = !1;
|
|
207
207
|
function g() {
|
|
208
208
|
return f || (f = new J(t, p), f._setWalletIndexChangeCallback(d)), f;
|
|
209
209
|
}
|
|
210
|
-
return z((
|
|
211
|
-
function
|
|
212
|
-
if (
|
|
210
|
+
return z((C) => {
|
|
211
|
+
function v(s) {
|
|
212
|
+
if (b) return;
|
|
213
213
|
const h = g();
|
|
214
|
-
h.on("accountsChanged",
|
|
214
|
+
h.on("accountsChanged", s.onAccountsChanged.bind(s)), h.on("chainChanged", s.onChainChanged.bind(s)), h.on("disconnect", s.onDisconnect.bind(s)), b = !0;
|
|
215
215
|
}
|
|
216
216
|
async function _() {
|
|
217
217
|
if (!x)
|
|
218
218
|
return m || (m = (async () => {
|
|
219
|
-
const
|
|
220
|
-
await t.initialize({ preferredWalletIndex:
|
|
219
|
+
const s = n(), h = e() ?? void 0;
|
|
220
|
+
await t.initialize({ preferredWalletIndex: s, preferredWalletAddress: h }), t.on("addressChanged", ({ address: i, index: I }) => {
|
|
221
221
|
if (S) return;
|
|
222
222
|
const E = g();
|
|
223
|
-
E.setWalletIndex(
|
|
223
|
+
E.setWalletIndex(I), i && (E.notifyAccountsChanged([i]), c(i));
|
|
224
224
|
}), t.on("authChanged", (i) => {
|
|
225
225
|
if (!(S || W))
|
|
226
226
|
if (i.isAuthenticated && i.address) {
|
|
227
|
-
const
|
|
228
|
-
|
|
227
|
+
const I = g();
|
|
228
|
+
I.notifyAccountsChanged([i.address]), C.emitter.emit("connect", {
|
|
229
229
|
accounts: [i.address],
|
|
230
|
-
chainId:
|
|
230
|
+
chainId: I.getCurrentChainId()
|
|
231
231
|
});
|
|
232
|
-
} else i.isAuthenticated || (g().notifyDisconnect(), L(), l(), d(0),
|
|
232
|
+
} else i.isAuthenticated || (g().notifyDisconnect(), L(), l(), d(0), C.emitter.emit("disconnect"));
|
|
233
233
|
}), u && t.on("connectExternalWallet", u), x = !0;
|
|
234
234
|
})().finally(() => {
|
|
235
235
|
m = null;
|
|
@@ -237,15 +237,15 @@ function Z(s) {
|
|
|
237
237
|
}
|
|
238
238
|
return {
|
|
239
239
|
id: "crossx",
|
|
240
|
-
name:
|
|
240
|
+
name: K,
|
|
241
241
|
type: "crossx",
|
|
242
242
|
async setup() {
|
|
243
|
-
await _(),
|
|
243
|
+
await _(), v(this);
|
|
244
244
|
},
|
|
245
245
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
246
|
-
async connect({ chainId:
|
|
247
|
-
await _(),
|
|
248
|
-
const i = g(),
|
|
246
|
+
async connect({ chainId: s, isReconnecting: h } = {}) {
|
|
247
|
+
await _(), v(this);
|
|
248
|
+
const i = g(), I = s ?? p;
|
|
249
249
|
S = !0;
|
|
250
250
|
try {
|
|
251
251
|
if (t.isAuthenticated()) {
|
|
@@ -253,7 +253,7 @@ function Z(s) {
|
|
|
253
253
|
if (o)
|
|
254
254
|
return i.setWalletIndex(o.index), i.notifyAccountsChanged([o.address]), {
|
|
255
255
|
accounts: [o.address],
|
|
256
|
-
chainId:
|
|
256
|
+
chainId: I
|
|
257
257
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
258
|
};
|
|
259
259
|
if (h)
|
|
@@ -272,7 +272,7 @@ function Z(s) {
|
|
|
272
272
|
preferredWalletAddress: E ?? void 0
|
|
273
273
|
});
|
|
274
274
|
} catch (o) {
|
|
275
|
-
throw o instanceof q && o.code === M.EXTERNAL_WALLET_REQUESTED ? (i.notifyDisconnect(), new F(o)) : (t.isAuthenticated() || (i.notifyDisconnect(),
|
|
275
|
+
throw o instanceof q && o.code === M.EXTERNAL_WALLET_REQUESTED ? (i.notifyDisconnect(), new F(o)) : (t.isAuthenticated() || (i.notifyDisconnect(), C.emitter.emit("disconnect")), o);
|
|
276
276
|
}
|
|
277
277
|
if (!y.success)
|
|
278
278
|
throw new Error(y.error ?? "CROSSx sign-in failed");
|
|
@@ -284,7 +284,7 @@ function Z(s) {
|
|
|
284
284
|
), U = (D == null ? void 0 : D.index) ?? 0;
|
|
285
285
|
return i.setWalletIndex(U), i.notifyAccountsChanged(O), w && c(w), {
|
|
286
286
|
accounts: O,
|
|
287
|
-
chainId:
|
|
287
|
+
chainId: I
|
|
288
288
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
289
289
|
};
|
|
290
290
|
} finally {
|
|
@@ -295,8 +295,8 @@ function Z(s) {
|
|
|
295
295
|
async disconnect() {
|
|
296
296
|
W = !0;
|
|
297
297
|
try {
|
|
298
|
-
const
|
|
299
|
-
await t.signOut(),
|
|
298
|
+
const s = g();
|
|
299
|
+
await t.signOut(), s.notifyDisconnect(), L(), l(), d(0), C.emitter.emit("disconnect");
|
|
300
300
|
} finally {
|
|
301
301
|
W = !1;
|
|
302
302
|
}
|
|
@@ -313,34 +313,42 @@ function Z(s) {
|
|
|
313
313
|
return g().getCurrentChainId();
|
|
314
314
|
},
|
|
315
315
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
316
|
-
async getProvider({ chainId:
|
|
316
|
+
async getProvider({ chainId: s } = {}) {
|
|
317
317
|
return g();
|
|
318
318
|
},
|
|
319
319
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
320
320
|
async isAuthorized() {
|
|
321
|
-
|
|
321
|
+
try {
|
|
322
|
+
await _();
|
|
323
|
+
} catch (s) {
|
|
324
|
+
return console.warn(
|
|
325
|
+
"[CROSSx] isAuthorized: SDK 초기화 실패 — 미인증으로 처리",
|
|
326
|
+
s
|
|
327
|
+
), !1;
|
|
328
|
+
}
|
|
329
|
+
return t.isAuthenticated();
|
|
322
330
|
},
|
|
323
331
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
324
|
-
async switchChain({ chainId:
|
|
325
|
-
g().setChainId(
|
|
326
|
-
const i =
|
|
332
|
+
async switchChain({ chainId: s }) {
|
|
333
|
+
g().setChainId(s), C.emitter.emit("change", { chainId: s });
|
|
334
|
+
const i = C.chains.find((I) => I.id === s);
|
|
327
335
|
if (!i)
|
|
328
|
-
throw new Error(`Chain ${
|
|
336
|
+
throw new Error(`Chain ${s} is not configured`);
|
|
329
337
|
return i;
|
|
330
338
|
},
|
|
331
339
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
332
|
-
onAccountsChanged(
|
|
333
|
-
|
|
334
|
-
accounts:
|
|
340
|
+
onAccountsChanged(s) {
|
|
341
|
+
s.length === 0 ? C.emitter.emit("disconnect") : C.emitter.emit("change", {
|
|
342
|
+
accounts: s
|
|
335
343
|
});
|
|
336
344
|
},
|
|
337
|
-
onChainChanged(
|
|
338
|
-
|
|
339
|
-
chainId: Number(
|
|
345
|
+
onChainChanged(s) {
|
|
346
|
+
C.emitter.emit("change", {
|
|
347
|
+
chainId: Number(s)
|
|
340
348
|
});
|
|
341
349
|
},
|
|
342
350
|
onDisconnect() {
|
|
343
|
-
|
|
351
|
+
C.emitter.emit("disconnect");
|
|
344
352
|
}
|
|
345
353
|
};
|
|
346
354
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.9-beta.1",
|
|
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.
|
|
21
|
+
"@nexus-cross/crossx-sdk-core": "^2.3.9-beta.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|