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

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.
Files changed (46) hide show
  1. package/dist/index10.cjs +1 -1
  2. package/dist/index10.js +2 -83
  3. package/dist/index11.cjs +1 -1
  4. package/dist/index11.js +38 -84
  5. package/dist/index12.cjs +1 -1
  6. package/dist/index12.js +72 -70
  7. package/dist/index13.cjs +1 -1
  8. package/dist/index13.js +82 -40
  9. package/dist/index14.cjs +1 -1
  10. package/dist/index14.js +71 -159
  11. package/dist/index15.cjs +1 -1
  12. package/dist/index15.js +40 -180
  13. package/dist/index16.cjs +1 -1
  14. package/dist/index16.js +103 -7
  15. package/dist/index17.cjs +1 -1
  16. package/dist/index17.js +3 -2
  17. package/dist/index18.cjs +1 -1
  18. package/dist/index18.js +2 -3
  19. package/dist/index19.cjs +1 -1
  20. package/dist/index19.js +2 -2
  21. package/dist/index2.cjs +1 -1
  22. package/dist/index2.js +5 -5
  23. package/dist/index20.cjs +1 -1
  24. package/dist/index20.js +35 -2
  25. package/dist/index5.cjs +1 -1
  26. package/dist/index5.js +47 -53
  27. package/dist/index6.cjs +1 -1
  28. package/dist/index6.js +12 -22
  29. package/dist/index8.cjs +1 -1
  30. package/dist/index8.js +2 -2
  31. package/dist/index9.cjs +1 -1
  32. package/dist/index9.js +7 -61
  33. package/dist/src/bitcoin/btcWalletsProvider.d.ts +2 -0
  34. package/dist/src/litecoin/constants.d.ts +5 -15
  35. package/dist/src/litecoin/ltcWalletsProvider.d.ts +0 -12
  36. package/dist/src/litecoin/providers/ctrl/ctrl.types.d.ts +13 -0
  37. package/dist/src/litecoin/providers/ctrl/provider.d.ts +22 -0
  38. package/package.json +3 -3
  39. package/dist/index21.cjs +0 -3
  40. package/dist/index21.js +0 -116
  41. package/dist/index22.cjs +0 -1
  42. package/dist/index22.js +0 -4
  43. package/dist/src/litecoin/providers/enkrypt/enkrypt.types.d.ts +0 -22
  44. package/dist/src/litecoin/providers/enkrypt/provider.d.ts +0 -25
  45. package/dist/src/litecoin/providers/litescribe/litescribe.types.d.ts +0 -18
  46. package/dist/src/litecoin/providers/litescribe/provider.d.ts +0 -26
package/dist/index10.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("./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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.Mainnet="mainnet",e.Regtest="regtest",e))(t||{});exports.XverseSparkNetworkType=t;
package/dist/index10.js CHANGED
@@ -1,85 +1,4 @@
1
- var g = (e) => {
2
- throw TypeError(e);
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 "./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 {
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);
15
- }
16
- async connect(t) {
17
- 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({
29
- address: this.address,
30
- provider: this,
31
- network: t,
32
- id: l.Unisat.id
33
- });
34
- } catch (r) {
35
- return a("Error while connecting to the Unisat wallet", r);
36
- }
37
- }
38
- // requests accounts from the wallet, if not connected, it will connect first
39
- async requestAccounts() {
40
- return await h(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
41
- }
42
- //silently gets accounts if already connected
43
- async getAccounts() {
44
- return await h(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
45
- }
46
- 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");
55
- }
56
- 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
- }
68
- }
69
- async getBalance() {
70
- return await h(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
71
- }
72
- async sendBitcoin(t, r) {
73
- return await h(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
74
- }
75
- on(t, r) {
76
- i(this, n).on(t, r);
77
- }
78
- off(t, r) {
79
- i(this, n).removeListener(t, r);
80
- }
81
- }
82
- n = new WeakMap(), o = new WeakMap();
1
+ var n = /* @__PURE__ */ ((t) => (t.Mainnet = "mainnet", t.Regtest = "regtest", t))(n || {});
83
2
  export {
84
- U as UnisatProvider
3
+ n as XverseSparkNetworkType
85
4
  };
package/dist/index11.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=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/index11.js CHANGED
@@ -1,110 +1,64 @@
1
- var g = (n) => {
2
- throw TypeError(n);
1
+ var y = (e) => {
2
+ throw TypeError(e);
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);
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);
19
14
  }
20
- async connect(t) {
21
- if (t || (t = a.MAINNET), t === a.TESTNET)
22
- return i("Phantom wallet does not support testnet");
15
+ async connect() {
23
16
  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({
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({
28
19
  address: this.address,
29
20
  provider: this,
30
- network: t,
31
- id: c.Phantom.id
32
- });
33
- } catch (r) {
34
- return i("Error while connecting to Phantom wallet: " + r);
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);
35
26
  }
36
27
  }
28
+ async getPublicKey() {
29
+ return await h(async () => await n(this, i).getPublicKey(), "Error while getting public key from OKX wallet");
30
+ }
37
31
  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");
32
+ const t = await this.connect();
33
+ return t.ok ? c([t.val.address]) : o(t.error);
42
34
  }
