@nexus-cross/crossx-sdk-wagmi 2.4.0-beta.3 → 2.5.0-beta.1
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 +20 -0
- package/dist/connector.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -75
- package/package.json +5 -5
package/dist/connector.d.ts
CHANGED
|
@@ -58,6 +58,26 @@ export type CrossxConnectorOptions = Omit<SDKConfig, 'useMockWallet'> & {
|
|
|
58
58
|
*/
|
|
59
59
|
openConnectOtherWallet?: () => void;
|
|
60
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* 간편 모드 커넥터 — SDK 설정만 전달하면 내부에서 SDK를 생성
|
|
63
|
+
*
|
|
64
|
+
* @deprecated ONEpocket 리브랜드 — {@link onepocketConnector}를 사용하세요. 동작은 동일하며,
|
|
65
|
+
* 이 이름은 향후 major 버전에서 제거될 예정입니다.
|
|
66
|
+
*/
|
|
61
67
|
export declare function crossxConnector(options: CrossxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
|
68
|
+
/**
|
|
69
|
+
* 고급 모드 커넥터 — 이미 생성한 SDK 인스턴스를 직접 주입
|
|
70
|
+
*
|
|
71
|
+
* @deprecated ONEpocket 리브랜드 — {@link createONEpocketConnector}를 사용하세요. 동작은 동일하며,
|
|
72
|
+
* 이 이름은 향후 major 버전에서 제거될 예정입니다.
|
|
73
|
+
*/
|
|
62
74
|
export declare function createCROSSxConnector(options: CROSSxConnectorOptions): import('wagmi').CreateConnectorFn<CROSSxEIP1193Provider, Record<string, unknown>, Record<string, unknown>>;
|
|
75
|
+
/** 간편 모드 커넥터 (ONEpocket 리브랜드 이름 — crossxConnector와 동일) */
|
|
76
|
+
export declare const onepocketConnector: typeof crossxConnector;
|
|
77
|
+
/** 고급 모드 커넥터 (ONEpocket 리브랜드 이름 — createCROSSxConnector와 동일) */
|
|
78
|
+
export declare const createONEpocketConnector: typeof createCROSSxConnector;
|
|
79
|
+
/** 간편 모드 옵션 (ONEpocket 리브랜드 이름 — CrossxConnectorOptions와 동일) */
|
|
80
|
+
export type OnepocketConnectorOptions = CrossxConnectorOptions;
|
|
81
|
+
/** 고급 모드 옵션 (ONEpocket 리브랜드 이름 — CROSSxConnectorOptions와 동일) */
|
|
82
|
+
export type ONEpocketConnectorOptions = CROSSxConnectorOptions;
|
|
63
83
|
//# sourceMappingURL=connector.d.ts.map
|
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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1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("wagmi"),Q=require("viem"),p=require("@nexus-cross/crossx-sdk-core");function X(r){return parseInt(r.split(":")[1]??"1",10)}function v(r){return`eip155:${r}`}function M(r){return"0x"+r.toString(16)}function H(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 U{constructor(e,i=p.ChainId.ONE_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:X(i),this.sdk.on("addressChanged",({address:n,index:u})=>{this.setWalletIndex(u),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 p.CROSSxError&&n.code===p.ErrorCode.USER_REJECTED?Object.assign(new Error("User rejected the request"),{code:4001,data:n.details}):n}}async _handleRequest(e,i){var u;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 M(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[t]=n,o=t.startsWith("0x")?H(t):t;return(await this.sdk.signMessage(v(this.chainId),o,{index:this.walletIndex})).signature}case"eth_sign":{const[,t]=n,o=t.startsWith("0x")?H(t):t;return(await this.sdk.signMessage(v(this.chainId),o,{index:this.walletIndex})).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,t]=n,o=typeof t=="string"?JSON.parse(t):t,f=(u=o==null?void 0:o.domain)==null?void 0:u.chainId,x=f==null||f===0,A=x?0:Number(f),m={index:this.walletIndex};return(x?await this.sdk.signTypedDataOffchain(o,m):await this.sdk.signTypedData(v(A),o,m)).signature}case"eth_sendTransaction":{const[t]=n,o=v(this.chainId);return(await this.sdk.sendTransaction(o,{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,o=parseInt(t,16);return o!==this.chainId&&(this.chainId=o,this.emit("chainChanged",M(o))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(e,n,v(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(u=>u(...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",M(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 V(r){return typeof r=="number"?r:parseInt(r.split(":")[1]??"1",10)}const j="crossx-wallet-index";function Z(){try{const r=typeof window<"u"?localStorage.getItem(j):null;return r&&Number(r)||0}catch{return 0}}function ee(r){try{typeof window<"u"&&localStorage.setItem(j,String(r))}catch{}}function J(){try{typeof window<"u"&&localStorage.removeItem(j)}catch{}}const z="crossx-wallet-address";function te(){try{return typeof window<"u"?localStorage.getItem(z):null}catch{return null}}function ne(r){try{typeof window<"u"&&localStorage.setItem(z,r)}catch{}}function se(){try{typeof window<"u"&&localStorage.removeItem(z)}catch{}}function Y(r){const{defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:n,getStoredWalletAddress:u,onWalletAddressChanged:t,clearStoredWalletAddress:o,openConnectOtherWallet:f,...x}=r;if(f){const m=x.connectOtherWallets,W=Array.isArray(m)&&m.length>0,y=x.showConnectOtherWallets===!0;!W&&!y&&(x.showConnectOtherWallets=!0)}const A=p.createCROSSxSDK(x);return F({sdk:A,defaultChainId:e,getStoredWalletIndex:i,onWalletIndexChanged:n,getStoredWalletAddress:u,onWalletAddressChanged:t,clearStoredWalletAddress:o,openConnectOtherWallet:f})}function F(r){const{sdk:e,defaultChainId:i=p.ChainId.ONE_MAINNET,getStoredWalletIndex:n=Z,onWalletIndexChanged:u=ee,getStoredWalletAddress:t=te,onWalletAddressChanged:o=ne,clearStoredWalletAddress:f=se,openConnectOtherWallet:x}=r,A=V(i);let m=null,W=!1,y=null,K=!1,R=!1,N=!1,S=null,D=!1;function L(I){const O=S;return O?(S=null,D=!1,O(I),!0):!1}function C(){return m||(m=new U(e,A),m._setWalletIndexChangeCallback(u)),m}return B.createConnector(I=>{function O(s){if(K)return;const l=C();l.on("accountsChanged",s.onAccountsChanged.bind(s)),l.on("chainChanged",s.onChainChanged.bind(s)),l.on("disconnect",s.onDisconnect.bind(s)),K=!0}function q(s){const l=C();l.notifyAccountsChanged([s]),I.emitter.emit("connect",{accounts:[s],chainId:l.getCurrentChainId()})}async function G(){if(!W)return y||(y=(async()=>{const s=n(),l=t()??void 0;await e.initialize({preferredWalletIndex:s,preferredWalletAddress:l}),e.on("addressChanged",({address:a,index:d})=>{if(R){D&&a&&e.isAuthenticated()&&S&&(C().setWalletIndex(d),o(a),L(a));return}const P=C();P.setWalletIndex(d),a&&(o(a),e.isAuthenticated()?q(a):P.notifyAccountsChanged([a]))}),e.on("authChanged",a=>{if(a.isAuthenticated&&a.source==="external"&&S){if(a.address){L(a.address);return}D=!0,e.getAddress().then(d=>{d!=null&&d.address&&e.isAuthenticated()&&L(d.address)}).catch(()=>{});return}if(!(R||N)){if(a.isAuthenticated){if(a.address){q(a.address);return}e.getAddress().then(d=>{d!=null&&d.address&&e.isAuthenticated()&&q(d.address)}).catch(()=>{});return}C().notifyDisconnect(),J(),f(),u(0),I.emitter.emit("disconnect")}}),x&&e.on("connectExternalWallet",x),W=!0})().finally(()=>{y=null}),y)}return{id:"crossx",name:p.WALLET_BRAND_NAME,type:"crossx",async setup(){await G(),O(this)},async connect({chainId:s,isReconnecting:l}={}){const a=s??A;R=!0;const d=new Promise(w=>{S=w}),P=this,$=async()=>{await G(),O(P);const w=C();if(e.isAuthenticated()){const c=await e.getAddress();if(c)return w.setWalletIndex(c.index),w.notifyAccountsChanged([c.address]),{accounts:[c.address],chainId:a};if(l)throw new Error("CROSSx reconnect: authenticated session has no active wallet address");await e.signOut().catch(()=>{}),w.notifyDisconnect()}if(l)throw new Error("CROSSx reconnect: no authenticated session to restore");const k=t();let g;try{g=await e.signInWithCreate({preferredWalletAddress:k??void 0})}catch(c){throw c instanceof p.CROSSxError&&c.code===p.ErrorCode.EXTERNAL_WALLET_REQUESTED?(w.notifyDisconnect(),new Q.UserRejectedRequestError(c)):(e.isAuthenticated()||(w.notifyDisconnect(),I.emitter.emit("disconnect")),c)}if(!g.success)throw new Error(g.error??"CROSSx sign-in failed");const h=g.address,E=g.addresses.map(c=>c.address).filter(c=>!h||c.toLowerCase()!==h.toLowerCase()),b=h?[h,...E]:E;if(b.length===0)throw new Error("No address found after sign-in");const _=g.addresses.find(c=>h&&c.address.toLowerCase()===h.toLowerCase()),T=(_==null?void 0:_.index)??0;return w.setWalletIndex(T),w.notifyAccountsChanged(b),h&&o(h),{accounts:b,chainId:a}};try{const w=$();w.catch(()=>{});const k=await Promise.race([w.then(g=>({kind:"inner",value:g})),d.then(g=>({kind:"external",address:g}))]);if(k.kind==="external"){const g=C(),h=await e.getAddress().catch(()=>null),E=(h==null?void 0:h.address)??k.address,_=(await e.getAddresses().catch(()=>[])).map(c=>c.address).filter(c=>c.toLowerCase()!==E.toLowerCase()),T=[E,..._];return g.setWalletIndex((h==null?void 0:h.index)??0),g.notifyAccountsChanged(T),o(E),{accounts:T,chainId:a}}return k.value}finally{R=!1,S=null,D=!1}},async disconnect(){N=!0;try{const s=C();await e.signOut(),s.notifyDisconnect(),J(),f(),u(0),I.emitter.emit("disconnect")}finally{N=!1}},async getAccounts(){const l=C().getCurrentAccounts();if(l.length>0)return l;const a=await e.getAddress();return a?[a.address]:[]},async getChainId(){return C().getCurrentChainId()},async getProvider({chainId:s}={}){return C()},async isAuthorized(){return await G(),e.isAuthenticated()},async switchChain({chainId:s}){C().setChainId(s),I.emitter.emit("change",{chainId:s});const a=I.chains.find(d=>d.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")}}})}const re=Y,ae=F;exports.CROSSxEIP1193Provider=U;exports.ONEpocketEIP1193Provider=U;exports.createCROSSxConnector=F;exports.createONEpocketConnector=ae;exports.crossxConnector=Y;exports.onepocketConnector=re;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,4 +25,7 @@ export { crossxConnector, createCROSSxConnector } from './connector';
|
|
|
25
25
|
export type { CrossxConnectorOptions, CROSSxConnectorOptions, } from './connector';
|
|
26
26
|
export { CROSSxEIP1193Provider } from './provider';
|
|
27
27
|
export type { EIP1193RequestArguments } from './provider';
|
|
28
|
+
export { onepocketConnector, createONEpocketConnector } from './connector';
|
|
29
|
+
export type { OnepocketConnectorOptions, ONEpocketConnectorOptions, } from './connector';
|
|
30
|
+
export { CROSSxEIP1193Provider as ONEpocketEIP1193Provider } from './provider';
|
|
28
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,YAAY,EACV,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,YAAY,EACV,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EACV,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,IAAI,wBAAwB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createConnector as
|
|
2
|
-
import { UserRejectedRequestError as
|
|
3
|
-
import { ChainId as K, CROSSxError as H, ErrorCode as J, WALLET_BRAND_NAME as
|
|
4
|
-
function
|
|
1
|
+
import { createConnector as B } from "wagmi";
|
|
2
|
+
import { UserRejectedRequestError as Q } from "viem";
|
|
3
|
+
import { ChainId as K, CROSSxError as H, ErrorCode as J, WALLET_BRAND_NAME as X, createCROSSxSDK as V } from "@nexus-cross/crossx-sdk-core";
|
|
4
|
+
function Z(r) {
|
|
5
5
|
return parseInt(r.split(":")[1] ?? "1", 10);
|
|
6
6
|
}
|
|
7
7
|
function k(r) {
|
|
@@ -16,9 +16,9 @@ function F(r) {
|
|
|
16
16
|
i[n] = parseInt(t.substring(n * 2, n * 2 + 2), 16);
|
|
17
17
|
return new TextDecoder().decode(i);
|
|
18
18
|
}
|
|
19
|
-
class
|
|
19
|
+
class tt {
|
|
20
20
|
constructor(t, i = K.ONE_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 :
|
|
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 : Z(i), this.sdk.on("addressChanged", ({ address: n, index: u }) => {
|
|
22
22
|
this.setWalletIndex(u), this.notifyAccountsChanged([n]);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -41,6 +41,7 @@ class Z {
|
|
|
41
41
|
var u;
|
|
42
42
|
const n = i ?? [];
|
|
43
43
|
switch (t) {
|
|
44
|
+
// ── 계정 ──────────────────────────────────────────────────────────────
|
|
44
45
|
case "eth_requestAccounts":
|
|
45
46
|
case "eth_accounts": {
|
|
46
47
|
if (this.currentAccounts.length > 0)
|
|
@@ -48,35 +49,39 @@ class Z {
|
|
|
48
49
|
const e = await this.sdk.getAddress();
|
|
49
50
|
return e ? [e.address] : [];
|
|
50
51
|
}
|
|
52
|
+
// ── 체인 ──────────────────────────────────────────────────────────────
|
|
51
53
|
case "eth_chainId":
|
|
52
54
|
return q(this.chainId);
|
|
53
55
|
case "net_version":
|
|
54
56
|
return String(this.chainId);
|
|
57
|
+
// ── personal_sign ─────────────────────────────────────────────────────
|
|
55
58
|
case "personal_sign": {
|
|
56
|
-
const [e] = n,
|
|
59
|
+
const [e] = n, o = e.startsWith("0x") ? F(e) : e;
|
|
57
60
|
return (await this.sdk.signMessage(
|
|
58
61
|
k(this.chainId),
|
|
59
|
-
|
|
62
|
+
o,
|
|
60
63
|
{ index: this.walletIndex }
|
|
61
64
|
)).signature;
|
|
62
65
|
}
|
|
63
66
|
case "eth_sign": {
|
|
64
|
-
const [, e] = n,
|
|
67
|
+
const [, e] = n, o = e.startsWith("0x") ? F(e) : e;
|
|
65
68
|
return (await this.sdk.signMessage(
|
|
66
69
|
k(this.chainId),
|
|
67
|
-
|
|
70
|
+
o,
|
|
68
71
|
{ index: this.walletIndex }
|
|
69
72
|
)).signature;
|
|
70
73
|
}
|
|
74
|
+
// ── EIP-712 Typed Data ────────────────────────────────────────────────
|
|
71
75
|
case "eth_signTypedData":
|
|
72
76
|
case "eth_signTypedData_v3":
|
|
73
77
|
case "eth_signTypedData_v4": {
|
|
74
|
-
const [, e] = n,
|
|
75
|
-
return (m ? await this.sdk.signTypedDataOffchain(
|
|
78
|
+
const [, e] = n, o = typeof e == "string" ? JSON.parse(e) : e, f = (u = o == null ? void 0 : o.domain) == null ? void 0 : u.chainId, m = f == null || f === 0, A = m ? 0 : Number(f), p = { index: this.walletIndex };
|
|
79
|
+
return (m ? await this.sdk.signTypedDataOffchain(o, p) : await this.sdk.signTypedData(k(A), o, p)).signature;
|
|
76
80
|
}
|
|
81
|
+
// ── 트랜잭션 전송 ─────────────────────────────────────────────────────
|
|
77
82
|
case "eth_sendTransaction": {
|
|
78
|
-
const [e] = n,
|
|
79
|
-
return (await this.sdk.sendTransaction(
|
|
83
|
+
const [e] = n, o = k(this.chainId);
|
|
84
|
+
return (await this.sdk.sendTransaction(o, {
|
|
80
85
|
from: e.from,
|
|
81
86
|
to: e.to,
|
|
82
87
|
value: e.value,
|
|
@@ -89,12 +94,14 @@ class Z {
|
|
|
89
94
|
chainId: this.chainId
|
|
90
95
|
}, { index: this.walletIndex })).txHash;
|
|
91
96
|
}
|
|
97
|
+
// ── 체인 전환 ─────────────────────────────────────────────────────────
|
|
92
98
|
case "wallet_switchEthereumChain": {
|
|
93
|
-
const [{ chainId: e }] = n,
|
|
94
|
-
return
|
|
99
|
+
const [{ chainId: e }] = n, o = parseInt(e, 16);
|
|
100
|
+
return o !== this.chainId && (this.chainId = o, this.emit("chainChanged", q(o))), null;
|
|
95
101
|
}
|
|
96
102
|
case "wallet_addEthereumChain":
|
|
97
103
|
return null;
|
|
104
|
+
// ── 그 외 읽기 RPC → SDK walletRpc 프록시 ────────────────────────────
|
|
98
105
|
default:
|
|
99
106
|
return this.sdk.walletRpc(t, n, k(this.chainId));
|
|
100
107
|
}
|
|
@@ -139,11 +146,11 @@ class Z {
|
|
|
139
146
|
return [...this.currentAccounts];
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
|
-
function
|
|
149
|
+
function et(r) {
|
|
143
150
|
return typeof r == "number" ? r : parseInt(r.split(":")[1] ?? "1", 10);
|
|
144
151
|
}
|
|
145
152
|
const M = "crossx-wallet-index";
|
|
146
|
-
function
|
|
153
|
+
function nt() {
|
|
147
154
|
try {
|
|
148
155
|
const r = typeof window < "u" ? localStorage.getItem(M) : null;
|
|
149
156
|
return r && Number(r) || 0;
|
|
@@ -151,7 +158,7 @@ function et() {
|
|
|
151
158
|
return 0;
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
|
-
function
|
|
161
|
+
function st(r) {
|
|
155
162
|
try {
|
|
156
163
|
typeof window < "u" && localStorage.setItem(M, String(r));
|
|
157
164
|
} catch {
|
|
@@ -164,60 +171,60 @@ function j() {
|
|
|
164
171
|
}
|
|
165
172
|
}
|
|
166
173
|
const U = "crossx-wallet-address";
|
|
167
|
-
function
|
|
174
|
+
function rt() {
|
|
168
175
|
try {
|
|
169
176
|
return typeof window < "u" ? localStorage.getItem(U) : null;
|
|
170
177
|
} catch {
|
|
171
178
|
return null;
|
|
172
179
|
}
|
|
173
180
|
}
|
|
174
|
-
function
|
|
181
|
+
function at(r) {
|
|
175
182
|
try {
|
|
176
183
|
typeof window < "u" && localStorage.setItem(U, r);
|
|
177
184
|
} catch {
|
|
178
185
|
}
|
|
179
186
|
}
|
|
180
|
-
function
|
|
187
|
+
function it() {
|
|
181
188
|
try {
|
|
182
189
|
typeof window < "u" && localStorage.removeItem(U);
|
|
183
190
|
} catch {
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
function
|
|
187
|
-
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: u, onWalletAddressChanged: e, clearStoredWalletAddress:
|
|
193
|
+
function ot(r) {
|
|
194
|
+
const { defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: u, onWalletAddressChanged: e, clearStoredWalletAddress: o, openConnectOtherWallet: f, ...m } = r;
|
|
188
195
|
if (f) {
|
|
189
|
-
const
|
|
190
|
-
!E && !
|
|
196
|
+
const p = m.connectOtherWallets, E = Array.isArray(p) && p.length > 0, x = m.showConnectOtherWallets === !0;
|
|
197
|
+
!E && !x && (m.showConnectOtherWallets = !0);
|
|
191
198
|
}
|
|
192
|
-
const A =
|
|
193
|
-
return
|
|
199
|
+
const A = V(m);
|
|
200
|
+
return Y({ sdk: A, defaultChainId: t, getStoredWalletIndex: i, onWalletIndexChanged: n, getStoredWalletAddress: u, onWalletAddressChanged: e, clearStoredWalletAddress: o, openConnectOtherWallet: f });
|
|
194
201
|
}
|
|
195
|
-
function
|
|
202
|
+
function Y(r) {
|
|
196
203
|
const {
|
|
197
204
|
sdk: t,
|
|
198
205
|
defaultChainId: i = K.ONE_MAINNET,
|
|
199
|
-
getStoredWalletIndex: n =
|
|
200
|
-
onWalletIndexChanged: u =
|
|
201
|
-
getStoredWalletAddress: e =
|
|
202
|
-
onWalletAddressChanged:
|
|
203
|
-
clearStoredWalletAddress: f =
|
|
206
|
+
getStoredWalletIndex: n = nt,
|
|
207
|
+
onWalletIndexChanged: u = st,
|
|
208
|
+
getStoredWalletAddress: e = rt,
|
|
209
|
+
onWalletAddressChanged: o = at,
|
|
210
|
+
clearStoredWalletAddress: f = it,
|
|
204
211
|
openConnectOtherWallet: m
|
|
205
|
-
} = r, A =
|
|
206
|
-
let
|
|
207
|
-
function
|
|
212
|
+
} = r, A = et(i);
|
|
213
|
+
let p = null, E = !1, x = null, z = !1, D = !1, P = !1, y = null, v = !1;
|
|
214
|
+
function N(I) {
|
|
208
215
|
const W = y;
|
|
209
|
-
return W ? (y = null,
|
|
216
|
+
return W ? (y = null, v = !1, W(I), !0) : !1;
|
|
210
217
|
}
|
|
211
218
|
function C() {
|
|
212
|
-
return
|
|
219
|
+
return p || (p = new tt(t, A), p._setWalletIndexChangeCallback(u)), p;
|
|
213
220
|
}
|
|
214
|
-
return
|
|
221
|
+
return B((I) => {
|
|
215
222
|
function W(s) {
|
|
216
223
|
if (z) return;
|
|
217
224
|
const l = C();
|
|
218
225
|
l.on("accountsChanged", s.onAccountsChanged.bind(s)), l.on("chainChanged", s.onChainChanged.bind(s)), l.on("disconnect", s.onDisconnect.bind(s)), z = !0;
|
|
219
226
|
}
|
|
220
|
-
function
|
|
227
|
+
function L(s) {
|
|
221
228
|
const l = C();
|
|
222
229
|
l.notifyAccountsChanged([s]), I.emitter.emit("connect", {
|
|
223
230
|
accounts: [s],
|
|
@@ -226,23 +233,23 @@ function it(r) {
|
|
|
226
233
|
}
|
|
227
234
|
async function G() {
|
|
228
235
|
if (!E)
|
|
229
|
-
return
|
|
236
|
+
return x || (x = (async () => {
|
|
230
237
|
const s = n(), l = e() ?? void 0;
|
|
231
238
|
await t.initialize({ preferredWalletIndex: s, preferredWalletAddress: l }), t.on("addressChanged", ({ address: a, index: d }) => {
|
|
232
239
|
if (D) {
|
|
233
|
-
|
|
240
|
+
v && a && t.isAuthenticated() && y && (C().setWalletIndex(d), o(a), N(a));
|
|
234
241
|
return;
|
|
235
242
|
}
|
|
236
|
-
const
|
|
237
|
-
|
|
243
|
+
const R = C();
|
|
244
|
+
R.setWalletIndex(d), a && (o(a), t.isAuthenticated() ? L(a) : R.notifyAccountsChanged([a]));
|
|
238
245
|
}), t.on("authChanged", (a) => {
|
|
239
246
|
if (a.isAuthenticated && a.source === "external" && y) {
|
|
240
247
|
if (a.address) {
|
|
241
|
-
|
|
248
|
+
N(a.address);
|
|
242
249
|
return;
|
|
243
250
|
}
|
|
244
|
-
|
|
245
|
-
d != null && d.address && t.isAuthenticated() &&
|
|
251
|
+
v = !0, t.getAddress().then((d) => {
|
|
252
|
+
d != null && d.address && t.isAuthenticated() && N(d.address);
|
|
246
253
|
}).catch(() => {
|
|
247
254
|
});
|
|
248
255
|
return;
|
|
@@ -250,11 +257,11 @@ function it(r) {
|
|
|
250
257
|
if (!(D || P)) {
|
|
251
258
|
if (a.isAuthenticated) {
|
|
252
259
|
if (a.address) {
|
|
253
|
-
|
|
260
|
+
L(a.address);
|
|
254
261
|
return;
|
|
255
262
|
}
|
|
256
263
|
t.getAddress().then((d) => {
|
|
257
|
-
d != null && d.address && t.isAuthenticated() &&
|
|
264
|
+
d != null && d.address && t.isAuthenticated() && L(d.address);
|
|
258
265
|
}).catch(() => {
|
|
259
266
|
});
|
|
260
267
|
return;
|
|
@@ -263,12 +270,12 @@ function it(r) {
|
|
|
263
270
|
}
|
|
264
271
|
}), m && t.on("connectExternalWallet", m), E = !0;
|
|
265
272
|
})().finally(() => {
|
|
266
|
-
|
|
267
|
-
}),
|
|
273
|
+
x = null;
|
|
274
|
+
}), x);
|
|
268
275
|
}
|
|
269
276
|
return {
|
|
270
277
|
id: "crossx",
|
|
271
|
-
name:
|
|
278
|
+
name: X,
|
|
272
279
|
type: "crossx",
|
|
273
280
|
async setup() {
|
|
274
281
|
await G(), W(this);
|
|
@@ -279,14 +286,14 @@ function it(r) {
|
|
|
279
286
|
D = !0;
|
|
280
287
|
const d = new Promise((w) => {
|
|
281
288
|
y = w;
|
|
282
|
-
}),
|
|
283
|
-
await G(), W(
|
|
289
|
+
}), R = this, $ = async () => {
|
|
290
|
+
await G(), W(R);
|
|
284
291
|
const w = C();
|
|
285
292
|
if (t.isAuthenticated()) {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
return w.setWalletIndex(
|
|
289
|
-
accounts: [
|
|
293
|
+
const c = await t.getAddress();
|
|
294
|
+
if (c)
|
|
295
|
+
return w.setWalletIndex(c.index), w.notifyAccountsChanged([c.address]), {
|
|
296
|
+
accounts: [c.address],
|
|
290
297
|
chainId: a
|
|
291
298
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
299
|
};
|
|
@@ -305,25 +312,25 @@ function it(r) {
|
|
|
305
312
|
g = await t.signInWithCreate({
|
|
306
313
|
preferredWalletAddress: _ ?? void 0
|
|
307
314
|
});
|
|
308
|
-
} catch (
|
|
309
|
-
throw
|
|
315
|
+
} catch (c) {
|
|
316
|
+
throw c instanceof H && c.code === J.EXTERNAL_WALLET_REQUESTED ? (w.notifyDisconnect(), new Q(c)) : (t.isAuthenticated() || (w.notifyDisconnect(), I.emitter.emit("disconnect")), c);
|
|
310
317
|
}
|
|
311
318
|
if (!g.success)
|
|
312
319
|
throw new Error(g.error ?? "CROSSx sign-in failed");
|
|
313
|
-
const h = g.address, S = g.addresses.map((
|
|
314
|
-
if (
|
|
320
|
+
const h = g.address, S = g.addresses.map((c) => c.address).filter((c) => !h || c.toLowerCase() !== h.toLowerCase()), T = h ? [h, ...S] : S;
|
|
321
|
+
if (T.length === 0)
|
|
315
322
|
throw new Error("No address found after sign-in");
|
|
316
323
|
const O = g.addresses.find(
|
|
317
|
-
(
|
|
318
|
-
),
|
|
319
|
-
return w.setWalletIndex(
|
|
320
|
-
accounts:
|
|
324
|
+
(c) => h && c.address.toLowerCase() === h.toLowerCase()
|
|
325
|
+
), b = (O == null ? void 0 : O.index) ?? 0;
|
|
326
|
+
return w.setWalletIndex(b), w.notifyAccountsChanged(T), h && o(h), {
|
|
327
|
+
accounts: T,
|
|
321
328
|
chainId: a
|
|
322
329
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
330
|
};
|
|
324
331
|
};
|
|
325
332
|
try {
|
|
326
|
-
const w =
|
|
333
|
+
const w = $();
|
|
327
334
|
w.catch(() => {
|
|
328
335
|
});
|
|
329
336
|
const _ = await Promise.race([
|
|
@@ -331,16 +338,16 @@ function it(r) {
|
|
|
331
338
|
d.then((g) => ({ kind: "external", address: g }))
|
|
332
339
|
]);
|
|
333
340
|
if (_.kind === "external") {
|
|
334
|
-
const g = C(), h = await t.getAddress().catch(() => null), S = (h == null ? void 0 : h.address) ?? _.address, O = (await t.getAddresses().catch(() => [])).map((
|
|
335
|
-
return g.setWalletIndex((h == null ? void 0 : h.index) ?? 0), g.notifyAccountsChanged(
|
|
336
|
-
accounts:
|
|
341
|
+
const g = C(), h = await t.getAddress().catch(() => null), S = (h == null ? void 0 : h.address) ?? _.address, O = (await t.getAddresses().catch(() => [])).map((c) => c.address).filter((c) => c.toLowerCase() !== S.toLowerCase()), b = [S, ...O];
|
|
342
|
+
return g.setWalletIndex((h == null ? void 0 : h.index) ?? 0), g.notifyAccountsChanged(b), o(S), {
|
|
343
|
+
accounts: b,
|
|
337
344
|
chainId: a
|
|
338
345
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
339
346
|
};
|
|
340
347
|
}
|
|
341
348
|
return _.value;
|
|
342
349
|
} finally {
|
|
343
|
-
D = !1, y = null,
|
|
350
|
+
D = !1, y = null, v = !1;
|
|
344
351
|
}
|
|
345
352
|
},
|
|
346
353
|
// ── disconnect ──────────────────────────────────────────────────────────
|
|
@@ -397,8 +404,12 @@ function it(r) {
|
|
|
397
404
|
};
|
|
398
405
|
});
|
|
399
406
|
}
|
|
407
|
+
const ht = ot, ut = Y;
|
|
400
408
|
export {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
409
|
+
tt as CROSSxEIP1193Provider,
|
|
410
|
+
tt as ONEpocketEIP1193Provider,
|
|
411
|
+
Y as createCROSSxConnector,
|
|
412
|
+
ut as createONEpocketConnector,
|
|
413
|
+
ot as crossxConnector,
|
|
414
|
+
ht as onepocketConnector
|
|
404
415
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-beta.1",
|
|
4
4
|
"description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@nexus-cross/crossx-sdk-core": "^2.
|
|
21
|
+
"@nexus-cross/crossx-sdk-core": "^2.5.0-beta.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@nexus-cross/crossx-sdk-core": "^
|
|
24
|
+
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|
|
25
25
|
"viem": ">=2.0.0",
|
|
26
26
|
"wagmi": ">=2.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "^5.3.3",
|
|
30
30
|
"viem": "^2.46.2",
|
|
31
|
-
"vite": "^
|
|
31
|
+
"vite": "^6.4.3",
|
|
32
32
|
"vite-plugin-dts": "^3.7.1",
|
|
33
|
-
"vitest": "^
|
|
33
|
+
"vitest": "^3.2.0",
|
|
34
34
|
"wagmi": "^3.5.0"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|