@gardenfi/wallet-connectors 2.5.1 → 2.5.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/index14.cjs +1 -1
- package/dist/index14.js +168 -7
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +206 -2
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +7 -168
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +2 -206
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +2 -2
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +2 -2
- package/package.json +2 -2
package/dist/index14.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={
|
|
1
|
+
"use strict";var O=s=>{throw TypeError(s)};var m=(s,t,r)=>t.has(s)||O("Cannot "+r);var i=(s,t,r)=>(m(s,t,"read from private field"),r?r.call(s):t.get(s)),v=(s,t,r)=>t.has(s)?O("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,r),E=(s,t,r,n)=>(m(s,t,"write to private field"),n?n.call(s,r):t.set(s,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("bitcoinjs-lib"),A=require("tiny-secp256k1"),e=require("@gardenfi/utils"),p=require("./index6.cjs"),b=require("./index21.cjs");function P(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const N=P(I),L=P(A);N.initEccLib(L);var o,a;class x{constructor(t){v(this,o);v(this,a);this.address="",this.id=p.WALLET_CONFIG.Enkrypt.id,this.name=p.WALLET_CONFIG.Enkrypt.name,this.icon=p.WALLET_CONFIG.Enkrypt.icon,this.disconnect=()=>(this.address="",Promise.resolve(e.Ok("Disconnected Enkrypt wallet"))),E(this,o,t),E(this,a,e.Network.MAINNET)}async connect(t){if(t||(t=e.Network.MAINNET),t===e.Network.TESTNET)return e.Err("Enkrypt wallet does not support testnet");try{const r=await i(this,o).requestAccounts();return r.length>0&&(this.address=r[0]),e.Ok({address:this.address,provider:this,network:t,id:p.WALLET_CONFIG.Enkrypt.id})}catch(r){return e.Err("Error while connecting to Enkrypt wallet: "+r)}}async requestAccounts(){return await e.executeWithTryCatch(async()=>await i(this,o).requestAccounts(),"Error while requesting accounts from the Enkrypt wallet")}async getAccounts(){return this.requestAccounts()}async getNetwork(){return e.Ok(i(this,a))}async switchNetwork(){E(this,a,i(this,a)===e.Network.MAINNET?e.Network.TESTNET:e.Network.MAINNET);const t=await this.connect();return t.error?e.Err(`Failed to connect to ${i(this,a)}: ${t.error}`):e.Ok(i(this,a))}async getBalance(){let t=await this.getAccounts();if(!t.ok)return e.Err("Failed to get address");this.address=t.val[0];const r=await this.getNetwork();return r.ok?(E(this,a,r.val),await b.getBalance(this.address,i(this,a))):e.Err("Failed to get network")}async sendLitecoin(t,r){try{const n=await this.getAccounts();if(!n.ok)return e.Err("Failed to get address");this.address=n.val[0];const g=await this.getNetwork();if(!g.ok)return e.Err("Failed to get network");if(E(this,a,g.val),!t||t.trim()==="")return e.Err("Invalid destination address");if(r<=0)return e.Err("Amount must be greater than 0");const l=await this.getBalance();if(!l.ok)return e.Err("Failed to get balance",l.error);if(l.val.total<r)return e.Err("Insufficient balance");const u=await b.getUTXOs(this.address,i(this,a));if(!u.ok)return e.Err("Failed to fetch UTXOs",u.error);const w=u.val;if(!w||w.length===0)return e.Err("No UTXOs available");const h=await this.buildTransaction(w,t,r,this.address);if(!h.ok)return e.Err("Failed to build transaction",h.error);const f=await this.signPsbt(h.val);if(!f.ok)return e.Err("Failed to sign transaction",f.error);const c=await this.broadcastTransaction(f.val);return c.ok?e.Ok(c.val):e.Err("Failed to broadcast transaction",c.error)}catch(n){return n instanceof Error?n.message.includes("User rejected")||n.message.includes("cancelled")||n.message.includes("denied")?e.Err("Transaction cancelled by user"):e.Err("Error while sending Litecoin: "+n.message):e.Err("Error while sending Litecoin",String(n))}}async buildTransaction(t,r,n,g){try{const l=b.getLitecoinNetwork(i(this,a)),u=new N.Psbt({network:l}),w=t.sort((d,k)=>k.value-d.value),h=await b.getRecommendedFeeRate(i(this,a));if(!h.ok)return e.Err("Failed to fetch recommended fee rate",h.error);const f=h.val;let c=0;for(const d of w){if(c>=n+f*250)break;let k;try{k={script:N.address.toOutputScript(g,l),value:d.value}}catch{if(d.scriptPubKey)k={script:Buffer.from(d.scriptPubKey,"hex"),value:d.value};else throw new Error("Cannot determine script for UTXO")}u.addInput({hash:d.txid,index:d.vout,witnessUtxo:k}),c+=d.value}if(c===0)return e.Err("No valid UTXOs found");const y=(u.txInputs.length*148+2*34+10)*f;if(c<n+y)return e.Err(`Insufficient funds: need ${n+y} sats, have ${c} sats`);u.addOutput({address:r,value:n});const T=c-n-y;return T>546&&u.addOutput({address:g,value:T}),e.Ok(u.toBase64())}catch(l){return e.Err("Error building transaction",String(l))}}async signPsbt(t){return await e.executeWithTryCatch(async()=>await i(this,o).signPsbt(t),"Error while signing transaction")}async broadcastTransaction(t){const r=typeof i(this,o).pushPsbt=="function"?i(this,o).pushPsbt.bind(i(this,o)):void 0;return await b.broadcastTransaction(t,i(this,a),r)}on(t,r){i(this,o).on(t,r)}off(t,r){i(this,o).off(t,r)}}o=new WeakMap,a=new WeakMap;exports.EnkryptProvider=x;
|
package/dist/index14.js
CHANGED
|
@@ -1,10 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
id: "Xverse",
|
|
4
|
-
name: "Xverse Wallet",
|
|
5
|
-
icon: "https://garden.imgix.net/wallets/xverse.svg"
|
|
6
|
-
}
|
|
1
|
+
var P = (i) => {
|
|
2
|
+
throw TypeError(i);
|
|
7
3
|
};
|
|
4
|
+
var F = (i, t, e) => t.has(i) || P("Cannot " + e);
|
|
5
|
+
var n = (i, t, e) => (F(i, t, "read from private field"), e ? e.call(i) : t.get(i)), m = (i, t, e) => t.has(i) ? P("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, e), g = (i, t, e, s) => (F(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e);
|
|
6
|
+
import * as T from "bitcoinjs-lib";
|
|
7
|
+
import * as I from "tiny-secp256k1";
|
|
8
|
+
import { Ok as w, Network as p, Err as r, executeWithTryCatch as x } from "@gardenfi/utils";
|
|
9
|
+
import { WALLET_CONFIG as v } from "./index6.js";
|
|
10
|
+
import { getBalance as A, getUTXOs as O, getLitecoinNetwork as U, getRecommendedFeeRate as L, broadcastTransaction as S } from "./index21.js";
|
|
11
|
+
T.initEccLib(I);
|
|
12
|
+
var o, a;
|
|
13
|
+
class C {
|
|
14
|
+
constructor(t) {
|
|
15
|
+
m(this, o);
|
|
16
|
+
m(this, a);
|
|
17
|
+
this.address = "", this.id = v.Enkrypt.id, this.name = v.Enkrypt.name, this.icon = v.Enkrypt.icon, this.disconnect = () => (this.address = "", Promise.resolve(w("Disconnected Enkrypt wallet"))), g(this, o, t), g(this, a, p.MAINNET);
|
|
18
|
+
}
|
|
19
|
+
async connect(t) {
|
|
20
|
+
if (t || (t = p.MAINNET), t === p.TESTNET)
|
|
21
|
+
return r("Enkrypt wallet does not support testnet");
|
|
22
|
+
try {
|
|
23
|
+
const e = await n(this, o).requestAccounts();
|
|
24
|
+
return e.length > 0 && (this.address = e[0]), w({
|
|
25
|
+
address: this.address,
|
|
26
|
+
provider: this,
|
|
27
|
+
network: t,
|
|
28
|
+
id: v.Enkrypt.id
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return r("Error while connecting to Enkrypt wallet: " + e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async requestAccounts() {
|
|
35
|
+
return await x(async () => await n(this, o).requestAccounts(), "Error while requesting accounts from the Enkrypt wallet");
|
|
36
|
+
}
|
|
37
|
+
async getAccounts() {
|
|
38
|
+
return this.requestAccounts();
|
|
39
|
+
}
|
|
40
|
+
async getNetwork() {
|
|
41
|
+
return w(n(this, a));
|
|
42
|
+
}
|
|
43
|
+
async switchNetwork() {
|
|
44
|
+
g(this, a, n(this, a) === p.MAINNET ? p.TESTNET : p.MAINNET);
|
|
45
|
+
const t = await this.connect();
|
|
46
|
+
return t.error ? r(
|
|
47
|
+
`Failed to connect to ${n(this, a)}: ${t.error}`
|
|
48
|
+
) : w(n(this, a));
|
|
49
|
+
}
|
|
50
|
+
async getBalance() {
|
|
51
|
+
let t = await this.getAccounts();
|
|
52
|
+
if (!t.ok) return r("Failed to get address");
|
|
53
|
+
this.address = t.val[0];
|
|
54
|
+
const e = await this.getNetwork();
|
|
55
|
+
return e.ok ? (g(this, a, e.val), await A(this.address, n(this, a))) : r("Failed to get network");
|
|
56
|
+
}
|
|
57
|
+
async sendLitecoin(t, e) {
|
|
58
|
+
try {
|
|
59
|
+
const s = await this.getAccounts();
|
|
60
|
+
if (!s.ok) return r("Failed to get address");
|
|
61
|
+
this.address = s.val[0];
|
|
62
|
+
const b = await this.getNetwork();
|
|
63
|
+
if (!b.ok)
|
|
64
|
+
return r("Failed to get network");
|
|
65
|
+
if (g(this, a, b.val), !t || t.trim() === "")
|
|
66
|
+
return r("Invalid destination address");
|
|
67
|
+
if (e <= 0)
|
|
68
|
+
return r("Amount must be greater than 0");
|
|
69
|
+
const l = await this.getBalance();
|
|
70
|
+
if (!l.ok)
|
|
71
|
+
return r("Failed to get balance", l.error);
|
|
72
|
+
if (l.val.total < e)
|
|
73
|
+
return r("Insufficient balance");
|
|
74
|
+
const d = await O(this.address, n(this, a));
|
|
75
|
+
if (!d.ok)
|
|
76
|
+
return r("Failed to fetch UTXOs", d.error);
|
|
77
|
+
const k = d.val;
|
|
78
|
+
if (!k || k.length === 0)
|
|
79
|
+
return r("No UTXOs available");
|
|
80
|
+
const h = await this.buildTransaction(
|
|
81
|
+
k,
|
|
82
|
+
t,
|
|
83
|
+
e,
|
|
84
|
+
this.address
|
|
85
|
+
);
|
|
86
|
+
if (!h.ok)
|
|
87
|
+
return r("Failed to build transaction", h.error);
|
|
88
|
+
const f = await this.signPsbt(h.val);
|
|
89
|
+
if (!f.ok)
|
|
90
|
+
return r("Failed to sign transaction", f.error);
|
|
91
|
+
const c = await this.broadcastTransaction(f.val);
|
|
92
|
+
return c.ok ? w(c.val) : r("Failed to broadcast transaction", c.error);
|
|
93
|
+
} catch (s) {
|
|
94
|
+
return s instanceof Error ? s.message.includes("User rejected") || s.message.includes("cancelled") || s.message.includes("denied") ? r("Transaction cancelled by user") : r("Error while sending Litecoin: " + s.message) : r("Error while sending Litecoin", String(s));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async buildTransaction(t, e, s, b) {
|
|
98
|
+
try {
|
|
99
|
+
const l = U(n(this, a)), d = new T.Psbt({ network: l }), k = t.sort((u, y) => y.value - u.value), h = await L(n(this, a));
|
|
100
|
+
if (!h.ok)
|
|
101
|
+
return r("Failed to fetch recommended fee rate", h.error);
|
|
102
|
+
const f = h.val;
|
|
103
|
+
let c = 0;
|
|
104
|
+
for (const u of k) {
|
|
105
|
+
if (c >= s + f * 250) break;
|
|
106
|
+
let y;
|
|
107
|
+
try {
|
|
108
|
+
y = {
|
|
109
|
+
script: T.address.toOutputScript(
|
|
110
|
+
b,
|
|
111
|
+
l
|
|
112
|
+
),
|
|
113
|
+
value: u.value
|
|
114
|
+
};
|
|
115
|
+
} catch {
|
|
116
|
+
if (u.scriptPubKey)
|
|
117
|
+
y = {
|
|
118
|
+
script: Buffer.from(u.scriptPubKey, "hex"),
|
|
119
|
+
value: u.value
|
|
120
|
+
};
|
|
121
|
+
else
|
|
122
|
+
throw new Error("Cannot determine script for UTXO");
|
|
123
|
+
}
|
|
124
|
+
d.addInput({
|
|
125
|
+
hash: u.txid,
|
|
126
|
+
index: u.vout,
|
|
127
|
+
witnessUtxo: y
|
|
128
|
+
}), c += u.value;
|
|
129
|
+
}
|
|
130
|
+
if (c === 0)
|
|
131
|
+
return r("No valid UTXOs found");
|
|
132
|
+
const E = (d.txInputs.length * 148 + 2 * 34 + 10) * f;
|
|
133
|
+
if (c < s + E)
|
|
134
|
+
return r(
|
|
135
|
+
`Insufficient funds: need ${s + E} sats, have ${c} sats`
|
|
136
|
+
);
|
|
137
|
+
d.addOutput({
|
|
138
|
+
address: e,
|
|
139
|
+
value: s
|
|
140
|
+
});
|
|
141
|
+
const N = c - s - E;
|
|
142
|
+
return N > 546 && d.addOutput({
|
|
143
|
+
address: b,
|
|
144
|
+
value: N
|
|
145
|
+
}), w(d.toBase64());
|
|
146
|
+
} catch (l) {
|
|
147
|
+
return r("Error building transaction", String(l));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async signPsbt(t) {
|
|
151
|
+
return await x(async () => await n(this, o).signPsbt(t), "Error while signing transaction");
|
|
152
|
+
}
|
|
153
|
+
async broadcastTransaction(t) {
|
|
154
|
+
const e = typeof n(this, o).pushPsbt == "function" ? n(this, o).pushPsbt.bind(n(this, o)) : void 0;
|
|
155
|
+
return await S(
|
|
156
|
+
t,
|
|
157
|
+
n(this, a),
|
|
158
|
+
e
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
on(t, e) {
|
|
162
|
+
n(this, o).on(t, e);
|
|
163
|
+
}
|
|
164
|
+
off(t, e) {
|
|
165
|
+
n(this, o).off(t, e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
o = new WeakMap(), a = new WeakMap();
|
|
8
169
|
export {
|
|
9
|
-
|
|
170
|
+
C as EnkryptProvider
|
|
10
171
|
};
|
package/dist/index15.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.
|
|
1
|
+
"use strict";var L=s=>{throw TypeError(s)};var O=(s,t,e)=>t.has(s)||L("Cannot "+e);var n=(s,t,e)=>(O(s,t,"read from private field"),e?e.call(s):t.get(s)),y=(s,t,e)=>t.has(s)?L("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e),b=(s,t,e,i)=>(O(s,t,"write to private field"),i?i.call(s,e):t.set(s,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),k=require("./index22.cjs"),P=require("bitcoinjs-lib"),S=require("tiny-secp256k1"),N=require("./index6.cjs"),T=require("./index21.cjs");function x(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const v=x(P),I=x(S);v.initEccLib(I);var a,o;class U{constructor(t){y(this,a);y(this,o);this.address="",this.id=N.WALLET_CONFIG.LiteScribe.id,this.name=N.WALLET_CONFIG.LiteScribe.name,this.icon=N.WALLET_CONFIG.LiteScribe.icon,b(this,a,t),b(this,o,r.Network.TESTNET)}async connect(t){try{t||(t=n(this,o));let e=await this.getNetwork();if(!e.ok)return r.Err("Could not get network",e.error);if(e.val!==t){const d=await this.switchNetwork();if(!d.ok)return r.Err("Failed to switch network",d.error)}const i=await n(this,a).requestAccounts();return i.length>0&&(this.address=i[0]),r.Ok({address:this.address,provider:this,network:t,id:N.WALLET_CONFIG.LiteScribe.id})}catch(e){return r.Err("Error while connecting to the litescribe wallet",e)}}async getBalance(){let t=await this.getAccounts();if(!t.ok)return r.Err("Failed to get address");this.address=t.val[0];const e=await this.getNetwork();return e.ok?(b(this,o,e.val),await T.getBalance(this.address,n(this,o))):r.Err("Failed to get network")}async requestAccounts(){return await r.executeWithTryCatch(async()=>await n(this,a).requestAccounts(),"Error while requesting accounts from the litescribe wallet")}async getAccounts(){return await r.executeWithTryCatch(async()=>await n(this,a).getAccounts(),"Error while getting accounts from the litescribe wallet")}async sendLitecoin(t,e){try{const i=await this.getAccounts();if(!i.ok)return r.Err("Failed to get address");this.address=i.val[0];const d=await this.getNetwork();if(!d.ok)return r.Err("Failed to get network");if(b(this,o,d.val),!t||t.trim()==="")return r.Err("Invalid destination address");if(e<=0)return r.Err("Amount must be greater than 0");const h=await this.getBalance();if(!h.ok)return r.Err("Failed to get balance",h.error);if(h.val.total<e)return r.Err("Insufficient balance");const u=await this.getUTXOs();if(!u.ok)return r.Err("Failed to fetch UTXOs",u.error);const g=u.val;if(!g||g.length===0)return r.Err("No UTXOs available");const w=await this.buildTransaction(g,t,e,this.address);if(!w.ok)return r.Err("Failed to build transaction",w.error);console.log("psbtResult",w.val);const f=await this.signPsbt(w.val);if(!f.ok)return r.Err("Failed to sign transaction",f.error);const c=await this.broadcastTransaction(f.val);return c.ok?r.Ok(c.val):r.Err("Failed to broadcast transaction",c.error)}catch(i){return i instanceof Error?i.message.includes("User rejected")||i.message.includes("cancelled")||i.message.includes("denied")?r.Err("Transaction cancelled by user"):r.Err("Error while sending Litecoin: "+i.message):r.Err("Error while sending Litecoin",String(i))}}async getUTXOs(){return await r.executeWithTryCatch(async()=>{if(typeof n(this,a).getUtxos=="function")return await n(this,a).getUtxos();const t=n(this,o)===r.Network.MAINNET?`https://litecoinspace.org/api/address/${this.address}/utxo`:`https://litecoinspace.org/testnet/api/address/${this.address}/utxo`,e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch UTXOs: ${e.statusText}`);return await e.json()},"Error while fetching UTXOs")}async buildTransaction(t,e,i,d){try{const h=T.getLitecoinNetwork(n(this,o)),u=new v.Psbt({network:h}),g=t.sort((l,E)=>E.value-l.value),w=await T.getRecommendedFeeRate(n(this,o));if(!w.ok)return r.Err("Failed to fetch recommended fee rate",w.error);const f=w.val;let c=0;for(const l of g){if(c>=i+f*250)break;let E;try{E={script:v.address.toOutputScript(d,h),value:l.value}}catch{if(l.scriptPubKey)E={script:Buffer.from(l.scriptPubKey,"hex"),value:l.value};else throw new Error("Cannot determine script for UTXO")}u.addInput({hash:l.txid,index:l.vout,witnessUtxo:E}),c+=l.value}if(c===0)return r.Err("No valid UTXOs found");const p=(u.txInputs.length*148+2*34+10)*f;if(c<i+p)return r.Err(`Insufficient funds: need ${i+p} sats, have ${c} sats`);u.addOutput({address:e,value:i});const m=c-i-p;return m>546&&u.addOutput({address:d,value:m}),r.Ok(u.toBase64())}catch(h){return r.Err("Error building transaction",String(h))}}async signPsbt(t){return await r.executeWithTryCatch(async()=>await n(this,a).signPsbt(t),"Error while signing transaction")}async broadcastTransaction(t){const e=typeof n(this,a).pushPsbt=="function"?n(this,a).pushPsbt.bind(n(this,a)):void 0;return await T.broadcastTransaction(t,n(this,o),e)}async getNetwork(){return await r.executeWithTryCatch(async()=>{const t=await n(this,a).getNetwork();if(t===k.LitescribeNetworkEnum.LIVENET)return r.Network.MAINNET;if(t===k.LitescribeNetworkEnum.TESTNET)return r.Network.TESTNET;throw new Error("Invalid or unsupported network"+t)},"Error while getting network from Litescribe wallet")}async switchNetwork(){try{const t=await this.getNetwork();if(t.error)return r.Err("Failed to get current network");const e=t.val===r.Network.MAINNET?k.LitescribeNetworkEnum.TESTNET:k.LitescribeNetworkEnum.LIVENET;await n(this,a).switchNetwork(e);const i=await this.getNetwork();return i.ok?r.Ok(i.val):r.Err("Failed to verify network switch")}catch(t){return r.Err("Error while switching network in litescribe:",t)}}async disconnect(){return this.address="",Promise.resolve(r.Ok("Disconnected litescribe wallet"))}on(t,e){n(this,a).on(t,e)}off(t,e){n(this,a).off(t,e)}}a=new WeakMap,o=new WeakMap;exports.LitescribeProvider=U;
|
package/dist/index15.js
CHANGED
|
@@ -1,4 +1,208 @@
|
|
|
1
|
-
var
|
|
1
|
+
var L = (a) => {
|
|
2
|
+
throw TypeError(a);
|
|
3
|
+
};
|
|
4
|
+
var P = (a, t, e) => t.has(a) || L("Cannot " + e);
|
|
5
|
+
var i = (a, t, e) => (P(a, t, "read from private field"), e ? e.call(a) : t.get(a)), y = (a, t, e) => t.has(a) ? L("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(a) : t.set(a, e), k = (a, t, e, s) => (P(a, t, "write to private field"), s ? s.call(a, e) : t.set(a, e), e);
|
|
6
|
+
import { Network as p, Err as r, Ok as v, executeWithTryCatch as T } from "@gardenfi/utils";
|
|
7
|
+
import { LitescribeNetworkEnum as E } from "./index22.js";
|
|
8
|
+
import * as x from "bitcoinjs-lib";
|
|
9
|
+
import * as I from "tiny-secp256k1";
|
|
10
|
+
import { WALLET_CONFIG as N } from "./index6.js";
|
|
11
|
+
import { getBalance as O, getLitecoinNetwork as R, getRecommendedFeeRate as S, broadcastTransaction as A } from "./index21.js";
|
|
12
|
+
x.initEccLib(I);
|
|
13
|
+
var n, o;
|
|
14
|
+
class j {
|
|
15
|
+
constructor(t) {
|
|
16
|
+
y(this, n);
|
|
17
|
+
y(this, o);
|
|
18
|
+
this.address = "", this.id = N.LiteScribe.id, this.name = N.LiteScribe.name, this.icon = N.LiteScribe.icon, k(this, n, t), k(this, o, p.TESTNET);
|
|
19
|
+
}
|
|
20
|
+
async connect(t) {
|
|
21
|
+
try {
|
|
22
|
+
t || (t = i(this, o));
|
|
23
|
+
let e = await this.getNetwork();
|
|
24
|
+
if (!e.ok)
|
|
25
|
+
return r("Could not get network", e.error);
|
|
26
|
+
if (e.val !== t) {
|
|
27
|
+
const l = await this.switchNetwork();
|
|
28
|
+
if (!l.ok)
|
|
29
|
+
return r("Failed to switch network", l.error);
|
|
30
|
+
}
|
|
31
|
+
const s = await i(this, n).requestAccounts();
|
|
32
|
+
return s.length > 0 && (this.address = s[0]), v({
|
|
33
|
+
address: this.address,
|
|
34
|
+
provider: this,
|
|
35
|
+
network: t,
|
|
36
|
+
id: N.LiteScribe.id
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return r("Error while connecting to the litescribe wallet", e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async getBalance() {
|
|
43
|
+
let t = await this.getAccounts();
|
|
44
|
+
if (!t.ok) return r("Failed to get address");
|
|
45
|
+
this.address = t.val[0];
|
|
46
|
+
const e = await this.getNetwork();
|
|
47
|
+
return e.ok ? (k(this, o, e.val), await O(this.address, i(this, o))) : r("Failed to get network");
|
|
48
|
+
}
|
|
49
|
+
async requestAccounts() {
|
|
50
|
+
return await T(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the litescribe wallet");
|
|
51
|
+
}
|
|
52
|
+
async getAccounts() {
|
|
53
|
+
return await T(async () => await i(this, n).getAccounts(), "Error while getting accounts from the litescribe wallet");
|
|
54
|
+
}
|
|
55
|
+
async sendLitecoin(t, e) {
|
|
56
|
+
try {
|
|
57
|
+
const s = await this.getAccounts();
|
|
58
|
+
if (!s.ok) return r("Failed to get address");
|
|
59
|
+
this.address = s.val[0];
|
|
60
|
+
const l = await this.getNetwork();
|
|
61
|
+
if (!l.ok)
|
|
62
|
+
return r("Failed to get network");
|
|
63
|
+
if (k(this, o, l.val), !t || t.trim() === "")
|
|
64
|
+
return r("Invalid destination address");
|
|
65
|
+
if (e <= 0)
|
|
66
|
+
return r("Amount must be greater than 0");
|
|
67
|
+
const h = await this.getBalance();
|
|
68
|
+
if (!h.ok)
|
|
69
|
+
return r("Failed to get balance", h.error);
|
|
70
|
+
if (h.val.total < e)
|
|
71
|
+
return r("Insufficient balance");
|
|
72
|
+
const u = await this.getUTXOs();
|
|
73
|
+
if (!u.ok)
|
|
74
|
+
return r("Failed to fetch UTXOs", u.error);
|
|
75
|
+
const g = u.val;
|
|
76
|
+
if (!g || g.length === 0)
|
|
77
|
+
return r("No UTXOs available");
|
|
78
|
+
const w = await this.buildTransaction(
|
|
79
|
+
g,
|
|
80
|
+
t,
|
|
81
|
+
e,
|
|
82
|
+
this.address
|
|
83
|
+
);
|
|
84
|
+
if (!w.ok)
|
|
85
|
+
return r("Failed to build transaction", w.error);
|
|
86
|
+
console.log("psbtResult", w.val);
|
|
87
|
+
const f = await this.signPsbt(w.val);
|
|
88
|
+
if (!f.ok)
|
|
89
|
+
return r("Failed to sign transaction", f.error);
|
|
90
|
+
const c = await this.broadcastTransaction(f.val);
|
|
91
|
+
return c.ok ? v(c.val) : r("Failed to broadcast transaction", c.error);
|
|
92
|
+
} catch (s) {
|
|
93
|
+
return s instanceof Error ? s.message.includes("User rejected") || s.message.includes("cancelled") || s.message.includes("denied") ? r("Transaction cancelled by user") : r("Error while sending Litecoin: " + s.message) : r("Error while sending Litecoin", String(s));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async getUTXOs() {
|
|
97
|
+
return await T(async () => {
|
|
98
|
+
if (typeof i(this, n).getUtxos == "function")
|
|
99
|
+
return await i(this, n).getUtxos();
|
|
100
|
+
const t = i(this, o) === p.MAINNET ? `https://litecoinspace.org/api/address/${this.address}/utxo` : `https://litecoinspace.org/testnet/api/address/${this.address}/utxo`, e = await fetch(t);
|
|
101
|
+
if (!e.ok)
|
|
102
|
+
throw new Error(`Failed to fetch UTXOs: ${e.statusText}`);
|
|
103
|
+
return await e.json();
|
|
104
|
+
}, "Error while fetching UTXOs");
|
|
105
|
+
}
|
|
106
|
+
async buildTransaction(t, e, s, l) {
|
|
107
|
+
try {
|
|
108
|
+
const h = R(i(this, o)), u = new x.Psbt({ network: h }), g = t.sort((d, b) => b.value - d.value), w = await S(i(this, o));
|
|
109
|
+
if (!w.ok)
|
|
110
|
+
return r("Failed to fetch recommended fee rate", w.error);
|
|
111
|
+
const f = w.val;
|
|
112
|
+
let c = 0;
|
|
113
|
+
for (const d of g) {
|
|
114
|
+
if (c >= s + f * 250) break;
|
|
115
|
+
let b;
|
|
116
|
+
try {
|
|
117
|
+
b = {
|
|
118
|
+
script: x.address.toOutputScript(
|
|
119
|
+
l,
|
|
120
|
+
h
|
|
121
|
+
),
|
|
122
|
+
value: d.value
|
|
123
|
+
};
|
|
124
|
+
} catch {
|
|
125
|
+
if (d.scriptPubKey)
|
|
126
|
+
b = {
|
|
127
|
+
script: Buffer.from(d.scriptPubKey, "hex"),
|
|
128
|
+
value: d.value
|
|
129
|
+
};
|
|
130
|
+
else
|
|
131
|
+
throw new Error("Cannot determine script for UTXO");
|
|
132
|
+
}
|
|
133
|
+
u.addInput({
|
|
134
|
+
hash: d.txid,
|
|
135
|
+
index: d.vout,
|
|
136
|
+
witnessUtxo: b
|
|
137
|
+
}), c += d.value;
|
|
138
|
+
}
|
|
139
|
+
if (c === 0)
|
|
140
|
+
return r("No valid UTXOs found");
|
|
141
|
+
const m = (u.txInputs.length * 148 + 2 * 34 + 10) * f;
|
|
142
|
+
if (c < s + m)
|
|
143
|
+
return r(
|
|
144
|
+
`Insufficient funds: need ${s + m} sats, have ${c} sats`
|
|
145
|
+
);
|
|
146
|
+
u.addOutput({
|
|
147
|
+
address: e,
|
|
148
|
+
value: s
|
|
149
|
+
});
|
|
150
|
+
const F = c - s - m;
|
|
151
|
+
return F > 546 && u.addOutput({
|
|
152
|
+
address: l,
|
|
153
|
+
value: F
|
|
154
|
+
}), v(u.toBase64());
|
|
155
|
+
} catch (h) {
|
|
156
|
+
return r("Error building transaction", String(h));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async signPsbt(t) {
|
|
160
|
+
return await T(async () => await i(this, n).signPsbt(t), "Error while signing transaction");
|
|
161
|
+
}
|
|
162
|
+
async broadcastTransaction(t) {
|
|
163
|
+
const e = typeof i(this, n).pushPsbt == "function" ? i(this, n).pushPsbt.bind(
|
|
164
|
+
i(this, n)
|
|
165
|
+
) : void 0;
|
|
166
|
+
return await A(
|
|
167
|
+
t,
|
|
168
|
+
i(this, o),
|
|
169
|
+
e
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
async getNetwork() {
|
|
173
|
+
return await T(async () => {
|
|
174
|
+
const t = await i(this, n).getNetwork();
|
|
175
|
+
if (t === E.LIVENET)
|
|
176
|
+
return p.MAINNET;
|
|
177
|
+
if (t === E.TESTNET)
|
|
178
|
+
return p.TESTNET;
|
|
179
|
+
throw new Error("Invalid or unsupported network" + t);
|
|
180
|
+
}, "Error while getting network from Litescribe wallet");
|
|
181
|
+
}
|
|
182
|
+
async switchNetwork() {
|
|
183
|
+
try {
|
|
184
|
+
const t = await this.getNetwork();
|
|
185
|
+
if (t.error)
|
|
186
|
+
return r("Failed to get current network");
|
|
187
|
+
const e = t.val === p.MAINNET ? E.TESTNET : E.LIVENET;
|
|
188
|
+
await i(this, n).switchNetwork(e);
|
|
189
|
+
const s = await this.getNetwork();
|
|
190
|
+
return s.ok ? v(s.val) : r("Failed to verify network switch");
|
|
191
|
+
} catch (t) {
|
|
192
|
+
return r("Error while switching network in litescribe:", t);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async disconnect() {
|
|
196
|
+
return this.address = "", Promise.resolve(v("Disconnected litescribe wallet"));
|
|
197
|
+
}
|
|
198
|
+
on(t, e) {
|
|
199
|
+
i(this, n).on(t, e);
|
|
200
|
+
}
|
|
201
|
+
off(t, e) {
|
|
202
|
+
i(this, n).off(t, e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
n = new WeakMap(), o = new WeakMap();
|
|
2
206
|
export {
|
|
3
|
-
|
|
207
|
+
j as LitescribeProvider
|
|
4
208
|
};
|
package/dist/index16.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={Xverse:{id:"Xverse",name:"Xverse Wallet",icon:"https://garden.imgix.net/wallets/xverse.svg"}};exports.WALLET_CONFIG=e;
|
package/dist/index16.js
CHANGED
|
@@ -1,171 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import * as T from "bitcoinjs-lib";
|
|
7
|
-
import * as I from "tiny-secp256k1";
|
|
8
|
-
import { Ok as w, Network as p, Err as r, executeWithTryCatch as x } from "@gardenfi/utils";
|
|
9
|
-
import { WALLET_CONFIG as v } from "./index6.js";
|
|
10
|
-
import { getBalance as A, getUTXOs as O, getLitecoinNetwork as U, getRecommendedFeeRate as L, broadcastTransaction as S } from "./index21.js";
|
|
11
|
-
T.initEccLib(I);
|
|
12
|
-
var o, a;
|
|
13
|
-
class C {
|
|
14
|
-
constructor(t) {
|
|
15
|
-
m(this, o);
|
|
16
|
-
m(this, a);
|
|
17
|
-
this.address = "", this.id = v.Enkrypt.id, this.name = v.Enkrypt.name, this.icon = v.Enkrypt.icon, this.disconnect = () => (this.address = "", Promise.resolve(w("Disconnected Enkrypt wallet"))), g(this, o, t), g(this, a, p.MAINNET);
|
|
18
|
-
}
|
|
19
|
-
async connect(t) {
|
|
20
|
-
if (t || (t = p.MAINNET), t === p.TESTNET)
|
|
21
|
-
return r("Enkrypt wallet does not support testnet");
|
|
22
|
-
try {
|
|
23
|
-
const e = await n(this, o).requestAccounts();
|
|
24
|
-
return e.length > 0 && (this.address = e[0]), w({
|
|
25
|
-
address: this.address,
|
|
26
|
-
provider: this,
|
|
27
|
-
network: t,
|
|
28
|
-
id: v.Enkrypt.id
|
|
29
|
-
});
|
|
30
|
-
} catch (e) {
|
|
31
|
-
return r("Error while connecting to Enkrypt wallet: " + e);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async requestAccounts() {
|
|
35
|
-
return await x(async () => await n(this, o).requestAccounts(), "Error while requesting accounts from the Enkrypt wallet");
|
|
36
|
-
}
|
|
37
|
-
async getAccounts() {
|
|
38
|
-
return this.requestAccounts();
|
|
39
|
-
}
|
|
40
|
-
async getNetwork() {
|
|
41
|
-
return w(n(this, a));
|
|
42
|
-
}
|
|
43
|
-
async switchNetwork() {
|
|
44
|
-
g(this, a, n(this, a) === p.MAINNET ? p.TESTNET : p.MAINNET);
|
|
45
|
-
const t = await this.connect();
|
|
46
|
-
return t.error ? r(
|
|
47
|
-
`Failed to connect to ${n(this, a)}: ${t.error}`
|
|
48
|
-
) : w(n(this, a));
|
|
49
|
-
}
|
|
50
|
-
async getBalance() {
|
|
51
|
-
let t = await this.getAccounts();
|
|
52
|
-
if (!t.ok) return r("Failed to get address");
|
|
53
|
-
this.address = t.val[0];
|
|
54
|
-
const e = await this.getNetwork();
|
|
55
|
-
return e.ok ? (g(this, a, e.val), await A(this.address, n(this, a))) : r("Failed to get network");
|
|
1
|
+
const e = {
|
|
2
|
+
Xverse: {
|
|
3
|
+
id: "Xverse",
|
|
4
|
+
name: "Xverse Wallet",
|
|
5
|
+
icon: "https://garden.imgix.net/wallets/xverse.svg"
|
|
56
6
|
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const s = await this.getAccounts();
|
|
60
|
-
if (!s.ok) return r("Failed to get address");
|
|
61
|
-
this.address = s.val[0];
|
|
62
|
-
const b = await this.getNetwork();
|
|
63
|
-
if (!b.ok)
|
|
64
|
-
return r("Failed to get network");
|
|
65
|
-
if (g(this, a, b.val), !t || t.trim() === "")
|
|
66
|
-
return r("Invalid destination address");
|
|
67
|
-
if (e <= 0)
|
|
68
|
-
return r("Amount must be greater than 0");
|
|
69
|
-
const l = await this.getBalance();
|
|
70
|
-
if (!l.ok)
|
|
71
|
-
return r("Failed to get balance", l.error);
|
|
72
|
-
if (l.val.total < e)
|
|
73
|
-
return r("Insufficient balance");
|
|
74
|
-
const d = await O(this.address, n(this, a));
|
|
75
|
-
if (!d.ok)
|
|
76
|
-
return r("Failed to fetch UTXOs", d.error);
|
|
77
|
-
const k = d.val;
|
|
78
|
-
if (!k || k.length === 0)
|
|
79
|
-
return r("No UTXOs available");
|
|
80
|
-
const h = await this.buildTransaction(
|
|
81
|
-
k,
|
|
82
|
-
t,
|
|
83
|
-
e,
|
|
84
|
-
this.address
|
|
85
|
-
);
|
|
86
|
-
if (!h.ok)
|
|
87
|
-
return r("Failed to build transaction", h.error);
|
|
88
|
-
const f = await this.signPsbt(h.val);
|
|
89
|
-
if (!f.ok)
|
|
90
|
-
return r("Failed to sign transaction", f.error);
|
|
91
|
-
const c = await this.broadcastTransaction(f.val);
|
|
92
|
-
return c.ok ? w(c.val) : r("Failed to broadcast transaction", c.error);
|
|
93
|
-
} catch (s) {
|
|
94
|
-
return s instanceof Error ? s.message.includes("User rejected") || s.message.includes("cancelled") || s.message.includes("denied") ? r("Transaction cancelled by user") : r("Error while sending Litecoin: " + s.message) : r("Error while sending Litecoin", String(s));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async buildTransaction(t, e, s, b) {
|
|
98
|
-
try {
|
|
99
|
-
const l = U(n(this, a)), d = new T.Psbt({ network: l }), k = t.sort((u, y) => y.value - u.value), h = await L(n(this, a));
|
|
100
|
-
if (!h.ok)
|
|
101
|
-
return r("Failed to fetch recommended fee rate", h.error);
|
|
102
|
-
const f = h.val;
|
|
103
|
-
let c = 0;
|
|
104
|
-
for (const u of k) {
|
|
105
|
-
if (c >= s + f * 250) break;
|
|
106
|
-
let y;
|
|
107
|
-
try {
|
|
108
|
-
y = {
|
|
109
|
-
script: T.address.toOutputScript(
|
|
110
|
-
b,
|
|
111
|
-
l
|
|
112
|
-
),
|
|
113
|
-
value: u.value
|
|
114
|
-
};
|
|
115
|
-
} catch {
|
|
116
|
-
if (u.scriptPubKey)
|
|
117
|
-
y = {
|
|
118
|
-
script: Buffer.from(u.scriptPubKey, "hex"),
|
|
119
|
-
value: u.value
|
|
120
|
-
};
|
|
121
|
-
else
|
|
122
|
-
throw new Error("Cannot determine script for UTXO");
|
|
123
|
-
}
|
|
124
|
-
d.addInput({
|
|
125
|
-
hash: u.txid,
|
|
126
|
-
index: u.vout,
|
|
127
|
-
witnessUtxo: y
|
|
128
|
-
}), c += u.value;
|
|
129
|
-
}
|
|
130
|
-
if (c === 0)
|
|
131
|
-
return r("No valid UTXOs found");
|
|
132
|
-
const E = (d.txInputs.length * 148 + 2 * 34 + 10) * f;
|
|
133
|
-
if (c < s + E)
|
|
134
|
-
return r(
|
|
135
|
-
`Insufficient funds: need ${s + E} sats, have ${c} sats`
|
|
136
|
-
);
|
|
137
|
-
d.addOutput({
|
|
138
|
-
address: e,
|
|
139
|
-
value: s
|
|
140
|
-
});
|
|
141
|
-
const N = c - s - E;
|
|
142
|
-
return N > 546 && d.addOutput({
|
|
143
|
-
address: b,
|
|
144
|
-
value: N
|
|
145
|
-
}), w(d.toBase64());
|
|
146
|
-
} catch (l) {
|
|
147
|
-
return r("Error building transaction", String(l));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
async signPsbt(t) {
|
|
151
|
-
return await x(async () => await n(this, o).signPsbt(t), "Error while signing transaction");
|
|
152
|
-
}
|
|
153
|
-
async broadcastTransaction(t) {
|
|
154
|
-
const e = typeof n(this, o).pushPsbt == "function" ? n(this, o).pushPsbt.bind(n(this, o)) : void 0;
|
|
155
|
-
return await S(
|
|
156
|
-
t,
|
|
157
|
-
n(this, a),
|
|
158
|
-
e
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
on(t, e) {
|
|
162
|
-
n(this, o).on(t, e);
|
|
163
|
-
}
|
|
164
|
-
off(t, e) {
|
|
165
|
-
n(this, o).off(t, e);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
o = new WeakMap(), a = new WeakMap();
|
|
7
|
+
};
|
|
169
8
|
export {
|
|
170
|
-
|
|
9
|
+
e as WALLET_CONFIG
|
|
171
10
|
};
|
package/dist/index17.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
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/index17.js
CHANGED
|
@@ -1,208 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(a);
|
|
3
|
-
};
|
|
4
|
-
var P = (a, t, e) => t.has(a) || L("Cannot " + e);
|
|
5
|
-
var i = (a, t, e) => (P(a, t, "read from private field"), e ? e.call(a) : t.get(a)), y = (a, t, e) => t.has(a) ? L("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(a) : t.set(a, e), k = (a, t, e, s) => (P(a, t, "write to private field"), s ? s.call(a, e) : t.set(a, e), e);
|
|
6
|
-
import { Network as p, Err as r, Ok as v, executeWithTryCatch as T } from "@gardenfi/utils";
|
|
7
|
-
import { LitescribeNetworkEnum as E } from "./index22.js";
|
|
8
|
-
import * as x from "bitcoinjs-lib";
|
|
9
|
-
import * as I from "tiny-secp256k1";
|
|
10
|
-
import { WALLET_CONFIG as N } from "./index6.js";
|
|
11
|
-
import { getBalance as O, getLitecoinNetwork as R, getRecommendedFeeRate as S, broadcastTransaction as A } from "./index21.js";
|
|
12
|
-
x.initEccLib(I);
|
|
13
|
-
var n, o;
|
|
14
|
-
class j {
|
|
15
|
-
constructor(t) {
|
|
16
|
-
y(this, n);
|
|
17
|
-
y(this, o);
|
|
18
|
-
this.address = "", this.id = N.LiteScribe.id, this.name = N.LiteScribe.name, this.icon = N.LiteScribe.icon, k(this, n, t), k(this, o, p.TESTNET);
|
|
19
|
-
}
|
|
20
|
-
async connect(t) {
|
|
21
|
-
try {
|
|
22
|
-
t || (t = i(this, o));
|
|
23
|
-
let e = await this.getNetwork();
|
|
24
|
-
if (!e.ok)
|
|
25
|
-
return r("Could not get network", e.error);
|
|
26
|
-
if (e.val !== t) {
|
|
27
|
-
const l = await this.switchNetwork();
|
|
28
|
-
if (!l.ok)
|
|
29
|
-
return r("Failed to switch network", l.error);
|
|
30
|
-
}
|
|
31
|
-
const s = await i(this, n).requestAccounts();
|
|
32
|
-
return s.length > 0 && (this.address = s[0]), v({
|
|
33
|
-
address: this.address,
|
|
34
|
-
provider: this,
|
|
35
|
-
network: t,
|
|
36
|
-
id: N.LiteScribe.id
|
|
37
|
-
});
|
|
38
|
-
} catch (e) {
|
|
39
|
-
return r("Error while connecting to the litescribe wallet", e);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async getBalance() {
|
|
43
|
-
let t = await this.getAccounts();
|
|
44
|
-
if (!t.ok) return r("Failed to get address");
|
|
45
|
-
this.address = t.val[0];
|
|
46
|
-
const e = await this.getNetwork();
|
|
47
|
-
return e.ok ? (k(this, o, e.val), await O(this.address, i(this, o))) : r("Failed to get network");
|
|
48
|
-
}
|
|
49
|
-
async requestAccounts() {
|
|
50
|
-
return await T(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the litescribe wallet");
|
|
51
|
-
}
|
|
52
|
-
async getAccounts() {
|
|
53
|
-
return await T(async () => await i(this, n).getAccounts(), "Error while getting accounts from the litescribe wallet");
|
|
54
|
-
}
|
|
55
|
-
async sendLitecoin(t, e) {
|
|
56
|
-
try {
|
|
57
|
-
const s = await this.getAccounts();
|
|
58
|
-
if (!s.ok) return r("Failed to get address");
|
|
59
|
-
this.address = s.val[0];
|
|
60
|
-
const l = await this.getNetwork();
|
|
61
|
-
if (!l.ok)
|
|
62
|
-
return r("Failed to get network");
|
|
63
|
-
if (k(this, o, l.val), !t || t.trim() === "")
|
|
64
|
-
return r("Invalid destination address");
|
|
65
|
-
if (e <= 0)
|
|
66
|
-
return r("Amount must be greater than 0");
|
|
67
|
-
const h = await this.getBalance();
|
|
68
|
-
if (!h.ok)
|
|
69
|
-
return r("Failed to get balance", h.error);
|
|
70
|
-
if (h.val.total < e)
|
|
71
|
-
return r("Insufficient balance");
|
|
72
|
-
const u = await this.getUTXOs();
|
|
73
|
-
if (!u.ok)
|
|
74
|
-
return r("Failed to fetch UTXOs", u.error);
|
|
75
|
-
const g = u.val;
|
|
76
|
-
if (!g || g.length === 0)
|
|
77
|
-
return r("No UTXOs available");
|
|
78
|
-
const w = await this.buildTransaction(
|
|
79
|
-
g,
|
|
80
|
-
t,
|
|
81
|
-
e,
|
|
82
|
-
this.address
|
|
83
|
-
);
|
|
84
|
-
if (!w.ok)
|
|
85
|
-
return r("Failed to build transaction", w.error);
|
|
86
|
-
console.log("psbtResult", w.val);
|
|
87
|
-
const f = await this.signPsbt(w.val);
|
|
88
|
-
if (!f.ok)
|
|
89
|
-
return r("Failed to sign transaction", f.error);
|
|
90
|
-
const c = await this.broadcastTransaction(f.val);
|
|
91
|
-
return c.ok ? v(c.val) : r("Failed to broadcast transaction", c.error);
|
|
92
|
-
} catch (s) {
|
|
93
|
-
return s instanceof Error ? s.message.includes("User rejected") || s.message.includes("cancelled") || s.message.includes("denied") ? r("Transaction cancelled by user") : r("Error while sending Litecoin: " + s.message) : r("Error while sending Litecoin", String(s));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async getUTXOs() {
|
|
97
|
-
return await T(async () => {
|
|
98
|
-
if (typeof i(this, n).getUtxos == "function")
|
|
99
|
-
return await i(this, n).getUtxos();
|
|
100
|
-
const t = i(this, o) === p.MAINNET ? `https://litecoinspace.org/api/address/${this.address}/utxo` : `https://litecoinspace.org/testnet/api/address/${this.address}/utxo`, e = await fetch(t);
|
|
101
|
-
if (!e.ok)
|
|
102
|
-
throw new Error(`Failed to fetch UTXOs: ${e.statusText}`);
|
|
103
|
-
return await e.json();
|
|
104
|
-
}, "Error while fetching UTXOs");
|
|
105
|
-
}
|
|
106
|
-
async buildTransaction(t, e, s, l) {
|
|
107
|
-
try {
|
|
108
|
-
const h = R(i(this, o)), u = new x.Psbt({ network: h }), g = t.sort((d, b) => b.value - d.value), w = await S(i(this, o));
|
|
109
|
-
if (!w.ok)
|
|
110
|
-
return r("Failed to fetch recommended fee rate", w.error);
|
|
111
|
-
const f = w.val;
|
|
112
|
-
let c = 0;
|
|
113
|
-
for (const d of g) {
|
|
114
|
-
if (c >= s + f * 250) break;
|
|
115
|
-
let b;
|
|
116
|
-
try {
|
|
117
|
-
b = {
|
|
118
|
-
script: x.address.toOutputScript(
|
|
119
|
-
l,
|
|
120
|
-
h
|
|
121
|
-
),
|
|
122
|
-
value: d.value
|
|
123
|
-
};
|
|
124
|
-
} catch {
|
|
125
|
-
if (d.scriptPubKey)
|
|
126
|
-
b = {
|
|
127
|
-
script: Buffer.from(d.scriptPubKey, "hex"),
|
|
128
|
-
value: d.value
|
|
129
|
-
};
|
|
130
|
-
else
|
|
131
|
-
throw new Error("Cannot determine script for UTXO");
|
|
132
|
-
}
|
|
133
|
-
u.addInput({
|
|
134
|
-
hash: d.txid,
|
|
135
|
-
index: d.vout,
|
|
136
|
-
witnessUtxo: b
|
|
137
|
-
}), c += d.value;
|
|
138
|
-
}
|
|
139
|
-
if (c === 0)
|
|
140
|
-
return r("No valid UTXOs found");
|
|
141
|
-
const m = (u.txInputs.length * 148 + 2 * 34 + 10) * f;
|
|
142
|
-
if (c < s + m)
|
|
143
|
-
return r(
|
|
144
|
-
`Insufficient funds: need ${s + m} sats, have ${c} sats`
|
|
145
|
-
);
|
|
146
|
-
u.addOutput({
|
|
147
|
-
address: e,
|
|
148
|
-
value: s
|
|
149
|
-
});
|
|
150
|
-
const F = c - s - m;
|
|
151
|
-
return F > 546 && u.addOutput({
|
|
152
|
-
address: l,
|
|
153
|
-
value: F
|
|
154
|
-
}), v(u.toBase64());
|
|
155
|
-
} catch (h) {
|
|
156
|
-
return r("Error building transaction", String(h));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async signPsbt(t) {
|
|
160
|
-
return await T(async () => await i(this, n).signPsbt(t), "Error while signing transaction");
|
|
161
|
-
}
|
|
162
|
-
async broadcastTransaction(t) {
|
|
163
|
-
const e = typeof i(this, n).pushPsbt == "function" ? i(this, n).pushPsbt.bind(
|
|
164
|
-
i(this, n)
|
|
165
|
-
) : void 0;
|
|
166
|
-
return await A(
|
|
167
|
-
t,
|
|
168
|
-
i(this, o),
|
|
169
|
-
e
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
async getNetwork() {
|
|
173
|
-
return await T(async () => {
|
|
174
|
-
const t = await i(this, n).getNetwork();
|
|
175
|
-
if (t === E.LIVENET)
|
|
176
|
-
return p.MAINNET;
|
|
177
|
-
if (t === E.TESTNET)
|
|
178
|
-
return p.TESTNET;
|
|
179
|
-
throw new Error("Invalid or unsupported network" + t);
|
|
180
|
-
}, "Error while getting network from Litescribe wallet");
|
|
181
|
-
}
|
|
182
|
-
async switchNetwork() {
|
|
183
|
-
try {
|
|
184
|
-
const t = await this.getNetwork();
|
|
185
|
-
if (t.error)
|
|
186
|
-
return r("Failed to get current network");
|
|
187
|
-
const e = t.val === p.MAINNET ? E.TESTNET : E.LIVENET;
|
|
188
|
-
await i(this, n).switchNetwork(e);
|
|
189
|
-
const s = await this.getNetwork();
|
|
190
|
-
return s.ok ? v(s.val) : r("Failed to verify network switch");
|
|
191
|
-
} catch (t) {
|
|
192
|
-
return r("Error while switching network in litescribe:", t);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async disconnect() {
|
|
196
|
-
return this.address = "", Promise.resolve(v("Disconnected litescribe wallet"));
|
|
197
|
-
}
|
|
198
|
-
on(t, e) {
|
|
199
|
-
i(this, n).on(t, e);
|
|
200
|
-
}
|
|
201
|
-
off(t, e) {
|
|
202
|
-
i(this, n).off(t, e);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
n = new WeakMap(), o = new WeakMap();
|
|
1
|
+
var n = /* @__PURE__ */ ((t) => (t.Mainnet = "mainnet", t.Regtest = "regtest", t))(n || {});
|
|
206
2
|
export {
|
|
207
|
-
|
|
3
|
+
n as XverseSparkNetworkType
|
|
208
4
|
};
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),L=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),L=require("./index14.cjs"),o=require("@gardenfi/utils"),A=require("./index15.cjs"),C=n.createContext(void 0),h=({children:s,network:l,store:d})=>{const[r,u]=n.useState(),[v,i]=n.useState(),[y,c]=n.useState(!1),[a,g]=n.useState({}),W=n.useMemo(()=>!!r&&!!v,[r,v]),b=async e=>{c(!0);const t=await e.connect(l);return t.ok?t.val.network!==l?(c(!1),o.Err("Network mismatch")):(u(t.val.provider),i(t.val.address),d.setItem("litecoinWallet",JSON.stringify(t.val)),c(!1),o.Ok(o.Void)):(c(!1),o.Err(t.error))},k=()=>r?(r.disconnect(),u(void 0),i(void 0),d.removeItem("litecoinWallet"),o.Ok(o.Void)):o.Err("No provider to disconnect"),P=n.useCallback(async()=>{if(!r)return;const e=await r.getAccounts();if(!e.ok){console.error("Error getting accounts:",e.error);return}i(e.val[0])},[r]),w=e=>{g(t=>({...t,[e.id]:e}))},m=async()=>{if(window.enkrypt&&window.enkrypt.providers&&window.enkrypt.providers.bitcoin){const e=new L.EnkryptProvider(window.enkrypt.providers.bitcoin);w(e)}if(window.litescribe){const e=new A.LitescribeProvider(window.litescribe);w(e)}},E=async()=>{const e=d.getItem("litecoinWallet");if(e){const t=JSON.parse(e),f=a[t.id];if(f){const p=await f.getAccounts();if(!p.ok||!p.val[0])return;u(f),i(p.val[0])}}};return n.useEffect(()=>{m()},[]),n.useEffect(()=>{a&&E()},[a]),n.useEffect(()=>{if(!r)return;const e=async t=>{t.length!==0&&i(t[0])};return r.on("accountsChanged",e),()=>{r.off("accountsChanged",e)}},[r]),n.createElement(C.Provider,{value:{availableWallets:a,connect:b,provider:r,account:v,network:l,isConnecting:y,updateAccount:P,disconnect:k,isConnected:W}},s)},S=()=>{const s=n.useContext(C);if(!s)throw new Error("useLitecoinWallet must be used within LTCWalletProvider");return s};exports.LTCWalletProvider=h;exports.useLitecoinWallet=S;
|
package/dist/index5.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import x, { useState as s, useMemo as I, useCallback as N, useEffect as p, createContext as T, useContext as O } from "react";
|
|
2
|
-
import { EnkryptProvider as S } from "./
|
|
2
|
+
import { EnkryptProvider as S } from "./index14.js";
|
|
3
3
|
import { Err as w, Ok as C, Void as y } from "@gardenfi/utils";
|
|
4
|
-
import { LitescribeProvider as J } from "./
|
|
4
|
+
import { LitescribeProvider as J } from "./index15.js";
|
|
5
5
|
const g = T(void 0), V = ({
|
|
6
6
|
children: r,
|
|
7
7
|
network: a,
|
package/dist/index8.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=n=>{throw TypeError(n)};var k=(n,r,e)=>r.has(n)||w("Cannot "+e);var l=(n,r,e)=>(k(n,r,"read from private field"),e?e.call(n):r.get(n)),d=(n,r,e)=>r.has(n)?w("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(n):r.set(n,e),h=(n,r,e,s)=>(k(n,r,"write to private field"),s?s.call(n,e):r.set(n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./
|
|
1
|
+
"use strict";var w=n=>{throw TypeError(n)};var k=(n,r,e)=>r.has(n)||w("Cannot "+e);var l=(n,r,e)=>(k(n,r,"read from private field"),e?e.call(n):r.get(n)),d=(n,r,e)=>r.has(n)?w("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(n):r.set(n,e),h=(n,r,e,s)=>(k(n,r,"write to private field"),s?s.call(n,e):r.set(n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index16.cjs"),o=require("./index17.cjs"),a=require("@gardenfi/utils"),c=require("sats-connect");var i;class p{constructor(r){d(this,i);this.address="",this.id=u.WALLET_CONFIG.Xverse.id,this.name=u.WALLET_CONFIG.Xverse.name,this.icon=u.WALLET_CONFIG.Xverse.icon,this.connect=async e=>{try{e||(e=a.Network.TESTNET);const s=e===a.Network.MAINNET?o.XverseSparkNetworkType.Mainnet:o.XverseSparkNetworkType.Regtest;await l(this,i).request("wallet_connect",{network:s});const t=await this.getAccounts();return t.ok&&t.val.length>0&&(this.address=t.val[0]),a.Ok({address:this.address,provider:this,network:e,id:u.WALLET_CONFIG.Xverse.id})}catch(s){return a.Err("Error while connecting to the XVerse Spark wallet",s)}},this.getBalance=async()=>await a.executeWithTryCatch(async()=>{const e=await c.request("spark_getBalance",null);if(e.status==="success"&&e.result){const s=e.result,t=parseInt(s.balance||"0",10);return{confirmed:t,unconfirmed:0,total:t}}throw new Error("Failed to get Spark balance")},"Error while getting balance from XVerse Spark wallet"),this.requestAccounts=async()=>await a.executeWithTryCatch(async()=>{const e=await c.request("spark_getAddresses",null);if(e.status==="success"&&e.result)return e.result.addresses.map(t=>t.address);throw new Error("Failed to get Spark addresses")},"Error while requesting accounts from XVerse Spark wallet"),this.getAccounts=async()=>await a.executeWithTryCatch(async()=>{const e=await c.request("spark_getAddresses",null);if(e.status==="success"&&e.result)return e.result.addresses.map(t=>t.address);throw new Error("Failed to get Spark addresses")},"Error while getting accounts from XVerse Spark wallet"),this.sendSpark=async(e,s)=>await a.executeWithTryCatch(async()=>{const t=await c.request("spark_transfer",{receiverSparkAddress:e,amountSats:s});if(t.status==="success"&&t.result)return t.result.id;throw new Error("Failed to send Spark transaction")},"Error while sending Spark from Xverse Spark wallet"),this.on=()=>{},this.off=()=>{},this.disconnect=()=>(this.address="",Promise.resolve(a.Ok("Disconnected"))),h(this,i,r)}async getNetwork(){return await a.executeWithTryCatch(async()=>{var e,s;const r=await c.request("wallet_getNetwork",null);if(r.status==="success"&&r.result){const t=r.result;if(((e=t==null?void 0:t.spark)==null?void 0:e.name)===o.XverseSparkNetworkType.Mainnet)return a.Network.MAINNET;if(((s=t==null?void 0:t.spark)==null?void 0:s.name)===o.XverseSparkNetworkType.Regtest)return a.Network.TESTNET}throw new Error("Could not determine Spark network")},"Error while getting network from Xverse Spark wallet")}async switchNetwork(){try{const r=await this.getNetwork();if(r.error)return a.Err("Failed to get current network");const e=r.val===a.Network.MAINNET?o.XverseSparkNetworkType.Regtest:o.XverseSparkNetworkType.Mainnet;try{await l(this,i).request("wallet_changeNetwork",{name:e})}catch{return a.Err("Network switching not supported. Please switch network manually in Xverse wallet.")}const s=await this.getNetwork();return s.ok?a.Ok(s.val):a.Err("Failed to verify network switch")}catch(r){return a.Err("Error while switching network in Xverse Spark:",r)}}}i=new WeakMap;exports.XverseSparkProvider=p;
|
package/dist/index8.js
CHANGED
|
@@ -3,8 +3,8 @@ var k = (a) => {
|
|
|
3
3
|
};
|
|
4
4
|
var p = (a, r, e) => r.has(a) || k("Cannot " + e);
|
|
5
5
|
var d = (a, r, e) => (p(a, r, "read from private field"), e ? e.call(a) : r.get(a)), g = (a, r, e) => r.has(a) ? k("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(a) : r.set(a, e), f = (a, r, e, s) => (p(a, r, "write to private field"), s ? s.call(a, e) : r.set(a, e), e);
|
|
6
|
-
import { WALLET_CONFIG as w } from "./
|
|
7
|
-
import { XverseSparkNetworkType as n } from "./
|
|
6
|
+
import { WALLET_CONFIG as w } from "./index16.js";
|
|
7
|
+
import { XverseSparkNetworkType as n } from "./index17.js";
|
|
8
8
|
import { Network as i, Ok as h, Err as c, executeWithTryCatch as l } from "@gardenfi/utils";
|
|
9
9
|
import { request as u } from "sats-connect";
|
|
10
10
|
var o;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/wallet-connectors",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@gardenfi/core": "3.1.
|
|
40
|
+
"@gardenfi/core": "3.1.2",
|
|
41
41
|
"@gardenfi/utils": "3.1.1",
|
|
42
42
|
"axios": "^1.7.9",
|
|
43
43
|
"bitcoinjs-lib": "^6.1.7",
|