@nexus-cross/crossx-sdk-wagmi 1.2.6 → 1.2.7
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/index.cjs +1 -1
- package/dist/index.js +99 -89
- package/dist/provider.d.ts +1 -0
- package/dist/provider.d.ts.map +1 -1
- package/package.json +2 -2
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"),y=require("@nexus-cross/crossx-sdk-core");function P(a){return parseInt(a.split(":")[1]??"1",10)}function m(a){return`eip155:${a}`}function _(a){return"0x"+a.toString(16)}class b{constructor(t,s=y.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:P(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 y.CROSSxError&&n.code===y.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 _(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=n;return(await this.sdk.signMessage(m(this.chainId),e,{index:this.walletIndex})).signature}case"eth_sign":{const[,e]=n;return(await this.sdk.signMessage(m(this.chainId),e,{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,u=(o=r==null?void 0:r.domain)==null?void 0:o.chainId,I=u==null||u===0,h=I?0:Number(u),d={index:this.walletIndex};return(I?await this.sdk.signTypedDataOffchain(r,d):await this.sdk.signTypedData(m(h),r,d)).signature}case"eth_sendTransaction":{const[e]=n,r=m(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",_(r))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,n,m(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",_(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 D(a){return typeof a=="number"?a:parseInt(a.split(":")[1]??"1",10)}const E="crossx-wallet-index";function T(){try{const a=typeof window<"u"?localStorage.getItem(E):null;return a&&Number(a)||0}catch{return 0}}function N(a){try{typeof window<"u"&&localStorage.setItem(E,String(a))}catch{}}function L(){try{typeof window<"u"&&localStorage.removeItem(E)}catch{}}function q(a){const{defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n,...o}=a,e=y.createCROSSxSDK(o);return k({sdk:e,defaultChainId:t,getStoredWalletIndex:s,onWalletIndexChanged:n})}function k(a){const{sdk:t,defaultChainId:s=y.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=T,onWalletIndexChanged:o=N}=a,e=D(s);let r=null,u=!1,I=!1;function h(){return r||(r=new b(t,e),r._setWalletIndexChangeCallback(o)),r}return R.createConnector(d=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){if(!u){const g=n();await t.initialize({preferredWalletIndex:g}),u=!0,t.on("addressChanged",({address:c,index:C})=>{if(I)return;const w=h();w.setWalletIndex(C),c&&w.notifyAccountsChanged([c])})}const i=h();i.on("accountsChanged",this.onAccountsChanged.bind(this)),i.on("chainChanged",this.onChainChanged.bind(this)),i.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:i,isReconnecting:g}={}){var w;const c=h(),C=i??e;I=!0;try{if(g||t.isAuthenticated()){const l=n();if(t.isAuthenticated()){try{const S=await t.getAddresses();if(S.length>0){const A=S.find(v=>v.index===l)??S[0];return c.setWalletIndex(A.index),c.notifyAccountsChanged([A.address]),{accounts:[A.address],chainId:C}}}catch{}await t.signOut().catch(()=>{}),c.notifyDisconnect()}}let f;try{f=await t.signInWithCreate()}catch(l){throw t.isAuthenticated()||(c.notifyDisconnect(),d.emitter.emit("disconnect")),l}if(!f.success)throw new Error(f.error??"CROSSx sign-in failed");const x=f.address,O=f.addresses.map(l=>l.address).filter(l=>!x||l.toLowerCase()!==x.toLowerCase()),p=x?[x,...O]:O;if(p.length===0)throw new Error("No address found after sign-in");const W=((w=f.addresses.find(l=>x&&l.address.toLowerCase()===x.toLowerCase()))==null?void 0:w.index)??0;return c.setWalletIndex(W),c.notifyAccountsChanged(p),{accounts:p,chainId:C}}finally{I=!1}},async disconnect(){const i=h();await t.signOut(),i.notifyDisconnect(),L(),o(0),d.emitter.emit("disconnect")},async getAccounts(){const g=h().getCurrentAccounts();if(g.length>0)return g;const c=await t.getAddress();return c?[c.address]:[]},async getChainId(){return h().getCurrentChainId()},async getProvider({chainId:i}={}){return h()},async isAuthorized(){return await t.whenReady(),t.isAuthenticated()},async switchChain({chainId:i}){h().setChainId(i),d.emitter.emit("change",{chainId:i});const c=d.chains.find(C=>C.id===i);if(!c)throw new Error(`Chain ${i} is not configured`);return c},onAccountsChanged(i){i.length===0?d.emitter.emit("disconnect"):d.emitter.emit("change",{accounts:i})},onChainChanged(i){d.emitter.emit("change",{chainId:Number(i)})},onDisconnect(){d.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=b;exports.createCROSSxConnector=k;exports.crossxConnector=q;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { ChainId as
|
|
3
|
-
function P(
|
|
4
|
-
return parseInt(
|
|
1
|
+
import { createConnector as b } from "wagmi";
|
|
2
|
+
import { ChainId as k, CROSSxError as v, ErrorCode as R, createCROSSxSDK as D } from "@nexus-cross/crossx-sdk-core";
|
|
3
|
+
function P(a) {
|
|
4
|
+
return parseInt(a.split(":")[1] ?? "1", 10);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
return `eip155:${
|
|
6
|
+
function m(a) {
|
|
7
|
+
return `eip155:${a}`;
|
|
8
8
|
}
|
|
9
|
-
function A(
|
|
10
|
-
return "0x" +
|
|
9
|
+
function A(a) {
|
|
10
|
+
return "0x" + a.toString(16);
|
|
11
11
|
}
|
|
12
12
|
class T {
|
|
13
|
-
constructor(t,
|
|
14
|
-
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof
|
|
15
|
-
this.setWalletIndex(
|
|
13
|
+
constructor(t, s = k.CROSS_MAINNET) {
|
|
14
|
+
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 : P(s), this.sdk.on("addressChanged", ({ address: n, index: o }) => {
|
|
15
|
+
this.setWalletIndex(o), this.notifyAccountsChanged([n]);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -20,9 +20,19 @@ class T {
|
|
|
20
20
|
this.walletIndexChangeCallback = t;
|
|
21
21
|
}
|
|
22
22
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
23
|
-
async request({ method: t, params:
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
async request({ method: t, params: s }) {
|
|
24
|
+
try {
|
|
25
|
+
return await this._handleRequest(t, s);
|
|
26
|
+
} catch (n) {
|
|
27
|
+
throw n instanceof v && n.code === R.USER_REJECTED ? Object.assign(
|
|
28
|
+
new Error("User rejected the request"),
|
|
29
|
+
{ code: 4001, data: n.details }
|
|
30
|
+
) : n;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async _handleRequest(t, s) {
|
|
34
|
+
var o;
|
|
35
|
+
const n = s ?? [];
|
|
26
36
|
switch (t) {
|
|
27
37
|
case "eth_requestAccounts":
|
|
28
38
|
case "eth_accounts": {
|
|
@@ -36,17 +46,17 @@ class T {
|
|
|
36
46
|
case "net_version":
|
|
37
47
|
return String(this.chainId);
|
|
38
48
|
case "personal_sign": {
|
|
39
|
-
const [e] =
|
|
49
|
+
const [e] = n;
|
|
40
50
|
return (await this.sdk.signMessage(
|
|
41
|
-
|
|
51
|
+
m(this.chainId),
|
|
42
52
|
e,
|
|
43
53
|
{ index: this.walletIndex }
|
|
44
54
|
)).signature;
|
|
45
55
|
}
|
|
46
56
|
case "eth_sign": {
|
|
47
|
-
const [, e] =
|
|
57
|
+
const [, e] = n;
|
|
48
58
|
return (await this.sdk.signMessage(
|
|
49
|
-
|
|
59
|
+
m(this.chainId),
|
|
50
60
|
e,
|
|
51
61
|
{ index: this.walletIndex }
|
|
52
62
|
)).signature;
|
|
@@ -54,11 +64,11 @@ class T {
|
|
|
54
64
|
case "eth_signTypedData":
|
|
55
65
|
case "eth_signTypedData_v3":
|
|
56
66
|
case "eth_signTypedData_v4": {
|
|
57
|
-
const [, e] =
|
|
58
|
-
return (
|
|
67
|
+
const [, e] = n, r = typeof e == "string" ? JSON.parse(e) : e, u = (o = r == null ? void 0 : r.domain) == null ? void 0 : o.chainId, f = u == null || u === 0, h = f ? 0 : Number(u), d = { index: this.walletIndex };
|
|
68
|
+
return (f ? await this.sdk.signTypedDataOffchain(r, d) : await this.sdk.signTypedData(m(h), r, d)).signature;
|
|
59
69
|
}
|
|
60
70
|
case "eth_sendTransaction": {
|
|
61
|
-
const [e] =
|
|
71
|
+
const [e] = n, r = m(this.chainId);
|
|
62
72
|
return (await this.sdk.sendTransaction(r, {
|
|
63
73
|
from: e.from,
|
|
64
74
|
to: e.to,
|
|
@@ -73,26 +83,26 @@ class T {
|
|
|
73
83
|
}, { index: this.walletIndex })).txHash;
|
|
74
84
|
}
|
|
75
85
|
case "wallet_switchEthereumChain": {
|
|
76
|
-
const [{ chainId: e }] =
|
|
86
|
+
const [{ chainId: e }] = n, r = parseInt(e, 16);
|
|
77
87
|
return r !== this.chainId && (this.chainId = r, this.emit("chainChanged", A(r))), null;
|
|
78
88
|
}
|
|
79
89
|
case "wallet_addEthereumChain":
|
|
80
90
|
return null;
|
|
81
91
|
default:
|
|
82
|
-
return this.sdk.walletRpc(t,
|
|
92
|
+
return this.sdk.walletRpc(t, n, m(this.chainId));
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
95
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
86
|
-
on(t,
|
|
87
|
-
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(
|
|
96
|
+
on(t, s) {
|
|
97
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(s), this;
|
|
88
98
|
}
|
|
89
|
-
removeListener(t,
|
|
90
|
-
var
|
|
91
|
-
return (
|
|
99
|
+
removeListener(t, s) {
|
|
100
|
+
var n;
|
|
101
|
+
return (n = this.listeners.get(t)) == null || n.delete(s), this;
|
|
92
102
|
}
|
|
93
|
-
emit(t, ...
|
|
94
|
-
var
|
|
95
|
-
(
|
|
103
|
+
emit(t, ...s) {
|
|
104
|
+
var n;
|
|
105
|
+
(n = this.listeners.get(t)) == null || n.forEach((o) => o(...s));
|
|
96
106
|
}
|
|
97
107
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
98
108
|
notifyAccountsChanged(t) {
|
|
@@ -112,8 +122,8 @@ class T {
|
|
|
112
122
|
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
113
123
|
*/
|
|
114
124
|
setWalletIndex(t) {
|
|
115
|
-
var
|
|
116
|
-
this.walletIndex = t, (
|
|
125
|
+
var s;
|
|
126
|
+
this.walletIndex = t, (s = this.walletIndexChangeCallback) == null || s.call(this, t);
|
|
117
127
|
}
|
|
118
128
|
getWalletIndex() {
|
|
119
129
|
return this.walletIndex;
|
|
@@ -122,77 +132,77 @@ class T {
|
|
|
122
132
|
return [...this.currentAccounts];
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
|
-
function
|
|
126
|
-
return typeof
|
|
135
|
+
function N(a) {
|
|
136
|
+
return typeof a == "number" ? a : parseInt(a.split(":")[1] ?? "1", 10);
|
|
127
137
|
}
|
|
128
138
|
const _ = "crossx-wallet-index";
|
|
129
|
-
function
|
|
139
|
+
function L() {
|
|
130
140
|
try {
|
|
131
|
-
const
|
|
132
|
-
return
|
|
141
|
+
const a = typeof window < "u" ? localStorage.getItem(_) : null;
|
|
142
|
+
return a && Number(a) || 0;
|
|
133
143
|
} catch {
|
|
134
144
|
return 0;
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
|
-
function
|
|
147
|
+
function G(a) {
|
|
138
148
|
try {
|
|
139
|
-
typeof window < "u" && localStorage.setItem(_, String(
|
|
149
|
+
typeof window < "u" && localStorage.setItem(_, String(a));
|
|
140
150
|
} catch {
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
|
-
function
|
|
153
|
+
function q() {
|
|
144
154
|
try {
|
|
145
155
|
typeof window < "u" && localStorage.removeItem(_);
|
|
146
156
|
} catch {
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
|
-
function
|
|
150
|
-
const { defaultChainId: t, getStoredWalletIndex:
|
|
151
|
-
return
|
|
159
|
+
function j(a) {
|
|
160
|
+
const { defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n, ...o } = a, e = D(o);
|
|
161
|
+
return M({ sdk: e, defaultChainId: t, getStoredWalletIndex: s, onWalletIndexChanged: n });
|
|
152
162
|
}
|
|
153
|
-
function
|
|
163
|
+
function M(a) {
|
|
154
164
|
const {
|
|
155
165
|
sdk: t,
|
|
156
|
-
defaultChainId:
|
|
157
|
-
getStoredWalletIndex:
|
|
158
|
-
onWalletIndexChanged:
|
|
159
|
-
} =
|
|
160
|
-
let r = null, u = !1,
|
|
166
|
+
defaultChainId: s = k.CROSS_MAINNET,
|
|
167
|
+
getStoredWalletIndex: n = L,
|
|
168
|
+
onWalletIndexChanged: o = G
|
|
169
|
+
} = a, e = N(s);
|
|
170
|
+
let r = null, u = !1, f = !1;
|
|
161
171
|
function h() {
|
|
162
|
-
return r || (r = new T(t, e), r._setWalletIndexChangeCallback(
|
|
172
|
+
return r || (r = new T(t, e), r._setWalletIndexChangeCallback(o)), r;
|
|
163
173
|
}
|
|
164
|
-
return
|
|
174
|
+
return b((d) => ({
|
|
165
175
|
id: "crossx",
|
|
166
176
|
name: "CROSSx Wallet",
|
|
167
177
|
type: "crossx",
|
|
168
178
|
async setup() {
|
|
169
179
|
if (!u) {
|
|
170
|
-
const g =
|
|
171
|
-
await t.initialize({ preferredWalletIndex: g }), u = !0, t.on("addressChanged", ({ address: c, index:
|
|
172
|
-
if (
|
|
173
|
-
const
|
|
174
|
-
|
|
180
|
+
const g = n();
|
|
181
|
+
await t.initialize({ preferredWalletIndex: g }), u = !0, t.on("addressChanged", ({ address: c, index: I }) => {
|
|
182
|
+
if (f) return;
|
|
183
|
+
const w = h();
|
|
184
|
+
w.setWalletIndex(I), c && w.notifyAccountsChanged([c]);
|
|
175
185
|
});
|
|
176
186
|
}
|
|
177
|
-
const
|
|
178
|
-
|
|
187
|
+
const i = h();
|
|
188
|
+
i.on("accountsChanged", this.onAccountsChanged.bind(this)), i.on("chainChanged", this.onChainChanged.bind(this)), i.on("disconnect", this.onDisconnect.bind(this));
|
|
179
189
|
},
|
|
180
190
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
181
|
-
async connect({ chainId:
|
|
182
|
-
var
|
|
183
|
-
const c = h(),
|
|
184
|
-
|
|
191
|
+
async connect({ chainId: i, isReconnecting: g } = {}) {
|
|
192
|
+
var w;
|
|
193
|
+
const c = h(), I = i ?? e;
|
|
194
|
+
f = !0;
|
|
185
195
|
try {
|
|
186
196
|
if (g || t.isAuthenticated()) {
|
|
187
|
-
const l =
|
|
197
|
+
const l = n();
|
|
188
198
|
if (t.isAuthenticated()) {
|
|
189
199
|
try {
|
|
190
200
|
const y = await t.getAddresses();
|
|
191
201
|
if (y.length > 0) {
|
|
192
|
-
const S = y.find((
|
|
202
|
+
const S = y.find((W) => W.index === l) ?? y[0];
|
|
193
203
|
return c.setWalletIndex(S.index), c.notifyAccountsChanged([S.address]), {
|
|
194
204
|
accounts: [S.address],
|
|
195
|
-
chainId:
|
|
205
|
+
chainId: I
|
|
196
206
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
197
207
|
};
|
|
198
208
|
}
|
|
@@ -206,29 +216,29 @@ function G(s) {
|
|
|
206
216
|
try {
|
|
207
217
|
C = await t.signInWithCreate();
|
|
208
218
|
} catch (l) {
|
|
209
|
-
throw t.isAuthenticated() || (c.notifyDisconnect(),
|
|
219
|
+
throw t.isAuthenticated() || (c.notifyDisconnect(), d.emitter.emit("disconnect")), l;
|
|
210
220
|
}
|
|
211
221
|
if (!C.success)
|
|
212
222
|
throw new Error(C.error ?? "CROSSx sign-in failed");
|
|
213
|
-
const x = C.address,
|
|
223
|
+
const x = C.address, E = C.addresses.map((l) => l.address).filter((l) => !x || l.toLowerCase() !== x.toLowerCase()), p = x ? [x, ...E] : E;
|
|
214
224
|
if (p.length === 0)
|
|
215
225
|
throw new Error("No address found after sign-in");
|
|
216
|
-
const
|
|
226
|
+
const O = ((w = C.addresses.find(
|
|
217
227
|
(l) => x && l.address.toLowerCase() === x.toLowerCase()
|
|
218
|
-
)) == null ? void 0 :
|
|
219
|
-
return c.setWalletIndex(
|
|
228
|
+
)) == null ? void 0 : w.index) ?? 0;
|
|
229
|
+
return c.setWalletIndex(O), c.notifyAccountsChanged(p), {
|
|
220
230
|
accounts: p,
|
|
221
|
-
chainId:
|
|
231
|
+
chainId: I
|
|
222
232
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
233
|
};
|
|
224
234
|
} finally {
|
|
225
|
-
|
|
235
|
+
f = !1;
|
|
226
236
|
}
|
|
227
237
|
},
|
|
228
238
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
229
239
|
async disconnect() {
|
|
230
|
-
const
|
|
231
|
-
await t.signOut(),
|
|
240
|
+
const i = h();
|
|
241
|
+
await t.signOut(), i.notifyDisconnect(), q(), o(0), d.emitter.emit("disconnect");
|
|
232
242
|
},
|
|
233
243
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
234
244
|
async getAccounts() {
|
|
@@ -242,7 +252,7 @@ function G(s) {
|
|
|
242
252
|
return h().getCurrentChainId();
|
|
243
253
|
},
|
|
244
254
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
245
|
-
async getProvider({ chainId:
|
|
255
|
+
async getProvider({ chainId: i } = {}) {
|
|
246
256
|
return h();
|
|
247
257
|
},
|
|
248
258
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
@@ -250,31 +260,31 @@ function G(s) {
|
|
|
250
260
|
return await t.whenReady(), t.isAuthenticated();
|
|
251
261
|
},
|
|
252
262
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
253
|
-
async switchChain({ chainId:
|
|
254
|
-
h().setChainId(
|
|
255
|
-
const c =
|
|
263
|
+
async switchChain({ chainId: i }) {
|
|
264
|
+
h().setChainId(i), d.emitter.emit("change", { chainId: i });
|
|
265
|
+
const c = d.chains.find((I) => I.id === i);
|
|
256
266
|
if (!c)
|
|
257
|
-
throw new Error(`Chain ${
|
|
267
|
+
throw new Error(`Chain ${i} is not configured`);
|
|
258
268
|
return c;
|
|
259
269
|
},
|
|
260
270
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
261
|
-
onAccountsChanged(
|
|
262
|
-
|
|
263
|
-
accounts:
|
|
271
|
+
onAccountsChanged(i) {
|
|
272
|
+
i.length === 0 ? d.emitter.emit("disconnect") : d.emitter.emit("change", {
|
|
273
|
+
accounts: i
|
|
264
274
|
});
|
|
265
275
|
},
|
|
266
|
-
onChainChanged(
|
|
267
|
-
|
|
268
|
-
chainId: Number(
|
|
276
|
+
onChainChanged(i) {
|
|
277
|
+
d.emitter.emit("change", {
|
|
278
|
+
chainId: Number(i)
|
|
269
279
|
});
|
|
270
280
|
},
|
|
271
281
|
onDisconnect() {
|
|
272
|
-
|
|
282
|
+
d.emitter.emit("disconnect");
|
|
273
283
|
}
|
|
274
284
|
}));
|
|
275
285
|
}
|
|
276
286
|
export {
|
|
277
287
|
T as CROSSxEIP1193Provider,
|
|
278
|
-
|
|
279
|
-
|
|
288
|
+
M as createCROSSxConnector,
|
|
289
|
+
j as crossxConnector
|
|
280
290
|
};
|
package/dist/provider.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class CROSSxEIP1193Provider {
|
|
|
16
16
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
17
17
|
_setWalletIndexChangeCallback(cb: (index: number) => void): void;
|
|
18
18
|
request({ method, params }: EIP1193RequestArguments): Promise<unknown>;
|
|
19
|
+
private _handleRequest;
|
|
19
20
|
on(event: string, listener: EventListener): this;
|
|
20
21
|
removeListener(event: string, listener: EventListener): this;
|
|
21
22
|
off: (event: string, listener: EventListener) => this;
|
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;AAI9D,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;
|
|
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;AAI9D,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAO9C,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;YAe9D,cAAc;IAqG5B,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;IAK/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;IAKnC,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.2.
|
|
3
|
+
"version": "1.2.7",
|
|
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.2.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "1.2.7"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"viem": ">=2.0.0",
|