@nexus-cross/crossx-sdk-wagmi 1.0.4 → 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 +8 -0
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +162 -99
- package/dist/provider.d.ts +13 -1
- package/dist/provider.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/connector.d.ts
CHANGED
|
@@ -5,10 +5,18 @@ import { CROSSxEIP1193Provider } from './provider';
|
|
|
5
5
|
export interface CROSSxConnectorOptions {
|
|
6
6
|
sdk: CROSSxSDK;
|
|
7
7
|
defaultChainId?: string | number;
|
|
8
|
+
/** 저장된 지갑 인덱스를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
9
|
+
getStoredWalletIndex?: () => number;
|
|
10
|
+
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
11
|
+
onWalletIndexChanged?: (index: number) => void;
|
|
8
12
|
}
|
|
9
13
|
/** 간편 모드: SDK 설정만 전달하면 내부에서 SDK를 생성 */
|
|
10
14
|
export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
11
15
|
defaultChainId?: string | number;
|
|
16
|
+
/** 저장된 지갑 인덱스를 반환하는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
17
|
+
getStoredWalletIndex?: () => number;
|
|
18
|
+
/** 활성 지갑 인덱스 변경 시 호출되는 콜백. 미설정 시 localStorage 자동 사용. */
|
|
19
|
+
onWalletIndexChanged?: (index: number) => void;
|
|
12
20
|
};
|
|
13
21
|
export declare function crossxConnector(options: CrossxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
|
14
22
|
export declare function createCROSSxConnector(options: CROSSxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
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;
|
|
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,189 +1,252 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { ChainId as
|
|
3
|
-
function
|
|
4
|
-
return parseInt(
|
|
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
|
+
return parseInt(s.split(":")[1] ?? "1", 10);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
return `eip155:${
|
|
6
|
+
function x(s) {
|
|
7
|
+
return `eip155:${s}`;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return "0x" +
|
|
9
|
+
function p(s) {
|
|
10
|
+
return "0x" + s.toString(16);
|
|
11
11
|
}
|
|
12
|
-
class
|
|
13
|
-
constructor(
|
|
14
|
-
this.sdk =
|
|
12
|
+
class R {
|
|
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 : k(i), this.sdk.on("addressChanged", ({ address: c, index: o }) => {
|
|
15
|
+
this.setWalletIndex(o), this.notifyAccountsChanged([c]);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
19
|
+
_setWalletIndexChangeCallback(e) {
|
|
20
|
+
this.walletIndexChangeCallback = e;
|
|
15
21
|
}
|
|
16
22
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
17
|
-
async request({ method:
|
|
23
|
+
async request({ method: e, params: i }) {
|
|
18
24
|
var o;
|
|
19
|
-
const
|
|
20
|
-
switch (
|
|
25
|
+
const c = i ?? [];
|
|
26
|
+
switch (e) {
|
|
21
27
|
case "eth_requestAccounts":
|
|
22
28
|
case "eth_accounts": {
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
if (this.currentAccounts.length > 0)
|
|
30
|
+
return console.log("[CROSSx-debug] provider.eth_accounts → currentAccounts:", this.currentAccounts[0], "walletIndex:", this.walletIndex), [...this.currentAccounts];
|
|
31
|
+
const t = await this.sdk.getAddress();
|
|
32
|
+
return console.log("[CROSSx-debug] provider.eth_accounts → fallback sdk.getAddress():", t == null ? void 0 : t.address), t ? [t.address] : [];
|
|
25
33
|
}
|
|
26
34
|
case "eth_chainId":
|
|
27
|
-
return
|
|
35
|
+
return p(this.chainId);
|
|
28
36
|
case "net_version":
|
|
29
37
|
return String(this.chainId);
|
|
30
38
|
case "personal_sign": {
|
|
31
|
-
const [
|
|
32
|
-
return (await this.sdk.signMessage(
|
|
39
|
+
const [t] = c;
|
|
40
|
+
return (await this.sdk.signMessage(
|
|
41
|
+
x(this.chainId),
|
|
42
|
+
t,
|
|
43
|
+
{ index: this.walletIndex }
|
|
44
|
+
)).signature;
|
|
33
45
|
}
|
|
34
46
|
case "eth_sign": {
|
|
35
|
-
const [,
|
|
36
|
-
return (await this.sdk.signMessage(
|
|
47
|
+
const [, t] = c;
|
|
48
|
+
return (await this.sdk.signMessage(
|
|
49
|
+
x(this.chainId),
|
|
50
|
+
t,
|
|
51
|
+
{ index: this.walletIndex }
|
|
52
|
+
)).signature;
|
|
37
53
|
}
|
|
38
54
|
case "eth_signTypedData":
|
|
39
55
|
case "eth_signTypedData_v3":
|
|
40
56
|
case "eth_signTypedData_v4": {
|
|
41
|
-
const [,
|
|
42
|
-
return (
|
|
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;
|
|
43
59
|
}
|
|
44
60
|
case "eth_sendTransaction": {
|
|
45
|
-
const [
|
|
46
|
-
return (await this.sdk.sendTransaction(
|
|
47
|
-
from:
|
|
48
|
-
to:
|
|
49
|
-
value:
|
|
50
|
-
data:
|
|
51
|
-
gasLimit:
|
|
52
|
-
gasPrice:
|
|
53
|
-
maxFeePerGas:
|
|
54
|
-
maxPriorityFeePerGas:
|
|
55
|
-
nonce:
|
|
61
|
+
const [t] = c, a = x(this.chainId);
|
|
62
|
+
return (await this.sdk.sendTransaction(a, {
|
|
63
|
+
from: t.from,
|
|
64
|
+
to: t.to,
|
|
65
|
+
value: t.value,
|
|
66
|
+
data: t.data,
|
|
67
|
+
gasLimit: t.gasLimit ?? t.gas,
|
|
68
|
+
gasPrice: t.gasPrice,
|
|
69
|
+
maxFeePerGas: t.maxFeePerGas,
|
|
70
|
+
maxPriorityFeePerGas: t.maxPriorityFeePerGas,
|
|
71
|
+
nonce: t.nonce !== void 0 ? parseInt(String(t.nonce), 16) : void 0,
|
|
56
72
|
chainId: this.chainId
|
|
57
|
-
})).txHash;
|
|
73
|
+
}, { index: this.walletIndex })).txHash;
|
|
58
74
|
}
|
|
59
75
|
case "wallet_switchEthereumChain": {
|
|
60
|
-
const [{ chainId:
|
|
61
|
-
return
|
|
76
|
+
const [{ chainId: t }] = c, a = parseInt(t, 16);
|
|
77
|
+
return a !== this.chainId && (this.chainId = a, this.emit("chainChanged", p(a))), null;
|
|
62
78
|
}
|
|
63
79
|
case "wallet_addEthereumChain":
|
|
64
80
|
return null;
|
|
65
81
|
default:
|
|
66
|
-
return this.sdk.walletRpc(
|
|
82
|
+
return this.sdk.walletRpc(e, c, x(this.chainId));
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
70
|
-
on(
|
|
71
|
-
return this.listeners.has(
|
|
86
|
+
on(e, i) {
|
|
87
|
+
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(i), this;
|
|
72
88
|
}
|
|
73
|
-
removeListener(
|
|
74
|
-
var
|
|
75
|
-
return (
|
|
89
|
+
removeListener(e, i) {
|
|
90
|
+
var c;
|
|
91
|
+
return (c = this.listeners.get(e)) == null || c.delete(i), this;
|
|
76
92
|
}
|
|
77
|
-
emit(
|
|
78
|
-
var
|
|
79
|
-
(
|
|
93
|
+
emit(e, ...i) {
|
|
94
|
+
var c;
|
|
95
|
+
(c = this.listeners.get(e)) == null || c.forEach((o) => o(...i));
|
|
80
96
|
}
|
|
81
97
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
82
|
-
notifyAccountsChanged(
|
|
83
|
-
this.emit("accountsChanged",
|
|
98
|
+
notifyAccountsChanged(e) {
|
|
99
|
+
console.log("[CROSSx-debug] provider.notifyAccountsChanged:", e[0], "walletIndex:", this.walletIndex), this.currentAccounts = e, this.emit("accountsChanged", e);
|
|
84
100
|
}
|
|
85
|
-
notifyDisconnect(
|
|
86
|
-
this.emit("disconnect",
|
|
101
|
+
notifyDisconnect(e) {
|
|
102
|
+
this.currentAccounts = [], this.walletIndex = 0, this.emit("disconnect", e);
|
|
87
103
|
}
|
|
88
104
|
getCurrentChainId() {
|
|
89
105
|
return this.chainId;
|
|
90
106
|
}
|
|
91
|
-
setChainId(
|
|
92
|
-
|
|
107
|
+
setChainId(e) {
|
|
108
|
+
e !== this.chainId && (this.chainId = e, this.emit("chainChanged", p(e)));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 활성 지갑 인덱스 설정.
|
|
112
|
+
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
113
|
+
*/
|
|
114
|
+
setWalletIndex(e) {
|
|
115
|
+
var i;
|
|
116
|
+
console.log("[CROSSx-debug] provider.setWalletIndex:", e), this.walletIndex = e, (i = this.walletIndexChangeCallback) == null || i.call(this, e);
|
|
117
|
+
}
|
|
118
|
+
getWalletIndex() {
|
|
119
|
+
return this.walletIndex;
|
|
120
|
+
}
|
|
121
|
+
getCurrentAccounts() {
|
|
122
|
+
return [...this.currentAccounts];
|
|
93
123
|
}
|
|
94
124
|
}
|
|
95
|
-
function
|
|
96
|
-
return typeof
|
|
125
|
+
function _(s) {
|
|
126
|
+
return typeof s == "number" ? s : parseInt(s.split(":")[1] ?? "1", 10);
|
|
127
|
+
}
|
|
128
|
+
const w = "crossx-wallet-index";
|
|
129
|
+
function v() {
|
|
130
|
+
try {
|
|
131
|
+
const s = typeof window < "u" ? localStorage.getItem(w) : null;
|
|
132
|
+
return s && Number(s) || 0;
|
|
133
|
+
} catch {
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function W(s) {
|
|
138
|
+
try {
|
|
139
|
+
typeof window < "u" && localStorage.setItem(w, String(s));
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function P() {
|
|
144
|
+
try {
|
|
145
|
+
typeof window < "u" && localStorage.removeItem(w);
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
97
148
|
}
|
|
98
|
-
function
|
|
99
|
-
const { defaultChainId:
|
|
100
|
-
return
|
|
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 });
|
|
101
152
|
}
|
|
102
|
-
function
|
|
103
|
-
const {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
153
|
+
function D(s) {
|
|
154
|
+
const {
|
|
155
|
+
sdk: e,
|
|
156
|
+
defaultChainId: i = y.CROSS_MAINNET,
|
|
157
|
+
getStoredWalletIndex: c = v,
|
|
158
|
+
onWalletIndexChanged: o = W
|
|
159
|
+
} = s, t = _(i);
|
|
160
|
+
let a = null, g = !1;
|
|
161
|
+
function d() {
|
|
162
|
+
return a || (a = new R(e, t), a._setWalletIndexChangeCallback(o)), a;
|
|
107
163
|
}
|
|
108
|
-
return
|
|
164
|
+
return b((h) => ({
|
|
109
165
|
id: "crossx",
|
|
110
166
|
name: "CROSSx Wallet",
|
|
111
167
|
type: "crossx",
|
|
112
168
|
async setup() {
|
|
113
|
-
|
|
114
|
-
const n =
|
|
115
|
-
n.on("accountsChanged", this.onAccountsChanged.bind(this)), n.on("chainChanged", this.onChainChanged.bind(this)), n.on("disconnect", this.onDisconnect.bind(this));
|
|
169
|
+
console.log("[CROSSx-debug] connector.setup() 시작"), g || (await e.initialize(), g = !0), console.log("[CROSSx-debug] connector.setup() SDK initialized, isAuthenticated:", e.isAuthenticated());
|
|
170
|
+
const n = d();
|
|
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() 완료, 이벤트 리스너 등록됨");
|
|
116
172
|
},
|
|
117
173
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
118
|
-
async connect({ chainId: n, isReconnecting:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
126
185
|
};
|
|
186
|
+
console.log("[CROSSx-debug] connector.connect() 재연결 경로 — info null, 신규 로그인으로 진행");
|
|
127
187
|
}
|
|
128
|
-
const
|
|
129
|
-
if (!
|
|
130
|
-
throw new Error(
|
|
131
|
-
const
|
|
132
|
-
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)
|
|
133
193
|
throw new Error("No address found after sign-in");
|
|
134
|
-
return
|
|
135
|
-
accounts:
|
|
136
|
-
chainId:
|
|
194
|
+
return console.log("[CROSSx-debug] connector.connect() signIn 완료, primary:", I), r.notifyAccountsChanged(m), {
|
|
195
|
+
accounts: m,
|
|
196
|
+
chainId: S
|
|
137
197
|
};
|
|
138
198
|
},
|
|
139
199
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
140
200
|
async disconnect() {
|
|
141
|
-
const n =
|
|
142
|
-
await
|
|
201
|
+
const n = d();
|
|
202
|
+
await e.signOut(), n.notifyDisconnect(), P(), o(0), h.emitter.emit("disconnect");
|
|
143
203
|
},
|
|
144
204
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
145
205
|
async getAccounts() {
|
|
146
|
-
const n =
|
|
147
|
-
|
|
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] : [];
|
|
148
210
|
},
|
|
149
211
|
// ── getChainId ──────────────────────────────────────────────────────────
|
|
150
212
|
async getChainId() {
|
|
151
|
-
return
|
|
213
|
+
return d().getCurrentChainId();
|
|
152
214
|
},
|
|
153
215
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
154
216
|
async getProvider({ chainId: n } = {}) {
|
|
155
|
-
return
|
|
217
|
+
return d();
|
|
156
218
|
},
|
|
157
219
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
158
220
|
async isAuthorized() {
|
|
159
|
-
|
|
221
|
+
const n = e.isAuthenticated();
|
|
222
|
+
return console.log("[CROSSx-debug] connector.isAuthorized():", n), n;
|
|
160
223
|
},
|
|
161
224
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
162
225
|
async switchChain({ chainId: n }) {
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
if (!
|
|
226
|
+
d().setChainId(n), h.emitter.emit("change", { chainId: n });
|
|
227
|
+
const r = h.chains.find((S) => S.id === n);
|
|
228
|
+
if (!r)
|
|
166
229
|
throw new Error(`Chain ${n} is not configured`);
|
|
167
|
-
return
|
|
230
|
+
return r;
|
|
168
231
|
},
|
|
169
232
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
170
233
|
onAccountsChanged(n) {
|
|
171
|
-
n.length === 0 ?
|
|
234
|
+
console.log("[CROSSx-debug] connector.onAccountsChanged:", n), n.length === 0 ? h.emitter.emit("disconnect") : h.emitter.emit("change", {
|
|
172
235
|
accounts: n
|
|
173
236
|
});
|
|
174
237
|
},
|
|
175
238
|
onChainChanged(n) {
|
|
176
|
-
|
|
239
|
+
h.emitter.emit("change", {
|
|
177
240
|
chainId: Number(n)
|
|
178
241
|
});
|
|
179
242
|
},
|
|
180
243
|
onDisconnect() {
|
|
181
|
-
|
|
244
|
+
h.emitter.emit("disconnect");
|
|
182
245
|
}
|
|
183
246
|
}));
|
|
184
247
|
}
|
|
185
248
|
export {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
249
|
+
R as CROSSxEIP1193Provider,
|
|
250
|
+
D as createCROSSxConnector,
|
|
251
|
+
N as crossxConnector
|
|
189
252
|
};
|
package/dist/provider.d.ts
CHANGED
|
@@ -6,10 +6,15 @@ export interface EIP1193RequestArguments {
|
|
|
6
6
|
params?: readonly unknown[] | object;
|
|
7
7
|
}
|
|
8
8
|
export declare class CROSSxEIP1193Provider {
|
|
9
|
-
|
|
9
|
+
readonly sdk: CROSSxSDK;
|
|
10
10
|
private listeners;
|
|
11
11
|
private chainId;
|
|
12
|
+
private walletIndex;
|
|
13
|
+
private currentAccounts;
|
|
14
|
+
private walletIndexChangeCallback?;
|
|
12
15
|
constructor(sdk: CROSSxSDK, defaultChainId?: string | number);
|
|
16
|
+
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
17
|
+
_setWalletIndexChangeCallback(cb: (index: number) => void): void;
|
|
13
18
|
request({ method, params }: EIP1193RequestArguments): Promise<unknown>;
|
|
14
19
|
on(event: string, listener: EventListener): this;
|
|
15
20
|
removeListener(event: string, listener: EventListener): this;
|
|
@@ -19,6 +24,13 @@ export declare class CROSSxEIP1193Provider {
|
|
|
19
24
|
notifyDisconnect(error?: Error): void;
|
|
20
25
|
getCurrentChainId(): number;
|
|
21
26
|
setChainId(id: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* 활성 지갑 인덱스 설정.
|
|
29
|
+
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
30
|
+
*/
|
|
31
|
+
setWalletIndex(index: number): void;
|
|
32
|
+
getWalletIndex(): number;
|
|
33
|
+
getCurrentAccounts(): string[];
|
|
22
34
|
}
|
|
23
35
|
export {};
|
|
24
36
|
//# sourceMappingURL=provider.d.ts.map
|
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;
|
|
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",
|