@gardenfi/wallet-connectors 3.0.0-beta.19 → 3.0.0-beta.20

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/index10.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.Mainnet="mainnet",e.Regtest="regtest",e))(t||{});exports.XverseSparkNetworkType=t;
1
+ "use strict";var l=i=>{throw TypeError(i)};var d=(i,t,e)=>t.has(i)||l("Cannot "+e);var n=(i,t,e)=>(d(i,t,"read from private field"),e?e.call(i):t.get(i)),h=(i,t,e)=>t.has(i)?l("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),a=(i,t,e,u)=>(d(i,t,"write to private field"),u?u.call(i,e):t.set(i,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),o=require("./index3.cjs");var s,c;class w{constructor(t,e){h(this,s);h(this,c);this.address="",this.id=o.WALLET_CONFIG.OKX.id,this.name=o.WALLET_CONFIG.OKX.name,this.icon=o.WALLET_CONFIG.OKX.icon,this.disconnect=()=>(this.address="",n(this,s).disconnect(),Promise.resolve(r.Ok("Disconnected OKX wallet"))),a(this,s,t),a(this,c,e)}async connect(){try{const t=await n(this,s).connect();return!t||!t.address?r.Err("Failed to connect to OKX wallet"):(this.address=t.address,r.Ok({address:this.address,provider:this,network:n(this,c),id:o.WALLET_CONFIG.OKX.id}))}catch(t){return r.Err("Error while connecting to the OKX wallet",t)}}async getPublicKey(){return await r.executeWithTryCatch(async()=>await n(this,s).getPublicKey(),"Error while getting public key from OKX wallet")}async requestAccounts(){const t=await this.connect();return t.ok?r.Ok([t.val.address]):r.Err(t.error)}async getAccounts(){return n(this,c)===r.Network.TESTNET?await this.requestAccounts():await r.executeWithTryCatch(async()=>await n(this,s).getAccounts(),"Error while getting accounts from OKX wallet")}async getNetwork(){return r.Ok(n(this,c))}async switchNetwork(){a(this,c,n(this,c)===r.Network.MAINNET?r.Network.TESTNET:r.Network.MAINNET);const t=await this.connect();return t.error?r.Err(`Failed to connect to ${n(this,c)}: ${t.error}`):r.Ok(n(this,c))}async getBalance(){return await r.executeWithTryCatch(async()=>await n(this,s).getBalance(),"Error while getting balance from OKX wallet")}async sendBitcoin(t,e){return await r.executeWithTryCatch(async()=>await n(this,s).sendBitcoin(t,e),"Error while sending bitcoin from OKX wallet")}on(t,e){n(this,s).on(t,e)}off(t,e){n(this,s).off(t,e)}}s=new WeakMap,c=new WeakMap;exports.OKXProvider=w;
package/dist/index10.js CHANGED
@@ -1,4 +1,64 @@
1
- var n = /* @__PURE__ */ ((t) => (t.Mainnet = "mainnet", t.Regtest = "regtest", t))(n || {});
1
+ var y = (e) => {
2
+ throw TypeError(e);
3
+ };
4
+ var g = (e, t, r) => t.has(e) || y("Cannot " + r);
5
+ var n = (e, t, r) => (g(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), a = (e, t, r, w) => (g(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r);
6
+ import { Ok as c, Err as o, executeWithTryCatch as h, Network as l } from "@gardenfi/utils";
7
+ import { WALLET_CONFIG as u } from "./index3.js";
8
+ var i, s;
9
+ class E {
10
+ constructor(t, r) {
11
+ d(this, i);
12
+ d(this, s);
13
+ this.address = "", this.id = u.OKX.id, this.name = u.OKX.name, this.icon = u.OKX.icon, this.disconnect = () => (this.address = "", n(this, i).disconnect(), Promise.resolve(c("Disconnected OKX wallet"))), a(this, i, t), a(this, s, r);
14
+ }
15
+ async connect() {
16
+ try {
17
+ const t = await n(this, i).connect();
18
+ return !t || !t.address ? o("Failed to connect to OKX wallet") : (this.address = t.address, c({
19
+ address: this.address,
20
+ provider: this,
21
+ network: n(this, s),
22
+ id: u.OKX.id
23
+ }));
24
+ } catch (t) {
25
+ return o("Error while connecting to the OKX wallet", t);
26
+ }
27
+ }
28
+ async getPublicKey() {
29
+ return await h(async () => await n(this, i).getPublicKey(), "Error while getting public key from OKX wallet");
30
+ }
31
+ async requestAccounts() {
32
+ const t = await this.connect();
33
+ return t.ok ? c([t.val.address]) : o(t.error);
34
+ }
35
+ async getAccounts() {
36
+ return n(this, s) === l.TESTNET ? await this.requestAccounts() : await h(async () => await n(this, i).getAccounts(), "Error while getting accounts from OKX wallet");
37
+ }
38
+ async getNetwork() {
39
+ return c(n(this, s));
40
+ }
41
+ async switchNetwork() {
42
+ a(this, s, n(this, s) === l.MAINNET ? l.TESTNET : l.MAINNET);
43
+ const t = await this.connect();
44
+ return t.error ? o(
45
+ `Failed to connect to ${n(this, s)}: ${t.error}`
46
+ ) : c(n(this, s));
47
+ }
48
+ async getBalance() {
49
+ return await h(async () => await n(this, i).getBalance(), "Error while getting balance from OKX wallet");
50
+ }
51
+ async sendBitcoin(t, r) {
52
+ return await h(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
53
+ }
54
+ on(t, r) {
55
+ n(this, i).on(t, r);
56
+ }
57
+ off(t, r) {
58
+ n(this, i).off(t, r);
59
+ }
60
+ }
61
+ i = new WeakMap(), s = new WeakMap();
2
62
  export {
3
- n as XverseSparkNetworkType
63
+ E as OKXProvider
4
64
  };
package/dist/index11.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var l=i=>{throw TypeError(i)};var d=(i,t,e)=>t.has(i)||l("Cannot "+e);var n=(i,t,e)=>(d(i,t,"read from private field"),e?e.call(i):t.get(i)),h=(i,t,e)=>t.has(i)?l("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),a=(i,t,e,u)=>(d(i,t,"write to private field"),u?u.call(i,e):t.set(i,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),o=require("./index3.cjs");var s,c;class w{constructor(t,e){h(this,s);h(this,c);this.address="",this.id=o.WALLET_CONFIG.OKX.id,this.name=o.WALLET_CONFIG.OKX.name,this.icon=o.WALLET_CONFIG.OKX.icon,this.disconnect=()=>(this.address="",n(this,s).disconnect(),Promise.resolve(r.Ok("Disconnected OKX wallet"))),a(this,s,t),a(this,c,e)}async connect(){try{const t=await n(this,s).connect();return!t||!t.address?r.Err("Failed to connect to OKX wallet"):(this.address=t.address,r.Ok({address:this.address,provider:this,network:n(this,c),id:o.WALLET_CONFIG.OKX.id}))}catch(t){return r.Err("Error while connecting to the OKX wallet",t)}}async getPublicKey(){return await r.executeWithTryCatch(async()=>await n(this,s).getPublicKey(),"Error while getting public key from OKX wallet")}async requestAccounts(){const t=await this.connect();return t.ok?r.Ok([t.val.address]):r.Err(t.error)}async getAccounts(){return n(this,c)===r.Network.TESTNET?await this.requestAccounts():await r.executeWithTryCatch(async()=>await n(this,s).getAccounts(),"Error while getting accounts from OKX wallet")}async getNetwork(){return r.Ok(n(this,c))}async switchNetwork(){a(this,c,n(this,c)===r.Network.MAINNET?r.Network.TESTNET:r.Network.MAINNET);const t=await this.connect();return t.error?r.Err(`Failed to connect to ${n(this,c)}: ${t.error}`):r.Ok(n(this,c))}async getBalance(){return await r.executeWithTryCatch(async()=>await n(this,s).getBalance(),"Error while getting balance from OKX wallet")}async sendBitcoin(t,e){return await r.executeWithTryCatch(async()=>await n(this,s).sendBitcoin(t,e),"Error while sending bitcoin from OKX wallet")}on(t,e){n(this,s).on(t,e)}off(t,e){n(this,s).off(t,e)}}s=new WeakMap,c=new WeakMap;exports.OKXProvider=w;
1
+ "use strict";var N=n=>{throw TypeError(n)};var T=(n,t,r)=>t.has(n)||N("Cannot "+r);var s=(n,t,r)=>(T(n,t,"read from private field"),r?r.call(n):t.get(n)),w=(n,t,r)=>t.has(n)?N("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,r),E=(n,t,r,o)=>(T(n,t,"write to private field"),o?o.call(n,r):t.set(n,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index18.cjs"),e=require("@gardenfi/utils"),u=require("./index3.cjs");var i,c;class d{constructor(t,r){w(this,i);w(this,c);this.address="",this.id=u.WALLET_CONFIG.Unisat.id,this.name=u.WALLET_CONFIG.Unisat.name,this.icon=u.WALLET_CONFIG.Unisat.icon,this.disconnect=()=>(this.address="",Promise.resolve(e.Ok("Disconnected unisat wallet"))),E(this,i,t),E(this,c,r)}async connect(t){try{t||(t=s(this,c));const r=await this.getNetwork(),o=await s(this,i).getChain();if(r.error)return e.Err("Could not get network",r.error);if(r.val!==t||o.enum===a.UnisatChainEnum.BITCOIN_TESTNET){const l=await this.switchNetwork();if(l.error)return e.Err("Failed to switch network",l.error)}const h=await s(this,i).requestAccounts();return h.length>0&&(this.address=h[0]),e.Ok({address:this.address,provider:this,network:t,id:u.WALLET_CONFIG.Unisat.id})}catch(r){return e.Err("Error while connecting to the Unisat wallet",r)}}async requestAccounts(){return await e.executeWithTryCatch(async()=>await s(this,i).requestAccounts(),"Error while requesting accounts from the Unisat wallet")}async getAccounts(){return await e.executeWithTryCatch(async()=>await s(this,i).getAccounts(),"Error while getting accounts from the Unisat wallet")}async getNetwork(){return await e.executeWithTryCatch(async()=>{const t=await s(this,i).getNetwork();if(t===a.UnisatNetworkEnum.LIVENET)return e.Network.MAINNET;if(t===a.UnisatNetworkEnum.TESTNET)return e.Network.TESTNET;throw new Error("Invalid or unsupported network"+t)},"Error while getting network from Unisat wallet")}async switchNetwork(){try{const t=await this.getNetwork(),r=await s(this,i).getChain();if(t.error)return e.Err("Failed to get current network");const o=t.val===e.Network.MAINNET||s(this,c)===e.Network.TESTNET&&r.enum===a.UnisatChainEnum.BITCOIN_TESTNET?a.UnisatChainEnum.BITCOIN_TESTNET4:a.UnisatChainEnum.BITCOIN_MAINNET;await s(this,i).switchChain(o);const h=await this.getNetwork();return h.ok?e.Ok(h.val):e.Err("Failed to verify network switch")}catch(t){return e.Err("Error while switching network in Unisat:",t)}}async getBalance(){return await e.executeWithTryCatch(async()=>await s(this,i).getBalance(),"Error while getting balance from Unisat wallet")}async sendBitcoin(t,r){return await e.executeWithTryCatch(async()=>await s(this,i).sendBitcoin(t,r),"Error while sending bitcoin from Unisat wallet")}on(t,r){s(this,i).on(t,r)}off(t,r){s(this,i).removeListener(t,r)}}i=new WeakMap,c=new WeakMap;exports.UnisatProvider=d;
package/dist/index11.js CHANGED
@@ -1,64 +1,85 @@
1
- var y = (e) => {
1
+ var g = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var g = (e, t, r) => t.has(e) || y("Cannot " + r);
5
- var n = (e, t, r) => (g(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), a = (e, t, r, w) => (g(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r);
6
- import { Ok as c, Err as o, executeWithTryCatch as h, Network as l } from "@gardenfi/utils";
7
- import { WALLET_CONFIG as u } from "./index3.js";
8
- var i, s;
9
- class E {
4
+ var k = (e, t, r) => t.has(e) || g("Cannot " + r);
5
+ var i = (e, t, r) => (k(e, t, "read from private field"), r ? r.call(e) : t.get(e)), N = (e, t, r) => t.has(e) ? g("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), T = (e, t, r, s) => (k(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
+ import { UnisatChainEnum as w, UnisatNetworkEnum as f } from "./index18.js";
7
+ import { Ok as E, Err as a, executeWithTryCatch as h, Network as u } from "@gardenfi/utils";
8
+ import { WALLET_CONFIG as l } from "./index3.js";
9
+ var n, o;
10
+ class U {
10
11
  constructor(t, r) {
11
- d(this, i);
12
- d(this, s);
13
- this.address = "", this.id = u.OKX.id, this.name = u.OKX.name, this.icon = u.OKX.icon, this.disconnect = () => (this.address = "", n(this, i).disconnect(), Promise.resolve(c("Disconnected OKX wallet"))), a(this, i, t), a(this, s, r);
12
+ N(this, n);
13
+ N(this, o);
14
+ this.address = "", this.id = l.Unisat.id, this.name = l.Unisat.name, this.icon = l.Unisat.icon, this.disconnect = () => (this.address = "", Promise.resolve(E("Disconnected unisat wallet"))), T(this, n, t), T(this, o, r);
14
15
  }
15
- async connect() {
16
+ async connect(t) {
16
17
  try {
17
- const t = await n(this, i).connect();
18
- return !t || !t.address ? o("Failed to connect to OKX wallet") : (this.address = t.address, c({
18
+ t || (t = i(this, o));
19
+ const r = await this.getNetwork(), s = await i(this, n).getChain();
20
+ if (r.error)
21
+ return a("Could not get network", r.error);
22
+ if (r.val !== t || s.enum === w.BITCOIN_TESTNET) {
23
+ const d = await this.switchNetwork();
24
+ if (d.error)
25
+ return a("Failed to switch network", d.error);
26
+ }
27
+ const c = await i(this, n).requestAccounts();
28
+ return c.length > 0 && (this.address = c[0]), E({
19
29
  address: this.address,
20
30
  provider: this,
21
- network: n(this, s),
22
- id: u.OKX.id
23
- }));
24
- } catch (t) {
25
- return o("Error while connecting to the OKX wallet", t);
31
+ network: t,
32
+ id: l.Unisat.id
33
+ });
34
+ } catch (r) {
35
+ return a("Error while connecting to the Unisat wallet", r);
26
36
  }
27
37
  }
28
- async getPublicKey() {
29
- return await h(async () => await n(this, i).getPublicKey(), "Error while getting public key from OKX wallet");
30
- }
38
+ // requests accounts from the wallet, if not connected, it will connect first
31
39
  async requestAccounts() {
32
- const t = await this.connect();
33
- return t.ok ? c([t.val.address]) : o(t.error);
40
+ return await h(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
34
41
  }
42
+ //silently gets accounts if already connected
35
43
  async getAccounts() {
36
- return n(this, s) === l.TESTNET ? await this.requestAccounts() : await h(async () => await n(this, i).getAccounts(), "Error while getting accounts from OKX wallet");
44
+ return await h(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
37
45
  }
38
46
  async getNetwork() {
39
- return c(n(this, s));
47
+ return await h(async () => {
48
+ const t = await i(this, n).getNetwork();
49
+ if (t === f.LIVENET)
50
+ return u.MAINNET;
51
+ if (t === f.TESTNET)
52
+ return u.TESTNET;
53
+ throw new Error("Invalid or unsupported network" + t);
54
+ }, "Error while getting network from Unisat wallet");
40
55
  }
41
56
  async switchNetwork() {
42
- a(this, s, n(this, s) === l.MAINNET ? l.TESTNET : l.MAINNET);
43
- const t = await this.connect();
44
- return t.error ? o(
45
- `Failed to connect to ${n(this, s)}: ${t.error}`
46
- ) : c(n(this, s));
57
+ try {
58
+ const t = await this.getNetwork(), r = await i(this, n).getChain();
59
+ if (t.error)
60
+ return a("Failed to get current network");
61
+ const s = t.val === u.MAINNET ? w.BITCOIN_TESTNET4 : i(this, o) === u.TESTNET && r.enum === w.BITCOIN_TESTNET ? w.BITCOIN_TESTNET4 : w.BITCOIN_MAINNET;
62
+ await i(this, n).switchChain(s);
63
+ const c = await this.getNetwork();
64
+ return c.ok ? E(c.val) : a("Failed to verify network switch");
65
+ } catch (t) {
66
+ return a("Error while switching network in Unisat:", t);
67
+ }
47
68
  }
48
69
  async getBalance() {
49
- return await h(async () => await n(this, i).getBalance(), "Error while getting balance from OKX wallet");
70
+ return await h(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
50
71
  }
51
72
  async sendBitcoin(t, r) {
52
- return await h(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
73
+ return await h(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
53
74
  }
54
75
  on(t, r) {
55
- n(this, i).on(t, r);
76
+ i(this, n).on(t, r);
56
77
  }
57
78
  off(t, r) {
58
- n(this, i).off(t, r);
79
+ i(this, n).removeListener(t, r);
59
80
  }
60
81
  }
61
- i = new WeakMap(), s = new WeakMap();
82
+ n = new WeakMap(), o = new WeakMap();
62
83
  export {
63
- E as OKXProvider
84
+ U as UnisatProvider
64
85
  };
package/dist/index12.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var N=n=>{throw TypeError(n)};var T=(n,t,r)=>t.has(n)||N("Cannot "+r);var s=(n,t,r)=>(T(n,t,"read from private field"),r?r.call(n):t.get(n)),w=(n,t,r)=>t.has(n)?N("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,r),E=(n,t,r,o)=>(T(n,t,"write to private field"),o?o.call(n,r):t.set(n,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index17.cjs"),e=require("@gardenfi/utils"),u=require("./index3.cjs");var i,c;class d{constructor(t,r){w(this,i);w(this,c);this.address="",this.id=u.WALLET_CONFIG.Unisat.id,this.name=u.WALLET_CONFIG.Unisat.name,this.icon=u.WALLET_CONFIG.Unisat.icon,this.disconnect=()=>(this.address="",Promise.resolve(e.Ok("Disconnected unisat wallet"))),E(this,i,t),E(this,c,r)}async connect(t){try{t||(t=s(this,c));const r=await this.getNetwork(),o=await s(this,i).getChain();if(r.error)return e.Err("Could not get network",r.error);if(r.val!==t||o.enum===a.UnisatChainEnum.BITCOIN_TESTNET){const l=await this.switchNetwork();if(l.error)return e.Err("Failed to switch network",l.error)}const h=await s(this,i).requestAccounts();return h.length>0&&(this.address=h[0]),e.Ok({address:this.address,provider:this,network:t,id:u.WALLET_CONFIG.Unisat.id})}catch(r){return e.Err("Error while connecting to the Unisat wallet",r)}}async requestAccounts(){return await e.executeWithTryCatch(async()=>await s(this,i).requestAccounts(),"Error while requesting accounts from the Unisat wallet")}async getAccounts(){return await e.executeWithTryCatch(async()=>await s(this,i).getAccounts(),"Error while getting accounts from the Unisat wallet")}async getNetwork(){return await e.executeWithTryCatch(async()=>{const t=await s(this,i).getNetwork();if(t===a.UnisatNetworkEnum.LIVENET)return e.Network.MAINNET;if(t===a.UnisatNetworkEnum.TESTNET)return e.Network.TESTNET;throw new Error("Invalid or unsupported network"+t)},"Error while getting network from Unisat wallet")}async switchNetwork(){try{const t=await this.getNetwork(),r=await s(this,i).getChain();if(t.error)return e.Err("Failed to get current network");const o=t.val===e.Network.MAINNET||s(this,c)===e.Network.TESTNET&&r.enum===a.UnisatChainEnum.BITCOIN_TESTNET?a.UnisatChainEnum.BITCOIN_TESTNET4:a.UnisatChainEnum.BITCOIN_MAINNET;await s(this,i).switchChain(o);const h=await this.getNetwork();return h.ok?e.Ok(h.val):e.Err("Failed to verify network switch")}catch(t){return e.Err("Error while switching network in Unisat:",t)}}async getBalance(){return await e.executeWithTryCatch(async()=>await s(this,i).getBalance(),"Error while getting balance from Unisat wallet")}async sendBitcoin(t,r){return await e.executeWithTryCatch(async()=>await s(this,i).sendBitcoin(t,r),"Error while sending bitcoin from Unisat wallet")}on(t,r){s(this,i).on(t,r)}off(t,r){s(this,i).removeListener(t,r)}}i=new WeakMap,c=new WeakMap;exports.UnisatProvider=d;
1
+ "use strict";var m=r=>{throw TypeError(r)};var f=(r,t,e)=>t.has(r)||m("Cannot "+e);var a=(r,t,e)=>(f(r,t,"read from private field"),e?e.call(r):t.get(r)),w=(r,t,e)=>t.has(r)?m("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),g=(r,t,e,o)=>(f(r,t,"write to private field"),o?o.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("bitcoinjs-lib"),A=require("tiny-secp256k1"),n=require("@gardenfi/utils"),i=require("./index3.cjs"),P=require("@gardenfi/core"),x=require("./index4.cjs");function p(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const d=p(y),I=p(A);y.initEccLib(I);var s;class O{constructor(t){w(this,s);this.address="",this.id=i.WALLET_CONFIG.Phantom.id,this.name=i.WALLET_CONFIG.Phantom.name,this.icon=i.WALLET_CONFIG.Phantom.icon,this.disconnect=()=>(this.address="",Promise.resolve(n.Ok("Disconnected Phantom wallet"))),g(this,s,t)}async connect(t){if(t||(t=n.Network.MAINNET),t===n.Network.TESTNET)return n.Err("Phantom wallet does not support testnet");try{const e=await a(this,s).requestAccounts();for(const o of e)o.purpose==="payment"&&(this.address=o.address);return this.address===""?n.Err("Could not connect to Phantom bitcoin payment account"):n.Ok({address:this.address,provider:this,network:t,id:i.WALLET_CONFIG.Phantom.id})}catch(e){return n.Err("Error while connecting to Phantom wallet: "+e)}}async requestAccounts(){return await n.executeWithTryCatch(async()=>{const t=await a(this,s).requestAccounts();return t.length>0&&(this.address=t[0].address),t.map(e=>e.address)},"Error while requesting accounts from Phantom wallet")}async getAccounts(){return this.requestAccounts()}async getNetwork(){return n.Ok(n.Network.MAINNET)}async switchNetwork(){return n.Err("Phantom wallet does not support testnet")}async getBalance(){return await n.executeWithTryCatch(async()=>{const t=await x.getBalance(this.address,n.Network.MAINNET);if(t.ok&&t.val)return t.val;throw new Error(t.error)},"Error while getting balance from Phantom wallet")}async sendBitcoin(t,e){return await n.executeWithTryCatch(async()=>{const o=d.networks.bitcoin,h=new P.BitcoinProvider(n.Network.MAINNET);try{const{txHex:c,utxoCount:b}=await P.BitcoinWallet.generateUnsignedPSBT(h,o,this.address,t,e),E=await a(this,s).signPSBT(this.fromHexString(c),{inputsToSign:[{address:this.address,signingIndexes:Array.from({length:b},(S,T)=>T),sigHash:d.Transaction.SIGHASH_ALL}]}),l=d.Psbt.fromBuffer(Buffer.from(E));l.finalizeAllInputs();const u=l.extractTransaction();console.log("tx",u);const N=u.getId();return await h.broadcast(u.toHex()),N}catch(c){throw new Error(`Failed to send bitcoin: ${c}`)}},"Error while sending bitcoin from Phantom wallet")}fromHexString(t){return Uint8Array.from(t.match(/.{1,2}/g).map(e=>parseInt(e,16)))}on(t,e){a(this,s).on(t,e)}off(t,e){a(this,s).off(t,e)}}s=new WeakMap;exports.PhantomProvider=O;
package/dist/index12.js CHANGED
@@ -1,85 +1,110 @@
1
- var g = (e) => {
2
- throw TypeError(e);
1
+ var g = (n) => {
2
+ throw TypeError(n);
3
3
  };
4
- var k = (e, t, r) => t.has(e) || g("Cannot " + r);
5
- var i = (e, t, r) => (k(e, t, "read from private field"), r ? r.call(e) : t.get(e)), N = (e, t, r) => t.has(e) ? g("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), T = (e, t, r, s) => (k(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
- import { UnisatChainEnum as w, UnisatNetworkEnum as f } from "./index17.js";
7
- import { Ok as E, Err as a, executeWithTryCatch as h, Network as u } from "@gardenfi/utils";
8
- import { WALLET_CONFIG as l } from "./index3.js";
9
- var n, o;
10
- class U {
11
- constructor(t, r) {
12
- N(this, n);
13
- N(this, o);
14
- this.address = "", this.id = l.Unisat.id, this.name = l.Unisat.name, this.icon = l.Unisat.icon, this.disconnect = () => (this.address = "", Promise.resolve(E("Disconnected unisat wallet"))), T(this, n, t), T(this, o, r);
4
+ var p = (n, t, r) => t.has(n) || g("Cannot " + r);
5
+ var s = (n, t, r) => (p(n, t, "read from private field"), r ? r.call(n) : t.get(n)), P = (n, t, r) => t.has(n) ? g("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, r), y = (n, t, r, e) => (p(n, t, "write to private field"), e ? e.call(n, r) : t.set(n, r), r);
6
+ import * as m from "bitcoinjs-lib";
7
+ import { initEccLib as N } from "bitcoinjs-lib";
8
+ import * as b from "tiny-secp256k1";
9
+ import { Ok as u, Network as a, Err as i, executeWithTryCatch as l } from "@gardenfi/utils";
10
+ import { WALLET_CONFIG as c } from "./index3.js";
11
+ import { BitcoinProvider as I, BitcoinWallet as B } from "@gardenfi/core";
12
+ import { getBalance as v } from "./index4.js";
13
+ N(b);
14
+ var o;
15
+ class W {
16
+ constructor(t) {
17
+ P(this, o);
18
+ this.address = "", this.id = c.Phantom.id, this.name = c.Phantom.name, this.icon = c.Phantom.icon, this.disconnect = () => (this.address = "", Promise.resolve(u("Disconnected Phantom wallet"))), y(this, o, t);
15
19
  }
16
20
  async connect(t) {
21
+ if (t || (t = a.MAINNET), t === a.TESTNET)
22
+ return i("Phantom wallet does not support testnet");
17
23
  try {
18
- t || (t = i(this, o));
19
- const r = await this.getNetwork(), s = await i(this, n).getChain();
20
- if (r.error)
21
- return a("Could not get network", r.error);
22
- if (r.val !== t || s.enum === w.BITCOIN_TESTNET) {
23
- const d = await this.switchNetwork();
24
- if (d.error)
25
- return a("Failed to switch network", d.error);
26
- }
27
- const c = await i(this, n).requestAccounts();
28
- return c.length > 0 && (this.address = c[0]), E({
24
+ const r = await s(this, o).requestAccounts();
25
+ for (const e of r)
26
+ e.purpose === "payment" && (this.address = e.address);
27
+ return this.address === "" ? i("Could not connect to Phantom bitcoin payment account") : u({
29
28
  address: this.address,
30
29
  provider: this,
31
30
  network: t,
32
- id: l.Unisat.id
31
+ id: c.Phantom.id
33
32
  });
34
33
  } catch (r) {
35
- return a("Error while connecting to the Unisat wallet", r);
34
+ return i("Error while connecting to Phantom wallet: " + r);
36
35
  }
37
36
  }
38
- // requests accounts from the wallet, if not connected, it will connect first
39
37
  async requestAccounts() {
40
- return await h(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
38
+ return await l(async () => {
39
+ const t = await s(this, o).requestAccounts();
40
+ return t.length > 0 && (this.address = t[0].address), t.map((r) => r.address);
41
+ }, "Error while requesting accounts from Phantom wallet");
41
42
  }
42
- //silently gets accounts if already connected
43
43
  async getAccounts() {
44
- return await h(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
44
+ return this.requestAccounts();
45
45
  }
46
+ // bitcoin testnet is not supported in Phantom wallet
46
47
  async getNetwork() {
47
- return await h(async () => {
48
- const t = await i(this, n).getNetwork();
49
- if (t === f.LIVENET)
50
- return u.MAINNET;
51
- if (t === f.TESTNET)
52
- return u.TESTNET;
53
- throw new Error("Invalid or unsupported network" + t);
54
- }, "Error while getting network from Unisat wallet");
48
+ return u(a.MAINNET);
55
49
  }
56
50
  async switchNetwork() {
57
- try {
58
- const t = await this.getNetwork(), r = await i(this, n).getChain();
59
- if (t.error)
60
- return a("Failed to get current network");
61
- const s = t.val === u.MAINNET ? w.BITCOIN_TESTNET4 : i(this, o) === u.TESTNET && r.enum === w.BITCOIN_TESTNET ? w.BITCOIN_TESTNET4 : w.BITCOIN_MAINNET;
62
- await i(this, n).switchChain(s);
63
- const c = await this.getNetwork();
64
- return c.ok ? E(c.val) : a("Failed to verify network switch");
65
- } catch (t) {
66
- return a("Error while switching network in Unisat:", t);
67
- }
51
+ return i("Phantom wallet does not support testnet");
68
52
  }
69
53
  async getBalance() {
70
- return await h(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
54
+ return await l(async () => {
55
+ const t = await v(this.address, a.MAINNET);
56
+ if (t.ok && t.val)
57
+ return t.val;
58
+ throw new Error(t.error);
59
+ }, "Error while getting balance from Phantom wallet");
71
60
  }
72
61
  async sendBitcoin(t, r) {
73
- return await h(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
62
+ return await l(async () => {
63
+ const e = m.networks.bitcoin, f = new I(a.MAINNET);
64
+ try {
65
+ const { txHex: d, utxoCount: A } = await B.generateUnsignedPSBT(
66
+ f,
67
+ e,
68
+ this.address,
69
+ t,
70
+ r
71
+ ), E = await s(this, o).signPSBT(
72
+ this.fromHexString(d),
73
+ {
74
+ inputsToSign: [
75
+ {
76
+ address: this.address,
77
+ signingIndexes: Array.from({ length: A }, (S, x) => x),
78
+ sigHash: m.Transaction.SIGHASH_ALL
79
+ }
80
+ ]
81
+ }
82
+ ), w = m.Psbt.fromBuffer(
83
+ Buffer.from(E)
84
+ );
85
+ w.finalizeAllInputs();
86
+ const h = w.extractTransaction();
87
+ console.log("tx", h);
88
+ const T = h.getId();
89
+ return await f.broadcast(h.toHex()), T;
90
+ } catch (d) {
91
+ throw new Error(`Failed to send bitcoin: ${d}`);
92
+ }
93
+ }, "Error while sending bitcoin from Phantom wallet");
94
+ }
95
+ fromHexString(t) {
96
+ return Uint8Array.from(
97
+ t.match(/.{1,2}/g).map((r) => parseInt(r, 16))
98
+ );
74
99
  }
75
100
  on(t, r) {
76
- i(this, n).on(t, r);
101
+ s(this, o).on(t, r);
77
102
  }
78
103
  off(t, r) {
79
- i(this, n).removeListener(t, r);
104
+ s(this, o).off(t, r);
80
105
  }
81
106
  }
82
- n = new WeakMap(), o = new WeakMap();
107
+ o = new WeakMap();
83
108
  export {
84
- U as UnisatProvider
109
+ W as PhantomProvider
85
110
  };
package/dist/index13.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var m=r=>{throw TypeError(r)};var f=(r,t,e)=>t.has(r)||m("Cannot "+e);var a=(r,t,e)=>(f(r,t,"read from private field"),e?e.call(r):t.get(r)),w=(r,t,e)=>t.has(r)?m("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),g=(r,t,e,o)=>(f(r,t,"write to private field"),o?o.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("bitcoinjs-lib"),A=require("tiny-secp256k1"),n=require("@gardenfi/utils"),i=require("./index3.cjs"),P=require("@gardenfi/core"),x=require("./index4.cjs");function p(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const d=p(y),I=p(A);y.initEccLib(I);var s;class O{constructor(t){w(this,s);this.address="",this.id=i.WALLET_CONFIG.Phantom.id,this.name=i.WALLET_CONFIG.Phantom.name,this.icon=i.WALLET_CONFIG.Phantom.icon,this.disconnect=()=>(this.address="",Promise.resolve(n.Ok("Disconnected Phantom wallet"))),g(this,s,t)}async connect(t){if(t||(t=n.Network.MAINNET),t===n.Network.TESTNET)return n.Err("Phantom wallet does not support testnet");try{const e=await a(this,s).requestAccounts();for(const o of e)o.purpose==="payment"&&(this.address=o.address);return this.address===""?n.Err("Could not connect to Phantom bitcoin payment account"):n.Ok({address:this.address,provider:this,network:t,id:i.WALLET_CONFIG.Phantom.id})}catch(e){return n.Err("Error while connecting to Phantom wallet: "+e)}}async requestAccounts(){return await n.executeWithTryCatch(async()=>{const t=await a(this,s).requestAccounts();return t.length>0&&(this.address=t[0].address),t.map(e=>e.address)},"Error while requesting accounts from Phantom wallet")}async getAccounts(){return this.requestAccounts()}async getNetwork(){return n.Ok(n.Network.MAINNET)}async switchNetwork(){return n.Err("Phantom wallet does not support testnet")}async getBalance(){return await n.executeWithTryCatch(async()=>{const t=await x.getBalance(this.address,n.Network.MAINNET);if(t.ok&&t.val)return t.val;throw new Error(t.error)},"Error while getting balance from Phantom wallet")}async sendBitcoin(t,e){return await n.executeWithTryCatch(async()=>{const o=d.networks.bitcoin,h=new P.BitcoinProvider(n.Network.MAINNET);try{const{txHex:c,utxoCount:b}=await P.BitcoinWallet.generateUnsignedPSBT(h,o,this.address,t,e),E=await a(this,s).signPSBT(this.fromHexString(c),{inputsToSign:[{address:this.address,signingIndexes:Array.from({length:b},(S,T)=>T),sigHash:d.Transaction.SIGHASH_ALL}]}),l=d.Psbt.fromBuffer(Buffer.from(E));l.finalizeAllInputs();const u=l.extractTransaction();console.log("tx",u);const N=u.getId();return await h.broadcast(u.toHex()),N}catch(c){throw new Error(`Failed to send bitcoin: ${c}`)}},"Error while sending bitcoin from Phantom wallet")}fromHexString(t){return Uint8Array.from(t.match(/.{1,2}/g).map(e=>parseInt(e,16)))}on(t,e){a(this,s).on(t,e)}off(t,e){a(this,s).off(t,e)}}s=new WeakMap;exports.PhantomProvider=O;
1
+ "use strict";var l=n=>{throw TypeError(n)};var d=(n,e,t)=>e.has(n)||l("Cannot "+t);var o=(n,e,t)=>(d(n,e,"read from private field"),t?t.call(n):e.get(n)),N=(n,e,t)=>e.has(n)?l("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),k=(n,e,t,s)=>(d(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index3.cjs"),u=require("./index19.cjs"),r=require("@gardenfi/utils");var i;class y{constructor(e){N(this,i);this.address="",this.id=w.WALLET_CONFIG.Xverse.id,this.name=w.WALLET_CONFIG.Xverse.name,this.icon=w.WALLET_CONFIG.Xverse.icon,this.connect=async t=>{try{t||(t=r.Network.MAINNET),await o(this,i).request("wallet_connect",null);const s=await this.getNetwork();if(s.error)return r.Err("Could not get network",s.error);if(s.val!==t){const c=await this.switchNetwork();if(c.error)return r.Err("Failed to switch network",c.error)}const a=await this.getAccounts();return a.ok&&a.val.length>0&&(this.address=a.val[0]),r.Ok({address:this.address,provider:this,network:t,id:w.WALLET_CONFIG.Xverse.id})}catch(s){return r.Err("Error while connecting to the XVerse wallet",s)}},this.getBalance=async()=>await r.executeWithTryCatch(async()=>(await o(this,i).request("getBalance",{})).result,"Error while getting balance from XVerse wallet"),this.requestAccounts=async()=>await r.executeWithTryCatch(async()=>(await o(this,i).request("getAccounts",{purposes:["payment"],message:"I want to connect"})).result.map(s=>s.address)),this.getAccounts=async()=>await r.executeWithTryCatch(async()=>(await o(this,i).request("getAddresses",{purposes:["payment"]})).result.addresses.map(s=>s.address)),this.sendBitcoin=async(t,s)=>await r.executeWithTryCatch(async()=>{var h;const a=await o(this,i).request("sendTransfer",{recipients:[{address:t,amount:s}]}),c=(h=a.result)==null?void 0:h.txid;if(c)return r.Ok(c);throw new Error(a.error)},"Error while sending bitcoin from Xverse wallet"),this.on=()=>{},this.off=()=>{},this.disconnect=()=>(this.address="",Promise.resolve(r.Ok("Disconnected"))),k(this,i,e)}async getNetwork(){return await r.executeWithTryCatch(async()=>{const e=await o(this,i).request("wallet_getNetwork",null);if(e.result.bitcoin.name===u.XverseBitcoinNetworkType.Mainnet)return r.Network.MAINNET;if(e.result.bitcoin.name===u.XverseBitcoinNetworkType.Testnet4)return r.Network.TESTNET;throw new Error(e.result)},"Error while getting network from Xverse wallet")}async switchNetwork(){try{const e=await this.getNetwork();if(e.error)return r.Err("Failed to get current network");const t=e.val===r.Network.MAINNET?u.XverseBitcoinNetworkType.Testnet4:u.XverseBitcoinNetworkType.Mainnet;await o(this,i).request("wallet_changeNetwork",{name:t});const s=await this.getNetwork();return s.ok?r.Ok(s.val):r.Err("Failed to verify network switch")}catch(e){return r.Err("Error while switching network in Xverse:",e)}}}i=new WeakMap;exports.XverseProvider=y;
package/dist/index13.js CHANGED
@@ -1,110 +1,83 @@
1
- var g = (n) => {
2
- throw TypeError(n);
1
+ var N = (s) => {
2
+ throw TypeError(s);
3
3
  };
4
- var p = (n, t, r) => t.has(n) || g("Cannot " + r);
5
- var s = (n, t, r) => (p(n, t, "read from private field"), r ? r.call(n) : t.get(n)), P = (n, t, r) => t.has(n) ? g("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, r), y = (n, t, r, e) => (p(n, t, "write to private field"), e ? e.call(n, r) : t.set(n, r), r);
6
- import * as m from "bitcoinjs-lib";
7
- import { initEccLib as N } from "bitcoinjs-lib";
8
- import * as b from "tiny-secp256k1";
9
- import { Ok as u, Network as a, Err as i, executeWithTryCatch as l } from "@gardenfi/utils";
10
- import { WALLET_CONFIG as c } from "./index3.js";
11
- import { BitcoinProvider as I, BitcoinWallet as B } from "@gardenfi/core";
12
- import { getBalance as v } from "./index4.js";
13
- N(b);
14
- var o;
15
- class W {
16
- constructor(t) {
17
- P(this, o);
18
- this.address = "", this.id = c.Phantom.id, this.name = c.Phantom.name, this.icon = c.Phantom.icon, this.disconnect = () => (this.address = "", Promise.resolve(u("Disconnected Phantom wallet"))), y(this, o, t);
19
- }
20
- async connect(t) {
21
- if (t || (t = a.MAINNET), t === a.TESTNET)
22
- return i("Phantom wallet does not support testnet");
23
- try {
24
- const r = await s(this, o).requestAccounts();
25
- for (const e of r)
26
- e.purpose === "payment" && (this.address = e.address);
27
- return this.address === "" ? i("Could not connect to Phantom bitcoin payment account") : u({
28
- address: this.address,
29
- provider: this,
30
- network: t,
31
- id: c.Phantom.id
32
- });
33
- } catch (r) {
34
- return i("Error while connecting to Phantom wallet: " + r);
35
- }
36
- }
37
- async requestAccounts() {
38
- return await l(async () => {
39
- const t = await s(this, o).requestAccounts();
40
- return t.length > 0 && (this.address = t[0].address), t.map((r) => r.address);
41
- }, "Error while requesting accounts from Phantom wallet");
42
- }
43
- async getAccounts() {
44
- return this.requestAccounts();
45
- }
46
- // bitcoin testnet is not supported in Phantom wallet
47
- async getNetwork() {
48
- return u(a.MAINNET);
49
- }
50
- async switchNetwork() {
51
- return i("Phantom wallet does not support testnet");
52
- }
53
- async getBalance() {
54
- return await l(async () => {
55
- const t = await v(this.address, a.MAINNET);
56
- if (t.ok && t.val)
57
- return t.val;
58
- throw new Error(t.error);
59
- }, "Error while getting balance from Phantom wallet");
60
- }
61
- async sendBitcoin(t, r) {
62
- return await l(async () => {
63
- const e = m.networks.bitcoin, f = new I(a.MAINNET);
4
+ var k = (s, e, t) => e.has(s) || N("Cannot " + t);
5
+ var i = (s, e, t) => (k(s, e, "read from private field"), t ? t.call(s) : e.get(s)), m = (s, e, t) => e.has(s) ? N("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), f = (s, e, t, r) => (k(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
6
+ import { WALLET_CONFIG as u } from "./index3.js";
7
+ import { XverseBitcoinNetworkType as h } from "./index19.js";
8
+ import { Network as l, Err as a, Ok as d, executeWithTryCatch as w } from "@gardenfi/utils";
9
+ var n;
10
+ class T {
11
+ constructor(e) {
12
+ m(this, n);
13
+ this.address = "", this.id = u.Xverse.id, this.name = u.Xverse.name, this.icon = u.Xverse.icon, this.connect = async (t) => {
64
14
  try {
65
- const { txHex: d, utxoCount: A } = await B.generateUnsignedPSBT(
66
- f,
67
- e,
68
- this.address,
69
- t,
70
- r
71
- ), E = await s(this, o).signPSBT(
72
- this.fromHexString(d),
73
- {
74
- inputsToSign: [
75
- {
76
- address: this.address,
77
- signingIndexes: Array.from({ length: A }, (S, x) => x),
78
- sigHash: m.Transaction.SIGHASH_ALL
79
- }
80
- ]
81
- }
82
- ), w = m.Psbt.fromBuffer(
83
- Buffer.from(E)
84
- );
85
- w.finalizeAllInputs();
86
- const h = w.extractTransaction();
87
- console.log("tx", h);
88
- const T = h.getId();
89
- return await f.broadcast(h.toHex()), T;
90
- } catch (d) {
91
- throw new Error(`Failed to send bitcoin: ${d}`);
15
+ t || (t = l.MAINNET), await i(this, n).request("wallet_connect", null);
16
+ const r = await this.getNetwork();
17
+ if (r.error)
18
+ return a("Could not get network", r.error);
19
+ if (r.val !== t) {
20
+ const c = await this.switchNetwork();
21
+ if (c.error)
22
+ return a("Failed to switch network", c.error);
23
+ }
24
+ const o = await this.getAccounts();
25
+ return o.ok && o.val.length > 0 && (this.address = o.val[0]), d({
26
+ address: this.address,
27
+ provider: this,
28
+ network: t,
29
+ id: u.Xverse.id
30
+ });
31
+ } catch (r) {
32
+ return a("Error while connecting to the XVerse wallet", r);
92
33
  }
93
- }, "Error while sending bitcoin from Phantom wallet");
34
+ }, this.getBalance = async () => await w(async () => (await i(this, n).request("getBalance", {})).result, "Error while getting balance from XVerse wallet"), this.requestAccounts = async () => await w(async () => (await i(this, n).request("getAccounts", {
35
+ purposes: ["payment"],
36
+ message: "I want to connect"
37
+ })).result.map((r) => r.address)), this.getAccounts = async () => await w(async () => (await i(this, n).request("getAddresses", {
38
+ purposes: ["payment"]
39
+ })).result.addresses.map((r) => r.address)), this.sendBitcoin = async (t, r) => await w(async () => {
40
+ var g;
41
+ const o = await i(this, n).request("sendTransfer", {
42
+ recipients: [{ address: t, amount: r }]
43
+ }), c = (g = o.result) == null ? void 0 : g.txid;
44
+ if (c)
45
+ return d(c);
46
+ throw new Error(o.error);
47
+ }, "Error while sending bitcoin from Xverse wallet"), this.on = () => {
48
+ }, this.off = () => {
49
+ }, this.disconnect = () => (this.address = "", Promise.resolve(d("Disconnected"))), f(this, n, e);
94
50
  }
95
- fromHexString(t) {
96
- return Uint8Array.from(
97
- t.match(/.{1,2}/g).map((r) => parseInt(r, 16))
98
- );
99
- }
100
- on(t, r) {
101
- s(this, o).on(t, r);
51
+ async getNetwork() {
52
+ return await w(async () => {
53
+ const e = await i(this, n).request(
54
+ "wallet_getNetwork",
55
+ null
56
+ );
57
+ if (e.result.bitcoin.name === h.Mainnet)
58
+ return l.MAINNET;
59
+ if (e.result.bitcoin.name === h.Testnet4)
60
+ return l.TESTNET;
61
+ throw new Error(e.result);
62
+ }, "Error while getting network from Xverse wallet");
102
63
  }
103
- off(t, r) {
104
- s(this, o).off(t, r);
64
+ async switchNetwork() {
65
+ try {
66
+ const e = await this.getNetwork();
67
+ if (e.error)
68
+ return a("Failed to get current network");
69
+ const t = e.val === l.MAINNET ? h.Testnet4 : h.Mainnet;
70
+ await i(this, n).request("wallet_changeNetwork", {
71
+ name: t
72
+ });
73
+ const r = await this.getNetwork();
74
+ return r.ok ? d(r.val) : a("Failed to verify network switch");
75
+ } catch (e) {
76
+ return a("Error while switching network in Xverse:", e);
77
+ }
105
78
  }
106
79
  }
107
- o = new WeakMap();
80
+ n = new WeakMap();
108
81
  export {
109
- W as PhantomProvider
82
+ T as XverseProvider
110
83
  };