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