@nexus-cross/crossx-sdk-wagmi 2.1.3 → 2.2.0-beta.10
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 +4 -0
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +208 -189
- package/package.json +2 -2
package/dist/connector.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface CROSSxConnectorOptions {
|
|
|
13
13
|
getStoredWalletAddress?: () => string | null;
|
|
14
14
|
/** 활성 지갑 주소 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
15
15
|
onWalletAddressChanged?: (address: string) => void;
|
|
16
|
+
/** disconnect/signOut 시 저장된 지갑 주소를 제거하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
17
|
+
clearStoredWalletAddress?: () => void;
|
|
16
18
|
/**
|
|
17
19
|
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
18
20
|
*
|
|
@@ -38,6 +40,8 @@ export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
|
38
40
|
getStoredWalletAddress?: () => string | null;
|
|
39
41
|
/** 활성 지갑 주소 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
40
42
|
onWalletAddressChanged?: (address: string) => void;
|
|
43
|
+
/** disconnect/signOut 시 저장된 지갑 주소를 제거하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
44
|
+
clearStoredWalletAddress?: () => void;
|
|
41
45
|
/**
|
|
42
46
|
* 로그인 모달에서 외부 지갑 행 클릭 시 호출되는 콜백.
|
|
43
47
|
*
|
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,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AE,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,8GAyRpE"}
|
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 j=require("wagmi"),z=require("viem"),x=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=x.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 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,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 v="crossx-wallet-address";function Y(){try{return typeof window<"u"?localStorage.getItem(v):null}catch{return null}}function $(s){try{typeof window<"u"&&localStorage.setItem(v,s)}catch{}}function Q(){try{typeof window<"u"&&localStorage.removeItem(v)}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,y=u.showConnectOtherWallets===!0;!S&&!y&&(u.showConnectOtherWallets=!0)}const m=x.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=x.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,y=null,D=!1,W=!1,O=!1;function g(){return f||(f=new G(e,m),f._setWalletIndexChangeCallback(d)),f}return j.createConnector(C=>{function T(a){if(D)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)),D=!0}async function P(){if(!S)return y||(y=(async()=>{const a=n(),h=t()??void 0;await e.initialize({preferredWalletIndex:a,preferredWalletAddress:h}),e.on("addressChanged",({address:i,index:I})=>{if(W)return;const E=g();E.setWalletIndex(I),i&&(E.notifyAccountsChanged([i]),c(i))}),e.on("authChanged",i=>{if(!(W||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:"CROSSx Wallet",type:"crossx",async setup(){await P(),T(this)},async connect({chainId:a,isReconnecting:h}={}){await P(),T(this);const i=g(),I=a??m;W=!0;try{if((h||e.isAuthenticated())&&e.isAuthenticated()){const o=await e.getAddress();if(o)return i.setWalletIndex(o.index),i.notifyAccountsChanged([o.address]),{accounts:[o.address],chainId:I};await e.signOut().catch(()=>{}),i.notifyDisconnect()}const E=t();let p;try{p=await e.signInWithCreate({preferredWalletAddress:E??void 0})}catch(o){throw o instanceof x.CROSSxError&&o.code===x.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()),_=w?[w,...L]:L;if(_.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(_),w&&c(w),{accounts:_,chainId:I}}finally{W=!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.whenReady(),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
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
3
|
-
import { ChainId as
|
|
4
|
-
function
|
|
1
|
+
import { createConnector as z } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as F } from "viem";
|
|
3
|
+
import { ChainId as G, CROSSxError as q, ErrorCode as U, createCROSSxSDK as j } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function K(s) {
|
|
5
5
|
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
7
|
function A(s) {
|
|
8
8
|
return `eip155:${s}`;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function D(s) {
|
|
11
11
|
return "0x" + s.toString(16);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const t = s.startsWith("0x") ? s.slice(2) : s,
|
|
15
|
-
for (let n = 0; n <
|
|
16
|
-
|
|
17
|
-
return new TextDecoder().decode(
|
|
13
|
+
function L(s) {
|
|
14
|
+
const t = s.startsWith("0x") ? s.slice(2) : s, r = new Uint8Array(t.length / 2);
|
|
15
|
+
for (let n = 0; n < r.length; n++)
|
|
16
|
+
r[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
|
+
return new TextDecoder().decode(r);
|
|
18
18
|
}
|
|
19
|
-
class
|
|
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
|
|
22
|
-
this.setWalletIndex(
|
|
19
|
+
class H {
|
|
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: o }) => {
|
|
22
|
+
this.setWalletIndex(o), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -27,19 +27,19 @@ class M {
|
|
|
27
27
|
this.walletIndexChangeCallback = t;
|
|
28
28
|
}
|
|
29
29
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
30
|
-
async request({ method: t, params:
|
|
30
|
+
async request({ method: t, params: r }) {
|
|
31
31
|
try {
|
|
32
|
-
return await this._handleRequest(t,
|
|
32
|
+
return await this._handleRequest(t, r);
|
|
33
33
|
} catch (n) {
|
|
34
|
-
throw n instanceof
|
|
34
|
+
throw n instanceof q && n.code === U.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
|
-
async _handleRequest(t,
|
|
41
|
-
var
|
|
42
|
-
const n =
|
|
40
|
+
async _handleRequest(t, r) {
|
|
41
|
+
var o;
|
|
42
|
+
const n = r ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
45
45
|
case "eth_accounts": {
|
|
@@ -49,34 +49,34 @@ class M {
|
|
|
49
49
|
return e ? [e.address] : [];
|
|
50
50
|
}
|
|
51
51
|
case "eth_chainId":
|
|
52
|
-
return
|
|
52
|
+
return D(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") ? L(e) : e;
|
|
57
57
|
return (await this.sdk.signMessage(
|
|
58
58
|
A(this.chainId),
|
|
59
|
-
|
|
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") ? L(e) : e;
|
|
65
65
|
return (await this.sdk.signMessage(
|
|
66
66
|
A(this.chainId),
|
|
67
|
-
|
|
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, l = (o = c == null ? void 0 : c.domain) == null ? void 0 : o.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(A(p), c, f)).signature;
|
|
76
76
|
}
|
|
77
77
|
case "eth_sendTransaction": {
|
|
78
|
-
const [e] = n,
|
|
79
|
-
return (await this.sdk.sendTransaction(
|
|
78
|
+
const [e] = n, c = A(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,8 +90,8 @@ 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", D(c))), null;
|
|
95
95
|
}
|
|
96
96
|
case "wallet_addEthereumChain":
|
|
97
97
|
return null;
|
|
@@ -100,16 +100,16 @@ class M {
|
|
|
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, r) {
|
|
104
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(r), this;
|
|
105
105
|
}
|
|
106
|
-
removeListener(t,
|
|
106
|
+
removeListener(t, r) {
|
|
107
107
|
var n;
|
|
108
|
-
return (n = this.listeners.get(t)) == null || n.delete(
|
|
108
|
+
return (n = this.listeners.get(t)) == null || n.delete(r), this;
|
|
109
109
|
}
|
|
110
|
-
emit(t, ...
|
|
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((o) => o(...r));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -122,15 +122,15 @@ 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", D(t)));
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* 활성 지갑 인덱스 설정.
|
|
129
129
|
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
130
130
|
*/
|
|
131
131
|
setWalletIndex(t) {
|
|
132
|
-
var
|
|
133
|
-
this.walletIndex = t, (
|
|
132
|
+
var r;
|
|
133
|
+
this.walletIndex = t, (r = this.walletIndexChangeCallback) == null || r.call(this, t);
|
|
134
134
|
}
|
|
135
135
|
getWalletIndex() {
|
|
136
136
|
return this.walletIndex;
|
|
@@ -139,189 +139,208 @@ class M {
|
|
|
139
139
|
return [...this.currentAccounts];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function J(s) {
|
|
143
143
|
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
144
144
|
}
|
|
145
|
-
const
|
|
146
|
-
function
|
|
145
|
+
const R = "crossx-wallet-index";
|
|
146
|
+
function Y() {
|
|
147
147
|
try {
|
|
148
|
-
const s = typeof window < "u" ? localStorage.getItem(
|
|
148
|
+
const s = typeof window < "u" ? localStorage.getItem(R) : null;
|
|
149
149
|
return s && Number(s) || 0;
|
|
150
150
|
} catch {
|
|
151
151
|
return 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function $(s) {
|
|
155
155
|
try {
|
|
156
|
-
typeof window < "u" && localStorage.setItem(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(R, String(s));
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function N() {
|
|
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
|
|
167
|
-
function
|
|
166
|
+
const k = "crossx-wallet-address";
|
|
167
|
+
function Q() {
|
|
168
168
|
try {
|
|
169
|
-
return typeof window < "u" ? localStorage.getItem(
|
|
169
|
+
return typeof window < "u" ? localStorage.getItem(k) : null;
|
|
170
170
|
} catch {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function X(s) {
|
|
175
175
|
try {
|
|
176
|
-
typeof window < "u" && localStorage.setItem(
|
|
176
|
+
typeof window < "u" && localStorage.setItem(k, s);
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
!m && !p && (c.showConnectOtherWallets = !0);
|
|
180
|
+
function B() {
|
|
181
|
+
try {
|
|
182
|
+
typeof window < "u" && localStorage.removeItem(k);
|
|
183
|
+
} catch {
|
|
185
184
|
}
|
|
186
|
-
const w = q(c);
|
|
187
|
-
return J({ sdk: w, defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: l, onWalletAddressChanged: e, openConnectOtherWallet: r });
|
|
188
185
|
}
|
|
189
|
-
function
|
|
186
|
+
function nt(s) {
|
|
187
|
+
const { defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress: o, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l, ...u } = s;
|
|
188
|
+
if (l) {
|
|
189
|
+
const f = u.connectOtherWallets, x = Array.isArray(f) && f.length > 0, m = u.showConnectOtherWallets === !0;
|
|
190
|
+
!x && !m && (u.showConnectOtherWallets = !0);
|
|
191
|
+
}
|
|
192
|
+
const p = j(u);
|
|
193
|
+
return V({ sdk: p, defaultChainId: t, getStoredWalletIndex: r, onWalletIndexChanged: n, getStoredWalletAddress: o, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: l });
|
|
194
|
+
}
|
|
195
|
+
function V(s) {
|
|
190
196
|
const {
|
|
191
197
|
sdk: t,
|
|
192
|
-
defaultChainId:
|
|
193
|
-
getStoredWalletIndex: n =
|
|
194
|
-
onWalletIndexChanged:
|
|
195
|
-
getStoredWalletAddress: e =
|
|
196
|
-
onWalletAddressChanged:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
defaultChainId: r = G.CROSS_MAINNET,
|
|
199
|
+
getStoredWalletIndex: n = Y,
|
|
200
|
+
onWalletIndexChanged: o = $,
|
|
201
|
+
getStoredWalletAddress: e = Q,
|
|
202
|
+
onWalletAddressChanged: c = X,
|
|
203
|
+
clearStoredWalletAddress: l = B,
|
|
204
|
+
openConnectOtherWallet: u
|
|
205
|
+
} = s, p = J(r);
|
|
206
|
+
let f = null, x = !1, m = null, b = !1, S = !1, E = !1;
|
|
207
|
+
function g() {
|
|
208
|
+
return f || (f = new H(t, p), f._setWalletIndexChangeCallback(o)), f;
|
|
202
209
|
}
|
|
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
|
-
|
|
210
|
+
return z((C) => {
|
|
211
|
+
function T(a) {
|
|
212
|
+
if (b) return;
|
|
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)), b = !0;
|
|
215
|
+
}
|
|
216
|
+
async function v() {
|
|
217
|
+
if (!x)
|
|
218
|
+
return m || (m = (async () => {
|
|
219
|
+
const a = n(), h = e() ?? void 0;
|
|
220
|
+
await t.initialize({ preferredWalletIndex: a, preferredWalletAddress: h }), t.on("addressChanged", ({ address: i, index: I }) => {
|
|
221
|
+
if (S) return;
|
|
222
|
+
const W = g();
|
|
223
|
+
W.setWalletIndex(I), i && (W.notifyAccountsChanged([i]), c(i));
|
|
224
|
+
}), t.on("authChanged", (i) => {
|
|
225
|
+
if (!(S || E))
|
|
226
|
+
if (i.isAuthenticated && i.address) {
|
|
227
|
+
const I = g();
|
|
228
|
+
I.notifyAccountsChanged([i.address]), C.emitter.emit("connect", {
|
|
229
|
+
accounts: [i.address],
|
|
230
|
+
chainId: I.getCurrentChainId()
|
|
231
|
+
});
|
|
232
|
+
} else i.isAuthenticated || (g().notifyDisconnect(), N(), l(), o(0), C.emitter.emit("disconnect"));
|
|
233
|
+
}), u && t.on("connectExternalWallet", u), x = !0;
|
|
234
|
+
})().finally(() => {
|
|
235
|
+
m = null;
|
|
236
|
+
}), m);
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
id: "crossx",
|
|
240
|
+
name: "CROSSx Wallet",
|
|
241
|
+
type: "crossx",
|
|
242
|
+
async setup() {
|
|
243
|
+
await v(), T(this);
|
|
244
|
+
},
|
|
245
|
+
// ── connect ─────────────────────────────────────────────────────────────
|
|
246
|
+
async connect({ chainId: a, isReconnecting: h } = {}) {
|
|
247
|
+
await v(), T(this);
|
|
248
|
+
const i = g(), I = a ?? p;
|
|
249
|
+
S = !0;
|
|
250
|
+
try {
|
|
251
|
+
if ((h || t.isAuthenticated()) && t.isAuthenticated()) {
|
|
252
|
+
const d = await t.getAddress();
|
|
253
|
+
if (d)
|
|
254
|
+
return i.setWalletIndex(d.index), i.notifyAccountsChanged([d.address]), {
|
|
255
|
+
accounts: [d.address],
|
|
256
|
+
chainId: I
|
|
257
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
+
};
|
|
259
|
+
await t.signOut().catch(() => {
|
|
260
|
+
}), i.notifyDisconnect();
|
|
261
|
+
}
|
|
262
|
+
const W = e();
|
|
263
|
+
let y;
|
|
264
|
+
try {
|
|
265
|
+
y = await t.signInWithCreate({
|
|
266
|
+
preferredWalletAddress: W ?? void 0
|
|
267
|
+
});
|
|
268
|
+
} catch (d) {
|
|
269
|
+
throw d instanceof q && d.code === U.EXTERNAL_WALLET_REQUESTED ? (i.notifyDisconnect(), new F(d)) : (t.isAuthenticated() || (i.notifyDisconnect(), C.emitter.emit("disconnect")), d);
|
|
270
|
+
}
|
|
271
|
+
if (!y.success)
|
|
272
|
+
throw new Error(y.error ?? "CROSSx sign-in failed");
|
|
273
|
+
const w = y.address, P = y.addresses.map((d) => d.address).filter((d) => !w || d.toLowerCase() !== w.toLowerCase()), _ = w ? [w, ...P] : P;
|
|
274
|
+
if (_.length === 0)
|
|
275
|
+
throw new Error("No address found after sign-in");
|
|
276
|
+
const O = y.addresses.find(
|
|
277
|
+
(d) => w && d.address.toLowerCase() === w.toLowerCase()
|
|
278
|
+
), M = (O == null ? void 0 : O.index) ?? 0;
|
|
279
|
+
return i.setWalletIndex(M), i.notifyAccountsChanged(_), w && c(w), {
|
|
280
|
+
accounts: _,
|
|
281
|
+
chainId: I
|
|
282
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
|
+
};
|
|
284
|
+
} finally {
|
|
285
|
+
S = !1;
|
|
243
286
|
}
|
|
244
|
-
|
|
245
|
-
|
|
287
|
+
},
|
|
288
|
+
// ── disconnect ──────────────────────────────────────────────────────────
|
|
289
|
+
async disconnect() {
|
|
290
|
+
E = !0;
|
|
246
291
|
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);
|
|
292
|
+
const a = g();
|
|
293
|
+
await t.signOut(), a.notifyDisconnect(), N(), l(), o(0), C.emitter.emit("disconnect");
|
|
294
|
+
} finally {
|
|
295
|
+
E = !1;
|
|
252
296
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
297
|
+
},
|
|
298
|
+
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
299
|
+
async getAccounts() {
|
|
300
|
+
const h = g().getCurrentAccounts();
|
|
301
|
+
if (h.length > 0) return h;
|
|
302
|
+
const i = await t.getAddress();
|
|
303
|
+
return i ? [i.address] : [];
|
|
304
|
+
},
|
|
305
|
+
// ── getChainId ──────────────────────────────────────────────────────────
|
|
306
|
+
async getChainId() {
|
|
307
|
+
return g().getCurrentChainId();
|
|
308
|
+
},
|
|
309
|
+
// ── getProvider ─────────────────────────────────────────────────────────
|
|
310
|
+
async getProvider({ chainId: a } = {}) {
|
|
311
|
+
return g();
|
|
312
|
+
},
|
|
313
|
+
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
314
|
+
async isAuthorized() {
|
|
315
|
+
return await t.whenReady(), t.isAuthenticated();
|
|
316
|
+
},
|
|
317
|
+
// ── switchChain ─────────────────────────────────────────────────────────
|
|
318
|
+
async switchChain({ chainId: a }) {
|
|
319
|
+
g().setChainId(a), C.emitter.emit("change", { chainId: a });
|
|
320
|
+
const i = C.chains.find((I) => I.id === a);
|
|
321
|
+
if (!i)
|
|
322
|
+
throw new Error(`Chain ${a} is not configured`);
|
|
323
|
+
return i;
|
|
324
|
+
},
|
|
325
|
+
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
326
|
+
onAccountsChanged(a) {
|
|
327
|
+
a.length === 0 ? C.emitter.emit("disconnect") : C.emitter.emit("change", {
|
|
328
|
+
accounts: a
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
onChainChanged(a) {
|
|
332
|
+
C.emitter.emit("change", {
|
|
333
|
+
chainId: Number(a)
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
onDisconnect() {
|
|
337
|
+
C.emitter.emit("disconnect");
|
|
278
338
|
}
|
|
279
|
-
}
|
|
280
|
-
|
|
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
|
-
}));
|
|
339
|
+
};
|
|
340
|
+
});
|
|
322
341
|
}
|
|
323
342
|
export {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
H as CROSSxEIP1193Provider,
|
|
344
|
+
V as createCROSSxConnector,
|
|
345
|
+
nt as crossxConnector
|
|
327
346
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-beta.10",
|
|
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.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "^2.2.0-beta.10"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|