@omnisat/lasereyes 0.0.11 → 0.0.13
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/index.d.ts +36 -2
- package/dist/index.js +834 -34
- package/dist/index.mjs +819 -34
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -77,9 +77,13 @@ __export(src_exports, {
|
|
|
77
77
|
LEATHER_MAINNET: () => LEATHER_MAINNET,
|
|
78
78
|
LEATHER_TESTNET: () => LEATHER_TESTNET,
|
|
79
79
|
LaserEyesProvider: () => LaserEyesProvider,
|
|
80
|
+
MAGIC_EDEN: () => MAGIC_EDEN,
|
|
80
81
|
MAINNET: () => MAINNET,
|
|
81
82
|
MEMPOOL_SPACE_TESTNET_URL: () => MEMPOOL_SPACE_TESTNET_URL,
|
|
82
83
|
MEMPOOL_SPACE_URL: () => MEMPOOL_SPACE_URL,
|
|
84
|
+
OKX: () => OKX,
|
|
85
|
+
OKX_MAINNET: () => OKX_MAINNET,
|
|
86
|
+
OKX_TESTNET: () => OKX_TESTNET,
|
|
83
87
|
OYL: () => OYL,
|
|
84
88
|
P2PKH: () => P2PKH,
|
|
85
89
|
P2PSH: () => P2PSH,
|
|
@@ -89,27 +93,38 @@ __export(src_exports, {
|
|
|
89
93
|
P2WSH: () => P2WSH,
|
|
90
94
|
PHANTOM: () => PHANTOM,
|
|
91
95
|
REGTEST: () => REGTEST,
|
|
96
|
+
SIGNET: () => SIGNET,
|
|
92
97
|
TESTNET: () => TESTNET,
|
|
93
98
|
UNISAT: () => UNISAT,
|
|
94
99
|
UNISAT_MAINNET: () => UNISAT_MAINNET,
|
|
95
100
|
UNISAT_TESTNET: () => UNISAT_TESTNET,
|
|
96
101
|
WALLETS: () => WALLETS,
|
|
102
|
+
WIZZ: () => WIZZ,
|
|
103
|
+
WIZZ_MAINNET: () => WIZZ_MAINNET,
|
|
104
|
+
WIZZ_TESTNET: () => WIZZ_TESTNET,
|
|
97
105
|
XVERSE: () => XVERSE,
|
|
98
106
|
XVERSE_MAINNET: () => XVERSE_MAINNET,
|
|
99
107
|
XVERSE_NETWORK: () => XVERSE_NETWORK,
|
|
100
108
|
XVERSE_TESTNET: () => XVERSE_TESTNET,
|
|
101
109
|
createConfig: () => createConfig,
|
|
110
|
+
createSendBtcPsbt: () => createSendBtcPsbt,
|
|
111
|
+
estimateTxSize: () => estimateTxSize,
|
|
102
112
|
findOrdinalsAddress: () => findOrdinalsAddress,
|
|
103
113
|
findPaymentAddress: () => findPaymentAddress,
|
|
104
114
|
getAddressType: () => getAddressType,
|
|
115
|
+
getAddressUtxos: () => getAddressUtxos,
|
|
105
116
|
getBTCBalance: () => getBTCBalance,
|
|
106
117
|
getBitcoinNetwork: () => getBitcoinNetwork,
|
|
107
118
|
getLeatherNetwork: () => getLeatherNetwork,
|
|
108
119
|
getMempoolSpaceUrl: () => getMempoolSpaceUrl,
|
|
109
120
|
getNetworkForLeather: () => getNetworkForLeather,
|
|
121
|
+
getNetworkForOkx: () => getNetworkForOkx,
|
|
110
122
|
getNetworkForUnisat: () => getNetworkForUnisat,
|
|
123
|
+
getNetworkForWizz: () => getNetworkForWizz,
|
|
111
124
|
getNetworkForXverse: () => getNetworkForXverse,
|
|
125
|
+
getRedeemScript: () => getRedeemScript,
|
|
112
126
|
getUnisatNetwork: () => getUnisatNetwork,
|
|
127
|
+
getWizzNetwork: () => getWizzNetwork,
|
|
113
128
|
getXverseNetwork: () => getXverseNetwork,
|
|
114
129
|
isBase64: () => isBase64,
|
|
115
130
|
isHex: () => isHex,
|
|
@@ -124,9 +139,14 @@ var UNISAT_MAINNET = "livenet";
|
|
|
124
139
|
var UNISAT_TESTNET = "testnet";
|
|
125
140
|
var XVERSE_MAINNET = "Mainnet";
|
|
126
141
|
var XVERSE_TESTNET = "Testnet";
|
|
142
|
+
var OKX_MAINNET = "livenet";
|
|
143
|
+
var OKX_TESTNET = "testnet";
|
|
144
|
+
var WIZZ_MAINNET = "livenet";
|
|
145
|
+
var WIZZ_TESTNET = "testnet";
|
|
127
146
|
var LEATHER_MAINNET = "mainnet";
|
|
128
147
|
var LEATHER_TESTNET = "testnet";
|
|
129
148
|
var MAINNET = "mainnet";
|
|
149
|
+
var SIGNET = "signet";
|
|
130
150
|
var TESTNET = "testnet";
|
|
131
151
|
var REGTEST = "regtest";
|
|
132
152
|
var getXverseNetwork = (network) => {
|
|
@@ -150,6 +170,13 @@ var getUnisatNetwork = (network) => {
|
|
|
150
170
|
return UNISAT_TESTNET;
|
|
151
171
|
return UNISAT_MAINNET;
|
|
152
172
|
};
|
|
173
|
+
var getWizzNetwork = (network) => {
|
|
174
|
+
if (network === MAINNET)
|
|
175
|
+
return WIZZ_MAINNET;
|
|
176
|
+
if (network === TESTNET)
|
|
177
|
+
return WIZZ_TESTNET;
|
|
178
|
+
return WIZZ_MAINNET;
|
|
179
|
+
};
|
|
153
180
|
var getNetworkForUnisat = (network) => {
|
|
154
181
|
if (network === UNISAT_MAINNET)
|
|
155
182
|
return MAINNET;
|
|
@@ -171,6 +198,20 @@ var getNetworkForLeather = (network) => {
|
|
|
171
198
|
return TESTNET;
|
|
172
199
|
return MAINNET;
|
|
173
200
|
};
|
|
201
|
+
var getNetworkForOkx = (network) => {
|
|
202
|
+
if (network === OKX_MAINNET)
|
|
203
|
+
return MAINNET;
|
|
204
|
+
if (network === OKX_TESTNET)
|
|
205
|
+
return TESTNET;
|
|
206
|
+
return MAINNET;
|
|
207
|
+
};
|
|
208
|
+
var getNetworkForWizz = (network) => {
|
|
209
|
+
if (network === WIZZ_MAINNET)
|
|
210
|
+
return MAINNET;
|
|
211
|
+
if (network === WIZZ_TESTNET)
|
|
212
|
+
return TESTNET;
|
|
213
|
+
return MAINNET;
|
|
214
|
+
};
|
|
174
215
|
var MEMPOOL_SPACE_URL = "https://mempool.space";
|
|
175
216
|
var MEMPOOL_SPACE_TESTNET_URL = "https://mempool.space/testnet";
|
|
176
217
|
var getMempoolSpaceUrl = (network) => network === TESTNET ? MEMPOOL_SPACE_TESTNET_URL : MEMPOOL_SPACE_URL;
|
|
@@ -181,6 +222,9 @@ var UNISAT = "unisat";
|
|
|
181
222
|
var XVERSE = "xverse";
|
|
182
223
|
var PHANTOM = "phantom";
|
|
183
224
|
var LEATHER = "leather";
|
|
225
|
+
var MAGIC_EDEN = "magic-eden";
|
|
226
|
+
var OKX = "okx";
|
|
227
|
+
var WIZZ = "wizz";
|
|
184
228
|
var P2TR = "p2tr";
|
|
185
229
|
var P2PKH = "p2pkh";
|
|
186
230
|
var P2WPKH = "p2wpkh";
|
|
@@ -232,6 +276,12 @@ var LOCAL_STORAGE_DEFAULT_WALLET = "defaultWallet";
|
|
|
232
276
|
var initialWalletContext = {
|
|
233
277
|
hasUnisat: false,
|
|
234
278
|
hasXverse: false,
|
|
279
|
+
hasOyl: false,
|
|
280
|
+
hasMagicEden: false,
|
|
281
|
+
hasOkx: false,
|
|
282
|
+
hasLeather: false,
|
|
283
|
+
hasPhantom: false,
|
|
284
|
+
hasWizz: false,
|
|
235
285
|
connected: false,
|
|
236
286
|
isConnecting: false,
|
|
237
287
|
publicKey: "",
|
|
@@ -288,6 +338,15 @@ var import_usehooks_ts = require("usehooks-ts");
|
|
|
288
338
|
// src/lib/helpers.ts
|
|
289
339
|
var bitcoin = __toESM(require("bitcoinjs-lib"));
|
|
290
340
|
var import_axios = __toESM(require("axios"));
|
|
341
|
+
|
|
342
|
+
// src/lib/urls.ts
|
|
343
|
+
var MEMPOOL_SPACE_URL2 = "https://mempool.space";
|
|
344
|
+
var MEMPOOL_SPACE_TESTNET_URL2 = "https://mempool.space/testnet";
|
|
345
|
+
var getMempoolSpaceUrl2 = (network) => network === TESTNET ? MEMPOOL_SPACE_TESTNET_URL2 : MEMPOOL_SPACE_URL2;
|
|
346
|
+
|
|
347
|
+
// src/lib/helpers.ts
|
|
348
|
+
var ecc = __toESM(require("@bitcoinerlab/secp256k1"));
|
|
349
|
+
bitcoin.initEccLib(ecc);
|
|
291
350
|
var getBitcoinNetwork = (network) => {
|
|
292
351
|
if (network === TESTNET) {
|
|
293
352
|
return bitcoin.networks.testnet;
|
|
@@ -315,6 +374,13 @@ var getBTCBalance = (address2) => __async(void 0, null, function* () {
|
|
|
315
374
|
throw new Error("Failed to fetch BTC balance");
|
|
316
375
|
}
|
|
317
376
|
});
|
|
377
|
+
var getAddressUtxos = (address2) => __async(void 0, null, function* () {
|
|
378
|
+
try {
|
|
379
|
+
return yield import_axios.default.get(`https://blockchain.info/unspent?active=${address2}`).then((response) => response.data.unspent_outputs);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
throw new Error("Failed to fetch UTXOs");
|
|
382
|
+
}
|
|
383
|
+
});
|
|
318
384
|
var satoshisToBTC = (satoshis) => {
|
|
319
385
|
if (Number.isNaN(satoshis) || satoshis === void 0)
|
|
320
386
|
return "--";
|
|
@@ -355,10 +421,101 @@ function getAddressType(address2) {
|
|
|
355
421
|
}
|
|
356
422
|
throw new Error("Invalid address");
|
|
357
423
|
}
|
|
424
|
+
function estimateTxSize(taprootInputCount, nonTaprootInputCount, outputCount) {
|
|
425
|
+
const baseTxSize = 10;
|
|
426
|
+
const taprootInputSize = 57;
|
|
427
|
+
const nonTaprootInputSize = 41;
|
|
428
|
+
const outputSize = 34;
|
|
429
|
+
const totalInputSize = taprootInputCount * taprootInputSize + nonTaprootInputCount * nonTaprootInputSize;
|
|
430
|
+
const totalOutputSize = outputCount * outputSize;
|
|
431
|
+
return baseTxSize + totalInputSize + totalOutputSize;
|
|
432
|
+
}
|
|
433
|
+
function createSendBtcPsbt(address2, paymentAddress, recipientAddress, amount, paymentPublicKey, network, feeRate = 7) {
|
|
434
|
+
return __async(this, null, function* () {
|
|
435
|
+
const isTaprootOnly = address2 === paymentAddress;
|
|
436
|
+
const mempoolUrl = `${getMempoolSpaceUrl2(
|
|
437
|
+
network
|
|
438
|
+
)}/api/address/${paymentAddress}/utxo`;
|
|
439
|
+
const utxos = yield import_axios.default.get(mempoolUrl).then((response) => response.data);
|
|
440
|
+
const sortedUtxos = utxos.sort(
|
|
441
|
+
(a, b) => b.value - a.value
|
|
442
|
+
);
|
|
443
|
+
const psbt = new bitcoin.Psbt({ network: getBitcoinNetwork(network) });
|
|
444
|
+
const estTxSize = estimateTxSize(1, 0, 2);
|
|
445
|
+
const satsNeeded = Math.floor(estTxSize * feeRate) + amount;
|
|
446
|
+
let amountGathered = 0;
|
|
447
|
+
let counter = 0;
|
|
448
|
+
try {
|
|
449
|
+
for (var iter = __forAwait(sortedUtxos), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
|
|
450
|
+
let utxo = temp.value;
|
|
451
|
+
const { txid, vout, value } = utxo;
|
|
452
|
+
const script = bitcoin.address.toOutputScript(
|
|
453
|
+
paymentAddress,
|
|
454
|
+
getBitcoinNetwork(network)
|
|
455
|
+
);
|
|
456
|
+
psbt.addInput({
|
|
457
|
+
hash: txid,
|
|
458
|
+
index: vout,
|
|
459
|
+
witnessUtxo: {
|
|
460
|
+
script,
|
|
461
|
+
value
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
if (!isTaprootOnly) {
|
|
465
|
+
const redeemScript = getRedeemScript(paymentPublicKey, network);
|
|
466
|
+
psbt.updateInput(counter, { redeemScript });
|
|
467
|
+
}
|
|
468
|
+
amountGathered += value;
|
|
469
|
+
if (amountGathered >= satsNeeded) {
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
} catch (temp) {
|
|
474
|
+
error = [temp];
|
|
475
|
+
} finally {
|
|
476
|
+
try {
|
|
477
|
+
more && (temp = iter.return) && (yield temp.call(iter));
|
|
478
|
+
} finally {
|
|
479
|
+
if (error)
|
|
480
|
+
throw error[0];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (amountGathered < satsNeeded) {
|
|
484
|
+
throw new Error("Insufficient funds");
|
|
485
|
+
}
|
|
486
|
+
psbt.addOutput({
|
|
487
|
+
address: recipientAddress,
|
|
488
|
+
value: amount
|
|
489
|
+
});
|
|
490
|
+
if (amountGathered > satsNeeded) {
|
|
491
|
+
psbt.addOutput({
|
|
492
|
+
address: paymentAddress,
|
|
493
|
+
value: amountGathered - satsNeeded - amount
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
psbtBase64: psbt.toBase64(),
|
|
498
|
+
psbtHex: psbt.toHex()
|
|
499
|
+
};
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
function getRedeemScript(paymentPublicKey, network) {
|
|
503
|
+
var _a;
|
|
504
|
+
const p2wpkh = bitcoin.payments.p2wpkh({
|
|
505
|
+
pubkey: Buffer.from(paymentPublicKey, "hex"),
|
|
506
|
+
network: getBitcoinNetwork(network)
|
|
507
|
+
});
|
|
508
|
+
const p2sh = bitcoin.payments.p2sh({
|
|
509
|
+
redeem: p2wpkh,
|
|
510
|
+
network: getBitcoinNetwork(network)
|
|
511
|
+
});
|
|
512
|
+
return (_a = p2sh == null ? void 0 : p2sh.redeem) == null ? void 0 : _a.output;
|
|
513
|
+
}
|
|
358
514
|
|
|
359
515
|
// src/providers/LaserEyesProvider.tsx
|
|
360
516
|
var import_sats_connect = require("sats-connect");
|
|
361
517
|
var import_address = require("bitcoinjs-lib/src/address");
|
|
518
|
+
var import_axios2 = __toESM(require("axios"));
|
|
362
519
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
363
520
|
var LaserEyesContext = (0, import_react.createContext)(initialWalletContext);
|
|
364
521
|
var useLaserEyes = () => {
|
|
@@ -384,6 +541,12 @@ var LaserEyesProvider = ({
|
|
|
384
541
|
const [balance, setBalance] = (0, import_react.useState)();
|
|
385
542
|
const [hasUnisat, setHasUnisat] = (0, import_react.useState)(false);
|
|
386
543
|
const [hasXverse, setHasXverse] = (0, import_react.useState)(false);
|
|
544
|
+
const [hasOyl, setHasOyl] = (0, import_react.useState)(false);
|
|
545
|
+
const [hasMagicEden, setHasMagicEden] = (0, import_react.useState)(false);
|
|
546
|
+
const [hasOkx, setHasOkx] = (0, import_react.useState)(false);
|
|
547
|
+
const [hasLeather, setHasLeather] = (0, import_react.useState)(false);
|
|
548
|
+
const [hasPhantom, setHasPhantom] = (0, import_react.useState)(false);
|
|
549
|
+
const [hasWizz, setHasWizz] = (0, import_react.useState)(false);
|
|
387
550
|
const [network, setNetwork] = (0, import_usehooks_ts.useLocalStorage)("network", MAINNET, {
|
|
388
551
|
initializeWithValue: false
|
|
389
552
|
});
|
|
@@ -408,11 +571,47 @@ var LaserEyesProvider = ({
|
|
|
408
571
|
const xverseLib = (_a = window == null ? void 0 : window.XverseProviders) == null ? void 0 : _a.BitcoinProvider;
|
|
409
572
|
setHasXverse(!!xverseLib);
|
|
410
573
|
}, []);
|
|
574
|
+
(0, import_react.useEffect)(() => {
|
|
575
|
+
const oylLib = window == null ? void 0 : window.oyl;
|
|
576
|
+
setHasOyl(!!oylLib);
|
|
577
|
+
}, []);
|
|
578
|
+
(0, import_react.useEffect)(() => {
|
|
579
|
+
const magicEdenLib = window == null ? void 0 : window.magicEden;
|
|
580
|
+
setHasMagicEden(!!magicEdenLib);
|
|
581
|
+
}, []);
|
|
582
|
+
(0, import_react.useEffect)(() => {
|
|
583
|
+
}, []);
|
|
584
|
+
(0, import_react.useEffect)(() => {
|
|
585
|
+
let foundOkx;
|
|
586
|
+
if (network === TESTNET) {
|
|
587
|
+
foundOkx = window.okxwallet.bitcoinTestnet;
|
|
588
|
+
} else if (network === MAINNET) {
|
|
589
|
+
foundOkx = window.okxwallet.bitcoin;
|
|
590
|
+
}
|
|
591
|
+
setHasOkx(!!foundOkx);
|
|
592
|
+
}, []);
|
|
593
|
+
(0, import_react.useEffect)(() => {
|
|
594
|
+
const leatherLib = window == null ? void 0 : window.LeatherProvider;
|
|
595
|
+
setHasLeather(!!leatherLib);
|
|
596
|
+
}, []);
|
|
597
|
+
(0, import_react.useEffect)(() => {
|
|
598
|
+
var _a;
|
|
599
|
+
const phantomLib = (_a = window == null ? void 0 : window.phantom) == null ? void 0 : _a.bitcoin;
|
|
600
|
+
if (phantomLib && phantomLib.isPhantom) {
|
|
601
|
+
setHasPhantom(!!phantomLib);
|
|
602
|
+
} else {
|
|
603
|
+
setHasPhantom(false);
|
|
604
|
+
}
|
|
605
|
+
}, []);
|
|
606
|
+
(0, import_react.useEffect)(() => {
|
|
607
|
+
const wissLib = window == null ? void 0 : window.wizz;
|
|
608
|
+
setHasWizz(!!wissLib);
|
|
609
|
+
}, []);
|
|
411
610
|
(0, import_react.useEffect)(() => {
|
|
412
611
|
setBalance(void 0);
|
|
413
612
|
}, [network]);
|
|
414
613
|
(0, import_react.useEffect)(() => {
|
|
415
|
-
if (provider !== UNISAT) {
|
|
614
|
+
if (provider !== UNISAT && provider !== WIZZ) {
|
|
416
615
|
return;
|
|
417
616
|
}
|
|
418
617
|
library.getAccounts().then((accounts2) => {
|
|
@@ -462,7 +661,6 @@ var LaserEyesProvider = ({
|
|
|
462
661
|
try {
|
|
463
662
|
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, XVERSE);
|
|
464
663
|
let xverseNetwork = getXverseNetwork((config == null ? void 0 : config.network) || MAINNET);
|
|
465
|
-
console.log({ xverseNetwork });
|
|
466
664
|
const getAddressOptions = {
|
|
467
665
|
payload: {
|
|
468
666
|
purposes: ["ordinals", "payment"],
|
|
@@ -483,7 +681,6 @@ var LaserEyesProvider = ({
|
|
|
483
681
|
setLibrary(window.BitcoinProvider);
|
|
484
682
|
}
|
|
485
683
|
getBTCBalance(foundPaymentAddress.address).then((totalBalance) => {
|
|
486
|
-
console.log({ totalBalance });
|
|
487
684
|
setBalance(totalBalance);
|
|
488
685
|
});
|
|
489
686
|
},
|
|
@@ -500,38 +697,186 @@ var LaserEyesProvider = ({
|
|
|
500
697
|
throw error;
|
|
501
698
|
}
|
|
502
699
|
});
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
700
|
+
const connectOyl = () => __async(void 0, null, function* () {
|
|
701
|
+
try {
|
|
702
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OYL);
|
|
703
|
+
const lib = window.oyl;
|
|
704
|
+
const result = yield lib.requestAccounts();
|
|
705
|
+
const oylPubKey = yield lib.getPublicKey();
|
|
706
|
+
setPaymentPublicKey(oylPubKey);
|
|
707
|
+
setAccounts(result);
|
|
708
|
+
setAddress(result[0]);
|
|
709
|
+
setPaymentAddress(result[1]);
|
|
710
|
+
setLibrary(lib);
|
|
711
|
+
setProvider(OYL);
|
|
712
|
+
handleAccountsChanged(result);
|
|
713
|
+
setConnected(true);
|
|
714
|
+
} catch (error) {
|
|
715
|
+
throw new Error(`Can't lasereyes to ${OYL} wallet`);
|
|
507
716
|
}
|
|
508
|
-
|
|
509
|
-
|
|
717
|
+
});
|
|
718
|
+
const connectMagicEden = () => __async(void 0, null, function* () {
|
|
719
|
+
try {
|
|
720
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, MAGIC_EDEN);
|
|
721
|
+
let xverseNetwork = getXverseNetwork((config == null ? void 0 : config.network) || MAINNET);
|
|
722
|
+
const getAddressOptions = {
|
|
723
|
+
getProvider: () => __async(void 0, null, function* () {
|
|
724
|
+
return window.magicEden.bitcoin;
|
|
725
|
+
}),
|
|
726
|
+
payload: {
|
|
727
|
+
purposes: ["ordinals", "payment"],
|
|
728
|
+
message: "Address for receiving Ordinals and payments",
|
|
729
|
+
network: {
|
|
730
|
+
type: xverseNetwork
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
onFinish: (response) => {
|
|
734
|
+
setPublicKey(String(response.addresses[0].publicKey));
|
|
735
|
+
setPaymentPublicKey(String(response.addresses[1].publicKey));
|
|
736
|
+
const foundAddress = findOrdinalsAddress(response.addresses);
|
|
737
|
+
const foundPaymentAddress = findPaymentAddress(response.addresses);
|
|
738
|
+
if (foundAddress && foundPaymentAddress) {
|
|
739
|
+
setAddress(foundAddress.address);
|
|
740
|
+
setPaymentAddress(foundPaymentAddress.address);
|
|
741
|
+
setProvider(MAGIC_EDEN);
|
|
742
|
+
setLibrary(window.magicEden.bitcoin);
|
|
743
|
+
}
|
|
744
|
+
getBTCBalance(foundPaymentAddress.address).then((totalBalance) => {
|
|
745
|
+
setBalance(totalBalance);
|
|
746
|
+
});
|
|
747
|
+
},
|
|
748
|
+
onCancel: () => {
|
|
749
|
+
throw new Error(`User canceled lasereyes to ${MAGIC_EDEN} wallet`);
|
|
750
|
+
},
|
|
751
|
+
onError: (error) => {
|
|
752
|
+
throw new Error(`Can't lasereyes to ${MAGIC_EDEN} wallet`);
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
console.log(JSON.stringify(getAddressOptions));
|
|
756
|
+
yield (0, import_sats_connect.getAddress)(getAddressOptions);
|
|
757
|
+
setConnected(true);
|
|
758
|
+
} catch (error) {
|
|
759
|
+
console.log("error", error);
|
|
760
|
+
throw error;
|
|
510
761
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
762
|
+
});
|
|
763
|
+
const connectOkx = () => __async(void 0, null, function* () {
|
|
764
|
+
try {
|
|
765
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, OKX);
|
|
766
|
+
const lib = network === TESTNET ? window.okxwallet.bitcoinTestnet : window.okxwallet.bitcoin;
|
|
767
|
+
const okxAccounts = yield lib.requestAccounts();
|
|
768
|
+
if (!okxAccounts)
|
|
769
|
+
throw new Error("No accounts found");
|
|
770
|
+
const okxPubKey = yield lib.getPublicKey();
|
|
771
|
+
if (!okxPubKey)
|
|
772
|
+
throw new Error("No public key found");
|
|
773
|
+
setAccounts(okxAccounts);
|
|
774
|
+
setAddress(okxAccounts[0]);
|
|
775
|
+
setPaymentAddress(okxAccounts[0]);
|
|
776
|
+
setPublicKey(okxPubKey);
|
|
777
|
+
setPaymentPublicKey(okxPubKey);
|
|
778
|
+
setLibrary(lib);
|
|
779
|
+
setProvider(OKX);
|
|
780
|
+
setConnected(true);
|
|
781
|
+
const balance2 = yield lib == null ? void 0 : lib.getBalance();
|
|
782
|
+
setBalance(balance2 == null ? void 0 : balance2.total);
|
|
783
|
+
} catch (error) {
|
|
784
|
+
throw error;
|
|
517
785
|
}
|
|
518
|
-
};
|
|
519
|
-
const
|
|
786
|
+
});
|
|
787
|
+
const connectLeather = () => __async(void 0, null, function* () {
|
|
520
788
|
try {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
789
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
790
|
+
const lib = window.LeatherProvider;
|
|
791
|
+
const getAddressesResponse = yield lib.request(
|
|
792
|
+
"getAddresses"
|
|
793
|
+
);
|
|
794
|
+
const addressesResponse = getAddressesResponse.result;
|
|
795
|
+
const addresses = addressesResponse.addresses;
|
|
796
|
+
const leatherAccountsParsed = addresses.map(
|
|
797
|
+
(address3) => address3.address
|
|
798
|
+
);
|
|
799
|
+
const taprootAddress = addresses.find(
|
|
800
|
+
(address3) => address3.type === P2TR
|
|
801
|
+
);
|
|
802
|
+
const segwitAddress = addresses.find(
|
|
803
|
+
(address3) => address3.type === P2WPKH
|
|
804
|
+
);
|
|
805
|
+
setAccounts(leatherAccountsParsed);
|
|
806
|
+
setAddress(String(taprootAddress == null ? void 0 : taprootAddress.address));
|
|
807
|
+
setPublicKey(String(taprootAddress == null ? void 0 : taprootAddress.publicKey));
|
|
808
|
+
setPaymentAddress(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
809
|
+
setPaymentPublicKey(String(segwitAddress == null ? void 0 : segwitAddress.publicKey));
|
|
810
|
+
setLibrary(lib);
|
|
811
|
+
setProvider(LEATHER);
|
|
812
|
+
const balance2 = yield getBTCBalance(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
813
|
+
setBalance(balance2);
|
|
814
|
+
handleAccountsChanged(leatherAccountsParsed);
|
|
815
|
+
setConnected(true);
|
|
816
|
+
yield getNetwork().then((network2) => {
|
|
817
|
+
if (!network2) {
|
|
818
|
+
setNetwork(MAINNET);
|
|
819
|
+
} else {
|
|
820
|
+
setNetwork(network2);
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
setConnected(true);
|
|
824
|
+
} catch (error) {
|
|
825
|
+
new Error(`Can't lasereyes to ${LEATHER} wallet`);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
const connectPhantom = () => __async(void 0, null, function* () {
|
|
829
|
+
try {
|
|
830
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, PHANTOM);
|
|
831
|
+
const lib = window.phantom.bitcoin;
|
|
832
|
+
const phantomAccounts = yield lib.requestAccounts();
|
|
833
|
+
const phantomAccountsParsed = phantomAccounts.map(
|
|
834
|
+
(account) => account.address
|
|
835
|
+
);
|
|
836
|
+
setAccounts(phantomAccountsParsed);
|
|
837
|
+
const ordinalsAccount = phantomAccounts.find(
|
|
838
|
+
(account) => account.purpose === "ordinals"
|
|
839
|
+
);
|
|
840
|
+
const paymentAccount = phantomAccounts.find(
|
|
841
|
+
(account) => account.purpose === "payment"
|
|
842
|
+
);
|
|
843
|
+
setAddress(ordinalsAccount == null ? void 0 : ordinalsAccount.address);
|
|
844
|
+
setPublicKey(ordinalsAccount == null ? void 0 : ordinalsAccount.publicKey);
|
|
845
|
+
setPaymentAddress(paymentAccount == null ? void 0 : paymentAccount.address);
|
|
846
|
+
setPaymentPublicKey(paymentAccount == null ? void 0 : paymentAccount.publicKey);
|
|
847
|
+
setLibrary(lib);
|
|
848
|
+
setProvider(PHANTOM);
|
|
849
|
+
const balance2 = yield getBTCBalance(String(paymentAccount == null ? void 0 : paymentAccount.address));
|
|
850
|
+
setBalance(balance2);
|
|
851
|
+
setConnected(true);
|
|
852
|
+
} catch (error) {
|
|
853
|
+
throw new Error(`Can't lasereyes to ${PHANTOM} wallet`);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
const connectWizz = () => __async(void 0, null, function* () {
|
|
857
|
+
try {
|
|
858
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, WIZZ);
|
|
859
|
+
const lib = window.wizz;
|
|
860
|
+
const wizzAccounts = yield lib.requestAccounts();
|
|
861
|
+
if (!wizzAccounts)
|
|
862
|
+
throw new Error("No accounts found");
|
|
863
|
+
const wizzPubKey = yield lib.getPublicKey();
|
|
864
|
+
if (!wizzPubKey)
|
|
865
|
+
throw new Error("No public key found");
|
|
866
|
+
setAccounts(wizzAccounts);
|
|
867
|
+
setAddress(wizzAccounts[0]);
|
|
868
|
+
setPaymentAddress(wizzAccounts[0]);
|
|
869
|
+
setPublicKey(wizzPubKey);
|
|
870
|
+
setPaymentPublicKey(wizzPubKey);
|
|
871
|
+
setLibrary(lib);
|
|
872
|
+
setProvider(WIZZ);
|
|
873
|
+
setConnected(true);
|
|
874
|
+
const balance2 = yield lib == null ? void 0 : lib.getBalance();
|
|
875
|
+
setBalance(balance2 == null ? void 0 : balance2.total);
|
|
531
876
|
} catch (error) {
|
|
532
877
|
throw error;
|
|
533
878
|
}
|
|
534
|
-
};
|
|
879
|
+
});
|
|
535
880
|
const connect = (walletName) => __async(void 0, null, function* () {
|
|
536
881
|
setIsConnecting(true);
|
|
537
882
|
try {
|
|
@@ -541,8 +886,20 @@ var LaserEyesProvider = ({
|
|
|
541
886
|
yield connectUnisat();
|
|
542
887
|
} else if (walletName === XVERSE) {
|
|
543
888
|
yield connectXverse();
|
|
889
|
+
} else if (walletName === OYL) {
|
|
890
|
+
yield connectOyl();
|
|
891
|
+
} else if (walletName === MAGIC_EDEN) {
|
|
892
|
+
yield connectMagicEden();
|
|
893
|
+
} else if (walletName === OKX) {
|
|
894
|
+
yield connectOkx();
|
|
895
|
+
} else if (walletName === LEATHER) {
|
|
896
|
+
yield connectLeather();
|
|
897
|
+
} else if (walletName === PHANTOM) {
|
|
898
|
+
yield connectPhantom();
|
|
899
|
+
} else if (walletName === WIZZ) {
|
|
900
|
+
yield connectWizz();
|
|
544
901
|
} else {
|
|
545
|
-
throw new Error("
|
|
902
|
+
throw new Error("Unsupported wallet..");
|
|
546
903
|
}
|
|
547
904
|
setConnected(true);
|
|
548
905
|
} catch (error) {
|
|
@@ -565,6 +922,43 @@ var LaserEyesProvider = ({
|
|
|
565
922
|
setBalance(void 0);
|
|
566
923
|
localStorage == null ? void 0 : localStorage.removeItem(LOCAL_STORAGE_DEFAULT_WALLET);
|
|
567
924
|
};
|
|
925
|
+
const handleAccountsChanged = (_accounts) => {
|
|
926
|
+
if (provider !== UNISAT)
|
|
927
|
+
return;
|
|
928
|
+
if (!_accounts.length) {
|
|
929
|
+
disconnect();
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
if (self.accounts[0] === _accounts[0]) {
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
self.accounts = _accounts;
|
|
936
|
+
if (_accounts.length > 0) {
|
|
937
|
+
connect(UNISAT);
|
|
938
|
+
} else {
|
|
939
|
+
setConnected(false);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
const handleNetworkChanged = (network2) => {
|
|
943
|
+
try {
|
|
944
|
+
let foundNetwork = MAINNET;
|
|
945
|
+
if (provider === UNISAT) {
|
|
946
|
+
foundNetwork = getNetworkForUnisat(network2);
|
|
947
|
+
setNetwork(foundNetwork);
|
|
948
|
+
connect(provider);
|
|
949
|
+
} else if (provider === XVERSE) {
|
|
950
|
+
throw new Error("Not implemented");
|
|
951
|
+
} else if (provider === WIZZ) {
|
|
952
|
+
foundNetwork = getNetworkForWizz(network2);
|
|
953
|
+
setNetwork(foundNetwork);
|
|
954
|
+
connect(provider);
|
|
955
|
+
} else {
|
|
956
|
+
throw new Error("The connected wallet doesn't support this method..");
|
|
957
|
+
}
|
|
958
|
+
} catch (error) {
|
|
959
|
+
throw error;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
568
962
|
const requestAccounts = () => __async(void 0, null, function* () {
|
|
569
963
|
try {
|
|
570
964
|
if (!library)
|
|
@@ -594,6 +988,50 @@ var LaserEyesProvider = ({
|
|
|
594
988
|
}
|
|
595
989
|
};
|
|
596
990
|
return [address2];
|
|
991
|
+
} else if (provider === OYL) {
|
|
992
|
+
return yield library.requestAccounts();
|
|
993
|
+
} else if (provider === OKX) {
|
|
994
|
+
return yield library.requestAccounts();
|
|
995
|
+
} else if (provider === LEATHER) {
|
|
996
|
+
localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_DEFAULT_WALLET, LEATHER);
|
|
997
|
+
const lib = window.LeatherProvider;
|
|
998
|
+
const getAddressesResponse = yield lib.request(
|
|
999
|
+
"getAddresses"
|
|
1000
|
+
);
|
|
1001
|
+
const addressesResponse = getAddressesResponse.result;
|
|
1002
|
+
const addresses = addressesResponse.addresses;
|
|
1003
|
+
const leatherAccountsParsed = addresses.map(
|
|
1004
|
+
(address3) => address3.address
|
|
1005
|
+
);
|
|
1006
|
+
const taprootAddress = addresses.find(
|
|
1007
|
+
(address3) => address3.type === P2TR
|
|
1008
|
+
);
|
|
1009
|
+
const segwitAddress = addresses.find(
|
|
1010
|
+
(address3) => address3.type === P2WPKH
|
|
1011
|
+
);
|
|
1012
|
+
setAccounts(leatherAccountsParsed);
|
|
1013
|
+
setAddress(String(taprootAddress == null ? void 0 : taprootAddress.address));
|
|
1014
|
+
setPaymentAddress(String(segwitAddress == null ? void 0 : segwitAddress.address));
|
|
1015
|
+
setLibrary(lib);
|
|
1016
|
+
setProvider(LEATHER);
|
|
1017
|
+
handleAccountsChanged(leatherAccountsParsed);
|
|
1018
|
+
setConnected(true);
|
|
1019
|
+
yield getNetwork().then((network2) => {
|
|
1020
|
+
if (!network2) {
|
|
1021
|
+
setNetwork(MAINNET);
|
|
1022
|
+
} else {
|
|
1023
|
+
setNetwork(network2);
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
setConnected(true);
|
|
1027
|
+
} else if (provider === PHANTOM) {
|
|
1028
|
+
const phantomAccounts = yield library.requestAccounts();
|
|
1029
|
+
const phantomAccountsParsed = phantomAccounts.map(
|
|
1030
|
+
(account) => account.address
|
|
1031
|
+
);
|
|
1032
|
+
return phantomAccountsParsed;
|
|
1033
|
+
} else if (provider === WIZZ) {
|
|
1034
|
+
return yield library.requestAccounts();
|
|
597
1035
|
} else {
|
|
598
1036
|
throw new Error("The connected wallet doesn't support this method..");
|
|
599
1037
|
}
|
|
@@ -616,6 +1054,34 @@ var LaserEyesProvider = ({
|
|
|
616
1054
|
return TESTNET;
|
|
617
1055
|
}
|
|
618
1056
|
return MAINNET;
|
|
1057
|
+
} else if (provider === OYL) {
|
|
1058
|
+
if (address2.slice(0, 1) === "t") {
|
|
1059
|
+
return TESTNET;
|
|
1060
|
+
}
|
|
1061
|
+
return MAINNET;
|
|
1062
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1063
|
+
if (address2.slice(0, 1) === "t") {
|
|
1064
|
+
return TESTNET;
|
|
1065
|
+
}
|
|
1066
|
+
return MAINNET;
|
|
1067
|
+
} else if (provider === OKX) {
|
|
1068
|
+
const okxNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
1069
|
+
const foundNetwork = getNetworkForOkx(okxNetwork);
|
|
1070
|
+
setNetwork(foundNetwork);
|
|
1071
|
+
} else if (provider === LEATHER) {
|
|
1072
|
+
if (address2.slice(0, 1) === "t") {
|
|
1073
|
+
return TESTNET;
|
|
1074
|
+
}
|
|
1075
|
+
return MAINNET;
|
|
1076
|
+
} else if (provider === PHANTOM) {
|
|
1077
|
+
if (address2.slice(0, 1) === "t") {
|
|
1078
|
+
return TESTNET;
|
|
1079
|
+
}
|
|
1080
|
+
return MAINNET;
|
|
1081
|
+
} else if (provider === WIZZ) {
|
|
1082
|
+
const wizzNetwork = yield library == null ? void 0 : library.getNetwork();
|
|
1083
|
+
const foundNetwork = getNetworkForWizz(wizzNetwork);
|
|
1084
|
+
setNetwork(foundNetwork);
|
|
619
1085
|
}
|
|
620
1086
|
return (_a = config == null ? void 0 : config.network) != null ? _a : MAINNET;
|
|
621
1087
|
} catch (error) {
|
|
@@ -627,7 +1093,11 @@ var LaserEyesProvider = ({
|
|
|
627
1093
|
if (!library)
|
|
628
1094
|
return;
|
|
629
1095
|
if (provider === UNISAT) {
|
|
630
|
-
const wantedNetwork =
|
|
1096
|
+
const wantedNetwork = getWizzNetwork(network2);
|
|
1097
|
+
yield library == null ? void 0 : library.switchNetwork(wantedNetwork);
|
|
1098
|
+
setNetwork(network2);
|
|
1099
|
+
} else if (provider === WIZZ) {
|
|
1100
|
+
const wantedNetwork = getNetworkForWizz(network2);
|
|
631
1101
|
yield library == null ? void 0 : library.switchNetwork(wantedNetwork);
|
|
632
1102
|
setNetwork(network2);
|
|
633
1103
|
} else {
|
|
@@ -642,7 +1112,12 @@ var LaserEyesProvider = ({
|
|
|
642
1112
|
if (!library)
|
|
643
1113
|
return;
|
|
644
1114
|
if (provider === UNISAT) {
|
|
645
|
-
|
|
1115
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1116
|
+
} else if (provider === OYL) {
|
|
1117
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1118
|
+
} else if (provider === OKX) {
|
|
1119
|
+
return yield library == null ? void 0 : library.getPublicKey();
|
|
1120
|
+
} else if (provider === WIZZ) {
|
|
646
1121
|
return yield library == null ? void 0 : library.getPublicKey();
|
|
647
1122
|
} else {
|
|
648
1123
|
throw new Error("The connected wallet doesn't support this method..");
|
|
@@ -659,6 +1134,20 @@ var LaserEyesProvider = ({
|
|
|
659
1134
|
return yield library.getBalance();
|
|
660
1135
|
} else if (provider === XVERSE) {
|
|
661
1136
|
return yield getBTCBalance(paymentAddress);
|
|
1137
|
+
} else if (provider === OYL) {
|
|
1138
|
+
const balanceResponse = yield library.getBalance();
|
|
1139
|
+
return balanceResponse.btc.total * 1e8;
|
|
1140
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1141
|
+
return yield getBTCBalance(paymentAddress);
|
|
1142
|
+
} else if (provider === OKX) {
|
|
1143
|
+
return yield getBTCBalance(paymentAddress);
|
|
1144
|
+
} else if (provider === LEATHER) {
|
|
1145
|
+
return yield getBTCBalance(paymentAddress);
|
|
1146
|
+
} else if (provider === PHANTOM) {
|
|
1147
|
+
return yield getBTCBalance(paymentAddress);
|
|
1148
|
+
} else if (provider === WIZZ) {
|
|
1149
|
+
const balanceResponse = yield library.getBalance();
|
|
1150
|
+
return balanceResponse.total * 1e8;
|
|
662
1151
|
}
|
|
663
1152
|
} catch (error) {
|
|
664
1153
|
throw error;
|
|
@@ -670,6 +1159,12 @@ var LaserEyesProvider = ({
|
|
|
670
1159
|
return;
|
|
671
1160
|
if (provider === UNISAT) {
|
|
672
1161
|
return yield library.getInscriptions(0, 10);
|
|
1162
|
+
} else if (provider === OYL) {
|
|
1163
|
+
return yield library.getInscriptions(0, 10);
|
|
1164
|
+
} else if (provider === OKX) {
|
|
1165
|
+
return yield library.getInscriptions(0, 10);
|
|
1166
|
+
} else if (provider === WIZZ) {
|
|
1167
|
+
return yield library.getInscriptions(0, 10);
|
|
673
1168
|
} else {
|
|
674
1169
|
throw new Error("The connected wallet doesn't support this method..");
|
|
675
1170
|
}
|
|
@@ -678,6 +1173,7 @@ var LaserEyesProvider = ({
|
|
|
678
1173
|
}
|
|
679
1174
|
});
|
|
680
1175
|
const sendBTC = (to, amount) => __async(void 0, null, function* () {
|
|
1176
|
+
var _a;
|
|
681
1177
|
try {
|
|
682
1178
|
if (amount <= 0)
|
|
683
1179
|
throw new Error("Amount must be greater than 0");
|
|
@@ -695,7 +1191,7 @@ var LaserEyesProvider = ({
|
|
|
695
1191
|
recipients: [
|
|
696
1192
|
{
|
|
697
1193
|
address: to,
|
|
698
|
-
amount
|
|
1194
|
+
amount
|
|
699
1195
|
}
|
|
700
1196
|
]
|
|
701
1197
|
});
|
|
@@ -708,12 +1204,73 @@ var LaserEyesProvider = ({
|
|
|
708
1204
|
throw new Error("Error sending BTC: " + response.error.message);
|
|
709
1205
|
}
|
|
710
1206
|
}
|
|
1207
|
+
} else if (provider === OYL) {
|
|
1208
|
+
const { psbtHex, psbtBase64 } = yield createSendBtcPsbt(
|
|
1209
|
+
address2,
|
|
1210
|
+
paymentAddress,
|
|
1211
|
+
to,
|
|
1212
|
+
amount,
|
|
1213
|
+
paymentPublicKey,
|
|
1214
|
+
//@ts-ignore
|
|
1215
|
+
network,
|
|
1216
|
+
7
|
|
1217
|
+
);
|
|
1218
|
+
const psbt = yield signPsbt(psbtBase64, true, true);
|
|
1219
|
+
if (!psbt)
|
|
1220
|
+
throw new Error("Error sending BTC");
|
|
1221
|
+
return psbt.txId;
|
|
1222
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1223
|
+
const { psbtHex, psbtBase64 } = yield createSendBtcPsbt(
|
|
1224
|
+
address2,
|
|
1225
|
+
paymentAddress,
|
|
1226
|
+
to,
|
|
1227
|
+
amount,
|
|
1228
|
+
paymentPublicKey,
|
|
1229
|
+
//@ts-ignore
|
|
1230
|
+
network,
|
|
1231
|
+
7
|
|
1232
|
+
);
|
|
1233
|
+
const psbt = yield signPsbt(psbtBase64, true, true);
|
|
1234
|
+
if (!psbt)
|
|
1235
|
+
throw new Error("Error sending BTC");
|
|
1236
|
+
return psbt.txId;
|
|
1237
|
+
} else if (provider === OKX) {
|
|
1238
|
+
const txId = yield library == null ? void 0 : library.sendBitcoin(to, amount);
|
|
1239
|
+
if (!txId)
|
|
1240
|
+
throw new Error("Transaction failed");
|
|
1241
|
+
return txId;
|
|
1242
|
+
} else if (provider === LEATHER) {
|
|
1243
|
+
const response = yield library == null ? void 0 : library.request("sendTransfer", {
|
|
1244
|
+
recipients: [
|
|
1245
|
+
{
|
|
1246
|
+
address: to,
|
|
1247
|
+
amount
|
|
1248
|
+
}
|
|
1249
|
+
]
|
|
1250
|
+
});
|
|
1251
|
+
if ((_a = response == null ? void 0 : response.result) == null ? void 0 : _a.txid) {
|
|
1252
|
+
return response.result.txid;
|
|
1253
|
+
} else {
|
|
1254
|
+
if (response.error.code === import_sats_connect.RpcErrorCode.USER_REJECTION) {
|
|
1255
|
+
throw new Error("User rejected the request");
|
|
1256
|
+
} else {
|
|
1257
|
+
throw new Error("Error sending BTC: " + response.error.message);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
} else if (provider === WIZZ) {
|
|
1261
|
+
const txId = yield library == null ? void 0 : library.sendBitcoin(to, amount);
|
|
1262
|
+
if (txId) {
|
|
1263
|
+
return txId;
|
|
1264
|
+
} else {
|
|
1265
|
+
throw new Error("Error sending BTC");
|
|
1266
|
+
}
|
|
711
1267
|
}
|
|
712
1268
|
} catch (error) {
|
|
713
1269
|
throw error;
|
|
714
1270
|
}
|
|
715
1271
|
});
|
|
716
1272
|
const signMessage = (message) => __async(void 0, null, function* () {
|
|
1273
|
+
var _a;
|
|
717
1274
|
try {
|
|
718
1275
|
if (!library)
|
|
719
1276
|
return;
|
|
@@ -733,6 +1290,26 @@ var LaserEyesProvider = ({
|
|
|
733
1290
|
throw new Error("Error signing message: " + response.error.message);
|
|
734
1291
|
}
|
|
735
1292
|
}
|
|
1293
|
+
} else if (provider === OKX) {
|
|
1294
|
+
return yield library == null ? void 0 : library.signMessage(message);
|
|
1295
|
+
} else if (provider === LEATHER) {
|
|
1296
|
+
const signed = yield library == null ? void 0 : library.request("signMessage", {
|
|
1297
|
+
message,
|
|
1298
|
+
paymentType: P2TR
|
|
1299
|
+
});
|
|
1300
|
+
console.log(signed);
|
|
1301
|
+
return (_a = signed == null ? void 0 : signed.result) == null ? void 0 : _a.signature;
|
|
1302
|
+
} else if (provider === PHANTOM) {
|
|
1303
|
+
const utf8Bytes = new TextEncoder().encode(message);
|
|
1304
|
+
const uintArray = new Uint8Array(utf8Bytes);
|
|
1305
|
+
const response = yield library == null ? void 0 : library.signMessage(address2, uintArray);
|
|
1306
|
+
console.log(response);
|
|
1307
|
+
const binaryString = String.fromCharCode(...response.signature);
|
|
1308
|
+
return btoa(binaryString);
|
|
1309
|
+
} else if (provider === WIZZ) {
|
|
1310
|
+
return yield library == null ? void 0 : library.signMessage(message);
|
|
1311
|
+
} else {
|
|
1312
|
+
throw new Error("The connected wallet doesn't support this method..");
|
|
736
1313
|
}
|
|
737
1314
|
} catch (error) {
|
|
738
1315
|
throw error;
|
|
@@ -850,11 +1427,203 @@ var LaserEyesProvider = ({
|
|
|
850
1427
|
signedPsbtBase64,
|
|
851
1428
|
txId
|
|
852
1429
|
};
|
|
1430
|
+
} else if (provider === OYL) {
|
|
1431
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, true, true);
|
|
1432
|
+
console.log({ signedPsbt });
|
|
1433
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1434
|
+
console.log("psbtSignedPsbt", psbtSignedPsbt.toBase64());
|
|
1435
|
+
if (broadcast) {
|
|
1436
|
+
console.log("broadcastin");
|
|
1437
|
+
const txId = yield pushPsbt(psbtSignedPsbt.toHex());
|
|
1438
|
+
return {
|
|
1439
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1440
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1441
|
+
txId
|
|
1442
|
+
};
|
|
1443
|
+
} else {
|
|
1444
|
+
return {
|
|
1445
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1446
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1447
|
+
txId: void 0
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1451
|
+
const toSignPsbt = bitcoin2.Psbt.fromBase64(String(psbtBase64), {
|
|
1452
|
+
network: getBitcoinNetwork(network)
|
|
1453
|
+
});
|
|
1454
|
+
const inputs = toSignPsbt.data.inputs;
|
|
1455
|
+
const inputsToSign = [];
|
|
1456
|
+
const ordinalAddressData = {
|
|
1457
|
+
address: address2,
|
|
1458
|
+
signingIndexes: []
|
|
1459
|
+
};
|
|
1460
|
+
const paymentsAddressData = {
|
|
1461
|
+
address: paymentAddress,
|
|
1462
|
+
signingIndexes: []
|
|
1463
|
+
};
|
|
1464
|
+
let counter = 0;
|
|
1465
|
+
try {
|
|
1466
|
+
for (var iter2 = __forAwait(inputs), more2, temp2, error2; more2 = !(temp2 = yield iter2.next()).done; more2 = false) {
|
|
1467
|
+
let input = temp2.value;
|
|
1468
|
+
const { script } = input.witnessUtxo;
|
|
1469
|
+
const addressFromScript = (0, import_address.fromOutputScript)(
|
|
1470
|
+
script,
|
|
1471
|
+
getBitcoinNetwork(network)
|
|
1472
|
+
);
|
|
1473
|
+
if (addressFromScript === paymentAddress) {
|
|
1474
|
+
paymentsAddressData.signingIndexes.push(Number(counter));
|
|
1475
|
+
} else if (addressFromScript === address2) {
|
|
1476
|
+
ordinalAddressData.signingIndexes.push(Number(counter));
|
|
1477
|
+
}
|
|
1478
|
+
counter++;
|
|
1479
|
+
}
|
|
1480
|
+
} catch (temp2) {
|
|
1481
|
+
error2 = [temp2];
|
|
1482
|
+
} finally {
|
|
1483
|
+
try {
|
|
1484
|
+
more2 && (temp2 = iter2.return) && (yield temp2.call(iter2));
|
|
1485
|
+
} finally {
|
|
1486
|
+
if (error2)
|
|
1487
|
+
throw error2[0];
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
if (ordinalAddressData.signingIndexes.length > 0) {
|
|
1491
|
+
inputsToSign.push(ordinalAddressData);
|
|
1492
|
+
}
|
|
1493
|
+
if (paymentsAddressData.signingIndexes.length > 0) {
|
|
1494
|
+
inputsToSign.push(paymentsAddressData);
|
|
1495
|
+
}
|
|
1496
|
+
let txId, signedPsbtHex, signedPsbtBase64;
|
|
1497
|
+
const xverseNetwork = getXverseNetwork(network);
|
|
1498
|
+
const signPsbtOptions = {
|
|
1499
|
+
getProvider: () => __async(void 0, null, function* () {
|
|
1500
|
+
return window.magicEden.bitcoin;
|
|
1501
|
+
}),
|
|
1502
|
+
payload: {
|
|
1503
|
+
network: {
|
|
1504
|
+
type: xverseNetwork
|
|
1505
|
+
},
|
|
1506
|
+
message: "Sign Transaction",
|
|
1507
|
+
psbtBase64: toSignPsbt.toBase64(),
|
|
1508
|
+
broadcast,
|
|
1509
|
+
inputsToSign
|
|
1510
|
+
},
|
|
1511
|
+
onFinish: (response) => {
|
|
1512
|
+
if (response.psbtBase64) {
|
|
1513
|
+
const signedPsbt = bitcoin2.Psbt.fromBase64(
|
|
1514
|
+
String(response.psbtBase64),
|
|
1515
|
+
{
|
|
1516
|
+
network: getBitcoinNetwork(network)
|
|
1517
|
+
}
|
|
1518
|
+
);
|
|
1519
|
+
signedPsbtHex = signedPsbt.toHex();
|
|
1520
|
+
signedPsbtBase64 = signedPsbt.toBase64();
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
onCancel: () => {
|
|
1524
|
+
console.log("Canceled");
|
|
1525
|
+
throw new Error("User canceled the request");
|
|
1526
|
+
},
|
|
1527
|
+
onError: (error3) => {
|
|
1528
|
+
console.log("error", error3);
|
|
1529
|
+
throw error3;
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
yield (0, import_sats_connect.signTransaction)(signPsbtOptions);
|
|
1533
|
+
if (broadcast) {
|
|
1534
|
+
const signed = bitcoin2.Psbt.fromBase64(String(signedPsbtBase64));
|
|
1535
|
+
const finalized = signed.finalizeAllInputs();
|
|
1536
|
+
const extracted = finalized.extractTransaction();
|
|
1537
|
+
const txId2 = yield pushPsbt(extracted.toHex());
|
|
1538
|
+
return {
|
|
1539
|
+
signedPsbtHex: extracted.toHex(),
|
|
1540
|
+
signedPsbtBase64: "test",
|
|
1541
|
+
txId: txId2
|
|
1542
|
+
};
|
|
1543
|
+
} else {
|
|
1544
|
+
return {
|
|
1545
|
+
signedPsbtHex,
|
|
1546
|
+
signedPsbtBase64,
|
|
1547
|
+
txId
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
} else if (provider === OKX) {
|
|
1551
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, {
|
|
1552
|
+
autoFinalized: finalize
|
|
1553
|
+
});
|
|
1554
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1555
|
+
if (finalize && broadcast) {
|
|
1556
|
+
const txId = yield pushPsbt(signedPsbt);
|
|
1557
|
+
return {
|
|
1558
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1559
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1560
|
+
txId
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
return {
|
|
1564
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1565
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1566
|
+
txId: void 0
|
|
1567
|
+
};
|
|
1568
|
+
} else if (provider === LEATHER) {
|
|
1569
|
+
const requestParams = {
|
|
1570
|
+
hex: psbtHex,
|
|
1571
|
+
broadcast
|
|
1572
|
+
};
|
|
1573
|
+
const response = yield library == null ? void 0 : library.request(
|
|
1574
|
+
"signPsbt",
|
|
1575
|
+
requestParams
|
|
1576
|
+
);
|
|
1577
|
+
const leatherHexResult = response.result;
|
|
1578
|
+
const signedTx = leatherHexResult.hex;
|
|
1579
|
+
const signed = bitcoin2.Psbt.fromBase64(String(signedTx));
|
|
1580
|
+
if (finalize && broadcast) {
|
|
1581
|
+
const finalized = signed.finalizeAllInputs();
|
|
1582
|
+
const extracted = finalized.extractTransaction();
|
|
1583
|
+
const txId = yield pushPsbt(extracted.toHex());
|
|
1584
|
+
return {
|
|
1585
|
+
signedPsbtHex: signed.toHex(),
|
|
1586
|
+
signedPsbtBase64: signed.toBase64(),
|
|
1587
|
+
txId
|
|
1588
|
+
};
|
|
1589
|
+
} else if (finalize) {
|
|
1590
|
+
const finalized = signed.finalizeAllInputs();
|
|
1591
|
+
return {
|
|
1592
|
+
signedPsbtHex: finalized.toHex(),
|
|
1593
|
+
signedPsbtBase64: finalized.toBase64(),
|
|
1594
|
+
txId: void 0
|
|
1595
|
+
};
|
|
1596
|
+
} else {
|
|
1597
|
+
return {
|
|
1598
|
+
signedPsbtHex: signed.toHex(),
|
|
1599
|
+
signedPsbtBase64: signed.toBase64(),
|
|
1600
|
+
txId: void 0
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
} else if (provider === WIZZ) {
|
|
1604
|
+
const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, {
|
|
1605
|
+
autoFinalized: finalize,
|
|
1606
|
+
broadcast: false
|
|
1607
|
+
});
|
|
1608
|
+
const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
|
|
1609
|
+
if (finalize && broadcast) {
|
|
1610
|
+
const txId = yield pushPsbt(signedPsbt);
|
|
1611
|
+
return {
|
|
1612
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1613
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1614
|
+
txId
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
return {
|
|
1618
|
+
signedPsbtHex: psbtSignedPsbt.toHex(),
|
|
1619
|
+
signedPsbtBase64: psbtSignedPsbt.toBase64(),
|
|
1620
|
+
txId: void 0
|
|
1621
|
+
};
|
|
853
1622
|
} else {
|
|
854
1623
|
throw new Error("The connected wallet doesn't support this method..");
|
|
855
1624
|
}
|
|
856
|
-
} catch (
|
|
857
|
-
throw
|
|
1625
|
+
} catch (error3) {
|
|
1626
|
+
throw error3;
|
|
858
1627
|
}
|
|
859
1628
|
});
|
|
860
1629
|
const pushPsbt = (psbt) => __async(void 0, null, function* () {
|
|
@@ -863,6 +1632,16 @@ var LaserEyesProvider = ({
|
|
|
863
1632
|
return;
|
|
864
1633
|
if (provider === UNISAT) {
|
|
865
1634
|
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1635
|
+
} else if (provider === OYL) {
|
|
1636
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1637
|
+
} else if (provider === OKX) {
|
|
1638
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
1639
|
+
} else if (provider === MAGIC_EDEN) {
|
|
1640
|
+
return yield import_axios2.default.post("https://mempool.space/api/tx", psbt).then((res) => res.data);
|
|
1641
|
+
} else if (provider === LEATHER) {
|
|
1642
|
+
return yield import_axios2.default.post("https://mempool.space/api/tx", psbt).then((res) => res.data);
|
|
1643
|
+
} else if (provider === WIZZ) {
|
|
1644
|
+
return yield library == null ? void 0 : library.pushPsbt(psbt);
|
|
866
1645
|
} else {
|
|
867
1646
|
throw new Error("The connected wallet doesn't support this method..");
|
|
868
1647
|
}
|
|
@@ -887,6 +1666,12 @@ var LaserEyesProvider = ({
|
|
|
887
1666
|
isConnecting,
|
|
888
1667
|
hasUnisat,
|
|
889
1668
|
hasXverse,
|
|
1669
|
+
hasOyl,
|
|
1670
|
+
hasMagicEden,
|
|
1671
|
+
hasOkx,
|
|
1672
|
+
hasLeather,
|
|
1673
|
+
hasPhantom,
|
|
1674
|
+
hasWizz,
|
|
890
1675
|
// functions
|
|
891
1676
|
connect,
|
|
892
1677
|
disconnect,
|
|
@@ -911,9 +1696,13 @@ var LaserEyesProvider = ({
|
|
|
911
1696
|
LEATHER_MAINNET,
|
|
912
1697
|
LEATHER_TESTNET,
|
|
913
1698
|
LaserEyesProvider,
|
|
1699
|
+
MAGIC_EDEN,
|
|
914
1700
|
MAINNET,
|
|
915
1701
|
MEMPOOL_SPACE_TESTNET_URL,
|
|
916
1702
|
MEMPOOL_SPACE_URL,
|
|
1703
|
+
OKX,
|
|
1704
|
+
OKX_MAINNET,
|
|
1705
|
+
OKX_TESTNET,
|
|
917
1706
|
OYL,
|
|
918
1707
|
P2PKH,
|
|
919
1708
|
P2PSH,
|
|
@@ -923,27 +1712,38 @@ var LaserEyesProvider = ({
|
|
|
923
1712
|
P2WSH,
|
|
924
1713
|
PHANTOM,
|
|
925
1714
|
REGTEST,
|
|
1715
|
+
SIGNET,
|
|
926
1716
|
TESTNET,
|
|
927
1717
|
UNISAT,
|
|
928
1718
|
UNISAT_MAINNET,
|
|
929
1719
|
UNISAT_TESTNET,
|
|
930
1720
|
WALLETS,
|
|
1721
|
+
WIZZ,
|
|
1722
|
+
WIZZ_MAINNET,
|
|
1723
|
+
WIZZ_TESTNET,
|
|
931
1724
|
XVERSE,
|
|
932
1725
|
XVERSE_MAINNET,
|
|
933
1726
|
XVERSE_NETWORK,
|
|
934
1727
|
XVERSE_TESTNET,
|
|
935
1728
|
createConfig,
|
|
1729
|
+
createSendBtcPsbt,
|
|
1730
|
+
estimateTxSize,
|
|
936
1731
|
findOrdinalsAddress,
|
|
937
1732
|
findPaymentAddress,
|
|
938
1733
|
getAddressType,
|
|
1734
|
+
getAddressUtxos,
|
|
939
1735
|
getBTCBalance,
|
|
940
1736
|
getBitcoinNetwork,
|
|
941
1737
|
getLeatherNetwork,
|
|
942
1738
|
getMempoolSpaceUrl,
|
|
943
1739
|
getNetworkForLeather,
|
|
1740
|
+
getNetworkForOkx,
|
|
944
1741
|
getNetworkForUnisat,
|
|
1742
|
+
getNetworkForWizz,
|
|
945
1743
|
getNetworkForXverse,
|
|
1744
|
+
getRedeemScript,
|
|
946
1745
|
getUnisatNetwork,
|
|
1746
|
+
getWizzNetwork,
|
|
947
1747
|
getXverseNetwork,
|
|
948
1748
|
isBase64,
|
|
949
1749
|
isHex,
|