@nexus-cross/crossx-sdk-wagmi 1.3.1 → 1.3.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 +28 -0
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +96 -92
- package/package.json +2 -2
package/dist/connector.d.ts
CHANGED
|
@@ -9,6 +9,19 @@ export interface CROSSxConnectorOptions {
|
|
|
9
9
|
getStoredWalletIndex?: () => number;
|
|
10
10
|
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
11
11
|
onWalletIndexChanged?: (index: number) => void;
|
|
12
|
+
/**
|
|
13
|
+
* 로그인 모달에서 "Connect with Other Wallets" 클릭 시 호출되는 콜백.
|
|
14
|
+
*
|
|
15
|
+
* 제공 시 SDK의 `connectExternalWallet` 이벤트에 자동 등록됩니다.
|
|
16
|
+
* DApp에서 이 콜백으로 wagmi 등 외부 지갑 연결 UI를 열어주세요.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* createCROSSxConnector({
|
|
20
|
+
* sdk,
|
|
21
|
+
* openConnectOtherWallet: () => openConnectModal(),
|
|
22
|
+
* })
|
|
23
|
+
*/
|
|
24
|
+
openConnectOtherWallet?: () => void;
|
|
12
25
|
}
|
|
13
26
|
/** 간편 모드: SDK 설정만 전달하면 내부에서 SDK를 생성 */
|
|
14
27
|
export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
@@ -17,6 +30,21 @@ export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
|
17
30
|
getStoredWalletIndex?: () => number;
|
|
18
31
|
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
19
32
|
onWalletIndexChanged?: (index: number) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 로그인 모달에서 "Connect with Other Wallets" 클릭 시 호출되는 콜백.
|
|
35
|
+
*
|
|
36
|
+
* 제공 시 `showConnectOtherWallets: true`가 자동 적용되며,
|
|
37
|
+
* SDK의 `connectExternalWallet` 이벤트에 자동 등록됩니다.
|
|
38
|
+
* 별도로 `showConnectOtherWallets`를 설정하거나 이벤트 리스너를 등록할 필요가 없습니다.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* crossxConnector({
|
|
42
|
+
* projectId: '...',
|
|
43
|
+
* appName: 'MyDApp',
|
|
44
|
+
* openConnectOtherWallet: () => openConnectModal(),
|
|
45
|
+
* })
|
|
46
|
+
*/
|
|
47
|
+
openConnectOtherWallet?: () => void;
|
|
20
48
|
};
|
|
21
49
|
export declare function crossxConnector(options: CrossxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
|
22
50
|
export declare function createCROSSxConnector(options: CROSSxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
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;
|
|
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"}
|
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 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;
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { createConnector as v } from "wagmi";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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) {
|
|
4
5
|
return parseInt(i.split(":")[1] ?? "1", 10);
|
|
5
6
|
}
|
|
6
|
-
function
|
|
7
|
+
function p(i) {
|
|
7
8
|
return `eip155:${i}`;
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
+
function E(i) {
|
|
10
11
|
return "0x" + i.toString(16);
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function O(i) {
|
|
13
14
|
const t = i.startsWith("0x") ? i.slice(2) : i, s = new Uint8Array(t.length / 2);
|
|
14
15
|
for (let n = 0; n < s.length; n++)
|
|
15
16
|
s[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
16
17
|
return new TextDecoder().decode(s);
|
|
17
18
|
}
|
|
18
|
-
class
|
|
19
|
+
class q {
|
|
19
20
|
constructor(t, s = b.CROSS_MAINNET) {
|
|
20
|
-
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 :
|
|
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 }) => {
|
|
21
22
|
this.setWalletIndex(o), this.notifyAccountsChanged([n]);
|
|
22
23
|
});
|
|
23
24
|
}
|
|
@@ -30,7 +31,7 @@ class N {
|
|
|
30
31
|
try {
|
|
31
32
|
return await this._handleRequest(t, s);
|
|
32
33
|
} catch (n) {
|
|
33
|
-
throw n instanceof
|
|
34
|
+
throw n instanceof R && n.code === k.USER_REJECTED ? Object.assign(
|
|
34
35
|
new Error("User rejected the request"),
|
|
35
36
|
{ code: 4001, data: n.details }
|
|
36
37
|
) : n;
|
|
@@ -48,34 +49,34 @@ class N {
|
|
|
48
49
|
return e ? [e.address] : [];
|
|
49
50
|
}
|
|
50
51
|
case "eth_chainId":
|
|
51
|
-
return
|
|
52
|
+
return E(this.chainId);
|
|
52
53
|
case "net_version":
|
|
53
54
|
return String(this.chainId);
|
|
54
55
|
case "personal_sign": {
|
|
55
|
-
const [e] = n,
|
|
56
|
+
const [e] = n, r = e.startsWith("0x") ? O(e) : e;
|
|
56
57
|
return (await this.sdk.signMessage(
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
p(this.chainId),
|
|
59
|
+
r,
|
|
59
60
|
{ index: this.walletIndex }
|
|
60
61
|
)).signature;
|
|
61
62
|
}
|
|
62
63
|
case "eth_sign": {
|
|
63
|
-
const [, e] = n,
|
|
64
|
+
const [, e] = n, r = e.startsWith("0x") ? O(e) : e;
|
|
64
65
|
return (await this.sdk.signMessage(
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
p(this.chainId),
|
|
67
|
+
r,
|
|
67
68
|
{ index: this.walletIndex }
|
|
68
69
|
)).signature;
|
|
69
70
|
}
|
|
70
71
|
case "eth_signTypedData":
|
|
71
72
|
case "eth_signTypedData_v3":
|
|
72
73
|
case "eth_signTypedData_v4": {
|
|
73
|
-
const [, e] = n,
|
|
74
|
-
return (
|
|
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;
|
|
75
76
|
}
|
|
76
77
|
case "eth_sendTransaction": {
|
|
77
|
-
const [e] = n,
|
|
78
|
-
return (await this.sdk.sendTransaction(
|
|
78
|
+
const [e] = n, r = p(this.chainId);
|
|
79
|
+
return (await this.sdk.sendTransaction(r, {
|
|
79
80
|
from: e.from,
|
|
80
81
|
to: e.to,
|
|
81
82
|
value: e.value,
|
|
@@ -89,13 +90,13 @@ class N {
|
|
|
89
90
|
}, { index: this.walletIndex })).txHash;
|
|
90
91
|
}
|
|
91
92
|
case "wallet_switchEthereumChain": {
|
|
92
|
-
const [{ chainId: e }] = n,
|
|
93
|
-
return
|
|
93
|
+
const [{ chainId: e }] = n, r = parseInt(e, 16);
|
|
94
|
+
return r !== this.chainId && (this.chainId = r, this.emit("chainChanged", E(r))), null;
|
|
94
95
|
}
|
|
95
96
|
case "wallet_addEthereumChain":
|
|
96
97
|
return null;
|
|
97
98
|
default:
|
|
98
|
-
return this.sdk.walletRpc(t, n,
|
|
99
|
+
return this.sdk.walletRpc(t, n, p(this.chainId));
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
@@ -121,7 +122,7 @@ class N {
|
|
|
121
122
|
return this.chainId;
|
|
122
123
|
}
|
|
123
124
|
setChainId(t) {
|
|
124
|
-
t !== this.chainId && (this.chainId = t, this.emit("chainChanged",
|
|
125
|
+
t !== this.chainId && (this.chainId = t, this.emit("chainChanged", E(t)));
|
|
125
126
|
}
|
|
126
127
|
/**
|
|
127
128
|
* 활성 지갑 인덱스 설정.
|
|
@@ -138,77 +139,80 @@ class N {
|
|
|
138
139
|
return [...this.currentAccounts];
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
|
-
function
|
|
142
|
+
function G(i) {
|
|
142
143
|
return typeof i == "number" ? i : parseInt(i.split(":")[1] ?? "1", 10);
|
|
143
144
|
}
|
|
144
|
-
const
|
|
145
|
-
function
|
|
145
|
+
const W = "crossx-wallet-index";
|
|
146
|
+
function U() {
|
|
146
147
|
try {
|
|
147
|
-
const i = typeof window < "u" ? localStorage.getItem(
|
|
148
|
+
const i = typeof window < "u" ? localStorage.getItem(W) : null;
|
|
148
149
|
return i && Number(i) || 0;
|
|
149
150
|
} catch {
|
|
150
151
|
return 0;
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
|
-
function
|
|
154
|
+
function M(i) {
|
|
154
155
|
try {
|
|
155
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(W, String(i));
|
|
156
157
|
} catch {
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
|
-
function
|
|
160
|
+
function F() {
|
|
160
161
|
try {
|
|
161
|
-
typeof window < "u" && localStorage.removeItem(
|
|
162
|
+
typeof window < "u" && localStorage.removeItem(W);
|
|
162
163
|
} catch {
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
-
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n,
|
|
167
|
-
|
|
166
|
+
function K(i) {
|
|
167
|
+
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: o, ...e } = i;
|
|
168
|
+
o && (e.showConnectOtherWallets = !0);
|
|
169
|
+
const r = N(e);
|
|
170
|
+
return j({ sdk: r, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, openConnectOtherWallet: o });
|
|
168
171
|
}
|
|
169
|
-
function
|
|
172
|
+
function j(i) {
|
|
170
173
|
const {
|
|
171
174
|
sdk: t,
|
|
172
175
|
defaultChainId: s = b.CROSS_MAINNET,
|
|
173
|
-
getStoredWalletIndex: n =
|
|
174
|
-
onWalletIndexChanged: o =
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
getStoredWalletIndex: n = U,
|
|
177
|
+
onWalletIndexChanged: o = M,
|
|
178
|
+
openConnectOtherWallet: e
|
|
179
|
+
} = i, r = G(s);
|
|
180
|
+
let d = null, x = !1, w = !1;
|
|
177
181
|
function l() {
|
|
178
|
-
return
|
|
182
|
+
return d || (d = new q(t, r), d._setWalletIndexChangeCallback(o)), d;
|
|
179
183
|
}
|
|
180
|
-
return v((
|
|
184
|
+
return v((u) => ({
|
|
181
185
|
id: "crossx",
|
|
182
186
|
name: "CROSSx Wallet",
|
|
183
187
|
type: "crossx",
|
|
184
188
|
async setup() {
|
|
185
|
-
if (!
|
|
189
|
+
if (!x) {
|
|
186
190
|
const g = n();
|
|
187
|
-
await t.initialize({ preferredWalletIndex: g }),
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
});
|
|
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]);
|
|
195
|
+
}), e && t.on("connectExternalWallet", e);
|
|
192
196
|
}
|
|
193
|
-
const
|
|
194
|
-
|
|
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));
|
|
195
199
|
},
|
|
196
200
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
197
|
-
async connect({ chainId:
|
|
198
|
-
var
|
|
199
|
-
const c = l(),
|
|
200
|
-
|
|
201
|
+
async connect({ chainId: a, isReconnecting: g } = {}) {
|
|
202
|
+
var m;
|
|
203
|
+
const c = l(), f = a ?? r;
|
|
204
|
+
w = !0;
|
|
201
205
|
try {
|
|
202
206
|
if (g || t.isAuthenticated()) {
|
|
203
|
-
const
|
|
207
|
+
const h = n();
|
|
204
208
|
if (t.isAuthenticated()) {
|
|
205
209
|
try {
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
209
|
-
return c.setWalletIndex(
|
|
210
|
-
accounts: [
|
|
211
|
-
chainId:
|
|
210
|
+
const S = await t.getAddresses();
|
|
211
|
+
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],
|
|
215
|
+
chainId: f
|
|
212
216
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
217
|
};
|
|
214
218
|
}
|
|
@@ -218,33 +222,33 @@ function F(i) {
|
|
|
218
222
|
}), c.notifyDisconnect();
|
|
219
223
|
}
|
|
220
224
|
}
|
|
221
|
-
let
|
|
225
|
+
let I;
|
|
222
226
|
try {
|
|
223
|
-
|
|
224
|
-
} catch (
|
|
225
|
-
throw t.isAuthenticated() || (c.notifyDisconnect(),
|
|
227
|
+
I = await t.signInWithCreate();
|
|
228
|
+
} 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);
|
|
226
230
|
}
|
|
227
|
-
if (!
|
|
228
|
-
throw new Error(
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
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)
|
|
231
235
|
throw new Error("No address found after sign-in");
|
|
232
|
-
const
|
|
233
|
-
(
|
|
234
|
-
)) == null ? void 0 :
|
|
235
|
-
return c.setWalletIndex(
|
|
236
|
-
accounts:
|
|
237
|
-
chainId:
|
|
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,
|
|
241
|
+
chainId: f
|
|
238
242
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
239
243
|
};
|
|
240
244
|
} finally {
|
|
241
|
-
|
|
245
|
+
w = !1;
|
|
242
246
|
}
|
|
243
247
|
},
|
|
244
248
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
245
249
|
async disconnect() {
|
|
246
|
-
const
|
|
247
|
-
await t.signOut(),
|
|
250
|
+
const a = l();
|
|
251
|
+
await t.signOut(), a.notifyDisconnect(), F(), o(0), u.emitter.emit("disconnect");
|
|
248
252
|
},
|
|
249
253
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
250
254
|
async getAccounts() {
|
|
@@ -258,7 +262,7 @@ function F(i) {
|
|
|
258
262
|
return l().getCurrentChainId();
|
|
259
263
|
},
|
|
260
264
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
261
|
-
async getProvider({ chainId:
|
|
265
|
+
async getProvider({ chainId: a } = {}) {
|
|
262
266
|
return l();
|
|
263
267
|
},
|
|
264
268
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
@@ -266,31 +270,31 @@ function F(i) {
|
|
|
266
270
|
return await t.whenReady(), t.isAuthenticated();
|
|
267
271
|
},
|
|
268
272
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
269
|
-
async switchChain({ chainId:
|
|
270
|
-
l().setChainId(
|
|
271
|
-
const c =
|
|
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);
|
|
272
276
|
if (!c)
|
|
273
|
-
throw new Error(`Chain ${
|
|
277
|
+
throw new Error(`Chain ${a} is not configured`);
|
|
274
278
|
return c;
|
|
275
279
|
},
|
|
276
280
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
277
|
-
onAccountsChanged(
|
|
278
|
-
|
|
279
|
-
accounts:
|
|
281
|
+
onAccountsChanged(a) {
|
|
282
|
+
a.length === 0 ? u.emitter.emit("disconnect") : u.emitter.emit("change", {
|
|
283
|
+
accounts: a
|
|
280
284
|
});
|
|
281
285
|
},
|
|
282
|
-
onChainChanged(
|
|
283
|
-
|
|
284
|
-
chainId: Number(
|
|
286
|
+
onChainChanged(a) {
|
|
287
|
+
u.emitter.emit("change", {
|
|
288
|
+
chainId: Number(a)
|
|
285
289
|
});
|
|
286
290
|
},
|
|
287
291
|
onDisconnect() {
|
|
288
|
-
|
|
292
|
+
u.emitter.emit("disconnect");
|
|
289
293
|
}
|
|
290
294
|
}));
|
|
291
295
|
}
|
|
292
296
|
export {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
297
|
+
q as CROSSxEIP1193Provider,
|
|
298
|
+
j as createCROSSxConnector,
|
|
299
|
+
K as crossxConnector
|
|
296
300
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
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.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "1.3.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|