@gardenfi/wallet-connectors 2.0.10 → 2.0.11-beta.2
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/index4.cjs +1 -1
- package/dist/index4.js +12 -9
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +42 -36
- package/dist/src/bitcoin/providers/keplr/provider.d.ts +1 -1
- package/dist/src/bitcoin/providers/unisat/provider.d.ts +1 -1
- package/dist/src/bitcoin/providers/xverse/provider.d.ts +1 -1
- package/package.json +2 -2
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@catalogfi/utils"),p={testnet:{Mempool:"https://mempool.space/testnet4"},mainnet:{Mempool:"https://mempool.space",Blockstream:"https://blockstream.info"}},u=async(n,m)=>{const t=p[m];if(!t)return o.Err("Invalid network");const r="Blockstream"in t?`${t.Blockstream}/api/address/${n}`:null,a=`${t.Mempool}/api/address/${n}`;try{const s=r?[r,a]:[a],e=await o.Fetcher.getWithFallback(s,{retryCount:3,retryDelay:1e3}),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@catalogfi/utils"),p={testnet:{Mempool:"https://mempool.space/testnet4"},mainnet:{Mempool:"https://mempool.space",Blockstream:"https://blockstream.info"},localnet:{Mempool:"http://localhost:30000"}},u=async(n,m)=>{const t=p[m];if(!t)return o.Err("Invalid network");const r="Blockstream"in t?`${t.Blockstream}/api/address/${n}`:null,a=`${t.Mempool}/api/address/${n}`;try{const s=r?[r,a]:[a],e=await o.Fetcher.getWithFallback(s,{retryCount:3,retryDelay:1e3}),l=e.chain_stats.funded_txo_sum-e.chain_stats.spent_txo_sum,c=e.mempool_stats.funded_txo_sum-e.mempool_stats.spent_txo_sum,i=l+c;return o.Ok({confirmed:l,unconfirmed:c,total:i})}catch(s){return o.Err("Error while fetching balance",s)}};exports.getBalance=u;
|
package/dist/index4.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import { Err as l, Fetcher as
|
|
2
|
-
const
|
|
1
|
+
import { Err as l, Fetcher as i, Ok as h } from "@catalogfi/utils";
|
|
2
|
+
const u = {
|
|
3
3
|
testnet: {
|
|
4
4
|
Mempool: "https://mempool.space/testnet4"
|
|
5
5
|
},
|
|
6
6
|
mainnet: {
|
|
7
7
|
Mempool: "https://mempool.space",
|
|
8
8
|
Blockstream: "https://blockstream.info"
|
|
9
|
+
},
|
|
10
|
+
localnet: {
|
|
11
|
+
Mempool: "http://localhost:30000"
|
|
9
12
|
}
|
|
10
13
|
}, d = async (s, m) => {
|
|
11
|
-
const t =
|
|
14
|
+
const t = u[m];
|
|
12
15
|
if (!t) return l("Invalid network");
|
|
13
|
-
const n = "Blockstream" in t ? `${t.Blockstream}/api/address/${s}` : null,
|
|
16
|
+
const n = "Blockstream" in t ? `${t.Blockstream}/api/address/${s}` : null, a = `${t.Mempool}/api/address/${s}`;
|
|
14
17
|
try {
|
|
15
|
-
const e = n ? [n,
|
|
18
|
+
const e = n ? [n, a] : [a], o = await i.getWithFallback(e, {
|
|
16
19
|
retryCount: 3,
|
|
17
20
|
retryDelay: 1e3
|
|
18
|
-
}),
|
|
19
|
-
return
|
|
20
|
-
confirmed:
|
|
21
|
+
}), r = o.chain_stats.funded_txo_sum - o.chain_stats.spent_txo_sum, c = o.mempool_stats.funded_txo_sum - o.mempool_stats.spent_txo_sum, p = r + c;
|
|
22
|
+
return h({
|
|
23
|
+
confirmed: r,
|
|
21
24
|
unconfirmed: c,
|
|
22
|
-
total:
|
|
25
|
+
total: p
|
|
23
26
|
});
|
|
24
27
|
} catch (e) {
|
|
25
28
|
return l("Error while fetching balance", e);
|
package/dist/index7.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=r=>{throw TypeError(r)};var
|
|
1
|
+
"use strict";var f=r=>{throw TypeError(r)};var w=(r,t,e)=>t.has(r)||f("Cannot "+e);var i=(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,n)=>(w(r,t,"write to private field"),n?n.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@catalogfi/utils"),y=require("bitcoinjs-lib"),A=require("tiny-secp256k1"),a=require("@gardenfi/utils"),c=require("./index3.cjs"),u=require("@catalogfi/wallets"),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 n=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,n.get?n:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const d=p(y),O=p(A);y.initEccLib(O);var o;class q{constructor(t){g(this,o);this.address="",this.id=c.WALLET_CONFIG.Phantom.id,this.name=c.WALLET_CONFIG.Phantom.name,this.icon=c.WALLET_CONFIG.Phantom.icon,this.disconnect=()=>(this.address="",Promise.resolve(s.Ok("Disconnected Phantom wallet"))),P(this,o,t)}async connect(t){if(t||(t=a.Network.MAINNET),t===a.Network.TESTNET)return s.Err("Phantom wallet does not support testnet");try{const e=await i(this,o).requestAccounts();for(const n of e)n.purpose==="payment"&&(this.address=n.address);return this.address===""?s.Err("Could not connect to Phantom bitcoin payment account"):s.Ok({address:this.address,provider:this,network:t,id:c.WALLET_CONFIG.Phantom.id})}catch(e){return s.Err("Error while connecting to Phantom wallet: "+e)}}async requestAccounts(){return await s.executeWithTryCatch(async()=>{const t=await i(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 s.Ok(a.Network.MAINNET)}async switchNetwork(){return s.Err("Phantom wallet does not support testnet")}async getBalance(){return await s.executeWithTryCatch(async()=>{const t=await x.getBalance(this.address,a.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 s.executeWithTryCatch(async()=>{const n=d.networks.bitcoin,h=new u.BitcoinProvider(u.BitcoinNetwork.Mainnet);try{const{txHex:l,utxoCount:b}=await u.BitcoinWallet.generateUnsignedPSBT(h,n,this.address,t,e),E=await i(this,o).signPSBT(this.fromHexString(l),{inputsToSign:[{address:this.address,signingIndexes:Array.from({length:b},(S,N)=>N),sigHash:d.Transaction.SIGHASH_ALL}]}),m=d.Psbt.fromBuffer(Buffer.from(E)).extractTransaction(),T=m.getId();return await h.broadcast(m.toHex()),T}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){i(this,o).on(t,e)}off(t,e){i(this,o).off(t,e)}}o=new WeakMap;exports.PhantomProvider=q;
|
package/dist/index7.js
CHANGED
|
@@ -2,41 +2,42 @@ var w = (n) => {
|
|
|
2
2
|
throw TypeError(n);
|
|
3
3
|
};
|
|
4
4
|
var g = (n, t, r) => t.has(n) || w("Cannot " + r);
|
|
5
|
-
var
|
|
6
|
-
import { Ok as
|
|
7
|
-
import * as
|
|
8
|
-
import { initEccLib as
|
|
9
|
-
import * as
|
|
10
|
-
import { Network as
|
|
11
|
-
import { WALLET_CONFIG as
|
|
12
|
-
import { BitcoinProvider as
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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, e) => (g(n, t, "write to private field"), e ? e.call(n, r) : t.set(n, r), r);
|
|
6
|
+
import { Ok as d, Err as i, executeWithTryCatch as h } from "@catalogfi/utils";
|
|
7
|
+
import * as m from "bitcoinjs-lib";
|
|
8
|
+
import { initEccLib as T } from "bitcoinjs-lib";
|
|
9
|
+
import * as x from "tiny-secp256k1";
|
|
10
|
+
import { Network as a } from "@gardenfi/utils";
|
|
11
|
+
import { WALLET_CONFIG as c } from "./index3.js";
|
|
12
|
+
import { BitcoinProvider as N, BitcoinNetwork as B, BitcoinWallet as I } from "@catalogfi/wallets";
|
|
13
|
+
import { getBalance as v } from "./index4.js";
|
|
14
|
+
T(x);
|
|
15
|
+
var o;
|
|
16
|
+
class F {
|
|
16
17
|
constructor(t) {
|
|
17
|
-
p(this,
|
|
18
|
-
this.address = "", this.id =
|
|
18
|
+
p(this, o);
|
|
19
|
+
this.address = "", this.id = c.Phantom.id, this.name = c.Phantom.name, this.icon = c.Phantom.icon, this.disconnect = () => (this.address = "", Promise.resolve(d("Disconnected Phantom wallet"))), P(this, o, t);
|
|
19
20
|
}
|
|
20
21
|
async connect(t) {
|
|
21
|
-
if (t || (t =
|
|
22
|
+
if (t || (t = a.MAINNET), t === a.TESTNET)
|
|
22
23
|
return i("Phantom wallet does not support testnet");
|
|
23
24
|
try {
|
|
24
|
-
const r = await
|
|
25
|
-
for (const
|
|
26
|
-
|
|
27
|
-
return this.address === "" ? i("Could not connect to Phantom bitcoin payment account") :
|
|
25
|
+
const r = await s(this, o).requestAccounts();
|
|
26
|
+
for (const e of r)
|
|
27
|
+
e.purpose === "payment" && (this.address = e.address);
|
|
28
|
+
return this.address === "" ? i("Could not connect to Phantom bitcoin payment account") : d({
|
|
28
29
|
address: this.address,
|
|
29
30
|
provider: this,
|
|
30
31
|
network: t,
|
|
31
|
-
id:
|
|
32
|
+
id: c.Phantom.id
|
|
32
33
|
});
|
|
33
34
|
} catch (r) {
|
|
34
35
|
return i("Error while connecting to Phantom wallet: " + r);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
async requestAccounts() {
|
|
38
|
-
return await
|
|
39
|
-
const t = await
|
|
39
|
+
return await h(async () => {
|
|
40
|
+
const t = await s(this, o).requestAccounts();
|
|
40
41
|
return t.length > 0 && (this.address = t[0].address), t.map((r) => r.address);
|
|
41
42
|
}, "Error while requesting accounts from Phantom wallet");
|
|
42
43
|
}
|
|
@@ -45,39 +46,44 @@ class W {
|
|
|
45
46
|
}
|
|
46
47
|
// bitcoin testnet is not supported in Phantom wallet
|
|
47
48
|
async getNetwork() {
|
|
48
|
-
return
|
|
49
|
+
return d(a.MAINNET);
|
|
49
50
|
}
|
|
50
51
|
async switchNetwork() {
|
|
51
52
|
return i("Phantom wallet does not support testnet");
|
|
52
53
|
}
|
|
53
54
|
async getBalance() {
|
|
54
|
-
return await
|
|
55
|
+
return await h(async () => {
|
|
56
|
+
const t = await v(this.address, a.MAINNET);
|
|
57
|
+
if (t.ok && t.val)
|
|
58
|
+
return t.val;
|
|
59
|
+
throw new Error(t.error);
|
|
60
|
+
}, "Error while getting balance from Phantom wallet");
|
|
55
61
|
}
|
|
56
62
|
async sendBitcoin(t, r) {
|
|
57
|
-
return await
|
|
58
|
-
const
|
|
63
|
+
return await h(async () => {
|
|
64
|
+
const e = m.networks.bitcoin, u = new N(B.Mainnet);
|
|
59
65
|
try {
|
|
60
66
|
const { txHex: f, utxoCount: y } = await I.generateUnsignedPSBT(
|
|
61
67
|
u,
|
|
62
|
-
|
|
68
|
+
e,
|
|
63
69
|
this.address,
|
|
64
70
|
t,
|
|
65
71
|
r
|
|
66
|
-
),
|
|
72
|
+
), E = await s(this, o).signPSBT(
|
|
67
73
|
this.fromHexString(f),
|
|
68
74
|
{
|
|
69
75
|
inputsToSign: [
|
|
70
76
|
{
|
|
71
77
|
address: this.address,
|
|
72
78
|
signingIndexes: Array.from({ length: y }, (H, A) => A),
|
|
73
|
-
sigHash:
|
|
79
|
+
sigHash: m.Transaction.SIGHASH_ALL
|
|
74
80
|
}
|
|
75
81
|
]
|
|
76
82
|
}
|
|
77
|
-
), l =
|
|
78
|
-
Buffer.from(
|
|
79
|
-
).extractTransaction(),
|
|
80
|
-
return await u.broadcast(l.toHex()),
|
|
83
|
+
), l = m.Psbt.fromBuffer(
|
|
84
|
+
Buffer.from(E)
|
|
85
|
+
).extractTransaction(), b = l.getId();
|
|
86
|
+
return await u.broadcast(l.toHex()), b;
|
|
81
87
|
} catch {
|
|
82
88
|
throw new Error("Failed to send bitcoin");
|
|
83
89
|
}
|
|
@@ -89,13 +95,13 @@ class W {
|
|
|
89
95
|
);
|
|
90
96
|
}
|
|
91
97
|
on(t, r) {
|
|
92
|
-
|
|
98
|
+
s(this, o).on(t, r);
|
|
93
99
|
}
|
|
94
100
|
off(t, r) {
|
|
95
|
-
|
|
101
|
+
s(this, o).off(t, r);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
|
-
|
|
104
|
+
o = new WeakMap();
|
|
99
105
|
export {
|
|
100
|
-
|
|
106
|
+
F as PhantomProvider
|
|
101
107
|
};
|
|
@@ -13,7 +13,7 @@ export declare class KeplrProvider implements IInjectedBitcoinProvider {
|
|
|
13
13
|
connect(network?: Network): AsyncResult<Connect, string>;
|
|
14
14
|
requestAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
|
|
15
15
|
getAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
|
|
16
|
-
getNetwork(): Promise<import('@catalogfi/utils').Result<Network, string>>;
|
|
16
|
+
getNetwork(): Promise<import('@catalogfi/utils').Result<Network.MAINNET | Network.TESTNET, string>>;
|
|
17
17
|
switchNetwork(): AsyncResult<Network, string>;
|
|
18
18
|
getBalance(): Promise<import('@catalogfi/utils').Result<{
|
|
19
19
|
confirmed: number;
|
|
@@ -13,7 +13,7 @@ export declare class UnisatProvider implements IInjectedBitcoinProvider {
|
|
|
13
13
|
connect(network?: Network): AsyncResult<Connect, string>;
|
|
14
14
|
requestAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
|
|
15
15
|
getAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
|
|
16
|
-
getNetwork(): Promise<import('@catalogfi/utils').Result<Network, string>>;
|
|
16
|
+
getNetwork(): Promise<import('@catalogfi/utils').Result<Network.MAINNET | Network.TESTNET, string>>;
|
|
17
17
|
switchNetwork(): AsyncResult<Network, string>;
|
|
18
18
|
getBalance(): Promise<import('@catalogfi/utils').Result<{
|
|
19
19
|
confirmed: number;
|
|
@@ -15,7 +15,7 @@ export declare class XverseProvider implements IInjectedBitcoinProvider {
|
|
|
15
15
|
requestAccounts: () => AsyncResult<string[], string>;
|
|
16
16
|
getAccounts: () => AsyncResult<string[], string>;
|
|
17
17
|
sendBitcoin: (toAddress: string, satoshis: number) => AsyncResult<string, string>;
|
|
18
|
-
getNetwork(): Promise<import('@catalogfi/utils').Result<Network, string>>;
|
|
18
|
+
getNetwork(): Promise<import('@catalogfi/utils').Result<Network.MAINNET | Network.TESTNET, string>>;
|
|
19
19
|
switchNetwork(): AsyncResult<Network, string>;
|
|
20
20
|
/**
|
|
21
21
|
* not available in XVerse wallet
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/wallet-connectors",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@catalogfi/utils": "^0.1.11",
|
|
40
40
|
"@catalogfi/wallets": "^0.2.54",
|
|
41
|
-
"@gardenfi/utils": "2.1.3",
|
|
41
|
+
"@gardenfi/utils": "2.1.3-beta.22",
|
|
42
42
|
"axios": "^1.7.9",
|
|
43
43
|
"bitcoinjs-lib": "^6.1.7",
|
|
44
44
|
"react": "^18.3.1",
|