43
35
  async getAccounts() {
44
- return this.requestAccounts();
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");
45
37
  }
46
- // bitcoin testnet is not supported in Phantom wallet
47
38
  async getNetwork() {
48
- return u(a.MAINNET);
39
+ return c(n(this, s));
49
40
  }
50
41
  async switchNetwork() {
51
- return i("Phantom wallet does not support testnet");
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));
52
47
  }
53
48
  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");
49
+ return await h(async () => await n(this, i).getBalance(), "Error while getting balance from OKX wallet");
60
50
  }
61
51
  async sendBitcoin(t, r) {
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
- );
52
+ return await h(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
99
53
  }
100
54
  on(t, r) {
101
- s(this, o).on(t, r);
55
+ n(this, i).on(t, r);
102
56
  }
103
57
  off(t, r) {
104
- s(this, o).off(t, r);
58
+ n(this, i).off(t, r);
105
59
  }
106
60
  }
107
- o = new WeakMap();
61
+ i = new WeakMap(), s = new WeakMap();
108
62
  export {
109
- W as PhantomProvider
63
+ E as OKXProvider
110
64
  };
package/dist/index12.cjs CHANGED
@@ -1 +1 @@
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;
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;
package/dist/index12.js CHANGED
@@ -1,83 +1,85 @@
1
- var N = (s) => {
2
- throw TypeError(s);
1
+ var g = (e) => {
2
+ throw TypeError(e);
3
3
  };
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) => {
14
- try {
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);
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);
15
+ }
16
+ async connect(t) {
17
+ 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);
33
26
  }
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);
27
+ const c = await i(this, n).requestAccounts();
28
+ return c.length > 0 && (this.address = c[0]), E({
29
+ address: this.address,
30
+ provider: this,
31
+ network: t,
32
+ id: l.Unisat.id
33
+ });
34
+ } catch (r) {
35
+ return a("Error while connecting to the Unisat wallet", r);
36
+ }
37
+ }
38
+ // requests accounts from the wallet, if not connected, it will connect first
39
+ async requestAccounts() {
40
+ return await h(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
41
+ }
42
+ //silently gets accounts if already connected
43
+ async getAccounts() {
44
+ return await h(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
50
45
  }
51
46
  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");
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");
63
55
  }
64
56
  async switchNetwork() {
65
57
  try {
66
- const e = await this.getNetwork();
67
- if (e.error)
58
+ const t = await this.getNetwork(), r = await i(this, n).getChain();
59
+ if (t.error)
68
60
  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);
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);
77
67
  }
78
68
  }
