@gardenfi/wallet-connectors 2.2.1-beta.4 → 2.2.1-beta.6

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/index7.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,s)=>(f(r,t,"write to private field"),s?s.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("bitcoinjs-lib"),N=require("tiny-secp256k1"),n=require("@gardenfi/utils"),i=require("./index3.cjs"),c=require("@gardenfi/core"),A=require("./index4.cjs");function y(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const u=y(P),x=y(N);P.initEccLib(x);var o;class O{constructor(t){w(this,o);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,o,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,o).requestAccounts();for(const s of e)s.purpose==="payment"&&(this.address=s.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,o).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 A.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 s=u.networks.bitcoin,d=new c.BitcoinProvider(c.BitcoinNetwork.Mainnet);try{const{txHex:h,utxoCount:p}=await c.BitcoinWallet.generateUnsignedPSBT(d,s,this.address,t,e),b=await a(this,o).signPSBT(this.fromHexString(h),{inputsToSign:[{address:this.address,signingIndexes:Array.from({length:p},(S,T)=>T),sigHash:u.Transaction.SIGHASH_ALL}]}),l=u.Psbt.fromBuffer(Buffer.from(b)).extractTransaction(),E=l.getId();return await d.broadcast(l.toHex()),E}catch{throw new Error("Failed to send bitcoin")}},"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,o).on(t,e)}off(t,e){a(this,o).off(t,e)}}o=new WeakMap;exports.PhantomProvider=O;
1
+ "use strict";var f=r=>{throw TypeError(r)};var w=(r,t,e)=>t.has(r)||f("Cannot "+e);var a=(r,t,e)=>(w(r,t,"read from private field"),e?e.call(r):t.get(r)),g=(r,t,e)=>t.has(r)?f("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),P=(r,t,e,o)=>(w(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"),d=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 h=p(y),I=p(A);y.initEccLib(I);var s;class O{constructor(t){g(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"))),P(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=h.networks.bitcoin,l=new d.BitcoinProvider(d.BitcoinNetwork.Mainnet);try{const{txHex:c,utxoCount:b}=await d.BitcoinWallet.generateUnsignedPSBT(l,o,this.address,t,e),E=await a(this,s).signPSBT(this.fromHexString(c),{inputsToSign:[{address:this.address,signingIndexes:Array.from({length:b},(S,N)=>N),sigHash:h.Transaction.SIGHASH_ALL}]}),m=h.Psbt.fromBuffer(Buffer.from(E));m.finalizeAllInputs();const u=m.extractTransaction();console.log("tx",u);const T=u.getId();return await l.broadcast(u.toHex()),T}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/index7.js CHANGED
@@ -1,30 +1,30 @@
1
- var w = (n) => {
1
+ var g = (n) => {
2
2
  throw TypeError(n);
3
3
  };
4
- var g = (n, t, r) => t.has(n) || w("Cannot " + r);
5
- var s = (n, t, r) => (g(n, t, "read from private field"), r ? r.call(n) : t.get(n)), p = (n, t, r) => t.has(n) ? w("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, r), P = (n, t, r, o) => (g(n, t, "write to private field"), o ? o.call(n, r) : t.set(n, r), r);
6
- import * as d from "bitcoinjs-lib";
7
- import { initEccLib as T } from "bitcoinjs-lib";
8
- import * as x from "tiny-secp256k1";
9
- import { Ok as h, Network as a, Err as i, executeWithTryCatch as m } from "@gardenfi/utils";
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 b } from "bitcoinjs-lib";
8
+ import * as N from "tiny-secp256k1";
9
+ import { Ok as u, Network as a, Err as i, executeWithTryCatch as l } from "@gardenfi/utils";
10
10
  import { WALLET_CONFIG as c } from "./index3.js";
11
- import { BitcoinProvider as N, BitcoinNetwork as B, BitcoinWallet as I } from "@gardenfi/core";
12
- import { getBalance as v } from "./index4.js";
13
- T(x);
14
- var e;
11
+ import { BitcoinProvider as B, BitcoinNetwork as I, BitcoinWallet as v } from "@gardenfi/core";
12
+ import { getBalance as S } from "./index4.js";
13
+ b(N);
14
+ var o;
15
15
  class _ {
16
16
  constructor(t) {
17
- p(this, e);
18
- this.address = "", this.id = c.Phantom.id, this.name = c.Phantom.name, this.icon = c.Phantom.icon, this.disconnect = () => (this.address = "", Promise.resolve(h("Disconnected Phantom wallet"))), P(this, e, 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
19
  }
20
20
  async connect(t) {
21
21
  if (t || (t = a.MAINNET), t === a.TESTNET)
22
22
  return i("Phantom wallet does not support testnet");
23
23
  try {
24
- const r = await s(this, e).requestAccounts();
25
- for (const o of r)
26
- o.purpose === "payment" && (this.address = o.address);
27
- return this.address === "" ? i("Could not connect to Phantom bitcoin payment account") : h({
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
28
  address: this.address,
29
29
  provider: this,
30
30
  network: t,
@@ -35,8 +35,8 @@ class _ {
35
35
  }
36
36
  }
37
37
  async requestAccounts() {
38
- return await m(async () => {
39
- const t = await s(this, e).requestAccounts();
38
+ return await l(async () => {
39
+ const t = await s(this, o).requestAccounts();
40
40
  return t.length > 0 && (this.address = t[0].address), t.map((r) => r.address);
41
41
  }, "Error while requesting accounts from Phantom wallet");
42
42
  }
@@ -45,46 +45,50 @@ class _ {
45
45
  }
46
46
  // bitcoin testnet is not supported in Phantom wallet
47
47
  async getNetwork() {
48
- return h(a.MAINNET);
48
+ return u(a.MAINNET);
49
49
  }
50
50
  async switchNetwork() {
51
51
  return i("Phantom wallet does not support testnet");
52
52
  }
53
53
  async getBalance() {
54
- return await m(async () => {
55
- const t = await v(this.address, a.MAINNET);
54
+ return await l(async () => {
55
+ const t = await S(this.address, a.MAINNET);
56
56
  if (t.ok && t.val)
57
57
  return t.val;
58
58
  throw new Error(t.error);
59
59
  }, "Error while getting balance from Phantom wallet");
60
60
  }
61
61
  async sendBitcoin(t, r) {
62
- return await m(async () => {
63
- const o = d.networks.bitcoin, u = new N(B.Mainnet);
62
+ return await l(async () => {
63
+ const e = m.networks.bitcoin, f = new B(I.Mainnet);
64
64
  try {
65
- const { txHex: f, utxoCount: y } = await I.generateUnsignedPSBT(
66
- u,
67
- o,
65
+ const { txHex: d, utxoCount: A } = await v.generateUnsignedPSBT(
66
+ f,
67
+ e,
68
68
  this.address,
69
69
  t,
70
70
  r
71
- ), E = await s(this, e).signPSBT(
72
- this.fromHexString(f),
71
+ ), E = await s(this, o).signPSBT(
72
+ this.fromHexString(d),
73
73
  {
74
74
  inputsToSign: [
75
75
  {
76
76
  address: this.address,
77
- signingIndexes: Array.from({ length: y }, (H, A) => A),
78
- sigHash: d.Transaction.SIGHASH_ALL
77
+ signingIndexes: Array.from({ length: A }, (H, T) => T),
78
+ sigHash: m.Transaction.SIGHASH_ALL
79
79
  }
80
80
  ]
81
81
  }
82
- ), l = d.Psbt.fromBuffer(
82
+ ), w = m.Psbt.fromBuffer(
83
83
  Buffer.from(E)
84
- ).extractTransaction(), b = l.getId();
85
- return await u.broadcast(l.toHex()), b;
86
- } catch {
87
- throw new Error("Failed to send bitcoin");
84
+ );
85
+ w.finalizeAllInputs();
86
+ const h = w.extractTransaction();
87
+ console.log("tx", h);
88
+ const x = h.getId();
89
+ return await f.broadcast(h.toHex()), x;
90
+ } catch (d) {
91
+ throw new Error(`Failed to send bitcoin: ${d}`);
88
92
  }
89
93
  }, "Error while sending bitcoin from Phantom wallet");
90
94
  }
@@ -94,13 +98,13 @@ class _ {
94
98
  );
95
99
  }
96
100
  on(t, r) {
97
- s(this, e).on(t, r);
101
+ s(this, o).on(t, r);
98
102
  }
99
103
  off(t, r) {
100
- s(this, e).off(t, r);
104
+ s(this, o).off(t, r);
101
105
  }
102
106
  }
103
- e = new WeakMap();
107
+ o = new WeakMap();
104
108
  export {
105
109
  _ as PhantomProvider
106
110
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/wallet-connectors",
3
- "version": "2.2.1-beta.4",
3
+ "version": "2.2.1-beta.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "sideEffects": false,
38
38
  "dependencies": {
39
- "@gardenfi/core": "2.3.1-beta.4",
40
- "@gardenfi/utils": "2.3.0",
39
+ "@gardenfi/core": "2.3.1-beta.6",
40
+ "@gardenfi/utils": "2.3.1",
41
41
  "axios": "^1.7.9",
42
42
  "bitcoinjs-lib": "^6.1.7",
43
43
  "react": "^18.3.1",