@arkade-os/sdk 0.5.14 → 0.5.15
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 +49 -1
- 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/artifact-DA5YHM2k.d.cts +87 -0
- package/dist/artifact-DacurepK.d.ts +87 -0
- package/dist/{asyncStorageTaskQueue-p7zeFhA3.d.ts → asyncStorageTaskQueue-B3umqlkb.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-DzO5SBcm.d.cts → asyncStorageTaskQueue-Dq6AJHNv.d.cts} +2 -2
- package/dist/{chunk-MEIE2AEU.cjs → chunk-35GRSVCZ.cjs} +11 -11
- package/dist/{chunk-MEIE2AEU.cjs.map → chunk-35GRSVCZ.cjs.map} +1 -1
- package/dist/{chunk-X57WKONW.js → chunk-43APGKWL.js} +130 -22
- package/dist/chunk-43APGKWL.js.map +1 -0
- package/dist/{chunk-LQH7DACV.cjs → chunk-CMFRCBZW.cjs} +866 -615
- package/dist/chunk-CMFRCBZW.cjs.map +1 -0
- package/dist/{chunk-6J4GABF7.cjs → chunk-FKHUXSYW.cjs} +3 -3
- package/dist/chunk-FKHUXSYW.cjs.map +1 -0
- package/dist/{chunk-AZHBGWVC.js → chunk-HVUZKXB2.js} +4 -4
- package/dist/{chunk-AZHBGWVC.js.map → chunk-HVUZKXB2.js.map} +1 -1
- package/dist/{chunk-EVVLVFY7.cjs → chunk-INQAIZUO.cjs} +17 -17
- package/dist/{chunk-EVVLVFY7.cjs.map → chunk-INQAIZUO.cjs.map} +1 -1
- package/dist/{chunk-7LPT6AYH.cjs → chunk-JSYS2KX3.cjs} +18 -18
- package/dist/{chunk-7LPT6AYH.cjs.map → chunk-JSYS2KX3.cjs.map} +1 -1
- package/dist/{chunk-4HZQSKWG.js → chunk-R37I633T.js} +22 -17
- package/dist/chunk-R37I633T.js.map +1 -0
- package/dist/{chunk-ACIQZLWL.cjs → chunk-UNLH3NNG.cjs} +129 -20
- package/dist/chunk-UNLH3NNG.cjs.map +1 -0
- package/dist/{chunk-XZHTYYW5.cjs → chunk-VIQF74QJ.cjs} +38 -33
- package/dist/chunk-VIQF74QJ.cjs.map +1 -0
- package/dist/{chunk-LCGRZ24T.js → chunk-XPZ7TMXH.js} +4 -4
- package/dist/{chunk-LCGRZ24T.js.map → chunk-XPZ7TMXH.js.map} +1 -1
- package/dist/{chunk-72EC3ASW.js → chunk-YYSHQPCG.js} +3 -3
- package/dist/{chunk-72EC3ASW.js.map → chunk-YYSHQPCG.js.map} +1 -1
- package/dist/{chunk-J2JZZTOE.js → chunk-Z4LG3CZ4.js} +3 -3
- package/dist/chunk-Z4LG3CZ4.js.map +1 -0
- package/dist/{chunk-HWWSLCQN.js → chunk-ZECZ2MKX.js} +344 -93
- package/dist/chunk-ZECZ2MKX.js.map +1 -0
- package/dist/compiler.cjs +5 -5
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +9 -9
- package/dist/compiler.d.ts +9 -9
- package/dist/compiler.js +5 -5
- package/dist/compiler.js.map +1 -1
- package/dist/contracts/handlers/index.cjs +11 -11
- package/dist/contracts/handlers/index.d.cts +2 -2
- package/dist/contracts/handlers/index.d.ts +2 -2
- package/dist/contracts/handlers/index.js +3 -3
- package/dist/{index-Cy57QdcL.d.cts → index-Bi22mLsh.d.cts} +147 -43
- package/dist/{index-CaOBA9Ev.d.ts → index-CiLMmCHX.d.ts} +1 -1
- package/dist/{index-Db5qzYRi.d.ts → index-DOdoDqvM.d.ts} +147 -43
- package/dist/{index-Lq_u0hqj.d.cts → index-DnKugm-h.d.cts} +1 -1
- package/dist/index.cjs +327 -327
- package/dist/index.d.cts +32 -66
- package/dist/index.d.ts +32 -66
- package/dist/index.js +5 -5
- package/dist/repositories/realm/index.cjs +38 -38
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +6 -6
- package/dist/repositories/sqlite/index.cjs +36 -36
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +6 -6
- package/dist/{taskRunner-amPuilMW.d.ts → taskRunner-CoE4Xx9K.d.ts} +2 -2
- package/dist/{taskRunner-DhZ-KQBW.d.cts → taskRunner-DFG0BN_R.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +15 -15
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +7 -7
- package/dist/wallet/expo/index.cjs +19 -16
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +3 -2
- package/dist/wallet/expo/index.d.ts +3 -2
- package/dist/wallet/expo/index.js +9 -6
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +10 -10
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +6 -6
- package/package.json +3 -3
- package/dist/chunk-4HZQSKWG.js.map +0 -1
- package/dist/chunk-6J4GABF7.cjs.map +0 -1
- package/dist/chunk-ACIQZLWL.cjs.map +0 -1
- package/dist/chunk-HWWSLCQN.js.map +0 -1
- package/dist/chunk-J2JZZTOE.js.map +0 -1
- package/dist/chunk-LQH7DACV.cjs.map +0 -1
- package/dist/chunk-X57WKONW.js.map +0 -1
- package/dist/chunk-XZHTYYW5.cjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
3
|
+
var chunkJSYS2KX3_cjs = require('./chunk-JSYS2KX3.cjs');
|
|
4
|
+
var chunkVIQF74QJ_cjs = require('./chunk-VIQF74QJ.cjs');
|
|
5
|
+
var chunkUNLH3NNG_cjs = require('./chunk-UNLH3NNG.cjs');
|
|
6
|
+
var chunkFKHUXSYW_cjs = require('./chunk-FKHUXSYW.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 = chunkFKHUXSYW_cjs.getArkPsbtFields(tx.root, 0, chunkFKHUXSYW_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 = chunkFKHUXSYW_cjs.getArkPsbtFields(g.root, 0, chunkFKHUXSYW_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
|
+
chunkFKHUXSYW_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 = chunkVIQF74QJ_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 chunkVIQF74QJ_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 = chunkVIQF74QJ_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
|
+
chunkFKHUXSYW_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 = chunkVIQF74QJ_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 chunkVIQF74QJ_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 chunkVIQF74QJ_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
995
995
|
}
|
|
996
996
|
async compressedPublicKey() {
|
|
997
|
-
return
|
|
997
|
+
return chunkVIQF74QJ_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 = chunkVIQF74QJ_cjs.normalizeToDescriptor(descriptor);
|
|
1058
|
+
const pubKey = chunkVIQF74QJ_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 chunkVIQF74QJ_cjs.extractPubKey(chunkVIQF74QJ_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 && chunkVIQF74QJ_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 = chunkVIQF74QJ_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 chunkVIQF74QJ_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 chunkVIQF74QJ_cjs.identityDescriptor(wallet.identity);
|
|
1554
1554
|
}
|
|
1555
1555
|
async function provisionRefundKey(wallet) {
|
|
1556
|
-
const descriptorPromise =
|
|
1556
|
+
const descriptorPromise = chunkVIQF74QJ_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 = chunkVIQF74QJ_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
|
+
chunkFKHUXSYW_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 chunkFKHUXSYW_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: chunkFKHUXSYW_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 chunkFKHUXSYW_cjs.rateGate.runHttp(url, () => chunkFKHUXSYW_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 chunkFKHUXSYW_cjs.rateGate.runHttp(url, () => chunkFKHUXSYW_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 chunkFKHUXSYW_cjs.rateGate.runHttp(url, () => chunkFKHUXSYW_cjs.baseFetch(url));
|
|
1892
1892
|
if (!response.ok) {
|
|
1893
1893
|
throw await failure(response, "list Executor templates");
|
|
1894
1894
|
}
|
|
@@ -1905,7 +1905,7 @@ 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 chunkFKHUXSYW_cjs.baseFetch(url, {
|
|
1909
1909
|
method: "POST",
|
|
1910
1910
|
headers: { "Content-Type": "application/json" },
|
|
1911
1911
|
body: JSON.stringify(body),
|
|
@@ -1971,7 +1971,7 @@ var RestExecutorProvider = class {
|
|
|
1971
1971
|
}
|
|
1972
1972
|
async postJson(path, body, what, signal) {
|
|
1973
1973
|
const url = this.endpoint(path);
|
|
1974
|
-
const response = await
|
|
1974
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(url, {
|
|
1975
1975
|
method: "POST",
|
|
1976
1976
|
headers: { "Content-Type": "application/json" },
|
|
1977
1977
|
body: JSON.stringify(body),
|
|
@@ -1984,7 +1984,7 @@ var RestExecutorProvider = class {
|
|
|
1984
1984
|
}
|
|
1985
1985
|
async getJson(path, what, signal) {
|
|
1986
1986
|
const url = this.endpoint(path);
|
|
1987
|
-
const response = await
|
|
1987
|
+
const response = await chunkFKHUXSYW_cjs.rateGate.runHttp(url, () => chunkFKHUXSYW_cjs.baseFetch(url, { signal }));
|
|
1988
1988
|
if (!response.ok) {
|
|
1989
1989
|
throw await notFoundFailure(response, what);
|
|
1990
1990
|
}
|
|
@@ -2011,7 +2011,7 @@ async function postErrorBody(url, response) {
|
|
|
2011
2011
|
return body;
|
|
2012
2012
|
} finally {
|
|
2013
2013
|
if (response.status === 429 && (body === void 0 || grpcCode(body) !== 8)) {
|
|
2014
|
-
|
|
2014
|
+
chunkFKHUXSYW_cjs.rateGate.reportRateLimited(url, response.headers?.get("retry-after"));
|
|
2015
2015
|
}
|
|
2016
2016
|
}
|
|
2017
2017
|
}
|
|
@@ -2165,16 +2165,16 @@ function parseExecutorInfo(value) {
|
|
|
2165
2165
|
const info = {
|
|
2166
2166
|
version: requiredString(value, "version"),
|
|
2167
2167
|
network: requiredString(value, "network"),
|
|
2168
|
-
|
|
2169
|
-
|
|
2168
|
+
batchCosignerPubkey: requiredString(value, "batchCosignerPubkey"),
|
|
2169
|
+
operatorPubkey: requiredString(value, "operatorPubkey"),
|
|
2170
2170
|
emulatorPubkey: requiredString(value, "emulatorPubkey")
|
|
2171
2171
|
};
|
|
2172
|
-
decodeCompressed(info.
|
|
2173
|
-
decodeCompressed(info.
|
|
2172
|
+
decodeCompressed(info.batchCosignerPubkey, "batchCosignerPubkey");
|
|
2173
|
+
decodeCompressed(info.operatorPubkey, "operatorPubkey");
|
|
2174
2174
|
decodeCompressed(info.emulatorPubkey, "emulatorPubkey");
|
|
2175
|
-
if (value.
|
|
2176
|
-
info.
|
|
2177
|
-
decodeCompressed(info.
|
|
2175
|
+
if (value.sealingPubkey !== void 0 && value.sealingPubkey !== "") {
|
|
2176
|
+
info.sealingPubkey = requiredString(value, "sealingPubkey");
|
|
2177
|
+
decodeCompressed(info.sealingPubkey, "sealingPubkey");
|
|
2178
2178
|
}
|
|
2179
2179
|
return info;
|
|
2180
2180
|
}
|
|
@@ -2311,9 +2311,9 @@ var EsploraProvider = class {
|
|
|
2311
2311
|
*/
|
|
2312
2312
|
addressWatches = /* @__PURE__ */ new Map();
|
|
2313
2313
|
async getCoins(address) {
|
|
2314
|
-
const response = await
|
|
2314
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
2315
2315
|
if (!response.ok) {
|
|
2316
|
-
throw new
|
|
2316
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to fetch UTXOs", response);
|
|
2317
2317
|
}
|
|
2318
2318
|
const coins = await response.json();
|
|
2319
2319
|
const bad = coins.find(
|
|
@@ -2325,13 +2325,13 @@ var EsploraProvider = class {
|
|
|
2325
2325
|
async getFeeRate() {
|
|
2326
2326
|
let url = `${this.baseUrl}/fee-estimates`;
|
|
2327
2327
|
let key = "1";
|
|
2328
|
-
let response = await
|
|
2328
|
+
let response = await chunkFKHUXSYW_cjs.baseFetch(url);
|
|
2329
2329
|
if (response.status === 404) {
|
|
2330
2330
|
await response.body?.cancel().catch(() => {
|
|
2331
2331
|
});
|
|
2332
2332
|
url = `${this.baseUrl}/v1/fees/recommended`;
|
|
2333
2333
|
key = "fastestFee";
|
|
2334
|
-
response = await
|
|
2334
|
+
response = await chunkFKHUXSYW_cjs.baseFetch(url);
|
|
2335
2335
|
}
|
|
2336
2336
|
if (response.status === 404) {
|
|
2337
2337
|
await response.body?.cancel().catch(() => {
|
|
@@ -2341,7 +2341,7 @@ var EsploraProvider = class {
|
|
|
2341
2341
|
if (!response.ok) {
|
|
2342
2342
|
await response.body?.cancel().catch(() => {
|
|
2343
2343
|
});
|
|
2344
|
-
throw new
|
|
2344
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to fetch fee rate", response);
|
|
2345
2345
|
}
|
|
2346
2346
|
const mediaType = response.headers.get("content-type")?.split(";", 1)[0].trim().toLowerCase();
|
|
2347
2347
|
if (mediaType === "text/html") {
|
|
@@ -2371,10 +2371,10 @@ var EsploraProvider = class {
|
|
|
2371
2371
|
}
|
|
2372
2372
|
}
|
|
2373
2373
|
async getTxOutspends(txid) {
|
|
2374
|
-
const response = await
|
|
2374
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
2375
2375
|
if (!response.ok) {
|
|
2376
2376
|
const error = await response.text().catch(() => void 0);
|
|
2377
|
-
throw new
|
|
2377
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to get transaction outspends", response, error);
|
|
2378
2378
|
}
|
|
2379
2379
|
return response.json();
|
|
2380
2380
|
}
|
|
@@ -2387,7 +2387,7 @@ var EsploraProvider = class {
|
|
|
2387
2387
|
const page = await this.getAddressTxs(
|
|
2388
2388
|
`${this.baseUrl}/address/${address}/txs/chain/${last}`
|
|
2389
2389
|
).catch((error) => {
|
|
2390
|
-
if (error instanceof
|
|
2390
|
+
if (error instanceof chunkFKHUXSYW_cjs.HttpResponseError && error.status === 404) return [];
|
|
2391
2391
|
throw error;
|
|
2392
2392
|
});
|
|
2393
2393
|
const fresh = page.filter((tx) => !seen.has(tx.txid));
|
|
@@ -2398,26 +2398,26 @@ var EsploraProvider = class {
|
|
|
2398
2398
|
return txs;
|
|
2399
2399
|
}
|
|
2400
2400
|
async getAddressTxs(url) {
|
|
2401
|
-
const response = await
|
|
2401
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(url);
|
|
2402
2402
|
if (!response.ok) {
|
|
2403
2403
|
const error = await response.text().catch(() => void 0);
|
|
2404
|
-
throw new
|
|
2404
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to get transactions", response, error);
|
|
2405
2405
|
}
|
|
2406
2406
|
return response.json();
|
|
2407
2407
|
}
|
|
2408
2408
|
/** Orders of magnitude smaller than `/address/{addr}/txs`: the polling fallback's probe. */
|
|
2409
2409
|
async getAddressStats(address) {
|
|
2410
|
-
const response = await
|
|
2410
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
|
|
2411
2411
|
if (!response.ok) {
|
|
2412
|
-
throw new
|
|
2412
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to get address stats", response);
|
|
2413
2413
|
}
|
|
2414
2414
|
return response.json();
|
|
2415
2415
|
}
|
|
2416
2416
|
async getRawTransaction(txid) {
|
|
2417
|
-
const response = await
|
|
2417
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
2418
2418
|
if (!response.ok) {
|
|
2419
2419
|
const error = await response.text().catch(() => void 0);
|
|
2420
|
-
throw new
|
|
2420
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError(`Failed to get raw transaction ${txid}`, response, error);
|
|
2421
2421
|
}
|
|
2422
2422
|
const raw = base.hex.decode((await response.text()).trim());
|
|
2423
2423
|
const { id } = btcSigner.Transaction.fromRaw(raw, {
|
|
@@ -2432,17 +2432,17 @@ var EsploraProvider = class {
|
|
|
2432
2432
|
return raw;
|
|
2433
2433
|
}
|
|
2434
2434
|
async getTxStatus(txid) {
|
|
2435
|
-
const txresponse = await
|
|
2435
|
+
const txresponse = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
2436
2436
|
if (!txresponse.ok) {
|
|
2437
|
-
throw new
|
|
2437
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError(`Failed to get transaction ${txid}`, txresponse);
|
|
2438
2438
|
}
|
|
2439
2439
|
const tx = await txresponse.json();
|
|
2440
2440
|
if (!tx.status.confirmed) {
|
|
2441
2441
|
return { confirmed: false };
|
|
2442
2442
|
}
|
|
2443
|
-
const response = await
|
|
2443
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
2444
2444
|
if (!response.ok) {
|
|
2445
|
-
throw new
|
|
2445
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to get transaction status", response);
|
|
2446
2446
|
}
|
|
2447
2447
|
const data = await response.json();
|
|
2448
2448
|
if (!data.confirmed) {
|
|
@@ -2722,12 +2722,12 @@ var EsploraProvider = class {
|
|
|
2722
2722
|
return { subscribers, teardown, started };
|
|
2723
2723
|
}
|
|
2724
2724
|
async getChainTip() {
|
|
2725
|
-
let tipBlocks = await
|
|
2725
|
+
let tipBlocks = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2726
2726
|
if (tipBlocks.status === 404) {
|
|
2727
|
-
tipBlocks = await
|
|
2727
|
+
tipBlocks = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
|
|
2728
2728
|
}
|
|
2729
2729
|
if (!tipBlocks.ok) {
|
|
2730
|
-
throw new
|
|
2730
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to get chain tip", tipBlocks);
|
|
2731
2731
|
}
|
|
2732
2732
|
const tip = await tipBlocks.json();
|
|
2733
2733
|
if (!isValidBlocksTip(tip)) {
|
|
@@ -2748,18 +2748,18 @@ var EsploraProvider = class {
|
|
|
2748
2748
|
if (!Number.isInteger(height) || height < 0) {
|
|
2749
2749
|
throw new Error(`Invalid block height for median-time-past: ${height}`);
|
|
2750
2750
|
}
|
|
2751
|
-
const hashResponse = await
|
|
2751
|
+
const hashResponse = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/block-height/${height}`);
|
|
2752
2752
|
if (!hashResponse.ok) {
|
|
2753
|
-
throw new
|
|
2753
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError(
|
|
2754
2754
|
`Failed to get block hash at height ${height}`,
|
|
2755
2755
|
hashResponse
|
|
2756
2756
|
);
|
|
2757
2757
|
}
|
|
2758
2758
|
const hash = (await hashResponse.text()).trim();
|
|
2759
2759
|
if (!hash) throw new Error(`No block hash returned at height ${height}`);
|
|
2760
|
-
const blockResponse = await
|
|
2760
|
+
const blockResponse = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/block/${hash}`);
|
|
2761
2761
|
if (!blockResponse.ok) {
|
|
2762
|
-
throw new
|
|
2762
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError(`Failed to get block ${hash}`, blockResponse);
|
|
2763
2763
|
}
|
|
2764
2764
|
const block = await blockResponse.json();
|
|
2765
2765
|
if (!block || typeof block !== "object" || typeof block.mediantime !== "number" || !Number.isFinite(block.mediantime)) {
|
|
@@ -2768,7 +2768,7 @@ var EsploraProvider = class {
|
|
|
2768
2768
|
return block.mediantime;
|
|
2769
2769
|
}
|
|
2770
2770
|
async broadcastPackage(parent, child) {
|
|
2771
|
-
const response = await
|
|
2771
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
2772
2772
|
method: "POST",
|
|
2773
2773
|
headers: {
|
|
2774
2774
|
"Content-Type": "application/json"
|
|
@@ -2777,14 +2777,14 @@ var EsploraProvider = class {
|
|
|
2777
2777
|
});
|
|
2778
2778
|
if (!response.ok) {
|
|
2779
2779
|
const error = await response.text().catch(() => void 0);
|
|
2780
|
-
throw new
|
|
2780
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to broadcast package", response, error);
|
|
2781
2781
|
}
|
|
2782
2782
|
const result = await response.json();
|
|
2783
2783
|
assertPackageAccepted(result);
|
|
2784
2784
|
return result;
|
|
2785
2785
|
}
|
|
2786
2786
|
async broadcastTx(tx) {
|
|
2787
|
-
const response = await
|
|
2787
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
2788
2788
|
method: "POST",
|
|
2789
2789
|
headers: {
|
|
2790
2790
|
"Content-Type": "text/plain"
|
|
@@ -2793,7 +2793,7 @@ var EsploraProvider = class {
|
|
|
2793
2793
|
});
|
|
2794
2794
|
if (!response.ok) {
|
|
2795
2795
|
const error = await response.text().catch(() => void 0);
|
|
2796
|
-
throw new
|
|
2796
|
+
throw new chunkFKHUXSYW_cjs.HttpResponseError("Failed to broadcast transaction", response, error);
|
|
2797
2797
|
}
|
|
2798
2798
|
return response.text();
|
|
2799
2799
|
}
|
|
@@ -2957,7 +2957,7 @@ function findP2AOutput(tx) {
|
|
|
2957
2957
|
var CHILD_DUST_AMOUNT = 546;
|
|
2958
2958
|
function buildAnchorChild(params) {
|
|
2959
2959
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2960
|
-
const child = new
|
|
2960
|
+
const child = new chunkFKHUXSYW_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2961
2961
|
const anchor = findP2AOutput(parent);
|
|
2962
2962
|
child.addInput(anchor);
|
|
2963
2963
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
@@ -3006,7 +3006,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
3006
3006
|
);
|
|
3007
3007
|
}
|
|
3008
3008
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
3009
|
-
const tx = new
|
|
3009
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({
|
|
3010
3010
|
version: 3,
|
|
3011
3011
|
lockTime: txLocktime
|
|
3012
3012
|
});
|
|
@@ -3033,7 +3033,7 @@ function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
|
|
|
3033
3033
|
connectorsGraph.validate();
|
|
3034
3034
|
if (connectorsGraph.root.inputsLength !== 1) throw ErrNumberOfInputs;
|
|
3035
3035
|
const rootInput = connectorsGraph.root.getInput(0);
|
|
3036
|
-
const settlementTx =
|
|
3036
|
+
const settlementTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(settlementTxB64));
|
|
3037
3037
|
if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
|
|
3038
3038
|
throw ErrInvalidSettlementTxOutputs;
|
|
3039
3039
|
const expectedRootTxid = settlementTx.id;
|
|
@@ -3090,7 +3090,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
3090
3090
|
}
|
|
3091
3091
|
}
|
|
3092
3092
|
function cosignersOutputScript(tx, sweepTapTreeRoot) {
|
|
3093
|
-
const cosigners =
|
|
3093
|
+
const cosigners = chunkFKHUXSYW_cjs.getArkPsbtFields(tx, 0, chunkFKHUXSYW_cjs.CosignerPublicKey);
|
|
3094
3094
|
if (cosigners.length === 0) throw ErrMissingCosignersPublicKeys;
|
|
3095
3095
|
const keys = cosigners.map((c) => c.key);
|
|
3096
3096
|
const { finalKey } = aggregateKeys(keys, true, { taprootTweak: sweepTapTreeRoot });
|
|
@@ -3140,7 +3140,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
3140
3140
|
return new _EmulatorPacket(entries);
|
|
3141
3141
|
}
|
|
3142
3142
|
static fromBytes(data) {
|
|
3143
|
-
const reader = new
|
|
3143
|
+
const reader = new chunkJSYS2KX3_cjs.BufferReader(data);
|
|
3144
3144
|
const entryCount = reader.readCompactSize();
|
|
3145
3145
|
const entries = [];
|
|
3146
3146
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -3158,7 +3158,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
3158
3158
|
return _EmulatorPacket.PACKET_TYPE;
|
|
3159
3159
|
}
|
|
3160
3160
|
serialize() {
|
|
3161
|
-
const writer = new
|
|
3161
|
+
const writer = new chunkJSYS2KX3_cjs.BufferWriter();
|
|
3162
3162
|
writer.writeCompactSize(this.entries.length);
|
|
3163
3163
|
for (const entry of this.entries) {
|
|
3164
3164
|
writer.writeUint16LE(entry.vin);
|
|
@@ -3245,7 +3245,7 @@ var Extension = class _Extension {
|
|
|
3245
3245
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
3246
3246
|
);
|
|
3247
3247
|
}
|
|
3248
|
-
const reader = new
|
|
3248
|
+
const reader = new chunkJSYS2KX3_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
3249
3249
|
const packets = [];
|
|
3250
3250
|
while (reader.remaining() > 0) {
|
|
3251
3251
|
const packetType = reader.readByte();
|
|
@@ -3318,7 +3318,7 @@ var Extension = class _Extension {
|
|
|
3318
3318
|
* getAssetPacket returns the embedded Packet, or null if not present.
|
|
3319
3319
|
*/
|
|
3320
3320
|
getAssetPacket() {
|
|
3321
|
-
return this.packets.find((p) => p instanceof
|
|
3321
|
+
return this.packets.find((p) => p instanceof chunkJSYS2KX3_cjs.Packet) ?? null;
|
|
3322
3322
|
}
|
|
3323
3323
|
/**
|
|
3324
3324
|
* getEmulatorPacket returns the embedded EmulatorPacket, or null if not present.
|
|
@@ -3342,8 +3342,8 @@ var Extension = class _Extension {
|
|
|
3342
3342
|
};
|
|
3343
3343
|
function parsePacket(packetType, data) {
|
|
3344
3344
|
switch (packetType) {
|
|
3345
|
-
case
|
|
3346
|
-
return
|
|
3345
|
+
case chunkJSYS2KX3_cjs.Packet.PACKET_TYPE:
|
|
3346
|
+
return chunkJSYS2KX3_cjs.Packet.fromBytes(data);
|
|
3347
3347
|
case EmulatorPacket.PACKET_TYPE:
|
|
3348
3348
|
return EmulatorPacket.fromBytes(data);
|
|
3349
3349
|
default:
|
|
@@ -3390,22 +3390,22 @@ function buildOpReturnScript(data) {
|
|
|
3390
3390
|
}
|
|
3391
3391
|
return script;
|
|
3392
3392
|
}
|
|
3393
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
3394
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
3393
|
+
var ErrOffchainOutputNotFound = (address) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
3394
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3395
3395
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
3396
3396
|
);
|
|
3397
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
3398
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
3397
|
+
var ErrAssetGroupNotFound = (assetId) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
3398
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3399
3399
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
3400
3400
|
);
|
|
3401
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
3402
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
3401
|
+
var ErrOnchainOutputNotFound = (address) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
3402
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3403
3403
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
3404
3404
|
);
|
|
3405
|
-
var ErrIntentOutputNotFound = (index, kind) => new
|
|
3405
|
+
var ErrIntentOutputNotFound = (index, kind) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3406
3406
|
`${kind} output ${index} of the proof is not present in what the server built`
|
|
3407
3407
|
);
|
|
3408
|
-
var ErrUnvalidatedIntentOutput = (index) => new
|
|
3408
|
+
var ErrUnvalidatedIntentOutput = (index) => new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3409
3409
|
`offchain output ${index} of the proof cannot be validated: virtual output tree signing did not run`
|
|
3410
3410
|
);
|
|
3411
3411
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
@@ -3414,7 +3414,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
3414
3414
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
3415
3415
|
if (!validatedCommitmentTxid) return;
|
|
3416
3416
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
3417
|
-
throw new
|
|
3417
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
3418
3418
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
3419
3419
|
);
|
|
3420
3420
|
}
|
|
@@ -3445,7 +3445,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
3445
3445
|
}
|
|
3446
3446
|
}
|
|
3447
3447
|
function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
|
|
3448
|
-
const proof =
|
|
3448
|
+
const proof = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
|
|
3449
3449
|
const onchain = new Set(onchainOutputIndexes);
|
|
3450
3450
|
const declared = [];
|
|
3451
3451
|
for (let i = 0; i < proof.outputsLength; i++) {
|
|
@@ -3737,7 +3737,7 @@ function assetMintResolver() {
|
|
|
3737
3737
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
3738
3738
|
const minted = tx.assets.filter((a) => {
|
|
3739
3739
|
try {
|
|
3740
|
-
return base.hex.encode(
|
|
3740
|
+
return base.hex.encode(chunkJSYS2KX3_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
3741
3741
|
} catch {
|
|
3742
3742
|
return false;
|
|
3743
3743
|
}
|
|
@@ -3814,7 +3814,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3814
3814
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
3815
3815
|
inputsByAssetId.set(asset.assetId, [
|
|
3816
3816
|
...existing ?? [],
|
|
3817
|
-
|
|
3817
|
+
chunkJSYS2KX3_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
3818
3818
|
]);
|
|
3819
3819
|
}
|
|
3820
3820
|
}
|
|
@@ -3826,7 +3826,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3826
3826
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3827
3827
|
outputsByAssetId.set(asset.assetId, [
|
|
3828
3828
|
...existing ?? [],
|
|
3829
|
-
|
|
3829
|
+
chunkJSYS2KX3_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3830
3830
|
]);
|
|
3831
3831
|
}
|
|
3832
3832
|
}
|
|
@@ -3837,7 +3837,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3837
3837
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3838
3838
|
outputsByAssetId.set(asset.assetId, [
|
|
3839
3839
|
...existing ?? [],
|
|
3840
|
-
|
|
3840
|
+
chunkJSYS2KX3_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3841
3841
|
]);
|
|
3842
3842
|
}
|
|
3843
3843
|
}
|
|
@@ -3846,11 +3846,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3846
3846
|
for (const assetIdStr of allAssetIds) {
|
|
3847
3847
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
3848
3848
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
3849
|
-
const assetId =
|
|
3850
|
-
const group =
|
|
3849
|
+
const assetId = chunkJSYS2KX3_cjs.AssetId.fromString(assetIdStr);
|
|
3850
|
+
const group = chunkJSYS2KX3_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3851
3851
|
groups.push(group);
|
|
3852
3852
|
}
|
|
3853
|
-
return
|
|
3853
|
+
return chunkJSYS2KX3_cjs.Packet.create(groups);
|
|
3854
3854
|
}
|
|
3855
3855
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
3856
3856
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -3922,7 +3922,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3922
3922
|
};
|
|
3923
3923
|
}
|
|
3924
3924
|
function deriveContractTapscripts(contract) {
|
|
3925
|
-
const handler =
|
|
3925
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
3926
3926
|
if (!handler) {
|
|
3927
3927
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3928
3928
|
}
|
|
@@ -4210,7 +4210,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
4210
4210
|
feeRate,
|
|
4211
4211
|
params.address
|
|
4212
4212
|
);
|
|
4213
|
-
let tx = new
|
|
4213
|
+
let tx = new chunkFKHUXSYW_cjs.Transaction();
|
|
4214
4214
|
for (const input of inputs) {
|
|
4215
4215
|
tx.addInput({
|
|
4216
4216
|
txid: input.txid,
|
|
@@ -4273,7 +4273,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
4273
4273
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
4274
4274
|
*/
|
|
4275
4275
|
async bumpAnchor(parentHex, feeRate) {
|
|
4276
|
-
const parent =
|
|
4276
|
+
const parent = chunkFKHUXSYW_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
4277
4277
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
4278
4278
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
4279
4279
|
return [parent.hex, child.hex];
|
|
@@ -4415,14 +4415,14 @@ var toTimelock = (value) => ({
|
|
|
4415
4415
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
4416
4416
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
4417
4417
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
4418
|
-
throw new
|
|
4418
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4419
4419
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
4420
4420
|
);
|
|
4421
4421
|
}
|
|
4422
4422
|
const seconds = toSeconds(timelock);
|
|
4423
4423
|
if (seconds < policy.minSeconds) {
|
|
4424
4424
|
const remedy = overrideOption ? `; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it` : "";
|
|
4425
|
-
throw new
|
|
4425
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4426
4426
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor${remedy}`
|
|
4427
4427
|
);
|
|
4428
4428
|
}
|
|
@@ -4443,7 +4443,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
4443
4443
|
}
|
|
4444
4444
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
4445
4445
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
4446
|
-
throw new
|
|
4446
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4447
4447
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
4448
4448
|
);
|
|
4449
4449
|
}
|
|
@@ -4454,19 +4454,19 @@ function assertValidServerUnrollScript(checkpointTapscript, network, advertisedF
|
|
|
4454
4454
|
try {
|
|
4455
4455
|
script = chunk6TBTL42M_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
4456
4456
|
} catch (e) {
|
|
4457
|
-
throw new
|
|
4457
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4458
4458
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
4459
4459
|
);
|
|
4460
4460
|
}
|
|
4461
4461
|
if (advertisedForfeitPubkey !== void 0) {
|
|
4462
4462
|
const { pubkeys } = script.params;
|
|
4463
4463
|
if (pubkeys.length !== 1) {
|
|
4464
|
-
throw new
|
|
4464
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4465
4465
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
4466
4466
|
);
|
|
4467
4467
|
}
|
|
4468
4468
|
if (!utils_js.equalBytes(pubkeys[0], advertisedForfeitPubkey)) {
|
|
4469
|
-
throw new
|
|
4469
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4470
4470
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(advertisedForfeitPubkey)}`
|
|
4471
4471
|
);
|
|
4472
4472
|
}
|
|
@@ -4521,7 +4521,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
4521
4521
|
}
|
|
4522
4522
|
}
|
|
4523
4523
|
}
|
|
4524
|
-
const tx = new
|
|
4524
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({
|
|
4525
4525
|
version: 3,
|
|
4526
4526
|
lockTime: Number(lockTime)
|
|
4527
4527
|
});
|
|
@@ -4536,7 +4536,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
4536
4536
|
},
|
|
4537
4537
|
tapLeafScript: [input.tapLeafScript]
|
|
4538
4538
|
});
|
|
4539
|
-
|
|
4539
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(tx, i, chunkFKHUXSYW_cjs.VtxoTaprootTree, input.tapTree);
|
|
4540
4540
|
}
|
|
4541
4541
|
for (const output of outputs) {
|
|
4542
4542
|
tx.addOutput(output);
|
|
@@ -4679,10 +4679,15 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
4679
4679
|
);
|
|
4680
4680
|
}
|
|
4681
4681
|
}
|
|
4682
|
+
if (signature.length !== 64 && (signature.length !== 65 || signature[64] === btcSigner.SigHash.DEFAULT)) {
|
|
4683
|
+
throw new Error(
|
|
4684
|
+
`Input ${inputIndex}: signature from ${pubKeyHex} is not a BIP-341 signature encoding (${signature.length} bytes)`
|
|
4685
|
+
);
|
|
4686
|
+
}
|
|
4682
4687
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
4683
4688
|
const sig = signature.subarray(0, 64);
|
|
4684
4689
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
4685
|
-
const sighashName =
|
|
4690
|
+
const sighashName = chunkFKHUXSYW_cjs.formatSighash(sighashType);
|
|
4686
4691
|
throw new Error(
|
|
4687
4692
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
4688
4693
|
);
|
|
@@ -4764,16 +4769,16 @@ function isValidArkAddress(address) {
|
|
|
4764
4769
|
}
|
|
4765
4770
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
4766
4771
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
4767
|
-
throw new
|
|
4772
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4768
4773
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
4769
4774
|
);
|
|
4770
4775
|
}
|
|
4771
4776
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
4772
4777
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
4773
|
-
const server =
|
|
4778
|
+
const server = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
4774
4779
|
const local = byTxid.get(server.id);
|
|
4775
4780
|
if (!local) {
|
|
4776
|
-
throw new
|
|
4781
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4777
4782
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
4778
4783
|
);
|
|
4779
4784
|
}
|
|
@@ -4783,14 +4788,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
4783
4788
|
}
|
|
4784
4789
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
4785
4790
|
if (response.arkTxid !== signedArkTx.id) {
|
|
4786
|
-
throw new
|
|
4791
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4787
4792
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
4788
4793
|
);
|
|
4789
4794
|
}
|
|
4790
4795
|
if (response.finalArkTx === void 0) return;
|
|
4791
|
-
const finalTxid =
|
|
4796
|
+
const finalTxid = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
4792
4797
|
if (finalTxid !== signedArkTx.id) {
|
|
4793
|
-
throw new
|
|
4798
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4794
4799
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
4795
4800
|
);
|
|
4796
4801
|
}
|
|
@@ -4809,13 +4814,13 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
4809
4814
|
(key) => base.hex.encode(chunk6TBTL42M_cjs.toXOnly(key, "leaf key"))
|
|
4810
4815
|
);
|
|
4811
4816
|
} catch (error) {
|
|
4812
|
-
throw new
|
|
4817
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4813
4818
|
`${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
|
|
4814
4819
|
);
|
|
4815
4820
|
}
|
|
4816
4821
|
const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
|
|
4817
4822
|
if (!signer) {
|
|
4818
|
-
throw new
|
|
4823
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4819
4824
|
`${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
|
|
4820
4825
|
);
|
|
4821
4826
|
}
|
|
@@ -4832,7 +4837,7 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
4832
4837
|
payment_js.tapLeafHash(script)
|
|
4833
4838
|
);
|
|
4834
4839
|
} catch (error) {
|
|
4835
|
-
throw new
|
|
4840
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4836
4841
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
4837
4842
|
);
|
|
4838
4843
|
}
|
|
@@ -4842,20 +4847,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
4842
4847
|
const matched = [];
|
|
4843
4848
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
4844
4849
|
if (checkpoint.inputsLength !== 1) {
|
|
4845
|
-
throw new
|
|
4850
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4846
4851
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
4847
4852
|
);
|
|
4848
4853
|
}
|
|
4849
4854
|
const spent = checkpoint.getInput(0);
|
|
4850
4855
|
if (!spent.txid || spent.index === void 0) {
|
|
4851
|
-
throw new
|
|
4856
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4852
4857
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
4853
4858
|
);
|
|
4854
4859
|
}
|
|
4855
4860
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
4856
4861
|
const input = byOutpoint.get(outpoint);
|
|
4857
4862
|
if (!input) {
|
|
4858
|
-
throw new
|
|
4863
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4859
4864
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
4860
4865
|
);
|
|
4861
4866
|
}
|
|
@@ -4868,7 +4873,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
4868
4873
|
}
|
|
4869
4874
|
}
|
|
4870
4875
|
if (!rebuilt) {
|
|
4871
|
-
throw new
|
|
4876
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4872
4877
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
4873
4878
|
);
|
|
4874
4879
|
}
|
|
@@ -4885,7 +4890,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4885
4890
|
const outpoint = input.txid && input.index !== void 0 ? `${base.hex.encode(input.txid)}:${input.index}` : void 0;
|
|
4886
4891
|
const local = outpoint ? byOutpoint.get(outpoint) : void 0;
|
|
4887
4892
|
if (!local) {
|
|
4888
|
-
throw new
|
|
4893
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4889
4894
|
`${context}: ark tx input ${index} spends ${outpoint ?? "no outpoint"}, which is not a checkpoint of this tx`
|
|
4890
4895
|
);
|
|
4891
4896
|
}
|
|
@@ -4904,7 +4909,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4904
4909
|
}
|
|
4905
4910
|
const unspent = checkpoints.find((checkpoint) => !spent.includes(checkpoint));
|
|
4906
4911
|
if (unspent) {
|
|
4907
|
-
throw new
|
|
4912
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4908
4913
|
`${context}: ark tx does not spend checkpoint ${unspent.txid}`
|
|
4909
4914
|
);
|
|
4910
4915
|
}
|
|
@@ -4916,7 +4921,7 @@ function assertArkTxSignedOverCheckpoints(arkTx, checkpoints, context) {
|
|
|
4916
4921
|
try {
|
|
4917
4922
|
verifyTapscriptSignatures(probe, index, keys, void 0, void 0, payment_js.tapLeafHash(leaf));
|
|
4918
4923
|
} catch (error) {
|
|
4919
|
-
throw new
|
|
4924
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4920
4925
|
`${context}: ark tx input ${index} is not fully signed on the leaf spending ${local.txid} (${error instanceof Error ? error.message : String(error)})`
|
|
4921
4926
|
);
|
|
4922
4927
|
}
|
|
@@ -4945,9 +4950,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
4945
4950
|
if (!oneShot) {
|
|
4946
4951
|
matched.forEach(({ server }, index) => {
|
|
4947
4952
|
try {
|
|
4948
|
-
|
|
4953
|
+
chunkFKHUXSYW_cjs.assertAllowedSighashTypes(server);
|
|
4949
4954
|
} catch (error) {
|
|
4950
|
-
throw new
|
|
4955
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4951
4956
|
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
4952
4957
|
);
|
|
4953
4958
|
}
|
|
@@ -4956,11 +4961,11 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
4956
4961
|
const verify = options?.verifyServerSignatures;
|
|
4957
4962
|
if (verify) {
|
|
4958
4963
|
if (response.finalArkTx === void 0) {
|
|
4959
|
-
throw new
|
|
4964
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
4960
4965
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
4961
4966
|
);
|
|
4962
4967
|
}
|
|
4963
|
-
const finalArkTx =
|
|
4968
|
+
const finalArkTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
4964
4969
|
const serverPubkeys = new Set(
|
|
4965
4970
|
[verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
|
|
4966
4971
|
(key) => base.hex.encode(chunk6TBTL42M_cjs.toXOnly(key, "server key"))
|
|
@@ -5011,19 +5016,19 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
5011
5016
|
return result;
|
|
5012
5017
|
}
|
|
5013
5018
|
function carryConditionWitness(ours, server) {
|
|
5014
|
-
if (
|
|
5015
|
-
const [witness] =
|
|
5016
|
-
if (witness)
|
|
5019
|
+
if (chunkFKHUXSYW_cjs.getArkPsbtFields(server, 0, chunkFKHUXSYW_cjs.ConditionWitness).length > 0) return;
|
|
5020
|
+
const [witness] = chunkFKHUXSYW_cjs.getArkPsbtFields(ours, 0, chunkFKHUXSYW_cjs.ConditionWitness);
|
|
5021
|
+
if (witness) chunkFKHUXSYW_cjs.setArkPsbtField(server, 0, chunkFKHUXSYW_cjs.ConditionWitness, witness);
|
|
5017
5022
|
}
|
|
5018
5023
|
function withArkInputWitness(checkpoint, signedArkTx) {
|
|
5019
|
-
if (
|
|
5024
|
+
if (chunkFKHUXSYW_cjs.getArkPsbtFields(checkpoint, 0, chunkFKHUXSYW_cjs.ConditionWitness).length > 0) return checkpoint;
|
|
5020
5025
|
for (let i = 0; i < signedArkTx.inputsLength; i++) {
|
|
5021
5026
|
const { txid } = signedArkTx.getInput(i);
|
|
5022
5027
|
if (!txid || base.hex.encode(txid) !== checkpoint.id) continue;
|
|
5023
|
-
const [witness] =
|
|
5028
|
+
const [witness] = chunkFKHUXSYW_cjs.getArkPsbtFields(signedArkTx, i, chunkFKHUXSYW_cjs.ConditionWitness);
|
|
5024
5029
|
if (!witness) return checkpoint;
|
|
5025
5030
|
const carried = checkpoint.clone();
|
|
5026
|
-
|
|
5031
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(carried, 0, chunkFKHUXSYW_cjs.ConditionWitness, witness);
|
|
5027
5032
|
return carried;
|
|
5028
5033
|
}
|
|
5029
5034
|
return checkpoint;
|
|
@@ -5064,7 +5069,7 @@ async function submitViaEmulator(emulator, offchainTx, signer, opts) {
|
|
|
5064
5069
|
base.base64.encode(arkTx.toPSBT()),
|
|
5065
5070
|
checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
5066
5071
|
);
|
|
5067
|
-
const txid =
|
|
5072
|
+
const txid = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(res.signedArkTx)).id;
|
|
5068
5073
|
assertSubmittedArkTxid({ arkTxid: txid }, arkTx, "emulator submitTx");
|
|
5069
5074
|
matchServerCheckpoints(res.signedCheckpointTxs, checkpoints, "emulator submitTx");
|
|
5070
5075
|
return { txid, signedArkTx: res.signedArkTx, signedCheckpointTxs: res.signedCheckpointTxs };
|
|
@@ -5073,12 +5078,12 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
5073
5078
|
return {
|
|
5074
5079
|
...identity,
|
|
5075
5080
|
sign: async (tx, inputIndexes) => {
|
|
5076
|
-
const signed =
|
|
5081
|
+
const signed = chunkFKHUXSYW_cjs.Transaction.fromPSBT(
|
|
5077
5082
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
5078
5083
|
);
|
|
5079
5084
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
5080
5085
|
for (const index of indexes) {
|
|
5081
|
-
|
|
5086
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(signed, index, chunkFKHUXSYW_cjs.ConditionWitness, [preimage]);
|
|
5082
5087
|
}
|
|
5083
5088
|
return signed;
|
|
5084
5089
|
}
|
|
@@ -5087,7 +5092,7 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
5087
5092
|
|
|
5088
5093
|
// src/contracts/scope.ts
|
|
5089
5094
|
function scopeOf(contract) {
|
|
5090
|
-
return contract.scope ??
|
|
5095
|
+
return contract.scope ?? chunkVIQF74QJ_cjs.contractHandlers.get(contract.type)?.defaultScope ?? "offchain";
|
|
5091
5096
|
}
|
|
5092
5097
|
function isOnchainScoped(contract) {
|
|
5093
5098
|
return scopeOf(contract) !== "offchain";
|
|
@@ -5164,9 +5169,9 @@ async function collectScriptVtxos(repository, script, options) {
|
|
|
5164
5169
|
return [...byOutpoint.values()].map((row) => row.vtxo);
|
|
5165
5170
|
}
|
|
5166
5171
|
function unspentScriptVtxos(rows, copies) {
|
|
5167
|
-
const spent = copies.filter((copy) =>
|
|
5172
|
+
const spent = copies.filter((copy) => chunkFKHUXSYW_cjs.isVtxoSpent(copy.vtxo));
|
|
5168
5173
|
return rows.filter(
|
|
5169
|
-
(row) => !
|
|
5174
|
+
(row) => !chunkFKHUXSYW_cjs.isVtxoSpent(row.vtxo) && !spent.some(
|
|
5170
5175
|
(copy) => copy.address !== row.address && copy.vtxo.txid === row.vtxo.txid && copy.vtxo.vout === row.vtxo.vout && shouldReplaceScriptVtxo(row, copy)
|
|
5171
5176
|
)
|
|
5172
5177
|
);
|
|
@@ -5237,8 +5242,8 @@ function checkSaveVtxosForScript(backend, key, vtxos) {
|
|
|
5237
5242
|
}
|
|
5238
5243
|
async function getVtxosForContract(repo, contract, options) {
|
|
5239
5244
|
const vtxos = repo.getVtxosForScriptPage ? await collectScriptVtxos(repo, contract.script, options) : filterVtxosForScript(await collectVtxos(repo, contract.address), contract.script);
|
|
5240
|
-
const normalized = vtxos.map(
|
|
5241
|
-
return options?.unspentOnly ? normalized.filter((vtxo) => !
|
|
5245
|
+
const normalized = vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
5246
|
+
return options?.unspentOnly ? normalized.filter((vtxo) => !chunkFKHUXSYW_cjs.isVtxoSpent(vtxo)) : normalized;
|
|
5242
5247
|
}
|
|
5243
5248
|
async function hasVtxosForContract(repo, contract) {
|
|
5244
5249
|
if (repo.getVtxosForScriptPage) {
|
|
@@ -5320,7 +5325,7 @@ async function saveVtxosForContract(repo, contract, vtxos) {
|
|
|
5320
5325
|
// src/contracts/onchainCoins.ts
|
|
5321
5326
|
var MIGRATED_KEY = "legacyUtxosMigrated";
|
|
5322
5327
|
function createScript(contract) {
|
|
5323
|
-
const handler =
|
|
5328
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
5324
5329
|
if (!handler) throw new Error(`No handler for contract type '${contract.type}'`);
|
|
5325
5330
|
return handler.createScript(contract.params);
|
|
5326
5331
|
}
|
|
@@ -5379,7 +5384,7 @@ async function migrateLegacyUtxos(deps) {
|
|
|
5379
5384
|
let migrated = 0;
|
|
5380
5385
|
for (const contract of await collectContracts(contractRepository)) {
|
|
5381
5386
|
if (!isOnchainScoped(contract)) continue;
|
|
5382
|
-
if (!
|
|
5387
|
+
if (!chunkVIQF74QJ_cjs.contractHandlers.has(contract.type)) {
|
|
5383
5388
|
console.warn("Skipping legacy utxos of a contract with no handler", contract.type);
|
|
5384
5389
|
continue;
|
|
5385
5390
|
}
|
|
@@ -5405,7 +5410,7 @@ var DEFAULT_COSIGN_MARGIN_BLOCKS = 6;
|
|
|
5405
5410
|
var MAX_COSIGN_INPUTS = 64;
|
|
5406
5411
|
var ONCHAIN_RENEW_WINDOW_BLOCKS = 144;
|
|
5407
5412
|
function exitCsvOf(contract) {
|
|
5408
|
-
const sequence =
|
|
5413
|
+
const sequence = chunkVIQF74QJ_cjs.exitSequence(contract);
|
|
5409
5414
|
return sequence === void 0 ? void 0 : chunk6TBTL42M_cjs.sequenceToTimelock(sequence);
|
|
5410
5415
|
}
|
|
5411
5416
|
var ONCHAIN_COSIGN_PREFLIGHT_PREFIX = "Onchain cosign preflight failed: ";
|
|
@@ -5423,7 +5428,7 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
|
|
|
5423
5428
|
tx.updateInput(index, { tapLeafScript: void 0, tapScriptSig: void 0 }, true);
|
|
5424
5429
|
}
|
|
5425
5430
|
const kept = unknown?.filter(
|
|
5426
|
-
(u) =>
|
|
5431
|
+
(u) => chunkFKHUXSYW_cjs.VtxoTaprootTree.decode(u) === null && chunkFKHUXSYW_cjs.ConditionWitness.decode(u) === null
|
|
5427
5432
|
);
|
|
5428
5433
|
if (kept && kept.length !== unknown.length) {
|
|
5429
5434
|
tx.updateInput(index, { unknown: void 0 }, true);
|
|
@@ -5434,9 +5439,9 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
|
|
|
5434
5439
|
tapLeafScript: [path.leaf],
|
|
5435
5440
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
5436
5441
|
});
|
|
5437
|
-
|
|
5442
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(tx, index, chunkFKHUXSYW_cjs.VtxoTaprootTree, tapTree);
|
|
5438
5443
|
if (path.extraWitness?.length) {
|
|
5439
|
-
|
|
5444
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(tx, index, chunkFKHUXSYW_cjs.ConditionWitness, path.extraWitness);
|
|
5440
5445
|
}
|
|
5441
5446
|
}
|
|
5442
5447
|
function emulatorInputIndexes(tx) {
|
|
@@ -5482,11 +5487,11 @@ function assertCosignable(coin, csv, tip, marginBlocks = DEFAULT_COSIGN_MARGIN_B
|
|
|
5482
5487
|
function isBoardingContract(contract, boardingCsv) {
|
|
5483
5488
|
if (!isOnchainScoped(contract)) return false;
|
|
5484
5489
|
if (contract.type === "boarding") return true;
|
|
5485
|
-
if (contract.type ===
|
|
5490
|
+
if (contract.type === chunkVIQF74QJ_cjs.ExecutorContractHandler.type) {
|
|
5486
5491
|
return contract.params.template === "boarding";
|
|
5487
5492
|
}
|
|
5488
5493
|
if (contract.type !== "default" || scopeOf(contract) !== "both") return false;
|
|
5489
|
-
return
|
|
5494
|
+
return chunkVIQF74QJ_cjs.exitSequence(contract) === chunk6TBTL42M_cjs.timelockToSequence(boardingCsv);
|
|
5490
5495
|
}
|
|
5491
5496
|
function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFAULT_COSIGN_MARGIN_BLOCKS) {
|
|
5492
5497
|
if (!isBoardingContract(contract, boardingCsv) || !isExplorerCoin(coin)) return false;
|
|
@@ -5498,7 +5503,7 @@ function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFA
|
|
|
5498
5503
|
return left.remaining > margin && left.remaining <= margin + window2;
|
|
5499
5504
|
}
|
|
5500
5505
|
function finalizeOwnedInput(tx, index) {
|
|
5501
|
-
const condition =
|
|
5506
|
+
const condition = chunkFKHUXSYW_cjs.getArkPsbtFields(tx, index, chunkFKHUXSYW_cjs.ConditionWitness)[0];
|
|
5502
5507
|
if (!condition) {
|
|
5503
5508
|
tx.finalizeIdx(index);
|
|
5504
5509
|
return;
|
|
@@ -5521,27 +5526,27 @@ var DEFINITE_COSIGN_REJECTIONS = /* @__PURE__ */ new Set([
|
|
|
5521
5526
|
"TX_TOO_LARGE"
|
|
5522
5527
|
]);
|
|
5523
5528
|
function isCosignRejectedAfterSigning(e) {
|
|
5524
|
-
return e instanceof
|
|
5529
|
+
return e instanceof chunkFKHUXSYW_cjs.OnchainCosignRejectedError && !isCosignFallback(e);
|
|
5525
5530
|
}
|
|
5526
5531
|
function isCosignFallback(e) {
|
|
5527
|
-
if (e instanceof
|
|
5532
|
+
if (e instanceof chunkFKHUXSYW_cjs.OnchainCosignRejectedError) {
|
|
5528
5533
|
return !!e.arkErrorName && DEFINITE_COSIGN_REJECTIONS.has(e.arkErrorName);
|
|
5529
5534
|
}
|
|
5530
|
-
return e instanceof
|
|
5535
|
+
return e instanceof chunkFKHUXSYW_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError;
|
|
5531
5536
|
}
|
|
5532
5537
|
function rehydrateCosignError(e) {
|
|
5533
|
-
if (!(e instanceof Error) || e instanceof
|
|
5538
|
+
if (!(e instanceof Error) || e instanceof chunkFKHUXSYW_cjs.OnchainCosignRejectedError || e instanceof chunkFKHUXSYW_cjs.OnchainCosignAmbiguousError || e instanceof chunkFKHUXSYW_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError) {
|
|
5534
5539
|
return e;
|
|
5535
5540
|
}
|
|
5536
5541
|
const { message } = e;
|
|
5537
|
-
if (message.startsWith(
|
|
5538
|
-
const rest = message.slice(
|
|
5542
|
+
if (message.startsWith(chunkFKHUXSYW_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX)) {
|
|
5543
|
+
const rest = message.slice(chunkFKHUXSYW_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX.length);
|
|
5539
5544
|
const named = rest.match(/^\[([A-Z0-9_]+)\] ([\s\S]*)$/);
|
|
5540
|
-
return named ? new
|
|
5545
|
+
return named ? new chunkFKHUXSYW_cjs.OnchainCosignRejectedError(named[2], named[1]) : new chunkFKHUXSYW_cjs.OnchainCosignRejectedError(rest);
|
|
5541
5546
|
}
|
|
5542
|
-
if (message.startsWith(
|
|
5543
|
-
return new
|
|
5544
|
-
message.slice(
|
|
5547
|
+
if (message.startsWith(chunkFKHUXSYW_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX)) {
|
|
5548
|
+
return new chunkFKHUXSYW_cjs.OnchainCosignAmbiguousError(
|
|
5549
|
+
message.slice(chunkFKHUXSYW_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX.length)
|
|
5545
5550
|
);
|
|
5546
5551
|
}
|
|
5547
5552
|
if (message.startsWith(ONCHAIN_COSIGN_PREFLIGHT_PREFIX)) {
|
|
@@ -5549,8 +5554,8 @@ function rehydrateCosignError(e) {
|
|
|
5549
5554
|
message.slice(ONCHAIN_COSIGN_PREFLIGHT_PREFIX.length)
|
|
5550
5555
|
);
|
|
5551
5556
|
}
|
|
5552
|
-
if (message.startsWith(
|
|
5553
|
-
return new
|
|
5557
|
+
if (message.startsWith(chunkFKHUXSYW_cjs.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX))
|
|
5558
|
+
return new chunkFKHUXSYW_cjs.OnchainCosignUnsupportedError();
|
|
5554
5559
|
return e;
|
|
5555
5560
|
}
|
|
5556
5561
|
function estimateOnchainCosignFee(nIn, nOut, feeRate) {
|
|
@@ -5566,13 +5571,13 @@ async function submitOnchainSpend(tx, arkInputs, deps) {
|
|
|
5566
5571
|
throw new Error("emulator inputs present but no emulator provider configured");
|
|
5567
5572
|
}
|
|
5568
5573
|
const { signedTx } = await deps.emulator.submitOnchainTx(base.base64.encode(tx.toPSBT()));
|
|
5569
|
-
tx =
|
|
5574
|
+
tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(signedTx));
|
|
5570
5575
|
}
|
|
5571
5576
|
if (arkInputs.size > 0) {
|
|
5572
5577
|
if (!deps.arkProvider) {
|
|
5573
5578
|
throw new Error("arkd-cosigned inputs present but no arkProvider configured");
|
|
5574
5579
|
}
|
|
5575
|
-
if (!deps.arkProvider.cosignOnchainTx) throw new
|
|
5580
|
+
if (!deps.arkProvider.cosignOnchainTx) throw new chunkFKHUXSYW_cjs.OnchainCosignUnsupportedError();
|
|
5576
5581
|
return deps.arkProvider.cosignOnchainTx(base.base64.encode(tx.toPSBT()));
|
|
5577
5582
|
}
|
|
5578
5583
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
@@ -5723,7 +5728,7 @@ function parseProgram(text, env) {
|
|
|
5723
5728
|
|
|
5724
5729
|
// src/contracts/spendability.ts
|
|
5725
5730
|
function isContractGenericallySpendable(contract) {
|
|
5726
|
-
return
|
|
5731
|
+
return chunkVIQF74QJ_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
5727
5732
|
}
|
|
5728
5733
|
function gatedContracts(contracts) {
|
|
5729
5734
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -5745,7 +5750,7 @@ function gateExclusion(gated) {
|
|
|
5745
5750
|
return (vtxo) => {
|
|
5746
5751
|
const type = gatedTypeOf(vtxo, gated);
|
|
5747
5752
|
if (type === void 0) return void 0;
|
|
5748
|
-
if (!
|
|
5753
|
+
if (!chunkVIQF74QJ_cjs.contractHandlers.has(type)) {
|
|
5749
5754
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
5750
5755
|
}
|
|
5751
5756
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -5848,7 +5853,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
5848
5853
|
*/
|
|
5849
5854
|
materializeDescriptorAt(index) {
|
|
5850
5855
|
const descriptor = this.identity.descriptor;
|
|
5851
|
-
const network =
|
|
5856
|
+
const network = chunkVIQF74QJ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
5852
5857
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
5853
5858
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
5854
5859
|
if (!keyInfo?.keyExpression) {
|
|
@@ -5916,7 +5921,7 @@ function signingDescriptorIndex(descriptor) {
|
|
|
5916
5921
|
}
|
|
5917
5922
|
function newestWalletReceiveContract(contracts, serverPubKeyHex) {
|
|
5918
5923
|
return contracts.filter(
|
|
5919
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
5924
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkVIQF74QJ_cjs.WALLET_RECEIVE_SOURCE
|
|
5920
5925
|
).sort((a, b) => {
|
|
5921
5926
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
5922
5927
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -5935,6 +5940,13 @@ var NonRangeableDescriptorError = class extends Error {
|
|
|
5935
5940
|
}
|
|
5936
5941
|
};
|
|
5937
5942
|
var ROTATION_MAX_BACKOFF_MS = 6e4;
|
|
5943
|
+
function isReceiptAtDisplayed(event, wallet) {
|
|
5944
|
+
if (event.type !== "vtxo_received") return false;
|
|
5945
|
+
if (event.contractScript === wallet.defaultContractScript) return true;
|
|
5946
|
+
if (!isContractVtxoEvent(event)) return false;
|
|
5947
|
+
const { type, params } = event.contract;
|
|
5948
|
+
return type === chunkVIQF74QJ_cjs.ExecutorContractHandler.type && params.template === "renewal" && params.owner?.slice(2).toLowerCase() === base.hex.encode(wallet.offchainTapscript.options.pubKey);
|
|
5949
|
+
}
|
|
5938
5950
|
var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
5939
5951
|
constructor(provider, priorTaggedScript, logger) {
|
|
5940
5952
|
this.provider = provider;
|
|
@@ -5967,7 +5979,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
5967
5979
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
5968
5980
|
if (!provider) return void 0;
|
|
5969
5981
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
5970
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
5982
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
5971
5983
|
const factoryOpts = {
|
|
5972
5984
|
walletRepository: setup.walletRepository,
|
|
5973
5985
|
contractRepository: setup.contractRepository,
|
|
@@ -6028,8 +6040,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
6028
6040
|
async install(wallet) {
|
|
6029
6041
|
const manager = await wallet.getContractManager();
|
|
6030
6042
|
this.unsubscribe = manager.onContractEvent((event) => {
|
|
6031
|
-
if (event
|
|
6032
|
-
if (event.contractScript !== wallet.defaultContractScript) return;
|
|
6043
|
+
if (!isReceiptAtDisplayed(event, wallet)) return;
|
|
6033
6044
|
this.chain = this.chain.catch(() => void 0).then(() => this.runRotateWithBackoff(wallet));
|
|
6034
6045
|
});
|
|
6035
6046
|
}
|
|
@@ -6112,6 +6123,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
6112
6123
|
const newScript = params.script;
|
|
6113
6124
|
const manager = await managerPromise;
|
|
6114
6125
|
await manager.createContract(params);
|
|
6126
|
+
await wallet.registerReceiveTwin?.(descriptor);
|
|
6115
6127
|
wallet.setOffchainTapscriptForRotation(newTapscript);
|
|
6116
6128
|
const previousTagged = this.currentTaggedScript;
|
|
6117
6129
|
if (previousTagged !== void 0 && previousTagged !== newScript) {
|
|
@@ -6127,7 +6139,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
6127
6139
|
};
|
|
6128
6140
|
function deriveLeafPubkey(descriptor) {
|
|
6129
6141
|
try {
|
|
6130
|
-
return
|
|
6142
|
+
return chunkVIQF74QJ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
6131
6143
|
} catch (e) {
|
|
6132
6144
|
throw new NonRangeableDescriptorError(
|
|
6133
6145
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -6147,11 +6159,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
6147
6159
|
// Read at sign time to route rotated-pubkey inputs through `signWithDescriptor`; without
|
|
6148
6160
|
// it spends are rejected with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
6149
6161
|
metadata: {
|
|
6150
|
-
...tagSource && { source:
|
|
6162
|
+
...tagSource && { source: chunkVIQF74QJ_cjs.WALLET_RECEIVE_SOURCE },
|
|
6151
6163
|
signingDescriptor: descriptor
|
|
6152
6164
|
}
|
|
6153
6165
|
};
|
|
6154
|
-
const params = tapscript instanceof
|
|
6166
|
+
const params = tapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? {
|
|
6155
6167
|
...base$1,
|
|
6156
6168
|
type: "delegate",
|
|
6157
6169
|
params: {
|
|
@@ -6172,10 +6184,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
6172
6184
|
return { tapscript, params };
|
|
6173
6185
|
}
|
|
6174
6186
|
function rebuildTapscript(current, pubKey) {
|
|
6175
|
-
if (current instanceof
|
|
6176
|
-
return new
|
|
6187
|
+
if (current instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script) {
|
|
6188
|
+
return new chunkVIQF74QJ_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
6177
6189
|
}
|
|
6178
|
-
return new
|
|
6190
|
+
return new chunkVIQF74QJ_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
6179
6191
|
}
|
|
6180
6192
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
6181
6193
|
const candidates = await collectContracts(contractRepository, {
|
|
@@ -6220,12 +6232,19 @@ var DELEGATION_STATUS_KEY = "delegationStatus";
|
|
|
6220
6232
|
var DELEGATION_EXPIRES_KEY = "delegationExpiresAt";
|
|
6221
6233
|
var DELEGATION_REGISTERED_KEY = "delegationRegisteredAt";
|
|
6222
6234
|
var DELEGATION_LOCAL_STATUS = "local";
|
|
6235
|
+
async function ownAddress(wallet) {
|
|
6236
|
+
return chunk6TBTL42M_cjs.ArkAddress.decode(await (wallet.getOwnAddress?.() ?? wallet.getAddress()));
|
|
6237
|
+
}
|
|
6238
|
+
var SCRIPT_CACHE_LIMIT = 512;
|
|
6223
6239
|
var scriptCache = /* @__PURE__ */ new Map();
|
|
6224
6240
|
function cachedScript(params) {
|
|
6225
6241
|
const key = JSON.stringify(Object.entries(params).sort(([a], [b]) => a < b ? -1 : 1));
|
|
6226
6242
|
let script = scriptCache.get(key);
|
|
6227
6243
|
if (!script) {
|
|
6228
|
-
script =
|
|
6244
|
+
script = chunkVIQF74QJ_cjs.ExecutorContractHandler.createScript(params);
|
|
6245
|
+
if (scriptCache.size >= SCRIPT_CACHE_LIMIT) {
|
|
6246
|
+
scriptCache.delete(scriptCache.keys().next().value);
|
|
6247
|
+
}
|
|
6229
6248
|
scriptCache.set(key, script);
|
|
6230
6249
|
}
|
|
6231
6250
|
return script;
|
|
@@ -6244,40 +6263,66 @@ async function delegatedContracts(identity, getContracts, template) {
|
|
|
6244
6263
|
try {
|
|
6245
6264
|
const owner = contract.params.owner?.slice(2).toLowerCase();
|
|
6246
6265
|
const descriptor = contract.metadata?.signingDescriptor;
|
|
6247
|
-
const held = owner === identityKey || typeof descriptor === "string" && base.hex.encode(
|
|
6266
|
+
const held = owner === identityKey || typeof descriptor === "string" && base.hex.encode(chunkVIQF74QJ_cjs.deriveDescriptorLeafPubKey(descriptor)) === owner;
|
|
6248
6267
|
if (!held || owner === void 0) continue;
|
|
6249
|
-
const
|
|
6250
|
-
if (
|
|
6251
|
-
const expiresAt = contract.metadata?.[DELEGATION_EXPIRES_KEY];
|
|
6252
|
-
watches.push({
|
|
6253
|
-
contract,
|
|
6254
|
-
owner,
|
|
6255
|
-
script,
|
|
6256
|
-
signer: chunk6TBTL42M_cjs.toXOnlySignerHex(contract.params.serverPubKey),
|
|
6257
|
-
live: contract.metadata?.[DELEGATION_STATUS_KEY] === "active" && !(typeof expiresAt === "number" && expiresAt > 0 && expiresAt <= now)
|
|
6258
|
-
});
|
|
6268
|
+
const watch = watchOf(contract, owner, now);
|
|
6269
|
+
if (watch) watches.push(watch);
|
|
6259
6270
|
} catch (e) {
|
|
6260
6271
|
console.warn("Skipping malformed delegated contract", contract.script, e);
|
|
6261
6272
|
}
|
|
6262
6273
|
}
|
|
6263
6274
|
return watches;
|
|
6264
6275
|
}
|
|
6276
|
+
function watchOf(contract, owner, now) {
|
|
6277
|
+
const script = cachedScript(contract.params);
|
|
6278
|
+
if (base.hex.encode(script.pkScript) !== contract.script) return void 0;
|
|
6279
|
+
const expiresAt = contract.metadata?.[DELEGATION_EXPIRES_KEY];
|
|
6280
|
+
return {
|
|
6281
|
+
contract,
|
|
6282
|
+
owner,
|
|
6283
|
+
script,
|
|
6284
|
+
signer: chunk6TBTL42M_cjs.toXOnlySignerHex(contract.params.serverPubKey),
|
|
6285
|
+
live: contract.metadata?.[DELEGATION_STATUS_KEY] === "active" && !(typeof expiresAt === "number" && expiresAt > 0 && expiresAt <= now)
|
|
6286
|
+
};
|
|
6287
|
+
}
|
|
6288
|
+
var warnedStatusless = /* @__PURE__ */ new Set();
|
|
6289
|
+
async function receiveTwin(getContracts, owner, signer) {
|
|
6290
|
+
const rows = (await getContracts({ type: ["executor"] })).filter(
|
|
6291
|
+
(c) => c.params.template === "renewal" && c.params.owner?.slice(2).toLowerCase() === owner && c.params.serverPubKey !== void 0 && chunk6TBTL42M_cjs.toXOnlySignerHex(c.params.serverPubKey) === signer
|
|
6292
|
+
).sort((a, b) => registeredAt(b) - registeredAt(a));
|
|
6293
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
6294
|
+
for (const contract of rows) {
|
|
6295
|
+
const watch = watchOf(contract, owner, now);
|
|
6296
|
+
if (watch?.live) return watch;
|
|
6297
|
+
if (contract.metadata?.[DELEGATION_STATUS_KEY] === void 0) warnStatusless(contract);
|
|
6298
|
+
}
|
|
6299
|
+
return void 0;
|
|
6300
|
+
}
|
|
6301
|
+
function warnStatusless(contract) {
|
|
6302
|
+
if (warnedStatusless.has(contract.script)) return;
|
|
6303
|
+
if (warnedStatusless.size >= SCRIPT_CACHE_LIMIT) {
|
|
6304
|
+
warnedStatusless.delete(warnedStatusless.values().next().value);
|
|
6305
|
+
}
|
|
6306
|
+
warnedStatusless.add(contract.script);
|
|
6307
|
+
console.warn(
|
|
6308
|
+
`Executor renewal watch ${contract.address} has no delegation status, as after a restore: the wallet shows its own address until registerRenewal() confirms it`
|
|
6309
|
+
);
|
|
6310
|
+
}
|
|
6265
6311
|
async function watchExecutorContracts(wallet, keys, params, registered, descriptor) {
|
|
6266
|
-
const [owner,
|
|
6312
|
+
const [owner, { hrp, serverPubKey }, manager] = await Promise.all([
|
|
6267
6313
|
descriptor === void 0 ? wallet.identity.compressedPublicKey() : ownerKey(wallet.identity, descriptor),
|
|
6268
|
-
wallet
|
|
6314
|
+
ownAddress(wallet),
|
|
6269
6315
|
wallet.getContractManager()
|
|
6270
6316
|
]);
|
|
6271
6317
|
const signing = descriptor === void 0 || utils_js.equalBytes(owner.subarray(1), await wallet.identity.xOnlyPublicKey()) ? void 0 : descriptor;
|
|
6272
|
-
const { hrp, serverPubKey } = chunk6TBTL42M_cjs.ArkAddress.decode(address);
|
|
6273
6318
|
const templates = params.boardingExitDelay === void 0 ? ["renewal"] : ["renewal", "boarding"];
|
|
6274
6319
|
const contracts = [];
|
|
6275
6320
|
for (const template of templates) {
|
|
6276
|
-
const serialized =
|
|
6277
|
-
const script =
|
|
6321
|
+
const serialized = chunkVIQF74QJ_cjs.executorContractParams(template, owner, keys, params);
|
|
6322
|
+
const script = chunkVIQF74QJ_cjs.ExecutorContractHandler.createScript(serialized);
|
|
6278
6323
|
contracts.push(
|
|
6279
6324
|
await manager.createContract({
|
|
6280
|
-
type:
|
|
6325
|
+
type: chunkVIQF74QJ_cjs.ExecutorContractHandler.type,
|
|
6281
6326
|
params: serialized,
|
|
6282
6327
|
script: base.hex.encode(script.pkScript),
|
|
6283
6328
|
address: script.address(hrp, serverPubKey).encode(),
|
|
@@ -6301,19 +6346,19 @@ function metadataFor(template, registered, signingDescriptor) {
|
|
|
6301
6346
|
return statusMetadata(signing, registered.status, registered.expiresAt);
|
|
6302
6347
|
}
|
|
6303
6348
|
async function ownerKey(identity, descriptor) {
|
|
6304
|
-
const xOnly =
|
|
6349
|
+
const xOnly = chunkVIQF74QJ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
6305
6350
|
const own = await identity.compressedPublicKey();
|
|
6306
|
-
return utils_js.equalBytes(own.subarray(1), xOnly) ? own :
|
|
6351
|
+
return utils_js.equalBytes(own.subarray(1), xOnly) ? own : chunkVIQF74QJ_cjs.evenOwnerKey(xOnly);
|
|
6307
6352
|
}
|
|
6308
6353
|
async function boardingDescriptor(wallet, serverPubKey) {
|
|
6309
6354
|
const manager = await wallet.getContractManager();
|
|
6310
6355
|
const rows = await manager.getContracts({ type: "boarding", state: "active" });
|
|
6311
6356
|
const descriptor = newestWalletReceiveContract(rows, serverPubKey)?.metadata?.signingDescriptor;
|
|
6312
|
-
return typeof descriptor === "string" ? descriptor :
|
|
6357
|
+
return typeof descriptor === "string" ? descriptor : chunkVIQF74QJ_cjs.identityDescriptor(wallet.identity);
|
|
6313
6358
|
}
|
|
6314
6359
|
function watchDescriptor(watch, identity) {
|
|
6315
6360
|
const descriptor = watch.contract.metadata?.signingDescriptor;
|
|
6316
|
-
return typeof descriptor === "string" ? Promise.resolve(descriptor) :
|
|
6361
|
+
return typeof descriptor === "string" ? Promise.resolve(descriptor) : chunkVIQF74QJ_cjs.identityDescriptor(identity);
|
|
6317
6362
|
}
|
|
6318
6363
|
function statusMetadata(metadata, status, expiresAt, registeredAtMs = Date.now()) {
|
|
6319
6364
|
const { [DELEGATION_EXPIRES_KEY]: _stale, ...rest } = metadata;
|
|
@@ -6325,7 +6370,7 @@ function statusMetadata(metadata, status, expiresAt, registeredAtMs = Date.now()
|
|
|
6325
6370
|
};
|
|
6326
6371
|
}
|
|
6327
6372
|
function reRegistrationOf(watch) {
|
|
6328
|
-
const p =
|
|
6373
|
+
const p = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6329
6374
|
const expiresAt = watch.contract.metadata?.[DELEGATION_EXPIRES_KEY];
|
|
6330
6375
|
return {
|
|
6331
6376
|
options: {
|
|
@@ -6340,9 +6385,14 @@ function reRegistrationOf(watch) {
|
|
|
6340
6385
|
}
|
|
6341
6386
|
};
|
|
6342
6387
|
}
|
|
6388
|
+
function sameDelegation(a, b) {
|
|
6389
|
+
const p = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(a.contract.params);
|
|
6390
|
+
const q = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(b.contract.params);
|
|
6391
|
+
return p.renewalWindow === q.renewalWindow && p.maxFee === q.maxFee && p.exitDelay === q.exitDelay && p.boardingExitDelay === q.boardingExitDelay && utils_js.equalBytes(p.emulatorPubKey, q.emulatorPubKey);
|
|
6392
|
+
}
|
|
6343
6393
|
function renewalScript(owner, keys, params) {
|
|
6344
|
-
const script =
|
|
6345
|
-
|
|
6394
|
+
const script = chunkVIQF74QJ_cjs.ExecutorContractHandler.createScript(
|
|
6395
|
+
chunkVIQF74QJ_cjs.executorContractParams("renewal", owner, keys, params)
|
|
6346
6396
|
);
|
|
6347
6397
|
return base.hex.encode(script.pkScript);
|
|
6348
6398
|
}
|
|
@@ -6373,7 +6423,7 @@ var ExecutorManagerImpl = class {
|
|
|
6373
6423
|
return this.executorProvider.getInfo();
|
|
6374
6424
|
}
|
|
6375
6425
|
async defaultTemplates() {
|
|
6376
|
-
const ids = { ...
|
|
6426
|
+
const ids = { ...chunkVIQF74QJ_cjs.DEFAULT_TEMPLATE_IDS };
|
|
6377
6427
|
const templates = await this.executorProvider.listTemplates();
|
|
6378
6428
|
const active = new Set(templates.filter((t) => t.status === "active").map((t) => t.id));
|
|
6379
6429
|
const missing = Object.entries(ids).filter(([, id]) => !active.has(id));
|
|
@@ -6405,8 +6455,8 @@ var ExecutorManagerImpl = class {
|
|
|
6405
6455
|
for (const watch of await this.heldWatches("boarding")) {
|
|
6406
6456
|
if (!watch.live || watch.signer !== server) continue;
|
|
6407
6457
|
try {
|
|
6408
|
-
const p =
|
|
6409
|
-
const keys =
|
|
6458
|
+
const p = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6459
|
+
const keys = chunkVIQF74QJ_cjs.executorKeysOf(p);
|
|
6410
6460
|
if (keys.emulatorPubkey !== first.keys.emulatorPubkey.toLowerCase()) {
|
|
6411
6461
|
console.warn(
|
|
6412
6462
|
`Skipping the held key ${watch.owner}: its watch uses another emulator key than the Executor's`
|
|
@@ -6441,6 +6491,11 @@ var ExecutorManagerImpl = class {
|
|
|
6441
6491
|
}
|
|
6442
6492
|
return first;
|
|
6443
6493
|
}
|
|
6494
|
+
/** @internal The renewal watch of `descriptor`'s key alone, under the params of `options`. */
|
|
6495
|
+
async registerRenewalAt(descriptor, options, registration = {}) {
|
|
6496
|
+
const context = this.lazyContext();
|
|
6497
|
+
return await this.storedWatch(descriptor, options, registration, "renewal") ?? await this.registerAt(await context(), descriptor, options, registration, "renewal");
|
|
6498
|
+
}
|
|
6444
6499
|
/** @internal {@link registerBoarding} for `descriptor`'s key; the displayed one by default. */
|
|
6445
6500
|
async registerBoardingAt(descriptor, options, registration = {}) {
|
|
6446
6501
|
const key = descriptor ?? await this.displayedDescriptor();
|
|
@@ -6461,10 +6516,11 @@ var ExecutorManagerImpl = class {
|
|
|
6461
6516
|
* registration moves the boarding address. One that cannot be revived stops being live, and
|
|
6462
6517
|
* the wallet boards its deposits itself. A failing watch leaves the others to be tried.
|
|
6463
6518
|
*
|
|
6464
|
-
* Only a
|
|
6465
|
-
* registered other key
|
|
6466
|
-
*
|
|
6467
|
-
*
|
|
6519
|
+
* Only a watch the wallet still needs is revived: the displayed boarding and receive keys', the
|
|
6520
|
+
* most recently registered other key's, and a renewal watch whose contract holds an unspent
|
|
6521
|
+
* coin, which the Executor must keep renewing while the wallet is offline. A lapsed watch of
|
|
6522
|
+
* any other key ends instead: it never held a coin, or none is left, and reviving it would
|
|
6523
|
+
* repeat for every rotation, forever.
|
|
6468
6524
|
*
|
|
6469
6525
|
* The status reads run as called; only the writes go through `write`, so a caller that orders
|
|
6470
6526
|
* them with its rotations holds those back for one write, never for the whole refresh.
|
|
@@ -6509,7 +6565,7 @@ var ExecutorManagerImpl = class {
|
|
|
6509
6565
|
const address = template === "boarding" ? watch.script.onchainAddress(context.network) : watch.script.address(context.hrp, context.serverPubKey).encode();
|
|
6510
6566
|
try {
|
|
6511
6567
|
const details = await this.executorProvider.getDelegation(address, {
|
|
6512
|
-
signal:
|
|
6568
|
+
signal: chunkFKHUXSYW_cjs.timeoutSignal(EXECUTOR_REQUEST_TIMEOUT_MS)
|
|
6513
6569
|
});
|
|
6514
6570
|
return details.delegation.status;
|
|
6515
6571
|
} catch (e) {
|
|
@@ -6523,7 +6579,7 @@ var ExecutorManagerImpl = class {
|
|
|
6523
6579
|
(w) => w.contract.script === lapsed.contract.script
|
|
6524
6580
|
);
|
|
6525
6581
|
if (!watch?.live) return;
|
|
6526
|
-
if (!await this.keyInUse(watch.owner, context.server)) {
|
|
6582
|
+
if (!await this.keyInUse(watch.owner, context.server) && !(template === "renewal" && await this.holdsCoin(watch.contract))) {
|
|
6527
6583
|
await this.endWatch(watch, status);
|
|
6528
6584
|
return;
|
|
6529
6585
|
}
|
|
@@ -6554,19 +6610,28 @@ var ExecutorManagerImpl = class {
|
|
|
6554
6610
|
)
|
|
6555
6611
|
});
|
|
6556
6612
|
}
|
|
6613
|
+
/** Whether `contract` holds an unspent, unswept coin, as stored. */
|
|
6614
|
+
async holdsCoin(contract) {
|
|
6615
|
+
const manager = await this.wallet.getContractManager();
|
|
6616
|
+
const [stored] = await manager.getStoredContractsWithVtxos({ script: contract.script });
|
|
6617
|
+
return (stored?.vtxos ?? []).some((v) => !chunkFKHUXSYW_cjs.isVtxoSpent(v) && !v.isSwept);
|
|
6618
|
+
}
|
|
6557
6619
|
/**
|
|
6558
|
-
* The displayed key,
|
|
6559
|
-
*
|
|
6560
|
-
*
|
|
6620
|
+
* The displayed boarding key, the displayed receive key, and the most recently registered
|
|
6621
|
+
* other key with a live watch, whose params a rotation copies when the displayed key has no
|
|
6622
|
+
* watch.
|
|
6561
6623
|
*/
|
|
6562
6624
|
async keyInUse(owner, server) {
|
|
6563
6625
|
const displayed = await ownerKey(this.wallet.identity, await this.displayedDescriptor());
|
|
6564
6626
|
const displayedOwner = base.hex.encode(displayed.subarray(1));
|
|
6565
|
-
|
|
6627
|
+
const receiveOwner = this.wallet.offchainTapscript ? base.hex.encode(this.wallet.offchainTapscript.options.pubKey) : void 0;
|
|
6628
|
+
if (owner === displayedOwner || owner === receiveOwner) return true;
|
|
6566
6629
|
const others = [
|
|
6567
6630
|
...await this.heldWatches("boarding"),
|
|
6568
6631
|
...await this.heldWatches("renewal")
|
|
6569
|
-
].filter(
|
|
6632
|
+
].filter(
|
|
6633
|
+
(w) => w.live && w.signer === server && w.owner !== displayedOwner && w.owner !== receiveOwner
|
|
6634
|
+
).sort((a, b) => registeredAt(b.contract) - registeredAt(a.contract));
|
|
6570
6635
|
return others[0]?.owner === owner;
|
|
6571
6636
|
}
|
|
6572
6637
|
/**
|
|
@@ -6595,11 +6660,10 @@ var ExecutorManagerImpl = class {
|
|
|
6595
6660
|
* params, or older ones registered again to move the boarding address back.
|
|
6596
6661
|
*/
|
|
6597
6662
|
async storedWatch(descriptor, options, { emulatorPubkey }, template) {
|
|
6598
|
-
const [
|
|
6599
|
-
this.wallet
|
|
6663
|
+
const [{ hrp, serverPubKey }, owner] = await Promise.all([
|
|
6664
|
+
ownAddress(this.wallet),
|
|
6600
6665
|
ownerKey(this.wallet.identity, descriptor)
|
|
6601
6666
|
]);
|
|
6602
|
-
const { hrp, serverPubKey } = chunk6TBTL42M_cjs.ArkAddress.decode(address);
|
|
6603
6667
|
const server = base.hex.encode(serverPubKey);
|
|
6604
6668
|
const xOnlyOwner = base.hex.encode(owner.subarray(1));
|
|
6605
6669
|
const watch = (await this.heldWatches(template)).find(
|
|
@@ -6609,15 +6673,15 @@ var ExecutorManagerImpl = class {
|
|
|
6609
6673
|
const operator = await this.wallet.getOperatorInfo();
|
|
6610
6674
|
const network = chunk6TBTL42M_cjs.networkFromOperatorInfo(operator);
|
|
6611
6675
|
const params = resolveParams(options, operator, template);
|
|
6612
|
-
const p =
|
|
6676
|
+
const p = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(watch.contract.params);
|
|
6613
6677
|
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)) {
|
|
6614
6678
|
return void 0;
|
|
6615
6679
|
}
|
|
6616
6680
|
return {
|
|
6617
6681
|
address: template === "boarding" ? watch.script.onchainAddress(network) : watch.script.address(hrp, serverPubKey).encode(),
|
|
6618
|
-
templateId:
|
|
6619
|
-
variables:
|
|
6620
|
-
keys:
|
|
6682
|
+
templateId: chunkVIQF74QJ_cjs.DEFAULT_TEMPLATE_IDS[template],
|
|
6683
|
+
variables: chunkVIQF74QJ_cjs.defaultVariables(template, owner, params),
|
|
6684
|
+
keys: chunkVIQF74QJ_cjs.executorKeysOf(p),
|
|
6621
6685
|
params
|
|
6622
6686
|
};
|
|
6623
6687
|
}
|
|
@@ -6628,7 +6692,7 @@ var ExecutorManagerImpl = class {
|
|
|
6628
6692
|
}
|
|
6629
6693
|
/** The wallet's operator key, x-only hex: the signer a live watch is registered under. */
|
|
6630
6694
|
async operatorSigner() {
|
|
6631
|
-
return base.hex.encode(
|
|
6695
|
+
return base.hex.encode((await ownAddress(this.wallet)).serverPubKey);
|
|
6632
6696
|
}
|
|
6633
6697
|
/**
|
|
6634
6698
|
* Both templates register the displayed boarding key: boarding moves its deposits in, renewal
|
|
@@ -6656,11 +6720,11 @@ var ExecutorManagerImpl = class {
|
|
|
6656
6720
|
`Executor runs on ${info.network}, the wallet's operator on ${operator.network}`
|
|
6657
6721
|
);
|
|
6658
6722
|
}
|
|
6659
|
-
const { hrp, serverPubKey } =
|
|
6723
|
+
const { hrp, serverPubKey } = await ownAddress(this.wallet);
|
|
6660
6724
|
const server = base.hex.encode(serverPubKey);
|
|
6661
|
-
if (info.
|
|
6725
|
+
if (info.operatorPubkey.slice(2).toLowerCase() !== server) {
|
|
6662
6726
|
throw new Error(
|
|
6663
|
-
`Executor's operator key ${info.
|
|
6727
|
+
`Executor's operator key ${info.operatorPubkey} is not the wallet's operator ${server}`
|
|
6664
6728
|
);
|
|
6665
6729
|
}
|
|
6666
6730
|
return {
|
|
@@ -6687,19 +6751,19 @@ var ExecutorManagerImpl = class {
|
|
|
6687
6751
|
const owner = await ownerKey(this.wallet.identity, descriptor);
|
|
6688
6752
|
const params = resolveParams(options, operator, template);
|
|
6689
6753
|
const keys = {
|
|
6690
|
-
|
|
6691
|
-
|
|
6754
|
+
batchCosignerPubkey: info.batchCosignerPubkey,
|
|
6755
|
+
operatorPubkey: info.operatorPubkey,
|
|
6692
6756
|
emulatorPubkey: info.emulatorPubkey
|
|
6693
6757
|
};
|
|
6694
|
-
const variables =
|
|
6695
|
-
const watchScript =
|
|
6696
|
-
|
|
6758
|
+
const variables = chunkVIQF74QJ_cjs.defaultVariables(template, owner, params);
|
|
6759
|
+
const watchScript = chunkVIQF74QJ_cjs.ExecutorContractHandler.createScript(
|
|
6760
|
+
chunkVIQF74QJ_cjs.executorContractParams(template, owner, keys, params)
|
|
6697
6761
|
);
|
|
6698
6762
|
const watchAddress = template === "boarding" ? watchScript.onchainAddress(network) : watchScript.address(hrp, serverPubKey).encode();
|
|
6699
|
-
const templateId =
|
|
6763
|
+
const templateId = chunkVIQF74QJ_cjs.DEFAULT_TEMPLATE_IDS[template];
|
|
6700
6764
|
const delegation = await this.executorProvider.registerDelegation(templateId, variables, {
|
|
6701
6765
|
expiresAt,
|
|
6702
|
-
signal:
|
|
6766
|
+
signal: chunkFKHUXSYW_cjs.timeoutSignal(EXECUTOR_REQUEST_TIMEOUT_MS)
|
|
6703
6767
|
});
|
|
6704
6768
|
const [input] = delegation.inputs;
|
|
6705
6769
|
if (delegation.inputs.length !== 1 || !input || (template === "boarding" ? !input.onchain : input.onchain)) {
|
|
@@ -6753,7 +6817,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
6753
6817
|
continue;
|
|
6754
6818
|
}
|
|
6755
6819
|
for (const v of vtxos) {
|
|
6756
|
-
if (!
|
|
6820
|
+
if (!chunkFKHUXSYW_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
|
|
6757
6821
|
out.add(`${v.txid}:${v.vout}`);
|
|
6758
6822
|
}
|
|
6759
6823
|
}
|
|
@@ -6796,7 +6860,7 @@ function byValueDescending(vtxos) {
|
|
|
6796
6860
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
6797
6861
|
}
|
|
6798
6862
|
async function fetchTimeHeight(wallet) {
|
|
6799
|
-
return
|
|
6863
|
+
return chunkFKHUXSYW_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
6800
6864
|
}
|
|
6801
6865
|
function heldVtxosOf(wallet) {
|
|
6802
6866
|
const held = wallet.getHeldVtxos;
|
|
@@ -6807,7 +6871,7 @@ async function heldOutpointsOf(wallet) {
|
|
|
6807
6871
|
return new Set((await heldVtxosOf(wallet)).map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
6808
6872
|
}
|
|
6809
6873
|
function canMigrateBySend(vtxo, now) {
|
|
6810
|
-
if (!
|
|
6874
|
+
if (!chunkFKHUXSYW_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
6811
6875
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
6812
6876
|
}
|
|
6813
6877
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -6815,7 +6879,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
6815
6879
|
if (vtxo.isSwept) return -Infinity;
|
|
6816
6880
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
6817
6881
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
6818
|
-
return
|
|
6882
|
+
return chunkFKHUXSYW_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
6819
6883
|
}
|
|
6820
6884
|
return Infinity;
|
|
6821
6885
|
};
|
|
@@ -6842,7 +6906,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
6842
6906
|
const payable = [];
|
|
6843
6907
|
const net = /* @__PURE__ */ new Map();
|
|
6844
6908
|
for (const vtxo of vtxos) {
|
|
6845
|
-
const inputFee = estimator.evalOffchainInput(
|
|
6909
|
+
const inputFee = estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(vtxo));
|
|
6846
6910
|
if (inputFee.satoshis >= vtxo.value) {
|
|
6847
6911
|
continue;
|
|
6848
6912
|
}
|
|
@@ -6922,10 +6986,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
6922
6986
|
};
|
|
6923
6987
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
6924
6988
|
return vtxos.filter((vtxo) => {
|
|
6925
|
-
if (
|
|
6989
|
+
if (chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now)) {
|
|
6926
6990
|
return true;
|
|
6927
6991
|
}
|
|
6928
|
-
if (
|
|
6992
|
+
if (chunkFKHUXSYW_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
6929
6993
|
return true;
|
|
6930
6994
|
}
|
|
6931
6995
|
return false;
|
|
@@ -6957,7 +7021,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
6957
7021
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
6958
7022
|
if (vtxo.isUnrolled) return false;
|
|
6959
7023
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
6960
|
-
const expiresAt =
|
|
7024
|
+
const expiresAt = chunkFKHUXSYW_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
6961
7025
|
if (expiresAt === void 0) return false;
|
|
6962
7026
|
const now = Date.now();
|
|
6963
7027
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -6968,7 +7032,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
|
6968
7032
|
return vtxos.filter(
|
|
6969
7033
|
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
6970
7034
|
// property and would otherwise re-admit an exited coin on its own.
|
|
6971
|
-
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
7035
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
6972
7036
|
);
|
|
6973
7037
|
}
|
|
6974
7038
|
function isMigrationCapable(wallet) {
|
|
@@ -7041,7 +7105,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7041
7105
|
constructor(wallet, settlementConfig) {
|
|
7042
7106
|
this.wallet = wallet;
|
|
7043
7107
|
if (settlementConfig !== false) {
|
|
7044
|
-
|
|
7108
|
+
chunkFKHUXSYW_cjs.assertTimerMs("pollIntervalMs", settlementConfig?.pollIntervalMs);
|
|
7045
7109
|
}
|
|
7046
7110
|
this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
7047
7111
|
this.contractEventsSubscriptionReady = this.initializeSubscription();
|
|
@@ -7360,7 +7424,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7360
7424
|
* {@link recoverImportedContracts}).
|
|
7361
7425
|
*/
|
|
7362
7426
|
async recoverOneImportedContract(wallet, contract, vtxos, info, dustAmount) {
|
|
7363
|
-
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !
|
|
7427
|
+
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !chunkFKHUXSYW_cjs.isVtxoSpent(vtxo));
|
|
7364
7428
|
const estimator = new Estimator(info?.fees.intentFee ?? {});
|
|
7365
7429
|
const { payable, net } = priceSettlementInputs(recoverable, estimator);
|
|
7366
7430
|
const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
|
|
@@ -7394,7 +7458,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7394
7458
|
if (vtxos.length === 0) return;
|
|
7395
7459
|
const spent = new Set(batch.map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
7396
7460
|
const stillSpendable = vtxos.some(
|
|
7397
|
-
(vtxo) => !
|
|
7461
|
+
(vtxo) => !chunkFKHUXSYW_cjs.isVtxoSpent(vtxo) && !spent.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
7398
7462
|
);
|
|
7399
7463
|
if (!stillSpendable) {
|
|
7400
7464
|
await wallet.removeRecoveryContract(contract.script);
|
|
@@ -7468,7 +7532,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7468
7532
|
const live = watches.filter((w) => w.live && w.signer === signer);
|
|
7469
7533
|
return vtxos.filter((vtxo) => {
|
|
7470
7534
|
const watch = live.find((w) => w.contract.script === vtxo.script);
|
|
7471
|
-
if (!watch ||
|
|
7535
|
+
if (!watch || chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dust)) return true;
|
|
7472
7536
|
if (BigInt(vtxo.value) <= BigInt(watch.contract.params.maxFee) + dust) return true;
|
|
7473
7537
|
const expiresAt = vtxo.expiresAt?.getTime();
|
|
7474
7538
|
if (expiresAt === void 0) return true;
|
|
@@ -7670,7 +7734,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7670
7734
|
return txid;
|
|
7671
7735
|
} catch (e) {
|
|
7672
7736
|
if (!isCosignFallback(e)) throw e;
|
|
7673
|
-
if (e instanceof
|
|
7737
|
+
if (e instanceof chunkFKHUXSYW_cjs.OnchainCosignRejectedError) {
|
|
7674
7738
|
console.warn("Onchain cosign sweep rejected, falling back to CSV exit:", e.message);
|
|
7675
7739
|
}
|
|
7676
7740
|
return void 0;
|
|
@@ -7747,7 +7811,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
7747
7811
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
7748
7812
|
);
|
|
7749
7813
|
}
|
|
7750
|
-
const tx = new
|
|
7814
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction();
|
|
7751
7815
|
for (const { utxo, script, leaf } of inputs) {
|
|
7752
7816
|
tx.addInput({
|
|
7753
7817
|
txid: utxo.txid,
|
|
@@ -7992,8 +8056,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
7992
8056
|
const cls = chunk6TBTL42M_cjs.classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
7993
8057
|
if (cls.status === "CURRENT") continue;
|
|
7994
8058
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
7995
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
7996
|
-
const spendable = live.filter((v) => !
|
|
8059
|
+
const recoverable = live.filter((v) => v.isSwept && !chunkFKHUXSYW_cjs.isVtxoSpent(v));
|
|
8060
|
+
const spendable = live.filter((v) => !chunkFKHUXSYW_cjs.isVtxoSpent(v) && !v.isSwept);
|
|
7997
8061
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
7998
8062
|
let recoverableCount = 0;
|
|
7999
8063
|
let recoverableValue = 0;
|
|
@@ -8349,8 +8413,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
8349
8413
|
}
|
|
8350
8414
|
/** The outpoint a `VTXO_ALREADY_SPENT` error carries in `metadata.vtxo_outpoint`, if any. */
|
|
8351
8415
|
extractSpentOutpoint(error) {
|
|
8352
|
-
const ark =
|
|
8353
|
-
if (!
|
|
8416
|
+
const ark = chunkFKHUXSYW_cjs.maybeArkError(error);
|
|
8417
|
+
if (!chunkFKHUXSYW_cjs.isArkError(ark, chunkFKHUXSYW_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
8354
8418
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
8355
8419
|
if (typeof raw !== "string") return void 0;
|
|
8356
8420
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -8541,7 +8605,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
8541
8605
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
8542
8606
|
break;
|
|
8543
8607
|
}
|
|
8544
|
-
const inputFee = estimator.evalOffchainInput(
|
|
8608
|
+
const inputFee = estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(v));
|
|
8545
8609
|
if (inputFee.satoshis >= v.value) {
|
|
8546
8610
|
continue;
|
|
8547
8611
|
}
|
|
@@ -8853,7 +8917,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
8853
8917
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
8854
8918
|
}
|
|
8855
8919
|
get vtxoScript() {
|
|
8856
|
-
return new
|
|
8920
|
+
return new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
8857
8921
|
pubKey: this._publicKey,
|
|
8858
8922
|
serverPubKey: this._serverPubKey,
|
|
8859
8923
|
csvTimelock: this.csvTimelock
|
|
@@ -8958,7 +9022,7 @@ function reservationOutpointSetKey(outpoints) {
|
|
|
8958
9022
|
// src/wallet/intentReconciliation.ts
|
|
8959
9023
|
var NON_TERMINAL_INTENT_STATES = ALL_BATCH_REGISTRATION_STATES.filter((s) => !isTerminalBatchRegistrationState(s));
|
|
8960
9024
|
function isConsumed(vtxo) {
|
|
8961
|
-
return vtxo !== void 0 &&
|
|
9025
|
+
return vtxo !== void 0 && chunkFKHUXSYW_cjs.isVtxoSpent(vtxo);
|
|
8962
9026
|
}
|
|
8963
9027
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
8964
9028
|
if (isTerminalBatchRegistrationState(intent.state)) return void 0;
|
|
@@ -8996,7 +9060,7 @@ async function reconcileIntents(deps) {
|
|
|
8996
9060
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
8997
9061
|
if (outpoints.length > 0) {
|
|
8998
9062
|
try {
|
|
8999
|
-
const { vtxos } = await
|
|
9063
|
+
const { vtxos } = await chunkFKHUXSYW_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9000
9064
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9001
9065
|
} catch (e) {
|
|
9002
9066
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9056,7 +9120,7 @@ async function releaseFromServer(intent, deps, now) {
|
|
|
9056
9120
|
});
|
|
9057
9121
|
}
|
|
9058
9122
|
function isNoMatchingIntentsError(e) {
|
|
9059
|
-
return
|
|
9123
|
+
return chunkFKHUXSYW_cjs.isArkError(e, chunkFKHUXSYW_cjs.ArkErrorName.INVALID_INTENT_PROOF) && e.message.includes("no matching intents found");
|
|
9060
9124
|
}
|
|
9061
9125
|
function terminal(intent, state, now, patch) {
|
|
9062
9126
|
return { ...intent, ...patch, state, updatedAt: now };
|
|
@@ -9283,7 +9347,7 @@ async function captureExitBranch(params) {
|
|
|
9283
9347
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
9284
9348
|
if (nonCommitment.length > 0) {
|
|
9285
9349
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
9286
|
-
psbtByTxid.set(
|
|
9350
|
+
psbtByTxid.set(chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
9287
9351
|
}
|
|
9288
9352
|
}
|
|
9289
9353
|
}
|
|
@@ -9321,10 +9385,10 @@ var IndexerExitDataSource = class {
|
|
|
9321
9385
|
name = "indexer";
|
|
9322
9386
|
async getVtxoChain(vtxo) {
|
|
9323
9387
|
const chain = [];
|
|
9324
|
-
for await (const { chain: page } of
|
|
9388
|
+
for await (const { chain: page } of chunkFKHUXSYW_cjs.indexerPages(
|
|
9325
9389
|
(pageIndex) => this.indexer.getVtxoChain(
|
|
9326
9390
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
9327
|
-
{ pageIndex, pageSize:
|
|
9391
|
+
{ pageIndex, pageSize: chunkFKHUXSYW_cjs.DEFAULT_PAGE_SIZE }
|
|
9328
9392
|
)
|
|
9329
9393
|
)) {
|
|
9330
9394
|
chain.push(...page);
|
|
@@ -9333,11 +9397,11 @@ var IndexerExitDataSource = class {
|
|
|
9333
9397
|
}
|
|
9334
9398
|
async getVirtualTxs(txids) {
|
|
9335
9399
|
const out = /* @__PURE__ */ new Map();
|
|
9336
|
-
for await (const { txs } of
|
|
9337
|
-
(pageIndex) => this.indexer.getVirtualTxs(txids, { pageIndex, pageSize:
|
|
9400
|
+
for await (const { txs } of chunkFKHUXSYW_cjs.indexerPages(
|
|
9401
|
+
(pageIndex) => this.indexer.getVirtualTxs(txids, { pageIndex, pageSize: chunkFKHUXSYW_cjs.DEFAULT_PAGE_SIZE })
|
|
9338
9402
|
)) {
|
|
9339
9403
|
for (const psbt of txs) {
|
|
9340
|
-
out.set(
|
|
9404
|
+
out.set(chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
9341
9405
|
}
|
|
9342
9406
|
}
|
|
9343
9407
|
return out;
|
|
@@ -9358,7 +9422,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
9358
9422
|
}
|
|
9359
9423
|
}
|
|
9360
9424
|
function psbtInputTxids(psbtBase64) {
|
|
9361
|
-
return txInputTxids(
|
|
9425
|
+
return txInputTxids(chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64)));
|
|
9362
9426
|
}
|
|
9363
9427
|
function txInputTxids(tx) {
|
|
9364
9428
|
const ids = [];
|
|
@@ -9665,10 +9729,10 @@ async function resolveArkInfo(arkProvider, walletRepository, opts) {
|
|
|
9665
9729
|
try {
|
|
9666
9730
|
info = await arkProvider.getInfo();
|
|
9667
9731
|
} catch (err) {
|
|
9668
|
-
if (opts?.requireLive || !
|
|
9732
|
+
if (opts?.requireLive || !chunkFKHUXSYW_cjs.isRetryableProviderError(err)) throw err;
|
|
9669
9733
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
9670
9734
|
if (!snapshot) {
|
|
9671
|
-
throw new
|
|
9735
|
+
throw new chunkFKHUXSYW_cjs.ProviderUnavailableError(
|
|
9672
9736
|
"Operator info is unavailable and no cached snapshot exists",
|
|
9673
9737
|
{ cause: err }
|
|
9674
9738
|
);
|
|
@@ -9848,7 +9912,7 @@ function buildGraph(rootTxid, chunksByTxid, visited = /* @__PURE__ */ new Set())
|
|
|
9848
9912
|
return new TxTree(rootTx, children);
|
|
9849
9913
|
}
|
|
9850
9914
|
function decodeNode(chunk) {
|
|
9851
|
-
const tx =
|
|
9915
|
+
const tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(chunk.tx));
|
|
9852
9916
|
return { tx, children: chunk.children };
|
|
9853
9917
|
}
|
|
9854
9918
|
exports.Batch = void 0;
|
|
@@ -10072,7 +10136,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
|
|
|
10072
10136
|
return [...txids];
|
|
10073
10137
|
}
|
|
10074
10138
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
|
|
10075
|
-
const normalized = vtxos.map(
|
|
10139
|
+
const normalized = vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
10076
10140
|
const localCreatedAt = localCreatedAtByTxid(normalized);
|
|
10077
10141
|
const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
|
|
10078
10142
|
const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
|
|
@@ -10259,7 +10323,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10259
10323
|
withRecoverable: false,
|
|
10260
10324
|
genericallySpendableOnly: true
|
|
10261
10325
|
});
|
|
10262
|
-
const controlAssetRef = params.controlAssetId ?
|
|
10326
|
+
const controlAssetRef = params.controlAssetId ? chunkJSYS2KX3_cjs.AssetRef.fromId(chunkJSYS2KX3_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
10263
10327
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
10264
10328
|
let totalBtcSelected = 0n;
|
|
10265
10329
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -10272,8 +10336,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10272
10336
|
}
|
|
10273
10337
|
}
|
|
10274
10338
|
const groups = [];
|
|
10275
|
-
const issuedAssetOutput =
|
|
10276
|
-
const issuedAssetGroup =
|
|
10339
|
+
const issuedAssetOutput = chunkJSYS2KX3_cjs.AssetOutput.create(0, params.amount);
|
|
10340
|
+
const issuedAssetGroup = chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
10277
10341
|
null,
|
|
10278
10342
|
controlAssetRef,
|
|
10279
10343
|
[],
|
|
@@ -10286,11 +10350,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10286
10350
|
for (const [assetId, amount] of assetChanges) {
|
|
10287
10351
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10288
10352
|
groups.push(
|
|
10289
|
-
|
|
10290
|
-
|
|
10353
|
+
chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
10354
|
+
chunkJSYS2KX3_cjs.AssetId.fromString(assetId),
|
|
10291
10355
|
null,
|
|
10292
10356
|
changeInputs,
|
|
10293
|
-
[
|
|
10357
|
+
[chunkJSYS2KX3_cjs.AssetOutput.create(0, amount)],
|
|
10294
10358
|
[]
|
|
10295
10359
|
)
|
|
10296
10360
|
);
|
|
@@ -10305,7 +10369,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10305
10369
|
);
|
|
10306
10370
|
return {
|
|
10307
10371
|
arkTxId: arkTxid,
|
|
10308
|
-
assetId:
|
|
10372
|
+
assetId: chunkJSYS2KX3_cjs.AssetId.create(arkTxid, 0).toString()
|
|
10309
10373
|
};
|
|
10310
10374
|
}
|
|
10311
10375
|
/**
|
|
@@ -10379,23 +10443,23 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10379
10443
|
const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
|
|
10380
10444
|
const reissueInputs = inputsForAsset(assetInputs, params.assetId);
|
|
10381
10445
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
10382
|
-
const reissueAssetIdObj =
|
|
10383
|
-
const reissueAssetGroup =
|
|
10446
|
+
const reissueAssetIdObj = chunkJSYS2KX3_cjs.AssetId.fromString(params.assetId);
|
|
10447
|
+
const reissueAssetGroup = chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
10384
10448
|
reissueAssetIdObj,
|
|
10385
10449
|
null,
|
|
10386
10450
|
reissueInputs,
|
|
10387
|
-
[
|
|
10451
|
+
[chunkJSYS2KX3_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
10388
10452
|
[]
|
|
10389
10453
|
);
|
|
10390
10454
|
const groups = [reissueAssetGroup];
|
|
10391
10455
|
for (const [assetId, amount] of assetChanges) {
|
|
10392
10456
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10393
10457
|
groups.push(
|
|
10394
|
-
|
|
10395
|
-
|
|
10458
|
+
chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
10459
|
+
chunkJSYS2KX3_cjs.AssetId.fromString(assetId),
|
|
10396
10460
|
null,
|
|
10397
10461
|
changeInputs,
|
|
10398
|
-
[
|
|
10462
|
+
[chunkJSYS2KX3_cjs.AssetOutput.create(0, amount)],
|
|
10399
10463
|
[]
|
|
10400
10464
|
)
|
|
10401
10465
|
);
|
|
@@ -10466,11 +10530,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
10466
10530
|
for (const [assetId, amount] of assetChanges) {
|
|
10467
10531
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
10468
10532
|
groups.push(
|
|
10469
|
-
|
|
10470
|
-
|
|
10533
|
+
chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
10534
|
+
chunkJSYS2KX3_cjs.AssetId.fromString(assetId),
|
|
10471
10535
|
null,
|
|
10472
10536
|
changeInputs,
|
|
10473
|
-
amount > 0n ? [
|
|
10537
|
+
amount > 0n ? [chunkJSYS2KX3_cjs.AssetOutput.create(0, amount)] : [],
|
|
10474
10538
|
[]
|
|
10475
10539
|
)
|
|
10476
10540
|
);
|
|
@@ -10483,7 +10547,7 @@ function inputsForAsset(assetInputs, assetId) {
|
|
|
10483
10547
|
for (const [inputIndex, assets] of assetInputs) {
|
|
10484
10548
|
for (const asset of assets) {
|
|
10485
10549
|
if (asset.assetId !== assetId) continue;
|
|
10486
|
-
inputs.push(
|
|
10550
|
+
inputs.push(chunkJSYS2KX3_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
10487
10551
|
}
|
|
10488
10552
|
}
|
|
10489
10553
|
return inputs;
|
|
@@ -10492,7 +10556,7 @@ async function submitToSelf(submit, wallet, inputs, amount, groups) {
|
|
|
10492
10556
|
const outputAddress = chunk6TBTL42M_cjs.ArkAddress.decode(await wallet.getAddress());
|
|
10493
10557
|
const outputs = [
|
|
10494
10558
|
{ script: outputAddress.pkScript, amount: BigInt(amount) },
|
|
10495
|
-
Extension.create([
|
|
10559
|
+
Extension.create([chunkJSYS2KX3_cjs.Packet.create(groups)]).txOut()
|
|
10496
10560
|
];
|
|
10497
10561
|
const { arkTxid } = await submit(inputs, outputs);
|
|
10498
10562
|
return arkTxid;
|
|
@@ -10516,7 +10580,7 @@ function castMetadata(metadata) {
|
|
|
10516
10580
|
} else {
|
|
10517
10581
|
throw new Error("Invalid metadata value type");
|
|
10518
10582
|
}
|
|
10519
|
-
md.push(
|
|
10583
|
+
md.push(chunkJSYS2KX3_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
10520
10584
|
}
|
|
10521
10585
|
return md;
|
|
10522
10586
|
}
|
|
@@ -10542,7 +10606,7 @@ var DelegateManagerImpl = class {
|
|
|
10542
10606
|
this.arkInfoProvider.getInfo(),
|
|
10543
10607
|
this.delegateProvider.getDelegateInfo()
|
|
10544
10608
|
]);
|
|
10545
|
-
const eligible = vtxos.map(
|
|
10609
|
+
const eligible = vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo).filter(
|
|
10546
10610
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
10547
10611
|
);
|
|
10548
10612
|
if (eligible.length === 0) {
|
|
@@ -10574,7 +10638,7 @@ var DelegateManagerImpl = class {
|
|
|
10574
10638
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
10575
10639
|
let recoverableVtxos = [];
|
|
10576
10640
|
for (const vtxo of eligible) {
|
|
10577
|
-
if (
|
|
10641
|
+
if (chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now)) {
|
|
10578
10642
|
recoverableVtxos.push(vtxo);
|
|
10579
10643
|
continue;
|
|
10580
10644
|
}
|
|
@@ -10626,7 +10690,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10626
10690
|
}
|
|
10627
10691
|
if (!delegateAt) {
|
|
10628
10692
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
10629
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
10693
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkFKHUXSYW_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
|
|
10630
10694
|
(min, coin) => Math.min(min, coin.expiresAt.getTime()),
|
|
10631
10695
|
Number.MAX_SAFE_INTEGER
|
|
10632
10696
|
);
|
|
@@ -10646,7 +10710,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10646
10710
|
let amount = 0n;
|
|
10647
10711
|
for (const coin of vtxos) {
|
|
10648
10712
|
const inputFee = estimator.evalOffchainInput({
|
|
10649
|
-
...
|
|
10713
|
+
...chunkFKHUXSYW_cjs.toOffchainInputFeeParams(coin),
|
|
10650
10714
|
type: "vtxo"
|
|
10651
10715
|
});
|
|
10652
10716
|
if (inputFee.satoshis >= coin.value) {
|
|
@@ -10701,7 +10765,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
10701
10765
|
btcSigner.Address(chunk6TBTL42M_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
10702
10766
|
);
|
|
10703
10767
|
const forfeits = await Promise.all(
|
|
10704
|
-
vtxos.filter((v) =>
|
|
10768
|
+
vtxos.filter((v) => chunkFKHUXSYW_cjs.requiresForfeit(v)).map(async (coin) => {
|
|
10705
10769
|
const forfeit = await makeDelegateForfeitTx(
|
|
10706
10770
|
coin,
|
|
10707
10771
|
dust,
|
|
@@ -10784,7 +10848,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
10784
10848
|
expire_at: 0,
|
|
10785
10849
|
cosigners_public_keys: cosignerPubKeys
|
|
10786
10850
|
};
|
|
10787
|
-
const proof =
|
|
10851
|
+
const proof = chunkFKHUXSYW_cjs.Proof.create(message, coins, outputs);
|
|
10788
10852
|
const signedProof = await identity.sign(proof);
|
|
10789
10853
|
return {
|
|
10790
10854
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -11573,7 +11637,7 @@ function decodeArkContract(encoded) {
|
|
|
11573
11637
|
}
|
|
11574
11638
|
function contractFromArkContract(encoded, options = {}) {
|
|
11575
11639
|
const parsed = decodeArkContract(encoded);
|
|
11576
|
-
const handler =
|
|
11640
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(parsed.type);
|
|
11577
11641
|
if (!handler) {
|
|
11578
11642
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
11579
11643
|
}
|
|
@@ -11589,7 +11653,7 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
11589
11653
|
}
|
|
11590
11654
|
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk6TBTL42M_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
11591
11655
|
const parsed = decodeArkContract(encoded);
|
|
11592
|
-
const handler =
|
|
11656
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
11593
11657
|
const params = parsed.data;
|
|
11594
11658
|
const vtxoScript = handler.createScript(params);
|
|
11595
11659
|
return {
|
|
@@ -11648,10 +11712,10 @@ var ContractWatcher = class {
|
|
|
11648
11712
|
eventSourceReported = false;
|
|
11649
11713
|
/** @see ContractWatcherConfig */
|
|
11650
11714
|
constructor(config) {
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
|
|
11654
|
-
|
|
11715
|
+
chunkFKHUXSYW_cjs.assertTimerMs("failsafePollIntervalMs", config.failsafePollIntervalMs);
|
|
11716
|
+
chunkFKHUXSYW_cjs.assertTimerMs("reconnectDelayMs", config.reconnectDelayMs);
|
|
11717
|
+
chunkFKHUXSYW_cjs.assertTimerMs("maxReconnectDelayMs", config.maxReconnectDelayMs);
|
|
11718
|
+
chunkFKHUXSYW_cjs.assertTimerMs("subscriptionRequestTimeoutMs", config.subscriptionRequestTimeoutMs);
|
|
11655
11719
|
if (config.subscriptionRequestTimeoutMs === 0) {
|
|
11656
11720
|
throw new Error("subscriptionRequestTimeoutMs must be greater than 0");
|
|
11657
11721
|
}
|
|
@@ -11876,9 +11940,9 @@ var ContractWatcher = class {
|
|
|
11876
11940
|
this.connectedAt = Date.now();
|
|
11877
11941
|
this.listenLoop().catch((e) => {
|
|
11878
11942
|
if (!this.isWatching || signal?.aborted) return;
|
|
11879
|
-
if (
|
|
11943
|
+
if (chunkFKHUXSYW_cjs.isEventSourceError(e)) {
|
|
11880
11944
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
11881
|
-
} else if (!
|
|
11945
|
+
} else if (!chunkFKHUXSYW_cjs.isEventSourceUnavailableError(e)) {
|
|
11882
11946
|
console.error(e);
|
|
11883
11947
|
}
|
|
11884
11948
|
this.connectionState = "disconnected";
|
|
@@ -11888,7 +11952,7 @@ var ContractWatcher = class {
|
|
|
11888
11952
|
});
|
|
11889
11953
|
} catch (error) {
|
|
11890
11954
|
if (!this.isWatching || signal?.aborted) return;
|
|
11891
|
-
if (!
|
|
11955
|
+
if (!chunkFKHUXSYW_cjs.isEventSourceUnavailableError(error)) {
|
|
11892
11956
|
console.error("ContractWatcher connection failed:", error);
|
|
11893
11957
|
}
|
|
11894
11958
|
this.connectionState = "disconnected";
|
|
@@ -11904,7 +11968,7 @@ var ContractWatcher = class {
|
|
|
11904
11968
|
* few seconds.
|
|
11905
11969
|
*/
|
|
11906
11970
|
reportEventSourceUnavailable(error) {
|
|
11907
|
-
if (!
|
|
11971
|
+
if (!chunkFKHUXSYW_cjs.isEventSourceUnavailableError(error)) return false;
|
|
11908
11972
|
if (!this.eventSourceReported) {
|
|
11909
11973
|
this.eventSourceReported = true;
|
|
11910
11974
|
console.warn(
|
|
@@ -11945,7 +12009,7 @@ var ContractWatcher = class {
|
|
|
11945
12009
|
this.config.reconnectDelayMs,
|
|
11946
12010
|
this.config.maxReconnectDelayMs
|
|
11947
12011
|
);
|
|
11948
|
-
const askedFor = Math.min(
|
|
12012
|
+
const askedFor = Math.min(chunkFKHUXSYW_cjs.retryAfterMsFromError(failure2) ?? 0, chunkFKHUXSYW_cjs.MAX_COOLDOWN_MS);
|
|
11949
12013
|
const floor = Math.max(capped / 2, askedFor);
|
|
11950
12014
|
const ceiling = Math.max(capped, askedFor * 1.5);
|
|
11951
12015
|
return floor + Math.random() * (ceiling - floor);
|
|
@@ -11985,7 +12049,7 @@ var ContractWatcher = class {
|
|
|
11985
12049
|
const now = Date.now();
|
|
11986
12050
|
let current;
|
|
11987
12051
|
try {
|
|
11988
|
-
current = await
|
|
12052
|
+
current = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
11989
12053
|
spendableOnly: true
|
|
11990
12054
|
});
|
|
11991
12055
|
} catch (error) {
|
|
@@ -12267,14 +12331,14 @@ var ContractWatcher = class {
|
|
|
12267
12331
|
const timestamp = Date.now();
|
|
12268
12332
|
if (update.newVtxos?.length) {
|
|
12269
12333
|
this.processSubscriptionVtxos(
|
|
12270
|
-
update.newVtxos.map(
|
|
12334
|
+
update.newVtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo),
|
|
12271
12335
|
"vtxo_received",
|
|
12272
12336
|
timestamp
|
|
12273
12337
|
);
|
|
12274
12338
|
}
|
|
12275
12339
|
if (update.spentVtxos?.length) {
|
|
12276
12340
|
this.processSubscriptionVtxos(
|
|
12277
|
-
update.spentVtxos.map(
|
|
12341
|
+
update.spentVtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo),
|
|
12278
12342
|
"vtxo_spent",
|
|
12279
12343
|
timestamp
|
|
12280
12344
|
);
|
|
@@ -12299,8 +12363,8 @@ var ContractWatcher = class {
|
|
|
12299
12363
|
continue;
|
|
12300
12364
|
}
|
|
12301
12365
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
12302
|
-
const n =
|
|
12303
|
-
if (
|
|
12366
|
+
const n = chunkFKHUXSYW_cjs.normalizeVtxo(vtxo);
|
|
12367
|
+
if (chunkFKHUXSYW_cjs.isVtxoSpent(n) || n.isSwept || chunkFKHUXSYW_cjs.isPastExpiry(n, now)) continue;
|
|
12304
12368
|
}
|
|
12305
12369
|
let bucket = target.get(vtxo.script);
|
|
12306
12370
|
if (!bucket) {
|
|
@@ -12488,7 +12552,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
12488
12552
|
if (!contract) continue;
|
|
12489
12553
|
try {
|
|
12490
12554
|
const key = contractKey(contract);
|
|
12491
|
-
const handler =
|
|
12555
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
12492
12556
|
const hit = memo?.get(script);
|
|
12493
12557
|
let tapscripts;
|
|
12494
12558
|
if (hit && hit.key === key && hit.handler === handler) {
|
|
@@ -12509,7 +12573,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
12509
12573
|
scripts.add(script);
|
|
12510
12574
|
} catch (err) {
|
|
12511
12575
|
const reason = `'${contract.type}' at ${script}: ${err instanceof Error ? err.message : String(err)}`;
|
|
12512
|
-
if (err instanceof
|
|
12576
|
+
if (err instanceof chunkUNLH3NNG_cjs.UnsupportedProgramVersionError) {
|
|
12513
12577
|
unsupported.set(script, { key: contractKey(contract), reason });
|
|
12514
12578
|
} else {
|
|
12515
12579
|
failures.set(script, reason);
|
|
@@ -12520,7 +12584,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
12520
12584
|
}
|
|
12521
12585
|
function annotateAgainst(vtxos, byScript, tapscripts = /* @__PURE__ */ new Map()) {
|
|
12522
12586
|
return vtxos.map(
|
|
12523
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
12587
|
+
(vtxo) => extendVirtualCoinForContract(chunkFKHUXSYW_cjs.normalizeVtxo(vtxo), byScript, tapscripts)
|
|
12524
12588
|
);
|
|
12525
12589
|
}
|
|
12526
12590
|
var SCAN_MAX_INDEX = 1e4;
|
|
@@ -12569,8 +12633,8 @@ var ContractManager = class _ContractManager {
|
|
|
12569
12633
|
/** Serializes onchain read-modify-writes so a pending spender is never overwritten. */
|
|
12570
12634
|
onchainChain = Promise.resolve();
|
|
12571
12635
|
constructor(config) {
|
|
12572
|
-
|
|
12573
|
-
|
|
12636
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", config.vtxoSyncMaxAgeMs);
|
|
12637
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", config.vtxoSyncOverlapMs);
|
|
12574
12638
|
this.config = { ...config };
|
|
12575
12639
|
if (config.onchainProvider && config.network) {
|
|
12576
12640
|
this.onchainWatcher = new OnchainContractWatcher({
|
|
@@ -12615,12 +12679,12 @@ var ContractManager = class _ContractManager {
|
|
|
12615
12679
|
}
|
|
12616
12680
|
/** @see ContractManagerConfig.vtxoSyncMaxAgeMs — for factory-built managers. */
|
|
12617
12681
|
setVtxoSyncMaxAge(maxAgeMs) {
|
|
12618
|
-
|
|
12682
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", maxAgeMs);
|
|
12619
12683
|
this.config.vtxoSyncMaxAgeMs = maxAgeMs;
|
|
12620
12684
|
}
|
|
12621
12685
|
/** @see ContractManagerConfig.vtxoSyncOverlapMs — for factory-built managers. */
|
|
12622
12686
|
setVtxoSyncOverlap(overlapMs) {
|
|
12623
|
-
|
|
12687
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", overlapMs);
|
|
12624
12688
|
this.config.vtxoSyncOverlapMs = overlapMs;
|
|
12625
12689
|
}
|
|
12626
12690
|
markSyncOnline() {
|
|
@@ -12684,10 +12748,10 @@ var ContractManager = class _ContractManager {
|
|
|
12684
12748
|
if (this.unsupportedContracts.get(contract.script) === key) return true;
|
|
12685
12749
|
if (this.tapscriptMemo.get(contract.script)?.key === key) return false;
|
|
12686
12750
|
try {
|
|
12687
|
-
|
|
12751
|
+
chunkVIQF74QJ_cjs.contractHandlers.get(contract.type)?.createScript(contract.params);
|
|
12688
12752
|
return false;
|
|
12689
12753
|
} catch (err) {
|
|
12690
|
-
if (!(err instanceof
|
|
12754
|
+
if (!(err instanceof chunkUNLH3NNG_cjs.UnsupportedProgramVersionError)) return false;
|
|
12691
12755
|
this.unsupportedContracts.set(contract.script, key);
|
|
12692
12756
|
return true;
|
|
12693
12757
|
}
|
|
@@ -12700,7 +12764,7 @@ var ContractManager = class _ContractManager {
|
|
|
12700
12764
|
this.markSyncOnline();
|
|
12701
12765
|
return void 0;
|
|
12702
12766
|
} catch (err) {
|
|
12703
|
-
if (!
|
|
12767
|
+
if (!chunkFKHUXSYW_cjs.isRetryableProviderError(err)) throw err;
|
|
12704
12768
|
this.markSyncDegraded(err);
|
|
12705
12769
|
return err;
|
|
12706
12770
|
}
|
|
@@ -12723,7 +12787,7 @@ var ContractManager = class _ContractManager {
|
|
|
12723
12787
|
try {
|
|
12724
12788
|
await this.scheduleLookAheadDrain();
|
|
12725
12789
|
} catch (err) {
|
|
12726
|
-
if (!
|
|
12790
|
+
if (!chunkFKHUXSYW_cjs.isRetryableProviderError(err)) throw err;
|
|
12727
12791
|
this.lookAheadRefillOwed = true;
|
|
12728
12792
|
this.markSyncDegraded(err);
|
|
12729
12793
|
}
|
|
@@ -12786,7 +12850,7 @@ var ContractManager = class _ContractManager {
|
|
|
12786
12850
|
/** No throw: construction returned long ago, so the state is the channel. */
|
|
12787
12851
|
reportBackgroundFailure(stage, err) {
|
|
12788
12852
|
this.markSyncDegraded(err);
|
|
12789
|
-
if (!
|
|
12853
|
+
if (!chunkFKHUXSYW_cjs.isRetryableProviderError(err)) {
|
|
12790
12854
|
console.error(`[contracts] background ${stage} failed`, err);
|
|
12791
12855
|
}
|
|
12792
12856
|
}
|
|
@@ -12898,7 +12962,7 @@ var ContractManager = class _ContractManager {
|
|
|
12898
12962
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
12899
12963
|
const to = watermark + lookAhead.size;
|
|
12900
12964
|
const deps = lookAhead.candidateDeps();
|
|
12901
|
-
const handlers =
|
|
12965
|
+
const handlers = chunkVIQF74QJ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkVIQF74QJ_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
12902
12966
|
const band = /* @__PURE__ */ new Map();
|
|
12903
12967
|
for (let index = from; index <= to; index++) {
|
|
12904
12968
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -12909,7 +12973,7 @@ var ContractManager = class _ContractManager {
|
|
|
12909
12973
|
index,
|
|
12910
12974
|
params: {
|
|
12911
12975
|
...candidate,
|
|
12912
|
-
...
|
|
12976
|
+
...chunkVIQF74QJ_cjs.speculativeReceiveMetadata(descriptor)
|
|
12913
12977
|
}
|
|
12914
12978
|
});
|
|
12915
12979
|
}
|
|
@@ -12968,7 +13032,7 @@ var ContractManager = class _ContractManager {
|
|
|
12968
13032
|
});
|
|
12969
13033
|
for (const entry of pending) entry.catchUpPending = false;
|
|
12970
13034
|
} catch (err) {
|
|
12971
|
-
if (!
|
|
13035
|
+
if (!chunkFKHUXSYW_cjs.isRetryableProviderError(err)) throw err;
|
|
12972
13036
|
this.markSyncDegraded(err);
|
|
12973
13037
|
}
|
|
12974
13038
|
}
|
|
@@ -13061,7 +13125,7 @@ var ContractManager = class _ContractManager {
|
|
|
13061
13125
|
return result;
|
|
13062
13126
|
}
|
|
13063
13127
|
async upsertContractRow(params) {
|
|
13064
|
-
const handler =
|
|
13128
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(params.type);
|
|
13065
13129
|
if (!handler) {
|
|
13066
13130
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
13067
13131
|
}
|
|
@@ -13170,7 +13234,7 @@ var ContractManager = class _ContractManager {
|
|
|
13170
13234
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
13171
13235
|
);
|
|
13172
13236
|
}
|
|
13173
|
-
const registered =
|
|
13237
|
+
const registered = chunkVIQF74QJ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkVIQF74QJ_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
13174
13238
|
const discoverables = [
|
|
13175
13239
|
...registered.filter((h) => h.type === "boarding"),
|
|
13176
13240
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -13301,7 +13365,7 @@ var ContractManager = class _ContractManager {
|
|
|
13301
13365
|
return contracts.filter((contract) => this.isUnsupported(contract));
|
|
13302
13366
|
}
|
|
13303
13367
|
async getContractsWithVtxos(filter, pageSize, options) {
|
|
13304
|
-
|
|
13368
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("maxSyncAgeMs", options?.maxSyncAgeMs);
|
|
13305
13369
|
const contracts = await this.getContracts(filter);
|
|
13306
13370
|
if (this.syncedWithin(
|
|
13307
13371
|
contracts,
|
|
@@ -13409,7 +13473,7 @@ var ContractManager = class _ContractManager {
|
|
|
13409
13473
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
13410
13474
|
const asking = vtxos.filter((vtxo) => {
|
|
13411
13475
|
const contract = byScript.get(vtxo.script);
|
|
13412
|
-
return contract !== void 0 &&
|
|
13476
|
+
return contract !== void 0 && chunkVIQF74QJ_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
13413
13477
|
});
|
|
13414
13478
|
if (asking.length === 0) return refused;
|
|
13415
13479
|
const [tip, walletDescriptorValue] = await Promise.all([
|
|
@@ -13418,7 +13482,7 @@ var ContractManager = class _ContractManager {
|
|
|
13418
13482
|
]);
|
|
13419
13483
|
for (const vtxo of asking) {
|
|
13420
13484
|
const contract = byScript.get(vtxo.script);
|
|
13421
|
-
const handler =
|
|
13485
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
13422
13486
|
if (!handler?.assertSpendableNow) continue;
|
|
13423
13487
|
const context = {
|
|
13424
13488
|
collaborative: true,
|
|
@@ -13428,7 +13492,7 @@ var ContractManager = class _ContractManager {
|
|
|
13428
13492
|
walletDescriptor: walletDescriptorValue,
|
|
13429
13493
|
// `isVirtualCoin` only checks `script`, which every input has; `isCsvSpendable`
|
|
13430
13494
|
// reads `vtxo.status.block_time` unguarded, so require `status` too.
|
|
13431
|
-
vtxo:
|
|
13495
|
+
vtxo: chunkFKHUXSYW_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
13432
13496
|
};
|
|
13433
13497
|
try {
|
|
13434
13498
|
await handler.assertSpendableNow(
|
|
@@ -13542,7 +13606,7 @@ var ContractManager = class _ContractManager {
|
|
|
13542
13606
|
const { contractScript, collaborative = true, walletDescriptor, vtxo } = options;
|
|
13543
13607
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
13544
13608
|
if (!contract) return [];
|
|
13545
|
-
const handler =
|
|
13609
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
13546
13610
|
if (!handler) return [];
|
|
13547
13611
|
const script = handler.createScript(contract.params);
|
|
13548
13612
|
const tip = await this.currentChainTip();
|
|
@@ -13564,7 +13628,7 @@ var ContractManager = class _ContractManager {
|
|
|
13564
13628
|
const { contractScript, collaborative = true, walletDescriptor } = options;
|
|
13565
13629
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
13566
13630
|
if (!contract) return [];
|
|
13567
|
-
const handler =
|
|
13631
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
13568
13632
|
if (!handler) return [];
|
|
13569
13633
|
const script = handler.createScript(contract.params);
|
|
13570
13634
|
const context = {
|
|
@@ -13610,7 +13674,7 @@ var ContractManager = class _ContractManager {
|
|
|
13610
13674
|
}
|
|
13611
13675
|
async refreshOutpoints(outpoints) {
|
|
13612
13676
|
if (outpoints.length === 0) return;
|
|
13613
|
-
const { vtxos } = await
|
|
13677
|
+
const { vtxos } = await chunkFKHUXSYW_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
13614
13678
|
outpoints
|
|
13615
13679
|
});
|
|
13616
13680
|
if (vtxos.length === 0) return;
|
|
@@ -13673,7 +13737,7 @@ var ContractManager = class _ContractManager {
|
|
|
13673
13737
|
* retarget adds their addresses to the onchain watch. Best-effort: the next sync retries.
|
|
13674
13738
|
*/
|
|
13675
13739
|
async syncNewOnchain(contracts) {
|
|
13676
|
-
const scripts = contracts.filter((c) => c.type ===
|
|
13740
|
+
const scripts = contracts.filter((c) => c.type === chunkVIQF74QJ_cjs.ExecutorContractHandler.type && isOnchainScoped(c)).map((c) => c.script);
|
|
13677
13741
|
if (scripts.length === 0) return;
|
|
13678
13742
|
await this.syncOnchain(scripts).catch(
|
|
13679
13743
|
(e) => console.warn("[contracts] onchain sync of new contracts failed", e)
|
|
@@ -13746,7 +13810,7 @@ var ContractManager = class _ContractManager {
|
|
|
13746
13810
|
...Object.values(pending).map((p) => p.script)
|
|
13747
13811
|
]);
|
|
13748
13812
|
const targets = contracts.filter(
|
|
13749
|
-
(c) =>
|
|
13813
|
+
(c) => chunkVIQF74QJ_cjs.contractHandlers.has(c.type) && (c.state === "active" && isOnchainScoped(c) || owners.has(c.script))
|
|
13750
13814
|
);
|
|
13751
13815
|
const wanted = scripts && new Set(scripts);
|
|
13752
13816
|
const settled = [];
|
|
@@ -13781,7 +13845,7 @@ var ContractManager = class _ContractManager {
|
|
|
13781
13845
|
).catch((e) => console.warn("[contracts] onchain watch failed", e));
|
|
13782
13846
|
}
|
|
13783
13847
|
async syncOnchainContract(contract, onchainProvider, network, pending, tipHeight, prefetched) {
|
|
13784
|
-
|
|
13848
|
+
chunkVIQF74QJ_cjs.contractHandlers.get(contract.type).createScript(contract.params);
|
|
13785
13849
|
const coins = prefetched ?? await onchainProvider.getCoins(onchainAddressOf(contract, network));
|
|
13786
13850
|
const stored = new Map(
|
|
13787
13851
|
(await getVtxosForContract(this.config.walletRepository, contract)).map((v) => [
|
|
@@ -13879,8 +13943,8 @@ var ContractManager = class _ContractManager {
|
|
|
13879
13943
|
const found = /* @__PURE__ */ new Map();
|
|
13880
13944
|
if (!indexerProvider.getUtxos || rows.length === 0) return found;
|
|
13881
13945
|
try {
|
|
13882
|
-
for (let i = 0; i < rows.length; i +=
|
|
13883
|
-
const outpoints = rows.slice(i, i +
|
|
13946
|
+
for (let i = 0; i < rows.length; i += chunkFKHUXSYW_cjs.OUTPOINT_QUERY_CHUNK_SIZE) {
|
|
13947
|
+
const outpoints = rows.slice(i, i + chunkFKHUXSYW_cjs.OUTPOINT_QUERY_CHUNK_SIZE).map(({ txid, vout }) => ({ txid, vout }));
|
|
13884
13948
|
let pageIndex;
|
|
13885
13949
|
let pages = 0;
|
|
13886
13950
|
do {
|
|
@@ -13890,7 +13954,7 @@ var ContractManager = class _ContractManager {
|
|
|
13890
13954
|
const { utxos, page } = await indexerProvider.getUtxos({
|
|
13891
13955
|
outpoints,
|
|
13892
13956
|
pageIndex,
|
|
13893
|
-
pageSize:
|
|
13957
|
+
pageSize: chunkFKHUXSYW_cjs.OUTPOINT_QUERY_CHUNK_SIZE
|
|
13894
13958
|
});
|
|
13895
13959
|
for (const utxo of utxos) found.set(vtxoOutpoint(utxo), utxo);
|
|
13896
13960
|
const more = page && page.current < page.total && page.next > page.current;
|
|
@@ -13898,7 +13962,7 @@ var ContractManager = class _ContractManager {
|
|
|
13898
13962
|
} while (pageIndex !== void 0);
|
|
13899
13963
|
}
|
|
13900
13964
|
} catch (e) {
|
|
13901
|
-
if (e instanceof
|
|
13965
|
+
if (e instanceof chunkJSYS2KX3_cjs.IndexerUtxosUnsupportedError) return found;
|
|
13902
13966
|
console.warn("[contracts] arkd spend lookup failed; using the explorer", e);
|
|
13903
13967
|
return void 0;
|
|
13904
13968
|
}
|
|
@@ -13951,7 +14015,7 @@ var ContractManager = class _ContractManager {
|
|
|
13951
14015
|
break;
|
|
13952
14016
|
}
|
|
13953
14017
|
} catch (err) {
|
|
13954
|
-
if (!
|
|
14018
|
+
if (!chunkFKHUXSYW_cjs.isRetryableProviderError(err)) throw err;
|
|
13955
14019
|
this.markSyncDegraded(err);
|
|
13956
14020
|
synced = false;
|
|
13957
14021
|
}
|
|
@@ -14039,7 +14103,7 @@ var ContractManager = class _ContractManager {
|
|
|
14039
14103
|
*/
|
|
14040
14104
|
async reconcilePendingFrontier(contracts) {
|
|
14041
14105
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
14042
|
-
const vtxos = await
|
|
14106
|
+
const vtxos = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(
|
|
14043
14107
|
this.config.indexerProvider,
|
|
14044
14108
|
contracts.map((c) => c.script),
|
|
14045
14109
|
{ pendingOnly: true }
|
|
@@ -14114,7 +14178,7 @@ var ContractManager = class _ContractManager {
|
|
|
14114
14178
|
}
|
|
14115
14179
|
return result;
|
|
14116
14180
|
}
|
|
14117
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
14181
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkFKHUXSYW_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
14118
14182
|
if (contracts.length === 0) {
|
|
14119
14183
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
14120
14184
|
}
|
|
@@ -14130,7 +14194,7 @@ var ContractManager = class _ContractManager {
|
|
|
14130
14194
|
before: syncWindow.before
|
|
14131
14195
|
}
|
|
14132
14196
|
} : {};
|
|
14133
|
-
const vtxos = await
|
|
14197
|
+
const vtxos = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(
|
|
14134
14198
|
this.config.indexerProvider,
|
|
14135
14199
|
contracts.map((c) => c.script),
|
|
14136
14200
|
{ ...windowOpts, pageSize }
|
|
@@ -14237,7 +14301,7 @@ function parseLegacyExpiry(batchExpiry) {
|
|
|
14237
14301
|
if (typeof batchExpiry !== "number" || !Number.isFinite(batchExpiry) || batchExpiry <= 0) {
|
|
14238
14302
|
return {};
|
|
14239
14303
|
}
|
|
14240
|
-
if (batchExpiry >=
|
|
14304
|
+
if (batchExpiry >= chunkFKHUXSYW_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
|
|
14241
14305
|
return { expiresAtHeight: batchExpiry / 1e3 };
|
|
14242
14306
|
}
|
|
14243
14307
|
function legacyVtxoFacts(status) {
|
|
@@ -14475,7 +14539,7 @@ function backfillContractWatchState(store) {
|
|
|
14475
14539
|
};
|
|
14476
14540
|
readPage();
|
|
14477
14541
|
}
|
|
14478
|
-
var unspentFlag = (vtxo) =>
|
|
14542
|
+
var unspentFlag = (vtxo) => chunkFKHUXSYW_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
|
|
14479
14543
|
function backfillVtxoIndexFields(transaction) {
|
|
14480
14544
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
14481
14545
|
const pageSize = 1e3;
|
|
@@ -14506,7 +14570,7 @@ var DEFAULT_DB_NAME = "arkade-service-worker";
|
|
|
14506
14570
|
var DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS = 1e4;
|
|
14507
14571
|
function normalizeOptions2(pathOrOptions) {
|
|
14508
14572
|
const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
14509
|
-
|
|
14573
|
+
chunkFKHUXSYW_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
|
|
14510
14574
|
return {
|
|
14511
14575
|
path: o.path,
|
|
14512
14576
|
activationTimeoutMs: o.activationTimeoutMs ?? DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS
|
|
@@ -14734,7 +14798,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
14734
14798
|
var deserializeVtxo = ({
|
|
14735
14799
|
intentTapLeafScript,
|
|
14736
14800
|
...o
|
|
14737
|
-
}) =>
|
|
14801
|
+
}) => chunkFKHUXSYW_cjs.normalizeVtxo({
|
|
14738
14802
|
...o,
|
|
14739
14803
|
createdAt: new Date(o.createdAt),
|
|
14740
14804
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -15134,7 +15198,7 @@ var RestEmulatorProvider = class {
|
|
|
15134
15198
|
serverUrl;
|
|
15135
15199
|
async getInfo() {
|
|
15136
15200
|
const url = `${this.serverUrl}/v1/info`;
|
|
15137
|
-
const response = await
|
|
15201
|
+
const response = await chunkFKHUXSYW_cjs.baseFetch(url);
|
|
15138
15202
|
if (!response.ok) {
|
|
15139
15203
|
const errorText2 = await response.text();
|
|
15140
15204
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -15258,7 +15322,7 @@ function arkadeServiceUrl(service) {
|
|
|
15258
15322
|
}
|
|
15259
15323
|
async function resolveArkadeService(service, opts = {}) {
|
|
15260
15324
|
const operatorUrl = arkadeServiceUrl(service);
|
|
15261
|
-
const arkProvider = opts.arkProvider ?? new
|
|
15325
|
+
const arkProvider = opts.arkProvider ?? new chunkFKHUXSYW_cjs.RestOperatorProvider(operatorUrl);
|
|
15262
15326
|
const info = opts.info ?? await arkProvider.getInfo();
|
|
15263
15327
|
if ("network" in service && service.network !== info.network) {
|
|
15264
15328
|
throw new Error(
|
|
@@ -15277,7 +15341,7 @@ async function resolveArkadeService(service, opts = {}) {
|
|
|
15277
15341
|
}
|
|
15278
15342
|
return {
|
|
15279
15343
|
arkProvider,
|
|
15280
|
-
indexerProvider: new
|
|
15344
|
+
indexerProvider: new chunkJSYS2KX3_cjs.RestIndexerProvider(operatorUrl),
|
|
15281
15345
|
onchainProvider: new EsploraProvider(esploraUrl),
|
|
15282
15346
|
emulator,
|
|
15283
15347
|
info
|
|
@@ -15298,7 +15362,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
15298
15362
|
try {
|
|
15299
15363
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
15300
15364
|
for (const psbt of txs) {
|
|
15301
|
-
const tx =
|
|
15365
|
+
const tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
15302
15366
|
resolved.set(tx.id, tx.toBytes());
|
|
15303
15367
|
}
|
|
15304
15368
|
} catch (err) {
|
|
@@ -15331,7 +15395,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
15331
15395
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
15332
15396
|
const pending = [];
|
|
15333
15397
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
15334
|
-
if (
|
|
15398
|
+
if (chunkFKHUXSYW_cjs.getArkPsbtFields(tx, i, chunkFKHUXSYW_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
15335
15399
|
}
|
|
15336
15400
|
if (pending.length === 0) return;
|
|
15337
15401
|
const resolved = await resolvePrevTxs(
|
|
@@ -15340,13 +15404,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
15340
15404
|
onchain
|
|
15341
15405
|
);
|
|
15342
15406
|
for (const i of pending) {
|
|
15343
|
-
|
|
15407
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(tx, i, chunkFKHUXSYW_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
15344
15408
|
}
|
|
15345
15409
|
}
|
|
15346
15410
|
async function attachPrevoutTxs(tx, source) {
|
|
15347
15411
|
const pending = [];
|
|
15348
15412
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
15349
|
-
if (
|
|
15413
|
+
if (chunkFKHUXSYW_cjs.getArkPsbtFields(tx, i, chunkFKHUXSYW_cjs.PrevoutTxField).length > 0) continue;
|
|
15350
15414
|
const input = tx.getInput(i);
|
|
15351
15415
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
15352
15416
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -15361,7 +15425,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
15361
15425
|
resolved.set(txids[i], result.value);
|
|
15362
15426
|
}
|
|
15363
15427
|
for (const { index, txid } of pending) {
|
|
15364
|
-
|
|
15428
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(tx, index, chunkFKHUXSYW_cjs.PrevoutTxField, resolved.get(txid));
|
|
15365
15429
|
}
|
|
15366
15430
|
}
|
|
15367
15431
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -15402,7 +15466,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
15402
15466
|
}
|
|
15403
15467
|
};
|
|
15404
15468
|
for (const vtxo of vtxos) {
|
|
15405
|
-
if (
|
|
15469
|
+
if (chunkFKHUXSYW_cjs.isVtxoSpent(vtxo)) continue;
|
|
15406
15470
|
addAssets(owned, vtxo);
|
|
15407
15471
|
if (vtxo.isUnrolled) {
|
|
15408
15472
|
unrolled += vtxo.value;
|
|
@@ -15412,11 +15476,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
15412
15476
|
deprecatedSignerLocked += vtxo.value;
|
|
15413
15477
|
continue;
|
|
15414
15478
|
}
|
|
15415
|
-
if (
|
|
15479
|
+
if (chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15416
15480
|
recoverable += vtxo.value;
|
|
15417
15481
|
continue;
|
|
15418
15482
|
}
|
|
15419
|
-
if (!
|
|
15483
|
+
if (!chunkFKHUXSYW_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
15420
15484
|
if (vtxo.isPreconfirmed) {
|
|
15421
15485
|
preconfirmed += vtxo.value;
|
|
15422
15486
|
} else {
|
|
@@ -15674,6 +15738,7 @@ var MAX_USED_SIGNING_DESCRIPTORS_LOOK_AHEAD = 1e3;
|
|
|
15674
15738
|
var MAINNET_UNILATERAL_EXIT_DELAY = 605184n;
|
|
15675
15739
|
var EXECUTOR_REFRESH_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
15676
15740
|
var EXECUTOR_REFRESHED_KEY = "executorRefreshedAt";
|
|
15741
|
+
var EXECUTOR_RECEIVE_RETRY_MS = 10 * 60 * 1e3;
|
|
15677
15742
|
function dedupeTimelocks(timelocks) {
|
|
15678
15743
|
const seen = /* @__PURE__ */ new Set();
|
|
15679
15744
|
const deduped = [];
|
|
@@ -15694,7 +15759,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
15694
15759
|
if (!newest?.params.pubKey) return baseline;
|
|
15695
15760
|
try {
|
|
15696
15761
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
15697
|
-
return new
|
|
15762
|
+
return new chunkVIQF74QJ_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
15698
15763
|
} catch (e) {
|
|
15699
15764
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
15700
15765
|
return baseline;
|
|
@@ -15726,21 +15791,21 @@ function filterFlatVtxos(vtxos, filter, pendingSpendOutpoints) {
|
|
|
15726
15791
|
if (vtxo.isUnrolled) {
|
|
15727
15792
|
return !!f.withUnrolled;
|
|
15728
15793
|
}
|
|
15729
|
-
if (
|
|
15794
|
+
if (chunkFKHUXSYW_cjs.isVtxoSpent(vtxo)) {
|
|
15730
15795
|
return false;
|
|
15731
15796
|
}
|
|
15732
|
-
if (!f.withRecoverable &&
|
|
15797
|
+
if (!f.withRecoverable && chunkFKHUXSYW_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15733
15798
|
return false;
|
|
15734
15799
|
}
|
|
15735
15800
|
return true;
|
|
15736
15801
|
});
|
|
15737
15802
|
}
|
|
15738
15803
|
async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
15739
|
-
const candidates = inputs.filter(
|
|
15804
|
+
const candidates = inputs.filter(chunkFKHUXSYW_cjs.isVirtualCoin).map(chunkFKHUXSYW_cjs.normalizeVtxo).filter((v) => !v.isSwept);
|
|
15740
15805
|
if (candidates.length === 0) return inputs;
|
|
15741
|
-
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await
|
|
15806
|
+
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await chunkFKHUXSYW_cjs.resolveTimeHeight(wallet.onchainProvider) : { timestamp: /* @__PURE__ */ new Date() };
|
|
15742
15807
|
const suspects = candidates.filter(
|
|
15743
|
-
(v) =>
|
|
15808
|
+
(v) => chunkFKHUXSYW_cjs.isPastExpiry(v, now) || v.expiresAtHeight !== void 0 && now.height === void 0
|
|
15744
15809
|
);
|
|
15745
15810
|
if (suspects.length === 0) return inputs;
|
|
15746
15811
|
let sweptNow;
|
|
@@ -15754,12 +15819,12 @@ async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
|
15754
15819
|
);
|
|
15755
15820
|
} catch (e) {
|
|
15756
15821
|
const message = "could not confirm the swept state of expired settlement inputs; retry the settlement";
|
|
15757
|
-
throw
|
|
15822
|
+
throw chunkFKHUXSYW_cjs.isRetryableProviderError(e) ? new chunkFKHUXSYW_cjs.ProviderUnavailableError(message, { cause: e }) : new Error(message, { cause: e });
|
|
15758
15823
|
}
|
|
15759
15824
|
if (sweptNow.size === 0) return inputs;
|
|
15760
15825
|
return inputs.map((input) => {
|
|
15761
|
-
if (!
|
|
15762
|
-
return { ...
|
|
15826
|
+
if (!chunkFKHUXSYW_cjs.isVirtualCoin(input) || !sweptNow.has(`${input.txid}:${input.vout}`)) return input;
|
|
15827
|
+
return { ...chunkFKHUXSYW_cjs.normalizeVtxo(input), isSwept: true };
|
|
15763
15828
|
});
|
|
15764
15829
|
}
|
|
15765
15830
|
var PENDING_RECOVERY_REASON = "is past its operator signer's rotation cutoff \u2014 the operator will not co-sign it until it recovers";
|
|
@@ -16083,7 +16148,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16083
16148
|
async getArkadeReader() {
|
|
16084
16149
|
const indexer = this.indexerProvider;
|
|
16085
16150
|
return {
|
|
16086
|
-
getVtxos: (opts) =>
|
|
16151
|
+
getVtxos: (opts) => chunkFKHUXSYW_cjs.getNormalizedVtxos(indexer, opts),
|
|
16087
16152
|
getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
|
|
16088
16153
|
};
|
|
16089
16154
|
}
|
|
@@ -16134,7 +16199,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16134
16199
|
"Pass either `service` or `operatorProvider`/`indexerProvider`/`onchainProvider`, not both"
|
|
16135
16200
|
);
|
|
16136
16201
|
}
|
|
16137
|
-
const arkProvider = callerProvider || new
|
|
16202
|
+
const arkProvider = callerProvider || new chunkFKHUXSYW_cjs.RestOperatorProvider(config.service ? arkadeServiceUrl(config.service) : void 0);
|
|
16138
16203
|
let indexerProvider = config.indexerProvider;
|
|
16139
16204
|
if (!indexerProvider && !config.service) {
|
|
16140
16205
|
const derived = extractOperatorProviderUrl(arkProvider);
|
|
@@ -16143,7 +16208,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16143
16208
|
"indexerProvider is required when operatorProvider is provided without a discoverable serverUrl"
|
|
16144
16209
|
);
|
|
16145
16210
|
}
|
|
16146
|
-
indexerProvider = new
|
|
16211
|
+
indexerProvider = new chunkJSYS2KX3_cjs.RestIndexerProvider(derived ?? chunk6TBTL42M_cjs.DEFAULT_ARKADE_SERVER_URL);
|
|
16147
16212
|
}
|
|
16148
16213
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
16149
16214
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -16201,8 +16266,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16201
16266
|
serverPubKey,
|
|
16202
16267
|
csvTimelock: exitTimelock
|
|
16203
16268
|
};
|
|
16204
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
16205
|
-
const boardingTapscript =
|
|
16269
|
+
const offchainTapscript = !delegatePubKey ? new chunkVIQF74QJ_cjs.DefaultVtxo.Script(offchainOptions) : new chunkVIQF74QJ_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
16270
|
+
const boardingTapscript = chunkVIQF74QJ_cjs.BoardingContractHandler.createScript({
|
|
16206
16271
|
pubKey: base.hex.encode(pubKey),
|
|
16207
16272
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
16208
16273
|
csvTimelock: chunk6TBTL42M_cjs.timelockToSequence(boardingTimelock).toString()
|
|
@@ -16266,9 +16331,17 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16266
16331
|
wallet.refreshDeprecatedSigners(setup.info);
|
|
16267
16332
|
return wallet;
|
|
16268
16333
|
}
|
|
16334
|
+
/**
|
|
16335
|
+
* The wallet's own address, under its own key: what its hrp and operator key are read from.
|
|
16336
|
+
* Not where to receive; that is {@link getAddress}, which answers the delegated twin once the
|
|
16337
|
+
* Executor watches this key.
|
|
16338
|
+
*/
|
|
16269
16339
|
get arkAddress() {
|
|
16270
16340
|
return this.offchainTapscript.address(this.network.hrp, this.arkServerPublicKey);
|
|
16271
16341
|
}
|
|
16342
|
+
async getOwnAddress() {
|
|
16343
|
+
return this.arkAddress.encode();
|
|
16344
|
+
}
|
|
16272
16345
|
/**
|
|
16273
16346
|
* Get the pkScript hex for the wallet's primary offchain address.
|
|
16274
16347
|
* For the full wallet-owned script set registered in ContractManager, use getWalletScripts().
|
|
@@ -16277,11 +16350,42 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16277
16350
|
return base.hex.encode(this.offchainTapscript.pkScript);
|
|
16278
16351
|
}
|
|
16279
16352
|
/**
|
|
16280
|
-
* Returns the
|
|
16281
|
-
*
|
|
16353
|
+
* Returns the Arkade address to receive at: the delegated twin of the current receive key
|
|
16354
|
+
* while its Executor renewal watch is live, so the Executor renews what lands here while the
|
|
16355
|
+
* wallet is offline; the wallet's own address otherwise. See
|
|
16356
|
+
* {@link IExecutorManager.registerRenewal}.
|
|
16357
|
+
*
|
|
16358
|
+
* The answer changes without a receipt when a watch registers or ends, and when the operator
|
|
16359
|
+
* signer rotates: do not store it. Use {@link arkAddress} for the wallet's own address.
|
|
16282
16360
|
*/
|
|
16283
16361
|
async getAddress() {
|
|
16284
|
-
|
|
16362
|
+
const serverPubKey = this.arkServerPublicKey;
|
|
16363
|
+
const tapscript = await this.destinationTapscript(serverPubKey);
|
|
16364
|
+
return tapscript.address(this.network.hrp, serverPubKey).encode();
|
|
16365
|
+
}
|
|
16366
|
+
/**
|
|
16367
|
+
* Where receives go under `serverPubKey`: the live Executor renewal watch of the receive key
|
|
16368
|
+
* (the delegated twin), else `own`. With `amount`, a twin the Executor cannot renew it at
|
|
16369
|
+
* (`maxFee + dust` or less) gives way to `own`. Fail-open: a lookup must not fail a receive.
|
|
16370
|
+
*
|
|
16371
|
+
* Callers read `own` and `serverPubKey` before their first await, then pass them here.
|
|
16372
|
+
*/
|
|
16373
|
+
async destinationTapscript(serverPubKey, own = this.offchainTapscript, amount) {
|
|
16374
|
+
try {
|
|
16375
|
+
const twin = await receiveTwin(
|
|
16376
|
+
(filter) => collectContracts(this.contractRepository, filter),
|
|
16377
|
+
base.hex.encode(own.options.pubKey),
|
|
16378
|
+
chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(serverPubKey))
|
|
16379
|
+
);
|
|
16380
|
+
if (twin && (amount === void 0 || this.renews(twin, amount))) return twin.script;
|
|
16381
|
+
} catch (e) {
|
|
16382
|
+
console.warn("Unable to inspect Executor renewal watches", e);
|
|
16383
|
+
}
|
|
16384
|
+
return own;
|
|
16385
|
+
}
|
|
16386
|
+
/** Whether the Executor can renew `amount` at `watch`: not for `maxFee + dust` or less. */
|
|
16387
|
+
renews(watch, amount) {
|
|
16388
|
+
return amount > BigInt(watch.contract.params.maxFee) + this.dustAmount;
|
|
16285
16389
|
}
|
|
16286
16390
|
/**
|
|
16287
16391
|
* Returns the onchain boarding address used to move funds into Arkade: with an Executor
|
|
@@ -16420,7 +16524,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16420
16524
|
if (!filter?.withUnrolled) {
|
|
16421
16525
|
logExcludedVtxos(
|
|
16422
16526
|
"getSpendableVtxos",
|
|
16423
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
16527
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkFKHUXSYW_cjs.isVtxoSpent(vtxo)),
|
|
16424
16528
|
[() => UNROLLED_REASON]
|
|
16425
16529
|
);
|
|
16426
16530
|
}
|
|
@@ -16562,7 +16666,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16562
16666
|
]);
|
|
16563
16667
|
const snapshot = fullSnapshot.filter(({ contract }) => !isRecoveryOnlyContract(contract));
|
|
16564
16668
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
16565
|
-
const resolveTxCreatedAt = (txids) =>
|
|
16669
|
+
const resolveTxCreatedAt = (txids) => chunkFKHUXSYW_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
16566
16670
|
return buildTransactionHistory(
|
|
16567
16671
|
allVtxos,
|
|
16568
16672
|
boardingTxs,
|
|
@@ -16762,11 +16866,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16762
16866
|
const currentServerPubKey = this.boardingTapscript.options.serverPubKey;
|
|
16763
16867
|
const currentServerSigner = chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(currentServerPubKey));
|
|
16764
16868
|
const signers = /* @__PURE__ */ new Set([currentServerSigner, ...allowedSigners ?? []]);
|
|
16765
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
16869
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
16766
16870
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
16767
16871
|
for (const signer of signers) {
|
|
16768
16872
|
add(
|
|
16769
|
-
new
|
|
16873
|
+
new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
16770
16874
|
pubKey: baselinePubkey,
|
|
16771
16875
|
serverPubKey: base.hex.decode(signer),
|
|
16772
16876
|
csvTimelock: boardingCsv
|
|
@@ -16787,7 +16891,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16787
16891
|
continue;
|
|
16788
16892
|
}
|
|
16789
16893
|
add(
|
|
16790
|
-
c.type === "default" ?
|
|
16894
|
+
c.type === "default" ? chunkVIQF74QJ_cjs.DefaultContractHandler.createScript(c.params) : chunkVIQF74QJ_cjs.BoardingContractHandler.createScript(c.params)
|
|
16791
16895
|
);
|
|
16792
16896
|
} catch (e) {
|
|
16793
16897
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
@@ -16839,7 +16943,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16839
16943
|
tapscripts.map(async (tapscript, i) => {
|
|
16840
16944
|
const contract = contracts.get(scripts[i]);
|
|
16841
16945
|
const spent = new Set(
|
|
16842
|
-
contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(
|
|
16946
|
+
contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(chunkFKHUXSYW_cjs.isVtxoSpent).map(vtxoOutpoint) : []
|
|
16843
16947
|
);
|
|
16844
16948
|
const utxos = fetched[i].filter((c) => !spent.has(vtxoOutpoint(c))).map((utxo) => extendCoinWithTapscript(tapscript, utxo));
|
|
16845
16949
|
return {
|
|
@@ -16868,10 +16972,10 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
16868
16972
|
timer = setTimeout(
|
|
16869
16973
|
() => reject(
|
|
16870
16974
|
new Error(
|
|
16871
|
-
`Boarding address lookup timed out after ${
|
|
16975
|
+
`Boarding address lookup timed out after ${chunkFKHUXSYW_cjs.READ_TIMEOUT_MS}ms`
|
|
16872
16976
|
)
|
|
16873
16977
|
),
|
|
16874
|
-
|
|
16978
|
+
chunkFKHUXSYW_cjs.READ_TIMEOUT_MS
|
|
16875
16979
|
);
|
|
16876
16980
|
})
|
|
16877
16981
|
]);
|
|
@@ -17072,7 +17176,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17072
17176
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
17073
17177
|
async fetchPendingTxs() {
|
|
17074
17178
|
const scripts = await this.getWalletScripts();
|
|
17075
|
-
const vtxos = await
|
|
17179
|
+
const vtxos = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
17076
17180
|
return vtxos.filter(
|
|
17077
17181
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
17078
17182
|
).map((_) => _.arkTxId);
|
|
@@ -17104,7 +17208,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17104
17208
|
for (const contract of contracts) {
|
|
17105
17209
|
if (map.has(contract.script)) continue;
|
|
17106
17210
|
if (contract.type === "executor" && contract.params.template !== "renewal") continue;
|
|
17107
|
-
const handler =
|
|
17211
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
17108
17212
|
if (handler) {
|
|
17109
17213
|
const script = handler.createScript(contract.params);
|
|
17110
17214
|
if (contract.type === "executor" && base.hex.encode(script.pkScript) !== contract.script) {
|
|
@@ -17231,8 +17335,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17231
17335
|
});
|
|
17232
17336
|
try {
|
|
17233
17337
|
const baselinePubkey = await baselinePubkeyPromise;
|
|
17234
|
-
const delegatePubKeys =
|
|
17235
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
17338
|
+
const delegatePubKeys = chunkVIQF74QJ_cjs.delegateDiscoveryKeys({
|
|
17339
|
+
delegatePubKey: this.offchainTapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0,
|
|
17236
17340
|
retiredDelegatePubKeys: this.retiredDelegateKeys()
|
|
17237
17341
|
});
|
|
17238
17342
|
const baselineSigners = [
|
|
@@ -17244,7 +17348,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17244
17348
|
for (const serverPubKey of baselineSigners) {
|
|
17245
17349
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
17246
17350
|
const csvTimelockStr = chunk6TBTL42M_cjs.timelockToSequence(csvTimelock).toString();
|
|
17247
|
-
const defaultScript = new
|
|
17351
|
+
const defaultScript = new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
17248
17352
|
pubKey: baselinePubkey,
|
|
17249
17353
|
serverPubKey,
|
|
17250
17354
|
csvTimelock
|
|
@@ -17265,7 +17369,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17265
17369
|
});
|
|
17266
17370
|
}
|
|
17267
17371
|
for (const delegatePubKey of delegatePubKeys) {
|
|
17268
|
-
const delegateScript = new
|
|
17372
|
+
const delegateScript = new chunkVIQF74QJ_cjs.DelegateVtxo.Script({
|
|
17269
17373
|
pubKey: baselinePubkey,
|
|
17270
17374
|
serverPubKey,
|
|
17271
17375
|
delegatePubKey,
|
|
@@ -17289,9 +17393,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
17289
17393
|
}
|
|
17290
17394
|
}
|
|
17291
17395
|
}
|
|
17292
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
17396
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
17293
17397
|
for (const serverPubKey of baselineSigners) {
|
|
17294
|
-
const baselineBoarding = new
|
|
17398
|
+
const baselineBoarding = new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
17295
17399
|
pubKey: baselinePubkey,
|
|
17296
17400
|
serverPubKey,
|
|
17297
17401
|
csvTimelock: boardingCsvTimelock
|
|
@@ -17524,7 +17628,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17524
17628
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
17525
17629
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
17526
17630
|
csvTimelocks: this.walletContractTimelocks,
|
|
17527
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
17631
|
+
delegatePubKey: this.offchainTapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0,
|
|
17528
17632
|
retiredDelegatePubKeys: this.retiredDelegateKeys()
|
|
17529
17633
|
};
|
|
17530
17634
|
}
|
|
@@ -17650,6 +17754,80 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17650
17754
|
console.warn("Failed to register an Executor watch for the new boarding address", e);
|
|
17651
17755
|
}
|
|
17652
17756
|
}
|
|
17757
|
+
/**
|
|
17758
|
+
* @internal Register the Executor twin of the receive key at `descriptor`, under the params
|
|
17759
|
+
* of {@link delegationSource}: none means the app never opted in, and nothing is done.
|
|
17760
|
+
* Only the displayed key gets one: look-ahead addresses may have been issued to others and
|
|
17761
|
+
* are not delegated. Never throws: on failure the own address is shown until
|
|
17762
|
+
* {@link syncReceiveDelegation} registers the twin.
|
|
17763
|
+
*/
|
|
17764
|
+
async registerReceiveTwin(descriptor) {
|
|
17765
|
+
const executor = this._executorManager;
|
|
17766
|
+
if (!executor) return;
|
|
17767
|
+
try {
|
|
17768
|
+
const watch = this.delegationSource(
|
|
17769
|
+
await this.liveRenewalWatches(
|
|
17770
|
+
chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(this.arkServerPublicKey))
|
|
17771
|
+
)
|
|
17772
|
+
);
|
|
17773
|
+
if (!watch) return;
|
|
17774
|
+
const { options, registration } = reRegistrationOf(watch);
|
|
17775
|
+
await executor.registerRenewalAt(descriptor, options, registration);
|
|
17776
|
+
} catch (e) {
|
|
17777
|
+
console.warn("Failed to register an Executor watch for the new receive address", e);
|
|
17778
|
+
}
|
|
17779
|
+
}
|
|
17780
|
+
/**
|
|
17781
|
+
* The live renewal watch whose params a twin copies: the displayed boarding key's, which
|
|
17782
|
+
* `registerRenewal` registers with the app's params, else the newest.
|
|
17783
|
+
*/
|
|
17784
|
+
delegationSource(watches) {
|
|
17785
|
+
const boarding = base.hex.encode(this._boardingTapscript.options.pubKey);
|
|
17786
|
+
return watches.find((w) => w.owner === boarding) ?? watches[0];
|
|
17787
|
+
}
|
|
17788
|
+
_receiveSyncFailedAt = 0;
|
|
17789
|
+
/**
|
|
17790
|
+
* @internal The upkeep of receive delegation for an HD wallet that opted in, run from the poll
|
|
17791
|
+
* and at boot, and never throwing:
|
|
17792
|
+
* - the receive key never is the displayed boarding key, as a payment at the twin would
|
|
17793
|
+
* rotate boarding: it rotates boarding first, once, when they coincide;
|
|
17794
|
+
* - the displayed receive key gets its twin when a rotation could not register one, or a new
|
|
17795
|
+
* one when the app registered renewal with other params since.
|
|
17796
|
+
*
|
|
17797
|
+
* A failure is not tried again for a few minutes, as the Executor may be down.
|
|
17798
|
+
*/
|
|
17799
|
+
syncReceiveDelegation() {
|
|
17800
|
+
const executor = this._executorManager;
|
|
17801
|
+
if (!executor || !this._descriptorProvider) return Promise.resolve();
|
|
17802
|
+
return this.onBoardChain(async () => {
|
|
17803
|
+
if (this._executorStopping || Date.now() - this._receiveSyncFailedAt < EXECUTOR_RECEIVE_RETRY_MS) {
|
|
17804
|
+
return;
|
|
17805
|
+
}
|
|
17806
|
+
const signer = chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(this.arkServerPublicKey));
|
|
17807
|
+
const watches = await this.liveRenewalWatches(signer);
|
|
17808
|
+
if (watches.length === 0) return;
|
|
17809
|
+
const key = base.hex.encode(this.offchainTapscript.options.pubKey);
|
|
17810
|
+
if (key === base.hex.encode(this._boardingTapscript.options.pubKey)) {
|
|
17811
|
+
await this.rotateBoarding();
|
|
17812
|
+
}
|
|
17813
|
+
const source = this.delegationSource(watches);
|
|
17814
|
+
const twin = watches.find((w) => w.owner === key);
|
|
17815
|
+
if (twin && sameDelegation(twin, source)) return;
|
|
17816
|
+
const [row] = await (await this.getContractManager()).getContracts({
|
|
17817
|
+
script: this.defaultContractScript
|
|
17818
|
+
});
|
|
17819
|
+
const descriptor = row?.metadata?.signingDescriptor;
|
|
17820
|
+
const { options, registration } = reRegistrationOf(source);
|
|
17821
|
+
await executor.registerRenewalAt(
|
|
17822
|
+
typeof descriptor === "string" ? descriptor : await chunkVIQF74QJ_cjs.identityDescriptor(this.identity),
|
|
17823
|
+
options,
|
|
17824
|
+
registration
|
|
17825
|
+
);
|
|
17826
|
+
}).catch((e) => {
|
|
17827
|
+
this._receiveSyncFailedAt = Date.now();
|
|
17828
|
+
console.warn("Failed to keep the receive address under Executor delegation", e);
|
|
17829
|
+
});
|
|
17830
|
+
}
|
|
17653
17831
|
/**
|
|
17654
17832
|
* Startup work for an Executor: refresh its watches (every wallet), then, with a descriptor
|
|
17655
17833
|
* provider, rotate-on-board. The Executor boards a deposit into the renewal contract of its
|
|
@@ -17666,7 +17844,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17666
17844
|
this._executorBoardUnsub = eager.onContractEvent((event) => {
|
|
17667
17845
|
if (event.type !== "vtxo_received" || !isContractVtxoEvent(event)) return;
|
|
17668
17846
|
const { type, params } = event.contract;
|
|
17669
|
-
if (type !==
|
|
17847
|
+
if (type !== chunkVIQF74QJ_cjs.ExecutorContractHandler.type || params.template !== "renewal") return;
|
|
17670
17848
|
this.queueExecutorBoardRotation(params.owner);
|
|
17671
17849
|
});
|
|
17672
17850
|
}
|
|
@@ -17691,7 +17869,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17691
17869
|
* Best-effort: never throws. Never call it from a board chain task: it would wait on itself.
|
|
17692
17870
|
*/
|
|
17693
17871
|
refreshExecutorWatches() {
|
|
17694
|
-
this._executorRefreshing ??= this.refreshExecutorWatchesNow().finally(() => {
|
|
17872
|
+
this._executorRefreshing ??= this.refreshExecutorWatchesNow().then(() => this.syncReceiveDelegation()).finally(() => {
|
|
17695
17873
|
this._executorRefreshing = void 0;
|
|
17696
17874
|
});
|
|
17697
17875
|
return this._executorRefreshing;
|
|
@@ -17752,7 +17930,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17752
17930
|
try {
|
|
17753
17931
|
const displayed = base.hex.encode(this._boardingTapscript.options.pubKey);
|
|
17754
17932
|
const rows = await collectContracts(this.contractRepository, {
|
|
17755
|
-
type: [
|
|
17933
|
+
type: [chunkVIQF74QJ_cjs.ExecutorContractHandler.type]
|
|
17756
17934
|
});
|
|
17757
17935
|
for (const row of rows) {
|
|
17758
17936
|
if (row.params.template !== "renewal") continue;
|
|
@@ -17855,7 +18033,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17855
18033
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
17856
18034
|
const persisted = row?.metadata?.signingDescriptor;
|
|
17857
18035
|
if (typeof persisted === "string") return persisted;
|
|
17858
|
-
return
|
|
18036
|
+
return chunkVIQF74QJ_cjs.identityDescriptor(this.identity);
|
|
17859
18037
|
}
|
|
17860
18038
|
/**
|
|
17861
18039
|
* Build, persist and shape one address of `type` owned by `descriptor`. The descriptor is the
|
|
@@ -17865,7 +18043,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17865
18043
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
17866
18044
|
if (type === "boarding") {
|
|
17867
18045
|
const built2 = this.buildBoardingContract(
|
|
17868
|
-
|
|
18046
|
+
chunkVIQF74QJ_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
17869
18047
|
descriptor,
|
|
17870
18048
|
tagSource
|
|
17871
18049
|
);
|
|
@@ -17902,11 +18080,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17902
18080
|
* (offchain analogue: {@link buildReceiveContract}).
|
|
17903
18081
|
*/
|
|
17904
18082
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
17905
|
-
const tapscript = new
|
|
18083
|
+
const tapscript = new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
17906
18084
|
...this._boardingTapscript.options,
|
|
17907
18085
|
pubKey
|
|
17908
18086
|
});
|
|
17909
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
18087
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
17910
18088
|
return {
|
|
17911
18089
|
tapscript,
|
|
17912
18090
|
params: {
|
|
@@ -17920,7 +18098,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17920
18098
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
17921
18099
|
state: "active",
|
|
17922
18100
|
metadata: {
|
|
17923
|
-
...tagSource && { source:
|
|
18101
|
+
...tagSource && { source: chunkVIQF74QJ_cjs.WALLET_RECEIVE_SOURCE },
|
|
17924
18102
|
signingDescriptor: descriptor
|
|
17925
18103
|
}
|
|
17926
18104
|
}
|
|
@@ -17942,7 +18120,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17942
18120
|
if (this._hdProvider) {
|
|
17943
18121
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
17944
18122
|
}
|
|
17945
|
-
return
|
|
18123
|
+
return chunkVIQF74QJ_cjs.identityDescriptor(this.identity);
|
|
17946
18124
|
}
|
|
17947
18125
|
/**
|
|
17948
18126
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -18040,6 +18218,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18040
18218
|
}
|
|
18041
18219
|
async _doRotateServerSigner(xonly, newServerUnrollScript) {
|
|
18042
18220
|
if (utils_js.equalBytes(xonly, this.arkServerPublicKey)) return;
|
|
18221
|
+
const previousSigner = chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(this.arkServerPublicKey));
|
|
18043
18222
|
const manager = await this.getContractManager();
|
|
18044
18223
|
const currentBoardingScript = base.hex.encode(this._boardingTapscript.pkScript);
|
|
18045
18224
|
const [offchainRows2, boardingRows] = await Promise.all([
|
|
@@ -18048,21 +18227,21 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18048
18227
|
]);
|
|
18049
18228
|
const [currentOffchainRow] = offchainRows2;
|
|
18050
18229
|
const [currentBoardingRow] = boardingRows;
|
|
18051
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
18230
|
+
const newOffchain = this.offchainTapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? new chunkVIQF74QJ_cjs.DelegateVtxo.Script({
|
|
18052
18231
|
...this.offchainTapscript.options,
|
|
18053
18232
|
serverPubKey: xonly
|
|
18054
|
-
}) : new
|
|
18233
|
+
}) : new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
18055
18234
|
...this.offchainTapscript.options,
|
|
18056
18235
|
serverPubKey: xonly
|
|
18057
18236
|
});
|
|
18058
|
-
const newBoarding = new
|
|
18237
|
+
const newBoarding = new chunkVIQF74QJ_cjs.DefaultVtxo.Script({
|
|
18059
18238
|
...this._boardingTapscript.options,
|
|
18060
18239
|
serverPubKey: xonly
|
|
18061
18240
|
});
|
|
18062
18241
|
const offchainCsv = chunk6TBTL42M_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
18063
18242
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
18064
18243
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
18065
|
-
if (newOffchain instanceof
|
|
18244
|
+
if (newOffchain instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script) {
|
|
18066
18245
|
await manager.createContract({
|
|
18067
18246
|
type: "delegate",
|
|
18068
18247
|
params: {
|
|
@@ -18090,7 +18269,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18090
18269
|
metadata: currentOffchainRow?.metadata
|
|
18091
18270
|
});
|
|
18092
18271
|
}
|
|
18093
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
18272
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
18094
18273
|
await manager.createContract({
|
|
18095
18274
|
type: "boarding",
|
|
18096
18275
|
params: {
|
|
@@ -18112,6 +18291,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18112
18291
|
} catch (e) {
|
|
18113
18292
|
console.warn("look-ahead refill after server-signer rotation failed", e);
|
|
18114
18293
|
}
|
|
18294
|
+
if (this._executorManager) {
|
|
18295
|
+
const held = await this.liveRenewalWatches(previousSigner).catch(() => []);
|
|
18296
|
+
if (held.length > 0) {
|
|
18297
|
+
console.warn(
|
|
18298
|
+
"Executor delegations stay under the previous operator key, and getAddress() shows the own address: call registerRenewal() again to delegate under the new one"
|
|
18299
|
+
);
|
|
18300
|
+
}
|
|
18301
|
+
}
|
|
18115
18302
|
}
|
|
18116
18303
|
/**
|
|
18117
18304
|
* Serializes `settle`/`send` so VtxoManager's background renewal can't race user
|
|
@@ -18124,14 +18311,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18124
18311
|
_restoreInFlight;
|
|
18125
18312
|
_addPendingSpends(inputs) {
|
|
18126
18313
|
for (const input of inputs) {
|
|
18127
|
-
if (
|
|
18314
|
+
if (chunkFKHUXSYW_cjs.isVirtualCoin(input)) {
|
|
18128
18315
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
18129
18316
|
}
|
|
18130
18317
|
}
|
|
18131
18318
|
}
|
|
18132
18319
|
_removePendingSpends(inputs) {
|
|
18133
18320
|
for (const input of inputs) {
|
|
18134
|
-
if (
|
|
18321
|
+
if (chunkFKHUXSYW_cjs.isVirtualCoin(input)) {
|
|
18135
18322
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
18136
18323
|
}
|
|
18137
18324
|
}
|
|
@@ -18290,7 +18477,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18290
18477
|
if (clashing.length > 0) throw new VtxoReservedError(clashing, "in-flight");
|
|
18291
18478
|
}
|
|
18292
18479
|
_assertNotHeld(inputs) {
|
|
18293
|
-
const held = coinKeys(inputs.filter(
|
|
18480
|
+
const held = coinKeys(inputs.filter(chunkFKHUXSYW_cjs.isVirtualCoin)).filter(
|
|
18294
18481
|
(key) => this._heldOutpoints.has(key)
|
|
18295
18482
|
);
|
|
18296
18483
|
if (held.length > 0) throw new VtxoReservedError(held, "held");
|
|
@@ -18330,15 +18517,15 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18330
18517
|
*/
|
|
18331
18518
|
async executorWatchTemplates() {
|
|
18332
18519
|
const rows = await collectContracts(this.contractRepository, {
|
|
18333
|
-
type: [
|
|
18520
|
+
type: [chunkVIQF74QJ_cjs.ExecutorContractHandler.type]
|
|
18334
18521
|
});
|
|
18335
18522
|
const boarding = /* @__PURE__ */ new Map();
|
|
18336
18523
|
const renewalOnly = /* @__PURE__ */ new Map();
|
|
18337
18524
|
const boardingBases = /* @__PURE__ */ new Set();
|
|
18338
18525
|
for (const row of rows) {
|
|
18339
18526
|
try {
|
|
18340
|
-
const p =
|
|
18341
|
-
const keys =
|
|
18527
|
+
const p = chunkVIQF74QJ_cjs.ExecutorContractHandler.deserializeParams(row.params);
|
|
18528
|
+
const keys = chunkVIQF74QJ_cjs.executorKeysOf(p);
|
|
18342
18529
|
const base = JSON.stringify([keys, p.exitDelay, p.renewalWindow, p.maxFee]);
|
|
18343
18530
|
const params = {
|
|
18344
18531
|
exitDelay: p.exitDelay,
|
|
@@ -18368,12 +18555,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18368
18555
|
const hd = provider !== void 0;
|
|
18369
18556
|
const [manager, staticDescriptor, arkInfo, executorWatches] = await Promise.all([
|
|
18370
18557
|
this.getContractManager(),
|
|
18371
|
-
hd ? void 0 :
|
|
18558
|
+
hd ? void 0 : chunkVIQF74QJ_cjs.identityDescriptor(this.identity),
|
|
18372
18559
|
this.arkProvider.getInfo(),
|
|
18373
18560
|
this.executorWatchTemplates()
|
|
18374
18561
|
]);
|
|
18375
18562
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
18376
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
18563
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkVIQF74QJ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
18377
18564
|
const currentSignerPubKey = chunk6TBTL42M_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
18378
18565
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
18379
18566
|
(s) => chunk6TBTL42M_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
@@ -18388,7 +18575,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18388
18575
|
deprecatedSignerPubKeys,
|
|
18389
18576
|
csvTimelocks: this.walletContractTimelocks,
|
|
18390
18577
|
// Boarding-exit CSV, distinct from the unilateral-exit matrix.
|
|
18391
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
18578
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
18392
18579
|
delegatePubKey,
|
|
18393
18580
|
// Raw hex: the lookup skips malformed signers rather than failing the restore.
|
|
18394
18581
|
retiredDelegatePubKeys: this.executorProvider ? chunk6TBTL42M_cjs.retiredDelegatePubKeys(this.network, [
|
|
@@ -18804,7 +18991,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18804
18991
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
18805
18992
|
break;
|
|
18806
18993
|
}
|
|
18807
|
-
const inputFee = estimator.evalOffchainInput(
|
|
18994
|
+
const inputFee = estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(vtxo));
|
|
18808
18995
|
if (inputFee.satoshis >= vtxo.value) {
|
|
18809
18996
|
continue;
|
|
18810
18997
|
}
|
|
@@ -18928,11 +19115,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18928
19115
|
]);
|
|
18929
19116
|
let intentTxId;
|
|
18930
19117
|
try {
|
|
18931
|
-
intentTxId =
|
|
19118
|
+
intentTxId = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(intent.proof)).id;
|
|
18932
19119
|
} catch {
|
|
18933
19120
|
intentTxId = params.inputs.map((i) => `${i.txid}:${i.vout}`).sort().join("|");
|
|
18934
19121
|
}
|
|
18935
|
-
const settleInputVtxos = params.inputs.filter(
|
|
19122
|
+
const settleInputVtxos = params.inputs.filter(chunkFKHUXSYW_cjs.isVirtualCoin);
|
|
18936
19123
|
const contractManager = await this.getContractManager();
|
|
18937
19124
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
18938
19125
|
await contractManager.assertSpendableNow?.(
|
|
@@ -18943,7 +19130,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
18943
19130
|
assertNoPersistentReservation(params.inputs, this.persistentReservedOutpoints);
|
|
18944
19131
|
if (picked) this._assertNotHeld(params.inputs);
|
|
18945
19132
|
this._addPendingSpends(params.inputs);
|
|
18946
|
-
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !
|
|
19133
|
+
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !chunkFKHUXSYW_cjs.isVirtualCoin(i))) : [];
|
|
18947
19134
|
for (const key of boardingKeys) this._pendingSpendOutpoints.add(key);
|
|
18948
19135
|
const settlingKeys = params.inputs.map((i) => `${i.txid}:${i.vout}`);
|
|
18949
19136
|
for (const key of settlingKeys) this._settlingOutpoints.add(key);
|
|
@@ -19061,7 +19248,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19061
19248
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
19062
19249
|
if (!this._descriptorProvider) return;
|
|
19063
19250
|
const consumedBoarding = inputs.some(
|
|
19064
|
-
(input) => typeof input !== "string" && !
|
|
19251
|
+
(input) => typeof input !== "string" && !chunkFKHUXSYW_cjs.isVirtualCoin(input)
|
|
19065
19252
|
);
|
|
19066
19253
|
if (!consumedBoarding) return;
|
|
19067
19254
|
const rotation = this.onBoardChain(async () => {
|
|
@@ -19075,7 +19262,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19075
19262
|
}
|
|
19076
19263
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, expectedRecipients, connectorsGraph, validatedCommitmentTxid) {
|
|
19077
19264
|
const signedForfeits = [];
|
|
19078
|
-
let settlementPsbt =
|
|
19265
|
+
let settlementPsbt = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
19079
19266
|
assertFinalCommitmentMatchesValidated(
|
|
19080
19267
|
settlementPsbt,
|
|
19081
19268
|
validatedCommitmentTxid,
|
|
@@ -19088,7 +19275,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19088
19275
|
let connectorIndex = 0;
|
|
19089
19276
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
19090
19277
|
for (const input of inputs) {
|
|
19091
|
-
if (!
|
|
19278
|
+
if (!chunkFKHUXSYW_cjs.isVirtualCoin(input)) {
|
|
19092
19279
|
let matched = false;
|
|
19093
19280
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
19094
19281
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -19127,7 +19314,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19127
19314
|
}
|
|
19128
19315
|
continue;
|
|
19129
19316
|
}
|
|
19130
|
-
if (!
|
|
19317
|
+
if (!chunkFKHUXSYW_cjs.requiresForfeit(input) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
19131
19318
|
continue;
|
|
19132
19319
|
}
|
|
19133
19320
|
if (connectorsLeaves.length === 0) {
|
|
@@ -19254,7 +19441,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19254
19441
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
19255
19442
|
return { skip: true };
|
|
19256
19443
|
}
|
|
19257
|
-
const commitmentTx =
|
|
19444
|
+
const commitmentTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(
|
|
19258
19445
|
base.base64.decode(event.unsignedCommitmentTx)
|
|
19259
19446
|
);
|
|
19260
19447
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
@@ -19344,9 +19531,9 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19344
19531
|
...existing ?? {},
|
|
19345
19532
|
proofTxId: intentTxId,
|
|
19346
19533
|
registerProof: intent.proof,
|
|
19347
|
-
registerProofMessage:
|
|
19534
|
+
registerProofMessage: chunkFKHUXSYW_cjs.Proof.encodeMessage(intent.message),
|
|
19348
19535
|
deleteProof: deleteIntent.proof,
|
|
19349
|
-
deleteProofMessage:
|
|
19536
|
+
deleteProofMessage: chunkFKHUXSYW_cjs.Proof.encodeMessage(deleteIntent.message),
|
|
19350
19537
|
proofInputs: inputs.map((i) => ({
|
|
19351
19538
|
txid: i.txid,
|
|
19352
19539
|
vout: i.vout
|
|
@@ -19378,7 +19565,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19378
19565
|
}
|
|
19379
19566
|
/** @see IWallet.cosignOnchainTx */
|
|
19380
19567
|
async cosignOnchainTx(psbt) {
|
|
19381
|
-
const tx = typeof psbt === "string" ?
|
|
19568
|
+
const tx = typeof psbt === "string" ? chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbt)) : psbt;
|
|
19382
19569
|
return this._withTxLock(async () => {
|
|
19383
19570
|
await (await this.getContractManager()).syncOnchain();
|
|
19384
19571
|
return this._cosignOnchainTxImpl(tx);
|
|
@@ -19444,7 +19631,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19444
19631
|
if (reasons.length > 0) throw new OnchainCosignPreflightError(reasons.join("; "));
|
|
19445
19632
|
}
|
|
19446
19633
|
const feeRate = await providerFeeRate(this.onchainProvider);
|
|
19447
|
-
const tx = new
|
|
19634
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 2 });
|
|
19448
19635
|
if (sweepTo) {
|
|
19449
19636
|
const swept = candidates.slice(0, MAX_COSIGN_INPUTS);
|
|
19450
19637
|
for (const { coin } of swept) {
|
|
@@ -19505,7 +19692,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19505
19692
|
continue;
|
|
19506
19693
|
}
|
|
19507
19694
|
const { coin, contract, script } = mine;
|
|
19508
|
-
const path =
|
|
19695
|
+
const path = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type).selectPath(script, contract, {
|
|
19509
19696
|
collaborative: true,
|
|
19510
19697
|
currentTime: Date.now(),
|
|
19511
19698
|
blockHeight: tip.height,
|
|
@@ -19555,7 +19742,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19555
19742
|
onchainProvider: this.onchainProvider
|
|
19556
19743
|
});
|
|
19557
19744
|
} catch (e) {
|
|
19558
|
-
if (e instanceof
|
|
19745
|
+
if (e instanceof chunkFKHUXSYW_cjs.OnchainCosignAmbiguousError || isCosignRejectedAfterSigning(e)) {
|
|
19559
19746
|
await markPending(signed.id);
|
|
19560
19747
|
}
|
|
19561
19748
|
throw e;
|
|
@@ -19575,7 +19762,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19575
19762
|
this.lockedOutpoints(),
|
|
19576
19763
|
this.onchainCoins(manager)
|
|
19577
19764
|
]);
|
|
19578
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
19765
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkVIQF74QJ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
19579
19766
|
return coins.filter(
|
|
19580
19767
|
({ coin, contract }) => !locked.has(vtxoOutpoint(coin)) && needsOnchainSweep(coin, contract, boardingCsv, tip, this._cosignMarginBlocks)
|
|
19581
19768
|
).slice(0, MAX_COSIGN_INPUTS).map(({ coin }) => ({ txid: coin.txid, vout: coin.vout }));
|
|
@@ -19587,8 +19774,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19587
19774
|
unspentOnly: true
|
|
19588
19775
|
});
|
|
19589
19776
|
return snapshot.flatMap(({ contract, vtxos }) => {
|
|
19590
|
-
const handler =
|
|
19591
|
-
const coins = vtxos.filter((v) => v.isUnrolled && !
|
|
19777
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
19778
|
+
const coins = vtxos.filter((v) => v.isUnrolled && !chunkFKHUXSYW_cjs.isVtxoSpent(v));
|
|
19592
19779
|
if (!handler || coins.length === 0) return [];
|
|
19593
19780
|
const script = handler.createScript(contract.params);
|
|
19594
19781
|
return coins.map((coin) => ({ coin, contract, script }));
|
|
@@ -19598,7 +19785,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19598
19785
|
try {
|
|
19599
19786
|
return await this.arkProvider.registerIntent(intent);
|
|
19600
19787
|
} catch (error) {
|
|
19601
|
-
if (error instanceof
|
|
19788
|
+
if (error instanceof chunkFKHUXSYW_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
19602
19789
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
19603
19790
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
19604
19791
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -19614,7 +19801,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19614
19801
|
expire_at: 0,
|
|
19615
19802
|
cosigners_public_keys: cosignerPubKeys
|
|
19616
19803
|
};
|
|
19617
|
-
const proof =
|
|
19804
|
+
const proof = chunkFKHUXSYW_cjs.Proof.create(message, coins, outputs);
|
|
19618
19805
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19619
19806
|
return {
|
|
19620
19807
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19626,7 +19813,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19626
19813
|
type: "delete",
|
|
19627
19814
|
expire_at: 0
|
|
19628
19815
|
};
|
|
19629
|
-
const proof =
|
|
19816
|
+
const proof = chunkFKHUXSYW_cjs.Proof.create(message, coins, []);
|
|
19630
19817
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19631
19818
|
return {
|
|
19632
19819
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19638,7 +19825,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19638
19825
|
type: "get-pending-tx",
|
|
19639
19826
|
expire_at: 0
|
|
19640
19827
|
};
|
|
19641
|
-
const proof =
|
|
19828
|
+
const proof = chunkFKHUXSYW_cjs.Proof.create(message, coins, []);
|
|
19642
19829
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
19643
19830
|
return {
|
|
19644
19831
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -19670,7 +19857,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19670
19857
|
try {
|
|
19671
19858
|
await this.finalizePendingTxsImpl(void 0, { info, isCurrent });
|
|
19672
19859
|
} catch (error) {
|
|
19673
|
-
if (!
|
|
19860
|
+
if (!chunkFKHUXSYW_cjs.isTransientOperatorError(error) && isCurrent()) {
|
|
19674
19861
|
this.pendingTxRecoveryDeferred = false;
|
|
19675
19862
|
}
|
|
19676
19863
|
throw error;
|
|
@@ -19689,7 +19876,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19689
19876
|
const scriptMap = await this.getScriptMap();
|
|
19690
19877
|
if (!isCurrent()) return { finalized: [], pending: [] };
|
|
19691
19878
|
const allExtended = [];
|
|
19692
|
-
const fetchedVtxos = await
|
|
19879
|
+
const fetchedVtxos = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
19693
19880
|
...scriptMap.keys()
|
|
19694
19881
|
]);
|
|
19695
19882
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -19740,8 +19927,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19740
19927
|
try {
|
|
19741
19928
|
const context = `pending tx ${pendingTx.arkTxid}`;
|
|
19742
19929
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
19743
|
-
const tx =
|
|
19744
|
-
|
|
19930
|
+
const tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
19931
|
+
chunkFKHUXSYW_cjs.assertAllowedSighashTypes(tx);
|
|
19745
19932
|
return tx;
|
|
19746
19933
|
});
|
|
19747
19934
|
const localCheckpoints = assertCheckpointsMatchInputs(
|
|
@@ -19751,15 +19938,15 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19751
19938
|
context
|
|
19752
19939
|
);
|
|
19753
19940
|
if (!pendingTx.finalArkTx) {
|
|
19754
|
-
throw new
|
|
19941
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
19755
19942
|
`${context}: no final ark tx to bind the checkpoints to`
|
|
19756
19943
|
);
|
|
19757
19944
|
}
|
|
19758
|
-
const finalArkTx =
|
|
19945
|
+
const finalArkTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(
|
|
19759
19946
|
base.base64.decode(pendingTx.finalArkTx)
|
|
19760
19947
|
);
|
|
19761
19948
|
if (finalArkTx.id !== pendingTx.arkTxid) {
|
|
19762
|
-
throw new
|
|
19949
|
+
throw new chunkFKHUXSYW_cjs.ServerResponseMismatchError(
|
|
19763
19950
|
`${context}: final ark tx is ${finalArkTx.id}`
|
|
19764
19951
|
);
|
|
19765
19952
|
}
|
|
@@ -19798,7 +19985,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
19798
19985
|
await this.arkProvider.finalizeTx(pendingTx.arkTxid, finalCheckpoints);
|
|
19799
19986
|
batchFinalized.push(pendingTx.arkTxid);
|
|
19800
19987
|
} catch (error) {
|
|
19801
|
-
if (recovery &&
|
|
19988
|
+
if (recovery && chunkFKHUXSYW_cjs.isTransientOperatorError(error)) throw error;
|
|
19802
19989
|
console.error(
|
|
19803
19990
|
`Failed to finalize transaction ${pendingTx.arkTxid}:`,
|
|
19804
19991
|
error
|
|
@@ -20181,7 +20368,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20181
20368
|
const recoverable = [];
|
|
20182
20369
|
const unclaimed = [];
|
|
20183
20370
|
for (const vtxo of vtxos) {
|
|
20184
|
-
if (
|
|
20371
|
+
if (chunkFKHUXSYW_cjs.isVtxoSpent(vtxo)) {
|
|
20185
20372
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
20186
20373
|
} else if (vtxo.isUnrolled) {
|
|
20187
20374
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -20201,8 +20388,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20201
20388
|
async fetchAllVtxos(scripts) {
|
|
20202
20389
|
const all = [];
|
|
20203
20390
|
const seen = /* @__PURE__ */ new Set();
|
|
20204
|
-
for await (const { vtxos } of
|
|
20205
|
-
(pageIndex) =>
|
|
20391
|
+
for await (const { vtxos } of chunkFKHUXSYW_cjs.indexerPages(
|
|
20392
|
+
(pageIndex) => chunkFKHUXSYW_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
20206
20393
|
scripts,
|
|
20207
20394
|
pageIndex,
|
|
20208
20395
|
pageSize: 100
|
|
@@ -20246,7 +20433,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20246
20433
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_PROOF) {
|
|
20247
20434
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_PROOF);
|
|
20248
20435
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
20249
|
-
const proof =
|
|
20436
|
+
const proof = chunkFKHUXSYW_cjs.Proof.create(message, batch, []);
|
|
20250
20437
|
const signedProof = await identity.sign(
|
|
20251
20438
|
proof,
|
|
20252
20439
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -20267,8 +20454,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20267
20454
|
for (const pendingTx of pendingTxs) {
|
|
20268
20455
|
try {
|
|
20269
20456
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
20270
|
-
const tx =
|
|
20271
|
-
|
|
20457
|
+
const tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
20458
|
+
chunkFKHUXSYW_cjs.assertAllowedSighashTypes(tx);
|
|
20272
20459
|
return tx;
|
|
20273
20460
|
});
|
|
20274
20461
|
assertCheckpointsMatchInputs(
|
|
@@ -20309,7 +20496,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20309
20496
|
}
|
|
20310
20497
|
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
20311
20498
|
arkTxAmountPaidTo(arkTxPsbt, pkScriptHex) {
|
|
20312
|
-
const arkTx =
|
|
20499
|
+
const arkTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
|
|
20313
20500
|
let total = 0;
|
|
20314
20501
|
for (let i = 0; i < arkTx.outputsLength; i++) {
|
|
20315
20502
|
const output = arkTx.getOutput(i);
|
|
@@ -20369,7 +20556,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20369
20556
|
}
|
|
20370
20557
|
if (selectedVtxos) {
|
|
20371
20558
|
await assertNoIntentLockedInputs(selectedVtxos, this.intentRepository);
|
|
20372
|
-
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(
|
|
20559
|
+
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
20373
20560
|
if (inputExpiryFloor && selectedVtxos.some((coin) => !meetsInputExpiryFloor(coin, inputExpiryFloor))) {
|
|
20374
20561
|
throw new Error("send({ selectedVtxos }): input expiry floor not met");
|
|
20375
20562
|
}
|
|
@@ -20657,8 +20844,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20657
20844
|
}
|
|
20658
20845
|
/**
|
|
20659
20846
|
* Change follows its inputs: a send spending a coin at a live renewal watch returns the change
|
|
20660
|
-
* to that contract, so the Executor keeps renewing it.
|
|
20661
|
-
* send must not fail over a delegation lookup.
|
|
20847
|
+
* to that contract, so the Executor keeps renewing it. Otherwise it goes where receives go.
|
|
20848
|
+
* Fail-open: a send must not fail over a delegation lookup.
|
|
20662
20849
|
*/
|
|
20663
20850
|
async changeTapscriptFor(inputs, changeAmount, serverPubKey, own) {
|
|
20664
20851
|
try {
|
|
@@ -20670,8 +20857,9 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20670
20857
|
}
|
|
20671
20858
|
} catch (e) {
|
|
20672
20859
|
console.warn("Unable to inspect Executor renewal watches", e);
|
|
20860
|
+
return own;
|
|
20673
20861
|
}
|
|
20674
|
-
return own;
|
|
20862
|
+
return this.destinationTapscript(serverPubKey, own, BigInt(changeAmount));
|
|
20675
20863
|
}
|
|
20676
20864
|
/** The live Executor renewal watches under `signer`, the operator's x-only key. */
|
|
20677
20865
|
async liveRenewalWatches(signer) {
|
|
@@ -20679,35 +20867,34 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20679
20867
|
(w) => w.live && w.signer === signer
|
|
20680
20868
|
);
|
|
20681
20869
|
}
|
|
20682
|
-
/** Whether the Executor can renew `amount` at `watch`: not for `maxFee + dust` or less. */
|
|
20683
|
-
renews(watch, amount) {
|
|
20684
|
-
return amount > BigInt(watch.contract.params.maxFee) + this.dustAmount;
|
|
20685
|
-
}
|
|
20686
20870
|
/**
|
|
20687
|
-
* @internal Where the wallet's own renewals pay `amount`:
|
|
20688
|
-
*
|
|
20689
|
-
*
|
|
20690
|
-
*
|
|
20691
|
-
*
|
|
20692
|
-
*
|
|
20693
|
-
*
|
|
20694
|
-
*
|
|
20695
|
-
* delegation lookup.
|
|
20871
|
+
* @internal Where the wallet's own renewals pay `amount`: {@link getAddress}, except for
|
|
20872
|
+
* `maxFee + dust` or less, which the Executor cannot renew, and when any of `inputScripts`
|
|
20873
|
+
* sits at a live renewal contract, whatever the reason: the Executor had its chance at that
|
|
20874
|
+
* coin, and paying it back there only repeats the miss. Both pay the wallet's own address.
|
|
20875
|
+
* Fail-open: a renewal must not fail over a delegation lookup.
|
|
20876
|
+
*
|
|
20877
|
+
* {@link VtxoManager} does not ask for a renewal of a coin that carries assets: `settle()`
|
|
20878
|
+
* places assets only at {@link getAddress}, which that renewal pays whatever the rules above say.
|
|
20696
20879
|
*/
|
|
20697
20880
|
async renewalAddress(amount, inputScripts = []) {
|
|
20698
|
-
const own =
|
|
20699
|
-
|
|
20700
|
-
|
|
20701
|
-
|
|
20702
|
-
|
|
20703
|
-
|
|
20704
|
-
|
|
20705
|
-
|
|
20706
|
-
|
|
20707
|
-
|
|
20708
|
-
|
|
20709
|
-
|
|
20881
|
+
const own = this.offchainTapscript;
|
|
20882
|
+
const serverPubKey = this.arkServerPublicKey;
|
|
20883
|
+
const addressOf = (tapscript) => tapscript.address(this.network.hrp, serverPubKey).encode();
|
|
20884
|
+
if (inputScripts.length > 0) {
|
|
20885
|
+
try {
|
|
20886
|
+
const live = await this.liveRenewalWatches(
|
|
20887
|
+
chunk6TBTL42M_cjs.toXOnlySignerHex(base.hex.encode(serverPubKey))
|
|
20888
|
+
);
|
|
20889
|
+
if (live.some((w) => inputScripts.includes(w.contract.script))) {
|
|
20890
|
+
return addressOf(own);
|
|
20891
|
+
}
|
|
20892
|
+
} catch (e) {
|
|
20893
|
+
console.warn("Unable to inspect Executor renewal watches", e);
|
|
20894
|
+
return addressOf(own);
|
|
20895
|
+
}
|
|
20710
20896
|
}
|
|
20897
|
+
return addressOf(await this.destinationTapscript(serverPubKey, own, amount));
|
|
20711
20898
|
}
|
|
20712
20899
|
/**
|
|
20713
20900
|
* Shared submit/persist tail of `send` and {@link sendSelectedVtxosToSelf}; callers own coin
|
|
@@ -20761,10 +20948,10 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20761
20948
|
const serverPubKey = this.arkServerPublicKey;
|
|
20762
20949
|
const serverUnrollScript = this.serverUnrollScript;
|
|
20763
20950
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
20764
|
-
const normalizedInputs = inputs.map(
|
|
20765
|
-
const at = now ?? await
|
|
20951
|
+
const normalizedInputs = inputs.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
20952
|
+
const at = now ?? await chunkFKHUXSYW_cjs.resolveTimeHeight(this.onchainProvider);
|
|
20766
20953
|
for (const input of normalizedInputs) {
|
|
20767
|
-
if (!
|
|
20954
|
+
if (!chunkFKHUXSYW_cjs.canSpendOffchain(input, at)) {
|
|
20768
20955
|
throw new Error(
|
|
20769
20956
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
20770
20957
|
);
|
|
@@ -20972,7 +21159,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
20972
21159
|
}
|
|
20973
21160
|
const checkpointIdByOutpoint = /* @__PURE__ */ new Map();
|
|
20974
21161
|
for (const encoded of signedCheckpointTxs) {
|
|
20975
|
-
const checkpoint =
|
|
21162
|
+
const checkpoint = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
20976
21163
|
for (let i = 0; i < checkpoint.inputsLength; i++) {
|
|
20977
21164
|
const input = checkpoint.getInput(i);
|
|
20978
21165
|
if (!input.txid) continue;
|
|
@@ -21089,12 +21276,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
21089
21276
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
21090
21277
|
const boardingScripts = /* @__PURE__ */ new Set();
|
|
21091
21278
|
const boardingOutpoints = [];
|
|
21092
|
-
const vtxoInputs = inputs.filter(
|
|
21279
|
+
const vtxoInputs = inputs.filter(chunkFKHUXSYW_cjs.isVirtualCoin);
|
|
21093
21280
|
const cm = await this.getContractManager();
|
|
21094
21281
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
21095
21282
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
21096
21283
|
for (const input of inputs) {
|
|
21097
|
-
if (
|
|
21284
|
+
if (chunkFKHUXSYW_cjs.isVirtualCoin(input)) {
|
|
21098
21285
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
21099
21286
|
const vtxo = annotatedByKey.get(outpoint);
|
|
21100
21287
|
if (!vtxo) {
|
|
@@ -21177,7 +21364,7 @@ function bySelectionOrder(a, b) {
|
|
|
21177
21364
|
return b.value - a.value;
|
|
21178
21365
|
}
|
|
21179
21366
|
function selectVirtualCoins(coins, targetAmount) {
|
|
21180
|
-
const sortedCoins = coins.map(
|
|
21367
|
+
const sortedCoins = coins.map(chunkFKHUXSYW_cjs.normalizeVtxo).sort(bySelectionOrder);
|
|
21181
21368
|
const selectedCoins = [];
|
|
21182
21369
|
let selectedAmount = 0;
|
|
21183
21370
|
for (const coin of sortedCoins) {
|
|
@@ -21631,7 +21818,7 @@ function assertTimeoutMap(name, timeouts) {
|
|
|
21631
21818
|
if (value === void 0) {
|
|
21632
21819
|
throw new Error(`${name}.${key} must be a non-negative safe integer`);
|
|
21633
21820
|
}
|
|
21634
|
-
|
|
21821
|
+
chunkFKHUXSYW_cjs.assertTimerMs(`${name}.${key}`, value);
|
|
21635
21822
|
}
|
|
21636
21823
|
}
|
|
21637
21824
|
var MessageBus = class {
|
|
@@ -21648,8 +21835,8 @@ var MessageBus = class {
|
|
|
21648
21835
|
}) {
|
|
21649
21836
|
this.walletRepository = walletRepository;
|
|
21650
21837
|
this.contractRepository = contractRepository;
|
|
21651
|
-
|
|
21652
|
-
|
|
21838
|
+
chunkFKHUXSYW_cjs.assertTimerMs("tickIntervalMs", tickIntervalMs);
|
|
21839
|
+
chunkFKHUXSYW_cjs.assertTimerMs("messageTimeoutMs", messageTimeoutMs);
|
|
21653
21840
|
assertTimeoutMap("messageTimeoutOverrides", messageTimeoutOverrides);
|
|
21654
21841
|
this.intentRepository = intentRepository;
|
|
21655
21842
|
this.onchainProvider = onchainProvider;
|
|
@@ -21933,14 +22120,14 @@ var MessageBus = class {
|
|
|
21933
22120
|
this.initialized = true;
|
|
21934
22121
|
}
|
|
21935
22122
|
async buildServices(config) {
|
|
21936
|
-
const arkProvider = new
|
|
22123
|
+
const arkProvider = new chunkFKHUXSYW_cjs.RestOperatorProvider(config.arkServer.url);
|
|
21937
22124
|
const storage = {
|
|
21938
22125
|
walletRepository: this.walletRepository,
|
|
21939
22126
|
contractRepository: this.contractRepository,
|
|
21940
22127
|
...this.intentRepository && { intentRepository: this.intentRepository }
|
|
21941
22128
|
};
|
|
21942
22129
|
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : void 0;
|
|
21943
|
-
const indexerProvider = new
|
|
22130
|
+
const indexerProvider = new chunkJSYS2KX3_cjs.RestIndexerProvider(config.arkServer.url);
|
|
21944
22131
|
const executorProvider = config.executorUrl ? new RestExecutorProvider(config.executorUrl) : void 0;
|
|
21945
22132
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
21946
22133
|
if (isSigningSerialized(serialized)) {
|
|
@@ -22360,7 +22547,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
|
22360
22547
|
const inputs = [];
|
|
22361
22548
|
let subtotal = 0n;
|
|
22362
22549
|
for (const vtxo of vtxos) {
|
|
22363
|
-
const inputFee = estimator.evalOffchainInput(
|
|
22550
|
+
const inputFee = estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(vtxo));
|
|
22364
22551
|
if (inputFee.satoshis >= vtxo.value) {
|
|
22365
22552
|
if (named) {
|
|
22366
22553
|
throw new Error(
|
|
@@ -22608,7 +22795,7 @@ var Ramps = class {
|
|
|
22608
22795
|
outputs: [{ address, amount: Number(amount) }]
|
|
22609
22796
|
});
|
|
22610
22797
|
} catch (e) {
|
|
22611
|
-
if (!isCosignFallback(e) || e instanceof
|
|
22798
|
+
if (!isCosignFallback(e) || e instanceof chunkFKHUXSYW_cjs.OnchainCosignRejectedError) throw e;
|
|
22612
22799
|
return void 0;
|
|
22613
22800
|
}
|
|
22614
22801
|
}
|
|
@@ -22631,7 +22818,7 @@ var Ramps = class {
|
|
|
22631
22818
|
const ordered = [...candidates].sort(bySelectionOrder);
|
|
22632
22819
|
let covered = 0n;
|
|
22633
22820
|
for (let i = 0; i < ordered.length && i < MAX_VTXOS_PER_SETTLEMENT; i++) {
|
|
22634
|
-
const fee = estimator.evalOffchainInput(
|
|
22821
|
+
const fee = estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(ordered[i])).satoshis;
|
|
22635
22822
|
covered += BigInt(ordered[i].value) - BigInt(fee);
|
|
22636
22823
|
if (covered < needed) continue;
|
|
22637
22824
|
try {
|
|
@@ -22704,11 +22891,11 @@ async function readArkadeCash(token, indexer, info, onchain) {
|
|
|
22704
22891
|
if (signer.status === "UNKNOWN_SIGNER") {
|
|
22705
22892
|
throw new Error("ArkadeCash belongs to another operator");
|
|
22706
22893
|
}
|
|
22707
|
-
const coins = await
|
|
22894
|
+
const coins = await chunkFKHUXSYW_cjs.getAllNormalizedVtxos(indexer, [arkadeCashId(cash)]);
|
|
22708
22895
|
return classifyArkadeCash(
|
|
22709
22896
|
coins,
|
|
22710
22897
|
info.dust,
|
|
22711
|
-
await
|
|
22898
|
+
await chunkFKHUXSYW_cjs.resolveTimeHeight(onchain),
|
|
22712
22899
|
signer.status === "EXPIRED"
|
|
22713
22900
|
);
|
|
22714
22901
|
}
|
|
@@ -22716,16 +22903,16 @@ function classifyArkadeCash(coins, dust, now, awaitingSweep = false) {
|
|
|
22716
22903
|
const eligible = coins.filter(
|
|
22717
22904
|
(coin) => coin.value >= Number(dust) && !(coin.assets && coin.assets.length > 0)
|
|
22718
22905
|
);
|
|
22719
|
-
const hasSpent = eligible.some(
|
|
22720
|
-
const hasLive = eligible.some((coin) => !
|
|
22721
|
-
const hasExit = eligible.some((coin) => !
|
|
22722
|
-
const recoverable = eligible.some((coin) => !
|
|
22906
|
+
const hasSpent = eligible.some(chunkFKHUXSYW_cjs.isVtxoSpent);
|
|
22907
|
+
const hasLive = eligible.some((coin) => !chunkFKHUXSYW_cjs.isVtxoSpent(coin) && !coin.isUnrolled);
|
|
22908
|
+
const hasExit = eligible.some((coin) => !chunkFKHUXSYW_cjs.isVtxoSpent(coin) && coin.isUnrolled);
|
|
22909
|
+
const recoverable = eligible.some((coin) => !chunkFKHUXSYW_cjs.isVtxoSpent(coin) && coin.isSwept);
|
|
22723
22910
|
const elapsedBatch = eligible.some(
|
|
22724
|
-
(coin) => !
|
|
22911
|
+
(coin) => !chunkFKHUXSYW_cjs.isVtxoSpent(coin) && !coin.isSwept && chunkFKHUXSYW_cjs.isPastExpiry(coin, now)
|
|
22725
22912
|
);
|
|
22726
22913
|
return {
|
|
22727
22914
|
status: eligible.length === 0 ? "unissued" : hasExit && !hasLive ? "exited" : hasSpent && !hasLive ? "claimed" : recoverable ? "recovering" : elapsedBatch || awaitingSweep ? "expired" : "available",
|
|
22728
|
-
amount: eligible.reduce((sum, coin) => sum + (
|
|
22915
|
+
amount: eligible.reduce((sum, coin) => sum + (chunkFKHUXSYW_cjs.isVtxoSpent(coin) ? 0 : coin.value), 0),
|
|
22729
22916
|
issues: groupByTxid(eligible),
|
|
22730
22917
|
claims: groupByTxid(
|
|
22731
22918
|
// `||`: the indexer reports an unset id as an empty string, not as absent.
|
|
@@ -23219,6 +23406,14 @@ var WalletMessageHandler = class {
|
|
|
23219
23406
|
payload: { address }
|
|
23220
23407
|
});
|
|
23221
23408
|
}
|
|
23409
|
+
case "GET_OWN_ADDRESS": {
|
|
23410
|
+
const address = await readonlyWallet.getOwnAddress();
|
|
23411
|
+
return this.tagged({
|
|
23412
|
+
id,
|
|
23413
|
+
type: "OWN_ADDRESS",
|
|
23414
|
+
payload: { address }
|
|
23415
|
+
});
|
|
23416
|
+
}
|
|
23222
23417
|
case "GET_BOARDING_ADDRESS": {
|
|
23223
23418
|
const address = await readonlyWallet.getBoardingAddress();
|
|
23224
23419
|
return this.tagged({
|
|
@@ -24036,7 +24231,7 @@ var WalletMessageHandler = class {
|
|
|
24036
24231
|
);
|
|
24037
24232
|
} catch (error) {
|
|
24038
24233
|
if (init.stale) return;
|
|
24039
|
-
if (
|
|
24234
|
+
if (chunkFKHUXSYW_cjs.isTransientOperatorError(error) && await signingWallet.deferPendingTxRecovery()) {
|
|
24040
24235
|
if (init.stale) return;
|
|
24041
24236
|
this.schedulePendingTxRecovery(signingWallet, context, init);
|
|
24042
24237
|
} else {
|
|
@@ -24082,7 +24277,7 @@ var WalletMessageHandler = class {
|
|
|
24082
24277
|
console.error("Error recovering pending transactions:", error);
|
|
24083
24278
|
return;
|
|
24084
24279
|
}
|
|
24085
|
-
if (!
|
|
24280
|
+
if (!chunkFKHUXSYW_cjs.isTransientOperatorError(error)) {
|
|
24086
24281
|
const reason = String(error);
|
|
24087
24282
|
if (!reported.has(reason)) {
|
|
24088
24283
|
reported.add(reason);
|
|
@@ -24475,7 +24670,7 @@ var WalletMessageHandler = class {
|
|
|
24475
24670
|
this.repoSnapshot({}, context),
|
|
24476
24671
|
wallet.getBoardingTxs()
|
|
24477
24672
|
]);
|
|
24478
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
24673
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkFKHUXSYW_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
24479
24674
|
return buildTransactionHistory(
|
|
24480
24675
|
vtxos,
|
|
24481
24676
|
boardingTxs,
|
|
@@ -24523,6 +24718,7 @@ var initWaitBackoffMs = (attempt) => Math.min(100 * 2 ** attempt, INIT_WAIT_BACK
|
|
|
24523
24718
|
var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
24524
24719
|
// Fast reads — fail quickly
|
|
24525
24720
|
GET_ADDRESS: 1e4,
|
|
24721
|
+
GET_OWN_ADDRESS: 1e4,
|
|
24526
24722
|
GET_BALANCE: 1e4,
|
|
24527
24723
|
GET_BOARDING_ADDRESS: 1e4,
|
|
24528
24724
|
GET_STATUS: 1e4,
|
|
@@ -24544,9 +24740,9 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
24544
24740
|
// budget so the worker's snapshot fallback stays reachable before this
|
|
24545
24741
|
// page deadline fires — lowering it below the budget would time the page
|
|
24546
24742
|
// out while the worker is still seconds from answering from cache.
|
|
24547
|
-
GET_OPERATOR_INFO:
|
|
24743
|
+
GET_OPERATOR_INFO: chunkFKHUXSYW_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
24548
24744
|
/** @deprecated Use `GET_OPERATOR_INFO`. */
|
|
24549
|
-
GET_ARKADE_INFO:
|
|
24745
|
+
GET_ARKADE_INFO: chunkFKHUXSYW_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
24550
24746
|
INDEXER_GET_VTXOS: 2e4,
|
|
24551
24747
|
INDEXER_GET_VIRTUAL_TXS: 2e4,
|
|
24552
24748
|
GET_VTXOS: 2e4,
|
|
@@ -24617,6 +24813,7 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
24617
24813
|
};
|
|
24618
24814
|
var DEDUPABLE_REQUEST_TYPES = /* @__PURE__ */ new Set([
|
|
24619
24815
|
"GET_ADDRESS",
|
|
24816
|
+
"GET_OWN_ADDRESS",
|
|
24620
24817
|
"GET_OPERATOR_INFO",
|
|
24621
24818
|
"INDEXER_GET_VTXOS",
|
|
24622
24819
|
"INDEXER_GET_VIRTUAL_TXS",
|
|
@@ -24650,10 +24847,10 @@ function getRequestDedupKey(request) {
|
|
|
24650
24847
|
}
|
|
24651
24848
|
function cosignWorkerError(e) {
|
|
24652
24849
|
if (e instanceof Error && e.message === "Unknown message") {
|
|
24653
|
-
return new
|
|
24850
|
+
return new chunkFKHUXSYW_cjs.OnchainCosignUnsupportedError();
|
|
24654
24851
|
}
|
|
24655
24852
|
if (e instanceof ServiceWorkerTimeoutError) {
|
|
24656
|
-
return new
|
|
24853
|
+
return new chunkFKHUXSYW_cjs.OnchainCosignAmbiguousError(e.message, { cause: e });
|
|
24657
24854
|
}
|
|
24658
24855
|
return rehydrateCosignError(e);
|
|
24659
24856
|
}
|
|
@@ -24708,7 +24905,7 @@ var ServiceWorkerAssetManager = class extends ServiceWorkerReadonlyAssetManager
|
|
|
24708
24905
|
}
|
|
24709
24906
|
};
|
|
24710
24907
|
var initializeMessageBus = (serviceWorker, config, timeoutMs = 2e3) => {
|
|
24711
|
-
|
|
24908
|
+
chunkFKHUXSYW_cjs.assertTimerMs("messageBusTimeoutMs", timeoutMs);
|
|
24712
24909
|
const initCmd = {
|
|
24713
24910
|
tag: "INITIALIZE_MESSAGE_BUS",
|
|
24714
24911
|
id: getRandomId(),
|
|
@@ -24839,7 +25036,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
24839
25036
|
Object.entries(options.messageTimeouts ?? {}).filter(([, ms]) => ms !== void 0)
|
|
24840
25037
|
);
|
|
24841
25038
|
for (const [key, value] of Object.entries(overrides)) {
|
|
24842
|
-
|
|
25039
|
+
chunkFKHUXSYW_cjs.assertTimerMs(`messageTimeouts.${key}`, value);
|
|
24843
25040
|
}
|
|
24844
25041
|
const messageTimeouts = {
|
|
24845
25042
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -25215,6 +25412,22 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25215
25412
|
throw new Error(`Failed to get address: ${error}`);
|
|
25216
25413
|
}
|
|
25217
25414
|
}
|
|
25415
|
+
async getOwnAddress() {
|
|
25416
|
+
const message = {
|
|
25417
|
+
id: getRandomId(),
|
|
25418
|
+
tag: this.messageTag,
|
|
25419
|
+
type: "GET_OWN_ADDRESS"
|
|
25420
|
+
};
|
|
25421
|
+
try {
|
|
25422
|
+
const response = await this.sendMessage(message);
|
|
25423
|
+
return response.payload.address;
|
|
25424
|
+
} catch (error) {
|
|
25425
|
+
if (error instanceof Error && error.message === "Unknown message") {
|
|
25426
|
+
return this.getAddress();
|
|
25427
|
+
}
|
|
25428
|
+
throw new Error(`Failed to get own address: ${error}`);
|
|
25429
|
+
}
|
|
25430
|
+
}
|
|
25218
25431
|
async getBoardingAddress() {
|
|
25219
25432
|
const message = {
|
|
25220
25433
|
id: getRandomId(),
|
|
@@ -25271,7 +25484,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25271
25484
|
try {
|
|
25272
25485
|
const response = await this.sendMessage(message);
|
|
25273
25486
|
const { vtxos, page } = response.payload;
|
|
25274
|
-
return { vtxos: vtxos.map(
|
|
25487
|
+
return { vtxos: vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo), page: page && { ...page } };
|
|
25275
25488
|
} catch (cause) {
|
|
25276
25489
|
throw new Error(`Failed to get vtxos: ${cause}`, { cause });
|
|
25277
25490
|
}
|
|
@@ -25380,7 +25593,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25380
25593
|
};
|
|
25381
25594
|
try {
|
|
25382
25595
|
const response = await this.sendMessage(message);
|
|
25383
|
-
return response.payload.vtxos.map(
|
|
25596
|
+
return response.payload.vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
25384
25597
|
} catch (error) {
|
|
25385
25598
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
25386
25599
|
}
|
|
@@ -25411,7 +25624,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25411
25624
|
"Service worker does not support the requested contract scope or freshness check"
|
|
25412
25625
|
);
|
|
25413
25626
|
}
|
|
25414
|
-
return payload.vtxos.map(
|
|
25627
|
+
return payload.vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
25415
25628
|
} catch (error) {
|
|
25416
25629
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
25417
25630
|
}
|
|
@@ -25621,7 +25834,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
25621
25834
|
};
|
|
25622
25835
|
try {
|
|
25623
25836
|
const response = await sendContractMessage(message);
|
|
25624
|
-
return response.payload.vtxos.map(
|
|
25837
|
+
return response.payload.vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
25625
25838
|
} catch (cause) {
|
|
25626
25839
|
throw new Error(`Failed to annotate vtxos: ${cause}`, { cause });
|
|
25627
25840
|
}
|
|
@@ -26328,7 +26541,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
26328
26541
|
};
|
|
26329
26542
|
try {
|
|
26330
26543
|
const response = await wallet.sendMessage(message);
|
|
26331
|
-
return response.payload.vtxos.map(
|
|
26544
|
+
return response.payload.vtxos.map(chunkFKHUXSYW_cjs.normalizeVtxo);
|
|
26332
26545
|
} catch (e) {
|
|
26333
26546
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
26334
26547
|
}
|
|
@@ -27209,7 +27422,7 @@ var CachingOperatorProvider = class {
|
|
|
27209
27422
|
constructor(inner, ttlMs = DEFAULT_TTL_MS) {
|
|
27210
27423
|
this.inner = inner;
|
|
27211
27424
|
this.ttlMs = ttlMs;
|
|
27212
|
-
|
|
27425
|
+
chunkFKHUXSYW_cjs.assertNonNegativeMs("ttlMs", ttlMs);
|
|
27213
27426
|
this.unsubscribe = inner.onServerInfoChanged?.((info) => {
|
|
27214
27427
|
this.cached = info;
|
|
27215
27428
|
this.expiresAt = Date.now() + this.ttlMs;
|
|
@@ -27296,7 +27509,7 @@ exports.BIP322 = void 0;
|
|
|
27296
27509
|
async function sign2(message, identity, network) {
|
|
27297
27510
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
27298
27511
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
27299
|
-
const toSpend =
|
|
27512
|
+
const toSpend = chunkFKHUXSYW_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
27300
27513
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
27301
27514
|
const signed = await identity.sign(toSign, [0]);
|
|
27302
27515
|
signed.finalizeIdx(0);
|
|
@@ -27354,7 +27567,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
27354
27567
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
27355
27568
|
return false;
|
|
27356
27569
|
}
|
|
27357
|
-
const toSpend =
|
|
27570
|
+
const toSpend = chunkFKHUXSYW_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
27358
27571
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript);
|
|
27359
27572
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
27360
27573
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -27375,7 +27588,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
27375
27588
|
}
|
|
27376
27589
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
27377
27590
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
27378
|
-
const toSpend =
|
|
27591
|
+
const toSpend = chunkFKHUXSYW_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
27379
27592
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
27380
27593
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
27381
27594
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -27428,7 +27641,7 @@ function encodeCompactSize(n) {
|
|
|
27428
27641
|
return buf;
|
|
27429
27642
|
}
|
|
27430
27643
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
27431
|
-
const tx = new
|
|
27644
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 0 });
|
|
27432
27645
|
tx.addInput({
|
|
27433
27646
|
txid: toSpend.id,
|
|
27434
27647
|
index: 0,
|
|
@@ -27442,12 +27655,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
27442
27655
|
});
|
|
27443
27656
|
tx.addOutput({
|
|
27444
27657
|
amount: 0n,
|
|
27445
|
-
script:
|
|
27658
|
+
script: chunkFKHUXSYW_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
27446
27659
|
});
|
|
27447
27660
|
return tx;
|
|
27448
27661
|
}
|
|
27449
27662
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
27450
|
-
const tx = new
|
|
27663
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 0 });
|
|
27451
27664
|
tx.addInput({
|
|
27452
27665
|
txid: toSpend.id,
|
|
27453
27666
|
index: 0,
|
|
@@ -27459,12 +27672,12 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
27459
27672
|
});
|
|
27460
27673
|
tx.addOutput({
|
|
27461
27674
|
amount: 0n,
|
|
27462
|
-
script:
|
|
27675
|
+
script: chunkFKHUXSYW_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
27463
27676
|
});
|
|
27464
27677
|
return tx;
|
|
27465
27678
|
}
|
|
27466
27679
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
27467
|
-
const tx =
|
|
27680
|
+
const tx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
27468
27681
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
27469
27682
|
const input = tx.getInput(0);
|
|
27470
27683
|
if (!input) {
|
|
@@ -27498,7 +27711,7 @@ async function resolveUnilateralPath(params) {
|
|
|
27498
27711
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
27499
27712
|
const contract = contractRepository ? (await collectContracts(contractRepository, { script: scriptHex }))[0] : void 0;
|
|
27500
27713
|
if (contract) {
|
|
27501
|
-
const handler =
|
|
27714
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
27502
27715
|
if (!handler) {
|
|
27503
27716
|
throw new ExitPathError(
|
|
27504
27717
|
"no-handler",
|
|
@@ -27734,7 +27947,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
27734
27947
|
let totalAmount = 0n;
|
|
27735
27948
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
27736
27949
|
for (const vtxo of vtxos) {
|
|
27737
|
-
if (!
|
|
27950
|
+
if (!chunkFKHUXSYW_cjs.canSweepOnchain(vtxo)) {
|
|
27738
27951
|
throw new Error(
|
|
27739
27952
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
27740
27953
|
);
|
|
@@ -27786,7 +27999,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
27786
27999
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
27787
28000
|
);
|
|
27788
28001
|
}
|
|
27789
|
-
const tx = new
|
|
28002
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 2 });
|
|
27790
28003
|
for (const input of inputs) {
|
|
27791
28004
|
tx.addInput(input);
|
|
27792
28005
|
}
|
|
@@ -27866,7 +28079,7 @@ async function buildSignedSweep(params) {
|
|
|
27866
28079
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
27867
28080
|
);
|
|
27868
28081
|
}
|
|
27869
|
-
const tx = new
|
|
28082
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 2 });
|
|
27870
28083
|
tx.addInput({
|
|
27871
28084
|
txid: vtxo.txid,
|
|
27872
28085
|
index: vtxo.vout,
|
|
@@ -27919,7 +28132,7 @@ async function resolveFeeRate(opts) {
|
|
|
27919
28132
|
}
|
|
27920
28133
|
async function selectExitVtxos(opts) {
|
|
27921
28134
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
27922
|
-
const res = await
|
|
28135
|
+
const res = await chunkFKHUXSYW_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
27923
28136
|
const scripts = [
|
|
27924
28137
|
...new Set(res.vtxos.filter((vtxo) => !vtxo.isSpent).map((vtxo) => vtxo.script))
|
|
27925
28138
|
];
|
|
@@ -27937,7 +28150,7 @@ async function selectExitVtxos(opts) {
|
|
|
27937
28150
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
27938
28151
|
);
|
|
27939
28152
|
}
|
|
27940
|
-
const handler =
|
|
28153
|
+
const handler = chunkVIQF74QJ_cjs.contractHandlers.get(contract.type);
|
|
27941
28154
|
if (!handler) {
|
|
27942
28155
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
27943
28156
|
}
|
|
@@ -27971,7 +28184,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
27971
28184
|
if (pendingNodes.length > 0) {
|
|
27972
28185
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
27973
28186
|
for (const psbt of txs) {
|
|
27974
|
-
psbts.set(
|
|
28187
|
+
psbts.set(chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
27975
28188
|
}
|
|
27976
28189
|
}
|
|
27977
28190
|
const childVsize = Number(
|
|
@@ -28136,7 +28349,7 @@ var Executor = class {
|
|
|
28136
28349
|
constructor(pkg, provider, opts) {
|
|
28137
28350
|
this.pkg = pkg;
|
|
28138
28351
|
this.provider = provider;
|
|
28139
|
-
|
|
28352
|
+
chunkFKHUXSYW_cjs.assertTimerMs("pollIntervalMs", opts?.pollIntervalMs);
|
|
28140
28353
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
28141
28354
|
this.feeWallet = opts?.feeWallet;
|
|
28142
28355
|
this.signal = opts?.signal;
|
|
@@ -28520,7 +28733,7 @@ async function prepare(opts) {
|
|
|
28520
28733
|
if (newFee <= splitterFee) break;
|
|
28521
28734
|
splitterFee = newFee;
|
|
28522
28735
|
}
|
|
28523
|
-
const splitter = new
|
|
28736
|
+
const splitter = new chunkFKHUXSYW_cjs.Transaction({ version: 2 });
|
|
28524
28737
|
for (const coin of selected.inputs) {
|
|
28525
28738
|
splitter.addInput({
|
|
28526
28739
|
txid: coin.txid,
|
|
@@ -28660,46 +28873,46 @@ var UnilateralExit = {
|
|
|
28660
28873
|
// src/arkade/index.ts
|
|
28661
28874
|
var arkade_exports = {};
|
|
28662
28875
|
chunk6TBTL42M_cjs.__export(arkade_exports, {
|
|
28663
|
-
ARKADE_OP: () =>
|
|
28664
|
-
ARKADE_OPCODES: () =>
|
|
28665
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
28666
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
28667
|
-
ARKADE_OPS: () =>
|
|
28876
|
+
ARKADE_OP: () => chunkUNLH3NNG_cjs.ARKADE_OP,
|
|
28877
|
+
ARKADE_OPCODES: () => chunkUNLH3NNG_cjs.ARKADE_OPCODES,
|
|
28878
|
+
ARKADE_OPCODE_NAMES: () => chunkUNLH3NNG_cjs.ARKADE_OPCODE_NAMES,
|
|
28879
|
+
ARKADE_OPCODE_VALUES: () => chunkUNLH3NNG_cjs.ARKADE_OPCODE_VALUES,
|
|
28880
|
+
ARKADE_OPS: () => chunkUNLH3NNG_cjs.ARKADE_OPS,
|
|
28668
28881
|
Arkade: () => Arkade,
|
|
28669
28882
|
ArkadeContract: () => ArkadeContract,
|
|
28670
|
-
ArkadeProgramScript: () =>
|
|
28671
|
-
ArkadeScript: () =>
|
|
28883
|
+
ArkadeProgramScript: () => chunkUNLH3NNG_cjs.ArkadeProgramScript,
|
|
28884
|
+
ArkadeScript: () => chunkUNLH3NNG_cjs.ArkadeScript,
|
|
28672
28885
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
28673
|
-
BigNum: () =>
|
|
28886
|
+
BigNum: () => chunkUNLH3NNG_cjs.bignum_exports,
|
|
28674
28887
|
OP: () => btcSigner.OP,
|
|
28675
|
-
OPCODE_NAMES: () =>
|
|
28676
|
-
OPCODE_VALUES: () =>
|
|
28677
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
28888
|
+
OPCODE_NAMES: () => chunkUNLH3NNG_cjs.OPCODE_NAMES,
|
|
28889
|
+
OPCODE_VALUES: () => chunkUNLH3NNG_cjs.OPCODE_VALUES,
|
|
28890
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkUNLH3NNG_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
28678
28891
|
Script: () => btcSigner.Script,
|
|
28679
|
-
UnsupportedProgramVersionError: () =>
|
|
28680
|
-
arkadeScriptHash: () =>
|
|
28681
|
-
arkadeWitnessHash: () =>
|
|
28682
|
-
asmToBytes: () =>
|
|
28683
|
-
bytesToASM: () =>
|
|
28684
|
-
computeArkadeScriptPublicKey: () =>
|
|
28892
|
+
UnsupportedProgramVersionError: () => chunkUNLH3NNG_cjs.UnsupportedProgramVersionError,
|
|
28893
|
+
arkadeScriptHash: () => chunkUNLH3NNG_cjs.arkadeScriptHash,
|
|
28894
|
+
arkadeWitnessHash: () => chunkUNLH3NNG_cjs.arkadeWitnessHash,
|
|
28895
|
+
asmToBytes: () => chunkUNLH3NNG_cjs.asmToBytes,
|
|
28896
|
+
bytesToASM: () => chunkUNLH3NNG_cjs.bytesToASM,
|
|
28897
|
+
computeArkadeScriptPublicKey: () => chunkUNLH3NNG_cjs.computeArkadeScriptPublicKey,
|
|
28685
28898
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
28686
|
-
deserializeArkadeContractParams: () =>
|
|
28687
|
-
fromASM: () =>
|
|
28688
|
-
getOpcodeName: () =>
|
|
28689
|
-
getOpcodeValue: () =>
|
|
28690
|
-
isContractArtifact: () =>
|
|
28691
|
-
parseArtifact: () =>
|
|
28692
|
-
programFromArtifact: () =>
|
|
28899
|
+
deserializeArkadeContractParams: () => chunkUNLH3NNG_cjs.deserializeArkadeContractParams,
|
|
28900
|
+
fromASM: () => chunkUNLH3NNG_cjs.fromASM,
|
|
28901
|
+
getOpcodeName: () => chunkUNLH3NNG_cjs.getOpcodeName,
|
|
28902
|
+
getOpcodeValue: () => chunkUNLH3NNG_cjs.getOpcodeValue,
|
|
28903
|
+
isContractArtifact: () => chunkUNLH3NNG_cjs.isContractArtifact,
|
|
28904
|
+
parseArtifact: () => chunkUNLH3NNG_cjs.parseArtifact,
|
|
28905
|
+
programFromArtifact: () => chunkUNLH3NNG_cjs.programFromArtifact,
|
|
28693
28906
|
renewProgramContractOutputs: () => renewProgramContractOutputs,
|
|
28694
28907
|
resolveArkadeService: () => resolveArkadeService,
|
|
28695
|
-
resolveAsm: () =>
|
|
28696
|
-
serializeArkadeContractParams: () =>
|
|
28697
|
-
stringifyArtifact: () =>
|
|
28698
|
-
toASM: () =>
|
|
28699
|
-
validateProgram: () =>
|
|
28700
|
-
witnessRefToBytes: () =>
|
|
28908
|
+
resolveAsm: () => chunkUNLH3NNG_cjs.resolveAsm,
|
|
28909
|
+
serializeArkadeContractParams: () => chunkUNLH3NNG_cjs.serializeArkadeContractParams,
|
|
28910
|
+
stringifyArtifact: () => chunkUNLH3NNG_cjs.stringifyArtifact,
|
|
28911
|
+
toASM: () => chunkUNLH3NNG_cjs.toASM,
|
|
28912
|
+
validateProgram: () => chunkUNLH3NNG_cjs.validateProgram,
|
|
28913
|
+
witnessRefToBytes: () => chunkUNLH3NNG_cjs.witnessRefToBytes
|
|
28701
28914
|
});
|
|
28702
|
-
var isVtxoCoin = (input) =>
|
|
28915
|
+
var isVtxoCoin = (input) => chunkFKHUXSYW_cjs.isVirtualCoin(input);
|
|
28703
28916
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
28704
28917
|
if (!signer && inputs.some((input) => !isVtxoCoin(input))) {
|
|
28705
28918
|
throw new Error("createArkadeBatchHandler: boarding inputs need a signer");
|
|
@@ -28742,7 +28955,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28742
28955
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
28743
28956
|
return { skip: true };
|
|
28744
28957
|
}
|
|
28745
|
-
const commitmentTx =
|
|
28958
|
+
const commitmentTx = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
28746
28959
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
28747
28960
|
if (recipients && recipients.length > 0) {
|
|
28748
28961
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -28780,7 +28993,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28780
28993
|
if (connectorTree) {
|
|
28781
28994
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
28782
28995
|
}
|
|
28783
|
-
let commitmentPsbt =
|
|
28996
|
+
let commitmentPsbt = chunkFKHUXSYW_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
28784
28997
|
assertFinalCommitmentMatchesValidated(
|
|
28785
28998
|
commitmentPsbt,
|
|
28786
28999
|
validatedCommitmentTxid,
|
|
@@ -28823,7 +29036,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28823
29036
|
boardingIndices.push(boardingIdx);
|
|
28824
29037
|
continue;
|
|
28825
29038
|
}
|
|
28826
|
-
if (!
|
|
29039
|
+
if (!chunkFKHUXSYW_cjs.requiresForfeit(input) || isSubdust(input, info.dust)) {
|
|
28827
29040
|
continue;
|
|
28828
29041
|
}
|
|
28829
29042
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -28861,7 +29074,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
28861
29074
|
forfeitOutputScript
|
|
28862
29075
|
);
|
|
28863
29076
|
if (input.extraWitness?.length) {
|
|
28864
|
-
|
|
29077
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(forfeitTx, 0, chunkFKHUXSYW_cjs.ConditionWitness, input.extraWitness);
|
|
28865
29078
|
}
|
|
28866
29079
|
if (signer) forfeitTx = await signer.sign(forfeitTx, [0]);
|
|
28867
29080
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -28945,8 +29158,8 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
|
|
|
28945
29158
|
if (compiled.def.tapscript.csv) {
|
|
28946
29159
|
throw new Error(`renewProgramContractOutputs: ${fn} has a CSV timelock`);
|
|
28947
29160
|
}
|
|
28948
|
-
const condition =
|
|
28949
|
-
const stack =
|
|
29161
|
+
const condition = chunkUNLH3NNG_cjs.staticWitness(compiled.def.tapscript.witness, contract.args);
|
|
29162
|
+
const stack = chunkUNLH3NNG_cjs.staticWitness(compiled.def.arkadeScript?.witness, contract.args);
|
|
28950
29163
|
if (!condition || !stack) {
|
|
28951
29164
|
throw new Error(
|
|
28952
29165
|
`renewProgramContractOutputs: ${fn} needs call arguments, which a renewal cannot supply`
|
|
@@ -28956,7 +29169,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
|
|
|
28956
29169
|
});
|
|
28957
29170
|
const { fees } = await arkProvider.getInfo();
|
|
28958
29171
|
const fee = new Estimator(fees?.intentFee ?? {}).evaluate(
|
|
28959
|
-
legs.map(({ coin }) =>
|
|
29172
|
+
legs.map(({ coin }) => chunkFKHUXSYW_cjs.toOffchainInputFeeParams(chunkFKHUXSYW_cjs.normalizeVtxo(coin))),
|
|
28960
29173
|
[],
|
|
28961
29174
|
legs.map(({ contract, coin }) => ({
|
|
28962
29175
|
amount: BigInt(coin.value),
|
|
@@ -29019,7 +29232,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
|
|
|
29019
29232
|
const [signedProof, deleteProof] = await Promise.all(
|
|
29020
29233
|
[message, deleteMessage].map(
|
|
29021
29234
|
(m) => emulator.submitIntent({
|
|
29022
|
-
proof: base.base64.encode(
|
|
29235
|
+
proof: base.base64.encode(chunkFKHUXSYW_cjs.Proof.create(m, coins, outputs).toPSBT()),
|
|
29023
29236
|
message: m
|
|
29024
29237
|
})
|
|
29025
29238
|
)
|
|
@@ -29283,7 +29496,9 @@ var Arkade = class _Arkade {
|
|
|
29283
29496
|
* the program's literal type, so `functions` is strongly typed.
|
|
29284
29497
|
*
|
|
29285
29498
|
* Declared `server`/`user` params default to the client's keys. Compiler
|
|
29286
|
-
* artifacts reserve the operator key and exit delay to the connected operator
|
|
29499
|
+
* artifacts reserve the operator key and exit delay to the connected operator,
|
|
29500
|
+
* and the witness program of each contract they instantiate to the derived one
|
|
29501
|
+
* (see {@link ArkadeContract}'s constructor).
|
|
29287
29502
|
* Struct and array params are passed whole by name (see {@link ArkadeNestedValue}).
|
|
29288
29503
|
*/
|
|
29289
29504
|
contract(program, args = {}) {
|
|
@@ -29295,18 +29510,7 @@ var Arkade = class _Arkade {
|
|
|
29295
29510
|
args = { ...args, user: this.userKey };
|
|
29296
29511
|
}
|
|
29297
29512
|
if (declared.includes("SERVER_EXIT_DELAY")) {
|
|
29298
|
-
const
|
|
29299
|
-
if (delay === void 0 || delay <= 0n)
|
|
29300
|
-
throw new Error(
|
|
29301
|
-
"compiler artifact: server must provide a positive unilateral exit delay"
|
|
29302
|
-
);
|
|
29303
|
-
const typed = toTimelock(delay);
|
|
29304
|
-
if (typed.type === "seconds" && delay % 512n !== 0n) {
|
|
29305
|
-
throw new Error(
|
|
29306
|
-
`compiler artifact: server exit delay ${delay}s must be a multiple of 512 seconds`
|
|
29307
|
-
);
|
|
29308
|
-
}
|
|
29309
|
-
const sequence = BigInt(chunk6TBTL42M_cjs.timelockToSequence(typed));
|
|
29513
|
+
const sequence = exitDelaySequence(this.serverExitDelay);
|
|
29310
29514
|
if (args.SERVER_EXIT_DELAY !== void 0 && args.SERVER_EXIT_DELAY !== sequence && args.SERVER_EXIT_DELAY !== Number(sequence)) {
|
|
29311
29515
|
throw new Error(
|
|
29312
29516
|
"compiler artifact: reserved SERVER_EXIT_DELAY must match the connected server"
|
|
@@ -29325,6 +29529,11 @@ var Arkade = class _Arkade {
|
|
|
29325
29529
|
}
|
|
29326
29530
|
};
|
|
29327
29531
|
var ArkadeContract = class _ArkadeContract {
|
|
29532
|
+
/**
|
|
29533
|
+
* Compile `program` with `args` against `keys` (the client's by default). Each contract a
|
|
29534
|
+
* compiler artifact instantiates is bound to its witness program, derived with `keys` and the
|
|
29535
|
+
* client's exit delay; a value passed for it by hand must match.
|
|
29536
|
+
*/
|
|
29328
29537
|
constructor(client, program, args = {}, keys) {
|
|
29329
29538
|
this.client = client;
|
|
29330
29539
|
this.program = program;
|
|
@@ -29335,7 +29544,8 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
29335
29544
|
userKey: client.userKey,
|
|
29336
29545
|
emulatorKey: client.emulatorKey
|
|
29337
29546
|
};
|
|
29338
|
-
|
|
29547
|
+
instantiate(program, this.args, this.keys, client.serverExitDelay);
|
|
29548
|
+
this.vtxoScript = new chunkUNLH3NNG_cjs.ArkadeProgramScript(program, this.args, this.keys);
|
|
29339
29549
|
this.tapTree = this.vtxoScript.encode();
|
|
29340
29550
|
this.compiled = this.vtxoScript.compiled;
|
|
29341
29551
|
}
|
|
@@ -29361,7 +29571,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
29361
29571
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
29362
29572
|
);
|
|
29363
29573
|
}
|
|
29364
|
-
const typed =
|
|
29574
|
+
const typed = chunkUNLH3NNG_cjs.deserializeArkadeContractParams(contract.params);
|
|
29365
29575
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
29366
29576
|
serverKey: typed.serverKey,
|
|
29367
29577
|
userKey: typed.userKey,
|
|
@@ -29416,7 +29626,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
29416
29626
|
toContractParams() {
|
|
29417
29627
|
return {
|
|
29418
29628
|
type: "arkade",
|
|
29419
|
-
params:
|
|
29629
|
+
params: chunkUNLH3NNG_cjs.serializeArkadeContractParams({
|
|
29420
29630
|
program: this.program,
|
|
29421
29631
|
args: this.args,
|
|
29422
29632
|
serverKey: this.keys.serverKey,
|
|
@@ -29503,17 +29713,17 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
29503
29713
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
29504
29714
|
if (registered) {
|
|
29505
29715
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
29506
|
-
return (withVtxos?.vtxos ?? []).filter((v) => !
|
|
29716
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunkFKHUXSYW_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
29507
29717
|
}
|
|
29508
29718
|
}
|
|
29509
29719
|
if (!this.client.indexer) {
|
|
29510
29720
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
29511
29721
|
}
|
|
29512
|
-
const { vtxos } = await
|
|
29722
|
+
const { vtxos } = await chunkFKHUXSYW_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
29513
29723
|
scripts: [scriptHex],
|
|
29514
29724
|
spendableOnly: true
|
|
29515
29725
|
});
|
|
29516
|
-
return vtxos.filter((v) => !
|
|
29726
|
+
return vtxos.filter((v) => !chunkFKHUXSYW_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
29517
29727
|
}
|
|
29518
29728
|
/** Total spendable balance (requires an indexer). */
|
|
29519
29729
|
async getBalance() {
|
|
@@ -29679,7 +29889,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
29679
29889
|
this.client.checkpoint
|
|
29680
29890
|
);
|
|
29681
29891
|
inputs.forEach(({ coin }, i) => {
|
|
29682
|
-
if (coin.sourceTx)
|
|
29892
|
+
if (coin.sourceTx) chunkFKHUXSYW_cjs.setArkPsbtField(arkTx, i, chunkFKHUXSYW_cjs.PrevArkTxField, coin.sourceTx);
|
|
29683
29893
|
});
|
|
29684
29894
|
if (inputs.some(({ unlocker }) => unlocker.fn.arkadeScript)) {
|
|
29685
29895
|
const indexer = this.client.indexer;
|
|
@@ -29699,8 +29909,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
29699
29909
|
(w) => witnessBytes(unlocker, "tapscript", w)
|
|
29700
29910
|
);
|
|
29701
29911
|
if (condition.length === 0) return;
|
|
29702
|
-
|
|
29703
|
-
|
|
29912
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(arkTx, i, chunkFKHUXSYW_cjs.ConditionWitness, condition);
|
|
29913
|
+
chunkFKHUXSYW_cjs.setArkPsbtField(checkpoints[i], 0, chunkFKHUXSYW_cjs.ConditionWitness, condition);
|
|
29704
29914
|
});
|
|
29705
29915
|
const packets = [];
|
|
29706
29916
|
if (this.assetSpecs.length > 0) {
|
|
@@ -29765,7 +29975,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
29765
29975
|
);
|
|
29766
29976
|
}
|
|
29767
29977
|
const { sequence, lockTime } = this.leafTimelocks(fn);
|
|
29768
|
-
const tx = new
|
|
29978
|
+
const tx = new chunkFKHUXSYW_cjs.Transaction({ version: 2, lockTime });
|
|
29769
29979
|
tx.addInput({ txid: base.hex.decode(coin.txid), index: coin.vout, sequence });
|
|
29770
29980
|
for (const o of outputs) tx.addOutput(o);
|
|
29771
29981
|
const condition = (fn.def.tapscript.witness ?? []).map(
|
|
@@ -29931,20 +30141,20 @@ var ArkadeTransactionBuilder = class {
|
|
|
29931
30141
|
* A caller's packet counts for every input, unread; arkd checks what it actually routes.
|
|
29932
30142
|
*/
|
|
29933
30143
|
routesAssetsFrom(vin) {
|
|
29934
|
-
return this.extraPackets.some((p) => p.type() ===
|
|
30144
|
+
return this.extraPackets.some((p) => p.type() === chunkJSYS2KX3_cjs.Packet.PACKET_TYPE) || this.assetSpecs.some((spec) => spec.inputs.some((i) => i.vin === vin));
|
|
29935
30145
|
}
|
|
29936
30146
|
buildAssetPacket() {
|
|
29937
30147
|
const groups = this.assetSpecs.map((s) => {
|
|
29938
|
-
const id = typeof s.assetId === "string" ?
|
|
29939
|
-
return
|
|
30148
|
+
const id = typeof s.assetId === "string" ? chunkJSYS2KX3_cjs.AssetId.fromString(s.assetId) : chunkJSYS2KX3_cjs.AssetId.fromBytes(s.assetId);
|
|
30149
|
+
return chunkJSYS2KX3_cjs.AssetGroup.create(
|
|
29940
30150
|
id,
|
|
29941
30151
|
null,
|
|
29942
|
-
s.inputs.map((i) =>
|
|
29943
|
-
s.outputs.map((o) =>
|
|
29944
|
-
(s.metadata ?? []).map((m) =>
|
|
30152
|
+
s.inputs.map((i) => chunkJSYS2KX3_cjs.AssetInput.create(i.vin, i.amount)),
|
|
30153
|
+
s.outputs.map((o) => chunkJSYS2KX3_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
30154
|
+
(s.metadata ?? []).map((m) => chunkJSYS2KX3_cjs.Metadata.create(m.key, m.value))
|
|
29945
30155
|
);
|
|
29946
30156
|
});
|
|
29947
|
-
return
|
|
30157
|
+
return chunkJSYS2KX3_cjs.Packet.create(groups);
|
|
29948
30158
|
}
|
|
29949
30159
|
};
|
|
29950
30160
|
function unspendable(coin, now) {
|
|
@@ -29953,7 +30163,48 @@ function unspendable(coin, now) {
|
|
|
29953
30163
|
return void 0;
|
|
29954
30164
|
}
|
|
29955
30165
|
function witnessBytes({ contract, args }, segment, ref) {
|
|
29956
|
-
return
|
|
30166
|
+
return chunkUNLH3NNG_cjs.witnessRefToBytes(ref, args[segment], contract.args);
|
|
30167
|
+
}
|
|
30168
|
+
function exitDelaySequence(delay) {
|
|
30169
|
+
if (delay === void 0 || delay <= 0n)
|
|
30170
|
+
throw new Error("compiler artifact: server must provide a positive unilateral exit delay");
|
|
30171
|
+
const typed = toTimelock(delay);
|
|
30172
|
+
if (typed.type === "seconds" && delay % 512n !== 0n) {
|
|
30173
|
+
throw new Error(
|
|
30174
|
+
`compiler artifact: server exit delay ${delay}s must be a multiple of 512 seconds`
|
|
30175
|
+
);
|
|
30176
|
+
}
|
|
30177
|
+
return BigInt(chunk6TBTL42M_cjs.timelockToSequence(typed));
|
|
30178
|
+
}
|
|
30179
|
+
function instantiate(program, args, keys, exitDelay) {
|
|
30180
|
+
const defs = new Map((program.params ?? []).map((def) => [def.name, def]));
|
|
30181
|
+
for (const [param, child] of Object.entries(chunkUNLH3NNG_cjs.instantiatedContracts(program))) {
|
|
30182
|
+
const childArgs = { server: keys.serverKey };
|
|
30183
|
+
for (const [name, from] of Object.entries(child.args)) {
|
|
30184
|
+
if (typeof from !== "string") {
|
|
30185
|
+
childArgs[name] = from;
|
|
30186
|
+
continue;
|
|
30187
|
+
}
|
|
30188
|
+
const value = Object.hasOwn(args, from) ? args[from] : void 0;
|
|
30189
|
+
if (value === void 0) {
|
|
30190
|
+
throw new Error(`program parameter '${from}' is declared but not bound in args`);
|
|
30191
|
+
}
|
|
30192
|
+
chunkUNLH3NNG_cjs.validateParamValue(defs.get(from), value);
|
|
30193
|
+
childArgs[name] = value;
|
|
30194
|
+
}
|
|
30195
|
+
if (child.program.params?.some((p) => p.name === "SERVER_EXIT_DELAY")) {
|
|
30196
|
+
childArgs.SERVER_EXIT_DELAY = exitDelaySequence(exitDelay);
|
|
30197
|
+
}
|
|
30198
|
+
instantiate(child.program, childArgs, keys, exitDelay);
|
|
30199
|
+
const key = new chunkUNLH3NNG_cjs.ArkadeProgramScript(child.program, childArgs, keys).tweakedPublicKey;
|
|
30200
|
+
const passed = args[param];
|
|
30201
|
+
if (passed !== void 0 && !(passed instanceof Uint8Array && utils_js.equalBytes(passed, key))) {
|
|
30202
|
+
throw new Error(
|
|
30203
|
+
`compiler artifact: '${param}' must be the ${child.program.name} witness program derived from its arguments`
|
|
30204
|
+
);
|
|
30205
|
+
}
|
|
30206
|
+
args[param] = key;
|
|
30207
|
+
}
|
|
29957
30208
|
}
|
|
29958
30209
|
function flattenValue(name, value, out, ancestors = /* @__PURE__ */ new Set()) {
|
|
29959
30210
|
if (typeof value !== "object" || value === null || ArrayBuffer.isView(value)) {
|
|
@@ -30016,7 +30267,7 @@ function bindInputs(label, inputs, callArgs) {
|
|
|
30016
30267
|
}
|
|
30017
30268
|
for (const def of inputs) {
|
|
30018
30269
|
if (bound[def.name] === void 0) throw new Error(`${label}: missing input '${def.name}'`);
|
|
30019
|
-
|
|
30270
|
+
chunkUNLH3NNG_cjs.validateParamValue(def, bound[def.name]);
|
|
30020
30271
|
}
|
|
30021
30272
|
return bound;
|
|
30022
30273
|
}
|
|
@@ -30426,14 +30677,14 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
|
|
|
30426
30677
|
function offchainInputFees(vtxos, fees) {
|
|
30427
30678
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
30428
30679
|
return vtxos.reduce(
|
|
30429
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
30680
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
30430
30681
|
0
|
|
30431
30682
|
);
|
|
30432
30683
|
}
|
|
30433
30684
|
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
30434
30685
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
30435
30686
|
const net = inputs.reduce(
|
|
30436
|
-
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(
|
|
30687
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkFKHUXSYW_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
30437
30688
|
0n
|
|
30438
30689
|
);
|
|
30439
30690
|
const script = base.hex.encode(chunk6TBTL42M_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
@@ -30775,5 +31026,5 @@ exports.walletFeeSource = walletFeeSource;
|
|
|
30775
31026
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
30776
31027
|
exports.watchExecutorContracts = watchExecutorContracts;
|
|
30777
31028
|
exports.withPrevTxs = withPrevTxs;
|
|
30778
|
-
//# sourceMappingURL=chunk-
|
|
30779
|
-
//# sourceMappingURL=chunk-
|
|
31029
|
+
//# sourceMappingURL=chunk-CMFRCBZW.cjs.map
|
|
31030
|
+
//# sourceMappingURL=chunk-CMFRCBZW.cjs.map
|