@nexus-cross/crossx-sdk-wagmi 1.0.9 → 1.1.0
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 +114 -92
- 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;CAChD;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;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;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;CAChD;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;CAChD,CAAC;AAgCF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAgNpE"}
|
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 _=require("wagmi"),y=require("@nexus-cross/crossx-sdk-core");function W(s){return parseInt(s.split(":")[1]??"1",10)}function w(s){return`eip155:${s}`}function A(s){return"0x"+s.toString(16)}class R{constructor(e,c=y.ChainId.CROSS_MAINNET){this.sdk=e,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof c=="number"?c:W(c),this.sdk.on("addressChanged",({address:i,index:a})=>{this.setWalletIndex(a),this.notifyAccountsChanged([i])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:c}){var a;const i=c??[];switch(e){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return console.log("[CROSSx-debug] provider.eth_accounts → currentAccounts:",this.currentAccounts[0],"walletIndex:",this.walletIndex),[...this.currentAccounts];const t=await this.sdk.getAddress();return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():",t==null?void 0:t.address),t?[t.address]:[]}case"eth_chainId":return A(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=i;return(await this.sdk.signMessage(w(this.chainId),t,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=i;return(await this.sdk.signMessage(w(this.chainId),t,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=i,o=typeof t=="string"?JSON.parse(t):t,C=(a=o==null?void 0:o.domain)==null?void 0:a.chainId,l=C==null||C===0,h=l?0:Number(C),n={index:this.walletIndex};return(l?await this.sdk.signTypedDataOffchain(o,n):await this.sdk.signTypedData(w(h),o,n)).signature}case"eth_sendTransaction":{const[t]=i,o=w(this.chainId);return(await this.sdk.sendTransaction(o,{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}]=i,o=parseInt(t,16);return o!==this.chainId&&(this.chainId=o,this.emit("chainChanged",A(o))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,i,w(this.chainId))}}on(e,c){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(c),this}removeListener(e,c){var i;return(i=this.listeners.get(e))==null||i.delete(c),this}emit(e,...c){var i;(i=this.listeners.get(e))==null||i.forEach(a=>a(...c))}notifyAccountsChanged(e){console.log("[CROSSx-debug] provider.notifyAccountsChanged:",e[0],"walletIndex:",this.walletIndex),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",A(e)))}setWalletIndex(e){var c;console.log("[CROSSx-debug] provider.setWalletIndex:",e),this.walletIndex=e,(c=this.walletIndexChangeCallback)==null||c.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function P(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const b="crossx-wallet-index";function D(){try{const s=typeof window<"u"?localStorage.getItem(b):null;return s&&Number(s)||0}catch{return 0}}function T(s){try{typeof window<"u"&&localStorage.setItem(b,String(s))}catch{}}function E(){try{typeof window<"u"&&localStorage.removeItem(b)}catch{}}function N(s){const{defaultChainId:e,getStoredWalletIndex:c,onWalletIndexChanged:i,...a}=s,t=y.createCROSSxSDK(a);return k({sdk:t,defaultChainId:e,getStoredWalletIndex:c,onWalletIndexChanged:i})}function k(s){const{sdk:e,defaultChainId:c=y.ChainId.CROSS_MAINNET,getStoredWalletIndex:i=D,onWalletIndexChanged:a=T}=s,t=P(c);let o=null,C=!1;function l(){return o||(o=new R(e,t),o._setWalletIndexChangeCallback(a)),o}return _.createConnector(h=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){console.log("[CROSSx-debug] connector.setup() 시작"),C||(await e.initialize(),C=!0),console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:",e.isAuthenticated());const n=l();n.on("accountsChanged",this.onAccountsChanged.bind(this)),n.on("chainChanged",this.onChainChanged.bind(this)),n.on("disconnect",this.onDisconnect.bind(this)),console.log("[CROSSx-debug] connector.setup() 완료, 이벤트 리스너 등록됨")},async connect({chainId:n,isReconnecting:g}={}){console.log("[CROSSx-debug] connector.connect() 호출",{isReconnecting:g,targetChainId:n});const r=l(),x=n??t;if(g||e.isAuthenticated()){const d=i();console.log("[CROSSx-debug] connector.connect() 재연결 경로",{storedIndex:d,isAuth:e.isAuthenticated()});const u=await e.getAddress(d||void 0);if(console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과",{address:u==null?void 0:u.address,index:u==null?void 0:u.index,requestedIndex:d||void 0}),u)return r.setWalletIndex(d),r.notifyAccountsChanged([u.address]),console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:",u.address),{accounts:[u.address],chainId:x};if(e.isAuthenticated()){console.log("[CROSSx-debug] connector.connect() 캐시 없음 — getAddresses() 재시도");try{const f=await e.getAddresses();if(f.length>0){const m=f.find(v=>v.index===d)??f[0];return r.setWalletIndex(m.index),r.notifyAccountsChanged([m.address]),console.log("[CROSSx-debug] connector.connect() getAddresses 재시도 성공 →",m.address),{accounts:[m.address],chainId:x}}}catch(f){console.warn("[CROSSx-debug] connector.connect() getAddresses 실패:",f)}console.log("[CROSSx-debug] connector.connect() 지갑 없음 — 로그아웃 후 신규 로그인"),await e.signOut().catch(()=>{}),r.notifyDisconnect()}console.log("[CROSSx-debug] connector.connect() 신규 로그인으로 진행")}let I;try{I=await e.signInWithCreate()}catch(d){throw e.isAuthenticated()||(r.notifyDisconnect(),h.emitter.emit("disconnect")),d}if(!I.success)throw new Error(I.error??"CROSSx sign-in failed");const S=I.address,O=I.addresses.map(d=>d.address).filter(d=>!S||d.toLowerCase()!==S.toLowerCase()),p=S?[S,...O]:O;if(p.length===0)throw new Error("No address found after sign-in");return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:",S),r.notifyAccountsChanged(p),{accounts:p,chainId:x}},async disconnect(){const n=l();await e.signOut(),n.notifyDisconnect(),E(),a(0),h.emitter.emit("disconnect")},async getAccounts(){const n=l(),g=n.getCurrentAccounts();if(console.log("[CROSSx-debug] connector.getAccounts()",{trackedLen:g.length,tracked:g[0],walletIndex:n.getWalletIndex()}),g.length>0)return g;const r=await e.getAddress();return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():",r==null?void 0:r.address),r?[r.address]:[]},async getChainId(){return l().getCurrentChainId()},async getProvider({chainId:n}={}){return l()},async isAuthorized(){const n=e.isAuthenticated();return console.log("[CROSSx-debug] connector.isAuthorized():",n),n},async switchChain({chainId:n}){l().setChainId(n),h.emitter.emit("change",{chainId:n});const r=h.chains.find(x=>x.id===n);if(!r)throw new Error(`Chain ${n} is not configured`);return r},onAccountsChanged(n){console.log("[CROSSx-debug] connector.onAccountsChanged:",n),n.length===0?h.emitter.emit("disconnect"):h.emitter.emit("change",{accounts:n})},onChainChanged(n){h.emitter.emit("change",{chainId:Number(n)})},onDisconnect(){h.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=R;exports.createCROSSxConnector=k;exports.crossxConnector=N;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { ChainId as
|
|
3
|
-
function
|
|
1
|
+
import { createConnector as k } from "wagmi";
|
|
2
|
+
import { ChainId as O, createCROSSxSDK as _ } from "@nexus-cross/crossx-sdk-core";
|
|
3
|
+
function v(s) {
|
|
4
4
|
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function m(s) {
|
|
7
7
|
return `eip155:${s}`;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function A(s) {
|
|
10
10
|
return "0x" + s.toString(16);
|
|
11
11
|
}
|
|
12
|
-
class
|
|
13
|
-
constructor(e,
|
|
14
|
-
this.sdk = e, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof
|
|
15
|
-
this.setWalletIndex(
|
|
12
|
+
class W {
|
|
13
|
+
constructor(e, c = O.CROSS_MAINNET) {
|
|
14
|
+
this.sdk = e, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof c == "number" ? c : v(c), this.sdk.on("addressChanged", ({ address: i, index: r }) => {
|
|
15
|
+
this.setWalletIndex(r), this.notifyAccountsChanged([i]);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -20,9 +20,9 @@ class R {
|
|
|
20
20
|
this.walletIndexChangeCallback = e;
|
|
21
21
|
}
|
|
22
22
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
23
|
-
async request({ method: e, params:
|
|
24
|
-
var
|
|
25
|
-
const
|
|
23
|
+
async request({ method: e, params: c }) {
|
|
24
|
+
var r;
|
|
25
|
+
const i = c ?? [];
|
|
26
26
|
switch (e) {
|
|
27
27
|
case "eth_requestAccounts":
|
|
28
28
|
case "eth_accounts": {
|
|
@@ -32,21 +32,21 @@ class R {
|
|
|
32
32
|
return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():", t == null ? void 0 : t.address), t ? [t.address] : [];
|
|
33
33
|
}
|
|
34
34
|
case "eth_chainId":
|
|
35
|
-
return
|
|
35
|
+
return A(this.chainId);
|
|
36
36
|
case "net_version":
|
|
37
37
|
return String(this.chainId);
|
|
38
38
|
case "personal_sign": {
|
|
39
|
-
const [t] =
|
|
39
|
+
const [t] = i;
|
|
40
40
|
return (await this.sdk.signMessage(
|
|
41
|
-
|
|
41
|
+
m(this.chainId),
|
|
42
42
|
t,
|
|
43
43
|
{ index: this.walletIndex }
|
|
44
44
|
)).signature;
|
|
45
45
|
}
|
|
46
46
|
case "eth_sign": {
|
|
47
|
-
const [, t] =
|
|
47
|
+
const [, t] = i;
|
|
48
48
|
return (await this.sdk.signMessage(
|
|
49
|
-
|
|
49
|
+
m(this.chainId),
|
|
50
50
|
t,
|
|
51
51
|
{ index: this.walletIndex }
|
|
52
52
|
)).signature;
|
|
@@ -54,11 +54,11 @@ class R {
|
|
|
54
54
|
case "eth_signTypedData":
|
|
55
55
|
case "eth_signTypedData_v3":
|
|
56
56
|
case "eth_signTypedData_v4": {
|
|
57
|
-
const [, t] =
|
|
58
|
-
return (
|
|
57
|
+
const [, t] = i, a = typeof t == "string" ? JSON.parse(t) : t, C = (r = a == null ? void 0 : a.domain) == null ? void 0 : r.chainId, l = C == null || C === 0, h = l ? 0 : Number(C), n = { index: this.walletIndex };
|
|
58
|
+
return (l ? await this.sdk.signTypedDataOffchain(a, n) : await this.sdk.signTypedData(m(h), a, n)).signature;
|
|
59
59
|
}
|
|
60
60
|
case "eth_sendTransaction": {
|
|
61
|
-
const [t] =
|
|
61
|
+
const [t] = i, a = m(this.chainId);
|
|
62
62
|
return (await this.sdk.sendTransaction(a, {
|
|
63
63
|
from: t.from,
|
|
64
64
|
to: t.to,
|
|
@@ -73,26 +73,26 @@ class R {
|
|
|
73
73
|
}, { index: this.walletIndex })).txHash;
|
|
74
74
|
}
|
|
75
75
|
case "wallet_switchEthereumChain": {
|
|
76
|
-
const [{ chainId: t }] =
|
|
77
|
-
return a !== this.chainId && (this.chainId = a, this.emit("chainChanged",
|
|
76
|
+
const [{ chainId: t }] = i, a = parseInt(t, 16);
|
|
77
|
+
return a !== this.chainId && (this.chainId = a, this.emit("chainChanged", A(a))), null;
|
|
78
78
|
}
|
|
79
79
|
case "wallet_addEthereumChain":
|
|
80
80
|
return null;
|
|
81
81
|
default:
|
|
82
|
-
return this.sdk.walletRpc(e,
|
|
82
|
+
return this.sdk.walletRpc(e, i, m(this.chainId));
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
86
|
-
on(e,
|
|
87
|
-
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(
|
|
86
|
+
on(e, c) {
|
|
87
|
+
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(c), this;
|
|
88
88
|
}
|
|
89
|
-
removeListener(e,
|
|
90
|
-
var
|
|
91
|
-
return (
|
|
89
|
+
removeListener(e, c) {
|
|
90
|
+
var i;
|
|
91
|
+
return (i = this.listeners.get(e)) == null || i.delete(c), this;
|
|
92
92
|
}
|
|
93
|
-
emit(e, ...
|
|
94
|
-
var
|
|
95
|
-
(
|
|
93
|
+
emit(e, ...c) {
|
|
94
|
+
var i;
|
|
95
|
+
(i = this.listeners.get(e)) == null || i.forEach((r) => r(...c));
|
|
96
96
|
}
|
|
97
97
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
98
98
|
notifyAccountsChanged(e) {
|
|
@@ -105,15 +105,15 @@ class R {
|
|
|
105
105
|
return this.chainId;
|
|
106
106
|
}
|
|
107
107
|
setChainId(e) {
|
|
108
|
-
e !== this.chainId && (this.chainId = e, this.emit("chainChanged",
|
|
108
|
+
e !== this.chainId && (this.chainId = e, this.emit("chainChanged", A(e)));
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* 활성 지갑 인덱스 설정.
|
|
112
112
|
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
113
113
|
*/
|
|
114
114
|
setWalletIndex(e) {
|
|
115
|
-
var
|
|
116
|
-
console.log("[CROSSx-debug] provider.setWalletIndex:", e), this.walletIndex = e, (
|
|
115
|
+
var c;
|
|
116
|
+
console.log("[CROSSx-debug] provider.setWalletIndex:", e), this.walletIndex = e, (c = this.walletIndexChangeCallback) == null || c.call(this, e);
|
|
117
117
|
}
|
|
118
118
|
getWalletIndex() {
|
|
119
119
|
return this.walletIndex;
|
|
@@ -122,99 +122,121 @@ class R {
|
|
|
122
122
|
return [...this.currentAccounts];
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function D(s) {
|
|
126
126
|
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
127
127
|
}
|
|
128
|
-
const
|
|
129
|
-
function
|
|
128
|
+
const y = "crossx-wallet-index";
|
|
129
|
+
function P() {
|
|
130
130
|
try {
|
|
131
|
-
const s = typeof window < "u" ? localStorage.getItem(
|
|
131
|
+
const s = typeof window < "u" ? localStorage.getItem(y) : null;
|
|
132
132
|
return s && Number(s) || 0;
|
|
133
133
|
} catch {
|
|
134
134
|
return 0;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
function
|
|
137
|
+
function T(s) {
|
|
138
138
|
try {
|
|
139
|
-
typeof window < "u" && localStorage.setItem(
|
|
139
|
+
typeof window < "u" && localStorage.setItem(y, String(s));
|
|
140
140
|
} catch {
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function E() {
|
|
144
144
|
try {
|
|
145
|
-
typeof window < "u" && localStorage.removeItem(
|
|
145
|
+
typeof window < "u" && localStorage.removeItem(y);
|
|
146
146
|
} catch {
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
const { defaultChainId: e, getStoredWalletIndex:
|
|
151
|
-
return
|
|
149
|
+
function z(s) {
|
|
150
|
+
const { defaultChainId: e, getStoredWalletIndex: c, onWalletIndexChanged: i, ...r } = s, t = _(r);
|
|
151
|
+
return N({ sdk: t, defaultChainId: e, getStoredWalletIndex: c, onWalletIndexChanged: i });
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function N(s) {
|
|
154
154
|
const {
|
|
155
155
|
sdk: e,
|
|
156
|
-
defaultChainId:
|
|
157
|
-
getStoredWalletIndex:
|
|
158
|
-
onWalletIndexChanged:
|
|
159
|
-
} = s, t =
|
|
160
|
-
let a = null,
|
|
161
|
-
function
|
|
162
|
-
return a || (a = new
|
|
163
|
-
}
|
|
164
|
-
return
|
|
156
|
+
defaultChainId: c = O.CROSS_MAINNET,
|
|
157
|
+
getStoredWalletIndex: i = P,
|
|
158
|
+
onWalletIndexChanged: r = T
|
|
159
|
+
} = s, t = D(c);
|
|
160
|
+
let a = null, C = !1;
|
|
161
|
+
function l() {
|
|
162
|
+
return a || (a = new W(e, t), a._setWalletIndexChangeCallback(r)), a;
|
|
163
|
+
}
|
|
164
|
+
return k((h) => ({
|
|
165
165
|
id: "crossx",
|
|
166
166
|
name: "CROSSx Wallet",
|
|
167
167
|
type: "crossx",
|
|
168
168
|
async setup() {
|
|
169
|
-
console.log("[CROSSx-debug] connector.setup() 시작"),
|
|
170
|
-
const n =
|
|
169
|
+
console.log("[CROSSx-debug] connector.setup() 시작"), C || (await e.initialize(), C = !0), console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:", e.isAuthenticated());
|
|
170
|
+
const n = l();
|
|
171
171
|
n.on("accountsChanged", this.onAccountsChanged.bind(this)), n.on("chainChanged", this.onChainChanged.bind(this)), n.on("disconnect", this.onDisconnect.bind(this)), console.log("[CROSSx-debug] connector.setup() 완료, 이벤트 리스너 등록됨");
|
|
172
172
|
},
|
|
173
173
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
174
|
-
async connect({ chainId: n, isReconnecting:
|
|
175
|
-
console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting:
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
179
|
-
console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex:
|
|
180
|
-
const
|
|
181
|
-
if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address:
|
|
182
|
-
return
|
|
183
|
-
accounts: [
|
|
184
|
-
chainId:
|
|
174
|
+
async connect({ chainId: n, isReconnecting: g } = {}) {
|
|
175
|
+
console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting: g, targetChainId: n });
|
|
176
|
+
const o = l(), x = n ?? t;
|
|
177
|
+
if (g || e.isAuthenticated()) {
|
|
178
|
+
const d = i();
|
|
179
|
+
console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex: d, isAuth: e.isAuthenticated() });
|
|
180
|
+
const u = await e.getAddress(d || void 0);
|
|
181
|
+
if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address: u == null ? void 0 : u.address, index: u == null ? void 0 : u.index, requestedIndex: d || void 0 }), u)
|
|
182
|
+
return o.setWalletIndex(d), o.notifyAccountsChanged([u.address]), console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:", u.address), {
|
|
183
|
+
accounts: [u.address],
|
|
184
|
+
chainId: x
|
|
185
185
|
};
|
|
186
|
-
|
|
186
|
+
if (e.isAuthenticated()) {
|
|
187
|
+
console.log("[CROSSx-debug] connector.connect() 캐시 없음 — getAddresses() 재시도");
|
|
188
|
+
try {
|
|
189
|
+
const f = await e.getAddresses();
|
|
190
|
+
if (f.length > 0) {
|
|
191
|
+
const w = f.find((R) => R.index === d) ?? f[0];
|
|
192
|
+
return o.setWalletIndex(w.index), o.notifyAccountsChanged([w.address]), console.log("[CROSSx-debug] connector.connect() getAddresses 재시도 성공 →", w.address), {
|
|
193
|
+
accounts: [w.address],
|
|
194
|
+
chainId: x
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
} catch (f) {
|
|
198
|
+
console.warn("[CROSSx-debug] connector.connect() getAddresses 실패:", f);
|
|
199
|
+
}
|
|
200
|
+
console.log("[CROSSx-debug] connector.connect() 지갑 없음 — 로그아웃 후 신규 로그인"), await e.signOut().catch(() => {
|
|
201
|
+
}), o.notifyDisconnect();
|
|
202
|
+
}
|
|
203
|
+
console.log("[CROSSx-debug] connector.connect() 신규 로그인으로 진행");
|
|
204
|
+
}
|
|
205
|
+
let I;
|
|
206
|
+
try {
|
|
207
|
+
I = await e.signInWithCreate();
|
|
208
|
+
} catch (d) {
|
|
209
|
+
throw e.isAuthenticated() || (o.notifyDisconnect(), h.emitter.emit("disconnect")), d;
|
|
187
210
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (m.length === 0)
|
|
211
|
+
if (!I.success)
|
|
212
|
+
throw new Error(I.error ?? "CROSSx sign-in failed");
|
|
213
|
+
const S = I.address, b = I.addresses.map((d) => d.address).filter((d) => !S || d.toLowerCase() !== S.toLowerCase()), p = S ? [S, ...b] : b;
|
|
214
|
+
if (p.length === 0)
|
|
193
215
|
throw new Error("No address found after sign-in");
|
|
194
|
-
return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:",
|
|
195
|
-
accounts:
|
|
196
|
-
chainId:
|
|
216
|
+
return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:", S), o.notifyAccountsChanged(p), {
|
|
217
|
+
accounts: p,
|
|
218
|
+
chainId: x
|
|
197
219
|
};
|
|
198
220
|
},
|
|
199
221
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
200
222
|
async disconnect() {
|
|
201
|
-
const n =
|
|
202
|
-
await e.signOut(), n.notifyDisconnect(),
|
|
223
|
+
const n = l();
|
|
224
|
+
await e.signOut(), n.notifyDisconnect(), E(), r(0), h.emitter.emit("disconnect");
|
|
203
225
|
},
|
|
204
226
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
205
227
|
async getAccounts() {
|
|
206
|
-
const n =
|
|
207
|
-
if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen:
|
|
208
|
-
const
|
|
209
|
-
return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():",
|
|
228
|
+
const n = l(), g = n.getCurrentAccounts();
|
|
229
|
+
if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen: g.length, tracked: g[0], walletIndex: n.getWalletIndex() }), g.length > 0) return g;
|
|
230
|
+
const o = await e.getAddress();
|
|
231
|
+
return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():", o == null ? void 0 : o.address), o ? [o.address] : [];
|
|
210
232
|
},
|
|
211
233
|
// ── getChainId ──────────────────────────────────────────────────────────
|
|
212
234
|
async getChainId() {
|
|
213
|
-
return
|
|
235
|
+
return l().getCurrentChainId();
|
|
214
236
|
},
|
|
215
237
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
216
238
|
async getProvider({ chainId: n } = {}) {
|
|
217
|
-
return
|
|
239
|
+
return l();
|
|
218
240
|
},
|
|
219
241
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
220
242
|
async isAuthorized() {
|
|
@@ -223,11 +245,11 @@ function D(s) {
|
|
|
223
245
|
},
|
|
224
246
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
225
247
|
async switchChain({ chainId: n }) {
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
if (!
|
|
248
|
+
l().setChainId(n), h.emitter.emit("change", { chainId: n });
|
|
249
|
+
const o = h.chains.find((x) => x.id === n);
|
|
250
|
+
if (!o)
|
|
229
251
|
throw new Error(`Chain ${n} is not configured`);
|
|
230
|
-
return
|
|
252
|
+
return o;
|
|
231
253
|
},
|
|
232
254
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
233
255
|
onAccountsChanged(n) {
|
|
@@ -246,7 +268,7 @@ function D(s) {
|
|
|
246
268
|
}));
|
|
247
269
|
}
|
|
248
270
|
export {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
271
|
+
W as CROSSxEIP1193Provider,
|
|
272
|
+
N as createCROSSxConnector,
|
|
273
|
+
z as crossxConnector
|
|
252
274
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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.0
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "1.1.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|