@nexus-cross/crossx-sdk-wagmi 2.1.2 → 2.2.0-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 +189 -177
- 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;;;;;;;;;;;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;;;;;;;;;;;;;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;;;;;;;;;;;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;;;;;;;;;;;;;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,8GAsRpE"}
|
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 U=require("wagmi"),j=require("viem"),m=require("@nexus-cross/crossx-sdk-core");function z(s){return parseInt(s.split(":")[1]??"1",10)}function S(s){return`eip155:${s}`}function R(s){return"0x"+s.toString(16)}function P(s){const t=s.startsWith("0x")?s.slice(2):s,r=new Uint8Array(t.length/2);for(let n=0;n<r.length;n++)r[n]=parseInt(t.substring(n*2,n*2+2),16);return new TextDecoder().decode(r)}class N{constructor(t,r=m.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof r=="number"?r:z(r),this.sdk.on("addressChanged",({address:n,index:h})=>{this.setWalletIndex(h),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(t){this.walletIndexChangeCallback=t}async request({method:t,params:r}){try{return await this._handleRequest(t,r)}catch(n){throw n instanceof m.CROSSxError&&n.code===m.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(t,r){var h;const n=r??[];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 R(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n,c=e.startsWith("0x")?P(e):e;return(await this.sdk.signMessage(S(this.chainId),c,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n,c=e.startsWith("0x")?P(e):e;return(await this.sdk.signMessage(S(this.chainId),c,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=n,c=typeof e=="string"?JSON.parse(e):e,o=(h=c==null?void 0:c.domain)==null?void 0:h.chainId,x=o==null||o===0,C=x?0:Number(o),y={index:this.walletIndex};return(x?await this.sdk.signTypedDataOffchain(c,y):await this.sdk.signTypedData(S(C),c,y)).signature}case"eth_sendTransaction":{const[e]=n,c=S(this.chainId);return(await this.sdk.sendTransaction(c,{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,c=parseInt(e,16);return c!==this.chainId&&(this.chainId=c,this.emit("chainChanged",R(c))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,S(this.chainId))}}on(t,r){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(r),this}removeListener(t,r){var n;return(n=this.listeners.get(t))==null||n.delete(r),this}emit(t,...r){var n;(n=this.listeners.get(t))==null||n.forEach(h=>h(...r))}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",R(t)))}setWalletIndex(t){var r;this.walletIndex=t,(r=this.walletIndexChangeCallback)==null||r.call(this,t)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function F(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const b="crossx-wallet-index";function K(){try{const s=typeof window<"u"?localStorage.getItem(b):null;return s&&Number(s)||0}catch{return 0}}function H(s){try{typeof window<"u"&&localStorage.setItem(b,String(s))}catch{}}function L(){try{typeof window<"u"&&localStorage.removeItem(b)}catch{}}const q="crossx-wallet-address";function J(){try{return typeof window<"u"?localStorage.getItem(q):null}catch{return null}}function Y(s){try{typeof window<"u"&&localStorage.setItem(q,s)}catch{}}function $(s){const{defaultChainId:t,getStoredWalletIndex:r,onWalletIndexChanged:n,getStoredWalletAddress:h,onWalletAddressChanged:e,openConnectOtherWallet:c,...o}=s;if(c){const C=o.connectOtherWallets,y=Array.isArray(C)&&C.length>0,I=o.showConnectOtherWallets===!0;!y&&!I&&(o.showConnectOtherWallets=!0)}const x=m.createCROSSxSDK(o);return G({sdk:x,defaultChainId:t,getStoredWalletIndex:r,onWalletIndexChanged:n,getStoredWalletAddress:h,onWalletAddressChanged:e,openConnectOtherWallet:c})}function G(s){const{sdk:t,defaultChainId:r=m.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=K,onWalletIndexChanged:h=H,getStoredWalletAddress:e=J,onWalletAddressChanged:c=Y,openConnectOtherWallet:o}=s,x=F(r);let C=null,y=!1,I=null,k=!1,A=!1,W=!1;function u(){return C||(C=new N(t,x),C._setWalletIndexChangeCallback(h)),C}return U.createConnector(f=>{function D(i){if(k)return;const l=u();l.on("accountsChanged",i.onAccountsChanged.bind(i)),l.on("chainChanged",i.onChainChanged.bind(i)),l.on("disconnect",i.onDisconnect.bind(i)),k=!0}async function v(){if(!y)return I||(I=(async()=>{const i=n(),l=e()??void 0;await t.initialize({preferredWalletIndex:i,preferredWalletAddress:l}),t.on("addressChanged",({address:a,index:g})=>{if(A)return;const E=u();E.setWalletIndex(g),a&&(E.notifyAccountsChanged([a]),c(a))}),t.on("authChanged",a=>{if(!(A||W))if(a.isAuthenticated&&a.address){const g=u();g.notifyAccountsChanged([a.address]),f.emitter.emit("connect",{accounts:[a.address],chainId:g.getCurrentChainId()})}else a.isAuthenticated||(u().notifyDisconnect(),L(),h(0),f.emitter.emit("disconnect"))}),o&&t.on("connectExternalWallet",o),y=!0})().finally(()=>{I=null}),I)}return{id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){await v(),D(this)},async connect({chainId:i,isReconnecting:l}={}){await v(),D(this);const a=u(),g=i??x;A=!0;try{if((l||t.isAuthenticated())&&t.isAuthenticated()){const d=await t.getAddress();if(d)return a.setWalletIndex(d.index),a.notifyAccountsChanged([d.address]),{accounts:[d.address],chainId:g};await t.signOut().catch(()=>{}),a.notifyDisconnect()}const E=e();let p;try{p=await t.signInWithCreate({preferredWalletAddress:E??void 0})}catch(d){throw d instanceof m.CROSSxError&&d.code===m.ErrorCode.EXTERNAL_WALLET_REQUESTED?(a.notifyDisconnect(),new j.UserRejectedRequestError(d)):(t.isAuthenticated()||(a.notifyDisconnect(),f.emitter.emit("disconnect")),d)}if(!p.success)throw new Error(p.error??"CROSSx sign-in failed");const w=p.address,T=p.addresses.map(d=>d.address).filter(d=>!w||d.toLowerCase()!==w.toLowerCase()),O=w?[w,...T]:T;if(O.length===0)throw new Error("No address found after sign-in");const _=p.addresses.find(d=>w&&d.address.toLowerCase()===w.toLowerCase()),M=(_==null?void 0:_.index)??0;return a.setWalletIndex(M),a.notifyAccountsChanged(O),w&&c(w),{accounts:O,chainId:g}}finally{A=!1}},async disconnect(){W=!0;try{const i=u();await t.signOut(),i.notifyDisconnect(),L(),h(0),f.emitter.emit("disconnect")}finally{W=!1}},async getAccounts(){const l=u().getCurrentAccounts();if(l.length>0)return l;const a=await t.getAddress();return a?[a.address]:[]},async getChainId(){return u().getCurrentChainId()},async getProvider({chainId:i}={}){return u()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:i}){u().setChainId(i),f.emitter.emit("change",{chainId:i});const a=f.chains.find(g=>g.id===i);if(!a)throw new Error(`Chain ${i} is not configured`);return a},onAccountsChanged(i){i.length===0?f.emitter.emit("disconnect"):f.emitter.emit("change",{accounts:i})},onChainChanged(i){f.emitter.emit("change",{chainId:Number(i)})},onDisconnect(){f.emitter.emit("disconnect")}}})}exports.CROSSxEIP1193Provider=N;exports.createCROSSxConnector=G;exports.crossxConnector=$;
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
3
|
-
import { ChainId as
|
|
4
|
-
function
|
|
1
|
+
import { createConnector as M } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as z } from "viem";
|
|
3
|
+
import { ChainId as L, CROSSxError as N, ErrorCode as G, createCROSSxSDK as F } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function j(s) {
|
|
5
5
|
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function x(s) {
|
|
8
8
|
return `eip155:${s}`;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function O(s) {
|
|
11
11
|
return "0x" + s.toString(16);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function v(s) {
|
|
14
14
|
const t = s.startsWith("0x") ? s.slice(2) : s, i = new Uint8Array(t.length / 2);
|
|
15
15
|
for (let n = 0; n < i.length; n++)
|
|
16
16
|
i[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
17
|
return new TextDecoder().decode(i);
|
|
18
18
|
}
|
|
19
|
-
class
|
|
20
|
-
constructor(t, i =
|
|
21
|
-
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof i == "number" ? i :
|
|
22
|
-
this.setWalletIndex(
|
|
19
|
+
class K {
|
|
20
|
+
constructor(t, i = L.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 i == "number" ? i : j(i), this.sdk.on("addressChanged", ({ address: n, index: h }) => {
|
|
22
|
+
this.setWalletIndex(h), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -31,14 +31,14 @@ class M {
|
|
|
31
31
|
try {
|
|
32
32
|
return await this._handleRequest(t, i);
|
|
33
33
|
} catch (n) {
|
|
34
|
-
throw n instanceof
|
|
34
|
+
throw n instanceof N && n.code === G.USER_REJECTED ? Object.assign(
|
|
35
35
|
new Error("User rejected the request"),
|
|
36
36
|
{ code: 4001, data: n.details }
|
|
37
37
|
) : n;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
async _handleRequest(t, i) {
|
|
41
|
-
var
|
|
41
|
+
var h;
|
|
42
42
|
const n = i ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
@@ -49,34 +49,34 @@ class M {
|
|
|
49
49
|
return e ? [e.address] : [];
|
|
50
50
|
}
|
|
51
51
|
case "eth_chainId":
|
|
52
|
-
return
|
|
52
|
+
return O(this.chainId);
|
|
53
53
|
case "net_version":
|
|
54
54
|
return String(this.chainId);
|
|
55
55
|
case "personal_sign": {
|
|
56
|
-
const [e] = n,
|
|
56
|
+
const [e] = n, c = e.startsWith("0x") ? v(e) : e;
|
|
57
57
|
return (await this.sdk.signMessage(
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
x(this.chainId),
|
|
59
|
+
c,
|
|
60
60
|
{ index: this.walletIndex }
|
|
61
61
|
)).signature;
|
|
62
62
|
}
|
|
63
63
|
case "eth_sign": {
|
|
64
|
-
const [, e] = n,
|
|
64
|
+
const [, e] = n, c = e.startsWith("0x") ? v(e) : e;
|
|
65
65
|
return (await this.sdk.signMessage(
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
x(this.chainId),
|
|
67
|
+
c,
|
|
68
68
|
{ index: this.walletIndex }
|
|
69
69
|
)).signature;
|
|
70
70
|
}
|
|
71
71
|
case "eth_signTypedData":
|
|
72
72
|
case "eth_signTypedData_v3":
|
|
73
73
|
case "eth_signTypedData_v4": {
|
|
74
|
-
const [, e] = n,
|
|
75
|
-
return (
|
|
74
|
+
const [, e] = n, c = typeof e == "string" ? JSON.parse(e) : e, o = (h = c == null ? void 0 : c.domain) == null ? void 0 : h.chainId, m = o == null || o === 0, C = m ? 0 : Number(o), p = { index: this.walletIndex };
|
|
75
|
+
return (m ? await this.sdk.signTypedDataOffchain(c, p) : await this.sdk.signTypedData(x(C), c, p)).signature;
|
|
76
76
|
}
|
|
77
77
|
case "eth_sendTransaction": {
|
|
78
|
-
const [e] = n,
|
|
79
|
-
return (await this.sdk.sendTransaction(
|
|
78
|
+
const [e] = n, c = x(this.chainId);
|
|
79
|
+
return (await this.sdk.sendTransaction(c, {
|
|
80
80
|
from: e.from,
|
|
81
81
|
to: e.to,
|
|
82
82
|
value: e.value,
|
|
@@ -90,13 +90,13 @@ class M {
|
|
|
90
90
|
}, { index: this.walletIndex })).txHash;
|
|
91
91
|
}
|
|
92
92
|
case "wallet_switchEthereumChain": {
|
|
93
|
-
const [{ chainId: e }] = n,
|
|
94
|
-
return
|
|
93
|
+
const [{ chainId: e }] = n, c = parseInt(e, 16);
|
|
94
|
+
return c !== this.chainId && (this.chainId = c, this.emit("chainChanged", O(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, x(this.chainId));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
@@ -109,7 +109,7 @@ class M {
|
|
|
109
109
|
}
|
|
110
110
|
emit(t, ...i) {
|
|
111
111
|
var n;
|
|
112
|
-
(n = this.listeners.get(t)) == null || n.forEach((
|
|
112
|
+
(n = this.listeners.get(t)) == null || n.forEach((h) => h(...i));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -122,7 +122,7 @@ class M {
|
|
|
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", O(t)));
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* 활성 지갑 인덱스 설정.
|
|
@@ -139,189 +139,201 @@ class M {
|
|
|
139
139
|
return [...this.currentAccounts];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function H(s) {
|
|
143
143
|
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
144
144
|
}
|
|
145
|
-
const
|
|
146
|
-
function
|
|
145
|
+
const D = "crossx-wallet-index";
|
|
146
|
+
function J() {
|
|
147
147
|
try {
|
|
148
|
-
const s = typeof window < "u" ? localStorage.getItem(
|
|
148
|
+
const s = typeof window < "u" ? localStorage.getItem(D) : null;
|
|
149
149
|
return s && Number(s) || 0;
|
|
150
150
|
} catch {
|
|
151
151
|
return 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Y(s) {
|
|
155
155
|
try {
|
|
156
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(D, String(s));
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function P() {
|
|
161
161
|
try {
|
|
162
|
-
typeof window < "u" && localStorage.removeItem(
|
|
162
|
+
typeof window < "u" && localStorage.removeItem(D);
|
|
163
163
|
} catch {
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const
|
|
167
|
-
function
|
|
166
|
+
const q = "crossx-wallet-address";
|
|
167
|
+
function $() {
|
|
168
168
|
try {
|
|
169
|
-
return typeof window < "u" ? localStorage.getItem(
|
|
169
|
+
return typeof window < "u" ? localStorage.getItem(q) : null;
|
|
170
170
|
} catch {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function Q(s) {
|
|
175
175
|
try {
|
|
176
|
-
typeof window < "u" && localStorage.setItem(
|
|
176
|
+
typeof window < "u" && localStorage.setItem(q, s);
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
function
|
|
181
|
-
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress:
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
!
|
|
180
|
+
function tt(s) {
|
|
181
|
+
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: h, onWalletAddressChanged: e, openConnectOtherWallet: c, ...o } = s;
|
|
182
|
+
if (c) {
|
|
183
|
+
const C = o.connectOtherWallets, p = Array.isArray(C) && C.length > 0, I = o.showConnectOtherWallets === !0;
|
|
184
|
+
!p && !I && (o.showConnectOtherWallets = !0);
|
|
185
185
|
}
|
|
186
|
-
const
|
|
187
|
-
return
|
|
186
|
+
const m = F(o);
|
|
187
|
+
return X({ sdk: m, defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: h, onWalletAddressChanged: e, openConnectOtherWallet: c });
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function X(s) {
|
|
190
190
|
const {
|
|
191
191
|
sdk: t,
|
|
192
|
-
defaultChainId: i =
|
|
193
|
-
getStoredWalletIndex: n =
|
|
194
|
-
onWalletIndexChanged:
|
|
195
|
-
getStoredWalletAddress: e =
|
|
196
|
-
onWalletAddressChanged:
|
|
197
|
-
openConnectOtherWallet:
|
|
198
|
-
} = s,
|
|
199
|
-
let
|
|
192
|
+
defaultChainId: i = L.CROSS_MAINNET,
|
|
193
|
+
getStoredWalletIndex: n = J,
|
|
194
|
+
onWalletIndexChanged: h = Y,
|
|
195
|
+
getStoredWalletAddress: e = $,
|
|
196
|
+
onWalletAddressChanged: c = Q,
|
|
197
|
+
openConnectOtherWallet: o
|
|
198
|
+
} = s, m = H(i);
|
|
199
|
+
let C = null, p = !1, I = null, R = !1, A = !1, W = !1;
|
|
200
200
|
function u() {
|
|
201
|
-
return
|
|
201
|
+
return C || (C = new K(t, m), C._setWalletIndexChangeCallback(h)), C;
|
|
202
202
|
}
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
203
|
+
return M((f) => {
|
|
204
|
+
function k(r) {
|
|
205
|
+
if (R) return;
|
|
206
|
+
const l = u();
|
|
207
|
+
l.on("accountsChanged", r.onAccountsChanged.bind(r)), l.on("chainChanged", r.onChainChanged.bind(r)), l.on("disconnect", r.onDisconnect.bind(r)), R = !0;
|
|
208
|
+
}
|
|
209
|
+
async function b() {
|
|
210
|
+
if (!p)
|
|
211
|
+
return I || (I = (async () => {
|
|
212
|
+
const r = n(), l = e() ?? void 0;
|
|
213
|
+
await t.initialize({ preferredWalletIndex: r, preferredWalletAddress: l }), t.on("addressChanged", ({ address: a, index: g }) => {
|
|
214
|
+
if (A) return;
|
|
215
|
+
const S = u();
|
|
216
|
+
S.setWalletIndex(g), a && (S.notifyAccountsChanged([a]), c(a));
|
|
217
|
+
}), t.on("authChanged", (a) => {
|
|
218
|
+
if (!(A || W))
|
|
219
|
+
if (a.isAuthenticated && a.address) {
|
|
220
|
+
const g = u();
|
|
221
|
+
g.notifyAccountsChanged([a.address]), f.emitter.emit("connect", {
|
|
222
|
+
accounts: [a.address],
|
|
223
|
+
chainId: g.getCurrentChainId()
|
|
224
|
+
});
|
|
225
|
+
} else a.isAuthenticated || (u().notifyDisconnect(), P(), h(0), f.emitter.emit("disconnect"));
|
|
226
|
+
}), o && t.on("connectExternalWallet", o), p = !0;
|
|
227
|
+
})().finally(() => {
|
|
228
|
+
I = null;
|
|
229
|
+
}), I);
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
id: "crossx",
|
|
233
|
+
name: "CROSSx Wallet",
|
|
234
|
+
type: "crossx",
|
|
235
|
+
async setup() {
|
|
236
|
+
await b(), k(this);
|
|
237
|
+
},
|
|
238
|
+
// ── connect ─────────────────────────────────────────────────────────────
|
|
239
|
+
async connect({ chainId: r, isReconnecting: l } = {}) {
|
|
240
|
+
await b(), k(this);
|
|
241
|
+
const a = u(), g = r ?? m;
|
|
242
|
+
A = !0;
|
|
243
|
+
try {
|
|
244
|
+
if ((l || t.isAuthenticated()) && t.isAuthenticated()) {
|
|
245
|
+
const d = await t.getAddress();
|
|
246
|
+
if (d)
|
|
247
|
+
return a.setWalletIndex(d.index), a.notifyAccountsChanged([d.address]), {
|
|
248
|
+
accounts: [d.address],
|
|
249
|
+
chainId: g
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
251
|
+
};
|
|
252
|
+
await t.signOut().catch(() => {
|
|
253
|
+
}), a.notifyDisconnect();
|
|
254
|
+
}
|
|
255
|
+
const S = e();
|
|
256
|
+
let y;
|
|
257
|
+
try {
|
|
258
|
+
y = await t.signInWithCreate({
|
|
259
|
+
preferredWalletAddress: S ?? void 0
|
|
260
|
+
});
|
|
261
|
+
} catch (d) {
|
|
262
|
+
throw d instanceof N && d.code === G.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new z(d)) : (t.isAuthenticated() || (a.notifyDisconnect(), f.emitter.emit("disconnect")), d);
|
|
263
|
+
}
|
|
264
|
+
if (!y.success)
|
|
265
|
+
throw new Error(y.error ?? "CROSSx sign-in failed");
|
|
266
|
+
const w = y.address, T = y.addresses.map((d) => d.address).filter((d) => !w || d.toLowerCase() !== w.toLowerCase()), E = w ? [w, ...T] : T;
|
|
267
|
+
if (E.length === 0)
|
|
268
|
+
throw new Error("No address found after sign-in");
|
|
269
|
+
const _ = y.addresses.find(
|
|
270
|
+
(d) => w && d.address.toLowerCase() === w.toLowerCase()
|
|
271
|
+
), U = (_ == null ? void 0 : _.index) ?? 0;
|
|
272
|
+
return a.setWalletIndex(U), a.notifyAccountsChanged(E), w && c(w), {
|
|
273
|
+
accounts: E,
|
|
274
|
+
chainId: g
|
|
275
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
276
|
+
};
|
|
277
|
+
} finally {
|
|
278
|
+
A = !1;
|
|
243
279
|
}
|
|
244
|
-
|
|
245
|
-
|
|
280
|
+
},
|
|
281
|
+
// ── disconnect ──────────────────────────────────────────────────────────
|
|
282
|
+
async disconnect() {
|
|
283
|
+
W = !0;
|
|
246
284
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
throw d instanceof k && d.code === v.EXTERNAL_WALLET_REQUESTED ? (o.notifyDisconnect(), new G(d)) : (t.isAuthenticated() || (o.notifyDisconnect(), f.emitter.emit("disconnect")), d);
|
|
285
|
+
const r = u();
|
|
286
|
+
await t.signOut(), r.notifyDisconnect(), P(), h(0), f.emitter.emit("disconnect");
|
|
287
|
+
} finally {
|
|
288
|
+
W = !1;
|
|
252
289
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
290
|
+
},
|
|
291
|
+
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
292
|
+
async getAccounts() {
|
|
293
|
+
const l = u().getCurrentAccounts();
|
|
294
|
+
if (l.length > 0) return l;
|
|
295
|
+
const a = await t.getAddress();
|
|
296
|
+
return a ? [a.address] : [];
|
|
297
|
+
},
|
|
298
|
+
// ── getChainId ──────────────────────────────────────────────────────────
|
|
299
|
+
async getChainId() {
|
|
300
|
+
return u().getCurrentChainId();
|
|
301
|
+
},
|
|
302
|
+
// ── getProvider ─────────────────────────────────────────────────────────
|
|
303
|
+
async getProvider({ chainId: r } = {}) {
|
|
304
|
+
return u();
|
|
305
|
+
},
|
|
306
|
+
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
307
|
+
async isAuthorized() {
|
|
308
|
+
return await t.whenReady(), t.isAuthenticated();
|
|
309
|
+
},
|
|
310
|
+
// ── switchChain ─────────────────────────────────────────────────────────
|
|
311
|
+
async switchChain({ chainId: r }) {
|
|
312
|
+
u().setChainId(r), f.emitter.emit("change", { chainId: r });
|
|
313
|
+
const a = f.chains.find((g) => g.id === r);
|
|
314
|
+
if (!a)
|
|
315
|
+
throw new Error(`Chain ${r} is not configured`);
|
|
316
|
+
return a;
|
|
317
|
+
},
|
|
318
|
+
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
319
|
+
onAccountsChanged(r) {
|
|
320
|
+
r.length === 0 ? f.emitter.emit("disconnect") : f.emitter.emit("change", {
|
|
321
|
+
accounts: r
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
onChainChanged(r) {
|
|
325
|
+
f.emitter.emit("change", {
|
|
326
|
+
chainId: Number(r)
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
onDisconnect() {
|
|
330
|
+
f.emitter.emit("disconnect");
|
|
268
331
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
async disconnect() {
|
|
272
|
-
S = !0;
|
|
273
|
-
try {
|
|
274
|
-
const a = u();
|
|
275
|
-
await t.signOut(), a.notifyDisconnect(), b(), l(0), f.emitter.emit("disconnect");
|
|
276
|
-
} finally {
|
|
277
|
-
S = !1;
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
281
|
-
async getAccounts() {
|
|
282
|
-
const x = u().getCurrentAccounts();
|
|
283
|
-
if (x.length > 0) return x;
|
|
284
|
-
const o = await t.getAddress();
|
|
285
|
-
return o ? [o.address] : [];
|
|
286
|
-
},
|
|
287
|
-
// ── getChainId ──────────────────────────────────────────────────────────
|
|
288
|
-
async getChainId() {
|
|
289
|
-
return u().getCurrentChainId();
|
|
290
|
-
},
|
|
291
|
-
// ── getProvider ─────────────────────────────────────────────────────────
|
|
292
|
-
async getProvider({ chainId: a } = {}) {
|
|
293
|
-
return u();
|
|
294
|
-
},
|
|
295
|
-
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
296
|
-
async isAuthorized() {
|
|
297
|
-
return await t.whenReady(), t.isAuthenticated();
|
|
298
|
-
},
|
|
299
|
-
// ── switchChain ─────────────────────────────────────────────────────────
|
|
300
|
-
async switchChain({ chainId: a }) {
|
|
301
|
-
u().setChainId(a), f.emitter.emit("change", { chainId: a });
|
|
302
|
-
const o = f.chains.find((h) => h.id === a);
|
|
303
|
-
if (!o)
|
|
304
|
-
throw new Error(`Chain ${a} is not configured`);
|
|
305
|
-
return o;
|
|
306
|
-
},
|
|
307
|
-
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
308
|
-
onAccountsChanged(a) {
|
|
309
|
-
a.length === 0 ? f.emitter.emit("disconnect") : f.emitter.emit("change", {
|
|
310
|
-
accounts: a
|
|
311
|
-
});
|
|
312
|
-
},
|
|
313
|
-
onChainChanged(a) {
|
|
314
|
-
f.emitter.emit("change", {
|
|
315
|
-
chainId: Number(a)
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
onDisconnect() {
|
|
319
|
-
f.emitter.emit("disconnect");
|
|
320
|
-
}
|
|
321
|
-
}));
|
|
332
|
+
};
|
|
333
|
+
});
|
|
322
334
|
}
|
|
323
335
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
336
|
+
K as CROSSxEIP1193Provider,
|
|
337
|
+
X as createCROSSxConnector,
|
|
338
|
+
tt as crossxConnector
|
|
327
339
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.0-beta.1",
|
|
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": "^2.1
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "^2.2.0-beta.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|