@bestinslot/wallet-kit 0.14.2 → 0.15.0-rc.0
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/README.md +1 -0
- package/dist/{balances-BCIlZEmP.js → balances-C92Gmgw4.js} +2747 -2586
- package/dist/browser.js +55 -51
- package/dist/core.js +40 -34
- package/dist/{mint-CSk_3TfL.js → mint-FmqHYTrX.js} +3803 -3408
- package/dist/node.js +383 -355
- package/dist/react.js +4 -4
- package/dist/register-browser-providers-C-EltUwj.js +569 -0
- package/dist/types/api/helpers.d.ts +3 -0
- package/dist/types/api/swap.d.ts +9 -6
- package/dist/types/api/wallet.d.ts +2 -2
- package/dist/types/core/bis-providers.d.ts +49 -0
- package/dist/types/core/bis.d.ts +2 -0
- package/dist/types/core/bis_swap.d.ts +59 -10
- package/dist/types/core/brc20-send.d.ts +2 -1
- package/dist/types/core/chain-providers.d.ts +133 -0
- package/dist/types/core/helpers.d.ts +48 -31
- package/dist/types/core/mint.d.ts +82 -8
- package/dist/types/core/providers.d.ts +11 -3
- package/dist/types/core/sign-progress.d.ts +3 -1
- package/dist/types/core/store-network.d.ts +8 -0
- package/dist/types/core.d.ts +2 -0
- package/dist/types/lib/swap-route.d.ts +118 -0
- package/dist/types/provider/api.d.ts +20 -0
- package/dist/types/types/global.d.ts +2 -0
- package/dist/vue.js +3 -3
- package/package.json +1 -1
- package/dist/register-browser-providers-BdTwEVwB.js +0 -500
package/dist/react.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useSyncExternalStore as
|
|
2
|
-
import {
|
|
1
|
+
import { useSyncExternalStore as l, useCallback as r, useState as i } from "react";
|
|
2
|
+
import { Z as u, e, l as c, j as n } from "./mint-FmqHYTrX.js";
|
|
3
3
|
function m() {
|
|
4
|
-
const t = u
|
|
4
|
+
const t = l(u, e, e), s = r((o) => c(o), []);
|
|
5
5
|
return [t, s];
|
|
6
6
|
}
|
|
7
7
|
function S() {
|
|
8
|
-
const t = u
|
|
8
|
+
const t = l(u, e, e), [s, o] = i(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((w) => c(w), []);
|
|
9
9
|
return { session: s, network: t, setNetwork: k, refresh: a };
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { K as c, J as x, L as y, e as d, _ as T, N as u, h as m, $ as b, Y as k } from "./mint-FmqHYTrX.js";
|
|
2
|
+
async function K() {
|
|
3
|
+
if (!window.LeatherProvider) throw new Error("Leather extension not found.");
|
|
4
|
+
const n = await window.LeatherProvider.request("getAddresses");
|
|
5
|
+
if (!n) throw new Error("Failed to get wallets.");
|
|
6
|
+
return n.result.addresses.map((t) => ({
|
|
7
|
+
address: t.address,
|
|
8
|
+
pubkey: t.publicKey || null,
|
|
9
|
+
purpose: t.type === "p2wpkh" ? "payment" : t.type === "p2tr" ? "ordinals" : "stx"
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
async function O(n, e) {
|
|
13
|
+
if (!window.LeatherProvider) throw new Error("Leather extension not found.");
|
|
14
|
+
if (!e) throw new Error("Wallet type is required for signing messages with Leather.");
|
|
15
|
+
try {
|
|
16
|
+
const t = await window.LeatherProvider.request("signMessage", {
|
|
17
|
+
message: n,
|
|
18
|
+
paymentType: e === "ordinals" ? "p2tr" : "p2wpkh",
|
|
19
|
+
network: d()
|
|
20
|
+
});
|
|
21
|
+
return u.from(t.result.signature, "base64").toString("hex");
|
|
22
|
+
} catch (t) {
|
|
23
|
+
throw new Error(`Failed to sign message: ${t.message}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function U(n) {
|
|
27
|
+
if (!window.LeatherProvider) throw new Error("Leather extension not found.");
|
|
28
|
+
try {
|
|
29
|
+
const e = await window.LeatherProvider.request("signMessage", {
|
|
30
|
+
message: n,
|
|
31
|
+
paymentType: "p2wpkh",
|
|
32
|
+
network: d()
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
signature: u.from(e.result.signature, "base64").toString("hex"),
|
|
36
|
+
address: e.result.address
|
|
37
|
+
};
|
|
38
|
+
} catch (e) {
|
|
39
|
+
throw new Error(`Failed to sign message: ${e.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function N(n, e) {
|
|
43
|
+
if (!window.LeatherProvider) throw new Error("Leather extension not found.");
|
|
44
|
+
try {
|
|
45
|
+
return (await window.LeatherProvider.request("sendTransfer", {
|
|
46
|
+
recipients: [
|
|
47
|
+
{
|
|
48
|
+
address: e,
|
|
49
|
+
amount: n.toString()
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
network: d()
|
|
53
|
+
})).result.txid;
|
|
54
|
+
} catch (t) {
|
|
55
|
+
throw new Error(`Failed to send BTC: ${t.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function S(n, e, t) {
|
|
59
|
+
if (!window.LeatherProvider) throw new Error("Leather extension not found.");
|
|
60
|
+
const s = [];
|
|
61
|
+
for (let i = 0; i < t.length; i++)
|
|
62
|
+
for (let r = 0; r < t[i].signingIndexes.length; r++)
|
|
63
|
+
s.push(t[i].signingIndexes[r]);
|
|
64
|
+
return (await window.LeatherProvider.request("signPsbt", {
|
|
65
|
+
hex: T(n),
|
|
66
|
+
network: d(),
|
|
67
|
+
broadcast: e,
|
|
68
|
+
signAtIndex: s
|
|
69
|
+
})).result?.hex ?? "";
|
|
70
|
+
}
|
|
71
|
+
async function D(n, e, t, s, o, i) {
|
|
72
|
+
const r = c.Psbt.fromHex(n), a = [];
|
|
73
|
+
for (let h = 0; h < r.inputCount; h++)
|
|
74
|
+
i && i.includes(h) || s.includes(h) || a.push(h);
|
|
75
|
+
const w = await S(x(n), !1, [
|
|
76
|
+
{
|
|
77
|
+
address: e,
|
|
78
|
+
signingIndexes: a,
|
|
79
|
+
sigHash: c.Transaction.SIGHASH_DEFAULT
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
address: t,
|
|
83
|
+
signingIndexes: s,
|
|
84
|
+
sigHash: c.Transaction.SIGHASH_DEFAULT
|
|
85
|
+
}
|
|
86
|
+
]), f = c.Psbt.fromHex(w);
|
|
87
|
+
y(f, i);
|
|
88
|
+
const p = f.extractTransaction(), g = p.toHex();
|
|
89
|
+
return {
|
|
90
|
+
txId: p.getId(),
|
|
91
|
+
signedTxHex: g
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const W = {
|
|
95
|
+
getWallets: K,
|
|
96
|
+
signMessage: O,
|
|
97
|
+
signMessageDeterministic: U,
|
|
98
|
+
sendBTC: N,
|
|
99
|
+
signPSBT: S,
|
|
100
|
+
sign: D
|
|
101
|
+
};
|
|
102
|
+
async function _() {
|
|
103
|
+
if (!window.okxwallet) throw new Error("OKX extension not found.");
|
|
104
|
+
const n = d();
|
|
105
|
+
let e;
|
|
106
|
+
if (n === "mainnet") e = await window.okxwallet.bitcoin.connect();
|
|
107
|
+
else if (n === "testnet") e = await window.okxwallet.bitcoinTestnet.connect();
|
|
108
|
+
else if (n === "signet") e = await window.okxwallet.bitcoinSignet.connect();
|
|
109
|
+
else throw new Error("Unsupported network for OKX.");
|
|
110
|
+
if (!e) throw new Error("Error fetching wallet data.");
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
address: e.address,
|
|
114
|
+
pubkey: e.publicKey,
|
|
115
|
+
purpose: "all"
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
function v() {
|
|
120
|
+
const n = d();
|
|
121
|
+
if (n === "mainnet") return window.okxwallet?.bitcoin;
|
|
122
|
+
if (n === "testnet") return window.okxwallet?.bitcoinTestnet;
|
|
123
|
+
if (n === "signet") return window.okxwallet?.bitcoinSignet;
|
|
124
|
+
}
|
|
125
|
+
async function q() {
|
|
126
|
+
const n = v();
|
|
127
|
+
return typeof n?.getAccounts != "function" ? [] : await n.getAccounts() ?? [];
|
|
128
|
+
}
|
|
129
|
+
function z(n) {
|
|
130
|
+
const e = v();
|
|
131
|
+
if (typeof e?.on != "function") return () => {
|
|
132
|
+
};
|
|
133
|
+
const t = (s) => n(s?.address ? [s.address] : []);
|
|
134
|
+
return e.on("accountChanged", t), () => e.removeListener?.("accountChanged", t);
|
|
135
|
+
}
|
|
136
|
+
async function R(n) {
|
|
137
|
+
if (!window.okxwallet) throw new Error("OKX extension not found.");
|
|
138
|
+
const e = d();
|
|
139
|
+
let t;
|
|
140
|
+
if (e === "mainnet")
|
|
141
|
+
t = await window.okxwallet.bitcoin.signMessage(n, "bip322-simple");
|
|
142
|
+
else if (e === "testnet")
|
|
143
|
+
t = await window.okxwallet.bitcoinTestnet.signMessage(n, "bip322-simple");
|
|
144
|
+
else if (e === "signet")
|
|
145
|
+
t = await window.okxwallet.bitcoinSignet.signMessage(n, "bip322-simple");
|
|
146
|
+
else throw new Error("Unsupported network for OKX.");
|
|
147
|
+
return u.from(t, "base64").toString("hex");
|
|
148
|
+
}
|
|
149
|
+
async function G(n) {
|
|
150
|
+
if (!window.okxwallet) throw new Error("OKX extension not found.");
|
|
151
|
+
const e = m();
|
|
152
|
+
if (!e) throw new Error("No payment wallet found.");
|
|
153
|
+
const t = e.address, s = d();
|
|
154
|
+
let o;
|
|
155
|
+
if (s === "mainnet")
|
|
156
|
+
o = await window.okxwallet.bitcoin.signMessage(n, "ecdsa");
|
|
157
|
+
else if (s === "testnet")
|
|
158
|
+
o = await window.okxwallet.bitcoinTestnet.signMessage(n, "ecdsa");
|
|
159
|
+
else if (s === "signet")
|
|
160
|
+
o = await window.okxwallet.bitcoinSignet.signMessage(n, "ecdsa");
|
|
161
|
+
else throw new Error("Unsupported network for OKX.");
|
|
162
|
+
return {
|
|
163
|
+
signature: u.from(o, "base64").toString("hex"),
|
|
164
|
+
address: t
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async function j(n, e) {
|
|
168
|
+
if (!window.okxwallet) throw new Error("OKX extension not found.");
|
|
169
|
+
const t = d();
|
|
170
|
+
let s;
|
|
171
|
+
if (t === "mainnet")
|
|
172
|
+
s = await window.okxwallet.bitcoin.sendBitcoin(e, n);
|
|
173
|
+
else if (t === "testnet")
|
|
174
|
+
s = await window.okxwallet.bitcoinTestnet.sendBitcoin(e, n);
|
|
175
|
+
else if (t === "signet")
|
|
176
|
+
s = await window.okxwallet.bitcoinSignet.sendBitcoin(e, n);
|
|
177
|
+
else
|
|
178
|
+
throw new Error("Unsupported network for OKX.");
|
|
179
|
+
return s;
|
|
180
|
+
}
|
|
181
|
+
async function E(n, e, t) {
|
|
182
|
+
const s = T(n);
|
|
183
|
+
let o = null;
|
|
184
|
+
if (t.length !== 0) {
|
|
185
|
+
const i = [];
|
|
186
|
+
for (const r of t)
|
|
187
|
+
for (let a = 0; a < r.signingIndexes.length; a++)
|
|
188
|
+
i.push({
|
|
189
|
+
address: r.address,
|
|
190
|
+
index: r.signingIndexes[a]
|
|
191
|
+
// disableTweakSigner: i == 0 ? true : false // TODO: remove this hack!!
|
|
192
|
+
});
|
|
193
|
+
o = {
|
|
194
|
+
autoFinalized: !0,
|
|
195
|
+
toSignInputs: i
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (d() === "mainnet") {
|
|
199
|
+
let i = null;
|
|
200
|
+
return o ? i = await window.okxwallet.bitcoin.signPsbt(s, o) : i = await window.okxwallet.bitcoin.signPsbt(s), e && await window.okxwallet.bitcoin.pushPsbt(i), i;
|
|
201
|
+
} else if (d() === "testnet") {
|
|
202
|
+
if (e)
|
|
203
|
+
throw new Error("Cannot broadcast on testnet with okx");
|
|
204
|
+
let i = null;
|
|
205
|
+
return o ? i = await window.okxwallet.bitcoinTestnet.signPsbt(s, o) : i = await window.okxwallet.bitcoinTestnet.signPsbt(s), i;
|
|
206
|
+
} else if (d() === "signet") {
|
|
207
|
+
if (e)
|
|
208
|
+
throw new Error("Cannot broadcast on signet with okx");
|
|
209
|
+
let i = null;
|
|
210
|
+
return o ? i = await window.okxwallet.bitcoinSignet.signPsbt(s, o) : i = await window.okxwallet.bitcoinSignet.signPsbt(s), i;
|
|
211
|
+
} else
|
|
212
|
+
throw new Error("Unsupported network for OKX.");
|
|
213
|
+
}
|
|
214
|
+
function B(n) {
|
|
215
|
+
const { unsignedPsbtHex: e, paymentAddr: t, ordAddr: s, ordAddrIdxes: o, noSignIdxes: i } = n;
|
|
216
|
+
if (!t) return [];
|
|
217
|
+
const r = c.Psbt.fromHex(e), a = [];
|
|
218
|
+
for (let w = 0; w < r.inputCount; w++)
|
|
219
|
+
i && i.includes(w) || o.includes(w) || a.push(w);
|
|
220
|
+
return [
|
|
221
|
+
{ address: t, signingIndexes: a },
|
|
222
|
+
{ address: s, signingIndexes: o }
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
function I(n, e) {
|
|
226
|
+
const t = c.Psbt.fromHex(n);
|
|
227
|
+
y(t, e);
|
|
228
|
+
const s = t.extractTransaction();
|
|
229
|
+
return { txId: s.getId(), signedTxHex: s.toHex() };
|
|
230
|
+
}
|
|
231
|
+
async function J(n, e, t, s, o, i) {
|
|
232
|
+
const r = B({
|
|
233
|
+
unsignedPsbtHex: n,
|
|
234
|
+
paymentAddr: e,
|
|
235
|
+
ordAddr: t,
|
|
236
|
+
ordAddrIdxes: s,
|
|
237
|
+
noSignIdxes: i
|
|
238
|
+
}), a = await E(x(n), !1, r);
|
|
239
|
+
return I(a, i);
|
|
240
|
+
}
|
|
241
|
+
function M() {
|
|
242
|
+
const n = d();
|
|
243
|
+
if (n === "mainnet") return window.okxwallet?.bitcoin;
|
|
244
|
+
if (n === "testnet") return window.okxwallet?.bitcoinTestnet;
|
|
245
|
+
if (n === "signet") return window.okxwallet?.bitcoinSignet;
|
|
246
|
+
}
|
|
247
|
+
async function V(n) {
|
|
248
|
+
const e = M();
|
|
249
|
+
if (typeof e?.signPsbts != "function")
|
|
250
|
+
throw new Error("OKX cannot sign several PSBTs at once.");
|
|
251
|
+
const t = await e.signPsbts(
|
|
252
|
+
n.map((s) => s.unsignedPsbtHex),
|
|
253
|
+
n.map((s) => {
|
|
254
|
+
const o = B(s).flatMap(
|
|
255
|
+
(i) => i.signingIndexes.map((r) => ({ address: i.address, index: r }))
|
|
256
|
+
);
|
|
257
|
+
return o.length > 0 ? { autoFinalized: !0, toSignInputs: o } : { autoFinalized: !0 };
|
|
258
|
+
})
|
|
259
|
+
);
|
|
260
|
+
if (t.length !== n.length) throw new Error("OKX returned the wrong PSBT count.");
|
|
261
|
+
return t.map((s, o) => I(s, n[o].noSignIdxes));
|
|
262
|
+
}
|
|
263
|
+
function Y() {
|
|
264
|
+
return typeof window < "u" && typeof M()?.signPsbts == "function" ? V : null;
|
|
265
|
+
}
|
|
266
|
+
const Q = {
|
|
267
|
+
getWallets: _,
|
|
268
|
+
getAccounts: q,
|
|
269
|
+
onAccountsChanged: z,
|
|
270
|
+
signMessage: R,
|
|
271
|
+
signMessageDeterministic: G,
|
|
272
|
+
sendBTC: j,
|
|
273
|
+
signPSBT: E,
|
|
274
|
+
sign: J,
|
|
275
|
+
getSignMany: Y
|
|
276
|
+
};
|
|
277
|
+
async function l() {
|
|
278
|
+
if (!window.unisat) throw new Error("UniSat not found.");
|
|
279
|
+
const n = await window.unisat.getNetwork(), e = d();
|
|
280
|
+
n !== "livenet" && e === "mainnet" ? await window.unisat.switchNetwork("livenet") : n === "livenet" && (e === "testnet" || e === "signet") && await window.unisat.switchNetwork("testnet");
|
|
281
|
+
}
|
|
282
|
+
async function Z() {
|
|
283
|
+
await l();
|
|
284
|
+
const n = await window.unisat?.requestAccounts(), e = await window.unisat?.getPublicKey();
|
|
285
|
+
if (!n) throw new Error("Failed to get wallets.");
|
|
286
|
+
return n.map((s) => ({
|
|
287
|
+
address: s,
|
|
288
|
+
pubkey: e,
|
|
289
|
+
purpose: "all"
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
async function nn() {
|
|
293
|
+
return typeof window.unisat?.getAccounts != "function" ? [] : await window.unisat.getAccounts() ?? [];
|
|
294
|
+
}
|
|
295
|
+
function en(n) {
|
|
296
|
+
const e = window.unisat;
|
|
297
|
+
if (!e?.on) return () => {
|
|
298
|
+
};
|
|
299
|
+
const t = (s) => n(s ?? []);
|
|
300
|
+
return e.on("accountsChanged", t), () => e.removeListener?.("accountsChanged", t);
|
|
301
|
+
}
|
|
302
|
+
async function tn(n) {
|
|
303
|
+
await l();
|
|
304
|
+
try {
|
|
305
|
+
const e = await window.unisat.signMessage(n, "bip322-simple");
|
|
306
|
+
return u.from(e, "base64").toString("hex");
|
|
307
|
+
} catch (e) {
|
|
308
|
+
throw console.error("Failed to sign message", e), new Error("Failed to sign message.");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function sn(n) {
|
|
312
|
+
await l();
|
|
313
|
+
const e = m();
|
|
314
|
+
if (!e) throw new Error("No payment wallet found.");
|
|
315
|
+
const t = e.address;
|
|
316
|
+
try {
|
|
317
|
+
const s = await window.unisat.signMessage(n, "ecdsa");
|
|
318
|
+
return {
|
|
319
|
+
signature: u.from(s, "base64").toString("hex"),
|
|
320
|
+
address: t
|
|
321
|
+
};
|
|
322
|
+
} catch (s) {
|
|
323
|
+
throw console.error("Failed to sign message", s), new Error("Failed to sign message.");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async function on(n, e) {
|
|
327
|
+
await l();
|
|
328
|
+
try {
|
|
329
|
+
return await window.unisat.sendBitcoin(e, n);
|
|
330
|
+
} catch (t) {
|
|
331
|
+
throw console.error("Failed to send BTC", t), new Error("Failed to send BTC.");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async function H(n, e, t) {
|
|
335
|
+
if (await l(), !window.unisat) throw new Error("UniSat not found.");
|
|
336
|
+
const s = T(n);
|
|
337
|
+
let o = null;
|
|
338
|
+
return t.length === 0 ? o = await window.unisat.signPsbt(s) : o = await window.unisat.signPsbt(s, $(t)), e && (o = await window.unisat.pushPsbt(o)), o;
|
|
339
|
+
}
|
|
340
|
+
function $(n) {
|
|
341
|
+
const e = [];
|
|
342
|
+
for (const t of n)
|
|
343
|
+
for (let s = 0; s < t.signingIndexes.length; s++)
|
|
344
|
+
e.push({
|
|
345
|
+
address: t.address,
|
|
346
|
+
index: t.signingIndexes[s],
|
|
347
|
+
useTweakedSigner: t.useTweakedSigner ? t.useTweakedSigner[s] : void 0
|
|
348
|
+
});
|
|
349
|
+
return { autoFinalized: !0, toSignInputs: e };
|
|
350
|
+
}
|
|
351
|
+
function X(n) {
|
|
352
|
+
const { unsignedPsbtHex: e, paymentAddr: t, ordAddr: s, ordAddrIdxes: o, useTweakSignerIdxes: i, noSignIdxes: r } = n;
|
|
353
|
+
if (!t) return [];
|
|
354
|
+
const a = c.Psbt.fromHex(e), w = [], f = [], p = [];
|
|
355
|
+
for (let g = 0; g < a.inputCount; g++)
|
|
356
|
+
if (!(r && r.includes(g))) {
|
|
357
|
+
if (o.includes(g)) {
|
|
358
|
+
i && i.includes(g) ? p.push(!0) : i && p.push(!1);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
w.push(g), i && i.includes(g) ? f.push(!0) : i && f.push(!1);
|
|
362
|
+
}
|
|
363
|
+
return [
|
|
364
|
+
{
|
|
365
|
+
address: t,
|
|
366
|
+
signingIndexes: w,
|
|
367
|
+
useTweakedSigner: f
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
address: s,
|
|
371
|
+
signingIndexes: o,
|
|
372
|
+
useTweakedSigner: p
|
|
373
|
+
}
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
function A(n, e) {
|
|
377
|
+
const t = c.Psbt.fromHex(n);
|
|
378
|
+
y(t, e);
|
|
379
|
+
const s = t.extractTransaction();
|
|
380
|
+
return { txId: s.getId(), signedTxHex: s.toHex() };
|
|
381
|
+
}
|
|
382
|
+
async function rn(n, e, t, s, o, i) {
|
|
383
|
+
const r = X({
|
|
384
|
+
unsignedPsbtHex: n,
|
|
385
|
+
paymentAddr: e,
|
|
386
|
+
ordAddr: t,
|
|
387
|
+
ordAddrIdxes: s,
|
|
388
|
+
useTweakSignerIdxes: o,
|
|
389
|
+
noSignIdxes: i
|
|
390
|
+
}), a = await H(x(n), !1, r);
|
|
391
|
+
return A(a, i);
|
|
392
|
+
}
|
|
393
|
+
async function an(n) {
|
|
394
|
+
if (await l(), !window.unisat?.signPsbts) throw new Error("UniSat cannot sign several PSBTs at once.");
|
|
395
|
+
const e = await window.unisat.signPsbts(
|
|
396
|
+
n.map((t) => t.unsignedPsbtHex),
|
|
397
|
+
n.map((t) => $(X(t)))
|
|
398
|
+
);
|
|
399
|
+
if (e.length !== n.length) throw new Error("UniSat returned the wrong PSBT count.");
|
|
400
|
+
return e.map((t, s) => A(t, n[s].noSignIdxes));
|
|
401
|
+
}
|
|
402
|
+
function wn() {
|
|
403
|
+
return typeof window < "u" && typeof window.unisat?.signPsbts == "function" ? an : null;
|
|
404
|
+
}
|
|
405
|
+
const dn = {
|
|
406
|
+
checkNetwork: l,
|
|
407
|
+
getWallets: Z,
|
|
408
|
+
getAccounts: nn,
|
|
409
|
+
onAccountsChanged: en,
|
|
410
|
+
signMessage: tn,
|
|
411
|
+
signMessageDeterministic: sn,
|
|
412
|
+
sendBTC: on,
|
|
413
|
+
signPSBT: H,
|
|
414
|
+
sign: rn,
|
|
415
|
+
getSignMany: wn
|
|
416
|
+
};
|
|
417
|
+
function P() {
|
|
418
|
+
const n = d();
|
|
419
|
+
if (n === "mainnet") return "Mainnet";
|
|
420
|
+
if (n === "testnet") return "Testnet4";
|
|
421
|
+
if (n === "signet") return "Signet";
|
|
422
|
+
throw new Error("Unknown BTC network type.");
|
|
423
|
+
}
|
|
424
|
+
async function cn() {
|
|
425
|
+
if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
|
|
426
|
+
const n = b({
|
|
427
|
+
purposes: ["ordinals", "payment"],
|
|
428
|
+
message: "[Best in Slot] wants to know your addresses!",
|
|
429
|
+
network: {
|
|
430
|
+
type: P()
|
|
431
|
+
}
|
|
432
|
+
}), e = await window.XverseProviders.BitcoinProvider?.connect(n);
|
|
433
|
+
if (!e) throw new Error("Error fetching wallet data.");
|
|
434
|
+
return e.addresses.map((s) => ({
|
|
435
|
+
address: s.address,
|
|
436
|
+
pubkey: s.publicKey,
|
|
437
|
+
purpose: s.purpose
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
440
|
+
async function gn(n, e, t) {
|
|
441
|
+
if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
|
|
442
|
+
const s = b({
|
|
443
|
+
address: t,
|
|
444
|
+
message: n,
|
|
445
|
+
protocol: "BIP322",
|
|
446
|
+
network: {
|
|
447
|
+
type: P()
|
|
448
|
+
}
|
|
449
|
+
}), o = await window.XverseProviders.BitcoinProvider.signMessage(s).catch(
|
|
450
|
+
(i) => {
|
|
451
|
+
throw console.error("Failed to sign message.", i), new Error("Failed to sign message.");
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
return u.from(o, "base64").toString("hex");
|
|
455
|
+
}
|
|
456
|
+
async function un(n) {
|
|
457
|
+
if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
|
|
458
|
+
const e = m();
|
|
459
|
+
if (!e) throw new Error("No payment wallet found.");
|
|
460
|
+
const t = e.address, s = b({
|
|
461
|
+
address: t,
|
|
462
|
+
message: n,
|
|
463
|
+
protocol: "ECDSA",
|
|
464
|
+
network: {
|
|
465
|
+
type: P()
|
|
466
|
+
}
|
|
467
|
+
}), o = await window.XverseProviders.BitcoinProvider.signMessage(s).catch(
|
|
468
|
+
(i) => {
|
|
469
|
+
throw console.error("Failed to sign message.", i), new Error("Failed to sign message.");
|
|
470
|
+
}
|
|
471
|
+
);
|
|
472
|
+
return {
|
|
473
|
+
signature: u.from(o, "base64").toString("hex"),
|
|
474
|
+
address: t
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async function ln(n, e) {
|
|
478
|
+
if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
|
|
479
|
+
return (await window.XverseProviders.BitcoinProvider.request("sendTransfer", {
|
|
480
|
+
recipients: [
|
|
481
|
+
{
|
|
482
|
+
address: e,
|
|
483
|
+
amount: n
|
|
484
|
+
}
|
|
485
|
+
]
|
|
486
|
+
})).result.txid;
|
|
487
|
+
}
|
|
488
|
+
async function C(n, e, t, s) {
|
|
489
|
+
if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
|
|
490
|
+
const o = b({
|
|
491
|
+
network: {
|
|
492
|
+
type: P()
|
|
493
|
+
},
|
|
494
|
+
message: s || "Sign Transaction",
|
|
495
|
+
psbtBase64: n,
|
|
496
|
+
broadcast: e,
|
|
497
|
+
inputsToSign: t
|
|
498
|
+
});
|
|
499
|
+
return await window.XverseProviders.BitcoinProvider.signTransaction(o);
|
|
500
|
+
}
|
|
501
|
+
function L(n) {
|
|
502
|
+
const { unsignedPsbtHex: e, paymentAddr: t, ordAddr: s, ordAddrIdxes: o, noSignIdxes: i } = n, r = c.Psbt.fromHex(e), a = [];
|
|
503
|
+
for (let w = 0; w < r.inputCount; w++)
|
|
504
|
+
i && i.includes(w) || o.includes(w) || a.push(w);
|
|
505
|
+
return [
|
|
506
|
+
{
|
|
507
|
+
address: t,
|
|
508
|
+
signingIndexes: a,
|
|
509
|
+
sigHash: c.Transaction.SIGHASH_DEFAULT
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
address: s,
|
|
513
|
+
signingIndexes: o,
|
|
514
|
+
sigHash: c.Transaction.SIGHASH_DEFAULT
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
}
|
|
518
|
+
function F(n, e) {
|
|
519
|
+
const t = c.Psbt.fromBase64(n);
|
|
520
|
+
y(t, e);
|
|
521
|
+
const s = t.extractTransaction();
|
|
522
|
+
return { txId: s.getId(), signedTxHex: s.toHex() };
|
|
523
|
+
}
|
|
524
|
+
async function fn(n, e, t, s, o, i) {
|
|
525
|
+
const r = await C(
|
|
526
|
+
x(n),
|
|
527
|
+
!1,
|
|
528
|
+
L({
|
|
529
|
+
unsignedPsbtHex: n,
|
|
530
|
+
paymentAddr: e,
|
|
531
|
+
ordAddr: t,
|
|
532
|
+
ordAddrIdxes: s,
|
|
533
|
+
noSignIdxes: i
|
|
534
|
+
}),
|
|
535
|
+
"sign this pls"
|
|
536
|
+
);
|
|
537
|
+
return F(r.psbtBase64, i);
|
|
538
|
+
}
|
|
539
|
+
async function pn(n) {
|
|
540
|
+
const e = window.XverseProviders?.BitcoinProvider;
|
|
541
|
+
if (typeof e?.signMultipleTransactions != "function")
|
|
542
|
+
throw new Error("Xverse cannot sign several PSBTs at once.");
|
|
543
|
+
const t = b({
|
|
544
|
+
network: { type: P() },
|
|
545
|
+
message: "Sign Transactions",
|
|
546
|
+
psbts: n.map((o) => ({
|
|
547
|
+
psbtBase64: x(o.unsignedPsbtHex),
|
|
548
|
+
inputsToSign: L(o)
|
|
549
|
+
}))
|
|
550
|
+
}), s = await e.signMultipleTransactions(t);
|
|
551
|
+
if (s.length !== n.length) throw new Error("Xverse returned the wrong PSBT count.");
|
|
552
|
+
return s.map((o, i) => F(o.psbtBase64, n[i].noSignIdxes));
|
|
553
|
+
}
|
|
554
|
+
function hn() {
|
|
555
|
+
return typeof window < "u" && typeof window.XverseProviders?.BitcoinProvider?.signMultipleTransactions == "function" ? pn : null;
|
|
556
|
+
}
|
|
557
|
+
const xn = {
|
|
558
|
+
getWallets: cn,
|
|
559
|
+
signMessage: gn,
|
|
560
|
+
signMessageDeterministic: un,
|
|
561
|
+
sendBTC: ln,
|
|
562
|
+
signPSBT: C,
|
|
563
|
+
sign: fn,
|
|
564
|
+
getSignMany: hn
|
|
565
|
+
};
|
|
566
|
+
k("leather", W);
|
|
567
|
+
k("okx", Q);
|
|
568
|
+
k("unisat", dn);
|
|
569
|
+
k("xverse", xn);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { BackendError } from '../core/backend-error';
|
|
2
|
+
export { BisBrc20RpcProvider, BisChainProvider } from '../core/bis-providers';
|
|
3
|
+
export type { BisBrc20RpcProviderOptions, BisChainProviderOptions } from '../core/bis-providers';
|
|
2
4
|
export { getEvmAddressFromBitcoinAddress, getEvmAddressFromPkScript } from '../core/brc20';
|
|
5
|
+
export type { Brc20RpcProvider, ChainBalance, ChainProvider, MempoolAcceptResult, OrdinalUtxo, Utxo, } from '../core/chain-providers';
|
|
3
6
|
export { delegateInscription, jsonInscription, textInscription } from '../types/inscription';
|
|
4
7
|
export { addressWalletInfo, opReturnWalletInfo } from '../types/wallet';
|
package/dist/types/api/swap.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
|
|
1
|
+
import { DepositOrderOptions, GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
|
|
2
2
|
import { SignProgressOptions } from '../core/sign-progress';
|
|
3
|
-
export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
|
|
3
|
+
export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapRoute, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
|
|
4
4
|
export type { EnsureSwapWalletResult, GetActivityOfPairResponse, GetKlinesRequest, GetKlinesResponse, GetPairVolumeRequest, GetPairVolumeResponse, GetRecentActivityRequest, GetRecentActivityResponse, GetSwapStatusResponse, GetTvlHistoryRequest, GetTvlHistoryResponse, GetWalletActivitiesResponse, ImportSwapWalletOptions, Kline, ListPairsOrderBy, ListPairsRequest, ListPairsResponse, PairActivityEntry, PairInfo, PairReserves, RecentActivityEntry, RecentActivityKind, RecentActivityToken, SwapBalance, SwapInfo, TokenInfo, TvlPoint, WalletActivityEntry, WalletActivityKind, } from '../core/bis_swap';
|
|
5
5
|
export type { AllBalanceDetails } from '../core/helpers';
|
|
6
6
|
export type { SignProgressOptions, SignRequest } from '../core/sign-progress';
|
|
@@ -8,6 +8,7 @@ export type { BISSwapWalletInfo } from '../core/store';
|
|
|
8
8
|
export type { FeePolicy } from '../lib/fee-policy';
|
|
9
9
|
export type { SwapFees } from '../lib/swap-reporting';
|
|
10
10
|
export { satsToBtc, satsToUsd, swapSide } from '../lib/swap-reporting';
|
|
11
|
+
export type { SwapRoute, SwapRouteHop } from '../lib/swap-route';
|
|
11
12
|
export { calculatePairAddress as getPairAddress } from '../lib/uniswap_ops';
|
|
12
13
|
/**
|
|
13
14
|
* Retrieves the wallet activities for a given public key, on one pair or across every pair.
|
|
@@ -91,9 +92,10 @@ export declare function removeLiquidity(token1Address: string, token2Address: st
|
|
|
91
92
|
* @param amountOutMin - The expected (quoted) output amount. The enforced minimum is derived from this by applying `slippageBPS` — pass the quote, not an already slippage-adjusted value, to avoid double-applying slippage.
|
|
92
93
|
* @param slippageBPS - The slippage tolerance in basis points.
|
|
93
94
|
* @param referrerId - An optional referral ID. When valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
|
|
95
|
+
* @param path - (Optional) The route to execute: `getSwapRoute(...).path`, token addresses from `tokenInAddress` to `tokenOutAddress`. A 3-token path swaps through its middle token and needs `SwapInfo.allow_multi_hop_routes`. When omitted, the swap uses the direct pool.
|
|
94
96
|
* @returns A promise that resolves to a boolean indicating the success of the swap operation.
|
|
95
97
|
*/
|
|
96
|
-
export declare function swapExactInput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOutMin: bigint, slippageBPS: bigint, referrerId?: string): Promise<boolean>;
|
|
98
|
+
export declare function swapExactInput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOutMin: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<boolean>;
|
|
97
99
|
/**
|
|
98
100
|
* Executes an exact-output token swap: receives an exact `amountOut` of the
|
|
99
101
|
* output token and spends at most the input amount (the `amountIn` reference
|
|
@@ -105,9 +107,10 @@ export declare function swapExactInput(tokenInAddress: string, tokenOutAddress:
|
|
|
105
107
|
* @param amountOut - The exact amount of the output token to receive.
|
|
106
108
|
* @param slippageBPS - The slippage tolerance in basis points.
|
|
107
109
|
* @param referrerId - An optional referral ID. When valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
|
|
110
|
+
* @param path - (Optional) The route to execute: `getSwapRoute(..., { exactOut: true }).path`, token addresses from `tokenInAddress` to `tokenOutAddress`. A 3-token path swaps through its middle token and needs `SwapInfo.allow_multi_hop_routes`. When omitted, the swap uses the direct pool.
|
|
108
111
|
* @returns A promise that resolves to a boolean indicating the success of the swap operation.
|
|
109
112
|
*/
|
|
110
|
-
export declare function swapExactOutput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOut: bigint, slippageBPS: bigint, referrerId?: string): Promise<boolean>;
|
|
113
|
+
export declare function swapExactOutput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOut: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<boolean>;
|
|
111
114
|
/**
|
|
112
115
|
* Redeems WBTC from the smart wallet back into BTC on Bitcoin L1, the reverse of
|
|
113
116
|
* `wrapBtc`. The BTC is paid out on L1 to `pkscript`, so that value must be an
|
|
@@ -127,13 +130,13 @@ export declare function unwrapBtc(pkscript: string, amount: bigint): Promise<boo
|
|
|
127
130
|
* @param feeRate - The fee rate for the deposit operation.
|
|
128
131
|
* @param createAllowanceIfNeeded - Whether to create an allowance if needed.
|
|
129
132
|
* @param reclaimInscriptions - Optional transfer inscriptions to reclaim toward the deposit, each with `inscriptionId` and `amount` (bigint, 18 decimals).
|
|
130
|
-
* @param options - `onSignRequest` is called before each wallet prompt with `{ step, total }`. `total` is 3, 5 or 7.
|
|
133
|
+
* @param options - `onSignRequest` is called before each wallet prompt with `{ step, total }`. `total` is 3, 5 or 7, and 3 whenever `batchInscriptions` is set. `batchInscriptions` inscribes the base-layer conversion, the allowance and the deposit from one commit and sends them to OP_RETURN in one tx. `batchSendLayout` (`single`, `interleaved` or `auto`, default `single`) picks how that tx lays out its OP_RETURN outputs.
|
|
131
134
|
* @returns A promise that resolves to an array of transaction IDs related to the deposit operation.
|
|
132
135
|
*/
|
|
133
136
|
export declare function deposit(tokenAddress: string, amount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: {
|
|
134
137
|
inscriptionId: string;
|
|
135
138
|
amount: bigint;
|
|
136
|
-
}[], options?:
|
|
139
|
+
}[], options?: DepositOrderOptions): Promise<string[]>;
|
|
137
140
|
/**
|
|
138
141
|
* Wraps BTC into the smart wallet as WBTC (the swap layer's BTC representation),
|
|
139
142
|
* the BTC equivalent of `deposit`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletInfo } from '../types/wallet';
|
|
2
|
-
export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
|
|
3
|
-
export type { AccountChangeEvent, Endpoints, EndpointsConfig } from '../core/bis';
|
|
2
|
+
export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getProviders, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, setProviders, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
|
|
3
|
+
export type { AccountChangeEvent, Endpoints, EndpointsConfig, NetworkProviders, ProvidersConfig, } from '../core/bis';
|
|
4
4
|
export type { WalletInfo };
|
|
5
5
|
export { getNetwork } from '../core/store-network';
|
|
6
6
|
export type { BISNetwork, BISSession, BISWallet, BISWalletProvider, BISWalletPurpose, } from '../types/common';
|