@arkade-os/sdk 0.4.73 → 0.4.75
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-DA2OdpJ0.d.cts → asyncStorageTaskQueue-5k0H_cDM.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-C5IwA_Hs.d.ts → asyncStorageTaskQueue-DjwCbb07.d.ts} +2 -2
- package/dist/{chunk-L7IEXVXI.cjs → chunk-2Q2PYU3Y.cjs} +10 -10
- package/dist/{chunk-L7IEXVXI.cjs.map → chunk-2Q2PYU3Y.cjs.map} +1 -1
- package/dist/{chunk-QX2M67YI.js → chunk-2ULUCL6A.js} +21 -22
- package/dist/chunk-2ULUCL6A.js.map +1 -0
- package/dist/{chunk-G5RPUZJE.js → chunk-4GLSOP6L.js} +12 -5
- package/dist/chunk-4GLSOP6L.js.map +1 -0
- package/dist/{chunk-C4RKZY7D.cjs → chunk-EHJYR4E5.cjs} +827 -580
- package/dist/chunk-EHJYR4E5.cjs.map +1 -0
- package/dist/{chunk-YHJJSLE5.js → chunk-FTLPTF3R.js} +391 -147
- package/dist/chunk-FTLPTF3R.js.map +1 -0
- package/dist/{chunk-KJ5E646Y.cjs → chunk-J5EX3OMM.cjs} +8 -4
- package/dist/chunk-J5EX3OMM.cjs.map +1 -0
- package/dist/{chunk-M6HIWM5N.js → chunk-PS564TAU.js} +3 -3
- package/dist/{chunk-M6HIWM5N.js.map → chunk-PS564TAU.js.map} +1 -1
- package/dist/{chunk-D5DLGVN4.cjs → chunk-SH23SRZE.cjs} +17 -17
- package/dist/{chunk-D5DLGVN4.cjs.map → chunk-SH23SRZE.cjs.map} +1 -1
- package/dist/{chunk-5YCAC6XE.js → chunk-SKAL4MCW.js} +4 -4
- package/dist/{chunk-5YCAC6XE.js.map → chunk-SKAL4MCW.js.map} +1 -1
- package/dist/{chunk-OV4GLPZI.js → chunk-UKFA7NVE.js} +8 -4
- package/dist/chunk-UKFA7NVE.js.map +1 -0
- package/dist/{chunk-ZLDO4QDR.cjs → chunk-YA3L3WL4.cjs} +31 -32
- package/dist/chunk-YA3L3WL4.cjs.map +1 -0
- package/dist/{chunk-2D7F5IU3.cjs → chunk-YYWEBYFJ.cjs} +58 -51
- package/dist/chunk-YYWEBYFJ.cjs.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-BJp8f6LT.d.cts → delegate-D0v8yT-a.d.cts} +1 -1
- package/dist/{delegate-Ckz_TWzM.d.ts → delegate-D_sW61rj.d.ts} +1 -1
- package/dist/{hdWalletCapable-DABgAD-T.d.ts → hdWalletCapable-66hG5KQP.d.cts} +3 -11
- package/dist/{hdWalletCapable-DA9bJ5eB.d.cts → hdWalletCapable-DHCNbAgl.d.ts} +3 -11
- package/dist/{index-DSbDm0Io.d.cts → index-B2JSxDi1.d.cts} +2 -2
- package/dist/{index-Dg0-TvBQ.d.cts → index-TZBbMNqA.d.cts} +22 -7
- package/dist/{index-Dg0-TvBQ.d.ts → index-TZBbMNqA.d.ts} +22 -7
- package/dist/{index-B8xrELXY.d.ts → index-vUeTpifq.d.ts} +2 -2
- package/dist/index.cjs +312 -300
- package/dist/index.d.cts +89 -29
- package/dist/index.d.ts +89 -29
- 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-C_uAJDsn.d.cts → taskRunner-CAAPpdyi.d.cts} +2 -2
- package/dist/{taskRunner-DARTFnZN.d.ts → taskRunner-CairkunF.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-2D7F5IU3.cjs.map +0 -1
- package/dist/chunk-C4RKZY7D.cjs.map +0 -1
- package/dist/chunk-G5RPUZJE.js.map +0 -1
- package/dist/chunk-KJ5E646Y.cjs.map +0 -1
- package/dist/chunk-OV4GLPZI.js.map +0 -1
- package/dist/chunk-QX2M67YI.js.map +0 -1
- package/dist/chunk-YHJJSLE5.js.map +0 -1
- package/dist/chunk-ZLDO4QDR.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkSH23SRZE_cjs = require('./chunk-SH23SRZE.cjs');
|
|
4
|
+
var chunkYYWEBYFJ_cjs = require('./chunk-YYWEBYFJ.cjs');
|
|
5
|
+
var chunkJ5EX3OMM_cjs = require('./chunk-J5EX3OMM.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 = chunkJ5EX3OMM_cjs.getArkPsbtFields(tx.root, 0, chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.getArkPsbtFields(g.root, 0, chunkJ5EX3OMM_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
|
+
chunkJ5EX3OMM_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 = chunkYYWEBYFJ_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 chunkYYWEBYFJ_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 = chunkYYWEBYFJ_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
|
+
chunkJ5EX3OMM_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 = chunkYYWEBYFJ_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 chunkYYWEBYFJ_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 chunkYYWEBYFJ_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
882
882
|
}
|
|
883
883
|
async compressedPublicKey() {
|
|
884
|
-
return
|
|
884
|
+
return chunkYYWEBYFJ_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 && chunkYYWEBYFJ_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 = chunkYYWEBYFJ_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 chunkYYWEBYFJ_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 chunkYYWEBYFJ_cjs.identityDescriptor(wallet.identity);
|
|
1337
1337
|
}
|
|
1338
1338
|
async function provisionRefundKey(wallet) {
|
|
1339
|
-
const descriptor = await
|
|
1339
|
+
const descriptor = await chunkYYWEBYFJ_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 } = chunkJ5EX3OMM_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 = chunkYYWEBYFJ_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 chunkJ5EX3OMM_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: chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.rateGate.runHttp(url, () => chunkJ5EX3OMM_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[chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2042
2042
|
if (tipBlocks.status === 404) {
|
|
2043
|
-
tipBlocks = await
|
|
2043
|
+
tipBlocks = await chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.getArkPsbtFields(child.root, 0, chunkJ5EX3OMM_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 chunkSH23SRZE_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 chunkSH23SRZE_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 chunkSH23SRZE_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 chunkSH23SRZE_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 chunkSH23SRZE_cjs.Packet.PACKET_TYPE:
|
|
2664
|
+
return chunkSH23SRZE_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 chunkJ5EX3OMM_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2712
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2716
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2720
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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
|
+
chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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(chunkSH23SRZE_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
|
+
chunkSH23SRZE_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
|
+
chunkSH23SRZE_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
|
+
chunkSH23SRZE_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 = chunkSH23SRZE_cjs.AssetId.fromString(assetIdStr);
|
|
3167
|
+
const group = chunkSH23SRZE_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3168
3168
|
groups.push(group);
|
|
3169
3169
|
}
|
|
3170
|
-
return
|
|
3170
|
+
return chunkSH23SRZE_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(chunkYYWEBYFJ_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
3312
3312
|
} catch (e) {
|
|
3313
|
-
throw new
|
|
3313
|
+
throw new chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.decodeTapscript(chunkJ5EX3OMM_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3370
|
+
if (chunkJ5EX3OMM_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 chunkJ5EX3OMM_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: chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3392
3392
|
amount: BigInt(input.value)
|
|
3393
3393
|
},
|
|
3394
3394
|
tapLeafScript: [input.tapLeafScript]
|
|
3395
3395
|
});
|
|
3396
|
-
|
|
3396
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(tx, i, chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.decodeTapscript(chunkJ5EX3OMM_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3406
|
+
const checkpointVtxoScript = new chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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
|
+
chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3589
3589
|
if (finalTxid !== signedArkTx.id) {
|
|
3590
|
-
throw new
|
|
3590
|
+
throw new chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.scriptFromTapLeafScript(leaf);
|
|
3603
3603
|
let leafPubkeys;
|
|
3604
3604
|
try {
|
|
3605
|
-
leafPubkeys =
|
|
3606
|
-
(key) => base.hex.encode(
|
|
3605
|
+
leafPubkeys = chunkJ5EX3OMM_cjs.decodeTapscript(script).params.pubkeys.map(
|
|
3606
|
+
(key) => base.hex.encode(chunkYYWEBYFJ_cjs.toXOnly(key, "leaf key"))
|
|
3607
3607
|
);
|
|
3608
3608
|
} catch (error) {
|
|
3609
|
-
throw new
|
|
3609
|
+
throw new chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 chunkJ5EX3OMM_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
|
+
chunkJ5EX3OMM_cjs.assertAllowedSighashTypes(server);
|
|
3686
3686
|
} catch (error) {
|
|
3687
|
-
throw new
|
|
3687
|
+
throw new chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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(chunkYYWEBYFJ_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 = chunkJ5EX3OMM_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
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(signed, index, chunkJ5EX3OMM_cjs.ConditionWitness, [preimage]);
|
|
3760
3760
|
}
|
|
3761
3761
|
return signed;
|
|
3762
3762
|
}
|
|
@@ -3951,7 +3951,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3951
3951
|
};
|
|
3952
3952
|
}
|
|
3953
3953
|
function deriveContractTapscripts(contract) {
|
|
3954
|
-
const handler =
|
|
3954
|
+
const handler = chunkYYWEBYFJ_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
|
+
chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 chunkYYWEBYFJ_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 (!chunkYYWEBYFJ_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 (!chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
4189
4189
|
}
|
|
4190
4190
|
function canMigrateBySend(vtxo, now) {
|
|
4191
|
-
if (!
|
|
4191
|
+
if (!chunkJ5EX3OMM_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 chunkJ5EX3OMM_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(chunkJ5EX3OMM_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(chunkJ5EX3OMM_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 (chunkJ5EX3OMM_cjs.canRecoverOnchain(vtxo, now)) {
|
|
4271
4271
|
return true;
|
|
4272
4272
|
}
|
|
4273
|
-
if (
|
|
4273
|
+
if (chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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) || chunkJ5EX3OMM_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 chunkJ5EX3OMM_cjs.Transaction();
|
|
4916
4916
|
for (const utxo of expiredUtxos) {
|
|
4917
|
-
const utxoScript =
|
|
4917
|
+
const utxoScript = chunkJ5EX3OMM_cjs.VtxoScript.decode(utxo.tapTree);
|
|
4918
4918
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
4919
|
-
(leaf) =>
|
|
4919
|
+
(leaf) => chunkJ5EX3OMM_cjs.CSVMultisigTapscript.isScriptValid(chunkJ5EX3OMM_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: chunkJ5EX3OMM_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 && !chunkJ5EX3OMM_cjs.hasTerminalSpend(v));
|
|
5178
|
+
const spendable = live.filter((v) => !chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.maybeArkError(error);
|
|
5584
|
+
if (!chunkJ5EX3OMM_cjs.isArkError(ark, chunkJ5EX3OMM_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(chunkJ5EX3OMM_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(chunkJ5EX3OMM_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 chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 chunkYYWEBYFJ_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(chunkJ5EX3OMM_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: chunkJ5EX3OMM_cjs.DEFAULT_PAGE_SIZE }
|
|
6363
6363
|
);
|
|
6364
6364
|
chain.push(...page);
|
|
6365
|
-
hasMore = meta ? page.length ===
|
|
6365
|
+
hasMore = meta ? page.length === chunkJ5EX3OMM_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: chunkJ5EX3OMM_cjs.DEFAULT_PAGE_SIZE
|
|
6378
6378
|
});
|
|
6379
6379
|
for (const psbt of txs) {
|
|
6380
|
-
out.set(
|
|
6380
|
+
out.set(chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6381
6381
|
}
|
|
6382
|
-
hasMore = page ? txs.length ===
|
|
6382
|
+
hasMore = page ? txs.length === chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
6763
6763
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
6764
6764
|
if (!snapshot) {
|
|
6765
|
-
throw new
|
|
6765
|
+
throw new chunkJ5EX3OMM_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(chunkJ5EX3OMM_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 ? chunkSH23SRZE_cjs.AssetRef.fromId(chunkSH23SRZE_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 = chunkSH23SRZE_cjs.AssetOutput.create(0, params.amount);
|
|
7360
|
+
const issuedAssetGroup = chunkSH23SRZE_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(chunkSH23SRZE_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7376
7376
|
}
|
|
7377
7377
|
}
|
|
7378
7378
|
groups.push(
|
|
7379
|
-
|
|
7380
|
-
|
|
7379
|
+
chunkSH23SRZE_cjs.AssetGroup.create(
|
|
7380
|
+
chunkSH23SRZE_cjs.AssetId.fromString(assetId),
|
|
7381
7381
|
null,
|
|
7382
7382
|
changeInputs,
|
|
7383
|
-
[
|
|
7383
|
+
[chunkSH23SRZE_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 = chunkJ5EX3OMM_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([chunkSH23SRZE_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: chunkSH23SRZE_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(chunkSH23SRZE_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 = chunkSH23SRZE_cjs.AssetId.fromString(params.assetId);
|
|
7481
|
+
const reissueAssetGroup = chunkSH23SRZE_cjs.AssetGroup.create(
|
|
7482
7482
|
reissueAssetIdObj,
|
|
7483
7483
|
null,
|
|
7484
7484
|
reissueInputs,
|
|
7485
|
-
[
|
|
7485
|
+
[chunkSH23SRZE_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(chunkSH23SRZE_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7495
7495
|
}
|
|
7496
7496
|
}
|
|
7497
7497
|
groups.push(
|
|
7498
|
-
|
|
7499
|
-
|
|
7498
|
+
chunkSH23SRZE_cjs.AssetGroup.create(
|
|
7499
|
+
chunkSH23SRZE_cjs.AssetId.fromString(assetId),
|
|
7500
7500
|
null,
|
|
7501
7501
|
changeInputs,
|
|
7502
|
-
[
|
|
7502
|
+
[chunkSH23SRZE_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 = chunkJ5EX3OMM_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([chunkSH23SRZE_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(chunkSH23SRZE_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7582
7582
|
}
|
|
7583
7583
|
}
|
|
7584
7584
|
groups.push(
|
|
7585
|
-
|
|
7586
|
-
|
|
7585
|
+
chunkSH23SRZE_cjs.AssetGroup.create(
|
|
7586
|
+
chunkSH23SRZE_cjs.AssetId.fromString(assetId),
|
|
7587
7587
|
null,
|
|
7588
7588
|
changeInputs,
|
|
7589
|
-
amount > 0n ? [
|
|
7589
|
+
amount > 0n ? [chunkSH23SRZE_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 = chunkJ5EX3OMM_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([chunkSH23SRZE_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(chunkSH23SRZE_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 = chunkJ5EX3OMM_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(chunkJ5EX3OMM_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 (chunkJ5EX3OMM_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7680
7680
|
recoverableVtxos.push(vtxo);
|
|
7681
7681
|
continue;
|
|
7682
7682
|
}
|
|
7683
|
-
const expiry =
|
|
7683
|
+
const expiry = chunkJ5EX3OMM_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) => !chunkJ5EX3OMM_cjs.canRecoverOnchain(coin, now) && chunkJ5EX3OMM_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunkJ5EX3OMM_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
|
+
...chunkJ5EX3OMM_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: chunkJ5EX3OMM_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(chunkJ5EX3OMM_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
7820
7820
|
);
|
|
7821
7821
|
const forfeits = await Promise.all(
|
|
7822
|
-
vtxos.filter((v) => !
|
|
7822
|
+
vtxos.filter((v) => !chunkJ5EX3OMM_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: chunkJ5EX3OMM_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 = chunkJ5EX3OMM_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 = chunkJ5EX3OMM_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
7932
7932
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
7933
|
-
const arkTapscript =
|
|
7934
|
-
if (!
|
|
7933
|
+
const arkTapscript = chunkJ5EX3OMM_cjs.decodeTapscript(chunkJ5EX3OMM_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
7934
|
+
if (!chunkJ5EX3OMM_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(chunkJ5EX3OMM_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(chunkJ5EX3OMM_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 = chunkYYWEBYFJ_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 = chunkJ5EX3OMM_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
8867
8926
|
const parsed = decodeArkContract(encoded);
|
|
8868
|
-
const handler =
|
|
8927
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
8869
8928
|
const params = parsed.data;
|
|
8870
8929
|
const vtxoScript = handler.createScript(params);
|
|
8871
8930
|
return {
|
|
@@ -9032,23 +9091,32 @@ var ContractWatcher = class {
|
|
|
9032
9091
|
}
|
|
9033
9092
|
/** @see IContractManager.watchScript for the delivery and filter contract. */
|
|
9034
9093
|
async addWatchedScript(script, options) {
|
|
9035
|
-
const
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9094
|
+
const added = [];
|
|
9095
|
+
for (const one of Array.isArray(script) ? script : [script]) {
|
|
9096
|
+
const existing = this.watchedScripts.get(one);
|
|
9097
|
+
if (existing) {
|
|
9098
|
+
if (options?.label !== void 0) existing.label = options.label;
|
|
9099
|
+
continue;
|
|
9100
|
+
}
|
|
9101
|
+
this.watchedScripts.set(one, {
|
|
9102
|
+
label: options?.label,
|
|
9103
|
+
lastKnownVtxos: /* @__PURE__ */ new Map()
|
|
9104
|
+
});
|
|
9105
|
+
added.push(one);
|
|
9039
9106
|
}
|
|
9040
|
-
this.
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
});
|
|
9044
|
-
if (this.isWatching) {
|
|
9045
|
-
await this.pollWatchedScripts([script]);
|
|
9107
|
+
if (added.length === 0 || !this.isWatching) return;
|
|
9108
|
+
await this.withCoalescedSubscription(async () => {
|
|
9109
|
+
await this.pollWatchedScripts(added);
|
|
9046
9110
|
await this.tryUpdateSubscription();
|
|
9047
|
-
}
|
|
9111
|
+
});
|
|
9048
9112
|
}
|
|
9049
9113
|
/** Stop watching a script added by {@link addWatchedScript}. */
|
|
9050
9114
|
async removeWatchedScript(script) {
|
|
9051
|
-
|
|
9115
|
+
let removed = false;
|
|
9116
|
+
for (const one of Array.isArray(script) ? script : [script]) {
|
|
9117
|
+
if (this.watchedScripts.delete(one)) removed = true;
|
|
9118
|
+
}
|
|
9119
|
+
if (!removed) return;
|
|
9052
9120
|
if (this.isWatching) {
|
|
9053
9121
|
await this.tryUpdateSubscription();
|
|
9054
9122
|
}
|
|
@@ -9162,9 +9230,9 @@ var ContractWatcher = class {
|
|
|
9162
9230
|
this.connectionState = "connected";
|
|
9163
9231
|
this.reconnectAttempts = 0;
|
|
9164
9232
|
this.listenLoop().catch((e) => {
|
|
9165
|
-
if (
|
|
9233
|
+
if (chunkJ5EX3OMM_cjs.isEventSourceError(e)) {
|
|
9166
9234
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
9167
|
-
} else if (!
|
|
9235
|
+
} else if (!chunkJ5EX3OMM_cjs.isEventSourceUnavailableError(e)) {
|
|
9168
9236
|
console.error(e);
|
|
9169
9237
|
}
|
|
9170
9238
|
this.connectionState = "disconnected";
|
|
@@ -9176,7 +9244,7 @@ var ContractWatcher = class {
|
|
|
9176
9244
|
this.scheduleReconnect();
|
|
9177
9245
|
});
|
|
9178
9246
|
} catch (error) {
|
|
9179
|
-
if (!
|
|
9247
|
+
if (!chunkJ5EX3OMM_cjs.isEventSourceUnavailableError(error)) {
|
|
9180
9248
|
console.error("ContractWatcher connection failed:", error);
|
|
9181
9249
|
}
|
|
9182
9250
|
this.connectionState = "disconnected";
|
|
@@ -9202,7 +9270,7 @@ var ContractWatcher = class {
|
|
|
9202
9270
|
* slower; what it loses is push latency.
|
|
9203
9271
|
*/
|
|
9204
9272
|
reportEventSourceUnavailable(error) {
|
|
9205
|
-
if (!
|
|
9273
|
+
if (!chunkJ5EX3OMM_cjs.isEventSourceUnavailableError(error)) return false;
|
|
9206
9274
|
if (!this.eventSourceReported) {
|
|
9207
9275
|
this.eventSourceReported = true;
|
|
9208
9276
|
console.warn(
|
|
@@ -9274,7 +9342,7 @@ var ContractWatcher = class {
|
|
|
9274
9342
|
const now = Date.now();
|
|
9275
9343
|
let current;
|
|
9276
9344
|
try {
|
|
9277
|
-
current = await
|
|
9345
|
+
current = await chunkJ5EX3OMM_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
9278
9346
|
spendableOnly: true
|
|
9279
9347
|
});
|
|
9280
9348
|
} catch (error) {
|
|
@@ -9483,14 +9551,14 @@ var ContractWatcher = class {
|
|
|
9483
9551
|
const timestamp = Date.now();
|
|
9484
9552
|
if (update.newVtxos?.length) {
|
|
9485
9553
|
this.processSubscriptionVtxos(
|
|
9486
|
-
update.newVtxos.map(
|
|
9554
|
+
update.newVtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo),
|
|
9487
9555
|
"vtxo_received",
|
|
9488
9556
|
timestamp
|
|
9489
9557
|
);
|
|
9490
9558
|
}
|
|
9491
9559
|
if (update.spentVtxos?.length) {
|
|
9492
9560
|
this.processSubscriptionVtxos(
|
|
9493
|
-
update.spentVtxos.map(
|
|
9561
|
+
update.spentVtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo),
|
|
9494
9562
|
"vtxo_spent",
|
|
9495
9563
|
timestamp
|
|
9496
9564
|
);
|
|
@@ -9518,8 +9586,8 @@ var ContractWatcher = class {
|
|
|
9518
9586
|
continue;
|
|
9519
9587
|
}
|
|
9520
9588
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
9521
|
-
const n =
|
|
9522
|
-
if (
|
|
9589
|
+
const n = chunkJ5EX3OMM_cjs.normalizeVtxo(vtxo);
|
|
9590
|
+
if (chunkJ5EX3OMM_cjs.hasTerminalSpend(n) || n.isSwept || chunkJ5EX3OMM_cjs.isPastExpiry(n, now)) continue;
|
|
9523
9591
|
}
|
|
9524
9592
|
let bucket = target.get(vtxo.script);
|
|
9525
9593
|
if (!bucket) {
|
|
@@ -9618,7 +9686,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
9618
9686
|
(s) => !isTerminalIntentState(s)
|
|
9619
9687
|
);
|
|
9620
9688
|
function isConsumed(vtxo) {
|
|
9621
|
-
return vtxo !== void 0 &&
|
|
9689
|
+
return vtxo !== void 0 && chunkJ5EX3OMM_cjs.hasTerminalSpend(vtxo);
|
|
9622
9690
|
}
|
|
9623
9691
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
9624
9692
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -9661,7 +9729,7 @@ async function reconcileIntents(deps) {
|
|
|
9661
9729
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
9662
9730
|
if (outpoints.length > 0) {
|
|
9663
9731
|
try {
|
|
9664
|
-
const { vtxos } = await
|
|
9732
|
+
const { vtxos } = await chunkJ5EX3OMM_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9665
9733
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9666
9734
|
} catch (e) {
|
|
9667
9735
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9801,7 +9869,21 @@ var ContractManager = class _ContractManager {
|
|
|
9801
9869
|
}
|
|
9802
9870
|
markSyncOnline() {
|
|
9803
9871
|
this.lastSyncedAt = Date.now();
|
|
9804
|
-
this.syncDegradedReason = this.
|
|
9872
|
+
this.syncDegradedReason = this.syncGapReason();
|
|
9873
|
+
}
|
|
9874
|
+
/**
|
|
9875
|
+
* Why a sync that just succeeded still has not covered everything it should
|
|
9876
|
+
* have. Both reasons outlive the sync that failed to cover them, so neither
|
|
9877
|
+
* is discharged by the next one succeeding — which is the point: a wallet
|
|
9878
|
+
* that reported itself current while the look-ahead band sat behind the
|
|
9879
|
+
* watermark, or while a contract could not be annotated, would be claiming
|
|
9880
|
+
* coverage it never had. `getSyncState()` is the channel apps already watch.
|
|
9881
|
+
*/
|
|
9882
|
+
syncGapReason() {
|
|
9883
|
+
const annotations = this.annotationDegradedReason();
|
|
9884
|
+
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;
|
|
9885
|
+
const reasons = [annotations, owedRefill].filter((r) => r !== void 0);
|
|
9886
|
+
return reasons.length === 0 ? void 0 : reasons.join("; ");
|
|
9805
9887
|
}
|
|
9806
9888
|
/** Contracts a sync could not annotate, as `script → reason`. */
|
|
9807
9889
|
annotationFailures = /* @__PURE__ */ new Map();
|
|
@@ -9835,12 +9917,18 @@ var ContractManager = class _ContractManager {
|
|
|
9835
9917
|
for (const contract of contracts) {
|
|
9836
9918
|
await this.watcher.addContract(contract);
|
|
9837
9919
|
}
|
|
9838
|
-
|
|
9920
|
+
try {
|
|
9921
|
+
await this.scheduleLookAheadDrain();
|
|
9922
|
+
} catch (err) {
|
|
9923
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
9924
|
+
this.lookAheadRefillOwed = true;
|
|
9925
|
+
this.markSyncDegraded(err);
|
|
9926
|
+
}
|
|
9839
9927
|
try {
|
|
9840
9928
|
await this.reconcileWatched();
|
|
9841
9929
|
this.markSyncOnline();
|
|
9842
9930
|
} catch (err) {
|
|
9843
|
-
if (!
|
|
9931
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
9844
9932
|
this.markSyncDegraded(err);
|
|
9845
9933
|
}
|
|
9846
9934
|
this.initialized = true;
|
|
@@ -9972,7 +10060,7 @@ var ContractManager = class _ContractManager {
|
|
|
9972
10060
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
9973
10061
|
const to = watermark + lookAhead.size;
|
|
9974
10062
|
const deps = lookAhead.candidateDeps();
|
|
9975
|
-
const handlers =
|
|
10063
|
+
const handlers = chunkYYWEBYFJ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkYYWEBYFJ_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
9976
10064
|
const band = /* @__PURE__ */ new Map();
|
|
9977
10065
|
for (let index = from; index <= to; index++) {
|
|
9978
10066
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -9983,7 +10071,7 @@ var ContractManager = class _ContractManager {
|
|
|
9983
10071
|
index,
|
|
9984
10072
|
params: {
|
|
9985
10073
|
...candidate,
|
|
9986
|
-
...
|
|
10074
|
+
...chunkYYWEBYFJ_cjs.speculativeReceiveMetadata(descriptor)
|
|
9987
10075
|
}
|
|
9988
10076
|
});
|
|
9989
10077
|
}
|
|
@@ -10045,7 +10133,7 @@ var ContractManager = class _ContractManager {
|
|
|
10045
10133
|
});
|
|
10046
10134
|
for (const entry of pending) entry.catchUpPending = false;
|
|
10047
10135
|
} catch (err) {
|
|
10048
|
-
if (!
|
|
10136
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
10049
10137
|
this.markSyncDegraded(err);
|
|
10050
10138
|
}
|
|
10051
10139
|
}
|
|
@@ -10095,7 +10183,7 @@ var ContractManager = class _ContractManager {
|
|
|
10095
10183
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
10096
10184
|
this.markSyncOnline();
|
|
10097
10185
|
} catch (err) {
|
|
10098
|
-
if (!
|
|
10186
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
10099
10187
|
this.markSyncDegraded(err);
|
|
10100
10188
|
}
|
|
10101
10189
|
await this.watcher.addContract(contract);
|
|
@@ -10129,7 +10217,7 @@ var ContractManager = class _ContractManager {
|
|
|
10129
10217
|
await this.fetchContractVxosFromIndexer(fresh);
|
|
10130
10218
|
this.markSyncOnline();
|
|
10131
10219
|
} catch (err) {
|
|
10132
|
-
if (!
|
|
10220
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
10133
10221
|
this.markSyncDegraded(err);
|
|
10134
10222
|
}
|
|
10135
10223
|
for (const contract of fresh) await this.watcher.addContract(contract);
|
|
@@ -10167,7 +10255,7 @@ var ContractManager = class _ContractManager {
|
|
|
10167
10255
|
return result;
|
|
10168
10256
|
}
|
|
10169
10257
|
async upsertContractRow(params) {
|
|
10170
|
-
const handler =
|
|
10258
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(params.type);
|
|
10171
10259
|
if (!handler) {
|
|
10172
10260
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
10173
10261
|
}
|
|
@@ -10267,7 +10355,7 @@ var ContractManager = class _ContractManager {
|
|
|
10267
10355
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
10268
10356
|
);
|
|
10269
10357
|
}
|
|
10270
|
-
const registered =
|
|
10358
|
+
const registered = chunkYYWEBYFJ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkYYWEBYFJ_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
10271
10359
|
const discoverables = [
|
|
10272
10360
|
...registered.filter((h) => h.type === "boarding"),
|
|
10273
10361
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -10405,7 +10493,7 @@ var ContractManager = class _ContractManager {
|
|
|
10405
10493
|
await this.syncContracts({ contracts, pageSize });
|
|
10406
10494
|
this.markSyncOnline();
|
|
10407
10495
|
} catch (err) {
|
|
10408
|
-
if (!
|
|
10496
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
10409
10497
|
this.markSyncDegraded(err);
|
|
10410
10498
|
}
|
|
10411
10499
|
}
|
|
@@ -10427,7 +10515,7 @@ var ContractManager = class _ContractManager {
|
|
|
10427
10515
|
}
|
|
10428
10516
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
10429
10517
|
return vtxos.map(
|
|
10430
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
10518
|
+
(vtxo) => extendVirtualCoinForContract(chunkJ5EX3OMM_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
10431
10519
|
);
|
|
10432
10520
|
}
|
|
10433
10521
|
/** @inheritdoc */
|
|
@@ -10471,14 +10559,14 @@ var ContractManager = class _ContractManager {
|
|
|
10471
10559
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10472
10560
|
const asking = vtxos.filter((vtxo) => {
|
|
10473
10561
|
const contract = byScript.get(vtxo.script);
|
|
10474
|
-
return contract !== void 0 &&
|
|
10562
|
+
return contract !== void 0 && chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10475
10563
|
});
|
|
10476
10564
|
if (asking.length === 0) return refused;
|
|
10477
10565
|
const tip = await this.currentChainTip();
|
|
10478
10566
|
const walletKey = await walletPubKey?.();
|
|
10479
10567
|
for (const vtxo of asking) {
|
|
10480
10568
|
const contract = byScript.get(vtxo.script);
|
|
10481
|
-
const handler =
|
|
10569
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
10482
10570
|
if (!handler?.assertSpendableNow) continue;
|
|
10483
10571
|
const context = {
|
|
10484
10572
|
collaborative: true,
|
|
@@ -10493,7 +10581,7 @@ var ContractManager = class _ContractManager {
|
|
|
10493
10581
|
// the next handler to answer a CSV question would meet a
|
|
10494
10582
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
10495
10583
|
// really is one.
|
|
10496
|
-
vtxo:
|
|
10584
|
+
vtxo: chunkJ5EX3OMM_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10497
10585
|
};
|
|
10498
10586
|
try {
|
|
10499
10587
|
await handler.assertSpendableNow(
|
|
@@ -10649,7 +10737,7 @@ var ContractManager = class _ContractManager {
|
|
|
10649
10737
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
10650
10738
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10651
10739
|
if (!contract) return [];
|
|
10652
|
-
const handler =
|
|
10740
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
10653
10741
|
if (!handler) return [];
|
|
10654
10742
|
const script = handler.createScript(contract.params);
|
|
10655
10743
|
const tip = await this.currentChainTip();
|
|
@@ -10677,7 +10765,7 @@ var ContractManager = class _ContractManager {
|
|
|
10677
10765
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
10678
10766
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10679
10767
|
if (!contract) return [];
|
|
10680
|
-
const handler =
|
|
10768
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
10681
10769
|
if (!handler) return [];
|
|
10682
10770
|
const script = handler.createScript(contract.params);
|
|
10683
10771
|
const context = {
|
|
@@ -10733,7 +10821,7 @@ var ContractManager = class _ContractManager {
|
|
|
10733
10821
|
}
|
|
10734
10822
|
async refreshOutpoints(outpoints) {
|
|
10735
10823
|
if (outpoints.length === 0) return;
|
|
10736
|
-
const { vtxos } = await
|
|
10824
|
+
const { vtxos } = await chunkJ5EX3OMM_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10737
10825
|
outpoints
|
|
10738
10826
|
});
|
|
10739
10827
|
if (vtxos.length === 0) return;
|
|
@@ -10759,7 +10847,13 @@ var ContractManager = class _ContractManager {
|
|
|
10759
10847
|
if (contract) {
|
|
10760
10848
|
await saveVtxosForContract(this.config.walletRepository, contract, addressVtxos);
|
|
10761
10849
|
} else {
|
|
10762
|
-
await
|
|
10850
|
+
await inVtxoWriteOrder(
|
|
10851
|
+
this.config.walletRepository,
|
|
10852
|
+
async () => this.config.walletRepository.saveVtxos(
|
|
10853
|
+
address,
|
|
10854
|
+
applyRecordedSpends(this.config.walletRepository, addressVtxos)
|
|
10855
|
+
)
|
|
10856
|
+
);
|
|
10763
10857
|
}
|
|
10764
10858
|
}
|
|
10765
10859
|
}
|
|
@@ -10829,7 +10923,7 @@ var ContractManager = class _ContractManager {
|
|
|
10829
10923
|
break;
|
|
10830
10924
|
}
|
|
10831
10925
|
} catch (err) {
|
|
10832
|
-
if (!
|
|
10926
|
+
if (!chunkJ5EX3OMM_cjs.isRetryableProviderError(err)) throw err;
|
|
10833
10927
|
this.markSyncDegraded(err);
|
|
10834
10928
|
}
|
|
10835
10929
|
this.emitEvent(event);
|
|
@@ -10920,7 +11014,7 @@ var ContractManager = class _ContractManager {
|
|
|
10920
11014
|
*/
|
|
10921
11015
|
async reconcilePendingFrontier(contracts) {
|
|
10922
11016
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
10923
|
-
const vtxos = await
|
|
11017
|
+
const vtxos = await chunkJ5EX3OMM_cjs.getAllNormalizedVtxos(
|
|
10924
11018
|
this.config.indexerProvider,
|
|
10925
11019
|
contracts.map((c) => c.script),
|
|
10926
11020
|
{ pendingOnly: true }
|
|
@@ -11003,7 +11097,7 @@ var ContractManager = class _ContractManager {
|
|
|
11003
11097
|
}
|
|
11004
11098
|
return result;
|
|
11005
11099
|
}
|
|
11006
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
11100
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkJ5EX3OMM_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
11007
11101
|
if (contracts.length === 0) {
|
|
11008
11102
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
11009
11103
|
}
|
|
@@ -11019,7 +11113,7 @@ var ContractManager = class _ContractManager {
|
|
|
11019
11113
|
before: syncWindow.before
|
|
11020
11114
|
}
|
|
11021
11115
|
} : {};
|
|
11022
|
-
const vtxos = await
|
|
11116
|
+
const vtxos = await chunkJ5EX3OMM_cjs.getAllNormalizedVtxos(
|
|
11023
11117
|
this.config.indexerProvider,
|
|
11024
11118
|
contracts.map((c) => c.script),
|
|
11025
11119
|
{ ...windowOpts, pageSize }
|
|
@@ -11164,7 +11258,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
11164
11258
|
const s = base.hex.decode(t.s);
|
|
11165
11259
|
return [cb, s];
|
|
11166
11260
|
};
|
|
11167
|
-
var deserializeVtxo = (o) =>
|
|
11261
|
+
var deserializeVtxo = (o) => chunkJ5EX3OMM_cjs.normalizeVtxo({
|
|
11168
11262
|
...o,
|
|
11169
11263
|
createdAt: new Date(o.createdAt),
|
|
11170
11264
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11987,7 +12081,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11987
12081
|
*/
|
|
11988
12082
|
materializeDescriptorAt(index) {
|
|
11989
12083
|
const descriptor = this.identity.descriptor;
|
|
11990
|
-
const network =
|
|
12084
|
+
const network = chunkYYWEBYFJ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
11991
12085
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
11992
12086
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
11993
12087
|
if (!keyInfo?.keyExpression) {
|
|
@@ -12135,7 +12229,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12135
12229
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
12136
12230
|
if (!provider) return void 0;
|
|
12137
12231
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
12138
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
12232
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
12139
12233
|
const factoryOpts = {
|
|
12140
12234
|
walletRepository: setup.walletRepository,
|
|
12141
12235
|
contractRepository: setup.contractRepository,
|
|
@@ -12336,7 +12430,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12336
12430
|
};
|
|
12337
12431
|
function deriveLeafPubkey(descriptor) {
|
|
12338
12432
|
try {
|
|
12339
|
-
return
|
|
12433
|
+
return chunkYYWEBYFJ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
12340
12434
|
} catch (e) {
|
|
12341
12435
|
throw new NonRangeableDescriptorError(
|
|
12342
12436
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -12348,7 +12442,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12348
12442
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
12349
12443
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
12350
12444
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
12351
|
-
const csvTimelock =
|
|
12445
|
+
const csvTimelock = chunkJ5EX3OMM_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
12352
12446
|
const base$1 = {
|
|
12353
12447
|
script: base.hex.encode(tapscript.pkScript),
|
|
12354
12448
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -12359,11 +12453,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12359
12453
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
12360
12454
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
12361
12455
|
metadata: {
|
|
12362
|
-
...tagSource && { source:
|
|
12456
|
+
...tagSource && { source: chunkYYWEBYFJ_cjs.WALLET_RECEIVE_SOURCE },
|
|
12363
12457
|
signingDescriptor: descriptor
|
|
12364
12458
|
}
|
|
12365
12459
|
};
|
|
12366
|
-
const params = tapscript instanceof
|
|
12460
|
+
const params = tapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? {
|
|
12367
12461
|
...base$1,
|
|
12368
12462
|
type: "delegate",
|
|
12369
12463
|
params: {
|
|
@@ -12384,10 +12478,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12384
12478
|
return { tapscript, params };
|
|
12385
12479
|
}
|
|
12386
12480
|
function rebuildTapscript(current, pubKey) {
|
|
12387
|
-
if (current instanceof
|
|
12388
|
-
return new
|
|
12481
|
+
if (current instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script) {
|
|
12482
|
+
return new chunkYYWEBYFJ_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12389
12483
|
}
|
|
12390
|
-
return new
|
|
12484
|
+
return new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12391
12485
|
}
|
|
12392
12486
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12393
12487
|
const candidates = await contractRepository.getContracts({
|
|
@@ -12396,7 +12490,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
12396
12490
|
});
|
|
12397
12491
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
12398
12492
|
const matching = candidates.filter(
|
|
12399
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12493
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkYYWEBYFJ_cjs.WALLET_RECEIVE_SOURCE
|
|
12400
12494
|
).sort((a, b) => {
|
|
12401
12495
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12402
12496
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12452,7 +12546,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12452
12546
|
}
|
|
12453
12547
|
};
|
|
12454
12548
|
for (const vtxo of vtxos) {
|
|
12455
|
-
if (
|
|
12549
|
+
if (chunkJ5EX3OMM_cjs.hasTerminalSpend(vtxo)) continue;
|
|
12456
12550
|
addAssets(owned, vtxo);
|
|
12457
12551
|
if (vtxo.isUnrolled) {
|
|
12458
12552
|
unrolled += vtxo.value;
|
|
@@ -12462,11 +12556,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12462
12556
|
pendingRecovery += vtxo.value;
|
|
12463
12557
|
continue;
|
|
12464
12558
|
}
|
|
12465
|
-
if (
|
|
12559
|
+
if (chunkJ5EX3OMM_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12466
12560
|
recoverable += vtxo.value;
|
|
12467
12561
|
continue;
|
|
12468
12562
|
}
|
|
12469
|
-
if (!
|
|
12563
|
+
if (!chunkJ5EX3OMM_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12470
12564
|
if (vtxo.isPreconfirmed) {
|
|
12471
12565
|
preconfirmed += vtxo.value;
|
|
12472
12566
|
} else {
|
|
@@ -12538,8 +12632,9 @@ var InputSignerRouter = class {
|
|
|
12538
12632
|
async classify(jobs) {
|
|
12539
12633
|
const identityIndexes = [];
|
|
12540
12634
|
const descriptorGroups = /* @__PURE__ */ new Map();
|
|
12635
|
+
const unknownIndexes = [];
|
|
12541
12636
|
if (jobs.length === 0) {
|
|
12542
|
-
return { identityIndexes, descriptorGroups };
|
|
12637
|
+
return { identityIndexes, descriptorGroups, unknownIndexes };
|
|
12543
12638
|
}
|
|
12544
12639
|
const distinctScripts = Array.from(new Set(jobs.map((j) => base.hex.encode(j.lookupScript))));
|
|
12545
12640
|
const contracts = await this.deps.contractRepository.getContracts({
|
|
@@ -12559,6 +12654,8 @@ var InputSignerRouter = class {
|
|
|
12559
12654
|
if (!contract) {
|
|
12560
12655
|
if (scriptHex === boardingScriptHex) {
|
|
12561
12656
|
identityIndexes.push(job.index);
|
|
12657
|
+
} else {
|
|
12658
|
+
unknownIndexes.push(job.index);
|
|
12562
12659
|
}
|
|
12563
12660
|
continue;
|
|
12564
12661
|
}
|
|
@@ -12585,7 +12682,7 @@ var InputSignerRouter = class {
|
|
|
12585
12682
|
descriptorGroups.set(descriptor, [job.index]);
|
|
12586
12683
|
}
|
|
12587
12684
|
}
|
|
12588
|
-
return { identityIndexes, descriptorGroups };
|
|
12685
|
+
return { identityIndexes, descriptorGroups, unknownIndexes };
|
|
12589
12686
|
}
|
|
12590
12687
|
/**
|
|
12591
12688
|
* Returns `true` when every signable input across all `jobSets` resolves
|
|
@@ -12607,12 +12704,13 @@ var InputSignerRouter = class {
|
|
|
12607
12704
|
const plan = await this.classify(jobSets.flat());
|
|
12608
12705
|
return plan.descriptorGroups.size === 0;
|
|
12609
12706
|
}
|
|
12610
|
-
async sign(tx, jobs) {
|
|
12707
|
+
async sign(tx, jobs, opts) {
|
|
12611
12708
|
if (jobs.length === 0) return tx;
|
|
12612
|
-
const { identityIndexes, descriptorGroups } = await this.classify(jobs);
|
|
12709
|
+
const { identityIndexes, descriptorGroups, unknownIndexes } = await this.classify(jobs);
|
|
12710
|
+
const identitySignIndexes = opts?.onUnknownScript === "sign" ? [...identityIndexes, ...unknownIndexes] : identityIndexes;
|
|
12613
12711
|
let signed = tx;
|
|
12614
|
-
if (
|
|
12615
|
-
signed = await this.deps.identity.sign(signed,
|
|
12712
|
+
if (identitySignIndexes.length > 0) {
|
|
12713
|
+
signed = await this.deps.identity.sign(signed, identitySignIndexes);
|
|
12616
12714
|
}
|
|
12617
12715
|
if (descriptorGroups.size > 0) {
|
|
12618
12716
|
if (!this.deps.descriptorProvider) {
|
|
@@ -12636,12 +12734,12 @@ var InputSignerRouter = class {
|
|
|
12636
12734
|
};
|
|
12637
12735
|
|
|
12638
12736
|
// src/wallet/wallet.ts
|
|
12639
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
12737
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkJ5EX3OMM_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12640
12738
|
function intentProofJobs(coins) {
|
|
12641
12739
|
if (coins.length === 0) return [];
|
|
12642
12740
|
const coinJobs = coins.map((coin, i) => ({
|
|
12643
12741
|
index: i + 1,
|
|
12644
|
-
lookupScript:
|
|
12742
|
+
lookupScript: chunkJ5EX3OMM_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12645
12743
|
}));
|
|
12646
12744
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12647
12745
|
}
|
|
@@ -12673,7 +12771,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12673
12771
|
const seen = /* @__PURE__ */ new Set();
|
|
12674
12772
|
const deduped = [];
|
|
12675
12773
|
for (const timelock of timelocks) {
|
|
12676
|
-
const sequence =
|
|
12774
|
+
const sequence = chunkJ5EX3OMM_cjs.timelockToSequence(timelock).toString();
|
|
12677
12775
|
if (seen.has(sequence)) continue;
|
|
12678
12776
|
seen.add(sequence);
|
|
12679
12777
|
deduped.push(timelock);
|
|
@@ -12690,7 +12788,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12690
12788
|
state: "active"
|
|
12691
12789
|
});
|
|
12692
12790
|
const newest = candidates.filter(
|
|
12693
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12791
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkYYWEBYFJ_cjs.WALLET_RECEIVE_SOURCE
|
|
12694
12792
|
).sort((a, b) => {
|
|
12695
12793
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12696
12794
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12698,7 +12796,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12698
12796
|
if (!newest?.params.pubKey) return baseline;
|
|
12699
12797
|
try {
|
|
12700
12798
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12701
|
-
return new
|
|
12799
|
+
return new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12702
12800
|
} catch (e) {
|
|
12703
12801
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12704
12802
|
return baseline;
|
|
@@ -12717,10 +12815,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12717
12815
|
if (vtxo.isUnrolled) {
|
|
12718
12816
|
return !!f.withUnrolled;
|
|
12719
12817
|
}
|
|
12720
|
-
if (
|
|
12818
|
+
if (chunkJ5EX3OMM_cjs.hasTerminalSpend(vtxo)) {
|
|
12721
12819
|
return false;
|
|
12722
12820
|
}
|
|
12723
|
-
if (!f.withRecoverable &&
|
|
12821
|
+
if (!f.withRecoverable && chunkJ5EX3OMM_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12724
12822
|
return false;
|
|
12725
12823
|
}
|
|
12726
12824
|
return true;
|
|
@@ -13060,7 +13158,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13060
13158
|
*/
|
|
13061
13159
|
static async setupWalletConfig(config, pubKey) {
|
|
13062
13160
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
13063
|
-
const arkProvider = config.arkProvider || new
|
|
13161
|
+
const arkProvider = config.arkProvider || new chunkJ5EX3OMM_cjs.RestArkProvider(arkadeServerUrl);
|
|
13064
13162
|
let indexerProvider = config.indexerProvider;
|
|
13065
13163
|
if (!indexerProvider) {
|
|
13066
13164
|
let indexerUrl = config.indexerUrl;
|
|
@@ -13077,7 +13175,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13077
13175
|
indexerUrl = arkadeServerUrl;
|
|
13078
13176
|
}
|
|
13079
13177
|
}
|
|
13080
|
-
indexerProvider = new
|
|
13178
|
+
indexerProvider = new chunkSH23SRZE_cjs.RestIndexerProvider(indexerUrl);
|
|
13081
13179
|
}
|
|
13082
13180
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
13083
13181
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -13086,7 +13184,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13086
13184
|
source: serverInfoSource,
|
|
13087
13185
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
13088
13186
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
13089
|
-
const network =
|
|
13187
|
+
const network = chunkJ5EX3OMM_cjs.getNetwork(info.network);
|
|
13090
13188
|
if ("descriptor" in config.identity) {
|
|
13091
13189
|
const descriptor = config.identity.descriptor;
|
|
13092
13190
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -13126,18 +13224,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13126
13224
|
value: info.boardingExitDelay,
|
|
13127
13225
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
13128
13226
|
};
|
|
13129
|
-
const serverPubKey =
|
|
13130
|
-
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) =>
|
|
13227
|
+
const serverPubKey = chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
13228
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
|
|
13131
13229
|
const offchainOptions = {
|
|
13132
13230
|
pubKey,
|
|
13133
13231
|
serverPubKey,
|
|
13134
13232
|
csvTimelock: exitTimelock
|
|
13135
13233
|
};
|
|
13136
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
13137
|
-
const boardingTapscript =
|
|
13234
|
+
const offchainTapscript = !delegatePubKey ? new chunkYYWEBYFJ_cjs.DefaultVtxo.Script(offchainOptions) : new chunkYYWEBYFJ_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
13235
|
+
const boardingTapscript = chunkYYWEBYFJ_cjs.BoardingContractHandler.createScript({
|
|
13138
13236
|
pubKey: base.hex.encode(pubKey),
|
|
13139
13237
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13140
|
-
csvTimelock:
|
|
13238
|
+
csvTimelock: chunkJ5EX3OMM_cjs.timelockToSequence(boardingTimelock).toString()
|
|
13141
13239
|
});
|
|
13142
13240
|
return {
|
|
13143
13241
|
arkProvider,
|
|
@@ -13303,7 +13401,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13303
13401
|
if (!filter?.withUnrolled) {
|
|
13304
13402
|
logExcludedVtxos(
|
|
13305
13403
|
"getSpendableVtxos",
|
|
13306
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
13404
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkJ5EX3OMM_cjs.hasTerminalSpend(vtxo)),
|
|
13307
13405
|
[() => UNROLLED_REASON]
|
|
13308
13406
|
);
|
|
13309
13407
|
}
|
|
@@ -13447,7 +13545,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13447
13545
|
this.getBoardingTxs()
|
|
13448
13546
|
]);
|
|
13449
13547
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
13450
|
-
const resolveTxCreatedAt = (txids) =>
|
|
13548
|
+
const resolveTxCreatedAt = (txids) => chunkJ5EX3OMM_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13451
13549
|
return buildTransactionHistory(
|
|
13452
13550
|
allVtxos,
|
|
13453
13551
|
boardingTxs,
|
|
@@ -13542,7 +13640,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13542
13640
|
},
|
|
13543
13641
|
isUnrolled: true,
|
|
13544
13642
|
...boardingFacts,
|
|
13545
|
-
virtualStatus:
|
|
13643
|
+
virtualStatus: chunkJ5EX3OMM_cjs.toVirtualStatus(boardingFacts),
|
|
13546
13644
|
spentBy: "",
|
|
13547
13645
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
13548
13646
|
script: scriptHex
|
|
@@ -13598,9 +13696,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13598
13696
|
async getBoardingTapscripts(allowedSigners) {
|
|
13599
13697
|
const byScript = /* @__PURE__ */ new Map();
|
|
13600
13698
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
13601
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13699
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkYYWEBYFJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13602
13700
|
add(
|
|
13603
|
-
new
|
|
13701
|
+
new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
13604
13702
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
13605
13703
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
13606
13704
|
csvTimelock: boardingCsv
|
|
@@ -13615,7 +13713,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13615
13713
|
for (const c of boardingContracts) {
|
|
13616
13714
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
13617
13715
|
try {
|
|
13618
|
-
add(
|
|
13716
|
+
add(chunkYYWEBYFJ_cjs.BoardingContractHandler.createScript(c.params));
|
|
13619
13717
|
} catch (e) {
|
|
13620
13718
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
13621
13719
|
}
|
|
@@ -13639,23 +13737,26 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13639
13737
|
*/
|
|
13640
13738
|
async getBoardingUtxosForSigners(allowedSigners) {
|
|
13641
13739
|
const tapscripts = await this.getBoardingTapscripts(allowedSigners);
|
|
13642
|
-
const
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
})
|
|
13740
|
+
const addresses = tapscripts.map((tapscript) => tapscript.onchainAddress(this.network));
|
|
13741
|
+
const groups = await Promise.all(
|
|
13742
|
+
tapscripts.map(async (tapscript, i) => {
|
|
13743
|
+
const coins = await this.onchainProvider.getCoins(addresses[i]);
|
|
13744
|
+
const utxos = coins.map((utxo) => extendCoinWithTapscript(tapscript, utxo));
|
|
13745
|
+
return {
|
|
13746
|
+
tapscript,
|
|
13747
|
+
// Normalize so the group key matches the axis/contract x-only
|
|
13748
|
+
// form regardless of how the tapscript's key was stored.
|
|
13749
|
+
serverPubKey: toXOnlySignerHex(base.hex.encode(tapscript.options.serverPubKey)),
|
|
13750
|
+
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13751
|
+
// not the wallet's current boarding timelock, which a signer
|
|
13752
|
+
// rotation may have changed.
|
|
13753
|
+
csvTimelock: chunkJ5EX3OMM_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13754
|
+
coins: utxos
|
|
13755
|
+
};
|
|
13756
|
+
})
|
|
13757
|
+
);
|
|
13758
|
+
for (const [i, group] of groups.entries()) {
|
|
13759
|
+
await this.walletRepository.saveUtxos(addresses[i], group.coins);
|
|
13659
13760
|
}
|
|
13660
13761
|
return groups;
|
|
13661
13762
|
}
|
|
@@ -13786,7 +13887,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13786
13887
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13787
13888
|
async fetchPendingTxs() {
|
|
13788
13889
|
const scripts = await this.getWalletScripts();
|
|
13789
|
-
const vtxos = await
|
|
13890
|
+
const vtxos = await chunkJ5EX3OMM_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13790
13891
|
return vtxos.filter(
|
|
13791
13892
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13792
13893
|
).map((_) => _.arkTxId);
|
|
@@ -13817,7 +13918,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13817
13918
|
});
|
|
13818
13919
|
for (const contract of contracts) {
|
|
13819
13920
|
if (map.has(contract.script)) continue;
|
|
13820
|
-
const handler =
|
|
13921
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
13821
13922
|
if (handler) {
|
|
13822
13923
|
const script = handler.createScript(contract.params);
|
|
13823
13924
|
map.set(contract.script, script);
|
|
@@ -13929,7 +14030,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13929
14030
|
}
|
|
13930
14031
|
});
|
|
13931
14032
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
13932
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14033
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
13933
14034
|
const baselineSigners = [
|
|
13934
14035
|
this.offchainTapscript.options.serverPubKey,
|
|
13935
14036
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -13937,8 +14038,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13937
14038
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
13938
14039
|
for (const serverPubKey of baselineSigners) {
|
|
13939
14040
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
13940
|
-
const csvTimelockStr =
|
|
13941
|
-
const defaultScript = new
|
|
14041
|
+
const csvTimelockStr = chunkJ5EX3OMM_cjs.timelockToSequence(csvTimelock).toString();
|
|
14042
|
+
const defaultScript = new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
13942
14043
|
pubKey: baselinePubkey,
|
|
13943
14044
|
serverPubKey,
|
|
13944
14045
|
csvTimelock
|
|
@@ -13959,7 +14060,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13959
14060
|
});
|
|
13960
14061
|
}
|
|
13961
14062
|
if (delegatePubKey) {
|
|
13962
|
-
const delegateScript = new
|
|
14063
|
+
const delegateScript = new chunkYYWEBYFJ_cjs.DelegateVtxo.Script({
|
|
13963
14064
|
pubKey: baselinePubkey,
|
|
13964
14065
|
serverPubKey,
|
|
13965
14066
|
delegatePubKey,
|
|
@@ -13983,9 +14084,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13983
14084
|
}
|
|
13984
14085
|
}
|
|
13985
14086
|
}
|
|
13986
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
14087
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkYYWEBYFJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13987
14088
|
for (const serverPubKey of baselineSigners) {
|
|
13988
|
-
const baselineBoarding = new
|
|
14089
|
+
const baselineBoarding = new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
13989
14090
|
pubKey: baselinePubkey,
|
|
13990
14091
|
serverPubKey,
|
|
13991
14092
|
csvTimelock: boardingCsvTimelock
|
|
@@ -13998,7 +14099,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13998
14099
|
params: {
|
|
13999
14100
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14000
14101
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
14001
|
-
csvTimelock:
|
|
14102
|
+
csvTimelock: chunkJ5EX3OMM_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14002
14103
|
},
|
|
14003
14104
|
script: boardingScriptHex,
|
|
14004
14105
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -14198,7 +14299,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14198
14299
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
14199
14300
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
14200
14301
|
csvTimelocks: this.walletContractTimelocks,
|
|
14201
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
14302
|
+
delegatePubKey: this.offchainTapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
14202
14303
|
};
|
|
14203
14304
|
}
|
|
14204
14305
|
_signerRouter;
|
|
@@ -14443,7 +14544,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14443
14544
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14444
14545
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14445
14546
|
if (typeof persisted === "string") return persisted;
|
|
14446
|
-
return
|
|
14547
|
+
return chunkYYWEBYFJ_cjs.identityDescriptor(this.identity);
|
|
14447
14548
|
}
|
|
14448
14549
|
/**
|
|
14449
14550
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -14459,7 +14560,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14459
14560
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14460
14561
|
if (type === "boarding") {
|
|
14461
14562
|
const built2 = this.buildBoardingContract(
|
|
14462
|
-
|
|
14563
|
+
chunkYYWEBYFJ_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14463
14564
|
descriptor,
|
|
14464
14565
|
tagSource
|
|
14465
14566
|
);
|
|
@@ -14504,11 +14605,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14504
14605
|
* {@link buildReceiveContract}.
|
|
14505
14606
|
*/
|
|
14506
14607
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14507
|
-
const tapscript = new
|
|
14608
|
+
const tapscript = new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
14508
14609
|
...this._boardingTapscript.options,
|
|
14509
14610
|
pubKey
|
|
14510
14611
|
});
|
|
14511
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
14612
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkYYWEBYFJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14512
14613
|
return {
|
|
14513
14614
|
tapscript,
|
|
14514
14615
|
params: {
|
|
@@ -14516,13 +14617,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14516
14617
|
params: {
|
|
14517
14618
|
pubKey: base.hex.encode(pubKey),
|
|
14518
14619
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14519
|
-
csvTimelock:
|
|
14620
|
+
csvTimelock: chunkJ5EX3OMM_cjs.timelockToSequence(csvTimelock).toString()
|
|
14520
14621
|
},
|
|
14521
14622
|
script: base.hex.encode(tapscript.pkScript),
|
|
14522
14623
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14523
14624
|
state: "active",
|
|
14524
14625
|
metadata: {
|
|
14525
|
-
...tagSource && { source:
|
|
14626
|
+
...tagSource && { source: chunkYYWEBYFJ_cjs.WALLET_RECEIVE_SOURCE },
|
|
14526
14627
|
signingDescriptor: descriptor
|
|
14527
14628
|
}
|
|
14528
14629
|
}
|
|
@@ -14551,7 +14652,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14551
14652
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
14552
14653
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14553
14654
|
}
|
|
14554
|
-
return
|
|
14655
|
+
return chunkYYWEBYFJ_cjs.identityDescriptor(this.identity);
|
|
14555
14656
|
}
|
|
14556
14657
|
/**
|
|
14557
14658
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14647,7 +14748,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14647
14748
|
* the stable public API.
|
|
14648
14749
|
*/
|
|
14649
14750
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14650
|
-
const xonly =
|
|
14751
|
+
const xonly = chunkYYWEBYFJ_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14651
14752
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14652
14753
|
checkpointTapscript,
|
|
14653
14754
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14676,21 +14777,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14676
14777
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14677
14778
|
script: currentBoardingScript
|
|
14678
14779
|
});
|
|
14679
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14780
|
+
const newOffchain = this.offchainTapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? new chunkYYWEBYFJ_cjs.DelegateVtxo.Script({
|
|
14680
14781
|
...this.offchainTapscript.options,
|
|
14681
14782
|
serverPubKey: xonly
|
|
14682
|
-
}) : new
|
|
14783
|
+
}) : new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
14683
14784
|
...this.offchainTapscript.options,
|
|
14684
14785
|
serverPubKey: xonly
|
|
14685
14786
|
});
|
|
14686
|
-
const newBoarding = new
|
|
14787
|
+
const newBoarding = new chunkYYWEBYFJ_cjs.DefaultVtxo.Script({
|
|
14687
14788
|
...this._boardingTapscript.options,
|
|
14688
14789
|
serverPubKey: xonly
|
|
14689
14790
|
});
|
|
14690
|
-
const offchainCsv =
|
|
14791
|
+
const offchainCsv = chunkJ5EX3OMM_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14691
14792
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14692
14793
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14693
|
-
if (newOffchain instanceof
|
|
14794
|
+
if (newOffchain instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script) {
|
|
14694
14795
|
await manager.createContract({
|
|
14695
14796
|
type: "delegate",
|
|
14696
14797
|
params: {
|
|
@@ -14718,13 +14819,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14718
14819
|
metadata: currentOffchainRow?.metadata
|
|
14719
14820
|
});
|
|
14720
14821
|
}
|
|
14721
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14822
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkYYWEBYFJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14722
14823
|
await manager.createContract({
|
|
14723
14824
|
type: "boarding",
|
|
14724
14825
|
params: {
|
|
14725
14826
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14726
14827
|
serverPubKey: base.hex.encode(xonly),
|
|
14727
|
-
csvTimelock:
|
|
14828
|
+
csvTimelock: chunkJ5EX3OMM_cjs.timelockToSequence(boardingCsv).toString()
|
|
14728
14829
|
},
|
|
14729
14830
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14730
14831
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14757,14 +14858,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14757
14858
|
_restoreInFlight;
|
|
14758
14859
|
_addPendingSpends(inputs) {
|
|
14759
14860
|
for (const input of inputs) {
|
|
14760
|
-
if (
|
|
14861
|
+
if (chunkJ5EX3OMM_cjs.isVirtualCoin(input)) {
|
|
14761
14862
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14762
14863
|
}
|
|
14763
14864
|
}
|
|
14764
14865
|
}
|
|
14765
14866
|
_removePendingSpends(inputs) {
|
|
14766
14867
|
for (const input of inputs) {
|
|
14767
|
-
if (
|
|
14868
|
+
if (chunkJ5EX3OMM_cjs.isVirtualCoin(input)) {
|
|
14768
14869
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14769
14870
|
}
|
|
14770
14871
|
}
|
|
@@ -14825,13 +14926,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14825
14926
|
const manager = await this.getContractManager();
|
|
14826
14927
|
const provider = this._descriptorProvider;
|
|
14827
14928
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14828
|
-
const staticDescriptor = hd ? void 0 : await
|
|
14929
|
+
const staticDescriptor = hd ? void 0 : await chunkYYWEBYFJ_cjs.identityDescriptor(this.identity);
|
|
14829
14930
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14830
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14931
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkYYWEBYFJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14831
14932
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14832
|
-
const currentSignerPubKey =
|
|
14933
|
+
const currentSignerPubKey = chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14833
14934
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14834
|
-
(s) =>
|
|
14935
|
+
(s) => chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14835
14936
|
);
|
|
14836
14937
|
const deps = {
|
|
14837
14938
|
indexerProvider: this.indexerProvider,
|
|
@@ -14846,7 +14947,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14846
14947
|
csvTimelocks: this.walletContractTimelocks,
|
|
14847
14948
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14848
14949
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14849
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
14950
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkYYWEBYFJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14850
14951
|
delegatePubKey
|
|
14851
14952
|
};
|
|
14852
14953
|
const result = await manager.scanContracts({
|
|
@@ -14960,7 +15061,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14960
15061
|
throw new Error("Invalid configured public key");
|
|
14961
15062
|
}
|
|
14962
15063
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
14963
|
-
const forfeitPubkey =
|
|
15064
|
+
const forfeitPubkey = chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
14964
15065
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
14965
15066
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
14966
15067
|
const checkpointExitDelayOverrides = {
|
|
@@ -15109,7 +15210,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15109
15210
|
inputs: params.selectedVtxos,
|
|
15110
15211
|
changeAmount: BigInt(changeAmount)
|
|
15111
15212
|
};
|
|
15112
|
-
const outputAddress =
|
|
15213
|
+
const outputAddress = chunkJ5EX3OMM_cjs.ArkAddress.decode(params.address);
|
|
15113
15214
|
assertRecipientArkAddress(
|
|
15114
15215
|
params.address,
|
|
15115
15216
|
outputAddress,
|
|
@@ -15175,13 +15276,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15175
15276
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
15176
15277
|
}
|
|
15177
15278
|
const offchainAddress = await this.getAddress();
|
|
15178
|
-
const offchainPkScript =
|
|
15279
|
+
const offchainPkScript = chunkJ5EX3OMM_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
15179
15280
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
15180
15281
|
if (!params) {
|
|
15181
15282
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
15182
15283
|
const estimator = new Estimator(fees.intentFee);
|
|
15183
15284
|
let amount = 0;
|
|
15184
|
-
const exitScript =
|
|
15285
|
+
const exitScript = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.decode(
|
|
15185
15286
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
15186
15287
|
);
|
|
15187
15288
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -15210,7 +15311,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15210
15311
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
15211
15312
|
break;
|
|
15212
15313
|
}
|
|
15213
|
-
const inputFee = estimator.evalOffchainInput(
|
|
15314
|
+
const inputFee = estimator.evalOffchainInput(chunkJ5EX3OMM_cjs.toOffchainInputFeeParams(vtxo));
|
|
15214
15315
|
if (inputFee.satoshis >= vtxo.value) {
|
|
15215
15316
|
continue;
|
|
15216
15317
|
}
|
|
@@ -15257,7 +15358,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15257
15358
|
let script;
|
|
15258
15359
|
let arkAddress;
|
|
15259
15360
|
try {
|
|
15260
|
-
arkAddress =
|
|
15361
|
+
arkAddress = chunkJ5EX3OMM_cjs.ArkAddress.decode(output.address);
|
|
15261
15362
|
} catch {
|
|
15262
15363
|
arkAddress = void 0;
|
|
15263
15364
|
}
|
|
@@ -15347,7 +15448,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15347
15448
|
const abortController = new AbortController();
|
|
15348
15449
|
let stream;
|
|
15349
15450
|
let committedTxid;
|
|
15350
|
-
const settleInputVtxos = params.inputs.filter(
|
|
15451
|
+
const settleInputVtxos = params.inputs.filter(chunkJ5EX3OMM_cjs.isVirtualCoin);
|
|
15351
15452
|
const contractManager = await this.getContractManager();
|
|
15352
15453
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15353
15454
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15459,7 +15560,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15459
15560
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15460
15561
|
if (!this._descriptorProvider) return;
|
|
15461
15562
|
const consumedBoarding = inputs.some(
|
|
15462
|
-
(input) => typeof input !== "string" && !
|
|
15563
|
+
(input) => typeof input !== "string" && !chunkJ5EX3OMM_cjs.isVirtualCoin(input)
|
|
15463
15564
|
);
|
|
15464
15565
|
if (!consumedBoarding) return;
|
|
15465
15566
|
try {
|
|
@@ -15483,7 +15584,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15483
15584
|
let connectorIndex = 0;
|
|
15484
15585
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15485
15586
|
for (const input of inputs) {
|
|
15486
|
-
if (!
|
|
15587
|
+
if (!chunkJ5EX3OMM_cjs.isVirtualCoin(input)) {
|
|
15487
15588
|
let matched = false;
|
|
15488
15589
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15489
15590
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -15521,7 +15622,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15521
15622
|
}
|
|
15522
15623
|
continue;
|
|
15523
15624
|
}
|
|
15524
|
-
if (
|
|
15625
|
+
if (chunkJ5EX3OMM_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15525
15626
|
continue;
|
|
15526
15627
|
}
|
|
15527
15628
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15549,7 +15650,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15549
15650
|
index: input.vout,
|
|
15550
15651
|
witnessUtxo: {
|
|
15551
15652
|
amount: BigInt(input.value),
|
|
15552
|
-
script:
|
|
15653
|
+
script: chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15553
15654
|
},
|
|
15554
15655
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15555
15656
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15568,7 +15669,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15568
15669
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15569
15670
|
{
|
|
15570
15671
|
index: 0,
|
|
15571
|
-
lookupScript:
|
|
15672
|
+
lookupScript: chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15572
15673
|
}
|
|
15573
15674
|
]);
|
|
15574
15675
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15626,7 +15727,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15626
15727
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15627
15728
|
);
|
|
15628
15729
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15629
|
-
const sweepTapscript =
|
|
15730
|
+
const sweepTapscript = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.encode({
|
|
15630
15731
|
timelock,
|
|
15631
15732
|
pubkeys: [this.forfeitPubkey]
|
|
15632
15733
|
}).script;
|
|
@@ -15641,10 +15742,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15641
15742
|
throw new Error("Sweep tap tree root not set");
|
|
15642
15743
|
}
|
|
15643
15744
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15644
|
-
(k) => base.hex.encode(
|
|
15745
|
+
(k) => base.hex.encode(chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15645
15746
|
);
|
|
15646
15747
|
const signerPublicKey = await session.getPublicKey();
|
|
15647
|
-
const xonlySignerPublicKey =
|
|
15748
|
+
const xonlySignerPublicKey = chunkYYWEBYFJ_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15648
15749
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15649
15750
|
return { skip: true };
|
|
15650
15751
|
}
|
|
@@ -15734,9 +15835,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15734
15835
|
...existing ?? {},
|
|
15735
15836
|
intentTxId,
|
|
15736
15837
|
registerProof: intent.proof,
|
|
15737
|
-
registerProofMessage:
|
|
15838
|
+
registerProofMessage: chunkJ5EX3OMM_cjs.Intent.encodeMessage(intent.message),
|
|
15738
15839
|
deleteProof: deleteIntent.proof,
|
|
15739
|
-
deleteProofMessage:
|
|
15840
|
+
deleteProofMessage: chunkJ5EX3OMM_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15740
15841
|
intentVtxos: inputs.map((i) => ({
|
|
15741
15842
|
txid: i.txid,
|
|
15742
15843
|
vout: i.vout
|
|
@@ -15751,15 +15852,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15751
15852
|
console.error(`Failed to persist intent ${intentTxId} (state=${state})`, e);
|
|
15752
15853
|
}
|
|
15753
15854
|
}
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
|
|
15759
|
-
|
|
15760
|
-
|
|
15761
|
-
|
|
15762
|
-
|
|
15855
|
+
async signInputsByWitnessScript(tx) {
|
|
15856
|
+
const signed = await this._signerRouter.sign(
|
|
15857
|
+
tx,
|
|
15858
|
+
this.inputSigningJobsFromWitnessUtxos(tx),
|
|
15859
|
+
{
|
|
15860
|
+
onUnknownScript: "sign"
|
|
15861
|
+
}
|
|
15862
|
+
);
|
|
15863
|
+
return signed;
|
|
15864
|
+
}
|
|
15763
15865
|
async signOnchainBoardingTx(tx) {
|
|
15764
15866
|
const signed = await this._signerRouter.sign(tx, this.inputSigningJobsFromWitnessUtxos(tx));
|
|
15765
15867
|
return signed;
|
|
@@ -15768,7 +15870,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15768
15870
|
try {
|
|
15769
15871
|
return await this.arkProvider.registerIntent(intent);
|
|
15770
15872
|
} catch (error) {
|
|
15771
|
-
if (error instanceof
|
|
15873
|
+
if (error instanceof chunkJ5EX3OMM_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15772
15874
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15773
15875
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15774
15876
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15784,7 +15886,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15784
15886
|
expire_at: 0,
|
|
15785
15887
|
cosigners_public_keys: cosignerPubKeys
|
|
15786
15888
|
};
|
|
15787
|
-
const proof =
|
|
15889
|
+
const proof = chunkJ5EX3OMM_cjs.Intent.create(message, coins, outputs);
|
|
15788
15890
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15789
15891
|
return {
|
|
15790
15892
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15796,7 +15898,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15796
15898
|
type: "delete",
|
|
15797
15899
|
expire_at: 0
|
|
15798
15900
|
};
|
|
15799
|
-
const proof =
|
|
15901
|
+
const proof = chunkJ5EX3OMM_cjs.Intent.create(message, coins, []);
|
|
15800
15902
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15801
15903
|
return {
|
|
15802
15904
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15808,7 +15910,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15808
15910
|
type: "get-pending-tx",
|
|
15809
15911
|
expire_at: 0
|
|
15810
15912
|
};
|
|
15811
|
-
const proof =
|
|
15913
|
+
const proof = chunkJ5EX3OMM_cjs.Intent.create(message, coins, []);
|
|
15812
15914
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15813
15915
|
return {
|
|
15814
15916
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15829,7 +15931,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15829
15931
|
if (!vtxos || vtxos.length === 0) {
|
|
15830
15932
|
const scriptMap = await this.getScriptMap();
|
|
15831
15933
|
const allExtended = [];
|
|
15832
|
-
const fetchedVtxos = await
|
|
15934
|
+
const fetchedVtxos = await chunkJ5EX3OMM_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15833
15935
|
...scriptMap.keys()
|
|
15834
15936
|
]);
|
|
15835
15937
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -15873,7 +15975,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15873
15975
|
try {
|
|
15874
15976
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
15875
15977
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
15876
|
-
|
|
15978
|
+
chunkJ5EX3OMM_cjs.assertAllowedSighashTypes(tx);
|
|
15877
15979
|
return tx;
|
|
15878
15980
|
});
|
|
15879
15981
|
assertCheckpointsMatchInputs(
|
|
@@ -15945,11 +16047,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15945
16047
|
* against the current key alone would leave it pending forever.
|
|
15946
16048
|
*/
|
|
15947
16049
|
checkpointUnrollCandidates(info) {
|
|
15948
|
-
const current =
|
|
16050
|
+
const current = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
15949
16051
|
const candidates = [this._serverUnrollScript, current];
|
|
15950
16052
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
15951
16053
|
candidates.push(
|
|
15952
|
-
|
|
16054
|
+
chunkJ5EX3OMM_cjs.CSVMultisigTapscript.encode({
|
|
15953
16055
|
...current.params,
|
|
15954
16056
|
pubkeys: [base.hex.decode(deprecated)]
|
|
15955
16057
|
})
|
|
@@ -16040,7 +16142,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16040
16142
|
if (vtxos.length === 0) {
|
|
16041
16143
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
16042
16144
|
}
|
|
16043
|
-
const myPkScript =
|
|
16145
|
+
const myPkScript = chunkJ5EX3OMM_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
16044
16146
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
16045
16147
|
let swept = 0;
|
|
16046
16148
|
const drainable = vtxos.filter(
|
|
@@ -16116,7 +16218,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16116
16218
|
const spendable = [];
|
|
16117
16219
|
const unclaimed = [];
|
|
16118
16220
|
for (const vtxo of vtxos) {
|
|
16119
|
-
if (
|
|
16221
|
+
if (chunkJ5EX3OMM_cjs.hasTerminalSpend(vtxo)) {
|
|
16120
16222
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
16121
16223
|
} else if (vtxo.isUnrolled) {
|
|
16122
16224
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -16138,7 +16240,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16138
16240
|
const all = [];
|
|
16139
16241
|
const seen = /* @__PURE__ */ new Set();
|
|
16140
16242
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
16141
|
-
const { vtxos, page } = await
|
|
16243
|
+
const { vtxos, page } = await chunkJ5EX3OMM_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
16142
16244
|
scripts,
|
|
16143
16245
|
pageIndex,
|
|
16144
16246
|
pageSize
|
|
@@ -16185,7 +16287,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16185
16287
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
16186
16288
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
16187
16289
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
16188
|
-
const proof =
|
|
16290
|
+
const proof = chunkJ5EX3OMM_cjs.Intent.create(message, batch, []);
|
|
16189
16291
|
const signedProof = await identity.sign(
|
|
16190
16292
|
proof,
|
|
16191
16293
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -16207,7 +16309,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16207
16309
|
try {
|
|
16208
16310
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
16209
16311
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
16210
|
-
|
|
16312
|
+
chunkJ5EX3OMM_cjs.assertAllowedSighashTypes(tx);
|
|
16211
16313
|
return tx;
|
|
16212
16314
|
});
|
|
16213
16315
|
assertCheckpointsMatchInputs(
|
|
@@ -16406,7 +16508,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16406
16508
|
script: recipient.script,
|
|
16407
16509
|
amount: BigInt(recipient.amount),
|
|
16408
16510
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16409
|
-
...recipient.tapTree ? { tapTree:
|
|
16511
|
+
...recipient.tapTree ? { tapTree: chunkJ5EX3OMM_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
16410
16512
|
}));
|
|
16411
16513
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16412
16514
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -16550,10 +16652,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16550
16652
|
const serverPubKey = this.arkServerPublicKey;
|
|
16551
16653
|
const serverUnrollScript = this.serverUnrollScript;
|
|
16552
16654
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
16553
|
-
const normalizedInputs = inputs.map(
|
|
16554
|
-
const at = now ?? await
|
|
16655
|
+
const normalizedInputs = inputs.map(chunkJ5EX3OMM_cjs.normalizeVtxo);
|
|
16656
|
+
const at = now ?? await chunkJ5EX3OMM_cjs.resolveTimeHeight(this.onchainProvider);
|
|
16555
16657
|
for (const input of normalizedInputs) {
|
|
16556
|
-
if (!
|
|
16658
|
+
if (!chunkJ5EX3OMM_cjs.canSpendOffchain(input, at)) {
|
|
16557
16659
|
throw new Error(
|
|
16558
16660
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
16559
16661
|
);
|
|
@@ -16623,7 +16725,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16623
16725
|
);
|
|
16624
16726
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
16625
16727
|
index,
|
|
16626
|
-
lookupScript:
|
|
16728
|
+
lookupScript: chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
16627
16729
|
}));
|
|
16628
16730
|
const identity = this.identity;
|
|
16629
16731
|
const signer = {
|
|
@@ -16724,14 +16826,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16724
16826
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16725
16827
|
spentVtxos.push({
|
|
16726
16828
|
...spentFacts,
|
|
16727
|
-
virtualStatus:
|
|
16829
|
+
virtualStatus: chunkJ5EX3OMM_cjs.toVirtualStatus(spentFacts),
|
|
16728
16830
|
...spentBy ? { spentBy } : {},
|
|
16729
16831
|
arkTxId: arkTxid
|
|
16730
16832
|
});
|
|
16731
16833
|
for (const id of vtxo.commitmentTxIds) {
|
|
16732
16834
|
commitmentTxIds.add(id);
|
|
16733
16835
|
}
|
|
16734
|
-
const vtxoExpiry =
|
|
16836
|
+
const vtxoExpiry = chunkJ5EX3OMM_cjs.toBatchExpiry(vtxo);
|
|
16735
16837
|
if (vtxoExpiry) {
|
|
16736
16838
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16737
16839
|
}
|
|
@@ -16744,7 +16846,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16744
16846
|
isSwept: false,
|
|
16745
16847
|
isPreconfirmed: true,
|
|
16746
16848
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16747
|
-
...
|
|
16849
|
+
...chunkJ5EX3OMM_cjs.parseLegacyExpiry(batchExpiry)
|
|
16748
16850
|
};
|
|
16749
16851
|
changeVtxo = {
|
|
16750
16852
|
txid: arkTxid,
|
|
@@ -16756,7 +16858,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16756
16858
|
tapTree: offchainTapscript.encode(),
|
|
16757
16859
|
value: Number(changeAmount),
|
|
16758
16860
|
...changeFacts,
|
|
16759
|
-
virtualStatus:
|
|
16861
|
+
virtualStatus: chunkJ5EX3OMM_cjs.toVirtualStatus(changeFacts),
|
|
16760
16862
|
spentBy: "",
|
|
16761
16863
|
status: {
|
|
16762
16864
|
confirmed: false
|
|
@@ -16825,12 +16927,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16825
16927
|
const spentVtxos = [];
|
|
16826
16928
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16827
16929
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16828
|
-
const vtxoInputs = inputs.filter(
|
|
16930
|
+
const vtxoInputs = inputs.filter(chunkJ5EX3OMM_cjs.isVirtualCoin);
|
|
16829
16931
|
const cm = await this.getContractManager();
|
|
16830
16932
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16831
16933
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16832
16934
|
for (const input of inputs) {
|
|
16833
|
-
if (
|
|
16935
|
+
if (chunkJ5EX3OMM_cjs.isVirtualCoin(input)) {
|
|
16834
16936
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16835
16937
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16836
16938
|
if (!vtxo) {
|
|
@@ -16842,13 +16944,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16842
16944
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16843
16945
|
spentVtxos.push({
|
|
16844
16946
|
...settledFacts,
|
|
16845
|
-
virtualStatus:
|
|
16947
|
+
virtualStatus: chunkJ5EX3OMM_cjs.toVirtualStatus(settledFacts),
|
|
16846
16948
|
settledBy: commitmentTxid
|
|
16847
16949
|
});
|
|
16848
16950
|
} else {
|
|
16849
16951
|
let sourceAddress;
|
|
16850
16952
|
try {
|
|
16851
|
-
sourceAddress =
|
|
16953
|
+
sourceAddress = chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16852
16954
|
this.network
|
|
16853
16955
|
);
|
|
16854
16956
|
} catch {
|
|
@@ -16906,9 +17008,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16906
17008
|
}
|
|
16907
17009
|
};
|
|
16908
17010
|
function selectVirtualCoins(coins, targetAmount) {
|
|
16909
|
-
const sortedCoins = coins.map(
|
|
16910
|
-
const expiryA =
|
|
16911
|
-
const expiryB =
|
|
17011
|
+
const sortedCoins = coins.map(chunkJ5EX3OMM_cjs.normalizeVtxo).sort((a, b) => {
|
|
17012
|
+
const expiryA = chunkJ5EX3OMM_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
17013
|
+
const expiryB = chunkJ5EX3OMM_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
16912
17014
|
if (expiryA !== expiryB) {
|
|
16913
17015
|
return expiryA - expiryB;
|
|
16914
17016
|
}
|
|
@@ -17277,7 +17379,7 @@ var MessageBus = class {
|
|
|
17277
17379
|
this.initialized = true;
|
|
17278
17380
|
}
|
|
17279
17381
|
async buildServices(config) {
|
|
17280
|
-
const arkProvider = new
|
|
17382
|
+
const arkProvider = new chunkJ5EX3OMM_cjs.RestArkProvider(config.arkServer.url);
|
|
17281
17383
|
const storage = {
|
|
17282
17384
|
walletRepository: this.walletRepository,
|
|
17283
17385
|
contractRepository: this.contractRepository,
|
|
@@ -17609,6 +17711,18 @@ var DustChangeError = class extends Error {
|
|
|
17609
17711
|
this.dustAmount = dustAmount;
|
|
17610
17712
|
}
|
|
17611
17713
|
};
|
|
17714
|
+
var OversizedChangeError = class extends Error {
|
|
17715
|
+
change;
|
|
17716
|
+
maxAmount;
|
|
17717
|
+
constructor(change, maxAmount) {
|
|
17718
|
+
super(
|
|
17719
|
+
`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`
|
|
17720
|
+
);
|
|
17721
|
+
this.name = "OversizedChangeError";
|
|
17722
|
+
this.change = change;
|
|
17723
|
+
this.maxAmount = maxAmount;
|
|
17724
|
+
}
|
|
17725
|
+
};
|
|
17612
17726
|
var offboardNetworkNames = [
|
|
17613
17727
|
"bitcoin",
|
|
17614
17728
|
"regtest",
|
|
@@ -17619,7 +17733,7 @@ var offboardNetworkNames = [
|
|
|
17619
17733
|
function offboardDestinationScript(destinationAddress) {
|
|
17620
17734
|
for (const networkName of offboardNetworkNames) {
|
|
17621
17735
|
try {
|
|
17622
|
-
const network =
|
|
17736
|
+
const network = chunkJ5EX3OMM_cjs.networks[networkName];
|
|
17623
17737
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
17624
17738
|
return btcSigner.OutScript.encode(addr);
|
|
17625
17739
|
} catch {
|
|
@@ -17628,6 +17742,62 @@ function offboardDestinationScript(destinationAddress) {
|
|
|
17628
17742
|
}
|
|
17629
17743
|
throw new Error(`Failed to decode destination address: ${destinationAddress}`);
|
|
17630
17744
|
}
|
|
17745
|
+
var CHANGE_FEE_MAX_ROUNDS = 8;
|
|
17746
|
+
function settleChangeAgainstFee(change, feeOn) {
|
|
17747
|
+
let net = change;
|
|
17748
|
+
for (let i = 0; i < CHANGE_FEE_MAX_ROUNDS; i++) {
|
|
17749
|
+
const next = change - feeOn(net > 0n ? net : 0n);
|
|
17750
|
+
if (next === net) return net > 0n ? net : 0n;
|
|
17751
|
+
net = next;
|
|
17752
|
+
}
|
|
17753
|
+
throw new Error(
|
|
17754
|
+
`change fee does not settle after ${CHANGE_FEE_MAX_ROUNDS} rounds (${change} sats of change); settle the full balance instead`
|
|
17755
|
+
);
|
|
17756
|
+
}
|
|
17757
|
+
function changeAfterOutputFee(left, feeOn) {
|
|
17758
|
+
if (left <= 0n) return { change: 0n, fee: 0n };
|
|
17759
|
+
const change = settleChangeAgainstFee(left, feeOn);
|
|
17760
|
+
return { change, fee: left - change };
|
|
17761
|
+
}
|
|
17762
|
+
function reportUngatedInputs(wallet, inputs) {
|
|
17763
|
+
if (!("logUngatedInputs" in wallet)) return;
|
|
17764
|
+
const logger = wallet;
|
|
17765
|
+
void logger.logUngatedInputs("Ramps.offboard({ vtxos })", inputs);
|
|
17766
|
+
}
|
|
17767
|
+
function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
17768
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17769
|
+
const inputs = [];
|
|
17770
|
+
let subtotal = 0n;
|
|
17771
|
+
for (const vtxo of vtxos) {
|
|
17772
|
+
const inputFee = estimator.evalOffchainInput(chunkJ5EX3OMM_cjs.toOffchainInputFeeParams(vtxo));
|
|
17773
|
+
if (inputFee.satoshis >= vtxo.value) {
|
|
17774
|
+
if (named) {
|
|
17775
|
+
throw new Error(
|
|
17776
|
+
`selected vtxo ${vtxo.txid}:${vtxo.vout} costs ${inputFee.satoshis} sats to spend and is worth ${vtxo.value} \u2014 drop it from the selection`
|
|
17777
|
+
);
|
|
17778
|
+
}
|
|
17779
|
+
continue;
|
|
17780
|
+
}
|
|
17781
|
+
inputs.push(vtxo);
|
|
17782
|
+
subtotal += BigInt(vtxo.value) - BigInt(inputFee.satoshis);
|
|
17783
|
+
}
|
|
17784
|
+
if (inputs.length === 0) {
|
|
17785
|
+
throw new Error("No vtxos available after deducting fees");
|
|
17786
|
+
}
|
|
17787
|
+
return { inputs, subtotal };
|
|
17788
|
+
}
|
|
17789
|
+
async function serverVtxoMaxAmount(wallet) {
|
|
17790
|
+
const provider = wallet.arkProvider;
|
|
17791
|
+
if (!provider) return void 0;
|
|
17792
|
+
return (await provider.getInfo()).vtxoMaxAmount;
|
|
17793
|
+
}
|
|
17794
|
+
function assertChangeSettleable(change, dustAmount, maxAmount) {
|
|
17795
|
+
if (change === 0n) return;
|
|
17796
|
+
if (change < dustAmount) throw new DustChangeError(change, dustAmount);
|
|
17797
|
+
if (maxAmount !== void 0 && maxAmount >= 0n && change > maxAmount) {
|
|
17798
|
+
throw new OversizedChangeError(change, maxAmount);
|
|
17799
|
+
}
|
|
17800
|
+
}
|
|
17631
17801
|
var Ramps = class {
|
|
17632
17802
|
/**
|
|
17633
17803
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -17681,9 +17851,22 @@ var Ramps = class {
|
|
|
17681
17851
|
}
|
|
17682
17852
|
change = totalAmount - amount;
|
|
17683
17853
|
}
|
|
17854
|
+
let boardingAddress;
|
|
17855
|
+
if (change > 0n) {
|
|
17856
|
+
boardingAddress = await this.wallet.getBoardingAddress();
|
|
17857
|
+
const changeScript = base.hex.encode(offboardDestinationScript(boardingAddress));
|
|
17858
|
+
change = settleChangeAgainstFee(
|
|
17859
|
+
change,
|
|
17860
|
+
(amt) => BigInt(estimator.evalOnchainOutput({ amount: amt, script: changeScript }).satoshis)
|
|
17861
|
+
);
|
|
17862
|
+
const dustAmount = getDustAmount(this.wallet);
|
|
17863
|
+
if (change > 0n && change < dustAmount) {
|
|
17864
|
+
throw new DustChangeError(change, dustAmount);
|
|
17865
|
+
}
|
|
17866
|
+
}
|
|
17684
17867
|
amount = amount ?? totalAmount;
|
|
17685
17868
|
const offchainAddress = await this.wallet.getAddress();
|
|
17686
|
-
const offchainAddr =
|
|
17869
|
+
const offchainAddr = chunkJ5EX3OMM_cjs.ArkAddress.decode(offchainAddress);
|
|
17687
17870
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
17688
17871
|
const outputFee = estimator.evalOffchainOutput({
|
|
17689
17872
|
amount,
|
|
@@ -17702,7 +17885,6 @@ var Ramps = class {
|
|
|
17702
17885
|
}
|
|
17703
17886
|
];
|
|
17704
17887
|
if (change > 0n) {
|
|
17705
|
-
const boardingAddress = await this.wallet.getBoardingAddress();
|
|
17706
17888
|
outputs.push({
|
|
17707
17889
|
address: boardingAddress,
|
|
17708
17890
|
amount: change
|
|
@@ -17723,6 +17905,10 @@ var Ramps = class {
|
|
|
17723
17905
|
* @param feeInfo - The fee info to deduct from the offboard amount.
|
|
17724
17906
|
* @param amount - The amount to offboard. If not provided, the total amount of virtual outputs will be offboarded.
|
|
17725
17907
|
* @param eventCallback - Optional callback that receives settlement events
|
|
17908
|
+
* @param vtxos - Specific virtual outputs to spend, mirroring {@link onboard}'s
|
|
17909
|
+
* `boardingUtxos`. Omitted, every spendable one is spent — merging the whole
|
|
17910
|
+
* off-chain balance into a single change output. Taken as given like
|
|
17911
|
+
* `settle({ inputs })`: an `amount` these cannot cover is an error, not a top-up.
|
|
17726
17912
|
* @returns The Arkade transaction id created by settlement
|
|
17727
17913
|
* @throws Error if no virtual outputs remain after fee deduction or the destination address cannot be decoded
|
|
17728
17914
|
* @see IWallet.getSpendableVtxos
|
|
@@ -17734,68 +17920,90 @@ var Ramps = class {
|
|
|
17734
17920
|
* await ramps.offboard('bc1q...', feeInfo);
|
|
17735
17921
|
* ```
|
|
17736
17922
|
*/
|
|
17737
|
-
async offboard(destinationAddress, feeInfo, amount, eventCallback) {
|
|
17738
|
-
const
|
|
17923
|
+
async offboard(destinationAddress, feeInfo, amount, eventCallback, vtxos) {
|
|
17924
|
+
const named = vtxos !== void 0;
|
|
17925
|
+
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17926
|
+
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17739
17927
|
withRecoverable: true,
|
|
17740
17928
|
withUnrolled: false
|
|
17741
17929
|
});
|
|
17742
17930
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17743
|
-
const
|
|
17744
|
-
|
|
17745
|
-
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
|
|
17749
|
-
|
|
17750
|
-
|
|
17751
|
-
|
|
17752
|
-
}
|
|
17753
|
-
if (filteredVtxos.length === 0) {
|
|
17754
|
-
throw new Error("No vtxos available after deducting fees");
|
|
17755
|
-
}
|
|
17756
|
-
let change = 0n;
|
|
17757
|
-
if (amount) {
|
|
17758
|
-
if (amount > totalAmount) {
|
|
17759
|
-
throw new Error("Amount is greater than total amount of vtxos after fees");
|
|
17760
|
-
}
|
|
17761
|
-
change = totalAmount - amount;
|
|
17762
|
-
}
|
|
17763
|
-
const dustAmount = getDustAmount(this.wallet);
|
|
17764
|
-
if (change > 0n && change < dustAmount) {
|
|
17765
|
-
throw new DustChangeError(change, dustAmount);
|
|
17766
|
-
}
|
|
17767
|
-
amount = amount ?? totalAmount;
|
|
17768
|
-
const destinationScript = offboardDestinationScript(destinationAddress);
|
|
17931
|
+
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
17932
|
+
if (amount && amount > subtotal) {
|
|
17933
|
+
throw new Error("Amount is greater than total amount of vtxos after fees");
|
|
17934
|
+
}
|
|
17935
|
+
const handed = amount || subtotal;
|
|
17936
|
+
const { change, changeAddress } = await this.fundChange(
|
|
17937
|
+
amount ? subtotal - handed : 0n,
|
|
17938
|
+
estimator
|
|
17939
|
+
);
|
|
17769
17940
|
const outputFee = estimator.evalOnchainOutput({
|
|
17770
|
-
amount,
|
|
17771
|
-
script: base.hex.encode(
|
|
17941
|
+
amount: handed,
|
|
17942
|
+
script: base.hex.encode(offboardDestinationScript(destinationAddress))
|
|
17772
17943
|
});
|
|
17773
|
-
if (BigInt(outputFee.satoshis) >
|
|
17944
|
+
if (BigInt(outputFee.satoshis) > handed) {
|
|
17774
17945
|
throw new Error(
|
|
17775
|
-
`can't deduct fees from offboard amount (${outputFee.satoshis} > ${
|
|
17946
|
+
`can't deduct fees from offboard amount (${outputFee.satoshis} > ${handed})`
|
|
17776
17947
|
);
|
|
17777
17948
|
}
|
|
17778
|
-
amount -= BigInt(outputFee.satoshis);
|
|
17779
17949
|
const outputs = [
|
|
17780
|
-
{
|
|
17781
|
-
address: destinationAddress,
|
|
17782
|
-
amount
|
|
17783
|
-
}
|
|
17950
|
+
{ address: destinationAddress, amount: handed - BigInt(outputFee.satoshis) }
|
|
17784
17951
|
];
|
|
17785
|
-
if (change > 0n) {
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17952
|
+
if (change > 0n) outputs.push({ address: changeAddress, amount: change });
|
|
17953
|
+
return this.wallet.settle({ inputs, outputs }, eventCallback);
|
|
17954
|
+
}
|
|
17955
|
+
/**
|
|
17956
|
+
* Collaboratively exit with the DESTINATION paid exactly `amount`, pricing the
|
|
17957
|
+
* fee on that output rather than on a grossed-up figure. {@link offboard} keeps
|
|
17958
|
+
* the other anchor, which needs `g - fee(g) = amount` solved — impossible for
|
|
17959
|
+
* a program charging the whole output.
|
|
17960
|
+
*/
|
|
17961
|
+
async offboardExact(params) {
|
|
17962
|
+
const { destinationAddress, feeInfo, amount, eventCallback, vtxos } = params;
|
|
17963
|
+
if (amount <= 0n) {
|
|
17964
|
+
throw new Error(`offboard amount must be positive, got ${amount}`);
|
|
17791
17965
|
}
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17966
|
+
const named = vtxos !== void 0;
|
|
17967
|
+
if (vtxos) reportUngatedInputs(this.wallet, vtxos);
|
|
17968
|
+
const spendable = vtxos ?? await this.wallet.getSpendableVtxos({
|
|
17969
|
+
withRecoverable: true,
|
|
17970
|
+
withUnrolled: false
|
|
17971
|
+
});
|
|
17972
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
17973
|
+
const { inputs, subtotal } = filterOffboardInputs(spendable, feeInfo, named);
|
|
17974
|
+
const outputFee = BigInt(
|
|
17975
|
+
estimator.evalOnchainOutput({
|
|
17976
|
+
amount,
|
|
17977
|
+
script: base.hex.encode(offboardDestinationScript(destinationAddress))
|
|
17978
|
+
}).satoshis
|
|
17979
|
+
);
|
|
17980
|
+
const needed = amount + outputFee;
|
|
17981
|
+
if (needed > subtotal) {
|
|
17982
|
+
throw new Error(
|
|
17983
|
+
`selected vtxos net ${subtotal} sats, ${needed} needed to deliver ${amount} exactly (${amount} + a ${outputFee} sat exit fee)`
|
|
17984
|
+
);
|
|
17985
|
+
}
|
|
17986
|
+
const { change, changeAddress } = await this.fundChange(subtotal - needed, estimator);
|
|
17987
|
+
const outputs = [{ address: destinationAddress, amount }];
|
|
17988
|
+
if (change > 0n) outputs.push({ address: changeAddress, amount: change });
|
|
17989
|
+
return this.wallet.settle({ inputs, outputs }, eventCallback);
|
|
17990
|
+
}
|
|
17991
|
+
/** Fund the change output: pay its own fee, then judge it against both
|
|
17992
|
+
* server-side bounds. `0n` in is `0n` out — no change output at all. */
|
|
17993
|
+
async fundChange(left, estimator) {
|
|
17994
|
+
if (left <= 0n) return { change: 0n };
|
|
17995
|
+
const changeAddress = await this.wallet.getAddress();
|
|
17996
|
+
const changeScript = base.hex.encode(chunkJ5EX3OMM_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
17997
|
+
const { change } = changeAfterOutputFee(
|
|
17998
|
+
left,
|
|
17999
|
+
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script: changeScript }).satoshis)
|
|
17798
18000
|
);
|
|
18001
|
+
assertChangeSettleable(
|
|
18002
|
+
change,
|
|
18003
|
+
getDustAmount(this.wallet),
|
|
18004
|
+
await serverVtxoMaxAmount(this.wallet)
|
|
18005
|
+
);
|
|
18006
|
+
return { change, changeAddress };
|
|
17799
18007
|
}
|
|
17800
18008
|
};
|
|
17801
18009
|
|
|
@@ -18614,7 +18822,7 @@ var WalletMessageHandler = class {
|
|
|
18614
18822
|
// Wallet methods
|
|
18615
18823
|
async handleInitWallet({ payload }) {
|
|
18616
18824
|
const { arkServerUrl } = payload;
|
|
18617
|
-
this.indexerProvider = new
|
|
18825
|
+
this.indexerProvider = new chunkSH23SRZE_cjs.RestIndexerProvider(arkServerUrl);
|
|
18618
18826
|
await this.onWalletInitialized();
|
|
18619
18827
|
}
|
|
18620
18828
|
/**
|
|
@@ -18902,7 +19110,7 @@ var WalletMessageHandler = class {
|
|
|
18902
19110
|
if (v.isUnrolled) {
|
|
18903
19111
|
return withUnrolled;
|
|
18904
19112
|
}
|
|
18905
|
-
if (
|
|
19113
|
+
if (chunkJ5EX3OMM_cjs.hasTerminalSpend(v)) {
|
|
18906
19114
|
return false;
|
|
18907
19115
|
}
|
|
18908
19116
|
if (includeRecoverable) {
|
|
@@ -18911,10 +19119,10 @@ var WalletMessageHandler = class {
|
|
|
18911
19119
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
18912
19120
|
return false;
|
|
18913
19121
|
}
|
|
18914
|
-
if (
|
|
19122
|
+
if (chunkJ5EX3OMM_cjs.isRecoverable(v)) {
|
|
18915
19123
|
return false;
|
|
18916
19124
|
}
|
|
18917
|
-
if (
|
|
19125
|
+
if (chunkJ5EX3OMM_cjs.isExpired(v)) {
|
|
18918
19126
|
return false;
|
|
18919
19127
|
}
|
|
18920
19128
|
return true;
|
|
@@ -19022,7 +19230,7 @@ var WalletMessageHandler = class {
|
|
|
19022
19230
|
this.readonlyWallet.getBoardingTxs()
|
|
19023
19231
|
]);
|
|
19024
19232
|
const indexerProvider = this.indexerProvider;
|
|
19025
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
19233
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkJ5EX3OMM_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
19026
19234
|
return buildTransactionHistory(
|
|
19027
19235
|
vtxos,
|
|
19028
19236
|
boardingTxs,
|
|
@@ -19730,7 +19938,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19730
19938
|
};
|
|
19731
19939
|
try {
|
|
19732
19940
|
const response = await this.sendMessage(message);
|
|
19733
|
-
return response.payload.vtxos.map(
|
|
19941
|
+
return response.payload.vtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo);
|
|
19734
19942
|
} catch (error) {
|
|
19735
19943
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
19736
19944
|
}
|
|
@@ -19755,7 +19963,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19755
19963
|
};
|
|
19756
19964
|
try {
|
|
19757
19965
|
const response = await this.sendMessage(message);
|
|
19758
|
-
return response.payload.vtxos.map(
|
|
19966
|
+
return response.payload.vtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo);
|
|
19759
19967
|
} catch (error) {
|
|
19760
19968
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
19761
19969
|
}
|
|
@@ -19926,7 +20134,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19926
20134
|
};
|
|
19927
20135
|
try {
|
|
19928
20136
|
const response = await sendContractMessage(message);
|
|
19929
|
-
return response.payload.vtxos.map(
|
|
20137
|
+
return response.payload.vtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo);
|
|
19930
20138
|
} catch (e) {
|
|
19931
20139
|
throw new Error("Failed to annotate vtxos");
|
|
19932
20140
|
}
|
|
@@ -20538,7 +20746,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20538
20746
|
};
|
|
20539
20747
|
try {
|
|
20540
20748
|
const response = await wallet.sendMessage(message);
|
|
20541
|
-
return response.payload.vtxos.map(
|
|
20749
|
+
return response.payload.vtxos.map(chunkJ5EX3OMM_cjs.normalizeVtxo);
|
|
20542
20750
|
} catch (e) {
|
|
20543
20751
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
20544
20752
|
}
|
|
@@ -20650,12 +20858,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20650
20858
|
* @returns Configured onchain wallet
|
|
20651
20859
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
20652
20860
|
*/
|
|
20653
|
-
static async create(identity, networkName =
|
|
20861
|
+
static async create(identity, networkName = chunkJ5EX3OMM_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
20654
20862
|
const pubkey = await identity.xOnlyPublicKey();
|
|
20655
20863
|
if (!pubkey) {
|
|
20656
20864
|
throw new Error("Invalid configured public key");
|
|
20657
20865
|
}
|
|
20658
|
-
const network =
|
|
20866
|
+
const network = chunkJ5EX3OMM_cjs.getNetwork(networkName);
|
|
20659
20867
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
20660
20868
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
20661
20869
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -20761,7 +20969,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20761
20969
|
if (!inputs) {
|
|
20762
20970
|
throw new Error("Fee estimation failed");
|
|
20763
20971
|
}
|
|
20764
|
-
let tx = new
|
|
20972
|
+
let tx = new chunkJ5EX3OMM_cjs.Transaction();
|
|
20765
20973
|
for (const input of inputs) {
|
|
20766
20974
|
tx.addInput({
|
|
20767
20975
|
txid: input.txid,
|
|
@@ -20819,7 +21027,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20819
21027
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
20820
21028
|
*/
|
|
20821
21029
|
async bumpAnchor(parentHex, feeRate) {
|
|
20822
|
-
const parent =
|
|
21030
|
+
const parent = chunkJ5EX3OMM_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
20823
21031
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
20824
21032
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
20825
21033
|
return [parent.hex, child.hex];
|
|
@@ -21726,7 +21934,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21726
21934
|
try {
|
|
21727
21935
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
21728
21936
|
for (const psbt of txs) {
|
|
21729
|
-
const tx =
|
|
21937
|
+
const tx = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
21730
21938
|
resolved.set(tx.id, tx.toBytes());
|
|
21731
21939
|
}
|
|
21732
21940
|
} catch (err) {
|
|
@@ -21759,7 +21967,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21759
21967
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
21760
21968
|
const pending = [];
|
|
21761
21969
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21762
|
-
if (
|
|
21970
|
+
if (chunkJ5EX3OMM_cjs.getArkPsbtFields(tx, i, chunkJ5EX3OMM_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
21763
21971
|
}
|
|
21764
21972
|
if (pending.length === 0) return;
|
|
21765
21973
|
const resolved = await resolvePrevTxs(
|
|
@@ -21768,13 +21976,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
21768
21976
|
onchain
|
|
21769
21977
|
);
|
|
21770
21978
|
for (const i of pending) {
|
|
21771
|
-
|
|
21979
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(tx, i, chunkJ5EX3OMM_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
21772
21980
|
}
|
|
21773
21981
|
}
|
|
21774
21982
|
async function attachPrevoutTxs(tx, source) {
|
|
21775
21983
|
const pending = [];
|
|
21776
21984
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21777
|
-
if (
|
|
21985
|
+
if (chunkJ5EX3OMM_cjs.getArkPsbtFields(tx, i, chunkJ5EX3OMM_cjs.PrevoutTxField).length > 0) continue;
|
|
21778
21986
|
const input = tx.getInput(i);
|
|
21779
21987
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
21780
21988
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -21785,7 +21993,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
21785
21993
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
21786
21994
|
}
|
|
21787
21995
|
for (const { index, txid } of pending) {
|
|
21788
|
-
|
|
21996
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(tx, index, chunkJ5EX3OMM_cjs.PrevoutTxField, resolved.get(txid));
|
|
21789
21997
|
}
|
|
21790
21998
|
}
|
|
21791
21999
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -21811,7 +22019,7 @@ exports.BIP322 = void 0;
|
|
|
21811
22019
|
async function sign2(message, identity, network) {
|
|
21812
22020
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
21813
22021
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
21814
|
-
const toSpend =
|
|
22022
|
+
const toSpend = chunkJ5EX3OMM_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
21815
22023
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
21816
22024
|
const signed = await identity.sign(toSign, [0]);
|
|
21817
22025
|
signed.finalizeIdx(0);
|
|
@@ -21869,7 +22077,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
21869
22077
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
21870
22078
|
return false;
|
|
21871
22079
|
}
|
|
21872
|
-
const toSpend =
|
|
22080
|
+
const toSpend = chunkJ5EX3OMM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21873
22081
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
21874
22082
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
21875
22083
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -21890,7 +22098,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
21890
22098
|
}
|
|
21891
22099
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
21892
22100
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
21893
|
-
const toSpend =
|
|
22101
|
+
const toSpend = chunkJ5EX3OMM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21894
22102
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
21895
22103
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
21896
22104
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -21943,7 +22151,7 @@ function encodeCompactSize(n) {
|
|
|
21943
22151
|
return buf;
|
|
21944
22152
|
}
|
|
21945
22153
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
21946
|
-
const tx = new
|
|
22154
|
+
const tx = new chunkJ5EX3OMM_cjs.Transaction({ version: 0 });
|
|
21947
22155
|
tx.addInput({
|
|
21948
22156
|
txid: toSpend.id,
|
|
21949
22157
|
index: 0,
|
|
@@ -21957,12 +22165,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
21957
22165
|
});
|
|
21958
22166
|
tx.addOutput({
|
|
21959
22167
|
amount: 0n,
|
|
21960
|
-
script:
|
|
22168
|
+
script: chunkJ5EX3OMM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21961
22169
|
});
|
|
21962
22170
|
return tx;
|
|
21963
22171
|
}
|
|
21964
22172
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
21965
|
-
const tx = new
|
|
22173
|
+
const tx = new chunkJ5EX3OMM_cjs.Transaction({ version: 0 });
|
|
21966
22174
|
tx.addInput({
|
|
21967
22175
|
txid: toSpend.id,
|
|
21968
22176
|
index: 0,
|
|
@@ -21974,7 +22182,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
21974
22182
|
});
|
|
21975
22183
|
tx.addOutput({
|
|
21976
22184
|
amount: 0n,
|
|
21977
|
-
script:
|
|
22185
|
+
script: chunkJ5EX3OMM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21978
22186
|
});
|
|
21979
22187
|
return tx;
|
|
21980
22188
|
}
|
|
@@ -21987,7 +22195,7 @@ var RestEmulatorProvider = class {
|
|
|
21987
22195
|
serverUrl;
|
|
21988
22196
|
async getInfo() {
|
|
21989
22197
|
const url = `${this.serverUrl}/v1/info`;
|
|
21990
|
-
const response = await
|
|
22198
|
+
const response = await chunkJ5EX3OMM_cjs.baseFetch(url);
|
|
21991
22199
|
if (!response.ok) {
|
|
21992
22200
|
const errorText2 = await response.text();
|
|
21993
22201
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -22105,7 +22313,7 @@ var RestEmulatorProvider = class {
|
|
|
22105
22313
|
}
|
|
22106
22314
|
};
|
|
22107
22315
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
22108
|
-
const tx =
|
|
22316
|
+
const tx = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
22109
22317
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
22110
22318
|
const input = tx.getInput(0);
|
|
22111
22319
|
if (!input) {
|
|
@@ -22132,14 +22340,14 @@ var ExitPathError = class extends Error {
|
|
|
22132
22340
|
reason;
|
|
22133
22341
|
};
|
|
22134
22342
|
function delayWeight(sequence) {
|
|
22135
|
-
const t =
|
|
22343
|
+
const t = chunkJ5EX3OMM_cjs.sequenceToTimelock(sequence);
|
|
22136
22344
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
22137
22345
|
}
|
|
22138
22346
|
async function resolveUnilateralPath(params) {
|
|
22139
22347
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
22140
22348
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
22141
22349
|
if (contract) {
|
|
22142
|
-
const handler =
|
|
22350
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
22143
22351
|
if (!handler) {
|
|
22144
22352
|
throw new ExitPathError(
|
|
22145
22353
|
"no-handler",
|
|
@@ -22162,12 +22370,12 @@ async function resolveUnilateralPath(params) {
|
|
|
22162
22370
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
22163
22371
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
22164
22372
|
}
|
|
22165
|
-
const decoded =
|
|
22373
|
+
const decoded = chunkJ5EX3OMM_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
22166
22374
|
let best;
|
|
22167
22375
|
for (const exit of decoded.exitPaths()) {
|
|
22168
22376
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
22169
22377
|
if (!leaf) continue;
|
|
22170
|
-
const sequence =
|
|
22378
|
+
const sequence = chunkJ5EX3OMM_cjs.timelockToSequence(exit.params.timelock);
|
|
22171
22379
|
const weight = delayWeight(sequence);
|
|
22172
22380
|
if (!best || weight < best.weight) {
|
|
22173
22381
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -22387,7 +22595,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22387
22595
|
let totalAmount = 0n;
|
|
22388
22596
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
22389
22597
|
for (const vtxo of vtxos) {
|
|
22390
|
-
if (!
|
|
22598
|
+
if (!chunkJ5EX3OMM_cjs.canSweepOnchain(vtxo)) {
|
|
22391
22599
|
throw new Error(
|
|
22392
22600
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
22393
22601
|
);
|
|
@@ -22398,14 +22606,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22398
22606
|
}
|
|
22399
22607
|
const resolved = await resolveUnilateralPath({
|
|
22400
22608
|
vtxo,
|
|
22401
|
-
scriptHex: base.hex.encode(
|
|
22609
|
+
scriptHex: base.hex.encode(chunkJ5EX3OMM_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22402
22610
|
contractRepository: wallet.contractRepository,
|
|
22403
22611
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
22404
22612
|
currentTime: Date.now()
|
|
22405
22613
|
});
|
|
22406
22614
|
const spendingLeaf = resolved.selection.leaf;
|
|
22407
22615
|
const sequence = resolved.selection.sequence;
|
|
22408
|
-
const timelock =
|
|
22616
|
+
const timelock = chunkJ5EX3OMM_cjs.sequenceToTimelock(sequence);
|
|
22409
22617
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
22410
22618
|
if (!elapsed) {
|
|
22411
22619
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -22418,7 +22626,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22418
22626
|
sequence,
|
|
22419
22627
|
witnessUtxo: {
|
|
22420
22628
|
amount: BigInt(vtxo.value),
|
|
22421
|
-
script:
|
|
22629
|
+
script: chunkJ5EX3OMM_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
22422
22630
|
},
|
|
22423
22631
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22424
22632
|
});
|
|
@@ -22428,7 +22636,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22428
22636
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
22429
22637
|
);
|
|
22430
22638
|
}
|
|
22431
|
-
const tx = new
|
|
22639
|
+
const tx = new chunkJ5EX3OMM_cjs.Transaction({ version: 2 });
|
|
22432
22640
|
for (const input of inputs) {
|
|
22433
22641
|
tx.addInput(input);
|
|
22434
22642
|
}
|
|
@@ -22503,7 +22711,7 @@ function sweepFeeFor(path, outputAddress, network, feeRate) {
|
|
|
22503
22711
|
return Number(estimator.vsize().fee(BigInt(Math.ceil(feeRate))));
|
|
22504
22712
|
}
|
|
22505
22713
|
async function buildSignedSweep(params) {
|
|
22506
|
-
const { vtxo, path, outputAddress, feeRate, network, identity } = params;
|
|
22714
|
+
const { vtxo, path, outputAddress, feeRate, network, identity, signer } = params;
|
|
22507
22715
|
const fee = sweepFeeFor(path, outputAddress, network, feeRate);
|
|
22508
22716
|
const sendAmount = BigInt(vtxo.value) - BigInt(fee);
|
|
22509
22717
|
if (sendAmount < BigInt(DUST_AMOUNT)) {
|
|
@@ -22511,7 +22719,7 @@ async function buildSignedSweep(params) {
|
|
|
22511
22719
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
22512
22720
|
);
|
|
22513
22721
|
}
|
|
22514
|
-
const tx = new
|
|
22722
|
+
const tx = new chunkJ5EX3OMM_cjs.Transaction({ version: 2 });
|
|
22515
22723
|
tx.addInput({
|
|
22516
22724
|
txid: vtxo.txid,
|
|
22517
22725
|
index: vtxo.vout,
|
|
@@ -22521,7 +22729,7 @@ async function buildSignedSweep(params) {
|
|
|
22521
22729
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22522
22730
|
});
|
|
22523
22731
|
tx.addOutputAddress(outputAddress, sendAmount, network);
|
|
22524
|
-
const signed = await identity.sign(tx);
|
|
22732
|
+
const signed = signer ? await signer(tx) : await identity.sign(tx);
|
|
22525
22733
|
if (!path.extraWitness || path.extraWitness.length === 0) {
|
|
22526
22734
|
signed.finalize();
|
|
22527
22735
|
return { tx: signed, fee };
|
|
@@ -22536,7 +22744,7 @@ async function buildSignedSweep(params) {
|
|
|
22536
22744
|
finalScriptWitness: [
|
|
22537
22745
|
tapScriptSig[0][1],
|
|
22538
22746
|
...path.extraWitness,
|
|
22539
|
-
|
|
22747
|
+
chunkJ5EX3OMM_cjs.scriptFromTapLeafScript(path.leaf),
|
|
22540
22748
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
22541
22749
|
]
|
|
22542
22750
|
});
|
|
@@ -22566,7 +22774,7 @@ async function resolveFeeRate(opts) {
|
|
|
22566
22774
|
}
|
|
22567
22775
|
async function selectExitVtxos(opts) {
|
|
22568
22776
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
22569
|
-
const res = await
|
|
22777
|
+
const res = await chunkJ5EX3OMM_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
22570
22778
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
22571
22779
|
const out = [];
|
|
22572
22780
|
for (const vtxo of res.vtxos) {
|
|
@@ -22581,7 +22789,7 @@ async function selectExitVtxos(opts) {
|
|
|
22581
22789
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
22582
22790
|
);
|
|
22583
22791
|
}
|
|
22584
|
-
const handler =
|
|
22792
|
+
const handler = chunkYYWEBYFJ_cjs.contractHandlers.get(contract.type);
|
|
22585
22793
|
if (!handler) {
|
|
22586
22794
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
22587
22795
|
}
|
|
@@ -22611,7 +22819,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22611
22819
|
if (pendingNodes.length > 0) {
|
|
22612
22820
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
22613
22821
|
for (const psbt of txs) {
|
|
22614
|
-
psbts.set(
|
|
22822
|
+
psbts.set(chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
22615
22823
|
}
|
|
22616
22824
|
}
|
|
22617
22825
|
const childVsize = Number(
|
|
@@ -22647,7 +22855,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22647
22855
|
try {
|
|
22648
22856
|
const resolved = await resolveUnilateralPath({
|
|
22649
22857
|
vtxo,
|
|
22650
|
-
scriptHex: base.hex.encode(
|
|
22858
|
+
scriptHex: base.hex.encode(chunkJ5EX3OMM_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22651
22859
|
contractRepository: wallet.contractRepository,
|
|
22652
22860
|
walletPubKeyHex,
|
|
22653
22861
|
currentTime: Date.now()
|
|
@@ -22666,7 +22874,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22666
22874
|
});
|
|
22667
22875
|
continue;
|
|
22668
22876
|
}
|
|
22669
|
-
const t =
|
|
22877
|
+
const t = chunkJ5EX3OMM_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
22670
22878
|
const delay = { type: t.type, value: Number(t.value) };
|
|
22671
22879
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
22672
22880
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -23067,13 +23275,14 @@ async function prepare(opts) {
|
|
|
23067
23275
|
txid: sweep.vtxo.txid,
|
|
23068
23276
|
vout: sweep.vtxo.vout,
|
|
23069
23277
|
value: sweep.vtxo.value,
|
|
23070
|
-
pkScript:
|
|
23278
|
+
pkScript: chunkJ5EX3OMM_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
23071
23279
|
},
|
|
23072
23280
|
path: sweep.resolved.selection,
|
|
23073
23281
|
outputAddress: opts.sweepAddress,
|
|
23074
23282
|
feeRate,
|
|
23075
23283
|
network: wallet.network,
|
|
23076
|
-
identity: wallet.identity
|
|
23284
|
+
identity: wallet.identity,
|
|
23285
|
+
signer: (tx2) => wallet.signInputsByWitnessScript(tx2)
|
|
23077
23286
|
});
|
|
23078
23287
|
activeOutpoints.add(outpoint);
|
|
23079
23288
|
sweepSteps.push({
|
|
@@ -23155,7 +23364,7 @@ async function prepare(opts) {
|
|
|
23155
23364
|
if (newFee <= splitterFee) break;
|
|
23156
23365
|
splitterFee = newFee;
|
|
23157
23366
|
}
|
|
23158
|
-
const splitter = new
|
|
23367
|
+
const splitter = new chunkJ5EX3OMM_cjs.Transaction({ version: 2 });
|
|
23159
23368
|
for (const coin of selected.inputs) {
|
|
23160
23369
|
splitter.addInput({
|
|
23161
23370
|
txid: coin.txid,
|
|
@@ -23299,41 +23508,41 @@ var UnilateralExit = {
|
|
|
23299
23508
|
// src/arkade/index.ts
|
|
23300
23509
|
var arkade_exports = {};
|
|
23301
23510
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
23302
|
-
ARKADE_OP: () =>
|
|
23303
|
-
ARKADE_OPCODES: () =>
|
|
23304
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
23305
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
23306
|
-
ARKADE_OPS: () =>
|
|
23511
|
+
ARKADE_OP: () => chunkYYWEBYFJ_cjs.ARKADE_OP,
|
|
23512
|
+
ARKADE_OPCODES: () => chunkYYWEBYFJ_cjs.ARKADE_OPCODES,
|
|
23513
|
+
ARKADE_OPCODE_NAMES: () => chunkYYWEBYFJ_cjs.ARKADE_OPCODE_NAMES,
|
|
23514
|
+
ARKADE_OPCODE_VALUES: () => chunkYYWEBYFJ_cjs.ARKADE_OPCODE_VALUES,
|
|
23515
|
+
ARKADE_OPS: () => chunkYYWEBYFJ_cjs.ARKADE_OPS,
|
|
23307
23516
|
Arkade: () => Arkade,
|
|
23308
23517
|
ArkadeContract: () => ArkadeContract,
|
|
23309
|
-
ArkadeProgramScript: () =>
|
|
23310
|
-
ArkadeScript: () =>
|
|
23518
|
+
ArkadeProgramScript: () => chunkYYWEBYFJ_cjs.ArkadeProgramScript,
|
|
23519
|
+
ArkadeScript: () => chunkYYWEBYFJ_cjs.ArkadeScript,
|
|
23311
23520
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
23312
|
-
BigNum: () =>
|
|
23521
|
+
BigNum: () => chunkYYWEBYFJ_cjs.bignum_exports,
|
|
23313
23522
|
OP: () => btcSigner.OP,
|
|
23314
|
-
OPCODE_NAMES: () =>
|
|
23315
|
-
OPCODE_VALUES: () =>
|
|
23316
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
23523
|
+
OPCODE_NAMES: () => chunkYYWEBYFJ_cjs.OPCODE_NAMES,
|
|
23524
|
+
OPCODE_VALUES: () => chunkYYWEBYFJ_cjs.OPCODE_VALUES,
|
|
23525
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkYYWEBYFJ_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
23317
23526
|
Script: () => btcSigner.Script,
|
|
23318
|
-
arkadeScriptHash: () =>
|
|
23319
|
-
arkadeWitnessHash: () =>
|
|
23320
|
-
asmToBytes: () =>
|
|
23321
|
-
bytesToASM: () =>
|
|
23322
|
-
computeArkadeScriptPublicKey: () =>
|
|
23527
|
+
arkadeScriptHash: () => chunkYYWEBYFJ_cjs.arkadeScriptHash,
|
|
23528
|
+
arkadeWitnessHash: () => chunkYYWEBYFJ_cjs.arkadeWitnessHash,
|
|
23529
|
+
asmToBytes: () => chunkYYWEBYFJ_cjs.asmToBytes,
|
|
23530
|
+
bytesToASM: () => chunkYYWEBYFJ_cjs.bytesToASM,
|
|
23531
|
+
computeArkadeScriptPublicKey: () => chunkYYWEBYFJ_cjs.computeArkadeScriptPublicKey,
|
|
23323
23532
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
23324
|
-
deserializeArkadeContractParams: () =>
|
|
23325
|
-
fromASM: () =>
|
|
23326
|
-
getOpcodeName: () =>
|
|
23327
|
-
getOpcodeValue: () =>
|
|
23328
|
-
parseArtifact: () =>
|
|
23329
|
-
resolveAsm: () =>
|
|
23330
|
-
serializeArkadeContractParams: () =>
|
|
23331
|
-
stringifyArtifact: () =>
|
|
23332
|
-
toASM: () =>
|
|
23333
|
-
validateProgram: () =>
|
|
23334
|
-
witnessRefToBytes: () =>
|
|
23533
|
+
deserializeArkadeContractParams: () => chunkYYWEBYFJ_cjs.deserializeArkadeContractParams,
|
|
23534
|
+
fromASM: () => chunkYYWEBYFJ_cjs.fromASM,
|
|
23535
|
+
getOpcodeName: () => chunkYYWEBYFJ_cjs.getOpcodeName,
|
|
23536
|
+
getOpcodeValue: () => chunkYYWEBYFJ_cjs.getOpcodeValue,
|
|
23537
|
+
parseArtifact: () => chunkYYWEBYFJ_cjs.parseArtifact,
|
|
23538
|
+
resolveAsm: () => chunkYYWEBYFJ_cjs.resolveAsm,
|
|
23539
|
+
serializeArkadeContractParams: () => chunkYYWEBYFJ_cjs.serializeArkadeContractParams,
|
|
23540
|
+
stringifyArtifact: () => chunkYYWEBYFJ_cjs.stringifyArtifact,
|
|
23541
|
+
toASM: () => chunkYYWEBYFJ_cjs.toASM,
|
|
23542
|
+
validateProgram: () => chunkYYWEBYFJ_cjs.validateProgram,
|
|
23543
|
+
witnessRefToBytes: () => chunkYYWEBYFJ_cjs.witnessRefToBytes
|
|
23335
23544
|
});
|
|
23336
|
-
var isVtxoCoin = (input) =>
|
|
23545
|
+
var isVtxoCoin = (input) => chunkJ5EX3OMM_cjs.isVirtualCoin(input);
|
|
23337
23546
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
23338
23547
|
let batchId;
|
|
23339
23548
|
let sweepTapTreeRoot;
|
|
@@ -23354,23 +23563,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23354
23563
|
);
|
|
23355
23564
|
await arkProvider.confirmRegistration(intentId);
|
|
23356
23565
|
batchId = event.id;
|
|
23357
|
-
const sweepTapscript =
|
|
23566
|
+
const sweepTapscript = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.encode({
|
|
23358
23567
|
timelock,
|
|
23359
|
-
pubkeys: [
|
|
23568
|
+
pubkeys: [chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
23360
23569
|
}).script;
|
|
23361
23570
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
23362
23571
|
return { skip: false };
|
|
23363
23572
|
},
|
|
23364
23573
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
23365
23574
|
const signerPubKey = await session.getPublicKey();
|
|
23366
|
-
const xonlySignerPubKey =
|
|
23575
|
+
const xonlySignerPubKey = chunkYYWEBYFJ_cjs.toXOnly(signerPubKey, "signer key");
|
|
23367
23576
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
23368
|
-
(k) => base.hex.encode(
|
|
23577
|
+
(k) => base.hex.encode(chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
23369
23578
|
);
|
|
23370
23579
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
23371
23580
|
return { skip: true };
|
|
23372
23581
|
}
|
|
23373
|
-
const commitmentTx =
|
|
23582
|
+
const commitmentTx = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
23374
23583
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
23375
23584
|
if (recipients && recipients.length > 0) {
|
|
23376
23585
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -23408,7 +23617,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23408
23617
|
if (connectorTree) {
|
|
23409
23618
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
23410
23619
|
}
|
|
23411
|
-
let commitmentPsbt =
|
|
23620
|
+
let commitmentPsbt = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
23412
23621
|
assertFinalCommitmentMatchesValidated(
|
|
23413
23622
|
commitmentPsbt,
|
|
23414
23623
|
validatedCommitmentTxid,
|
|
@@ -23450,7 +23659,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23450
23659
|
boardingIndices.push(boardingIdx);
|
|
23451
23660
|
continue;
|
|
23452
23661
|
}
|
|
23453
|
-
if (
|
|
23662
|
+
if (chunkJ5EX3OMM_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
23454
23663
|
continue;
|
|
23455
23664
|
}
|
|
23456
23665
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -23471,7 +23680,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23471
23680
|
index: input.vout,
|
|
23472
23681
|
witnessUtxo: {
|
|
23473
23682
|
amount: BigInt(input.value),
|
|
23474
|
-
script:
|
|
23683
|
+
script: chunkJ5EX3OMM_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
23475
23684
|
},
|
|
23476
23685
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
23477
23686
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -23562,16 +23771,16 @@ var Arkade = class _Arkade {
|
|
|
23562
23771
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
23563
23772
|
static async connect(opts) {
|
|
23564
23773
|
const info = await opts.arkade.getInfo();
|
|
23565
|
-
const serverKey =
|
|
23566
|
-
const checkpoint =
|
|
23567
|
-
const network = opts.network ??
|
|
23774
|
+
const serverKey = chunkYYWEBYFJ_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
23775
|
+
const checkpoint = chunkJ5EX3OMM_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
23776
|
+
const network = opts.network ?? (Object.hasOwn(chunkJ5EX3OMM_cjs.networks, info.network) ? chunkJ5EX3OMM_cjs.getNetwork(info.network) : chunkJ5EX3OMM_cjs.DEFAULT_NETWORK);
|
|
23568
23777
|
let emulatorKey;
|
|
23569
23778
|
if (opts.emulator) {
|
|
23570
|
-
emulatorKey = base.hex.decode(
|
|
23779
|
+
emulatorKey = base.hex.decode(chunkJ5EX3OMM_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
23571
23780
|
}
|
|
23572
23781
|
let userKey;
|
|
23573
23782
|
if (opts.identity) {
|
|
23574
|
-
userKey =
|
|
23783
|
+
userKey = chunkYYWEBYFJ_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
23575
23784
|
}
|
|
23576
23785
|
return new _Arkade({
|
|
23577
23786
|
arkProvider: opts.arkade,
|
|
@@ -23597,7 +23806,7 @@ var Arkade = class _Arkade {
|
|
|
23597
23806
|
* key respectively; explicit args always win.
|
|
23598
23807
|
*/
|
|
23599
23808
|
contract(program, args = {}) {
|
|
23600
|
-
const declared = (program.params ?? []).map(
|
|
23809
|
+
const declared = (program.params ?? []).map(chunkYYWEBYFJ_cjs.inputName);
|
|
23601
23810
|
if (declared.includes("server") && args.server === void 0) {
|
|
23602
23811
|
args = { ...args, server: this.serverKey };
|
|
23603
23812
|
}
|
|
@@ -23617,7 +23826,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23617
23826
|
userKey: client.userKey,
|
|
23618
23827
|
emulatorKey: client.emulatorKey
|
|
23619
23828
|
};
|
|
23620
|
-
this.vtxoScript = new
|
|
23829
|
+
this.vtxoScript = new chunkYYWEBYFJ_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
23621
23830
|
this.tapTree = this.vtxoScript.encode();
|
|
23622
23831
|
this.compiled = this.vtxoScript.compiled;
|
|
23623
23832
|
}
|
|
@@ -23645,7 +23854,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23645
23854
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
23646
23855
|
);
|
|
23647
23856
|
}
|
|
23648
|
-
const typed =
|
|
23857
|
+
const typed = chunkYYWEBYFJ_cjs.deserializeArkadeContractParams(contract.params);
|
|
23649
23858
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
23650
23859
|
serverKey: typed.serverKey,
|
|
23651
23860
|
userKey: typed.userKey,
|
|
@@ -23686,7 +23895,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23686
23895
|
toContractParams() {
|
|
23687
23896
|
return {
|
|
23688
23897
|
type: "arkade",
|
|
23689
|
-
params:
|
|
23898
|
+
params: chunkYYWEBYFJ_cjs.serializeArkadeContractParams({
|
|
23690
23899
|
program: this.program,
|
|
23691
23900
|
args: this.args,
|
|
23692
23901
|
serverKey: this.keys.serverKey,
|
|
@@ -23736,18 +23945,18 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23736
23945
|
if (registered) {
|
|
23737
23946
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
23738
23947
|
return (withVtxos?.vtxos ?? []).filter(
|
|
23739
|
-
(v) => !
|
|
23948
|
+
(v) => !chunkJ5EX3OMM_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
23740
23949
|
);
|
|
23741
23950
|
}
|
|
23742
23951
|
}
|
|
23743
23952
|
if (!this.client.indexer) {
|
|
23744
23953
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
23745
23954
|
}
|
|
23746
|
-
const { vtxos } = await
|
|
23955
|
+
const { vtxos } = await chunkJ5EX3OMM_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
23747
23956
|
scripts: [scriptHex],
|
|
23748
23957
|
spendableOnly: true
|
|
23749
23958
|
});
|
|
23750
|
-
return vtxos.filter((v) => !
|
|
23959
|
+
return vtxos.filter((v) => !chunkJ5EX3OMM_cjs.hasTerminalSpend(v) && !v.isUnrolled);
|
|
23751
23960
|
}
|
|
23752
23961
|
/** Total spendable balance (requires an indexer). */
|
|
23753
23962
|
async getBalance() {
|
|
@@ -23845,7 +24054,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23845
24054
|
this.contract.client.checkpoint
|
|
23846
24055
|
);
|
|
23847
24056
|
if (coin.sourceTx) {
|
|
23848
|
-
|
|
24057
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(arkTx, 0, chunkJ5EX3OMM_cjs.PrevArkTxField, coin.sourceTx);
|
|
23849
24058
|
}
|
|
23850
24059
|
if (this.fn.arkadeScript) {
|
|
23851
24060
|
const indexer = this.contract.client.indexer;
|
|
@@ -23862,8 +24071,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
23862
24071
|
}
|
|
23863
24072
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
23864
24073
|
if (condition.length > 0) {
|
|
23865
|
-
|
|
23866
|
-
|
|
24074
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(arkTx, 0, chunkJ5EX3OMM_cjs.ConditionWitness, condition);
|
|
24075
|
+
chunkJ5EX3OMM_cjs.setArkPsbtField(checkpoints[0], 0, chunkJ5EX3OMM_cjs.ConditionWitness, condition);
|
|
23867
24076
|
}
|
|
23868
24077
|
const packets = [];
|
|
23869
24078
|
if (this.assetSpecs.length > 0) {
|
|
@@ -23902,7 +24111,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23902
24111
|
base.base64.encode(signedArk2.toPSBT()),
|
|
23903
24112
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
23904
24113
|
);
|
|
23905
|
-
const txid =
|
|
24114
|
+
const txid = chunkJ5EX3OMM_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
23906
24115
|
return {
|
|
23907
24116
|
txid,
|
|
23908
24117
|
signedArkTx: res2.signedArkTx,
|
|
@@ -23961,23 +24170,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
23961
24170
|
}
|
|
23962
24171
|
buildAssetPacket() {
|
|
23963
24172
|
const groups = this.assetSpecs.map((s) => {
|
|
23964
|
-
const id = typeof s.assetId === "string" ?
|
|
23965
|
-
return
|
|
24173
|
+
const id = typeof s.assetId === "string" ? chunkSH23SRZE_cjs.AssetId.fromString(s.assetId) : chunkSH23SRZE_cjs.AssetId.fromBytes(s.assetId);
|
|
24174
|
+
return chunkSH23SRZE_cjs.AssetGroup.create(
|
|
23966
24175
|
id,
|
|
23967
24176
|
null,
|
|
23968
|
-
s.inputs.map((i) =>
|
|
23969
|
-
s.outputs.map((o) =>
|
|
23970
|
-
(s.metadata ?? []).map((m) =>
|
|
24177
|
+
s.inputs.map((i) => chunkSH23SRZE_cjs.AssetInput.create(i.vin, i.amount)),
|
|
24178
|
+
s.outputs.map((o) => chunkSH23SRZE_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
24179
|
+
(s.metadata ?? []).map((m) => chunkSH23SRZE_cjs.Metadata.create(m.key, m.value))
|
|
23971
24180
|
);
|
|
23972
24181
|
});
|
|
23973
|
-
return
|
|
24182
|
+
return chunkSH23SRZE_cjs.Packet.create(groups);
|
|
23974
24183
|
}
|
|
23975
24184
|
witnessBytes(ref) {
|
|
23976
|
-
return
|
|
24185
|
+
return chunkYYWEBYFJ_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
23977
24186
|
}
|
|
23978
24187
|
};
|
|
23979
24188
|
function bindInputs(fn, callArgs) {
|
|
23980
|
-
const names = (fn.def.inputs ?? []).map(
|
|
24189
|
+
const names = (fn.def.inputs ?? []).map(chunkYYWEBYFJ_cjs.inputName);
|
|
23981
24190
|
if (callArgs.length !== names.length) {
|
|
23982
24191
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
23983
24192
|
}
|
|
@@ -24181,6 +24390,16 @@ function assertNoAssets(railId, req) {
|
|
|
24181
24390
|
);
|
|
24182
24391
|
}
|
|
24183
24392
|
}
|
|
24393
|
+
function selectionOf(req) {
|
|
24394
|
+
return req.selectedVtxos;
|
|
24395
|
+
}
|
|
24396
|
+
function assertNoSelection(railId, req) {
|
|
24397
|
+
if (selectionOf(req) !== void 0) {
|
|
24398
|
+
throw new Error(
|
|
24399
|
+
`${railId}: cannot spend a caller-chosen input set (selectedVtxos) \u2014 this rail does not choose the coins it spends`
|
|
24400
|
+
);
|
|
24401
|
+
}
|
|
24402
|
+
}
|
|
24184
24403
|
function resolveAssetAmount(railId, req) {
|
|
24185
24404
|
const assets = assetsOf(req);
|
|
24186
24405
|
if (assets.length !== 1) {
|
|
@@ -24324,13 +24543,17 @@ function arkRail() {
|
|
|
24324
24543
|
const address = arkTarget(req.raw);
|
|
24325
24544
|
assertNoAssets("ark", req);
|
|
24326
24545
|
const amt = resolveSendAmount("ark", req.raw, req.amount);
|
|
24546
|
+
const selectedVtxos = selectionOf(req);
|
|
24327
24547
|
return {
|
|
24328
24548
|
railId: "ark",
|
|
24329
24549
|
amount: amt,
|
|
24330
24550
|
fee: 0,
|
|
24331
24551
|
total: amt,
|
|
24332
24552
|
send: async () => makeHandle("ark", async (emit) => {
|
|
24333
|
-
const txid = await ctx.wallet.send({
|
|
24553
|
+
const txid = selectedVtxos ? await ctx.wallet.send({
|
|
24554
|
+
recipients: [{ address, amount: amt }],
|
|
24555
|
+
selectedVtxos
|
|
24556
|
+
}) : await ctx.wallet.send({ address, amount: amt });
|
|
24334
24557
|
const result = { railId: "ark", txid };
|
|
24335
24558
|
emit({ status: "settled", result });
|
|
24336
24559
|
return result;
|
|
@@ -24353,6 +24576,7 @@ function arkAssetRail() {
|
|
|
24353
24576
|
const asset = resolveAssetAmount("ark-asset", req);
|
|
24354
24577
|
if (req.amount !== void 0) assertSendableAmount("ark-asset", req.amount);
|
|
24355
24578
|
const carrier = tryResolveSendAmount(req.raw, req.amount) ?? ASSET_CARRIER_SATS;
|
|
24579
|
+
const selectedVtxos = selectionOf(req);
|
|
24356
24580
|
return {
|
|
24357
24581
|
railId: "ark-asset",
|
|
24358
24582
|
amount: carrier,
|
|
@@ -24360,11 +24584,8 @@ function arkAssetRail() {
|
|
|
24360
24584
|
total: carrier,
|
|
24361
24585
|
assets: { delivered: asset, spent: asset },
|
|
24362
24586
|
send: async () => makeHandle("ark-asset", async (emit) => {
|
|
24363
|
-
const
|
|
24364
|
-
|
|
24365
|
-
amount: carrier,
|
|
24366
|
-
assets: [asset]
|
|
24367
|
-
});
|
|
24587
|
+
const recipient = { address, amount: carrier, assets: [asset] };
|
|
24588
|
+
const txid = selectedVtxos ? await ctx.wallet.send({ recipients: [recipient], selectedVtxos }) : await ctx.wallet.send(recipient);
|
|
24368
24589
|
const result = { railId: "ark-asset", txid };
|
|
24369
24590
|
emit({ status: "settled", result });
|
|
24370
24591
|
return result;
|
|
@@ -24374,17 +24595,24 @@ function arkAssetRail() {
|
|
|
24374
24595
|
};
|
|
24375
24596
|
}
|
|
24376
24597
|
var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo()).fees;
|
|
24377
|
-
|
|
24378
|
-
|
|
24379
|
-
|
|
24380
|
-
|
|
24381
|
-
|
|
24382
|
-
|
|
24383
|
-
|
|
24384
|
-
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24598
|
+
function offchainInputFees(vtxos, fees) {
|
|
24599
|
+
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24600
|
+
return vtxos.reduce(
|
|
24601
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkJ5EX3OMM_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
24602
|
+
0
|
|
24603
|
+
);
|
|
24604
|
+
}
|
|
24605
|
+
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
24606
|
+
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
24607
|
+
const net = inputs.reduce(
|
|
24608
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkJ5EX3OMM_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
24609
|
+
0n
|
|
24610
|
+
);
|
|
24611
|
+
const script = base.hex.encode(chunkJ5EX3OMM_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
24612
|
+
return changeAfterOutputFee(
|
|
24613
|
+
net - needed,
|
|
24614
|
+
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script }).satoshis)
|
|
24615
|
+
).fee;
|
|
24388
24616
|
}
|
|
24389
24617
|
function onchainRail(deps) {
|
|
24390
24618
|
if (typeof deps?.feeInfo !== "function") {
|
|
@@ -24401,18 +24629,34 @@ function onchainRail(deps) {
|
|
|
24401
24629
|
const amt = resolveSendAmount("onchain", req.raw, req.amount);
|
|
24402
24630
|
const fees = await deps.feeInfo();
|
|
24403
24631
|
const script = base.hex.encode(offboardDestinationScript(address));
|
|
24404
|
-
const
|
|
24632
|
+
const exitFee = Number(
|
|
24633
|
+
new Estimator(fees?.intentFee ?? {}).evalOnchainOutput({
|
|
24634
|
+
amount: BigInt(amt),
|
|
24635
|
+
script
|
|
24636
|
+
}).satoshis
|
|
24637
|
+
);
|
|
24638
|
+
const selectedVtxos = selectionOf(req);
|
|
24639
|
+
const inputFee = selectedVtxos ? offchainInputFees(selectedVtxos, fees) : 0;
|
|
24640
|
+
const changeFee = selectedVtxos ? await changeOutputFee(
|
|
24641
|
+
ctx.wallet,
|
|
24642
|
+
selectedVtxos,
|
|
24643
|
+
BigInt(amt) + BigInt(exitFee),
|
|
24644
|
+
fees
|
|
24645
|
+
) : 0n;
|
|
24405
24646
|
return {
|
|
24406
24647
|
railId: "onchain",
|
|
24407
24648
|
amount: amt,
|
|
24408
|
-
fee,
|
|
24409
|
-
total:
|
|
24649
|
+
fee: exitFee + inputFee + Number(changeFee),
|
|
24650
|
+
total: amt + exitFee + inputFee + Number(changeFee),
|
|
24410
24651
|
send: async () => makeHandle("onchain", async (emit) => {
|
|
24411
|
-
const
|
|
24412
|
-
|
|
24413
|
-
|
|
24414
|
-
|
|
24415
|
-
|
|
24652
|
+
const ramps = new Ramps(ctx.wallet);
|
|
24653
|
+
const txid = await ramps.offboardExact({
|
|
24654
|
+
destinationAddress: address,
|
|
24655
|
+
feeInfo: fees,
|
|
24656
|
+
amount: BigInt(amt),
|
|
24657
|
+
// Omitted, not undefined: an empty set covers nothing.
|
|
24658
|
+
...selectedVtxos ? { vtxos: selectedVtxos } : {}
|
|
24659
|
+
});
|
|
24416
24660
|
const result = { railId: "onchain", txid };
|
|
24417
24661
|
emit({ status: "settled", result });
|
|
24418
24662
|
return result;
|
|
@@ -24498,6 +24742,7 @@ exports.MessageBusNotInitializedError = MessageBusNotInitializedError;
|
|
|
24498
24742
|
exports.MissingSigningDescriptorError = MissingSigningDescriptorError;
|
|
24499
24743
|
exports.MnemonicIdentity = MnemonicIdentity;
|
|
24500
24744
|
exports.OnchainWallet = OnchainWallet;
|
|
24745
|
+
exports.OversizedChangeError = OversizedChangeError;
|
|
24501
24746
|
exports.P2A = P2A;
|
|
24502
24747
|
exports.PaymentRouter = PaymentRouter;
|
|
24503
24748
|
exports.PrevTxUnavailableError = PrevTxUnavailableError;
|
|
@@ -24540,6 +24785,7 @@ exports.arkade_exports = arkade_exports;
|
|
|
24540
24785
|
exports.assertFinalCommitmentMatchesValidated = assertFinalCommitmentMatchesValidated;
|
|
24541
24786
|
exports.assertIntentIdUnique = assertIntentIdUnique;
|
|
24542
24787
|
exports.assertNoAssets = assertNoAssets;
|
|
24788
|
+
exports.assertNoSelection = assertNoSelection;
|
|
24543
24789
|
exports.assertSendableAmount = assertSendableAmount;
|
|
24544
24790
|
exports.assertSubmittedArkTxid = assertSubmittedArkTxid;
|
|
24545
24791
|
exports.assertValidBatchExpiry = assertValidBatchExpiry;
|
|
@@ -24642,6 +24888,7 @@ exports.saveVtxosForContract = saveVtxosForContract;
|
|
|
24642
24888
|
exports.scriptFromArkAddress = scriptFromArkAddress;
|
|
24643
24889
|
exports.selectCoinsWithAsset = selectCoinsWithAsset;
|
|
24644
24890
|
exports.selectVirtualCoins = selectVirtualCoins;
|
|
24891
|
+
exports.selectionOf = selectionOf;
|
|
24645
24892
|
exports.serializeAssets = serializeAssets;
|
|
24646
24893
|
exports.serializeExitPackage = serializeExitPackage;
|
|
24647
24894
|
exports.serializeUtxo = serializeUtxo;
|
|
@@ -24661,5 +24908,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
|
24661
24908
|
exports.walletFeeSource = walletFeeSource;
|
|
24662
24909
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
24663
24910
|
exports.withPrevTxs = withPrevTxs;
|
|
24664
|
-
//# sourceMappingURL=chunk-
|
|
24665
|
-
//# sourceMappingURL=chunk-
|
|
24911
|
+
//# sourceMappingURL=chunk-EHJYR4E5.cjs.map
|
|
24912
|
+
//# sourceMappingURL=chunk-EHJYR4E5.cjs.map
|