@nexus-cross/crossx-sdk-wagmi 2.3.10-beta.1 → 2.3.10-beta.3
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 +146 -133
- 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;IAC/C,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;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;IAC/C,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAoDF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAc9D;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;IAC/C,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC;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;IAC/C,oDAAoD;IACpD,sBAAsB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC7C,uDAAuD;IACvD,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,yEAAyE;IACzE,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC;;;;;;;;;;;;;OAaG;IACH,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAC;CACrC,CAAC;AAoDF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAc9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAgWpE"}
|
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 z=require("wagmi"),F=require("viem"),x=require("@nexus-cross/crossx-sdk-core");function K(r){return parseInt(r.split(":")[1]??"1",10)}function A(r){return`eip155:${r}`}function b(r){return"0x"+r.toString(16)}function q(r){const e=r.startsWith("0x")?r.slice(2):r,i=new Uint8Array(e.length/2);for(let n=0;n<i.length;n++)i[n]=parseInt(e.substring(n*2,n*2+2),16);return new TextDecoder().decode(i)}class M{constructor(e,i=x.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:n,index:l})=>{this.setWalletIndex(l),this.notifyAccountsChanged([n])})}_setWalletIndexChangeCallback(e){this.walletIndexChangeCallback=e}async request({method:e,params:i}){try{return await this._handleRequest(e,i)}catch(n){throw n instanceof x.CROSSxError&&n.code===x.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(e,i){var l;const n=i??[];switch(e){case"eth_requestAccounts":case"eth_accounts":{if(this.currentAccounts.length>0)return[...this.currentAccounts];const t=await this.sdk.getAddress();return t?[t.address]:[]}case"eth_chainId":return b(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=n,c=t.startsWith("0x")?q(t):t;return(await this.sdk.signMessage(A(this.chainId),c,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=n,c=t.startsWith("0x")?q(t):t;return(await this.sdk.signMessage(A(this.chainId),c,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=n,c=typeof t=="string"?JSON.parse(t):t,h=(l=c==null?void 0:c.domain)==null?void 0:l.chainId,f=h==null||h===0,m=f?0:Number(h),g={index:this.walletIndex};return(f?await this.sdk.signTypedDataOffchain(c,g):await this.sdk.signTypedData(A(m),c,g)).signature}case"eth_sendTransaction":{const[t]=n,c=A(this.chainId);return(await this.sdk.sendTransaction(c,{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}]=n,c=parseInt(t,16);return c!==this.chainId&&(this.chainId=c,this.emit("chainChanged",b(c))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,n,A(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 n;return(n=this.listeners.get(e))==null||n.delete(i),this}emit(e,...i){var n;(n=this.listeners.get(e))==null||n.forEach(l=>l(...i))}notifyAccountsChanged(e){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",b(e)))}setWalletIndex(e){var i;this.walletIndex=e,(i=this.walletIndexChangeCallback)==null||i.call(this,e)}getWalletIndex(){return this.walletIndex}getCurrentAccounts(){return[...this.currentAccounts]}}function H(r){return typeof r=="number"?r:parseInt(r.split(":")[1]??"1",10)}const k="crossx-wallet-index";function J(){try{const r=typeof window<"u"?localStorage.getItem(k):null;return r&&Number(r)||0}catch{return 0}}function Y(r){try{typeof window<"u"&&localStorage.setItem(k,String(r))}catch{}}function G(){try{typeof window<"u"&&localStorage.removeItem(k)}catch{}}const T="crossx-wallet-address";function $(){try{return typeof window<"u"?localStorage.getItem(T):null}catch{return null}}function B(r){try{typeof window<"u"&&localStorage.setItem(T,r)}catch{}}function Q(){try{typeof window<"u"&&localStorage.removeItem(T)}catch{}}function X(r){const{defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:n,getStoredWalletAddress:l,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:h,...f}=r;if(h){const g=f.connectOtherWallets,S=Array.isArray(g)&&g.length>0,y=f.showConnectOtherWallets===!0;!S&&!y&&(f.showConnectOtherWallets=!0)}const m=x.createCROSSxSDK(f);return U({sdk:m,defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:n,getStoredWalletAddress:l,onWalletAddressChanged:t,clearStoredWalletAddress:c,openConnectOtherWallet:h})}function U(r){const{sdk:e,defaultChainId:i=x.ChainId.CROSS_MAINNET,getStoredWalletIndex:n=J,onWalletIndexChanged:l=Y,getStoredWalletAddress:t=$,onWalletAddressChanged:c=B,clearStoredWalletAddress:h=Q,openConnectOtherWallet:f}=r,m=H(i);let g=null,S=!1,y=null,P=!1,E=!1,O=!1;function C(){return g||(g=new M(e,m),g._setWalletIndexChangeCallback(l)),g}return z.createConnector(I=>{function L(s){if(P)return;const o=C();o.on("accountsChanged",s.onAccountsChanged.bind(s)),o.on("chainChanged",s.onChainChanged.bind(s)),o.on("disconnect",s.onDisconnect.bind(s)),P=!0}function _(s){const o=C();o.notifyAccountsChanged([s]),I.emitter.emit("connect",{accounts:[s],chainId:o.getCurrentChainId()})}async function v(){if(!S)return y||(y=(async()=>{const s=n(),o=t()??void 0;await e.initialize({preferredWalletIndex:s,preferredWalletAddress:o}),e.on("addressChanged",({address:a,index:u})=>{if(E)return;const W=C();W.setWalletIndex(u),a&&(c(a),e.isAuthenticated()?_(a):W.notifyAccountsChanged([a]))}),e.on("authChanged",a=>{if(!(E||O)){if(a.isAuthenticated){if(a.address){_(a.address);return}e.getAddress().then(u=>{u!=null&&u.address&&e.isAuthenticated()&&_(u.address)}).catch(()=>{});return}C().notifyDisconnect(),G(),h(),l(0),I.emitter.emit("disconnect")}}),f&&e.on("connectExternalWallet",f),S=!0})().finally(()=>{y=null}),y)}return{id:"crossx",name:x.WALLET_BRAND_NAME,type:"crossx",async setup(){await v(),L(this)},async connect({chainId:s,isReconnecting:o}={}){await v(),L(this);const a=C(),u=s??m;E=!0;try{if(e.isAuthenticated()){const d=await e.getAddress();if(d)return a.setWalletIndex(d.index),a.notifyAccountsChanged([d.address]),{accounts:[d.address],chainId:u};if(o)throw new Error("CROSSx reconnect: authenticated session has no active wallet address");await e.signOut().catch(()=>{}),a.notifyDisconnect()}if(o)throw new Error("CROSSx reconnect: no authenticated session to restore");const W=t();let p;try{p=await e.signInWithCreate({preferredWalletAddress:W??void 0})}catch(d){throw d instanceof x.CROSSxError&&d.code===x.ErrorCode.EXTERNAL_WALLET_REQUESTED?(a.notifyDisconnect(),new F.UserRejectedRequestError(d)):(e.isAuthenticated()||(a.notifyDisconnect(),I.emitter.emit("disconnect")),d)}if(!p.success)throw new Error(p.error??"CROSSx sign-in failed");const w=p.address,N=p.addresses.map(d=>d.address).filter(d=>!w||d.toLowerCase()!==w.toLowerCase()),R=w?[w,...N]:N;if(R.length===0)throw new Error("No address found after sign-in");const D=p.addresses.find(d=>w&&d.address.toLowerCase()===w.toLowerCase()),j=(D==null?void 0:D.index)??0;return a.setWalletIndex(j),a.notifyAccountsChanged(R),w&&c(w),{accounts:R,chainId:u}}finally{E=!1}},async disconnect(){O=!0;try{const s=C();await e.signOut(),s.notifyDisconnect(),G(),h(),l(0),I.emitter.emit("disconnect")}finally{O=!1}},async getAccounts(){const o=C().getCurrentAccounts();if(o.length>0)return o;const a=await e.getAddress();return a?[a.address]:[]},async getChainId(){return C().getCurrentChainId()},async getProvider({chainId:s}={}){return C()},async isAuthorized(){return await v(),e.isAuthenticated()},async switchChain({chainId:s}){C().setChainId(s),I.emitter.emit("change",{chainId:s});const a=I.chains.find(u=>u.id===s);if(!a)throw new Error(`Chain ${s} is not configured`);return a},onAccountsChanged(s){s.length===0?I.emitter.emit("disconnect"):I.emitter.emit("change",{accounts:s})},onChainChanged(s){I.emitter.emit("change",{chainId:Number(s)})},onDisconnect(){I.emitter.emit("disconnect")}}})}exports.CROSSxEIP1193Provider=M;exports.createCROSSxConnector=U;exports.crossxConnector=X;
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
3
|
-
import { ChainId as
|
|
4
|
-
function
|
|
5
|
-
return parseInt(
|
|
1
|
+
import { createConnector as F } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as j } from "viem";
|
|
3
|
+
import { ChainId as q, CROSSxError as M, ErrorCode as U, WALLET_BRAND_NAME as K, createCROSSxSDK as H } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function J(r) {
|
|
5
|
+
return parseInt(r.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
|
-
function A(
|
|
8
|
-
return `eip155:${
|
|
7
|
+
function A(r) {
|
|
8
|
+
return `eip155:${r}`;
|
|
9
9
|
}
|
|
10
|
-
function R(
|
|
11
|
-
return "0x" +
|
|
10
|
+
function R(r) {
|
|
11
|
+
return "0x" + r.toString(16);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const t =
|
|
15
|
-
for (let n = 0; n <
|
|
16
|
-
|
|
17
|
-
return new TextDecoder().decode(
|
|
13
|
+
function N(r) {
|
|
14
|
+
const t = r.startsWith("0x") ? r.slice(2) : r, i = new Uint8Array(t.length / 2);
|
|
15
|
+
for (let n = 0; n < i.length; n++)
|
|
16
|
+
i[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
|
+
return new TextDecoder().decode(i);
|
|
18
18
|
}
|
|
19
|
-
class
|
|
20
|
-
constructor(t,
|
|
21
|
-
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof
|
|
22
|
-
this.setWalletIndex(
|
|
19
|
+
class Y {
|
|
20
|
+
constructor(t, i = q.CROSS_MAINNET) {
|
|
21
|
+
this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.walletIndex = 0, this.currentAccounts = [], this.off = this.removeListener.bind(this), this.chainId = typeof i == "number" ? i : J(i), this.sdk.on("addressChanged", ({ address: n, index: l }) => {
|
|
22
|
+
this.setWalletIndex(l), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
/** connector가 내부적으로 호출. 외부에서 사용하지 않습니다. */
|
|
@@ -27,19 +27,19 @@ class J {
|
|
|
27
27
|
this.walletIndexChangeCallback = t;
|
|
28
28
|
}
|
|
29
29
|
// ── EIP-1193 request ──────────────────────────────────────────────────────
|
|
30
|
-
async request({ method: t, params:
|
|
30
|
+
async request({ method: t, params: i }) {
|
|
31
31
|
try {
|
|
32
|
-
return await this._handleRequest(t,
|
|
32
|
+
return await this._handleRequest(t, i);
|
|
33
33
|
} catch (n) {
|
|
34
|
-
throw n instanceof
|
|
34
|
+
throw n instanceof M && n.code === U.USER_REJECTED ? Object.assign(
|
|
35
35
|
new Error("User rejected the request"),
|
|
36
36
|
{ code: 4001, data: n.details }
|
|
37
37
|
) : n;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
async _handleRequest(t,
|
|
41
|
-
var
|
|
42
|
-
const n =
|
|
40
|
+
async _handleRequest(t, i) {
|
|
41
|
+
var l;
|
|
42
|
+
const n = i ?? [];
|
|
43
43
|
switch (t) {
|
|
44
44
|
case "eth_requestAccounts":
|
|
45
45
|
case "eth_accounts": {
|
|
@@ -53,7 +53,7 @@ class J {
|
|
|
53
53
|
case "net_version":
|
|
54
54
|
return String(this.chainId);
|
|
55
55
|
case "personal_sign": {
|
|
56
|
-
const [e] = n, c = e.startsWith("0x") ?
|
|
56
|
+
const [e] = n, c = e.startsWith("0x") ? N(e) : e;
|
|
57
57
|
return (await this.sdk.signMessage(
|
|
58
58
|
A(this.chainId),
|
|
59
59
|
c,
|
|
@@ -61,7 +61,7 @@ class J {
|
|
|
61
61
|
)).signature;
|
|
62
62
|
}
|
|
63
63
|
case "eth_sign": {
|
|
64
|
-
const [, e] = n, c = e.startsWith("0x") ?
|
|
64
|
+
const [, e] = n, c = e.startsWith("0x") ? N(e) : e;
|
|
65
65
|
return (await this.sdk.signMessage(
|
|
66
66
|
A(this.chainId),
|
|
67
67
|
c,
|
|
@@ -71,8 +71,8 @@ class J {
|
|
|
71
71
|
case "eth_signTypedData":
|
|
72
72
|
case "eth_signTypedData_v3":
|
|
73
73
|
case "eth_signTypedData_v4": {
|
|
74
|
-
const [, e] = n, c = typeof e == "string" ? JSON.parse(e) : e,
|
|
75
|
-
return (
|
|
74
|
+
const [, e] = n, c = typeof e == "string" ? JSON.parse(e) : e, h = (l = c == null ? void 0 : c.domain) == null ? void 0 : l.chainId, f = h == null || h === 0, p = f ? 0 : Number(h), g = { index: this.walletIndex };
|
|
75
|
+
return (f ? await this.sdk.signTypedDataOffchain(c, g) : await this.sdk.signTypedData(A(p), c, g)).signature;
|
|
76
76
|
}
|
|
77
77
|
case "eth_sendTransaction": {
|
|
78
78
|
const [e] = n, c = A(this.chainId);
|
|
@@ -100,16 +100,16 @@ class J {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
// ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
|
|
103
|
-
on(t,
|
|
104
|
-
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(
|
|
103
|
+
on(t, i) {
|
|
104
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(i), this;
|
|
105
105
|
}
|
|
106
|
-
removeListener(t,
|
|
106
|
+
removeListener(t, i) {
|
|
107
107
|
var n;
|
|
108
|
-
return (n = this.listeners.get(t)) == null || n.delete(
|
|
108
|
+
return (n = this.listeners.get(t)) == null || n.delete(i), this;
|
|
109
109
|
}
|
|
110
|
-
emit(t, ...
|
|
110
|
+
emit(t, ...i) {
|
|
111
111
|
var n;
|
|
112
|
-
(n = this.listeners.get(t)) == null || n.forEach((
|
|
112
|
+
(n = this.listeners.get(t)) == null || n.forEach((l) => l(...i));
|
|
113
113
|
}
|
|
114
114
|
// ── Connector 전용 헬퍼 ───────────────────────────────────────────────────
|
|
115
115
|
notifyAccountsChanged(t) {
|
|
@@ -129,8 +129,8 @@ class J {
|
|
|
129
129
|
* Provider가 SDK 메서드를 호출할 때 이 인덱스를 전달합니다.
|
|
130
130
|
*/
|
|
131
131
|
setWalletIndex(t) {
|
|
132
|
-
var
|
|
133
|
-
this.walletIndex = t, (
|
|
132
|
+
var i;
|
|
133
|
+
this.walletIndex = t, (i = this.walletIndexChangeCallback) == null || i.call(this, t);
|
|
134
134
|
}
|
|
135
135
|
getWalletIndex() {
|
|
136
136
|
return this.walletIndex;
|
|
@@ -139,131 +139,144 @@ class J {
|
|
|
139
139
|
return [...this.currentAccounts];
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
return typeof
|
|
142
|
+
function $(r) {
|
|
143
|
+
return typeof r == "number" ? r : parseInt(r.split(":")[1] ?? "1", 10);
|
|
144
144
|
}
|
|
145
145
|
const k = "crossx-wallet-index";
|
|
146
|
-
function
|
|
146
|
+
function B() {
|
|
147
147
|
try {
|
|
148
|
-
const
|
|
149
|
-
return
|
|
148
|
+
const r = typeof window < "u" ? localStorage.getItem(k) : null;
|
|
149
|
+
return r && Number(r) || 0;
|
|
150
150
|
} catch {
|
|
151
151
|
return 0;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Q(r) {
|
|
155
155
|
try {
|
|
156
|
-
typeof window < "u" && localStorage.setItem(k, String(
|
|
156
|
+
typeof window < "u" && localStorage.setItem(k, String(r));
|
|
157
157
|
} catch {
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function G() {
|
|
161
161
|
try {
|
|
162
162
|
typeof window < "u" && localStorage.removeItem(k);
|
|
163
163
|
} catch {
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
const T = "crossx-wallet-address";
|
|
167
|
-
function
|
|
167
|
+
function X() {
|
|
168
168
|
try {
|
|
169
169
|
return typeof window < "u" ? localStorage.getItem(T) : null;
|
|
170
170
|
} catch {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function V(r) {
|
|
175
175
|
try {
|
|
176
|
-
typeof window < "u" && localStorage.setItem(T,
|
|
176
|
+
typeof window < "u" && localStorage.setItem(T, r);
|
|
177
177
|
} catch {
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function Z() {
|
|
181
181
|
try {
|
|
182
182
|
typeof window < "u" && localStorage.removeItem(T);
|
|
183
183
|
} catch {
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
const { defaultChainId: t, getStoredWalletIndex:
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
!x && !m && (
|
|
186
|
+
function rt(r) {
|
|
187
|
+
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: l, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: h, ...f } = r;
|
|
188
|
+
if (h) {
|
|
189
|
+
const g = f.connectOtherWallets, x = Array.isArray(g) && g.length > 0, m = f.showConnectOtherWallets === !0;
|
|
190
|
+
!x && !m && (f.showConnectOtherWallets = !0);
|
|
191
191
|
}
|
|
192
|
-
const p =
|
|
193
|
-
return
|
|
192
|
+
const p = H(f);
|
|
193
|
+
return tt({ sdk: p, defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: l, onWalletAddressChanged: e, clearStoredWalletAddress: c, openConnectOtherWallet: h });
|
|
194
194
|
}
|
|
195
|
-
function
|
|
195
|
+
function tt(r) {
|
|
196
196
|
const {
|
|
197
197
|
sdk: t,
|
|
198
|
-
defaultChainId:
|
|
199
|
-
getStoredWalletIndex: n =
|
|
200
|
-
onWalletIndexChanged:
|
|
201
|
-
getStoredWalletAddress: e =
|
|
202
|
-
onWalletAddressChanged: c =
|
|
203
|
-
clearStoredWalletAddress:
|
|
204
|
-
openConnectOtherWallet:
|
|
205
|
-
} =
|
|
206
|
-
let
|
|
207
|
-
function
|
|
208
|
-
return
|
|
198
|
+
defaultChainId: i = q.CROSS_MAINNET,
|
|
199
|
+
getStoredWalletIndex: n = B,
|
|
200
|
+
onWalletIndexChanged: l = Q,
|
|
201
|
+
getStoredWalletAddress: e = X,
|
|
202
|
+
onWalletAddressChanged: c = V,
|
|
203
|
+
clearStoredWalletAddress: h = Z,
|
|
204
|
+
openConnectOtherWallet: f
|
|
205
|
+
} = r, p = $(i);
|
|
206
|
+
let g = null, x = !1, m = null, b = !1, S = !1, E = !1;
|
|
207
|
+
function C() {
|
|
208
|
+
return g || (g = new Y(t, p), g._setWalletIndexChangeCallback(l)), g;
|
|
209
209
|
}
|
|
210
|
-
return
|
|
211
|
-
function
|
|
210
|
+
return F((I) => {
|
|
211
|
+
function P(s) {
|
|
212
212
|
if (b) return;
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
const o = C();
|
|
214
|
+
o.on("accountsChanged", s.onAccountsChanged.bind(s)), o.on("chainChanged", s.onChainChanged.bind(s)), o.on("disconnect", s.onDisconnect.bind(s)), b = !0;
|
|
215
215
|
}
|
|
216
|
-
|
|
216
|
+
function _(s) {
|
|
217
|
+
const o = C();
|
|
218
|
+
o.notifyAccountsChanged([s]), I.emitter.emit("connect", {
|
|
219
|
+
accounts: [s],
|
|
220
|
+
chainId: o.getCurrentChainId()
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async function O() {
|
|
217
224
|
if (!x)
|
|
218
225
|
return m || (m = (async () => {
|
|
219
|
-
const
|
|
220
|
-
await t.initialize({ preferredWalletIndex:
|
|
226
|
+
const s = n(), o = e() ?? void 0;
|
|
227
|
+
await t.initialize({ preferredWalletIndex: s, preferredWalletAddress: o }), t.on("addressChanged", ({ address: a, index: u }) => {
|
|
221
228
|
if (S) return;
|
|
222
|
-
const W =
|
|
223
|
-
W.setWalletIndex(
|
|
224
|
-
}), t.on("authChanged", (
|
|
225
|
-
if (!(S || E))
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
const W = C();
|
|
230
|
+
W.setWalletIndex(u), a && (c(a), t.isAuthenticated() ? _(a) : W.notifyAccountsChanged([a]));
|
|
231
|
+
}), t.on("authChanged", (a) => {
|
|
232
|
+
if (!(S || E)) {
|
|
233
|
+
if (a.isAuthenticated) {
|
|
234
|
+
if (a.address) {
|
|
235
|
+
_(a.address);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
t.getAddress().then((u) => {
|
|
239
|
+
u != null && u.address && t.isAuthenticated() && _(u.address);
|
|
240
|
+
}).catch(() => {
|
|
231
241
|
});
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
C().notifyDisconnect(), G(), h(), l(0), I.emitter.emit("disconnect");
|
|
245
|
+
}
|
|
246
|
+
}), f && t.on("connectExternalWallet", f), x = !0;
|
|
234
247
|
})().finally(() => {
|
|
235
248
|
m = null;
|
|
236
249
|
}), m);
|
|
237
250
|
}
|
|
238
251
|
return {
|
|
239
252
|
id: "crossx",
|
|
240
|
-
name:
|
|
253
|
+
name: K,
|
|
241
254
|
type: "crossx",
|
|
242
255
|
async setup() {
|
|
243
|
-
await
|
|
256
|
+
await O(), P(this);
|
|
244
257
|
},
|
|
245
258
|
// ── connect ─────────────────────────────────────────────────────────────
|
|
246
|
-
async connect({ chainId:
|
|
247
|
-
await
|
|
248
|
-
const
|
|
259
|
+
async connect({ chainId: s, isReconnecting: o } = {}) {
|
|
260
|
+
await O(), P(this);
|
|
261
|
+
const a = C(), u = s ?? p;
|
|
249
262
|
S = !0;
|
|
250
263
|
try {
|
|
251
264
|
if (t.isAuthenticated()) {
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
return
|
|
255
|
-
accounts: [
|
|
256
|
-
chainId:
|
|
265
|
+
const d = await t.getAddress();
|
|
266
|
+
if (d)
|
|
267
|
+
return a.setWalletIndex(d.index), a.notifyAccountsChanged([d.address]), {
|
|
268
|
+
accounts: [d.address],
|
|
269
|
+
chainId: u
|
|
257
270
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
271
|
};
|
|
259
|
-
if (
|
|
272
|
+
if (o)
|
|
260
273
|
throw new Error(
|
|
261
274
|
"CROSSx reconnect: authenticated session has no active wallet address"
|
|
262
275
|
);
|
|
263
276
|
await t.signOut().catch(() => {
|
|
264
|
-
}),
|
|
277
|
+
}), a.notifyDisconnect();
|
|
265
278
|
}
|
|
266
|
-
if (
|
|
279
|
+
if (o)
|
|
267
280
|
throw new Error("CROSSx reconnect: no authenticated session to restore");
|
|
268
281
|
const W = e();
|
|
269
282
|
let y;
|
|
@@ -271,20 +284,20 @@ function Z(s) {
|
|
|
271
284
|
y = await t.signInWithCreate({
|
|
272
285
|
preferredWalletAddress: W ?? void 0
|
|
273
286
|
});
|
|
274
|
-
} catch (
|
|
275
|
-
throw
|
|
287
|
+
} catch (d) {
|
|
288
|
+
throw d instanceof M && d.code === U.EXTERNAL_WALLET_REQUESTED ? (a.notifyDisconnect(), new j(d)) : (t.isAuthenticated() || (a.notifyDisconnect(), I.emitter.emit("disconnect")), d);
|
|
276
289
|
}
|
|
277
290
|
if (!y.success)
|
|
278
291
|
throw new Error(y.error ?? "CROSSx sign-in failed");
|
|
279
|
-
const w = y.address,
|
|
280
|
-
if (
|
|
292
|
+
const w = y.address, L = y.addresses.map((d) => d.address).filter((d) => !w || d.toLowerCase() !== w.toLowerCase()), v = w ? [w, ...L] : L;
|
|
293
|
+
if (v.length === 0)
|
|
281
294
|
throw new Error("No address found after sign-in");
|
|
282
295
|
const D = y.addresses.find(
|
|
283
|
-
(
|
|
284
|
-
),
|
|
285
|
-
return
|
|
286
|
-
accounts:
|
|
287
|
-
chainId:
|
|
296
|
+
(d) => w && d.address.toLowerCase() === w.toLowerCase()
|
|
297
|
+
), z = (D == null ? void 0 : D.index) ?? 0;
|
|
298
|
+
return a.setWalletIndex(z), a.notifyAccountsChanged(v), w && c(w), {
|
|
299
|
+
accounts: v,
|
|
300
|
+
chainId: u
|
|
288
301
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
289
302
|
};
|
|
290
303
|
} finally {
|
|
@@ -295,58 +308,58 @@ function Z(s) {
|
|
|
295
308
|
async disconnect() {
|
|
296
309
|
E = !0;
|
|
297
310
|
try {
|
|
298
|
-
const
|
|
299
|
-
await t.signOut(),
|
|
311
|
+
const s = C();
|
|
312
|
+
await t.signOut(), s.notifyDisconnect(), G(), h(), l(0), I.emitter.emit("disconnect");
|
|
300
313
|
} finally {
|
|
301
314
|
E = !1;
|
|
302
315
|
}
|
|
303
316
|
},
|
|
304
317
|
// ── getAccounts ─────────────────────────────────────────────────────────
|
|
305
318
|
async getAccounts() {
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
return
|
|
319
|
+
const o = C().getCurrentAccounts();
|
|
320
|
+
if (o.length > 0) return o;
|
|
321
|
+
const a = await t.getAddress();
|
|
322
|
+
return a ? [a.address] : [];
|
|
310
323
|
},
|
|
311
324
|
// ── getChainId ──────────────────────────────────────────────────────────
|
|
312
325
|
async getChainId() {
|
|
313
|
-
return
|
|
326
|
+
return C().getCurrentChainId();
|
|
314
327
|
},
|
|
315
328
|
// ── getProvider ─────────────────────────────────────────────────────────
|
|
316
|
-
async getProvider({ chainId:
|
|
317
|
-
return
|
|
329
|
+
async getProvider({ chainId: s } = {}) {
|
|
330
|
+
return C();
|
|
318
331
|
},
|
|
319
332
|
// ── isAuthorized ────────────────────────────────────────────────────────
|
|
320
333
|
async isAuthorized() {
|
|
321
|
-
return await
|
|
334
|
+
return await O(), t.isAuthenticated();
|
|
322
335
|
},
|
|
323
336
|
// ── switchChain ─────────────────────────────────────────────────────────
|
|
324
|
-
async switchChain({ chainId:
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
if (!
|
|
328
|
-
throw new Error(`Chain ${
|
|
329
|
-
return
|
|
337
|
+
async switchChain({ chainId: s }) {
|
|
338
|
+
C().setChainId(s), I.emitter.emit("change", { chainId: s });
|
|
339
|
+
const a = I.chains.find((u) => u.id === s);
|
|
340
|
+
if (!a)
|
|
341
|
+
throw new Error(`Chain ${s} is not configured`);
|
|
342
|
+
return a;
|
|
330
343
|
},
|
|
331
344
|
// ── 이벤트 핸들러 ───────────────────────────────────────────────────────
|
|
332
|
-
onAccountsChanged(
|
|
333
|
-
|
|
334
|
-
accounts:
|
|
345
|
+
onAccountsChanged(s) {
|
|
346
|
+
s.length === 0 ? I.emitter.emit("disconnect") : I.emitter.emit("change", {
|
|
347
|
+
accounts: s
|
|
335
348
|
});
|
|
336
349
|
},
|
|
337
|
-
onChainChanged(
|
|
338
|
-
|
|
339
|
-
chainId: Number(
|
|
350
|
+
onChainChanged(s) {
|
|
351
|
+
I.emitter.emit("change", {
|
|
352
|
+
chainId: Number(s)
|
|
340
353
|
});
|
|
341
354
|
},
|
|
342
355
|
onDisconnect() {
|
|
343
|
-
|
|
356
|
+
I.emitter.emit("disconnect");
|
|
344
357
|
}
|
|
345
358
|
};
|
|
346
359
|
});
|
|
347
360
|
}
|
|
348
361
|
export {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
362
|
+
Y as CROSSxEIP1193Provider,
|
|
363
|
+
tt as createCROSSxConnector,
|
|
364
|
+
rt as crossxConnector
|
|
352
365
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.3.10-beta.
|
|
3
|
+
"version": "2.3.10-beta.3",
|
|
4
4
|
"description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@nexus-cross/crossx-sdk-core": "^2.3.10-beta.
|
|
21
|
+
"@nexus-cross/crossx-sdk-core": "^2.3.10-beta.3"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|