@arkade-os/sdk 0.4.76 → 0.4.77
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/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +3 -5
- package/dist/adapters/indexedDB.cjs.map +1 -1
- package/dist/adapters/indexedDB.d.cts +1 -1
- package/dist/adapters/indexedDB.d.ts +1 -1
- package/dist/adapters/indexedDB.js +3 -5
- package/dist/adapters/indexedDB.js.map +1 -1
- package/dist/{asyncStorageTaskQueue-DrKbfleJ.d.ts → asyncStorageTaskQueue-DTl0WM7E.d.ts} +1 -1
- package/dist/{asyncStorageTaskQueue-D7BU-BdP.d.cts → asyncStorageTaskQueue-MmJyAnu-.d.cts} +1 -1
- package/dist/{chunk-2KFXM3N5.cjs → chunk-4LP6XOMW.cjs} +17 -17
- package/dist/{chunk-2KFXM3N5.cjs.map → chunk-4LP6XOMW.cjs.map} +1 -1
- package/dist/{chunk-F6YOCYWU.js → chunk-52OA3UIC.js} +25 -12
- package/dist/chunk-52OA3UIC.js.map +1 -0
- package/dist/{chunk-7UJLIZQU.js → chunk-ACPANSOX.js} +43 -11
- package/dist/chunk-ACPANSOX.js.map +1 -0
- package/dist/{chunk-P53OHGXY.cjs → chunk-CJN4CUEU.cjs} +25 -11
- package/dist/chunk-CJN4CUEU.cjs.map +1 -0
- package/dist/{chunk-T327OEMV.cjs → chunk-H62OOAS4.cjs} +17 -17
- package/dist/{chunk-T327OEMV.cjs.map → chunk-H62OOAS4.cjs.map} +1 -1
- package/dist/{chunk-54W6QBXL.js → chunk-HKOFYHZP.js} +3 -3
- package/dist/{chunk-54W6QBXL.js.map → chunk-HKOFYHZP.js.map} +1 -1
- package/dist/{chunk-CQNX4BTA.cjs → chunk-LUWSY2QO.cjs} +89 -57
- package/dist/chunk-LUWSY2QO.cjs.map +1 -0
- package/dist/{chunk-WMHELOHH.js → chunk-MLOZHTBN.js} +523 -104
- package/dist/chunk-MLOZHTBN.js.map +1 -0
- package/dist/{chunk-O2BIWLZC.js → chunk-T6MGH4V4.js} +4 -4
- package/dist/{chunk-O2BIWLZC.js.map → chunk-T6MGH4V4.js.map} +1 -1
- package/dist/{chunk-LQM6RHNT.cjs → chunk-Y4YK44IM.cjs} +10 -10
- package/dist/{chunk-LQM6RHNT.cjs.map → chunk-Y4YK44IM.cjs.map} +1 -1
- package/dist/{chunk-LHSVPDFJ.cjs → chunk-YJEWWLOQ.cjs} +959 -541
- package/dist/chunk-YJEWWLOQ.cjs.map +1 -0
- package/dist/{chunk-MUBPGYUE.js → chunk-YKNTUOUG.js} +4 -4
- package/dist/{chunk-MUBPGYUE.js.map → chunk-YKNTUOUG.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +9 -9
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-BAYpqkEx.d.ts → delegate-CjcysR7s.d.ts} +1 -1
- package/dist/{delegate-CR7msIXK.d.cts → delegate-QPCGaD_z.d.cts} +1 -1
- package/dist/{hdWalletCapable-BSF29IjK.d.ts → hdWalletCapable--pMncWbC.d.ts} +6 -4
- package/dist/{hdWalletCapable-BbZxCUeZ.d.cts → hdWalletCapable-Bp_p0WLj.d.cts} +6 -4
- package/dist/{index-4NF3srcg.d.cts → index-BMY272ns.d.cts} +26 -8
- package/dist/{index-B_RYn9rg.d.cts → index-Ie_ak2zY.d.cts} +35 -9
- package/dist/{index-B_RYn9rg.d.ts → index-Ie_ak2zY.d.ts} +35 -9
- package/dist/{index-Dj2yOhQ2.d.ts → index-m-EM-e8D.d.ts} +26 -8
- package/dist/index.cjs +307 -303
- package/dist/index.d.cts +75 -13
- package/dist/index.d.ts +75 -13
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +36 -19
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +6 -3
- package/dist/repositories/realm/index.d.ts +6 -3
- package/dist/repositories/realm/index.js +22 -5
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +42 -18
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +5 -2
- package/dist/repositories/sqlite/index.d.ts +5 -2
- package/dist/repositories/sqlite/index.js +29 -5
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-DGxde-YU.d.cts → taskRunner-BgRowCqB.d.cts} +1 -1
- package/dist/{taskRunner-TzGUhxP-.d.ts → taskRunner-CqrlrJEt.d.ts} +1 -1
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +5 -5
- package/dist/wallet/expo/index.d.ts +5 -5
- package/dist/wallet/expo/index.js +5 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-7UJLIZQU.js.map +0 -1
- package/dist/chunk-CQNX4BTA.cjs.map +0 -1
- package/dist/chunk-F6YOCYWU.js.map +0 -1
- package/dist/chunk-LHSVPDFJ.cjs.map +0 -1
- package/dist/chunk-P53OHGXY.cjs.map +0 -1
- package/dist/chunk-WMHELOHH.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkH62OOAS4_cjs = require('./chunk-H62OOAS4.cjs');
|
|
4
|
+
var chunkLUWSY2QO_cjs = require('./chunk-LUWSY2QO.cjs');
|
|
5
|
+
var chunkCJN4CUEU_cjs = require('./chunk-CJN4CUEU.cjs');
|
|
6
6
|
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
7
7
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
8
8
|
var btcSigner = require('@scure/btc-signer');
|
|
@@ -188,7 +188,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
188
188
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
189
189
|
const tx = this.graph.find(txid);
|
|
190
190
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
191
|
-
const cosigners =
|
|
191
|
+
const cosigners = chunkCJN4CUEU_cjs.getArkPsbtFields(tx.root, 0, chunkCJN4CUEU_cjs.CosignerPublicKey).map(
|
|
192
192
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
193
193
|
// xonly pubkey
|
|
194
194
|
);
|
|
@@ -240,7 +240,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
240
240
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
241
241
|
const prevoutAmounts = [];
|
|
242
242
|
const prevoutScripts = [];
|
|
243
|
-
const cosigners =
|
|
243
|
+
const cosigners = chunkCJN4CUEU_cjs.getArkPsbtFields(g.root, 0, chunkCJN4CUEU_cjs.CosignerPublicKey).map((c) => c.key);
|
|
244
244
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
245
245
|
taprootTweak: this.scriptRoot
|
|
246
246
|
});
|
|
@@ -323,7 +323,7 @@ var SingleKey = class _SingleKey {
|
|
|
323
323
|
async sign(tx, inputIndexes) {
|
|
324
324
|
const txCpy = tx.clone();
|
|
325
325
|
if (!inputIndexes) {
|
|
326
|
-
|
|
326
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
|
|
327
327
|
try {
|
|
328
328
|
if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
|
|
329
329
|
throw new Error("Failed to sign transaction");
|
|
@@ -432,7 +432,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
432
432
|
let network;
|
|
433
433
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
434
434
|
descriptor = opts.descriptor;
|
|
435
|
-
network =
|
|
435
|
+
network = chunkLUWSY2QO_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
436
436
|
} else {
|
|
437
437
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
438
438
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -530,7 +530,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
530
530
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
531
531
|
*/
|
|
532
532
|
isOurs(descriptor) {
|
|
533
|
-
return
|
|
533
|
+
return chunkLUWSY2QO_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
536
536
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -579,7 +579,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
579
579
|
}
|
|
580
580
|
// ── internal helpers ─────────────────────────────────────────────
|
|
581
581
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
582
|
-
const network =
|
|
582
|
+
const network = chunkLUWSY2QO_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
583
583
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
584
584
|
if (expansion.isRanged) {
|
|
585
585
|
throw new Error(
|
|
@@ -604,7 +604,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
604
604
|
signTxWithKey(tx, key, inputIndexes) {
|
|
605
605
|
const txCpy = tx.clone();
|
|
606
606
|
if (!inputIndexes) {
|
|
607
|
-
|
|
607
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
|
|
608
608
|
try {
|
|
609
609
|
if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
|
|
610
610
|
throw new Error("Failed to sign transaction");
|
|
@@ -666,7 +666,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
666
666
|
*/
|
|
667
667
|
descriptor;
|
|
668
668
|
constructor(descriptor) {
|
|
669
|
-
const network =
|
|
669
|
+
const network = chunkLUWSY2QO_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
670
670
|
let expansion;
|
|
671
671
|
try {
|
|
672
672
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -716,7 +716,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
716
716
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
717
717
|
*/
|
|
718
718
|
isOurs(descriptor) {
|
|
719
|
-
return
|
|
719
|
+
return chunkLUWSY2QO_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
720
720
|
}
|
|
721
721
|
};
|
|
722
722
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -878,10 +878,10 @@ var DescriptorIdentity = class {
|
|
|
878
878
|
this.base = base;
|
|
879
879
|
}
|
|
880
880
|
async xOnlyPublicKey() {
|
|
881
|
-
return
|
|
881
|
+
return chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
882
882
|
}
|
|
883
883
|
async compressedPublicKey() {
|
|
884
|
-
return
|
|
884
|
+
return chunkLUWSY2QO_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
|
|
885
885
|
}
|
|
886
886
|
async sign(tx, inputIndexes) {
|
|
887
887
|
const [signed] = await this.signer.signWithDescriptor([
|
|
@@ -949,12 +949,12 @@ var WalletCannotAllocateAddressError = class extends Error {
|
|
|
949
949
|
};
|
|
950
950
|
async function resolveDescriptorSigner(descriptor, identity, provider) {
|
|
951
951
|
const owner = provider?.isOurs(descriptor) ? provider : isHDCapableIdentity(identity) && identity.isOurs(descriptor) ? identity : void 0;
|
|
952
|
-
if (owner &&
|
|
952
|
+
if (owner && chunkLUWSY2QO_cjs.parseHDDescriptor(descriptor)) {
|
|
953
953
|
return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
|
|
954
954
|
}
|
|
955
955
|
let key;
|
|
956
956
|
try {
|
|
957
|
-
key =
|
|
957
|
+
key = chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
958
958
|
} catch {
|
|
959
959
|
throw new ForeignDescriptorError(descriptor);
|
|
960
960
|
}
|
|
@@ -1329,14 +1329,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
|
|
|
1329
1329
|
}
|
|
1330
1330
|
var PREIMAGE_INDEX = 0;
|
|
1331
1331
|
function isPerArtifactDescriptor(descriptor) {
|
|
1332
|
-
return
|
|
1332
|
+
return chunkLUWSY2QO_cjs.parseHDDescriptor(descriptor) !== null;
|
|
1333
1333
|
}
|
|
1334
1334
|
async function provisionDescriptor(wallet) {
|
|
1335
1335
|
const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
|
|
1336
|
-
return allocated ?? await
|
|
1336
|
+
return allocated ?? await chunkLUWSY2QO_cjs.identityDescriptor(wallet.identity);
|
|
1337
1337
|
}
|
|
1338
1338
|
async function provisionRefundKey(wallet) {
|
|
1339
|
-
const descriptor = await
|
|
1339
|
+
const descriptor = await chunkLUWSY2QO_cjs.identityDescriptor(wallet.identity);
|
|
1340
1340
|
const signer = await contractSigner(wallet, descriptor);
|
|
1341
1341
|
const pubkey = await signer.xOnlyPublicKey();
|
|
1342
1342
|
const identityPubkey = await wallet.identity.xOnlyPublicKey();
|
|
@@ -1346,7 +1346,7 @@ async function provisionRefundKey(wallet) {
|
|
|
1346
1346
|
);
|
|
1347
1347
|
}
|
|
1348
1348
|
const address = await wallet.getAddress();
|
|
1349
|
-
const { pkScript } =
|
|
1349
|
+
const { pkScript } = chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
1350
1350
|
return { descriptor, pubkey, pkScript, address };
|
|
1351
1351
|
}
|
|
1352
1352
|
async function provisionClaimSecret(wallet, opts = {}) {
|
|
@@ -1356,7 +1356,7 @@ async function provisionClaimSecret(wallet, opts = {}) {
|
|
|
1356
1356
|
const descriptor = await provisionDescriptor(wallet);
|
|
1357
1357
|
const signer = await contractSigner(wallet, descriptor);
|
|
1358
1358
|
const pubkey = await signer.xOnlyPublicKey();
|
|
1359
|
-
const
|
|
1359
|
+
const claim2 = async () => {
|
|
1360
1360
|
if (opts.preimage) return { preimage: opts.preimage, mustPersistPreimage: true };
|
|
1361
1361
|
if (isPerArtifactDescriptor(descriptor)) {
|
|
1362
1362
|
return {
|
|
@@ -1378,7 +1378,7 @@ async function provisionClaimSecret(wallet, opts = {}) {
|
|
|
1378
1378
|
return { preimage: randomBytes(32), mustPersistPreimage: true };
|
|
1379
1379
|
}
|
|
1380
1380
|
};
|
|
1381
|
-
const { preimage, preimageSalt, mustPersistPreimage } = await
|
|
1381
|
+
const { preimage, preimageSalt, mustPersistPreimage } = await claim2();
|
|
1382
1382
|
return {
|
|
1383
1383
|
descriptor,
|
|
1384
1384
|
pubkey,
|
|
@@ -1392,7 +1392,7 @@ async function contractSigner(wallet, descriptor) {
|
|
|
1392
1392
|
const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
|
|
1393
1393
|
let expected;
|
|
1394
1394
|
try {
|
|
1395
|
-
expected =
|
|
1395
|
+
expected = chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1396
1396
|
} catch (cause) {
|
|
1397
1397
|
throw new ForeignDescriptorError(descriptor, { cause });
|
|
1398
1398
|
}
|
|
@@ -1611,14 +1611,14 @@ var RestDelegateProvider = class {
|
|
|
1611
1611
|
*/
|
|
1612
1612
|
async delegate(intent, forfeitTxs, options) {
|
|
1613
1613
|
const url = `${this.url}/v1/delegate`;
|
|
1614
|
-
const response = await
|
|
1614
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(url, {
|
|
1615
1615
|
method: "POST",
|
|
1616
1616
|
headers: {
|
|
1617
1617
|
"Content-Type": "application/json"
|
|
1618
1618
|
},
|
|
1619
1619
|
body: JSON.stringify({
|
|
1620
1620
|
intent: {
|
|
1621
|
-
message:
|
|
1621
|
+
message: chunkCJN4CUEU_cjs.Intent.encodeMessage(intent.message),
|
|
1622
1622
|
proof: intent.proof
|
|
1623
1623
|
},
|
|
1624
1624
|
forfeit_txs: forfeitTxs,
|
|
@@ -1638,7 +1638,7 @@ var RestDelegateProvider = class {
|
|
|
1638
1638
|
*/
|
|
1639
1639
|
async getDelegateInfo() {
|
|
1640
1640
|
const url = `${this.url}/v1/delegator/info`;
|
|
1641
|
-
const response = await
|
|
1641
|
+
const response = await chunkCJN4CUEU_cjs.rateGate.runHttp(url, () => chunkCJN4CUEU_cjs.baseFetch(url));
|
|
1642
1642
|
if (!response.ok) {
|
|
1643
1643
|
const errorText2 = await response.text();
|
|
1644
1644
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1663,7 +1663,7 @@ var ESPLORA_URL = {
|
|
|
1663
1663
|
regtest: "http://localhost:3000/api"
|
|
1664
1664
|
};
|
|
1665
1665
|
var EsploraProvider = class {
|
|
1666
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1666
|
+
constructor(baseUrl = ESPLORA_URL[chunkCJN4CUEU_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1667
1667
|
this.baseUrl = baseUrl;
|
|
1668
1668
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1669
1669
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1682,14 +1682,14 @@ var EsploraProvider = class {
|
|
|
1682
1682
|
*/
|
|
1683
1683
|
addressWatches = /* @__PURE__ */ new Map();
|
|
1684
1684
|
async getCoins(address) {
|
|
1685
|
-
const response = await
|
|
1685
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1686
1686
|
if (!response.ok) {
|
|
1687
1687
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1688
1688
|
}
|
|
1689
1689
|
return response.json();
|
|
1690
1690
|
}
|
|
1691
1691
|
async getFeeRate() {
|
|
1692
|
-
const response = await
|
|
1692
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1693
1693
|
if (response.status === 404) {
|
|
1694
1694
|
return void 0;
|
|
1695
1695
|
}
|
|
@@ -1710,7 +1710,7 @@ var EsploraProvider = class {
|
|
|
1710
1710
|
}
|
|
1711
1711
|
}
|
|
1712
1712
|
async getTxOutspends(txid) {
|
|
1713
|
-
const response = await
|
|
1713
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1714
1714
|
if (!response.ok) {
|
|
1715
1715
|
const error = await response.text();
|
|
1716
1716
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1718,7 +1718,7 @@ var EsploraProvider = class {
|
|
|
1718
1718
|
return response.json();
|
|
1719
1719
|
}
|
|
1720
1720
|
async getTransactions(address) {
|
|
1721
|
-
const response = await
|
|
1721
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1722
1722
|
if (!response.ok) {
|
|
1723
1723
|
const error = await response.text();
|
|
1724
1724
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1731,14 +1731,14 @@ var EsploraProvider = class {
|
|
|
1731
1731
|
* usable as a change probe for the polling fallback.
|
|
1732
1732
|
*/
|
|
1733
1733
|
async getAddressStats(address) {
|
|
1734
|
-
const response = await
|
|
1734
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
|
|
1735
1735
|
if (!response.ok) {
|
|
1736
1736
|
throw new Error(`Failed to get address stats: ${response.statusText}`);
|
|
1737
1737
|
}
|
|
1738
1738
|
return response.json();
|
|
1739
1739
|
}
|
|
1740
1740
|
async getRawTransaction(txid) {
|
|
1741
|
-
const response = await
|
|
1741
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
1742
1742
|
if (!response.ok) {
|
|
1743
1743
|
const error = await response.text();
|
|
1744
1744
|
throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
|
|
@@ -1746,7 +1746,7 @@ var EsploraProvider = class {
|
|
|
1746
1746
|
return base.hex.decode((await response.text()).trim());
|
|
1747
1747
|
}
|
|
1748
1748
|
async getTxStatus(txid) {
|
|
1749
|
-
const txresponse = await
|
|
1749
|
+
const txresponse = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1750
1750
|
if (!txresponse.ok) {
|
|
1751
1751
|
throw new Error(txresponse.statusText);
|
|
1752
1752
|
}
|
|
@@ -1754,7 +1754,7 @@ var EsploraProvider = class {
|
|
|
1754
1754
|
if (!tx.status.confirmed) {
|
|
1755
1755
|
return { confirmed: false };
|
|
1756
1756
|
}
|
|
1757
|
-
const response = await
|
|
1757
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1758
1758
|
if (!response.ok) {
|
|
1759
1759
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1760
1760
|
}
|
|
@@ -2038,9 +2038,9 @@ var EsploraProvider = class {
|
|
|
2038
2038
|
return { subscribers, teardown, started };
|
|
2039
2039
|
}
|
|
2040
2040
|
async getChainTip() {
|
|
2041
|
-
let tipBlocks = await
|
|
2041
|
+
let tipBlocks = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2042
2042
|
if (tipBlocks.status === 404) {
|
|
2043
|
-
tipBlocks = await
|
|
2043
|
+
tipBlocks = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
|
|
2044
2044
|
}
|
|
2045
2045
|
if (!tipBlocks.ok) {
|
|
2046
2046
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
@@ -2062,7 +2062,7 @@ var EsploraProvider = class {
|
|
|
2062
2062
|
};
|
|
2063
2063
|
}
|
|
2064
2064
|
async broadcastPackage(parent, child) {
|
|
2065
|
-
const response = await
|
|
2065
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
2066
2066
|
method: "POST",
|
|
2067
2067
|
headers: {
|
|
2068
2068
|
"Content-Type": "application/json"
|
|
@@ -2078,7 +2078,7 @@ var EsploraProvider = class {
|
|
|
2078
2078
|
return result;
|
|
2079
2079
|
}
|
|
2080
2080
|
async broadcastTx(tx) {
|
|
2081
|
-
const response = await
|
|
2081
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
2082
2082
|
method: "POST",
|
|
2083
2083
|
headers: {
|
|
2084
2084
|
"Content-Type": "text/plain"
|
|
@@ -2261,7 +2261,7 @@ function findP2AOutput(tx) {
|
|
|
2261
2261
|
var CHILD_DUST_AMOUNT = 546;
|
|
2262
2262
|
function buildAnchorChild(params) {
|
|
2263
2263
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2264
|
-
const child = new
|
|
2264
|
+
const child = new chunkCJN4CUEU_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2265
2265
|
child.addInput(findP2AOutput(parent));
|
|
2266
2266
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
2267
2267
|
for (const _ of fundingCoins) {
|
|
@@ -2309,7 +2309,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
2309
2309
|
);
|
|
2310
2310
|
}
|
|
2311
2311
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
2312
|
-
const tx = new
|
|
2312
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({
|
|
2313
2313
|
version: 3,
|
|
2314
2314
|
lockTime: txLocktime
|
|
2315
2315
|
});
|
|
@@ -2385,7 +2385,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
2385
2385
|
if (previousScriptKey.length !== 32) {
|
|
2386
2386
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
2387
2387
|
}
|
|
2388
|
-
const cosigners =
|
|
2388
|
+
const cosigners = chunkCJN4CUEU_cjs.getArkPsbtFields(child.root, 0, chunkCJN4CUEU_cjs.CosignerPublicKey);
|
|
2389
2389
|
if (cosigners.length === 0) {
|
|
2390
2390
|
throw ErrMissingCosignersPublicKeys;
|
|
2391
2391
|
}
|
|
@@ -2443,7 +2443,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2443
2443
|
return new _EmulatorPacket(entries);
|
|
2444
2444
|
}
|
|
2445
2445
|
static fromBytes(data) {
|
|
2446
|
-
const reader = new
|
|
2446
|
+
const reader = new chunkH62OOAS4_cjs.BufferReader(data);
|
|
2447
2447
|
const entryCount = reader.readCompactSize();
|
|
2448
2448
|
const entries = [];
|
|
2449
2449
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -2461,7 +2461,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2461
2461
|
return _EmulatorPacket.PACKET_TYPE;
|
|
2462
2462
|
}
|
|
2463
2463
|
serialize() {
|
|
2464
|
-
const writer = new
|
|
2464
|
+
const writer = new chunkH62OOAS4_cjs.BufferWriter();
|
|
2465
2465
|
writer.writeCompactSize(this.entries.length);
|
|
2466
2466
|
for (const entry of this.entries) {
|
|
2467
2467
|
writer.writeUint16LE(entry.vin);
|
|
@@ -2548,7 +2548,7 @@ var Extension = class _Extension {
|
|
|
2548
2548
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
2549
2549
|
);
|
|
2550
2550
|
}
|
|
2551
|
-
const reader = new
|
|
2551
|
+
const reader = new chunkH62OOAS4_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
2552
2552
|
const packets = [];
|
|
2553
2553
|
while (reader.remaining() > 0) {
|
|
2554
2554
|
const packetType = reader.readByte();
|
|
@@ -2622,7 +2622,7 @@ var Extension = class _Extension {
|
|
|
2622
2622
|
*/
|
|
2623
2623
|
getAssetPacket() {
|
|
2624
2624
|
for (const p of this.packets) {
|
|
2625
|
-
if (p instanceof
|
|
2625
|
+
if (p instanceof chunkH62OOAS4_cjs.Packet) {
|
|
2626
2626
|
return p;
|
|
2627
2627
|
}
|
|
2628
2628
|
}
|
|
@@ -2660,8 +2660,8 @@ var Extension = class _Extension {
|
|
|
2660
2660
|
};
|
|
2661
2661
|
function parsePacket(packetType, data) {
|
|
2662
2662
|
switch (packetType) {
|
|
2663
|
-
case
|
|
2664
|
-
return
|
|
2663
|
+
case chunkH62OOAS4_cjs.Packet.PACKET_TYPE:
|
|
2664
|
+
return chunkH62OOAS4_cjs.Packet.fromBytes(data);
|
|
2665
2665
|
case EmulatorPacket.PACKET_TYPE:
|
|
2666
2666
|
return EmulatorPacket.fromBytes(data);
|
|
2667
2667
|
default:
|
|
@@ -2708,22 +2708,22 @@ function buildOpReturnScript(data) {
|
|
|
2708
2708
|
}
|
|
2709
2709
|
return script;
|
|
2710
2710
|
}
|
|
2711
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
2712
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
2711
|
+
var ErrOffchainOutputNotFound = (address) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2712
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2713
2713
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
2714
2714
|
);
|
|
2715
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
2716
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
2715
|
+
var ErrAssetGroupNotFound = (assetId) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2716
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2717
2717
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
2718
2718
|
);
|
|
2719
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
2720
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
2719
|
+
var ErrOnchainOutputNotFound = (address) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2720
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2721
2721
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
2722
2722
|
);
|
|
2723
|
-
var ErrIntentOutputNotFound = (index, kind) => new
|
|
2723
|
+
var ErrIntentOutputNotFound = (index, kind) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2724
2724
|
`${kind} output ${index} of the intent proof is not present in what the server built`
|
|
2725
2725
|
);
|
|
2726
|
-
var ErrUnvalidatedIntentOutput = (index) => new
|
|
2726
|
+
var ErrUnvalidatedIntentOutput = (index) => new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2727
2727
|
`offchain output ${index} of the intent proof cannot be validated: virtual output tree signing did not run`
|
|
2728
2728
|
);
|
|
2729
2729
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
@@ -2732,7 +2732,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
2732
2732
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
2733
2733
|
if (!validatedCommitmentTxid) return;
|
|
2734
2734
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
2735
|
-
throw new
|
|
2735
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
2736
2736
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
2737
2737
|
);
|
|
2738
2738
|
}
|
|
@@ -2742,7 +2742,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
2742
2742
|
for (const recipient of recipients) {
|
|
2743
2743
|
let arkAddress;
|
|
2744
2744
|
try {
|
|
2745
|
-
arkAddress =
|
|
2745
|
+
arkAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(recipient.address);
|
|
2746
2746
|
} catch {
|
|
2747
2747
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2748
2748
|
continue;
|
|
@@ -2754,7 +2754,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2754
2754
|
const usedOnchainOutputs = /* @__PURE__ */ new Set();
|
|
2755
2755
|
for (const recipient of recipients) {
|
|
2756
2756
|
try {
|
|
2757
|
-
|
|
2757
|
+
chunkCJN4CUEU_cjs.ArkAddress.decode(recipient.address);
|
|
2758
2758
|
} catch {
|
|
2759
2759
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2760
2760
|
continue;
|
|
@@ -2763,7 +2763,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2763
2763
|
}
|
|
2764
2764
|
}
|
|
2765
2765
|
function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
|
|
2766
|
-
const proof =
|
|
2766
|
+
const proof = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
|
|
2767
2767
|
const onchain = new Set(onchainOutputIndexes);
|
|
2768
2768
|
const declared = [];
|
|
2769
2769
|
for (let i = 0; i < proof.outputsLength; i++) {
|
|
@@ -3055,7 +3055,7 @@ function assetMintResolver() {
|
|
|
3055
3055
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
3056
3056
|
const minted = tx.assets.filter((a) => {
|
|
3057
3057
|
try {
|
|
3058
|
-
return base.hex.encode(
|
|
3058
|
+
return base.hex.encode(chunkH62OOAS4_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
3059
3059
|
} catch {
|
|
3060
3060
|
return false;
|
|
3061
3061
|
}
|
|
@@ -3131,7 +3131,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3131
3131
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
3132
3132
|
inputsByAssetId.set(asset.assetId, [
|
|
3133
3133
|
...existing ?? [],
|
|
3134
|
-
|
|
3134
|
+
chunkH62OOAS4_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
3135
3135
|
]);
|
|
3136
3136
|
}
|
|
3137
3137
|
}
|
|
@@ -3143,7 +3143,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3143
3143
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3144
3144
|
outputsByAssetId.set(asset.assetId, [
|
|
3145
3145
|
...existing ?? [],
|
|
3146
|
-
|
|
3146
|
+
chunkH62OOAS4_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3147
3147
|
]);
|
|
3148
3148
|
}
|
|
3149
3149
|
}
|
|
@@ -3154,7 +3154,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3154
3154
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3155
3155
|
outputsByAssetId.set(asset.assetId, [
|
|
3156
3156
|
...existing ?? [],
|
|
3157
|
-
|
|
3157
|
+
chunkH62OOAS4_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3158
3158
|
]);
|
|
3159
3159
|
}
|
|
3160
3160
|
}
|
|
@@ -3163,11 +3163,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3163
3163
|
for (const assetIdStr of allAssetIds) {
|
|
3164
3164
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
3165
3165
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
3166
|
-
const assetId =
|
|
3167
|
-
const group =
|
|
3166
|
+
const assetId = chunkH62OOAS4_cjs.AssetId.fromString(assetIdStr);
|
|
3167
|
+
const group = chunkH62OOAS4_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3168
3168
|
groups.push(group);
|
|
3169
3169
|
}
|
|
3170
|
-
return
|
|
3170
|
+
return chunkH62OOAS4_cjs.Packet.create(groups);
|
|
3171
3171
|
}
|
|
3172
3172
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
3173
3173
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -3204,7 +3204,7 @@ function selectedCoinsToAssetInputs(selectedCoins) {
|
|
|
3204
3204
|
}
|
|
3205
3205
|
function toXOnlySignerHex(pubkeyHex) {
|
|
3206
3206
|
const bytes = base.hex.decode(pubkeyHex);
|
|
3207
|
-
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(
|
|
3207
|
+
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(bytes, "signer key"));
|
|
3208
3208
|
throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes.length}`);
|
|
3209
3209
|
}
|
|
3210
3210
|
function signerSetFromInfo(info) {
|
|
@@ -3251,13 +3251,13 @@ var toTimelock = (value) => ({
|
|
|
3251
3251
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
3252
3252
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
3253
3253
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
3254
|
-
throw new
|
|
3254
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3255
3255
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
3256
3256
|
);
|
|
3257
3257
|
}
|
|
3258
3258
|
const seconds = toSeconds(timelock);
|
|
3259
3259
|
if (seconds < policy.minSeconds) {
|
|
3260
|
-
throw new
|
|
3260
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3261
3261
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it`
|
|
3262
3262
|
);
|
|
3263
3263
|
}
|
|
@@ -3278,7 +3278,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
3278
3278
|
}
|
|
3279
3279
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
3280
3280
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
3281
|
-
throw new
|
|
3281
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3282
3282
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
3283
3283
|
);
|
|
3284
3284
|
}
|
|
@@ -3308,21 +3308,21 @@ function resolveCheckpointExitDelayPolicy(network, overrides) {
|
|
|
3308
3308
|
function assertValidServerUnrollScript(checkpointTapscript, policy) {
|
|
3309
3309
|
let script;
|
|
3310
3310
|
try {
|
|
3311
|
-
script =
|
|
3311
|
+
script = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
3312
3312
|
} catch (e) {
|
|
3313
|
-
throw new
|
|
3313
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3314
3314
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
3315
3315
|
);
|
|
3316
3316
|
}
|
|
3317
3317
|
if (policy.advertisedForfeitPubkey !== void 0) {
|
|
3318
3318
|
const { pubkeys } = script.params;
|
|
3319
3319
|
if (pubkeys.length !== 1) {
|
|
3320
|
-
throw new
|
|
3320
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3321
3321
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
3322
3322
|
);
|
|
3323
3323
|
}
|
|
3324
3324
|
if (!utils_js.equalBytes(pubkeys[0], policy.advertisedForfeitPubkey)) {
|
|
3325
|
-
throw new
|
|
3325
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3326
3326
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(policy.advertisedForfeitPubkey)}`
|
|
3327
3327
|
);
|
|
3328
3328
|
}
|
|
@@ -3366,8 +3366,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
3366
3366
|
function buildVirtualTx(inputs, outputs) {
|
|
3367
3367
|
let lockTime = 0n;
|
|
3368
3368
|
for (const input of inputs) {
|
|
3369
|
-
const tapscript =
|
|
3370
|
-
if (
|
|
3369
|
+
const tapscript = chunkCJN4CUEU_cjs.decodeTapscript(chunkCJN4CUEU_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3370
|
+
if (chunkCJN4CUEU_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
3371
3371
|
if (lockTime !== 0n) {
|
|
3372
3372
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
3373
3373
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -3378,7 +3378,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3378
3378
|
}
|
|
3379
3379
|
}
|
|
3380
3380
|
}
|
|
3381
|
-
const tx = new
|
|
3381
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({
|
|
3382
3382
|
version: 3,
|
|
3383
3383
|
lockTime: Number(lockTime)
|
|
3384
3384
|
});
|
|
@@ -3388,12 +3388,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3388
3388
|
index: input.vout,
|
|
3389
3389
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
3390
3390
|
witnessUtxo: {
|
|
3391
|
-
script:
|
|
3391
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3392
3392
|
amount: BigInt(input.value)
|
|
3393
3393
|
},
|
|
3394
3394
|
tapLeafScript: [input.tapLeafScript]
|
|
3395
3395
|
});
|
|
3396
|
-
|
|
3396
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(tx, i, chunkCJN4CUEU_cjs.VtxoTaprootTree, input.tapTree);
|
|
3397
3397
|
}
|
|
3398
3398
|
for (const output of outputs) {
|
|
3399
3399
|
tx.addOutput(output);
|
|
@@ -3402,8 +3402,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3402
3402
|
return tx;
|
|
3403
3403
|
}
|
|
3404
3404
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
3405
|
-
const collaborativeClosure =
|
|
3406
|
-
const checkpointVtxoScript = new
|
|
3405
|
+
const collaborativeClosure = chunkCJN4CUEU_cjs.decodeTapscript(chunkCJN4CUEU_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3406
|
+
const checkpointVtxoScript = new chunkCJN4CUEU_cjs.VtxoScript([
|
|
3407
3407
|
serverUnrollScript.script,
|
|
3408
3408
|
collaborativeClosure.script
|
|
3409
3409
|
]);
|
|
@@ -3479,7 +3479,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
3479
3479
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
3480
3480
|
const sig = signature.subarray(0, 64);
|
|
3481
3481
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
3482
|
-
const sighashName =
|
|
3482
|
+
const sighashName = chunkCJN4CUEU_cjs.formatSighash(sighashType);
|
|
3483
3483
|
throw new Error(
|
|
3484
3484
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
3485
3485
|
);
|
|
@@ -3553,7 +3553,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
3553
3553
|
}
|
|
3554
3554
|
function isValidArkAddress(address) {
|
|
3555
3555
|
try {
|
|
3556
|
-
|
|
3556
|
+
chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
3557
3557
|
return true;
|
|
3558
3558
|
} catch (e) {
|
|
3559
3559
|
return false;
|
|
@@ -3561,16 +3561,16 @@ function isValidArkAddress(address) {
|
|
|
3561
3561
|
}
|
|
3562
3562
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
3563
3563
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
3564
|
-
throw new
|
|
3564
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3565
3565
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
3566
3566
|
);
|
|
3567
3567
|
}
|
|
3568
3568
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
3569
3569
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
3570
|
-
const server =
|
|
3570
|
+
const server = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
3571
3571
|
const local = byTxid.get(server.id);
|
|
3572
3572
|
if (!local) {
|
|
3573
|
-
throw new
|
|
3573
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3574
3574
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
3575
3575
|
);
|
|
3576
3576
|
}
|
|
@@ -3580,14 +3580,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
3580
3580
|
}
|
|
3581
3581
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
3582
3582
|
if (response.arkTxid !== signedArkTx.id) {
|
|
3583
|
-
throw new
|
|
3583
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3584
3584
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
3585
3585
|
);
|
|
3586
3586
|
}
|
|
3587
3587
|
if (response.finalArkTx === void 0) return;
|
|
3588
|
-
const finalTxid =
|
|
3588
|
+
const finalTxid = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3589
3589
|
if (finalTxid !== signedArkTx.id) {
|
|
3590
|
-
throw new
|
|
3590
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3591
3591
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
3592
3592
|
);
|
|
3593
3593
|
}
|
|
@@ -3599,20 +3599,20 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
3599
3599
|
`${context}: input ${inputIndex} carries no spend leaf to verify the server signature against`
|
|
3600
3600
|
);
|
|
3601
3601
|
}
|
|
3602
|
-
const script =
|
|
3602
|
+
const script = chunkCJN4CUEU_cjs.scriptFromTapLeafScript(leaf);
|
|
3603
3603
|
let leafPubkeys;
|
|
3604
3604
|
try {
|
|
3605
|
-
leafPubkeys =
|
|
3606
|
-
(key) => base.hex.encode(
|
|
3605
|
+
leafPubkeys = chunkCJN4CUEU_cjs.decodeTapscript(script).params.pubkeys.map(
|
|
3606
|
+
(key) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(key, "leaf key"))
|
|
3607
3607
|
);
|
|
3608
3608
|
} catch (error) {
|
|
3609
|
-
throw new
|
|
3609
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3610
3610
|
`${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
|
|
3611
3611
|
);
|
|
3612
3612
|
}
|
|
3613
3613
|
const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
|
|
3614
3614
|
if (!signer) {
|
|
3615
|
-
throw new
|
|
3615
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3616
3616
|
`${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
|
|
3617
3617
|
);
|
|
3618
3618
|
}
|
|
@@ -3626,7 +3626,7 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
3626
3626
|
payment_js.tapLeafHash(script)
|
|
3627
3627
|
);
|
|
3628
3628
|
} catch (error) {
|
|
3629
|
-
throw new
|
|
3629
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3630
3630
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
3631
3631
|
);
|
|
3632
3632
|
}
|
|
@@ -3635,20 +3635,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3635
3635
|
const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
|
|
3636
3636
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
3637
3637
|
if (checkpoint.inputsLength !== 1) {
|
|
3638
|
-
throw new
|
|
3638
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3639
3639
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
3640
3640
|
);
|
|
3641
3641
|
}
|
|
3642
3642
|
const spent = checkpoint.getInput(0);
|
|
3643
3643
|
if (!spent.txid || spent.index === void 0) {
|
|
3644
|
-
throw new
|
|
3644
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3645
3645
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
3646
3646
|
);
|
|
3647
3647
|
}
|
|
3648
3648
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
3649
3649
|
const input = byOutpoint.get(outpoint);
|
|
3650
3650
|
if (!input) {
|
|
3651
|
-
throw new
|
|
3651
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3652
3652
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
3653
3653
|
);
|
|
3654
3654
|
}
|
|
@@ -3656,7 +3656,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3656
3656
|
(unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
|
|
3657
3657
|
);
|
|
3658
3658
|
if (!rebuilt) {
|
|
3659
|
-
throw new
|
|
3659
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3660
3660
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
3661
3661
|
);
|
|
3662
3662
|
}
|
|
@@ -3682,9 +3682,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3682
3682
|
const matched = matchServerCheckpoints(signedCheckpointTxs, offchainTx.checkpoints, "submitTx");
|
|
3683
3683
|
matched.forEach(({ server }, index) => {
|
|
3684
3684
|
try {
|
|
3685
|
-
|
|
3685
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(server);
|
|
3686
3686
|
} catch (error) {
|
|
3687
|
-
throw new
|
|
3687
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3688
3688
|
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
3689
3689
|
);
|
|
3690
3690
|
}
|
|
@@ -3692,14 +3692,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3692
3692
|
const verify = options?.verifyServerSignatures;
|
|
3693
3693
|
if (verify) {
|
|
3694
3694
|
if (response.finalArkTx === void 0) {
|
|
3695
|
-
throw new
|
|
3695
|
+
throw new chunkCJN4CUEU_cjs.ServerResponseMismatchError(
|
|
3696
3696
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
3697
3697
|
);
|
|
3698
3698
|
}
|
|
3699
|
-
const finalArkTx =
|
|
3699
|
+
const finalArkTx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
3700
3700
|
const serverPubkeys = new Set(
|
|
3701
3701
|
[verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
|
|
3702
|
-
(key) => base.hex.encode(
|
|
3702
|
+
(key) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(key, "server key"))
|
|
3703
3703
|
)
|
|
3704
3704
|
);
|
|
3705
3705
|
for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
|
|
@@ -3751,12 +3751,12 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
3751
3751
|
return {
|
|
3752
3752
|
...identity,
|
|
3753
3753
|
sign: async (tx, inputIndexes) => {
|
|
3754
|
-
const signed =
|
|
3754
|
+
const signed = chunkCJN4CUEU_cjs.Transaction.fromPSBT(
|
|
3755
3755
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
3756
3756
|
);
|
|
3757
3757
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
3758
3758
|
for (const index of indexes) {
|
|
3759
|
-
|
|
3759
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(signed, index, chunkCJN4CUEU_cjs.ConditionWitness, [preimage]);
|
|
3760
3760
|
}
|
|
3761
3761
|
return signed;
|
|
3762
3762
|
}
|
|
@@ -3951,7 +3951,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3951
3951
|
};
|
|
3952
3952
|
}
|
|
3953
3953
|
function deriveContractTapscripts(contract) {
|
|
3954
|
-
const handler =
|
|
3954
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
3955
3955
|
if (!handler) {
|
|
3956
3956
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3957
3957
|
}
|
|
@@ -4022,7 +4022,7 @@ function getRandomId() {
|
|
|
4022
4022
|
}
|
|
4023
4023
|
function isValidArkAddress2(address) {
|
|
4024
4024
|
try {
|
|
4025
|
-
|
|
4025
|
+
chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
4026
4026
|
return true;
|
|
4027
4027
|
} catch (e) {
|
|
4028
4028
|
return false;
|
|
@@ -4050,7 +4050,7 @@ function assertRecipientArkAddress(encoded, address, context) {
|
|
|
4050
4050
|
function assertTapTreeDerivesAddress(encoded, tapTree, address) {
|
|
4051
4051
|
let derived;
|
|
4052
4052
|
try {
|
|
4053
|
-
derived =
|
|
4053
|
+
derived = chunkCJN4CUEU_cjs.VtxoScript.decode(tapTree).pkScript;
|
|
4054
4054
|
} catch (e) {
|
|
4055
4055
|
throw new Error(
|
|
4056
4056
|
`Invalid tapTree for ${encoded}: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -4067,7 +4067,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
4067
4067
|
for (const recipient of recipients) {
|
|
4068
4068
|
let address;
|
|
4069
4069
|
try {
|
|
4070
|
-
address =
|
|
4070
|
+
address = chunkCJN4CUEU_cjs.ArkAddress.decode(recipient.address);
|
|
4071
4071
|
} catch (e) {
|
|
4072
4072
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
4073
4073
|
}
|
|
@@ -4092,7 +4092,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
4092
4092
|
|
|
4093
4093
|
// src/contracts/spendability.ts
|
|
4094
4094
|
function isContractGenericallySpendable(contract) {
|
|
4095
|
-
return
|
|
4095
|
+
return chunkLUWSY2QO_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
4096
4096
|
}
|
|
4097
4097
|
function gatedContracts(contracts) {
|
|
4098
4098
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -4114,7 +4114,7 @@ function gateExclusion(gated) {
|
|
|
4114
4114
|
return (vtxo) => {
|
|
4115
4115
|
const type = gatedTypeOf(vtxo, gated);
|
|
4116
4116
|
if (type === void 0) return void 0;
|
|
4117
|
-
if (!
|
|
4117
|
+
if (!chunkLUWSY2QO_cjs.contractHandlers.has(type)) {
|
|
4118
4118
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
4119
4119
|
}
|
|
4120
4120
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -4150,7 +4150,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
4150
4150
|
continue;
|
|
4151
4151
|
}
|
|
4152
4152
|
for (const v of vtxos) {
|
|
4153
|
-
if (!
|
|
4153
|
+
if (!chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
|
|
4154
4154
|
out.add(`${v.txid}:${v.vout}`);
|
|
4155
4155
|
}
|
|
4156
4156
|
}
|
|
@@ -4185,10 +4185,10 @@ function byValueDescending(vtxos) {
|
|
|
4185
4185
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
4186
4186
|
}
|
|
4187
4187
|
async function fetchTimeHeight(wallet) {
|
|
4188
|
-
return
|
|
4188
|
+
return chunkCJN4CUEU_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
4189
4189
|
}
|
|
4190
4190
|
function canMigrateBySend(vtxo, now) {
|
|
4191
|
-
if (!
|
|
4191
|
+
if (!chunkCJN4CUEU_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
4192
4192
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
4193
4193
|
}
|
|
4194
4194
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -4196,7 +4196,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
4196
4196
|
if (vtxo.isSwept) return -Infinity;
|
|
4197
4197
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
4198
4198
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
4199
|
-
return
|
|
4199
|
+
return chunkCJN4CUEU_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
4200
4200
|
}
|
|
4201
4201
|
return Infinity;
|
|
4202
4202
|
};
|
|
@@ -4223,7 +4223,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
4223
4223
|
const payable = [];
|
|
4224
4224
|
const net = /* @__PURE__ */ new Map();
|
|
4225
4225
|
for (const vtxo of vtxos) {
|
|
4226
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4226
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo));
|
|
4227
4227
|
if (inputFee.satoshis >= vtxo.value) {
|
|
4228
4228
|
continue;
|
|
4229
4229
|
}
|
|
@@ -4249,7 +4249,7 @@ function deductOffchainOutputFee(subtotal, estimator, arkAddress) {
|
|
|
4249
4249
|
}
|
|
4250
4250
|
const outputFee = estimator.evalOffchainOutput({
|
|
4251
4251
|
amount: subtotal,
|
|
4252
|
-
script: base.hex.encode(
|
|
4252
|
+
script: base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4253
4253
|
});
|
|
4254
4254
|
return subtotal - BigInt(outputFee.satoshis);
|
|
4255
4255
|
}
|
|
@@ -4267,10 +4267,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
4267
4267
|
};
|
|
4268
4268
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
4269
4269
|
return vtxos.filter((vtxo) => {
|
|
4270
|
-
if (
|
|
4270
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
4271
4271
|
return true;
|
|
4272
4272
|
}
|
|
4273
|
-
if (
|
|
4273
|
+
if (chunkCJN4CUEU_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
4274
4274
|
return true;
|
|
4275
4275
|
}
|
|
4276
4276
|
return false;
|
|
@@ -4302,7 +4302,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
4302
4302
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
4303
4303
|
if (vtxo.isUnrolled) return false;
|
|
4304
4304
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
4305
|
-
const expiresAt =
|
|
4305
|
+
const expiresAt = chunkCJN4CUEU_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
4306
4306
|
if (expiresAt === void 0) return false;
|
|
4307
4307
|
const now = Date.now();
|
|
4308
4308
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -4313,7 +4313,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
|
4313
4313
|
return vtxos.filter(
|
|
4314
4314
|
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
4315
4315
|
// property and would otherwise re-admit an exited coin on its own.
|
|
4316
|
-
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
4316
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
4317
4317
|
);
|
|
4318
4318
|
}
|
|
4319
4319
|
function isMigrationCapable(wallet) {
|
|
@@ -4677,7 +4677,10 @@ var VtxoManager = class _VtxoManager {
|
|
|
4677
4677
|
if (this.settlementConfig === false && thresholdMs === void 0) {
|
|
4678
4678
|
return [];
|
|
4679
4679
|
}
|
|
4680
|
-
const vtxos = await this.wallet.getSpendableVtxos({
|
|
4680
|
+
const vtxos = await this.wallet.getSpendableVtxos({
|
|
4681
|
+
withRecoverable: true,
|
|
4682
|
+
genericallySpendableOnly: true
|
|
4683
|
+
});
|
|
4681
4684
|
let threshold;
|
|
4682
4685
|
if (thresholdMs !== void 0) {
|
|
4683
4686
|
threshold = thresholdMs;
|
|
@@ -4912,11 +4915,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4912
4915
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
4913
4916
|
);
|
|
4914
4917
|
}
|
|
4915
|
-
const tx = new
|
|
4918
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction();
|
|
4916
4919
|
for (const utxo of expiredUtxos) {
|
|
4917
|
-
const utxoScript =
|
|
4920
|
+
const utxoScript = chunkCJN4CUEU_cjs.VtxoScript.decode(utxo.tapTree);
|
|
4918
4921
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
4919
|
-
(leaf) =>
|
|
4922
|
+
(leaf) => chunkCJN4CUEU_cjs.CSVMultisigTapscript.isScriptValid(chunkCJN4CUEU_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
4920
4923
|
);
|
|
4921
4924
|
if (!utxoExitLeaf) {
|
|
4922
4925
|
throw new Error(
|
|
@@ -4931,7 +4934,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4931
4934
|
amount: BigInt(utxo.value)
|
|
4932
4935
|
},
|
|
4933
4936
|
tapLeafScript: [utxoExitLeaf],
|
|
4934
|
-
sequence:
|
|
4937
|
+
sequence: chunkCJN4CUEU_cjs.getSequence(utxoExitLeaf)
|
|
4935
4938
|
});
|
|
4936
4939
|
}
|
|
4937
4940
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -5174,8 +5177,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5174
5177
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
5175
5178
|
if (cls.status === "CURRENT") continue;
|
|
5176
5179
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
5177
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
5178
|
-
const spendable = live.filter((v) => !
|
|
5180
|
+
const recoverable = live.filter((v) => v.isSwept && !chunkCJN4CUEU_cjs.isVtxoSpent(v));
|
|
5181
|
+
const spendable = live.filter((v) => !chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isSwept);
|
|
5179
5182
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
5180
5183
|
let recoverableCount = 0;
|
|
5181
5184
|
let recoverableValue = 0;
|
|
@@ -5188,7 +5191,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5188
5191
|
awaitingSweepCount = spendable.length;
|
|
5189
5192
|
awaitingSweepValue = value;
|
|
5190
5193
|
for (const v of spendable) {
|
|
5191
|
-
const exp =
|
|
5194
|
+
const exp = chunkCJN4CUEU_cjs.toBatchExpiry(v);
|
|
5192
5195
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
5193
5196
|
nextSweepEta = exp;
|
|
5194
5197
|
}
|
|
@@ -5449,7 +5452,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5449
5452
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
5450
5453
|
getBoardingTimelock() {
|
|
5451
5454
|
const wallet = this.getSweepWallet();
|
|
5452
|
-
const exitScript =
|
|
5455
|
+
const exitScript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(
|
|
5453
5456
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
5454
5457
|
);
|
|
5455
5458
|
return exitScript.params.timelock;
|
|
@@ -5580,8 +5583,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5580
5583
|
* or doesn't carry the metadata.
|
|
5581
5584
|
*/
|
|
5582
5585
|
extractSpentOutpoint(error) {
|
|
5583
|
-
const ark =
|
|
5584
|
-
if (!
|
|
5586
|
+
const ark = chunkCJN4CUEU_cjs.maybeArkError(error);
|
|
5587
|
+
if (!chunkCJN4CUEU_cjs.isArkError(ark, chunkCJN4CUEU_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
5585
5588
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
5586
5589
|
if (typeof raw !== "string") return void 0;
|
|
5587
5590
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -5771,7 +5774,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5771
5774
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
5772
5775
|
break;
|
|
5773
5776
|
}
|
|
5774
|
-
const inputFee = estimator.evalOffchainInput(
|
|
5777
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(v));
|
|
5775
5778
|
if (inputFee.satoshis >= v.value) {
|
|
5776
5779
|
continue;
|
|
5777
5780
|
}
|
|
@@ -5791,7 +5794,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5791
5794
|
const arkAddress = await this.wallet.getAddress();
|
|
5792
5795
|
const outputFee = estimator.evalOffchainOutput({
|
|
5793
5796
|
amount: totalAmount,
|
|
5794
|
-
script: base.hex.encode(
|
|
5797
|
+
script: base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
5795
5798
|
});
|
|
5796
5799
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
5797
5800
|
if (totalAmount < dustAmount) return;
|
|
@@ -5871,7 +5874,7 @@ var ArkNote = class _ArkNote {
|
|
|
5871
5874
|
this.value = value;
|
|
5872
5875
|
this.HRP = HRP;
|
|
5873
5876
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
5874
|
-
this.vtxoScript = new
|
|
5877
|
+
this.vtxoScript = new chunkCJN4CUEU_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
5875
5878
|
const leaf = this.vtxoScript.leaves[0];
|
|
5876
5879
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
5877
5880
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -6038,7 +6041,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6038
6041
|
const privateKey = data.slice(1, 33);
|
|
6039
6042
|
const serverPubKey = data.slice(33, 65);
|
|
6040
6043
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
6041
|
-
const csvTimelock =
|
|
6044
|
+
const csvTimelock = chunkCJN4CUEU_cjs.sequenceToTimelock(sequence);
|
|
6042
6045
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
6043
6046
|
}
|
|
6044
6047
|
toString() {
|
|
@@ -6046,7 +6049,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6046
6049
|
data[0] = _ArkadeCash.Version;
|
|
6047
6050
|
data.set(this._privateKey, 1);
|
|
6048
6051
|
data.set(this._serverPubKey, 33);
|
|
6049
|
-
const sequence =
|
|
6052
|
+
const sequence = chunkCJN4CUEU_cjs.timelockToSequence(this.csvTimelock);
|
|
6050
6053
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
6051
6054
|
const words = base.bech32m.toWords(data);
|
|
6052
6055
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -6055,7 +6058,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6055
6058
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
6056
6059
|
}
|
|
6057
6060
|
get vtxoScript() {
|
|
6058
|
-
return new
|
|
6061
|
+
return new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
6059
6062
|
pubKey: this._publicKey,
|
|
6060
6063
|
serverPubKey: this._serverPubKey,
|
|
6061
6064
|
csvTimelock: this.csvTimelock
|
|
@@ -6316,7 +6319,7 @@ async function captureExitBranch(params) {
|
|
|
6316
6319
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
6317
6320
|
if (nonCommitment.length > 0) {
|
|
6318
6321
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
6319
|
-
psbtByTxid.set(
|
|
6322
|
+
psbtByTxid.set(chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6320
6323
|
}
|
|
6321
6324
|
}
|
|
6322
6325
|
}
|
|
@@ -6359,10 +6362,10 @@ var IndexerExitDataSource = class {
|
|
|
6359
6362
|
while (hasMore) {
|
|
6360
6363
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
6361
6364
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
6362
|
-
{ pageIndex, pageSize:
|
|
6365
|
+
{ pageIndex, pageSize: chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE }
|
|
6363
6366
|
);
|
|
6364
6367
|
chain.push(...page);
|
|
6365
|
-
hasMore = meta ? page.length ===
|
|
6368
|
+
hasMore = meta ? page.length === chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6366
6369
|
pageIndex++;
|
|
6367
6370
|
}
|
|
6368
6371
|
return chain;
|
|
@@ -6374,12 +6377,12 @@ var IndexerExitDataSource = class {
|
|
|
6374
6377
|
while (hasMore) {
|
|
6375
6378
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
6376
6379
|
pageIndex,
|
|
6377
|
-
pageSize:
|
|
6380
|
+
pageSize: chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE
|
|
6378
6381
|
});
|
|
6379
6382
|
for (const psbt of txs) {
|
|
6380
|
-
out.set(
|
|
6383
|
+
out.set(chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6381
6384
|
}
|
|
6382
|
-
hasMore = page ? txs.length ===
|
|
6385
|
+
hasMore = page ? txs.length === chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6383
6386
|
pageIndex++;
|
|
6384
6387
|
}
|
|
6385
6388
|
return out;
|
|
@@ -6400,7 +6403,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
6400
6403
|
}
|
|
6401
6404
|
}
|
|
6402
6405
|
function psbtInputTxids(psbtBase64) {
|
|
6403
|
-
const tx =
|
|
6406
|
+
const tx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
6404
6407
|
const ids = [];
|
|
6405
6408
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
6406
6409
|
const txid = tx.getInput(i).txid;
|
|
@@ -6759,10 +6762,10 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
6759
6762
|
try {
|
|
6760
6763
|
info = await arkProvider.getInfo();
|
|
6761
6764
|
} catch (err) {
|
|
6762
|
-
if (!
|
|
6765
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
6763
6766
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
6764
6767
|
if (!snapshot) {
|
|
6765
|
-
throw new
|
|
6768
|
+
throw new chunkCJN4CUEU_cjs.ProviderUnavailableError(
|
|
6766
6769
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
6767
6770
|
{ cause: err }
|
|
6768
6771
|
);
|
|
@@ -7169,7 +7172,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
|
|
|
7169
7172
|
return [...txids];
|
|
7170
7173
|
}
|
|
7171
7174
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
|
|
7172
|
-
const normalized = vtxos.map(
|
|
7175
|
+
const normalized = vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
7173
7176
|
const localCreatedAt = localCreatedAtByTxid(normalized);
|
|
7174
7177
|
const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
|
|
7175
7178
|
const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
|
|
@@ -7341,9 +7344,10 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7341
7344
|
}
|
|
7342
7345
|
const metadata = castMetadata(params.metadata);
|
|
7343
7346
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
7344
|
-
withRecoverable: false
|
|
7347
|
+
withRecoverable: false,
|
|
7348
|
+
genericallySpendableOnly: true
|
|
7345
7349
|
});
|
|
7346
|
-
const controlAssetRef = params.controlAssetId ?
|
|
7350
|
+
const controlAssetRef = params.controlAssetId ? chunkH62OOAS4_cjs.AssetRef.fromId(chunkH62OOAS4_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
7347
7351
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
7348
7352
|
let totalBtcSelected = 0n;
|
|
7349
7353
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -7356,8 +7360,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7356
7360
|
}
|
|
7357
7361
|
}
|
|
7358
7362
|
const groups = [];
|
|
7359
|
-
const issuedAssetOutput =
|
|
7360
|
-
const issuedAssetGroup =
|
|
7363
|
+
const issuedAssetOutput = chunkH62OOAS4_cjs.AssetOutput.create(0, params.amount);
|
|
7364
|
+
const issuedAssetGroup = chunkH62OOAS4_cjs.AssetGroup.create(
|
|
7361
7365
|
null,
|
|
7362
7366
|
controlAssetRef,
|
|
7363
7367
|
[],
|
|
@@ -7372,28 +7376,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7372
7376
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7373
7377
|
for (const asset of assets) {
|
|
7374
7378
|
if (asset.assetId !== assetId) continue;
|
|
7375
|
-
changeInputs.push(
|
|
7379
|
+
changeInputs.push(chunkH62OOAS4_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7376
7380
|
}
|
|
7377
7381
|
}
|
|
7378
7382
|
groups.push(
|
|
7379
|
-
|
|
7380
|
-
|
|
7383
|
+
chunkH62OOAS4_cjs.AssetGroup.create(
|
|
7384
|
+
chunkH62OOAS4_cjs.AssetId.fromString(assetId),
|
|
7381
7385
|
null,
|
|
7382
7386
|
changeInputs,
|
|
7383
|
-
[
|
|
7387
|
+
[chunkH62OOAS4_cjs.AssetOutput.create(0, amount)],
|
|
7384
7388
|
[]
|
|
7385
7389
|
)
|
|
7386
7390
|
);
|
|
7387
7391
|
}
|
|
7388
7392
|
}
|
|
7389
7393
|
const address = await this.wallet.getAddress();
|
|
7390
|
-
const outputAddress =
|
|
7394
|
+
const outputAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
7391
7395
|
const outputs = [
|
|
7392
7396
|
{
|
|
7393
7397
|
script: outputAddress.pkScript,
|
|
7394
7398
|
amount: BigInt(totalBtcSelected)
|
|
7395
7399
|
},
|
|
7396
|
-
Extension.create([
|
|
7400
|
+
Extension.create([chunkH62OOAS4_cjs.Packet.create(groups)]).txOut()
|
|
7397
7401
|
];
|
|
7398
7402
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
7399
7403
|
coinSelection.inputs,
|
|
@@ -7401,7 +7405,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7401
7405
|
);
|
|
7402
7406
|
return {
|
|
7403
7407
|
arkTxId: arkTxid,
|
|
7404
|
-
assetId:
|
|
7408
|
+
assetId: chunkH62OOAS4_cjs.AssetId.create(arkTxid, 0).toString()
|
|
7405
7409
|
};
|
|
7406
7410
|
}
|
|
7407
7411
|
/**
|
|
@@ -7430,7 +7434,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7430
7434
|
throw new Error(`Asset ${params.assetId} is not reissuable`);
|
|
7431
7435
|
}
|
|
7432
7436
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
7433
|
-
withRecoverable: false
|
|
7437
|
+
withRecoverable: false,
|
|
7438
|
+
genericallySpendableOnly: true
|
|
7434
7439
|
});
|
|
7435
7440
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
7436
7441
|
const { selected: controlCoins } = selectCoinsWithAsset(virtualCoins, controlAssetId, 1n);
|
|
@@ -7473,16 +7478,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7473
7478
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7474
7479
|
for (const asset of assets) {
|
|
7475
7480
|
if (asset.assetId !== params.assetId) continue;
|
|
7476
|
-
reissueInputs.push(
|
|
7481
|
+
reissueInputs.push(chunkH62OOAS4_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7477
7482
|
}
|
|
7478
7483
|
}
|
|
7479
7484
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
7480
|
-
const reissueAssetIdObj =
|
|
7481
|
-
const reissueAssetGroup =
|
|
7485
|
+
const reissueAssetIdObj = chunkH62OOAS4_cjs.AssetId.fromString(params.assetId);
|
|
7486
|
+
const reissueAssetGroup = chunkH62OOAS4_cjs.AssetGroup.create(
|
|
7482
7487
|
reissueAssetIdObj,
|
|
7483
7488
|
null,
|
|
7484
7489
|
reissueInputs,
|
|
7485
|
-
[
|
|
7490
|
+
[chunkH62OOAS4_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
7486
7491
|
[]
|
|
7487
7492
|
);
|
|
7488
7493
|
const groups = [reissueAssetGroup];
|
|
@@ -7491,27 +7496,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7491
7496
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7492
7497
|
for (const asset of assets) {
|
|
7493
7498
|
if (asset.assetId !== assetId) continue;
|
|
7494
|
-
changeInputs.push(
|
|
7499
|
+
changeInputs.push(chunkH62OOAS4_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7495
7500
|
}
|
|
7496
7501
|
}
|
|
7497
7502
|
groups.push(
|
|
7498
|
-
|
|
7499
|
-
|
|
7503
|
+
chunkH62OOAS4_cjs.AssetGroup.create(
|
|
7504
|
+
chunkH62OOAS4_cjs.AssetId.fromString(assetId),
|
|
7500
7505
|
null,
|
|
7501
7506
|
changeInputs,
|
|
7502
|
-
[
|
|
7507
|
+
[chunkH62OOAS4_cjs.AssetOutput.create(0, amount)],
|
|
7503
7508
|
[]
|
|
7504
7509
|
)
|
|
7505
7510
|
);
|
|
7506
7511
|
}
|
|
7507
7512
|
const address = await this.wallet.getAddress();
|
|
7508
|
-
const outputAddress =
|
|
7513
|
+
const outputAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
7509
7514
|
const outputs = [
|
|
7510
7515
|
{
|
|
7511
7516
|
script: outputAddress.pkScript,
|
|
7512
7517
|
amount: BigInt(totalBtcSelected)
|
|
7513
7518
|
},
|
|
7514
|
-
Extension.create([
|
|
7519
|
+
Extension.create([chunkH62OOAS4_cjs.Packet.create(groups)]).txOut()
|
|
7515
7520
|
];
|
|
7516
7521
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7517
7522
|
return arkTxid;
|
|
@@ -7536,7 +7541,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7536
7541
|
throw new Error(`Burn amount must be greater than 0, got ${params.amount}`);
|
|
7537
7542
|
}
|
|
7538
7543
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
7539
|
-
withRecoverable: false
|
|
7544
|
+
withRecoverable: false,
|
|
7545
|
+
genericallySpendableOnly: true
|
|
7540
7546
|
});
|
|
7541
7547
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
7542
7548
|
const { selected: assetCoins } = selectCoinsWithAsset(
|
|
@@ -7578,27 +7584,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7578
7584
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7579
7585
|
for (const asset of assets) {
|
|
7580
7586
|
if (asset.assetId !== assetId) continue;
|
|
7581
|
-
changeInputs.push(
|
|
7587
|
+
changeInputs.push(chunkH62OOAS4_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7582
7588
|
}
|
|
7583
7589
|
}
|
|
7584
7590
|
groups.push(
|
|
7585
|
-
|
|
7586
|
-
|
|
7591
|
+
chunkH62OOAS4_cjs.AssetGroup.create(
|
|
7592
|
+
chunkH62OOAS4_cjs.AssetId.fromString(assetId),
|
|
7587
7593
|
null,
|
|
7588
7594
|
changeInputs,
|
|
7589
|
-
amount > 0n ? [
|
|
7595
|
+
amount > 0n ? [chunkH62OOAS4_cjs.AssetOutput.create(0, amount)] : [],
|
|
7590
7596
|
[]
|
|
7591
7597
|
)
|
|
7592
7598
|
);
|
|
7593
7599
|
}
|
|
7594
7600
|
const address = await this.wallet.getAddress();
|
|
7595
|
-
const outputAddress =
|
|
7601
|
+
const outputAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(address);
|
|
7596
7602
|
const outputs = [
|
|
7597
7603
|
{
|
|
7598
7604
|
script: outputAddress.pkScript,
|
|
7599
7605
|
amount: BigInt(totalBtcSelected)
|
|
7600
7606
|
},
|
|
7601
|
-
Extension.create([
|
|
7607
|
+
Extension.create([chunkH62OOAS4_cjs.Packet.create(groups)]).txOut()
|
|
7602
7608
|
];
|
|
7603
7609
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7604
7610
|
return arkTxid;
|
|
@@ -7623,7 +7629,7 @@ function castMetadata(metadata) {
|
|
|
7623
7629
|
} else {
|
|
7624
7630
|
throw new Error("Invalid metadata value type");
|
|
7625
7631
|
}
|
|
7626
|
-
md.push(
|
|
7632
|
+
md.push(chunkH62OOAS4_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
7627
7633
|
}
|
|
7628
7634
|
return md;
|
|
7629
7635
|
}
|
|
@@ -7644,10 +7650,10 @@ var DelegateManagerImpl = class {
|
|
|
7644
7650
|
if (vtxos.length === 0) {
|
|
7645
7651
|
return { delegated: [], failed: [] };
|
|
7646
7652
|
}
|
|
7647
|
-
const destinationScript =
|
|
7653
|
+
const destinationScript = chunkCJN4CUEU_cjs.ArkAddress.decode(destination).pkScript;
|
|
7648
7654
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
7649
7655
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
7650
|
-
const eligible = vtxos.map(
|
|
7656
|
+
const eligible = vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo).filter(
|
|
7651
7657
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
7652
7658
|
);
|
|
7653
7659
|
if (eligible.length === 0) {
|
|
@@ -7676,11 +7682,11 @@ var DelegateManagerImpl = class {
|
|
|
7676
7682
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
7677
7683
|
let recoverableVtxos = [];
|
|
7678
7684
|
for (const vtxo of eligible) {
|
|
7679
|
-
if (
|
|
7685
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7680
7686
|
recoverableVtxos.push(vtxo);
|
|
7681
7687
|
continue;
|
|
7682
7688
|
}
|
|
7683
|
-
const expiry =
|
|
7689
|
+
const expiry = chunkCJN4CUEU_cjs.toBatchExpiry(vtxo);
|
|
7684
7690
|
if (!expiry) continue;
|
|
7685
7691
|
const dayKey = getDayTimestamp(expiry);
|
|
7686
7692
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -7745,7 +7751,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7745
7751
|
}
|
|
7746
7752
|
if (!delegateAt) {
|
|
7747
7753
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
7748
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
7754
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkCJN4CUEU_cjs.canRecoverOnchain(coin, now) && chunkCJN4CUEU_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunkCJN4CUEU_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
|
|
7749
7755
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
7750
7756
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
7751
7757
|
} else {
|
|
@@ -7769,7 +7775,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7769
7775
|
let amount = 0n;
|
|
7770
7776
|
for (const coin of vtxos) {
|
|
7771
7777
|
const inputFee = estimator.evalOffchainInput({
|
|
7772
|
-
...
|
|
7778
|
+
...chunkCJN4CUEU_cjs.toOffchainInputFeeParams(coin),
|
|
7773
7779
|
type: "vtxo"
|
|
7774
7780
|
});
|
|
7775
7781
|
if (inputFee.value >= coin.value) {
|
|
@@ -7783,7 +7789,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7783
7789
|
const delegateFee = BigInt(Number(fee));
|
|
7784
7790
|
if (delegateFee > 0n) {
|
|
7785
7791
|
outputs.push({
|
|
7786
|
-
script:
|
|
7792
|
+
script: chunkCJN4CUEU_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
7787
7793
|
amount: delegateFee
|
|
7788
7794
|
});
|
|
7789
7795
|
}
|
|
@@ -7816,10 +7822,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7816
7822
|
destinationScript
|
|
7817
7823
|
);
|
|
7818
7824
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
7819
|
-
btcSigner.Address(
|
|
7825
|
+
btcSigner.Address(chunkCJN4CUEU_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
7820
7826
|
);
|
|
7821
7827
|
const forfeits = await Promise.all(
|
|
7822
|
-
vtxos.filter((v) => !
|
|
7828
|
+
vtxos.filter((v) => !chunkCJN4CUEU_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
7823
7829
|
const forfeit = await makeDelegateForfeitTx(
|
|
7824
7830
|
coin,
|
|
7825
7831
|
dust,
|
|
@@ -7844,7 +7850,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
7844
7850
|
index: input.vout,
|
|
7845
7851
|
witnessUtxo: {
|
|
7846
7852
|
amount: BigInt(input.value),
|
|
7847
|
-
script:
|
|
7853
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
7848
7854
|
},
|
|
7849
7855
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
7850
7856
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -7902,7 +7908,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
7902
7908
|
expire_at: 0,
|
|
7903
7909
|
cosigners_public_keys: cosignerPubKeys
|
|
7904
7910
|
};
|
|
7905
|
-
const proof =
|
|
7911
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, outputs);
|
|
7906
7912
|
const signedProof = await identity.sign(proof);
|
|
7907
7913
|
return {
|
|
7908
7914
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -7928,10 +7934,10 @@ function getDayTimestamp(timestamp) {
|
|
|
7928
7934
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
7929
7935
|
if (!vtxo.tapTree) return void 0;
|
|
7930
7936
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
7931
|
-
const vtxoScript =
|
|
7937
|
+
const vtxoScript = chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
7932
7938
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
7933
|
-
const arkTapscript =
|
|
7934
|
-
if (!
|
|
7939
|
+
const arkTapscript = chunkCJN4CUEU_cjs.decodeTapscript(chunkCJN4CUEU_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
7940
|
+
if (!chunkCJN4CUEU_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
7935
7941
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
7936
7942
|
});
|
|
7937
7943
|
}
|
|
@@ -8212,7 +8218,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
|
|
|
8212
8218
|
};
|
|
8213
8219
|
}
|
|
8214
8220
|
function scriptFromArkAddress(address) {
|
|
8215
|
-
return base.hex.encode(
|
|
8221
|
+
return base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(address).pkScript);
|
|
8216
8222
|
}
|
|
8217
8223
|
|
|
8218
8224
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -8225,7 +8231,7 @@ var STORE_INTENTS = "intents";
|
|
|
8225
8231
|
var STORE_VIRTUAL_TXS = "virtualTxs";
|
|
8226
8232
|
var STORE_VTXO_BRANCHES = "vtxoBranches";
|
|
8227
8233
|
var LEGACY_STORE_CONTRACT_COLLECTIONS = "contractsCollections";
|
|
8228
|
-
var DB_VERSION =
|
|
8234
|
+
var DB_VERSION = 4;
|
|
8229
8235
|
var INTENT_DB_VERSION = 5;
|
|
8230
8236
|
function initDatabase(db, oldVersion, transaction) {
|
|
8231
8237
|
if (!db.objectStoreNames.contains(STORE_VTXOS)) {
|
|
@@ -8288,6 +8294,7 @@ function initDatabase(db, oldVersion, transaction) {
|
|
|
8288
8294
|
unique: false
|
|
8289
8295
|
});
|
|
8290
8296
|
}
|
|
8297
|
+
vtxosStore.createIndex("scriptUnspent", ["script", "unspent"], { unique: false });
|
|
8291
8298
|
}
|
|
8292
8299
|
if (!db.objectStoreNames.contains(STORE_UTXOS)) {
|
|
8293
8300
|
const utxosStore = db.createObjectStore(STORE_UTXOS, {
|
|
@@ -8370,14 +8377,18 @@ function initDatabase(db, oldVersion, transaction) {
|
|
|
8370
8377
|
keyPath: "key"
|
|
8371
8378
|
});
|
|
8372
8379
|
}
|
|
8373
|
-
if (oldVersion >= 1 && oldVersion <
|
|
8380
|
+
if (oldVersion >= 1 && oldVersion < 4 && transaction) {
|
|
8374
8381
|
const vtxosStore = transaction.objectStore(STORE_VTXOS);
|
|
8375
8382
|
if (!vtxosStore.indexNames.contains("script")) {
|
|
8376
8383
|
vtxosStore.createIndex("script", "script", { unique: false });
|
|
8377
8384
|
}
|
|
8378
|
-
|
|
8385
|
+
if (!vtxosStore.indexNames.contains("scriptUnspent")) {
|
|
8386
|
+
vtxosStore.createIndex("scriptUnspent", ["script", "unspent"], { unique: false });
|
|
8387
|
+
}
|
|
8388
|
+
backfillVtxoIndexFields(transaction);
|
|
8379
8389
|
}
|
|
8380
8390
|
}
|
|
8391
|
+
var unspentFlag = (vtxo) => chunkCJN4CUEU_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
|
|
8381
8392
|
function initDatabaseWithIntents(db, oldVersion, transaction) {
|
|
8382
8393
|
initDatabase(db, oldVersion, transaction);
|
|
8383
8394
|
if (!db.objectStoreNames.contains(STORE_INTENTS)) {
|
|
@@ -8427,19 +8438,28 @@ function dedupeIntentIds(store, onComplete) {
|
|
|
8427
8438
|
cursor.continue();
|
|
8428
8439
|
};
|
|
8429
8440
|
}
|
|
8430
|
-
function
|
|
8441
|
+
function backfillVtxoIndexFields(transaction) {
|
|
8431
8442
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
8432
|
-
const
|
|
8433
|
-
|
|
8434
|
-
const
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8443
|
+
const pageSize = 1e3;
|
|
8444
|
+
const readPage = (after) => {
|
|
8445
|
+
const request = store.getAll(after && IDBKeyRange.lowerBound(after, true), pageSize);
|
|
8446
|
+
request.onsuccess = () => {
|
|
8447
|
+
const rows = request.result;
|
|
8448
|
+
for (const value of rows) {
|
|
8449
|
+
const next = {
|
|
8450
|
+
...value,
|
|
8451
|
+
script: value.script || scriptFromArkAddress(value.address),
|
|
8452
|
+
...unspentFlag(value)
|
|
8453
|
+
};
|
|
8454
|
+
if (next.script !== value.script || next.unspent !== value.unspent) {
|
|
8455
|
+
store.put(next);
|
|
8456
|
+
}
|
|
8457
|
+
}
|
|
8458
|
+
const last = rows.at(-1);
|
|
8459
|
+
if (rows.length === pageSize && last) readPage([last.address, last.txid, last.vout]);
|
|
8460
|
+
};
|
|
8442
8461
|
};
|
|
8462
|
+
readPage();
|
|
8443
8463
|
}
|
|
8444
8464
|
|
|
8445
8465
|
// src/worker/browser/utils.ts
|
|
@@ -8707,7 +8727,7 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
8707
8727
|
}
|
|
8708
8728
|
async function getVtxosForContract(repo, contract) {
|
|
8709
8729
|
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
8710
|
-
return vtxos.map(
|
|
8730
|
+
return vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
8711
8731
|
}
|
|
8712
8732
|
function hasRecordedSpend(vtxo) {
|
|
8713
8733
|
return vtxo.isSpent === true && (!!vtxo.spentBy || !!vtxo.arkTxId || !!vtxo.settledBy);
|
|
@@ -8798,15 +8818,21 @@ var InMemoryWalletRepository = class {
|
|
|
8798
8818
|
this.vtxosByAddress.delete(address);
|
|
8799
8819
|
}
|
|
8800
8820
|
async getVtxosForScript(script) {
|
|
8801
|
-
|
|
8821
|
+
return this.getVtxosForScripts([script]);
|
|
8822
|
+
}
|
|
8823
|
+
async getVtxosForScripts(scripts, options) {
|
|
8824
|
+
if (scripts.length === 0) return [];
|
|
8825
|
+
const selected = new Set(scripts);
|
|
8826
|
+
const byOutpoint = /* @__PURE__ */ new Map();
|
|
8802
8827
|
for (const bucket of this.vtxosByAddress.values()) {
|
|
8803
8828
|
for (const vtxo of bucket) {
|
|
8804
|
-
if (
|
|
8805
|
-
|
|
8829
|
+
if (vtxo.script && selected.has(vtxo.script)) {
|
|
8830
|
+
byOutpoint.set(`${vtxo.script}:${vtxo.txid}:${vtxo.vout}`, vtxo);
|
|
8806
8831
|
}
|
|
8807
8832
|
}
|
|
8808
8833
|
}
|
|
8809
|
-
|
|
8834
|
+
const rows = [...byOutpoint.values()];
|
|
8835
|
+
return options?.unspentOnly ? rows.filter((vtxo) => !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) : rows;
|
|
8810
8836
|
}
|
|
8811
8837
|
async saveVtxosForScript(key, vtxos) {
|
|
8812
8838
|
if (!key.address) {
|
|
@@ -8908,7 +8934,7 @@ function decodeArkContract(encoded) {
|
|
|
8908
8934
|
}
|
|
8909
8935
|
function contractFromArkContract(encoded, options = {}) {
|
|
8910
8936
|
const parsed = decodeArkContract(encoded);
|
|
8911
|
-
const handler =
|
|
8937
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(parsed.type);
|
|
8912
8938
|
if (!handler) {
|
|
8913
8939
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
8914
8940
|
}
|
|
@@ -8922,9 +8948,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
8922
8948
|
metadata: options.metadata
|
|
8923
8949
|
};
|
|
8924
8950
|
}
|
|
8925
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
8951
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkCJN4CUEU_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
8926
8952
|
const parsed = decodeArkContract(encoded);
|
|
8927
|
-
const handler =
|
|
8953
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
8928
8954
|
const params = parsed.data;
|
|
8929
8955
|
const vtxoScript = handler.createScript(params);
|
|
8930
8956
|
return {
|
|
@@ -9230,9 +9256,9 @@ var ContractWatcher = class {
|
|
|
9230
9256
|
this.connectionState = "connected";
|
|
9231
9257
|
this.reconnectAttempts = 0;
|
|
9232
9258
|
this.listenLoop().catch((e) => {
|
|
9233
|
-
if (
|
|
9259
|
+
if (chunkCJN4CUEU_cjs.isEventSourceError(e)) {
|
|
9234
9260
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
9235
|
-
} else if (!
|
|
9261
|
+
} else if (!chunkCJN4CUEU_cjs.isEventSourceUnavailableError(e)) {
|
|
9236
9262
|
console.error(e);
|
|
9237
9263
|
}
|
|
9238
9264
|
this.connectionState = "disconnected";
|
|
@@ -9244,7 +9270,7 @@ var ContractWatcher = class {
|
|
|
9244
9270
|
this.scheduleReconnect();
|
|
9245
9271
|
});
|
|
9246
9272
|
} catch (error) {
|
|
9247
|
-
if (!
|
|
9273
|
+
if (!chunkCJN4CUEU_cjs.isEventSourceUnavailableError(error)) {
|
|
9248
9274
|
console.error("ContractWatcher connection failed:", error);
|
|
9249
9275
|
}
|
|
9250
9276
|
this.connectionState = "disconnected";
|
|
@@ -9270,7 +9296,7 @@ var ContractWatcher = class {
|
|
|
9270
9296
|
* slower; what it loses is push latency.
|
|
9271
9297
|
*/
|
|
9272
9298
|
reportEventSourceUnavailable(error) {
|
|
9273
|
-
if (!
|
|
9299
|
+
if (!chunkCJN4CUEU_cjs.isEventSourceUnavailableError(error)) return false;
|
|
9274
9300
|
if (!this.eventSourceReported) {
|
|
9275
9301
|
this.eventSourceReported = true;
|
|
9276
9302
|
console.warn(
|
|
@@ -9342,7 +9368,7 @@ var ContractWatcher = class {
|
|
|
9342
9368
|
const now = Date.now();
|
|
9343
9369
|
let current;
|
|
9344
9370
|
try {
|
|
9345
|
-
current = await
|
|
9371
|
+
current = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
9346
9372
|
spendableOnly: true
|
|
9347
9373
|
});
|
|
9348
9374
|
} catch (error) {
|
|
@@ -9551,14 +9577,14 @@ var ContractWatcher = class {
|
|
|
9551
9577
|
const timestamp = Date.now();
|
|
9552
9578
|
if (update.newVtxos?.length) {
|
|
9553
9579
|
this.processSubscriptionVtxos(
|
|
9554
|
-
update.newVtxos.map(
|
|
9580
|
+
update.newVtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo),
|
|
9555
9581
|
"vtxo_received",
|
|
9556
9582
|
timestamp
|
|
9557
9583
|
);
|
|
9558
9584
|
}
|
|
9559
9585
|
if (update.spentVtxos?.length) {
|
|
9560
9586
|
this.processSubscriptionVtxos(
|
|
9561
|
-
update.spentVtxos.map(
|
|
9587
|
+
update.spentVtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo),
|
|
9562
9588
|
"vtxo_spent",
|
|
9563
9589
|
timestamp
|
|
9564
9590
|
);
|
|
@@ -9586,8 +9612,8 @@ var ContractWatcher = class {
|
|
|
9586
9612
|
continue;
|
|
9587
9613
|
}
|
|
9588
9614
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
9589
|
-
const n =
|
|
9590
|
-
if (
|
|
9615
|
+
const n = chunkCJN4CUEU_cjs.normalizeVtxo(vtxo);
|
|
9616
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(n) || n.isSwept || chunkCJN4CUEU_cjs.isPastExpiry(n, now)) continue;
|
|
9591
9617
|
}
|
|
9592
9618
|
let bucket = target.get(vtxo.script);
|
|
9593
9619
|
if (!bucket) {
|
|
@@ -9686,7 +9712,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
9686
9712
|
(s) => !isTerminalIntentState(s)
|
|
9687
9713
|
);
|
|
9688
9714
|
function isConsumed(vtxo) {
|
|
9689
|
-
return vtxo !== void 0 &&
|
|
9715
|
+
return vtxo !== void 0 && chunkCJN4CUEU_cjs.isVtxoSpent(vtxo);
|
|
9690
9716
|
}
|
|
9691
9717
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
9692
9718
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -9729,7 +9755,7 @@ async function reconcileIntents(deps) {
|
|
|
9729
9755
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
9730
9756
|
if (outpoints.length > 0) {
|
|
9731
9757
|
try {
|
|
9732
|
-
const { vtxos } = await
|
|
9758
|
+
const { vtxos } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9733
9759
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9734
9760
|
} catch (e) {
|
|
9735
9761
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9786,7 +9812,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
9786
9812
|
if (!contract) continue;
|
|
9787
9813
|
try {
|
|
9788
9814
|
const key = `${contract.type}\0${script}\0${JSON.stringify(contract.params)}`;
|
|
9789
|
-
const handler =
|
|
9815
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
9790
9816
|
const hit = memo?.get(script);
|
|
9791
9817
|
let tapscripts;
|
|
9792
9818
|
if (hit && hit.key === key && hit.handler === handler) {
|
|
@@ -9941,7 +9967,7 @@ var ContractManager = class _ContractManager {
|
|
|
9941
9967
|
try {
|
|
9942
9968
|
await this.scheduleLookAheadDrain();
|
|
9943
9969
|
} catch (err) {
|
|
9944
|
-
if (!
|
|
9970
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
9945
9971
|
this.lookAheadRefillOwed = true;
|
|
9946
9972
|
this.markSyncDegraded(err);
|
|
9947
9973
|
}
|
|
@@ -9949,7 +9975,7 @@ var ContractManager = class _ContractManager {
|
|
|
9949
9975
|
await this.reconcileWatched();
|
|
9950
9976
|
this.markSyncOnline();
|
|
9951
9977
|
} catch (err) {
|
|
9952
|
-
if (!
|
|
9978
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
9953
9979
|
this.markSyncDegraded(err);
|
|
9954
9980
|
}
|
|
9955
9981
|
this.initialized = true;
|
|
@@ -10081,7 +10107,7 @@ var ContractManager = class _ContractManager {
|
|
|
10081
10107
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
10082
10108
|
const to = watermark + lookAhead.size;
|
|
10083
10109
|
const deps = lookAhead.candidateDeps();
|
|
10084
|
-
const handlers =
|
|
10110
|
+
const handlers = chunkLUWSY2QO_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkLUWSY2QO_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
10085
10111
|
const band = /* @__PURE__ */ new Map();
|
|
10086
10112
|
for (let index = from; index <= to; index++) {
|
|
10087
10113
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -10092,7 +10118,7 @@ var ContractManager = class _ContractManager {
|
|
|
10092
10118
|
index,
|
|
10093
10119
|
params: {
|
|
10094
10120
|
...candidate,
|
|
10095
|
-
...
|
|
10121
|
+
...chunkLUWSY2QO_cjs.speculativeReceiveMetadata(descriptor)
|
|
10096
10122
|
}
|
|
10097
10123
|
});
|
|
10098
10124
|
}
|
|
@@ -10154,7 +10180,7 @@ var ContractManager = class _ContractManager {
|
|
|
10154
10180
|
});
|
|
10155
10181
|
for (const entry of pending) entry.catchUpPending = false;
|
|
10156
10182
|
} catch (err) {
|
|
10157
|
-
if (!
|
|
10183
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10158
10184
|
this.markSyncDegraded(err);
|
|
10159
10185
|
}
|
|
10160
10186
|
}
|
|
@@ -10204,7 +10230,7 @@ var ContractManager = class _ContractManager {
|
|
|
10204
10230
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
10205
10231
|
this.markSyncOnline();
|
|
10206
10232
|
} catch (err) {
|
|
10207
|
-
if (!
|
|
10233
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10208
10234
|
this.markSyncDegraded(err);
|
|
10209
10235
|
}
|
|
10210
10236
|
await this.watcher.addContract(contract);
|
|
@@ -10238,7 +10264,7 @@ var ContractManager = class _ContractManager {
|
|
|
10238
10264
|
await this.fetchContractVxosFromIndexer(fresh);
|
|
10239
10265
|
this.markSyncOnline();
|
|
10240
10266
|
} catch (err) {
|
|
10241
|
-
if (!
|
|
10267
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10242
10268
|
this.markSyncDegraded(err);
|
|
10243
10269
|
}
|
|
10244
10270
|
for (const contract of fresh) await this.watcher.addContract(contract);
|
|
@@ -10276,7 +10302,7 @@ var ContractManager = class _ContractManager {
|
|
|
10276
10302
|
return result;
|
|
10277
10303
|
}
|
|
10278
10304
|
async upsertContractRow(params) {
|
|
10279
|
-
const handler =
|
|
10305
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(params.type);
|
|
10280
10306
|
if (!handler) {
|
|
10281
10307
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
10282
10308
|
}
|
|
@@ -10376,7 +10402,7 @@ var ContractManager = class _ContractManager {
|
|
|
10376
10402
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
10377
10403
|
);
|
|
10378
10404
|
}
|
|
10379
|
-
const registered =
|
|
10405
|
+
const registered = chunkLUWSY2QO_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkLUWSY2QO_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
10380
10406
|
const discoverables = [
|
|
10381
10407
|
...registered.filter((h) => h.type === "boarding"),
|
|
10382
10408
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -10505,23 +10531,40 @@ var ContractManager = class _ContractManager {
|
|
|
10505
10531
|
const dbFilter = this.buildContractsDbFilter(filter ?? {});
|
|
10506
10532
|
return await this.config.contractRepository.getContracts(dbFilter);
|
|
10507
10533
|
}
|
|
10508
|
-
async getContractsWithVtxos(filter, pageSize) {
|
|
10534
|
+
async getContractsWithVtxos(filter, pageSize, options) {
|
|
10535
|
+
if (options?.maxSyncAgeMs !== void 0 && (!Number.isSafeInteger(options.maxSyncAgeMs) || options.maxSyncAgeMs < 0)) {
|
|
10536
|
+
throw new Error("maxSyncAgeMs must be a non-negative safe integer");
|
|
10537
|
+
}
|
|
10509
10538
|
const contracts = await this.getContracts(filter);
|
|
10510
|
-
if (this.syncedWithin(
|
|
10539
|
+
if (this.syncedWithin(
|
|
10540
|
+
contracts,
|
|
10541
|
+
options?.maxSyncAgeMs ?? (options?.requireSynced ? 0 : this.config.vtxoSyncMaxAgeMs ?? 0)
|
|
10542
|
+
)) {
|
|
10511
10543
|
await this.demoteFundedAwaitingContracts(contracts);
|
|
10512
10544
|
} else {
|
|
10513
10545
|
try {
|
|
10514
10546
|
await this.syncContracts({ contracts, pageSize });
|
|
10515
10547
|
this.markSyncOnline();
|
|
10516
10548
|
} catch (err) {
|
|
10517
|
-
if (!
|
|
10549
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10518
10550
|
this.markSyncDegraded(err);
|
|
10551
|
+
if (options?.requireSynced) {
|
|
10552
|
+
throw new Error("Spendable VTXO read requires an online contract sync", {
|
|
10553
|
+
cause: err
|
|
10554
|
+
});
|
|
10555
|
+
}
|
|
10519
10556
|
}
|
|
10520
10557
|
}
|
|
10521
|
-
const vtxos = await this.getVtxosForContracts(contracts);
|
|
10558
|
+
const vtxos = await this.getVtxosForContracts(contracts, options);
|
|
10559
|
+
const vtxosByScript = /* @__PURE__ */ new Map();
|
|
10560
|
+
for (const vtxo of vtxos) {
|
|
10561
|
+
const group = vtxosByScript.get(vtxo.contractScript) ?? [];
|
|
10562
|
+
group.push(vtxo);
|
|
10563
|
+
vtxosByScript.set(vtxo.contractScript, group);
|
|
10564
|
+
}
|
|
10522
10565
|
return contracts.map((contract) => ({
|
|
10523
10566
|
contract,
|
|
10524
|
-
vtxos:
|
|
10567
|
+
vtxos: vtxosByScript.get(contract.script)?.slice() ?? []
|
|
10525
10568
|
}));
|
|
10526
10569
|
}
|
|
10527
10570
|
async annotateVtxos(vtxos, tapscripts) {
|
|
@@ -10536,7 +10579,7 @@ var ContractManager = class _ContractManager {
|
|
|
10536
10579
|
}
|
|
10537
10580
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
10538
10581
|
return vtxos.map(
|
|
10539
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
10582
|
+
(vtxo) => extendVirtualCoinForContract(chunkCJN4CUEU_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
10540
10583
|
);
|
|
10541
10584
|
}
|
|
10542
10585
|
/** @inheritdoc */
|
|
@@ -10581,14 +10624,14 @@ var ContractManager = class _ContractManager {
|
|
|
10581
10624
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10582
10625
|
const asking = vtxos.filter((vtxo) => {
|
|
10583
10626
|
const contract = byScript.get(vtxo.script);
|
|
10584
|
-
return contract !== void 0 &&
|
|
10627
|
+
return contract !== void 0 && chunkLUWSY2QO_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10585
10628
|
});
|
|
10586
10629
|
if (asking.length === 0) return refused;
|
|
10587
10630
|
const tip = await this.currentChainTip();
|
|
10588
10631
|
const walletKey = await walletPubKey?.();
|
|
10589
10632
|
for (const vtxo of asking) {
|
|
10590
10633
|
const contract = byScript.get(vtxo.script);
|
|
10591
|
-
const handler =
|
|
10634
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10592
10635
|
if (!handler?.assertSpendableNow) continue;
|
|
10593
10636
|
const context = {
|
|
10594
10637
|
collaborative: true,
|
|
@@ -10603,7 +10646,7 @@ var ContractManager = class _ContractManager {
|
|
|
10603
10646
|
// the next handler to answer a CSV question would meet a
|
|
10604
10647
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
10605
10648
|
// really is one.
|
|
10606
|
-
vtxo:
|
|
10649
|
+
vtxo: chunkCJN4CUEU_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10607
10650
|
};
|
|
10608
10651
|
try {
|
|
10609
10652
|
await handler.assertSpendableNow(
|
|
@@ -10760,7 +10803,7 @@ var ContractManager = class _ContractManager {
|
|
|
10760
10803
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
10761
10804
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10762
10805
|
if (!contract) return [];
|
|
10763
|
-
const handler =
|
|
10806
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10764
10807
|
if (!handler) return [];
|
|
10765
10808
|
const script = handler.createScript(contract.params);
|
|
10766
10809
|
const tip = await this.currentChainTip();
|
|
@@ -10788,7 +10831,7 @@ var ContractManager = class _ContractManager {
|
|
|
10788
10831
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
10789
10832
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10790
10833
|
if (!contract) return [];
|
|
10791
|
-
const handler =
|
|
10834
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10792
10835
|
if (!handler) return [];
|
|
10793
10836
|
const script = handler.createScript(contract.params);
|
|
10794
10837
|
const context = {
|
|
@@ -10844,7 +10887,7 @@ var ContractManager = class _ContractManager {
|
|
|
10844
10887
|
}
|
|
10845
10888
|
async refreshOutpoints(outpoints) {
|
|
10846
10889
|
if (outpoints.length === 0) return;
|
|
10847
|
-
const { vtxos } = await
|
|
10890
|
+
const { vtxos } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10848
10891
|
outpoints
|
|
10849
10892
|
});
|
|
10850
10893
|
if (vtxos.length === 0) return;
|
|
@@ -10946,25 +10989,33 @@ var ContractManager = class _ContractManager {
|
|
|
10946
10989
|
break;
|
|
10947
10990
|
}
|
|
10948
10991
|
} catch (err) {
|
|
10949
|
-
if (!
|
|
10992
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10950
10993
|
this.markSyncDegraded(err);
|
|
10951
10994
|
}
|
|
10952
10995
|
this.emitEvent(event);
|
|
10953
10996
|
}
|
|
10954
|
-
async getVtxosForContracts(contracts) {
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10997
|
+
async getVtxosForContracts(contracts, options) {
|
|
10998
|
+
if (contracts.length === 0) return [];
|
|
10999
|
+
let rows;
|
|
11000
|
+
if (this.config.walletRepository.getVtxosForScripts) {
|
|
11001
|
+
const byScript = new Set(contracts.map((contract) => contract.script));
|
|
11002
|
+
rows = (await this.config.walletRepository.getVtxosForScripts([...byScript], options)).filter((vtxo) => vtxo.script !== void 0 && byScript.has(vtxo.script)).map((vtxo) => ({ ...chunkCJN4CUEU_cjs.normalizeVtxo(vtxo), contractScript: vtxo.script }));
|
|
11003
|
+
} else {
|
|
11004
|
+
const res = await Promise.all(
|
|
11005
|
+
contracts.map(
|
|
11006
|
+
(contract) => getVtxosForContract(this.config.walletRepository, contract).then(
|
|
11007
|
+
(vtxos) => vtxos.map(
|
|
11008
|
+
(vtxo) => ({
|
|
11009
|
+
...vtxo,
|
|
11010
|
+
contractScript: contract.script
|
|
11011
|
+
})
|
|
11012
|
+
)
|
|
10963
11013
|
)
|
|
10964
11014
|
)
|
|
10965
|
-
)
|
|
10966
|
-
|
|
10967
|
-
|
|
11015
|
+
);
|
|
11016
|
+
rows = res.flat();
|
|
11017
|
+
}
|
|
11018
|
+
return options?.unspentOnly ? rows.filter((vtxo) => !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) : rows;
|
|
10968
11019
|
}
|
|
10969
11020
|
/**
|
|
10970
11021
|
* Sync virtual outputs for the given contracts against the indexer.
|
|
@@ -11037,7 +11088,7 @@ var ContractManager = class _ContractManager {
|
|
|
11037
11088
|
*/
|
|
11038
11089
|
async reconcilePendingFrontier(contracts) {
|
|
11039
11090
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
11040
|
-
const vtxos = await
|
|
11091
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(
|
|
11041
11092
|
this.config.indexerProvider,
|
|
11042
11093
|
contracts.map((c) => c.script),
|
|
11043
11094
|
{ pendingOnly: true }
|
|
@@ -11124,7 +11175,7 @@ var ContractManager = class _ContractManager {
|
|
|
11124
11175
|
}
|
|
11125
11176
|
return result;
|
|
11126
11177
|
}
|
|
11127
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
11178
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
11128
11179
|
if (contracts.length === 0) {
|
|
11129
11180
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
11130
11181
|
}
|
|
@@ -11140,7 +11191,7 @@ var ContractManager = class _ContractManager {
|
|
|
11140
11191
|
before: syncWindow.before
|
|
11141
11192
|
}
|
|
11142
11193
|
} : {};
|
|
11143
|
-
const vtxos = await
|
|
11194
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(
|
|
11144
11195
|
this.config.indexerProvider,
|
|
11145
11196
|
contracts.map((c) => c.script),
|
|
11146
11197
|
{ ...windowOpts, pageSize }
|
|
@@ -11289,7 +11340,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
11289
11340
|
const s = base.hex.decode(t.s);
|
|
11290
11341
|
return [cb, s];
|
|
11291
11342
|
};
|
|
11292
|
-
var deserializeVtxo = (o) =>
|
|
11343
|
+
var deserializeVtxo = (o) => chunkCJN4CUEU_cjs.normalizeVtxo({
|
|
11293
11344
|
...o,
|
|
11294
11345
|
createdAt: new Date(o.createdAt),
|
|
11295
11346
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11465,7 +11516,7 @@ var IndexedDBWalletRepository = class {
|
|
|
11465
11516
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
11466
11517
|
for (const vtxo of vtxos) {
|
|
11467
11518
|
const serialized = serializeVtxo(vtxo);
|
|
11468
|
-
store.put({ address, ...serialized });
|
|
11519
|
+
store.put({ address, ...serialized, ...unspentFlag(vtxo) });
|
|
11469
11520
|
}
|
|
11470
11521
|
await awaitTransaction(transaction);
|
|
11471
11522
|
} catch (error) {
|
|
@@ -11485,31 +11536,52 @@ var IndexedDBWalletRepository = class {
|
|
|
11485
11536
|
}
|
|
11486
11537
|
}
|
|
11487
11538
|
async getVtxosForScript(script) {
|
|
11539
|
+
return this.getVtxosForScripts([script]);
|
|
11540
|
+
}
|
|
11541
|
+
async getVtxosForScripts(scripts, options) {
|
|
11542
|
+
const unique = [...new Set(scripts)];
|
|
11543
|
+
if (unique.length === 0) return [];
|
|
11488
11544
|
try {
|
|
11489
11545
|
const db = await this.getDB();
|
|
11490
|
-
const
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11546
|
+
const rows = options?.unspentOnly ? await getAllByIndexValues(
|
|
11547
|
+
this.vtxoStore(db),
|
|
11548
|
+
"scriptUnspent",
|
|
11549
|
+
unique.map((script) => [script, 1])
|
|
11550
|
+
) : await getAllByIndexValues(this.vtxoStore(db), "script", unique);
|
|
11551
|
+
const selected = new Set(unique);
|
|
11495
11552
|
const byOutpoint = /* @__PURE__ */ new Map();
|
|
11496
|
-
for (const row of
|
|
11497
|
-
|
|
11498
|
-
const
|
|
11499
|
-
|
|
11500
|
-
|
|
11553
|
+
for (const row of rows) {
|
|
11554
|
+
if (!selected.has(row.script)) continue;
|
|
11555
|
+
const key = `${row.script}:${row.txid}:${row.vout}`;
|
|
11556
|
+
const existing = byOutpoint.get(key);
|
|
11557
|
+
if (!existing || shouldReplaceVtxo(existing, row)) byOutpoint.set(key, row);
|
|
11558
|
+
}
|
|
11559
|
+
if (options?.unspentOnly && byOutpoint.size > 0) {
|
|
11560
|
+
const txids = [...new Set([...byOutpoint.values()].map((row) => row.txid))];
|
|
11561
|
+
const store = this.vtxoStore(db);
|
|
11562
|
+
for (const row of await getAllByIndexValues(store, "txid", txids)) {
|
|
11563
|
+
const key = `${row.script}:${row.txid}:${row.vout}`;
|
|
11564
|
+
const existing = byOutpoint.get(key);
|
|
11565
|
+
if (existing && shouldReplaceVtxo(existing, row)) byOutpoint.set(key, row);
|
|
11566
|
+
}
|
|
11567
|
+
}
|
|
11568
|
+
const result = [];
|
|
11569
|
+
for (const row of byOutpoint.values()) {
|
|
11570
|
+
if (options?.unspentOnly && (row.isSpent || row.spentBy || row.settledBy)) {
|
|
11501
11571
|
continue;
|
|
11502
11572
|
}
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
}
|
|
11573
|
+
const vtxo = deserializeVtxoWithBackfill(row);
|
|
11574
|
+
if (!options?.unspentOnly || !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) result.push(vtxo);
|
|
11506
11575
|
}
|
|
11507
|
-
return
|
|
11576
|
+
return result;
|
|
11508
11577
|
} catch (error) {
|
|
11509
|
-
console.error(
|
|
11578
|
+
console.error("Failed to get VTXOs for scripts:", error);
|
|
11510
11579
|
throw error;
|
|
11511
11580
|
}
|
|
11512
11581
|
}
|
|
11582
|
+
vtxoStore(db) {
|
|
11583
|
+
return db.transaction([STORE_VTXOS], "readonly").objectStore(STORE_VTXOS);
|
|
11584
|
+
}
|
|
11513
11585
|
async saveVtxosForScript(key, vtxos) {
|
|
11514
11586
|
if (!key.address) {
|
|
11515
11587
|
throw new Error("IndexedDBWalletRepository requires an address");
|
|
@@ -11640,7 +11712,7 @@ var IndexedDBWalletRepository = class {
|
|
|
11640
11712
|
return this.connection.get();
|
|
11641
11713
|
}
|
|
11642
11714
|
};
|
|
11643
|
-
function deserializeVtxoWithBackfill(o) {
|
|
11715
|
+
function deserializeVtxoWithBackfill({ unspent: _unspent, ...o }) {
|
|
11644
11716
|
if (!o.script) {
|
|
11645
11717
|
o = { ...o, script: scriptFromArkAddress(o.address) };
|
|
11646
11718
|
}
|
|
@@ -12112,7 +12184,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
12112
12184
|
*/
|
|
12113
12185
|
materializeDescriptorAt(index) {
|
|
12114
12186
|
const descriptor = this.identity.descriptor;
|
|
12115
|
-
const network =
|
|
12187
|
+
const network = chunkLUWSY2QO_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
12116
12188
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
12117
12189
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
12118
12190
|
if (!keyInfo?.keyExpression) {
|
|
@@ -12260,7 +12332,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12260
12332
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
12261
12333
|
if (!provider) return void 0;
|
|
12262
12334
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
12263
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
12335
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
12264
12336
|
const factoryOpts = {
|
|
12265
12337
|
walletRepository: setup.walletRepository,
|
|
12266
12338
|
contractRepository: setup.contractRepository,
|
|
@@ -12461,7 +12533,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12461
12533
|
};
|
|
12462
12534
|
function deriveLeafPubkey(descriptor) {
|
|
12463
12535
|
try {
|
|
12464
|
-
return
|
|
12536
|
+
return chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
12465
12537
|
} catch (e) {
|
|
12466
12538
|
throw new NonRangeableDescriptorError(
|
|
12467
12539
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -12473,7 +12545,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12473
12545
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
12474
12546
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
12475
12547
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
12476
|
-
const csvTimelock =
|
|
12548
|
+
const csvTimelock = chunkCJN4CUEU_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
12477
12549
|
const base$1 = {
|
|
12478
12550
|
script: base.hex.encode(tapscript.pkScript),
|
|
12479
12551
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -12484,11 +12556,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12484
12556
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
12485
12557
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
12486
12558
|
metadata: {
|
|
12487
|
-
...tagSource && { source:
|
|
12559
|
+
...tagSource && { source: chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE },
|
|
12488
12560
|
signingDescriptor: descriptor
|
|
12489
12561
|
}
|
|
12490
12562
|
};
|
|
12491
|
-
const params = tapscript instanceof
|
|
12563
|
+
const params = tapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? {
|
|
12492
12564
|
...base$1,
|
|
12493
12565
|
type: "delegate",
|
|
12494
12566
|
params: {
|
|
@@ -12509,10 +12581,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12509
12581
|
return { tapscript, params };
|
|
12510
12582
|
}
|
|
12511
12583
|
function rebuildTapscript(current, pubKey) {
|
|
12512
|
-
if (current instanceof
|
|
12513
|
-
return new
|
|
12584
|
+
if (current instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script) {
|
|
12585
|
+
return new chunkLUWSY2QO_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12514
12586
|
}
|
|
12515
|
-
return new
|
|
12587
|
+
return new chunkLUWSY2QO_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12516
12588
|
}
|
|
12517
12589
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12518
12590
|
const candidates = await contractRepository.getContracts({
|
|
@@ -12521,7 +12593,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
12521
12593
|
});
|
|
12522
12594
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
12523
12595
|
const matching = candidates.filter(
|
|
12524
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12596
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE
|
|
12525
12597
|
).sort((a, b) => {
|
|
12526
12598
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12527
12599
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12577,7 +12649,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12577
12649
|
}
|
|
12578
12650
|
};
|
|
12579
12651
|
for (const vtxo of vtxos) {
|
|
12580
|
-
if (
|
|
12652
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) continue;
|
|
12581
12653
|
addAssets(owned, vtxo);
|
|
12582
12654
|
if (vtxo.isUnrolled) {
|
|
12583
12655
|
unrolled += vtxo.value;
|
|
@@ -12587,11 +12659,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12587
12659
|
pendingRecovery += vtxo.value;
|
|
12588
12660
|
continue;
|
|
12589
12661
|
}
|
|
12590
|
-
if (
|
|
12662
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12591
12663
|
recoverable += vtxo.value;
|
|
12592
12664
|
continue;
|
|
12593
12665
|
}
|
|
12594
|
-
if (!
|
|
12666
|
+
if (!chunkCJN4CUEU_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12595
12667
|
if (vtxo.isPreconfirmed) {
|
|
12596
12668
|
preconfirmed += vtxo.value;
|
|
12597
12669
|
} else {
|
|
@@ -12768,12 +12840,12 @@ var InputSignerRouter = class {
|
|
|
12768
12840
|
};
|
|
12769
12841
|
|
|
12770
12842
|
// src/wallet/wallet.ts
|
|
12771
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
12843
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkCJN4CUEU_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12772
12844
|
function intentProofJobs(coins) {
|
|
12773
12845
|
if (coins.length === 0) return [];
|
|
12774
12846
|
const coinJobs = coins.map((coin, i) => ({
|
|
12775
12847
|
index: i + 1,
|
|
12776
|
-
lookupScript:
|
|
12848
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12777
12849
|
}));
|
|
12778
12850
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12779
12851
|
}
|
|
@@ -12805,7 +12877,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12805
12877
|
const seen = /* @__PURE__ */ new Set();
|
|
12806
12878
|
const deduped = [];
|
|
12807
12879
|
for (const timelock of timelocks) {
|
|
12808
|
-
const sequence =
|
|
12880
|
+
const sequence = chunkCJN4CUEU_cjs.timelockToSequence(timelock).toString();
|
|
12809
12881
|
if (seen.has(sequence)) continue;
|
|
12810
12882
|
seen.add(sequence);
|
|
12811
12883
|
deduped.push(timelock);
|
|
@@ -12822,7 +12894,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12822
12894
|
state: "active"
|
|
12823
12895
|
});
|
|
12824
12896
|
const newest = candidates.filter(
|
|
12825
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12897
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE
|
|
12826
12898
|
).sort((a, b) => {
|
|
12827
12899
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12828
12900
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12830,7 +12902,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12830
12902
|
if (!newest?.params.pubKey) return baseline;
|
|
12831
12903
|
try {
|
|
12832
12904
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12833
|
-
return new
|
|
12905
|
+
return new chunkLUWSY2QO_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12834
12906
|
} catch (e) {
|
|
12835
12907
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12836
12908
|
return baseline;
|
|
@@ -12849,10 +12921,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12849
12921
|
if (vtxo.isUnrolled) {
|
|
12850
12922
|
return !!f.withUnrolled;
|
|
12851
12923
|
}
|
|
12852
|
-
if (
|
|
12924
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) {
|
|
12853
12925
|
return false;
|
|
12854
12926
|
}
|
|
12855
|
-
if (!f.withRecoverable &&
|
|
12927
|
+
if (!f.withRecoverable && chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12856
12928
|
return false;
|
|
12857
12929
|
}
|
|
12858
12930
|
return true;
|
|
@@ -13192,7 +13264,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13192
13264
|
*/
|
|
13193
13265
|
static async setupWalletConfig(config, pubKey) {
|
|
13194
13266
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
13195
|
-
const arkProvider = config.arkProvider || new
|
|
13267
|
+
const arkProvider = config.arkProvider || new chunkCJN4CUEU_cjs.RestArkProvider(arkadeServerUrl);
|
|
13196
13268
|
let indexerProvider = config.indexerProvider;
|
|
13197
13269
|
if (!indexerProvider) {
|
|
13198
13270
|
let indexerUrl = config.indexerUrl;
|
|
@@ -13209,7 +13281,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13209
13281
|
indexerUrl = arkadeServerUrl;
|
|
13210
13282
|
}
|
|
13211
13283
|
}
|
|
13212
|
-
indexerProvider = new
|
|
13284
|
+
indexerProvider = new chunkH62OOAS4_cjs.RestIndexerProvider(indexerUrl);
|
|
13213
13285
|
}
|
|
13214
13286
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
13215
13287
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -13218,7 +13290,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13218
13290
|
source: serverInfoSource,
|
|
13219
13291
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
13220
13292
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
13221
|
-
const network =
|
|
13293
|
+
const network = chunkCJN4CUEU_cjs.getNetwork(info.network);
|
|
13222
13294
|
if ("descriptor" in config.identity) {
|
|
13223
13295
|
const descriptor = config.identity.descriptor;
|
|
13224
13296
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -13258,18 +13330,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13258
13330
|
value: info.boardingExitDelay,
|
|
13259
13331
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
13260
13332
|
};
|
|
13261
|
-
const serverPubKey =
|
|
13262
|
-
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) =>
|
|
13333
|
+
const serverPubKey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
13334
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
|
|
13263
13335
|
const offchainOptions = {
|
|
13264
13336
|
pubKey,
|
|
13265
13337
|
serverPubKey,
|
|
13266
13338
|
csvTimelock: exitTimelock
|
|
13267
13339
|
};
|
|
13268
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
13269
|
-
const boardingTapscript =
|
|
13340
|
+
const offchainTapscript = !delegatePubKey ? new chunkLUWSY2QO_cjs.DefaultVtxo.Script(offchainOptions) : new chunkLUWSY2QO_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
13341
|
+
const boardingTapscript = chunkLUWSY2QO_cjs.BoardingContractHandler.createScript({
|
|
13270
13342
|
pubKey: base.hex.encode(pubKey),
|
|
13271
13343
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13272
|
-
csvTimelock:
|
|
13344
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingTimelock).toString()
|
|
13273
13345
|
});
|
|
13274
13346
|
return {
|
|
13275
13347
|
arkProvider,
|
|
@@ -13417,7 +13489,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13417
13489
|
}
|
|
13418
13490
|
/** @inheritdoc */
|
|
13419
13491
|
async getSpendableVtxos(filter) {
|
|
13420
|
-
const snapshot = await this.contractSnapshot(
|
|
13492
|
+
const snapshot = await this.contractSnapshot(filter, {
|
|
13493
|
+
unspentOnly: !filter?.withUnrolled
|
|
13494
|
+
});
|
|
13421
13495
|
const vtxos = filterSnapshotVtxos(snapshot, filter, this._pendingSpendOutpoints);
|
|
13422
13496
|
const { gated, pendingRecovery } = this.spendabilityView(snapshot);
|
|
13423
13497
|
const selectable = vtxos.filter(
|
|
@@ -13435,7 +13509,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13435
13509
|
if (!filter?.withUnrolled) {
|
|
13436
13510
|
logExcludedVtxos(
|
|
13437
13511
|
"getSpendableVtxos",
|
|
13438
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
13512
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)),
|
|
13439
13513
|
[() => UNROLLED_REASON]
|
|
13440
13514
|
);
|
|
13441
13515
|
}
|
|
@@ -13509,9 +13583,25 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13509
13583
|
* otherwise the gate and the pending-recovery set answer about two different
|
|
13510
13584
|
* points in time, and each read costs another sync.
|
|
13511
13585
|
*/
|
|
13512
|
-
async contractSnapshot() {
|
|
13586
|
+
async contractSnapshot(filter, options) {
|
|
13513
13587
|
const contractManager = await this.getContractManager();
|
|
13514
|
-
|
|
13588
|
+
const scope = filter?.watchedOnly ? { watch: ["watched", "awaiting-funds"] } : void 0;
|
|
13589
|
+
let query = scope;
|
|
13590
|
+
if (filter?.genericallySpendableOnly) {
|
|
13591
|
+
const scripts = (await contractManager.getContracts(scope)).filter(isContractGenericallySpendable).map((contract) => contract.script);
|
|
13592
|
+
if (scripts.length === 0) {
|
|
13593
|
+
if (filter.requireSynced) {
|
|
13594
|
+
throw new Error("No generically spendable contracts to sync");
|
|
13595
|
+
}
|
|
13596
|
+
return [];
|
|
13597
|
+
}
|
|
13598
|
+
query = { ...scope, script: scripts };
|
|
13599
|
+
}
|
|
13600
|
+
return contractManager.getContractsWithVtxos(query, void 0, {
|
|
13601
|
+
maxSyncAgeMs: filter?.maxSyncAgeMs,
|
|
13602
|
+
unspentOnly: options?.unspentOnly,
|
|
13603
|
+
requireSynced: filter?.requireSynced
|
|
13604
|
+
});
|
|
13515
13605
|
}
|
|
13516
13606
|
/**
|
|
13517
13607
|
* The two exclusion sets the gate is made of, derived from one snapshot so
|
|
@@ -13580,7 +13670,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13580
13670
|
this.getBoardingTxs()
|
|
13581
13671
|
]);
|
|
13582
13672
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
13583
|
-
const resolveTxCreatedAt = (txids) =>
|
|
13673
|
+
const resolveTxCreatedAt = (txids) => chunkCJN4CUEU_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13584
13674
|
return buildTransactionHistory(
|
|
13585
13675
|
allVtxos,
|
|
13586
13676
|
boardingTxs,
|
|
@@ -13675,7 +13765,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13675
13765
|
},
|
|
13676
13766
|
isUnrolled: true,
|
|
13677
13767
|
...boardingFacts,
|
|
13678
|
-
virtualStatus:
|
|
13768
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(boardingFacts),
|
|
13679
13769
|
spentBy: "",
|
|
13680
13770
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
13681
13771
|
script: scriptHex
|
|
@@ -13731,9 +13821,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13731
13821
|
async getBoardingTapscripts(allowedSigners) {
|
|
13732
13822
|
const byScript = /* @__PURE__ */ new Map();
|
|
13733
13823
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
13734
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13824
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13735
13825
|
add(
|
|
13736
|
-
new
|
|
13826
|
+
new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
13737
13827
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
13738
13828
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
13739
13829
|
csvTimelock: boardingCsv
|
|
@@ -13748,7 +13838,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13748
13838
|
for (const c of boardingContracts) {
|
|
13749
13839
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
13750
13840
|
try {
|
|
13751
|
-
add(
|
|
13841
|
+
add(chunkLUWSY2QO_cjs.BoardingContractHandler.createScript(c.params));
|
|
13752
13842
|
} catch (e) {
|
|
13753
13843
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
13754
13844
|
}
|
|
@@ -13785,7 +13875,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13785
13875
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13786
13876
|
// not the wallet's current boarding timelock, which a signer
|
|
13787
13877
|
// rotation may have changed.
|
|
13788
|
-
csvTimelock:
|
|
13878
|
+
csvTimelock: chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13789
13879
|
coins: utxos
|
|
13790
13880
|
};
|
|
13791
13881
|
})
|
|
@@ -13922,7 +14012,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13922
14012
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13923
14013
|
async fetchPendingTxs() {
|
|
13924
14014
|
const scripts = await this.getWalletScripts();
|
|
13925
|
-
const vtxos = await
|
|
14015
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13926
14016
|
return vtxos.filter(
|
|
13927
14017
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13928
14018
|
).map((_) => _.arkTxId);
|
|
@@ -13953,7 +14043,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13953
14043
|
});
|
|
13954
14044
|
for (const contract of contracts) {
|
|
13955
14045
|
if (map.has(contract.script)) continue;
|
|
13956
|
-
const handler =
|
|
14046
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
13957
14047
|
if (handler) {
|
|
13958
14048
|
const script = handler.createScript(contract.params);
|
|
13959
14049
|
map.set(contract.script, script);
|
|
@@ -14065,7 +14155,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14065
14155
|
}
|
|
14066
14156
|
});
|
|
14067
14157
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
14068
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14158
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14069
14159
|
const baselineSigners = [
|
|
14070
14160
|
this.offchainTapscript.options.serverPubKey,
|
|
14071
14161
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -14073,8 +14163,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14073
14163
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
14074
14164
|
for (const serverPubKey of baselineSigners) {
|
|
14075
14165
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
14076
|
-
const csvTimelockStr =
|
|
14077
|
-
const defaultScript = new
|
|
14166
|
+
const csvTimelockStr = chunkCJN4CUEU_cjs.timelockToSequence(csvTimelock).toString();
|
|
14167
|
+
const defaultScript = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14078
14168
|
pubKey: baselinePubkey,
|
|
14079
14169
|
serverPubKey,
|
|
14080
14170
|
csvTimelock
|
|
@@ -14095,7 +14185,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14095
14185
|
});
|
|
14096
14186
|
}
|
|
14097
14187
|
if (delegatePubKey) {
|
|
14098
|
-
const delegateScript = new
|
|
14188
|
+
const delegateScript = new chunkLUWSY2QO_cjs.DelegateVtxo.Script({
|
|
14099
14189
|
pubKey: baselinePubkey,
|
|
14100
14190
|
serverPubKey,
|
|
14101
14191
|
delegatePubKey,
|
|
@@ -14119,9 +14209,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14119
14209
|
}
|
|
14120
14210
|
}
|
|
14121
14211
|
}
|
|
14122
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
14212
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14123
14213
|
for (const serverPubKey of baselineSigners) {
|
|
14124
|
-
const baselineBoarding = new
|
|
14214
|
+
const baselineBoarding = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14125
14215
|
pubKey: baselinePubkey,
|
|
14126
14216
|
serverPubKey,
|
|
14127
14217
|
csvTimelock: boardingCsvTimelock
|
|
@@ -14134,7 +14224,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14134
14224
|
params: {
|
|
14135
14225
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14136
14226
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
14137
|
-
csvTimelock:
|
|
14227
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14138
14228
|
},
|
|
14139
14229
|
script: boardingScriptHex,
|
|
14140
14230
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -14334,7 +14424,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14334
14424
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
14335
14425
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
14336
14426
|
csvTimelocks: this.walletContractTimelocks,
|
|
14337
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
14427
|
+
delegatePubKey: this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
14338
14428
|
};
|
|
14339
14429
|
}
|
|
14340
14430
|
_signerRouter;
|
|
@@ -14579,7 +14669,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14579
14669
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14580
14670
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14581
14671
|
if (typeof persisted === "string") return persisted;
|
|
14582
|
-
return
|
|
14672
|
+
return chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14583
14673
|
}
|
|
14584
14674
|
/**
|
|
14585
14675
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -14595,7 +14685,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14595
14685
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14596
14686
|
if (type === "boarding") {
|
|
14597
14687
|
const built2 = this.buildBoardingContract(
|
|
14598
|
-
|
|
14688
|
+
chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14599
14689
|
descriptor,
|
|
14600
14690
|
tagSource
|
|
14601
14691
|
);
|
|
@@ -14640,11 +14730,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14640
14730
|
* {@link buildReceiveContract}.
|
|
14641
14731
|
*/
|
|
14642
14732
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14643
|
-
const tapscript = new
|
|
14733
|
+
const tapscript = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14644
14734
|
...this._boardingTapscript.options,
|
|
14645
14735
|
pubKey
|
|
14646
14736
|
});
|
|
14647
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
14737
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14648
14738
|
return {
|
|
14649
14739
|
tapscript,
|
|
14650
14740
|
params: {
|
|
@@ -14652,13 +14742,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14652
14742
|
params: {
|
|
14653
14743
|
pubKey: base.hex.encode(pubKey),
|
|
14654
14744
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14655
|
-
csvTimelock:
|
|
14745
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(csvTimelock).toString()
|
|
14656
14746
|
},
|
|
14657
14747
|
script: base.hex.encode(tapscript.pkScript),
|
|
14658
14748
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14659
14749
|
state: "active",
|
|
14660
14750
|
metadata: {
|
|
14661
|
-
...tagSource && { source:
|
|
14751
|
+
...tagSource && { source: chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE },
|
|
14662
14752
|
signingDescriptor: descriptor
|
|
14663
14753
|
}
|
|
14664
14754
|
}
|
|
@@ -14687,7 +14777,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14687
14777
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
14688
14778
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14689
14779
|
}
|
|
14690
|
-
return
|
|
14780
|
+
return chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14691
14781
|
}
|
|
14692
14782
|
/**
|
|
14693
14783
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14783,7 +14873,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14783
14873
|
* the stable public API.
|
|
14784
14874
|
*/
|
|
14785
14875
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14786
|
-
const xonly =
|
|
14876
|
+
const xonly = chunkLUWSY2QO_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14787
14877
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14788
14878
|
checkpointTapscript,
|
|
14789
14879
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14812,21 +14902,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14812
14902
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14813
14903
|
script: currentBoardingScript
|
|
14814
14904
|
});
|
|
14815
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14905
|
+
const newOffchain = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? new chunkLUWSY2QO_cjs.DelegateVtxo.Script({
|
|
14816
14906
|
...this.offchainTapscript.options,
|
|
14817
14907
|
serverPubKey: xonly
|
|
14818
|
-
}) : new
|
|
14908
|
+
}) : new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14819
14909
|
...this.offchainTapscript.options,
|
|
14820
14910
|
serverPubKey: xonly
|
|
14821
14911
|
});
|
|
14822
|
-
const newBoarding = new
|
|
14912
|
+
const newBoarding = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14823
14913
|
...this._boardingTapscript.options,
|
|
14824
14914
|
serverPubKey: xonly
|
|
14825
14915
|
});
|
|
14826
|
-
const offchainCsv =
|
|
14916
|
+
const offchainCsv = chunkCJN4CUEU_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14827
14917
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14828
14918
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14829
|
-
if (newOffchain instanceof
|
|
14919
|
+
if (newOffchain instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script) {
|
|
14830
14920
|
await manager.createContract({
|
|
14831
14921
|
type: "delegate",
|
|
14832
14922
|
params: {
|
|
@@ -14854,13 +14944,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14854
14944
|
metadata: currentOffchainRow?.metadata
|
|
14855
14945
|
});
|
|
14856
14946
|
}
|
|
14857
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14947
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14858
14948
|
await manager.createContract({
|
|
14859
14949
|
type: "boarding",
|
|
14860
14950
|
params: {
|
|
14861
14951
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14862
14952
|
serverPubKey: base.hex.encode(xonly),
|
|
14863
|
-
csvTimelock:
|
|
14953
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingCsv).toString()
|
|
14864
14954
|
},
|
|
14865
14955
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14866
14956
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14893,14 +14983,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14893
14983
|
_restoreInFlight;
|
|
14894
14984
|
_addPendingSpends(inputs) {
|
|
14895
14985
|
for (const input of inputs) {
|
|
14896
|
-
if (
|
|
14986
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
14897
14987
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14898
14988
|
}
|
|
14899
14989
|
}
|
|
14900
14990
|
}
|
|
14901
14991
|
_removePendingSpends(inputs) {
|
|
14902
14992
|
for (const input of inputs) {
|
|
14903
|
-
if (
|
|
14993
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
14904
14994
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14905
14995
|
}
|
|
14906
14996
|
}
|
|
@@ -14961,13 +15051,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14961
15051
|
const manager = await this.getContractManager();
|
|
14962
15052
|
const provider = this._descriptorProvider;
|
|
14963
15053
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14964
|
-
const staticDescriptor = hd ? void 0 : await
|
|
15054
|
+
const staticDescriptor = hd ? void 0 : await chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14965
15055
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14966
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
15056
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14967
15057
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14968
|
-
const currentSignerPubKey =
|
|
15058
|
+
const currentSignerPubKey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14969
15059
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14970
|
-
(s) =>
|
|
15060
|
+
(s) => chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14971
15061
|
);
|
|
14972
15062
|
const deps = {
|
|
14973
15063
|
indexerProvider: this.indexerProvider,
|
|
@@ -14982,7 +15072,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14982
15072
|
csvTimelocks: this.walletContractTimelocks,
|
|
14983
15073
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14984
15074
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14985
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
15075
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14986
15076
|
delegatePubKey
|
|
14987
15077
|
};
|
|
14988
15078
|
const result = await manager.scanContracts({
|
|
@@ -15096,7 +15186,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15096
15186
|
throw new Error("Invalid configured public key");
|
|
15097
15187
|
}
|
|
15098
15188
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
15099
|
-
const forfeitPubkey =
|
|
15189
|
+
const forfeitPubkey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
15100
15190
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
15101
15191
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
15102
15192
|
const checkpointExitDelayOverrides = {
|
|
@@ -15245,7 +15335,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15245
15335
|
inputs: params.selectedVtxos,
|
|
15246
15336
|
changeAmount: BigInt(changeAmount)
|
|
15247
15337
|
};
|
|
15248
|
-
const outputAddress =
|
|
15338
|
+
const outputAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(params.address);
|
|
15249
15339
|
assertRecipientArkAddress(
|
|
15250
15340
|
params.address,
|
|
15251
15341
|
outputAddress,
|
|
@@ -15311,13 +15401,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15311
15401
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
15312
15402
|
}
|
|
15313
15403
|
const offchainAddress = await this.getAddress();
|
|
15314
|
-
const offchainPkScript =
|
|
15404
|
+
const offchainPkScript = chunkCJN4CUEU_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
15315
15405
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
15316
15406
|
if (!params) {
|
|
15317
15407
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
15318
15408
|
const estimator = new Estimator(fees.intentFee);
|
|
15319
15409
|
let amount = 0;
|
|
15320
|
-
const exitScript =
|
|
15410
|
+
const exitScript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(
|
|
15321
15411
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
15322
15412
|
);
|
|
15323
15413
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -15340,13 +15430,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15340
15430
|
filteredBoardingUtxos.push(utxo);
|
|
15341
15431
|
amount += utxo.value - inputFee.satoshis;
|
|
15342
15432
|
}
|
|
15343
|
-
const vtxos = await this.getSpendableVtxos({
|
|
15433
|
+
const vtxos = await this.getSpendableVtxos({
|
|
15434
|
+
withRecoverable: true,
|
|
15435
|
+
genericallySpendableOnly: true
|
|
15436
|
+
});
|
|
15344
15437
|
const filteredVtxos = [];
|
|
15345
15438
|
for (const vtxo of byValueDescending(vtxos)) {
|
|
15346
15439
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
15347
15440
|
break;
|
|
15348
15441
|
}
|
|
15349
|
-
const inputFee = estimator.evalOffchainInput(
|
|
15442
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo));
|
|
15350
15443
|
if (inputFee.satoshis >= vtxo.value) {
|
|
15351
15444
|
continue;
|
|
15352
15445
|
}
|
|
@@ -15393,7 +15486,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15393
15486
|
let script;
|
|
15394
15487
|
let arkAddress;
|
|
15395
15488
|
try {
|
|
15396
|
-
arkAddress =
|
|
15489
|
+
arkAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(output.address);
|
|
15397
15490
|
} catch {
|
|
15398
15491
|
arkAddress = void 0;
|
|
15399
15492
|
}
|
|
@@ -15483,7 +15576,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15483
15576
|
const abortController = new AbortController();
|
|
15484
15577
|
let stream;
|
|
15485
15578
|
let committedTxid;
|
|
15486
|
-
const settleInputVtxos = params.inputs.filter(
|
|
15579
|
+
const settleInputVtxos = params.inputs.filter(chunkCJN4CUEU_cjs.isVirtualCoin);
|
|
15487
15580
|
const contractManager = await this.getContractManager();
|
|
15488
15581
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15489
15582
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15595,7 +15688,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15595
15688
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15596
15689
|
if (!this._descriptorProvider) return;
|
|
15597
15690
|
const consumedBoarding = inputs.some(
|
|
15598
|
-
(input) => typeof input !== "string" && !
|
|
15691
|
+
(input) => typeof input !== "string" && !chunkCJN4CUEU_cjs.isVirtualCoin(input)
|
|
15599
15692
|
);
|
|
15600
15693
|
if (!consumedBoarding) return;
|
|
15601
15694
|
try {
|
|
@@ -15619,7 +15712,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15619
15712
|
let connectorIndex = 0;
|
|
15620
15713
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15621
15714
|
for (const input of inputs) {
|
|
15622
|
-
if (!
|
|
15715
|
+
if (!chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
15623
15716
|
let matched = false;
|
|
15624
15717
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15625
15718
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -15657,7 +15750,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15657
15750
|
}
|
|
15658
15751
|
continue;
|
|
15659
15752
|
}
|
|
15660
|
-
if (
|
|
15753
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15661
15754
|
continue;
|
|
15662
15755
|
}
|
|
15663
15756
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15685,7 +15778,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15685
15778
|
index: input.vout,
|
|
15686
15779
|
witnessUtxo: {
|
|
15687
15780
|
amount: BigInt(input.value),
|
|
15688
|
-
script:
|
|
15781
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15689
15782
|
},
|
|
15690
15783
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15691
15784
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15704,7 +15797,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15704
15797
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15705
15798
|
{
|
|
15706
15799
|
index: 0,
|
|
15707
|
-
lookupScript:
|
|
15800
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15708
15801
|
}
|
|
15709
15802
|
]);
|
|
15710
15803
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15762,7 +15855,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15762
15855
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15763
15856
|
);
|
|
15764
15857
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15765
|
-
const sweepTapscript =
|
|
15858
|
+
const sweepTapscript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
15766
15859
|
timelock,
|
|
15767
15860
|
pubkeys: [this.forfeitPubkey]
|
|
15768
15861
|
}).script;
|
|
@@ -15777,10 +15870,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15777
15870
|
throw new Error("Sweep tap tree root not set");
|
|
15778
15871
|
}
|
|
15779
15872
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15780
|
-
(k) => base.hex.encode(
|
|
15873
|
+
(k) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15781
15874
|
);
|
|
15782
15875
|
const signerPublicKey = await session.getPublicKey();
|
|
15783
|
-
const xonlySignerPublicKey =
|
|
15876
|
+
const xonlySignerPublicKey = chunkLUWSY2QO_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15784
15877
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15785
15878
|
return { skip: true };
|
|
15786
15879
|
}
|
|
@@ -15870,9 +15963,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15870
15963
|
...existing ?? {},
|
|
15871
15964
|
intentTxId,
|
|
15872
15965
|
registerProof: intent.proof,
|
|
15873
|
-
registerProofMessage:
|
|
15966
|
+
registerProofMessage: chunkCJN4CUEU_cjs.Intent.encodeMessage(intent.message),
|
|
15874
15967
|
deleteProof: deleteIntent.proof,
|
|
15875
|
-
deleteProofMessage:
|
|
15968
|
+
deleteProofMessage: chunkCJN4CUEU_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15876
15969
|
intentVtxos: inputs.map((i) => ({
|
|
15877
15970
|
txid: i.txid,
|
|
15878
15971
|
vout: i.vout
|
|
@@ -15905,7 +15998,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15905
15998
|
try {
|
|
15906
15999
|
return await this.arkProvider.registerIntent(intent);
|
|
15907
16000
|
} catch (error) {
|
|
15908
|
-
if (error instanceof
|
|
16001
|
+
if (error instanceof chunkCJN4CUEU_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15909
16002
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15910
16003
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15911
16004
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15921,7 +16014,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15921
16014
|
expire_at: 0,
|
|
15922
16015
|
cosigners_public_keys: cosignerPubKeys
|
|
15923
16016
|
};
|
|
15924
|
-
const proof =
|
|
16017
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, outputs);
|
|
15925
16018
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15926
16019
|
return {
|
|
15927
16020
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15933,7 +16026,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15933
16026
|
type: "delete",
|
|
15934
16027
|
expire_at: 0
|
|
15935
16028
|
};
|
|
15936
|
-
const proof =
|
|
16029
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, []);
|
|
15937
16030
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15938
16031
|
return {
|
|
15939
16032
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15945,7 +16038,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15945
16038
|
type: "get-pending-tx",
|
|
15946
16039
|
expire_at: 0
|
|
15947
16040
|
};
|
|
15948
|
-
const proof =
|
|
16041
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, []);
|
|
15949
16042
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15950
16043
|
return {
|
|
15951
16044
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15966,7 +16059,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15966
16059
|
if (!vtxos || vtxos.length === 0) {
|
|
15967
16060
|
const scriptMap = await this.getScriptMap();
|
|
15968
16061
|
const allExtended = [];
|
|
15969
|
-
const fetchedVtxos = await
|
|
16062
|
+
const fetchedVtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15970
16063
|
...scriptMap.keys()
|
|
15971
16064
|
]);
|
|
15972
16065
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -16010,7 +16103,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16010
16103
|
try {
|
|
16011
16104
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
16012
16105
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
16013
|
-
|
|
16106
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(tx);
|
|
16014
16107
|
return tx;
|
|
16015
16108
|
});
|
|
16016
16109
|
assertCheckpointsMatchInputs(
|
|
@@ -16082,11 +16175,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16082
16175
|
* against the current key alone would leave it pending forever.
|
|
16083
16176
|
*/
|
|
16084
16177
|
checkpointUnrollCandidates(info) {
|
|
16085
|
-
const current =
|
|
16178
|
+
const current = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
16086
16179
|
const candidates = [this._serverUnrollScript, current];
|
|
16087
16180
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
16088
16181
|
candidates.push(
|
|
16089
|
-
|
|
16182
|
+
chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
16090
16183
|
...current.params,
|
|
16091
16184
|
pubkeys: [base.hex.decode(deprecated)]
|
|
16092
16185
|
})
|
|
@@ -16177,7 +16270,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16177
16270
|
if (vtxos.length === 0) {
|
|
16178
16271
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
16179
16272
|
}
|
|
16180
|
-
const myPkScript =
|
|
16273
|
+
const myPkScript = chunkCJN4CUEU_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
16181
16274
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
16182
16275
|
let swept = 0;
|
|
16183
16276
|
const drainable = vtxos.filter(
|
|
@@ -16253,7 +16346,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16253
16346
|
const spendable = [];
|
|
16254
16347
|
const unclaimed = [];
|
|
16255
16348
|
for (const vtxo of vtxos) {
|
|
16256
|
-
if (
|
|
16349
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) {
|
|
16257
16350
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
16258
16351
|
} else if (vtxo.isUnrolled) {
|
|
16259
16352
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -16275,7 +16368,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16275
16368
|
const all = [];
|
|
16276
16369
|
const seen = /* @__PURE__ */ new Set();
|
|
16277
16370
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
16278
|
-
const { vtxos, page } = await
|
|
16371
|
+
const { vtxos, page } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
16279
16372
|
scripts,
|
|
16280
16373
|
pageIndex,
|
|
16281
16374
|
pageSize
|
|
@@ -16322,7 +16415,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16322
16415
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
16323
16416
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
16324
16417
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
16325
|
-
const proof =
|
|
16418
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, batch, []);
|
|
16326
16419
|
const signedProof = await identity.sign(
|
|
16327
16420
|
proof,
|
|
16328
16421
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -16344,7 +16437,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16344
16437
|
try {
|
|
16345
16438
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
16346
16439
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
16347
|
-
|
|
16440
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(tx);
|
|
16348
16441
|
return tx;
|
|
16349
16442
|
});
|
|
16350
16443
|
assertCheckpointsMatchInputs(
|
|
@@ -16444,7 +16537,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16444
16537
|
let virtualCoins = [];
|
|
16445
16538
|
if (!selectedVtxos) {
|
|
16446
16539
|
virtualCoins = await this.getSpendableVtxos({
|
|
16447
|
-
withRecoverable: false
|
|
16540
|
+
withRecoverable: false,
|
|
16541
|
+
genericallySpendableOnly: true
|
|
16448
16542
|
});
|
|
16449
16543
|
}
|
|
16450
16544
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -16476,6 +16570,15 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16476
16570
|
}
|
|
16477
16571
|
}
|
|
16478
16572
|
} else {
|
|
16573
|
+
const coinsByAsset = /* @__PURE__ */ new Map();
|
|
16574
|
+
for (const coin of virtualCoins) {
|
|
16575
|
+
for (const assetId of new Set(coin.assets?.map((asset) => asset.assetId))) {
|
|
16576
|
+
const coins = coinsByAsset.get(assetId) ?? [];
|
|
16577
|
+
coins.push(coin);
|
|
16578
|
+
coinsByAsset.set(assetId, coins);
|
|
16579
|
+
}
|
|
16580
|
+
}
|
|
16581
|
+
const selectedOutpoints2 = /* @__PURE__ */ new Set();
|
|
16479
16582
|
for (const recipient of recipients) {
|
|
16480
16583
|
if (!recipient.assets) {
|
|
16481
16584
|
continue;
|
|
@@ -16494,8 +16597,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16494
16597
|
amountToSelect -= existingChange;
|
|
16495
16598
|
assetChanges.delete(receiverAsset.assetId);
|
|
16496
16599
|
}
|
|
16497
|
-
const availableCoins =
|
|
16498
|
-
(
|
|
16600
|
+
const availableCoins = (coinsByAsset.get(receiverAsset.assetId) ?? []).filter(
|
|
16601
|
+
(coin) => !selectedOutpoints2.has(vtxoOutpoint(coin))
|
|
16499
16602
|
);
|
|
16500
16603
|
const { selected, totalAssetAmount } = selectCoinsWithAsset(
|
|
16501
16604
|
availableCoins,
|
|
@@ -16504,6 +16607,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16504
16607
|
);
|
|
16505
16608
|
for (const coin of selected) {
|
|
16506
16609
|
selectedCoins.push(coin);
|
|
16610
|
+
selectedOutpoints2.add(vtxoOutpoint(coin));
|
|
16507
16611
|
btcAmountToSelect -= coin.value;
|
|
16508
16612
|
if (coin.assets) {
|
|
16509
16613
|
for (const a of coin.assets) {
|
|
@@ -16524,7 +16628,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16524
16628
|
}
|
|
16525
16629
|
if (btcAmountToSelect > 0) {
|
|
16526
16630
|
const availableCoins = virtualCoins.filter(
|
|
16527
|
-
(
|
|
16631
|
+
(coin) => !selectedOutpoints2.has(vtxoOutpoint(coin))
|
|
16528
16632
|
);
|
|
16529
16633
|
const { inputs: btcCoins } = selectVirtualCoins(availableCoins, btcAmountToSelect);
|
|
16530
16634
|
for (const coin of btcCoins) {
|
|
@@ -16536,6 +16640,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16536
16640
|
}
|
|
16537
16641
|
}
|
|
16538
16642
|
selectedCoins = [...selectedCoins, ...btcCoins];
|
|
16643
|
+
for (const coin of btcCoins) selectedOutpoints2.add(vtxoOutpoint(coin));
|
|
16539
16644
|
}
|
|
16540
16645
|
}
|
|
16541
16646
|
let totalBtcSelected = selectedCoins.reduce((sum, c) => sum + c.value, 0);
|
|
@@ -16543,7 +16648,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16543
16648
|
script: recipient.script,
|
|
16544
16649
|
amount: BigInt(recipient.amount),
|
|
16545
16650
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16546
|
-
...recipient.tapTree ? { tapTree:
|
|
16651
|
+
...recipient.tapTree ? { tapTree: chunkCJN4CUEU_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
16547
16652
|
}));
|
|
16548
16653
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16549
16654
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -16552,19 +16657,58 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16552
16657
|
`send({ selectedVtxos }): inputs total ${totalBtcSelected} sats, outputs need ${totalBtcOutput}`
|
|
16553
16658
|
);
|
|
16554
16659
|
}
|
|
16555
|
-
if (assetChanges.size > 0 && changeAmount < Number(this.dustAmount)) {
|
|
16556
|
-
|
|
16557
|
-
|
|
16558
|
-
|
|
16559
|
-
|
|
16560
|
-
|
|
16561
|
-
|
|
16562
|
-
|
|
16660
|
+
if (selectedVtxos && assetChanges.size > 0 && changeAmount < Number(this.dustAmount)) {
|
|
16661
|
+
throw new Error(
|
|
16662
|
+
`send({ selectedVtxos }): ${changeAmount} sats of change cannot carry ${assetChanges.size} asset change(s), needs ${this.dustAmount}`
|
|
16663
|
+
);
|
|
16664
|
+
}
|
|
16665
|
+
const vtxoMinAmount = changeAmount > 0 || assetChanges.size > 0 ? (await this.arkProvider.getInfo()).vtxoMinAmount ?? 0n : 0n;
|
|
16666
|
+
if (selectedVtxos && changeAmount > 0 && BigInt(changeAmount) < vtxoMinAmount) {
|
|
16667
|
+
throw new Error(
|
|
16668
|
+
`send({ selectedVtxos }): ${changeAmount} sats of change is below the operator minimum of ${vtxoMinAmount} sats`
|
|
16563
16669
|
);
|
|
16564
|
-
|
|
16565
|
-
|
|
16566
|
-
|
|
16670
|
+
}
|
|
16671
|
+
const selectedOutpoints = new Set(selectedCoins.map(vtxoOutpoint));
|
|
16672
|
+
while (!selectedVtxos && (changeAmount > 0 && BigInt(changeAmount) < vtxoMinAmount || assetChanges.size > 0 && BigInt(changeAmount) < this.dustAmount)) {
|
|
16673
|
+
const minimumChange = assetChanges.size > 0 && this.dustAmount > vtxoMinAmount ? this.dustAmount : vtxoMinAmount;
|
|
16674
|
+
const availableCoins = virtualCoins.filter(
|
|
16675
|
+
(coin) => !selectedOutpoints.has(vtxoOutpoint(coin))
|
|
16567
16676
|
);
|
|
16677
|
+
let extraCoins;
|
|
16678
|
+
try {
|
|
16679
|
+
({ inputs: extraCoins } = selectVirtualCoins(
|
|
16680
|
+
availableCoins,
|
|
16681
|
+
Number(minimumChange) - changeAmount
|
|
16682
|
+
));
|
|
16683
|
+
} catch (error) {
|
|
16684
|
+
if (!(error instanceof Error) || error.message !== "Insufficient funds") {
|
|
16685
|
+
throw error;
|
|
16686
|
+
}
|
|
16687
|
+
if (recipients.every((r) => r.assets.length === 0)) {
|
|
16688
|
+
const plainCoins = virtualCoins.filter((coin) => !coin.assets?.length);
|
|
16689
|
+
const exact = plainCoins.find((coin) => coin.value === totalBtcOutput);
|
|
16690
|
+
let exactCoins = exact ? [exact] : void 0;
|
|
16691
|
+
if (!exactCoins) {
|
|
16692
|
+
const byAmount = /* @__PURE__ */ new Map();
|
|
16693
|
+
for (const coin of plainCoins) {
|
|
16694
|
+
const partner = byAmount.get(totalBtcOutput - coin.value);
|
|
16695
|
+
if (partner) {
|
|
16696
|
+
exactCoins = [partner, coin];
|
|
16697
|
+
break;
|
|
16698
|
+
}
|
|
16699
|
+
byAmount.set(coin.value, coin);
|
|
16700
|
+
}
|
|
16701
|
+
}
|
|
16702
|
+
if (exactCoins) {
|
|
16703
|
+
selectedCoins = exactCoins;
|
|
16704
|
+
assetChanges.clear();
|
|
16705
|
+
totalBtcSelected = totalBtcOutput;
|
|
16706
|
+
changeAmount = 0;
|
|
16707
|
+
break;
|
|
16708
|
+
}
|
|
16709
|
+
}
|
|
16710
|
+
throw new Error(`Cannot form minimum change amount of ${minimumChange} sats`);
|
|
16711
|
+
}
|
|
16568
16712
|
for (const coin of extraCoins) {
|
|
16569
16713
|
if (coin.assets) {
|
|
16570
16714
|
for (const asset of coin.assets) {
|
|
@@ -16574,6 +16718,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16574
16718
|
}
|
|
16575
16719
|
}
|
|
16576
16720
|
selectedCoins = [...selectedCoins, ...extraCoins];
|
|
16721
|
+
for (const coin of extraCoins) selectedOutpoints.add(vtxoOutpoint(coin));
|
|
16577
16722
|
totalBtcSelected += extraCoins.reduce((sum, c) => sum + c.value, 0);
|
|
16578
16723
|
changeAmount = totalBtcSelected - totalBtcOutput;
|
|
16579
16724
|
}
|
|
@@ -16687,10 +16832,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16687
16832
|
const serverPubKey = this.arkServerPublicKey;
|
|
16688
16833
|
const serverUnrollScript = this.serverUnrollScript;
|
|
16689
16834
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
16690
|
-
const normalizedInputs = inputs.map(
|
|
16691
|
-
const at = now ?? await
|
|
16835
|
+
const normalizedInputs = inputs.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
16836
|
+
const at = now ?? await chunkCJN4CUEU_cjs.resolveTimeHeight(this.onchainProvider);
|
|
16692
16837
|
for (const input of normalizedInputs) {
|
|
16693
|
-
if (!
|
|
16838
|
+
if (!chunkCJN4CUEU_cjs.canSpendOffchain(input, at)) {
|
|
16694
16839
|
throw new Error(
|
|
16695
16840
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
16696
16841
|
);
|
|
@@ -16760,7 +16905,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16760
16905
|
);
|
|
16761
16906
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
16762
16907
|
index,
|
|
16763
|
-
lookupScript:
|
|
16908
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
16764
16909
|
}));
|
|
16765
16910
|
const identity = this.identity;
|
|
16766
16911
|
const signer = {
|
|
@@ -16861,14 +17006,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16861
17006
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16862
17007
|
spentVtxos.push({
|
|
16863
17008
|
...spentFacts,
|
|
16864
|
-
virtualStatus:
|
|
17009
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(spentFacts),
|
|
16865
17010
|
...spentBy ? { spentBy } : {},
|
|
16866
17011
|
arkTxId: arkTxid
|
|
16867
17012
|
});
|
|
16868
17013
|
for (const id of vtxo.commitmentTxIds) {
|
|
16869
17014
|
commitmentTxIds.add(id);
|
|
16870
17015
|
}
|
|
16871
|
-
const vtxoExpiry =
|
|
17016
|
+
const vtxoExpiry = chunkCJN4CUEU_cjs.toBatchExpiry(vtxo);
|
|
16872
17017
|
if (vtxoExpiry) {
|
|
16873
17018
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16874
17019
|
}
|
|
@@ -16881,7 +17026,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16881
17026
|
isSwept: false,
|
|
16882
17027
|
isPreconfirmed: true,
|
|
16883
17028
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16884
|
-
...
|
|
17029
|
+
...chunkCJN4CUEU_cjs.parseLegacyExpiry(batchExpiry)
|
|
16885
17030
|
};
|
|
16886
17031
|
changeVtxo = {
|
|
16887
17032
|
txid: arkTxid,
|
|
@@ -16893,7 +17038,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16893
17038
|
tapTree: offchainTapscript.encode(),
|
|
16894
17039
|
value: Number(changeAmount),
|
|
16895
17040
|
...changeFacts,
|
|
16896
|
-
virtualStatus:
|
|
17041
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(changeFacts),
|
|
16897
17042
|
spentBy: "",
|
|
16898
17043
|
status: {
|
|
16899
17044
|
confirmed: false
|
|
@@ -16962,12 +17107,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16962
17107
|
const spentVtxos = [];
|
|
16963
17108
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16964
17109
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16965
|
-
const vtxoInputs = inputs.filter(
|
|
17110
|
+
const vtxoInputs = inputs.filter(chunkCJN4CUEU_cjs.isVirtualCoin);
|
|
16966
17111
|
const cm = await this.getContractManager();
|
|
16967
17112
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16968
17113
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16969
17114
|
for (const input of inputs) {
|
|
16970
|
-
if (
|
|
17115
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
16971
17116
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16972
17117
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16973
17118
|
if (!vtxo) {
|
|
@@ -16979,13 +17124,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16979
17124
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16980
17125
|
spentVtxos.push({
|
|
16981
17126
|
...settledFacts,
|
|
16982
|
-
virtualStatus:
|
|
17127
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(settledFacts),
|
|
16983
17128
|
settledBy: commitmentTxid
|
|
16984
17129
|
});
|
|
16985
17130
|
} else {
|
|
16986
17131
|
let sourceAddress;
|
|
16987
17132
|
try {
|
|
16988
|
-
sourceAddress =
|
|
17133
|
+
sourceAddress = chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16989
17134
|
this.network
|
|
16990
17135
|
);
|
|
16991
17136
|
} catch {
|
|
@@ -17043,9 +17188,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
17043
17188
|
}
|
|
17044
17189
|
};
|
|
17045
17190
|
function selectVirtualCoins(coins, targetAmount) {
|
|
17046
|
-
const sortedCoins = coins.map(
|
|
17047
|
-
const expiryA =
|
|
17048
|
-
const expiryB =
|
|
17191
|
+
const sortedCoins = coins.map(chunkCJN4CUEU_cjs.normalizeVtxo).sort((a, b) => {
|
|
17192
|
+
const expiryA = chunkCJN4CUEU_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
17193
|
+
const expiryB = chunkCJN4CUEU_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
17049
17194
|
if (expiryA !== expiryB) {
|
|
17050
17195
|
return expiryA - expiryB;
|
|
17051
17196
|
}
|
|
@@ -17414,7 +17559,7 @@ var MessageBus = class {
|
|
|
17414
17559
|
this.initialized = true;
|
|
17415
17560
|
}
|
|
17416
17561
|
async buildServices(config) {
|
|
17417
|
-
const arkProvider = new
|
|
17562
|
+
const arkProvider = new chunkCJN4CUEU_cjs.RestArkProvider(config.arkServer.url);
|
|
17418
17563
|
const storage = {
|
|
17419
17564
|
walletRepository: this.walletRepository,
|
|
17420
17565
|
contractRepository: this.contractRepository,
|
|
@@ -17768,7 +17913,7 @@ var offboardNetworkNames = [
|
|
|
17768
17913
|
function offboardDestinationScript(destinationAddress) {
|
|
17769
17914
|
for (const networkName of offboardNetworkNames) {
|
|
17770
17915
|
try {
|
|
17771
|
-
const network =
|
|
17916
|
+
const network = chunkCJN4CUEU_cjs.networks[networkName];
|
|
17772
17917
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
17773
17918
|
return btcSigner.OutScript.encode(addr);
|
|
17774
17919
|
} catch {
|
|
@@ -17804,7 +17949,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
|
17804
17949
|
const inputs = [];
|
|
17805
17950
|
let subtotal = 0n;
|
|
17806
17951
|
for (const vtxo of vtxos) {
|
|
17807
|
-
const inputFee = estimator.evalOffchainInput(
|
|
17952
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo));
|
|
17808
17953
|
if (inputFee.satoshis >= vtxo.value) {
|
|
17809
17954
|
if (named) {
|
|
17810
17955
|
throw new Error(
|
|
@@ -17901,7 +18046,7 @@ var Ramps = class {
|
|
|
17901
18046
|
}
|
|
17902
18047
|
amount = amount ?? totalAmount;
|
|
17903
18048
|
const offchainAddress = await this.wallet.getAddress();
|
|
17904
|
-
const offchainAddr =
|
|
18049
|
+
const offchainAddr = chunkCJN4CUEU_cjs.ArkAddress.decode(offchainAddress);
|
|
17905
18050
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
17906
18051
|
const outputFee = estimator.evalOffchainOutput({
|
|
17907
18052
|
amount,
|
|
@@ -17960,7 +18105,8 @@ var Ramps = class {
|
|
|
17960
18105
|
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17961
18106
|
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17962
18107
|
withRecoverable: true,
|
|
17963
|
-
withUnrolled: false
|
|
18108
|
+
withUnrolled: false,
|
|
18109
|
+
genericallySpendableOnly: true
|
|
17964
18110
|
});
|
|
17965
18111
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17966
18112
|
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
@@ -18002,7 +18148,8 @@ var Ramps = class {
|
|
|
18002
18148
|
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
18003
18149
|
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
18004
18150
|
withRecoverable: true,
|
|
18005
|
-
withUnrolled: false
|
|
18151
|
+
withUnrolled: false,
|
|
18152
|
+
genericallySpendableOnly: true
|
|
18006
18153
|
});
|
|
18007
18154
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
18008
18155
|
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
@@ -18028,7 +18175,7 @@ var Ramps = class {
|
|
|
18028
18175
|
async fundChange(left, estimator) {
|
|
18029
18176
|
if (left <= 0n) return { change: 0n };
|
|
18030
18177
|
const changeAddress = await this.wallet.getAddress();
|
|
18031
|
-
const changeScript = base.hex.encode(
|
|
18178
|
+
const changeScript = base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
18032
18179
|
const { change } = changeAfterOutputFee(
|
|
18033
18180
|
left,
|
|
18034
18181
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script: changeScript }).satoshis)
|
|
@@ -18389,7 +18536,7 @@ var WalletMessageHandler = class {
|
|
|
18389
18536
|
return this.tagged({
|
|
18390
18537
|
id,
|
|
18391
18538
|
type: "SPENDABLE_VTXOS",
|
|
18392
|
-
payload: { vtxos }
|
|
18539
|
+
payload: { vtxos, filterApplied: true }
|
|
18393
18540
|
});
|
|
18394
18541
|
}
|
|
18395
18542
|
case "GET_BOARDING_UTXOS": {
|
|
@@ -18470,11 +18617,15 @@ var WalletMessageHandler = class {
|
|
|
18470
18617
|
}
|
|
18471
18618
|
case "GET_CONTRACTS_WITH_VTXOS": {
|
|
18472
18619
|
const manager = await this.readonlyWallet.getContractManager();
|
|
18473
|
-
const contracts = await manager.getContractsWithVtxos(
|
|
18620
|
+
const contracts = await manager.getContractsWithVtxos(
|
|
18621
|
+
message.payload.filter,
|
|
18622
|
+
void 0,
|
|
18623
|
+
message.payload.options
|
|
18624
|
+
);
|
|
18474
18625
|
return this.tagged({
|
|
18475
18626
|
id,
|
|
18476
18627
|
type: "CONTRACTS_WITH_VTXOS",
|
|
18477
|
-
payload: { contracts }
|
|
18628
|
+
payload: { contracts, filterApplied: true }
|
|
18478
18629
|
});
|
|
18479
18630
|
}
|
|
18480
18631
|
case "WATCH_SCRIPT": {
|
|
@@ -18857,7 +19008,7 @@ var WalletMessageHandler = class {
|
|
|
18857
19008
|
// Wallet methods
|
|
18858
19009
|
async handleInitWallet({ payload }) {
|
|
18859
19010
|
const { arkServerUrl } = payload;
|
|
18860
|
-
this.indexerProvider = new
|
|
19011
|
+
this.indexerProvider = new chunkH62OOAS4_cjs.RestIndexerProvider(arkServerUrl);
|
|
18861
19012
|
await this.onWalletInitialized();
|
|
18862
19013
|
}
|
|
18863
19014
|
/**
|
|
@@ -19146,7 +19297,7 @@ var WalletMessageHandler = class {
|
|
|
19146
19297
|
if (v.isUnrolled) {
|
|
19147
19298
|
return withUnrolled;
|
|
19148
19299
|
}
|
|
19149
|
-
if (
|
|
19300
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(v)) {
|
|
19150
19301
|
return false;
|
|
19151
19302
|
}
|
|
19152
19303
|
if (includeRecoverable) {
|
|
@@ -19155,10 +19306,10 @@ var WalletMessageHandler = class {
|
|
|
19155
19306
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
19156
19307
|
return false;
|
|
19157
19308
|
}
|
|
19158
|
-
if (
|
|
19309
|
+
if (chunkCJN4CUEU_cjs.isRecoverable(v)) {
|
|
19159
19310
|
return false;
|
|
19160
19311
|
}
|
|
19161
|
-
if (
|
|
19312
|
+
if (chunkCJN4CUEU_cjs.isExpired(v)) {
|
|
19162
19313
|
return false;
|
|
19163
19314
|
}
|
|
19164
19315
|
return true;
|
|
@@ -19266,7 +19417,7 @@ var WalletMessageHandler = class {
|
|
|
19266
19417
|
this.readonlyWallet.getBoardingTxs()
|
|
19267
19418
|
]);
|
|
19268
19419
|
const indexerProvider = this.indexerProvider;
|
|
19269
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
19420
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkCJN4CUEU_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
19270
19421
|
return buildTransactionHistory(
|
|
19271
19422
|
vtxos,
|
|
19272
19423
|
boardingTxs,
|
|
@@ -19974,7 +20125,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19974
20125
|
};
|
|
19975
20126
|
try {
|
|
19976
20127
|
const response = await this.sendMessage(message);
|
|
19977
|
-
return response.payload.vtxos.map(
|
|
20128
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
19978
20129
|
} catch (error) {
|
|
19979
20130
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
19980
20131
|
}
|
|
@@ -19999,7 +20150,13 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19999
20150
|
};
|
|
20000
20151
|
try {
|
|
20001
20152
|
const response = await this.sendMessage(message);
|
|
20002
|
-
|
|
20153
|
+
const payload = response.payload;
|
|
20154
|
+
if ((filter?.watchedOnly || filter?.genericallySpendableOnly || filter?.requireSynced) && payload.filterApplied !== true) {
|
|
20155
|
+
throw new Error(
|
|
20156
|
+
"Service worker does not support the requested contract scope or freshness check"
|
|
20157
|
+
);
|
|
20158
|
+
}
|
|
20159
|
+
return payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
20003
20160
|
} catch (error) {
|
|
20004
20161
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
20005
20162
|
}
|
|
@@ -20084,15 +20241,20 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20084
20241
|
throw new Error("Failed to get contracts");
|
|
20085
20242
|
}
|
|
20086
20243
|
},
|
|
20087
|
-
async getContractsWithVtxos(filter) {
|
|
20244
|
+
async getContractsWithVtxos(filter, _pageSize, options) {
|
|
20088
20245
|
const message = {
|
|
20089
20246
|
type: "GET_CONTRACTS_WITH_VTXOS",
|
|
20090
20247
|
id: getRandomId(),
|
|
20091
20248
|
tag: messageTag,
|
|
20092
|
-
payload: { filter }
|
|
20249
|
+
payload: { filter, options }
|
|
20093
20250
|
};
|
|
20094
20251
|
try {
|
|
20095
20252
|
const response = await sendContractMessage(message);
|
|
20253
|
+
if (options?.requireSynced && response.payload.filterApplied !== true) {
|
|
20254
|
+
throw new Error(
|
|
20255
|
+
"Service worker does not support the requested freshness check"
|
|
20256
|
+
);
|
|
20257
|
+
}
|
|
20096
20258
|
await refreshSyncState();
|
|
20097
20259
|
return response.payload.contracts;
|
|
20098
20260
|
} catch (e) {
|
|
@@ -20170,7 +20332,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20170
20332
|
};
|
|
20171
20333
|
try {
|
|
20172
20334
|
const response = await sendContractMessage(message);
|
|
20173
|
-
return response.payload.vtxos.map(
|
|
20335
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
20174
20336
|
} catch (e) {
|
|
20175
20337
|
throw new Error("Failed to annotate vtxos");
|
|
20176
20338
|
}
|
|
@@ -20782,7 +20944,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20782
20944
|
};
|
|
20783
20945
|
try {
|
|
20784
20946
|
const response = await wallet.sendMessage(message);
|
|
20785
|
-
return response.payload.vtxos.map(
|
|
20947
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
20786
20948
|
} catch (e) {
|
|
20787
20949
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
20788
20950
|
}
|
|
@@ -20894,12 +21056,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20894
21056
|
* @returns Configured onchain wallet
|
|
20895
21057
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
20896
21058
|
*/
|
|
20897
|
-
static async create(identity, networkName =
|
|
21059
|
+
static async create(identity, networkName = chunkCJN4CUEU_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
20898
21060
|
const pubkey = await identity.xOnlyPublicKey();
|
|
20899
21061
|
if (!pubkey) {
|
|
20900
21062
|
throw new Error("Invalid configured public key");
|
|
20901
21063
|
}
|
|
20902
|
-
const network =
|
|
21064
|
+
const network = chunkCJN4CUEU_cjs.getNetwork(networkName);
|
|
20903
21065
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
20904
21066
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
20905
21067
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -21005,7 +21167,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21005
21167
|
if (!inputs) {
|
|
21006
21168
|
throw new Error("Fee estimation failed");
|
|
21007
21169
|
}
|
|
21008
|
-
let tx = new
|
|
21170
|
+
let tx = new chunkCJN4CUEU_cjs.Transaction();
|
|
21009
21171
|
for (const input of inputs) {
|
|
21010
21172
|
tx.addInput({
|
|
21011
21173
|
txid: input.txid,
|
|
@@ -21063,7 +21225,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21063
21225
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
21064
21226
|
*/
|
|
21065
21227
|
async bumpAnchor(parentHex, feeRate) {
|
|
21066
|
-
const parent =
|
|
21228
|
+
const parent = chunkCJN4CUEU_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
21067
21229
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
21068
21230
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
21069
21231
|
return [parent.hex, child.hex];
|
|
@@ -21970,7 +22132,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21970
22132
|
try {
|
|
21971
22133
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
21972
22134
|
for (const psbt of txs) {
|
|
21973
|
-
const tx =
|
|
22135
|
+
const tx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
21974
22136
|
resolved.set(tx.id, tx.toBytes());
|
|
21975
22137
|
}
|
|
21976
22138
|
} catch (err) {
|
|
@@ -22003,7 +22165,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
22003
22165
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
22004
22166
|
const pending = [];
|
|
22005
22167
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
22006
|
-
if (
|
|
22168
|
+
if (chunkCJN4CUEU_cjs.getArkPsbtFields(tx, i, chunkCJN4CUEU_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
22007
22169
|
}
|
|
22008
22170
|
if (pending.length === 0) return;
|
|
22009
22171
|
const resolved = await resolvePrevTxs(
|
|
@@ -22012,13 +22174,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
22012
22174
|
onchain
|
|
22013
22175
|
);
|
|
22014
22176
|
for (const i of pending) {
|
|
22015
|
-
|
|
22177
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(tx, i, chunkCJN4CUEU_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
22016
22178
|
}
|
|
22017
22179
|
}
|
|
22018
22180
|
async function attachPrevoutTxs(tx, source) {
|
|
22019
22181
|
const pending = [];
|
|
22020
22182
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
22021
|
-
if (
|
|
22183
|
+
if (chunkCJN4CUEU_cjs.getArkPsbtFields(tx, i, chunkCJN4CUEU_cjs.PrevoutTxField).length > 0) continue;
|
|
22022
22184
|
const input = tx.getInput(i);
|
|
22023
22185
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
22024
22186
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -22029,7 +22191,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
22029
22191
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
22030
22192
|
}
|
|
22031
22193
|
for (const { index, txid } of pending) {
|
|
22032
|
-
|
|
22194
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(tx, index, chunkCJN4CUEU_cjs.PrevoutTxField, resolved.get(txid));
|
|
22033
22195
|
}
|
|
22034
22196
|
}
|
|
22035
22197
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -22055,7 +22217,7 @@ exports.BIP322 = void 0;
|
|
|
22055
22217
|
async function sign2(message, identity, network) {
|
|
22056
22218
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
22057
22219
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
22058
|
-
const toSpend =
|
|
22220
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
22059
22221
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
22060
22222
|
const signed = await identity.sign(toSign, [0]);
|
|
22061
22223
|
signed.finalizeIdx(0);
|
|
@@ -22113,7 +22275,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
22113
22275
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
22114
22276
|
return false;
|
|
22115
22277
|
}
|
|
22116
|
-
const toSpend =
|
|
22278
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22117
22279
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
22118
22280
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
22119
22281
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -22134,7 +22296,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
22134
22296
|
}
|
|
22135
22297
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
22136
22298
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
22137
|
-
const toSpend =
|
|
22299
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22138
22300
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
22139
22301
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
22140
22302
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -22187,7 +22349,7 @@ function encodeCompactSize(n) {
|
|
|
22187
22349
|
return buf;
|
|
22188
22350
|
}
|
|
22189
22351
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
22190
|
-
const tx = new
|
|
22352
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 0 });
|
|
22191
22353
|
tx.addInput({
|
|
22192
22354
|
txid: toSpend.id,
|
|
22193
22355
|
index: 0,
|
|
@@ -22201,12 +22363,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
22201
22363
|
});
|
|
22202
22364
|
tx.addOutput({
|
|
22203
22365
|
amount: 0n,
|
|
22204
|
-
script:
|
|
22366
|
+
script: chunkCJN4CUEU_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22205
22367
|
});
|
|
22206
22368
|
return tx;
|
|
22207
22369
|
}
|
|
22208
22370
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
22209
|
-
const tx = new
|
|
22371
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 0 });
|
|
22210
22372
|
tx.addInput({
|
|
22211
22373
|
txid: toSpend.id,
|
|
22212
22374
|
index: 0,
|
|
@@ -22218,7 +22380,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
22218
22380
|
});
|
|
22219
22381
|
tx.addOutput({
|
|
22220
22382
|
amount: 0n,
|
|
22221
|
-
script:
|
|
22383
|
+
script: chunkCJN4CUEU_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22222
22384
|
});
|
|
22223
22385
|
return tx;
|
|
22224
22386
|
}
|
|
@@ -22231,7 +22393,7 @@ var RestEmulatorProvider = class {
|
|
|
22231
22393
|
serverUrl;
|
|
22232
22394
|
async getInfo() {
|
|
22233
22395
|
const url = `${this.serverUrl}/v1/info`;
|
|
22234
|
-
const response = await
|
|
22396
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(url);
|
|
22235
22397
|
if (!response.ok) {
|
|
22236
22398
|
const errorText2 = await response.text();
|
|
22237
22399
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -22349,7 +22511,7 @@ var RestEmulatorProvider = class {
|
|
|
22349
22511
|
}
|
|
22350
22512
|
};
|
|
22351
22513
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
22352
|
-
const tx =
|
|
22514
|
+
const tx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
22353
22515
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
22354
22516
|
const input = tx.getInput(0);
|
|
22355
22517
|
if (!input) {
|
|
@@ -22376,14 +22538,14 @@ var ExitPathError = class extends Error {
|
|
|
22376
22538
|
reason;
|
|
22377
22539
|
};
|
|
22378
22540
|
function delayWeight(sequence) {
|
|
22379
|
-
const t =
|
|
22541
|
+
const t = chunkCJN4CUEU_cjs.sequenceToTimelock(sequence);
|
|
22380
22542
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
22381
22543
|
}
|
|
22382
22544
|
async function resolveUnilateralPath(params) {
|
|
22383
22545
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
22384
22546
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
22385
22547
|
if (contract) {
|
|
22386
|
-
const handler =
|
|
22548
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
22387
22549
|
if (!handler) {
|
|
22388
22550
|
throw new ExitPathError(
|
|
22389
22551
|
"no-handler",
|
|
@@ -22406,12 +22568,12 @@ async function resolveUnilateralPath(params) {
|
|
|
22406
22568
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
22407
22569
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
22408
22570
|
}
|
|
22409
|
-
const decoded =
|
|
22571
|
+
const decoded = chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
22410
22572
|
let best;
|
|
22411
22573
|
for (const exit of decoded.exitPaths()) {
|
|
22412
22574
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
22413
22575
|
if (!leaf) continue;
|
|
22414
|
-
const sequence =
|
|
22576
|
+
const sequence = chunkCJN4CUEU_cjs.timelockToSequence(exit.params.timelock);
|
|
22415
22577
|
const weight = delayWeight(sequence);
|
|
22416
22578
|
if (!best || weight < best.weight) {
|
|
22417
22579
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -22631,7 +22793,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22631
22793
|
let totalAmount = 0n;
|
|
22632
22794
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
22633
22795
|
for (const vtxo of vtxos) {
|
|
22634
|
-
if (!
|
|
22796
|
+
if (!chunkCJN4CUEU_cjs.canSweepOnchain(vtxo)) {
|
|
22635
22797
|
throw new Error(
|
|
22636
22798
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
22637
22799
|
);
|
|
@@ -22642,14 +22804,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22642
22804
|
}
|
|
22643
22805
|
const resolved = await resolveUnilateralPath({
|
|
22644
22806
|
vtxo,
|
|
22645
|
-
scriptHex: base.hex.encode(
|
|
22807
|
+
scriptHex: base.hex.encode(chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22646
22808
|
contractRepository: wallet.contractRepository,
|
|
22647
22809
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
22648
22810
|
currentTime: Date.now()
|
|
22649
22811
|
});
|
|
22650
22812
|
const spendingLeaf = resolved.selection.leaf;
|
|
22651
22813
|
const sequence = resolved.selection.sequence;
|
|
22652
|
-
const timelock =
|
|
22814
|
+
const timelock = chunkCJN4CUEU_cjs.sequenceToTimelock(sequence);
|
|
22653
22815
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
22654
22816
|
if (!elapsed) {
|
|
22655
22817
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -22662,7 +22824,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22662
22824
|
sequence,
|
|
22663
22825
|
witnessUtxo: {
|
|
22664
22826
|
amount: BigInt(vtxo.value),
|
|
22665
|
-
script:
|
|
22827
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
22666
22828
|
},
|
|
22667
22829
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22668
22830
|
});
|
|
@@ -22672,7 +22834,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22672
22834
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
22673
22835
|
);
|
|
22674
22836
|
}
|
|
22675
|
-
const tx = new
|
|
22837
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
22676
22838
|
for (const input of inputs) {
|
|
22677
22839
|
tx.addInput(input);
|
|
22678
22840
|
}
|
|
@@ -22755,7 +22917,7 @@ async function buildSignedSweep(params) {
|
|
|
22755
22917
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
22756
22918
|
);
|
|
22757
22919
|
}
|
|
22758
|
-
const tx = new
|
|
22920
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
22759
22921
|
tx.addInput({
|
|
22760
22922
|
txid: vtxo.txid,
|
|
22761
22923
|
index: vtxo.vout,
|
|
@@ -22780,7 +22942,7 @@ async function buildSignedSweep(params) {
|
|
|
22780
22942
|
finalScriptWitness: [
|
|
22781
22943
|
tapScriptSig[0][1],
|
|
22782
22944
|
...path.extraWitness,
|
|
22783
|
-
|
|
22945
|
+
chunkCJN4CUEU_cjs.scriptFromTapLeafScript(path.leaf),
|
|
22784
22946
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
22785
22947
|
]
|
|
22786
22948
|
});
|
|
@@ -22810,7 +22972,7 @@ async function resolveFeeRate(opts) {
|
|
|
22810
22972
|
}
|
|
22811
22973
|
async function selectExitVtxos(opts) {
|
|
22812
22974
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
22813
|
-
const res = await
|
|
22975
|
+
const res = await chunkCJN4CUEU_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
22814
22976
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
22815
22977
|
const out = [];
|
|
22816
22978
|
for (const vtxo of res.vtxos) {
|
|
@@ -22825,7 +22987,7 @@ async function selectExitVtxos(opts) {
|
|
|
22825
22987
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
22826
22988
|
);
|
|
22827
22989
|
}
|
|
22828
|
-
const handler =
|
|
22990
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
22829
22991
|
if (!handler) {
|
|
22830
22992
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
22831
22993
|
}
|
|
@@ -22855,7 +23017,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22855
23017
|
if (pendingNodes.length > 0) {
|
|
22856
23018
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
22857
23019
|
for (const psbt of txs) {
|
|
22858
|
-
psbts.set(
|
|
23020
|
+
psbts.set(chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
22859
23021
|
}
|
|
22860
23022
|
}
|
|
22861
23023
|
const childVsize = Number(
|
|
@@ -22891,7 +23053,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22891
23053
|
try {
|
|
22892
23054
|
const resolved = await resolveUnilateralPath({
|
|
22893
23055
|
vtxo,
|
|
22894
|
-
scriptHex: base.hex.encode(
|
|
23056
|
+
scriptHex: base.hex.encode(chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22895
23057
|
contractRepository: wallet.contractRepository,
|
|
22896
23058
|
walletPubKeyHex,
|
|
22897
23059
|
currentTime: Date.now()
|
|
@@ -22910,7 +23072,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22910
23072
|
});
|
|
22911
23073
|
continue;
|
|
22912
23074
|
}
|
|
22913
|
-
const t =
|
|
23075
|
+
const t = chunkCJN4CUEU_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
22914
23076
|
const delay = { type: t.type, value: Number(t.value) };
|
|
22915
23077
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
22916
23078
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -23311,7 +23473,7 @@ async function prepare(opts) {
|
|
|
23311
23473
|
txid: sweep.vtxo.txid,
|
|
23312
23474
|
vout: sweep.vtxo.vout,
|
|
23313
23475
|
value: sweep.vtxo.value,
|
|
23314
|
-
pkScript:
|
|
23476
|
+
pkScript: chunkCJN4CUEU_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
23315
23477
|
},
|
|
23316
23478
|
path: sweep.resolved.selection,
|
|
23317
23479
|
outputAddress: opts.sweepAddress,
|
|
@@ -23400,7 +23562,7 @@ async function prepare(opts) {
|
|
|
23400
23562
|
if (newFee <= splitterFee) break;
|
|
23401
23563
|
splitterFee = newFee;
|
|
23402
23564
|
}
|
|
23403
|
-
const splitter = new
|
|
23565
|
+
const splitter = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
23404
23566
|
for (const coin of selected.inputs) {
|
|
23405
23567
|
splitter.addInput({
|
|
23406
23568
|
txid: coin.txid,
|
|
@@ -23544,41 +23706,43 @@ var UnilateralExit = {
|
|
|
23544
23706
|
// src/arkade/index.ts
|
|
23545
23707
|
var arkade_exports = {};
|
|
23546
23708
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
23547
|
-
ARKADE_OP: () =>
|
|
23548
|
-
ARKADE_OPCODES: () =>
|
|
23549
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
23550
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
23551
|
-
ARKADE_OPS: () =>
|
|
23709
|
+
ARKADE_OP: () => chunkLUWSY2QO_cjs.ARKADE_OP,
|
|
23710
|
+
ARKADE_OPCODES: () => chunkLUWSY2QO_cjs.ARKADE_OPCODES,
|
|
23711
|
+
ARKADE_OPCODE_NAMES: () => chunkLUWSY2QO_cjs.ARKADE_OPCODE_NAMES,
|
|
23712
|
+
ARKADE_OPCODE_VALUES: () => chunkLUWSY2QO_cjs.ARKADE_OPCODE_VALUES,
|
|
23713
|
+
ARKADE_OPS: () => chunkLUWSY2QO_cjs.ARKADE_OPS,
|
|
23552
23714
|
Arkade: () => Arkade,
|
|
23553
23715
|
ArkadeContract: () => ArkadeContract,
|
|
23554
|
-
ArkadeProgramScript: () =>
|
|
23555
|
-
ArkadeScript: () =>
|
|
23716
|
+
ArkadeProgramScript: () => chunkLUWSY2QO_cjs.ArkadeProgramScript,
|
|
23717
|
+
ArkadeScript: () => chunkLUWSY2QO_cjs.ArkadeScript,
|
|
23556
23718
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
23557
|
-
BigNum: () =>
|
|
23719
|
+
BigNum: () => chunkLUWSY2QO_cjs.bignum_exports,
|
|
23558
23720
|
OP: () => btcSigner.OP,
|
|
23559
|
-
OPCODE_NAMES: () =>
|
|
23560
|
-
OPCODE_VALUES: () =>
|
|
23561
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
23721
|
+
OPCODE_NAMES: () => chunkLUWSY2QO_cjs.OPCODE_NAMES,
|
|
23722
|
+
OPCODE_VALUES: () => chunkLUWSY2QO_cjs.OPCODE_VALUES,
|
|
23723
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkLUWSY2QO_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
23562
23724
|
Script: () => btcSigner.Script,
|
|
23563
|
-
arkadeScriptHash: () =>
|
|
23564
|
-
arkadeWitnessHash: () =>
|
|
23565
|
-
asmToBytes: () =>
|
|
23566
|
-
bytesToASM: () =>
|
|
23567
|
-
computeArkadeScriptPublicKey: () =>
|
|
23725
|
+
arkadeScriptHash: () => chunkLUWSY2QO_cjs.arkadeScriptHash,
|
|
23726
|
+
arkadeWitnessHash: () => chunkLUWSY2QO_cjs.arkadeWitnessHash,
|
|
23727
|
+
asmToBytes: () => chunkLUWSY2QO_cjs.asmToBytes,
|
|
23728
|
+
bytesToASM: () => chunkLUWSY2QO_cjs.bytesToASM,
|
|
23729
|
+
computeArkadeScriptPublicKey: () => chunkLUWSY2QO_cjs.computeArkadeScriptPublicKey,
|
|
23568
23730
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
23569
|
-
deserializeArkadeContractParams: () =>
|
|
23570
|
-
fromASM: () =>
|
|
23571
|
-
getOpcodeName: () =>
|
|
23572
|
-
getOpcodeValue: () =>
|
|
23573
|
-
|
|
23574
|
-
|
|
23575
|
-
|
|
23576
|
-
|
|
23577
|
-
|
|
23578
|
-
|
|
23579
|
-
|
|
23731
|
+
deserializeArkadeContractParams: () => chunkLUWSY2QO_cjs.deserializeArkadeContractParams,
|
|
23732
|
+
fromASM: () => chunkLUWSY2QO_cjs.fromASM,
|
|
23733
|
+
getOpcodeName: () => chunkLUWSY2QO_cjs.getOpcodeName,
|
|
23734
|
+
getOpcodeValue: () => chunkLUWSY2QO_cjs.getOpcodeValue,
|
|
23735
|
+
isContractArtifact: () => isContractArtifact,
|
|
23736
|
+
parseArtifact: () => chunkLUWSY2QO_cjs.parseArtifact,
|
|
23737
|
+
programFromArtifact: () => programFromArtifact,
|
|
23738
|
+
resolveAsm: () => chunkLUWSY2QO_cjs.resolveAsm,
|
|
23739
|
+
serializeArkadeContractParams: () => chunkLUWSY2QO_cjs.serializeArkadeContractParams,
|
|
23740
|
+
stringifyArtifact: () => chunkLUWSY2QO_cjs.stringifyArtifact,
|
|
23741
|
+
toASM: () => chunkLUWSY2QO_cjs.toASM,
|
|
23742
|
+
validateProgram: () => chunkLUWSY2QO_cjs.validateProgram,
|
|
23743
|
+
witnessRefToBytes: () => chunkLUWSY2QO_cjs.witnessRefToBytes
|
|
23580
23744
|
});
|
|
23581
|
-
var isVtxoCoin = (input) =>
|
|
23745
|
+
var isVtxoCoin = (input) => chunkCJN4CUEU_cjs.isVirtualCoin(input);
|
|
23582
23746
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
23583
23747
|
let batchId;
|
|
23584
23748
|
let sweepTapTreeRoot;
|
|
@@ -23599,23 +23763,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23599
23763
|
);
|
|
23600
23764
|
await arkProvider.confirmRegistration(intentId);
|
|
23601
23765
|
batchId = event.id;
|
|
23602
|
-
const sweepTapscript =
|
|
23766
|
+
const sweepTapscript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
23603
23767
|
timelock,
|
|
23604
|
-
pubkeys: [
|
|
23768
|
+
pubkeys: [chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
23605
23769
|
}).script;
|
|
23606
23770
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
23607
23771
|
return { skip: false };
|
|
23608
23772
|
},
|
|
23609
23773
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
23610
23774
|
const signerPubKey = await session.getPublicKey();
|
|
23611
|
-
const xonlySignerPubKey =
|
|
23775
|
+
const xonlySignerPubKey = chunkLUWSY2QO_cjs.toXOnly(signerPubKey, "signer key");
|
|
23612
23776
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
23613
|
-
(k) => base.hex.encode(
|
|
23777
|
+
(k) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
23614
23778
|
);
|
|
23615
23779
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
23616
23780
|
return { skip: true };
|
|
23617
23781
|
}
|
|
23618
|
-
const commitmentTx =
|
|
23782
|
+
const commitmentTx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
23619
23783
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
23620
23784
|
if (recipients && recipients.length > 0) {
|
|
23621
23785
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -23653,7 +23817,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23653
23817
|
if (connectorTree) {
|
|
23654
23818
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
23655
23819
|
}
|
|
23656
|
-
let commitmentPsbt =
|
|
23820
|
+
let commitmentPsbt = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
23657
23821
|
assertFinalCommitmentMatchesValidated(
|
|
23658
23822
|
commitmentPsbt,
|
|
23659
23823
|
validatedCommitmentTxid,
|
|
@@ -23695,7 +23859,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23695
23859
|
boardingIndices.push(boardingIdx);
|
|
23696
23860
|
continue;
|
|
23697
23861
|
}
|
|
23698
|
-
if (
|
|
23862
|
+
if (chunkCJN4CUEU_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
23699
23863
|
continue;
|
|
23700
23864
|
}
|
|
23701
23865
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -23716,7 +23880,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23716
23880
|
index: input.vout,
|
|
23717
23881
|
witnessUtxo: {
|
|
23718
23882
|
amount: BigInt(input.value),
|
|
23719
|
-
script:
|
|
23883
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
23720
23884
|
},
|
|
23721
23885
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
23722
23886
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -23768,6 +23932,263 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23768
23932
|
}
|
|
23769
23933
|
};
|
|
23770
23934
|
}
|
|
23935
|
+
var NATIVE_STRUCTS = {
|
|
23936
|
+
AssetId: [
|
|
23937
|
+
["txid", "bytes32"],
|
|
23938
|
+
["gidx", "int"]
|
|
23939
|
+
],
|
|
23940
|
+
Outpoint: [
|
|
23941
|
+
["txid", "bytes32"],
|
|
23942
|
+
["vout", "int"]
|
|
23943
|
+
],
|
|
23944
|
+
ECPoint: [
|
|
23945
|
+
["x", "int"],
|
|
23946
|
+
["y", "int"]
|
|
23947
|
+
]
|
|
23948
|
+
};
|
|
23949
|
+
var HASH_OPCODES = /* @__PURE__ */ new Set(["OP_SHA256", "OP_HASH160", "OP_HASH256", "OP_RIPEMD160"]);
|
|
23950
|
+
function isRecord(value) {
|
|
23951
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23952
|
+
}
|
|
23953
|
+
function isNamed(value) {
|
|
23954
|
+
return isRecord(value) && typeof value.name === "string" && typeof value.type === "string" && value.type.length > 0;
|
|
23955
|
+
}
|
|
23956
|
+
function isContractArtifact(value) {
|
|
23957
|
+
if (!isRecord(value) || typeof value.contractName !== "string") return false;
|
|
23958
|
+
if (!Array.isArray(value.constructorInputs)) return false;
|
|
23959
|
+
if (value.structs !== void 0 && !Array.isArray(value.structs)) return false;
|
|
23960
|
+
if (!Array.isArray(value.functions) || value.functions.length === 0) return false;
|
|
23961
|
+
return value.functions.every(
|
|
23962
|
+
(group) => isRecord(group) && typeof group.name === "string" && Array.isArray(group.leaves) && group.leaves.length > 0
|
|
23963
|
+
);
|
|
23964
|
+
}
|
|
23965
|
+
function fail(detail) {
|
|
23966
|
+
throw new Error(`programFromArtifact: ${detail}`);
|
|
23967
|
+
}
|
|
23968
|
+
function claim(seen, name, kind) {
|
|
23969
|
+
if (seen.has(name)) fail(`duplicate ${kind} '${name}'`);
|
|
23970
|
+
seen.add(name);
|
|
23971
|
+
}
|
|
23972
|
+
var SCALAR_TYPES = {
|
|
23973
|
+
pubkey: "pubkey",
|
|
23974
|
+
signature: "sig",
|
|
23975
|
+
bytes: "bytes",
|
|
23976
|
+
bytes20: "hash",
|
|
23977
|
+
bytes32: "hash",
|
|
23978
|
+
asset: "hash",
|
|
23979
|
+
int: "int",
|
|
23980
|
+
bool: "int"
|
|
23981
|
+
};
|
|
23982
|
+
function argType(arkType) {
|
|
23983
|
+
if (!Object.hasOwn(SCALAR_TYPES, arkType)) fail(`unknown type '${arkType}'`);
|
|
23984
|
+
return SCALAR_TYPES[arkType];
|
|
23985
|
+
}
|
|
23986
|
+
function arrayParts(type) {
|
|
23987
|
+
const open = type.indexOf("[");
|
|
23988
|
+
if (open < 0 || !type.endsWith("]")) return [type, 0];
|
|
23989
|
+
const length = Number(type.slice(open + 1, -1));
|
|
23990
|
+
return Number.isInteger(length) && length > 0 ? [type.slice(0, open), length] : [type, 0];
|
|
23991
|
+
}
|
|
23992
|
+
function flatten(param, structs, stack = []) {
|
|
23993
|
+
if (!isNamed(param)) fail("parameter needs a name and a type");
|
|
23994
|
+
if (Object.hasOwn(NATIVE_STRUCTS, param.type)) {
|
|
23995
|
+
return NATIVE_STRUCTS[param.type].map(([field, type]) => ({
|
|
23996
|
+
name: `${param.name}.${field}`,
|
|
23997
|
+
type: argType(type)
|
|
23998
|
+
}));
|
|
23999
|
+
}
|
|
24000
|
+
const declared = structs.find((struct) => struct?.name === param.type);
|
|
24001
|
+
if (declared) {
|
|
24002
|
+
if (stack.includes(param.type)) fail(`recursive struct layout '${param.type}'`);
|
|
24003
|
+
return declared.fields.flatMap(
|
|
24004
|
+
(field) => flatten({ name: `${param.name}.${field.name}`, type: field.type }, structs, [
|
|
24005
|
+
...stack,
|
|
24006
|
+
param.type
|
|
24007
|
+
])
|
|
24008
|
+
);
|
|
24009
|
+
}
|
|
24010
|
+
const [element, length] = arrayParts(param.type);
|
|
24011
|
+
if (length === 0) {
|
|
24012
|
+
if (param.type.includes("[") || param.type.includes("]")) {
|
|
24013
|
+
fail(`invalid array type '${param.type}'`);
|
|
24014
|
+
}
|
|
24015
|
+
return [{ name: param.name, type: argType(param.type) }];
|
|
24016
|
+
}
|
|
24017
|
+
if (Object.hasOwn(NATIVE_STRUCTS, element) || structs.some((struct) => struct.name === element)) {
|
|
24018
|
+
fail(`arrays of structs are not supported: '${param.type}'`);
|
|
24019
|
+
}
|
|
24020
|
+
return Array.from({ length }, (_, index) => ({
|
|
24021
|
+
name: `${param.name}.${index}`,
|
|
24022
|
+
type: argType(element)
|
|
24023
|
+
}));
|
|
24024
|
+
}
|
|
24025
|
+
function opcodeToken(token) {
|
|
24026
|
+
const base = token.slice(3);
|
|
24027
|
+
const name = base === "0" || /^([1-9]|1[0-6])$/.test(base) ? token : base;
|
|
24028
|
+
if (!Object.hasOwn(chunkLUWSY2QO_cjs.ARKADE_OPS, name)) {
|
|
24029
|
+
fail(`opcode '${token}' is not in this SDK's table`);
|
|
24030
|
+
}
|
|
24031
|
+
return name;
|
|
24032
|
+
}
|
|
24033
|
+
function instantiationParam(body) {
|
|
24034
|
+
return `contract_${body.replace(/[^A-Za-z0-9]+/g, "_")}`.replace(/_+$/, "");
|
|
24035
|
+
}
|
|
24036
|
+
function asmToken(token, instantiations) {
|
|
24037
|
+
if (token.startsWith("OP_")) return opcodeToken(token);
|
|
24038
|
+
if (token.startsWith("<") && token.endsWith(">")) {
|
|
24039
|
+
const inner = token.slice(1, -1);
|
|
24040
|
+
if (inner.startsWith("CONTRACT:")) {
|
|
24041
|
+
const body = inner.slice("CONTRACT:".length);
|
|
24042
|
+
const name = instantiationParam(body);
|
|
24043
|
+
const seen = instantiations.get(name);
|
|
24044
|
+
if (seen !== void 0 && seen !== body) {
|
|
24045
|
+
fail(`instantiations '${seen}' and '${body}' both map to parameter '${name}'`);
|
|
24046
|
+
}
|
|
24047
|
+
instantiations.set(name, body);
|
|
24048
|
+
return `$${name}`;
|
|
24049
|
+
}
|
|
24050
|
+
if (inner.startsWith("VTXO:")) {
|
|
24051
|
+
fail(`'${token}' is not a placeholder; the compiler emits <CONTRACT:\u2026>`);
|
|
24052
|
+
}
|
|
24053
|
+
if (inner === "SERVER_KEY" || inner.startsWith("EMULATOR_KEY:")) {
|
|
24054
|
+
fail(`${token} is a signer role and cannot appear in a covenant`);
|
|
24055
|
+
}
|
|
24056
|
+
return `$${inner}`;
|
|
24057
|
+
}
|
|
24058
|
+
if (token.startsWith("0x")) return base.hex.decode(token.slice(2));
|
|
24059
|
+
try {
|
|
24060
|
+
return BigInt(token);
|
|
24061
|
+
} catch {
|
|
24062
|
+
fail(`unrecognized assembly token '${token}'`);
|
|
24063
|
+
}
|
|
24064
|
+
}
|
|
24065
|
+
function providedWitness(witness) {
|
|
24066
|
+
if (witness === void 0) return [];
|
|
24067
|
+
if (!Array.isArray(witness)) fail("leaf witness must be an array");
|
|
24068
|
+
return witness.filter((item) => {
|
|
24069
|
+
if (!isNamed(item)) fail("witness item needs a name and a type");
|
|
24070
|
+
return !item.injected && item.type !== "signature";
|
|
24071
|
+
});
|
|
24072
|
+
}
|
|
24073
|
+
function parseLeaf(leaf, hasCovenant, instantiations, extras) {
|
|
24074
|
+
const asm = leaf.asm;
|
|
24075
|
+
let index = 0;
|
|
24076
|
+
let condition;
|
|
24077
|
+
if (asm.length >= 4 && HASH_OPCODES.has(asm[0]) && asm[2] === "OP_EQUAL") {
|
|
24078
|
+
if (asm[3] !== "OP_VERIFY")
|
|
24079
|
+
fail(`leaf '${leaf.name}': hash condition must end in OP_VERIFY`);
|
|
24080
|
+
condition = asm.slice(0, 3).map((token) => asmToken(token, instantiations));
|
|
24081
|
+
index = 4;
|
|
24082
|
+
}
|
|
24083
|
+
let csv;
|
|
24084
|
+
let cltv;
|
|
24085
|
+
if (asm.length >= index + 3 && asm[index + 2] === "OP_DROP") {
|
|
24086
|
+
const operand = asm[index].startsWith("<") && asm[index].endsWith(">") ? `$${asm[index].slice(1, -1)}` : BigInt(asm[index]);
|
|
24087
|
+
if (asm[index + 1] === "OP_CHECKSEQUENCEVERIFY") csv = { type: "blocks", value: operand };
|
|
24088
|
+
else if (asm[index + 1] === "OP_CHECKLOCKTIMEVERIFY") cltv = operand;
|
|
24089
|
+
else fail(`leaf '${leaf.name}': unexpected timelock opcode ${asm[index + 1]}`);
|
|
24090
|
+
index += 3;
|
|
24091
|
+
}
|
|
24092
|
+
const signers = [];
|
|
24093
|
+
let emulator;
|
|
24094
|
+
while (index < asm.length) {
|
|
24095
|
+
const key = asm[index];
|
|
24096
|
+
const terminator = asm[index + 1];
|
|
24097
|
+
const last = terminator === "OP_CHECKSIG";
|
|
24098
|
+
if (!last && terminator !== "OP_CHECKSIGVERIFY") {
|
|
24099
|
+
fail(`leaf '${leaf.name}': expected CHECKSIG after '${key}', found '${terminator}'`);
|
|
24100
|
+
}
|
|
24101
|
+
if (!key.startsWith("<") || !key.endsWith(">")) {
|
|
24102
|
+
fail(`leaf '${leaf.name}': unsupported key operand '${key}'`);
|
|
24103
|
+
}
|
|
24104
|
+
const inner = key.slice(1, -1);
|
|
24105
|
+
if (inner === "SERVER_KEY") signers.push("$server");
|
|
24106
|
+
else if (inner.startsWith("TWEAK:")) {
|
|
24107
|
+
const [, base, fn] = inner.match(/^TWEAK:([^:]+):([^:]+)$/) ?? [];
|
|
24108
|
+
if (!base || !fn) fail(`leaf '${leaf.name}': malformed tweak '${key}'`);
|
|
24109
|
+
signers.push({ tweak: `$${base}`, fn });
|
|
24110
|
+
} else if (inner.startsWith("EMULATOR_KEY:")) {
|
|
24111
|
+
if (!hasCovenant) fail(`leaf '${leaf.name}': ${key} needs a covenant`);
|
|
24112
|
+
if (!last) fail(`leaf '${leaf.name}': ${key} must be the last signer`);
|
|
24113
|
+
emulator = inner.slice("EMULATOR_KEY:".length);
|
|
24114
|
+
} else signers.push(`$${inner}`);
|
|
24115
|
+
index += 2;
|
|
24116
|
+
}
|
|
24117
|
+
const constructorTweak = signers.some((signer) => typeof signer !== "string");
|
|
24118
|
+
if (hasCovenant && emulator === void 0 && !constructorTweak) {
|
|
24119
|
+
fail(
|
|
24120
|
+
`leaf '${leaf.name}': covenant leaf must sign with the emulator or a tweaked constructor key`
|
|
24121
|
+
);
|
|
24122
|
+
}
|
|
24123
|
+
if (signers.length === 0) fail(`leaf '${leaf.name}': at least one named signer is required`);
|
|
24124
|
+
return {
|
|
24125
|
+
signers,
|
|
24126
|
+
...emulator !== void 0 ? { emulator } : hasCovenant ? { emulator: null } : {},
|
|
24127
|
+
...condition ? { asm: condition } : {},
|
|
24128
|
+
...csv ? { csv } : {},
|
|
24129
|
+
...cltv !== void 0 ? { cltv } : {},
|
|
24130
|
+
...extras.length > 0 ? { witness: extras.map((item) => item.name) } : {}
|
|
24131
|
+
};
|
|
24132
|
+
}
|
|
24133
|
+
function programFromArtifact(artifact) {
|
|
24134
|
+
if (!isContractArtifact(artifact)) {
|
|
24135
|
+
fail(
|
|
24136
|
+
"expected a complete arkadec artifact with contractName, constructorInputs, and non-empty functions"
|
|
24137
|
+
);
|
|
24138
|
+
}
|
|
24139
|
+
const structs = artifact.structs ?? [];
|
|
24140
|
+
const structNames = /* @__PURE__ */ new Set();
|
|
24141
|
+
for (const struct of structs) {
|
|
24142
|
+
if (!isRecord(struct) || typeof struct.name !== "string") continue;
|
|
24143
|
+
if (Object.hasOwn(SCALAR_TYPES, struct.name) || Object.hasOwn(NATIVE_STRUCTS, struct.name)) {
|
|
24144
|
+
fail(`struct name '${struct.name}' shadows a built-in type`);
|
|
24145
|
+
}
|
|
24146
|
+
claim(structNames, struct.name, "struct");
|
|
24147
|
+
}
|
|
24148
|
+
const instantiations = /* @__PURE__ */ new Map();
|
|
24149
|
+
const functions = {};
|
|
24150
|
+
const groups = /* @__PURE__ */ new Set();
|
|
24151
|
+
const leafNames = /* @__PURE__ */ new Set();
|
|
24152
|
+
for (const group of artifact.functions) {
|
|
24153
|
+
claim(groups, group.name, "spend group");
|
|
24154
|
+
const covenantInputs = (group.arkade?.inputs ?? []).flatMap(
|
|
24155
|
+
(input) => flatten(input, structs)
|
|
24156
|
+
);
|
|
24157
|
+
const arkadeScript = group.arkade ? {
|
|
24158
|
+
asm: group.arkade.asm.map((token) => asmToken(token, instantiations)),
|
|
24159
|
+
// Covenant witness is reverse declaration order.
|
|
24160
|
+
witness: covenantInputs.map((field) => field.name).reverse()
|
|
24161
|
+
} : void 0;
|
|
24162
|
+
for (const [index, leaf] of group.leaves.entries()) {
|
|
24163
|
+
const name = index === 0 ? group.name : `${group.name}/${index}:${leaf.name}`;
|
|
24164
|
+
claim(leafNames, name, "function name");
|
|
24165
|
+
const extras = providedWitness(leaf.witness);
|
|
24166
|
+
const tapscript = parseLeaf(leaf, group.arkade !== void 0, instantiations, extras);
|
|
24167
|
+
const inputs = [
|
|
24168
|
+
...covenantInputs,
|
|
24169
|
+
...extras.map((item) => ({ name: item.name, type: argType(item.type) }))
|
|
24170
|
+
];
|
|
24171
|
+
functions[name] = {
|
|
24172
|
+
...inputs.length > 0 ? { inputs } : {},
|
|
24173
|
+
tapscript,
|
|
24174
|
+
...arkadeScript ? { arkadeScript } : {}
|
|
24175
|
+
};
|
|
24176
|
+
}
|
|
24177
|
+
}
|
|
24178
|
+
const params = [
|
|
24179
|
+
...artifact.constructorInputs.flatMap((input) => flatten(input, structs)),
|
|
24180
|
+
{ name: "server", type: "pubkey" },
|
|
24181
|
+
...[...instantiations.keys()].map((name) => ({ name, type: "hash" }))
|
|
24182
|
+
];
|
|
24183
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
24184
|
+
for (const param of params) claim(paramNames, param.name, "program parameter");
|
|
24185
|
+
return {
|
|
24186
|
+
version: chunkLUWSY2QO_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
24187
|
+
name: artifact.contractName,
|
|
24188
|
+
params,
|
|
24189
|
+
functions
|
|
24190
|
+
};
|
|
24191
|
+
}
|
|
23771
24192
|
var Arkade = class _Arkade {
|
|
23772
24193
|
arkProvider;
|
|
23773
24194
|
/** The co-signing service, or undefined for emulator-less (pure tapscript) usage. */
|
|
@@ -23807,16 +24228,16 @@ var Arkade = class _Arkade {
|
|
|
23807
24228
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
23808
24229
|
static async connect(opts) {
|
|
23809
24230
|
const info = await opts.arkade.getInfo();
|
|
23810
|
-
const serverKey =
|
|
23811
|
-
const checkpoint =
|
|
23812
|
-
const network = opts.network ?? (Object.hasOwn(
|
|
24231
|
+
const serverKey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
24232
|
+
const checkpoint = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
24233
|
+
const network = opts.network ?? (Object.hasOwn(chunkCJN4CUEU_cjs.networks, info.network) ? chunkCJN4CUEU_cjs.getNetwork(info.network) : chunkCJN4CUEU_cjs.DEFAULT_NETWORK);
|
|
23813
24234
|
let emulatorKey;
|
|
23814
24235
|
if (opts.emulator) {
|
|
23815
|
-
emulatorKey = base.hex.decode(
|
|
24236
|
+
emulatorKey = base.hex.decode(chunkCJN4CUEU_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
23816
24237
|
}
|
|
23817
24238
|
let userKey;
|
|
23818
24239
|
if (opts.identity) {
|
|
23819
|
-
userKey =
|
|
24240
|
+
userKey = chunkLUWSY2QO_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
23820
24241
|
}
|
|
23821
24242
|
return new _Arkade({
|
|
23822
24243
|
arkProvider: opts.arkade,
|
|
@@ -23842,7 +24263,7 @@ var Arkade = class _Arkade {
|
|
|
23842
24263
|
* key respectively; explicit args always win.
|
|
23843
24264
|
*/
|
|
23844
24265
|
contract(program, args = {}) {
|
|
23845
|
-
const declared = (program.params ?? []).map(
|
|
24266
|
+
const declared = (program.params ?? []).map(chunkLUWSY2QO_cjs.inputName);
|
|
23846
24267
|
if (declared.includes("server") && args.server === void 0) {
|
|
23847
24268
|
args = { ...args, server: this.serverKey };
|
|
23848
24269
|
}
|
|
@@ -23862,7 +24283,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23862
24283
|
userKey: client.userKey,
|
|
23863
24284
|
emulatorKey: client.emulatorKey
|
|
23864
24285
|
};
|
|
23865
|
-
this.vtxoScript = new
|
|
24286
|
+
this.vtxoScript = new chunkLUWSY2QO_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
23866
24287
|
this.tapTree = this.vtxoScript.encode();
|
|
23867
24288
|
this.compiled = this.vtxoScript.compiled;
|
|
23868
24289
|
}
|
|
@@ -23890,7 +24311,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23890
24311
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
23891
24312
|
);
|
|
23892
24313
|
}
|
|
23893
|
-
const typed =
|
|
24314
|
+
const typed = chunkLUWSY2QO_cjs.deserializeArkadeContractParams(contract.params);
|
|
23894
24315
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
23895
24316
|
serverKey: typed.serverKey,
|
|
23896
24317
|
userKey: typed.userKey,
|
|
@@ -23931,7 +24352,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23931
24352
|
toContractParams() {
|
|
23932
24353
|
return {
|
|
23933
24354
|
type: "arkade",
|
|
23934
|
-
params:
|
|
24355
|
+
params: chunkLUWSY2QO_cjs.serializeArkadeContractParams({
|
|
23935
24356
|
program: this.program,
|
|
23936
24357
|
args: this.args,
|
|
23937
24358
|
serverKey: this.keys.serverKey,
|
|
@@ -23980,19 +24401,17 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23980
24401
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
23981
24402
|
if (registered) {
|
|
23982
24403
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
23983
|
-
return (withVtxos?.vtxos ?? []).filter(
|
|
23984
|
-
(v) => !chunkP53OHGXY_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
23985
|
-
);
|
|
24404
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
23986
24405
|
}
|
|
23987
24406
|
}
|
|
23988
24407
|
if (!this.client.indexer) {
|
|
23989
24408
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
23990
24409
|
}
|
|
23991
|
-
const { vtxos } = await
|
|
24410
|
+
const { vtxos } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
23992
24411
|
scripts: [scriptHex],
|
|
23993
24412
|
spendableOnly: true
|
|
23994
24413
|
});
|
|
23995
|
-
return vtxos.filter((v) => !
|
|
24414
|
+
return vtxos.filter((v) => !chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
23996
24415
|
}
|
|
23997
24416
|
/** Total spendable balance (requires an indexer). */
|
|
23998
24417
|
async getBalance() {
|
|
@@ -24090,7 +24509,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
24090
24509
|
this.contract.client.checkpoint
|
|
24091
24510
|
);
|
|
24092
24511
|
if (coin.sourceTx) {
|
|
24093
|
-
|
|
24512
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(arkTx, 0, chunkCJN4CUEU_cjs.PrevArkTxField, coin.sourceTx);
|
|
24094
24513
|
}
|
|
24095
24514
|
if (this.fn.arkadeScript) {
|
|
24096
24515
|
const indexer = this.contract.client.indexer;
|
|
@@ -24107,8 +24526,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
24107
24526
|
}
|
|
24108
24527
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
24109
24528
|
if (condition.length > 0) {
|
|
24110
|
-
|
|
24111
|
-
|
|
24529
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(arkTx, 0, chunkCJN4CUEU_cjs.ConditionWitness, condition);
|
|
24530
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(checkpoints[0], 0, chunkCJN4CUEU_cjs.ConditionWitness, condition);
|
|
24112
24531
|
}
|
|
24113
24532
|
const packets = [];
|
|
24114
24533
|
if (this.assetSpecs.length > 0) {
|
|
@@ -24147,7 +24566,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
24147
24566
|
base.base64.encode(signedArk2.toPSBT()),
|
|
24148
24567
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
24149
24568
|
);
|
|
24150
|
-
const txid =
|
|
24569
|
+
const txid = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
24151
24570
|
return {
|
|
24152
24571
|
txid,
|
|
24153
24572
|
signedArkTx: res2.signedArkTx,
|
|
@@ -24206,23 +24625,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
24206
24625
|
}
|
|
24207
24626
|
buildAssetPacket() {
|
|
24208
24627
|
const groups = this.assetSpecs.map((s) => {
|
|
24209
|
-
const id = typeof s.assetId === "string" ?
|
|
24210
|
-
return
|
|
24628
|
+
const id = typeof s.assetId === "string" ? chunkH62OOAS4_cjs.AssetId.fromString(s.assetId) : chunkH62OOAS4_cjs.AssetId.fromBytes(s.assetId);
|
|
24629
|
+
return chunkH62OOAS4_cjs.AssetGroup.create(
|
|
24211
24630
|
id,
|
|
24212
24631
|
null,
|
|
24213
|
-
s.inputs.map((i) =>
|
|
24214
|
-
s.outputs.map((o) =>
|
|
24215
|
-
(s.metadata ?? []).map((m) =>
|
|
24632
|
+
s.inputs.map((i) => chunkH62OOAS4_cjs.AssetInput.create(i.vin, i.amount)),
|
|
24633
|
+
s.outputs.map((o) => chunkH62OOAS4_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
24634
|
+
(s.metadata ?? []).map((m) => chunkH62OOAS4_cjs.Metadata.create(m.key, m.value))
|
|
24216
24635
|
);
|
|
24217
24636
|
});
|
|
24218
|
-
return
|
|
24637
|
+
return chunkH62OOAS4_cjs.Packet.create(groups);
|
|
24219
24638
|
}
|
|
24220
24639
|
witnessBytes(ref) {
|
|
24221
|
-
return
|
|
24640
|
+
return chunkLUWSY2QO_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
24222
24641
|
}
|
|
24223
24642
|
};
|
|
24224
24643
|
function bindInputs(fn, callArgs) {
|
|
24225
|
-
const names = (fn.def.inputs ?? []).map(
|
|
24644
|
+
const names = (fn.def.inputs ?? []).map(chunkLUWSY2QO_cjs.inputName);
|
|
24226
24645
|
if (callArgs.length !== names.length) {
|
|
24227
24646
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
24228
24647
|
}
|
|
@@ -24635,17 +25054,17 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
|
|
|
24635
25054
|
function offchainInputFees(vtxos, fees) {
|
|
24636
25055
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24637
25056
|
return vtxos.reduce(
|
|
24638
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
25057
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
24639
25058
|
0
|
|
24640
25059
|
);
|
|
24641
25060
|
}
|
|
24642
25061
|
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
24643
25062
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24644
25063
|
const net = inputs.reduce(
|
|
24645
|
-
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(
|
|
25064
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
24646
25065
|
0n
|
|
24647
25066
|
);
|
|
24648
|
-
const script = base.hex.encode(
|
|
25067
|
+
const script = base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
24649
25068
|
return changeAfterOutputFee(
|
|
24650
25069
|
net - needed,
|
|
24651
25070
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script }).satoshis)
|
|
@@ -24736,7 +25155,6 @@ exports.ConnectionDisposedError = ConnectionDisposedError;
|
|
|
24736
25155
|
exports.ContractManager = ContractManager;
|
|
24737
25156
|
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
24738
25157
|
exports.ContractWatcher = ContractWatcher;
|
|
24739
|
-
exports.DB_VERSION = DB_VERSION;
|
|
24740
25158
|
exports.DEFAULT_MESSAGE_TIMEOUTS = DEFAULT_MESSAGE_TIMEOUTS;
|
|
24741
25159
|
exports.DEFAULT_MIN_BATCH_EXPIRY_SECONDS = DEFAULT_MIN_BATCH_EXPIRY_SECONDS;
|
|
24742
25160
|
exports.DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS = DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS;
|
|
@@ -24945,5 +25363,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
|
24945
25363
|
exports.walletFeeSource = walletFeeSource;
|
|
24946
25364
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
24947
25365
|
exports.withPrevTxs = withPrevTxs;
|
|
24948
|
-
//# sourceMappingURL=chunk-
|
|
24949
|
-
//# sourceMappingURL=chunk-
|
|
25366
|
+
//# sourceMappingURL=chunk-YJEWWLOQ.cjs.map
|
|
25367
|
+
//# sourceMappingURL=chunk-YJEWWLOQ.cjs.map
|