@arkade-os/sdk 0.5.13 → 0.5.14
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/README.md +6 -0
- package/dist/adapters/expo.cjs +6 -6
- 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/{asyncStorageTaskQueue-Y4BlVm41.d.cts → asyncStorageTaskQueue-DzO5SBcm.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-Dhbe00Ya.d.ts → asyncStorageTaskQueue-p7zeFhA3.d.ts} +2 -2
- package/dist/{chunk-QSERJPTT.js → chunk-4HZQSKWG.js} +3 -3
- package/dist/{chunk-QSERJPTT.js.map → chunk-4HZQSKWG.js.map} +1 -1
- package/dist/{chunk-HS7TKVOZ.cjs → chunk-6J4GABF7.cjs} +8 -4
- package/dist/chunk-6J4GABF7.cjs.map +1 -0
- package/dist/{chunk-BA36SQY2.js → chunk-72EC3ASW.js} +3 -3
- package/dist/{chunk-BA36SQY2.js.map → chunk-72EC3ASW.js.map} +1 -1
- package/dist/{chunk-WFJPLXOE.cjs → chunk-7LPT6AYH.cjs} +18 -18
- package/dist/{chunk-WFJPLXOE.cjs.map → chunk-7LPT6AYH.cjs.map} +1 -1
- package/dist/{chunk-BP4NA7HK.js → chunk-AZHBGWVC.js} +4 -4
- package/dist/{chunk-BP4NA7HK.js.map → chunk-AZHBGWVC.js.map} +1 -1
- package/dist/{chunk-6XVTGWQK.cjs → chunk-EVVLVFY7.cjs} +17 -17
- package/dist/{chunk-6XVTGWQK.cjs.map → chunk-EVVLVFY7.cjs.map} +1 -1
- package/dist/{chunk-Y3AWLHQP.js → chunk-HWWSLCQN.js} +394 -58
- package/dist/chunk-HWWSLCQN.js.map +1 -0
- package/dist/{chunk-LHLRG2BE.js → chunk-J2JZZTOE.js} +8 -5
- package/dist/chunk-J2JZZTOE.js.map +1 -0
- package/dist/{chunk-D4QH6L54.js → chunk-LCGRZ24T.js} +4 -4
- package/dist/{chunk-D4QH6L54.js.map → chunk-LCGRZ24T.js.map} +1 -1
- package/dist/{chunk-6WPP4UGN.cjs → chunk-LQH7DACV.cjs} +871 -535
- package/dist/chunk-LQH7DACV.cjs.map +1 -0
- package/dist/{chunk-TYSUFG2K.cjs → chunk-MEIE2AEU.cjs} +11 -11
- package/dist/{chunk-TYSUFG2K.cjs.map → chunk-MEIE2AEU.cjs.map} +1 -1
- package/dist/{chunk-TD4PKK2I.cjs → chunk-XZHTYYW5.cjs} +8 -8
- package/dist/{chunk-TD4PKK2I.cjs.map → chunk-XZHTYYW5.cjs.map} +1 -1
- package/dist/compiler.d.cts +1 -1
- package/dist/compiler.d.ts +1 -1
- package/dist/contracts/handlers/index.cjs +10 -10
- 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/{index-BapVvuoI.d.ts → index-CaOBA9Ev.d.ts} +2 -2
- package/dist/{index-BQwrHcOh.d.cts → index-Cy57QdcL.d.cts} +67 -2
- package/dist/{index-DuXylQrN.d.ts → index-Db5qzYRi.d.ts} +67 -2
- package/dist/{index-BaTItxPx.d.cts → index-Lq_u0hqj.d.cts} +2 -2
- package/dist/index.cjs +325 -325
- package/dist/index.d.cts +126 -57
- package/dist/index.d.ts +126 -57
- package/dist/index.js +4 -4
- package/dist/{program-DPzf5qsk.d.cts → program-ZWUAWy_9.d.cts} +1 -1
- package/dist/{program-38A2Twvj.d.ts → program-zdDO4cMt.d.ts} +1 -1
- package/dist/repositories/realm/index.cjs +37 -37
- 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 +35 -35
- 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-D2itCXf6.d.cts → taskRunner-DhZ-KQBW.d.cts} +2 -2
- package/dist/{taskRunner-BxOmg-O6.d.ts → taskRunner-amPuilMW.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 +15 -15
- package/dist/wallet/expo/index.d.cts +2 -2
- package/dist/wallet/expo/index.d.ts +2 -2
- 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-6WPP4UGN.cjs.map +0 -1
- package/dist/chunk-HS7TKVOZ.cjs.map +0 -1
- package/dist/chunk-LHLRG2BE.js.map +0 -1
- package/dist/chunk-Y3AWLHQP.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk7LPT6AYH_cjs = require('./chunk-7LPT6AYH.cjs');
|
|
4
|
+
var chunkXZHTYYW5_cjs = require('./chunk-XZHTYYW5.cjs');
|
|
5
5
|
var chunkACIQZLWL_cjs = require('./chunk-ACIQZLWL.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunk6J4GABF7_cjs = require('./chunk-6J4GABF7.cjs');
|
|
7
7
|
var chunk6TBTL42M_cjs = require('./chunk-6TBTL42M.cjs');
|
|
8
8
|
var bip39 = require('@scure/bip39');
|
|
9
9
|
var english_js = require('@scure/bip39/wordlists/english.js');
|
|
@@ -336,7 +336,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
336
336
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
337
337
|
const tx = this.graph.find(txid);
|
|
338
338
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
339
|
-
const cosigners =
|
|
339
|
+
const cosigners = chunk6J4GABF7_cjs.getArkPsbtFields(tx.root, 0, chunk6J4GABF7_cjs.CosignerPublicKey).map(
|
|
340
340
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
341
341
|
// xonly pubkey
|
|
342
342
|
);
|
|
@@ -388,7 +388,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
388
388
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
389
389
|
const prevoutAmounts = [];
|
|
390
390
|
const prevoutScripts = [];
|
|
391
|
-
const cosigners =
|
|
391
|
+
const cosigners = chunk6J4GABF7_cjs.getArkPsbtFields(g.root, 0, chunk6J4GABF7_cjs.CosignerPublicKey).map((c) => c.key);
|
|
392
392
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
393
393
|
taprootTweak: this.scriptRoot
|
|
394
394
|
});
|
|
@@ -471,7 +471,7 @@ var SingleKey = class _SingleKey {
|
|
|
471
471
|
async sign(tx, inputIndexes) {
|
|
472
472
|
const txCpy = tx.clone();
|
|
473
473
|
if (!inputIndexes) {
|
|
474
|
-
|
|
474
|
+
chunk6J4GABF7_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
|
|
475
475
|
try {
|
|
476
476
|
if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
|
|
477
477
|
throw new Error("Failed to sign transaction");
|
|
@@ -571,7 +571,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
571
571
|
let network;
|
|
572
572
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
573
573
|
descriptor = opts.descriptor;
|
|
574
|
-
network =
|
|
574
|
+
network = chunkXZHTYYW5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
575
575
|
} else {
|
|
576
576
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
577
577
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -648,7 +648,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
648
648
|
}
|
|
649
649
|
/** Returns true when `descriptor` is derived from this identity's seed. */
|
|
650
650
|
ownsDescriptor(descriptor) {
|
|
651
|
-
return
|
|
651
|
+
return chunkXZHTYYW5_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
652
652
|
}
|
|
653
653
|
/**
|
|
654
654
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -687,7 +687,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
687
687
|
}
|
|
688
688
|
// ── internal helpers ─────────────────────────────────────────────
|
|
689
689
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
690
|
-
const network =
|
|
690
|
+
const network = chunkXZHTYYW5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
691
691
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
692
692
|
if (expansion.isRanged) {
|
|
693
693
|
throw new Error(
|
|
@@ -712,7 +712,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
712
712
|
signTxWithKey(tx, key, inputIndexes) {
|
|
713
713
|
const txCpy = tx.clone();
|
|
714
714
|
if (!inputIndexes) {
|
|
715
|
-
|
|
715
|
+
chunk6J4GABF7_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
|
|
716
716
|
try {
|
|
717
717
|
if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
|
|
718
718
|
throw new Error("Failed to sign transaction");
|
|
@@ -813,7 +813,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
813
813
|
/** Wildcard account-descriptor template (e.g. `tr([fp/86'/0'/0']xpub/0/*)`). */
|
|
814
814
|
descriptor;
|
|
815
815
|
constructor(descriptor) {
|
|
816
|
-
const network =
|
|
816
|
+
const network = chunkXZHTYYW5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
817
817
|
let expansion;
|
|
818
818
|
try {
|
|
819
819
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -848,7 +848,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
848
848
|
}
|
|
849
849
|
/** Returns true when `descriptor` derives from this identity's xpub. */
|
|
850
850
|
ownsDescriptor(descriptor) {
|
|
851
|
-
return
|
|
851
|
+
return chunkXZHTYYW5_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
852
852
|
}
|
|
853
853
|
};
|
|
854
854
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -991,10 +991,10 @@ var DescriptorIdentity = class {
|
|
|
991
991
|
this.base = base;
|
|
992
992
|
}
|
|
993
993
|
async xOnlyPublicKey() {
|
|
994
|
-
return
|
|
994
|
+
return chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
995
995
|
}
|
|
996
996
|
async compressedPublicKey() {
|
|
997
|
-
return
|
|
997
|
+
return chunkXZHTYYW5_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
|
|
998
998
|
}
|
|
999
999
|
async sign(tx, inputIndexes) {
|
|
1000
1000
|
const [signed] = await this.signer.signWithDescriptor([
|
|
@@ -1054,8 +1054,8 @@ var StaticDescriptorProvider = class _StaticDescriptorProvider {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
isOurs(descriptor) {
|
|
1056
1056
|
try {
|
|
1057
|
-
const normalized =
|
|
1058
|
-
const pubKey =
|
|
1057
|
+
const normalized = chunkXZHTYYW5_cjs.normalizeToDescriptor(descriptor);
|
|
1058
|
+
const pubKey = chunkXZHTYYW5_cjs.extractPubKey(normalized);
|
|
1059
1059
|
return pubKey.toLowerCase() === this.pubKeyHex.toLowerCase();
|
|
1060
1060
|
} catch {
|
|
1061
1061
|
return false;
|
|
@@ -1397,7 +1397,7 @@ function unwrapKeyring(provider) {
|
|
|
1397
1397
|
}
|
|
1398
1398
|
function keyOf(descriptor) {
|
|
1399
1399
|
try {
|
|
1400
|
-
return
|
|
1400
|
+
return chunkXZHTYYW5_cjs.extractPubKey(chunkXZHTYYW5_cjs.normalizeToDescriptor(descriptor)).toLowerCase();
|
|
1401
1401
|
} catch {
|
|
1402
1402
|
return void 0;
|
|
1403
1403
|
}
|
|
@@ -1488,12 +1488,12 @@ async function resolveDescriptorSigner(descriptor, identity, provider) {
|
|
|
1488
1488
|
signMessageWithDescriptor: (ownedDescriptor, message, signatureType) => identity.signDescriptorMessage(ownedDescriptor, message, signatureType)
|
|
1489
1489
|
} : void 0;
|
|
1490
1490
|
const owner = providerOwner ?? identityOwner;
|
|
1491
|
-
if (owner &&
|
|
1491
|
+
if (owner && chunkXZHTYYW5_cjs.parseHDDescriptor(descriptor)) {
|
|
1492
1492
|
return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
|
|
1493
1493
|
}
|
|
1494
1494
|
let key;
|
|
1495
1495
|
try {
|
|
1496
|
-
key =
|
|
1496
|
+
key = chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1497
1497
|
} catch {
|
|
1498
1498
|
throw new ForeignDescriptorError(descriptor);
|
|
1499
1499
|
}
|
|
@@ -1546,14 +1546,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
|
|
|
1546
1546
|
}
|
|
1547
1547
|
var PREIMAGE_INDEX = 0;
|
|
1548
1548
|
function isPerArtifactDescriptor(descriptor) {
|
|
1549
|
-
return
|
|
1549
|
+
return chunkXZHTYYW5_cjs.parseHDDescriptor(descriptor) !== null;
|
|
1550
1550
|
}
|
|
1551
1551
|
async function provisionDescriptor(wallet) {
|
|
1552
1552
|
const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
|
|
1553
|
-
return allocated ?? await
|
|
1553
|
+
return allocated ?? await chunkXZHTYYW5_cjs.identityDescriptor(wallet.identity);
|
|
1554
1554
|
}
|
|
1555
1555
|
async function provisionRefundKey(wallet) {
|
|
1556
|
-
const descriptorPromise =
|
|
1556
|
+
const descriptorPromise = chunkXZHTYYW5_cjs.identityDescriptor(wallet.identity);
|
|
1557
1557
|
const identityPubkeyPromise = wallet.identity.xOnlyPublicKey();
|
|
1558
1558
|
void identityPubkeyPromise.catch(() => void 0);
|
|
1559
1559
|
const descriptor = await descriptorPromise;
|
|
@@ -1616,7 +1616,7 @@ async function contractSigner(wallet, descriptor) {
|
|
|
1616
1616
|
const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
|
|
1617
1617
|
let expected;
|
|
1618
1618
|
try {
|
|
1619
|
-
expected =
|
|
1619
|
+
expected = chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1620
1620
|
} catch (cause) {
|
|
1621
1621
|
throw new ForeignDescriptorError(descriptor, { cause });
|
|
1622
1622
|
}
|
|
@@ -1698,7 +1698,7 @@ function debugLog(debug, ...args) {
|
|
|
1698
1698
|
}
|
|
1699
1699
|
function normalizeOptions(pathOrOptions) {
|
|
1700
1700
|
const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
1701
|
-
|
|
1701
|
+
chunk6J4GABF7_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
|
|
1702
1702
|
return {
|
|
1703
1703
|
path: o.path,
|
|
1704
1704
|
updateViaCache: o.updateViaCache ?? "none",
|
|
@@ -1821,14 +1821,14 @@ var RestDelegateProvider = class {
|
|
|
1821
1821
|
*/
|
|
1822
1822
|
async delegate(intent, forfeitTxs, options) {
|
|
1823
1823
|
const url = `${this.url}/v1/delegate`;
|
|
1824
|
-
const response = await
|
|
1824
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(url, {
|
|
1825
1825
|
method: "POST",
|
|
1826
1826
|
headers: {
|
|
1827
1827
|
"Content-Type": "application/json"
|
|
1828
1828
|
},
|
|
1829
1829
|
body: JSON.stringify({
|
|
1830
1830
|
intent: {
|
|
1831
|
-
message:
|
|
1831
|
+
message: chunk6J4GABF7_cjs.Proof.encodeMessage(intent.message),
|
|
1832
1832
|
proof: intent.proof
|
|
1833
1833
|
},
|
|
1834
1834
|
forfeit_txs: forfeitTxs,
|
|
@@ -1847,7 +1847,7 @@ var RestDelegateProvider = class {
|
|
|
1847
1847
|
*/
|
|
1848
1848
|
async getDelegateInfo() {
|
|
1849
1849
|
const url = `${this.url}/v1/delegator/info`;
|
|
1850
|
-
const response = await
|
|
1850
|
+
const response = await chunk6J4GABF7_cjs.rateGate.runHttp(url, () => chunk6J4GABF7_cjs.baseFetch(url));
|
|
1851
1851
|
if (!response.ok) {
|
|
1852
1852
|
const errorText2 = await response.text();
|
|
1853
1853
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1880,7 +1880,7 @@ var RestExecutorProvider = class {
|
|
|
1880
1880
|
}
|
|
1881
1881
|
async getInfo() {
|
|
1882
1882
|
const url = this.endpoint("/v1/info");
|
|
1883
|
-
const response = await
|
|
1883
|
+
const response = await chunk6J4GABF7_cjs.rateGate.runHttp(url, () => chunk6J4GABF7_cjs.baseFetch(url));
|
|
1884
1884
|
if (!response.ok) {
|
|
1885
1885
|
throw await failure(response, "get Executor info");
|
|
1886
1886
|
}
|
|
@@ -1888,7 +1888,7 @@ var RestExecutorProvider = class {
|
|
|
1888
1888
|
}
|
|
1889
1889
|
async listTemplates() {
|
|
1890
1890
|
const url = this.endpoint("/v1/templates");
|
|
1891
|
-
const response = await
|
|
1891
|
+
const response = await chunk6J4GABF7_cjs.rateGate.runHttp(url, () => chunk6J4GABF7_cjs.baseFetch(url));
|
|
1892
1892
|
if (!response.ok) {
|
|
1893
1893
|
throw await failure(response, "list Executor templates");
|
|
1894
1894
|
}
|
|
@@ -1905,35 +1905,28 @@ var RestExecutorProvider = class {
|
|
|
1905
1905
|
body.expiresAt = options.expiresAt;
|
|
1906
1906
|
}
|
|
1907
1907
|
const url = this.endpoint("/v1/delegation");
|
|
1908
|
-
const response = await
|
|
1908
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(url, {
|
|
1909
1909
|
method: "POST",
|
|
1910
1910
|
headers: { "Content-Type": "application/json" },
|
|
1911
1911
|
body: JSON.stringify(body),
|
|
1912
1912
|
signal: options.signal
|
|
1913
1913
|
});
|
|
1914
|
-
if (response.status === 429) {
|
|
1915
|
-
chunkHS7TKVOZ_cjs.rateGate.reportRateLimited(url, response.headers?.get("retry-after"));
|
|
1916
|
-
}
|
|
1917
1914
|
if (!response.ok) {
|
|
1918
|
-
throw await failure(
|
|
1915
|
+
throw await failure(
|
|
1916
|
+
response,
|
|
1917
|
+
"register delegation",
|
|
1918
|
+
await postErrorBody(url, response)
|
|
1919
|
+
);
|
|
1919
1920
|
}
|
|
1920
1921
|
const data = await response.json();
|
|
1921
1922
|
return parseDelegation(isObject(data) ? data.delegation : void 0);
|
|
1922
1923
|
}
|
|
1923
1924
|
async getDelegation(address, options = {}) {
|
|
1924
|
-
const
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1925
|
+
const data = await this.getJson(
|
|
1926
|
+
`/v1/delegation?address=${encodeURIComponent(address)}`,
|
|
1927
|
+
"get Executor delegation",
|
|
1928
|
+
options.signal
|
|
1928
1929
|
);
|
|
1929
|
-
if (!response.ok) {
|
|
1930
|
-
const body = await response.text();
|
|
1931
|
-
throw new ExecutorRequestError(
|
|
1932
|
-
`Failed to get Executor delegation (${response.status}): ${body}`,
|
|
1933
|
-
response.status === 404 && !isGrpcNotFound(body) ? void 0 : response.status
|
|
1934
|
-
);
|
|
1935
|
-
}
|
|
1936
|
-
const data = await response.json();
|
|
1937
1930
|
if (!isObject(data)) {
|
|
1938
1931
|
throw new Error("Invalid Executor delegation response");
|
|
1939
1932
|
}
|
|
@@ -1942,28 +1935,104 @@ var RestExecutorProvider = class {
|
|
|
1942
1935
|
coins: optionalArray(data.coins, "coins").map(parseCoin)
|
|
1943
1936
|
};
|
|
1944
1937
|
}
|
|
1938
|
+
async registerArtifact(document, options = {}) {
|
|
1939
|
+
const data = await this.postJson(
|
|
1940
|
+
"/v1/artifact",
|
|
1941
|
+
{ document: documentText(document) },
|
|
1942
|
+
"register Executor artifact",
|
|
1943
|
+
options.signal
|
|
1944
|
+
);
|
|
1945
|
+
return parseArtifact2(isObject(data) ? data.artifact : void 0);
|
|
1946
|
+
}
|
|
1947
|
+
async getArtifact(id, options = {}) {
|
|
1948
|
+
const data = await this.getJson(
|
|
1949
|
+
`/v1/artifact/${encodeURIComponent(id)}`,
|
|
1950
|
+
"get Executor artifact",
|
|
1951
|
+
options.signal
|
|
1952
|
+
);
|
|
1953
|
+
return parseArtifact2(isObject(data) ? data.artifact : void 0);
|
|
1954
|
+
}
|
|
1955
|
+
async registerTemplate(document, options = {}) {
|
|
1956
|
+
const data = await this.postJson(
|
|
1957
|
+
"/v1/template",
|
|
1958
|
+
{ document: documentText(document) },
|
|
1959
|
+
"register Executor template",
|
|
1960
|
+
options.signal
|
|
1961
|
+
);
|
|
1962
|
+
return parseTemplateDetails(isObject(data) ? data.template : void 0);
|
|
1963
|
+
}
|
|
1964
|
+
async getTemplate(id, options = {}) {
|
|
1965
|
+
const data = await this.getJson(
|
|
1966
|
+
`/v1/template/${encodeURIComponent(id)}`,
|
|
1967
|
+
"get Executor template",
|
|
1968
|
+
options.signal
|
|
1969
|
+
);
|
|
1970
|
+
return parseTemplateDetails(isObject(data) ? data.template : void 0);
|
|
1971
|
+
}
|
|
1972
|
+
async postJson(path, body, what, signal) {
|
|
1973
|
+
const url = this.endpoint(path);
|
|
1974
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(url, {
|
|
1975
|
+
method: "POST",
|
|
1976
|
+
headers: { "Content-Type": "application/json" },
|
|
1977
|
+
body: JSON.stringify(body),
|
|
1978
|
+
signal
|
|
1979
|
+
});
|
|
1980
|
+
if (!response.ok) {
|
|
1981
|
+
throw await notFoundFailure(response, what, await postErrorBody(url, response));
|
|
1982
|
+
}
|
|
1983
|
+
return response.json();
|
|
1984
|
+
}
|
|
1985
|
+
async getJson(path, what, signal) {
|
|
1986
|
+
const url = this.endpoint(path);
|
|
1987
|
+
const response = await chunk6J4GABF7_cjs.rateGate.runHttp(url, () => chunk6J4GABF7_cjs.baseFetch(url, { signal }));
|
|
1988
|
+
if (!response.ok) {
|
|
1989
|
+
throw await notFoundFailure(response, what);
|
|
1990
|
+
}
|
|
1991
|
+
return response.json();
|
|
1992
|
+
}
|
|
1945
1993
|
};
|
|
1946
|
-
async function
|
|
1994
|
+
async function notFoundFailure(response, what, text) {
|
|
1995
|
+
const body = text ?? await response.text();
|
|
1947
1996
|
return new ExecutorRequestError(
|
|
1948
|
-
`Failed to ${what} (${response.status}): ${
|
|
1997
|
+
`Failed to ${what} (${response.status}): ${body}`,
|
|
1998
|
+
response.status === 404 && grpcCode(body) !== 5 ? void 0 : response.status
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
async function failure(response, what, text) {
|
|
2002
|
+
return new ExecutorRequestError(
|
|
2003
|
+
`Failed to ${what} (${response.status}): ${text ?? await response.text()}`,
|
|
1949
2004
|
response.status
|
|
1950
2005
|
);
|
|
1951
2006
|
}
|
|
1952
|
-
function
|
|
2007
|
+
async function postErrorBody(url, response) {
|
|
2008
|
+
let body;
|
|
2009
|
+
try {
|
|
2010
|
+
body = await response.text();
|
|
2011
|
+
return body;
|
|
2012
|
+
} finally {
|
|
2013
|
+
if (response.status === 429 && (body === void 0 || grpcCode(body) !== 8)) {
|
|
2014
|
+
chunk6J4GABF7_cjs.rateGate.reportRateLimited(url, response.headers?.get("retry-after"));
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
function documentText(document) {
|
|
2019
|
+
return typeof document === "string" ? document : JSON.stringify(document);
|
|
2020
|
+
}
|
|
2021
|
+
function grpcCode(body) {
|
|
1953
2022
|
try {
|
|
1954
2023
|
const parsed = JSON.parse(body);
|
|
1955
|
-
return isObject(parsed)
|
|
2024
|
+
return isObject(parsed) ? parsed.code : void 0;
|
|
1956
2025
|
} catch {
|
|
1957
|
-
return
|
|
2026
|
+
return void 0;
|
|
1958
2027
|
}
|
|
1959
2028
|
}
|
|
1960
2029
|
function isObject(value) {
|
|
1961
2030
|
return typeof value === "object" && value !== null;
|
|
1962
2031
|
}
|
|
1963
|
-
function requiredString(object, key) {
|
|
2032
|
+
function requiredString(object, key, what = "info") {
|
|
1964
2033
|
const value = object[key];
|
|
1965
2034
|
if (typeof value !== "string" || value.length === 0) {
|
|
1966
|
-
throw new Error(`Invalid Executor
|
|
2035
|
+
throw new Error(`Invalid Executor ${what}: missing ${key}`);
|
|
1967
2036
|
}
|
|
1968
2037
|
return value;
|
|
1969
2038
|
}
|
|
@@ -2061,6 +2130,36 @@ function parseTemplate(value) {
|
|
|
2061
2130
|
}
|
|
2062
2131
|
return { id: value.id, status: typeof value.status === "string" ? value.status : "" };
|
|
2063
2132
|
}
|
|
2133
|
+
function parseTemplateDetails(value) {
|
|
2134
|
+
if (!isObject(value)) throw new Error("Invalid Executor template");
|
|
2135
|
+
const artifactIds = optionalArray(value.artifactIds, "artifactIds");
|
|
2136
|
+
if (artifactIds.some((id) => typeof id !== "string" || id.length === 0)) {
|
|
2137
|
+
throw new Error("Invalid Executor template: artifactIds are not strings");
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
id: requiredString(value, "id", "template"),
|
|
2141
|
+
status: requiredString(value, "status", "template"),
|
|
2142
|
+
document: requiredString(value, "document", "template"),
|
|
2143
|
+
artifactIds,
|
|
2144
|
+
params: optionalArray(value.params, "params").map((param) => {
|
|
2145
|
+
if (!isObject(param)) throw new Error("Invalid Executor template param");
|
|
2146
|
+
return {
|
|
2147
|
+
name: requiredString(param, "name", "template param"),
|
|
2148
|
+
type: requiredString(param, "type", "template param")
|
|
2149
|
+
};
|
|
2150
|
+
}),
|
|
2151
|
+
type: requiredString(value, "type", "template"),
|
|
2152
|
+
createdAt: parseOptionalInt64(value.createdAt, "createdAt")
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
function parseArtifact2(value) {
|
|
2156
|
+
if (!isObject(value)) throw new Error("Invalid Executor artifact");
|
|
2157
|
+
return {
|
|
2158
|
+
id: requiredString(value, "id", "artifact"),
|
|
2159
|
+
document: requiredString(value, "document", "artifact"),
|
|
2160
|
+
createdAt: parseOptionalInt64(value.createdAt, "createdAt")
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2064
2163
|
function parseExecutorInfo(value) {
|
|
2065
2164
|
if (!isObject(value)) throw new Error("Invalid Executor info");
|
|
2066
2165
|
const info = {
|
|
@@ -2073,6 +2172,10 @@ function parseExecutorInfo(value) {
|
|
|
2073
2172
|
decodeCompressed(info.cosignerPubkey, "cosignerPubkey");
|
|
2074
2173
|
decodeCompressed(info.serverPubkey, "serverPubkey");
|
|
2075
2174
|
decodeCompressed(info.emulatorPubkey, "emulatorPubkey");
|
|
2175
|
+
if (value.encryptionPubkey !== void 0 && value.encryptionPubkey !== "") {
|
|
2176
|
+
info.encryptionPubkey = requiredString(value, "encryptionPubkey");
|
|
2177
|
+
decodeCompressed(info.encryptionPubkey, "encryptionPubkey");
|
|
2178
|
+
}
|
|
2076
2179
|
return info;
|
|
2077
2180
|
}
|
|
2078
2181
|
function decodeCompressed(value, label) {
|
|
@@ -2208,9 +2311,9 @@ var EsploraProvider = class {
|
|
|
2208
2311
|
*/
|
|
2209
2312
|
addressWatches = /* @__PURE__ */ new Map();
|
|
2210
2313
|
async getCoins(address) {
|
|
2211
|
-
const response = await
|
|
2314
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
2212
2315
|
if (!response.ok) {
|
|
2213
|
-
throw new
|
|
2316
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to fetch UTXOs", response);
|
|
2214
2317
|
}
|
|
2215
2318
|
const coins = await response.json();
|
|
2216
2319
|
const bad = coins.find(
|
|
@@ -2222,13 +2325,13 @@ var EsploraProvider = class {
|
|
|
2222
2325
|
async getFeeRate() {
|
|
2223
2326
|
let url = `${this.baseUrl}/fee-estimates`;
|
|
2224
2327
|
let key = "1";
|
|
2225
|
-
let response = await
|
|
2328
|
+
let response = await chunk6J4GABF7_cjs.baseFetch(url);
|
|
2226
2329
|
if (response.status === 404) {
|
|
2227
2330
|
await response.body?.cancel().catch(() => {
|
|
2228
2331
|
});
|
|
2229
2332
|
url = `${this.baseUrl}/v1/fees/recommended`;
|
|
2230
2333
|
key = "fastestFee";
|
|
2231
|
-
response = await
|
|
2334
|
+
response = await chunk6J4GABF7_cjs.baseFetch(url);
|
|
2232
2335
|
}
|
|
2233
2336
|
if (response.status === 404) {
|
|
2234
2337
|
await response.body?.cancel().catch(() => {
|
|
@@ -2238,7 +2341,7 @@ var EsploraProvider = class {
|
|
|
2238
2341
|
if (!response.ok) {
|
|
2239
2342
|
await response.body?.cancel().catch(() => {
|
|
2240
2343
|
});
|
|
2241
|
-
throw new
|
|
2344
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to fetch fee rate", response);
|
|
2242
2345
|
}
|
|
2243
2346
|
const mediaType = response.headers.get("content-type")?.split(";", 1)[0].trim().toLowerCase();
|
|
2244
2347
|
if (mediaType === "text/html") {
|
|
@@ -2268,10 +2371,10 @@ var EsploraProvider = class {
|
|
|
2268
2371
|
}
|
|
2269
2372
|
}
|
|
2270
2373
|
async getTxOutspends(txid) {
|
|
2271
|
-
const response = await
|
|
2374
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
2272
2375
|
if (!response.ok) {
|
|
2273
2376
|
const error = await response.text().catch(() => void 0);
|
|
2274
|
-
throw new
|
|
2377
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to get transaction outspends", response, error);
|
|
2275
2378
|
}
|
|
2276
2379
|
return response.json();
|
|
2277
2380
|
}
|
|
@@ -2284,7 +2387,7 @@ var EsploraProvider = class {
|
|
|
2284
2387
|
const page = await this.getAddressTxs(
|
|
2285
2388
|
`${this.baseUrl}/address/${address}/txs/chain/${last}`
|
|
2286
2389
|
).catch((error) => {
|
|
2287
|
-
if (error instanceof
|
|
2390
|
+
if (error instanceof chunk6J4GABF7_cjs.HttpResponseError && error.status === 404) return [];
|
|
2288
2391
|
throw error;
|
|
2289
2392
|
});
|
|
2290
2393
|
const fresh = page.filter((tx) => !seen.has(tx.txid));
|
|
@@ -2295,26 +2398,26 @@ var EsploraProvider = class {
|
|
|
2295
2398
|
return txs;
|
|
2296
2399
|
}
|
|
2297
2400
|
async getAddressTxs(url) {
|
|
2298
|
-
const response = await
|
|
2401
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(url);
|
|
2299
2402
|
if (!response.ok) {
|
|
2300
2403
|
const error = await response.text().catch(() => void 0);
|
|
2301
|
-
throw new
|
|
2404
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to get transactions", response, error);
|
|
2302
2405
|
}
|
|
2303
2406
|
return response.json();
|
|
2304
2407
|
}
|
|
2305
2408
|
/** Orders of magnitude smaller than `/address/{addr}/txs`: the polling fallback's probe. */
|
|
2306
2409
|
async getAddressStats(address) {
|
|
2307
|
-
const response = await
|
|
2410
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
|
|
2308
2411
|
if (!response.ok) {
|
|
2309
|
-
throw new
|
|
2412
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to get address stats", response);
|
|
2310
2413
|
}
|
|
2311
2414
|
return response.json();
|
|
2312
2415
|
}
|
|
2313
2416
|
async getRawTransaction(txid) {
|
|
2314
|
-
const response = await
|
|
2417
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
2315
2418
|
if (!response.ok) {
|
|
2316
2419
|
const error = await response.text().catch(() => void 0);
|
|
2317
|
-
throw new
|
|
2420
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError(`Failed to get raw transaction ${txid}`, response, error);
|
|
2318
2421
|
}
|
|
2319
2422
|
const raw = base.hex.decode((await response.text()).trim());
|
|
2320
2423
|
const { id } = btcSigner.Transaction.fromRaw(raw, {
|
|
@@ -2329,17 +2432,17 @@ var EsploraProvider = class {
|
|
|
2329
2432
|
return raw;
|
|
2330
2433
|
}
|
|
2331
2434
|
async getTxStatus(txid) {
|
|
2332
|
-
const txresponse = await
|
|
2435
|
+
const txresponse = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
2333
2436
|
if (!txresponse.ok) {
|
|
2334
|
-
throw new
|
|
2437
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError(`Failed to get transaction ${txid}`, txresponse);
|
|
2335
2438
|
}
|
|
2336
2439
|
const tx = await txresponse.json();
|
|
2337
2440
|
if (!tx.status.confirmed) {
|
|
2338
2441
|
return { confirmed: false };
|
|
2339
2442
|
}
|
|
2340
|
-
const response = await
|
|
2443
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
2341
2444
|
if (!response.ok) {
|
|
2342
|
-
throw new
|
|
2445
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to get transaction status", response);
|
|
2343
2446
|
}
|
|
2344
2447
|
const data = await response.json();
|
|
2345
2448
|
if (!data.confirmed) {
|
|
@@ -2619,12 +2722,12 @@ var EsploraProvider = class {
|
|
|
2619
2722
|
return { subscribers, teardown, started };
|
|
2620
2723
|
}
|
|
2621
2724
|
async getChainTip() {
|
|
2622
|
-
let tipBlocks = await
|
|
2725
|
+
let tipBlocks = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2623
2726
|
if (tipBlocks.status === 404) {
|
|
2624
|
-
tipBlocks = await
|
|
2727
|
+
tipBlocks = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
|
|
2625
2728
|
}
|
|
2626
2729
|
if (!tipBlocks.ok) {
|
|
2627
|
-
throw new
|
|
2730
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to get chain tip", tipBlocks);
|
|
2628
2731
|
}
|
|
2629
2732
|
const tip = await tipBlocks.json();
|
|
2630
2733
|
if (!isValidBlocksTip(tip)) {
|
|
@@ -2645,18 +2748,18 @@ var EsploraProvider = class {
|
|
|
2645
2748
|
if (!Number.isInteger(height) || height < 0) {
|
|
2646
2749
|
throw new Error(`Invalid block height for median-time-past: ${height}`);
|
|
2647
2750
|
}
|
|
2648
|
-
const hashResponse = await
|
|
2751
|
+
const hashResponse = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/block-height/${height}`);
|
|
2649
2752
|
if (!hashResponse.ok) {
|
|
2650
|
-
throw new
|
|
2753
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError(
|
|
2651
2754
|
`Failed to get block hash at height ${height}`,
|
|
2652
2755
|
hashResponse
|
|
2653
2756
|
);
|
|
2654
2757
|
}
|
|
2655
2758
|
const hash = (await hashResponse.text()).trim();
|
|
2656
2759
|
if (!hash) throw new Error(`No block hash returned at height ${height}`);
|
|
2657
|
-
const blockResponse = await
|
|
2760
|
+
const blockResponse = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/block/${hash}`);
|
|
2658
2761
|
if (!blockResponse.ok) {
|
|
2659
|
-
throw new
|
|
2762
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError(`Failed to get block ${hash}`, blockResponse);
|
|
2660
2763
|
}
|
|
2661
2764
|
const block = await blockResponse.json();
|
|
2662
2765
|
if (!block || typeof block !== "object" || typeof block.mediantime !== "number" || !Number.isFinite(block.mediantime)) {
|
|
@@ -2665,7 +2768,7 @@ var EsploraProvider = class {
|
|
|
2665
2768
|
return block.mediantime;
|
|
2666
2769
|
}
|
|
2667
2770
|
async broadcastPackage(parent, child) {
|
|
2668
|
-
const response = await
|
|
2771
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
2669
2772
|
method: "POST",
|
|
2670
2773
|
headers: {
|
|
2671
2774
|
"Content-Type": "application/json"
|
|
@@ -2674,14 +2777,14 @@ var EsploraProvider = class {
|
|
|
2674
2777
|
});
|
|
2675
2778
|
if (!response.ok) {
|
|
2676
2779
|
const error = await response.text().catch(() => void 0);
|
|
2677
|
-
throw new
|
|
2780
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to broadcast package", response, error);
|
|
2678
2781
|
}
|
|
2679
2782
|
const result = await response.json();
|
|
2680
2783
|
assertPackageAccepted(result);
|
|
2681
2784
|
return result;
|
|
2682
2785
|
}
|
|
2683
2786
|
async broadcastTx(tx) {
|
|
2684
|
-
const response = await
|
|
2787
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
2685
2788
|
method: "POST",
|
|
2686
2789
|
headers: {
|
|
2687
2790
|
"Content-Type": "text/plain"
|
|
@@ -2690,7 +2793,7 @@ var EsploraProvider = class {
|
|
|
2690
2793
|
});
|
|
2691
2794
|
if (!response.ok) {
|
|
2692
2795
|
const error = await response.text().catch(() => void 0);
|
|
2693
|
-
throw new
|
|
2796
|
+
throw new chunk6J4GABF7_cjs.HttpResponseError("Failed to broadcast transaction", response, error);
|
|
2694
2797
|
}
|
|
2695
2798
|
return response.text();
|
|
2696
2799
|
}
|
|
@@ -2854,7 +2957,7 @@ function findP2AOutput(tx) {
|
|
|
2854
2957
|
var CHILD_DUST_AMOUNT = 546;
|
|
2855
2958
|
function buildAnchorChild(params) {
|
|
2856
2959
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2857
|
-
const child = new
|
|
2960
|
+
const child = new chunk6J4GABF7_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2858
2961
|
const anchor = findP2AOutput(parent);
|
|
2859
2962
|
child.addInput(anchor);
|
|
2860
2963
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
@@ -2903,7 +3006,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
2903
3006
|
);
|
|
2904
3007
|
}
|
|
2905
3008
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
2906
|
-
const tx = new
|
|
3009
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({
|
|
2907
3010
|
version: 3,
|
|
2908
3011
|
lockTime: txLocktime
|
|
2909
3012
|
});
|
|
@@ -2930,7 +3033,7 @@ function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
|
|
|
2930
3033
|
connectorsGraph.validate();
|
|
2931
3034
|
if (connectorsGraph.root.inputsLength !== 1) throw ErrNumberOfInputs;
|
|
2932
3035
|
const rootInput = connectorsGraph.root.getInput(0);
|
|
2933
|
-
const settlementTx =
|
|
3036
|
+
const settlementTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(settlementTxB64));
|
|
2934
3037
|
if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
|
|
2935
3038
|
throw ErrInvalidSettlementTxOutputs;
|
|
2936
3039
|
const expectedRootTxid = settlementTx.id;
|
|
@@ -2987,7 +3090,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
2987
3090
|
}
|
|
2988
3091
|
}
|
|
2989
3092
|
function cosignersOutputScript(tx, sweepTapTreeRoot) {
|
|
2990
|
-
const cosigners =
|
|
3093
|
+
const cosigners = chunk6J4GABF7_cjs.getArkPsbtFields(tx, 0, chunk6J4GABF7_cjs.CosignerPublicKey);
|
|
2991
3094
|
if (cosigners.length === 0) throw ErrMissingCosignersPublicKeys;
|
|
2992
3095
|
const keys = cosigners.map((c) => c.key);
|
|
2993
3096
|
const { finalKey } = aggregateKeys(keys, true, { taprootTweak: sweepTapTreeRoot });
|
|
@@ -3037,7 +3140,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
3037
3140
|
return new _EmulatorPacket(entries);
|
|
3038
3141
|
}
|
|
3039
3142
|
static fromBytes(data) {
|
|
3040
|
-
const reader = new
|
|
3143
|
+
const reader = new chunk7LPT6AYH_cjs.BufferReader(data);
|
|
3041
3144
|
const entryCount = reader.readCompactSize();
|
|
3042
3145
|
const entries = [];
|
|
3043
3146
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -3055,7 +3158,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
3055
3158
|
return _EmulatorPacket.PACKET_TYPE;
|
|
3056
3159
|
}
|
|
3057
3160
|
serialize() {
|
|
3058
|
-
const writer = new
|
|
3161
|
+
const writer = new chunk7LPT6AYH_cjs.BufferWriter();
|
|
3059
3162
|
writer.writeCompactSize(this.entries.length);
|
|
3060
3163
|
for (const entry of this.entries) {
|
|
3061
3164
|
writer.writeUint16LE(entry.vin);
|
|
@@ -3142,7 +3245,7 @@ var Extension = class _Extension {
|
|
|
3142
3245
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
3143
3246
|
);
|
|
3144
3247
|
}
|
|
3145
|
-
const reader = new
|
|
3248
|
+
const reader = new chunk7LPT6AYH_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
3146
3249
|
const packets = [];
|
|
3147
3250
|
while (reader.remaining() > 0) {
|
|
3148
3251
|
const packetType = reader.readByte();
|
|
@@ -3215,7 +3318,7 @@ var Extension = class _Extension {
|
|
|
3215
3318
|
* getAssetPacket returns the embedded Packet, or null if not present.
|
|
3216
3319
|
*/
|
|
3217
3320
|
getAssetPacket() {
|
|
3218
|
-
return this.packets.find((p) => p instanceof
|
|
3321
|
+
return this.packets.find((p) => p instanceof chunk7LPT6AYH_cjs.Packet) ?? null;
|
|
3219
3322
|
}
|
|
3220
3323
|
/**
|
|
3221
3324
|
* getEmulatorPacket returns the embedded EmulatorPacket, or null if not present.
|
|
@@ -3239,8 +3342,8 @@ var Extension = class _Extension {
|
|
|
3239
3342
|
};
|
|
3240
3343
|
function parsePacket(packetType, data) {
|
|
3241
3344
|
switch (packetType) {
|
|
3242
|
-
case
|
|
3243
|
-
return
|
|
3345
|
+
case chunk7LPT6AYH_cjs.Packet.PACKET_TYPE:
|
|
3346
|
+
return chunk7LPT6AYH_cjs.Packet.fromBytes(data);
|
|
3244
3347
|
case EmulatorPacket.PACKET_TYPE:
|
|
3245
3348
|
return EmulatorPacket.fromBytes(data);
|
|
3246
3349
|
default:
|
|
@@ -3287,22 +3390,22 @@ function buildOpReturnScript(data) {
|
|
|
3287
3390
|
}
|
|
3288
3391
|
return script;
|
|
3289
3392
|
}
|
|
3290
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
3291
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
3393
|
+
var ErrOffchainOutputNotFound = (address) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
3394
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3292
3395
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
3293
3396
|
);
|
|
3294
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
3295
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
3397
|
+
var ErrAssetGroupNotFound = (assetId) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
3398
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3296
3399
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
3297
3400
|
);
|
|
3298
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
3299
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
3401
|
+
var ErrOnchainOutputNotFound = (address) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
3402
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3300
3403
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
3301
3404
|
);
|
|
3302
|
-
var ErrIntentOutputNotFound = (index, kind) => new
|
|
3405
|
+
var ErrIntentOutputNotFound = (index, kind) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3303
3406
|
`${kind} output ${index} of the proof is not present in what the server built`
|
|
3304
3407
|
);
|
|
3305
|
-
var ErrUnvalidatedIntentOutput = (index) => new
|
|
3408
|
+
var ErrUnvalidatedIntentOutput = (index) => new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3306
3409
|
`offchain output ${index} of the proof cannot be validated: virtual output tree signing did not run`
|
|
3307
3410
|
);
|
|
3308
3411
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
@@ -3311,7 +3414,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
3311
3414
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
3312
3415
|
if (!validatedCommitmentTxid) return;
|
|
3313
3416
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
3314
|
-
throw new
|
|
3417
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
3315
3418
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
3316
3419
|
);
|
|
3317
3420
|
}
|
|
@@ -3342,7 +3445,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
3342
3445
|
}
|
|
3343
3446
|
}
|
|
3344
3447
|
function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
|
|
3345
|
-
const proof =
|
|
3448
|
+
const proof = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
|
|
3346
3449
|
const onchain = new Set(onchainOutputIndexes);
|
|
3347
3450
|
const declared = [];
|
|
3348
3451
|
for (let i = 0; i < proof.outputsLength; i++) {
|
|
@@ -3634,7 +3737,7 @@ function assetMintResolver() {
|
|
|
3634
3737
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
3635
3738
|
const minted = tx.assets.filter((a) => {
|
|
3636
3739
|
try {
|
|
3637
|
-
return base.hex.encode(
|
|
3740
|
+
return base.hex.encode(chunk7LPT6AYH_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
3638
3741
|
} catch {
|
|
3639
3742
|
return false;
|
|
3640
3743
|
}
|
|
@@ -3711,7 +3814,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3711
3814
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
3712
3815
|
inputsByAssetId.set(asset.assetId, [
|
|
3713
3816
|
...existing ?? [],
|
|
3714
|
-
|
|
3817
|
+
chunk7LPT6AYH_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
3715
3818
|
]);
|
|
3716
3819
|
}
|
|
3717
3820
|
}
|
|
@@ -3723,7 +3826,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3723
3826
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3724
3827
|
outputsByAssetId.set(asset.assetId, [
|
|
3725
3828
|
...existing ?? [],
|
|
3726
|
-
|
|
3829
|
+
chunk7LPT6AYH_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3727
3830
|
]);
|
|
3728
3831
|
}
|
|
3729
3832
|
}
|
|
@@ -3734,7 +3837,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3734
3837
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3735
3838
|
outputsByAssetId.set(asset.assetId, [
|
|
3736
3839
|
...existing ?? [],
|
|
3737
|
-
|
|
3840
|
+
chunk7LPT6AYH_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3738
3841
|
]);
|
|
3739
3842
|
}
|
|
3740
3843
|
}
|
|
@@ -3743,11 +3846,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3743
3846
|
for (const assetIdStr of allAssetIds) {
|
|
3744
3847
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
3745
3848
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
3746
|
-
const assetId =
|
|
3747
|
-
const group =
|
|
3849
|
+
const assetId = chunk7LPT6AYH_cjs.AssetId.fromString(assetIdStr);
|
|
3850
|
+
const group = chunk7LPT6AYH_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3748
3851
|
groups.push(group);
|
|
3749
3852
|
}
|
|
3750
|
-
return
|
|
3853
|
+
return chunk7LPT6AYH_cjs.Packet.create(groups);
|
|
3751
3854
|
}
|
|
3752
3855
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
3753
3856
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -3819,7 +3922,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3819
3922
|
};
|
|
3820
3923
|
}
|
|
3821
3924
|
function deriveContractTapscripts(contract) {
|
|
3822
|
-
const handler =
|
|
3925
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
3823
3926
|
if (!handler) {
|
|
3824
3927
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3825
3928
|
}
|
|
@@ -3962,6 +4065,9 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
3962
4065
|
if (amount <= 0) {
|
|
3963
4066
|
throw new Error("Amount must be positive");
|
|
3964
4067
|
}
|
|
4068
|
+
if ((recipient.assets?.length ?? 0) > 0 && amount < dustAmount) {
|
|
4069
|
+
throw new Error(`Asset recipient amount ${amount} is below dust ${dustAmount}`);
|
|
4070
|
+
}
|
|
3965
4071
|
if (recipient.tapTree) {
|
|
3966
4072
|
assertTapTreeDerivesAddress(recipient.address, recipient.tapTree, address);
|
|
3967
4073
|
}
|
|
@@ -4104,7 +4210,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
4104
4210
|
feeRate,
|
|
4105
4211
|
params.address
|
|
4106
4212
|
);
|
|
4107
|
-
let tx = new
|
|
4213
|
+
let tx = new chunk6J4GABF7_cjs.Transaction();
|
|
4108
4214
|
for (const input of inputs) {
|
|
4109
4215
|
tx.addInput({
|
|
4110
4216
|
txid: input.txid,
|
|
@@ -4167,7 +4273,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
4167
4273
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
4168
4274
|
*/
|
|
4169
4275
|
async bumpAnchor(parentHex, feeRate) {
|
|
4170
|
-
const parent =
|
|
4276
|
+
const parent = chunk6J4GABF7_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
4171
4277
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
4172
4278
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
4173
4279
|
return [parent.hex, child.hex];
|
|
@@ -4309,14 +4415,14 @@ var toTimelock = (value) => ({
|
|
|
4309
4415
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
4310
4416
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
4311
4417
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
4312
|
-
throw new
|
|
4418
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4313
4419
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
4314
4420
|
);
|
|
4315
4421
|
}
|
|
4316
4422
|
const seconds = toSeconds(timelock);
|
|
4317
4423
|
if (seconds < policy.minSeconds) {
|
|
4318
4424
|
const remedy = overrideOption ? `; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it` : "";
|
|
4319
|
-
throw new
|
|
4425
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4320
4426
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor${remedy}`
|
|
4321
4427
|
);
|
|
4322
4428
|
}
|
|
@@ -4337,7 +4443,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
4337
4443
|
}
|
|
4338
4444
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
4339
4445
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
4340
|
-
throw new
|
|
4446
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4341
4447
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
4342
4448
|
);
|
|
4343
4449
|
}
|
|
@@ -4348,19 +4454,19 @@ function assertValidServerUnrollScript(checkpointTapscript, network, advertisedF
|
|
|
4348
4454
|
try {
|
|
4349
4455
|
script = chunk6TBTL42M_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
4350
4456
|
} catch (e) {
|
|
4351
|
-
throw new
|
|
4457
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4352
4458
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
4353
4459
|
);
|
|
4354
4460
|
}
|
|
4355
4461
|
if (advertisedForfeitPubkey !== void 0) {
|
|
4356
4462
|
const { pubkeys } = script.params;
|
|
4357
4463
|
if (pubkeys.length !== 1) {
|
|
4358
|
-
throw new
|
|
4464
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4359
4465
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
4360
4466
|
);
|
|
4361
4467
|
}
|
|
4362
4468
|
if (!utils_js.equalBytes(pubkeys[0], advertisedForfeitPubkey)) {
|
|
4363
|
-
throw new
|
|
4469
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4364
4470
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(advertisedForfeitPubkey)}`
|
|
4365
4471
|
);
|
|
4366
4472
|
}
|
|
@@ -4415,7 +4521,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
4415
4521
|
}
|
|
4416
4522
|
}
|
|
4417
4523
|
}
|
|
4418
|
-
const tx = new
|
|
4524
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({
|
|
4419
4525
|
version: 3,
|
|
4420
4526
|
lockTime: Number(lockTime)
|
|
4421
4527
|
});
|
|
@@ -4430,7 +4536,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
4430
4536
|
},
|
|
4431
4537
|
tapLeafScript: [input.tapLeafScript]
|
|
4432
4538
|
});
|
|
4433
|
-
|
|
4539
|
+
chunk6J4GABF7_cjs.setArkPsbtField(tx, i, chunk6J4GABF7_cjs.VtxoTaprootTree, input.tapTree);
|
|
4434
4540
|
}
|
|
4435
4541
|
for (const output of outputs) {
|
|
4436
4542
|
tx.addOutput(output);
|
|
@@ -4576,7 +4682,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
4576
4682
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
4577
4683
|
const sig = signature.subarray(0, 64);
|
|
4578
4684
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
4579
|
-
const sighashName =
|
|
4685
|
+
const sighashName = chunk6J4GABF7_cjs.formatSighash(sighashType);
|
|
4580
4686
|
throw new Error(
|
|
4581
4687
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
4582
4688
|
);
|
|
@@ -4658,16 +4764,16 @@ function isValidArkAddress(address) {
|
|
|
4658
4764
|
}
|
|
4659
4765
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
4660
4766
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
4661
|
-
throw new
|
|
4767
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4662
4768
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
4663
4769
|
);
|
|
4664
4770
|
}
|
|
4665
4771
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
4666
4772
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
4667
|
-
const server =
|
|
4773
|
+
const server = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
4668
4774
|
const local = byTxid.get(server.id);
|
|
4669
4775
|
if (!local) {
|
|
4670
|
-
throw new
|
|
4776
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4671
4777
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
4672
4778
|
);
|
|
4673
4779
|
}
|
|
@@ -4677,14 +4783,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
4677
4783
|
}
|
|
4678
4784
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
4679
4785
|
if (response.arkTxid !== signedArkTx.id) {
|
|
4680
|
-
throw new
|
|
4786
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4681
4787
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
4682
4788
|
);
|
|
4683
4789
|
}
|
|
4684
4790
|
if (response.finalArkTx === void 0) return;
|
|
4685
|
-
const finalTxid =
|
|
4791
|
+
const finalTxid = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
4686
4792
|
if (finalTxid !== signedArkTx.id) {
|
|
4687
|
-
throw new
|
|
4793
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4688
4794
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
4689
4795
|
);
|
|
4690
4796
|
}
|
|
@@ -4703,13 +4809,13 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
4703
4809
|
(key) => base.hex.encode(chunk6TBTL42M_cjs.toXOnly(key, "leaf key"))
|
|
4704
4810
|
);
|
|
4705
4811
|
} catch (error) {
|
|
4706
|
-
throw new
|
|
4812
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4707
4813
|
`${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
|
|
4708
4814
|
);
|
|
4709
4815
|
}
|
|
4710
4816
|
const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
|
|
4711
4817
|
if (!signer) {
|
|
4712
|
-
throw new
|
|
4818
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4713
4819
|
`${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
|
|
4714
4820
|
);
|
|
4715
4821
|
}
|
|
@@ -4726,7 +4832,7 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
4726
4832
|
payment_js.tapLeafHash(script)
|
|
4727
4833
|
);
|
|
4728
4834
|
} catch (error) {
|
|
4729
|
-
throw new
|
|
4835
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4730
4836
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
4731
4837
|
);
|
|
4732
4838
|
}
|
|
@@ -4736,20 +4842,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
4736
4842
|
const matched = [];
|
|
4737
4843
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
4738
4844
|
if (checkpoint.inputsLength !== 1) {
|
|
4739
|
-
throw new
|
|
4845
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4740
4846
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
4741
4847
|
);
|
|
4742
4848
|
}
|
|
4743
4849
|
const spent = checkpoint.getInput(0);
|
|
4744
4850
|
if (!spent.txid || spent.index === void 0) {
|
|
4745
|
-
throw new
|
|
4851
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4746
4852
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
4747
4853
|
);
|
|
4748
4854
|
}
|
|
4749
4855
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
4750
4856
|
const input = byOutpoint.get(outpoint);
|
|
4751
4857
|
if (!input) {
|
|
4752
|
-
throw new
|
|
4858
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4753
4859
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
4754
4860
|
);
|
|
4755
4861
|
}
|
|
@@ -4762,7 +4868,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
4762
4868
|
}
|
|
4763
4869
|
}
|
|
4764
4870
|
if (!rebuilt) {
|
|
4765
|
-
throw new
|
|
4871
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4766
4872
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
4767
4873
|
);
|
|
4768
4874
|
}
|
|
@@ -4779,7 +4885,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4779
4885
|
const outpoint = input.txid && input.index !== void 0 ? `${base.hex.encode(input.txid)}:${input.index}` : void 0;
|
|
4780
4886
|
const local = outpoint ? byOutpoint.get(outpoint) : void 0;
|
|
4781
4887
|
if (!local) {
|
|
4782
|
-
throw new
|
|
4888
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4783
4889
|
`${context}: ark tx input ${index} spends ${outpoint ?? "no outpoint"}, which is not a checkpoint of this tx`
|
|
4784
4890
|
);
|
|
4785
4891
|
}
|
|
@@ -4798,7 +4904,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4798
4904
|
}
|
|
4799
4905
|
const unspent = checkpoints.find((checkpoint) => !spent.includes(checkpoint));
|
|
4800
4906
|
if (unspent) {
|
|
4801
|
-
throw new
|
|
4907
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4802
4908
|
`${context}: ark tx does not spend checkpoint ${unspent.txid}`
|
|
4803
4909
|
);
|
|
4804
4910
|
}
|
|
@@ -4810,7 +4916,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4810
4916
|
try {
|
|
4811
4917
|
verifyTapscriptSignatures(probe, index, keys, void 0, void 0, payment_js.tapLeafHash(leaf));
|
|
4812
4918
|
} catch (error) {
|
|
4813
|
-
throw new
|
|
4919
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4814
4920
|
`${context}: ark tx input ${index} is not fully signed on the leaf spending ${local.txid} (${error instanceof Error ? error.message : String(error)})`
|
|
4815
4921
|
);
|
|
4816
4922
|
}
|
|
@@ -4839,9 +4945,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
4839
4945
|
if (!oneShot) {
|
|
4840
4946
|
matched.forEach(({ server }, index) => {
|
|
4841
4947
|
try {
|
|
4842
|
-
|
|
4948
|
+
chunk6J4GABF7_cjs.assertAllowedSighashTypes(server);
|
|
4843
4949
|
} catch (error) {
|
|
4844
|
-
throw new
|
|
4950
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4845
4951
|
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
4846
4952
|
);
|
|
4847
4953
|
}
|
|
@@ -4850,11 +4956,11 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
4850
4956
|
const verify = options?.verifyServerSignatures;
|
|
4851
4957
|
if (verify) {
|
|
4852
4958
|
if (response.finalArkTx === void 0) {
|
|
4853
|
-
throw new
|
|
4959
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
4854
4960
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
4855
4961
|
);
|
|
4856
4962
|
}
|
|
4857
|
-
const finalArkTx =
|
|
4963
|
+
const finalArkTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
4858
4964
|
const serverPubkeys = new Set(
|
|
4859
4965
|
[verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
|
|
4860
4966
|
(key) => base.hex.encode(chunk6TBTL42M_cjs.toXOnly(key, "server key"))
|
|
@@ -4905,19 +5011,19 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
4905
5011
|
return result;
|
|
4906
5012
|
}
|
|
4907
5013
|
function carryConditionWitness(ours, server) {
|
|
4908
|
-
if (
|
|
4909
|
-
const [witness] =
|
|
4910
|
-
if (witness)
|
|
5014
|
+
if (chunk6J4GABF7_cjs.getArkPsbtFields(server, 0, chunk6J4GABF7_cjs.ConditionWitness).length > 0) return;
|
|
5015
|
+
const [witness] = chunk6J4GABF7_cjs.getArkPsbtFields(ours, 0, chunk6J4GABF7_cjs.ConditionWitness);
|
|
5016
|
+
if (witness) chunk6J4GABF7_cjs.setArkPsbtField(server, 0, chunk6J4GABF7_cjs.ConditionWitness, witness);
|
|
4911
5017
|
}
|
|
4912
5018
|
function withArkInputWitness(checkpoint, signedArkTx) {
|
|
4913
|
-
if (
|
|
5019
|
+
if (chunk6J4GABF7_cjs.getArkPsbtFields(checkpoint, 0, chunk6J4GABF7_cjs.ConditionWitness).length > 0) return checkpoint;
|
|
4914
5020
|
for (let i = 0; i < signedArkTx.inputsLength; i++) {
|
|
4915
5021
|
const { txid } = signedArkTx.getInput(i);
|
|
4916
5022
|
if (!txid || base.hex.encode(txid) !== checkpoint.id) continue;
|
|
4917
|
-
const [witness] =
|
|
5023
|
+
const [witness] = chunk6J4GABF7_cjs.getArkPsbtFields(signedArkTx, i, chunk6J4GABF7_cjs.ConditionWitness);
|
|
4918
5024
|
if (!witness) return checkpoint;
|
|
4919
5025
|
const carried = checkpoint.clone();
|
|
4920
|
-
|
|
5026
|
+
chunk6J4GABF7_cjs.setArkPsbtField(carried, 0, chunk6J4GABF7_cjs.ConditionWitness, witness);
|
|
4921
5027
|
return carried;
|
|
4922
5028
|
}
|
|
4923
5029
|
return checkpoint;
|
|
@@ -4958,7 +5064,7 @@ async function submitViaEmulator(emulator, offchainTx, signer, opts) {
|
|
|
4958
5064
|
base.base64.encode(arkTx.toPSBT()),
|
|
4959
5065
|
checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
4960
5066
|
);
|
|
4961
|
-
const txid =
|
|
5067
|
+
const txid = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(res.signedArkTx)).id;
|
|
4962
5068
|
assertSubmittedArkTxid({ arkTxid: txid }, arkTx, "emulator submitTx");
|
|
4963
5069
|
matchServerCheckpoints(res.signedCheckpointTxs, checkpoints, "emulator submitTx");
|
|
4964
5070
|
return { txid, signedArkTx: res.signedArkTx, signedCheckpointTxs: res.signedCheckpointTxs };
|
|
@@ -4967,12 +5073,12 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
4967
5073
|
return {
|
|
4968
5074
|
...identity,
|
|
4969
5075
|
sign: async (tx, inputIndexes) => {
|
|
4970
|
-
const signed =
|
|
5076
|
+
const signed = chunk6J4GABF7_cjs.Transaction.fromPSBT(
|
|
4971
5077
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
4972
5078
|
);
|
|
4973
5079
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
4974
5080
|
for (const index of indexes) {
|
|
4975
|
-
|
|
5081
|
+
chunk6J4GABF7_cjs.setArkPsbtField(signed, index, chunk6J4GABF7_cjs.ConditionWitness, [preimage]);
|
|
4976
5082
|
}
|
|
4977
5083
|
return signed;
|
|
4978
5084
|
}
|
|
@@ -4981,7 +5087,7 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
4981
5087
|
|
|
4982
5088
|
// src/contracts/scope.ts
|
|
4983
5089
|
function scopeOf(contract) {
|
|
4984
|
-
return contract.scope ??
|
|
5090
|
+
return contract.scope ?? chunkXZHTYYW5_cjs.contractHandlers.get(contract.type)?.defaultScope ?? "offchain";
|
|
4985
5091
|
}
|
|
4986
5092
|
function isOnchainScoped(contract) {
|
|
4987
5093
|
return scopeOf(contract) !== "offchain";
|
|
@@ -5058,9 +5164,9 @@ async function collectScriptVtxos(repository, script, options) {
|
|
|
5058
5164
|
return [...byOutpoint.values()].map((row) => row.vtxo);
|
|
5059
5165
|
}
|
|
5060
5166
|
function unspentScriptVtxos(rows, copies) {
|
|
5061
|
-
const spent = copies.filter((copy) =>
|
|
5167
|
+
const spent = copies.filter((copy) => chunk6J4GABF7_cjs.isVtxoSpent(copy.vtxo));
|
|
5062
5168
|
return rows.filter(
|
|
5063
|
-
(row) => !
|
|
5169
|
+
(row) => !chunk6J4GABF7_cjs.isVtxoSpent(row.vtxo) && !spent.some(
|
|
5064
5170
|
(copy) => copy.address !== row.address && copy.vtxo.txid === row.vtxo.txid && copy.vtxo.vout === row.vtxo.vout && shouldReplaceScriptVtxo(row, copy)
|
|
5065
5171
|
)
|
|
5066
5172
|
);
|
|
@@ -5131,8 +5237,8 @@ function checkSaveVtxosForScript(backend, key, vtxos) {
|
|
|
5131
5237
|
}
|
|
5132
5238
|
async function getVtxosForContract(repo, contract, options) {
|
|
5133
5239
|
const vtxos = repo.getVtxosForScriptPage ? await collectScriptVtxos(repo, contract.script, options) : filterVtxosForScript(await collectVtxos(repo, contract.address), contract.script);
|
|
5134
|
-
const normalized = vtxos.map(
|
|
5135
|
-
return options?.unspentOnly ? normalized.filter((vtxo) => !
|
|
5240
|
+
const normalized = vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
5241
|
+
return options?.unspentOnly ? normalized.filter((vtxo) => !chunk6J4GABF7_cjs.isVtxoSpent(vtxo)) : normalized;
|
|
5136
5242
|
}
|
|
5137
5243
|
async function hasVtxosForContract(repo, contract) {
|
|
5138
5244
|
if (repo.getVtxosForScriptPage) {
|
|
@@ -5214,7 +5320,7 @@ async function saveVtxosForContract(repo, contract, vtxos) {
|
|
|
5214
5320
|
// src/contracts/onchainCoins.ts
|
|
5215
5321
|
var MIGRATED_KEY = "legacyUtxosMigrated";
|
|
5216
5322
|
function createScript(contract) {
|
|
5217
|
-
const handler =
|
|
5323
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
5218
5324
|
if (!handler) throw new Error(`No handler for contract type '${contract.type}'`);
|
|
5219
5325
|
return handler.createScript(contract.params);
|
|
5220
5326
|
}
|
|
@@ -5273,7 +5379,7 @@ async function migrateLegacyUtxos(deps) {
|
|
|
5273
5379
|
let migrated = 0;
|
|
5274
5380
|
for (const contract of await collectContracts(contractRepository)) {
|
|
5275
5381
|
if (!isOnchainScoped(contract)) continue;
|
|
5276
|
-
if (!
|
|
5382
|
+
if (!chunkXZHTYYW5_cjs.contractHandlers.has(contract.type)) {
|
|
5277
5383
|
console.warn("Skipping legacy utxos of a contract with no handler", contract.type);
|
|
5278
5384
|
continue;
|
|
5279
5385
|
}
|
|
@@ -5299,7 +5405,7 @@ var DEFAULT_COSIGN_MARGIN_BLOCKS = 6;
|
|
|
5299
5405
|
var MAX_COSIGN_INPUTS = 64;
|
|
5300
5406
|
var ONCHAIN_RENEW_WINDOW_BLOCKS = 144;
|
|
5301
5407
|
function exitCsvOf(contract) {
|
|
5302
|
-
const sequence =
|
|
5408
|
+
const sequence = chunkXZHTYYW5_cjs.exitSequence(contract);
|
|
5303
5409
|
return sequence === void 0 ? void 0 : chunk6TBTL42M_cjs.sequenceToTimelock(sequence);
|
|
5304
5410
|
}
|
|
5305
5411
|
var ONCHAIN_COSIGN_PREFLIGHT_PREFIX = "Onchain cosign preflight failed: ";
|
|
@@ -5317,7 +5423,7 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
|
|
|
5317
5423
|
tx.updateInput(index, { tapLeafScript: void 0, tapScriptSig: void 0 }, true);
|
|
5318
5424
|
}
|
|
5319
5425
|
const kept = unknown?.filter(
|
|
5320
|
-
(u) =>
|
|
5426
|
+
(u) => chunk6J4GABF7_cjs.VtxoTaprootTree.decode(u) === null && chunk6J4GABF7_cjs.ConditionWitness.decode(u) === null
|
|
5321
5427
|
);
|
|
5322
5428
|
if (kept && kept.length !== unknown.length) {
|
|
5323
5429
|
tx.updateInput(index, { unknown: void 0 }, true);
|
|
@@ -5328,9 +5434,9 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
|
|
|
5328
5434
|
tapLeafScript: [path.leaf],
|
|
5329
5435
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
5330
5436
|
});
|
|
5331
|
-
|
|
5437
|
+
chunk6J4GABF7_cjs.setArkPsbtField(tx, index, chunk6J4GABF7_cjs.VtxoTaprootTree, tapTree);
|
|
5332
5438
|
if (path.extraWitness?.length) {
|
|
5333
|
-
|
|
5439
|
+
chunk6J4GABF7_cjs.setArkPsbtField(tx, index, chunk6J4GABF7_cjs.ConditionWitness, path.extraWitness);
|
|
5334
5440
|
}
|
|
5335
5441
|
}
|
|
5336
5442
|
function emulatorInputIndexes(tx) {
|
|
@@ -5376,11 +5482,11 @@ function assertCosignable(coin, csv, tip, marginBlocks = DEFAULT_COSIGN_MARGIN_B
|
|
|
5376
5482
|
function isBoardingContract(contract, boardingCsv) {
|
|
5377
5483
|
if (!isOnchainScoped(contract)) return false;
|
|
5378
5484
|
if (contract.type === "boarding") return true;
|
|
5379
|
-
if (contract.type ===
|
|
5485
|
+
if (contract.type === chunkXZHTYYW5_cjs.ExecutorContractHandler.type) {
|
|
5380
5486
|
return contract.params.template === "boarding";
|
|
5381
5487
|
}
|
|
5382
5488
|
if (contract.type !== "default" || scopeOf(contract) !== "both") return false;
|
|
5383
|
-
return
|
|
5489
|
+
return chunkXZHTYYW5_cjs.exitSequence(contract) === chunk6TBTL42M_cjs.timelockToSequence(boardingCsv);
|
|
5384
5490
|
}
|
|
5385
5491
|
function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFAULT_COSIGN_MARGIN_BLOCKS) {
|
|
5386
5492
|
if (!isBoardingContract(contract, boardingCsv) || !isExplorerCoin(coin)) return false;
|
|
@@ -5392,7 +5498,7 @@ function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFA
|
|
|
5392
5498
|
return left.remaining > margin && left.remaining <= margin + window2;
|
|
5393
5499
|
}
|
|
5394
5500
|
function finalizeOwnedInput(tx, index) {
|
|
5395
|
-
const condition =
|
|
5501
|
+
const condition = chunk6J4GABF7_cjs.getArkPsbtFields(tx, index, chunk6J4GABF7_cjs.ConditionWitness)[0];
|
|
5396
5502
|
if (!condition) {
|
|
5397
5503
|
tx.finalizeIdx(index);
|
|
5398
5504
|
return;
|
|
@@ -5415,27 +5521,27 @@ var DEFINITE_COSIGN_REJECTIONS = /* @__PURE__ */ new Set([
|
|
|
5415
5521
|
"TX_TOO_LARGE"
|
|
5416
5522
|
]);
|
|
5417
5523
|
function isCosignRejectedAfterSigning(e) {
|
|
5418
|
-
return e instanceof
|
|
5524
|
+
return e instanceof chunk6J4GABF7_cjs.OnchainCosignRejectedError && !isCosignFallback(e);
|
|
5419
5525
|
}
|
|
5420
5526
|
function isCosignFallback(e) {
|
|
5421
|
-
if (e instanceof
|
|
5527
|
+
if (e instanceof chunk6J4GABF7_cjs.OnchainCosignRejectedError) {
|
|
5422
5528
|
return !!e.arkErrorName && DEFINITE_COSIGN_REJECTIONS.has(e.arkErrorName);
|
|
5423
5529
|
}
|
|
5424
|
-
return e instanceof
|
|
5530
|
+
return e instanceof chunk6J4GABF7_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError;
|
|
5425
5531
|
}
|
|
5426
5532
|
function rehydrateCosignError(e) {
|
|
5427
|
-
if (!(e instanceof Error) || e instanceof
|
|
5533
|
+
if (!(e instanceof Error) || e instanceof chunk6J4GABF7_cjs.OnchainCosignRejectedError || e instanceof chunk6J4GABF7_cjs.OnchainCosignAmbiguousError || e instanceof chunk6J4GABF7_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError) {
|
|
5428
5534
|
return e;
|
|
5429
5535
|
}
|
|
5430
5536
|
const { message } = e;
|
|
5431
|
-
if (message.startsWith(
|
|
5432
|
-
const rest = message.slice(
|
|
5537
|
+
if (message.startsWith(chunk6J4GABF7_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX)) {
|
|
5538
|
+
const rest = message.slice(chunk6J4GABF7_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX.length);
|
|
5433
5539
|
const named = rest.match(/^\[([A-Z0-9_]+)\] ([\s\S]*)$/);
|
|
5434
|
-
return named ? new
|
|
5540
|
+
return named ? new chunk6J4GABF7_cjs.OnchainCosignRejectedError(named[2], named[1]) : new chunk6J4GABF7_cjs.OnchainCosignRejectedError(rest);
|
|
5435
5541
|
}
|
|
5436
|
-
if (message.startsWith(
|
|
5437
|
-
return new
|
|
5438
|
-
message.slice(
|
|
5542
|
+
if (message.startsWith(chunk6J4GABF7_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX)) {
|
|
5543
|
+
return new chunk6J4GABF7_cjs.OnchainCosignAmbiguousError(
|
|
5544
|
+
message.slice(chunk6J4GABF7_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX.length)
|
|
5439
5545
|
);
|
|
5440
5546
|
}
|
|
5441
5547
|
if (message.startsWith(ONCHAIN_COSIGN_PREFLIGHT_PREFIX)) {
|
|
@@ -5443,8 +5549,8 @@ function rehydrateCosignError(e) {
|
|
|
5443
5549
|
message.slice(ONCHAIN_COSIGN_PREFLIGHT_PREFIX.length)
|
|
5444
5550
|
);
|
|
5445
5551
|
}
|
|
5446
|
-
if (message.startsWith(
|
|
5447
|
-
return new
|
|
5552
|
+
if (message.startsWith(chunk6J4GABF7_cjs.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX))
|
|
5553
|
+
return new chunk6J4GABF7_cjs.OnchainCosignUnsupportedError();
|
|
5448
5554
|
return e;
|
|
5449
5555
|
}
|
|
5450
5556
|
function estimateOnchainCosignFee(nIn, nOut, feeRate) {
|
|
@@ -5460,13 +5566,13 @@ async function submitOnchainSpend(tx, arkInputs, deps) {
|
|
|
5460
5566
|
throw new Error("emulator inputs present but no emulator provider configured");
|
|
5461
5567
|
}
|
|
5462
5568
|
const { signedTx } = await deps.emulator.submitOnchainTx(base.base64.encode(tx.toPSBT()));
|
|
5463
|
-
tx =
|
|
5569
|
+
tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(signedTx));
|
|
5464
5570
|
}
|
|
5465
5571
|
if (arkInputs.size > 0) {
|
|
5466
5572
|
if (!deps.arkProvider) {
|
|
5467
5573
|
throw new Error("arkd-cosigned inputs present but no arkProvider configured");
|
|
5468
5574
|
}
|
|
5469
|
-
if (!deps.arkProvider.cosignOnchainTx) throw new
|
|
5575
|
+
if (!deps.arkProvider.cosignOnchainTx) throw new chunk6J4GABF7_cjs.OnchainCosignUnsupportedError();
|
|
5470
5576
|
return deps.arkProvider.cosignOnchainTx(base.base64.encode(tx.toPSBT()));
|
|
5471
5577
|
}
|
|
5472
5578
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
@@ -5617,7 +5723,7 @@ function parseProgram(text, env) {
|
|
|
5617
5723
|
|
|
5618
5724
|
// src/contracts/spendability.ts
|
|
5619
5725
|
function isContractGenericallySpendable(contract) {
|
|
5620
|
-
return
|
|
5726
|
+
return chunkXZHTYYW5_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
5621
5727
|
}
|
|
5622
5728
|
function gatedContracts(contracts) {
|
|
5623
5729
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -5639,7 +5745,7 @@ function gateExclusion(gated) {
|
|
|
5639
5745
|
return (vtxo) => {
|
|
5640
5746
|
const type = gatedTypeOf(vtxo, gated);
|
|
5641
5747
|
if (type === void 0) return void 0;
|
|
5642
|
-
if (!
|
|
5748
|
+
if (!chunkXZHTYYW5_cjs.contractHandlers.has(type)) {
|
|
5643
5749
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
5644
5750
|
}
|
|
5645
5751
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -5742,7 +5848,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
5742
5848
|
*/
|
|
5743
5849
|
materializeDescriptorAt(index) {
|
|
5744
5850
|
const descriptor = this.identity.descriptor;
|
|
5745
|
-
const network =
|
|
5851
|
+
const network = chunkXZHTYYW5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
5746
5852
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
5747
5853
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
5748
5854
|
if (!keyInfo?.keyExpression) {
|
|
@@ -5810,7 +5916,7 @@ function signingDescriptorIndex(descriptor) {
|
|
|
5810
5916
|
}
|
|
5811
5917
|
function newestWalletReceiveContract(contracts, serverPubKeyHex) {
|
|
5812
5918
|
return contracts.filter(
|
|
5813
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
5919
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkXZHTYYW5_cjs.WALLET_RECEIVE_SOURCE
|
|
5814
5920
|
).sort((a, b) => {
|
|
5815
5921
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
5816
5922
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -5861,7 +5967,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
5861
5967
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
5862
5968
|
if (!provider) return void 0;
|
|
5863
5969
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
5864
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
5970
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
5865
5971
|
const factoryOpts = {
|
|
5866
5972
|
walletRepository: setup.walletRepository,
|
|
5867
5973
|
contractRepository: setup.contractRepository,
|
|
@@ -6021,7 +6127,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
6021
6127
|
};
|
|
6022
6128
|
function deriveLeafPubkey(descriptor) {
|
|
6023
6129
|
try {
|
|
6024
|
-
return
|
|
6130
|
+
return chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
6025
6131
|
} catch (e) {
|
|
6026
6132
|
throw new NonRangeableDescriptorError(
|
|
6027
6133
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -6041,11 +6147,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
6041
6147
|
// Read at sign time to route rotated-pubkey inputs through `signWithDescriptor`; without
|
|
6042
6148
|
// it spends are rejected with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
6043
6149
|
metadata: {
|
|
6044
|
-
...tagSource && { source:
|
|
6150
|
+
...tagSource && { source: chunkXZHTYYW5_cjs.WALLET_RECEIVE_SOURCE },
|
|
6045
6151
|
signingDescriptor: descriptor
|
|
6046
6152
|
}
|
|
6047
6153
|
};
|
|
6048
|
-
const params = tapscript instanceof
|
|
6154
|
+
const params = tapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? {
|
|
6049
6155
|
...base$1,
|
|
6050
6156
|
type: "delegate",
|
|
6051
6157
|
params: {
|
|
@@ -6066,10 +6172,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
6066
6172
|
return { tapscript, params };
|
|
6067
6173
|
}
|
|
6068
6174
|
function rebuildTapscript(current, pubKey) {
|
|
6069
|
-
if (current instanceof
|
|
6070
|
-
return new
|
|
6175
|
+
if (current instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script) {
|
|
6176
|
+
return new chunkXZHTYYW5_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
6071
6177
|
}
|
|
6072
|
-
return new
|
|
6178
|
+
return new chunkXZHTYYW5_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
6073
6179
|
}
|
|
6074
6180
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
6075
6181
|
const candidates = await collectContracts(contractRepository, {
|
|
@@ -6119,7 +6225,7 @@ function cachedScript(params) {
|
|
|
6119
6225
|
const key = JSON.stringify(Object.entries(params).sort(([a], [b]) => a < b ? -1 : 1));
|
|
6120
6226
|
let script = scriptCache.get(key);
|
|
6121
6227
|
if (!script) {
|
|
6122
|
-
script =
|
|
6228
|
+
script = chunkXZHTYYW5_cjs.ExecutorContractHandler.createScript(params);
|
|
6123
6229
|
scriptCache.set(key, script);
|
|
6124
6230
|
}
|
|
6125
6231
|
return script;
|
|
@@ -6138,7 +6244,7 @@ async function delegatedContracts(identity, getContracts, template) {
|
|
|
6138
6244
|
try {
|
|
6139
6245
|
const owner = contract.params.owner?.slice(2).toLowerCase();
|
|
6140
6246
|
const descriptor = contract.metadata?.signingDescriptor;
|
|
6141
|
-
const held = owner === identityKey || typeof descriptor === "string" && base.hex.encode(
|
|
6247
|
+
const held = owner === identityKey || typeof descriptor === "string" && base.hex.encode(chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor)) === owner;
|
|
6142
6248
|
if (!held || owner === void 0) continue;
|
|
6143
6249
|
const script = cachedScript(contract.params);
|
|
6144
6250
|
if (base.hex.encode(script.pkScript) !== contract.script) continue;
|
|
@@ -6167,11 +6273,11 @@ async function watchExecutorContracts(wallet, keys, params, registered, descript
|
|
|
6167
6273
|
const templates = params.boardingExitDelay === void 0 ? ["renewal"] : ["renewal", "boarding"];
|
|
6168
6274
|
const contracts = [];
|
|
6169
6275
|
for (const template of templates) {
|
|
6170
|
-
const serialized =
|
|
6171
|
-
const script =
|
|
6276
|
+
const serialized = chunkXZHTYYW5_cjs.executorContractParams(template, owner, keys, params);
|
|
6277
|
+
const script = chunkXZHTYYW5_cjs.ExecutorContractHandler.createScript(serialized);
|
|
6172
6278
|
contracts.push(
|
|
6173
6279
|
await manager.createContract({
|
|
6174
|
-
type:
|
|
6280
|
+
type: chunkXZHTYYW5_cjs.ExecutorContractHandler.type,
|
|
6175
6281
|
params: serialized,
|
|
6176
6282
|
script: base.hex.encode(script.pkScript),
|
|
6177
6283
|
address: script.address(hrp, serverPubKey).encode(),
|
|
@@ -6195,19 +6301,19 @@ function metadataFor(template, registered, signingDescriptor) {
|
|
|
6195
6301
|
return statusMetadata(signing, registered.status, registered.expiresAt);
|
|
6196
6302
|
}
|
|
6197
6303
|
async function ownerKey(identity, descriptor) {
|
|
6198
|
-
const xOnly =
|
|
6304
|
+
const xOnly = chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
6199
6305
|
const own = await identity.compressedPublicKey();
|
|
6200
|
-
return utils_js.equalBytes(own.subarray(1), xOnly) ? own :
|
|
6306
|
+
return utils_js.equalBytes(own.subarray(1), xOnly) ? own : chunkXZHTYYW5_cjs.evenOwnerKey(xOnly);
|
|
6201
6307
|
}
|
|
6202
6308
|
async function boardingDescriptor(wallet, serverPubKey) {
|
|
6203
6309
|
const manager = await wallet.getContractManager();
|
|
6204
6310
|
const rows = await manager.getContracts({ type: "boarding", state: "active" });
|
|
6205
6311
|
const descriptor = newestWalletReceiveContract(rows, serverPubKey)?.metadata?.signingDescriptor;
|
|
6206
|
-
return typeof descriptor === "string" ? descriptor :
|
|
6312
|
+
return typeof descriptor === "string" ? descriptor : chunkXZHTYYW5_cjs.identityDescriptor(wallet.identity);
|
|
6207
6313
|
}
|
|
6208
6314
|
function watchDescriptor(watch, identity) {
|
|
6209
6315
|
const descriptor = watch.contract.metadata?.signingDescriptor;
|
|
6210
|
-
return typeof descriptor === "string" ? Promise.resolve(descriptor) :
|
|
6316
|
+
return typeof descriptor === "string" ? Promise.resolve(descriptor) : chunkXZHTYYW5_cjs.identityDescriptor(identity);
|
|
6211
6317
|
}
|
|
6212
6318
|
function statusMetadata(metadata, status, expiresAt, registeredAtMs = Date.now()) {
|
|
6213
6319
|
const { [DELEGATION_EXPIRES_KEY]: _stale, ...rest } = metadata;
|
|
@@ -6219,7 +6325,7 @@ function statusMetadata(metadata, status, expiresAt, registeredAtMs = Date.now()
|
|
|
6219
6325
|
};
|
|
6220
6326
|
}
|
|
6221
6327
|
function reRegistrationOf(watch) {
|
|
6222
|
-
const p =
|
|
6328
|
+
const p = chunkXZHTYYW5_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6223
6329
|
const expiresAt = watch.contract.metadata?.[DELEGATION_EXPIRES_KEY];
|
|
6224
6330
|
return {
|
|
6225
6331
|
options: {
|
|
@@ -6235,8 +6341,8 @@ function reRegistrationOf(watch) {
|
|
|
6235
6341
|
};
|
|
6236
6342
|
}
|
|
6237
6343
|
function renewalScript(owner, keys, params) {
|
|
6238
|
-
const script =
|
|
6239
|
-
|
|
6344
|
+
const script = chunkXZHTYYW5_cjs.ExecutorContractHandler.createScript(
|
|
6345
|
+
chunkXZHTYYW5_cjs.executorContractParams("renewal", owner, keys, params)
|
|
6240
6346
|
);
|
|
6241
6347
|
return base.hex.encode(script.pkScript);
|
|
6242
6348
|
}
|
|
@@ -6267,7 +6373,7 @@ var ExecutorManagerImpl = class {
|
|
|
6267
6373
|
return this.executorProvider.getInfo();
|
|
6268
6374
|
}
|
|
6269
6375
|
async defaultTemplates() {
|
|
6270
|
-
const ids = { ...
|
|
6376
|
+
const ids = { ...chunkXZHTYYW5_cjs.DEFAULT_TEMPLATE_IDS };
|
|
6271
6377
|
const templates = await this.executorProvider.listTemplates();
|
|
6272
6378
|
const active = new Set(templates.filter((t) => t.status === "active").map((t) => t.id));
|
|
6273
6379
|
const missing = Object.entries(ids).filter(([, id]) => !active.has(id));
|
|
@@ -6299,8 +6405,8 @@ var ExecutorManagerImpl = class {
|
|
|
6299
6405
|
for (const watch of await this.heldWatches("boarding")) {
|
|
6300
6406
|
if (!watch.live || watch.signer !== server) continue;
|
|
6301
6407
|
try {
|
|
6302
|
-
const p =
|
|
6303
|
-
const keys =
|
|
6408
|
+
const p = chunkXZHTYYW5_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6409
|
+
const keys = chunkXZHTYYW5_cjs.executorKeysOf(p);
|
|
6304
6410
|
if (keys.emulatorPubkey !== first.keys.emulatorPubkey.toLowerCase()) {
|
|
6305
6411
|
console.warn(
|
|
6306
6412
|
`Skipping the held key ${watch.owner}: its watch uses another emulator key than the Executor's`
|
|
@@ -6403,7 +6509,7 @@ var ExecutorManagerImpl = class {
|
|
|
6403
6509
|
const address = template === "boarding" ? watch.script.onchainAddress(context.network) : watch.script.address(context.hrp, context.serverPubKey).encode();
|
|
6404
6510
|
try {
|
|
6405
6511
|
const details = await this.executorProvider.getDelegation(address, {
|
|
6406
|
-
signal:
|
|
6512
|
+
signal: chunk6J4GABF7_cjs.timeoutSignal(EXECUTOR_REQUEST_TIMEOUT_MS)
|
|
6407
6513
|
});
|
|
6408
6514
|
return details.delegation.status;
|
|
6409
6515
|
} catch (e) {
|
|
@@ -6503,15 +6609,15 @@ var ExecutorManagerImpl = class {
|
|
|
6503
6609
|
const operator = await this.wallet.getOperatorInfo();
|
|
6504
6610
|
const network = chunk6TBTL42M_cjs.networkFromOperatorInfo(operator);
|
|
6505
6611
|
const params = resolveParams(options, operator, template);
|
|
6506
|
-
const p =
|
|
6612
|
+
const p = chunkXZHTYYW5_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6507
6613
|
if (base.hex.encode(p.emulatorPubKey) !== chunk6TBTL42M_cjs.resolveEmulatorPubkey(network, emulatorPubkey) || p.renewalWindow !== params.renewalWindow || p.maxFee !== params.maxFee || p.exitDelay !== params.exitDelay || p.boardingExitDelay !== params.boardingExitDelay || windowPastExpiry(params.renewalWindow, operator.vtxoTreeExpiry)) {
|
|
6508
6614
|
return void 0;
|
|
6509
6615
|
}
|
|
6510
6616
|
return {
|
|
6511
6617
|
address: template === "boarding" ? watch.script.onchainAddress(network) : watch.script.address(hrp, serverPubKey).encode(),
|
|
6512
|
-
templateId:
|
|
6513
|
-
variables:
|
|
6514
|
-
keys:
|
|
6618
|
+
templateId: chunkXZHTYYW5_cjs.DEFAULT_TEMPLATE_IDS[template],
|
|
6619
|
+
variables: chunkXZHTYYW5_cjs.defaultVariables(template, owner, params),
|
|
6620
|
+
keys: chunkXZHTYYW5_cjs.executorKeysOf(p),
|
|
6515
6621
|
params
|
|
6516
6622
|
};
|
|
6517
6623
|
}
|
|
@@ -6585,15 +6691,15 @@ var ExecutorManagerImpl = class {
|
|
|
6585
6691
|
serverPubkey: info.serverPubkey,
|
|
6586
6692
|
emulatorPubkey: info.emulatorPubkey
|
|
6587
6693
|
};
|
|
6588
|
-
const variables =
|
|
6589
|
-
const watchScript =
|
|
6590
|
-
|
|
6694
|
+
const variables = chunkXZHTYYW5_cjs.defaultVariables(template, owner, params);
|
|
6695
|
+
const watchScript = chunkXZHTYYW5_cjs.ExecutorContractHandler.createScript(
|
|
6696
|
+
chunkXZHTYYW5_cjs.executorContractParams(template, owner, keys, params)
|
|
6591
6697
|
);
|
|
6592
6698
|
const watchAddress = template === "boarding" ? watchScript.onchainAddress(network) : watchScript.address(hrp, serverPubKey).encode();
|
|
6593
|
-
const templateId =
|
|
6699
|
+
const templateId = chunkXZHTYYW5_cjs.DEFAULT_TEMPLATE_IDS[template];
|
|
6594
6700
|
const delegation = await this.executorProvider.registerDelegation(templateId, variables, {
|
|
6595
6701
|
expiresAt,
|
|
6596
|
-
signal:
|
|
6702
|
+
signal: chunk6J4GABF7_cjs.timeoutSignal(EXECUTOR_REQUEST_TIMEOUT_MS)
|
|
6597
6703
|
});
|
|
6598
6704
|
const [input] = delegation.inputs;
|
|
6599
6705
|
if (delegation.inputs.length !== 1 || !input || (template === "boarding" ? !input.onchain : input.onchain)) {
|
|
@@ -6647,7 +6753,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
6647
6753
|
continue;
|
|
6648
6754
|
}
|
|
6649
6755
|
for (const v of vtxos) {
|
|
6650
|
-
if (!
|
|
6756
|
+
if (!chunk6J4GABF7_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
|
|
6651
6757
|
out.add(`${v.txid}:${v.vout}`);
|
|
6652
6758
|
}
|
|
6653
6759
|
}
|
|
@@ -6690,7 +6796,7 @@ function byValueDescending(vtxos) {
|
|
|
6690
6796
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
6691
6797
|
}
|
|
6692
6798
|
async function fetchTimeHeight(wallet) {
|
|
6693
|
-
return
|
|
6799
|
+
return chunk6J4GABF7_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
6694
6800
|
}
|
|
6695
6801
|
function heldVtxosOf(wallet) {
|
|
6696
6802
|
const held = wallet.getHeldVtxos;
|
|
@@ -6701,7 +6807,7 @@ async function heldOutpointsOf(wallet) {
|
|
|
6701
6807
|
return new Set((await heldVtxosOf(wallet)).map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
6702
6808
|
}
|
|
6703
6809
|
function canMigrateBySend(vtxo, now) {
|
|
6704
|
-
if (!
|
|
6810
|
+
if (!chunk6J4GABF7_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
6705
6811
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
6706
6812
|
}
|
|
6707
6813
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -6709,7 +6815,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
6709
6815
|
if (vtxo.isSwept) return -Infinity;
|
|
6710
6816
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
6711
6817
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
6712
|
-
return
|
|
6818
|
+
return chunk6J4GABF7_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
6713
6819
|
}
|
|
6714
6820
|
return Infinity;
|
|
6715
6821
|
};
|
|
@@ -6736,7 +6842,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
6736
6842
|
const payable = [];
|
|
6737
6843
|
const net = /* @__PURE__ */ new Map();
|
|
6738
6844
|
for (const vtxo of vtxos) {
|
|
6739
|
-
const inputFee = estimator.evalOffchainInput(
|
|
6845
|
+
const inputFee = estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(vtxo));
|
|
6740
6846
|
if (inputFee.satoshis >= vtxo.value) {
|
|
6741
6847
|
continue;
|
|
6742
6848
|
}
|
|
@@ -6816,10 +6922,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
6816
6922
|
};
|
|
6817
6923
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
6818
6924
|
return vtxos.filter((vtxo) => {
|
|
6819
|
-
if (
|
|
6925
|
+
if (chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
6820
6926
|
return true;
|
|
6821
6927
|
}
|
|
6822
|
-
if (
|
|
6928
|
+
if (chunk6J4GABF7_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
6823
6929
|
return true;
|
|
6824
6930
|
}
|
|
6825
6931
|
return false;
|
|
@@ -6851,7 +6957,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
6851
6957
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
6852
6958
|
if (vtxo.isUnrolled) return false;
|
|
6853
6959
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
6854
|
-
const expiresAt =
|
|
6960
|
+
const expiresAt = chunk6J4GABF7_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
6855
6961
|
if (expiresAt === void 0) return false;
|
|
6856
6962
|
const now = Date.now();
|
|
6857
6963
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -6862,7 +6968,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
|
6862
6968
|
return vtxos.filter(
|
|
6863
6969
|
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
6864
6970
|
// property and would otherwise re-admit an exited coin on its own.
|
|
6865
|
-
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
6971
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
6866
6972
|
);
|
|
6867
6973
|
}
|
|
6868
6974
|
function isMigrationCapable(wallet) {
|
|
@@ -6935,7 +7041,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
6935
7041
|
constructor(wallet, settlementConfig) {
|
|
6936
7042
|
this.wallet = wallet;
|
|
6937
7043
|
if (settlementConfig !== false) {
|
|
6938
|
-
|
|
7044
|
+
chunk6J4GABF7_cjs.assertTimerMs("pollIntervalMs", settlementConfig?.pollIntervalMs);
|
|
6939
7045
|
}
|
|
6940
7046
|
this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
6941
7047
|
this.contractEventsSubscriptionReady = this.initializeSubscription();
|
|
@@ -7254,7 +7360,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7254
7360
|
* {@link recoverImportedContracts}).
|
|
7255
7361
|
*/
|
|
7256
7362
|
async recoverOneImportedContract(wallet, contract, vtxos, info, dustAmount) {
|
|
7257
|
-
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !
|
|
7363
|
+
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !chunk6J4GABF7_cjs.isVtxoSpent(vtxo));
|
|
7258
7364
|
const estimator = new Estimator(info?.fees.intentFee ?? {});
|
|
7259
7365
|
const { payable, net } = priceSettlementInputs(recoverable, estimator);
|
|
7260
7366
|
const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
|
|
@@ -7288,7 +7394,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7288
7394
|
if (vtxos.length === 0) return;
|
|
7289
7395
|
const spent = new Set(batch.map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
7290
7396
|
const stillSpendable = vtxos.some(
|
|
7291
|
-
(vtxo) => !
|
|
7397
|
+
(vtxo) => !chunk6J4GABF7_cjs.isVtxoSpent(vtxo) && !spent.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
7292
7398
|
);
|
|
7293
7399
|
if (!stillSpendable) {
|
|
7294
7400
|
await wallet.removeRecoveryContract(contract.script);
|
|
@@ -7362,7 +7468,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7362
7468
|
const live = watches.filter((w) => w.live && w.signer === signer);
|
|
7363
7469
|
return vtxos.filter((vtxo) => {
|
|
7364
7470
|
const watch = live.find((w) => w.contract.script === vtxo.script);
|
|
7365
|
-
if (!watch ||
|
|
7471
|
+
if (!watch || chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dust)) return true;
|
|
7366
7472
|
if (BigInt(vtxo.value) <= BigInt(watch.contract.params.maxFee) + dust) return true;
|
|
7367
7473
|
const expiresAt = vtxo.expiresAt?.getTime();
|
|
7368
7474
|
if (expiresAt === void 0) return true;
|
|
@@ -7564,7 +7670,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7564
7670
|
return txid;
|
|
7565
7671
|
} catch (e) {
|
|
7566
7672
|
if (!isCosignFallback(e)) throw e;
|
|
7567
|
-
if (e instanceof
|
|
7673
|
+
if (e instanceof chunk6J4GABF7_cjs.OnchainCosignRejectedError) {
|
|
7568
7674
|
console.warn("Onchain cosign sweep rejected, falling back to CSV exit:", e.message);
|
|
7569
7675
|
}
|
|
7570
7676
|
return void 0;
|
|
@@ -7641,7 +7747,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7641
7747
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
7642
7748
|
);
|
|
7643
7749
|
}
|
|
7644
|
-
const tx = new
|
|
7750
|
+
const tx = new chunk6J4GABF7_cjs.Transaction();
|
|
7645
7751
|
for (const { utxo, script, leaf } of inputs) {
|
|
7646
7752
|
tx.addInput({
|
|
7647
7753
|
txid: utxo.txid,
|
|
@@ -7886,8 +7992,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
7886
7992
|
const cls = chunk6TBTL42M_cjs.classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
7887
7993
|
if (cls.status === "CURRENT") continue;
|
|
7888
7994
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
7889
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
7890
|
-
const spendable = live.filter((v) => !
|
|
7995
|
+
const recoverable = live.filter((v) => v.isSwept && !chunk6J4GABF7_cjs.isVtxoSpent(v));
|
|
7996
|
+
const spendable = live.filter((v) => !chunk6J4GABF7_cjs.isVtxoSpent(v) && !v.isSwept);
|
|
7891
7997
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
7892
7998
|
let recoverableCount = 0;
|
|
7893
7999
|
let recoverableValue = 0;
|
|
@@ -8243,8 +8349,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
8243
8349
|
}
|
|
8244
8350
|
/** The outpoint a `VTXO_ALREADY_SPENT` error carries in `metadata.vtxo_outpoint`, if any. */
|
|
8245
8351
|
extractSpentOutpoint(error) {
|
|
8246
|
-
const ark =
|
|
8247
|
-
if (!
|
|
8352
|
+
const ark = chunk6J4GABF7_cjs.maybeArkError(error);
|
|
8353
|
+
if (!chunk6J4GABF7_cjs.isArkError(ark, chunk6J4GABF7_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
8248
8354
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
8249
8355
|
if (typeof raw !== "string") return void 0;
|
|
8250
8356
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -8435,7 +8541,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
8435
8541
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
8436
8542
|
break;
|
|
8437
8543
|
}
|
|
8438
|
-
const inputFee = estimator.evalOffchainInput(
|
|
8544
|
+
const inputFee = estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(v));
|
|
8439
8545
|
if (inputFee.satoshis >= v.value) {
|
|
8440
8546
|
continue;
|
|
8441
8547
|
}
|
|
@@ -8747,7 +8853,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
8747
8853
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
8748
8854
|
}
|
|
8749
8855
|
get vtxoScript() {
|
|
8750
|
-
return new
|
|
8856
|
+
return new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
8751
8857
|
pubKey: this._publicKey,
|
|
8752
8858
|
serverPubKey: this._serverPubKey,
|
|
8753
8859
|
csvTimelock: this.csvTimelock
|
|
@@ -8844,10 +8950,15 @@ async function arkadeCashActivity(records, txs) {
|
|
|
8844
8950
|
return activities.filter((activity) => activity.intent?.kind === "arkade-cash");
|
|
8845
8951
|
}
|
|
8846
8952
|
|
|
8953
|
+
// src/repositories/vtxoReservationRepository.ts
|
|
8954
|
+
function reservationOutpointSetKey(outpoints) {
|
|
8955
|
+
return outpoints.map(({ txid, vout }) => `${txid}:${vout}`).sort().join("|");
|
|
8956
|
+
}
|
|
8957
|
+
|
|
8847
8958
|
// src/wallet/intentReconciliation.ts
|
|
8848
8959
|
var NON_TERMINAL_INTENT_STATES = ALL_BATCH_REGISTRATION_STATES.filter((s) => !isTerminalBatchRegistrationState(s));
|
|
8849
8960
|
function isConsumed(vtxo) {
|
|
8850
|
-
return vtxo !== void 0 &&
|
|
8961
|
+
return vtxo !== void 0 && chunk6J4GABF7_cjs.isVtxoSpent(vtxo);
|
|
8851
8962
|
}
|
|
8852
8963
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
8853
8964
|
if (isTerminalBatchRegistrationState(intent.state)) return void 0;
|
|
@@ -8885,7 +8996,7 @@ async function reconcileIntents(deps) {
|
|
|
8885
8996
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
8886
8997
|
if (outpoints.length > 0) {
|
|
8887
8998
|
try {
|
|
8888
|
-
const { vtxos } = await
|
|
8999
|
+
const { vtxos } = await chunk6J4GABF7_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
8889
9000
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
8890
9001
|
} catch (e) {
|
|
8891
9002
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -8945,7 +9056,7 @@ async function releaseFromServer(intent, deps, now) {
|
|
|
8945
9056
|
});
|
|
8946
9057
|
}
|
|
8947
9058
|
function isNoMatchingIntentsError(e) {
|
|
8948
|
-
return
|
|
9059
|
+
return chunk6J4GABF7_cjs.isArkError(e, chunk6J4GABF7_cjs.ArkErrorName.INVALID_INTENT_PROOF) && e.message.includes("no matching intents found");
|
|
8949
9060
|
}
|
|
8950
9061
|
function terminal(intent, state, now, patch) {
|
|
8951
9062
|
return { ...intent, ...patch, state, updatedAt: now };
|
|
@@ -9172,7 +9283,7 @@ async function captureExitBranch(params) {
|
|
|
9172
9283
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
9173
9284
|
if (nonCommitment.length > 0) {
|
|
9174
9285
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
9175
|
-
psbtByTxid.set(
|
|
9286
|
+
psbtByTxid.set(chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
9176
9287
|
}
|
|
9177
9288
|
}
|
|
9178
9289
|
}
|
|
@@ -9210,10 +9321,10 @@ var IndexerExitDataSource = class {
|
|
|
9210
9321
|
name = "indexer";
|
|
9211
9322
|
async getVtxoChain(vtxo) {
|
|
9212
9323
|
const chain = [];
|
|
9213
|
-
for await (const { chain: page } of
|
|
9324
|
+
for await (const { chain: page } of chunk6J4GABF7_cjs.indexerPages(
|
|
9214
9325
|
(pageIndex) => this.indexer.getVtxoChain(
|
|
9215
9326
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
9216
|
-
{ pageIndex, pageSize:
|
|
9327
|
+
{ pageIndex, pageSize: chunk6J4GABF7_cjs.DEFAULT_PAGE_SIZE }
|
|
9217
9328
|
)
|
|
9218
9329
|
)) {
|
|
9219
9330
|
chain.push(...page);
|
|
@@ -9222,11 +9333,11 @@ var IndexerExitDataSource = class {
|
|
|
9222
9333
|
}
|
|
9223
9334
|
async getVirtualTxs(txids) {
|
|
9224
9335
|
const out = /* @__PURE__ */ new Map();
|
|
9225
|
-
for await (const { txs } of
|
|
9226
|
-
(pageIndex) => this.indexer.getVirtualTxs(txids, { pageIndex, pageSize:
|
|
9336
|
+
for await (const { txs } of chunk6J4GABF7_cjs.indexerPages(
|
|
9337
|
+
(pageIndex) => this.indexer.getVirtualTxs(txids, { pageIndex, pageSize: chunk6J4GABF7_cjs.DEFAULT_PAGE_SIZE })
|
|
9227
9338
|
)) {
|
|
9228
9339
|
for (const psbt of txs) {
|
|
9229
|
-
out.set(
|
|
9340
|
+
out.set(chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
9230
9341
|
}
|
|
9231
9342
|
}
|
|
9232
9343
|
return out;
|
|
@@ -9247,7 +9358,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
9247
9358
|
}
|
|
9248
9359
|
}
|
|
9249
9360
|
function psbtInputTxids(psbtBase64) {
|
|
9250
|
-
return txInputTxids(
|
|
9361
|
+
return txInputTxids(chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64)));
|
|
9251
9362
|
}
|
|
9252
9363
|
function txInputTxids(tx) {
|
|
9253
9364
|
const ids = [];
|
|
@@ -9554,10 +9665,10 @@ async function resolveArkInfo(arkProvider, walletRepository, opts) {
|
|
|
9554
9665
|
try {
|
|
9555
9666
|
info = await arkProvider.getInfo();
|
|
9556
9667
|
} catch (err) {
|
|
9557
|
-
if (opts?.requireLive || !
|
|
9668
|
+
if (opts?.requireLive || !chunk6J4GABF7_cjs.isRetryableProviderError(err)) throw err;
|
|
9558
9669
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
9559
9670
|
if (!snapshot) {
|
|
9560
|
-
throw new
|
|
9671
|
+
throw new chunk6J4GABF7_cjs.ProviderUnavailableError(
|
|
9561
9672
|
"Operator info is unavailable and no cached snapshot exists",
|
|
9562
9673
|
{ cause: err }
|
|
9563
9674
|
);
|
|
@@ -9737,7 +9848,7 @@ function buildGraph(rootTxid, chunksByTxid, visited = /* @__PURE__ */ new Set())
|
|
|
9737
9848
|
return new TxTree(rootTx, children);
|
|
9738
9849
|
}
|
|
9739
9850
|
function decodeNode(chunk) {
|
|
9740
|
-
const tx =
|
|
9851
|
+
const tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(chunk.tx));
|
|
9741
9852
|
return { tx, children: chunk.children };
|
|
9742
9853
|
}
|
|
9743
9854
|
exports.Batch = void 0;
|
|
@@ -9961,7 +10072,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
|
|
|
9961
10072
|
return [...txids];
|
|
9962
10073
|
}
|
|
9963
10074
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
|
|
9964
|
-
const normalized = vtxos.map(
|
|
10075
|
+
const normalized = vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
9965
10076
|
const localCreatedAt = localCreatedAtByTxid(normalized);
|
|
9966
10077
|
const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
|
|
9967
10078
|
const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
|
|
@@ -10148,7 +10259,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10148
10259
|
withRecoverable: false,
|
|
10149
10260
|
genericallySpendableOnly: true
|
|
10150
10261
|
});
|
|
10151
|
-
const controlAssetRef = params.controlAssetId ?
|
|
10262
|
+
const controlAssetRef = params.controlAssetId ? chunk7LPT6AYH_cjs.AssetRef.fromId(chunk7LPT6AYH_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
10152
10263
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
10153
10264
|
let totalBtcSelected = 0n;
|
|
10154
10265
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -10161,8 +10272,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10161
10272
|
}
|
|
10162
10273
|
}
|
|
10163
10274
|
const groups = [];
|
|
10164
|
-
const issuedAssetOutput =
|
|
10165
|
-
const issuedAssetGroup =
|
|
10275
|
+
const issuedAssetOutput = chunk7LPT6AYH_cjs.AssetOutput.create(0, params.amount);
|
|
10276
|
+
const issuedAssetGroup = chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
10166
10277
|
null,
|
|
10167
10278
|
controlAssetRef,
|
|
10168
10279
|
[],
|
|
@@ -10175,11 +10286,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10175
10286
|
for (const [assetId, amount] of assetChanges) {
|
|
10176
10287
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10177
10288
|
groups.push(
|
|
10178
|
-
|
|
10179
|
-
|
|
10289
|
+
chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
10290
|
+
chunk7LPT6AYH_cjs.AssetId.fromString(assetId),
|
|
10180
10291
|
null,
|
|
10181
10292
|
changeInputs,
|
|
10182
|
-
[
|
|
10293
|
+
[chunk7LPT6AYH_cjs.AssetOutput.create(0, amount)],
|
|
10183
10294
|
[]
|
|
10184
10295
|
)
|
|
10185
10296
|
);
|
|
@@ -10194,7 +10305,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10194
10305
|
);
|
|
10195
10306
|
return {
|
|
10196
10307
|
arkTxId: arkTxid,
|
|
10197
|
-
assetId:
|
|
10308
|
+
assetId: chunk7LPT6AYH_cjs.AssetId.create(arkTxid, 0).toString()
|
|
10198
10309
|
};
|
|
10199
10310
|
}
|
|
10200
10311
|
/**
|
|
@@ -10268,23 +10379,23 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10268
10379
|
const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
|
|
10269
10380
|
const reissueInputs = inputsForAsset(assetInputs, params.assetId);
|
|
10270
10381
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
10271
|
-
const reissueAssetIdObj =
|
|
10272
|
-
const reissueAssetGroup =
|
|
10382
|
+
const reissueAssetIdObj = chunk7LPT6AYH_cjs.AssetId.fromString(params.assetId);
|
|
10383
|
+
const reissueAssetGroup = chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
10273
10384
|
reissueAssetIdObj,
|
|
10274
10385
|
null,
|
|
10275
10386
|
reissueInputs,
|
|
10276
|
-
[
|
|
10387
|
+
[chunk7LPT6AYH_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
10277
10388
|
[]
|
|
10278
10389
|
);
|
|
10279
10390
|
const groups = [reissueAssetGroup];
|
|
10280
10391
|
for (const [assetId, amount] of assetChanges) {
|
|
10281
10392
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10282
10393
|
groups.push(
|
|
10283
|
-
|
|
10284
|
-
|
|
10394
|
+
chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
10395
|
+
chunk7LPT6AYH_cjs.AssetId.fromString(assetId),
|
|
10285
10396
|
null,
|
|
10286
10397
|
changeInputs,
|
|
10287
|
-
[
|
|
10398
|
+
[chunk7LPT6AYH_cjs.AssetOutput.create(0, amount)],
|
|
10288
10399
|
[]
|
|
10289
10400
|
)
|
|
10290
10401
|
);
|
|
@@ -10355,11 +10466,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10355
10466
|
for (const [assetId, amount] of assetChanges) {
|
|
10356
10467
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10357
10468
|
groups.push(
|
|
10358
|
-
|
|
10359
|
-
|
|
10469
|
+
chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
10470
|
+
chunk7LPT6AYH_cjs.AssetId.fromString(assetId),
|
|
10360
10471
|
null,
|
|
10361
10472
|
changeInputs,
|
|
10362
|
-
amount > 0n ? [
|
|
10473
|
+
amount > 0n ? [chunk7LPT6AYH_cjs.AssetOutput.create(0, amount)] : [],
|
|
10363
10474
|
[]
|
|
10364
10475
|
)
|
|
10365
10476
|
);
|
|
@@ -10372,7 +10483,7 @@ function inputsForAsset(assetInputs, assetId) {
|
|
|
10372
10483
|
for (const [inputIndex, assets] of assetInputs) {
|
|
10373
10484
|
for (const asset of assets) {
|
|
10374
10485
|
if (asset.assetId !== assetId) continue;
|
|
10375
|
-
inputs.push(
|
|
10486
|
+
inputs.push(chunk7LPT6AYH_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
10376
10487
|
}
|
|
10377
10488
|
}
|
|
10378
10489
|
return inputs;
|
|
@@ -10381,7 +10492,7 @@ async function submitToSelf(submit, wallet, inputs, amount, groups) {
|
|
|
10381
10492
|
const outputAddress = chunk6TBTL42M_cjs.ArkAddress.decode(await wallet.getAddress());
|
|
10382
10493
|
const outputs = [
|
|
10383
10494
|
{ script: outputAddress.pkScript, amount: BigInt(amount) },
|
|
10384
|
-
Extension.create([
|
|
10495
|
+
Extension.create([chunk7LPT6AYH_cjs.Packet.create(groups)]).txOut()
|
|
10385
10496
|
];
|
|
10386
10497
|
const { arkTxid } = await submit(inputs, outputs);
|
|
10387
10498
|
return arkTxid;
|
|
@@ -10405,7 +10516,7 @@ function castMetadata(metadata) {
|
|
|
10405
10516
|
} else {
|
|
10406
10517
|
throw new Error("Invalid metadata value type");
|
|
10407
10518
|
}
|
|
10408
|
-
md.push(
|
|
10519
|
+
md.push(chunk7LPT6AYH_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
10409
10520
|
}
|
|
10410
10521
|
return md;
|
|
10411
10522
|
}
|
|
@@ -10431,7 +10542,7 @@ var DelegateManagerImpl = class {
|
|
|
10431
10542
|
this.arkInfoProvider.getInfo(),
|
|
10432
10543
|
this.delegateProvider.getDelegateInfo()
|
|
10433
10544
|
]);
|
|
10434
|
-
const eligible = vtxos.map(
|
|
10545
|
+
const eligible = vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo).filter(
|
|
10435
10546
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
10436
10547
|
);
|
|
10437
10548
|
if (eligible.length === 0) {
|
|
@@ -10463,7 +10574,7 @@ var DelegateManagerImpl = class {
|
|
|
10463
10574
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
10464
10575
|
let recoverableVtxos = [];
|
|
10465
10576
|
for (const vtxo of eligible) {
|
|
10466
|
-
if (
|
|
10577
|
+
if (chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
10467
10578
|
recoverableVtxos.push(vtxo);
|
|
10468
10579
|
continue;
|
|
10469
10580
|
}
|
|
@@ -10515,7 +10626,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10515
10626
|
}
|
|
10516
10627
|
if (!delegateAt) {
|
|
10517
10628
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
10518
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
10629
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunk6J4GABF7_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
|
|
10519
10630
|
(min, coin) => Math.min(min, coin.expiresAt.getTime()),
|
|
10520
10631
|
Number.MAX_SAFE_INTEGER
|
|
10521
10632
|
);
|
|
@@ -10535,7 +10646,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10535
10646
|
let amount = 0n;
|
|
10536
10647
|
for (const coin of vtxos) {
|
|
10537
10648
|
const inputFee = estimator.evalOffchainInput({
|
|
10538
|
-
...
|
|
10649
|
+
...chunk6J4GABF7_cjs.toOffchainInputFeeParams(coin),
|
|
10539
10650
|
type: "vtxo"
|
|
10540
10651
|
});
|
|
10541
10652
|
if (inputFee.satoshis >= coin.value) {
|
|
@@ -10590,7 +10701,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10590
10701
|
btcSigner.Address(chunk6TBTL42M_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
10591
10702
|
);
|
|
10592
10703
|
const forfeits = await Promise.all(
|
|
10593
|
-
vtxos.filter((v) =>
|
|
10704
|
+
vtxos.filter((v) => chunk6J4GABF7_cjs.requiresForfeit(v)).map(async (coin) => {
|
|
10594
10705
|
const forfeit = await makeDelegateForfeitTx(
|
|
10595
10706
|
coin,
|
|
10596
10707
|
dust,
|
|
@@ -10673,7 +10784,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
10673
10784
|
expire_at: 0,
|
|
10674
10785
|
cosigners_public_keys: cosignerPubKeys
|
|
10675
10786
|
};
|
|
10676
|
-
const proof =
|
|
10787
|
+
const proof = chunk6J4GABF7_cjs.Proof.create(message, coins, outputs);
|
|
10677
10788
|
const signedProof = await identity.sign(proof);
|
|
10678
10789
|
return {
|
|
10679
10790
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -10893,7 +11004,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
|
|
|
10893
11004
|
// src/repositories/indexedDB/vtxoReservationRepository.ts
|
|
10894
11005
|
var STORE = "reservations";
|
|
10895
11006
|
var IndexedDBVtxoReservationRepository = class {
|
|
10896
|
-
version =
|
|
11007
|
+
version = 2;
|
|
10897
11008
|
connection;
|
|
10898
11009
|
constructor(dbName) {
|
|
10899
11010
|
this.connection = createManagedConnection(dbName, 1, (db) => {
|
|
@@ -10916,6 +11027,22 @@ var IndexedDBVtxoReservationRepository = class {
|
|
|
10916
11027
|
transaction.objectStore(STORE).delete(id);
|
|
10917
11028
|
await awaitTransaction(transaction);
|
|
10918
11029
|
}
|
|
11030
|
+
async deleteReservationIfMatches(id, expected) {
|
|
11031
|
+
const expectedKey = reservationOutpointSetKey(expected);
|
|
11032
|
+
const db = await this.connection.get();
|
|
11033
|
+
const transaction = db.transaction(STORE, "readwrite");
|
|
11034
|
+
const store = transaction.objectStore(STORE);
|
|
11035
|
+
let deleted = false;
|
|
11036
|
+
const request = store.get(id);
|
|
11037
|
+
request.onsuccess = () => {
|
|
11038
|
+
const current = request.result;
|
|
11039
|
+
if (!current || reservationOutpointSetKey(current.outpoints) !== expectedKey) return;
|
|
11040
|
+
store.delete(id);
|
|
11041
|
+
deleted = true;
|
|
11042
|
+
};
|
|
11043
|
+
await awaitTransaction(transaction);
|
|
11044
|
+
return deleted;
|
|
11045
|
+
}
|
|
10919
11046
|
async [Symbol.asyncDispose]() {
|
|
10920
11047
|
await this.connection[Symbol.asyncDispose]();
|
|
10921
11048
|
}
|
|
@@ -11446,7 +11573,7 @@ function decodeArkContract(encoded) {
|
|
|
11446
11573
|
}
|
|
11447
11574
|
function contractFromArkContract(encoded, options = {}) {
|
|
11448
11575
|
const parsed = decodeArkContract(encoded);
|
|
11449
|
-
const handler =
|
|
11576
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(parsed.type);
|
|
11450
11577
|
if (!handler) {
|
|
11451
11578
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
11452
11579
|
}
|
|
@@ -11462,7 +11589,7 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
11462
11589
|
}
|
|
11463
11590
|
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk6TBTL42M_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
11464
11591
|
const parsed = decodeArkContract(encoded);
|
|
11465
|
-
const handler =
|
|
11592
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
11466
11593
|
const params = parsed.data;
|
|
11467
11594
|
const vtxoScript = handler.createScript(params);
|
|
11468
11595
|
return {
|
|
@@ -11521,10 +11648,10 @@ var ContractWatcher = class {
|
|
|
11521
11648
|
eventSourceReported = false;
|
|
11522
11649
|
/** @see ContractWatcherConfig */
|
|
11523
11650
|
constructor(config) {
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11651
|
+
chunk6J4GABF7_cjs.assertTimerMs("failsafePollIntervalMs", config.failsafePollIntervalMs);
|
|
11652
|
+
chunk6J4GABF7_cjs.assertTimerMs("reconnectDelayMs", config.reconnectDelayMs);
|
|
11653
|
+
chunk6J4GABF7_cjs.assertTimerMs("maxReconnectDelayMs", config.maxReconnectDelayMs);
|
|
11654
|
+
chunk6J4GABF7_cjs.assertTimerMs("subscriptionRequestTimeoutMs", config.subscriptionRequestTimeoutMs);
|
|
11528
11655
|
if (config.subscriptionRequestTimeoutMs === 0) {
|
|
11529
11656
|
throw new Error("subscriptionRequestTimeoutMs must be greater than 0");
|
|
11530
11657
|
}
|
|
@@ -11749,9 +11876,9 @@ var ContractWatcher = class {
|
|
|
11749
11876
|
this.connectedAt = Date.now();
|
|
11750
11877
|
this.listenLoop().catch((e) => {
|
|
11751
11878
|
if (!this.isWatching || signal?.aborted) return;
|
|
11752
|
-
if (
|
|
11879
|
+
if (chunk6J4GABF7_cjs.isEventSourceError(e)) {
|
|
11753
11880
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
11754
|
-
} else if (!
|
|
11881
|
+
} else if (!chunk6J4GABF7_cjs.isEventSourceUnavailableError(e)) {
|
|
11755
11882
|
console.error(e);
|
|
11756
11883
|
}
|
|
11757
11884
|
this.connectionState = "disconnected";
|
|
@@ -11761,7 +11888,7 @@ var ContractWatcher = class {
|
|
|
11761
11888
|
});
|
|
11762
11889
|
} catch (error) {
|
|
11763
11890
|
if (!this.isWatching || signal?.aborted) return;
|
|
11764
|
-
if (!
|
|
11891
|
+
if (!chunk6J4GABF7_cjs.isEventSourceUnavailableError(error)) {
|
|
11765
11892
|
console.error("ContractWatcher connection failed:", error);
|
|
11766
11893
|
}
|
|
11767
11894
|
this.connectionState = "disconnected";
|
|
@@ -11777,7 +11904,7 @@ var ContractWatcher = class {
|
|
|
11777
11904
|
* few seconds.
|
|
11778
11905
|
*/
|
|
11779
11906
|
reportEventSourceUnavailable(error) {
|
|
11780
|
-
if (!
|
|
11907
|
+
if (!chunk6J4GABF7_cjs.isEventSourceUnavailableError(error)) return false;
|
|
11781
11908
|
if (!this.eventSourceReported) {
|
|
11782
11909
|
this.eventSourceReported = true;
|
|
11783
11910
|
console.warn(
|
|
@@ -11818,7 +11945,7 @@ var ContractWatcher = class {
|
|
|
11818
11945
|
this.config.reconnectDelayMs,
|
|
11819
11946
|
this.config.maxReconnectDelayMs
|
|
11820
11947
|
);
|
|
11821
|
-
const askedFor = Math.min(
|
|
11948
|
+
const askedFor = Math.min(chunk6J4GABF7_cjs.retryAfterMsFromError(failure2) ?? 0, chunk6J4GABF7_cjs.MAX_COOLDOWN_MS);
|
|
11822
11949
|
const floor = Math.max(capped / 2, askedFor);
|
|
11823
11950
|
const ceiling = Math.max(capped, askedFor * 1.5);
|
|
11824
11951
|
return floor + Math.random() * (ceiling - floor);
|
|
@@ -11858,7 +11985,7 @@ var ContractWatcher = class {
|
|
|
11858
11985
|
const now = Date.now();
|
|
11859
11986
|
let current;
|
|
11860
11987
|
try {
|
|
11861
|
-
current = await
|
|
11988
|
+
current = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
11862
11989
|
spendableOnly: true
|
|
11863
11990
|
});
|
|
11864
11991
|
} catch (error) {
|
|
@@ -12140,14 +12267,14 @@ var ContractWatcher = class {
|
|
|
12140
12267
|
const timestamp = Date.now();
|
|
12141
12268
|
if (update.newVtxos?.length) {
|
|
12142
12269
|
this.processSubscriptionVtxos(
|
|
12143
|
-
update.newVtxos.map(
|
|
12270
|
+
update.newVtxos.map(chunk6J4GABF7_cjs.normalizeVtxo),
|
|
12144
12271
|
"vtxo_received",
|
|
12145
12272
|
timestamp
|
|
12146
12273
|
);
|
|
12147
12274
|
}
|
|
12148
12275
|
if (update.spentVtxos?.length) {
|
|
12149
12276
|
this.processSubscriptionVtxos(
|
|
12150
|
-
update.spentVtxos.map(
|
|
12277
|
+
update.spentVtxos.map(chunk6J4GABF7_cjs.normalizeVtxo),
|
|
12151
12278
|
"vtxo_spent",
|
|
12152
12279
|
timestamp
|
|
12153
12280
|
);
|
|
@@ -12172,8 +12299,8 @@ var ContractWatcher = class {
|
|
|
12172
12299
|
continue;
|
|
12173
12300
|
}
|
|
12174
12301
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
12175
|
-
const n =
|
|
12176
|
-
if (
|
|
12302
|
+
const n = chunk6J4GABF7_cjs.normalizeVtxo(vtxo);
|
|
12303
|
+
if (chunk6J4GABF7_cjs.isVtxoSpent(n) || n.isSwept || chunk6J4GABF7_cjs.isPastExpiry(n, now)) continue;
|
|
12177
12304
|
}
|
|
12178
12305
|
let bucket = target.get(vtxo.script);
|
|
12179
12306
|
if (!bucket) {
|
|
@@ -12361,7 +12488,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
12361
12488
|
if (!contract) continue;
|
|
12362
12489
|
try {
|
|
12363
12490
|
const key = contractKey(contract);
|
|
12364
|
-
const handler =
|
|
12491
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
12365
12492
|
const hit = memo?.get(script);
|
|
12366
12493
|
let tapscripts;
|
|
12367
12494
|
if (hit && hit.key === key && hit.handler === handler) {
|
|
@@ -12393,7 +12520,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
12393
12520
|
}
|
|
12394
12521
|
function annotateAgainst(vtxos, byScript, tapscripts = /* @__PURE__ */ new Map()) {
|
|
12395
12522
|
return vtxos.map(
|
|
12396
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
12523
|
+
(vtxo) => extendVirtualCoinForContract(chunk6J4GABF7_cjs.normalizeVtxo(vtxo), byScript, tapscripts)
|
|
12397
12524
|
);
|
|
12398
12525
|
}
|
|
12399
12526
|
var SCAN_MAX_INDEX = 1e4;
|
|
@@ -12442,8 +12569,8 @@ var ContractManager = class _ContractManager {
|
|
|
12442
12569
|
/** Serializes onchain read-modify-writes so a pending spender is never overwritten. */
|
|
12443
12570
|
onchainChain = Promise.resolve();
|
|
12444
12571
|
constructor(config) {
|
|
12445
|
-
|
|
12446
|
-
|
|
12572
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", config.vtxoSyncMaxAgeMs);
|
|
12573
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", config.vtxoSyncOverlapMs);
|
|
12447
12574
|
this.config = { ...config };
|
|
12448
12575
|
if (config.onchainProvider && config.network) {
|
|
12449
12576
|
this.onchainWatcher = new OnchainContractWatcher({
|
|
@@ -12488,12 +12615,12 @@ var ContractManager = class _ContractManager {
|
|
|
12488
12615
|
}
|
|
12489
12616
|
/** @see ContractManagerConfig.vtxoSyncMaxAgeMs — for factory-built managers. */
|
|
12490
12617
|
setVtxoSyncMaxAge(maxAgeMs) {
|
|
12491
|
-
|
|
12618
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", maxAgeMs);
|
|
12492
12619
|
this.config.vtxoSyncMaxAgeMs = maxAgeMs;
|
|
12493
12620
|
}
|
|
12494
12621
|
/** @see ContractManagerConfig.vtxoSyncOverlapMs — for factory-built managers. */
|
|
12495
12622
|
setVtxoSyncOverlap(overlapMs) {
|
|
12496
|
-
|
|
12623
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", overlapMs);
|
|
12497
12624
|
this.config.vtxoSyncOverlapMs = overlapMs;
|
|
12498
12625
|
}
|
|
12499
12626
|
markSyncOnline() {
|
|
@@ -12557,7 +12684,7 @@ var ContractManager = class _ContractManager {
|
|
|
12557
12684
|
if (this.unsupportedContracts.get(contract.script) === key) return true;
|
|
12558
12685
|
if (this.tapscriptMemo.get(contract.script)?.key === key) return false;
|
|
12559
12686
|
try {
|
|
12560
|
-
|
|
12687
|
+
chunkXZHTYYW5_cjs.contractHandlers.get(contract.type)?.createScript(contract.params);
|
|
12561
12688
|
return false;
|
|
12562
12689
|
} catch (err) {
|
|
12563
12690
|
if (!(err instanceof chunkACIQZLWL_cjs.UnsupportedProgramVersionError)) return false;
|
|
@@ -12573,7 +12700,7 @@ var ContractManager = class _ContractManager {
|
|
|
12573
12700
|
this.markSyncOnline();
|
|
12574
12701
|
return void 0;
|
|
12575
12702
|
} catch (err) {
|
|
12576
|
-
if (!
|
|
12703
|
+
if (!chunk6J4GABF7_cjs.isRetryableProviderError(err)) throw err;
|
|
12577
12704
|
this.markSyncDegraded(err);
|
|
12578
12705
|
return err;
|
|
12579
12706
|
}
|
|
@@ -12596,7 +12723,7 @@ var ContractManager = class _ContractManager {
|
|
|
12596
12723
|
try {
|
|
12597
12724
|
await this.scheduleLookAheadDrain();
|
|
12598
12725
|
} catch (err) {
|
|
12599
|
-
if (!
|
|
12726
|
+
if (!chunk6J4GABF7_cjs.isRetryableProviderError(err)) throw err;
|
|
12600
12727
|
this.lookAheadRefillOwed = true;
|
|
12601
12728
|
this.markSyncDegraded(err);
|
|
12602
12729
|
}
|
|
@@ -12659,7 +12786,7 @@ var ContractManager = class _ContractManager {
|
|
|
12659
12786
|
/** No throw: construction returned long ago, so the state is the channel. */
|
|
12660
12787
|
reportBackgroundFailure(stage, err) {
|
|
12661
12788
|
this.markSyncDegraded(err);
|
|
12662
|
-
if (!
|
|
12789
|
+
if (!chunk6J4GABF7_cjs.isRetryableProviderError(err)) {
|
|
12663
12790
|
console.error(`[contracts] background ${stage} failed`, err);
|
|
12664
12791
|
}
|
|
12665
12792
|
}
|
|
@@ -12771,7 +12898,7 @@ var ContractManager = class _ContractManager {
|
|
|
12771
12898
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
12772
12899
|
const to = watermark + lookAhead.size;
|
|
12773
12900
|
const deps = lookAhead.candidateDeps();
|
|
12774
|
-
const handlers =
|
|
12901
|
+
const handlers = chunkXZHTYYW5_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkXZHTYYW5_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
12775
12902
|
const band = /* @__PURE__ */ new Map();
|
|
12776
12903
|
for (let index = from; index <= to; index++) {
|
|
12777
12904
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -12782,7 +12909,7 @@ var ContractManager = class _ContractManager {
|
|
|
12782
12909
|
index,
|
|
12783
12910
|
params: {
|
|
12784
12911
|
...candidate,
|
|
12785
|
-
...
|
|
12912
|
+
...chunkXZHTYYW5_cjs.speculativeReceiveMetadata(descriptor)
|
|
12786
12913
|
}
|
|
12787
12914
|
});
|
|
12788
12915
|
}
|
|
@@ -12841,7 +12968,7 @@ var ContractManager = class _ContractManager {
|
|
|
12841
12968
|
});
|
|
12842
12969
|
for (const entry of pending) entry.catchUpPending = false;
|
|
12843
12970
|
} catch (err) {
|
|
12844
|
-
if (!
|
|
12971
|
+
if (!chunk6J4GABF7_cjs.isRetryableProviderError(err)) throw err;
|
|
12845
12972
|
this.markSyncDegraded(err);
|
|
12846
12973
|
}
|
|
12847
12974
|
}
|
|
@@ -12934,7 +13061,7 @@ var ContractManager = class _ContractManager {
|
|
|
12934
13061
|
return result;
|
|
12935
13062
|
}
|
|
12936
13063
|
async upsertContractRow(params) {
|
|
12937
|
-
const handler =
|
|
13064
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(params.type);
|
|
12938
13065
|
if (!handler) {
|
|
12939
13066
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
12940
13067
|
}
|
|
@@ -13043,7 +13170,7 @@ var ContractManager = class _ContractManager {
|
|
|
13043
13170
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
13044
13171
|
);
|
|
13045
13172
|
}
|
|
13046
|
-
const registered =
|
|
13173
|
+
const registered = chunkXZHTYYW5_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkXZHTYYW5_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
13047
13174
|
const discoverables = [
|
|
13048
13175
|
...registered.filter((h) => h.type === "boarding"),
|
|
13049
13176
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -13174,7 +13301,7 @@ var ContractManager = class _ContractManager {
|
|
|
13174
13301
|
return contracts.filter((contract) => this.isUnsupported(contract));
|
|
13175
13302
|
}
|
|
13176
13303
|
async getContractsWithVtxos(filter, pageSize, options) {
|
|
13177
|
-
|
|
13304
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("maxSyncAgeMs", options?.maxSyncAgeMs);
|
|
13178
13305
|
const contracts = await this.getContracts(filter);
|
|
13179
13306
|
if (this.syncedWithin(
|
|
13180
13307
|
contracts,
|
|
@@ -13282,7 +13409,7 @@ var ContractManager = class _ContractManager {
|
|
|
13282
13409
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
13283
13410
|
const asking = vtxos.filter((vtxo) => {
|
|
13284
13411
|
const contract = byScript.get(vtxo.script);
|
|
13285
|
-
return contract !== void 0 &&
|
|
13412
|
+
return contract !== void 0 && chunkXZHTYYW5_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
13286
13413
|
});
|
|
13287
13414
|
if (asking.length === 0) return refused;
|
|
13288
13415
|
const [tip, walletDescriptorValue] = await Promise.all([
|
|
@@ -13291,7 +13418,7 @@ var ContractManager = class _ContractManager {
|
|
|
13291
13418
|
]);
|
|
13292
13419
|
for (const vtxo of asking) {
|
|
13293
13420
|
const contract = byScript.get(vtxo.script);
|
|
13294
|
-
const handler =
|
|
13421
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
13295
13422
|
if (!handler?.assertSpendableNow) continue;
|
|
13296
13423
|
const context = {
|
|
13297
13424
|
collaborative: true,
|
|
@@ -13301,7 +13428,7 @@ var ContractManager = class _ContractManager {
|
|
|
13301
13428
|
walletDescriptor: walletDescriptorValue,
|
|
13302
13429
|
// `isVirtualCoin` only checks `script`, which every input has; `isCsvSpendable`
|
|
13303
13430
|
// reads `vtxo.status.block_time` unguarded, so require `status` too.
|
|
13304
|
-
vtxo:
|
|
13431
|
+
vtxo: chunk6J4GABF7_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
13305
13432
|
};
|
|
13306
13433
|
try {
|
|
13307
13434
|
await handler.assertSpendableNow(
|
|
@@ -13415,7 +13542,7 @@ var ContractManager = class _ContractManager {
|
|
|
13415
13542
|
const { contractScript, collaborative = true, walletDescriptor, vtxo } = options;
|
|
13416
13543
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
13417
13544
|
if (!contract) return [];
|
|
13418
|
-
const handler =
|
|
13545
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
13419
13546
|
if (!handler) return [];
|
|
13420
13547
|
const script = handler.createScript(contract.params);
|
|
13421
13548
|
const tip = await this.currentChainTip();
|
|
@@ -13437,7 +13564,7 @@ var ContractManager = class _ContractManager {
|
|
|
13437
13564
|
const { contractScript, collaborative = true, walletDescriptor } = options;
|
|
13438
13565
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
13439
13566
|
if (!contract) return [];
|
|
13440
|
-
const handler =
|
|
13567
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
13441
13568
|
if (!handler) return [];
|
|
13442
13569
|
const script = handler.createScript(contract.params);
|
|
13443
13570
|
const context = {
|
|
@@ -13483,7 +13610,7 @@ var ContractManager = class _ContractManager {
|
|
|
13483
13610
|
}
|
|
13484
13611
|
async refreshOutpoints(outpoints) {
|
|
13485
13612
|
if (outpoints.length === 0) return;
|
|
13486
|
-
const { vtxos } = await
|
|
13613
|
+
const { vtxos } = await chunk6J4GABF7_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
13487
13614
|
outpoints
|
|
13488
13615
|
});
|
|
13489
13616
|
if (vtxos.length === 0) return;
|
|
@@ -13546,7 +13673,7 @@ var ContractManager = class _ContractManager {
|
|
|
13546
13673
|
* retarget adds their addresses to the onchain watch. Best-effort: the next sync retries.
|
|
13547
13674
|
*/
|
|
13548
13675
|
async syncNewOnchain(contracts) {
|
|
13549
|
-
const scripts = contracts.filter((c) => c.type ===
|
|
13676
|
+
const scripts = contracts.filter((c) => c.type === chunkXZHTYYW5_cjs.ExecutorContractHandler.type && isOnchainScoped(c)).map((c) => c.script);
|
|
13550
13677
|
if (scripts.length === 0) return;
|
|
13551
13678
|
await this.syncOnchain(scripts).catch(
|
|
13552
13679
|
(e) => console.warn("[contracts] onchain sync of new contracts failed", e)
|
|
@@ -13619,7 +13746,7 @@ var ContractManager = class _ContractManager {
|
|
|
13619
13746
|
...Object.values(pending).map((p) => p.script)
|
|
13620
13747
|
]);
|
|
13621
13748
|
const targets = contracts.filter(
|
|
13622
|
-
(c) =>
|
|
13749
|
+
(c) => chunkXZHTYYW5_cjs.contractHandlers.has(c.type) && (c.state === "active" && isOnchainScoped(c) || owners.has(c.script))
|
|
13623
13750
|
);
|
|
13624
13751
|
const wanted = scripts && new Set(scripts);
|
|
13625
13752
|
const settled = [];
|
|
@@ -13654,7 +13781,7 @@ var ContractManager = class _ContractManager {
|
|
|
13654
13781
|
).catch((e) => console.warn("[contracts] onchain watch failed", e));
|
|
13655
13782
|
}
|
|
13656
13783
|
async syncOnchainContract(contract, onchainProvider, network, pending, tipHeight, prefetched) {
|
|
13657
|
-
|
|
13784
|
+
chunkXZHTYYW5_cjs.contractHandlers.get(contract.type).createScript(contract.params);
|
|
13658
13785
|
const coins = prefetched ?? await onchainProvider.getCoins(onchainAddressOf(contract, network));
|
|
13659
13786
|
const stored = new Map(
|
|
13660
13787
|
(await getVtxosForContract(this.config.walletRepository, contract)).map((v) => [
|
|
@@ -13752,8 +13879,8 @@ var ContractManager = class _ContractManager {
|
|
|
13752
13879
|
const found = /* @__PURE__ */ new Map();
|
|
13753
13880
|
if (!indexerProvider.getUtxos || rows.length === 0) return found;
|
|
13754
13881
|
try {
|
|
13755
|
-
for (let i = 0; i < rows.length; i +=
|
|
13756
|
-
const outpoints = rows.slice(i, i +
|
|
13882
|
+
for (let i = 0; i < rows.length; i += chunk6J4GABF7_cjs.OUTPOINT_QUERY_CHUNK_SIZE) {
|
|
13883
|
+
const outpoints = rows.slice(i, i + chunk6J4GABF7_cjs.OUTPOINT_QUERY_CHUNK_SIZE).map(({ txid, vout }) => ({ txid, vout }));
|
|
13757
13884
|
let pageIndex;
|
|
13758
13885
|
let pages = 0;
|
|
13759
13886
|
do {
|
|
@@ -13763,7 +13890,7 @@ var ContractManager = class _ContractManager {
|
|
|
13763
13890
|
const { utxos, page } = await indexerProvider.getUtxos({
|
|
13764
13891
|
outpoints,
|
|
13765
13892
|
pageIndex,
|
|
13766
|
-
pageSize:
|
|
13893
|
+
pageSize: chunk6J4GABF7_cjs.OUTPOINT_QUERY_CHUNK_SIZE
|
|
13767
13894
|
});
|
|
13768
13895
|
for (const utxo of utxos) found.set(vtxoOutpoint(utxo), utxo);
|
|
13769
13896
|
const more = page && page.current < page.total && page.next > page.current;
|
|
@@ -13771,7 +13898,7 @@ var ContractManager = class _ContractManager {
|
|
|
13771
13898
|
} while (pageIndex !== void 0);
|
|
13772
13899
|
}
|
|
13773
13900
|
} catch (e) {
|
|
13774
|
-
if (e instanceof
|
|
13901
|
+
if (e instanceof chunk7LPT6AYH_cjs.IndexerUtxosUnsupportedError) return found;
|
|
13775
13902
|
console.warn("[contracts] arkd spend lookup failed; using the explorer", e);
|
|
13776
13903
|
return void 0;
|
|
13777
13904
|
}
|
|
@@ -13824,7 +13951,7 @@ var ContractManager = class _ContractManager {
|
|
|
13824
13951
|
break;
|
|
13825
13952
|
}
|
|
13826
13953
|
} catch (err) {
|
|
13827
|
-
if (!
|
|
13954
|
+
if (!chunk6J4GABF7_cjs.isRetryableProviderError(err)) throw err;
|
|
13828
13955
|
this.markSyncDegraded(err);
|
|
13829
13956
|
synced = false;
|
|
13830
13957
|
}
|
|
@@ -13912,7 +14039,7 @@ var ContractManager = class _ContractManager {
|
|
|
13912
14039
|
*/
|
|
13913
14040
|
async reconcilePendingFrontier(contracts) {
|
|
13914
14041
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
13915
|
-
const vtxos = await
|
|
14042
|
+
const vtxos = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(
|
|
13916
14043
|
this.config.indexerProvider,
|
|
13917
14044
|
contracts.map((c) => c.script),
|
|
13918
14045
|
{ pendingOnly: true }
|
|
@@ -13987,7 +14114,7 @@ var ContractManager = class _ContractManager {
|
|
|
13987
14114
|
}
|
|
13988
14115
|
return result;
|
|
13989
14116
|
}
|
|
13990
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
14117
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunk6J4GABF7_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
13991
14118
|
if (contracts.length === 0) {
|
|
13992
14119
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
13993
14120
|
}
|
|
@@ -14003,7 +14130,7 @@ var ContractManager = class _ContractManager {
|
|
|
14003
14130
|
before: syncWindow.before
|
|
14004
14131
|
}
|
|
14005
14132
|
} : {};
|
|
14006
|
-
const vtxos = await
|
|
14133
|
+
const vtxos = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(
|
|
14007
14134
|
this.config.indexerProvider,
|
|
14008
14135
|
contracts.map((c) => c.script),
|
|
14009
14136
|
{ ...windowOpts, pageSize }
|
|
@@ -14110,7 +14237,7 @@ function parseLegacyExpiry(batchExpiry) {
|
|
|
14110
14237
|
if (typeof batchExpiry !== "number" || !Number.isFinite(batchExpiry) || batchExpiry <= 0) {
|
|
14111
14238
|
return {};
|
|
14112
14239
|
}
|
|
14113
|
-
if (batchExpiry >=
|
|
14240
|
+
if (batchExpiry >= chunk6J4GABF7_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
|
|
14114
14241
|
return { expiresAtHeight: batchExpiry / 1e3 };
|
|
14115
14242
|
}
|
|
14116
14243
|
function legacyVtxoFacts(status) {
|
|
@@ -14348,7 +14475,7 @@ function backfillContractWatchState(store) {
|
|
|
14348
14475
|
};
|
|
14349
14476
|
readPage();
|
|
14350
14477
|
}
|
|
14351
|
-
var unspentFlag = (vtxo) =>
|
|
14478
|
+
var unspentFlag = (vtxo) => chunk6J4GABF7_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
|
|
14352
14479
|
function backfillVtxoIndexFields(transaction) {
|
|
14353
14480
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
14354
14481
|
const pageSize = 1e3;
|
|
@@ -14379,7 +14506,7 @@ var DEFAULT_DB_NAME = "arkade-service-worker";
|
|
|
14379
14506
|
var DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS = 1e4;
|
|
14380
14507
|
function normalizeOptions2(pathOrOptions) {
|
|
14381
14508
|
const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
14382
|
-
|
|
14509
|
+
chunk6J4GABF7_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
|
|
14383
14510
|
return {
|
|
14384
14511
|
path: o.path,
|
|
14385
14512
|
activationTimeoutMs: o.activationTimeoutMs ?? DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS
|
|
@@ -14607,7 +14734,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
14607
14734
|
var deserializeVtxo = ({
|
|
14608
14735
|
intentTapLeafScript,
|
|
14609
14736
|
...o
|
|
14610
|
-
}) =>
|
|
14737
|
+
}) => chunk6J4GABF7_cjs.normalizeVtxo({
|
|
14611
14738
|
...o,
|
|
14612
14739
|
createdAt: new Date(o.createdAt),
|
|
14613
14740
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -15007,7 +15134,7 @@ var RestEmulatorProvider = class {
|
|
|
15007
15134
|
serverUrl;
|
|
15008
15135
|
async getInfo() {
|
|
15009
15136
|
const url = `${this.serverUrl}/v1/info`;
|
|
15010
|
-
const response = await
|
|
15137
|
+
const response = await chunk6J4GABF7_cjs.baseFetch(url);
|
|
15011
15138
|
if (!response.ok) {
|
|
15012
15139
|
const errorText2 = await response.text();
|
|
15013
15140
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -15131,7 +15258,7 @@ function arkadeServiceUrl(service) {
|
|
|
15131
15258
|
}
|
|
15132
15259
|
async function resolveArkadeService(service, opts = {}) {
|
|
15133
15260
|
const operatorUrl = arkadeServiceUrl(service);
|
|
15134
|
-
const arkProvider = opts.arkProvider ?? new
|
|
15261
|
+
const arkProvider = opts.arkProvider ?? new chunk6J4GABF7_cjs.RestOperatorProvider(operatorUrl);
|
|
15135
15262
|
const info = opts.info ?? await arkProvider.getInfo();
|
|
15136
15263
|
if ("network" in service && service.network !== info.network) {
|
|
15137
15264
|
throw new Error(
|
|
@@ -15150,7 +15277,7 @@ async function resolveArkadeService(service, opts = {}) {
|
|
|
15150
15277
|
}
|
|
15151
15278
|
return {
|
|
15152
15279
|
arkProvider,
|
|
15153
|
-
indexerProvider: new
|
|
15280
|
+
indexerProvider: new chunk7LPT6AYH_cjs.RestIndexerProvider(operatorUrl),
|
|
15154
15281
|
onchainProvider: new EsploraProvider(esploraUrl),
|
|
15155
15282
|
emulator,
|
|
15156
15283
|
info
|
|
@@ -15171,7 +15298,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
15171
15298
|
try {
|
|
15172
15299
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
15173
15300
|
for (const psbt of txs) {
|
|
15174
|
-
const tx =
|
|
15301
|
+
const tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
15175
15302
|
resolved.set(tx.id, tx.toBytes());
|
|
15176
15303
|
}
|
|
15177
15304
|
} catch (err) {
|
|
@@ -15204,7 +15331,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
15204
15331
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
15205
15332
|
const pending = [];
|
|
15206
15333
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
15207
|
-
if (
|
|
15334
|
+
if (chunk6J4GABF7_cjs.getArkPsbtFields(tx, i, chunk6J4GABF7_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
15208
15335
|
}
|
|
15209
15336
|
if (pending.length === 0) return;
|
|
15210
15337
|
const resolved = await resolvePrevTxs(
|
|
@@ -15213,13 +15340,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
15213
15340
|
onchain
|
|
15214
15341
|
);
|
|
15215
15342
|
for (const i of pending) {
|
|
15216
|
-
|
|
15343
|
+
chunk6J4GABF7_cjs.setArkPsbtField(tx, i, chunk6J4GABF7_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
15217
15344
|
}
|
|
15218
15345
|
}
|
|
15219
15346
|
async function attachPrevoutTxs(tx, source) {
|
|
15220
15347
|
const pending = [];
|
|
15221
15348
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
15222
|
-
if (
|
|
15349
|
+
if (chunk6J4GABF7_cjs.getArkPsbtFields(tx, i, chunk6J4GABF7_cjs.PrevoutTxField).length > 0) continue;
|
|
15223
15350
|
const input = tx.getInput(i);
|
|
15224
15351
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
15225
15352
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -15234,7 +15361,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
15234
15361
|
resolved.set(txids[i], result.value);
|
|
15235
15362
|
}
|
|
15236
15363
|
for (const { index, txid } of pending) {
|
|
15237
|
-
|
|
15364
|
+
chunk6J4GABF7_cjs.setArkPsbtField(tx, index, chunk6J4GABF7_cjs.PrevoutTxField, resolved.get(txid));
|
|
15238
15365
|
}
|
|
15239
15366
|
}
|
|
15240
15367
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -15275,7 +15402,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
15275
15402
|
}
|
|
15276
15403
|
};
|
|
15277
15404
|
for (const vtxo of vtxos) {
|
|
15278
|
-
if (
|
|
15405
|
+
if (chunk6J4GABF7_cjs.isVtxoSpent(vtxo)) continue;
|
|
15279
15406
|
addAssets(owned, vtxo);
|
|
15280
15407
|
if (vtxo.isUnrolled) {
|
|
15281
15408
|
unrolled += vtxo.value;
|
|
@@ -15285,11 +15412,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
15285
15412
|
deprecatedSignerLocked += vtxo.value;
|
|
15286
15413
|
continue;
|
|
15287
15414
|
}
|
|
15288
|
-
if (
|
|
15415
|
+
if (chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15289
15416
|
recoverable += vtxo.value;
|
|
15290
15417
|
continue;
|
|
15291
15418
|
}
|
|
15292
|
-
if (!
|
|
15419
|
+
if (!chunk6J4GABF7_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
15293
15420
|
if (vtxo.isPreconfirmed) {
|
|
15294
15421
|
preconfirmed += vtxo.value;
|
|
15295
15422
|
} else {
|
|
@@ -15567,7 +15694,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
15567
15694
|
if (!newest?.params.pubKey) return baseline;
|
|
15568
15695
|
try {
|
|
15569
15696
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
15570
|
-
return new
|
|
15697
|
+
return new chunkXZHTYYW5_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
15571
15698
|
} catch (e) {
|
|
15572
15699
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
15573
15700
|
return baseline;
|
|
@@ -15599,21 +15726,21 @@ function filterFlatVtxos(vtxos, filter, pendingSpendOutpoints) {
|
|
|
15599
15726
|
if (vtxo.isUnrolled) {
|
|
15600
15727
|
return !!f.withUnrolled;
|
|
15601
15728
|
}
|
|
15602
|
-
if (
|
|
15729
|
+
if (chunk6J4GABF7_cjs.isVtxoSpent(vtxo)) {
|
|
15603
15730
|
return false;
|
|
15604
15731
|
}
|
|
15605
|
-
if (!f.withRecoverable &&
|
|
15732
|
+
if (!f.withRecoverable && chunk6J4GABF7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15606
15733
|
return false;
|
|
15607
15734
|
}
|
|
15608
15735
|
return true;
|
|
15609
15736
|
});
|
|
15610
15737
|
}
|
|
15611
15738
|
async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
15612
|
-
const candidates = inputs.filter(
|
|
15739
|
+
const candidates = inputs.filter(chunk6J4GABF7_cjs.isVirtualCoin).map(chunk6J4GABF7_cjs.normalizeVtxo).filter((v) => !v.isSwept);
|
|
15613
15740
|
if (candidates.length === 0) return inputs;
|
|
15614
|
-
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await
|
|
15741
|
+
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await chunk6J4GABF7_cjs.resolveTimeHeight(wallet.onchainProvider) : { timestamp: /* @__PURE__ */ new Date() };
|
|
15615
15742
|
const suspects = candidates.filter(
|
|
15616
|
-
(v) =>
|
|
15743
|
+
(v) => chunk6J4GABF7_cjs.isPastExpiry(v, now) || v.expiresAtHeight !== void 0 && now.height === void 0
|
|
15617
15744
|
);
|
|
15618
15745
|
if (suspects.length === 0) return inputs;
|
|
15619
15746
|
let sweptNow;
|
|
@@ -15627,12 +15754,12 @@ async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
|
15627
15754
|
);
|
|
15628
15755
|
} catch (e) {
|
|
15629
15756
|
const message = "could not confirm the swept state of expired settlement inputs; retry the settlement";
|
|
15630
|
-
throw
|
|
15757
|
+
throw chunk6J4GABF7_cjs.isRetryableProviderError(e) ? new chunk6J4GABF7_cjs.ProviderUnavailableError(message, { cause: e }) : new Error(message, { cause: e });
|
|
15631
15758
|
}
|
|
15632
15759
|
if (sweptNow.size === 0) return inputs;
|
|
15633
15760
|
return inputs.map((input) => {
|
|
15634
|
-
if (!
|
|
15635
|
-
return { ...
|
|
15761
|
+
if (!chunk6J4GABF7_cjs.isVirtualCoin(input) || !sweptNow.has(`${input.txid}:${input.vout}`)) return input;
|
|
15762
|
+
return { ...chunk6J4GABF7_cjs.normalizeVtxo(input), isSwept: true };
|
|
15636
15763
|
});
|
|
15637
15764
|
}
|
|
15638
15765
|
var PENDING_RECOVERY_REASON = "is past its operator signer's rotation cutoff \u2014 the operator will not co-sign it until it recovers";
|
|
@@ -15647,9 +15774,6 @@ function omittedOutpoints(before, after) {
|
|
|
15647
15774
|
function coinKeys(inputs) {
|
|
15648
15775
|
return inputs.filter((input) => typeof input === "object" && input !== null).map((input) => `${input.txid}:${input.vout}`);
|
|
15649
15776
|
}
|
|
15650
|
-
function outpointSetKey(outpoints) {
|
|
15651
|
-
return outpoints.map(({ txid, vout }) => `${txid}:${vout}`).sort().join("|");
|
|
15652
|
-
}
|
|
15653
15777
|
function assertNoPersistentReservation(inputs, reservations) {
|
|
15654
15778
|
const held = coinKeys(inputs).filter((key) => reservations?.has(key));
|
|
15655
15779
|
if (held.length > 0) throw new VtxoReservedError(held, "held");
|
|
@@ -15959,7 +16083,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
15959
16083
|
async getArkadeReader() {
|
|
15960
16084
|
const indexer = this.indexerProvider;
|
|
15961
16085
|
return {
|
|
15962
|
-
getVtxos: (opts) =>
|
|
16086
|
+
getVtxos: (opts) => chunk6J4GABF7_cjs.getNormalizedVtxos(indexer, opts),
|
|
15963
16087
|
getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
|
|
15964
16088
|
};
|
|
15965
16089
|
}
|
|
@@ -16010,7 +16134,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16010
16134
|
"Pass either `service` or `operatorProvider`/`indexerProvider`/`onchainProvider`, not both"
|
|
16011
16135
|
);
|
|
16012
16136
|
}
|
|
16013
|
-
const arkProvider = callerProvider || new
|
|
16137
|
+
const arkProvider = callerProvider || new chunk6J4GABF7_cjs.RestOperatorProvider(config.service ? arkadeServiceUrl(config.service) : void 0);
|
|
16014
16138
|
let indexerProvider = config.indexerProvider;
|
|
16015
16139
|
if (!indexerProvider && !config.service) {
|
|
16016
16140
|
const derived = extractOperatorProviderUrl(arkProvider);
|
|
@@ -16019,7 +16143,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16019
16143
|
"indexerProvider is required when operatorProvider is provided without a discoverable serverUrl"
|
|
16020
16144
|
);
|
|
16021
16145
|
}
|
|
16022
|
-
indexerProvider = new
|
|
16146
|
+
indexerProvider = new chunk7LPT6AYH_cjs.RestIndexerProvider(derived ?? chunk6TBTL42M_cjs.DEFAULT_ARKADE_SERVER_URL);
|
|
16023
16147
|
}
|
|
16024
16148
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
16025
16149
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -16077,8 +16201,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16077
16201
|
serverPubKey,
|
|
16078
16202
|
csvTimelock: exitTimelock
|
|
16079
16203
|
};
|
|
16080
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
16081
|
-
const boardingTapscript =
|
|
16204
|
+
const offchainTapscript = !delegatePubKey ? new chunkXZHTYYW5_cjs.DefaultVtxo.Script(offchainOptions) : new chunkXZHTYYW5_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
16205
|
+
const boardingTapscript = chunkXZHTYYW5_cjs.BoardingContractHandler.createScript({
|
|
16082
16206
|
pubKey: base.hex.encode(pubKey),
|
|
16083
16207
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
16084
16208
|
csvTimelock: chunk6TBTL42M_cjs.timelockToSequence(boardingTimelock).toString()
|
|
@@ -16296,7 +16420,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16296
16420
|
if (!filter?.withUnrolled) {
|
|
16297
16421
|
logExcludedVtxos(
|
|
16298
16422
|
"getSpendableVtxos",
|
|
16299
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
16423
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunk6J4GABF7_cjs.isVtxoSpent(vtxo)),
|
|
16300
16424
|
[() => UNROLLED_REASON]
|
|
16301
16425
|
);
|
|
16302
16426
|
}
|
|
@@ -16438,7 +16562,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16438
16562
|
]);
|
|
16439
16563
|
const snapshot = fullSnapshot.filter(({ contract }) => !isRecoveryOnlyContract(contract));
|
|
16440
16564
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
16441
|
-
const resolveTxCreatedAt = (txids) =>
|
|
16565
|
+
const resolveTxCreatedAt = (txids) => chunk6J4GABF7_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
16442
16566
|
return buildTransactionHistory(
|
|
16443
16567
|
allVtxos,
|
|
16444
16568
|
boardingTxs,
|
|
@@ -16638,11 +16762,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16638
16762
|
const currentServerPubKey = this.boardingTapscript.options.serverPubKey;
|
|
16639
16763
|
const currentServerSigner = chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(currentServerPubKey));
|
|
16640
16764
|
const signers = /* @__PURE__ */ new Set([currentServerSigner, ...allowedSigners ?? []]);
|
|
16641
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
16765
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
16642
16766
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
16643
16767
|
for (const signer of signers) {
|
|
16644
16768
|
add(
|
|
16645
|
-
new
|
|
16769
|
+
new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
16646
16770
|
pubKey: baselinePubkey,
|
|
16647
16771
|
serverPubKey: base.hex.decode(signer),
|
|
16648
16772
|
csvTimelock: boardingCsv
|
|
@@ -16663,7 +16787,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16663
16787
|
continue;
|
|
16664
16788
|
}
|
|
16665
16789
|
add(
|
|
16666
|
-
c.type === "default" ?
|
|
16790
|
+
c.type === "default" ? chunkXZHTYYW5_cjs.DefaultContractHandler.createScript(c.params) : chunkXZHTYYW5_cjs.BoardingContractHandler.createScript(c.params)
|
|
16667
16791
|
);
|
|
16668
16792
|
} catch (e) {
|
|
16669
16793
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
@@ -16715,7 +16839,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16715
16839
|
tapscripts.map(async (tapscript, i) => {
|
|
16716
16840
|
const contract = contracts.get(scripts[i]);
|
|
16717
16841
|
const spent = new Set(
|
|
16718
|
-
contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(
|
|
16842
|
+
contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(chunk6J4GABF7_cjs.isVtxoSpent).map(vtxoOutpoint) : []
|
|
16719
16843
|
);
|
|
16720
16844
|
const utxos = fetched[i].filter((c) => !spent.has(vtxoOutpoint(c))).map((utxo) => extendCoinWithTapscript(tapscript, utxo));
|
|
16721
16845
|
return {
|
|
@@ -16744,10 +16868,10 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16744
16868
|
timer = setTimeout(
|
|
16745
16869
|
() => reject(
|
|
16746
16870
|
new Error(
|
|
16747
|
-
`Boarding address lookup timed out after ${
|
|
16871
|
+
`Boarding address lookup timed out after ${chunk6J4GABF7_cjs.READ_TIMEOUT_MS}ms`
|
|
16748
16872
|
)
|
|
16749
16873
|
),
|
|
16750
|
-
|
|
16874
|
+
chunk6J4GABF7_cjs.READ_TIMEOUT_MS
|
|
16751
16875
|
);
|
|
16752
16876
|
})
|
|
16753
16877
|
]);
|
|
@@ -16948,7 +17072,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16948
17072
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
16949
17073
|
async fetchPendingTxs() {
|
|
16950
17074
|
const scripts = await this.getWalletScripts();
|
|
16951
|
-
const vtxos = await
|
|
17075
|
+
const vtxos = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
16952
17076
|
return vtxos.filter(
|
|
16953
17077
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
16954
17078
|
).map((_) => _.arkTxId);
|
|
@@ -16980,7 +17104,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16980
17104
|
for (const contract of contracts) {
|
|
16981
17105
|
if (map.has(contract.script)) continue;
|
|
16982
17106
|
if (contract.type === "executor" && contract.params.template !== "renewal") continue;
|
|
16983
|
-
const handler =
|
|
17107
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
16984
17108
|
if (handler) {
|
|
16985
17109
|
const script = handler.createScript(contract.params);
|
|
16986
17110
|
if (contract.type === "executor" && base.hex.encode(script.pkScript) !== contract.script) {
|
|
@@ -17107,8 +17231,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17107
17231
|
});
|
|
17108
17232
|
try {
|
|
17109
17233
|
const baselinePubkey = await baselinePubkeyPromise;
|
|
17110
|
-
const delegatePubKeys =
|
|
17111
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
17234
|
+
const delegatePubKeys = chunkXZHTYYW5_cjs.delegateDiscoveryKeys({
|
|
17235
|
+
delegatePubKey: this.offchainTapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0,
|
|
17112
17236
|
retiredDelegatePubKeys: this.retiredDelegateKeys()
|
|
17113
17237
|
});
|
|
17114
17238
|
const baselineSigners = [
|
|
@@ -17120,7 +17244,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17120
17244
|
for (const serverPubKey of baselineSigners) {
|
|
17121
17245
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
17122
17246
|
const csvTimelockStr = chunk6TBTL42M_cjs.timelockToSequence(csvTimelock).toString();
|
|
17123
|
-
const defaultScript = new
|
|
17247
|
+
const defaultScript = new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
17124
17248
|
pubKey: baselinePubkey,
|
|
17125
17249
|
serverPubKey,
|
|
17126
17250
|
csvTimelock
|
|
@@ -17141,7 +17265,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17141
17265
|
});
|
|
17142
17266
|
}
|
|
17143
17267
|
for (const delegatePubKey of delegatePubKeys) {
|
|
17144
|
-
const delegateScript = new
|
|
17268
|
+
const delegateScript = new chunkXZHTYYW5_cjs.DelegateVtxo.Script({
|
|
17145
17269
|
pubKey: baselinePubkey,
|
|
17146
17270
|
serverPubKey,
|
|
17147
17271
|
delegatePubKey,
|
|
@@ -17165,9 +17289,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17165
17289
|
}
|
|
17166
17290
|
}
|
|
17167
17291
|
}
|
|
17168
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
17292
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
17169
17293
|
for (const serverPubKey of baselineSigners) {
|
|
17170
|
-
const baselineBoarding = new
|
|
17294
|
+
const baselineBoarding = new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
17171
17295
|
pubKey: baselinePubkey,
|
|
17172
17296
|
serverPubKey,
|
|
17173
17297
|
csvTimelock: boardingCsvTimelock
|
|
@@ -17400,7 +17524,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17400
17524
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
17401
17525
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
17402
17526
|
csvTimelocks: this.walletContractTimelocks,
|
|
17403
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
17527
|
+
delegatePubKey: this.offchainTapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0,
|
|
17404
17528
|
retiredDelegatePubKeys: this.retiredDelegateKeys()
|
|
17405
17529
|
};
|
|
17406
17530
|
}
|
|
@@ -17542,7 +17666,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17542
17666
|
this._executorBoardUnsub = eager.onContractEvent((event) => {
|
|
17543
17667
|
if (event.type !== "vtxo_received" || !isContractVtxoEvent(event)) return;
|
|
17544
17668
|
const { type, params } = event.contract;
|
|
17545
|
-
if (type !==
|
|
17669
|
+
if (type !== chunkXZHTYYW5_cjs.ExecutorContractHandler.type || params.template !== "renewal") return;
|
|
17546
17670
|
this.queueExecutorBoardRotation(params.owner);
|
|
17547
17671
|
});
|
|
17548
17672
|
}
|
|
@@ -17628,7 +17752,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17628
17752
|
try {
|
|
17629
17753
|
const displayed = base.hex.encode(this._boardingTapscript.options.pubKey);
|
|
17630
17754
|
const rows = await collectContracts(this.contractRepository, {
|
|
17631
|
-
type: [
|
|
17755
|
+
type: [chunkXZHTYYW5_cjs.ExecutorContractHandler.type]
|
|
17632
17756
|
});
|
|
17633
17757
|
for (const row of rows) {
|
|
17634
17758
|
if (row.params.template !== "renewal") continue;
|
|
@@ -17731,7 +17855,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17731
17855
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
17732
17856
|
const persisted = row?.metadata?.signingDescriptor;
|
|
17733
17857
|
if (typeof persisted === "string") return persisted;
|
|
17734
|
-
return
|
|
17858
|
+
return chunkXZHTYYW5_cjs.identityDescriptor(this.identity);
|
|
17735
17859
|
}
|
|
17736
17860
|
/**
|
|
17737
17861
|
* Build, persist and shape one address of `type` owned by `descriptor`. The descriptor is the
|
|
@@ -17741,7 +17865,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17741
17865
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
17742
17866
|
if (type === "boarding") {
|
|
17743
17867
|
const built2 = this.buildBoardingContract(
|
|
17744
|
-
|
|
17868
|
+
chunkXZHTYYW5_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
17745
17869
|
descriptor,
|
|
17746
17870
|
tagSource
|
|
17747
17871
|
);
|
|
@@ -17778,11 +17902,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17778
17902
|
* (offchain analogue: {@link buildReceiveContract}).
|
|
17779
17903
|
*/
|
|
17780
17904
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
17781
|
-
const tapscript = new
|
|
17905
|
+
const tapscript = new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
17782
17906
|
...this._boardingTapscript.options,
|
|
17783
17907
|
pubKey
|
|
17784
17908
|
});
|
|
17785
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
17909
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
17786
17910
|
return {
|
|
17787
17911
|
tapscript,
|
|
17788
17912
|
params: {
|
|
@@ -17796,7 +17920,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17796
17920
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
17797
17921
|
state: "active",
|
|
17798
17922
|
metadata: {
|
|
17799
|
-
...tagSource && { source:
|
|
17923
|
+
...tagSource && { source: chunkXZHTYYW5_cjs.WALLET_RECEIVE_SOURCE },
|
|
17800
17924
|
signingDescriptor: descriptor
|
|
17801
17925
|
}
|
|
17802
17926
|
}
|
|
@@ -17818,7 +17942,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17818
17942
|
if (this._hdProvider) {
|
|
17819
17943
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
17820
17944
|
}
|
|
17821
|
-
return
|
|
17945
|
+
return chunkXZHTYYW5_cjs.identityDescriptor(this.identity);
|
|
17822
17946
|
}
|
|
17823
17947
|
/**
|
|
17824
17948
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -17924,21 +18048,21 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17924
18048
|
]);
|
|
17925
18049
|
const [currentOffchainRow] = offchainRows2;
|
|
17926
18050
|
const [currentBoardingRow] = boardingRows;
|
|
17927
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
18051
|
+
const newOffchain = this.offchainTapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? new chunkXZHTYYW5_cjs.DelegateVtxo.Script({
|
|
17928
18052
|
...this.offchainTapscript.options,
|
|
17929
18053
|
serverPubKey: xonly
|
|
17930
|
-
}) : new
|
|
18054
|
+
}) : new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
17931
18055
|
...this.offchainTapscript.options,
|
|
17932
18056
|
serverPubKey: xonly
|
|
17933
18057
|
});
|
|
17934
|
-
const newBoarding = new
|
|
18058
|
+
const newBoarding = new chunkXZHTYYW5_cjs.DefaultVtxo.Script({
|
|
17935
18059
|
...this._boardingTapscript.options,
|
|
17936
18060
|
serverPubKey: xonly
|
|
17937
18061
|
});
|
|
17938
18062
|
const offchainCsv = chunk6TBTL42M_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
17939
18063
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
17940
18064
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
17941
|
-
if (newOffchain instanceof
|
|
18065
|
+
if (newOffchain instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script) {
|
|
17942
18066
|
await manager.createContract({
|
|
17943
18067
|
type: "delegate",
|
|
17944
18068
|
params: {
|
|
@@ -17966,7 +18090,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17966
18090
|
metadata: currentOffchainRow?.metadata
|
|
17967
18091
|
});
|
|
17968
18092
|
}
|
|
17969
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
18093
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
17970
18094
|
await manager.createContract({
|
|
17971
18095
|
type: "boarding",
|
|
17972
18096
|
params: {
|
|
@@ -18000,14 +18124,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18000
18124
|
_restoreInFlight;
|
|
18001
18125
|
_addPendingSpends(inputs) {
|
|
18002
18126
|
for (const input of inputs) {
|
|
18003
|
-
if (
|
|
18127
|
+
if (chunk6J4GABF7_cjs.isVirtualCoin(input)) {
|
|
18004
18128
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
18005
18129
|
}
|
|
18006
18130
|
}
|
|
18007
18131
|
}
|
|
18008
18132
|
_removePendingSpends(inputs) {
|
|
18009
18133
|
for (const input of inputs) {
|
|
18010
|
-
if (
|
|
18134
|
+
if (chunk6J4GABF7_cjs.isVirtualCoin(input)) {
|
|
18011
18135
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
18012
18136
|
}
|
|
18013
18137
|
}
|
|
@@ -18057,6 +18181,16 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18057
18181
|
// Own queue, not the tx lock: a settle holds that for a whole batch round. The pending and
|
|
18058
18182
|
// held sets already order a hold against a spend.
|
|
18059
18183
|
reservationQueue = Promise.resolve();
|
|
18184
|
+
requireReservationRepository() {
|
|
18185
|
+
const repository = this.reservationRepository;
|
|
18186
|
+
if (!repository) throw new Error("VTXO reservation repository is required");
|
|
18187
|
+
if (repository.version !== 2 || typeof repository.deleteReservationIfMatches !== "function") {
|
|
18188
|
+
throw new Error(
|
|
18189
|
+
"VTXO reservation repository version 2 with atomic release is required"
|
|
18190
|
+
);
|
|
18191
|
+
}
|
|
18192
|
+
return repository;
|
|
18193
|
+
}
|
|
18060
18194
|
withReservationWrite(fn) {
|
|
18061
18195
|
const run = this.reservationQueue.then(fn);
|
|
18062
18196
|
this.reservationQueue = run.catch(() => void 0);
|
|
@@ -18069,13 +18203,13 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18069
18203
|
}
|
|
18070
18204
|
/** Restored before automatic spending. Reusing an owner id must name the same inputs. */
|
|
18071
18205
|
async reserveVtxosPersistently(outpoints, id) {
|
|
18072
|
-
|
|
18206
|
+
const repository = this.requireReservationRepository();
|
|
18073
18207
|
if (typeof id !== "string" || !id) throw new Error("Reservation id is required");
|
|
18074
18208
|
const snapshot = outpoints.map(({ txid, vout }) => ({ txid, vout }));
|
|
18075
18209
|
await this.withReservationWrite(async () => {
|
|
18076
18210
|
const existing = this.persistentReservations.get(id);
|
|
18077
18211
|
if (existing) {
|
|
18078
|
-
if (
|
|
18212
|
+
if (reservationOutpointSetKey(existing) !== reservationOutpointSetKey(snapshot)) {
|
|
18079
18213
|
throw new Error("Reservation id already holds different inputs");
|
|
18080
18214
|
}
|
|
18081
18215
|
return;
|
|
@@ -18085,7 +18219,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18085
18219
|
this.persistentReservedOutpoints.add(`${txid}:${vout}`);
|
|
18086
18220
|
try {
|
|
18087
18221
|
await assertNoIntentLockedInputs(snapshot, this.intentRepository);
|
|
18088
|
-
await
|
|
18222
|
+
await repository.saveReservation({ id, outpoints: snapshot });
|
|
18089
18223
|
this.persistentReservations.set(id, snapshot);
|
|
18090
18224
|
} catch (error) {
|
|
18091
18225
|
hold.release();
|
|
@@ -18101,11 +18235,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18101
18235
|
* newer hold under its id alone.
|
|
18102
18236
|
*/
|
|
18103
18237
|
async releaseVtxoReservation(id, expected) {
|
|
18104
|
-
|
|
18238
|
+
const repository = this.requireReservationRepository();
|
|
18105
18239
|
await this.withReservationWrite(async () => {
|
|
18106
18240
|
const outpoints = this.persistentReservations.get(id) ?? [];
|
|
18107
|
-
if (expected &&
|
|
18108
|
-
|
|
18241
|
+
if (expected && reservationOutpointSetKey(outpoints) !== reservationOutpointSetKey(expected))
|
|
18242
|
+
return;
|
|
18243
|
+
if (!await repository.deleteReservationIfMatches(id, expected ?? outpoints)) return;
|
|
18109
18244
|
this.persistentReservations.delete(id);
|
|
18110
18245
|
const stillNamed = new Set(
|
|
18111
18246
|
[...this.persistentReservations.values()].flat().map(({ txid, vout }) => `${txid}:${vout}`)
|
|
@@ -18155,7 +18290,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18155
18290
|
if (clashing.length > 0) throw new VtxoReservedError(clashing, "in-flight");
|
|
18156
18291
|
}
|
|
18157
18292
|
_assertNotHeld(inputs) {
|
|
18158
|
-
const held = coinKeys(inputs.filter(
|
|
18293
|
+
const held = coinKeys(inputs.filter(chunk6J4GABF7_cjs.isVirtualCoin)).filter(
|
|
18159
18294
|
(key) => this._heldOutpoints.has(key)
|
|
18160
18295
|
);
|
|
18161
18296
|
if (held.length > 0) throw new VtxoReservedError(held, "held");
|
|
@@ -18195,15 +18330,15 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18195
18330
|
*/
|
|
18196
18331
|
async executorWatchTemplates() {
|
|
18197
18332
|
const rows = await collectContracts(this.contractRepository, {
|
|
18198
|
-
type: [
|
|
18333
|
+
type: [chunkXZHTYYW5_cjs.ExecutorContractHandler.type]
|
|
18199
18334
|
});
|
|
18200
18335
|
const boarding = /* @__PURE__ */ new Map();
|
|
18201
18336
|
const renewalOnly = /* @__PURE__ */ new Map();
|
|
18202
18337
|
const boardingBases = /* @__PURE__ */ new Set();
|
|
18203
18338
|
for (const row of rows) {
|
|
18204
18339
|
try {
|
|
18205
|
-
const p =
|
|
18206
|
-
const keys =
|
|
18340
|
+
const p = chunkXZHTYYW5_cjs.ExecutorContractHandler.deserializeParams(row.params);
|
|
18341
|
+
const keys = chunkXZHTYYW5_cjs.executorKeysOf(p);
|
|
18207
18342
|
const base = JSON.stringify([keys, p.exitDelay, p.renewalWindow, p.maxFee]);
|
|
18208
18343
|
const params = {
|
|
18209
18344
|
exitDelay: p.exitDelay,
|
|
@@ -18233,12 +18368,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18233
18368
|
const hd = provider !== void 0;
|
|
18234
18369
|
const [manager, staticDescriptor, arkInfo, executorWatches] = await Promise.all([
|
|
18235
18370
|
this.getContractManager(),
|
|
18236
|
-
hd ? void 0 :
|
|
18371
|
+
hd ? void 0 : chunkXZHTYYW5_cjs.identityDescriptor(this.identity),
|
|
18237
18372
|
this.arkProvider.getInfo(),
|
|
18238
18373
|
this.executorWatchTemplates()
|
|
18239
18374
|
]);
|
|
18240
18375
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
18241
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
18376
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkXZHTYYW5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
18242
18377
|
const currentSignerPubKey = chunk6TBTL42M_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
18243
18378
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
18244
18379
|
(s) => chunk6TBTL42M_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
@@ -18253,7 +18388,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18253
18388
|
deprecatedSignerPubKeys,
|
|
18254
18389
|
csvTimelocks: this.walletContractTimelocks,
|
|
18255
18390
|
// Boarding-exit CSV, distinct from the unilateral-exit matrix.
|
|
18256
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
18391
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
18257
18392
|
delegatePubKey,
|
|
18258
18393
|
// Raw hex: the lookup skips malformed signers rather than failing the restore.
|
|
18259
18394
|
retiredDelegatePubKeys: this.executorProvider ? chunk6TBTL42M_cjs.retiredDelegatePubKeys(this.network, [
|
|
@@ -18292,6 +18427,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18292
18427
|
settlementConfig;
|
|
18293
18428
|
_concurrentSpending = false;
|
|
18294
18429
|
_submitsAwaitingFinalize = 0;
|
|
18430
|
+
pendingTxRecoveryDeferred = false;
|
|
18431
|
+
/** @internal */
|
|
18432
|
+
get hasDeferredPendingTxRecovery() {
|
|
18433
|
+
return this.pendingTxRecoveryDeferred;
|
|
18434
|
+
}
|
|
18295
18435
|
/** @see WalletConfig.concurrentSpending */
|
|
18296
18436
|
get concurrentSpending() {
|
|
18297
18437
|
return this._concurrentSpending;
|
|
@@ -18303,10 +18443,18 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18303
18443
|
async getArkadeBroadcaster() {
|
|
18304
18444
|
const ark = this.arkProvider;
|
|
18305
18445
|
return {
|
|
18306
|
-
submitTx: (signedArkTx, checkpointTxs) =>
|
|
18446
|
+
submitTx: async (signedArkTx, checkpointTxs) => {
|
|
18447
|
+
this.assertNoDeferredPendingTxRecovery();
|
|
18448
|
+
return ark.submitTx(signedArkTx, checkpointTxs);
|
|
18449
|
+
},
|
|
18307
18450
|
finalizeTx: (arkTxid, finalCheckpointTxs) => ark.finalizeTx(arkTxid, finalCheckpointTxs)
|
|
18308
18451
|
};
|
|
18309
18452
|
}
|
|
18453
|
+
assertNoDeferredPendingTxRecovery() {
|
|
18454
|
+
if (this.pendingTxRecoveryDeferred) {
|
|
18455
|
+
throw new Error("Pending Arkade transaction recovery is required before sending");
|
|
18456
|
+
}
|
|
18457
|
+
}
|
|
18310
18458
|
get assetManager() {
|
|
18311
18459
|
this._walletAssetManager ??= new AssetManager(this);
|
|
18312
18460
|
return this._walletAssetManager;
|
|
@@ -18656,7 +18804,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18656
18804
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
18657
18805
|
break;
|
|
18658
18806
|
}
|
|
18659
|
-
const inputFee = estimator.evalOffchainInput(
|
|
18807
|
+
const inputFee = estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(vtxo));
|
|
18660
18808
|
if (inputFee.satoshis >= vtxo.value) {
|
|
18661
18809
|
continue;
|
|
18662
18810
|
}
|
|
@@ -18780,11 +18928,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18780
18928
|
]);
|
|
18781
18929
|
let intentTxId;
|
|
18782
18930
|
try {
|
|
18783
|
-
intentTxId =
|
|
18931
|
+
intentTxId = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(intent.proof)).id;
|
|
18784
18932
|
} catch {
|
|
18785
18933
|
intentTxId = params.inputs.map((i) => `${i.txid}:${i.vout}`).sort().join("|");
|
|
18786
18934
|
}
|
|
18787
|
-
const settleInputVtxos = params.inputs.filter(
|
|
18935
|
+
const settleInputVtxos = params.inputs.filter(chunk6J4GABF7_cjs.isVirtualCoin);
|
|
18788
18936
|
const contractManager = await this.getContractManager();
|
|
18789
18937
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
18790
18938
|
await contractManager.assertSpendableNow?.(
|
|
@@ -18795,7 +18943,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18795
18943
|
assertNoPersistentReservation(params.inputs, this.persistentReservedOutpoints);
|
|
18796
18944
|
if (picked) this._assertNotHeld(params.inputs);
|
|
18797
18945
|
this._addPendingSpends(params.inputs);
|
|
18798
|
-
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !
|
|
18946
|
+
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !chunk6J4GABF7_cjs.isVirtualCoin(i))) : [];
|
|
18799
18947
|
for (const key of boardingKeys) this._pendingSpendOutpoints.add(key);
|
|
18800
18948
|
const settlingKeys = params.inputs.map((i) => `${i.txid}:${i.vout}`);
|
|
18801
18949
|
for (const key of settlingKeys) this._settlingOutpoints.add(key);
|
|
@@ -18913,7 +19061,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18913
19061
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
18914
19062
|
if (!this._descriptorProvider) return;
|
|
18915
19063
|
const consumedBoarding = inputs.some(
|
|
18916
|
-
(input) => typeof input !== "string" && !
|
|
19064
|
+
(input) => typeof input !== "string" && !chunk6J4GABF7_cjs.isVirtualCoin(input)
|
|
18917
19065
|
);
|
|
18918
19066
|
if (!consumedBoarding) return;
|
|
18919
19067
|
const rotation = this.onBoardChain(async () => {
|
|
@@ -18927,7 +19075,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18927
19075
|
}
|
|
18928
19076
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, expectedRecipients, connectorsGraph, validatedCommitmentTxid) {
|
|
18929
19077
|
const signedForfeits = [];
|
|
18930
|
-
let settlementPsbt =
|
|
19078
|
+
let settlementPsbt = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
18931
19079
|
assertFinalCommitmentMatchesValidated(
|
|
18932
19080
|
settlementPsbt,
|
|
18933
19081
|
validatedCommitmentTxid,
|
|
@@ -18940,7 +19088,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18940
19088
|
let connectorIndex = 0;
|
|
18941
19089
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
18942
19090
|
for (const input of inputs) {
|
|
18943
|
-
if (!
|
|
19091
|
+
if (!chunk6J4GABF7_cjs.isVirtualCoin(input)) {
|
|
18944
19092
|
let matched = false;
|
|
18945
19093
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
18946
19094
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -18979,7 +19127,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18979
19127
|
}
|
|
18980
19128
|
continue;
|
|
18981
19129
|
}
|
|
18982
|
-
if (!
|
|
19130
|
+
if (!chunk6J4GABF7_cjs.requiresForfeit(input) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
18983
19131
|
continue;
|
|
18984
19132
|
}
|
|
18985
19133
|
if (connectorsLeaves.length === 0) {
|
|
@@ -19106,7 +19254,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19106
19254
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
19107
19255
|
return { skip: true };
|
|
19108
19256
|
}
|
|
19109
|
-
const commitmentTx =
|
|
19257
|
+
const commitmentTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(
|
|
19110
19258
|
base.base64.decode(event.unsignedCommitmentTx)
|
|
19111
19259
|
);
|
|
19112
19260
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
@@ -19196,9 +19344,9 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19196
19344
|
...existing ?? {},
|
|
19197
19345
|
proofTxId: intentTxId,
|
|
19198
19346
|
registerProof: intent.proof,
|
|
19199
|
-
registerProofMessage:
|
|
19347
|
+
registerProofMessage: chunk6J4GABF7_cjs.Proof.encodeMessage(intent.message),
|
|
19200
19348
|
deleteProof: deleteIntent.proof,
|
|
19201
|
-
deleteProofMessage:
|
|
19349
|
+
deleteProofMessage: chunk6J4GABF7_cjs.Proof.encodeMessage(deleteIntent.message),
|
|
19202
19350
|
proofInputs: inputs.map((i) => ({
|
|
19203
19351
|
txid: i.txid,
|
|
19204
19352
|
vout: i.vout
|
|
@@ -19230,7 +19378,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19230
19378
|
}
|
|
19231
19379
|
/** @see IWallet.cosignOnchainTx */
|
|
19232
19380
|
async cosignOnchainTx(psbt) {
|
|
19233
|
-
const tx = typeof psbt === "string" ?
|
|
19381
|
+
const tx = typeof psbt === "string" ? chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)) : psbt;
|
|
19234
19382
|
return this._withTxLock(async () => {
|
|
19235
19383
|
await (await this.getContractManager()).syncOnchain();
|
|
19236
19384
|
return this._cosignOnchainTxImpl(tx);
|
|
@@ -19296,7 +19444,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19296
19444
|
if (reasons.length > 0) throw new OnchainCosignPreflightError(reasons.join("; "));
|
|
19297
19445
|
}
|
|
19298
19446
|
const feeRate = await providerFeeRate(this.onchainProvider);
|
|
19299
|
-
const tx = new
|
|
19447
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 2 });
|
|
19300
19448
|
if (sweepTo) {
|
|
19301
19449
|
const swept = candidates.slice(0, MAX_COSIGN_INPUTS);
|
|
19302
19450
|
for (const { coin } of swept) {
|
|
@@ -19357,7 +19505,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19357
19505
|
continue;
|
|
19358
19506
|
}
|
|
19359
19507
|
const { coin, contract, script } = mine;
|
|
19360
|
-
const path =
|
|
19508
|
+
const path = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type).selectPath(script, contract, {
|
|
19361
19509
|
collaborative: true,
|
|
19362
19510
|
currentTime: Date.now(),
|
|
19363
19511
|
blockHeight: tip.height,
|
|
@@ -19407,7 +19555,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19407
19555
|
onchainProvider: this.onchainProvider
|
|
19408
19556
|
});
|
|
19409
19557
|
} catch (e) {
|
|
19410
|
-
if (e instanceof
|
|
19558
|
+
if (e instanceof chunk6J4GABF7_cjs.OnchainCosignAmbiguousError || isCosignRejectedAfterSigning(e)) {
|
|
19411
19559
|
await markPending(signed.id);
|
|
19412
19560
|
}
|
|
19413
19561
|
throw e;
|
|
@@ -19427,7 +19575,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19427
19575
|
this.lockedOutpoints(),
|
|
19428
19576
|
this.onchainCoins(manager)
|
|
19429
19577
|
]);
|
|
19430
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
19578
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkXZHTYYW5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
19431
19579
|
return coins.filter(
|
|
19432
19580
|
({ coin, contract }) => !locked.has(vtxoOutpoint(coin)) && needsOnchainSweep(coin, contract, boardingCsv, tip, this._cosignMarginBlocks)
|
|
19433
19581
|
).slice(0, MAX_COSIGN_INPUTS).map(({ coin }) => ({ txid: coin.txid, vout: coin.vout }));
|
|
@@ -19439,8 +19587,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19439
19587
|
unspentOnly: true
|
|
19440
19588
|
});
|
|
19441
19589
|
return snapshot.flatMap(({ contract, vtxos }) => {
|
|
19442
|
-
const handler =
|
|
19443
|
-
const coins = vtxos.filter((v) => v.isUnrolled && !
|
|
19590
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
19591
|
+
const coins = vtxos.filter((v) => v.isUnrolled && !chunk6J4GABF7_cjs.isVtxoSpent(v));
|
|
19444
19592
|
if (!handler || coins.length === 0) return [];
|
|
19445
19593
|
const script = handler.createScript(contract.params);
|
|
19446
19594
|
return coins.map((coin) => ({ coin, contract, script }));
|
|
@@ -19450,7 +19598,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19450
19598
|
try {
|
|
19451
19599
|
return await this.arkProvider.registerIntent(intent);
|
|
19452
19600
|
} catch (error) {
|
|
19453
|
-
if (error instanceof
|
|
19601
|
+
if (error instanceof chunk6J4GABF7_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
19454
19602
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
19455
19603
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
19456
19604
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -19466,7 +19614,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19466
19614
|
expire_at: 0,
|
|
19467
19615
|
cosigners_public_keys: cosignerPubKeys
|
|
19468
19616
|
};
|
|
19469
|
-
const proof =
|
|
19617
|
+
const proof = chunk6J4GABF7_cjs.Proof.create(message, coins, outputs);
|
|
19470
19618
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19471
19619
|
return {
|
|
19472
19620
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19478,7 +19626,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19478
19626
|
type: "delete",
|
|
19479
19627
|
expire_at: 0
|
|
19480
19628
|
};
|
|
19481
|
-
const proof =
|
|
19629
|
+
const proof = chunk6J4GABF7_cjs.Proof.create(message, coins, []);
|
|
19482
19630
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19483
19631
|
return {
|
|
19484
19632
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19490,7 +19638,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19490
19638
|
type: "get-pending-tx",
|
|
19491
19639
|
expire_at: 0
|
|
19492
19640
|
};
|
|
19493
|
-
const proof =
|
|
19641
|
+
const proof = chunk6J4GABF7_cjs.Proof.create(message, coins, []);
|
|
19494
19642
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19495
19643
|
return {
|
|
19496
19644
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19504,20 +19652,52 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19504
19652
|
* @returns Array of transaction IDs that were finalized
|
|
19505
19653
|
*/
|
|
19506
19654
|
async finalizePendingTxs(vtxos) {
|
|
19655
|
+
return this.finalizePendingTxsImpl(vtxos);
|
|
19656
|
+
}
|
|
19657
|
+
/** @internal */
|
|
19658
|
+
async deferPendingTxRecovery() {
|
|
19659
|
+
this.pendingTxRecoveryDeferred = await this.hasPendingTxFlag();
|
|
19660
|
+
return this.pendingTxRecoveryDeferred;
|
|
19661
|
+
}
|
|
19662
|
+
/** @internal */
|
|
19663
|
+
async resumeDeferredPendingTxs(isCurrent) {
|
|
19664
|
+
const info = await this.getOperatorInfo({ requireLive: true });
|
|
19665
|
+
if (info.network !== this.network.name) {
|
|
19666
|
+
throw new Error("Operator network changed while recovering pending transactions");
|
|
19667
|
+
}
|
|
19668
|
+
await this._withTxLock(async () => {
|
|
19669
|
+
if (!isCurrent()) return;
|
|
19670
|
+
try {
|
|
19671
|
+
await this.finalizePendingTxsImpl(void 0, { info, isCurrent });
|
|
19672
|
+
} catch (error) {
|
|
19673
|
+
if (!chunk6J4GABF7_cjs.isTransientOperatorError(error) && isCurrent()) {
|
|
19674
|
+
this.pendingTxRecoveryDeferred = false;
|
|
19675
|
+
}
|
|
19676
|
+
throw error;
|
|
19677
|
+
}
|
|
19678
|
+
if (isCurrent()) this.pendingTxRecoveryDeferred = false;
|
|
19679
|
+
});
|
|
19680
|
+
}
|
|
19681
|
+
async finalizePendingTxsImpl(vtxos, recovery) {
|
|
19682
|
+
const isCurrent = recovery?.isCurrent ?? (() => true);
|
|
19507
19683
|
const hasPending = await this.hasPendingTxFlag();
|
|
19508
|
-
if (!hasPending) {
|
|
19684
|
+
if (!hasPending || !isCurrent()) {
|
|
19685
|
+
if (!hasPending && isCurrent()) this.pendingTxRecoveryDeferred = false;
|
|
19509
19686
|
return { finalized: [], pending: [] };
|
|
19510
19687
|
}
|
|
19511
19688
|
if (!vtxos || vtxos.length === 0) {
|
|
19512
19689
|
const scriptMap = await this.getScriptMap();
|
|
19690
|
+
if (!isCurrent()) return { finalized: [], pending: [] };
|
|
19513
19691
|
const allExtended = [];
|
|
19514
|
-
const fetchedVtxos = await
|
|
19692
|
+
const fetchedVtxos = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
19515
19693
|
...scriptMap.keys()
|
|
19516
19694
|
]);
|
|
19517
19695
|
for (const vtxo of fetchedVtxos) {
|
|
19518
19696
|
const vtxoScript = scriptMap.get(vtxo.script);
|
|
19519
19697
|
if (!vtxoScript) continue;
|
|
19520
|
-
if (
|
|
19698
|
+
if (recovery) {
|
|
19699
|
+
if (isSubdust(vtxo, this.dustAmount) || vtxo.isUnrolled) continue;
|
|
19700
|
+
} else if (!vtxo.isSpent && !(vtxo.isPreconfirmed && !vtxo.isSwept)) {
|
|
19521
19701
|
continue;
|
|
19522
19702
|
}
|
|
19523
19703
|
allExtended.push({
|
|
@@ -19536,27 +19716,32 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19536
19716
|
for (let i = 0; i < vtxos.length; i += MAX_INPUTS_PER_PROOF) {
|
|
19537
19717
|
batches.push(vtxos.slice(i, i + MAX_INPUTS_PER_PROOF));
|
|
19538
19718
|
}
|
|
19539
|
-
const unrollCandidates = this.checkpointUnrollCandidates(
|
|
19719
|
+
const unrollCandidates = this.checkpointUnrollCandidates(
|
|
19720
|
+
recovery?.info ?? await this.arkProvider.getInfo()
|
|
19721
|
+
);
|
|
19722
|
+
if (!isCurrent()) return { finalized: [], pending: [] };
|
|
19540
19723
|
const checkpointInputs = vtxos.map((vtxo) => ({
|
|
19541
19724
|
...vtxo,
|
|
19542
19725
|
tapLeafScript: vtxo.forfeitTapLeafScript
|
|
19543
19726
|
}));
|
|
19544
19727
|
const seen = /* @__PURE__ */ new Set();
|
|
19545
|
-
const results = await Promise.
|
|
19728
|
+
const results = await Promise.allSettled(
|
|
19546
19729
|
batches.map(async (batch) => {
|
|
19547
19730
|
const batchFinalized = [];
|
|
19548
19731
|
const batchPending = [];
|
|
19549
19732
|
const intent = await this.makeGetPendingTxIntentSignature(batch);
|
|
19733
|
+
if (!isCurrent()) return { finalized: batchFinalized, pending: batchPending };
|
|
19550
19734
|
const pendingTxs = await this.arkProvider.getPendingTxs(intent);
|
|
19551
19735
|
for (const pendingTx of pendingTxs) {
|
|
19736
|
+
if (!isCurrent()) break;
|
|
19552
19737
|
if (seen.has(pendingTx.arkTxid)) continue;
|
|
19553
19738
|
seen.add(pendingTx.arkTxid);
|
|
19554
19739
|
batchPending.push(pendingTx.arkTxid);
|
|
19555
19740
|
try {
|
|
19556
19741
|
const context = `pending tx ${pendingTx.arkTxid}`;
|
|
19557
19742
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
19558
|
-
const tx =
|
|
19559
|
-
|
|
19743
|
+
const tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
19744
|
+
chunk6J4GABF7_cjs.assertAllowedSighashTypes(tx);
|
|
19560
19745
|
return tx;
|
|
19561
19746
|
});
|
|
19562
19747
|
const localCheckpoints = assertCheckpointsMatchInputs(
|
|
@@ -19566,15 +19751,15 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19566
19751
|
context
|
|
19567
19752
|
);
|
|
19568
19753
|
if (!pendingTx.finalArkTx) {
|
|
19569
|
-
throw new
|
|
19754
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
19570
19755
|
`${context}: no final ark tx to bind the checkpoints to`
|
|
19571
19756
|
);
|
|
19572
19757
|
}
|
|
19573
|
-
const finalArkTx =
|
|
19758
|
+
const finalArkTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(
|
|
19574
19759
|
base.base64.decode(pendingTx.finalArkTx)
|
|
19575
19760
|
);
|
|
19576
19761
|
if (finalArkTx.id !== pendingTx.arkTxid) {
|
|
19577
|
-
throw new
|
|
19762
|
+
throw new chunk6J4GABF7_cjs.ServerResponseMismatchError(
|
|
19578
19763
|
`${context}: final ark tx is ${finalArkTx.id}`
|
|
19579
19764
|
);
|
|
19580
19765
|
}
|
|
@@ -19584,6 +19769,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19584
19769
|
);
|
|
19585
19770
|
const identity = this.identity;
|
|
19586
19771
|
const batchEligible = isBatchSignable(identity) && await this._signerRouter.canBatch(...checkpointJobs);
|
|
19772
|
+
if (!isCurrent()) break;
|
|
19587
19773
|
let finalCheckpoints;
|
|
19588
19774
|
if (batchEligible) {
|
|
19589
19775
|
const requests = checkpointTxs.map((tx, i) => ({
|
|
@@ -19608,9 +19794,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19608
19794
|
})
|
|
19609
19795
|
);
|
|
19610
19796
|
}
|
|
19797
|
+
if (!isCurrent()) break;
|
|
19611
19798
|
await this.arkProvider.finalizeTx(pendingTx.arkTxid, finalCheckpoints);
|
|
19612
19799
|
batchFinalized.push(pendingTx.arkTxid);
|
|
19613
19800
|
} catch (error) {
|
|
19801
|
+
if (recovery && chunk6J4GABF7_cjs.isTransientOperatorError(error)) throw error;
|
|
19614
19802
|
console.error(
|
|
19615
19803
|
`Failed to finalize transaction ${pendingTx.arkTxid}:`,
|
|
19616
19804
|
error
|
|
@@ -19626,11 +19814,13 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19626
19814
|
const finalized = [];
|
|
19627
19815
|
const pending = [];
|
|
19628
19816
|
for (const result of results) {
|
|
19629
|
-
|
|
19630
|
-
|
|
19817
|
+
if (result.status === "rejected") throw result.reason;
|
|
19818
|
+
finalized.push(...result.value.finalized);
|
|
19819
|
+
pending.push(...result.value.pending);
|
|
19631
19820
|
}
|
|
19632
|
-
if (finalized.length === pending.length) {
|
|
19633
|
-
await this.setPendingTxFlag(false);
|
|
19821
|
+
if (finalized.length === pending.length && isCurrent()) {
|
|
19822
|
+
await this.setPendingTxFlag(false, isCurrent);
|
|
19823
|
+
if (isCurrent()) this.pendingTxRecoveryDeferred = false;
|
|
19634
19824
|
}
|
|
19635
19825
|
return { finalized, pending };
|
|
19636
19826
|
}
|
|
@@ -19665,11 +19855,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19665
19855
|
const state = await this.walletRepository.getWalletState();
|
|
19666
19856
|
return state?.settings?.hasPendingTx === true;
|
|
19667
19857
|
}
|
|
19668
|
-
async setPendingTxFlag(value) {
|
|
19669
|
-
await updateWalletState(
|
|
19670
|
-
|
|
19671
|
-
settings: { ...state.settings, hasPendingTx: value }
|
|
19672
|
-
|
|
19858
|
+
async setPendingTxFlag(value, isCurrent = () => true) {
|
|
19859
|
+
await updateWalletState(
|
|
19860
|
+
this.walletRepository,
|
|
19861
|
+
(state) => isCurrent() ? { ...state, settings: { ...state.settings, hasPendingTx: value } } : state
|
|
19862
|
+
);
|
|
19673
19863
|
}
|
|
19674
19864
|
/**
|
|
19675
19865
|
* Create an ArkadeCash bearer instrument: sends `amount` to a DefaultVtxo controlled by a fresh
|
|
@@ -19991,7 +20181,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19991
20181
|
const recoverable = [];
|
|
19992
20182
|
const unclaimed = [];
|
|
19993
20183
|
for (const vtxo of vtxos) {
|
|
19994
|
-
if (
|
|
20184
|
+
if (chunk6J4GABF7_cjs.isVtxoSpent(vtxo)) {
|
|
19995
20185
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
19996
20186
|
} else if (vtxo.isUnrolled) {
|
|
19997
20187
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -20011,8 +20201,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20011
20201
|
async fetchAllVtxos(scripts) {
|
|
20012
20202
|
const all = [];
|
|
20013
20203
|
const seen = /* @__PURE__ */ new Set();
|
|
20014
|
-
for await (const { vtxos } of
|
|
20015
|
-
(pageIndex) =>
|
|
20204
|
+
for await (const { vtxos } of chunk6J4GABF7_cjs.indexerPages(
|
|
20205
|
+
(pageIndex) => chunk6J4GABF7_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
20016
20206
|
scripts,
|
|
20017
20207
|
pageIndex,
|
|
20018
20208
|
pageSize: 100
|
|
@@ -20056,7 +20246,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20056
20246
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_PROOF) {
|
|
20057
20247
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_PROOF);
|
|
20058
20248
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
20059
|
-
const proof =
|
|
20249
|
+
const proof = chunk6J4GABF7_cjs.Proof.create(message, batch, []);
|
|
20060
20250
|
const signedProof = await identity.sign(
|
|
20061
20251
|
proof,
|
|
20062
20252
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -20077,8 +20267,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20077
20267
|
for (const pendingTx of pendingTxs) {
|
|
20078
20268
|
try {
|
|
20079
20269
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
20080
|
-
const tx =
|
|
20081
|
-
|
|
20270
|
+
const tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
20271
|
+
chunk6J4GABF7_cjs.assertAllowedSighashTypes(tx);
|
|
20082
20272
|
return tx;
|
|
20083
20273
|
});
|
|
20084
20274
|
assertCheckpointsMatchInputs(
|
|
@@ -20119,7 +20309,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20119
20309
|
}
|
|
20120
20310
|
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
20121
20311
|
arkTxAmountPaidTo(arkTxPsbt, pkScriptHex) {
|
|
20122
|
-
const arkTx =
|
|
20312
|
+
const arkTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
|
|
20123
20313
|
let total = 0;
|
|
20124
20314
|
for (let i = 0; i < arkTx.outputsLength; i++) {
|
|
20125
20315
|
const output = arkTx.getOutput(i);
|
|
@@ -20179,7 +20369,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20179
20369
|
}
|
|
20180
20370
|
if (selectedVtxos) {
|
|
20181
20371
|
await assertNoIntentLockedInputs(selectedVtxos, this.intentRepository);
|
|
20182
|
-
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(
|
|
20372
|
+
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
20183
20373
|
if (inputExpiryFloor && selectedVtxos.some((coin) => !meetsInputExpiryFloor(coin, inputExpiryFloor))) {
|
|
20184
20374
|
throw new Error("send({ selectedVtxos }): input expiry floor not met");
|
|
20185
20375
|
}
|
|
@@ -20571,10 +20761,10 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20571
20761
|
const serverPubKey = this.arkServerPublicKey;
|
|
20572
20762
|
const serverUnrollScript = this.serverUnrollScript;
|
|
20573
20763
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
20574
|
-
const normalizedInputs = inputs.map(
|
|
20575
|
-
const at = now ?? await
|
|
20764
|
+
const normalizedInputs = inputs.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
20765
|
+
const at = now ?? await chunk6J4GABF7_cjs.resolveTimeHeight(this.onchainProvider);
|
|
20576
20766
|
for (const input of normalizedInputs) {
|
|
20577
|
-
if (!
|
|
20767
|
+
if (!chunk6J4GABF7_cjs.canSpendOffchain(input, at)) {
|
|
20578
20768
|
throw new Error(
|
|
20579
20769
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
20580
20770
|
);
|
|
@@ -20652,6 +20842,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20652
20842
|
});
|
|
20653
20843
|
}
|
|
20654
20844
|
async _buildAndSubmitOffchainTx(inputs, outputs, serverUnrollScript, options) {
|
|
20845
|
+
this.assertNoDeferredPendingTxRecovery();
|
|
20655
20846
|
await assertNoIntentLockedInputs(inputs, this.intentRepository);
|
|
20656
20847
|
assertNoPersistentReservation(inputs, this.persistentReservedOutpoints);
|
|
20657
20848
|
const validUntil = captureSendDeadline(options?.validUntil);
|
|
@@ -20781,7 +20972,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20781
20972
|
}
|
|
20782
20973
|
const checkpointIdByOutpoint = /* @__PURE__ */ new Map();
|
|
20783
20974
|
for (const encoded of signedCheckpointTxs) {
|
|
20784
|
-
const checkpoint =
|
|
20975
|
+
const checkpoint = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
20785
20976
|
for (let i = 0; i < checkpoint.inputsLength; i++) {
|
|
20786
20977
|
const input = checkpoint.getInput(i);
|
|
20787
20978
|
if (!input.txid) continue;
|
|
@@ -20898,12 +21089,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20898
21089
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
20899
21090
|
const boardingScripts = /* @__PURE__ */ new Set();
|
|
20900
21091
|
const boardingOutpoints = [];
|
|
20901
|
-
const vtxoInputs = inputs.filter(
|
|
21092
|
+
const vtxoInputs = inputs.filter(chunk6J4GABF7_cjs.isVirtualCoin);
|
|
20902
21093
|
const cm = await this.getContractManager();
|
|
20903
21094
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
20904
21095
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
20905
21096
|
for (const input of inputs) {
|
|
20906
|
-
if (
|
|
21097
|
+
if (chunk6J4GABF7_cjs.isVirtualCoin(input)) {
|
|
20907
21098
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
20908
21099
|
const vtxo = annotatedByKey.get(outpoint);
|
|
20909
21100
|
if (!vtxo) {
|
|
@@ -20986,7 +21177,7 @@ function bySelectionOrder(a, b) {
|
|
|
20986
21177
|
return b.value - a.value;
|
|
20987
21178
|
}
|
|
20988
21179
|
function selectVirtualCoins(coins, targetAmount) {
|
|
20989
|
-
const sortedCoins = coins.map(
|
|
21180
|
+
const sortedCoins = coins.map(chunk6J4GABF7_cjs.normalizeVtxo).sort(bySelectionOrder);
|
|
20990
21181
|
const selectedCoins = [];
|
|
20991
21182
|
let selectedAmount = 0;
|
|
20992
21183
|
for (const coin of sortedCoins) {
|
|
@@ -21440,7 +21631,7 @@ function assertTimeoutMap(name, timeouts) {
|
|
|
21440
21631
|
if (value === void 0) {
|
|
21441
21632
|
throw new Error(`${name}.${key} must be a non-negative safe integer`);
|
|
21442
21633
|
}
|
|
21443
|
-
|
|
21634
|
+
chunk6J4GABF7_cjs.assertTimerMs(`${name}.${key}`, value);
|
|
21444
21635
|
}
|
|
21445
21636
|
}
|
|
21446
21637
|
var MessageBus = class {
|
|
@@ -21457,8 +21648,8 @@ var MessageBus = class {
|
|
|
21457
21648
|
}) {
|
|
21458
21649
|
this.walletRepository = walletRepository;
|
|
21459
21650
|
this.contractRepository = contractRepository;
|
|
21460
|
-
|
|
21461
|
-
|
|
21651
|
+
chunk6J4GABF7_cjs.assertTimerMs("tickIntervalMs", tickIntervalMs);
|
|
21652
|
+
chunk6J4GABF7_cjs.assertTimerMs("messageTimeoutMs", messageTimeoutMs);
|
|
21462
21653
|
assertTimeoutMap("messageTimeoutOverrides", messageTimeoutOverrides);
|
|
21463
21654
|
this.intentRepository = intentRepository;
|
|
21464
21655
|
this.onchainProvider = onchainProvider;
|
|
@@ -21489,8 +21680,8 @@ var MessageBus = class {
|
|
|
21489
21680
|
*/
|
|
21490
21681
|
initChain = Promise.resolve();
|
|
21491
21682
|
/**
|
|
21492
|
-
* Number of inits accepted but not yet settled (queued or
|
|
21493
|
-
* bus refuses ordinary wallet messages while this is > 0.
|
|
21683
|
+
* Number of inits and releases accepted but not yet settled (queued or
|
|
21684
|
+
* running). The bus refuses ordinary wallet messages while this is > 0.
|
|
21494
21685
|
*/
|
|
21495
21686
|
pendingInitCount = 0;
|
|
21496
21687
|
buildServicesFn;
|
|
@@ -21667,6 +21858,30 @@ var MessageBus = class {
|
|
|
21667
21858
|
this.initChain = run.catch(() => void 0);
|
|
21668
21859
|
return run;
|
|
21669
21860
|
}
|
|
21861
|
+
/**
|
|
21862
|
+
* Back to a fresh worker's state. On the init chain, so a later init
|
|
21863
|
+
* builds only after these handlers stop.
|
|
21864
|
+
*/
|
|
21865
|
+
release(epoch) {
|
|
21866
|
+
this.pendingInitCount += 1;
|
|
21867
|
+
const run = this.initChain.then(async () => {
|
|
21868
|
+
if (epoch !== this.broadcastEpoch || !this.initialized) return;
|
|
21869
|
+
this.initialized = false;
|
|
21870
|
+
this.invalidateBroadcasts();
|
|
21871
|
+
if (this.tickTimeout !== null) {
|
|
21872
|
+
self.clearTimeout(this.tickTimeout);
|
|
21873
|
+
this.tickTimeout = null;
|
|
21874
|
+
}
|
|
21875
|
+
await Promise.all(
|
|
21876
|
+
Array.from(this.handlers.values()).map((h) => h.stop().catch(() => {
|
|
21877
|
+
}))
|
|
21878
|
+
);
|
|
21879
|
+
}).finally(() => {
|
|
21880
|
+
this.pendingInitCount -= 1;
|
|
21881
|
+
});
|
|
21882
|
+
this.initChain = run.catch(() => void 0);
|
|
21883
|
+
return run;
|
|
21884
|
+
}
|
|
21670
21885
|
/**
|
|
21671
21886
|
* The bus serves ordinary wallet messages only when it is initialized AND
|
|
21672
21887
|
* no init is in flight.
|
|
@@ -21686,7 +21901,8 @@ var MessageBus = class {
|
|
|
21686
21901
|
broadcast: (response) => {
|
|
21687
21902
|
if (epoch !== this.broadcastEpoch) return;
|
|
21688
21903
|
this.broadcastToClients([response]);
|
|
21689
|
-
}
|
|
21904
|
+
},
|
|
21905
|
+
release: () => this.release(epoch)
|
|
21690
21906
|
};
|
|
21691
21907
|
if (this.initialized) {
|
|
21692
21908
|
this.initialized = false;
|
|
@@ -21717,14 +21933,14 @@ var MessageBus = class {
|
|
|
21717
21933
|
this.initialized = true;
|
|
21718
21934
|
}
|
|
21719
21935
|
async buildServices(config) {
|
|
21720
|
-
const arkProvider = new
|
|
21936
|
+
const arkProvider = new chunk6J4GABF7_cjs.RestOperatorProvider(config.arkServer.url);
|
|
21721
21937
|
const storage = {
|
|
21722
21938
|
walletRepository: this.walletRepository,
|
|
21723
21939
|
contractRepository: this.contractRepository,
|
|
21724
21940
|
...this.intentRepository && { intentRepository: this.intentRepository }
|
|
21725
21941
|
};
|
|
21726
21942
|
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : void 0;
|
|
21727
|
-
const indexerProvider = new
|
|
21943
|
+
const indexerProvider = new chunk7LPT6AYH_cjs.RestIndexerProvider(config.arkServer.url);
|
|
21728
21944
|
const executorProvider = config.executorUrl ? new RestExecutorProvider(config.executorUrl) : void 0;
|
|
21729
21945
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
21730
21946
|
if (isSigningSerialized(serialized)) {
|
|
@@ -22144,7 +22360,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
|
22144
22360
|
const inputs = [];
|
|
22145
22361
|
let subtotal = 0n;
|
|
22146
22362
|
for (const vtxo of vtxos) {
|
|
22147
|
-
const inputFee = estimator.evalOffchainInput(
|
|
22363
|
+
const inputFee = estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(vtxo));
|
|
22148
22364
|
if (inputFee.satoshis >= vtxo.value) {
|
|
22149
22365
|
if (named) {
|
|
22150
22366
|
throw new Error(
|
|
@@ -22338,6 +22554,12 @@ var Ramps = class {
|
|
|
22338
22554
|
*
|
|
22339
22555
|
* Returns the onchain txid instead when onchain coins alone cover `amount`
|
|
22340
22556
|
* and were spent via arkd cosigning.
|
|
22557
|
+
*
|
|
22558
|
+
* Rethrows a cosign that failed after the client signed (`OnchainCosignRejectedError`,
|
|
22559
|
+
* `OnchainCosignAmbiguousError`): the operator may still hold that signed tx and complete it,
|
|
22560
|
+
* so paying from other coins can pay twice. No batch here can conflict with it, as arkd
|
|
22561
|
+
* refuses an intent mixing onchain inputs and outputs. See "Onchain cosigning" in the README for
|
|
22562
|
+
* the caller's options.
|
|
22341
22563
|
*/
|
|
22342
22564
|
async offboardExact(params) {
|
|
22343
22565
|
const { destinationAddress, feeInfo, amount, eventCallback, vtxos } = params;
|
|
@@ -22386,7 +22608,7 @@ var Ramps = class {
|
|
|
22386
22608
|
outputs: [{ address, amount: Number(amount) }]
|
|
22387
22609
|
});
|
|
22388
22610
|
} catch (e) {
|
|
22389
|
-
if (!isCosignFallback(e) || e instanceof
|
|
22611
|
+
if (!isCosignFallback(e) || e instanceof chunk6J4GABF7_cjs.OnchainCosignRejectedError) throw e;
|
|
22390
22612
|
return void 0;
|
|
22391
22613
|
}
|
|
22392
22614
|
}
|
|
@@ -22409,7 +22631,7 @@ var Ramps = class {
|
|
|
22409
22631
|
const ordered = [...candidates].sort(bySelectionOrder);
|
|
22410
22632
|
let covered = 0n;
|
|
22411
22633
|
for (let i = 0; i < ordered.length && i < MAX_VTXOS_PER_SETTLEMENT; i++) {
|
|
22412
|
-
const fee = estimator.evalOffchainInput(
|
|
22634
|
+
const fee = estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(ordered[i])).satoshis;
|
|
22413
22635
|
covered += BigInt(ordered[i].value) - BigInt(fee);
|
|
22414
22636
|
if (covered < needed) continue;
|
|
22415
22637
|
try {
|
|
@@ -22482,11 +22704,11 @@ async function readArkadeCash(token, indexer, info, onchain) {
|
|
|
22482
22704
|
if (signer.status === "UNKNOWN_SIGNER") {
|
|
22483
22705
|
throw new Error("ArkadeCash belongs to another operator");
|
|
22484
22706
|
}
|
|
22485
|
-
const coins = await
|
|
22707
|
+
const coins = await chunk6J4GABF7_cjs.getAllNormalizedVtxos(indexer, [arkadeCashId(cash)]);
|
|
22486
22708
|
return classifyArkadeCash(
|
|
22487
22709
|
coins,
|
|
22488
22710
|
info.dust,
|
|
22489
|
-
await
|
|
22711
|
+
await chunk6J4GABF7_cjs.resolveTimeHeight(onchain),
|
|
22490
22712
|
signer.status === "EXPIRED"
|
|
22491
22713
|
);
|
|
22492
22714
|
}
|
|
@@ -22494,16 +22716,16 @@ function classifyArkadeCash(coins, dust, now, awaitingSweep = false) {
|
|
|
22494
22716
|
const eligible = coins.filter(
|
|
22495
22717
|
(coin) => coin.value >= Number(dust) && !(coin.assets && coin.assets.length > 0)
|
|
22496
22718
|
);
|
|
22497
|
-
const hasSpent = eligible.some(
|
|
22498
|
-
const hasLive = eligible.some((coin) => !
|
|
22499
|
-
const hasExit = eligible.some((coin) => !
|
|
22500
|
-
const recoverable = eligible.some((coin) => !
|
|
22719
|
+
const hasSpent = eligible.some(chunk6J4GABF7_cjs.isVtxoSpent);
|
|
22720
|
+
const hasLive = eligible.some((coin) => !chunk6J4GABF7_cjs.isVtxoSpent(coin) && !coin.isUnrolled);
|
|
22721
|
+
const hasExit = eligible.some((coin) => !chunk6J4GABF7_cjs.isVtxoSpent(coin) && coin.isUnrolled);
|
|
22722
|
+
const recoverable = eligible.some((coin) => !chunk6J4GABF7_cjs.isVtxoSpent(coin) && coin.isSwept);
|
|
22501
22723
|
const elapsedBatch = eligible.some(
|
|
22502
|
-
(coin) => !
|
|
22724
|
+
(coin) => !chunk6J4GABF7_cjs.isVtxoSpent(coin) && !coin.isSwept && chunk6J4GABF7_cjs.isPastExpiry(coin, now)
|
|
22503
22725
|
);
|
|
22504
22726
|
return {
|
|
22505
22727
|
status: eligible.length === 0 ? "unissued" : hasExit && !hasLive ? "exited" : hasSpent && !hasLive ? "claimed" : recoverable ? "recovering" : elapsedBatch || awaitingSweep ? "expired" : "available",
|
|
22506
|
-
amount: eligible.reduce((sum, coin) => sum + (
|
|
22728
|
+
amount: eligible.reduce((sum, coin) => sum + (chunk6J4GABF7_cjs.isVtxoSpent(coin) ? 0 : coin.value), 0),
|
|
22507
22729
|
issues: groupByTxid(eligible),
|
|
22508
22730
|
claims: groupByTxid(
|
|
22509
22731
|
// `||`: the indexer reports an unset id as an empty string, not as absent.
|
|
@@ -22689,6 +22911,7 @@ var WalletMessageHandler = class {
|
|
|
22689
22911
|
incomingFundsSubscription;
|
|
22690
22912
|
incomingFundsRegistrations = /* @__PURE__ */ new WeakMap();
|
|
22691
22913
|
contractEventsSubscription;
|
|
22914
|
+
retryPendingTxs;
|
|
22692
22915
|
onNextTick = [];
|
|
22693
22916
|
channel;
|
|
22694
22917
|
// One counter per subscription field, bumped exactly where that field is
|
|
@@ -22719,6 +22942,9 @@ var WalletMessageHandler = class {
|
|
|
22719
22942
|
// lifecycle methods
|
|
22720
22943
|
async start(...params) {
|
|
22721
22944
|
const [services, repositories, channel] = params;
|
|
22945
|
+
if (services.wallet?.serverInfoSource === "cache") {
|
|
22946
|
+
await services.wallet.deferPendingTxRecovery();
|
|
22947
|
+
}
|
|
22722
22948
|
this.readonlyWallet = services.readonlyWallet;
|
|
22723
22949
|
this.wallet = services.wallet;
|
|
22724
22950
|
this.walletRequestBinding = services.walletRequestBinding ? Object.freeze({ ...services.walletRequestBinding }) : void 0;
|
|
@@ -22727,6 +22953,7 @@ var WalletMessageHandler = class {
|
|
|
22727
22953
|
this.walletRepository = repositories.walletRepository;
|
|
22728
22954
|
this.channel = channel;
|
|
22729
22955
|
this.onNextTick = [];
|
|
22956
|
+
this.retryPendingTxs = void 0;
|
|
22730
22957
|
}
|
|
22731
22958
|
async stop() {
|
|
22732
22959
|
const wallet = this.wallet ?? this.readonlyWallet;
|
|
@@ -22738,6 +22965,7 @@ var WalletMessageHandler = class {
|
|
|
22738
22965
|
this.channel = void 0;
|
|
22739
22966
|
this.walletRequestBinding = void 0;
|
|
22740
22967
|
this.onNextTick = [];
|
|
22968
|
+
this.retryPendingTxs = void 0;
|
|
22741
22969
|
if (this.incomingFundsSubscription) {
|
|
22742
22970
|
this.incomingFundsSubscription();
|
|
22743
22971
|
this.incomingFundsSubscription = void 0;
|
|
@@ -22759,6 +22987,9 @@ var WalletMessageHandler = class {
|
|
|
22759
22987
|
}
|
|
22760
22988
|
}
|
|
22761
22989
|
async tick(_now) {
|
|
22990
|
+
const retryPendingTxs = this.retryPendingTxs;
|
|
22991
|
+
this.retryPendingTxs = void 0;
|
|
22992
|
+
void retryPendingTxs?.();
|
|
22762
22993
|
const pending = this.onNextTick.splice(0);
|
|
22763
22994
|
const results = await Promise.allSettled(pending.map((fn) => fn()));
|
|
22764
22995
|
return results.map((result) => {
|
|
@@ -22895,6 +23126,11 @@ var WalletMessageHandler = class {
|
|
|
22895
23126
|
throw new Error("Invalid scoped wallet request");
|
|
22896
23127
|
}
|
|
22897
23128
|
const context = this.captureRequestContext(message.payload.binding);
|
|
23129
|
+
if (request.type === "DISPOSE") {
|
|
23130
|
+
const release = this.channel?.release;
|
|
23131
|
+
await (release ? release() : this.stop());
|
|
23132
|
+
return this.tagged({ id: request.id, type: "DISPOSE_SUCCESS" });
|
|
23133
|
+
}
|
|
22898
23134
|
if (request.type === "CLEAR" && this.longRunningOperations.size > 0) {
|
|
22899
23135
|
throw new Error(
|
|
22900
23136
|
"Cannot clear the wallet while a long-running operation such as a settlement is in progress"
|
|
@@ -22909,6 +23145,7 @@ var WalletMessageHandler = class {
|
|
|
22909
23145
|
this.contractEventsEpoch++;
|
|
22910
23146
|
this.boardingEpoch++;
|
|
22911
23147
|
this.onNextTick = [];
|
|
23148
|
+
this.retryPendingTxs = void 0;
|
|
22912
23149
|
}
|
|
22913
23150
|
const execution = pending ? settledWithin(pending, this.drainBudgetMs).then((drained) => {
|
|
22914
23151
|
if (!drained) {
|
|
@@ -23768,12 +24005,21 @@ var WalletMessageHandler = class {
|
|
|
23768
24005
|
return;
|
|
23769
24006
|
}
|
|
23770
24007
|
this.initEpoch++;
|
|
24008
|
+
this.retryPendingTxs = void 0;
|
|
23771
24009
|
const init = this.newGeneration("init");
|
|
24010
|
+
if (signingWallet?.serverInfoSource === "cache" && !signingWallet.hasDeferredPendingTxRecovery) {
|
|
24011
|
+
await signingWallet.deferPendingTxRecovery();
|
|
24012
|
+
if (init.stale) return;
|
|
24013
|
+
}
|
|
24014
|
+
const deferred = signingWallet?.hasDeferredPendingTxRecovery === true;
|
|
24015
|
+
if (signingWallet && deferred) {
|
|
24016
|
+
this.schedulePendingTxRecovery(signingWallet, context, init);
|
|
24017
|
+
}
|
|
23772
24018
|
await this.ensureContractEventBroadcasting(context);
|
|
23773
24019
|
if (init.stale) return;
|
|
23774
24020
|
await this.refreshCachedData({ lazyBoarding }, context, init);
|
|
23775
24021
|
if (init.stale) return;
|
|
23776
|
-
if (signingWallet) {
|
|
24022
|
+
if (signingWallet && !deferred) {
|
|
23777
24023
|
try {
|
|
23778
24024
|
const vtxos = await this.getVtxosFromRepo(void 0, context);
|
|
23779
24025
|
if (init.stale) return;
|
|
@@ -23789,7 +24035,13 @@ var WalletMessageHandler = class {
|
|
|
23789
24035
|
`Recovered ${finalized.length}/${pending.length} pending transactions: ${finalized.join(", ")}`
|
|
23790
24036
|
);
|
|
23791
24037
|
} catch (error) {
|
|
23792
|
-
|
|
24038
|
+
if (init.stale) return;
|
|
24039
|
+
if (chunk6J4GABF7_cjs.isTransientOperatorError(error) && await signingWallet.deferPendingTxRecovery()) {
|
|
24040
|
+
if (init.stale) return;
|
|
24041
|
+
this.schedulePendingTxRecovery(signingWallet, context, init);
|
|
24042
|
+
} else {
|
|
24043
|
+
console.error("Error recovering pending transactions:", error);
|
|
24044
|
+
}
|
|
23793
24045
|
}
|
|
23794
24046
|
if (init.stale) return;
|
|
23795
24047
|
}
|
|
@@ -23815,6 +24067,33 @@ var WalletMessageHandler = class {
|
|
|
23815
24067
|
}
|
|
23816
24068
|
}
|
|
23817
24069
|
}
|
|
24070
|
+
schedulePendingTxRecovery(wallet, context, init) {
|
|
24071
|
+
const reported = /* @__PURE__ */ new Set();
|
|
24072
|
+
const retry = async () => {
|
|
24073
|
+
if (init.stale) return;
|
|
24074
|
+
try {
|
|
24075
|
+
await this.runOwnedOperation(
|
|
24076
|
+
context,
|
|
24077
|
+
() => wallet.resumeDeferredPendingTxs(() => !init.stale)
|
|
24078
|
+
);
|
|
24079
|
+
} catch (error) {
|
|
24080
|
+
if (init.stale) return;
|
|
24081
|
+
if (!wallet.hasDeferredPendingTxRecovery) {
|
|
24082
|
+
console.error("Error recovering pending transactions:", error);
|
|
24083
|
+
return;
|
|
24084
|
+
}
|
|
24085
|
+
if (!chunk6J4GABF7_cjs.isTransientOperatorError(error)) {
|
|
24086
|
+
const reason = String(error);
|
|
24087
|
+
if (!reported.has(reason)) {
|
|
24088
|
+
reported.add(reason);
|
|
24089
|
+
console.error("Retrying pending transaction recovery:", error);
|
|
24090
|
+
}
|
|
24091
|
+
}
|
|
24092
|
+
this.retryPendingTxs = retry;
|
|
24093
|
+
}
|
|
24094
|
+
};
|
|
24095
|
+
this.retryPendingTxs = retry;
|
|
24096
|
+
}
|
|
23818
24097
|
async registerIncomingFunds(wallet, emitter, context) {
|
|
23819
24098
|
const repository = context.walletRepository;
|
|
23820
24099
|
if (emitter.stale) return;
|
|
@@ -24196,7 +24475,7 @@ var WalletMessageHandler = class {
|
|
|
24196
24475
|
this.repoSnapshot({}, context),
|
|
24197
24476
|
wallet.getBoardingTxs()
|
|
24198
24477
|
]);
|
|
24199
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
24478
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunk6J4GABF7_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
24200
24479
|
return buildTransactionHistory(
|
|
24201
24480
|
vtxos,
|
|
24202
24481
|
boardingTxs,
|
|
@@ -24265,9 +24544,9 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
24265
24544
|
// budget so the worker's snapshot fallback stays reachable before this
|
|
24266
24545
|
// page deadline fires — lowering it below the budget would time the page
|
|
24267
24546
|
// out while the worker is still seconds from answering from cache.
|
|
24268
|
-
GET_OPERATOR_INFO:
|
|
24547
|
+
GET_OPERATOR_INFO: chunk6J4GABF7_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
24269
24548
|
/** @deprecated Use `GET_OPERATOR_INFO`. */
|
|
24270
|
-
GET_ARKADE_INFO:
|
|
24549
|
+
GET_ARKADE_INFO: chunk6J4GABF7_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
24271
24550
|
INDEXER_GET_VTXOS: 2e4,
|
|
24272
24551
|
INDEXER_GET_VIRTUAL_TXS: 2e4,
|
|
24273
24552
|
GET_VTXOS: 2e4,
|
|
@@ -24324,6 +24603,7 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
24324
24603
|
INIT_WALLET: 3e4,
|
|
24325
24604
|
SCOPED_WALLET_REQUEST_V1: 3e4,
|
|
24326
24605
|
CLEAR: 1e4,
|
|
24606
|
+
DISPOSE: 3e4,
|
|
24327
24607
|
SIGN_TRANSACTION: 3e4,
|
|
24328
24608
|
CREATE_CONTRACT: 3e4,
|
|
24329
24609
|
UPDATE_CONTRACT: 3e4,
|
|
@@ -24370,10 +24650,10 @@ function getRequestDedupKey(request) {
|
|
|
24370
24650
|
}
|
|
24371
24651
|
function cosignWorkerError(e) {
|
|
24372
24652
|
if (e instanceof Error && e.message === "Unknown message") {
|
|
24373
|
-
return new
|
|
24653
|
+
return new chunk6J4GABF7_cjs.OnchainCosignUnsupportedError();
|
|
24374
24654
|
}
|
|
24375
24655
|
if (e instanceof ServiceWorkerTimeoutError) {
|
|
24376
|
-
return new
|
|
24656
|
+
return new chunk6J4GABF7_cjs.OnchainCosignAmbiguousError(e.message, { cause: e });
|
|
24377
24657
|
}
|
|
24378
24658
|
return rehydrateCosignError(e);
|
|
24379
24659
|
}
|
|
@@ -24428,7 +24708,7 @@ var ServiceWorkerAssetManager = class extends ServiceWorkerReadonlyAssetManager
|
|
|
24428
24708
|
}
|
|
24429
24709
|
};
|
|
24430
24710
|
var initializeMessageBus = (serviceWorker, config, timeoutMs = 2e3) => {
|
|
24431
|
-
|
|
24711
|
+
chunk6J4GABF7_cjs.assertTimerMs("messageBusTimeoutMs", timeoutMs);
|
|
24432
24712
|
const initCmd = {
|
|
24433
24713
|
tag: "INITIALIZE_MESSAGE_BUS",
|
|
24434
24714
|
id: getRandomId(),
|
|
@@ -24506,6 +24786,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24506
24786
|
messageBusTimeoutMs;
|
|
24507
24787
|
messageTimeouts = DEFAULT_MESSAGE_TIMEOUTS;
|
|
24508
24788
|
reinitPromise = null;
|
|
24789
|
+
disposed = false;
|
|
24790
|
+
disposePromise;
|
|
24509
24791
|
pingPromise = null;
|
|
24510
24792
|
inflightRequests = /* @__PURE__ */ new Map();
|
|
24511
24793
|
get assetManager() {
|
|
@@ -24557,7 +24839,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24557
24839
|
Object.entries(options.messageTimeouts ?? {}).filter(([, ms]) => ms !== void 0)
|
|
24558
24840
|
);
|
|
24559
24841
|
for (const [key, value] of Object.entries(overrides)) {
|
|
24560
|
-
|
|
24842
|
+
chunk6J4GABF7_cjs.assertTimerMs(`messageTimeouts.${key}`, value);
|
|
24561
24843
|
}
|
|
24562
24844
|
const messageTimeouts = {
|
|
24563
24845
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -24688,6 +24970,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24688
24970
|
});
|
|
24689
24971
|
}
|
|
24690
24972
|
async sendMessage(request) {
|
|
24973
|
+
this.assertNotDisposed();
|
|
24691
24974
|
if (!DEDUPABLE_REQUEST_TYPES.has(request.type)) {
|
|
24692
24975
|
return this.sendMessageWithRetry(request);
|
|
24693
24976
|
}
|
|
@@ -24731,17 +25014,20 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24731
25014
|
// send a message, retrying up to 2 times if the service worker was
|
|
24732
25015
|
// killed and restarted by the OS (mobile browsers do this aggressively)
|
|
24733
25016
|
async sendMessageWithRetry(request, withEvents) {
|
|
25017
|
+
this.assertNotDisposed();
|
|
24734
25018
|
request = this.scopeRequest(request);
|
|
24735
25019
|
if (this.initConfig) {
|
|
24736
25020
|
try {
|
|
24737
25021
|
await this.pingServiceWorker();
|
|
24738
25022
|
} catch {
|
|
25023
|
+
this.assertNotDisposed();
|
|
24739
25024
|
await this.reinitialize();
|
|
24740
25025
|
}
|
|
24741
25026
|
}
|
|
24742
25027
|
const timeoutMs = this.getTimeoutForRequest(request);
|
|
24743
25028
|
const maxRetries = 2;
|
|
24744
25029
|
for (let attempt = 0, initWaits = 0; ; attempt++) {
|
|
25030
|
+
this.assertNotDisposed();
|
|
24745
25031
|
try {
|
|
24746
25032
|
if (withEvents) {
|
|
24747
25033
|
return await this.sendMessageStreaming(
|
|
@@ -24753,6 +25039,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24753
25039
|
return await this.sendMessageDirect(request, timeoutMs);
|
|
24754
25040
|
} catch (error) {
|
|
24755
25041
|
if (isMessageBusInitializingError(error)) {
|
|
25042
|
+
this.assertNotDisposed();
|
|
24756
25043
|
if (initWaits >= MAX_INIT_WAITS) throw error;
|
|
24757
25044
|
await sleep(initWaitBackoffMs(initWaits++));
|
|
24758
25045
|
attempt--;
|
|
@@ -24761,6 +25048,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24761
25048
|
if (!isMessageBusNotInitializedError(error) || attempt >= maxRetries) {
|
|
24762
25049
|
throw error;
|
|
24763
25050
|
}
|
|
25051
|
+
this.assertNotDisposed();
|
|
24764
25052
|
await this.reinitialize();
|
|
24765
25053
|
}
|
|
24766
25054
|
}
|
|
@@ -24793,11 +25081,14 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24793
25081
|
return this.initWalletPayload;
|
|
24794
25082
|
}
|
|
24795
25083
|
async reinitialize() {
|
|
25084
|
+
this.assertNotDisposed();
|
|
24796
25085
|
if (this.reinitPromise) return this.reinitPromise;
|
|
24797
25086
|
this.reinitPromise = (async () => {
|
|
24798
25087
|
const config = await this.buildInitConfig();
|
|
25088
|
+
this.assertNotDisposed();
|
|
24799
25089
|
const payload = this.buildInitWalletPayload();
|
|
24800
25090
|
await initializeMessageBus(this.serviceWorker, config, this.messageBusTimeoutMs);
|
|
25091
|
+
this.assertNotDisposed();
|
|
24801
25092
|
const initMessage = {
|
|
24802
25093
|
tag: this.messageTag,
|
|
24803
25094
|
type: "INIT_WALLET",
|
|
@@ -24805,6 +25096,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24805
25096
|
payload
|
|
24806
25097
|
};
|
|
24807
25098
|
await this.assertWorkerIdentityMatches();
|
|
25099
|
+
this.assertNotDisposed();
|
|
24808
25100
|
await this.sendMessageDirect(
|
|
24809
25101
|
this.scopeRequest(initMessage),
|
|
24810
25102
|
this.getTimeoutForRequest(initMessage)
|
|
@@ -24858,6 +25150,49 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24858
25150
|
}
|
|
24859
25151
|
this.walletRequestBinding ??= Object.freeze({ ...binding });
|
|
24860
25152
|
}
|
|
25153
|
+
assertNotDisposed() {
|
|
25154
|
+
if (this.disposed) throw new Error("Service worker wallet is disposed");
|
|
25155
|
+
}
|
|
25156
|
+
/**
|
|
25157
|
+
* Revoke this worker wallet and proxy without deleting persisted data or
|
|
25158
|
+
* holds; call again after a failure to retry.
|
|
25159
|
+
*/
|
|
25160
|
+
dispose() {
|
|
25161
|
+
this.disposed = true;
|
|
25162
|
+
this.disposePromise ??= this.disposeWorker().catch((error) => {
|
|
25163
|
+
this.disposePromise = void 0;
|
|
25164
|
+
throw error;
|
|
25165
|
+
});
|
|
25166
|
+
return this.disposePromise;
|
|
25167
|
+
}
|
|
25168
|
+
async disposeWorker() {
|
|
25169
|
+
await this.reinitPromise?.catch(() => void 0);
|
|
25170
|
+
const message = {
|
|
25171
|
+
id: getRandomId(),
|
|
25172
|
+
tag: this.messageTag,
|
|
25173
|
+
type: "DISPOSE"
|
|
25174
|
+
};
|
|
25175
|
+
for (let initWaits = 0; ; ) {
|
|
25176
|
+
try {
|
|
25177
|
+
const response = await this.sendMessageDirect(
|
|
25178
|
+
this.scopeRequest(message),
|
|
25179
|
+
this.getTimeoutForRequest(message)
|
|
25180
|
+
);
|
|
25181
|
+
if (response.type !== "DISPOSE_SUCCESS") {
|
|
25182
|
+
throw new Error("Worker did not confirm wallet disposal");
|
|
25183
|
+
}
|
|
25184
|
+
return;
|
|
25185
|
+
} catch (error) {
|
|
25186
|
+
if (isMessageBusInitializingError(error)) {
|
|
25187
|
+
if (initWaits >= MAX_INIT_WAITS) throw error;
|
|
25188
|
+
await sleep(initWaitBackoffMs(initWaits++));
|
|
25189
|
+
continue;
|
|
25190
|
+
}
|
|
25191
|
+
if (isMessageBusNotInitializedError(error)) return;
|
|
25192
|
+
throw error;
|
|
25193
|
+
}
|
|
25194
|
+
}
|
|
25195
|
+
}
|
|
24861
25196
|
/** This tells the service worker to wipe all locally persisted wallet data. */
|
|
24862
25197
|
async clear() {
|
|
24863
25198
|
const message = {
|
|
@@ -24936,7 +25271,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24936
25271
|
try {
|
|
24937
25272
|
const response = await this.sendMessage(message);
|
|
24938
25273
|
const { vtxos, page } = response.payload;
|
|
24939
|
-
return { vtxos: vtxos.map(
|
|
25274
|
+
return { vtxos: vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo), page: page && { ...page } };
|
|
24940
25275
|
} catch (cause) {
|
|
24941
25276
|
throw new Error(`Failed to get vtxos: ${cause}`, { cause });
|
|
24942
25277
|
}
|
|
@@ -25045,7 +25380,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25045
25380
|
};
|
|
25046
25381
|
try {
|
|
25047
25382
|
const response = await this.sendMessage(message);
|
|
25048
|
-
return response.payload.vtxos.map(
|
|
25383
|
+
return response.payload.vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
25049
25384
|
} catch (error) {
|
|
25050
25385
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
25051
25386
|
}
|
|
@@ -25076,7 +25411,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25076
25411
|
"Service worker does not support the requested contract scope or freshness check"
|
|
25077
25412
|
);
|
|
25078
25413
|
}
|
|
25079
|
-
return payload.vtxos.map(
|
|
25414
|
+
return payload.vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
25080
25415
|
} catch (error) {
|
|
25081
25416
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
25082
25417
|
}
|
|
@@ -25101,11 +25436,12 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25101
25436
|
}
|
|
25102
25437
|
/** Subscribe to contract and coin updates bound to this proxy's wallet. */
|
|
25103
25438
|
onWalletUpdate(callback) {
|
|
25439
|
+
this.assertNotDisposed();
|
|
25104
25440
|
const binding = this.walletRequestBinding;
|
|
25105
25441
|
const tag = this.messageTag;
|
|
25106
25442
|
const messageHandler = (event) => {
|
|
25107
25443
|
const response = event.data;
|
|
25108
|
-
if (!binding || !response || response.tag !== tag || response.broadcast !== true || !["CONTRACT_EVENT", "VTXO_UPDATE", "UTXO_UPDATE"].includes(response.type) || response.walletRequestBinding?.scope !== binding.scope || response.walletRequestBinding?.network !== binding.network) {
|
|
25444
|
+
if (this.disposed || !binding || !response || response.tag !== tag || response.broadcast !== true || !["CONTRACT_EVENT", "VTXO_UPDATE", "UTXO_UPDATE"].includes(response.type) || response.walletRequestBinding?.scope !== binding.scope || response.walletRequestBinding?.network !== binding.network) {
|
|
25109
25445
|
return;
|
|
25110
25446
|
}
|
|
25111
25447
|
callback(response);
|
|
@@ -25285,7 +25621,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25285
25621
|
};
|
|
25286
25622
|
try {
|
|
25287
25623
|
const response = await sendContractMessage(message);
|
|
25288
|
-
return response.payload.vtxos.map(
|
|
25624
|
+
return response.payload.vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
25289
25625
|
} catch (cause) {
|
|
25290
25626
|
throw new Error(`Failed to annotate vtxos: ${cause}`, { cause });
|
|
25291
25627
|
}
|
|
@@ -25992,7 +26328,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
25992
26328
|
};
|
|
25993
26329
|
try {
|
|
25994
26330
|
const response = await wallet.sendMessage(message);
|
|
25995
|
-
return response.payload.vtxos.map(
|
|
26331
|
+
return response.payload.vtxos.map(chunk6J4GABF7_cjs.normalizeVtxo);
|
|
25996
26332
|
} catch (e) {
|
|
25997
26333
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
25998
26334
|
}
|
|
@@ -26873,7 +27209,7 @@ var CachingOperatorProvider = class {
|
|
|
26873
27209
|
constructor(inner, ttlMs = DEFAULT_TTL_MS) {
|
|
26874
27210
|
this.inner = inner;
|
|
26875
27211
|
this.ttlMs = ttlMs;
|
|
26876
|
-
|
|
27212
|
+
chunk6J4GABF7_cjs.assertNonNegativeMs("ttlMs", ttlMs);
|
|
26877
27213
|
this.unsubscribe = inner.onServerInfoChanged?.((info) => {
|
|
26878
27214
|
this.cached = info;
|
|
26879
27215
|
this.expiresAt = Date.now() + this.ttlMs;
|
|
@@ -26960,7 +27296,7 @@ exports.BIP322 = void 0;
|
|
|
26960
27296
|
async function sign2(message, identity, network) {
|
|
26961
27297
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
26962
27298
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
26963
|
-
const toSpend =
|
|
27299
|
+
const toSpend = chunk6J4GABF7_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
26964
27300
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
26965
27301
|
const signed = await identity.sign(toSign, [0]);
|
|
26966
27302
|
signed.finalizeIdx(0);
|
|
@@ -27018,7 +27354,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
27018
27354
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
27019
27355
|
return false;
|
|
27020
27356
|
}
|
|
27021
|
-
const toSpend =
|
|
27357
|
+
const toSpend = chunk6J4GABF7_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
27022
27358
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript);
|
|
27023
27359
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
27024
27360
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -27039,7 +27375,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
27039
27375
|
}
|
|
27040
27376
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
27041
27377
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
27042
|
-
const toSpend =
|
|
27378
|
+
const toSpend = chunk6J4GABF7_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
27043
27379
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
27044
27380
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
27045
27381
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -27092,7 +27428,7 @@ function encodeCompactSize(n) {
|
|
|
27092
27428
|
return buf;
|
|
27093
27429
|
}
|
|
27094
27430
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
27095
|
-
const tx = new
|
|
27431
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 0 });
|
|
27096
27432
|
tx.addInput({
|
|
27097
27433
|
txid: toSpend.id,
|
|
27098
27434
|
index: 0,
|
|
@@ -27106,12 +27442,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
27106
27442
|
});
|
|
27107
27443
|
tx.addOutput({
|
|
27108
27444
|
amount: 0n,
|
|
27109
|
-
script:
|
|
27445
|
+
script: chunk6J4GABF7_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
27110
27446
|
});
|
|
27111
27447
|
return tx;
|
|
27112
27448
|
}
|
|
27113
27449
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
27114
|
-
const tx = new
|
|
27450
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 0 });
|
|
27115
27451
|
tx.addInput({
|
|
27116
27452
|
txid: toSpend.id,
|
|
27117
27453
|
index: 0,
|
|
@@ -27123,12 +27459,12 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
27123
27459
|
});
|
|
27124
27460
|
tx.addOutput({
|
|
27125
27461
|
amount: 0n,
|
|
27126
|
-
script:
|
|
27462
|
+
script: chunk6J4GABF7_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
27127
27463
|
});
|
|
27128
27464
|
return tx;
|
|
27129
27465
|
}
|
|
27130
27466
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
27131
|
-
const tx =
|
|
27467
|
+
const tx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
27132
27468
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
27133
27469
|
const input = tx.getInput(0);
|
|
27134
27470
|
if (!input) {
|
|
@@ -27162,7 +27498,7 @@ async function resolveUnilateralPath(params) {
|
|
|
27162
27498
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
27163
27499
|
const contract = contractRepository ? (await collectContracts(contractRepository, { script: scriptHex }))[0] : void 0;
|
|
27164
27500
|
if (contract) {
|
|
27165
|
-
const handler =
|
|
27501
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
27166
27502
|
if (!handler) {
|
|
27167
27503
|
throw new ExitPathError(
|
|
27168
27504
|
"no-handler",
|
|
@@ -27398,7 +27734,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
27398
27734
|
let totalAmount = 0n;
|
|
27399
27735
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
27400
27736
|
for (const vtxo of vtxos) {
|
|
27401
|
-
if (!
|
|
27737
|
+
if (!chunk6J4GABF7_cjs.canSweepOnchain(vtxo)) {
|
|
27402
27738
|
throw new Error(
|
|
27403
27739
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
27404
27740
|
);
|
|
@@ -27450,7 +27786,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
27450
27786
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
27451
27787
|
);
|
|
27452
27788
|
}
|
|
27453
|
-
const tx = new
|
|
27789
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 2 });
|
|
27454
27790
|
for (const input of inputs) {
|
|
27455
27791
|
tx.addInput(input);
|
|
27456
27792
|
}
|
|
@@ -27530,7 +27866,7 @@ async function buildSignedSweep(params) {
|
|
|
27530
27866
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
27531
27867
|
);
|
|
27532
27868
|
}
|
|
27533
|
-
const tx = new
|
|
27869
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 2 });
|
|
27534
27870
|
tx.addInput({
|
|
27535
27871
|
txid: vtxo.txid,
|
|
27536
27872
|
index: vtxo.vout,
|
|
@@ -27583,7 +27919,7 @@ async function resolveFeeRate(opts) {
|
|
|
27583
27919
|
}
|
|
27584
27920
|
async function selectExitVtxos(opts) {
|
|
27585
27921
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
27586
|
-
const res = await
|
|
27922
|
+
const res = await chunk6J4GABF7_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
27587
27923
|
const scripts = [
|
|
27588
27924
|
...new Set(res.vtxos.filter((vtxo) => !vtxo.isSpent).map((vtxo) => vtxo.script))
|
|
27589
27925
|
];
|
|
@@ -27601,7 +27937,7 @@ async function selectExitVtxos(opts) {
|
|
|
27601
27937
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
27602
27938
|
);
|
|
27603
27939
|
}
|
|
27604
|
-
const handler =
|
|
27940
|
+
const handler = chunkXZHTYYW5_cjs.contractHandlers.get(contract.type);
|
|
27605
27941
|
if (!handler) {
|
|
27606
27942
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
27607
27943
|
}
|
|
@@ -27635,7 +27971,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
27635
27971
|
if (pendingNodes.length > 0) {
|
|
27636
27972
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
27637
27973
|
for (const psbt of txs) {
|
|
27638
|
-
psbts.set(
|
|
27974
|
+
psbts.set(chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
27639
27975
|
}
|
|
27640
27976
|
}
|
|
27641
27977
|
const childVsize = Number(
|
|
@@ -27800,7 +28136,7 @@ var Executor = class {
|
|
|
27800
28136
|
constructor(pkg, provider, opts) {
|
|
27801
28137
|
this.pkg = pkg;
|
|
27802
28138
|
this.provider = provider;
|
|
27803
|
-
|
|
28139
|
+
chunk6J4GABF7_cjs.assertTimerMs("pollIntervalMs", opts?.pollIntervalMs);
|
|
27804
28140
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
27805
28141
|
this.feeWallet = opts?.feeWallet;
|
|
27806
28142
|
this.signal = opts?.signal;
|
|
@@ -28184,7 +28520,7 @@ async function prepare(opts) {
|
|
|
28184
28520
|
if (newFee <= splitterFee) break;
|
|
28185
28521
|
splitterFee = newFee;
|
|
28186
28522
|
}
|
|
28187
|
-
const splitter = new
|
|
28523
|
+
const splitter = new chunk6J4GABF7_cjs.Transaction({ version: 2 });
|
|
28188
28524
|
for (const coin of selected.inputs) {
|
|
28189
28525
|
splitter.addInput({
|
|
28190
28526
|
txid: coin.txid,
|
|
@@ -28363,7 +28699,7 @@ chunk6TBTL42M_cjs.__export(arkade_exports, {
|
|
|
28363
28699
|
validateProgram: () => chunkACIQZLWL_cjs.validateProgram,
|
|
28364
28700
|
witnessRefToBytes: () => chunkACIQZLWL_cjs.witnessRefToBytes
|
|
28365
28701
|
});
|
|
28366
|
-
var isVtxoCoin = (input) =>
|
|
28702
|
+
var isVtxoCoin = (input) => chunk6J4GABF7_cjs.isVirtualCoin(input);
|
|
28367
28703
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
28368
28704
|
if (!signer && inputs.some((input) => !isVtxoCoin(input))) {
|
|
28369
28705
|
throw new Error("createArkadeBatchHandler: boarding inputs need a signer");
|
|
@@ -28406,7 +28742,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28406
28742
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
28407
28743
|
return { skip: true };
|
|
28408
28744
|
}
|
|
28409
|
-
const commitmentTx =
|
|
28745
|
+
const commitmentTx = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
28410
28746
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
28411
28747
|
if (recipients && recipients.length > 0) {
|
|
28412
28748
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -28444,7 +28780,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28444
28780
|
if (connectorTree) {
|
|
28445
28781
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
28446
28782
|
}
|
|
28447
|
-
let commitmentPsbt =
|
|
28783
|
+
let commitmentPsbt = chunk6J4GABF7_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
28448
28784
|
assertFinalCommitmentMatchesValidated(
|
|
28449
28785
|
commitmentPsbt,
|
|
28450
28786
|
validatedCommitmentTxid,
|
|
@@ -28487,7 +28823,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28487
28823
|
boardingIndices.push(boardingIdx);
|
|
28488
28824
|
continue;
|
|
28489
28825
|
}
|
|
28490
|
-
if (!
|
|
28826
|
+
if (!chunk6J4GABF7_cjs.requiresForfeit(input) || isSubdust(input, info.dust)) {
|
|
28491
28827
|
continue;
|
|
28492
28828
|
}
|
|
28493
28829
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -28525,7 +28861,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28525
28861
|
forfeitOutputScript
|
|
28526
28862
|
);
|
|
28527
28863
|
if (input.extraWitness?.length) {
|
|
28528
|
-
|
|
28864
|
+
chunk6J4GABF7_cjs.setArkPsbtField(forfeitTx, 0, chunk6J4GABF7_cjs.ConditionWitness, input.extraWitness);
|
|
28529
28865
|
}
|
|
28530
28866
|
if (signer) forfeitTx = await signer.sign(forfeitTx, [0]);
|
|
28531
28867
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -28620,7 +28956,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
|
|
|
28620
28956
|
});
|
|
28621
28957
|
const { fees } = await arkProvider.getInfo();
|
|
28622
28958
|
const fee = new Estimator(fees?.intentFee ?? {}).evaluate(
|
|
28623
|
-
legs.map(({ coin }) =>
|
|
28959
|
+
legs.map(({ coin }) => chunk6J4GABF7_cjs.toOffchainInputFeeParams(chunk6J4GABF7_cjs.normalizeVtxo(coin))),
|
|
28624
28960
|
[],
|
|
28625
28961
|
legs.map(({ contract, coin }) => ({
|
|
28626
28962
|
amount: BigInt(coin.value),
|
|
@@ -28683,7 +29019,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
|
|
|
28683
29019
|
const [signedProof, deleteProof] = await Promise.all(
|
|
28684
29020
|
[message, deleteMessage].map(
|
|
28685
29021
|
(m) => emulator.submitIntent({
|
|
28686
|
-
proof: base.base64.encode(
|
|
29022
|
+
proof: base.base64.encode(chunk6J4GABF7_cjs.Proof.create(m, coins, outputs).toPSBT()),
|
|
28687
29023
|
message: m
|
|
28688
29024
|
})
|
|
28689
29025
|
)
|
|
@@ -29167,17 +29503,17 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
29167
29503
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
29168
29504
|
if (registered) {
|
|
29169
29505
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
29170
|
-
return (withVtxos?.vtxos ?? []).filter((v) => !
|
|
29506
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunk6J4GABF7_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
29171
29507
|
}
|
|
29172
29508
|
}
|
|
29173
29509
|
if (!this.client.indexer) {
|
|
29174
29510
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
29175
29511
|
}
|
|
29176
|
-
const { vtxos } = await
|
|
29512
|
+
const { vtxos } = await chunk6J4GABF7_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
29177
29513
|
scripts: [scriptHex],
|
|
29178
29514
|
spendableOnly: true
|
|
29179
29515
|
});
|
|
29180
|
-
return vtxos.filter((v) => !
|
|
29516
|
+
return vtxos.filter((v) => !chunk6J4GABF7_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
29181
29517
|
}
|
|
29182
29518
|
/** Total spendable balance (requires an indexer). */
|
|
29183
29519
|
async getBalance() {
|
|
@@ -29343,7 +29679,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
29343
29679
|
this.client.checkpoint
|
|
29344
29680
|
);
|
|
29345
29681
|
inputs.forEach(({ coin }, i) => {
|
|
29346
|
-
if (coin.sourceTx)
|
|
29682
|
+
if (coin.sourceTx) chunk6J4GABF7_cjs.setArkPsbtField(arkTx, i, chunk6J4GABF7_cjs.PrevArkTxField, coin.sourceTx);
|
|
29347
29683
|
});
|
|
29348
29684
|
if (inputs.some(({ unlocker }) => unlocker.fn.arkadeScript)) {
|
|
29349
29685
|
const indexer = this.client.indexer;
|
|
@@ -29363,8 +29699,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
29363
29699
|
(w) => witnessBytes(unlocker, "tapscript", w)
|
|
29364
29700
|
);
|
|
29365
29701
|
if (condition.length === 0) return;
|
|
29366
|
-
|
|
29367
|
-
|
|
29702
|
+
chunk6J4GABF7_cjs.setArkPsbtField(arkTx, i, chunk6J4GABF7_cjs.ConditionWitness, condition);
|
|
29703
|
+
chunk6J4GABF7_cjs.setArkPsbtField(checkpoints[i], 0, chunk6J4GABF7_cjs.ConditionWitness, condition);
|
|
29368
29704
|
});
|
|
29369
29705
|
const packets = [];
|
|
29370
29706
|
if (this.assetSpecs.length > 0) {
|
|
@@ -29429,7 +29765,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
29429
29765
|
);
|
|
29430
29766
|
}
|
|
29431
29767
|
const { sequence, lockTime } = this.leafTimelocks(fn);
|
|
29432
|
-
const tx = new
|
|
29768
|
+
const tx = new chunk6J4GABF7_cjs.Transaction({ version: 2, lockTime });
|
|
29433
29769
|
tx.addInput({ txid: base.hex.decode(coin.txid), index: coin.vout, sequence });
|
|
29434
29770
|
for (const o of outputs) tx.addOutput(o);
|
|
29435
29771
|
const condition = (fn.def.tapscript.witness ?? []).map(
|
|
@@ -29595,20 +29931,20 @@ var ArkadeTransactionBuilder = class {
|
|
|
29595
29931
|
* A caller's packet counts for every input, unread; arkd checks what it actually routes.
|
|
29596
29932
|
*/
|
|
29597
29933
|
routesAssetsFrom(vin) {
|
|
29598
|
-
return this.extraPackets.some((p) => p.type() ===
|
|
29934
|
+
return this.extraPackets.some((p) => p.type() === chunk7LPT6AYH_cjs.Packet.PACKET_TYPE) || this.assetSpecs.some((spec) => spec.inputs.some((i) => i.vin === vin));
|
|
29599
29935
|
}
|
|
29600
29936
|
buildAssetPacket() {
|
|
29601
29937
|
const groups = this.assetSpecs.map((s) => {
|
|
29602
|
-
const id = typeof s.assetId === "string" ?
|
|
29603
|
-
return
|
|
29938
|
+
const id = typeof s.assetId === "string" ? chunk7LPT6AYH_cjs.AssetId.fromString(s.assetId) : chunk7LPT6AYH_cjs.AssetId.fromBytes(s.assetId);
|
|
29939
|
+
return chunk7LPT6AYH_cjs.AssetGroup.create(
|
|
29604
29940
|
id,
|
|
29605
29941
|
null,
|
|
29606
|
-
s.inputs.map((i) =>
|
|
29607
|
-
s.outputs.map((o) =>
|
|
29608
|
-
(s.metadata ?? []).map((m) =>
|
|
29942
|
+
s.inputs.map((i) => chunk7LPT6AYH_cjs.AssetInput.create(i.vin, i.amount)),
|
|
29943
|
+
s.outputs.map((o) => chunk7LPT6AYH_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
29944
|
+
(s.metadata ?? []).map((m) => chunk7LPT6AYH_cjs.Metadata.create(m.key, m.value))
|
|
29609
29945
|
);
|
|
29610
29946
|
});
|
|
29611
|
-
return
|
|
29947
|
+
return chunk7LPT6AYH_cjs.Packet.create(groups);
|
|
29612
29948
|
}
|
|
29613
29949
|
};
|
|
29614
29950
|
function unspendable(coin, now) {
|
|
@@ -30090,14 +30426,14 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
|
|
|
30090
30426
|
function offchainInputFees(vtxos, fees) {
|
|
30091
30427
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
30092
30428
|
return vtxos.reduce(
|
|
30093
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
30429
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
30094
30430
|
0
|
|
30095
30431
|
);
|
|
30096
30432
|
}
|
|
30097
30433
|
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
30098
30434
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
30099
30435
|
const net = inputs.reduce(
|
|
30100
|
-
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(
|
|
30436
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunk6J4GABF7_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
30101
30437
|
0n
|
|
30102
30438
|
);
|
|
30103
30439
|
const script = base.hex.encode(chunk6TBTL42M_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
@@ -30439,5 +30775,5 @@ exports.walletFeeSource = walletFeeSource;
|
|
|
30439
30775
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
30440
30776
|
exports.watchExecutorContracts = watchExecutorContracts;
|
|
30441
30777
|
exports.withPrevTxs = withPrevTxs;
|
|
30442
|
-
//# sourceMappingURL=chunk-
|
|
30443
|
-
//# sourceMappingURL=chunk-
|
|
30778
|
+
//# sourceMappingURL=chunk-LQH7DACV.cjs.map
|
|
30779
|
+
//# sourceMappingURL=chunk-LQH7DACV.cjs.map
|