69
+ async getBalance() {
70
+ return await h(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
71
+ }
72
+ async sendBitcoin(t, r) {
73
+ return await h(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
74
+ }
75
+ on(t, r) {
76
+ i(this, n).on(t, r);
77
+ }
78
+ off(t, r) {
79
+ i(this, n).removeListener(t, r);
80
+ }
79
81
  }
80
- n = new WeakMap();
82
+ n = new WeakMap(), o = new WeakMap();
81
83
  export {
82
- T as XverseProvider
84
+ U as UnisatProvider
83
85
  };
package/dist/index13.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var o=r=>{throw TypeError(r)};var l=(r,e,t)=>e.has(r)||o("Cannot "+t);var s=(r,e,t)=>(l(r,e,"read from private field"),t?t.call(r):e.get(r)),u=(r,e,t)=>e.has(r)?o("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),h=(r,e,t,c)=>(l(r,e,"write to private field"),c?c.call(r,t):e.set(r,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index20.cjs"),a=require("./index3.cjs"),n=require("@gardenfi/utils");var i;class p{constructor(e){u(this,i);this.address="",this.id=a.WALLET_CONFIG.Keplr.id,this.name=a.WALLET_CONFIG.Keplr.name,this.icon=a.WALLET_CONFIG.Keplr.icon,h(this,i,e)}async connect(e){if(e||(e=n.Network.MAINNET),e===n.Network.TESTNET)return n.Err("Keplr wallet does not support testnet4");try{const t=await s(this,i).requestAccounts();return t.length>0&&(this.address=t[0]),n.Ok({address:this.address,provider:this,network:e,id:a.WALLET_CONFIG.Keplr.id})}catch(t){return n.Err("Error while connecting to the Keplr wallet",t)}}async requestAccounts(){return await n.executeWithTryCatch(async()=>await s(this,i).requestAccounts(),"Error while requesting accounts from the Keplr wallet")}async getAccounts(){return await n.executeWithTryCatch(async()=>await s(this,i).getAccounts(),"Error while getting accounts from the Keplr wallet")}async getNetwork(){return await n.executeWithTryCatch(async()=>{const e=await s(this,i).getChain();if(e.enum===w.KeplrBitcoinChainType.MAINNET)return n.Network.MAINNET;if(e.enum===w.KeplrBitcoinChainType.TESTNET)return n.Network.TESTNET;throw new Error("Invalid or unsupported network"+e.enum)},"Error while getting network from the Keplr wallet")}async switchNetwork(){return n.Err("Keplr wallet does not support testnet4")}async getBalance(){return await n.executeWithTryCatch(async()=>await s(this,i).getBalance(),"Error while getting balance from Keplr wallet")}async sendBitcoin(e,t){return await n.executeWithTryCatch(async()=>await s(this,i).sendBitcoin(e,t),"Error while sending bitcoin from Keplr wallet")}on(e,t){s(this,i).on(e,t)}off(e,t){s(this,i).off(e,t)}async disconnect(){return await s(this,i).disconnect(),this.address="",n.Ok("Disconnected Keplr wallet")}}i=new WeakMap;exports.KeplrProvider=p;
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/index13.js CHANGED
@@ -1,68 +1,110 @@
1
- var u = (r) => {
2
- throw TypeError(r);
1
+ var g = (n) => {
2
+ throw TypeError(n);
3
3
  };
4
- var h = (r, t, e) => t.has(r) || u("Cannot " + e);
5
- var s = (r, t, e) => (h(r, t, "read from private field"), e ? e.call(r) : t.get(r)), w = (r, t, e) => t.has(r) ? u("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), p = (r, t, e, l) => (h(r, t, "write to private field"), l ? l.call(r, e) : t.set(r, e), e);
6
- import { KeplrBitcoinChainType as d } from "./index20.js";
7
- import { WALLET_CONFIG as a } from "./index3.js";
8
- import { Network as o, Err as c, Ok as E, executeWithTryCatch as i } from "@gardenfi/utils";
9
- var n;
10
- class K {
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 {
11
16
  constructor(t) {
12
- w(this, n);
13
- this.address = "", this.id = a.Keplr.id, this.name = a.Keplr.name, this.icon = a.Keplr.icon, p(this, n, 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);
14
19
  }
15
20
  async connect(t) {
16
- if (t || (t = o.MAINNET), t === o.TESTNET)
17
- return c("Keplr wallet does not support testnet4");
21
+ if (t || (t = a.MAINNET), t === a.TESTNET)
22
+ return i("Phantom wallet does not support testnet");
18
23
  try {
19
- const e = await s(this, n).requestAccounts();
20
- return e.length > 0 && (this.address = e[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({
21
28
  address: this.address,
22
29
  provider: this,
23
30
  network: t,
24
- id: a.Keplr.id
31
+ id: c.Phantom.id
25
32
  });
26
- } catch (e) {
27
- return c("Error while connecting to the Keplr wallet", e);
33
+ } catch (r) {
34
+ return i("Error while connecting to Phantom wallet: " + r);
28
35
  }
29
36
  }
30
37
  async requestAccounts() {
31
- return await i(async () => await s(this, n).requestAccounts(), "Error while requesting accounts from the Keplr 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");
32
42
  }
33
43
  async getAccounts() {
34
- return await i(async () => await s(this, n).getAccounts(), "Error while getting accounts from the Keplr wallet");
44
+ return this.requestAccounts();
35
45
  }
46
+ // bitcoin testnet is not supported in Phantom wallet
36
47
  async getNetwork() {
37
- return await i(async () => {
38
- const t = await s(this, n).getChain();
39
- if (t.enum === d.MAINNET)
40
- return o.MAINNET;
41
- if (t.enum === d.TESTNET)
42
- return o.TESTNET;
43
- throw new Error("Invalid or unsupported network" + t.enum);
44
- }, "Error while getting network from the Keplr wallet");
48
+ return u(a.MAINNET);
45
49
  }
46
50
  async switchNetwork() {
47
- return c("Keplr wallet does not support testnet4");
51
+ return i("Phantom wallet does not support testnet");
48
52
  }
49
53
  async getBalance() {
50
- return await i(async () => await s(this, n).getBalance(), "Error while getting balance from Keplr 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");
51
60
  }
52
- async sendBitcoin(t, e) {
53
- return await i(async () => await s(this, n).sendBitcoin(t, e), "Error while sending bitcoin from Keplr wallet");
61
+ async sendBitcoin(t, r) {
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");
54
94
  }
55
- on(t, e) {
56
- s(this, n).on(t, e);
95
+ fromHexString(t) {
96
+ return Uint8Array.from(
97
+ t.match(/.{1,2}/g).map((r) => parseInt(r, 16))
98
+ );
57
99
  }
58
- off(t, e) {
59
- s(this, n).off(t, e);
100
+ on(t, r) {
101
+ s(this, o).on(t, r);
60
102
  }
61
- async disconnect() {
62
- return await s(this, n).disconnect(), this.address = "", E("Disconnected Keplr wallet");
103
+ off(t, r) {
104
+ s(this, o).off(t, r);
63
105
  }
64
106
  }
65
- n = new WeakMap();
107
+ o = new WeakMap();
66
108
  export {
67
- K as KeplrProvider
109
+ W as PhantomProvider
68
110
  };