@arkade-os/sdk 0.4.75 → 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-DjwCbb07.d.ts → asyncStorageTaskQueue-DTl0WM7E.d.ts} +1 -1
- package/dist/{asyncStorageTaskQueue-5k0H_cDM.d.cts → asyncStorageTaskQueue-MmJyAnu-.d.cts} +1 -1
- package/dist/{chunk-YA3L3WL4.cjs → chunk-4LP6XOMW.cjs} +17 -17
- package/dist/{chunk-YA3L3WL4.cjs.map → chunk-4LP6XOMW.cjs.map} +1 -1
- package/dist/{chunk-UKFA7NVE.js → chunk-52OA3UIC.js} +25 -12
- package/dist/chunk-52OA3UIC.js.map +1 -0
- package/dist/{chunk-4GLSOP6L.js → chunk-ACPANSOX.js} +43 -11
- package/dist/chunk-ACPANSOX.js.map +1 -0
- package/dist/{chunk-J5EX3OMM.cjs → chunk-CJN4CUEU.cjs} +25 -11
- package/dist/chunk-CJN4CUEU.cjs.map +1 -0
- package/dist/{chunk-SH23SRZE.cjs → chunk-H62OOAS4.cjs} +17 -17
- package/dist/{chunk-SH23SRZE.cjs.map → chunk-H62OOAS4.cjs.map} +1 -1
- package/dist/{chunk-PS564TAU.js → chunk-HKOFYHZP.js} +3 -3
- package/dist/{chunk-PS564TAU.js.map → chunk-HKOFYHZP.js.map} +1 -1
- package/dist/{chunk-YYWEBYFJ.cjs → chunk-LUWSY2QO.cjs} +89 -57
- package/dist/chunk-LUWSY2QO.cjs.map +1 -0
- package/dist/{chunk-FTLPTF3R.js → chunk-MLOZHTBN.js} +570 -114
- package/dist/chunk-MLOZHTBN.js.map +1 -0
- package/dist/{chunk-SKAL4MCW.js → chunk-T6MGH4V4.js} +4 -4
- package/dist/{chunk-SKAL4MCW.js.map → chunk-T6MGH4V4.js.map} +1 -1
- package/dist/{chunk-2Q2PYU3Y.cjs → chunk-Y4YK44IM.cjs} +10 -10
- package/dist/{chunk-2Q2PYU3Y.cjs.map → chunk-Y4YK44IM.cjs.map} +1 -1
- package/dist/{chunk-EHJYR4E5.cjs → chunk-YJEWWLOQ.cjs} +1005 -550
- package/dist/chunk-YJEWWLOQ.cjs.map +1 -0
- package/dist/{chunk-2ULUCL6A.js → chunk-YKNTUOUG.js} +4 -4
- package/dist/{chunk-2ULUCL6A.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-D_sW61rj.d.ts → delegate-CjcysR7s.d.ts} +1 -1
- package/dist/{delegate-D0v8yT-a.d.cts → delegate-QPCGaD_z.d.cts} +1 -1
- package/dist/{hdWalletCapable-66hG5KQP.d.cts → hdWalletCapable--pMncWbC.d.ts} +6 -4
- package/dist/{hdWalletCapable-DHCNbAgl.d.ts → hdWalletCapable-Bp_p0WLj.d.cts} +6 -4
- package/dist/{index-B2JSxDi1.d.cts → index-BMY272ns.d.cts} +26 -8
- package/dist/{index-TZBbMNqA.d.ts → index-Ie_ak2zY.d.cts} +39 -9
- package/dist/{index-TZBbMNqA.d.cts → index-Ie_ak2zY.d.ts} +39 -9
- package/dist/{index-vUeTpifq.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-CAAPpdyi.d.cts → taskRunner-BgRowCqB.d.cts} +1 -1
- package/dist/{taskRunner-CairkunF.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-4GLSOP6L.js.map +0 -1
- package/dist/chunk-EHJYR4E5.cjs.map +0 -1
- package/dist/chunk-FTLPTF3R.js.map +0 -1
- package/dist/chunk-J5EX3OMM.cjs.map +0 -1
- package/dist/chunk-UKFA7NVE.js.map +0 -1
- package/dist/chunk-YYWEBYFJ.cjs.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
|
}
|
|
@@ -3940,7 +3940,7 @@ function parseProgram(text, env) {
|
|
|
3940
3940
|
var DUST_AMOUNT = 546;
|
|
3941
3941
|
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
3942
3942
|
function getDustAmount(wallet) {
|
|
3943
|
-
return "dustAmount" in wallet ? wallet.dustAmount : FALLBACK_WALLET_DUST_AMOUNT;
|
|
3943
|
+
return wallet && "dustAmount" in wallet ? wallet.dustAmount : FALLBACK_WALLET_DUST_AMOUNT;
|
|
3944
3944
|
}
|
|
3945
3945
|
function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
3946
3946
|
return {
|
|
@@ -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);
|
|
@@ -9776,7 +9802,8 @@ function areCoalescibleContractTypes(a, b) {
|
|
|
9776
9802
|
function toWatchOnlyContract(params) {
|
|
9777
9803
|
return { ...params, state: params.state ?? "active", createdAt: Date.now() };
|
|
9778
9804
|
}
|
|
9779
|
-
|
|
9805
|
+
var TAPSCRIPT_MEMO_MAX_ENTRIES = 1024;
|
|
9806
|
+
function annotatableIn(scriptToContract, vtxos, memo) {
|
|
9780
9807
|
const scripts = /* @__PURE__ */ new Set();
|
|
9781
9808
|
const cache = /* @__PURE__ */ new Map();
|
|
9782
9809
|
const failures = /* @__PURE__ */ new Map();
|
|
@@ -9784,7 +9811,25 @@ function annotatableIn(scriptToContract, vtxos) {
|
|
|
9784
9811
|
const contract = scriptToContract.get(script);
|
|
9785
9812
|
if (!contract) continue;
|
|
9786
9813
|
try {
|
|
9787
|
-
|
|
9814
|
+
const key = `${contract.type}\0${script}\0${JSON.stringify(contract.params)}`;
|
|
9815
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
9816
|
+
const hit = memo?.get(script);
|
|
9817
|
+
let tapscripts;
|
|
9818
|
+
if (hit && hit.key === key && hit.handler === handler) {
|
|
9819
|
+
tapscripts = hit.tapscripts;
|
|
9820
|
+
memo.delete(script);
|
|
9821
|
+
memo.set(script, hit);
|
|
9822
|
+
} else {
|
|
9823
|
+
memo?.delete(script);
|
|
9824
|
+
tapscripts = deriveContractTapscripts(contract);
|
|
9825
|
+
if (handler && memo) {
|
|
9826
|
+
memo.set(script, { key, handler, tapscripts });
|
|
9827
|
+
if (memo.size > TAPSCRIPT_MEMO_MAX_ENTRIES) {
|
|
9828
|
+
memo.delete(memo.keys().next().value);
|
|
9829
|
+
}
|
|
9830
|
+
}
|
|
9831
|
+
}
|
|
9832
|
+
cache.set(script, tapscripts);
|
|
9788
9833
|
scripts.add(script);
|
|
9789
9834
|
} catch (err) {
|
|
9790
9835
|
failures.set(
|
|
@@ -9802,6 +9847,8 @@ var CHAIN_TIP_TIMEOUT_MS = 5e3;
|
|
|
9802
9847
|
var ContractManager = class _ContractManager {
|
|
9803
9848
|
config;
|
|
9804
9849
|
watcher;
|
|
9850
|
+
/** Per-sync tapscript caches start empty; this outlives them. Consumers only ever see clones. */
|
|
9851
|
+
tapscriptMemo = /* @__PURE__ */ new Map();
|
|
9805
9852
|
initialized = false;
|
|
9806
9853
|
eventCallbacks = /* @__PURE__ */ new Set();
|
|
9807
9854
|
stopWatcherFn;
|
|
@@ -9920,7 +9967,7 @@ var ContractManager = class _ContractManager {
|
|
|
9920
9967
|
try {
|
|
9921
9968
|
await this.scheduleLookAheadDrain();
|
|
9922
9969
|
} catch (err) {
|
|
9923
|
-
if (!
|
|
9970
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
9924
9971
|
this.lookAheadRefillOwed = true;
|
|
9925
9972
|
this.markSyncDegraded(err);
|
|
9926
9973
|
}
|
|
@@ -9928,7 +9975,7 @@ var ContractManager = class _ContractManager {
|
|
|
9928
9975
|
await this.reconcileWatched();
|
|
9929
9976
|
this.markSyncOnline();
|
|
9930
9977
|
} catch (err) {
|
|
9931
|
-
if (!
|
|
9978
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
9932
9979
|
this.markSyncDegraded(err);
|
|
9933
9980
|
}
|
|
9934
9981
|
this.initialized = true;
|
|
@@ -10060,7 +10107,7 @@ var ContractManager = class _ContractManager {
|
|
|
10060
10107
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
10061
10108
|
const to = watermark + lookAhead.size;
|
|
10062
10109
|
const deps = lookAhead.candidateDeps();
|
|
10063
|
-
const handlers =
|
|
10110
|
+
const handlers = chunkLUWSY2QO_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkLUWSY2QO_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
10064
10111
|
const band = /* @__PURE__ */ new Map();
|
|
10065
10112
|
for (let index = from; index <= to; index++) {
|
|
10066
10113
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -10071,7 +10118,7 @@ var ContractManager = class _ContractManager {
|
|
|
10071
10118
|
index,
|
|
10072
10119
|
params: {
|
|
10073
10120
|
...candidate,
|
|
10074
|
-
...
|
|
10121
|
+
...chunkLUWSY2QO_cjs.speculativeReceiveMetadata(descriptor)
|
|
10075
10122
|
}
|
|
10076
10123
|
});
|
|
10077
10124
|
}
|
|
@@ -10133,7 +10180,7 @@ var ContractManager = class _ContractManager {
|
|
|
10133
10180
|
});
|
|
10134
10181
|
for (const entry of pending) entry.catchUpPending = false;
|
|
10135
10182
|
} catch (err) {
|
|
10136
|
-
if (!
|
|
10183
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10137
10184
|
this.markSyncDegraded(err);
|
|
10138
10185
|
}
|
|
10139
10186
|
}
|
|
@@ -10183,7 +10230,7 @@ var ContractManager = class _ContractManager {
|
|
|
10183
10230
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
10184
10231
|
this.markSyncOnline();
|
|
10185
10232
|
} catch (err) {
|
|
10186
|
-
if (!
|
|
10233
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10187
10234
|
this.markSyncDegraded(err);
|
|
10188
10235
|
}
|
|
10189
10236
|
await this.watcher.addContract(contract);
|
|
@@ -10217,7 +10264,7 @@ var ContractManager = class _ContractManager {
|
|
|
10217
10264
|
await this.fetchContractVxosFromIndexer(fresh);
|
|
10218
10265
|
this.markSyncOnline();
|
|
10219
10266
|
} catch (err) {
|
|
10220
|
-
if (!
|
|
10267
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10221
10268
|
this.markSyncDegraded(err);
|
|
10222
10269
|
}
|
|
10223
10270
|
for (const contract of fresh) await this.watcher.addContract(contract);
|
|
@@ -10255,7 +10302,7 @@ var ContractManager = class _ContractManager {
|
|
|
10255
10302
|
return result;
|
|
10256
10303
|
}
|
|
10257
10304
|
async upsertContractRow(params) {
|
|
10258
|
-
const handler =
|
|
10305
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(params.type);
|
|
10259
10306
|
if (!handler) {
|
|
10260
10307
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
10261
10308
|
}
|
|
@@ -10355,7 +10402,7 @@ var ContractManager = class _ContractManager {
|
|
|
10355
10402
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
10356
10403
|
);
|
|
10357
10404
|
}
|
|
10358
|
-
const registered =
|
|
10405
|
+
const registered = chunkLUWSY2QO_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkLUWSY2QO_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
10359
10406
|
const discoverables = [
|
|
10360
10407
|
...registered.filter((h) => h.type === "boarding"),
|
|
10361
10408
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -10484,23 +10531,40 @@ var ContractManager = class _ContractManager {
|
|
|
10484
10531
|
const dbFilter = this.buildContractsDbFilter(filter ?? {});
|
|
10485
10532
|
return await this.config.contractRepository.getContracts(dbFilter);
|
|
10486
10533
|
}
|
|
10487
|
-
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
|
+
}
|
|
10488
10538
|
const contracts = await this.getContracts(filter);
|
|
10489
|
-
if (this.syncedWithin(
|
|
10539
|
+
if (this.syncedWithin(
|
|
10540
|
+
contracts,
|
|
10541
|
+
options?.maxSyncAgeMs ?? (options?.requireSynced ? 0 : this.config.vtxoSyncMaxAgeMs ?? 0)
|
|
10542
|
+
)) {
|
|
10490
10543
|
await this.demoteFundedAwaitingContracts(contracts);
|
|
10491
10544
|
} else {
|
|
10492
10545
|
try {
|
|
10493
10546
|
await this.syncContracts({ contracts, pageSize });
|
|
10494
10547
|
this.markSyncOnline();
|
|
10495
10548
|
} catch (err) {
|
|
10496
|
-
if (!
|
|
10549
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10497
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
|
+
}
|
|
10498
10556
|
}
|
|
10499
10557
|
}
|
|
10500
|
-
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
|
+
}
|
|
10501
10565
|
return contracts.map((contract) => ({
|
|
10502
10566
|
contract,
|
|
10503
|
-
vtxos:
|
|
10567
|
+
vtxos: vtxosByScript.get(contract.script)?.slice() ?? []
|
|
10504
10568
|
}));
|
|
10505
10569
|
}
|
|
10506
10570
|
async annotateVtxos(vtxos, tapscripts) {
|
|
@@ -10515,7 +10579,7 @@ var ContractManager = class _ContractManager {
|
|
|
10515
10579
|
}
|
|
10516
10580
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
10517
10581
|
return vtxos.map(
|
|
10518
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
10582
|
+
(vtxo) => extendVirtualCoinForContract(chunkCJN4CUEU_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
10519
10583
|
);
|
|
10520
10584
|
}
|
|
10521
10585
|
/** @inheritdoc */
|
|
@@ -10526,7 +10590,8 @@ var ContractManager = class _ContractManager {
|
|
|
10526
10590
|
});
|
|
10527
10591
|
const { scripts, failures } = annotatableIn(
|
|
10528
10592
|
new Map(contracts.map((contract) => [contract.script, contract])),
|
|
10529
|
-
vtxos
|
|
10593
|
+
vtxos,
|
|
10594
|
+
this.tapscriptMemo
|
|
10530
10595
|
);
|
|
10531
10596
|
const orphans = vtxos.filter(
|
|
10532
10597
|
(vtxo) => !scripts.has(vtxo.script) && !failures.has(vtxo.script)
|
|
@@ -10559,14 +10624,14 @@ var ContractManager = class _ContractManager {
|
|
|
10559
10624
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10560
10625
|
const asking = vtxos.filter((vtxo) => {
|
|
10561
10626
|
const contract = byScript.get(vtxo.script);
|
|
10562
|
-
return contract !== void 0 &&
|
|
10627
|
+
return contract !== void 0 && chunkLUWSY2QO_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10563
10628
|
});
|
|
10564
10629
|
if (asking.length === 0) return refused;
|
|
10565
10630
|
const tip = await this.currentChainTip();
|
|
10566
10631
|
const walletKey = await walletPubKey?.();
|
|
10567
10632
|
for (const vtxo of asking) {
|
|
10568
10633
|
const contract = byScript.get(vtxo.script);
|
|
10569
|
-
const handler =
|
|
10634
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10570
10635
|
if (!handler?.assertSpendableNow) continue;
|
|
10571
10636
|
const context = {
|
|
10572
10637
|
collaborative: true,
|
|
@@ -10581,7 +10646,7 @@ var ContractManager = class _ContractManager {
|
|
|
10581
10646
|
// the next handler to answer a CSV question would meet a
|
|
10582
10647
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
10583
10648
|
// really is one.
|
|
10584
|
-
vtxo:
|
|
10649
|
+
vtxo: chunkCJN4CUEU_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10585
10650
|
};
|
|
10586
10651
|
try {
|
|
10587
10652
|
await handler.assertSpendableNow(
|
|
@@ -10677,6 +10742,7 @@ var ContractManager = class _ContractManager {
|
|
|
10677
10742
|
*/
|
|
10678
10743
|
async deleteContract(script) {
|
|
10679
10744
|
await this.config.contractRepository.deleteContract(script);
|
|
10745
|
+
this.tapscriptMemo.delete(script);
|
|
10680
10746
|
await this.watcher.removeContract(script);
|
|
10681
10747
|
}
|
|
10682
10748
|
/**
|
|
@@ -10737,7 +10803,7 @@ var ContractManager = class _ContractManager {
|
|
|
10737
10803
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
10738
10804
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10739
10805
|
if (!contract) return [];
|
|
10740
|
-
const handler =
|
|
10806
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10741
10807
|
if (!handler) return [];
|
|
10742
10808
|
const script = handler.createScript(contract.params);
|
|
10743
10809
|
const tip = await this.currentChainTip();
|
|
@@ -10765,7 +10831,7 @@ var ContractManager = class _ContractManager {
|
|
|
10765
10831
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
10766
10832
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10767
10833
|
if (!contract) return [];
|
|
10768
|
-
const handler =
|
|
10834
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
10769
10835
|
if (!handler) return [];
|
|
10770
10836
|
const script = handler.createScript(contract.params);
|
|
10771
10837
|
const context = {
|
|
@@ -10821,7 +10887,7 @@ var ContractManager = class _ContractManager {
|
|
|
10821
10887
|
}
|
|
10822
10888
|
async refreshOutpoints(outpoints) {
|
|
10823
10889
|
if (outpoints.length === 0) return;
|
|
10824
|
-
const { vtxos } = await
|
|
10890
|
+
const { vtxos } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10825
10891
|
outpoints
|
|
10826
10892
|
});
|
|
10827
10893
|
if (vtxos.length === 0) return;
|
|
@@ -10923,25 +10989,33 @@ var ContractManager = class _ContractManager {
|
|
|
10923
10989
|
break;
|
|
10924
10990
|
}
|
|
10925
10991
|
} catch (err) {
|
|
10926
|
-
if (!
|
|
10992
|
+
if (!chunkCJN4CUEU_cjs.isRetryableProviderError(err)) throw err;
|
|
10927
10993
|
this.markSyncDegraded(err);
|
|
10928
10994
|
}
|
|
10929
10995
|
this.emitEvent(event);
|
|
10930
10996
|
}
|
|
10931
|
-
async getVtxosForContracts(contracts) {
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
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
|
+
)
|
|
10940
11013
|
)
|
|
10941
11014
|
)
|
|
10942
|
-
)
|
|
10943
|
-
|
|
10944
|
-
|
|
11015
|
+
);
|
|
11016
|
+
rows = res.flat();
|
|
11017
|
+
}
|
|
11018
|
+
return options?.unspentOnly ? rows.filter((vtxo) => !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) : rows;
|
|
10945
11019
|
}
|
|
10946
11020
|
/**
|
|
10947
11021
|
* Sync virtual outputs for the given contracts against the indexer.
|
|
@@ -11014,7 +11088,7 @@ var ContractManager = class _ContractManager {
|
|
|
11014
11088
|
*/
|
|
11015
11089
|
async reconcilePendingFrontier(contracts) {
|
|
11016
11090
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
11017
|
-
const vtxos = await
|
|
11091
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(
|
|
11018
11092
|
this.config.indexerProvider,
|
|
11019
11093
|
contracts.map((c) => c.script),
|
|
11020
11094
|
{ pendingOnly: true }
|
|
@@ -11022,7 +11096,11 @@ var ContractManager = class _ContractManager {
|
|
|
11022
11096
|
for (const [script, contract] of await this.promoteLookAheadHits(vtxos)) {
|
|
11023
11097
|
scriptToContract.set(script, contract);
|
|
11024
11098
|
}
|
|
11025
|
-
const {
|
|
11099
|
+
const {
|
|
11100
|
+
scripts: annotatable,
|
|
11101
|
+
cache,
|
|
11102
|
+
failures
|
|
11103
|
+
} = annotatableIn(scriptToContract, vtxos, this.tapscriptMemo);
|
|
11026
11104
|
this.recordAnnotationFailures(annotatable, failures);
|
|
11027
11105
|
const owned = vtxos.filter((v) => annotatable.has(v.script));
|
|
11028
11106
|
const annotated = await this.annotateVtxos(owned, cache);
|
|
@@ -11097,7 +11175,7 @@ var ContractManager = class _ContractManager {
|
|
|
11097
11175
|
}
|
|
11098
11176
|
return result;
|
|
11099
11177
|
}
|
|
11100
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
11178
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkCJN4CUEU_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
11101
11179
|
if (contracts.length === 0) {
|
|
11102
11180
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
11103
11181
|
}
|
|
@@ -11113,7 +11191,7 @@ var ContractManager = class _ContractManager {
|
|
|
11113
11191
|
before: syncWindow.before
|
|
11114
11192
|
}
|
|
11115
11193
|
} : {};
|
|
11116
|
-
const vtxos = await
|
|
11194
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(
|
|
11117
11195
|
this.config.indexerProvider,
|
|
11118
11196
|
contracts.map((c) => c.script),
|
|
11119
11197
|
{ ...windowOpts, pageSize }
|
|
@@ -11122,7 +11200,11 @@ var ContractManager = class _ContractManager {
|
|
|
11122
11200
|
for (const [script, contract] of promoted) {
|
|
11123
11201
|
scriptToContract.set(script, contract);
|
|
11124
11202
|
}
|
|
11125
|
-
const {
|
|
11203
|
+
const {
|
|
11204
|
+
scripts: annotatable,
|
|
11205
|
+
cache,
|
|
11206
|
+
failures
|
|
11207
|
+
} = annotatableIn(scriptToContract, vtxos, this.tapscriptMemo);
|
|
11126
11208
|
this.recordAnnotationFailures(annotatable, failures);
|
|
11127
11209
|
const owned = vtxos.filter((v) => annotatable.has(v.script));
|
|
11128
11210
|
const annotated = await this.annotateVtxos(owned, cache);
|
|
@@ -11258,7 +11340,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
11258
11340
|
const s = base.hex.decode(t.s);
|
|
11259
11341
|
return [cb, s];
|
|
11260
11342
|
};
|
|
11261
|
-
var deserializeVtxo = (o) =>
|
|
11343
|
+
var deserializeVtxo = (o) => chunkCJN4CUEU_cjs.normalizeVtxo({
|
|
11262
11344
|
...o,
|
|
11263
11345
|
createdAt: new Date(o.createdAt),
|
|
11264
11346
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11434,7 +11516,7 @@ var IndexedDBWalletRepository = class {
|
|
|
11434
11516
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
11435
11517
|
for (const vtxo of vtxos) {
|
|
11436
11518
|
const serialized = serializeVtxo(vtxo);
|
|
11437
|
-
store.put({ address, ...serialized });
|
|
11519
|
+
store.put({ address, ...serialized, ...unspentFlag(vtxo) });
|
|
11438
11520
|
}
|
|
11439
11521
|
await awaitTransaction(transaction);
|
|
11440
11522
|
} catch (error) {
|
|
@@ -11454,31 +11536,52 @@ var IndexedDBWalletRepository = class {
|
|
|
11454
11536
|
}
|
|
11455
11537
|
}
|
|
11456
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 [];
|
|
11457
11544
|
try {
|
|
11458
11545
|
const db = await this.getDB();
|
|
11459
|
-
const
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
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);
|
|
11464
11552
|
const byOutpoint = /* @__PURE__ */ new Map();
|
|
11465
|
-
for (const row of
|
|
11466
|
-
|
|
11467
|
-
const
|
|
11468
|
-
|
|
11469
|
-
|
|
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)) {
|
|
11470
11571
|
continue;
|
|
11471
11572
|
}
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
}
|
|
11573
|
+
const vtxo = deserializeVtxoWithBackfill(row);
|
|
11574
|
+
if (!options?.unspentOnly || !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) result.push(vtxo);
|
|
11475
11575
|
}
|
|
11476
|
-
return
|
|
11576
|
+
return result;
|
|
11477
11577
|
} catch (error) {
|
|
11478
|
-
console.error(
|
|
11578
|
+
console.error("Failed to get VTXOs for scripts:", error);
|
|
11479
11579
|
throw error;
|
|
11480
11580
|
}
|
|
11481
11581
|
}
|
|
11582
|
+
vtxoStore(db) {
|
|
11583
|
+
return db.transaction([STORE_VTXOS], "readonly").objectStore(STORE_VTXOS);
|
|
11584
|
+
}
|
|
11482
11585
|
async saveVtxosForScript(key, vtxos) {
|
|
11483
11586
|
if (!key.address) {
|
|
11484
11587
|
throw new Error("IndexedDBWalletRepository requires an address");
|
|
@@ -11609,7 +11712,7 @@ var IndexedDBWalletRepository = class {
|
|
|
11609
11712
|
return this.connection.get();
|
|
11610
11713
|
}
|
|
11611
11714
|
};
|
|
11612
|
-
function deserializeVtxoWithBackfill(o) {
|
|
11715
|
+
function deserializeVtxoWithBackfill({ unspent: _unspent, ...o }) {
|
|
11613
11716
|
if (!o.script) {
|
|
11614
11717
|
o = { ...o, script: scriptFromArkAddress(o.address) };
|
|
11615
11718
|
}
|
|
@@ -12081,7 +12184,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
12081
12184
|
*/
|
|
12082
12185
|
materializeDescriptorAt(index) {
|
|
12083
12186
|
const descriptor = this.identity.descriptor;
|
|
12084
|
-
const network =
|
|
12187
|
+
const network = chunkLUWSY2QO_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
12085
12188
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
12086
12189
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
12087
12190
|
if (!keyInfo?.keyExpression) {
|
|
@@ -12229,7 +12332,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12229
12332
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
12230
12333
|
if (!provider) return void 0;
|
|
12231
12334
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
12232
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
12335
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
12233
12336
|
const factoryOpts = {
|
|
12234
12337
|
walletRepository: setup.walletRepository,
|
|
12235
12338
|
contractRepository: setup.contractRepository,
|
|
@@ -12430,7 +12533,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12430
12533
|
};
|
|
12431
12534
|
function deriveLeafPubkey(descriptor) {
|
|
12432
12535
|
try {
|
|
12433
|
-
return
|
|
12536
|
+
return chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
12434
12537
|
} catch (e) {
|
|
12435
12538
|
throw new NonRangeableDescriptorError(
|
|
12436
12539
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -12442,7 +12545,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12442
12545
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
12443
12546
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
12444
12547
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
12445
|
-
const csvTimelock =
|
|
12548
|
+
const csvTimelock = chunkCJN4CUEU_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
12446
12549
|
const base$1 = {
|
|
12447
12550
|
script: base.hex.encode(tapscript.pkScript),
|
|
12448
12551
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -12453,11 +12556,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12453
12556
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
12454
12557
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
12455
12558
|
metadata: {
|
|
12456
|
-
...tagSource && { source:
|
|
12559
|
+
...tagSource && { source: chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE },
|
|
12457
12560
|
signingDescriptor: descriptor
|
|
12458
12561
|
}
|
|
12459
12562
|
};
|
|
12460
|
-
const params = tapscript instanceof
|
|
12563
|
+
const params = tapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? {
|
|
12461
12564
|
...base$1,
|
|
12462
12565
|
type: "delegate",
|
|
12463
12566
|
params: {
|
|
@@ -12478,10 +12581,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12478
12581
|
return { tapscript, params };
|
|
12479
12582
|
}
|
|
12480
12583
|
function rebuildTapscript(current, pubKey) {
|
|
12481
|
-
if (current instanceof
|
|
12482
|
-
return new
|
|
12584
|
+
if (current instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script) {
|
|
12585
|
+
return new chunkLUWSY2QO_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12483
12586
|
}
|
|
12484
|
-
return new
|
|
12587
|
+
return new chunkLUWSY2QO_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12485
12588
|
}
|
|
12486
12589
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12487
12590
|
const candidates = await contractRepository.getContracts({
|
|
@@ -12490,7 +12593,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
12490
12593
|
});
|
|
12491
12594
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
12492
12595
|
const matching = candidates.filter(
|
|
12493
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12596
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE
|
|
12494
12597
|
).sort((a, b) => {
|
|
12495
12598
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12496
12599
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12529,7 +12632,7 @@ async function resolveDescriptorProvider(config, walletRepository) {
|
|
|
12529
12632
|
|
|
12530
12633
|
// src/wallet/balance.ts
|
|
12531
12634
|
function computeOffchainBalance(vtxos, caps) {
|
|
12532
|
-
const { now, isPendingRecovery, isGenericallySpendable, isUnlocked } = caps;
|
|
12635
|
+
const { now, isPendingRecovery, isGenericallySpendable, isUnlocked, dustCarrier } = caps;
|
|
12533
12636
|
let settled = 0;
|
|
12534
12637
|
let preconfirmed = 0;
|
|
12535
12638
|
let available = 0;
|
|
@@ -12546,7 +12649,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12546
12649
|
}
|
|
12547
12650
|
};
|
|
12548
12651
|
for (const vtxo of vtxos) {
|
|
12549
|
-
if (
|
|
12652
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) continue;
|
|
12550
12653
|
addAssets(owned, vtxo);
|
|
12551
12654
|
if (vtxo.isUnrolled) {
|
|
12552
12655
|
unrolled += vtxo.value;
|
|
@@ -12556,11 +12659,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12556
12659
|
pendingRecovery += vtxo.value;
|
|
12557
12660
|
continue;
|
|
12558
12661
|
}
|
|
12559
|
-
if (
|
|
12662
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12560
12663
|
recoverable += vtxo.value;
|
|
12561
12664
|
continue;
|
|
12562
12665
|
}
|
|
12563
|
-
if (!
|
|
12666
|
+
if (!chunkCJN4CUEU_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12564
12667
|
if (vtxo.isPreconfirmed) {
|
|
12565
12668
|
preconfirmed += vtxo.value;
|
|
12566
12669
|
} else {
|
|
@@ -12575,6 +12678,9 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12575
12678
|
addAssets(spendable, vtxo);
|
|
12576
12679
|
}
|
|
12577
12680
|
}
|
|
12681
|
+
if (available > 0 && spendable.size > 0) {
|
|
12682
|
+
available = Math.max(0, available - Number(dustCarrier));
|
|
12683
|
+
}
|
|
12578
12684
|
const toAssets = (from) => Array.from(from.entries()).map(([assetId, amount]) => ({ assetId, amount }));
|
|
12579
12685
|
return {
|
|
12580
12686
|
settled,
|
|
@@ -12734,12 +12840,12 @@ var InputSignerRouter = class {
|
|
|
12734
12840
|
};
|
|
12735
12841
|
|
|
12736
12842
|
// src/wallet/wallet.ts
|
|
12737
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
12843
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkCJN4CUEU_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12738
12844
|
function intentProofJobs(coins) {
|
|
12739
12845
|
if (coins.length === 0) return [];
|
|
12740
12846
|
const coinJobs = coins.map((coin, i) => ({
|
|
12741
12847
|
index: i + 1,
|
|
12742
|
-
lookupScript:
|
|
12848
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12743
12849
|
}));
|
|
12744
12850
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12745
12851
|
}
|
|
@@ -12771,7 +12877,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12771
12877
|
const seen = /* @__PURE__ */ new Set();
|
|
12772
12878
|
const deduped = [];
|
|
12773
12879
|
for (const timelock of timelocks) {
|
|
12774
|
-
const sequence =
|
|
12880
|
+
const sequence = chunkCJN4CUEU_cjs.timelockToSequence(timelock).toString();
|
|
12775
12881
|
if (seen.has(sequence)) continue;
|
|
12776
12882
|
seen.add(sequence);
|
|
12777
12883
|
deduped.push(timelock);
|
|
@@ -12788,7 +12894,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12788
12894
|
state: "active"
|
|
12789
12895
|
});
|
|
12790
12896
|
const newest = candidates.filter(
|
|
12791
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12897
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE
|
|
12792
12898
|
).sort((a, b) => {
|
|
12793
12899
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12794
12900
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12796,7 +12902,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12796
12902
|
if (!newest?.params.pubKey) return baseline;
|
|
12797
12903
|
try {
|
|
12798
12904
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12799
|
-
return new
|
|
12905
|
+
return new chunkLUWSY2QO_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12800
12906
|
} catch (e) {
|
|
12801
12907
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12802
12908
|
return baseline;
|
|
@@ -12815,10 +12921,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12815
12921
|
if (vtxo.isUnrolled) {
|
|
12816
12922
|
return !!f.withUnrolled;
|
|
12817
12923
|
}
|
|
12818
|
-
if (
|
|
12924
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) {
|
|
12819
12925
|
return false;
|
|
12820
12926
|
}
|
|
12821
|
-
if (!f.withRecoverable &&
|
|
12927
|
+
if (!f.withRecoverable && chunkCJN4CUEU_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12822
12928
|
return false;
|
|
12823
12929
|
}
|
|
12824
12930
|
return true;
|
|
@@ -13158,7 +13264,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13158
13264
|
*/
|
|
13159
13265
|
static async setupWalletConfig(config, pubKey) {
|
|
13160
13266
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
13161
|
-
const arkProvider = config.arkProvider || new
|
|
13267
|
+
const arkProvider = config.arkProvider || new chunkCJN4CUEU_cjs.RestArkProvider(arkadeServerUrl);
|
|
13162
13268
|
let indexerProvider = config.indexerProvider;
|
|
13163
13269
|
if (!indexerProvider) {
|
|
13164
13270
|
let indexerUrl = config.indexerUrl;
|
|
@@ -13175,7 +13281,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13175
13281
|
indexerUrl = arkadeServerUrl;
|
|
13176
13282
|
}
|
|
13177
13283
|
}
|
|
13178
|
-
indexerProvider = new
|
|
13284
|
+
indexerProvider = new chunkH62OOAS4_cjs.RestIndexerProvider(indexerUrl);
|
|
13179
13285
|
}
|
|
13180
13286
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
13181
13287
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -13184,7 +13290,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13184
13290
|
source: serverInfoSource,
|
|
13185
13291
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
13186
13292
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
13187
|
-
const network =
|
|
13293
|
+
const network = chunkCJN4CUEU_cjs.getNetwork(info.network);
|
|
13188
13294
|
if ("descriptor" in config.identity) {
|
|
13189
13295
|
const descriptor = config.identity.descriptor;
|
|
13190
13296
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -13224,18 +13330,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13224
13330
|
value: info.boardingExitDelay,
|
|
13225
13331
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
13226
13332
|
};
|
|
13227
|
-
const serverPubKey =
|
|
13228
|
-
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;
|
|
13229
13335
|
const offchainOptions = {
|
|
13230
13336
|
pubKey,
|
|
13231
13337
|
serverPubKey,
|
|
13232
13338
|
csvTimelock: exitTimelock
|
|
13233
13339
|
};
|
|
13234
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
13235
|
-
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({
|
|
13236
13342
|
pubKey: base.hex.encode(pubKey),
|
|
13237
13343
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13238
|
-
csvTimelock:
|
|
13344
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingTimelock).toString()
|
|
13239
13345
|
});
|
|
13240
13346
|
return {
|
|
13241
13347
|
arkProvider,
|
|
@@ -13383,7 +13489,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13383
13489
|
}
|
|
13384
13490
|
/** @inheritdoc */
|
|
13385
13491
|
async getSpendableVtxos(filter) {
|
|
13386
|
-
const snapshot = await this.contractSnapshot(
|
|
13492
|
+
const snapshot = await this.contractSnapshot(filter, {
|
|
13493
|
+
unspentOnly: !filter?.withUnrolled
|
|
13494
|
+
});
|
|
13387
13495
|
const vtxos = filterSnapshotVtxos(snapshot, filter, this._pendingSpendOutpoints);
|
|
13388
13496
|
const { gated, pendingRecovery } = this.spendabilityView(snapshot);
|
|
13389
13497
|
const selectable = vtxos.filter(
|
|
@@ -13401,7 +13509,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13401
13509
|
if (!filter?.withUnrolled) {
|
|
13402
13510
|
logExcludedVtxos(
|
|
13403
13511
|
"getSpendableVtxos",
|
|
13404
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
13512
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)),
|
|
13405
13513
|
[() => UNROLLED_REASON]
|
|
13406
13514
|
);
|
|
13407
13515
|
}
|
|
@@ -13475,9 +13583,25 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13475
13583
|
* otherwise the gate and the pending-recovery set answer about two different
|
|
13476
13584
|
* points in time, and each read costs another sync.
|
|
13477
13585
|
*/
|
|
13478
|
-
async contractSnapshot() {
|
|
13586
|
+
async contractSnapshot(filter, options) {
|
|
13479
13587
|
const contractManager = await this.getContractManager();
|
|
13480
|
-
|
|
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
|
+
});
|
|
13481
13605
|
}
|
|
13482
13606
|
/**
|
|
13483
13607
|
* The two exclusion sets the gate is made of, derived from one snapshot so
|
|
@@ -13501,7 +13625,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13501
13625
|
now: { timestamp: /* @__PURE__ */ new Date() },
|
|
13502
13626
|
isPendingRecovery: (vtxo) => pendingRecovery.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
13503
13627
|
isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
|
|
13504
|
-
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
13628
|
+
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
13629
|
+
dustCarrier: getDustAmount(this)
|
|
13505
13630
|
};
|
|
13506
13631
|
}
|
|
13507
13632
|
/**
|
|
@@ -13545,7 +13670,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13545
13670
|
this.getBoardingTxs()
|
|
13546
13671
|
]);
|
|
13547
13672
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
13548
|
-
const resolveTxCreatedAt = (txids) =>
|
|
13673
|
+
const resolveTxCreatedAt = (txids) => chunkCJN4CUEU_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13549
13674
|
return buildTransactionHistory(
|
|
13550
13675
|
allVtxos,
|
|
13551
13676
|
boardingTxs,
|
|
@@ -13640,7 +13765,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13640
13765
|
},
|
|
13641
13766
|
isUnrolled: true,
|
|
13642
13767
|
...boardingFacts,
|
|
13643
|
-
virtualStatus:
|
|
13768
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(boardingFacts),
|
|
13644
13769
|
spentBy: "",
|
|
13645
13770
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
13646
13771
|
script: scriptHex
|
|
@@ -13696,9 +13821,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13696
13821
|
async getBoardingTapscripts(allowedSigners) {
|
|
13697
13822
|
const byScript = /* @__PURE__ */ new Map();
|
|
13698
13823
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
13699
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13824
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13700
13825
|
add(
|
|
13701
|
-
new
|
|
13826
|
+
new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
13702
13827
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
13703
13828
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
13704
13829
|
csvTimelock: boardingCsv
|
|
@@ -13713,7 +13838,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13713
13838
|
for (const c of boardingContracts) {
|
|
13714
13839
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
13715
13840
|
try {
|
|
13716
|
-
add(
|
|
13841
|
+
add(chunkLUWSY2QO_cjs.BoardingContractHandler.createScript(c.params));
|
|
13717
13842
|
} catch (e) {
|
|
13718
13843
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
13719
13844
|
}
|
|
@@ -13750,7 +13875,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13750
13875
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13751
13876
|
// not the wallet's current boarding timelock, which a signer
|
|
13752
13877
|
// rotation may have changed.
|
|
13753
|
-
csvTimelock:
|
|
13878
|
+
csvTimelock: chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13754
13879
|
coins: utxos
|
|
13755
13880
|
};
|
|
13756
13881
|
})
|
|
@@ -13887,7 +14012,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13887
14012
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13888
14013
|
async fetchPendingTxs() {
|
|
13889
14014
|
const scripts = await this.getWalletScripts();
|
|
13890
|
-
const vtxos = await
|
|
14015
|
+
const vtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13891
14016
|
return vtxos.filter(
|
|
13892
14017
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13893
14018
|
).map((_) => _.arkTxId);
|
|
@@ -13918,7 +14043,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13918
14043
|
});
|
|
13919
14044
|
for (const contract of contracts) {
|
|
13920
14045
|
if (map.has(contract.script)) continue;
|
|
13921
|
-
const handler =
|
|
14046
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
13922
14047
|
if (handler) {
|
|
13923
14048
|
const script = handler.createScript(contract.params);
|
|
13924
14049
|
map.set(contract.script, script);
|
|
@@ -14030,7 +14155,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14030
14155
|
}
|
|
14031
14156
|
});
|
|
14032
14157
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
14033
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14158
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14034
14159
|
const baselineSigners = [
|
|
14035
14160
|
this.offchainTapscript.options.serverPubKey,
|
|
14036
14161
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -14038,8 +14163,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14038
14163
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
14039
14164
|
for (const serverPubKey of baselineSigners) {
|
|
14040
14165
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
14041
|
-
const csvTimelockStr =
|
|
14042
|
-
const defaultScript = new
|
|
14166
|
+
const csvTimelockStr = chunkCJN4CUEU_cjs.timelockToSequence(csvTimelock).toString();
|
|
14167
|
+
const defaultScript = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14043
14168
|
pubKey: baselinePubkey,
|
|
14044
14169
|
serverPubKey,
|
|
14045
14170
|
csvTimelock
|
|
@@ -14060,7 +14185,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14060
14185
|
});
|
|
14061
14186
|
}
|
|
14062
14187
|
if (delegatePubKey) {
|
|
14063
|
-
const delegateScript = new
|
|
14188
|
+
const delegateScript = new chunkLUWSY2QO_cjs.DelegateVtxo.Script({
|
|
14064
14189
|
pubKey: baselinePubkey,
|
|
14065
14190
|
serverPubKey,
|
|
14066
14191
|
delegatePubKey,
|
|
@@ -14084,9 +14209,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14084
14209
|
}
|
|
14085
14210
|
}
|
|
14086
14211
|
}
|
|
14087
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
14212
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14088
14213
|
for (const serverPubKey of baselineSigners) {
|
|
14089
|
-
const baselineBoarding = new
|
|
14214
|
+
const baselineBoarding = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14090
14215
|
pubKey: baselinePubkey,
|
|
14091
14216
|
serverPubKey,
|
|
14092
14217
|
csvTimelock: boardingCsvTimelock
|
|
@@ -14099,7 +14224,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14099
14224
|
params: {
|
|
14100
14225
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14101
14226
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
14102
|
-
csvTimelock:
|
|
14227
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14103
14228
|
},
|
|
14104
14229
|
script: boardingScriptHex,
|
|
14105
14230
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -14299,7 +14424,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14299
14424
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
14300
14425
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
14301
14426
|
csvTimelocks: this.walletContractTimelocks,
|
|
14302
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
14427
|
+
delegatePubKey: this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
14303
14428
|
};
|
|
14304
14429
|
}
|
|
14305
14430
|
_signerRouter;
|
|
@@ -14544,7 +14669,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14544
14669
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14545
14670
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14546
14671
|
if (typeof persisted === "string") return persisted;
|
|
14547
|
-
return
|
|
14672
|
+
return chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14548
14673
|
}
|
|
14549
14674
|
/**
|
|
14550
14675
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -14560,7 +14685,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14560
14685
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14561
14686
|
if (type === "boarding") {
|
|
14562
14687
|
const built2 = this.buildBoardingContract(
|
|
14563
|
-
|
|
14688
|
+
chunkLUWSY2QO_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14564
14689
|
descriptor,
|
|
14565
14690
|
tagSource
|
|
14566
14691
|
);
|
|
@@ -14605,11 +14730,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14605
14730
|
* {@link buildReceiveContract}.
|
|
14606
14731
|
*/
|
|
14607
14732
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14608
|
-
const tapscript = new
|
|
14733
|
+
const tapscript = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14609
14734
|
...this._boardingTapscript.options,
|
|
14610
14735
|
pubKey
|
|
14611
14736
|
});
|
|
14612
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
14737
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14613
14738
|
return {
|
|
14614
14739
|
tapscript,
|
|
14615
14740
|
params: {
|
|
@@ -14617,13 +14742,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14617
14742
|
params: {
|
|
14618
14743
|
pubKey: base.hex.encode(pubKey),
|
|
14619
14744
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14620
|
-
csvTimelock:
|
|
14745
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(csvTimelock).toString()
|
|
14621
14746
|
},
|
|
14622
14747
|
script: base.hex.encode(tapscript.pkScript),
|
|
14623
14748
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14624
14749
|
state: "active",
|
|
14625
14750
|
metadata: {
|
|
14626
|
-
...tagSource && { source:
|
|
14751
|
+
...tagSource && { source: chunkLUWSY2QO_cjs.WALLET_RECEIVE_SOURCE },
|
|
14627
14752
|
signingDescriptor: descriptor
|
|
14628
14753
|
}
|
|
14629
14754
|
}
|
|
@@ -14652,7 +14777,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14652
14777
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
14653
14778
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14654
14779
|
}
|
|
14655
|
-
return
|
|
14780
|
+
return chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14656
14781
|
}
|
|
14657
14782
|
/**
|
|
14658
14783
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14748,7 +14873,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14748
14873
|
* the stable public API.
|
|
14749
14874
|
*/
|
|
14750
14875
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14751
|
-
const xonly =
|
|
14876
|
+
const xonly = chunkLUWSY2QO_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14752
14877
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14753
14878
|
checkpointTapscript,
|
|
14754
14879
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14777,21 +14902,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14777
14902
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14778
14903
|
script: currentBoardingScript
|
|
14779
14904
|
});
|
|
14780
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14905
|
+
const newOffchain = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? new chunkLUWSY2QO_cjs.DelegateVtxo.Script({
|
|
14781
14906
|
...this.offchainTapscript.options,
|
|
14782
14907
|
serverPubKey: xonly
|
|
14783
|
-
}) : new
|
|
14908
|
+
}) : new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14784
14909
|
...this.offchainTapscript.options,
|
|
14785
14910
|
serverPubKey: xonly
|
|
14786
14911
|
});
|
|
14787
|
-
const newBoarding = new
|
|
14912
|
+
const newBoarding = new chunkLUWSY2QO_cjs.DefaultVtxo.Script({
|
|
14788
14913
|
...this._boardingTapscript.options,
|
|
14789
14914
|
serverPubKey: xonly
|
|
14790
14915
|
});
|
|
14791
|
-
const offchainCsv =
|
|
14916
|
+
const offchainCsv = chunkCJN4CUEU_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14792
14917
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14793
14918
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14794
|
-
if (newOffchain instanceof
|
|
14919
|
+
if (newOffchain instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script) {
|
|
14795
14920
|
await manager.createContract({
|
|
14796
14921
|
type: "delegate",
|
|
14797
14922
|
params: {
|
|
@@ -14819,13 +14944,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14819
14944
|
metadata: currentOffchainRow?.metadata
|
|
14820
14945
|
});
|
|
14821
14946
|
}
|
|
14822
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14947
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14823
14948
|
await manager.createContract({
|
|
14824
14949
|
type: "boarding",
|
|
14825
14950
|
params: {
|
|
14826
14951
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14827
14952
|
serverPubKey: base.hex.encode(xonly),
|
|
14828
|
-
csvTimelock:
|
|
14953
|
+
csvTimelock: chunkCJN4CUEU_cjs.timelockToSequence(boardingCsv).toString()
|
|
14829
14954
|
},
|
|
14830
14955
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14831
14956
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14858,14 +14983,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14858
14983
|
_restoreInFlight;
|
|
14859
14984
|
_addPendingSpends(inputs) {
|
|
14860
14985
|
for (const input of inputs) {
|
|
14861
|
-
if (
|
|
14986
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
14862
14987
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14863
14988
|
}
|
|
14864
14989
|
}
|
|
14865
14990
|
}
|
|
14866
14991
|
_removePendingSpends(inputs) {
|
|
14867
14992
|
for (const input of inputs) {
|
|
14868
|
-
if (
|
|
14993
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
14869
14994
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14870
14995
|
}
|
|
14871
14996
|
}
|
|
@@ -14926,13 +15051,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14926
15051
|
const manager = await this.getContractManager();
|
|
14927
15052
|
const provider = this._descriptorProvider;
|
|
14928
15053
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14929
|
-
const staticDescriptor = hd ? void 0 : await
|
|
15054
|
+
const staticDescriptor = hd ? void 0 : await chunkLUWSY2QO_cjs.identityDescriptor(this.identity);
|
|
14930
15055
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14931
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
15056
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkLUWSY2QO_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14932
15057
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14933
|
-
const currentSignerPubKey =
|
|
15058
|
+
const currentSignerPubKey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14934
15059
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14935
|
-
(s) =>
|
|
15060
|
+
(s) => chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14936
15061
|
);
|
|
14937
15062
|
const deps = {
|
|
14938
15063
|
indexerProvider: this.indexerProvider,
|
|
@@ -14947,7 +15072,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14947
15072
|
csvTimelocks: this.walletContractTimelocks,
|
|
14948
15073
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14949
15074
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14950
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
15075
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkLUWSY2QO_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14951
15076
|
delegatePubKey
|
|
14952
15077
|
};
|
|
14953
15078
|
const result = await manager.scanContracts({
|
|
@@ -15061,7 +15186,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15061
15186
|
throw new Error("Invalid configured public key");
|
|
15062
15187
|
}
|
|
15063
15188
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
15064
|
-
const forfeitPubkey =
|
|
15189
|
+
const forfeitPubkey = chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
15065
15190
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
15066
15191
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
15067
15192
|
const checkpointExitDelayOverrides = {
|
|
@@ -15210,7 +15335,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15210
15335
|
inputs: params.selectedVtxos,
|
|
15211
15336
|
changeAmount: BigInt(changeAmount)
|
|
15212
15337
|
};
|
|
15213
|
-
const outputAddress =
|
|
15338
|
+
const outputAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(params.address);
|
|
15214
15339
|
assertRecipientArkAddress(
|
|
15215
15340
|
params.address,
|
|
15216
15341
|
outputAddress,
|
|
@@ -15276,13 +15401,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15276
15401
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
15277
15402
|
}
|
|
15278
15403
|
const offchainAddress = await this.getAddress();
|
|
15279
|
-
const offchainPkScript =
|
|
15404
|
+
const offchainPkScript = chunkCJN4CUEU_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
15280
15405
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
15281
15406
|
if (!params) {
|
|
15282
15407
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
15283
15408
|
const estimator = new Estimator(fees.intentFee);
|
|
15284
15409
|
let amount = 0;
|
|
15285
|
-
const exitScript =
|
|
15410
|
+
const exitScript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(
|
|
15286
15411
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
15287
15412
|
);
|
|
15288
15413
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -15305,13 +15430,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15305
15430
|
filteredBoardingUtxos.push(utxo);
|
|
15306
15431
|
amount += utxo.value - inputFee.satoshis;
|
|
15307
15432
|
}
|
|
15308
|
-
const vtxos = await this.getSpendableVtxos({
|
|
15433
|
+
const vtxos = await this.getSpendableVtxos({
|
|
15434
|
+
withRecoverable: true,
|
|
15435
|
+
genericallySpendableOnly: true
|
|
15436
|
+
});
|
|
15309
15437
|
const filteredVtxos = [];
|
|
15310
15438
|
for (const vtxo of byValueDescending(vtxos)) {
|
|
15311
15439
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
15312
15440
|
break;
|
|
15313
15441
|
}
|
|
15314
|
-
const inputFee = estimator.evalOffchainInput(
|
|
15442
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo));
|
|
15315
15443
|
if (inputFee.satoshis >= vtxo.value) {
|
|
15316
15444
|
continue;
|
|
15317
15445
|
}
|
|
@@ -15358,7 +15486,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15358
15486
|
let script;
|
|
15359
15487
|
let arkAddress;
|
|
15360
15488
|
try {
|
|
15361
|
-
arkAddress =
|
|
15489
|
+
arkAddress = chunkCJN4CUEU_cjs.ArkAddress.decode(output.address);
|
|
15362
15490
|
} catch {
|
|
15363
15491
|
arkAddress = void 0;
|
|
15364
15492
|
}
|
|
@@ -15448,7 +15576,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15448
15576
|
const abortController = new AbortController();
|
|
15449
15577
|
let stream;
|
|
15450
15578
|
let committedTxid;
|
|
15451
|
-
const settleInputVtxos = params.inputs.filter(
|
|
15579
|
+
const settleInputVtxos = params.inputs.filter(chunkCJN4CUEU_cjs.isVirtualCoin);
|
|
15452
15580
|
const contractManager = await this.getContractManager();
|
|
15453
15581
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15454
15582
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15560,7 +15688,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15560
15688
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15561
15689
|
if (!this._descriptorProvider) return;
|
|
15562
15690
|
const consumedBoarding = inputs.some(
|
|
15563
|
-
(input) => typeof input !== "string" && !
|
|
15691
|
+
(input) => typeof input !== "string" && !chunkCJN4CUEU_cjs.isVirtualCoin(input)
|
|
15564
15692
|
);
|
|
15565
15693
|
if (!consumedBoarding) return;
|
|
15566
15694
|
try {
|
|
@@ -15584,7 +15712,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15584
15712
|
let connectorIndex = 0;
|
|
15585
15713
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15586
15714
|
for (const input of inputs) {
|
|
15587
|
-
if (!
|
|
15715
|
+
if (!chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
15588
15716
|
let matched = false;
|
|
15589
15717
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15590
15718
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -15622,7 +15750,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15622
15750
|
}
|
|
15623
15751
|
continue;
|
|
15624
15752
|
}
|
|
15625
|
-
if (
|
|
15753
|
+
if (chunkCJN4CUEU_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15626
15754
|
continue;
|
|
15627
15755
|
}
|
|
15628
15756
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15650,7 +15778,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15650
15778
|
index: input.vout,
|
|
15651
15779
|
witnessUtxo: {
|
|
15652
15780
|
amount: BigInt(input.value),
|
|
15653
|
-
script:
|
|
15781
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15654
15782
|
},
|
|
15655
15783
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15656
15784
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15669,7 +15797,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15669
15797
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15670
15798
|
{
|
|
15671
15799
|
index: 0,
|
|
15672
|
-
lookupScript:
|
|
15800
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15673
15801
|
}
|
|
15674
15802
|
]);
|
|
15675
15803
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15727,7 +15855,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15727
15855
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15728
15856
|
);
|
|
15729
15857
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15730
|
-
const sweepTapscript =
|
|
15858
|
+
const sweepTapscript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
15731
15859
|
timelock,
|
|
15732
15860
|
pubkeys: [this.forfeitPubkey]
|
|
15733
15861
|
}).script;
|
|
@@ -15742,10 +15870,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15742
15870
|
throw new Error("Sweep tap tree root not set");
|
|
15743
15871
|
}
|
|
15744
15872
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15745
|
-
(k) => base.hex.encode(
|
|
15873
|
+
(k) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15746
15874
|
);
|
|
15747
15875
|
const signerPublicKey = await session.getPublicKey();
|
|
15748
|
-
const xonlySignerPublicKey =
|
|
15876
|
+
const xonlySignerPublicKey = chunkLUWSY2QO_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15749
15877
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15750
15878
|
return { skip: true };
|
|
15751
15879
|
}
|
|
@@ -15835,9 +15963,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15835
15963
|
...existing ?? {},
|
|
15836
15964
|
intentTxId,
|
|
15837
15965
|
registerProof: intent.proof,
|
|
15838
|
-
registerProofMessage:
|
|
15966
|
+
registerProofMessage: chunkCJN4CUEU_cjs.Intent.encodeMessage(intent.message),
|
|
15839
15967
|
deleteProof: deleteIntent.proof,
|
|
15840
|
-
deleteProofMessage:
|
|
15968
|
+
deleteProofMessage: chunkCJN4CUEU_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15841
15969
|
intentVtxos: inputs.map((i) => ({
|
|
15842
15970
|
txid: i.txid,
|
|
15843
15971
|
vout: i.vout
|
|
@@ -15870,7 +15998,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15870
15998
|
try {
|
|
15871
15999
|
return await this.arkProvider.registerIntent(intent);
|
|
15872
16000
|
} catch (error) {
|
|
15873
|
-
if (error instanceof
|
|
16001
|
+
if (error instanceof chunkCJN4CUEU_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15874
16002
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15875
16003
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15876
16004
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15886,7 +16014,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15886
16014
|
expire_at: 0,
|
|
15887
16015
|
cosigners_public_keys: cosignerPubKeys
|
|
15888
16016
|
};
|
|
15889
|
-
const proof =
|
|
16017
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, outputs);
|
|
15890
16018
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15891
16019
|
return {
|
|
15892
16020
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15898,7 +16026,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15898
16026
|
type: "delete",
|
|
15899
16027
|
expire_at: 0
|
|
15900
16028
|
};
|
|
15901
|
-
const proof =
|
|
16029
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, []);
|
|
15902
16030
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15903
16031
|
return {
|
|
15904
16032
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15910,7 +16038,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15910
16038
|
type: "get-pending-tx",
|
|
15911
16039
|
expire_at: 0
|
|
15912
16040
|
};
|
|
15913
|
-
const proof =
|
|
16041
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, coins, []);
|
|
15914
16042
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15915
16043
|
return {
|
|
15916
16044
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15931,7 +16059,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15931
16059
|
if (!vtxos || vtxos.length === 0) {
|
|
15932
16060
|
const scriptMap = await this.getScriptMap();
|
|
15933
16061
|
const allExtended = [];
|
|
15934
|
-
const fetchedVtxos = await
|
|
16062
|
+
const fetchedVtxos = await chunkCJN4CUEU_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15935
16063
|
...scriptMap.keys()
|
|
15936
16064
|
]);
|
|
15937
16065
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -15975,7 +16103,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15975
16103
|
try {
|
|
15976
16104
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
15977
16105
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
15978
|
-
|
|
16106
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(tx);
|
|
15979
16107
|
return tx;
|
|
15980
16108
|
});
|
|
15981
16109
|
assertCheckpointsMatchInputs(
|
|
@@ -16047,11 +16175,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16047
16175
|
* against the current key alone would leave it pending forever.
|
|
16048
16176
|
*/
|
|
16049
16177
|
checkpointUnrollCandidates(info) {
|
|
16050
|
-
const current =
|
|
16178
|
+
const current = chunkCJN4CUEU_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
16051
16179
|
const candidates = [this._serverUnrollScript, current];
|
|
16052
16180
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
16053
16181
|
candidates.push(
|
|
16054
|
-
|
|
16182
|
+
chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
16055
16183
|
...current.params,
|
|
16056
16184
|
pubkeys: [base.hex.decode(deprecated)]
|
|
16057
16185
|
})
|
|
@@ -16142,7 +16270,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16142
16270
|
if (vtxos.length === 0) {
|
|
16143
16271
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
16144
16272
|
}
|
|
16145
|
-
const myPkScript =
|
|
16273
|
+
const myPkScript = chunkCJN4CUEU_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
16146
16274
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
16147
16275
|
let swept = 0;
|
|
16148
16276
|
const drainable = vtxos.filter(
|
|
@@ -16218,7 +16346,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16218
16346
|
const spendable = [];
|
|
16219
16347
|
const unclaimed = [];
|
|
16220
16348
|
for (const vtxo of vtxos) {
|
|
16221
|
-
if (
|
|
16349
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(vtxo)) {
|
|
16222
16350
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
16223
16351
|
} else if (vtxo.isUnrolled) {
|
|
16224
16352
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -16240,7 +16368,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16240
16368
|
const all = [];
|
|
16241
16369
|
const seen = /* @__PURE__ */ new Set();
|
|
16242
16370
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
16243
|
-
const { vtxos, page } = await
|
|
16371
|
+
const { vtxos, page } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
16244
16372
|
scripts,
|
|
16245
16373
|
pageIndex,
|
|
16246
16374
|
pageSize
|
|
@@ -16287,7 +16415,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16287
16415
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
16288
16416
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
16289
16417
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
16290
|
-
const proof =
|
|
16418
|
+
const proof = chunkCJN4CUEU_cjs.Intent.create(message, batch, []);
|
|
16291
16419
|
const signedProof = await identity.sign(
|
|
16292
16420
|
proof,
|
|
16293
16421
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -16309,7 +16437,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16309
16437
|
try {
|
|
16310
16438
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
16311
16439
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
16312
|
-
|
|
16440
|
+
chunkCJN4CUEU_cjs.assertAllowedSighashTypes(tx);
|
|
16313
16441
|
return tx;
|
|
16314
16442
|
});
|
|
16315
16443
|
assertCheckpointsMatchInputs(
|
|
@@ -16409,7 +16537,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16409
16537
|
let virtualCoins = [];
|
|
16410
16538
|
if (!selectedVtxos) {
|
|
16411
16539
|
virtualCoins = await this.getSpendableVtxos({
|
|
16412
|
-
withRecoverable: false
|
|
16540
|
+
withRecoverable: false,
|
|
16541
|
+
genericallySpendableOnly: true
|
|
16413
16542
|
});
|
|
16414
16543
|
}
|
|
16415
16544
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -16441,6 +16570,15 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16441
16570
|
}
|
|
16442
16571
|
}
|
|
16443
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();
|
|
16444
16582
|
for (const recipient of recipients) {
|
|
16445
16583
|
if (!recipient.assets) {
|
|
16446
16584
|
continue;
|
|
@@ -16459,8 +16597,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16459
16597
|
amountToSelect -= existingChange;
|
|
16460
16598
|
assetChanges.delete(receiverAsset.assetId);
|
|
16461
16599
|
}
|
|
16462
|
-
const availableCoins =
|
|
16463
|
-
(
|
|
16600
|
+
const availableCoins = (coinsByAsset.get(receiverAsset.assetId) ?? []).filter(
|
|
16601
|
+
(coin) => !selectedOutpoints2.has(vtxoOutpoint(coin))
|
|
16464
16602
|
);
|
|
16465
16603
|
const { selected, totalAssetAmount } = selectCoinsWithAsset(
|
|
16466
16604
|
availableCoins,
|
|
@@ -16469,6 +16607,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16469
16607
|
);
|
|
16470
16608
|
for (const coin of selected) {
|
|
16471
16609
|
selectedCoins.push(coin);
|
|
16610
|
+
selectedOutpoints2.add(vtxoOutpoint(coin));
|
|
16472
16611
|
btcAmountToSelect -= coin.value;
|
|
16473
16612
|
if (coin.assets) {
|
|
16474
16613
|
for (const a of coin.assets) {
|
|
@@ -16489,7 +16628,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16489
16628
|
}
|
|
16490
16629
|
if (btcAmountToSelect > 0) {
|
|
16491
16630
|
const availableCoins = virtualCoins.filter(
|
|
16492
|
-
(
|
|
16631
|
+
(coin) => !selectedOutpoints2.has(vtxoOutpoint(coin))
|
|
16493
16632
|
);
|
|
16494
16633
|
const { inputs: btcCoins } = selectVirtualCoins(availableCoins, btcAmountToSelect);
|
|
16495
16634
|
for (const coin of btcCoins) {
|
|
@@ -16501,6 +16640,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16501
16640
|
}
|
|
16502
16641
|
}
|
|
16503
16642
|
selectedCoins = [...selectedCoins, ...btcCoins];
|
|
16643
|
+
for (const coin of btcCoins) selectedOutpoints2.add(vtxoOutpoint(coin));
|
|
16504
16644
|
}
|
|
16505
16645
|
}
|
|
16506
16646
|
let totalBtcSelected = selectedCoins.reduce((sum, c) => sum + c.value, 0);
|
|
@@ -16508,7 +16648,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16508
16648
|
script: recipient.script,
|
|
16509
16649
|
amount: BigInt(recipient.amount),
|
|
16510
16650
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16511
|
-
...recipient.tapTree ? { tapTree:
|
|
16651
|
+
...recipient.tapTree ? { tapTree: chunkCJN4CUEU_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
16512
16652
|
}));
|
|
16513
16653
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16514
16654
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -16517,19 +16657,58 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16517
16657
|
`send({ selectedVtxos }): inputs total ${totalBtcSelected} sats, outputs need ${totalBtcOutput}`
|
|
16518
16658
|
);
|
|
16519
16659
|
}
|
|
16520
|
-
if (assetChanges.size > 0 && changeAmount < Number(this.dustAmount)) {
|
|
16521
|
-
|
|
16522
|
-
|
|
16523
|
-
|
|
16524
|
-
|
|
16525
|
-
|
|
16526
|
-
|
|
16527
|
-
|
|
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`
|
|
16528
16669
|
);
|
|
16529
|
-
|
|
16530
|
-
|
|
16531
|
-
|
|
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))
|
|
16532
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
|
+
}
|
|
16533
16712
|
for (const coin of extraCoins) {
|
|
16534
16713
|
if (coin.assets) {
|
|
16535
16714
|
for (const asset of coin.assets) {
|
|
@@ -16539,6 +16718,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16539
16718
|
}
|
|
16540
16719
|
}
|
|
16541
16720
|
selectedCoins = [...selectedCoins, ...extraCoins];
|
|
16721
|
+
for (const coin of extraCoins) selectedOutpoints.add(vtxoOutpoint(coin));
|
|
16542
16722
|
totalBtcSelected += extraCoins.reduce((sum, c) => sum + c.value, 0);
|
|
16543
16723
|
changeAmount = totalBtcSelected - totalBtcOutput;
|
|
16544
16724
|
}
|
|
@@ -16652,10 +16832,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16652
16832
|
const serverPubKey = this.arkServerPublicKey;
|
|
16653
16833
|
const serverUnrollScript = this.serverUnrollScript;
|
|
16654
16834
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
16655
|
-
const normalizedInputs = inputs.map(
|
|
16656
|
-
const at = now ?? await
|
|
16835
|
+
const normalizedInputs = inputs.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
16836
|
+
const at = now ?? await chunkCJN4CUEU_cjs.resolveTimeHeight(this.onchainProvider);
|
|
16657
16837
|
for (const input of normalizedInputs) {
|
|
16658
|
-
if (!
|
|
16838
|
+
if (!chunkCJN4CUEU_cjs.canSpendOffchain(input, at)) {
|
|
16659
16839
|
throw new Error(
|
|
16660
16840
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
16661
16841
|
);
|
|
@@ -16725,7 +16905,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16725
16905
|
);
|
|
16726
16906
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
16727
16907
|
index,
|
|
16728
|
-
lookupScript:
|
|
16908
|
+
lookupScript: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
16729
16909
|
}));
|
|
16730
16910
|
const identity = this.identity;
|
|
16731
16911
|
const signer = {
|
|
@@ -16826,14 +17006,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16826
17006
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16827
17007
|
spentVtxos.push({
|
|
16828
17008
|
...spentFacts,
|
|
16829
|
-
virtualStatus:
|
|
17009
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(spentFacts),
|
|
16830
17010
|
...spentBy ? { spentBy } : {},
|
|
16831
17011
|
arkTxId: arkTxid
|
|
16832
17012
|
});
|
|
16833
17013
|
for (const id of vtxo.commitmentTxIds) {
|
|
16834
17014
|
commitmentTxIds.add(id);
|
|
16835
17015
|
}
|
|
16836
|
-
const vtxoExpiry =
|
|
17016
|
+
const vtxoExpiry = chunkCJN4CUEU_cjs.toBatchExpiry(vtxo);
|
|
16837
17017
|
if (vtxoExpiry) {
|
|
16838
17018
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16839
17019
|
}
|
|
@@ -16846,7 +17026,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16846
17026
|
isSwept: false,
|
|
16847
17027
|
isPreconfirmed: true,
|
|
16848
17028
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16849
|
-
...
|
|
17029
|
+
...chunkCJN4CUEU_cjs.parseLegacyExpiry(batchExpiry)
|
|
16850
17030
|
};
|
|
16851
17031
|
changeVtxo = {
|
|
16852
17032
|
txid: arkTxid,
|
|
@@ -16858,7 +17038,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16858
17038
|
tapTree: offchainTapscript.encode(),
|
|
16859
17039
|
value: Number(changeAmount),
|
|
16860
17040
|
...changeFacts,
|
|
16861
|
-
virtualStatus:
|
|
17041
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(changeFacts),
|
|
16862
17042
|
spentBy: "",
|
|
16863
17043
|
status: {
|
|
16864
17044
|
confirmed: false
|
|
@@ -16927,12 +17107,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16927
17107
|
const spentVtxos = [];
|
|
16928
17108
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16929
17109
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16930
|
-
const vtxoInputs = inputs.filter(
|
|
17110
|
+
const vtxoInputs = inputs.filter(chunkCJN4CUEU_cjs.isVirtualCoin);
|
|
16931
17111
|
const cm = await this.getContractManager();
|
|
16932
17112
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16933
17113
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16934
17114
|
for (const input of inputs) {
|
|
16935
|
-
if (
|
|
17115
|
+
if (chunkCJN4CUEU_cjs.isVirtualCoin(input)) {
|
|
16936
17116
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16937
17117
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16938
17118
|
if (!vtxo) {
|
|
@@ -16944,13 +17124,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16944
17124
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16945
17125
|
spentVtxos.push({
|
|
16946
17126
|
...settledFacts,
|
|
16947
|
-
virtualStatus:
|
|
17127
|
+
virtualStatus: chunkCJN4CUEU_cjs.toVirtualStatus(settledFacts),
|
|
16948
17128
|
settledBy: commitmentTxid
|
|
16949
17129
|
});
|
|
16950
17130
|
} else {
|
|
16951
17131
|
let sourceAddress;
|
|
16952
17132
|
try {
|
|
16953
|
-
sourceAddress =
|
|
17133
|
+
sourceAddress = chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16954
17134
|
this.network
|
|
16955
17135
|
);
|
|
16956
17136
|
} catch {
|
|
@@ -17008,9 +17188,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
17008
17188
|
}
|
|
17009
17189
|
};
|
|
17010
17190
|
function selectVirtualCoins(coins, targetAmount) {
|
|
17011
|
-
const sortedCoins = coins.map(
|
|
17012
|
-
const expiryA =
|
|
17013
|
-
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;
|
|
17014
17194
|
if (expiryA !== expiryB) {
|
|
17015
17195
|
return expiryA - expiryB;
|
|
17016
17196
|
}
|
|
@@ -17379,7 +17559,7 @@ var MessageBus = class {
|
|
|
17379
17559
|
this.initialized = true;
|
|
17380
17560
|
}
|
|
17381
17561
|
async buildServices(config) {
|
|
17382
|
-
const arkProvider = new
|
|
17562
|
+
const arkProvider = new chunkCJN4CUEU_cjs.RestArkProvider(config.arkServer.url);
|
|
17383
17563
|
const storage = {
|
|
17384
17564
|
walletRepository: this.walletRepository,
|
|
17385
17565
|
contractRepository: this.contractRepository,
|
|
@@ -17733,7 +17913,7 @@ var offboardNetworkNames = [
|
|
|
17733
17913
|
function offboardDestinationScript(destinationAddress) {
|
|
17734
17914
|
for (const networkName of offboardNetworkNames) {
|
|
17735
17915
|
try {
|
|
17736
|
-
const network =
|
|
17916
|
+
const network = chunkCJN4CUEU_cjs.networks[networkName];
|
|
17737
17917
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
17738
17918
|
return btcSigner.OutScript.encode(addr);
|
|
17739
17919
|
} catch {
|
|
@@ -17769,7 +17949,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
|
17769
17949
|
const inputs = [];
|
|
17770
17950
|
let subtotal = 0n;
|
|
17771
17951
|
for (const vtxo of vtxos) {
|
|
17772
|
-
const inputFee = estimator.evalOffchainInput(
|
|
17952
|
+
const inputFee = estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo));
|
|
17773
17953
|
if (inputFee.satoshis >= vtxo.value) {
|
|
17774
17954
|
if (named) {
|
|
17775
17955
|
throw new Error(
|
|
@@ -17866,7 +18046,7 @@ var Ramps = class {
|
|
|
17866
18046
|
}
|
|
17867
18047
|
amount = amount ?? totalAmount;
|
|
17868
18048
|
const offchainAddress = await this.wallet.getAddress();
|
|
17869
|
-
const offchainAddr =
|
|
18049
|
+
const offchainAddr = chunkCJN4CUEU_cjs.ArkAddress.decode(offchainAddress);
|
|
17870
18050
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
17871
18051
|
const outputFee = estimator.evalOffchainOutput({
|
|
17872
18052
|
amount,
|
|
@@ -17925,7 +18105,8 @@ var Ramps = class {
|
|
|
17925
18105
|
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17926
18106
|
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17927
18107
|
withRecoverable: true,
|
|
17928
|
-
withUnrolled: false
|
|
18108
|
+
withUnrolled: false,
|
|
18109
|
+
genericallySpendableOnly: true
|
|
17929
18110
|
});
|
|
17930
18111
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17931
18112
|
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
@@ -17967,7 +18148,8 @@ var Ramps = class {
|
|
|
17967
18148
|
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17968
18149
|
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17969
18150
|
withRecoverable: true,
|
|
17970
|
-
withUnrolled: false
|
|
18151
|
+
withUnrolled: false,
|
|
18152
|
+
genericallySpendableOnly: true
|
|
17971
18153
|
});
|
|
17972
18154
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17973
18155
|
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
@@ -17993,7 +18175,7 @@ var Ramps = class {
|
|
|
17993
18175
|
async fundChange(left, estimator) {
|
|
17994
18176
|
if (left <= 0n) return { change: 0n };
|
|
17995
18177
|
const changeAddress = await this.wallet.getAddress();
|
|
17996
|
-
const changeScript = base.hex.encode(
|
|
18178
|
+
const changeScript = base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
17997
18179
|
const { change } = changeAfterOutputFee(
|
|
17998
18180
|
left,
|
|
17999
18181
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script: changeScript }).satoshis)
|
|
@@ -18354,7 +18536,7 @@ var WalletMessageHandler = class {
|
|
|
18354
18536
|
return this.tagged({
|
|
18355
18537
|
id,
|
|
18356
18538
|
type: "SPENDABLE_VTXOS",
|
|
18357
|
-
payload: { vtxos }
|
|
18539
|
+
payload: { vtxos, filterApplied: true }
|
|
18358
18540
|
});
|
|
18359
18541
|
}
|
|
18360
18542
|
case "GET_BOARDING_UTXOS": {
|
|
@@ -18435,11 +18617,15 @@ var WalletMessageHandler = class {
|
|
|
18435
18617
|
}
|
|
18436
18618
|
case "GET_CONTRACTS_WITH_VTXOS": {
|
|
18437
18619
|
const manager = await this.readonlyWallet.getContractManager();
|
|
18438
|
-
const contracts = await manager.getContractsWithVtxos(
|
|
18620
|
+
const contracts = await manager.getContractsWithVtxos(
|
|
18621
|
+
message.payload.filter,
|
|
18622
|
+
void 0,
|
|
18623
|
+
message.payload.options
|
|
18624
|
+
);
|
|
18439
18625
|
return this.tagged({
|
|
18440
18626
|
id,
|
|
18441
18627
|
type: "CONTRACTS_WITH_VTXOS",
|
|
18442
|
-
payload: { contracts }
|
|
18628
|
+
payload: { contracts, filterApplied: true }
|
|
18443
18629
|
});
|
|
18444
18630
|
}
|
|
18445
18631
|
case "WATCH_SCRIPT": {
|
|
@@ -18822,7 +19008,7 @@ var WalletMessageHandler = class {
|
|
|
18822
19008
|
// Wallet methods
|
|
18823
19009
|
async handleInitWallet({ payload }) {
|
|
18824
19010
|
const { arkServerUrl } = payload;
|
|
18825
|
-
this.indexerProvider = new
|
|
19011
|
+
this.indexerProvider = new chunkH62OOAS4_cjs.RestIndexerProvider(arkServerUrl);
|
|
18826
19012
|
await this.onWalletInitialized();
|
|
18827
19013
|
}
|
|
18828
19014
|
/**
|
|
@@ -18857,7 +19043,8 @@ var WalletMessageHandler = class {
|
|
|
18857
19043
|
now: { timestamp: /* @__PURE__ */ new Date() },
|
|
18858
19044
|
isPendingRecovery: (vtxo) => pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
18859
19045
|
isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
|
|
18860
|
-
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
19046
|
+
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
19047
|
+
dustCarrier: getDustAmount(this.readonlyWallet)
|
|
18861
19048
|
});
|
|
18862
19049
|
return {
|
|
18863
19050
|
boarding: {
|
|
@@ -19110,7 +19297,7 @@ var WalletMessageHandler = class {
|
|
|
19110
19297
|
if (v.isUnrolled) {
|
|
19111
19298
|
return withUnrolled;
|
|
19112
19299
|
}
|
|
19113
|
-
if (
|
|
19300
|
+
if (chunkCJN4CUEU_cjs.isVtxoSpent(v)) {
|
|
19114
19301
|
return false;
|
|
19115
19302
|
}
|
|
19116
19303
|
if (includeRecoverable) {
|
|
@@ -19119,10 +19306,10 @@ var WalletMessageHandler = class {
|
|
|
19119
19306
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
19120
19307
|
return false;
|
|
19121
19308
|
}
|
|
19122
|
-
if (
|
|
19309
|
+
if (chunkCJN4CUEU_cjs.isRecoverable(v)) {
|
|
19123
19310
|
return false;
|
|
19124
19311
|
}
|
|
19125
|
-
if (
|
|
19312
|
+
if (chunkCJN4CUEU_cjs.isExpired(v)) {
|
|
19126
19313
|
return false;
|
|
19127
19314
|
}
|
|
19128
19315
|
return true;
|
|
@@ -19230,7 +19417,7 @@ var WalletMessageHandler = class {
|
|
|
19230
19417
|
this.readonlyWallet.getBoardingTxs()
|
|
19231
19418
|
]);
|
|
19232
19419
|
const indexerProvider = this.indexerProvider;
|
|
19233
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
19420
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkCJN4CUEU_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
19234
19421
|
return buildTransactionHistory(
|
|
19235
19422
|
vtxos,
|
|
19236
19423
|
boardingTxs,
|
|
@@ -19938,7 +20125,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19938
20125
|
};
|
|
19939
20126
|
try {
|
|
19940
20127
|
const response = await this.sendMessage(message);
|
|
19941
|
-
return response.payload.vtxos.map(
|
|
20128
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
19942
20129
|
} catch (error) {
|
|
19943
20130
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
19944
20131
|
}
|
|
@@ -19963,7 +20150,13 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19963
20150
|
};
|
|
19964
20151
|
try {
|
|
19965
20152
|
const response = await this.sendMessage(message);
|
|
19966
|
-
|
|
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);
|
|
19967
20160
|
} catch (error) {
|
|
19968
20161
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
19969
20162
|
}
|
|
@@ -20048,15 +20241,20 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20048
20241
|
throw new Error("Failed to get contracts");
|
|
20049
20242
|
}
|
|
20050
20243
|
},
|
|
20051
|
-
async getContractsWithVtxos(filter) {
|
|
20244
|
+
async getContractsWithVtxos(filter, _pageSize, options) {
|
|
20052
20245
|
const message = {
|
|
20053
20246
|
type: "GET_CONTRACTS_WITH_VTXOS",
|
|
20054
20247
|
id: getRandomId(),
|
|
20055
20248
|
tag: messageTag,
|
|
20056
|
-
payload: { filter }
|
|
20249
|
+
payload: { filter, options }
|
|
20057
20250
|
};
|
|
20058
20251
|
try {
|
|
20059
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
|
+
}
|
|
20060
20258
|
await refreshSyncState();
|
|
20061
20259
|
return response.payload.contracts;
|
|
20062
20260
|
} catch (e) {
|
|
@@ -20134,7 +20332,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20134
20332
|
};
|
|
20135
20333
|
try {
|
|
20136
20334
|
const response = await sendContractMessage(message);
|
|
20137
|
-
return response.payload.vtxos.map(
|
|
20335
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
20138
20336
|
} catch (e) {
|
|
20139
20337
|
throw new Error("Failed to annotate vtxos");
|
|
20140
20338
|
}
|
|
@@ -20746,7 +20944,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20746
20944
|
};
|
|
20747
20945
|
try {
|
|
20748
20946
|
const response = await wallet.sendMessage(message);
|
|
20749
|
-
return response.payload.vtxos.map(
|
|
20947
|
+
return response.payload.vtxos.map(chunkCJN4CUEU_cjs.normalizeVtxo);
|
|
20750
20948
|
} catch (e) {
|
|
20751
20949
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
20752
20950
|
}
|
|
@@ -20858,12 +21056,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20858
21056
|
* @returns Configured onchain wallet
|
|
20859
21057
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
20860
21058
|
*/
|
|
20861
|
-
static async create(identity, networkName =
|
|
21059
|
+
static async create(identity, networkName = chunkCJN4CUEU_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
20862
21060
|
const pubkey = await identity.xOnlyPublicKey();
|
|
20863
21061
|
if (!pubkey) {
|
|
20864
21062
|
throw new Error("Invalid configured public key");
|
|
20865
21063
|
}
|
|
20866
|
-
const network =
|
|
21064
|
+
const network = chunkCJN4CUEU_cjs.getNetwork(networkName);
|
|
20867
21065
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
20868
21066
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
20869
21067
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -20969,7 +21167,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20969
21167
|
if (!inputs) {
|
|
20970
21168
|
throw new Error("Fee estimation failed");
|
|
20971
21169
|
}
|
|
20972
|
-
let tx = new
|
|
21170
|
+
let tx = new chunkCJN4CUEU_cjs.Transaction();
|
|
20973
21171
|
for (const input of inputs) {
|
|
20974
21172
|
tx.addInput({
|
|
20975
21173
|
txid: input.txid,
|
|
@@ -21027,7 +21225,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21027
21225
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
21028
21226
|
*/
|
|
21029
21227
|
async bumpAnchor(parentHex, feeRate) {
|
|
21030
|
-
const parent =
|
|
21228
|
+
const parent = chunkCJN4CUEU_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
21031
21229
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
21032
21230
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
21033
21231
|
return [parent.hex, child.hex];
|
|
@@ -21934,7 +22132,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21934
22132
|
try {
|
|
21935
22133
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
21936
22134
|
for (const psbt of txs) {
|
|
21937
|
-
const tx =
|
|
22135
|
+
const tx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
21938
22136
|
resolved.set(tx.id, tx.toBytes());
|
|
21939
22137
|
}
|
|
21940
22138
|
} catch (err) {
|
|
@@ -21967,7 +22165,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21967
22165
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
21968
22166
|
const pending = [];
|
|
21969
22167
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21970
|
-
if (
|
|
22168
|
+
if (chunkCJN4CUEU_cjs.getArkPsbtFields(tx, i, chunkCJN4CUEU_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
21971
22169
|
}
|
|
21972
22170
|
if (pending.length === 0) return;
|
|
21973
22171
|
const resolved = await resolvePrevTxs(
|
|
@@ -21976,13 +22174,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
21976
22174
|
onchain
|
|
21977
22175
|
);
|
|
21978
22176
|
for (const i of pending) {
|
|
21979
|
-
|
|
22177
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(tx, i, chunkCJN4CUEU_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
21980
22178
|
}
|
|
21981
22179
|
}
|
|
21982
22180
|
async function attachPrevoutTxs(tx, source) {
|
|
21983
22181
|
const pending = [];
|
|
21984
22182
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21985
|
-
if (
|
|
22183
|
+
if (chunkCJN4CUEU_cjs.getArkPsbtFields(tx, i, chunkCJN4CUEU_cjs.PrevoutTxField).length > 0) continue;
|
|
21986
22184
|
const input = tx.getInput(i);
|
|
21987
22185
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
21988
22186
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -21993,7 +22191,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
21993
22191
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
21994
22192
|
}
|
|
21995
22193
|
for (const { index, txid } of pending) {
|
|
21996
|
-
|
|
22194
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(tx, index, chunkCJN4CUEU_cjs.PrevoutTxField, resolved.get(txid));
|
|
21997
22195
|
}
|
|
21998
22196
|
}
|
|
21999
22197
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -22019,7 +22217,7 @@ exports.BIP322 = void 0;
|
|
|
22019
22217
|
async function sign2(message, identity, network) {
|
|
22020
22218
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
22021
22219
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
22022
|
-
const toSpend =
|
|
22220
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
22023
22221
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
22024
22222
|
const signed = await identity.sign(toSign, [0]);
|
|
22025
22223
|
signed.finalizeIdx(0);
|
|
@@ -22077,7 +22275,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
22077
22275
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
22078
22276
|
return false;
|
|
22079
22277
|
}
|
|
22080
|
-
const toSpend =
|
|
22278
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22081
22279
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
22082
22280
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
22083
22281
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -22098,7 +22296,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
22098
22296
|
}
|
|
22099
22297
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
22100
22298
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
22101
|
-
const toSpend =
|
|
22299
|
+
const toSpend = chunkCJN4CUEU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22102
22300
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
22103
22301
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
22104
22302
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -22151,7 +22349,7 @@ function encodeCompactSize(n) {
|
|
|
22151
22349
|
return buf;
|
|
22152
22350
|
}
|
|
22153
22351
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
22154
|
-
const tx = new
|
|
22352
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 0 });
|
|
22155
22353
|
tx.addInput({
|
|
22156
22354
|
txid: toSpend.id,
|
|
22157
22355
|
index: 0,
|
|
@@ -22165,12 +22363,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
22165
22363
|
});
|
|
22166
22364
|
tx.addOutput({
|
|
22167
22365
|
amount: 0n,
|
|
22168
|
-
script:
|
|
22366
|
+
script: chunkCJN4CUEU_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22169
22367
|
});
|
|
22170
22368
|
return tx;
|
|
22171
22369
|
}
|
|
22172
22370
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
22173
|
-
const tx = new
|
|
22371
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 0 });
|
|
22174
22372
|
tx.addInput({
|
|
22175
22373
|
txid: toSpend.id,
|
|
22176
22374
|
index: 0,
|
|
@@ -22182,7 +22380,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
22182
22380
|
});
|
|
22183
22381
|
tx.addOutput({
|
|
22184
22382
|
amount: 0n,
|
|
22185
|
-
script:
|
|
22383
|
+
script: chunkCJN4CUEU_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22186
22384
|
});
|
|
22187
22385
|
return tx;
|
|
22188
22386
|
}
|
|
@@ -22195,7 +22393,7 @@ var RestEmulatorProvider = class {
|
|
|
22195
22393
|
serverUrl;
|
|
22196
22394
|
async getInfo() {
|
|
22197
22395
|
const url = `${this.serverUrl}/v1/info`;
|
|
22198
|
-
const response = await
|
|
22396
|
+
const response = await chunkCJN4CUEU_cjs.baseFetch(url);
|
|
22199
22397
|
if (!response.ok) {
|
|
22200
22398
|
const errorText2 = await response.text();
|
|
22201
22399
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -22313,7 +22511,7 @@ var RestEmulatorProvider = class {
|
|
|
22313
22511
|
}
|
|
22314
22512
|
};
|
|
22315
22513
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
22316
|
-
const tx =
|
|
22514
|
+
const tx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
22317
22515
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
22318
22516
|
const input = tx.getInput(0);
|
|
22319
22517
|
if (!input) {
|
|
@@ -22340,14 +22538,14 @@ var ExitPathError = class extends Error {
|
|
|
22340
22538
|
reason;
|
|
22341
22539
|
};
|
|
22342
22540
|
function delayWeight(sequence) {
|
|
22343
|
-
const t =
|
|
22541
|
+
const t = chunkCJN4CUEU_cjs.sequenceToTimelock(sequence);
|
|
22344
22542
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
22345
22543
|
}
|
|
22346
22544
|
async function resolveUnilateralPath(params) {
|
|
22347
22545
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
22348
22546
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
22349
22547
|
if (contract) {
|
|
22350
|
-
const handler =
|
|
22548
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
22351
22549
|
if (!handler) {
|
|
22352
22550
|
throw new ExitPathError(
|
|
22353
22551
|
"no-handler",
|
|
@@ -22370,12 +22568,12 @@ async function resolveUnilateralPath(params) {
|
|
|
22370
22568
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
22371
22569
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
22372
22570
|
}
|
|
22373
|
-
const decoded =
|
|
22571
|
+
const decoded = chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
22374
22572
|
let best;
|
|
22375
22573
|
for (const exit of decoded.exitPaths()) {
|
|
22376
22574
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
22377
22575
|
if (!leaf) continue;
|
|
22378
|
-
const sequence =
|
|
22576
|
+
const sequence = chunkCJN4CUEU_cjs.timelockToSequence(exit.params.timelock);
|
|
22379
22577
|
const weight = delayWeight(sequence);
|
|
22380
22578
|
if (!best || weight < best.weight) {
|
|
22381
22579
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -22595,7 +22793,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22595
22793
|
let totalAmount = 0n;
|
|
22596
22794
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
22597
22795
|
for (const vtxo of vtxos) {
|
|
22598
|
-
if (!
|
|
22796
|
+
if (!chunkCJN4CUEU_cjs.canSweepOnchain(vtxo)) {
|
|
22599
22797
|
throw new Error(
|
|
22600
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`
|
|
22601
22799
|
);
|
|
@@ -22606,14 +22804,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22606
22804
|
}
|
|
22607
22805
|
const resolved = await resolveUnilateralPath({
|
|
22608
22806
|
vtxo,
|
|
22609
|
-
scriptHex: base.hex.encode(
|
|
22807
|
+
scriptHex: base.hex.encode(chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22610
22808
|
contractRepository: wallet.contractRepository,
|
|
22611
22809
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
22612
22810
|
currentTime: Date.now()
|
|
22613
22811
|
});
|
|
22614
22812
|
const spendingLeaf = resolved.selection.leaf;
|
|
22615
22813
|
const sequence = resolved.selection.sequence;
|
|
22616
|
-
const timelock =
|
|
22814
|
+
const timelock = chunkCJN4CUEU_cjs.sequenceToTimelock(sequence);
|
|
22617
22815
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
22618
22816
|
if (!elapsed) {
|
|
22619
22817
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -22626,7 +22824,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22626
22824
|
sequence,
|
|
22627
22825
|
witnessUtxo: {
|
|
22628
22826
|
amount: BigInt(vtxo.value),
|
|
22629
|
-
script:
|
|
22827
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
22630
22828
|
},
|
|
22631
22829
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22632
22830
|
});
|
|
@@ -22636,7 +22834,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22636
22834
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
22637
22835
|
);
|
|
22638
22836
|
}
|
|
22639
|
-
const tx = new
|
|
22837
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
22640
22838
|
for (const input of inputs) {
|
|
22641
22839
|
tx.addInput(input);
|
|
22642
22840
|
}
|
|
@@ -22719,7 +22917,7 @@ async function buildSignedSweep(params) {
|
|
|
22719
22917
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
22720
22918
|
);
|
|
22721
22919
|
}
|
|
22722
|
-
const tx = new
|
|
22920
|
+
const tx = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
22723
22921
|
tx.addInput({
|
|
22724
22922
|
txid: vtxo.txid,
|
|
22725
22923
|
index: vtxo.vout,
|
|
@@ -22744,7 +22942,7 @@ async function buildSignedSweep(params) {
|
|
|
22744
22942
|
finalScriptWitness: [
|
|
22745
22943
|
tapScriptSig[0][1],
|
|
22746
22944
|
...path.extraWitness,
|
|
22747
|
-
|
|
22945
|
+
chunkCJN4CUEU_cjs.scriptFromTapLeafScript(path.leaf),
|
|
22748
22946
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
22749
22947
|
]
|
|
22750
22948
|
});
|
|
@@ -22774,7 +22972,7 @@ async function resolveFeeRate(opts) {
|
|
|
22774
22972
|
}
|
|
22775
22973
|
async function selectExitVtxos(opts) {
|
|
22776
22974
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
22777
|
-
const res = await
|
|
22975
|
+
const res = await chunkCJN4CUEU_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
22778
22976
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
22779
22977
|
const out = [];
|
|
22780
22978
|
for (const vtxo of res.vtxos) {
|
|
@@ -22789,7 +22987,7 @@ async function selectExitVtxos(opts) {
|
|
|
22789
22987
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
22790
22988
|
);
|
|
22791
22989
|
}
|
|
22792
|
-
const handler =
|
|
22990
|
+
const handler = chunkLUWSY2QO_cjs.contractHandlers.get(contract.type);
|
|
22793
22991
|
if (!handler) {
|
|
22794
22992
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
22795
22993
|
}
|
|
@@ -22819,7 +23017,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22819
23017
|
if (pendingNodes.length > 0) {
|
|
22820
23018
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
22821
23019
|
for (const psbt of txs) {
|
|
22822
|
-
psbts.set(
|
|
23020
|
+
psbts.set(chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
22823
23021
|
}
|
|
22824
23022
|
}
|
|
22825
23023
|
const childVsize = Number(
|
|
@@ -22855,7 +23053,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22855
23053
|
try {
|
|
22856
23054
|
const resolved = await resolveUnilateralPath({
|
|
22857
23055
|
vtxo,
|
|
22858
|
-
scriptHex: base.hex.encode(
|
|
23056
|
+
scriptHex: base.hex.encode(chunkCJN4CUEU_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22859
23057
|
contractRepository: wallet.contractRepository,
|
|
22860
23058
|
walletPubKeyHex,
|
|
22861
23059
|
currentTime: Date.now()
|
|
@@ -22874,7 +23072,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22874
23072
|
});
|
|
22875
23073
|
continue;
|
|
22876
23074
|
}
|
|
22877
|
-
const t =
|
|
23075
|
+
const t = chunkCJN4CUEU_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
22878
23076
|
const delay = { type: t.type, value: Number(t.value) };
|
|
22879
23077
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
22880
23078
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -23275,7 +23473,7 @@ async function prepare(opts) {
|
|
|
23275
23473
|
txid: sweep.vtxo.txid,
|
|
23276
23474
|
vout: sweep.vtxo.vout,
|
|
23277
23475
|
value: sweep.vtxo.value,
|
|
23278
|
-
pkScript:
|
|
23476
|
+
pkScript: chunkCJN4CUEU_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
23279
23477
|
},
|
|
23280
23478
|
path: sweep.resolved.selection,
|
|
23281
23479
|
outputAddress: opts.sweepAddress,
|
|
@@ -23364,7 +23562,7 @@ async function prepare(opts) {
|
|
|
23364
23562
|
if (newFee <= splitterFee) break;
|
|
23365
23563
|
splitterFee = newFee;
|
|
23366
23564
|
}
|
|
23367
|
-
const splitter = new
|
|
23565
|
+
const splitter = new chunkCJN4CUEU_cjs.Transaction({ version: 2 });
|
|
23368
23566
|
for (const coin of selected.inputs) {
|
|
23369
23567
|
splitter.addInput({
|
|
23370
23568
|
txid: coin.txid,
|
|
@@ -23508,41 +23706,43 @@ var UnilateralExit = {
|
|
|
23508
23706
|
// src/arkade/index.ts
|
|
23509
23707
|
var arkade_exports = {};
|
|
23510
23708
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
23511
|
-
ARKADE_OP: () =>
|
|
23512
|
-
ARKADE_OPCODES: () =>
|
|
23513
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
23514
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
23515
|
-
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,
|
|
23516
23714
|
Arkade: () => Arkade,
|
|
23517
23715
|
ArkadeContract: () => ArkadeContract,
|
|
23518
|
-
ArkadeProgramScript: () =>
|
|
23519
|
-
ArkadeScript: () =>
|
|
23716
|
+
ArkadeProgramScript: () => chunkLUWSY2QO_cjs.ArkadeProgramScript,
|
|
23717
|
+
ArkadeScript: () => chunkLUWSY2QO_cjs.ArkadeScript,
|
|
23520
23718
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
23521
|
-
BigNum: () =>
|
|
23719
|
+
BigNum: () => chunkLUWSY2QO_cjs.bignum_exports,
|
|
23522
23720
|
OP: () => btcSigner.OP,
|
|
23523
|
-
OPCODE_NAMES: () =>
|
|
23524
|
-
OPCODE_VALUES: () =>
|
|
23525
|
-
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,
|
|
23526
23724
|
Script: () => btcSigner.Script,
|
|
23527
|
-
arkadeScriptHash: () =>
|
|
23528
|
-
arkadeWitnessHash: () =>
|
|
23529
|
-
asmToBytes: () =>
|
|
23530
|
-
bytesToASM: () =>
|
|
23531
|
-
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,
|
|
23532
23730
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
23533
|
-
deserializeArkadeContractParams: () =>
|
|
23534
|
-
fromASM: () =>
|
|
23535
|
-
getOpcodeName: () =>
|
|
23536
|
-
getOpcodeValue: () =>
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23543
|
-
|
|
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
|
|
23544
23744
|
});
|
|
23545
|
-
var isVtxoCoin = (input) =>
|
|
23745
|
+
var isVtxoCoin = (input) => chunkCJN4CUEU_cjs.isVirtualCoin(input);
|
|
23546
23746
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
23547
23747
|
let batchId;
|
|
23548
23748
|
let sweepTapTreeRoot;
|
|
@@ -23563,23 +23763,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23563
23763
|
);
|
|
23564
23764
|
await arkProvider.confirmRegistration(intentId);
|
|
23565
23765
|
batchId = event.id;
|
|
23566
|
-
const sweepTapscript =
|
|
23766
|
+
const sweepTapscript = chunkCJN4CUEU_cjs.CSVMultisigTapscript.encode({
|
|
23567
23767
|
timelock,
|
|
23568
|
-
pubkeys: [
|
|
23768
|
+
pubkeys: [chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
23569
23769
|
}).script;
|
|
23570
23770
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
23571
23771
|
return { skip: false };
|
|
23572
23772
|
},
|
|
23573
23773
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
23574
23774
|
const signerPubKey = await session.getPublicKey();
|
|
23575
|
-
const xonlySignerPubKey =
|
|
23775
|
+
const xonlySignerPubKey = chunkLUWSY2QO_cjs.toXOnly(signerPubKey, "signer key");
|
|
23576
23776
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
23577
|
-
(k) => base.hex.encode(
|
|
23777
|
+
(k) => base.hex.encode(chunkLUWSY2QO_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
23578
23778
|
);
|
|
23579
23779
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
23580
23780
|
return { skip: true };
|
|
23581
23781
|
}
|
|
23582
|
-
const commitmentTx =
|
|
23782
|
+
const commitmentTx = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
23583
23783
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
23584
23784
|
if (recipients && recipients.length > 0) {
|
|
23585
23785
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -23617,7 +23817,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23617
23817
|
if (connectorTree) {
|
|
23618
23818
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
23619
23819
|
}
|
|
23620
|
-
let commitmentPsbt =
|
|
23820
|
+
let commitmentPsbt = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
23621
23821
|
assertFinalCommitmentMatchesValidated(
|
|
23622
23822
|
commitmentPsbt,
|
|
23623
23823
|
validatedCommitmentTxid,
|
|
@@ -23659,7 +23859,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23659
23859
|
boardingIndices.push(boardingIdx);
|
|
23660
23860
|
continue;
|
|
23661
23861
|
}
|
|
23662
|
-
if (
|
|
23862
|
+
if (chunkCJN4CUEU_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
23663
23863
|
continue;
|
|
23664
23864
|
}
|
|
23665
23865
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -23680,7 +23880,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23680
23880
|
index: input.vout,
|
|
23681
23881
|
witnessUtxo: {
|
|
23682
23882
|
amount: BigInt(input.value),
|
|
23683
|
-
script:
|
|
23883
|
+
script: chunkCJN4CUEU_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
23684
23884
|
},
|
|
23685
23885
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
23686
23886
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -23732,6 +23932,263 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23732
23932
|
}
|
|
23733
23933
|
};
|
|
23734
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
|
+
}
|
|
23735
24192
|
var Arkade = class _Arkade {
|
|
23736
24193
|
arkProvider;
|
|
23737
24194
|
/** The co-signing service, or undefined for emulator-less (pure tapscript) usage. */
|
|
@@ -23771,16 +24228,16 @@ var Arkade = class _Arkade {
|
|
|
23771
24228
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
23772
24229
|
static async connect(opts) {
|
|
23773
24230
|
const info = await opts.arkade.getInfo();
|
|
23774
|
-
const serverKey =
|
|
23775
|
-
const checkpoint =
|
|
23776
|
-
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);
|
|
23777
24234
|
let emulatorKey;
|
|
23778
24235
|
if (opts.emulator) {
|
|
23779
|
-
emulatorKey = base.hex.decode(
|
|
24236
|
+
emulatorKey = base.hex.decode(chunkCJN4CUEU_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
23780
24237
|
}
|
|
23781
24238
|
let userKey;
|
|
23782
24239
|
if (opts.identity) {
|
|
23783
|
-
userKey =
|
|
24240
|
+
userKey = chunkLUWSY2QO_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
23784
24241
|
}
|
|
23785
24242
|
return new _Arkade({
|
|
23786
24243
|
arkProvider: opts.arkade,
|
|
@@ -23806,7 +24263,7 @@ var Arkade = class _Arkade {
|
|
|
23806
24263
|
* key respectively; explicit args always win.
|
|
23807
24264
|
*/
|
|
23808
24265
|
contract(program, args = {}) {
|
|
23809
|
-
const declared = (program.params ?? []).map(
|
|
24266
|
+
const declared = (program.params ?? []).map(chunkLUWSY2QO_cjs.inputName);
|
|
23810
24267
|
if (declared.includes("server") && args.server === void 0) {
|
|
23811
24268
|
args = { ...args, server: this.serverKey };
|
|
23812
24269
|
}
|
|
@@ -23826,7 +24283,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23826
24283
|
userKey: client.userKey,
|
|
23827
24284
|
emulatorKey: client.emulatorKey
|
|
23828
24285
|
};
|
|
23829
|
-
this.vtxoScript = new
|
|
24286
|
+
this.vtxoScript = new chunkLUWSY2QO_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
23830
24287
|
this.tapTree = this.vtxoScript.encode();
|
|
23831
24288
|
this.compiled = this.vtxoScript.compiled;
|
|
23832
24289
|
}
|
|
@@ -23854,7 +24311,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23854
24311
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
23855
24312
|
);
|
|
23856
24313
|
}
|
|
23857
|
-
const typed =
|
|
24314
|
+
const typed = chunkLUWSY2QO_cjs.deserializeArkadeContractParams(contract.params);
|
|
23858
24315
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
23859
24316
|
serverKey: typed.serverKey,
|
|
23860
24317
|
userKey: typed.userKey,
|
|
@@ -23895,7 +24352,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23895
24352
|
toContractParams() {
|
|
23896
24353
|
return {
|
|
23897
24354
|
type: "arkade",
|
|
23898
|
-
params:
|
|
24355
|
+
params: chunkLUWSY2QO_cjs.serializeArkadeContractParams({
|
|
23899
24356
|
program: this.program,
|
|
23900
24357
|
args: this.args,
|
|
23901
24358
|
serverKey: this.keys.serverKey,
|
|
@@ -23944,19 +24401,17 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23944
24401
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
23945
24402
|
if (registered) {
|
|
23946
24403
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
23947
|
-
return (withVtxos?.vtxos ?? []).filter(
|
|
23948
|
-
(v) => !chunkJ5EX3OMM_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
23949
|
-
);
|
|
24404
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
23950
24405
|
}
|
|
23951
24406
|
}
|
|
23952
24407
|
if (!this.client.indexer) {
|
|
23953
24408
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
23954
24409
|
}
|
|
23955
|
-
const { vtxos } = await
|
|
24410
|
+
const { vtxos } = await chunkCJN4CUEU_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
23956
24411
|
scripts: [scriptHex],
|
|
23957
24412
|
spendableOnly: true
|
|
23958
24413
|
});
|
|
23959
|
-
return vtxos.filter((v) => !
|
|
24414
|
+
return vtxos.filter((v) => !chunkCJN4CUEU_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
23960
24415
|
}
|
|
23961
24416
|
/** Total spendable balance (requires an indexer). */
|
|
23962
24417
|
async getBalance() {
|
|
@@ -24054,7 +24509,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
24054
24509
|
this.contract.client.checkpoint
|
|
24055
24510
|
);
|
|
24056
24511
|
if (coin.sourceTx) {
|
|
24057
|
-
|
|
24512
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(arkTx, 0, chunkCJN4CUEU_cjs.PrevArkTxField, coin.sourceTx);
|
|
24058
24513
|
}
|
|
24059
24514
|
if (this.fn.arkadeScript) {
|
|
24060
24515
|
const indexer = this.contract.client.indexer;
|
|
@@ -24071,8 +24526,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
24071
24526
|
}
|
|
24072
24527
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
24073
24528
|
if (condition.length > 0) {
|
|
24074
|
-
|
|
24075
|
-
|
|
24529
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(arkTx, 0, chunkCJN4CUEU_cjs.ConditionWitness, condition);
|
|
24530
|
+
chunkCJN4CUEU_cjs.setArkPsbtField(checkpoints[0], 0, chunkCJN4CUEU_cjs.ConditionWitness, condition);
|
|
24076
24531
|
}
|
|
24077
24532
|
const packets = [];
|
|
24078
24533
|
if (this.assetSpecs.length > 0) {
|
|
@@ -24111,7 +24566,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
24111
24566
|
base.base64.encode(signedArk2.toPSBT()),
|
|
24112
24567
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
24113
24568
|
);
|
|
24114
|
-
const txid =
|
|
24569
|
+
const txid = chunkCJN4CUEU_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
24115
24570
|
return {
|
|
24116
24571
|
txid,
|
|
24117
24572
|
signedArkTx: res2.signedArkTx,
|
|
@@ -24170,23 +24625,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
24170
24625
|
}
|
|
24171
24626
|
buildAssetPacket() {
|
|
24172
24627
|
const groups = this.assetSpecs.map((s) => {
|
|
24173
|
-
const id = typeof s.assetId === "string" ?
|
|
24174
|
-
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(
|
|
24175
24630
|
id,
|
|
24176
24631
|
null,
|
|
24177
|
-
s.inputs.map((i) =>
|
|
24178
|
-
s.outputs.map((o) =>
|
|
24179
|
-
(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))
|
|
24180
24635
|
);
|
|
24181
24636
|
});
|
|
24182
|
-
return
|
|
24637
|
+
return chunkH62OOAS4_cjs.Packet.create(groups);
|
|
24183
24638
|
}
|
|
24184
24639
|
witnessBytes(ref) {
|
|
24185
|
-
return
|
|
24640
|
+
return chunkLUWSY2QO_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
24186
24641
|
}
|
|
24187
24642
|
};
|
|
24188
24643
|
function bindInputs(fn, callArgs) {
|
|
24189
|
-
const names = (fn.def.inputs ?? []).map(
|
|
24644
|
+
const names = (fn.def.inputs ?? []).map(chunkLUWSY2QO_cjs.inputName);
|
|
24190
24645
|
if (callArgs.length !== names.length) {
|
|
24191
24646
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
24192
24647
|
}
|
|
@@ -24221,6 +24676,7 @@ var BIP21Error = /* @__PURE__ */ ((BIP21Error2) => {
|
|
|
24221
24676
|
BIP21Error2["INVALID_ADDRESS"] = "Invalid address";
|
|
24222
24677
|
return BIP21Error2;
|
|
24223
24678
|
})(BIP21Error || {});
|
|
24679
|
+
var formatAmount = (btc) => btc.toFixed(8).replace(/\.?0+$/, "");
|
|
24224
24680
|
var BIP21 = class _BIP21 {
|
|
24225
24681
|
/**
|
|
24226
24682
|
* Create a BIP21 URI from the provided parameters.
|
|
@@ -24242,7 +24698,7 @@ var BIP21 = class _BIP21 {
|
|
|
24242
24698
|
if (amount < 0) {
|
|
24243
24699
|
continue;
|
|
24244
24700
|
}
|
|
24245
|
-
queryParams[key] =
|
|
24701
|
+
queryParams[key] = formatAmount(amount);
|
|
24246
24702
|
} else if (key === "ark") {
|
|
24247
24703
|
if (typeof value === "string" && (value.startsWith("ark") || value.startsWith("tark"))) {
|
|
24248
24704
|
queryParams[key] = value;
|
|
@@ -24598,17 +25054,17 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
|
|
|
24598
25054
|
function offchainInputFees(vtxos, fees) {
|
|
24599
25055
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24600
25056
|
return vtxos.reduce(
|
|
24601
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
25057
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
24602
25058
|
0
|
|
24603
25059
|
);
|
|
24604
25060
|
}
|
|
24605
25061
|
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
24606
25062
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24607
25063
|
const net = inputs.reduce(
|
|
24608
|
-
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(
|
|
25064
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkCJN4CUEU_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
24609
25065
|
0n
|
|
24610
25066
|
);
|
|
24611
|
-
const script = base.hex.encode(
|
|
25067
|
+
const script = base.hex.encode(chunkCJN4CUEU_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
24612
25068
|
return changeAfterOutputFee(
|
|
24613
25069
|
net - needed,
|
|
24614
25070
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script }).satoshis)
|
|
@@ -24699,7 +25155,6 @@ exports.ConnectionDisposedError = ConnectionDisposedError;
|
|
|
24699
25155
|
exports.ContractManager = ContractManager;
|
|
24700
25156
|
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
24701
25157
|
exports.ContractWatcher = ContractWatcher;
|
|
24702
|
-
exports.DB_VERSION = DB_VERSION;
|
|
24703
25158
|
exports.DEFAULT_MESSAGE_TIMEOUTS = DEFAULT_MESSAGE_TIMEOUTS;
|
|
24704
25159
|
exports.DEFAULT_MIN_BATCH_EXPIRY_SECONDS = DEFAULT_MIN_BATCH_EXPIRY_SECONDS;
|
|
24705
25160
|
exports.DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS = DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS;
|
|
@@ -24908,5 +25363,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
|
24908
25363
|
exports.walletFeeSource = walletFeeSource;
|
|
24909
25364
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
24910
25365
|
exports.withPrevTxs = withPrevTxs;
|
|
24911
|
-
//# sourceMappingURL=chunk-
|
|
24912
|
-
//# sourceMappingURL=chunk-
|
|
25366
|
+
//# sourceMappingURL=chunk-YJEWWLOQ.cjs.map
|
|
25367
|
+
//# sourceMappingURL=chunk-YJEWWLOQ.cjs.map
|