@nexus-cross/crossx-sdk-wagmi 1.0.2-beta.1 → 1.0.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.
@@ -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;CAClC;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,CAAC;AAWF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GAwIpE"}
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;CAClC;AAED,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,CAAC;AAWF,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,8GAI9D;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,8GA6IpE"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("wagmi"),I=require("@nexus-cross/crossx-sdk-core");function w(r){return parseInt(r.split(":")[1]??"1",10)}function h(r){return`eip155:${r}`}function C(r){return"0x"+r.toString(16)}class p{constructor(t,a=I.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.off=this.removeListener.bind(this),this.chainId=typeof a=="number"?a:w(a)}async request({method:t,params:a}){var o;const i=a??[];switch(t){case"eth_requestAccounts":case"eth_accounts":{const n=await this.sdk.getAddress();return n?[n.address]:[]}case"eth_chainId":return C(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[n]=i;return(await this.sdk.signMessage(h(this.chainId),n)).signature}case"eth_sign":{const[,n]=i;return(await this.sdk.signMessage(h(this.chainId),n)).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,n]=i,s=typeof n=="string"?JSON.parse(n):n,c=(o=s==null?void 0:s.domain)==null?void 0:o.chainId;return(c==null||c===0?await this.sdk.signTypedDataOffchain(s):await this.sdk.signTypedData(h(this.chainId),s)).signature}case"eth_sendTransaction":{const[n]=i,s=h(this.chainId);return(await this.sdk.sendTransaction(s,{from:n.from,to:n.to,value:n.value,data:n.data,gasLimit:n.gasLimit??n.gas,gasPrice:n.gasPrice,maxFeePerGas:n.maxFeePerGas,maxPriorityFeePerGas:n.maxPriorityFeePerGas,nonce:n.nonce!==void 0?parseInt(String(n.nonce),16):void 0,chainId:this.chainId})).txHash}case"wallet_switchEthereumChain":{const[{chainId:n}]=i,s=parseInt(n,16);return s!==this.chainId&&(this.chainId=s,this.emit("chainChanged",C(s))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,i,h(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.emit("accountsChanged",t)}notifyDisconnect(t){this.emit("disconnect",t)}getCurrentChainId(){return this.chainId}setChainId(t){t!==this.chainId&&(this.chainId=t,this.emit("chainChanged",C(t)))}}function x(r){return typeof r=="number"?r:parseInt(r.split(":")[1]??"1",10)}function _(r){const{defaultChainId:t,...a}=r,i=I.createCROSSxSDK(a);return y({sdk:i,defaultChainId:t})}function y(r){const{sdk:t,defaultChainId:a=I.ChainId.CROSS_MAINNET}=r,i=x(a);let o=null,n=!1;function s(){return o||(o=new p(t,i)),o}return S.createConnector(c=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){n||(await t.initialize(),n=!0);const e=s();e.on("accountsChanged",this.onAccountsChanged.bind(this)),e.on("chainChanged",this.onChainChanged.bind(this)),e.on("disconnect",this.onDisconnect.bind(this))},async connect({chainId:e,isReconnecting:g}={}){const d=s(),u=e??i;if(g||t.isAuthenticated()){const m=await t.getAddress();if(m)return{accounts:[m.address],chainId:u}}const f=await t.signIn();if(!f.success)throw new Error(f.error??"CROSSx sign-in failed");const l=await t.getAddress();if(!l)throw new Error("No address found after sign-in");return d.notifyAccountsChanged([l.address]),{accounts:[l.address],chainId:u}},async disconnect(){const e=s();await t.signOut(),e.notifyDisconnect(),c.emitter.emit("disconnect")},async getAccounts(){const e=await t.getAddress();return e?[e.address]:[]},async getChainId(){return s().getCurrentChainId()},async getProvider({chainId:e}={}){return s()},async isAuthorized(){return t.isAuthenticated()},async switchChain({chainId:e}){s().setChainId(e),c.emitter.emit("change",{chainId:e});const d=c.chains.find(u=>u.id===e);if(!d)throw new Error(`Chain ${e} is not configured`);return d},onAccountsChanged(e){e.length===0?c.emitter.emit("disconnect"):c.emitter.emit("change",{accounts:e})},onChainChanged(e){c.emitter.emit("change",{chainId:Number(e)})},onDisconnect(){c.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=p;exports.createCROSSxConnector=y;exports.crossxConnector=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("wagmi"),m=require("@nexus-cross/crossx-sdk-core");function w(r){return parseInt(r.split(":")[1]??"1",10)}function d(r){return`eip155:${r}`}function f(r){return"0x"+r.toString(16)}class p{constructor(t,a=m.ChainId.CROSS_MAINNET){this.sdk=t,this.listeners=new Map,this.off=this.removeListener.bind(this),this.chainId=typeof a=="number"?a:w(a)}async request({method:t,params:a}){var o;const i=a??[];switch(t){case"eth_requestAccounts":case"eth_accounts":{const e=await this.sdk.getAddress();return e?[e.address]:[]}case"eth_chainId":return f(this.chainId);case"net_version":return String(this.chainId);case"personal_sign":{const[e]=i;return(await this.sdk.signMessage(d(this.chainId),e)).signature}case"eth_sign":{const[,e]=i;return(await this.sdk.signMessage(d(this.chainId),e)).signature}case"eth_signTypedData":case"eth_signTypedData_v3":case"eth_signTypedData_v4":{const[,e]=i,s=typeof e=="string"?JSON.parse(e):e,c=(o=s==null?void 0:s.domain)==null?void 0:o.chainId;return(c==null||c===0?await this.sdk.signTypedDataOffchain(s):await this.sdk.signTypedData(d(this.chainId),s)).signature}case"eth_sendTransaction":{const[e]=i,s=d(this.chainId);return(await this.sdk.sendTransaction(s,{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})).txHash}case"wallet_switchEthereumChain":{const[{chainId:e}]=i,s=parseInt(e,16);return s!==this.chainId&&(this.chainId=s,this.emit("chainChanged",f(s))),null}case"wallet_addEthereumChain":return null;default:return this.sdk.walletRpc(t,i,d(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.emit("accountsChanged",t)}notifyDisconnect(t){this.emit("disconnect",t)}getCurrentChainId(){return this.chainId}setChainId(t){t!==this.chainId&&(this.chainId=t,this.emit("chainChanged",f(t)))}}function x(r){return typeof r=="number"?r:parseInt(r.split(":")[1]??"1",10)}function _(r){const{defaultChainId:t,...a}=r,i=m.createCROSSxSDK(a);return y({sdk:i,defaultChainId:t})}function y(r){const{sdk:t,defaultChainId:a=m.ChainId.CROSS_MAINNET}=r,i=x(a);let o=null,e=!1;function s(){return o||(o=new p(t,i)),o}return S.createConnector(c=>({id:"crossx",name:"CROSSx Wallet",type:"crossx",async setup(){e||(await t.initialize(),e=!0);const n=s();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:C}={}){const u=s(),g=n??i;if(C||t.isAuthenticated()){const l=await t.getAddress();if(l)return{accounts:[l.address],chainId:g}}const h=await t.signInWithCreate();if(!h.success)throw new Error(h.error??"CROSSx sign-in failed");const I=h.addresses.length>0?h.addresses.map(l=>l.address):h.address?[h.address]:[];if(I.length===0)throw new Error("No address found after sign-in");return u.notifyAccountsChanged(I),{accounts:I,chainId:g}},async disconnect(){const n=s();await t.signOut(),n.notifyDisconnect(),c.emitter.emit("disconnect")},async getAccounts(){const n=await t.getAddress();return n?[n.address]:[]},async getChainId(){return s().getCurrentChainId()},async getProvider({chainId:n}={}){return s()},async isAuthorized(){return t.isAuthenticated()},async switchChain({chainId:n}){s().setChainId(n),c.emitter.emit("change",{chainId:n});const u=c.chains.find(g=>g.id===n);if(!u)throw new Error(`Chain ${n} is not configured`);return u},onAccountsChanged(n){n.length===0?c.emitter.emit("disconnect"):c.emitter.emit("change",{accounts:n})},onChainChanged(n){c.emitter.emit("change",{chainId:Number(n)})},onDisconnect(){c.emitter.emit("disconnect")}}))}exports.CROSSxEIP1193Provider=p;exports.createCROSSxConnector=y;exports.crossxConnector=_;
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { createConnector as p } from "wagmi";
2
- import { ChainId as C, createCROSSxSDK as w } from "@nexus-cross/crossx-sdk-core";
3
- function y(r) {
2
+ import { ChainId as C, createCROSSxSDK as y } from "@nexus-cross/crossx-sdk-core";
3
+ function w(r) {
4
4
  return parseInt(r.split(":")[1] ?? "1", 10);
5
5
  }
6
- function h(r) {
6
+ function d(r) {
7
7
  return `eip155:${r}`;
8
8
  }
9
- function f(r) {
9
+ function I(r) {
10
10
  return "0x" + r.toString(16);
11
11
  }
12
12
  class S {
13
13
  constructor(t, a = C.CROSS_MAINNET) {
14
- this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.off = this.removeListener.bind(this), this.chainId = typeof a == "number" ? a : y(a);
14
+ this.sdk = t, this.listeners = /* @__PURE__ */ new Map(), this.off = this.removeListener.bind(this), this.chainId = typeof a == "number" ? a : w(a);
15
15
  }
16
16
  // ── EIP-1193 request ──────────────────────────────────────────────────────
17
17
  async request({ method: t, params: a }) {
@@ -24,25 +24,25 @@ class S {
24
24
  return n ? [n.address] : [];
25
25
  }
26
26
  case "eth_chainId":
27
- return f(this.chainId);
27
+ return I(this.chainId);
28
28
  case "net_version":
29
29
  return String(this.chainId);
30
30
  case "personal_sign": {
31
31
  const [n] = i;
32
- return (await this.sdk.signMessage(h(this.chainId), n)).signature;
32
+ return (await this.sdk.signMessage(d(this.chainId), n)).signature;
33
33
  }
34
34
  case "eth_sign": {
35
35
  const [, n] = i;
36
- return (await this.sdk.signMessage(h(this.chainId), n)).signature;
36
+ return (await this.sdk.signMessage(d(this.chainId), n)).signature;
37
37
  }
38
38
  case "eth_signTypedData":
39
39
  case "eth_signTypedData_v3":
40
40
  case "eth_signTypedData_v4": {
41
41
  const [, n] = i, s = typeof n == "string" ? JSON.parse(n) : n, c = (o = s == null ? void 0 : s.domain) == null ? void 0 : o.chainId;
42
- return (c == null || c === 0 ? await this.sdk.signTypedDataOffchain(s) : await this.sdk.signTypedData(h(this.chainId), s)).signature;
42
+ return (c == null || c === 0 ? await this.sdk.signTypedDataOffchain(s) : await this.sdk.signTypedData(d(this.chainId), s)).signature;
43
43
  }
44
44
  case "eth_sendTransaction": {
45
- const [n] = i, s = h(this.chainId);
45
+ const [n] = i, s = d(this.chainId);
46
46
  return (await this.sdk.sendTransaction(s, {
47
47
  from: n.from,
48
48
  to: n.to,
@@ -58,12 +58,12 @@ class S {
58
58
  }
59
59
  case "wallet_switchEthereumChain": {
60
60
  const [{ chainId: n }] = i, s = parseInt(n, 16);
61
- return s !== this.chainId && (this.chainId = s, this.emit("chainChanged", f(s))), null;
61
+ return s !== this.chainId && (this.chainId = s, this.emit("chainChanged", I(s))), null;
62
62
  }
63
63
  case "wallet_addEthereumChain":
64
64
  return null;
65
65
  default:
66
- return this.sdk.walletRpc(t, i, h(this.chainId));
66
+ return this.sdk.walletRpc(t, i, d(this.chainId));
67
67
  }
68
68
  }
69
69
  // ── EIP-1193 이벤트 ───────────────────────────────────────────────────────
@@ -89,14 +89,14 @@ class S {
89
89
  return this.chainId;
90
90
  }
91
91
  setChainId(t) {
92
- t !== this.chainId && (this.chainId = t, this.emit("chainChanged", f(t)));
92
+ t !== this.chainId && (this.chainId = t, this.emit("chainChanged", I(t)));
93
93
  }
94
94
  }
95
95
  function x(r) {
96
96
  return typeof r == "number" ? r : parseInt(r.split(":")[1] ?? "1", 10);
97
97
  }
98
98
  function O(r) {
99
- const { defaultChainId: t, ...a } = r, i = w(a);
99
+ const { defaultChainId: t, ...a } = r, i = y(a);
100
100
  return _({ sdk: i, defaultChainId: t });
101
101
  }
102
102
  function _(r) {
@@ -115,25 +115,25 @@ function _(r) {
115
115
  e.on("accountsChanged", this.onAccountsChanged.bind(this)), e.on("chainChanged", this.onChainChanged.bind(this)), e.on("disconnect", this.onDisconnect.bind(this));
116
116
  },
117
117
  // ── connect ─────────────────────────────────────────────────────────────
118
- async connect({ chainId: e, isReconnecting: g } = {}) {
119
- const d = s(), u = e ?? i;
120
- if (g || t.isAuthenticated()) {
121
- const m = await t.getAddress();
122
- if (m)
118
+ async connect({ chainId: e, isReconnecting: f } = {}) {
119
+ const u = s(), g = e ?? i;
120
+ if (f || t.isAuthenticated()) {
121
+ const l = await t.getAddress();
122
+ if (l)
123
123
  return {
124
- accounts: [m.address],
125
- chainId: u
124
+ accounts: [l.address],
125
+ chainId: g
126
126
  };
127
127
  }
128
- const I = await t.signIn();
129
- if (!I.success)
130
- throw new Error(I.error ?? "CROSSx sign-in failed");
131
- const l = await t.getAddress();
132
- if (!l)
128
+ const h = await t.signInWithCreate();
129
+ if (!h.success)
130
+ throw new Error(h.error ?? "CROSSx sign-in failed");
131
+ const m = h.addresses.length > 0 ? h.addresses.map((l) => l.address) : h.address ? [h.address] : [];
132
+ if (m.length === 0)
133
133
  throw new Error("No address found after sign-in");
134
- return d.notifyAccountsChanged([l.address]), {
135
- accounts: [l.address],
136
- chainId: u
134
+ return u.notifyAccountsChanged(m), {
135
+ accounts: m,
136
+ chainId: g
137
137
  };
138
138
  },
139
139
  // ── disconnect ──────────────────────────────────────────────────────────
@@ -161,10 +161,10 @@ function _(r) {
161
161
  // ── switchChain ─────────────────────────────────────────────────────────
162
162
  async switchChain({ chainId: e }) {
163
163
  s().setChainId(e), c.emitter.emit("change", { chainId: e });
164
- const d = c.chains.find((u) => u.id === e);
165
- if (!d)
164
+ const u = c.chains.find((g) => g.id === e);
165
+ if (!u)
166
166
  throw new Error(`Chain ${e} is not configured`);
167
- return d;
167
+ return u;
168
168
  },
169
169
  // ── 이벤트 핸들러 ───────────────────────────────────────────────────────
170
170
  onAccountsChanged(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/crossx-sdk-wagmi",
3
- "version": "1.0.2-beta.1",
3
+ "version": "1.0.3",
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.2-beta.1"
20
+ "@nexus-cross/crossx-sdk-core": "1.0.3"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": ">=2.0.0",