@nexus-cross/crossx-sdk-wagmi 1.0.5 → 1.0.6
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 +81 -82
- package/dist/provider.d.ts.map +1 -1
- 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,8GA2KpE"}
|
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 R=require("wagmi"),p=require("@nexus-cross/crossx-sdk-core");function k(s){return parseInt(s.split(":")[1]??"1",10)}function x(s){return`eip155:${s}`}function w(s){return"0x"+s.toString(16)}class b{constructor(e,i=p.ChainId.CROSS_MAINNET){this.sdk=e,this.listeners=new Map,this.walletIndex=0,this.currentAccounts=[],this.off=this.removeListener.bind(this),this.chainId=typeof i=="number"?i:k(i),this.sdk.on("addressChanged",({address:c,index:o})=>{this.setWalletIndex(o),this.notifyAccountsChanged([c])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:i}){var o;const c=i??[];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 w(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=c;return(await this.sdk.signMessage(x(this.chainId),t,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=c;return(await this.sdk.signMessage(x(this.chainId),t,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=c,a=typeof t=="string"?JSON.parse(t):t,g=(o=a==null?void 0:a.domain)==null?void 0:o.chainId,d=g==null||g===0,h=d?0:Number(g),n={index:this.walletIndex};return(d?await this.sdk.signTypedDataOffchain(a,n):await this.sdk.signTypedData(x(h),a,n)).signature}case"eth_sendTransaction":{const[t]=c,a=x(this.chainId);return(await this.sdk.sendTransaction(a,{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}]=c,a=parseInt(t,16);return a!==this.chainId&&(this.chainId=a,this.emit("chainChanged",w(a))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,c,x(this.chainId))}}on(e,i){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(i),this}removeListener(e,i){var c;return(c=this.listeners.get(e))==null||c.delete(i),this}emit(e,...i){var c;(c=this.listeners.get(e))==null||c.forEach(o=>o(...i))}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",w(e)))}setWalletIndex(e){var i;console.log("[CROSSx-debug] provider.setWalletIndex:",e),this.walletIndex=e,(i=this.walletIndexChangeCallback)==null||i.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function v(s){return typeof s=="number"?s:parseInt(s.split(":")[1]??"1",10)}const A="crossx-wallet-index";function _(){try{const s=typeof window<"u"?localStorage.getItem(A):null;return s&&Number(s)||0}catch{return 0}}function W(s){try{typeof window<"u"&&localStorage.setItem(A,String(s))}catch{}}function P(){try{typeof window<"u"&&localStorage.removeItem(A)}catch{}}function T(s){const{defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:c,...o}=s,t=p.createCROSSxSDK(o);return O({sdk:t,defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:c})}function O(s){const{sdk:e,defaultChainId:i=p.ChainId.CROSS_MAINNET,getStoredWalletIndex:c=_,onWalletIndexChanged:o=W}=s,t=v(i);let a=null,g=!1;function d(){return a||(a=new b(e,t),a._setWalletIndexChangeCallback(o)),a}return R.createConnector(h=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){console.log("[CROSSx-debug] connector.setup() 시작"),g||(await e.initialize(),g=!0),console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:",e.isAuthenticated());const n=d();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:u}={}){console.log("[CROSSx-debug] connector.connect() 호출",{isReconnecting:u,targetChainId:n});const r=d(),S=n??t;if(u||e.isAuthenticated()){const C=c();console.log("[CROSSx-debug] connector.connect() 재연결 경로",{storedIndex:C,isAuth:e.isAuthenticated()});const l=await e.getAddress(C||void 0);if(console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과",{address:l==null?void 0:l.address,index:l==null?void 0:l.index,requestedIndex:C||void 0}),l)return r.setWalletIndex(C),r.notifyAccountsChanged([l.address]),console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:",l.address),{accounts:[l.address],chainId:S};console.log("[CROSSx-debug] connector.connect() 재연결 경로 — info null, 신규 로그인으로 진행")}const f=await e.signInWithCreate();if(!f.success)throw new Error(f.error??"CROSSx sign-in failed");const I=f.address,y=f.addresses.map(C=>C.address).filter(C=>!I||C.toLowerCase()!==I.toLowerCase()),m=I?[I,...y]:y;if(m.length===0)throw new Error("No address found after sign-in");return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:",I),r.notifyAccountsChanged(m),{accounts:m,chainId:S}},async disconnect(){const n=d();await e.signOut(),n.notifyDisconnect(),P(),o(0),h.emitter.emit("disconnect")},async getAccounts(){const n=d(),u=n.getCurrentAccounts();if(console.log("[CROSSx-debug] connector.getAccounts()",{trackedLen:u.length,tracked:u[0],walletIndex:n.getWalletIndex()}),u.length>0)return u;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 d().getCurrentChainId()},async getProvider({chainId:n}={}){return d()},async isAuthorized(){const n=e.isAuthenticated();return console.log("[CROSSx-debug] connector.isAuthorized():",n),n},async switchChain({chainId:n}){d().setChainId(n),h.emitter.emit("change",{chainId:n});const r=h.chains.find(S=>S.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=b;exports.createCROSSxConnector=O;exports.crossxConnector=T;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { ChainId as y, createCROSSxSDK as
|
|
3
|
-
function
|
|
1
|
+
import { createConnector as b } from "wagmi";
|
|
2
|
+
import { ChainId as y, createCROSSxSDK as O } from "@nexus-cross/crossx-sdk-core";
|
|
3
|
+
function k(s) {
|
|
4
4
|
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function x(s) {
|
|
7
7
|
return `eip155:${s}`;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function p(s) {
|
|
10
10
|
return "0x" + s.toString(16);
|
|
11
11
|
}
|
|
12
|
-
class
|
|
12
|
+
class R {
|
|
13
13
|
constructor(e, i = y.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 i == "number" ? i :
|
|
14
|
+
this.sdk = e, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof i == "number" ? i : k(i), this.sdk.on("addressChanged", ({ address: c, index: o }) => {
|
|
15
|
+
this.setWalletIndex(o), this.notifyAccountsChanged([c]);
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
18
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
17
19
|
_setWalletIndexChangeCallback(e) {
|
|
@@ -19,8 +21,8 @@ class v {
|
|
|
19
21
|
}
|
|
20
22
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
21
23
|
async request({ method: e, params: i }) {
|
|
22
|
-
var
|
|
23
|
-
const
|
|
24
|
+
var o;
|
|
25
|
+
const c = i ?? [];
|
|
24
26
|
switch (e) {
|
|
25
27
|
case "eth_requestAccounts":
|
|
26
28
|
case "eth_accounts": {
|
|
@@ -30,21 +32,21 @@ class v {
|
|
|
30
32
|
return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():", t == null ? void 0 : t.address), t ? [t.address] : [];
|
|
31
33
|
}
|
|
32
34
|
case "eth_chainId":
|
|
33
|
-
return
|
|
35
|
+
return p(this.chainId);
|
|
34
36
|
case "net_version":
|
|
35
37
|
return String(this.chainId);
|
|
36
38
|
case "personal_sign": {
|
|
37
|
-
const [t] =
|
|
39
|
+
const [t] = c;
|
|
38
40
|
return (await this.sdk.signMessage(
|
|
39
|
-
|
|
41
|
+
x(this.chainId),
|
|
40
42
|
t,
|
|
41
43
|
{ index: this.walletIndex }
|
|
42
44
|
)).signature;
|
|
43
45
|
}
|
|
44
46
|
case "eth_sign": {
|
|
45
|
-
const [, t] =
|
|
47
|
+
const [, t] = c;
|
|
46
48
|
return (await this.sdk.signMessage(
|
|
47
|
-
|
|
49
|
+
x(this.chainId),
|
|
48
50
|
t,
|
|
49
51
|
{ index: this.walletIndex }
|
|
50
52
|
)).signature;
|
|
@@ -52,12 +54,12 @@ class v {
|
|
|
52
54
|
case "eth_signTypedData":
|
|
53
55
|
case "eth_signTypedData_v3":
|
|
54
56
|
case "eth_signTypedData_v4": {
|
|
55
|
-
const [, t] =
|
|
56
|
-
return (d ? await this.sdk.signTypedDataOffchain(
|
|
57
|
+
const [, t] = c, a = typeof t == "string" ? JSON.parse(t) : t, g = (o = a == null ? void 0 : a.domain) == null ? void 0 : o.chainId, d = g == null || g === 0, h = d ? 0 : Number(g), n = { index: this.walletIndex };
|
|
58
|
+
return (d ? await this.sdk.signTypedDataOffchain(a, n) : await this.sdk.signTypedData(x(h), a, n)).signature;
|
|
57
59
|
}
|
|
58
60
|
case "eth_sendTransaction": {
|
|
59
|
-
const [t] =
|
|
60
|
-
return (await this.sdk.sendTransaction(
|
|
61
|
+
const [t] = c, a = x(this.chainId);
|
|
62
|
+
return (await this.sdk.sendTransaction(a, {
|
|
61
63
|
from: t.from,
|
|
62
64
|
to: t.to,
|
|
63
65
|
value: t.value,
|
|
@@ -71,13 +73,13 @@ class v {
|
|
|
71
73
|
}, { index: this.walletIndex })).txHash;
|
|
72
74
|
}
|
|
73
75
|
case "wallet_switchEthereumChain": {
|
|
74
|
-
const [{ chainId: t }] =
|
|
75
|
-
return
|
|
76
|
+
const [{ chainId: t }] = c, a = parseInt(t, 16);
|
|
77
|
+
return a !== this.chainId && (this.chainId = a, this.emit("chainChanged", p(a))), null;
|
|
76
78
|
}
|
|
77
79
|
case "wallet_addEthereumChain":
|
|
78
80
|
return null;
|
|
79
81
|
default:
|
|
80
|
-
return this.sdk.walletRpc(e,
|
|
82
|
+
return this.sdk.walletRpc(e, c, x(this.chainId));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
@@ -85,12 +87,12 @@ class v {
|
|
|
85
87
|
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(i), this;
|
|
86
88
|
}
|
|
87
89
|
removeListener(e, i) {
|
|
88
|
-
var
|
|
89
|
-
return (
|
|
90
|
+
var c;
|
|
91
|
+
return (c = this.listeners.get(e)) == null || c.delete(i), this;
|
|
90
92
|
}
|
|
91
93
|
emit(e, ...i) {
|
|
92
|
-
var
|
|
93
|
-
(
|
|
94
|
+
var c;
|
|
95
|
+
(c = this.listeners.get(e)) == null || c.forEach((o) => o(...i));
|
|
94
96
|
}
|
|
95
97
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
96
98
|
notifyAccountsChanged(e) {
|
|
@@ -103,7 +105,7 @@ class v {
|
|
|
103
105
|
return this.chainId;
|
|
104
106
|
}
|
|
105
107
|
setChainId(e) {
|
|
106
|
-
e !== this.chainId && (this.chainId = e, this.emit("chainChanged",
|
|
108
|
+
e !== this.chainId && (this.chainId = e, this.emit("chainChanged", p(e)));
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
109
111
|
* 활성 지갑 인덱스 설정.
|
|
@@ -120,94 +122,91 @@ class v {
|
|
|
120
122
|
return [...this.currentAccounts];
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
function
|
|
125
|
+
function _(s) {
|
|
124
126
|
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
125
127
|
}
|
|
126
|
-
const
|
|
127
|
-
function
|
|
128
|
+
const w = "crossx-wallet-index";
|
|
129
|
+
function v() {
|
|
128
130
|
try {
|
|
129
|
-
const s = typeof window < "u" ? localStorage.getItem(
|
|
131
|
+
const s = typeof window < "u" ? localStorage.getItem(w) : null;
|
|
130
132
|
return s && Number(s) || 0;
|
|
131
133
|
} catch {
|
|
132
134
|
return 0;
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
function
|
|
137
|
+
function W(s) {
|
|
136
138
|
try {
|
|
137
|
-
typeof window < "u" && localStorage.setItem(
|
|
139
|
+
typeof window < "u" && localStorage.setItem(w, String(s));
|
|
138
140
|
} catch {
|
|
139
141
|
}
|
|
140
142
|
}
|
|
141
|
-
function
|
|
143
|
+
function P() {
|
|
142
144
|
try {
|
|
143
|
-
typeof window < "u" && localStorage.removeItem(
|
|
145
|
+
typeof window < "u" && localStorage.removeItem(w);
|
|
144
146
|
} catch {
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
|
-
function G(s) {
|
|
148
|
-
const { defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: a, ...r } = s, t = k(r);
|
|
149
|
-
return N({ sdk: t, defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: a });
|
|
150
|
-
}
|
|
151
149
|
function N(s) {
|
|
150
|
+
const { defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: c, ...o } = s, t = O(o);
|
|
151
|
+
return D({ sdk: t, defaultChainId: e, getStoredWalletIndex: i, onWalletIndexChanged: c });
|
|
152
|
+
}
|
|
153
|
+
function D(s) {
|
|
152
154
|
const {
|
|
153
155
|
sdk: e,
|
|
154
156
|
defaultChainId: i = y.CROSS_MAINNET,
|
|
155
|
-
getStoredWalletIndex:
|
|
156
|
-
onWalletIndexChanged:
|
|
157
|
-
} = s, t =
|
|
158
|
-
let
|
|
157
|
+
getStoredWalletIndex: c = v,
|
|
158
|
+
onWalletIndexChanged: o = W
|
|
159
|
+
} = s, t = _(i);
|
|
160
|
+
let a = null, g = !1;
|
|
159
161
|
function d() {
|
|
160
|
-
return
|
|
162
|
+
return a || (a = new R(e, t), a._setWalletIndexChangeCallback(o)), a;
|
|
161
163
|
}
|
|
162
|
-
return
|
|
164
|
+
return b((h) => ({
|
|
163
165
|
id: "crossx",
|
|
164
166
|
name: "CROSSx Wallet",
|
|
165
167
|
type: "crossx",
|
|
166
168
|
async setup() {
|
|
167
|
-
console.log("[CROSSx-debug] connector.setup() 시작"),
|
|
169
|
+
console.log("[CROSSx-debug] connector.setup() 시작"), g || (await e.initialize(), g = !0), console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:", e.isAuthenticated());
|
|
168
170
|
const n = d();
|
|
169
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() 완료, 이벤트 리스너 등록됨");
|
|
170
172
|
},
|
|
171
173
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
172
|
-
async connect({ chainId: n, isReconnecting:
|
|
173
|
-
console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting:
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
176
|
-
const
|
|
177
|
-
console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex:
|
|
178
|
-
const
|
|
179
|
-
if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address:
|
|
180
|
-
return
|
|
181
|
-
accounts: [
|
|
182
|
-
chainId:
|
|
174
|
+
async connect({ chainId: n, isReconnecting: u } = {}) {
|
|
175
|
+
console.log("[CROSSx-debug] connector.connect() 호출", { isReconnecting: u, targetChainId: n });
|
|
176
|
+
const r = d(), S = n ?? t;
|
|
177
|
+
if (u || e.isAuthenticated()) {
|
|
178
|
+
const C = c();
|
|
179
|
+
console.log("[CROSSx-debug] connector.connect() 재연결 경로", { storedIndex: C, isAuth: e.isAuthenticated() });
|
|
180
|
+
const l = await e.getAddress(C || void 0);
|
|
181
|
+
if (console.log("[CROSSx-debug] connector.connect() sdk.getAddress 결과", { address: l == null ? void 0 : l.address, index: l == null ? void 0 : l.index, requestedIndex: C || void 0 }), l)
|
|
182
|
+
return r.setWalletIndex(C), r.notifyAccountsChanged([l.address]), console.log("[CROSSx-debug] connector.connect() 재연결 완료 → 반환 address:", l.address), {
|
|
183
|
+
accounts: [l.address],
|
|
184
|
+
chainId: S
|
|
183
185
|
};
|
|
184
186
|
console.log("[CROSSx-debug] connector.connect() 재연결 경로 — info null, 신규 로그인으로 진행");
|
|
185
187
|
}
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
188
|
-
throw new Error(
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
188
|
+
const f = await e.signInWithCreate();
|
|
189
|
+
if (!f.success)
|
|
190
|
+
throw new Error(f.error ?? "CROSSx sign-in failed");
|
|
191
|
+
const I = f.address, A = f.addresses.map((C) => C.address).filter((C) => !I || C.toLowerCase() !== I.toLowerCase()), m = I ? [I, ...A] : A;
|
|
192
|
+
if (m.length === 0)
|
|
191
193
|
throw new Error("No address found after sign-in");
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return console.log("[CROSSx-debug] connector.connect() signIn 완료, selected:", { address: C, index: p }), o.setWalletIndex(p), r(p), o.notifyAccountsChanged(w), {
|
|
196
|
-
accounts: w,
|
|
197
|
-
chainId: f
|
|
194
|
+
return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:", I), r.notifyAccountsChanged(m), {
|
|
195
|
+
accounts: m,
|
|
196
|
+
chainId: S
|
|
198
197
|
};
|
|
199
198
|
},
|
|
200
199
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
201
200
|
async disconnect() {
|
|
202
201
|
const n = d();
|
|
203
|
-
await e.signOut(), n.notifyDisconnect(),
|
|
202
|
+
await e.signOut(), n.notifyDisconnect(), P(), o(0), h.emitter.emit("disconnect");
|
|
204
203
|
},
|
|
205
204
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
206
205
|
async getAccounts() {
|
|
207
|
-
const n = d(),
|
|
208
|
-
if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen:
|
|
209
|
-
const
|
|
210
|
-
return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():",
|
|
206
|
+
const n = d(), u = n.getCurrentAccounts();
|
|
207
|
+
if (console.log("[CROSSx-debug] connector.getAccounts()", { trackedLen: u.length, tracked: u[0], walletIndex: n.getWalletIndex() }), u.length > 0) return u;
|
|
208
|
+
const r = await e.getAddress();
|
|
209
|
+
return console.log("[CROSSx-debug] connector.getAccounts() fallback sdk.getAddress():", r == null ? void 0 : r.address), r ? [r.address] : [];
|
|
211
210
|
},
|
|
212
211
|
// ── getChainId ──────────────────────────────────────────────────────────
|
|
213
212
|
async getChainId() {
|
|
@@ -224,30 +223,30 @@ function N(s) {
|
|
|
224
223
|
},
|
|
225
224
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
226
225
|
async switchChain({ chainId: n }) {
|
|
227
|
-
d().setChainId(n),
|
|
228
|
-
const
|
|
229
|
-
if (!
|
|
226
|
+
d().setChainId(n), h.emitter.emit("change", { chainId: n });
|
|
227
|
+
const r = h.chains.find((S) => S.id === n);
|
|
228
|
+
if (!r)
|
|
230
229
|
throw new Error(`Chain ${n} is not configured`);
|
|
231
|
-
return
|
|
230
|
+
return r;
|
|
232
231
|
},
|
|
233
232
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
234
233
|
onAccountsChanged(n) {
|
|
235
|
-
console.log("[CROSSx-debug] connector.onAccountsChanged:", n), n.length === 0 ?
|
|
234
|
+
console.log("[CROSSx-debug] connector.onAccountsChanged:", n), n.length === 0 ? h.emitter.emit("disconnect") : h.emitter.emit("change", {
|
|
236
235
|
accounts: n
|
|
237
236
|
});
|
|
238
237
|
},
|
|
239
238
|
onChainChanged(n) {
|
|
240
|
-
|
|
239
|
+
h.emitter.emit("change", {
|
|
241
240
|
chainId: Number(n)
|
|
242
241
|
});
|
|
243
242
|
},
|
|
244
243
|
onDisconnect() {
|
|
245
|
-
|
|
244
|
+
h.emitter.emit("disconnect");
|
|
246
245
|
}
|
|
247
246
|
}));
|
|
248
247
|
}
|
|
249
248
|
export {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
R as CROSSxEIP1193Provider,
|
|
250
|
+
D as createCROSSxConnector,
|
|
251
|
+
N as crossxConnector
|
|
253
252
|
};
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE9C,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC;CACtC;AAcD,qBAAa,qBAAqB;IAQ9B,QAAQ,CAAC,GAAG,EAAE,SAAS;IAPzB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,yBAAyB,CAAC,CAA0B;gBAGjD,GAAG,EAAE,SAAS,EACvB,cAAc,GAAE,MAAM,GAAG,MAA8B;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAE9C,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC;CACtC;AAcD,qBAAa,qBAAqB;IAQ9B,QAAQ,CAAC,GAAG,EAAE,SAAS;IAPzB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,yBAAyB,CAAC,CAA0B;gBAGjD,GAAG,EAAE,SAAS,EACvB,cAAc,GAAE,MAAM,GAAG,MAA8B;IAazD,2CAA2C;IAC3C,6BAA6B,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAM1D,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC;IAqG5E,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAQhD,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI;IAK5D,GAAG,UALmB,MAAM,YAAY,aAAa,KAAG,IAAI,CAKvB;IAErC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM7C,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAM/C,gBAAgB,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAMrC,iBAAiB,IAAI,MAAM;IAI3B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAO5B;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMnC,cAAc,IAAI,MAAM;IAIxB,kBAAkB,IAAI,MAAM,EAAE;CAG/B"}
|
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.0.6",
|
|
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.0.6"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|