@arkade-os/sdk 0.4.74 → 0.4.76
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 +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{asyncStorageTaskQueue-D1AwLuqn.d.cts → asyncStorageTaskQueue-D7BU-BdP.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-aCaOBGTS.d.ts → asyncStorageTaskQueue-DrKbfleJ.d.ts} +2 -2
- package/dist/{chunk-J4ZR4VEM.cjs → chunk-2KFXM3N5.cjs} +17 -17
- package/dist/{chunk-J4ZR4VEM.cjs.map → chunk-2KFXM3N5.cjs.map} +1 -1
- package/dist/{chunk-X5BPARRD.js → chunk-54W6QBXL.js} +3 -3
- package/dist/{chunk-X5BPARRD.js.map → chunk-54W6QBXL.js.map} +1 -1
- package/dist/{chunk-LGB65ZCO.js → chunk-7UJLIZQU.js} +12 -5
- package/dist/chunk-7UJLIZQU.js.map +1 -0
- package/dist/{chunk-DXLVCFVK.cjs → chunk-CQNX4BTA.cjs} +58 -51
- package/dist/chunk-CQNX4BTA.cjs.map +1 -0
- package/dist/{chunk-WJVOFYTQ.js → chunk-F6YOCYWU.js} +3 -3
- package/dist/{chunk-WJVOFYTQ.js.map → chunk-F6YOCYWU.js.map} +1 -1
- package/dist/{chunk-WIHSU3YS.cjs → chunk-LHSVPDFJ.cjs} +788 -588
- package/dist/chunk-LHSVPDFJ.cjs.map +1 -0
- package/dist/{chunk-QS6AZE4F.cjs → chunk-LQM6RHNT.cjs} +10 -10
- package/dist/{chunk-QS6AZE4F.cjs.map → chunk-LQM6RHNT.cjs.map} +1 -1
- package/dist/{chunk-J3XVGWMP.js → chunk-MUBPGYUE.js} +4 -4
- package/dist/{chunk-J3XVGWMP.js.map → chunk-MUBPGYUE.js.map} +1 -1
- package/dist/{chunk-KPLQN4M4.js → chunk-O2BIWLZC.js} +4 -4
- package/dist/{chunk-KPLQN4M4.js.map → chunk-O2BIWLZC.js.map} +1 -1
- package/dist/{chunk-KMPNH7NS.cjs → chunk-P53OHGXY.cjs} +3 -3
- package/dist/{chunk-KMPNH7NS.cjs.map → chunk-P53OHGXY.cjs.map} +1 -1
- package/dist/{chunk-AS3W34MG.cjs → chunk-T327OEMV.cjs} +17 -17
- package/dist/{chunk-AS3W34MG.cjs.map → chunk-T327OEMV.cjs.map} +1 -1
- package/dist/{chunk-ZTGTQP2W.js → chunk-WMHELOHH.js} +353 -154
- package/dist/chunk-WMHELOHH.js.map +1 -0
- 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-z6veQfLI.d.ts → delegate-BAYpqkEx.d.ts} +1 -1
- package/dist/{delegate-6N0DKdnG.d.cts → delegate-CR7msIXK.d.cts} +1 -1
- package/dist/{hdWalletCapable-Bncp-eF0.d.ts → hdWalletCapable-BSF29IjK.d.ts} +3 -11
- package/dist/{hdWalletCapable-DJT8E8sN.d.cts → hdWalletCapable-BbZxCUeZ.d.cts} +3 -11
- package/dist/{index-BVqlZJwW.d.cts → index-4NF3srcg.d.cts} +2 -2
- package/dist/{index-Bxz3cKPA.d.ts → index-B_RYn9rg.d.cts} +13 -0
- package/dist/{index-Bxz3cKPA.d.cts → index-B_RYn9rg.d.ts} +13 -0
- package/dist/{index-CKQQ1oOg.d.ts → index-Dj2yOhQ2.d.ts} +2 -2
- package/dist/index.cjs +306 -302
- package/dist/index.d.cts +51 -14
- package/dist/index.d.ts +51 -14
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-C26IIg1F.d.cts → taskRunner-DGxde-YU.d.cts} +2 -2
- package/dist/{taskRunner-KxtIKYLv.d.ts → taskRunner-TzGUhxP-.d.ts} +2 -2
- 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.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +5 -5
- 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-DXLVCFVK.cjs.map +0 -1
- package/dist/chunk-LGB65ZCO.js.map +0 -1
- package/dist/chunk-WIHSU3YS.cjs.map +0 -1
- package/dist/chunk-ZTGTQP2W.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkT327OEMV_cjs = require('./chunk-T327OEMV.cjs');
|
|
4
|
+
var chunkCQNX4BTA_cjs = require('./chunk-CQNX4BTA.cjs');
|
|
5
|
+
var chunkP53OHGXY_cjs = require('./chunk-P53OHGXY.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 = chunkP53OHGXY_cjs.getArkPsbtFields(tx.root, 0, chunkP53OHGXY_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 = chunkP53OHGXY_cjs.getArkPsbtFields(g.root, 0, chunkP53OHGXY_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
|
+
chunkP53OHGXY_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 = chunkCQNX4BTA_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 chunkCQNX4BTA_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 = chunkCQNX4BTA_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
|
+
chunkP53OHGXY_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 = chunkCQNX4BTA_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 chunkCQNX4BTA_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 chunkCQNX4BTA_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
882
882
|
}
|
|
883
883
|
async compressedPublicKey() {
|
|
884
|
-
return
|
|
884
|
+
return chunkCQNX4BTA_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 && chunkCQNX4BTA_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 = chunkCQNX4BTA_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 chunkCQNX4BTA_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 chunkCQNX4BTA_cjs.identityDescriptor(wallet.identity);
|
|
1337
1337
|
}
|
|
1338
1338
|
async function provisionRefundKey(wallet) {
|
|
1339
|
-
const descriptor = await
|
|
1339
|
+
const descriptor = await chunkCQNX4BTA_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 } = chunkP53OHGXY_cjs.ArkAddress.decode(address);
|
|
1350
1350
|
return { descriptor, pubkey, pkScript, address };
|
|
1351
1351
|
}
|
|
1352
1352
|
async function provisionClaimSecret(wallet, opts = {}) {
|
|
@@ -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 = chunkCQNX4BTA_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 chunkP53OHGXY_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: chunkP53OHGXY_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 chunkP53OHGXY_cjs.rateGate.runHttp(url, () => chunkP53OHGXY_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[chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2042
2042
|
if (tipBlocks.status === 404) {
|
|
2043
|
-
tipBlocks = await
|
|
2043
|
+
tipBlocks = await chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_cjs.getArkPsbtFields(child.root, 0, chunkP53OHGXY_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 chunkT327OEMV_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 chunkT327OEMV_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 chunkT327OEMV_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 chunkT327OEMV_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 chunkT327OEMV_cjs.Packet.PACKET_TYPE:
|
|
2664
|
+
return chunkT327OEMV_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 chunkP53OHGXY_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2712
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkP53OHGXY_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 chunkP53OHGXY_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2716
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkP53OHGXY_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 chunkP53OHGXY_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2720
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_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
|
+
chunkP53OHGXY_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 = chunkP53OHGXY_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(chunkT327OEMV_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
|
+
chunkT327OEMV_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
|
+
chunkT327OEMV_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
|
+
chunkT327OEMV_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 = chunkT327OEMV_cjs.AssetId.fromString(assetIdStr);
|
|
3167
|
+
const group = chunkT327OEMV_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3168
3168
|
groups.push(group);
|
|
3169
3169
|
}
|
|
3170
|
-
return
|
|
3170
|
+
return chunkT327OEMV_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(chunkCQNX4BTA_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
3312
3312
|
} catch (e) {
|
|
3313
|
-
throw new
|
|
3313
|
+
throw new chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_cjs.decodeTapscript(chunkP53OHGXY_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3370
|
+
if (chunkP53OHGXY_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 chunkP53OHGXY_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: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3392
3392
|
amount: BigInt(input.value)
|
|
3393
3393
|
},
|
|
3394
3394
|
tapLeafScript: [input.tapLeafScript]
|
|
3395
3395
|
});
|
|
3396
|
-
|
|
3396
|
+
chunkP53OHGXY_cjs.setArkPsbtField(tx, i, chunkP53OHGXY_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 = chunkP53OHGXY_cjs.decodeTapscript(chunkP53OHGXY_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3406
|
+
const checkpointVtxoScript = new chunkP53OHGXY_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 = chunkP53OHGXY_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
|
+
chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3589
3589
|
if (finalTxid !== signedArkTx.id) {
|
|
3590
|
-
throw new
|
|
3590
|
+
throw new chunkP53OHGXY_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 = chunkP53OHGXY_cjs.scriptFromTapLeafScript(leaf);
|
|
3603
3603
|
let leafPubkeys;
|
|
3604
3604
|
try {
|
|
3605
|
-
leafPubkeys =
|
|
3606
|
-
(key) => base.hex.encode(
|
|
3605
|
+
leafPubkeys = chunkP53OHGXY_cjs.decodeTapscript(script).params.pubkeys.map(
|
|
3606
|
+
(key) => base.hex.encode(chunkCQNX4BTA_cjs.toXOnly(key, "leaf key"))
|
|
3607
3607
|
);
|
|
3608
3608
|
} catch (error) {
|
|
3609
|
-
throw new
|
|
3609
|
+
throw new chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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 chunkP53OHGXY_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
|
+
chunkP53OHGXY_cjs.assertAllowedSighashTypes(server);
|
|
3686
3686
|
} catch (error) {
|
|
3687
|
-
throw new
|
|
3687
|
+
throw new chunkP53OHGXY_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 chunkP53OHGXY_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 = chunkP53OHGXY_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(chunkCQNX4BTA_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 = chunkP53OHGXY_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
|
+
chunkP53OHGXY_cjs.setArkPsbtField(signed, index, chunkP53OHGXY_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 = chunkCQNX4BTA_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
|
+
chunkP53OHGXY_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 = chunkP53OHGXY_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 = chunkP53OHGXY_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 chunkCQNX4BTA_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 (!chunkCQNX4BTA_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 (!chunkP53OHGXY_cjs.hasTerminalSpend(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 chunkP53OHGXY_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
4189
4189
|
}
|
|
4190
4190
|
function canMigrateBySend(vtxo, now) {
|
|
4191
|
-
if (!
|
|
4191
|
+
if (!chunkP53OHGXY_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 chunkP53OHGXY_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(chunkP53OHGXY_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(chunkP53OHGXY_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 (chunkP53OHGXY_cjs.canRecoverOnchain(vtxo, now)) {
|
|
4271
4271
|
return true;
|
|
4272
4272
|
}
|
|
4273
|
-
if (
|
|
4273
|
+
if (chunkP53OHGXY_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 = chunkP53OHGXY_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) || chunkP53OHGXY_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
4317
4317
|
);
|
|
4318
4318
|
}
|
|
4319
4319
|
function isMigrationCapable(wallet) {
|
|
@@ -4912,11 +4912,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4912
4912
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
4913
4913
|
);
|
|
4914
4914
|
}
|
|
4915
|
-
const tx = new
|
|
4915
|
+
const tx = new chunkP53OHGXY_cjs.Transaction();
|
|
4916
4916
|
for (const utxo of expiredUtxos) {
|
|
4917
|
-
const utxoScript =
|
|
4917
|
+
const utxoScript = chunkP53OHGXY_cjs.VtxoScript.decode(utxo.tapTree);
|
|
4918
4918
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
4919
|
-
(leaf) =>
|
|
4919
|
+
(leaf) => chunkP53OHGXY_cjs.CSVMultisigTapscript.isScriptValid(chunkP53OHGXY_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
4920
4920
|
);
|
|
4921
4921
|
if (!utxoExitLeaf) {
|
|
4922
4922
|
throw new Error(
|
|
@@ -4931,7 +4931,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4931
4931
|
amount: BigInt(utxo.value)
|
|
4932
4932
|
},
|
|
4933
4933
|
tapLeafScript: [utxoExitLeaf],
|
|
4934
|
-
sequence:
|
|
4934
|
+
sequence: chunkP53OHGXY_cjs.getSequence(utxoExitLeaf)
|
|
4935
4935
|
});
|
|
4936
4936
|
}
|
|
4937
4937
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -5174,8 +5174,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5174
5174
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
5175
5175
|
if (cls.status === "CURRENT") continue;
|
|
5176
5176
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
5177
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
5178
|
-
const spendable = live.filter((v) => !
|
|
5177
|
+
const recoverable = live.filter((v) => v.isSwept && !chunkP53OHGXY_cjs.hasTerminalSpend(v));
|
|
5178
|
+
const spendable = live.filter((v) => !chunkP53OHGXY_cjs.hasTerminalSpend(v) && !v.isSwept);
|
|
5179
5179
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
5180
5180
|
let recoverableCount = 0;
|
|
5181
5181
|
let recoverableValue = 0;
|
|
@@ -5188,7 +5188,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5188
5188
|
awaitingSweepCount = spendable.length;
|
|
5189
5189
|
awaitingSweepValue = value;
|
|
5190
5190
|
for (const v of spendable) {
|
|
5191
|
-
const exp =
|
|
5191
|
+
const exp = chunkP53OHGXY_cjs.toBatchExpiry(v);
|
|
5192
5192
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
5193
5193
|
nextSweepEta = exp;
|
|
5194
5194
|
}
|
|
@@ -5449,7 +5449,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5449
5449
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
5450
5450
|
getBoardingTimelock() {
|
|
5451
5451
|
const wallet = this.getSweepWallet();
|
|
5452
|
-
const exitScript =
|
|
5452
|
+
const exitScript = chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(
|
|
5453
5453
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
5454
5454
|
);
|
|
5455
5455
|
return exitScript.params.timelock;
|
|
@@ -5580,8 +5580,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5580
5580
|
* or doesn't carry the metadata.
|
|
5581
5581
|
*/
|
|
5582
5582
|
extractSpentOutpoint(error) {
|
|
5583
|
-
const ark =
|
|
5584
|
-
if (!
|
|
5583
|
+
const ark = chunkP53OHGXY_cjs.maybeArkError(error);
|
|
5584
|
+
if (!chunkP53OHGXY_cjs.isArkError(ark, chunkP53OHGXY_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
5585
5585
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
5586
5586
|
if (typeof raw !== "string") return void 0;
|
|
5587
5587
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -5771,7 +5771,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5771
5771
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
5772
5772
|
break;
|
|
5773
5773
|
}
|
|
5774
|
-
const inputFee = estimator.evalOffchainInput(
|
|
5774
|
+
const inputFee = estimator.evalOffchainInput(chunkP53OHGXY_cjs.toOffchainInputFeeParams(v));
|
|
5775
5775
|
if (inputFee.satoshis >= v.value) {
|
|
5776
5776
|
continue;
|
|
5777
5777
|
}
|
|
@@ -5791,7 +5791,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5791
5791
|
const arkAddress = await this.wallet.getAddress();
|
|
5792
5792
|
const outputFee = estimator.evalOffchainOutput({
|
|
5793
5793
|
amount: totalAmount,
|
|
5794
|
-
script: base.hex.encode(
|
|
5794
|
+
script: base.hex.encode(chunkP53OHGXY_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
5795
5795
|
});
|
|
5796
5796
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
5797
5797
|
if (totalAmount < dustAmount) return;
|
|
@@ -5871,7 +5871,7 @@ var ArkNote = class _ArkNote {
|
|
|
5871
5871
|
this.value = value;
|
|
5872
5872
|
this.HRP = HRP;
|
|
5873
5873
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
5874
|
-
this.vtxoScript = new
|
|
5874
|
+
this.vtxoScript = new chunkP53OHGXY_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
5875
5875
|
const leaf = this.vtxoScript.leaves[0];
|
|
5876
5876
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
5877
5877
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -6038,7 +6038,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6038
6038
|
const privateKey = data.slice(1, 33);
|
|
6039
6039
|
const serverPubKey = data.slice(33, 65);
|
|
6040
6040
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
6041
|
-
const csvTimelock =
|
|
6041
|
+
const csvTimelock = chunkP53OHGXY_cjs.sequenceToTimelock(sequence);
|
|
6042
6042
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
6043
6043
|
}
|
|
6044
6044
|
toString() {
|
|
@@ -6046,7 +6046,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6046
6046
|
data[0] = _ArkadeCash.Version;
|
|
6047
6047
|
data.set(this._privateKey, 1);
|
|
6048
6048
|
data.set(this._serverPubKey, 33);
|
|
6049
|
-
const sequence =
|
|
6049
|
+
const sequence = chunkP53OHGXY_cjs.timelockToSequence(this.csvTimelock);
|
|
6050
6050
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
6051
6051
|
const words = base.bech32m.toWords(data);
|
|
6052
6052
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -6055,7 +6055,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6055
6055
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
6056
6056
|
}
|
|
6057
6057
|
get vtxoScript() {
|
|
6058
|
-
return new
|
|
6058
|
+
return new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
6059
6059
|
pubKey: this._publicKey,
|
|
6060
6060
|
serverPubKey: this._serverPubKey,
|
|
6061
6061
|
csvTimelock: this.csvTimelock
|
|
@@ -6316,7 +6316,7 @@ async function captureExitBranch(params) {
|
|
|
6316
6316
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
6317
6317
|
if (nonCommitment.length > 0) {
|
|
6318
6318
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
6319
|
-
psbtByTxid.set(
|
|
6319
|
+
psbtByTxid.set(chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6320
6320
|
}
|
|
6321
6321
|
}
|
|
6322
6322
|
}
|
|
@@ -6359,10 +6359,10 @@ var IndexerExitDataSource = class {
|
|
|
6359
6359
|
while (hasMore) {
|
|
6360
6360
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
6361
6361
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
6362
|
-
{ pageIndex, pageSize:
|
|
6362
|
+
{ pageIndex, pageSize: chunkP53OHGXY_cjs.DEFAULT_PAGE_SIZE }
|
|
6363
6363
|
);
|
|
6364
6364
|
chain.push(...page);
|
|
6365
|
-
hasMore = meta ? page.length ===
|
|
6365
|
+
hasMore = meta ? page.length === chunkP53OHGXY_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6366
6366
|
pageIndex++;
|
|
6367
6367
|
}
|
|
6368
6368
|
return chain;
|
|
@@ -6374,12 +6374,12 @@ var IndexerExitDataSource = class {
|
|
|
6374
6374
|
while (hasMore) {
|
|
6375
6375
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
6376
6376
|
pageIndex,
|
|
6377
|
-
pageSize:
|
|
6377
|
+
pageSize: chunkP53OHGXY_cjs.DEFAULT_PAGE_SIZE
|
|
6378
6378
|
});
|
|
6379
6379
|
for (const psbt of txs) {
|
|
6380
|
-
out.set(
|
|
6380
|
+
out.set(chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6381
6381
|
}
|
|
6382
|
-
hasMore = page ? txs.length ===
|
|
6382
|
+
hasMore = page ? txs.length === chunkP53OHGXY_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6383
6383
|
pageIndex++;
|
|
6384
6384
|
}
|
|
6385
6385
|
return out;
|
|
@@ -6400,7 +6400,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
6400
6400
|
}
|
|
6401
6401
|
}
|
|
6402
6402
|
function psbtInputTxids(psbtBase64) {
|
|
6403
|
-
const tx =
|
|
6403
|
+
const tx = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
6404
6404
|
const ids = [];
|
|
6405
6405
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
6406
6406
|
const txid = tx.getInput(i).txid;
|
|
@@ -6759,10 +6759,10 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
6759
6759
|
try {
|
|
6760
6760
|
info = await arkProvider.getInfo();
|
|
6761
6761
|
} catch (err) {
|
|
6762
|
-
if (!
|
|
6762
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
6763
6763
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
6764
6764
|
if (!snapshot) {
|
|
6765
|
-
throw new
|
|
6765
|
+
throw new chunkP53OHGXY_cjs.ProviderUnavailableError(
|
|
6766
6766
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
6767
6767
|
{ cause: err }
|
|
6768
6768
|
);
|
|
@@ -7169,7 +7169,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
|
|
|
7169
7169
|
return [...txids];
|
|
7170
7170
|
}
|
|
7171
7171
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
|
|
7172
|
-
const normalized = vtxos.map(
|
|
7172
|
+
const normalized = vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
7173
7173
|
const localCreatedAt = localCreatedAtByTxid(normalized);
|
|
7174
7174
|
const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
|
|
7175
7175
|
const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
|
|
@@ -7343,7 +7343,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7343
7343
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
7344
7344
|
withRecoverable: false
|
|
7345
7345
|
});
|
|
7346
|
-
const controlAssetRef = params.controlAssetId ?
|
|
7346
|
+
const controlAssetRef = params.controlAssetId ? chunkT327OEMV_cjs.AssetRef.fromId(chunkT327OEMV_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
7347
7347
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
7348
7348
|
let totalBtcSelected = 0n;
|
|
7349
7349
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -7356,8 +7356,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7356
7356
|
}
|
|
7357
7357
|
}
|
|
7358
7358
|
const groups = [];
|
|
7359
|
-
const issuedAssetOutput =
|
|
7360
|
-
const issuedAssetGroup =
|
|
7359
|
+
const issuedAssetOutput = chunkT327OEMV_cjs.AssetOutput.create(0, params.amount);
|
|
7360
|
+
const issuedAssetGroup = chunkT327OEMV_cjs.AssetGroup.create(
|
|
7361
7361
|
null,
|
|
7362
7362
|
controlAssetRef,
|
|
7363
7363
|
[],
|
|
@@ -7372,28 +7372,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7372
7372
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7373
7373
|
for (const asset of assets) {
|
|
7374
7374
|
if (asset.assetId !== assetId) continue;
|
|
7375
|
-
changeInputs.push(
|
|
7375
|
+
changeInputs.push(chunkT327OEMV_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7376
7376
|
}
|
|
7377
7377
|
}
|
|
7378
7378
|
groups.push(
|
|
7379
|
-
|
|
7380
|
-
|
|
7379
|
+
chunkT327OEMV_cjs.AssetGroup.create(
|
|
7380
|
+
chunkT327OEMV_cjs.AssetId.fromString(assetId),
|
|
7381
7381
|
null,
|
|
7382
7382
|
changeInputs,
|
|
7383
|
-
[
|
|
7383
|
+
[chunkT327OEMV_cjs.AssetOutput.create(0, amount)],
|
|
7384
7384
|
[]
|
|
7385
7385
|
)
|
|
7386
7386
|
);
|
|
7387
7387
|
}
|
|
7388
7388
|
}
|
|
7389
7389
|
const address = await this.wallet.getAddress();
|
|
7390
|
-
const outputAddress =
|
|
7390
|
+
const outputAddress = chunkP53OHGXY_cjs.ArkAddress.decode(address);
|
|
7391
7391
|
const outputs = [
|
|
7392
7392
|
{
|
|
7393
7393
|
script: outputAddress.pkScript,
|
|
7394
7394
|
amount: BigInt(totalBtcSelected)
|
|
7395
7395
|
},
|
|
7396
|
-
Extension.create([
|
|
7396
|
+
Extension.create([chunkT327OEMV_cjs.Packet.create(groups)]).txOut()
|
|
7397
7397
|
];
|
|
7398
7398
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
7399
7399
|
coinSelection.inputs,
|
|
@@ -7401,7 +7401,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7401
7401
|
);
|
|
7402
7402
|
return {
|
|
7403
7403
|
arkTxId: arkTxid,
|
|
7404
|
-
assetId:
|
|
7404
|
+
assetId: chunkT327OEMV_cjs.AssetId.create(arkTxid, 0).toString()
|
|
7405
7405
|
};
|
|
7406
7406
|
}
|
|
7407
7407
|
/**
|
|
@@ -7473,16 +7473,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7473
7473
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7474
7474
|
for (const asset of assets) {
|
|
7475
7475
|
if (asset.assetId !== params.assetId) continue;
|
|
7476
|
-
reissueInputs.push(
|
|
7476
|
+
reissueInputs.push(chunkT327OEMV_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7477
7477
|
}
|
|
7478
7478
|
}
|
|
7479
7479
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
7480
|
-
const reissueAssetIdObj =
|
|
7481
|
-
const reissueAssetGroup =
|
|
7480
|
+
const reissueAssetIdObj = chunkT327OEMV_cjs.AssetId.fromString(params.assetId);
|
|
7481
|
+
const reissueAssetGroup = chunkT327OEMV_cjs.AssetGroup.create(
|
|
7482
7482
|
reissueAssetIdObj,
|
|
7483
7483
|
null,
|
|
7484
7484
|
reissueInputs,
|
|
7485
|
-
[
|
|
7485
|
+
[chunkT327OEMV_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
7486
7486
|
[]
|
|
7487
7487
|
);
|
|
7488
7488
|
const groups = [reissueAssetGroup];
|
|
@@ -7491,27 +7491,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7491
7491
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7492
7492
|
for (const asset of assets) {
|
|
7493
7493
|
if (asset.assetId !== assetId) continue;
|
|
7494
|
-
changeInputs.push(
|
|
7494
|
+
changeInputs.push(chunkT327OEMV_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7495
7495
|
}
|
|
7496
7496
|
}
|
|
7497
7497
|
groups.push(
|
|
7498
|
-
|
|
7499
|
-
|
|
7498
|
+
chunkT327OEMV_cjs.AssetGroup.create(
|
|
7499
|
+
chunkT327OEMV_cjs.AssetId.fromString(assetId),
|
|
7500
7500
|
null,
|
|
7501
7501
|
changeInputs,
|
|
7502
|
-
[
|
|
7502
|
+
[chunkT327OEMV_cjs.AssetOutput.create(0, amount)],
|
|
7503
7503
|
[]
|
|
7504
7504
|
)
|
|
7505
7505
|
);
|
|
7506
7506
|
}
|
|
7507
7507
|
const address = await this.wallet.getAddress();
|
|
7508
|
-
const outputAddress =
|
|
7508
|
+
const outputAddress = chunkP53OHGXY_cjs.ArkAddress.decode(address);
|
|
7509
7509
|
const outputs = [
|
|
7510
7510
|
{
|
|
7511
7511
|
script: outputAddress.pkScript,
|
|
7512
7512
|
amount: BigInt(totalBtcSelected)
|
|
7513
7513
|
},
|
|
7514
|
-
Extension.create([
|
|
7514
|
+
Extension.create([chunkT327OEMV_cjs.Packet.create(groups)]).txOut()
|
|
7515
7515
|
];
|
|
7516
7516
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7517
7517
|
return arkTxid;
|
|
@@ -7578,27 +7578,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7578
7578
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7579
7579
|
for (const asset of assets) {
|
|
7580
7580
|
if (asset.assetId !== assetId) continue;
|
|
7581
|
-
changeInputs.push(
|
|
7581
|
+
changeInputs.push(chunkT327OEMV_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7582
7582
|
}
|
|
7583
7583
|
}
|
|
7584
7584
|
groups.push(
|
|
7585
|
-
|
|
7586
|
-
|
|
7585
|
+
chunkT327OEMV_cjs.AssetGroup.create(
|
|
7586
|
+
chunkT327OEMV_cjs.AssetId.fromString(assetId),
|
|
7587
7587
|
null,
|
|
7588
7588
|
changeInputs,
|
|
7589
|
-
amount > 0n ? [
|
|
7589
|
+
amount > 0n ? [chunkT327OEMV_cjs.AssetOutput.create(0, amount)] : [],
|
|
7590
7590
|
[]
|
|
7591
7591
|
)
|
|
7592
7592
|
);
|
|
7593
7593
|
}
|
|
7594
7594
|
const address = await this.wallet.getAddress();
|
|
7595
|
-
const outputAddress =
|
|
7595
|
+
const outputAddress = chunkP53OHGXY_cjs.ArkAddress.decode(address);
|
|
7596
7596
|
const outputs = [
|
|
7597
7597
|
{
|
|
7598
7598
|
script: outputAddress.pkScript,
|
|
7599
7599
|
amount: BigInt(totalBtcSelected)
|
|
7600
7600
|
},
|
|
7601
|
-
Extension.create([
|
|
7601
|
+
Extension.create([chunkT327OEMV_cjs.Packet.create(groups)]).txOut()
|
|
7602
7602
|
];
|
|
7603
7603
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7604
7604
|
return arkTxid;
|
|
@@ -7623,7 +7623,7 @@ function castMetadata(metadata) {
|
|
|
7623
7623
|
} else {
|
|
7624
7624
|
throw new Error("Invalid metadata value type");
|
|
7625
7625
|
}
|
|
7626
|
-
md.push(
|
|
7626
|
+
md.push(chunkT327OEMV_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
7627
7627
|
}
|
|
7628
7628
|
return md;
|
|
7629
7629
|
}
|
|
@@ -7644,10 +7644,10 @@ var DelegateManagerImpl = class {
|
|
|
7644
7644
|
if (vtxos.length === 0) {
|
|
7645
7645
|
return { delegated: [], failed: [] };
|
|
7646
7646
|
}
|
|
7647
|
-
const destinationScript =
|
|
7647
|
+
const destinationScript = chunkP53OHGXY_cjs.ArkAddress.decode(destination).pkScript;
|
|
7648
7648
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
7649
7649
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
7650
|
-
const eligible = vtxos.map(
|
|
7650
|
+
const eligible = vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo).filter(
|
|
7651
7651
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
7652
7652
|
);
|
|
7653
7653
|
if (eligible.length === 0) {
|
|
@@ -7676,11 +7676,11 @@ var DelegateManagerImpl = class {
|
|
|
7676
7676
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
7677
7677
|
let recoverableVtxos = [];
|
|
7678
7678
|
for (const vtxo of eligible) {
|
|
7679
|
-
if (
|
|
7679
|
+
if (chunkP53OHGXY_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7680
7680
|
recoverableVtxos.push(vtxo);
|
|
7681
7681
|
continue;
|
|
7682
7682
|
}
|
|
7683
|
-
const expiry =
|
|
7683
|
+
const expiry = chunkP53OHGXY_cjs.toBatchExpiry(vtxo);
|
|
7684
7684
|
if (!expiry) continue;
|
|
7685
7685
|
const dayKey = getDayTimestamp(expiry);
|
|
7686
7686
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -7745,7 +7745,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7745
7745
|
}
|
|
7746
7746
|
if (!delegateAt) {
|
|
7747
7747
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
7748
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
7748
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkP53OHGXY_cjs.canRecoverOnchain(coin, now) && chunkP53OHGXY_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunkP53OHGXY_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
|
|
7749
7749
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
7750
7750
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
7751
7751
|
} else {
|
|
@@ -7769,7 +7769,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7769
7769
|
let amount = 0n;
|
|
7770
7770
|
for (const coin of vtxos) {
|
|
7771
7771
|
const inputFee = estimator.evalOffchainInput({
|
|
7772
|
-
...
|
|
7772
|
+
...chunkP53OHGXY_cjs.toOffchainInputFeeParams(coin),
|
|
7773
7773
|
type: "vtxo"
|
|
7774
7774
|
});
|
|
7775
7775
|
if (inputFee.value >= coin.value) {
|
|
@@ -7783,7 +7783,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7783
7783
|
const delegateFee = BigInt(Number(fee));
|
|
7784
7784
|
if (delegateFee > 0n) {
|
|
7785
7785
|
outputs.push({
|
|
7786
|
-
script:
|
|
7786
|
+
script: chunkP53OHGXY_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
7787
7787
|
amount: delegateFee
|
|
7788
7788
|
});
|
|
7789
7789
|
}
|
|
@@ -7816,10 +7816,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7816
7816
|
destinationScript
|
|
7817
7817
|
);
|
|
7818
7818
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
7819
|
-
btcSigner.Address(
|
|
7819
|
+
btcSigner.Address(chunkP53OHGXY_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
7820
7820
|
);
|
|
7821
7821
|
const forfeits = await Promise.all(
|
|
7822
|
-
vtxos.filter((v) => !
|
|
7822
|
+
vtxos.filter((v) => !chunkP53OHGXY_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
7823
7823
|
const forfeit = await makeDelegateForfeitTx(
|
|
7824
7824
|
coin,
|
|
7825
7825
|
dust,
|
|
@@ -7844,7 +7844,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
7844
7844
|
index: input.vout,
|
|
7845
7845
|
witnessUtxo: {
|
|
7846
7846
|
amount: BigInt(input.value),
|
|
7847
|
-
script:
|
|
7847
|
+
script: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
7848
7848
|
},
|
|
7849
7849
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
7850
7850
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -7902,7 +7902,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
7902
7902
|
expire_at: 0,
|
|
7903
7903
|
cosigners_public_keys: cosignerPubKeys
|
|
7904
7904
|
};
|
|
7905
|
-
const proof =
|
|
7905
|
+
const proof = chunkP53OHGXY_cjs.Intent.create(message, coins, outputs);
|
|
7906
7906
|
const signedProof = await identity.sign(proof);
|
|
7907
7907
|
return {
|
|
7908
7908
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -7928,10 +7928,10 @@ function getDayTimestamp(timestamp) {
|
|
|
7928
7928
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
7929
7929
|
if (!vtxo.tapTree) return void 0;
|
|
7930
7930
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
7931
|
-
const vtxoScript =
|
|
7931
|
+
const vtxoScript = chunkP53OHGXY_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
7932
7932
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
7933
|
-
const arkTapscript =
|
|
7934
|
-
if (!
|
|
7933
|
+
const arkTapscript = chunkP53OHGXY_cjs.decodeTapscript(chunkP53OHGXY_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
7934
|
+
if (!chunkP53OHGXY_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
7935
7935
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
7936
7936
|
});
|
|
7937
7937
|
}
|
|
@@ -8212,7 +8212,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
|
|
|
8212
8212
|
};
|
|
8213
8213
|
}
|
|
8214
8214
|
function scriptFromArkAddress(address) {
|
|
8215
|
-
return base.hex.encode(
|
|
8215
|
+
return base.hex.encode(chunkP53OHGXY_cjs.ArkAddress.decode(address).pkScript);
|
|
8216
8216
|
}
|
|
8217
8217
|
|
|
8218
8218
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -8707,17 +8707,76 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
8707
8707
|
}
|
|
8708
8708
|
async function getVtxosForContract(repo, contract) {
|
|
8709
8709
|
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
8710
|
-
return vtxos.map(
|
|
8710
|
+
return vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
8711
|
+
}
|
|
8712
|
+
function hasRecordedSpend(vtxo) {
|
|
8713
|
+
return vtxo.isSpent === true && (!!vtxo.spentBy || !!vtxo.arkTxId || !!vtxo.settledBy);
|
|
8714
|
+
}
|
|
8715
|
+
var RECORDED_SPEND_TTL_MS = 6e4;
|
|
8716
|
+
var recordedSpends = /* @__PURE__ */ new WeakMap();
|
|
8717
|
+
function registryFor(repo) {
|
|
8718
|
+
const existing = recordedSpends.get(repo);
|
|
8719
|
+
if (existing) return existing;
|
|
8720
|
+
const created = /* @__PURE__ */ new Map();
|
|
8721
|
+
recordedSpends.set(repo, created);
|
|
8722
|
+
return created;
|
|
8723
|
+
}
|
|
8724
|
+
var writeChains = /* @__PURE__ */ new WeakMap();
|
|
8725
|
+
function inVtxoWriteOrder(repo, fn) {
|
|
8726
|
+
const prev = writeChains.get(repo) ?? Promise.resolve();
|
|
8727
|
+
const run = prev.then(fn, fn);
|
|
8728
|
+
writeChains.set(
|
|
8729
|
+
repo,
|
|
8730
|
+
run.catch(() => {
|
|
8731
|
+
})
|
|
8732
|
+
);
|
|
8733
|
+
return run;
|
|
8711
8734
|
}
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8735
|
+
function applyRecordedSpends(repo, vtxos) {
|
|
8736
|
+
const registry = registryFor(repo);
|
|
8737
|
+
const now = Date.now();
|
|
8738
|
+
for (const [key, spend] of registry) {
|
|
8739
|
+
if (now - spend.at >= RECORDED_SPEND_TTL_MS) registry.delete(key);
|
|
8740
|
+
}
|
|
8741
|
+
for (const incoming of vtxos) {
|
|
8742
|
+
const key = vtxoOutpoint(incoming);
|
|
8743
|
+
if (!hasRecordedSpend(incoming) || registry.has(key)) continue;
|
|
8744
|
+
registry.set(key, {
|
|
8745
|
+
at: now,
|
|
8746
|
+
spentBy: incoming.spentBy,
|
|
8747
|
+
arkTxId: incoming.arkTxId,
|
|
8748
|
+
settledBy: incoming.settledBy
|
|
8749
|
+
});
|
|
8718
8750
|
}
|
|
8719
|
-
|
|
8720
|
-
return
|
|
8751
|
+
if (registry.size === 0) return vtxos;
|
|
8752
|
+
return vtxos.map((incoming) => {
|
|
8753
|
+
if (hasRecordedSpend(incoming)) return incoming;
|
|
8754
|
+
const spent = registry.get(vtxoOutpoint(incoming));
|
|
8755
|
+
if (!spent) return incoming;
|
|
8756
|
+
const spentBy = incoming.spentBy || spent.spentBy;
|
|
8757
|
+
const arkTxId = incoming.arkTxId || spent.arkTxId;
|
|
8758
|
+
const settledBy = incoming.settledBy || spent.settledBy;
|
|
8759
|
+
return {
|
|
8760
|
+
...incoming,
|
|
8761
|
+
isSpent: true,
|
|
8762
|
+
...spentBy ? { spentBy } : {},
|
|
8763
|
+
...arkTxId ? { arkTxId } : {},
|
|
8764
|
+
...settledBy ? { settledBy } : {}
|
|
8765
|
+
};
|
|
8766
|
+
});
|
|
8767
|
+
}
|
|
8768
|
+
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
8769
|
+
return inVtxoWriteOrder(repo, async () => {
|
|
8770
|
+
const rows = applyRecordedSpends(repo, vtxos);
|
|
8771
|
+
if (repo.saveVtxosForScript) {
|
|
8772
|
+
return repo.saveVtxosForScript(
|
|
8773
|
+
{ script: contract.script, address: contract.address },
|
|
8774
|
+
rows
|
|
8775
|
+
);
|
|
8776
|
+
}
|
|
8777
|
+
validateVtxosForScript(rows, contract.script, "saveVtxosForContract");
|
|
8778
|
+
return repo.saveVtxos(contract.address, rows);
|
|
8779
|
+
});
|
|
8721
8780
|
}
|
|
8722
8781
|
|
|
8723
8782
|
// src/repositories/inMemory/walletRepository.ts
|
|
@@ -8849,7 +8908,7 @@ function decodeArkContract(encoded) {
|
|
|
8849
8908
|
}
|
|
8850
8909
|
function contractFromArkContract(encoded, options = {}) {
|
|
8851
8910
|
const parsed = decodeArkContract(encoded);
|
|
8852
|
-
const handler =
|
|
8911
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(parsed.type);
|
|
8853
8912
|
if (!handler) {
|
|
8854
8913
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
8855
8914
|
}
|
|
@@ -8863,9 +8922,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
8863
8922
|
metadata: options.metadata
|
|
8864
8923
|
};
|
|
8865
8924
|
}
|
|
8866
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
8925
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkP53OHGXY_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
8867
8926
|
const parsed = decodeArkContract(encoded);
|
|
8868
|
-
const handler =
|
|
8927
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
8869
8928
|
const params = parsed.data;
|
|
8870
8929
|
const vtxoScript = handler.createScript(params);
|
|
8871
8930
|
return {
|
|
@@ -9171,9 +9230,9 @@ var ContractWatcher = class {
|
|
|
9171
9230
|
this.connectionState = "connected";
|
|
9172
9231
|
this.reconnectAttempts = 0;
|
|
9173
9232
|
this.listenLoop().catch((e) => {
|
|
9174
|
-
if (
|
|
9233
|
+
if (chunkP53OHGXY_cjs.isEventSourceError(e)) {
|
|
9175
9234
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
9176
|
-
} else if (!
|
|
9235
|
+
} else if (!chunkP53OHGXY_cjs.isEventSourceUnavailableError(e)) {
|
|
9177
9236
|
console.error(e);
|
|
9178
9237
|
}
|
|
9179
9238
|
this.connectionState = "disconnected";
|
|
@@ -9185,7 +9244,7 @@ var ContractWatcher = class {
|
|
|
9185
9244
|
this.scheduleReconnect();
|
|
9186
9245
|
});
|
|
9187
9246
|
} catch (error) {
|
|
9188
|
-
if (!
|
|
9247
|
+
if (!chunkP53OHGXY_cjs.isEventSourceUnavailableError(error)) {
|
|
9189
9248
|
console.error("ContractWatcher connection failed:", error);
|
|
9190
9249
|
}
|
|
9191
9250
|
this.connectionState = "disconnected";
|
|
@@ -9211,7 +9270,7 @@ var ContractWatcher = class {
|
|
|
9211
9270
|
* slower; what it loses is push latency.
|
|
9212
9271
|
*/
|
|
9213
9272
|
reportEventSourceUnavailable(error) {
|
|
9214
|
-
if (!
|
|
9273
|
+
if (!chunkP53OHGXY_cjs.isEventSourceUnavailableError(error)) return false;
|
|
9215
9274
|
if (!this.eventSourceReported) {
|
|
9216
9275
|
this.eventSourceReported = true;
|
|
9217
9276
|
console.warn(
|
|
@@ -9283,7 +9342,7 @@ var ContractWatcher = class {
|
|
|
9283
9342
|
const now = Date.now();
|
|
9284
9343
|
let current;
|
|
9285
9344
|
try {
|
|
9286
|
-
current = await
|
|
9345
|
+
current = await chunkP53OHGXY_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
9287
9346
|
spendableOnly: true
|
|
9288
9347
|
});
|
|
9289
9348
|
} catch (error) {
|
|
@@ -9492,14 +9551,14 @@ var ContractWatcher = class {
|
|
|
9492
9551
|
const timestamp = Date.now();
|
|
9493
9552
|
if (update.newVtxos?.length) {
|
|
9494
9553
|
this.processSubscriptionVtxos(
|
|
9495
|
-
update.newVtxos.map(
|
|
9554
|
+
update.newVtxos.map(chunkP53OHGXY_cjs.normalizeVtxo),
|
|
9496
9555
|
"vtxo_received",
|
|
9497
9556
|
timestamp
|
|
9498
9557
|
);
|
|
9499
9558
|
}
|
|
9500
9559
|
if (update.spentVtxos?.length) {
|
|
9501
9560
|
this.processSubscriptionVtxos(
|
|
9502
|
-
update.spentVtxos.map(
|
|
9561
|
+
update.spentVtxos.map(chunkP53OHGXY_cjs.normalizeVtxo),
|
|
9503
9562
|
"vtxo_spent",
|
|
9504
9563
|
timestamp
|
|
9505
9564
|
);
|
|
@@ -9527,8 +9586,8 @@ var ContractWatcher = class {
|
|
|
9527
9586
|
continue;
|
|
9528
9587
|
}
|
|
9529
9588
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
9530
|
-
const n =
|
|
9531
|
-
if (
|
|
9589
|
+
const n = chunkP53OHGXY_cjs.normalizeVtxo(vtxo);
|
|
9590
|
+
if (chunkP53OHGXY_cjs.hasTerminalSpend(n) || n.isSwept || chunkP53OHGXY_cjs.isPastExpiry(n, now)) continue;
|
|
9532
9591
|
}
|
|
9533
9592
|
let bucket = target.get(vtxo.script);
|
|
9534
9593
|
if (!bucket) {
|
|
@@ -9627,7 +9686,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
9627
9686
|
(s) => !isTerminalIntentState(s)
|
|
9628
9687
|
);
|
|
9629
9688
|
function isConsumed(vtxo) {
|
|
9630
|
-
return vtxo !== void 0 &&
|
|
9689
|
+
return vtxo !== void 0 && chunkP53OHGXY_cjs.hasTerminalSpend(vtxo);
|
|
9631
9690
|
}
|
|
9632
9691
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
9633
9692
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -9670,7 +9729,7 @@ async function reconcileIntents(deps) {
|
|
|
9670
9729
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
9671
9730
|
if (outpoints.length > 0) {
|
|
9672
9731
|
try {
|
|
9673
|
-
const { vtxos } = await
|
|
9732
|
+
const { vtxos } = await chunkP53OHGXY_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9674
9733
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9675
9734
|
} catch (e) {
|
|
9676
9735
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9717,7 +9776,8 @@ function areCoalescibleContractTypes(a, b) {
|
|
|
9717
9776
|
function toWatchOnlyContract(params) {
|
|
9718
9777
|
return { ...params, state: params.state ?? "active", createdAt: Date.now() };
|
|
9719
9778
|
}
|
|
9720
|
-
|
|
9779
|
+
var TAPSCRIPT_MEMO_MAX_ENTRIES = 1024;
|
|
9780
|
+
function annotatableIn(scriptToContract, vtxos, memo) {
|
|
9721
9781
|
const scripts = /* @__PURE__ */ new Set();
|
|
9722
9782
|
const cache = /* @__PURE__ */ new Map();
|
|
9723
9783
|
const failures = /* @__PURE__ */ new Map();
|
|
@@ -9725,7 +9785,25 @@ function annotatableIn(scriptToContract, vtxos) {
|
|
|
9725
9785
|
const contract = scriptToContract.get(script);
|
|
9726
9786
|
if (!contract) continue;
|
|
9727
9787
|
try {
|
|
9728
|
-
|
|
9788
|
+
const key = `${contract.type}\0${script}\0${JSON.stringify(contract.params)}`;
|
|
9789
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
9790
|
+
const hit = memo?.get(script);
|
|
9791
|
+
let tapscripts;
|
|
9792
|
+
if (hit && hit.key === key && hit.handler === handler) {
|
|
9793
|
+
tapscripts = hit.tapscripts;
|
|
9794
|
+
memo.delete(script);
|
|
9795
|
+
memo.set(script, hit);
|
|
9796
|
+
} else {
|
|
9797
|
+
memo?.delete(script);
|
|
9798
|
+
tapscripts = deriveContractTapscripts(contract);
|
|
9799
|
+
if (handler && memo) {
|
|
9800
|
+
memo.set(script, { key, handler, tapscripts });
|
|
9801
|
+
if (memo.size > TAPSCRIPT_MEMO_MAX_ENTRIES) {
|
|
9802
|
+
memo.delete(memo.keys().next().value);
|
|
9803
|
+
}
|
|
9804
|
+
}
|
|
9805
|
+
}
|
|
9806
|
+
cache.set(script, tapscripts);
|
|
9729
9807
|
scripts.add(script);
|
|
9730
9808
|
} catch (err) {
|
|
9731
9809
|
failures.set(
|
|
@@ -9743,6 +9821,8 @@ var CHAIN_TIP_TIMEOUT_MS = 5e3;
|
|
|
9743
9821
|
var ContractManager = class _ContractManager {
|
|
9744
9822
|
config;
|
|
9745
9823
|
watcher;
|
|
9824
|
+
/** Per-sync tapscript caches start empty; this outlives them. Consumers only ever see clones. */
|
|
9825
|
+
tapscriptMemo = /* @__PURE__ */ new Map();
|
|
9746
9826
|
initialized = false;
|
|
9747
9827
|
eventCallbacks = /* @__PURE__ */ new Set();
|
|
9748
9828
|
stopWatcherFn;
|
|
@@ -9810,7 +9890,21 @@ var ContractManager = class _ContractManager {
|
|
|
9810
9890
|
}
|
|
9811
9891
|
markSyncOnline() {
|
|
9812
9892
|
this.lastSyncedAt = Date.now();
|
|
9813
|
-
this.syncDegradedReason = this.
|
|
9893
|
+
this.syncDegradedReason = this.syncGapReason();
|
|
9894
|
+
}
|
|
9895
|
+
/**
|
|
9896
|
+
* Why a sync that just succeeded still has not covered everything it should
|
|
9897
|
+
* have. Both reasons outlive the sync that failed to cover them, so neither
|
|
9898
|
+
* is discharged by the next one succeeding — which is the point: a wallet
|
|
9899
|
+
* that reported itself current while the look-ahead band sat behind the
|
|
9900
|
+
* watermark, or while a contract could not be annotated, would be claiming
|
|
9901
|
+
* coverage it never had. `getSyncState()` is the channel apps already watch.
|
|
9902
|
+
*/
|
|
9903
|
+
syncGapReason() {
|
|
9904
|
+
const annotations = this.annotationDegradedReason();
|
|
9905
|
+
const owedRefill = this.lookAheadRefillOwed ? "the look-ahead band is behind the allocation watermark, so a funded address inside it is not being watched yet" : void 0;
|
|
9906
|
+
const reasons = [annotations, owedRefill].filter((r) => r !== void 0);
|
|
9907
|
+
return reasons.length === 0 ? void 0 : reasons.join("; ");
|
|
9814
9908
|
}
|
|
9815
9909
|
/** Contracts a sync could not annotate, as `script → reason`. */
|
|
9816
9910
|
annotationFailures = /* @__PURE__ */ new Map();
|
|
@@ -9844,12 +9938,18 @@ var ContractManager = class _ContractManager {
|
|
|
9844
9938
|
for (const contract of contracts) {
|
|
9845
9939
|
await this.watcher.addContract(contract);
|
|
9846
9940
|
}
|
|
9847
|
-
|
|
9941
|
+
try {
|
|
9942
|
+
await this.scheduleLookAheadDrain();
|
|
9943
|
+
} catch (err) {
|
|
9944
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
9945
|
+
this.lookAheadRefillOwed = true;
|
|
9946
|
+
this.markSyncDegraded(err);
|
|
9947
|
+
}
|
|
9848
9948
|
try {
|
|
9849
9949
|
await this.reconcileWatched();
|
|
9850
9950
|
this.markSyncOnline();
|
|
9851
9951
|
} catch (err) {
|
|
9852
|
-
if (!
|
|
9952
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
9853
9953
|
this.markSyncDegraded(err);
|
|
9854
9954
|
}
|
|
9855
9955
|
this.initialized = true;
|
|
@@ -9981,7 +10081,7 @@ var ContractManager = class _ContractManager {
|
|
|
9981
10081
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
9982
10082
|
const to = watermark + lookAhead.size;
|
|
9983
10083
|
const deps = lookAhead.candidateDeps();
|
|
9984
|
-
const handlers =
|
|
10084
|
+
const handlers = chunkCQNX4BTA_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkCQNX4BTA_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
9985
10085
|
const band = /* @__PURE__ */ new Map();
|
|
9986
10086
|
for (let index = from; index <= to; index++) {
|
|
9987
10087
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -9992,7 +10092,7 @@ var ContractManager = class _ContractManager {
|
|
|
9992
10092
|
index,
|
|
9993
10093
|
params: {
|
|
9994
10094
|
...candidate,
|
|
9995
|
-
...
|
|
10095
|
+
...chunkCQNX4BTA_cjs.speculativeReceiveMetadata(descriptor)
|
|
9996
10096
|
}
|
|
9997
10097
|
});
|
|
9998
10098
|
}
|
|
@@ -10054,7 +10154,7 @@ var ContractManager = class _ContractManager {
|
|
|
10054
10154
|
});
|
|
10055
10155
|
for (const entry of pending) entry.catchUpPending = false;
|
|
10056
10156
|
} catch (err) {
|
|
10057
|
-
if (!
|
|
10157
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
10058
10158
|
this.markSyncDegraded(err);
|
|
10059
10159
|
}
|
|
10060
10160
|
}
|
|
@@ -10104,7 +10204,7 @@ var ContractManager = class _ContractManager {
|
|
|
10104
10204
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
10105
10205
|
this.markSyncOnline();
|
|
10106
10206
|
} catch (err) {
|
|
10107
|
-
if (!
|
|
10207
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
10108
10208
|
this.markSyncDegraded(err);
|
|
10109
10209
|
}
|
|
10110
10210
|
await this.watcher.addContract(contract);
|
|
@@ -10138,7 +10238,7 @@ var ContractManager = class _ContractManager {
|
|
|
10138
10238
|
await this.fetchContractVxosFromIndexer(fresh);
|
|
10139
10239
|
this.markSyncOnline();
|
|
10140
10240
|
} catch (err) {
|
|
10141
|
-
if (!
|
|
10241
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
10142
10242
|
this.markSyncDegraded(err);
|
|
10143
10243
|
}
|
|
10144
10244
|
for (const contract of fresh) await this.watcher.addContract(contract);
|
|
@@ -10176,7 +10276,7 @@ var ContractManager = class _ContractManager {
|
|
|
10176
10276
|
return result;
|
|
10177
10277
|
}
|
|
10178
10278
|
async upsertContractRow(params) {
|
|
10179
|
-
const handler =
|
|
10279
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(params.type);
|
|
10180
10280
|
if (!handler) {
|
|
10181
10281
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
10182
10282
|
}
|
|
@@ -10276,7 +10376,7 @@ var ContractManager = class _ContractManager {
|
|
|
10276
10376
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
10277
10377
|
);
|
|
10278
10378
|
}
|
|
10279
|
-
const registered =
|
|
10379
|
+
const registered = chunkCQNX4BTA_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkCQNX4BTA_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
10280
10380
|
const discoverables = [
|
|
10281
10381
|
...registered.filter((h) => h.type === "boarding"),
|
|
10282
10382
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -10414,7 +10514,7 @@ var ContractManager = class _ContractManager {
|
|
|
10414
10514
|
await this.syncContracts({ contracts, pageSize });
|
|
10415
10515
|
this.markSyncOnline();
|
|
10416
10516
|
} catch (err) {
|
|
10417
|
-
if (!
|
|
10517
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
10418
10518
|
this.markSyncDegraded(err);
|
|
10419
10519
|
}
|
|
10420
10520
|
}
|
|
@@ -10436,7 +10536,7 @@ var ContractManager = class _ContractManager {
|
|
|
10436
10536
|
}
|
|
10437
10537
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
10438
10538
|
return vtxos.map(
|
|
10439
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
10539
|
+
(vtxo) => extendVirtualCoinForContract(chunkP53OHGXY_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
10440
10540
|
);
|
|
10441
10541
|
}
|
|
10442
10542
|
/** @inheritdoc */
|
|
@@ -10447,7 +10547,8 @@ var ContractManager = class _ContractManager {
|
|
|
10447
10547
|
});
|
|
10448
10548
|
const { scripts, failures } = annotatableIn(
|
|
10449
10549
|
new Map(contracts.map((contract) => [contract.script, contract])),
|
|
10450
|
-
vtxos
|
|
10550
|
+
vtxos,
|
|
10551
|
+
this.tapscriptMemo
|
|
10451
10552
|
);
|
|
10452
10553
|
const orphans = vtxos.filter(
|
|
10453
10554
|
(vtxo) => !scripts.has(vtxo.script) && !failures.has(vtxo.script)
|
|
@@ -10480,14 +10581,14 @@ var ContractManager = class _ContractManager {
|
|
|
10480
10581
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10481
10582
|
const asking = vtxos.filter((vtxo) => {
|
|
10482
10583
|
const contract = byScript.get(vtxo.script);
|
|
10483
|
-
return contract !== void 0 &&
|
|
10584
|
+
return contract !== void 0 && chunkCQNX4BTA_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10484
10585
|
});
|
|
10485
10586
|
if (asking.length === 0) return refused;
|
|
10486
10587
|
const tip = await this.currentChainTip();
|
|
10487
10588
|
const walletKey = await walletPubKey?.();
|
|
10488
10589
|
for (const vtxo of asking) {
|
|
10489
10590
|
const contract = byScript.get(vtxo.script);
|
|
10490
|
-
const handler =
|
|
10591
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
10491
10592
|
if (!handler?.assertSpendableNow) continue;
|
|
10492
10593
|
const context = {
|
|
10493
10594
|
collaborative: true,
|
|
@@ -10502,7 +10603,7 @@ var ContractManager = class _ContractManager {
|
|
|
10502
10603
|
// the next handler to answer a CSV question would meet a
|
|
10503
10604
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
10504
10605
|
// really is one.
|
|
10505
|
-
vtxo:
|
|
10606
|
+
vtxo: chunkP53OHGXY_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10506
10607
|
};
|
|
10507
10608
|
try {
|
|
10508
10609
|
await handler.assertSpendableNow(
|
|
@@ -10598,6 +10699,7 @@ var ContractManager = class _ContractManager {
|
|
|
10598
10699
|
*/
|
|
10599
10700
|
async deleteContract(script) {
|
|
10600
10701
|
await this.config.contractRepository.deleteContract(script);
|
|
10702
|
+
this.tapscriptMemo.delete(script);
|
|
10601
10703
|
await this.watcher.removeContract(script);
|
|
10602
10704
|
}
|
|
10603
10705
|
/**
|
|
@@ -10658,7 +10760,7 @@ var ContractManager = class _ContractManager {
|
|
|
10658
10760
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
10659
10761
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10660
10762
|
if (!contract) return [];
|
|
10661
|
-
const handler =
|
|
10763
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
10662
10764
|
if (!handler) return [];
|
|
10663
10765
|
const script = handler.createScript(contract.params);
|
|
10664
10766
|
const tip = await this.currentChainTip();
|
|
@@ -10686,7 +10788,7 @@ var ContractManager = class _ContractManager {
|
|
|
10686
10788
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
10687
10789
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10688
10790
|
if (!contract) return [];
|
|
10689
|
-
const handler =
|
|
10791
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
10690
10792
|
if (!handler) return [];
|
|
10691
10793
|
const script = handler.createScript(contract.params);
|
|
10692
10794
|
const context = {
|
|
@@ -10742,7 +10844,7 @@ var ContractManager = class _ContractManager {
|
|
|
10742
10844
|
}
|
|
10743
10845
|
async refreshOutpoints(outpoints) {
|
|
10744
10846
|
if (outpoints.length === 0) return;
|
|
10745
|
-
const { vtxos } = await
|
|
10847
|
+
const { vtxos } = await chunkP53OHGXY_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10746
10848
|
outpoints
|
|
10747
10849
|
});
|
|
10748
10850
|
if (vtxos.length === 0) return;
|
|
@@ -10768,7 +10870,13 @@ var ContractManager = class _ContractManager {
|
|
|
10768
10870
|
if (contract) {
|
|
10769
10871
|
await saveVtxosForContract(this.config.walletRepository, contract, addressVtxos);
|
|
10770
10872
|
} else {
|
|
10771
|
-
await
|
|
10873
|
+
await inVtxoWriteOrder(
|
|
10874
|
+
this.config.walletRepository,
|
|
10875
|
+
async () => this.config.walletRepository.saveVtxos(
|
|
10876
|
+
address,
|
|
10877
|
+
applyRecordedSpends(this.config.walletRepository, addressVtxos)
|
|
10878
|
+
)
|
|
10879
|
+
);
|
|
10772
10880
|
}
|
|
10773
10881
|
}
|
|
10774
10882
|
}
|
|
@@ -10838,7 +10946,7 @@ var ContractManager = class _ContractManager {
|
|
|
10838
10946
|
break;
|
|
10839
10947
|
}
|
|
10840
10948
|
} catch (err) {
|
|
10841
|
-
if (!
|
|
10949
|
+
if (!chunkP53OHGXY_cjs.isRetryableProviderError(err)) throw err;
|
|
10842
10950
|
this.markSyncDegraded(err);
|
|
10843
10951
|
}
|
|
10844
10952
|
this.emitEvent(event);
|
|
@@ -10929,7 +11037,7 @@ var ContractManager = class _ContractManager {
|
|
|
10929
11037
|
*/
|
|
10930
11038
|
async reconcilePendingFrontier(contracts) {
|
|
10931
11039
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
10932
|
-
const vtxos = await
|
|
11040
|
+
const vtxos = await chunkP53OHGXY_cjs.getAllNormalizedVtxos(
|
|
10933
11041
|
this.config.indexerProvider,
|
|
10934
11042
|
contracts.map((c) => c.script),
|
|
10935
11043
|
{ pendingOnly: true }
|
|
@@ -10937,7 +11045,11 @@ var ContractManager = class _ContractManager {
|
|
|
10937
11045
|
for (const [script, contract] of await this.promoteLookAheadHits(vtxos)) {
|
|
10938
11046
|
scriptToContract.set(script, contract);
|
|
10939
11047
|
}
|
|
10940
|
-
const {
|
|
11048
|
+
const {
|
|
11049
|
+
scripts: annotatable,
|
|
11050
|
+
cache,
|
|
11051
|
+
failures
|
|
11052
|
+
} = annotatableIn(scriptToContract, vtxos, this.tapscriptMemo);
|
|
10941
11053
|
this.recordAnnotationFailures(annotatable, failures);
|
|
10942
11054
|
const owned = vtxos.filter((v) => annotatable.has(v.script));
|
|
10943
11055
|
const annotated = await this.annotateVtxos(owned, cache);
|
|
@@ -11012,7 +11124,7 @@ var ContractManager = class _ContractManager {
|
|
|
11012
11124
|
}
|
|
11013
11125
|
return result;
|
|
11014
11126
|
}
|
|
11015
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
11127
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkP53OHGXY_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
11016
11128
|
if (contracts.length === 0) {
|
|
11017
11129
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
11018
11130
|
}
|
|
@@ -11028,7 +11140,7 @@ var ContractManager = class _ContractManager {
|
|
|
11028
11140
|
before: syncWindow.before
|
|
11029
11141
|
}
|
|
11030
11142
|
} : {};
|
|
11031
|
-
const vtxos = await
|
|
11143
|
+
const vtxos = await chunkP53OHGXY_cjs.getAllNormalizedVtxos(
|
|
11032
11144
|
this.config.indexerProvider,
|
|
11033
11145
|
contracts.map((c) => c.script),
|
|
11034
11146
|
{ ...windowOpts, pageSize }
|
|
@@ -11037,7 +11149,11 @@ var ContractManager = class _ContractManager {
|
|
|
11037
11149
|
for (const [script, contract] of promoted) {
|
|
11038
11150
|
scriptToContract.set(script, contract);
|
|
11039
11151
|
}
|
|
11040
|
-
const {
|
|
11152
|
+
const {
|
|
11153
|
+
scripts: annotatable,
|
|
11154
|
+
cache,
|
|
11155
|
+
failures
|
|
11156
|
+
} = annotatableIn(scriptToContract, vtxos, this.tapscriptMemo);
|
|
11041
11157
|
this.recordAnnotationFailures(annotatable, failures);
|
|
11042
11158
|
const owned = vtxos.filter((v) => annotatable.has(v.script));
|
|
11043
11159
|
const annotated = await this.annotateVtxos(owned, cache);
|
|
@@ -11173,7 +11289,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
11173
11289
|
const s = base.hex.decode(t.s);
|
|
11174
11290
|
return [cb, s];
|
|
11175
11291
|
};
|
|
11176
|
-
var deserializeVtxo = (o) =>
|
|
11292
|
+
var deserializeVtxo = (o) => chunkP53OHGXY_cjs.normalizeVtxo({
|
|
11177
11293
|
...o,
|
|
11178
11294
|
createdAt: new Date(o.createdAt),
|
|
11179
11295
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11996,7 +12112,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11996
12112
|
*/
|
|
11997
12113
|
materializeDescriptorAt(index) {
|
|
11998
12114
|
const descriptor = this.identity.descriptor;
|
|
11999
|
-
const network =
|
|
12115
|
+
const network = chunkCQNX4BTA_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
12000
12116
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
12001
12117
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
12002
12118
|
if (!keyInfo?.keyExpression) {
|
|
@@ -12144,7 +12260,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12144
12260
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
12145
12261
|
if (!provider) return void 0;
|
|
12146
12262
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
12147
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
12263
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
12148
12264
|
const factoryOpts = {
|
|
12149
12265
|
walletRepository: setup.walletRepository,
|
|
12150
12266
|
contractRepository: setup.contractRepository,
|
|
@@ -12345,7 +12461,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12345
12461
|
};
|
|
12346
12462
|
function deriveLeafPubkey(descriptor) {
|
|
12347
12463
|
try {
|
|
12348
|
-
return
|
|
12464
|
+
return chunkCQNX4BTA_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
12349
12465
|
} catch (e) {
|
|
12350
12466
|
throw new NonRangeableDescriptorError(
|
|
12351
12467
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -12357,7 +12473,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12357
12473
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
12358
12474
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
12359
12475
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
12360
|
-
const csvTimelock =
|
|
12476
|
+
const csvTimelock = chunkP53OHGXY_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
12361
12477
|
const base$1 = {
|
|
12362
12478
|
script: base.hex.encode(tapscript.pkScript),
|
|
12363
12479
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -12368,11 +12484,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12368
12484
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
12369
12485
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
12370
12486
|
metadata: {
|
|
12371
|
-
...tagSource && { source:
|
|
12487
|
+
...tagSource && { source: chunkCQNX4BTA_cjs.WALLET_RECEIVE_SOURCE },
|
|
12372
12488
|
signingDescriptor: descriptor
|
|
12373
12489
|
}
|
|
12374
12490
|
};
|
|
12375
|
-
const params = tapscript instanceof
|
|
12491
|
+
const params = tapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? {
|
|
12376
12492
|
...base$1,
|
|
12377
12493
|
type: "delegate",
|
|
12378
12494
|
params: {
|
|
@@ -12393,10 +12509,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12393
12509
|
return { tapscript, params };
|
|
12394
12510
|
}
|
|
12395
12511
|
function rebuildTapscript(current, pubKey) {
|
|
12396
|
-
if (current instanceof
|
|
12397
|
-
return new
|
|
12512
|
+
if (current instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script) {
|
|
12513
|
+
return new chunkCQNX4BTA_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12398
12514
|
}
|
|
12399
|
-
return new
|
|
12515
|
+
return new chunkCQNX4BTA_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12400
12516
|
}
|
|
12401
12517
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12402
12518
|
const candidates = await contractRepository.getContracts({
|
|
@@ -12405,7 +12521,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
12405
12521
|
});
|
|
12406
12522
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
12407
12523
|
const matching = candidates.filter(
|
|
12408
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12524
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkCQNX4BTA_cjs.WALLET_RECEIVE_SOURCE
|
|
12409
12525
|
).sort((a, b) => {
|
|
12410
12526
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12411
12527
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12444,7 +12560,7 @@ async function resolveDescriptorProvider(config, walletRepository) {
|
|
|
12444
12560
|
|
|
12445
12561
|
// src/wallet/balance.ts
|
|
12446
12562
|
function computeOffchainBalance(vtxos, caps) {
|
|
12447
|
-
const { now, isPendingRecovery, isGenericallySpendable, isUnlocked } = caps;
|
|
12563
|
+
const { now, isPendingRecovery, isGenericallySpendable, isUnlocked, dustCarrier } = caps;
|
|
12448
12564
|
let settled = 0;
|
|
12449
12565
|
let preconfirmed = 0;
|
|
12450
12566
|
let available = 0;
|
|
@@ -12461,7 +12577,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12461
12577
|
}
|
|
12462
12578
|
};
|
|
12463
12579
|
for (const vtxo of vtxos) {
|
|
12464
|
-
if (
|
|
12580
|
+
if (chunkP53OHGXY_cjs.hasTerminalSpend(vtxo)) continue;
|
|
12465
12581
|
addAssets(owned, vtxo);
|
|
12466
12582
|
if (vtxo.isUnrolled) {
|
|
12467
12583
|
unrolled += vtxo.value;
|
|
@@ -12471,11 +12587,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12471
12587
|
pendingRecovery += vtxo.value;
|
|
12472
12588
|
continue;
|
|
12473
12589
|
}
|
|
12474
|
-
if (
|
|
12590
|
+
if (chunkP53OHGXY_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12475
12591
|
recoverable += vtxo.value;
|
|
12476
12592
|
continue;
|
|
12477
12593
|
}
|
|
12478
|
-
if (!
|
|
12594
|
+
if (!chunkP53OHGXY_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12479
12595
|
if (vtxo.isPreconfirmed) {
|
|
12480
12596
|
preconfirmed += vtxo.value;
|
|
12481
12597
|
} else {
|
|
@@ -12490,6 +12606,9 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12490
12606
|
addAssets(spendable, vtxo);
|
|
12491
12607
|
}
|
|
12492
12608
|
}
|
|
12609
|
+
if (available > 0 && spendable.size > 0) {
|
|
12610
|
+
available = Math.max(0, available - Number(dustCarrier));
|
|
12611
|
+
}
|
|
12493
12612
|
const toAssets = (from) => Array.from(from.entries()).map(([assetId, amount]) => ({ assetId, amount }));
|
|
12494
12613
|
return {
|
|
12495
12614
|
settled,
|
|
@@ -12547,8 +12666,9 @@ var InputSignerRouter = class {
|
|
|
12547
12666
|
async classify(jobs) {
|
|
12548
12667
|
const identityIndexes = [];
|
|
12549
12668
|
const descriptorGroups = /* @__PURE__ */ new Map();
|
|
12669
|
+
const unknownIndexes = [];
|
|
12550
12670
|
if (jobs.length === 0) {
|
|
12551
|
-
return { identityIndexes, descriptorGroups };
|
|
12671
|
+
return { identityIndexes, descriptorGroups, unknownIndexes };
|
|
12552
12672
|
}
|
|
12553
12673
|
const distinctScripts = Array.from(new Set(jobs.map((j) => base.hex.encode(j.lookupScript))));
|
|
12554
12674
|
const contracts = await this.deps.contractRepository.getContracts({
|
|
@@ -12568,6 +12688,8 @@ var InputSignerRouter = class {
|
|
|
12568
12688
|
if (!contract) {
|
|
12569
12689
|
if (scriptHex === boardingScriptHex) {
|
|
12570
12690
|
identityIndexes.push(job.index);
|
|
12691
|
+
} else {
|
|
12692
|
+
unknownIndexes.push(job.index);
|
|
12571
12693
|
}
|
|
12572
12694
|
continue;
|
|
12573
12695
|
}
|
|
@@ -12594,7 +12716,7 @@ var InputSignerRouter = class {
|
|
|
12594
12716
|
descriptorGroups.set(descriptor, [job.index]);
|
|
12595
12717
|
}
|
|
12596
12718
|
}
|
|
12597
|
-
return { identityIndexes, descriptorGroups };
|
|
12719
|
+
return { identityIndexes, descriptorGroups, unknownIndexes };
|
|
12598
12720
|
}
|
|
12599
12721
|
/**
|
|
12600
12722
|
* Returns `true` when every signable input across all `jobSets` resolves
|
|
@@ -12616,12 +12738,13 @@ var InputSignerRouter = class {
|
|
|
12616
12738
|
const plan = await this.classify(jobSets.flat());
|
|
12617
12739
|
return plan.descriptorGroups.size === 0;
|
|
12618
12740
|
}
|
|
12619
|
-
async sign(tx, jobs) {
|
|
12741
|
+
async sign(tx, jobs, opts) {
|
|
12620
12742
|
if (jobs.length === 0) return tx;
|
|
12621
|
-
const { identityIndexes, descriptorGroups } = await this.classify(jobs);
|
|
12743
|
+
const { identityIndexes, descriptorGroups, unknownIndexes } = await this.classify(jobs);
|
|
12744
|
+
const identitySignIndexes = opts?.onUnknownScript === "sign" ? [...identityIndexes, ...unknownIndexes] : identityIndexes;
|
|
12622
12745
|
let signed = tx;
|
|
12623
|
-
if (
|
|
12624
|
-
signed = await this.deps.identity.sign(signed,
|
|
12746
|
+
if (identitySignIndexes.length > 0) {
|
|
12747
|
+
signed = await this.deps.identity.sign(signed, identitySignIndexes);
|
|
12625
12748
|
}
|
|
12626
12749
|
if (descriptorGroups.size > 0) {
|
|
12627
12750
|
if (!this.deps.descriptorProvider) {
|
|
@@ -12645,12 +12768,12 @@ var InputSignerRouter = class {
|
|
|
12645
12768
|
};
|
|
12646
12769
|
|
|
12647
12770
|
// src/wallet/wallet.ts
|
|
12648
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
12771
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkP53OHGXY_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12649
12772
|
function intentProofJobs(coins) {
|
|
12650
12773
|
if (coins.length === 0) return [];
|
|
12651
12774
|
const coinJobs = coins.map((coin, i) => ({
|
|
12652
12775
|
index: i + 1,
|
|
12653
|
-
lookupScript:
|
|
12776
|
+
lookupScript: chunkP53OHGXY_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12654
12777
|
}));
|
|
12655
12778
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12656
12779
|
}
|
|
@@ -12682,7 +12805,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12682
12805
|
const seen = /* @__PURE__ */ new Set();
|
|
12683
12806
|
const deduped = [];
|
|
12684
12807
|
for (const timelock of timelocks) {
|
|
12685
|
-
const sequence =
|
|
12808
|
+
const sequence = chunkP53OHGXY_cjs.timelockToSequence(timelock).toString();
|
|
12686
12809
|
if (seen.has(sequence)) continue;
|
|
12687
12810
|
seen.add(sequence);
|
|
12688
12811
|
deduped.push(timelock);
|
|
@@ -12699,7 +12822,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12699
12822
|
state: "active"
|
|
12700
12823
|
});
|
|
12701
12824
|
const newest = candidates.filter(
|
|
12702
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12825
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkCQNX4BTA_cjs.WALLET_RECEIVE_SOURCE
|
|
12703
12826
|
).sort((a, b) => {
|
|
12704
12827
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12705
12828
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12707,7 +12830,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12707
12830
|
if (!newest?.params.pubKey) return baseline;
|
|
12708
12831
|
try {
|
|
12709
12832
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12710
|
-
return new
|
|
12833
|
+
return new chunkCQNX4BTA_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12711
12834
|
} catch (e) {
|
|
12712
12835
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12713
12836
|
return baseline;
|
|
@@ -12726,10 +12849,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12726
12849
|
if (vtxo.isUnrolled) {
|
|
12727
12850
|
return !!f.withUnrolled;
|
|
12728
12851
|
}
|
|
12729
|
-
if (
|
|
12852
|
+
if (chunkP53OHGXY_cjs.hasTerminalSpend(vtxo)) {
|
|
12730
12853
|
return false;
|
|
12731
12854
|
}
|
|
12732
|
-
if (!f.withRecoverable &&
|
|
12855
|
+
if (!f.withRecoverable && chunkP53OHGXY_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12733
12856
|
return false;
|
|
12734
12857
|
}
|
|
12735
12858
|
return true;
|
|
@@ -13069,7 +13192,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13069
13192
|
*/
|
|
13070
13193
|
static async setupWalletConfig(config, pubKey) {
|
|
13071
13194
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
13072
|
-
const arkProvider = config.arkProvider || new
|
|
13195
|
+
const arkProvider = config.arkProvider || new chunkP53OHGXY_cjs.RestArkProvider(arkadeServerUrl);
|
|
13073
13196
|
let indexerProvider = config.indexerProvider;
|
|
13074
13197
|
if (!indexerProvider) {
|
|
13075
13198
|
let indexerUrl = config.indexerUrl;
|
|
@@ -13086,7 +13209,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13086
13209
|
indexerUrl = arkadeServerUrl;
|
|
13087
13210
|
}
|
|
13088
13211
|
}
|
|
13089
|
-
indexerProvider = new
|
|
13212
|
+
indexerProvider = new chunkT327OEMV_cjs.RestIndexerProvider(indexerUrl);
|
|
13090
13213
|
}
|
|
13091
13214
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
13092
13215
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -13095,7 +13218,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13095
13218
|
source: serverInfoSource,
|
|
13096
13219
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
13097
13220
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
13098
|
-
const network =
|
|
13221
|
+
const network = chunkP53OHGXY_cjs.getNetwork(info.network);
|
|
13099
13222
|
if ("descriptor" in config.identity) {
|
|
13100
13223
|
const descriptor = config.identity.descriptor;
|
|
13101
13224
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -13135,18 +13258,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13135
13258
|
value: info.boardingExitDelay,
|
|
13136
13259
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
13137
13260
|
};
|
|
13138
|
-
const serverPubKey =
|
|
13139
|
-
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) =>
|
|
13261
|
+
const serverPubKey = chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
13262
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
|
|
13140
13263
|
const offchainOptions = {
|
|
13141
13264
|
pubKey,
|
|
13142
13265
|
serverPubKey,
|
|
13143
13266
|
csvTimelock: exitTimelock
|
|
13144
13267
|
};
|
|
13145
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
13146
|
-
const boardingTapscript =
|
|
13268
|
+
const offchainTapscript = !delegatePubKey ? new chunkCQNX4BTA_cjs.DefaultVtxo.Script(offchainOptions) : new chunkCQNX4BTA_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
13269
|
+
const boardingTapscript = chunkCQNX4BTA_cjs.BoardingContractHandler.createScript({
|
|
13147
13270
|
pubKey: base.hex.encode(pubKey),
|
|
13148
13271
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13149
|
-
csvTimelock:
|
|
13272
|
+
csvTimelock: chunkP53OHGXY_cjs.timelockToSequence(boardingTimelock).toString()
|
|
13150
13273
|
});
|
|
13151
13274
|
return {
|
|
13152
13275
|
arkProvider,
|
|
@@ -13312,7 +13435,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13312
13435
|
if (!filter?.withUnrolled) {
|
|
13313
13436
|
logExcludedVtxos(
|
|
13314
13437
|
"getSpendableVtxos",
|
|
13315
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
13438
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkP53OHGXY_cjs.hasTerminalSpend(vtxo)),
|
|
13316
13439
|
[() => UNROLLED_REASON]
|
|
13317
13440
|
);
|
|
13318
13441
|
}
|
|
@@ -13412,7 +13535,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13412
13535
|
now: { timestamp: /* @__PURE__ */ new Date() },
|
|
13413
13536
|
isPendingRecovery: (vtxo) => pendingRecovery.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
13414
13537
|
isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
|
|
13415
|
-
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
13538
|
+
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
13539
|
+
dustCarrier: getDustAmount(this)
|
|
13416
13540
|
};
|
|
13417
13541
|
}
|
|
13418
13542
|
/**
|
|
@@ -13456,7 +13580,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13456
13580
|
this.getBoardingTxs()
|
|
13457
13581
|
]);
|
|
13458
13582
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
13459
|
-
const resolveTxCreatedAt = (txids) =>
|
|
13583
|
+
const resolveTxCreatedAt = (txids) => chunkP53OHGXY_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13460
13584
|
return buildTransactionHistory(
|
|
13461
13585
|
allVtxos,
|
|
13462
13586
|
boardingTxs,
|
|
@@ -13551,7 +13675,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13551
13675
|
},
|
|
13552
13676
|
isUnrolled: true,
|
|
13553
13677
|
...boardingFacts,
|
|
13554
|
-
virtualStatus:
|
|
13678
|
+
virtualStatus: chunkP53OHGXY_cjs.toVirtualStatus(boardingFacts),
|
|
13555
13679
|
spentBy: "",
|
|
13556
13680
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
13557
13681
|
script: scriptHex
|
|
@@ -13607,9 +13731,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13607
13731
|
async getBoardingTapscripts(allowedSigners) {
|
|
13608
13732
|
const byScript = /* @__PURE__ */ new Map();
|
|
13609
13733
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
13610
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13734
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkCQNX4BTA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13611
13735
|
add(
|
|
13612
|
-
new
|
|
13736
|
+
new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
13613
13737
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
13614
13738
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
13615
13739
|
csvTimelock: boardingCsv
|
|
@@ -13624,7 +13748,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13624
13748
|
for (const c of boardingContracts) {
|
|
13625
13749
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
13626
13750
|
try {
|
|
13627
|
-
add(
|
|
13751
|
+
add(chunkCQNX4BTA_cjs.BoardingContractHandler.createScript(c.params));
|
|
13628
13752
|
} catch (e) {
|
|
13629
13753
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
13630
13754
|
}
|
|
@@ -13648,23 +13772,26 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13648
13772
|
*/
|
|
13649
13773
|
async getBoardingUtxosForSigners(allowedSigners) {
|
|
13650
13774
|
const tapscripts = await this.getBoardingTapscripts(allowedSigners);
|
|
13651
|
-
const
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
})
|
|
13775
|
+
const addresses = tapscripts.map((tapscript) => tapscript.onchainAddress(this.network));
|
|
13776
|
+
const groups = await Promise.all(
|
|
13777
|
+
tapscripts.map(async (tapscript, i) => {
|
|
13778
|
+
const coins = await this.onchainProvider.getCoins(addresses[i]);
|
|
13779
|
+
const utxos = coins.map((utxo) => extendCoinWithTapscript(tapscript, utxo));
|
|
13780
|
+
return {
|
|
13781
|
+
tapscript,
|
|
13782
|
+
// Normalize so the group key matches the axis/contract x-only
|
|
13783
|
+
// form regardless of how the tapscript's key was stored.
|
|
13784
|
+
serverPubKey: toXOnlySignerHex(base.hex.encode(tapscript.options.serverPubKey)),
|
|
13785
|
+
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13786
|
+
// not the wallet's current boarding timelock, which a signer
|
|
13787
|
+
// rotation may have changed.
|
|
13788
|
+
csvTimelock: chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13789
|
+
coins: utxos
|
|
13790
|
+
};
|
|
13791
|
+
})
|
|
13792
|
+
);
|
|
13793
|
+
for (const [i, group] of groups.entries()) {
|
|
13794
|
+
await this.walletRepository.saveUtxos(addresses[i], group.coins);
|
|
13668
13795
|
}
|
|
13669
13796
|
return groups;
|
|
13670
13797
|
}
|
|
@@ -13795,7 +13922,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13795
13922
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13796
13923
|
async fetchPendingTxs() {
|
|
13797
13924
|
const scripts = await this.getWalletScripts();
|
|
13798
|
-
const vtxos = await
|
|
13925
|
+
const vtxos = await chunkP53OHGXY_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13799
13926
|
return vtxos.filter(
|
|
13800
13927
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13801
13928
|
).map((_) => _.arkTxId);
|
|
@@ -13826,7 +13953,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13826
13953
|
});
|
|
13827
13954
|
for (const contract of contracts) {
|
|
13828
13955
|
if (map.has(contract.script)) continue;
|
|
13829
|
-
const handler =
|
|
13956
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
13830
13957
|
if (handler) {
|
|
13831
13958
|
const script = handler.createScript(contract.params);
|
|
13832
13959
|
map.set(contract.script, script);
|
|
@@ -13938,7 +14065,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13938
14065
|
}
|
|
13939
14066
|
});
|
|
13940
14067
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
13941
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14068
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
13942
14069
|
const baselineSigners = [
|
|
13943
14070
|
this.offchainTapscript.options.serverPubKey,
|
|
13944
14071
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -13946,8 +14073,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13946
14073
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
13947
14074
|
for (const serverPubKey of baselineSigners) {
|
|
13948
14075
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
13949
|
-
const csvTimelockStr =
|
|
13950
|
-
const defaultScript = new
|
|
14076
|
+
const csvTimelockStr = chunkP53OHGXY_cjs.timelockToSequence(csvTimelock).toString();
|
|
14077
|
+
const defaultScript = new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
13951
14078
|
pubKey: baselinePubkey,
|
|
13952
14079
|
serverPubKey,
|
|
13953
14080
|
csvTimelock
|
|
@@ -13968,7 +14095,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13968
14095
|
});
|
|
13969
14096
|
}
|
|
13970
14097
|
if (delegatePubKey) {
|
|
13971
|
-
const delegateScript = new
|
|
14098
|
+
const delegateScript = new chunkCQNX4BTA_cjs.DelegateVtxo.Script({
|
|
13972
14099
|
pubKey: baselinePubkey,
|
|
13973
14100
|
serverPubKey,
|
|
13974
14101
|
delegatePubKey,
|
|
@@ -13992,9 +14119,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13992
14119
|
}
|
|
13993
14120
|
}
|
|
13994
14121
|
}
|
|
13995
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
14122
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkCQNX4BTA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13996
14123
|
for (const serverPubKey of baselineSigners) {
|
|
13997
|
-
const baselineBoarding = new
|
|
14124
|
+
const baselineBoarding = new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
13998
14125
|
pubKey: baselinePubkey,
|
|
13999
14126
|
serverPubKey,
|
|
14000
14127
|
csvTimelock: boardingCsvTimelock
|
|
@@ -14007,7 +14134,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14007
14134
|
params: {
|
|
14008
14135
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14009
14136
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
14010
|
-
csvTimelock:
|
|
14137
|
+
csvTimelock: chunkP53OHGXY_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14011
14138
|
},
|
|
14012
14139
|
script: boardingScriptHex,
|
|
14013
14140
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -14207,7 +14334,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14207
14334
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
14208
14335
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
14209
14336
|
csvTimelocks: this.walletContractTimelocks,
|
|
14210
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
14337
|
+
delegatePubKey: this.offchainTapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
14211
14338
|
};
|
|
14212
14339
|
}
|
|
14213
14340
|
_signerRouter;
|
|
@@ -14452,7 +14579,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14452
14579
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14453
14580
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14454
14581
|
if (typeof persisted === "string") return persisted;
|
|
14455
|
-
return
|
|
14582
|
+
return chunkCQNX4BTA_cjs.identityDescriptor(this.identity);
|
|
14456
14583
|
}
|
|
14457
14584
|
/**
|
|
14458
14585
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -14468,7 +14595,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14468
14595
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14469
14596
|
if (type === "boarding") {
|
|
14470
14597
|
const built2 = this.buildBoardingContract(
|
|
14471
|
-
|
|
14598
|
+
chunkCQNX4BTA_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14472
14599
|
descriptor,
|
|
14473
14600
|
tagSource
|
|
14474
14601
|
);
|
|
@@ -14513,11 +14640,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14513
14640
|
* {@link buildReceiveContract}.
|
|
14514
14641
|
*/
|
|
14515
14642
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14516
|
-
const tapscript = new
|
|
14643
|
+
const tapscript = new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
14517
14644
|
...this._boardingTapscript.options,
|
|
14518
14645
|
pubKey
|
|
14519
14646
|
});
|
|
14520
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
14647
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkCQNX4BTA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14521
14648
|
return {
|
|
14522
14649
|
tapscript,
|
|
14523
14650
|
params: {
|
|
@@ -14525,13 +14652,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14525
14652
|
params: {
|
|
14526
14653
|
pubKey: base.hex.encode(pubKey),
|
|
14527
14654
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14528
|
-
csvTimelock:
|
|
14655
|
+
csvTimelock: chunkP53OHGXY_cjs.timelockToSequence(csvTimelock).toString()
|
|
14529
14656
|
},
|
|
14530
14657
|
script: base.hex.encode(tapscript.pkScript),
|
|
14531
14658
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14532
14659
|
state: "active",
|
|
14533
14660
|
metadata: {
|
|
14534
|
-
...tagSource && { source:
|
|
14661
|
+
...tagSource && { source: chunkCQNX4BTA_cjs.WALLET_RECEIVE_SOURCE },
|
|
14535
14662
|
signingDescriptor: descriptor
|
|
14536
14663
|
}
|
|
14537
14664
|
}
|
|
@@ -14560,7 +14687,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14560
14687
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
14561
14688
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14562
14689
|
}
|
|
14563
|
-
return
|
|
14690
|
+
return chunkCQNX4BTA_cjs.identityDescriptor(this.identity);
|
|
14564
14691
|
}
|
|
14565
14692
|
/**
|
|
14566
14693
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14656,7 +14783,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14656
14783
|
* the stable public API.
|
|
14657
14784
|
*/
|
|
14658
14785
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14659
|
-
const xonly =
|
|
14786
|
+
const xonly = chunkCQNX4BTA_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14660
14787
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14661
14788
|
checkpointTapscript,
|
|
14662
14789
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14685,21 +14812,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14685
14812
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14686
14813
|
script: currentBoardingScript
|
|
14687
14814
|
});
|
|
14688
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14815
|
+
const newOffchain = this.offchainTapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? new chunkCQNX4BTA_cjs.DelegateVtxo.Script({
|
|
14689
14816
|
...this.offchainTapscript.options,
|
|
14690
14817
|
serverPubKey: xonly
|
|
14691
|
-
}) : new
|
|
14818
|
+
}) : new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
14692
14819
|
...this.offchainTapscript.options,
|
|
14693
14820
|
serverPubKey: xonly
|
|
14694
14821
|
});
|
|
14695
|
-
const newBoarding = new
|
|
14822
|
+
const newBoarding = new chunkCQNX4BTA_cjs.DefaultVtxo.Script({
|
|
14696
14823
|
...this._boardingTapscript.options,
|
|
14697
14824
|
serverPubKey: xonly
|
|
14698
14825
|
});
|
|
14699
|
-
const offchainCsv =
|
|
14826
|
+
const offchainCsv = chunkP53OHGXY_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14700
14827
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14701
14828
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14702
|
-
if (newOffchain instanceof
|
|
14829
|
+
if (newOffchain instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script) {
|
|
14703
14830
|
await manager.createContract({
|
|
14704
14831
|
type: "delegate",
|
|
14705
14832
|
params: {
|
|
@@ -14727,13 +14854,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14727
14854
|
metadata: currentOffchainRow?.metadata
|
|
14728
14855
|
});
|
|
14729
14856
|
}
|
|
14730
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14857
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkCQNX4BTA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14731
14858
|
await manager.createContract({
|
|
14732
14859
|
type: "boarding",
|
|
14733
14860
|
params: {
|
|
14734
14861
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14735
14862
|
serverPubKey: base.hex.encode(xonly),
|
|
14736
|
-
csvTimelock:
|
|
14863
|
+
csvTimelock: chunkP53OHGXY_cjs.timelockToSequence(boardingCsv).toString()
|
|
14737
14864
|
},
|
|
14738
14865
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14739
14866
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14766,14 +14893,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14766
14893
|
_restoreInFlight;
|
|
14767
14894
|
_addPendingSpends(inputs) {
|
|
14768
14895
|
for (const input of inputs) {
|
|
14769
|
-
if (
|
|
14896
|
+
if (chunkP53OHGXY_cjs.isVirtualCoin(input)) {
|
|
14770
14897
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14771
14898
|
}
|
|
14772
14899
|
}
|
|
14773
14900
|
}
|
|
14774
14901
|
_removePendingSpends(inputs) {
|
|
14775
14902
|
for (const input of inputs) {
|
|
14776
|
-
if (
|
|
14903
|
+
if (chunkP53OHGXY_cjs.isVirtualCoin(input)) {
|
|
14777
14904
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14778
14905
|
}
|
|
14779
14906
|
}
|
|
@@ -14834,13 +14961,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14834
14961
|
const manager = await this.getContractManager();
|
|
14835
14962
|
const provider = this._descriptorProvider;
|
|
14836
14963
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14837
|
-
const staticDescriptor = hd ? void 0 : await
|
|
14964
|
+
const staticDescriptor = hd ? void 0 : await chunkCQNX4BTA_cjs.identityDescriptor(this.identity);
|
|
14838
14965
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14839
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14966
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkCQNX4BTA_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14840
14967
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14841
|
-
const currentSignerPubKey =
|
|
14968
|
+
const currentSignerPubKey = chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14842
14969
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14843
|
-
(s) =>
|
|
14970
|
+
(s) => chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14844
14971
|
);
|
|
14845
14972
|
const deps = {
|
|
14846
14973
|
indexerProvider: this.indexerProvider,
|
|
@@ -14855,7 +14982,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14855
14982
|
csvTimelocks: this.walletContractTimelocks,
|
|
14856
14983
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14857
14984
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14858
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
14985
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkCQNX4BTA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14859
14986
|
delegatePubKey
|
|
14860
14987
|
};
|
|
14861
14988
|
const result = await manager.scanContracts({
|
|
@@ -14969,7 +15096,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14969
15096
|
throw new Error("Invalid configured public key");
|
|
14970
15097
|
}
|
|
14971
15098
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
14972
|
-
const forfeitPubkey =
|
|
15099
|
+
const forfeitPubkey = chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
14973
15100
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
14974
15101
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
14975
15102
|
const checkpointExitDelayOverrides = {
|
|
@@ -15118,7 +15245,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15118
15245
|
inputs: params.selectedVtxos,
|
|
15119
15246
|
changeAmount: BigInt(changeAmount)
|
|
15120
15247
|
};
|
|
15121
|
-
const outputAddress =
|
|
15248
|
+
const outputAddress = chunkP53OHGXY_cjs.ArkAddress.decode(params.address);
|
|
15122
15249
|
assertRecipientArkAddress(
|
|
15123
15250
|
params.address,
|
|
15124
15251
|
outputAddress,
|
|
@@ -15184,13 +15311,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15184
15311
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
15185
15312
|
}
|
|
15186
15313
|
const offchainAddress = await this.getAddress();
|
|
15187
|
-
const offchainPkScript =
|
|
15314
|
+
const offchainPkScript = chunkP53OHGXY_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
15188
15315
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
15189
15316
|
if (!params) {
|
|
15190
15317
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
15191
15318
|
const estimator = new Estimator(fees.intentFee);
|
|
15192
15319
|
let amount = 0;
|
|
15193
|
-
const exitScript =
|
|
15320
|
+
const exitScript = chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(
|
|
15194
15321
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
15195
15322
|
);
|
|
15196
15323
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -15219,7 +15346,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15219
15346
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
15220
15347
|
break;
|
|
15221
15348
|
}
|
|
15222
|
-
const inputFee = estimator.evalOffchainInput(
|
|
15349
|
+
const inputFee = estimator.evalOffchainInput(chunkP53OHGXY_cjs.toOffchainInputFeeParams(vtxo));
|
|
15223
15350
|
if (inputFee.satoshis >= vtxo.value) {
|
|
15224
15351
|
continue;
|
|
15225
15352
|
}
|
|
@@ -15266,7 +15393,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15266
15393
|
let script;
|
|
15267
15394
|
let arkAddress;
|
|
15268
15395
|
try {
|
|
15269
|
-
arkAddress =
|
|
15396
|
+
arkAddress = chunkP53OHGXY_cjs.ArkAddress.decode(output.address);
|
|
15270
15397
|
} catch {
|
|
15271
15398
|
arkAddress = void 0;
|
|
15272
15399
|
}
|
|
@@ -15356,7 +15483,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15356
15483
|
const abortController = new AbortController();
|
|
15357
15484
|
let stream;
|
|
15358
15485
|
let committedTxid;
|
|
15359
|
-
const settleInputVtxos = params.inputs.filter(
|
|
15486
|
+
const settleInputVtxos = params.inputs.filter(chunkP53OHGXY_cjs.isVirtualCoin);
|
|
15360
15487
|
const contractManager = await this.getContractManager();
|
|
15361
15488
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15362
15489
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15468,7 +15595,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15468
15595
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15469
15596
|
if (!this._descriptorProvider) return;
|
|
15470
15597
|
const consumedBoarding = inputs.some(
|
|
15471
|
-
(input) => typeof input !== "string" && !
|
|
15598
|
+
(input) => typeof input !== "string" && !chunkP53OHGXY_cjs.isVirtualCoin(input)
|
|
15472
15599
|
);
|
|
15473
15600
|
if (!consumedBoarding) return;
|
|
15474
15601
|
try {
|
|
@@ -15492,7 +15619,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15492
15619
|
let connectorIndex = 0;
|
|
15493
15620
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15494
15621
|
for (const input of inputs) {
|
|
15495
|
-
if (!
|
|
15622
|
+
if (!chunkP53OHGXY_cjs.isVirtualCoin(input)) {
|
|
15496
15623
|
let matched = false;
|
|
15497
15624
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15498
15625
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -15530,7 +15657,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15530
15657
|
}
|
|
15531
15658
|
continue;
|
|
15532
15659
|
}
|
|
15533
|
-
if (
|
|
15660
|
+
if (chunkP53OHGXY_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15534
15661
|
continue;
|
|
15535
15662
|
}
|
|
15536
15663
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15558,7 +15685,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15558
15685
|
index: input.vout,
|
|
15559
15686
|
witnessUtxo: {
|
|
15560
15687
|
amount: BigInt(input.value),
|
|
15561
|
-
script:
|
|
15688
|
+
script: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15562
15689
|
},
|
|
15563
15690
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15564
15691
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15577,7 +15704,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15577
15704
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15578
15705
|
{
|
|
15579
15706
|
index: 0,
|
|
15580
|
-
lookupScript:
|
|
15707
|
+
lookupScript: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15581
15708
|
}
|
|
15582
15709
|
]);
|
|
15583
15710
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15635,7 +15762,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15635
15762
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15636
15763
|
);
|
|
15637
15764
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15638
|
-
const sweepTapscript =
|
|
15765
|
+
const sweepTapscript = chunkP53OHGXY_cjs.CSVMultisigTapscript.encode({
|
|
15639
15766
|
timelock,
|
|
15640
15767
|
pubkeys: [this.forfeitPubkey]
|
|
15641
15768
|
}).script;
|
|
@@ -15650,10 +15777,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15650
15777
|
throw new Error("Sweep tap tree root not set");
|
|
15651
15778
|
}
|
|
15652
15779
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15653
|
-
(k) => base.hex.encode(
|
|
15780
|
+
(k) => base.hex.encode(chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15654
15781
|
);
|
|
15655
15782
|
const signerPublicKey = await session.getPublicKey();
|
|
15656
|
-
const xonlySignerPublicKey =
|
|
15783
|
+
const xonlySignerPublicKey = chunkCQNX4BTA_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15657
15784
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15658
15785
|
return { skip: true };
|
|
15659
15786
|
}
|
|
@@ -15743,9 +15870,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15743
15870
|
...existing ?? {},
|
|
15744
15871
|
intentTxId,
|
|
15745
15872
|
registerProof: intent.proof,
|
|
15746
|
-
registerProofMessage:
|
|
15873
|
+
registerProofMessage: chunkP53OHGXY_cjs.Intent.encodeMessage(intent.message),
|
|
15747
15874
|
deleteProof: deleteIntent.proof,
|
|
15748
|
-
deleteProofMessage:
|
|
15875
|
+
deleteProofMessage: chunkP53OHGXY_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15749
15876
|
intentVtxos: inputs.map((i) => ({
|
|
15750
15877
|
txid: i.txid,
|
|
15751
15878
|
vout: i.vout
|
|
@@ -15760,15 +15887,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15760
15887
|
console.error(`Failed to persist intent ${intentTxId} (state=${state})`, e);
|
|
15761
15888
|
}
|
|
15762
15889
|
}
|
|
15763
|
-
|
|
15764
|
-
|
|
15765
|
-
|
|
15766
|
-
|
|
15767
|
-
|
|
15768
|
-
|
|
15769
|
-
|
|
15770
|
-
|
|
15771
|
-
|
|
15890
|
+
async signInputsByWitnessScript(tx) {
|
|
15891
|
+
const signed = await this._signerRouter.sign(
|
|
15892
|
+
tx,
|
|
15893
|
+
this.inputSigningJobsFromWitnessUtxos(tx),
|
|
15894
|
+
{
|
|
15895
|
+
onUnknownScript: "sign"
|
|
15896
|
+
}
|
|
15897
|
+
);
|
|
15898
|
+
return signed;
|
|
15899
|
+
}
|
|
15772
15900
|
async signOnchainBoardingTx(tx) {
|
|
15773
15901
|
const signed = await this._signerRouter.sign(tx, this.inputSigningJobsFromWitnessUtxos(tx));
|
|
15774
15902
|
return signed;
|
|
@@ -15777,7 +15905,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15777
15905
|
try {
|
|
15778
15906
|
return await this.arkProvider.registerIntent(intent);
|
|
15779
15907
|
} catch (error) {
|
|
15780
|
-
if (error instanceof
|
|
15908
|
+
if (error instanceof chunkP53OHGXY_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15781
15909
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15782
15910
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15783
15911
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15793,7 +15921,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15793
15921
|
expire_at: 0,
|
|
15794
15922
|
cosigners_public_keys: cosignerPubKeys
|
|
15795
15923
|
};
|
|
15796
|
-
const proof =
|
|
15924
|
+
const proof = chunkP53OHGXY_cjs.Intent.create(message, coins, outputs);
|
|
15797
15925
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15798
15926
|
return {
|
|
15799
15927
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15805,7 +15933,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15805
15933
|
type: "delete",
|
|
15806
15934
|
expire_at: 0
|
|
15807
15935
|
};
|
|
15808
|
-
const proof =
|
|
15936
|
+
const proof = chunkP53OHGXY_cjs.Intent.create(message, coins, []);
|
|
15809
15937
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15810
15938
|
return {
|
|
15811
15939
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15817,7 +15945,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15817
15945
|
type: "get-pending-tx",
|
|
15818
15946
|
expire_at: 0
|
|
15819
15947
|
};
|
|
15820
|
-
const proof =
|
|
15948
|
+
const proof = chunkP53OHGXY_cjs.Intent.create(message, coins, []);
|
|
15821
15949
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15822
15950
|
return {
|
|
15823
15951
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15838,7 +15966,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15838
15966
|
if (!vtxos || vtxos.length === 0) {
|
|
15839
15967
|
const scriptMap = await this.getScriptMap();
|
|
15840
15968
|
const allExtended = [];
|
|
15841
|
-
const fetchedVtxos = await
|
|
15969
|
+
const fetchedVtxos = await chunkP53OHGXY_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15842
15970
|
...scriptMap.keys()
|
|
15843
15971
|
]);
|
|
15844
15972
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -15882,7 +16010,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15882
16010
|
try {
|
|
15883
16011
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
15884
16012
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
15885
|
-
|
|
16013
|
+
chunkP53OHGXY_cjs.assertAllowedSighashTypes(tx);
|
|
15886
16014
|
return tx;
|
|
15887
16015
|
});
|
|
15888
16016
|
assertCheckpointsMatchInputs(
|
|
@@ -15954,11 +16082,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15954
16082
|
* against the current key alone would leave it pending forever.
|
|
15955
16083
|
*/
|
|
15956
16084
|
checkpointUnrollCandidates(info) {
|
|
15957
|
-
const current =
|
|
16085
|
+
const current = chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
15958
16086
|
const candidates = [this._serverUnrollScript, current];
|
|
15959
16087
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
15960
16088
|
candidates.push(
|
|
15961
|
-
|
|
16089
|
+
chunkP53OHGXY_cjs.CSVMultisigTapscript.encode({
|
|
15962
16090
|
...current.params,
|
|
15963
16091
|
pubkeys: [base.hex.decode(deprecated)]
|
|
15964
16092
|
})
|
|
@@ -16049,7 +16177,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16049
16177
|
if (vtxos.length === 0) {
|
|
16050
16178
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
16051
16179
|
}
|
|
16052
|
-
const myPkScript =
|
|
16180
|
+
const myPkScript = chunkP53OHGXY_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
16053
16181
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
16054
16182
|
let swept = 0;
|
|
16055
16183
|
const drainable = vtxos.filter(
|
|
@@ -16125,7 +16253,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16125
16253
|
const spendable = [];
|
|
16126
16254
|
const unclaimed = [];
|
|
16127
16255
|
for (const vtxo of vtxos) {
|
|
16128
|
-
if (
|
|
16256
|
+
if (chunkP53OHGXY_cjs.hasTerminalSpend(vtxo)) {
|
|
16129
16257
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
16130
16258
|
} else if (vtxo.isUnrolled) {
|
|
16131
16259
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -16147,7 +16275,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16147
16275
|
const all = [];
|
|
16148
16276
|
const seen = /* @__PURE__ */ new Set();
|
|
16149
16277
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
16150
|
-
const { vtxos, page } = await
|
|
16278
|
+
const { vtxos, page } = await chunkP53OHGXY_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
16151
16279
|
scripts,
|
|
16152
16280
|
pageIndex,
|
|
16153
16281
|
pageSize
|
|
@@ -16194,7 +16322,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16194
16322
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
16195
16323
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
16196
16324
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
16197
|
-
const proof =
|
|
16325
|
+
const proof = chunkP53OHGXY_cjs.Intent.create(message, batch, []);
|
|
16198
16326
|
const signedProof = await identity.sign(
|
|
16199
16327
|
proof,
|
|
16200
16328
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -16216,7 +16344,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16216
16344
|
try {
|
|
16217
16345
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
16218
16346
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
16219
|
-
|
|
16347
|
+
chunkP53OHGXY_cjs.assertAllowedSighashTypes(tx);
|
|
16220
16348
|
return tx;
|
|
16221
16349
|
});
|
|
16222
16350
|
assertCheckpointsMatchInputs(
|
|
@@ -16415,7 +16543,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16415
16543
|
script: recipient.script,
|
|
16416
16544
|
amount: BigInt(recipient.amount),
|
|
16417
16545
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16418
|
-
...recipient.tapTree ? { tapTree:
|
|
16546
|
+
...recipient.tapTree ? { tapTree: chunkP53OHGXY_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
16419
16547
|
}));
|
|
16420
16548
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16421
16549
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -16559,10 +16687,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16559
16687
|
const serverPubKey = this.arkServerPublicKey;
|
|
16560
16688
|
const serverUnrollScript = this.serverUnrollScript;
|
|
16561
16689
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
16562
|
-
const normalizedInputs = inputs.map(
|
|
16563
|
-
const at = now ?? await
|
|
16690
|
+
const normalizedInputs = inputs.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
16691
|
+
const at = now ?? await chunkP53OHGXY_cjs.resolveTimeHeight(this.onchainProvider);
|
|
16564
16692
|
for (const input of normalizedInputs) {
|
|
16565
|
-
if (!
|
|
16693
|
+
if (!chunkP53OHGXY_cjs.canSpendOffchain(input, at)) {
|
|
16566
16694
|
throw new Error(
|
|
16567
16695
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
16568
16696
|
);
|
|
@@ -16632,7 +16760,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16632
16760
|
);
|
|
16633
16761
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
16634
16762
|
index,
|
|
16635
|
-
lookupScript:
|
|
16763
|
+
lookupScript: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
16636
16764
|
}));
|
|
16637
16765
|
const identity = this.identity;
|
|
16638
16766
|
const signer = {
|
|
@@ -16733,14 +16861,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16733
16861
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16734
16862
|
spentVtxos.push({
|
|
16735
16863
|
...spentFacts,
|
|
16736
|
-
virtualStatus:
|
|
16864
|
+
virtualStatus: chunkP53OHGXY_cjs.toVirtualStatus(spentFacts),
|
|
16737
16865
|
...spentBy ? { spentBy } : {},
|
|
16738
16866
|
arkTxId: arkTxid
|
|
16739
16867
|
});
|
|
16740
16868
|
for (const id of vtxo.commitmentTxIds) {
|
|
16741
16869
|
commitmentTxIds.add(id);
|
|
16742
16870
|
}
|
|
16743
|
-
const vtxoExpiry =
|
|
16871
|
+
const vtxoExpiry = chunkP53OHGXY_cjs.toBatchExpiry(vtxo);
|
|
16744
16872
|
if (vtxoExpiry) {
|
|
16745
16873
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16746
16874
|
}
|
|
@@ -16753,7 +16881,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16753
16881
|
isSwept: false,
|
|
16754
16882
|
isPreconfirmed: true,
|
|
16755
16883
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16756
|
-
...
|
|
16884
|
+
...chunkP53OHGXY_cjs.parseLegacyExpiry(batchExpiry)
|
|
16757
16885
|
};
|
|
16758
16886
|
changeVtxo = {
|
|
16759
16887
|
txid: arkTxid,
|
|
@@ -16765,7 +16893,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16765
16893
|
tapTree: offchainTapscript.encode(),
|
|
16766
16894
|
value: Number(changeAmount),
|
|
16767
16895
|
...changeFacts,
|
|
16768
|
-
virtualStatus:
|
|
16896
|
+
virtualStatus: chunkP53OHGXY_cjs.toVirtualStatus(changeFacts),
|
|
16769
16897
|
spentBy: "",
|
|
16770
16898
|
status: {
|
|
16771
16899
|
confirmed: false
|
|
@@ -16834,12 +16962,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16834
16962
|
const spentVtxos = [];
|
|
16835
16963
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16836
16964
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16837
|
-
const vtxoInputs = inputs.filter(
|
|
16965
|
+
const vtxoInputs = inputs.filter(chunkP53OHGXY_cjs.isVirtualCoin);
|
|
16838
16966
|
const cm = await this.getContractManager();
|
|
16839
16967
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16840
16968
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16841
16969
|
for (const input of inputs) {
|
|
16842
|
-
if (
|
|
16970
|
+
if (chunkP53OHGXY_cjs.isVirtualCoin(input)) {
|
|
16843
16971
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16844
16972
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16845
16973
|
if (!vtxo) {
|
|
@@ -16851,13 +16979,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16851
16979
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16852
16980
|
spentVtxos.push({
|
|
16853
16981
|
...settledFacts,
|
|
16854
|
-
virtualStatus:
|
|
16982
|
+
virtualStatus: chunkP53OHGXY_cjs.toVirtualStatus(settledFacts),
|
|
16855
16983
|
settledBy: commitmentTxid
|
|
16856
16984
|
});
|
|
16857
16985
|
} else {
|
|
16858
16986
|
let sourceAddress;
|
|
16859
16987
|
try {
|
|
16860
|
-
sourceAddress =
|
|
16988
|
+
sourceAddress = chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16861
16989
|
this.network
|
|
16862
16990
|
);
|
|
16863
16991
|
} catch {
|
|
@@ -16915,9 +17043,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16915
17043
|
}
|
|
16916
17044
|
};
|
|
16917
17045
|
function selectVirtualCoins(coins, targetAmount) {
|
|
16918
|
-
const sortedCoins = coins.map(
|
|
16919
|
-
const expiryA =
|
|
16920
|
-
const expiryB =
|
|
17046
|
+
const sortedCoins = coins.map(chunkP53OHGXY_cjs.normalizeVtxo).sort((a, b) => {
|
|
17047
|
+
const expiryA = chunkP53OHGXY_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
17048
|
+
const expiryB = chunkP53OHGXY_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
16921
17049
|
if (expiryA !== expiryB) {
|
|
16922
17050
|
return expiryA - expiryB;
|
|
16923
17051
|
}
|
|
@@ -17286,7 +17414,7 @@ var MessageBus = class {
|
|
|
17286
17414
|
this.initialized = true;
|
|
17287
17415
|
}
|
|
17288
17416
|
async buildServices(config) {
|
|
17289
|
-
const arkProvider = new
|
|
17417
|
+
const arkProvider = new chunkP53OHGXY_cjs.RestArkProvider(config.arkServer.url);
|
|
17290
17418
|
const storage = {
|
|
17291
17419
|
walletRepository: this.walletRepository,
|
|
17292
17420
|
contractRepository: this.contractRepository,
|
|
@@ -17618,6 +17746,18 @@ var DustChangeError = class extends Error {
|
|
|
17618
17746
|
this.dustAmount = dustAmount;
|
|
17619
17747
|
}
|
|
17620
17748
|
};
|
|
17749
|
+
var OversizedChangeError = class extends Error {
|
|
17750
|
+
change;
|
|
17751
|
+
maxAmount;
|
|
17752
|
+
constructor(change, maxAmount) {
|
|
17753
|
+
super(
|
|
17754
|
+
`change ${change} sats is above the server's ${maxAmount} sat per-output ceiling; exit more of the balance, or split it into smaller VTXOs first`
|
|
17755
|
+
);
|
|
17756
|
+
this.name = "OversizedChangeError";
|
|
17757
|
+
this.change = change;
|
|
17758
|
+
this.maxAmount = maxAmount;
|
|
17759
|
+
}
|
|
17760
|
+
};
|
|
17621
17761
|
var offboardNetworkNames = [
|
|
17622
17762
|
"bitcoin",
|
|
17623
17763
|
"regtest",
|
|
@@ -17628,7 +17768,7 @@ var offboardNetworkNames = [
|
|
|
17628
17768
|
function offboardDestinationScript(destinationAddress) {
|
|
17629
17769
|
for (const networkName of offboardNetworkNames) {
|
|
17630
17770
|
try {
|
|
17631
|
-
const network =
|
|
17771
|
+
const network = chunkP53OHGXY_cjs.networks[networkName];
|
|
17632
17772
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
17633
17773
|
return btcSigner.OutScript.encode(addr);
|
|
17634
17774
|
} catch {
|
|
@@ -17649,11 +17789,50 @@ function settleChangeAgainstFee(change, feeOn) {
|
|
|
17649
17789
|
`change fee does not settle after ${CHANGE_FEE_MAX_ROUNDS} rounds (${change} sats of change); settle the full balance instead`
|
|
17650
17790
|
);
|
|
17651
17791
|
}
|
|
17792
|
+
function changeAfterOutputFee(left, feeOn) {
|
|
17793
|
+
if (left <= 0n) return { change: 0n, fee: 0n };
|
|
17794
|
+
const change = settleChangeAgainstFee(left, feeOn);
|
|
17795
|
+
return { change, fee: left - change };
|
|
17796
|
+
}
|
|
17652
17797
|
function reportUngatedInputs(wallet, inputs) {
|
|
17653
17798
|
if (!("logUngatedInputs" in wallet)) return;
|
|
17654
17799
|
const logger = wallet;
|
|
17655
17800
|
void logger.logUngatedInputs("Ramps.offboard({ vtxos })", inputs);
|
|
17656
17801
|
}
|
|
17802
|
+
function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
17803
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17804
|
+
const inputs = [];
|
|
17805
|
+
let subtotal = 0n;
|
|
17806
|
+
for (const vtxo of vtxos) {
|
|
17807
|
+
const inputFee = estimator.evalOffchainInput(chunkP53OHGXY_cjs.toOffchainInputFeeParams(vtxo));
|
|
17808
|
+
if (inputFee.satoshis >= vtxo.value) {
|
|
17809
|
+
if (named) {
|
|
17810
|
+
throw new Error(
|
|
17811
|
+
`selected vtxo ${vtxo.txid}:${vtxo.vout} costs ${inputFee.satoshis} sats to spend and is worth ${vtxo.value} \u2014 drop it from the selection`
|
|
17812
|
+
);
|
|
17813
|
+
}
|
|
17814
|
+
continue;
|
|
17815
|
+
}
|
|
17816
|
+
inputs.push(vtxo);
|
|
17817
|
+
subtotal += BigInt(vtxo.value) - BigInt(inputFee.satoshis);
|
|
17818
|
+
}
|
|
17819
|
+
if (inputs.length === 0) {
|
|
17820
|
+
throw new Error("No vtxos available after deducting fees");
|
|
17821
|
+
}
|
|
17822
|
+
return { inputs, subtotal };
|
|
17823
|
+
}
|
|
17824
|
+
async function serverVtxoMaxAmount(wallet) {
|
|
17825
|
+
const provider = wallet.arkProvider;
|
|
17826
|
+
if (!provider) return void 0;
|
|
17827
|
+
return (await provider.getInfo()).vtxoMaxAmount;
|
|
17828
|
+
}
|
|
17829
|
+
function assertChangeSettleable(change, dustAmount, maxAmount) {
|
|
17830
|
+
if (change === 0n) return;
|
|
17831
|
+
if (change < dustAmount) throw new DustChangeError(change, dustAmount);
|
|
17832
|
+
if (maxAmount !== void 0 && maxAmount >= 0n && change > maxAmount) {
|
|
17833
|
+
throw new OversizedChangeError(change, maxAmount);
|
|
17834
|
+
}
|
|
17835
|
+
}
|
|
17657
17836
|
var Ramps = class {
|
|
17658
17837
|
/**
|
|
17659
17838
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -17722,7 +17901,7 @@ var Ramps = class {
|
|
|
17722
17901
|
}
|
|
17723
17902
|
amount = amount ?? totalAmount;
|
|
17724
17903
|
const offchainAddress = await this.wallet.getAddress();
|
|
17725
|
-
const offchainAddr =
|
|
17904
|
+
const offchainAddr = chunkP53OHGXY_cjs.ArkAddress.decode(offchainAddress);
|
|
17726
17905
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
17727
17906
|
const outputFee = estimator.evalOffchainOutput({
|
|
17728
17907
|
amount,
|
|
@@ -17779,81 +17958,87 @@ var Ramps = class {
|
|
|
17779
17958
|
async offboard(destinationAddress, feeInfo, amount, eventCallback, vtxos) {
|
|
17780
17959
|
const named = vtxos !== void 0;
|
|
17781
17960
|
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17782
|
-
vtxos
|
|
17961
|
+
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17783
17962
|
withRecoverable: true,
|
|
17784
17963
|
withUnrolled: false
|
|
17785
17964
|
});
|
|
17786
17965
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17787
|
-
const
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
}
|
|
17797
|
-
continue;
|
|
17798
|
-
}
|
|
17799
|
-
filteredVtxos.push(vtxo);
|
|
17800
|
-
totalAmount += BigInt(vtxo.value) - BigInt(inputFee.satoshis);
|
|
17801
|
-
}
|
|
17802
|
-
if (filteredVtxos.length === 0) {
|
|
17803
|
-
throw new Error("No vtxos available after deducting fees");
|
|
17804
|
-
}
|
|
17805
|
-
let change = 0n;
|
|
17806
|
-
if (amount) {
|
|
17807
|
-
if (amount > totalAmount) {
|
|
17808
|
-
throw new Error("Amount is greater than total amount of vtxos after fees");
|
|
17809
|
-
}
|
|
17810
|
-
change = totalAmount - amount;
|
|
17811
|
-
}
|
|
17812
|
-
let changeAddress;
|
|
17813
|
-
if (change > 0n) {
|
|
17814
|
-
changeAddress = await this.wallet.getAddress();
|
|
17815
|
-
const changeScript = base.hex.encode(chunkKMPNH7NS_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
17816
|
-
change = settleChangeAgainstFee(
|
|
17817
|
-
change,
|
|
17818
|
-
(amount2) => BigInt(estimator.evalOffchainOutput({ amount: amount2, script: changeScript }).satoshis)
|
|
17819
|
-
);
|
|
17820
|
-
}
|
|
17821
|
-
const dustAmount = getDustAmount(this.wallet);
|
|
17822
|
-
if (change > 0n && change < dustAmount) {
|
|
17823
|
-
throw new DustChangeError(change, dustAmount);
|
|
17824
|
-
}
|
|
17825
|
-
amount = amount ?? totalAmount;
|
|
17826
|
-
const destinationScript = offboardDestinationScript(destinationAddress);
|
|
17966
|
+
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
17967
|
+
if (amount && amount > subtotal) {
|
|
17968
|
+
throw new Error("Amount is greater than total amount of vtxos after fees");
|
|
17969
|
+
}
|
|
17970
|
+
const handed = amount || subtotal;
|
|
17971
|
+
const { change, changeAddress } = await this.fundChange(
|
|
17972
|
+
amount ? subtotal - handed : 0n,
|
|
17973
|
+
estimator
|
|
17974
|
+
);
|
|
17827
17975
|
const outputFee = estimator.evalOnchainOutput({
|
|
17828
|
-
amount,
|
|
17829
|
-
script: base.hex.encode(
|
|
17976
|
+
amount: handed,
|
|
17977
|
+
script: base.hex.encode(offboardDestinationScript(destinationAddress))
|
|
17830
17978
|
});
|
|
17831
|
-
if (BigInt(outputFee.satoshis) >
|
|
17979
|
+
if (BigInt(outputFee.satoshis) > handed) {
|
|
17832
17980
|
throw new Error(
|
|
17833
|
-
`can't deduct fees from offboard amount (${outputFee.satoshis} > ${
|
|
17981
|
+
`can't deduct fees from offboard amount (${outputFee.satoshis} > ${handed})`
|
|
17834
17982
|
);
|
|
17835
17983
|
}
|
|
17836
|
-
amount -= BigInt(outputFee.satoshis);
|
|
17837
17984
|
const outputs = [
|
|
17838
|
-
{
|
|
17839
|
-
address: destinationAddress,
|
|
17840
|
-
amount
|
|
17841
|
-
}
|
|
17985
|
+
{ address: destinationAddress, amount: handed - BigInt(outputFee.satoshis) }
|
|
17842
17986
|
];
|
|
17843
|
-
if (change > 0n) {
|
|
17844
|
-
|
|
17845
|
-
|
|
17846
|
-
|
|
17847
|
-
|
|
17848
|
-
|
|
17987
|
+
if (change > 0n) outputs.push({ address: changeAddress, amount: change });
|
|
17988
|
+
return this.wallet.settle({ inputs, outputs }, eventCallback);
|
|
17989
|
+
}
|
|
17990
|
+
/**
|
|
17991
|
+
* Collaboratively exit with the DESTINATION paid exactly `amount`, pricing the
|
|
17992
|
+
* fee on that output rather than on a grossed-up figure. {@link offboard} keeps
|
|
17993
|
+
* the other anchor, which needs `g - fee(g) = amount` solved — impossible for
|
|
17994
|
+
* a program charging the whole output.
|
|
17995
|
+
*/
|
|
17996
|
+
async offboardExact(params) {
|
|
17997
|
+
const { destinationAddress, feeInfo, amount, eventCallback, vtxos } = params;
|
|
17998
|
+
if (amount <= 0n) {
|
|
17999
|
+
throw new Error(`offboard amount must be positive, got ${amount}`);
|
|
17849
18000
|
}
|
|
17850
|
-
|
|
17851
|
-
|
|
17852
|
-
|
|
17853
|
-
|
|
17854
|
-
|
|
17855
|
-
|
|
18001
|
+
const named = vtxos !== void 0;
|
|
18002
|
+
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
18003
|
+
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
18004
|
+
withRecoverable: true,
|
|
18005
|
+
withUnrolled: false
|
|
18006
|
+
});
|
|
18007
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
18008
|
+
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
18009
|
+
const outputFee = BigInt(
|
|
18010
|
+
estimator.evalOnchainOutput({
|
|
18011
|
+
amount,
|
|
18012
|
+
script: base.hex.encode(offboardDestinationScript(destinationAddress))
|
|
18013
|
+
}).satoshis
|
|
17856
18014
|
);
|
|
18015
|
+
const needed = amount + outputFee;
|
|
18016
|
+
if (needed > subtotal) {
|
|
18017
|
+
throw new Error(
|
|
18018
|
+
`selected vtxos net ${subtotal} sats, ${needed} needed to deliver ${amount} exactly (${amount} + a ${outputFee} sat exit fee)`
|
|
18019
|
+
);
|
|
18020
|
+
}
|
|
18021
|
+
const { change, changeAddress } = await this.fundChange(subtotal - needed, estimator);
|
|
18022
|
+
const outputs = [{ address: destinationAddress, amount }];
|
|
18023
|
+
if (change > 0n) outputs.push({ address: changeAddress, amount: change });
|
|
18024
|
+
return this.wallet.settle({ inputs, outputs }, eventCallback);
|
|
18025
|
+
}
|
|
18026
|
+
/** Fund the change output: pay its own fee, then judge it against both
|
|
18027
|
+
* server-side bounds. `0n` in is `0n` out — no change output at all. */
|
|
18028
|
+
async fundChange(left, estimator) {
|
|
18029
|
+
if (left <= 0n) return { change: 0n };
|
|
18030
|
+
const changeAddress = await this.wallet.getAddress();
|
|
18031
|
+
const changeScript = base.hex.encode(chunkP53OHGXY_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
18032
|
+
const { change } = changeAfterOutputFee(
|
|
18033
|
+
left,
|
|
18034
|
+
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script: changeScript }).satoshis)
|
|
18035
|
+
);
|
|
18036
|
+
assertChangeSettleable(
|
|
18037
|
+
change,
|
|
18038
|
+
getDustAmount(this.wallet),
|
|
18039
|
+
await serverVtxoMaxAmount(this.wallet)
|
|
18040
|
+
);
|
|
18041
|
+
return { change, changeAddress };
|
|
17857
18042
|
}
|
|
17858
18043
|
};
|
|
17859
18044
|
|
|
@@ -18672,7 +18857,7 @@ var WalletMessageHandler = class {
|
|
|
18672
18857
|
// Wallet methods
|
|
18673
18858
|
async handleInitWallet({ payload }) {
|
|
18674
18859
|
const { arkServerUrl } = payload;
|
|
18675
|
-
this.indexerProvider = new
|
|
18860
|
+
this.indexerProvider = new chunkT327OEMV_cjs.RestIndexerProvider(arkServerUrl);
|
|
18676
18861
|
await this.onWalletInitialized();
|
|
18677
18862
|
}
|
|
18678
18863
|
/**
|
|
@@ -18707,7 +18892,8 @@ var WalletMessageHandler = class {
|
|
|
18707
18892
|
now: { timestamp: /* @__PURE__ */ new Date() },
|
|
18708
18893
|
isPendingRecovery: (vtxo) => pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
18709
18894
|
isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
|
|
18710
|
-
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
18895
|
+
isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`),
|
|
18896
|
+
dustCarrier: getDustAmount(this.readonlyWallet)
|
|
18711
18897
|
});
|
|
18712
18898
|
return {
|
|
18713
18899
|
boarding: {
|
|
@@ -18960,7 +19146,7 @@ var WalletMessageHandler = class {
|
|
|
18960
19146
|
if (v.isUnrolled) {
|
|
18961
19147
|
return withUnrolled;
|
|
18962
19148
|
}
|
|
18963
|
-
if (
|
|
19149
|
+
if (chunkP53OHGXY_cjs.hasTerminalSpend(v)) {
|
|
18964
19150
|
return false;
|
|
18965
19151
|
}
|
|
18966
19152
|
if (includeRecoverable) {
|
|
@@ -18969,10 +19155,10 @@ var WalletMessageHandler = class {
|
|
|
18969
19155
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
18970
19156
|
return false;
|
|
18971
19157
|
}
|
|
18972
|
-
if (
|
|
19158
|
+
if (chunkP53OHGXY_cjs.isRecoverable(v)) {
|
|
18973
19159
|
return false;
|
|
18974
19160
|
}
|
|
18975
|
-
if (
|
|
19161
|
+
if (chunkP53OHGXY_cjs.isExpired(v)) {
|
|
18976
19162
|
return false;
|
|
18977
19163
|
}
|
|
18978
19164
|
return true;
|
|
@@ -19080,7 +19266,7 @@ var WalletMessageHandler = class {
|
|
|
19080
19266
|
this.readonlyWallet.getBoardingTxs()
|
|
19081
19267
|
]);
|
|
19082
19268
|
const indexerProvider = this.indexerProvider;
|
|
19083
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
19269
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkP53OHGXY_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
19084
19270
|
return buildTransactionHistory(
|
|
19085
19271
|
vtxos,
|
|
19086
19272
|
boardingTxs,
|
|
@@ -19788,7 +19974,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19788
19974
|
};
|
|
19789
19975
|
try {
|
|
19790
19976
|
const response = await this.sendMessage(message);
|
|
19791
|
-
return response.payload.vtxos.map(
|
|
19977
|
+
return response.payload.vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
19792
19978
|
} catch (error) {
|
|
19793
19979
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
19794
19980
|
}
|
|
@@ -19813,7 +19999,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19813
19999
|
};
|
|
19814
20000
|
try {
|
|
19815
20001
|
const response = await this.sendMessage(message);
|
|
19816
|
-
return response.payload.vtxos.map(
|
|
20002
|
+
return response.payload.vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
19817
20003
|
} catch (error) {
|
|
19818
20004
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
19819
20005
|
}
|
|
@@ -19984,7 +20170,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19984
20170
|
};
|
|
19985
20171
|
try {
|
|
19986
20172
|
const response = await sendContractMessage(message);
|
|
19987
|
-
return response.payload.vtxos.map(
|
|
20173
|
+
return response.payload.vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
19988
20174
|
} catch (e) {
|
|
19989
20175
|
throw new Error("Failed to annotate vtxos");
|
|
19990
20176
|
}
|
|
@@ -20596,7 +20782,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20596
20782
|
};
|
|
20597
20783
|
try {
|
|
20598
20784
|
const response = await wallet.sendMessage(message);
|
|
20599
|
-
return response.payload.vtxos.map(
|
|
20785
|
+
return response.payload.vtxos.map(chunkP53OHGXY_cjs.normalizeVtxo);
|
|
20600
20786
|
} catch (e) {
|
|
20601
20787
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
20602
20788
|
}
|
|
@@ -20708,12 +20894,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20708
20894
|
* @returns Configured onchain wallet
|
|
20709
20895
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
20710
20896
|
*/
|
|
20711
|
-
static async create(identity, networkName =
|
|
20897
|
+
static async create(identity, networkName = chunkP53OHGXY_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
20712
20898
|
const pubkey = await identity.xOnlyPublicKey();
|
|
20713
20899
|
if (!pubkey) {
|
|
20714
20900
|
throw new Error("Invalid configured public key");
|
|
20715
20901
|
}
|
|
20716
|
-
const network =
|
|
20902
|
+
const network = chunkP53OHGXY_cjs.getNetwork(networkName);
|
|
20717
20903
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
20718
20904
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
20719
20905
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -20819,7 +21005,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20819
21005
|
if (!inputs) {
|
|
20820
21006
|
throw new Error("Fee estimation failed");
|
|
20821
21007
|
}
|
|
20822
|
-
let tx = new
|
|
21008
|
+
let tx = new chunkP53OHGXY_cjs.Transaction();
|
|
20823
21009
|
for (const input of inputs) {
|
|
20824
21010
|
tx.addInput({
|
|
20825
21011
|
txid: input.txid,
|
|
@@ -20877,7 +21063,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20877
21063
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
20878
21064
|
*/
|
|
20879
21065
|
async bumpAnchor(parentHex, feeRate) {
|
|
20880
|
-
const parent =
|
|
21066
|
+
const parent = chunkP53OHGXY_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
20881
21067
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
20882
21068
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
20883
21069
|
return [parent.hex, child.hex];
|
|
@@ -21784,7 +21970,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21784
21970
|
try {
|
|
21785
21971
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
21786
21972
|
for (const psbt of txs) {
|
|
21787
|
-
const tx =
|
|
21973
|
+
const tx = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
21788
21974
|
resolved.set(tx.id, tx.toBytes());
|
|
21789
21975
|
}
|
|
21790
21976
|
} catch (err) {
|
|
@@ -21817,7 +22003,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21817
22003
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
21818
22004
|
const pending = [];
|
|
21819
22005
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21820
|
-
if (
|
|
22006
|
+
if (chunkP53OHGXY_cjs.getArkPsbtFields(tx, i, chunkP53OHGXY_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
21821
22007
|
}
|
|
21822
22008
|
if (pending.length === 0) return;
|
|
21823
22009
|
const resolved = await resolvePrevTxs(
|
|
@@ -21826,13 +22012,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
21826
22012
|
onchain
|
|
21827
22013
|
);
|
|
21828
22014
|
for (const i of pending) {
|
|
21829
|
-
|
|
22015
|
+
chunkP53OHGXY_cjs.setArkPsbtField(tx, i, chunkP53OHGXY_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
21830
22016
|
}
|
|
21831
22017
|
}
|
|
21832
22018
|
async function attachPrevoutTxs(tx, source) {
|
|
21833
22019
|
const pending = [];
|
|
21834
22020
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21835
|
-
if (
|
|
22021
|
+
if (chunkP53OHGXY_cjs.getArkPsbtFields(tx, i, chunkP53OHGXY_cjs.PrevoutTxField).length > 0) continue;
|
|
21836
22022
|
const input = tx.getInput(i);
|
|
21837
22023
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
21838
22024
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -21843,7 +22029,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
21843
22029
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
21844
22030
|
}
|
|
21845
22031
|
for (const { index, txid } of pending) {
|
|
21846
|
-
|
|
22032
|
+
chunkP53OHGXY_cjs.setArkPsbtField(tx, index, chunkP53OHGXY_cjs.PrevoutTxField, resolved.get(txid));
|
|
21847
22033
|
}
|
|
21848
22034
|
}
|
|
21849
22035
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -21869,7 +22055,7 @@ exports.BIP322 = void 0;
|
|
|
21869
22055
|
async function sign2(message, identity, network) {
|
|
21870
22056
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
21871
22057
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
21872
|
-
const toSpend =
|
|
22058
|
+
const toSpend = chunkP53OHGXY_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
21873
22059
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
21874
22060
|
const signed = await identity.sign(toSign, [0]);
|
|
21875
22061
|
signed.finalizeIdx(0);
|
|
@@ -21927,7 +22113,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
21927
22113
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
21928
22114
|
return false;
|
|
21929
22115
|
}
|
|
21930
|
-
const toSpend =
|
|
22116
|
+
const toSpend = chunkP53OHGXY_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21931
22117
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
21932
22118
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
21933
22119
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -21948,7 +22134,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
21948
22134
|
}
|
|
21949
22135
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
21950
22136
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
21951
|
-
const toSpend =
|
|
22137
|
+
const toSpend = chunkP53OHGXY_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21952
22138
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
21953
22139
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
21954
22140
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -22001,7 +22187,7 @@ function encodeCompactSize(n) {
|
|
|
22001
22187
|
return buf;
|
|
22002
22188
|
}
|
|
22003
22189
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
22004
|
-
const tx = new
|
|
22190
|
+
const tx = new chunkP53OHGXY_cjs.Transaction({ version: 0 });
|
|
22005
22191
|
tx.addInput({
|
|
22006
22192
|
txid: toSpend.id,
|
|
22007
22193
|
index: 0,
|
|
@@ -22015,12 +22201,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
22015
22201
|
});
|
|
22016
22202
|
tx.addOutput({
|
|
22017
22203
|
amount: 0n,
|
|
22018
|
-
script:
|
|
22204
|
+
script: chunkP53OHGXY_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22019
22205
|
});
|
|
22020
22206
|
return tx;
|
|
22021
22207
|
}
|
|
22022
22208
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
22023
|
-
const tx = new
|
|
22209
|
+
const tx = new chunkP53OHGXY_cjs.Transaction({ version: 0 });
|
|
22024
22210
|
tx.addInput({
|
|
22025
22211
|
txid: toSpend.id,
|
|
22026
22212
|
index: 0,
|
|
@@ -22032,7 +22218,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
22032
22218
|
});
|
|
22033
22219
|
tx.addOutput({
|
|
22034
22220
|
amount: 0n,
|
|
22035
|
-
script:
|
|
22221
|
+
script: chunkP53OHGXY_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
22036
22222
|
});
|
|
22037
22223
|
return tx;
|
|
22038
22224
|
}
|
|
@@ -22045,7 +22231,7 @@ var RestEmulatorProvider = class {
|
|
|
22045
22231
|
serverUrl;
|
|
22046
22232
|
async getInfo() {
|
|
22047
22233
|
const url = `${this.serverUrl}/v1/info`;
|
|
22048
|
-
const response = await
|
|
22234
|
+
const response = await chunkP53OHGXY_cjs.baseFetch(url);
|
|
22049
22235
|
if (!response.ok) {
|
|
22050
22236
|
const errorText2 = await response.text();
|
|
22051
22237
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -22163,7 +22349,7 @@ var RestEmulatorProvider = class {
|
|
|
22163
22349
|
}
|
|
22164
22350
|
};
|
|
22165
22351
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
22166
|
-
const tx =
|
|
22352
|
+
const tx = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
22167
22353
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
22168
22354
|
const input = tx.getInput(0);
|
|
22169
22355
|
if (!input) {
|
|
@@ -22190,14 +22376,14 @@ var ExitPathError = class extends Error {
|
|
|
22190
22376
|
reason;
|
|
22191
22377
|
};
|
|
22192
22378
|
function delayWeight(sequence) {
|
|
22193
|
-
const t =
|
|
22379
|
+
const t = chunkP53OHGXY_cjs.sequenceToTimelock(sequence);
|
|
22194
22380
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
22195
22381
|
}
|
|
22196
22382
|
async function resolveUnilateralPath(params) {
|
|
22197
22383
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
22198
22384
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
22199
22385
|
if (contract) {
|
|
22200
|
-
const handler =
|
|
22386
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
22201
22387
|
if (!handler) {
|
|
22202
22388
|
throw new ExitPathError(
|
|
22203
22389
|
"no-handler",
|
|
@@ -22220,12 +22406,12 @@ async function resolveUnilateralPath(params) {
|
|
|
22220
22406
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
22221
22407
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
22222
22408
|
}
|
|
22223
|
-
const decoded =
|
|
22409
|
+
const decoded = chunkP53OHGXY_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
22224
22410
|
let best;
|
|
22225
22411
|
for (const exit of decoded.exitPaths()) {
|
|
22226
22412
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
22227
22413
|
if (!leaf) continue;
|
|
22228
|
-
const sequence =
|
|
22414
|
+
const sequence = chunkP53OHGXY_cjs.timelockToSequence(exit.params.timelock);
|
|
22229
22415
|
const weight = delayWeight(sequence);
|
|
22230
22416
|
if (!best || weight < best.weight) {
|
|
22231
22417
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -22445,7 +22631,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22445
22631
|
let totalAmount = 0n;
|
|
22446
22632
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
22447
22633
|
for (const vtxo of vtxos) {
|
|
22448
|
-
if (!
|
|
22634
|
+
if (!chunkP53OHGXY_cjs.canSweepOnchain(vtxo)) {
|
|
22449
22635
|
throw new Error(
|
|
22450
22636
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
22451
22637
|
);
|
|
@@ -22456,14 +22642,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22456
22642
|
}
|
|
22457
22643
|
const resolved = await resolveUnilateralPath({
|
|
22458
22644
|
vtxo,
|
|
22459
|
-
scriptHex: base.hex.encode(
|
|
22645
|
+
scriptHex: base.hex.encode(chunkP53OHGXY_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22460
22646
|
contractRepository: wallet.contractRepository,
|
|
22461
22647
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
22462
22648
|
currentTime: Date.now()
|
|
22463
22649
|
});
|
|
22464
22650
|
const spendingLeaf = resolved.selection.leaf;
|
|
22465
22651
|
const sequence = resolved.selection.sequence;
|
|
22466
|
-
const timelock =
|
|
22652
|
+
const timelock = chunkP53OHGXY_cjs.sequenceToTimelock(sequence);
|
|
22467
22653
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
22468
22654
|
if (!elapsed) {
|
|
22469
22655
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -22476,7 +22662,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22476
22662
|
sequence,
|
|
22477
22663
|
witnessUtxo: {
|
|
22478
22664
|
amount: BigInt(vtxo.value),
|
|
22479
|
-
script:
|
|
22665
|
+
script: chunkP53OHGXY_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
22480
22666
|
},
|
|
22481
22667
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22482
22668
|
});
|
|
@@ -22486,7 +22672,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22486
22672
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
22487
22673
|
);
|
|
22488
22674
|
}
|
|
22489
|
-
const tx = new
|
|
22675
|
+
const tx = new chunkP53OHGXY_cjs.Transaction({ version: 2 });
|
|
22490
22676
|
for (const input of inputs) {
|
|
22491
22677
|
tx.addInput(input);
|
|
22492
22678
|
}
|
|
@@ -22561,7 +22747,7 @@ function sweepFeeFor(path, outputAddress, network, feeRate) {
|
|
|
22561
22747
|
return Number(estimator.vsize().fee(BigInt(Math.ceil(feeRate))));
|
|
22562
22748
|
}
|
|
22563
22749
|
async function buildSignedSweep(params) {
|
|
22564
|
-
const { vtxo, path, outputAddress, feeRate, network, identity } = params;
|
|
22750
|
+
const { vtxo, path, outputAddress, feeRate, network, identity, signer } = params;
|
|
22565
22751
|
const fee = sweepFeeFor(path, outputAddress, network, feeRate);
|
|
22566
22752
|
const sendAmount = BigInt(vtxo.value) - BigInt(fee);
|
|
22567
22753
|
if (sendAmount < BigInt(DUST_AMOUNT)) {
|
|
@@ -22569,7 +22755,7 @@ async function buildSignedSweep(params) {
|
|
|
22569
22755
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
22570
22756
|
);
|
|
22571
22757
|
}
|
|
22572
|
-
const tx = new
|
|
22758
|
+
const tx = new chunkP53OHGXY_cjs.Transaction({ version: 2 });
|
|
22573
22759
|
tx.addInput({
|
|
22574
22760
|
txid: vtxo.txid,
|
|
22575
22761
|
index: vtxo.vout,
|
|
@@ -22579,7 +22765,7 @@ async function buildSignedSweep(params) {
|
|
|
22579
22765
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22580
22766
|
});
|
|
22581
22767
|
tx.addOutputAddress(outputAddress, sendAmount, network);
|
|
22582
|
-
const signed = await identity.sign(tx);
|
|
22768
|
+
const signed = signer ? await signer(tx) : await identity.sign(tx);
|
|
22583
22769
|
if (!path.extraWitness || path.extraWitness.length === 0) {
|
|
22584
22770
|
signed.finalize();
|
|
22585
22771
|
return { tx: signed, fee };
|
|
@@ -22594,7 +22780,7 @@ async function buildSignedSweep(params) {
|
|
|
22594
22780
|
finalScriptWitness: [
|
|
22595
22781
|
tapScriptSig[0][1],
|
|
22596
22782
|
...path.extraWitness,
|
|
22597
|
-
|
|
22783
|
+
chunkP53OHGXY_cjs.scriptFromTapLeafScript(path.leaf),
|
|
22598
22784
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
22599
22785
|
]
|
|
22600
22786
|
});
|
|
@@ -22624,7 +22810,7 @@ async function resolveFeeRate(opts) {
|
|
|
22624
22810
|
}
|
|
22625
22811
|
async function selectExitVtxos(opts) {
|
|
22626
22812
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
22627
|
-
const res = await
|
|
22813
|
+
const res = await chunkP53OHGXY_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
22628
22814
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
22629
22815
|
const out = [];
|
|
22630
22816
|
for (const vtxo of res.vtxos) {
|
|
@@ -22639,7 +22825,7 @@ async function selectExitVtxos(opts) {
|
|
|
22639
22825
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
22640
22826
|
);
|
|
22641
22827
|
}
|
|
22642
|
-
const handler =
|
|
22828
|
+
const handler = chunkCQNX4BTA_cjs.contractHandlers.get(contract.type);
|
|
22643
22829
|
if (!handler) {
|
|
22644
22830
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
22645
22831
|
}
|
|
@@ -22669,7 +22855,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22669
22855
|
if (pendingNodes.length > 0) {
|
|
22670
22856
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
22671
22857
|
for (const psbt of txs) {
|
|
22672
|
-
psbts.set(
|
|
22858
|
+
psbts.set(chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
22673
22859
|
}
|
|
22674
22860
|
}
|
|
22675
22861
|
const childVsize = Number(
|
|
@@ -22705,7 +22891,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22705
22891
|
try {
|
|
22706
22892
|
const resolved = await resolveUnilateralPath({
|
|
22707
22893
|
vtxo,
|
|
22708
|
-
scriptHex: base.hex.encode(
|
|
22894
|
+
scriptHex: base.hex.encode(chunkP53OHGXY_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22709
22895
|
contractRepository: wallet.contractRepository,
|
|
22710
22896
|
walletPubKeyHex,
|
|
22711
22897
|
currentTime: Date.now()
|
|
@@ -22724,7 +22910,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22724
22910
|
});
|
|
22725
22911
|
continue;
|
|
22726
22912
|
}
|
|
22727
|
-
const t =
|
|
22913
|
+
const t = chunkP53OHGXY_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
22728
22914
|
const delay = { type: t.type, value: Number(t.value) };
|
|
22729
22915
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
22730
22916
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -23125,13 +23311,14 @@ async function prepare(opts) {
|
|
|
23125
23311
|
txid: sweep.vtxo.txid,
|
|
23126
23312
|
vout: sweep.vtxo.vout,
|
|
23127
23313
|
value: sweep.vtxo.value,
|
|
23128
|
-
pkScript:
|
|
23314
|
+
pkScript: chunkP53OHGXY_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
23129
23315
|
},
|
|
23130
23316
|
path: sweep.resolved.selection,
|
|
23131
23317
|
outputAddress: opts.sweepAddress,
|
|
23132
23318
|
feeRate,
|
|
23133
23319
|
network: wallet.network,
|
|
23134
|
-
identity: wallet.identity
|
|
23320
|
+
identity: wallet.identity,
|
|
23321
|
+
signer: (tx2) => wallet.signInputsByWitnessScript(tx2)
|
|
23135
23322
|
});
|
|
23136
23323
|
activeOutpoints.add(outpoint);
|
|
23137
23324
|
sweepSteps.push({
|
|
@@ -23213,7 +23400,7 @@ async function prepare(opts) {
|
|
|
23213
23400
|
if (newFee <= splitterFee) break;
|
|
23214
23401
|
splitterFee = newFee;
|
|
23215
23402
|
}
|
|
23216
|
-
const splitter = new
|
|
23403
|
+
const splitter = new chunkP53OHGXY_cjs.Transaction({ version: 2 });
|
|
23217
23404
|
for (const coin of selected.inputs) {
|
|
23218
23405
|
splitter.addInput({
|
|
23219
23406
|
txid: coin.txid,
|
|
@@ -23357,41 +23544,41 @@ var UnilateralExit = {
|
|
|
23357
23544
|
// src/arkade/index.ts
|
|
23358
23545
|
var arkade_exports = {};
|
|
23359
23546
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
23360
|
-
ARKADE_OP: () =>
|
|
23361
|
-
ARKADE_OPCODES: () =>
|
|
23362
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
23363
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
23364
|
-
ARKADE_OPS: () =>
|
|
23547
|
+
ARKADE_OP: () => chunkCQNX4BTA_cjs.ARKADE_OP,
|
|
23548
|
+
ARKADE_OPCODES: () => chunkCQNX4BTA_cjs.ARKADE_OPCODES,
|
|
23549
|
+
ARKADE_OPCODE_NAMES: () => chunkCQNX4BTA_cjs.ARKADE_OPCODE_NAMES,
|
|
23550
|
+
ARKADE_OPCODE_VALUES: () => chunkCQNX4BTA_cjs.ARKADE_OPCODE_VALUES,
|
|
23551
|
+
ARKADE_OPS: () => chunkCQNX4BTA_cjs.ARKADE_OPS,
|
|
23365
23552
|
Arkade: () => Arkade,
|
|
23366
23553
|
ArkadeContract: () => ArkadeContract,
|
|
23367
|
-
ArkadeProgramScript: () =>
|
|
23368
|
-
ArkadeScript: () =>
|
|
23554
|
+
ArkadeProgramScript: () => chunkCQNX4BTA_cjs.ArkadeProgramScript,
|
|
23555
|
+
ArkadeScript: () => chunkCQNX4BTA_cjs.ArkadeScript,
|
|
23369
23556
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
23370
|
-
BigNum: () =>
|
|
23557
|
+
BigNum: () => chunkCQNX4BTA_cjs.bignum_exports,
|
|
23371
23558
|
OP: () => btcSigner.OP,
|
|
23372
|
-
OPCODE_NAMES: () =>
|
|
23373
|
-
OPCODE_VALUES: () =>
|
|
23374
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
23559
|
+
OPCODE_NAMES: () => chunkCQNX4BTA_cjs.OPCODE_NAMES,
|
|
23560
|
+
OPCODE_VALUES: () => chunkCQNX4BTA_cjs.OPCODE_VALUES,
|
|
23561
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkCQNX4BTA_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
23375
23562
|
Script: () => btcSigner.Script,
|
|
23376
|
-
arkadeScriptHash: () =>
|
|
23377
|
-
arkadeWitnessHash: () =>
|
|
23378
|
-
asmToBytes: () =>
|
|
23379
|
-
bytesToASM: () =>
|
|
23380
|
-
computeArkadeScriptPublicKey: () =>
|
|
23563
|
+
arkadeScriptHash: () => chunkCQNX4BTA_cjs.arkadeScriptHash,
|
|
23564
|
+
arkadeWitnessHash: () => chunkCQNX4BTA_cjs.arkadeWitnessHash,
|
|
23565
|
+
asmToBytes: () => chunkCQNX4BTA_cjs.asmToBytes,
|
|
23566
|
+
bytesToASM: () => chunkCQNX4BTA_cjs.bytesToASM,
|
|
23567
|
+
computeArkadeScriptPublicKey: () => chunkCQNX4BTA_cjs.computeArkadeScriptPublicKey,
|
|
23381
23568
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
23382
|
-
deserializeArkadeContractParams: () =>
|
|
23383
|
-
fromASM: () =>
|
|
23384
|
-
getOpcodeName: () =>
|
|
23385
|
-
getOpcodeValue: () =>
|
|
23386
|
-
parseArtifact: () =>
|
|
23387
|
-
resolveAsm: () =>
|
|
23388
|
-
serializeArkadeContractParams: () =>
|
|
23389
|
-
stringifyArtifact: () =>
|
|
23390
|
-
toASM: () =>
|
|
23391
|
-
validateProgram: () =>
|
|
23392
|
-
witnessRefToBytes: () =>
|
|
23569
|
+
deserializeArkadeContractParams: () => chunkCQNX4BTA_cjs.deserializeArkadeContractParams,
|
|
23570
|
+
fromASM: () => chunkCQNX4BTA_cjs.fromASM,
|
|
23571
|
+
getOpcodeName: () => chunkCQNX4BTA_cjs.getOpcodeName,
|
|
23572
|
+
getOpcodeValue: () => chunkCQNX4BTA_cjs.getOpcodeValue,
|
|
23573
|
+
parseArtifact: () => chunkCQNX4BTA_cjs.parseArtifact,
|
|
23574
|
+
resolveAsm: () => chunkCQNX4BTA_cjs.resolveAsm,
|
|
23575
|
+
serializeArkadeContractParams: () => chunkCQNX4BTA_cjs.serializeArkadeContractParams,
|
|
23576
|
+
stringifyArtifact: () => chunkCQNX4BTA_cjs.stringifyArtifact,
|
|
23577
|
+
toASM: () => chunkCQNX4BTA_cjs.toASM,
|
|
23578
|
+
validateProgram: () => chunkCQNX4BTA_cjs.validateProgram,
|
|
23579
|
+
witnessRefToBytes: () => chunkCQNX4BTA_cjs.witnessRefToBytes
|
|
23393
23580
|
});
|
|
23394
|
-
var isVtxoCoin = (input) =>
|
|
23581
|
+
var isVtxoCoin = (input) => chunkP53OHGXY_cjs.isVirtualCoin(input);
|
|
23395
23582
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
23396
23583
|
let batchId;
|
|
23397
23584
|
let sweepTapTreeRoot;
|
|
@@ -23412,23 +23599,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23412
23599
|
);
|
|
23413
23600
|
await arkProvider.confirmRegistration(intentId);
|
|
23414
23601
|
batchId = event.id;
|
|
23415
|
-
const sweepTapscript =
|
|
23602
|
+
const sweepTapscript = chunkP53OHGXY_cjs.CSVMultisigTapscript.encode({
|
|
23416
23603
|
timelock,
|
|
23417
|
-
pubkeys: [
|
|
23604
|
+
pubkeys: [chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
23418
23605
|
}).script;
|
|
23419
23606
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
23420
23607
|
return { skip: false };
|
|
23421
23608
|
},
|
|
23422
23609
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
23423
23610
|
const signerPubKey = await session.getPublicKey();
|
|
23424
|
-
const xonlySignerPubKey =
|
|
23611
|
+
const xonlySignerPubKey = chunkCQNX4BTA_cjs.toXOnly(signerPubKey, "signer key");
|
|
23425
23612
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
23426
|
-
(k) => base.hex.encode(
|
|
23613
|
+
(k) => base.hex.encode(chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
23427
23614
|
);
|
|
23428
23615
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
23429
23616
|
return { skip: true };
|
|
23430
23617
|
}
|
|
23431
|
-
const commitmentTx =
|
|
23618
|
+
const commitmentTx = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
23432
23619
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
23433
23620
|
if (recipients && recipients.length > 0) {
|
|
23434
23621
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -23466,7 +23653,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23466
23653
|
if (connectorTree) {
|
|
23467
23654
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
23468
23655
|
}
|
|
23469
|
-
let commitmentPsbt =
|
|
23656
|
+
let commitmentPsbt = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
23470
23657
|
assertFinalCommitmentMatchesValidated(
|
|
23471
23658
|
commitmentPsbt,
|
|
23472
23659
|
validatedCommitmentTxid,
|
|
@@ -23508,7 +23695,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23508
23695
|
boardingIndices.push(boardingIdx);
|
|
23509
23696
|
continue;
|
|
23510
23697
|
}
|
|
23511
|
-
if (
|
|
23698
|
+
if (chunkP53OHGXY_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
23512
23699
|
continue;
|
|
23513
23700
|
}
|
|
23514
23701
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -23529,7 +23716,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23529
23716
|
index: input.vout,
|
|
23530
23717
|
witnessUtxo: {
|
|
23531
23718
|
amount: BigInt(input.value),
|
|
23532
|
-
script:
|
|
23719
|
+
script: chunkP53OHGXY_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
23533
23720
|
},
|
|
23534
23721
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
23535
23722
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -23620,16 +23807,16 @@ var Arkade = class _Arkade {
|
|
|
23620
23807
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
23621
23808
|
static async connect(opts) {
|
|
23622
23809
|
const info = await opts.arkade.getInfo();
|
|
23623
|
-
const serverKey =
|
|
23624
|
-
const checkpoint =
|
|
23625
|
-
const network = opts.network ??
|
|
23810
|
+
const serverKey = chunkCQNX4BTA_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
23811
|
+
const checkpoint = chunkP53OHGXY_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
23812
|
+
const network = opts.network ?? (Object.hasOwn(chunkP53OHGXY_cjs.networks, info.network) ? chunkP53OHGXY_cjs.getNetwork(info.network) : chunkP53OHGXY_cjs.DEFAULT_NETWORK);
|
|
23626
23813
|
let emulatorKey;
|
|
23627
23814
|
if (opts.emulator) {
|
|
23628
|
-
emulatorKey = base.hex.decode(
|
|
23815
|
+
emulatorKey = base.hex.decode(chunkP53OHGXY_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
23629
23816
|
}
|
|
23630
23817
|
let userKey;
|
|
23631
23818
|
if (opts.identity) {
|
|
23632
|
-
userKey =
|
|
23819
|
+
userKey = chunkCQNX4BTA_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
23633
23820
|
}
|
|
23634
23821
|
return new _Arkade({
|
|
23635
23822
|
arkProvider: opts.arkade,
|
|
@@ -23655,7 +23842,7 @@ var Arkade = class _Arkade {
|
|
|
23655
23842
|
* key respectively; explicit args always win.
|
|
23656
23843
|
*/
|
|
23657
23844
|
contract(program, args = {}) {
|
|
23658
|
-
const declared = (program.params ?? []).map(
|
|
23845
|
+
const declared = (program.params ?? []).map(chunkCQNX4BTA_cjs.inputName);
|
|
23659
23846
|
if (declared.includes("server") && args.server === void 0) {
|
|
23660
23847
|
args = { ...args, server: this.serverKey };
|
|
23661
23848
|
}
|
|
@@ -23675,7 +23862,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23675
23862
|
userKey: client.userKey,
|
|
23676
23863
|
emulatorKey: client.emulatorKey
|
|
23677
23864
|
};
|
|
23678
|
-
this.vtxoScript = new
|
|
23865
|
+
this.vtxoScript = new chunkCQNX4BTA_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
23679
23866
|
this.tapTree = this.vtxoScript.encode();
|
|
23680
23867
|
this.compiled = this.vtxoScript.compiled;
|
|
23681
23868
|
}
|
|
@@ -23703,7 +23890,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23703
23890
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
23704
23891
|
);
|
|
23705
23892
|
}
|
|
23706
|
-
const typed =
|
|
23893
|
+
const typed = chunkCQNX4BTA_cjs.deserializeArkadeContractParams(contract.params);
|
|
23707
23894
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
23708
23895
|
serverKey: typed.serverKey,
|
|
23709
23896
|
userKey: typed.userKey,
|
|
@@ -23744,7 +23931,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23744
23931
|
toContractParams() {
|
|
23745
23932
|
return {
|
|
23746
23933
|
type: "arkade",
|
|
23747
|
-
params:
|
|
23934
|
+
params: chunkCQNX4BTA_cjs.serializeArkadeContractParams({
|
|
23748
23935
|
program: this.program,
|
|
23749
23936
|
args: this.args,
|
|
23750
23937
|
serverKey: this.keys.serverKey,
|
|
@@ -23794,18 +23981,18 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23794
23981
|
if (registered) {
|
|
23795
23982
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
23796
23983
|
return (withVtxos?.vtxos ?? []).filter(
|
|
23797
|
-
(v) => !
|
|
23984
|
+
(v) => !chunkP53OHGXY_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
23798
23985
|
);
|
|
23799
23986
|
}
|
|
23800
23987
|
}
|
|
23801
23988
|
if (!this.client.indexer) {
|
|
23802
23989
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
23803
23990
|
}
|
|
23804
|
-
const { vtxos } = await
|
|
23991
|
+
const { vtxos } = await chunkP53OHGXY_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
23805
23992
|
scripts: [scriptHex],
|
|
23806
23993
|
spendableOnly: true
|
|
23807
23994
|
});
|
|
23808
|
-
return vtxos.filter((v) => !
|
|
23995
|
+
return vtxos.filter((v) => !chunkP53OHGXY_cjs.hasTerminalSpend(v) && !v.isUnrolled);
|
|
23809
23996
|
}
|
|
23810
23997
|
/** Total spendable balance (requires an indexer). */
|
|
23811
23998
|
async getBalance() {
|
|
@@ -23903,7 +24090,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23903
24090
|
this.contract.client.checkpoint
|
|
23904
24091
|
);
|
|
23905
24092
|
if (coin.sourceTx) {
|
|
23906
|
-
|
|
24093
|
+
chunkP53OHGXY_cjs.setArkPsbtField(arkTx, 0, chunkP53OHGXY_cjs.PrevArkTxField, coin.sourceTx);
|
|
23907
24094
|
}
|
|
23908
24095
|
if (this.fn.arkadeScript) {
|
|
23909
24096
|
const indexer = this.contract.client.indexer;
|
|
@@ -23920,8 +24107,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
23920
24107
|
}
|
|
23921
24108
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
23922
24109
|
if (condition.length > 0) {
|
|
23923
|
-
|
|
23924
|
-
|
|
24110
|
+
chunkP53OHGXY_cjs.setArkPsbtField(arkTx, 0, chunkP53OHGXY_cjs.ConditionWitness, condition);
|
|
24111
|
+
chunkP53OHGXY_cjs.setArkPsbtField(checkpoints[0], 0, chunkP53OHGXY_cjs.ConditionWitness, condition);
|
|
23925
24112
|
}
|
|
23926
24113
|
const packets = [];
|
|
23927
24114
|
if (this.assetSpecs.length > 0) {
|
|
@@ -23960,7 +24147,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23960
24147
|
base.base64.encode(signedArk2.toPSBT()),
|
|
23961
24148
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
23962
24149
|
);
|
|
23963
|
-
const txid =
|
|
24150
|
+
const txid = chunkP53OHGXY_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
23964
24151
|
return {
|
|
23965
24152
|
txid,
|
|
23966
24153
|
signedArkTx: res2.signedArkTx,
|
|
@@ -24019,23 +24206,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
24019
24206
|
}
|
|
24020
24207
|
buildAssetPacket() {
|
|
24021
24208
|
const groups = this.assetSpecs.map((s) => {
|
|
24022
|
-
const id = typeof s.assetId === "string" ?
|
|
24023
|
-
return
|
|
24209
|
+
const id = typeof s.assetId === "string" ? chunkT327OEMV_cjs.AssetId.fromString(s.assetId) : chunkT327OEMV_cjs.AssetId.fromBytes(s.assetId);
|
|
24210
|
+
return chunkT327OEMV_cjs.AssetGroup.create(
|
|
24024
24211
|
id,
|
|
24025
24212
|
null,
|
|
24026
|
-
s.inputs.map((i) =>
|
|
24027
|
-
s.outputs.map((o) =>
|
|
24028
|
-
(s.metadata ?? []).map((m) =>
|
|
24213
|
+
s.inputs.map((i) => chunkT327OEMV_cjs.AssetInput.create(i.vin, i.amount)),
|
|
24214
|
+
s.outputs.map((o) => chunkT327OEMV_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
24215
|
+
(s.metadata ?? []).map((m) => chunkT327OEMV_cjs.Metadata.create(m.key, m.value))
|
|
24029
24216
|
);
|
|
24030
24217
|
});
|
|
24031
|
-
return
|
|
24218
|
+
return chunkT327OEMV_cjs.Packet.create(groups);
|
|
24032
24219
|
}
|
|
24033
24220
|
witnessBytes(ref) {
|
|
24034
|
-
return
|
|
24221
|
+
return chunkCQNX4BTA_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
24035
24222
|
}
|
|
24036
24223
|
};
|
|
24037
24224
|
function bindInputs(fn, callArgs) {
|
|
24038
|
-
const names = (fn.def.inputs ?? []).map(
|
|
24225
|
+
const names = (fn.def.inputs ?? []).map(chunkCQNX4BTA_cjs.inputName);
|
|
24039
24226
|
if (callArgs.length !== names.length) {
|
|
24040
24227
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
24041
24228
|
}
|
|
@@ -24070,6 +24257,7 @@ var BIP21Error = /* @__PURE__ */ ((BIP21Error2) => {
|
|
|
24070
24257
|
BIP21Error2["INVALID_ADDRESS"] = "Invalid address";
|
|
24071
24258
|
return BIP21Error2;
|
|
24072
24259
|
})(BIP21Error || {});
|
|
24260
|
+
var formatAmount = (btc) => btc.toFixed(8).replace(/\.?0+$/, "");
|
|
24073
24261
|
var BIP21 = class _BIP21 {
|
|
24074
24262
|
/**
|
|
24075
24263
|
* Create a BIP21 URI from the provided parameters.
|
|
@@ -24091,7 +24279,7 @@ var BIP21 = class _BIP21 {
|
|
|
24091
24279
|
if (amount < 0) {
|
|
24092
24280
|
continue;
|
|
24093
24281
|
}
|
|
24094
|
-
queryParams[key] =
|
|
24282
|
+
queryParams[key] = formatAmount(amount);
|
|
24095
24283
|
} else if (key === "ark") {
|
|
24096
24284
|
if (typeof value === "string" && (value.startsWith("ark") || value.startsWith("tark"))) {
|
|
24097
24285
|
queryParams[key] = value;
|
|
@@ -24444,25 +24632,25 @@ function arkAssetRail() {
|
|
|
24444
24632
|
};
|
|
24445
24633
|
}
|
|
24446
24634
|
var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo()).fees;
|
|
24447
|
-
var GROSS_UP_MAX_ROUNDS = 8;
|
|
24448
|
-
function grossUpOffboard(net, feeInfo, script) {
|
|
24449
|
-
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
24450
|
-
const feeAt = (amount) => estimator.evalOnchainOutput({ amount: BigInt(amount), script }).satoshis;
|
|
24451
|
-
let gross = net;
|
|
24452
|
-
for (let i = 0; i < GROSS_UP_MAX_ROUNDS; i++) {
|
|
24453
|
-
const next = net + feeAt(gross);
|
|
24454
|
-
if (next === gross) break;
|
|
24455
|
-
gross = next;
|
|
24456
|
-
}
|
|
24457
|
-
return { gross, fee: gross - net };
|
|
24458
|
-
}
|
|
24459
24635
|
function offchainInputFees(vtxos, fees) {
|
|
24460
24636
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24461
24637
|
return vtxos.reduce(
|
|
24462
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
24638
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkP53OHGXY_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
24463
24639
|
0
|
|
24464
24640
|
);
|
|
24465
24641
|
}
|
|
24642
|
+
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
24643
|
+
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24644
|
+
const net = inputs.reduce(
|
|
24645
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkP53OHGXY_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
24646
|
+
0n
|
|
24647
|
+
);
|
|
24648
|
+
const script = base.hex.encode(chunkP53OHGXY_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
24649
|
+
return changeAfterOutputFee(
|
|
24650
|
+
net - needed,
|
|
24651
|
+
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script }).satoshis)
|
|
24652
|
+
).fee;
|
|
24653
|
+
}
|
|
24466
24654
|
function onchainRail(deps) {
|
|
24467
24655
|
if (typeof deps?.feeInfo !== "function") {
|
|
24468
24656
|
throw new Error("onchain rail: a feeInfo source is required");
|
|
@@ -24478,23 +24666,34 @@ function onchainRail(deps) {
|
|
|
24478
24666
|
const amt = resolveSendAmount("onchain", req.raw, req.amount);
|
|
24479
24667
|
const fees = await deps.feeInfo();
|
|
24480
24668
|
const script = base.hex.encode(offboardDestinationScript(address));
|
|
24481
|
-
const
|
|
24669
|
+
const exitFee = Number(
|
|
24670
|
+
new Estimator(fees?.intentFee ?? {}).evalOnchainOutput({
|
|
24671
|
+
amount: BigInt(amt),
|
|
24672
|
+
script
|
|
24673
|
+
}).satoshis
|
|
24674
|
+
);
|
|
24482
24675
|
const selectedVtxos = selectionOf(req);
|
|
24483
24676
|
const inputFee = selectedVtxos ? offchainInputFees(selectedVtxos, fees) : 0;
|
|
24677
|
+
const changeFee = selectedVtxos ? await changeOutputFee(
|
|
24678
|
+
ctx.wallet,
|
|
24679
|
+
selectedVtxos,
|
|
24680
|
+
BigInt(amt) + BigInt(exitFee),
|
|
24681
|
+
fees
|
|
24682
|
+
) : 0n;
|
|
24484
24683
|
return {
|
|
24485
24684
|
railId: "onchain",
|
|
24486
24685
|
amount: amt,
|
|
24487
|
-
fee:
|
|
24488
|
-
total:
|
|
24686
|
+
fee: exitFee + inputFee + Number(changeFee),
|
|
24687
|
+
total: amt + exitFee + inputFee + Number(changeFee),
|
|
24489
24688
|
send: async () => makeHandle("onchain", async (emit) => {
|
|
24490
24689
|
const ramps = new Ramps(ctx.wallet);
|
|
24491
|
-
const txid =
|
|
24492
|
-
address,
|
|
24493
|
-
fees,
|
|
24494
|
-
BigInt(
|
|
24495
|
-
|
|
24496
|
-
selectedVtxos
|
|
24497
|
-
)
|
|
24690
|
+
const txid = await ramps.offboardExact({
|
|
24691
|
+
destinationAddress: address,
|
|
24692
|
+
feeInfo: fees,
|
|
24693
|
+
amount: BigInt(amt),
|
|
24694
|
+
// Omitted, not undefined: an empty set covers nothing.
|
|
24695
|
+
...selectedVtxos ? { vtxos: selectedVtxos } : {}
|
|
24696
|
+
});
|
|
24498
24697
|
const result = { railId: "onchain", txid };
|
|
24499
24698
|
emit({ status: "settled", result });
|
|
24500
24699
|
return result;
|
|
@@ -24580,6 +24779,7 @@ exports.MessageBusNotInitializedError = MessageBusNotInitializedError;
|
|
|
24580
24779
|
exports.MissingSigningDescriptorError = MissingSigningDescriptorError;
|
|
24581
24780
|
exports.MnemonicIdentity = MnemonicIdentity;
|
|
24582
24781
|
exports.OnchainWallet = OnchainWallet;
|
|
24782
|
+
exports.OversizedChangeError = OversizedChangeError;
|
|
24583
24783
|
exports.P2A = P2A;
|
|
24584
24784
|
exports.PaymentRouter = PaymentRouter;
|
|
24585
24785
|
exports.PrevTxUnavailableError = PrevTxUnavailableError;
|
|
@@ -24745,5 +24945,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
|
24745
24945
|
exports.walletFeeSource = walletFeeSource;
|
|
24746
24946
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
24747
24947
|
exports.withPrevTxs = withPrevTxs;
|
|
24748
|
-
//# sourceMappingURL=chunk-
|
|
24749
|
-
//# sourceMappingURL=chunk-
|
|
24948
|
+
//# sourceMappingURL=chunk-LHSVPDFJ.cjs.map
|
|
24949
|
+
//# sourceMappingURL=chunk-LHSVPDFJ.cjs.map
|