@arkade-os/sdk 0.4.67 → 0.5.0-rc.0
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 +40 -5
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{asyncStorageTaskQueue-Za-e_zMk.d.ts → asyncStorageTaskQueue-BCzN3Y45.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-LTpeXYaD.d.cts → asyncStorageTaskQueue-CdF_ELX8.d.cts} +2 -2
- package/dist/{chunk-MJUTO3PY.cjs → chunk-5MJHZHG7.cjs} +771 -477
- package/dist/chunk-5MJHZHG7.cjs.map +1 -0
- package/dist/{chunk-2JV4VQ7C.cjs → chunk-6AFUNKK7.cjs} +33 -7
- package/dist/chunk-6AFUNKK7.cjs.map +1 -0
- package/dist/{chunk-AEWJU6NZ.js → chunk-6F2Q32KA.js} +352 -59
- package/dist/chunk-6F2Q32KA.js.map +1 -0
- package/dist/{chunk-EALWOVHK.js → chunk-ABJPM4JF.js} +4 -4
- package/dist/{chunk-EALWOVHK.js.map → chunk-ABJPM4JF.js.map} +1 -1
- package/dist/{chunk-CO3KKSWM.cjs → chunk-CZ32XADN.cjs} +17 -17
- package/dist/{chunk-CO3KKSWM.cjs.map → chunk-CZ32XADN.cjs.map} +1 -1
- package/dist/{chunk-X3VEMUVV.js → chunk-FVTJJQNM.js} +3 -3
- package/dist/{chunk-X3VEMUVV.js.map → chunk-FVTJJQNM.js.map} +1 -1
- package/dist/{chunk-OIZ2V2VD.cjs → chunk-HL7EC2Z5.cjs} +121 -170
- package/dist/chunk-HL7EC2Z5.cjs.map +1 -0
- package/dist/{chunk-MZFUZUTQ.js → chunk-JYP7YXT2.js} +4 -4
- package/dist/{chunk-MZFUZUTQ.js.map → chunk-JYP7YXT2.js.map} +1 -1
- package/dist/{chunk-6TAQF6EV.js → chunk-KTU44AEH.js} +75 -124
- package/dist/chunk-KTU44AEH.js.map +1 -0
- package/dist/{chunk-YDRZDZPP.cjs → chunk-PB5KJI4U.cjs} +10 -10
- package/dist/{chunk-YDRZDZPP.cjs.map → chunk-PB5KJI4U.cjs.map} +1 -1
- package/dist/{chunk-3WIWNE4P.js → chunk-PPG6W34P.js} +30 -8
- package/dist/chunk-PPG6W34P.js.map +1 -0
- package/dist/{chunk-R2YAMONM.cjs → chunk-RXWKCEZP.cjs} +17 -17
- package/dist/{chunk-R2YAMONM.cjs.map → chunk-RXWKCEZP.cjs.map} +1 -1
- package/dist/contracts/handlers/index.cjs +9 -9
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-Bz2e2zXY.d.cts → delegate-DLIOBQ5x.d.cts} +1 -1
- package/dist/{delegate-cdmzb2f9.d.ts → delegate-Dyn5L80J.d.ts} +1 -1
- package/dist/{hdWalletCapable-BSjuUYOO.d.cts → hdWalletCapable-D9tooZ6F.d.ts} +102 -27
- package/dist/{hdWalletCapable-Hi12xjCJ.d.ts → hdWalletCapable-Dt3MUiGE.d.cts} +102 -27
- package/dist/{index-BiACuWaf.d.ts → index-D3hmsuKs.d.cts} +100 -123
- package/dist/{index-D2GjZxBr.d.cts → index-D9tXd-tN.d.ts} +100 -123
- package/dist/{index-DU5o_hz7.d.ts → index-Udm5V2xW.d.cts} +184 -19
- package/dist/{index-DU5o_hz7.d.cts → index-Udm5V2xW.d.ts} +184 -19
- package/dist/index.cjs +309 -289
- package/dist/index.d.cts +125 -29
- package/dist/index.d.ts +125 -29
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-BZJMLQ6g.d.cts → taskRunner-DxZciNaa.d.cts} +2 -2
- package/dist/{taskRunner-DATaRQus.d.ts → taskRunner-ZdS16Ypm.d.ts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +23 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +7 -4
- package/dist/wallet/expo/index.d.ts +7 -4
- package/dist/wallet/expo/index.js +14 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +3 -2
- package/dist/chunk-2JV4VQ7C.cjs.map +0 -1
- package/dist/chunk-3WIWNE4P.js.map +0 -1
- package/dist/chunk-6TAQF6EV.js.map +0 -1
- package/dist/chunk-AEWJU6NZ.js.map +0 -1
- package/dist/chunk-MJUTO3PY.cjs.map +0 -1
- package/dist/chunk-OIZ2V2VD.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkCZ32XADN_cjs = require('./chunk-CZ32XADN.cjs');
|
|
4
|
+
var chunkHL7EC2Z5_cjs = require('./chunk-HL7EC2Z5.cjs');
|
|
5
|
+
var chunk6AFUNKK7_cjs = require('./chunk-6AFUNKK7.cjs');
|
|
6
6
|
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
7
7
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
8
8
|
var btcSigner = require('@scure/btc-signer');
|
|
@@ -188,7 +188,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
188
188
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
189
189
|
const tx = this.graph.find(txid);
|
|
190
190
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
191
|
-
const cosigners =
|
|
191
|
+
const cosigners = chunk6AFUNKK7_cjs.getArkPsbtFields(tx.root, 0, chunk6AFUNKK7_cjs.CosignerPublicKey).map(
|
|
192
192
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
193
193
|
// xonly pubkey
|
|
194
194
|
);
|
|
@@ -240,7 +240,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
240
240
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
241
241
|
const prevoutAmounts = [];
|
|
242
242
|
const prevoutScripts = [];
|
|
243
|
-
const cosigners =
|
|
243
|
+
const cosigners = chunk6AFUNKK7_cjs.getArkPsbtFields(g.root, 0, chunk6AFUNKK7_cjs.CosignerPublicKey).map((c) => c.key);
|
|
244
244
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
245
245
|
taprootTweak: this.scriptRoot
|
|
246
246
|
});
|
|
@@ -294,7 +294,7 @@ function getPrevOutput(finalKey, graph, sharedOutputAmount, tx) {
|
|
|
294
294
|
script: pkScript
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
-
var
|
|
297
|
+
var ALLOWED_SIGHASH = [btcSigner.SigHash.DEFAULT, btcSigner.SigHash.ALL, btcSigner.SigHash.ALL_ANYONECANPAY];
|
|
298
298
|
var SingleKey = class _SingleKey {
|
|
299
299
|
key;
|
|
300
300
|
constructor(key) {
|
|
@@ -323,8 +323,9 @@ var SingleKey = class _SingleKey {
|
|
|
323
323
|
async sign(tx, inputIndexes) {
|
|
324
324
|
const txCpy = tx.clone();
|
|
325
325
|
if (!inputIndexes) {
|
|
326
|
+
chunk6AFUNKK7_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
|
|
326
327
|
try {
|
|
327
|
-
if (!txCpy.sign(this.key,
|
|
328
|
+
if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
|
|
328
329
|
throw new Error("Failed to sign transaction");
|
|
329
330
|
}
|
|
330
331
|
} catch (e) {
|
|
@@ -335,7 +336,7 @@ var SingleKey = class _SingleKey {
|
|
|
335
336
|
return txCpy;
|
|
336
337
|
}
|
|
337
338
|
for (const inputIndex of inputIndexes) {
|
|
338
|
-
if (!txCpy.signIdx(this.key, inputIndex,
|
|
339
|
+
if (!txCpy.signIdx(this.key, inputIndex, ALLOWED_SIGHASH)) {
|
|
339
340
|
throw new Error(`Failed to sign input #${inputIndex}`);
|
|
340
341
|
}
|
|
341
342
|
}
|
|
@@ -400,7 +401,7 @@ var ReadonlySingleKey = class _ReadonlySingleKey {
|
|
|
400
401
|
return Promise.resolve(this.publicKey);
|
|
401
402
|
}
|
|
402
403
|
};
|
|
403
|
-
var
|
|
404
|
+
var ALLOWED_SIGHASH2 = [btcSigner.SigHash.DEFAULT, btcSigner.SigHash.ALL, btcSigner.SigHash.ALL_ANYONECANPAY];
|
|
404
405
|
var seedBytes = /* @__PURE__ */ new WeakMap();
|
|
405
406
|
var mnemonicMeta = /* @__PURE__ */ new WeakMap();
|
|
406
407
|
var SeedIdentity = class _SeedIdentity {
|
|
@@ -431,7 +432,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
431
432
|
let network;
|
|
432
433
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
433
434
|
descriptor = opts.descriptor;
|
|
434
|
-
network =
|
|
435
|
+
network = chunkHL7EC2Z5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
435
436
|
} else {
|
|
436
437
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
437
438
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -529,7 +530,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
529
530
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
530
531
|
*/
|
|
531
532
|
isOurs(descriptor) {
|
|
532
|
-
return
|
|
533
|
+
return chunkHL7EC2Z5_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
533
534
|
}
|
|
534
535
|
/**
|
|
535
536
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -578,7 +579,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
578
579
|
}
|
|
579
580
|
// ── internal helpers ─────────────────────────────────────────────
|
|
580
581
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
581
|
-
const network =
|
|
582
|
+
const network = chunkHL7EC2Z5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
582
583
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
583
584
|
if (expansion.isRanged) {
|
|
584
585
|
throw new Error(
|
|
@@ -603,8 +604,9 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
603
604
|
signTxWithKey(tx, key, inputIndexes) {
|
|
604
605
|
const txCpy = tx.clone();
|
|
605
606
|
if (!inputIndexes) {
|
|
607
|
+
chunk6AFUNKK7_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
|
|
606
608
|
try {
|
|
607
|
-
if (!txCpy.sign(key,
|
|
609
|
+
if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
|
|
608
610
|
throw new Error("Failed to sign transaction");
|
|
609
611
|
}
|
|
610
612
|
} catch (e) {
|
|
@@ -614,7 +616,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
614
616
|
}
|
|
615
617
|
} else {
|
|
616
618
|
for (const idx of inputIndexes) {
|
|
617
|
-
if (!txCpy.signIdx(key, idx,
|
|
619
|
+
if (!txCpy.signIdx(key, idx, ALLOWED_SIGHASH2)) {
|
|
618
620
|
throw new Error(`Failed to sign input #${idx}`);
|
|
619
621
|
}
|
|
620
622
|
}
|
|
@@ -664,7 +666,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
664
666
|
*/
|
|
665
667
|
descriptor;
|
|
666
668
|
constructor(descriptor) {
|
|
667
|
-
const network =
|
|
669
|
+
const network = chunkHL7EC2Z5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
668
670
|
let expansion;
|
|
669
671
|
try {
|
|
670
672
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -714,7 +716,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
714
716
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
715
717
|
*/
|
|
716
718
|
isOurs(descriptor) {
|
|
717
|
-
return
|
|
719
|
+
return chunkHL7EC2Z5_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
718
720
|
}
|
|
719
721
|
};
|
|
720
722
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -876,10 +878,10 @@ var DescriptorIdentity = class {
|
|
|
876
878
|
this.base = base;
|
|
877
879
|
}
|
|
878
880
|
async xOnlyPublicKey() {
|
|
879
|
-
return
|
|
881
|
+
return chunkHL7EC2Z5_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
880
882
|
}
|
|
881
883
|
async compressedPublicKey() {
|
|
882
|
-
return
|
|
884
|
+
return chunkHL7EC2Z5_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
|
|
883
885
|
}
|
|
884
886
|
async sign(tx, inputIndexes) {
|
|
885
887
|
const [signed] = await this.signer.signWithDescriptor([
|
|
@@ -947,12 +949,12 @@ var WalletCannotAllocateAddressError = class extends Error {
|
|
|
947
949
|
};
|
|
948
950
|
async function resolveDescriptorSigner(descriptor, identity, provider) {
|
|
949
951
|
const owner = provider?.isOurs(descriptor) ? provider : isHDCapableIdentity(identity) && identity.isOurs(descriptor) ? identity : void 0;
|
|
950
|
-
if (owner &&
|
|
952
|
+
if (owner && chunkHL7EC2Z5_cjs.parseHDDescriptor(descriptor)) {
|
|
951
953
|
return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
|
|
952
954
|
}
|
|
953
955
|
let key;
|
|
954
956
|
try {
|
|
955
|
-
key =
|
|
957
|
+
key = chunkHL7EC2Z5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
956
958
|
} catch {
|
|
957
959
|
throw new ForeignDescriptorError(descriptor);
|
|
958
960
|
}
|
|
@@ -1327,14 +1329,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
|
|
|
1327
1329
|
}
|
|
1328
1330
|
var PREIMAGE_INDEX = 0;
|
|
1329
1331
|
function isPerArtifactDescriptor(descriptor) {
|
|
1330
|
-
return
|
|
1332
|
+
return chunkHL7EC2Z5_cjs.parseHDDescriptor(descriptor) !== null;
|
|
1331
1333
|
}
|
|
1332
1334
|
async function provisionDescriptor(wallet) {
|
|
1333
1335
|
const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
|
|
1334
|
-
return allocated ?? await
|
|
1336
|
+
return allocated ?? await chunkHL7EC2Z5_cjs.identityDescriptor(wallet.identity);
|
|
1335
1337
|
}
|
|
1336
1338
|
async function provisionRefundKey(wallet) {
|
|
1337
|
-
const descriptor = await
|
|
1339
|
+
const descriptor = await chunkHL7EC2Z5_cjs.identityDescriptor(wallet.identity);
|
|
1338
1340
|
const signer = await contractSigner(wallet, descriptor);
|
|
1339
1341
|
const pubkey = await signer.xOnlyPublicKey();
|
|
1340
1342
|
const identityPubkey = await wallet.identity.xOnlyPublicKey();
|
|
@@ -1344,7 +1346,7 @@ async function provisionRefundKey(wallet) {
|
|
|
1344
1346
|
);
|
|
1345
1347
|
}
|
|
1346
1348
|
const address = await wallet.getAddress();
|
|
1347
|
-
const { pkScript } =
|
|
1349
|
+
const { pkScript } = chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
1348
1350
|
return { descriptor, pubkey, pkScript, address };
|
|
1349
1351
|
}
|
|
1350
1352
|
async function provisionClaimSecret(wallet, opts = {}) {
|
|
@@ -1390,7 +1392,7 @@ async function contractSigner(wallet, descriptor) {
|
|
|
1390
1392
|
const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
|
|
1391
1393
|
let expected;
|
|
1392
1394
|
try {
|
|
1393
|
-
expected =
|
|
1395
|
+
expected = chunkHL7EC2Z5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1394
1396
|
} catch (cause) {
|
|
1395
1397
|
throw new ForeignDescriptorError(descriptor, { cause });
|
|
1396
1398
|
}
|
|
@@ -1609,14 +1611,14 @@ var RestDelegateProvider = class {
|
|
|
1609
1611
|
*/
|
|
1610
1612
|
async delegate(intent, forfeitTxs, options) {
|
|
1611
1613
|
const url = `${this.url}/v1/delegate`;
|
|
1612
|
-
const response = await
|
|
1614
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(url, {
|
|
1613
1615
|
method: "POST",
|
|
1614
1616
|
headers: {
|
|
1615
1617
|
"Content-Type": "application/json"
|
|
1616
1618
|
},
|
|
1617
1619
|
body: JSON.stringify({
|
|
1618
1620
|
intent: {
|
|
1619
|
-
message:
|
|
1621
|
+
message: chunk6AFUNKK7_cjs.Intent.encodeMessage(intent.message),
|
|
1620
1622
|
proof: intent.proof
|
|
1621
1623
|
},
|
|
1622
1624
|
forfeit_txs: forfeitTxs,
|
|
@@ -1636,7 +1638,7 @@ var RestDelegateProvider = class {
|
|
|
1636
1638
|
*/
|
|
1637
1639
|
async getDelegateInfo() {
|
|
1638
1640
|
const url = `${this.url}/v1/delegator/info`;
|
|
1639
|
-
const response = await
|
|
1641
|
+
const response = await chunk6AFUNKK7_cjs.rateGate.runHttp(url, () => chunk6AFUNKK7_cjs.baseFetch(url));
|
|
1640
1642
|
if (!response.ok) {
|
|
1641
1643
|
const errorText2 = await response.text();
|
|
1642
1644
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1661,7 +1663,7 @@ var ESPLORA_URL = {
|
|
|
1661
1663
|
regtest: "http://localhost:3000/api"
|
|
1662
1664
|
};
|
|
1663
1665
|
var EsploraProvider = class {
|
|
1664
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1666
|
+
constructor(baseUrl = ESPLORA_URL[chunk6AFUNKK7_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1665
1667
|
this.baseUrl = baseUrl;
|
|
1666
1668
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1667
1669
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1670,14 +1672,14 @@ var EsploraProvider = class {
|
|
|
1670
1672
|
pollingInterval;
|
|
1671
1673
|
forcePolling;
|
|
1672
1674
|
async getCoins(address) {
|
|
1673
|
-
const response = await
|
|
1675
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1674
1676
|
if (!response.ok) {
|
|
1675
1677
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1676
1678
|
}
|
|
1677
1679
|
return response.json();
|
|
1678
1680
|
}
|
|
1679
1681
|
async getFeeRate() {
|
|
1680
|
-
const response = await
|
|
1682
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1681
1683
|
if (response.status === 404) {
|
|
1682
1684
|
return void 0;
|
|
1683
1685
|
}
|
|
@@ -1698,7 +1700,7 @@ var EsploraProvider = class {
|
|
|
1698
1700
|
}
|
|
1699
1701
|
}
|
|
1700
1702
|
async getTxOutspends(txid) {
|
|
1701
|
-
const response = await
|
|
1703
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1702
1704
|
if (!response.ok) {
|
|
1703
1705
|
const error = await response.text();
|
|
1704
1706
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1706,7 +1708,7 @@ var EsploraProvider = class {
|
|
|
1706
1708
|
return response.json();
|
|
1707
1709
|
}
|
|
1708
1710
|
async getTransactions(address) {
|
|
1709
|
-
const response = await
|
|
1711
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1710
1712
|
if (!response.ok) {
|
|
1711
1713
|
const error = await response.text();
|
|
1712
1714
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1714,7 +1716,7 @@ var EsploraProvider = class {
|
|
|
1714
1716
|
return response.json();
|
|
1715
1717
|
}
|
|
1716
1718
|
async getRawTransaction(txid) {
|
|
1717
|
-
const response = await
|
|
1719
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
1718
1720
|
if (!response.ok) {
|
|
1719
1721
|
const error = await response.text();
|
|
1720
1722
|
throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
|
|
@@ -1722,7 +1724,7 @@ var EsploraProvider = class {
|
|
|
1722
1724
|
return base.hex.decode((await response.text()).trim());
|
|
1723
1725
|
}
|
|
1724
1726
|
async getTxStatus(txid) {
|
|
1725
|
-
const txresponse = await
|
|
1727
|
+
const txresponse = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1726
1728
|
if (!txresponse.ok) {
|
|
1727
1729
|
throw new Error(txresponse.statusText);
|
|
1728
1730
|
}
|
|
@@ -1730,7 +1732,7 @@ var EsploraProvider = class {
|
|
|
1730
1732
|
if (!tx.status.confirmed) {
|
|
1731
1733
|
return { confirmed: false };
|
|
1732
1734
|
}
|
|
1733
|
-
const response = await
|
|
1735
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1734
1736
|
if (!response.ok) {
|
|
1735
1737
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1736
1738
|
}
|
|
@@ -1814,7 +1816,7 @@ var EsploraProvider = class {
|
|
|
1814
1816
|
return stopFunc;
|
|
1815
1817
|
}
|
|
1816
1818
|
async getChainTip() {
|
|
1817
|
-
const tipBlocks = await
|
|
1819
|
+
const tipBlocks = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
1818
1820
|
if (!tipBlocks.ok) {
|
|
1819
1821
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
1820
1822
|
}
|
|
@@ -1833,7 +1835,7 @@ var EsploraProvider = class {
|
|
|
1833
1835
|
};
|
|
1834
1836
|
}
|
|
1835
1837
|
async broadcastPackage(parent, child) {
|
|
1836
|
-
const response = await
|
|
1838
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
1837
1839
|
method: "POST",
|
|
1838
1840
|
headers: {
|
|
1839
1841
|
"Content-Type": "application/json"
|
|
@@ -1849,7 +1851,7 @@ var EsploraProvider = class {
|
|
|
1849
1851
|
return result;
|
|
1850
1852
|
}
|
|
1851
1853
|
async broadcastTx(tx) {
|
|
1852
|
-
const response = await
|
|
1854
|
+
const response = await chunk6AFUNKK7_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
1853
1855
|
method: "POST",
|
|
1854
1856
|
headers: {
|
|
1855
1857
|
"Content-Type": "text/plain"
|
|
@@ -2029,7 +2031,7 @@ function findP2AOutput(tx) {
|
|
|
2029
2031
|
var CHILD_DUST_AMOUNT = 546;
|
|
2030
2032
|
function buildAnchorChild(params) {
|
|
2031
2033
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2032
|
-
const child = new
|
|
2034
|
+
const child = new chunk6AFUNKK7_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2033
2035
|
child.addInput(findP2AOutput(parent));
|
|
2034
2036
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
2035
2037
|
for (const _ of fundingCoins) {
|
|
@@ -2077,7 +2079,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
2077
2079
|
);
|
|
2078
2080
|
}
|
|
2079
2081
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
2080
|
-
const tx = new
|
|
2082
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({
|
|
2081
2083
|
version: 3,
|
|
2082
2084
|
lockTime: txLocktime
|
|
2083
2085
|
});
|
|
@@ -2153,7 +2155,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
2153
2155
|
if (previousScriptKey.length !== 32) {
|
|
2154
2156
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
2155
2157
|
}
|
|
2156
|
-
const cosigners =
|
|
2158
|
+
const cosigners = chunk6AFUNKK7_cjs.getArkPsbtFields(child.root, 0, chunk6AFUNKK7_cjs.CosignerPublicKey);
|
|
2157
2159
|
if (cosigners.length === 0) {
|
|
2158
2160
|
throw ErrMissingCosignersPublicKeys;
|
|
2159
2161
|
}
|
|
@@ -2211,7 +2213,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2211
2213
|
return new _EmulatorPacket(entries);
|
|
2212
2214
|
}
|
|
2213
2215
|
static fromBytes(data) {
|
|
2214
|
-
const reader = new
|
|
2216
|
+
const reader = new chunkCZ32XADN_cjs.BufferReader(data);
|
|
2215
2217
|
const entryCount = reader.readCompactSize();
|
|
2216
2218
|
const entries = [];
|
|
2217
2219
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -2229,7 +2231,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2229
2231
|
return _EmulatorPacket.PACKET_TYPE;
|
|
2230
2232
|
}
|
|
2231
2233
|
serialize() {
|
|
2232
|
-
const writer = new
|
|
2234
|
+
const writer = new chunkCZ32XADN_cjs.BufferWriter();
|
|
2233
2235
|
writer.writeCompactSize(this.entries.length);
|
|
2234
2236
|
for (const entry of this.entries) {
|
|
2235
2237
|
writer.writeUint16LE(entry.vin);
|
|
@@ -2316,7 +2318,7 @@ var Extension = class _Extension {
|
|
|
2316
2318
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
2317
2319
|
);
|
|
2318
2320
|
}
|
|
2319
|
-
const reader = new
|
|
2321
|
+
const reader = new chunkCZ32XADN_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
2320
2322
|
const packets = [];
|
|
2321
2323
|
while (reader.remaining() > 0) {
|
|
2322
2324
|
const packetType = reader.readByte();
|
|
@@ -2390,7 +2392,7 @@ var Extension = class _Extension {
|
|
|
2390
2392
|
*/
|
|
2391
2393
|
getAssetPacket() {
|
|
2392
2394
|
for (const p of this.packets) {
|
|
2393
|
-
if (p instanceof
|
|
2395
|
+
if (p instanceof chunkCZ32XADN_cjs.Packet) {
|
|
2394
2396
|
return p;
|
|
2395
2397
|
}
|
|
2396
2398
|
}
|
|
@@ -2428,8 +2430,8 @@ var Extension = class _Extension {
|
|
|
2428
2430
|
};
|
|
2429
2431
|
function parsePacket(packetType, data) {
|
|
2430
2432
|
switch (packetType) {
|
|
2431
|
-
case
|
|
2432
|
-
return
|
|
2433
|
+
case chunkCZ32XADN_cjs.Packet.PACKET_TYPE:
|
|
2434
|
+
return chunkCZ32XADN_cjs.Packet.fromBytes(data);
|
|
2433
2435
|
case EmulatorPacket.PACKET_TYPE:
|
|
2434
2436
|
return EmulatorPacket.fromBytes(data);
|
|
2435
2437
|
default:
|
|
@@ -2476,16 +2478,16 @@ function buildOpReturnScript(data) {
|
|
|
2476
2478
|
}
|
|
2477
2479
|
return script;
|
|
2478
2480
|
}
|
|
2479
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
2480
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
2481
|
+
var ErrOffchainOutputNotFound = (address) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2482
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2481
2483
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
2482
2484
|
);
|
|
2483
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
2484
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
2485
|
+
var ErrAssetGroupNotFound = (assetId) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2486
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2485
2487
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
2486
2488
|
);
|
|
2487
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
2488
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
2489
|
+
var ErrOnchainOutputNotFound = (address) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2490
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2489
2491
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
2490
2492
|
);
|
|
2491
2493
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
@@ -2494,7 +2496,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
2494
2496
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
2495
2497
|
if (!validatedCommitmentTxid) return;
|
|
2496
2498
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
2497
|
-
throw new
|
|
2499
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2498
2500
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
2499
2501
|
);
|
|
2500
2502
|
}
|
|
@@ -2504,7 +2506,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
2504
2506
|
for (const recipient of recipients) {
|
|
2505
2507
|
let arkAddress;
|
|
2506
2508
|
try {
|
|
2507
|
-
arkAddress =
|
|
2509
|
+
arkAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(recipient.address);
|
|
2508
2510
|
} catch {
|
|
2509
2511
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2510
2512
|
continue;
|
|
@@ -2516,7 +2518,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2516
2518
|
const usedOnchainOutputs = /* @__PURE__ */ new Set();
|
|
2517
2519
|
for (const recipient of recipients) {
|
|
2518
2520
|
try {
|
|
2519
|
-
|
|
2521
|
+
chunk6AFUNKK7_cjs.ArkAddress.decode(recipient.address);
|
|
2520
2522
|
} catch {
|
|
2521
2523
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2522
2524
|
continue;
|
|
@@ -2749,7 +2751,7 @@ function assetMintResolver() {
|
|
|
2749
2751
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
2750
2752
|
const minted = tx.assets.filter((a) => {
|
|
2751
2753
|
try {
|
|
2752
|
-
return base.hex.encode(
|
|
2754
|
+
return base.hex.encode(chunkCZ32XADN_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
2753
2755
|
} catch {
|
|
2754
2756
|
return false;
|
|
2755
2757
|
}
|
|
@@ -2792,7 +2794,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2792
2794
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
2793
2795
|
inputsByAssetId.set(asset.assetId, [
|
|
2794
2796
|
...existing ?? [],
|
|
2795
|
-
|
|
2797
|
+
chunkCZ32XADN_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
2796
2798
|
]);
|
|
2797
2799
|
}
|
|
2798
2800
|
}
|
|
@@ -2804,7 +2806,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2804
2806
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2805
2807
|
outputsByAssetId.set(asset.assetId, [
|
|
2806
2808
|
...existing ?? [],
|
|
2807
|
-
|
|
2809
|
+
chunkCZ32XADN_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2808
2810
|
]);
|
|
2809
2811
|
}
|
|
2810
2812
|
}
|
|
@@ -2815,7 +2817,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2815
2817
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2816
2818
|
outputsByAssetId.set(asset.assetId, [
|
|
2817
2819
|
...existing ?? [],
|
|
2818
|
-
|
|
2820
|
+
chunkCZ32XADN_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2819
2821
|
]);
|
|
2820
2822
|
}
|
|
2821
2823
|
}
|
|
@@ -2824,11 +2826,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2824
2826
|
for (const assetIdStr of allAssetIds) {
|
|
2825
2827
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2826
2828
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2827
|
-
const assetId =
|
|
2828
|
-
const group =
|
|
2829
|
+
const assetId = chunkCZ32XADN_cjs.AssetId.fromString(assetIdStr);
|
|
2830
|
+
const group = chunkCZ32XADN_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2829
2831
|
groups.push(group);
|
|
2830
2832
|
}
|
|
2831
|
-
return
|
|
2833
|
+
return chunkCZ32XADN_cjs.Packet.create(groups);
|
|
2832
2834
|
}
|
|
2833
2835
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2834
2836
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2865,7 +2867,7 @@ function selectedCoinsToAssetInputs(selectedCoins) {
|
|
|
2865
2867
|
}
|
|
2866
2868
|
function toXOnlySignerHex(pubkeyHex) {
|
|
2867
2869
|
const bytes = base.hex.decode(pubkeyHex);
|
|
2868
|
-
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(
|
|
2870
|
+
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunkHL7EC2Z5_cjs.toXOnly(bytes, "signer key"));
|
|
2869
2871
|
throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes.length}`);
|
|
2870
2872
|
}
|
|
2871
2873
|
function signerSetFromInfo(info) {
|
|
@@ -2912,13 +2914,13 @@ var toTimelock = (value) => ({
|
|
|
2912
2914
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
2913
2915
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
2914
2916
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
2915
|
-
throw new
|
|
2917
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2916
2918
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
2917
2919
|
);
|
|
2918
2920
|
}
|
|
2919
2921
|
const seconds = toSeconds(timelock);
|
|
2920
2922
|
if (seconds < policy.minSeconds) {
|
|
2921
|
-
throw new
|
|
2923
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2922
2924
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it`
|
|
2923
2925
|
);
|
|
2924
2926
|
}
|
|
@@ -2939,7 +2941,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
2939
2941
|
}
|
|
2940
2942
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
2941
2943
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
2942
|
-
throw new
|
|
2944
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2943
2945
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
2944
2946
|
);
|
|
2945
2947
|
}
|
|
@@ -2969,21 +2971,21 @@ function resolveCheckpointExitDelayPolicy(network, overrides) {
|
|
|
2969
2971
|
function assertValidServerUnrollScript(checkpointTapscript, policy) {
|
|
2970
2972
|
let script;
|
|
2971
2973
|
try {
|
|
2972
|
-
script =
|
|
2974
|
+
script = chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
2973
2975
|
} catch (e) {
|
|
2974
|
-
throw new
|
|
2976
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2975
2977
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
2976
2978
|
);
|
|
2977
2979
|
}
|
|
2978
2980
|
if (policy.advertisedForfeitPubkey !== void 0) {
|
|
2979
2981
|
const { pubkeys } = script.params;
|
|
2980
2982
|
if (pubkeys.length !== 1) {
|
|
2981
|
-
throw new
|
|
2983
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2982
2984
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
2983
2985
|
);
|
|
2984
2986
|
}
|
|
2985
2987
|
if (!utils_js.equalBytes(pubkeys[0], policy.advertisedForfeitPubkey)) {
|
|
2986
|
-
throw new
|
|
2988
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
2987
2989
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(policy.advertisedForfeitPubkey)}`
|
|
2988
2990
|
);
|
|
2989
2991
|
}
|
|
@@ -3027,8 +3029,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
3027
3029
|
function buildVirtualTx(inputs, outputs) {
|
|
3028
3030
|
let lockTime = 0n;
|
|
3029
3031
|
for (const input of inputs) {
|
|
3030
|
-
const tapscript =
|
|
3031
|
-
if (
|
|
3032
|
+
const tapscript = chunk6AFUNKK7_cjs.decodeTapscript(chunk6AFUNKK7_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3033
|
+
if (chunk6AFUNKK7_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
3032
3034
|
if (lockTime !== 0n) {
|
|
3033
3035
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
3034
3036
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -3039,7 +3041,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3039
3041
|
}
|
|
3040
3042
|
}
|
|
3041
3043
|
}
|
|
3042
|
-
const tx = new
|
|
3044
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({
|
|
3043
3045
|
version: 3,
|
|
3044
3046
|
lockTime: Number(lockTime)
|
|
3045
3047
|
});
|
|
@@ -3049,12 +3051,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3049
3051
|
index: input.vout,
|
|
3050
3052
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
3051
3053
|
witnessUtxo: {
|
|
3052
|
-
script:
|
|
3054
|
+
script: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3053
3055
|
amount: BigInt(input.value)
|
|
3054
3056
|
},
|
|
3055
3057
|
tapLeafScript: [input.tapLeafScript]
|
|
3056
3058
|
});
|
|
3057
|
-
|
|
3059
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(tx, i, chunk6AFUNKK7_cjs.VtxoTaprootTree, input.tapTree);
|
|
3058
3060
|
}
|
|
3059
3061
|
for (const output of outputs) {
|
|
3060
3062
|
tx.addOutput(output);
|
|
@@ -3063,8 +3065,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3063
3065
|
return tx;
|
|
3064
3066
|
}
|
|
3065
3067
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
3066
|
-
const collaborativeClosure =
|
|
3067
|
-
const checkpointVtxoScript = new
|
|
3068
|
+
const collaborativeClosure = chunk6AFUNKK7_cjs.decodeTapscript(chunk6AFUNKK7_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3069
|
+
const checkpointVtxoScript = new chunk6AFUNKK7_cjs.VtxoScript([
|
|
3068
3070
|
serverUnrollScript.script,
|
|
3069
3071
|
collaborativeClosure.script
|
|
3070
3072
|
]);
|
|
@@ -3107,9 +3109,6 @@ function hasBoardingTxExpired(coin, boardingTimelock, chainTipHeight) {
|
|
|
3107
3109
|
const blockTime = BigInt(Math.floor(coin.status.block_time));
|
|
3108
3110
|
return blockTime + boardingTimelock.value <= now;
|
|
3109
3111
|
}
|
|
3110
|
-
function formatSighash(type) {
|
|
3111
|
-
return `0x${type.toString(16).padStart(2, "0")}`;
|
|
3112
|
-
}
|
|
3113
3112
|
function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [btcSigner.SigHash.DEFAULT], expectedLeafHash) {
|
|
3114
3113
|
const input = tx.getInput(inputIndex);
|
|
3115
3114
|
const prevoutScripts = [];
|
|
@@ -3143,7 +3142,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
3143
3142
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
3144
3143
|
const sig = signature.subarray(0, 64);
|
|
3145
3144
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
3146
|
-
const sighashName = formatSighash(sighashType);
|
|
3145
|
+
const sighashName = chunk6AFUNKK7_cjs.formatSighash(sighashType);
|
|
3147
3146
|
throw new Error(
|
|
3148
3147
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
3149
3148
|
);
|
|
@@ -3217,7 +3216,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
3217
3216
|
}
|
|
3218
3217
|
function isValidArkAddress(address) {
|
|
3219
3218
|
try {
|
|
3220
|
-
|
|
3219
|
+
chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
3221
3220
|
return true;
|
|
3222
3221
|
} catch (e) {
|
|
3223
3222
|
return false;
|
|
@@ -3225,16 +3224,16 @@ function isValidArkAddress(address) {
|
|
|
3225
3224
|
}
|
|
3226
3225
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
3227
3226
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
3228
|
-
throw new
|
|
3227
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3229
3228
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
3230
3229
|
);
|
|
3231
3230
|
}
|
|
3232
3231
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
3233
3232
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
3234
|
-
const server =
|
|
3233
|
+
const server = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
3235
3234
|
const local = byTxid.get(server.id);
|
|
3236
3235
|
if (!local) {
|
|
3237
|
-
throw new
|
|
3236
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3238
3237
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
3239
3238
|
);
|
|
3240
3239
|
}
|
|
@@ -3244,14 +3243,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
3244
3243
|
}
|
|
3245
3244
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
3246
3245
|
if (response.arkTxid !== signedArkTx.id) {
|
|
3247
|
-
throw new
|
|
3246
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3248
3247
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
3249
3248
|
);
|
|
3250
3249
|
}
|
|
3251
3250
|
if (response.finalArkTx === void 0) return;
|
|
3252
|
-
const finalTxid =
|
|
3251
|
+
const finalTxid = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3253
3252
|
if (finalTxid !== signedArkTx.id) {
|
|
3254
|
-
throw new
|
|
3253
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3255
3254
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
3256
3255
|
);
|
|
3257
3256
|
}
|
|
@@ -3270,10 +3269,10 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeyHex,
|
|
|
3270
3269
|
[serverPubkeyHex],
|
|
3271
3270
|
void 0,
|
|
3272
3271
|
void 0,
|
|
3273
|
-
payment_js.tapLeafHash(
|
|
3272
|
+
payment_js.tapLeafHash(chunk6AFUNKK7_cjs.scriptFromTapLeafScript(leaf))
|
|
3274
3273
|
);
|
|
3275
3274
|
} catch (error) {
|
|
3276
|
-
throw new
|
|
3275
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3277
3276
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
3278
3277
|
);
|
|
3279
3278
|
}
|
|
@@ -3282,20 +3281,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3282
3281
|
const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
|
|
3283
3282
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
3284
3283
|
if (checkpoint.inputsLength !== 1) {
|
|
3285
|
-
throw new
|
|
3284
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3286
3285
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
3287
3286
|
);
|
|
3288
3287
|
}
|
|
3289
3288
|
const spent = checkpoint.getInput(0);
|
|
3290
3289
|
if (!spent.txid || spent.index === void 0) {
|
|
3291
|
-
throw new
|
|
3290
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3292
3291
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
3293
3292
|
);
|
|
3294
3293
|
}
|
|
3295
3294
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
3296
3295
|
const input = byOutpoint.get(outpoint);
|
|
3297
3296
|
if (!input) {
|
|
3298
|
-
throw new
|
|
3297
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3299
3298
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
3300
3299
|
);
|
|
3301
3300
|
}
|
|
@@ -3303,7 +3302,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3303
3302
|
(unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
|
|
3304
3303
|
);
|
|
3305
3304
|
if (!rebuilt) {
|
|
3306
|
-
throw new
|
|
3305
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3307
3306
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
3308
3307
|
);
|
|
3309
3308
|
}
|
|
@@ -3327,15 +3326,24 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3327
3326
|
assertSubmittedArkTxid(response, signedArkTx, "submitTx");
|
|
3328
3327
|
const { arkTxid, signedCheckpointTxs } = response;
|
|
3329
3328
|
const matched = matchServerCheckpoints(signedCheckpointTxs, offchainTx.checkpoints, "submitTx");
|
|
3329
|
+
matched.forEach(({ server }, index) => {
|
|
3330
|
+
try {
|
|
3331
|
+
chunk6AFUNKK7_cjs.assertAllowedSighashTypes(server);
|
|
3332
|
+
} catch (error) {
|
|
3333
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3334
|
+
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
3335
|
+
);
|
|
3336
|
+
}
|
|
3337
|
+
});
|
|
3330
3338
|
const verify = options?.verifyServerSignatures;
|
|
3331
3339
|
if (verify) {
|
|
3332
3340
|
if (response.finalArkTx === void 0) {
|
|
3333
|
-
throw new
|
|
3341
|
+
throw new chunk6AFUNKK7_cjs.ServerResponseMismatchError(
|
|
3334
3342
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
3335
3343
|
);
|
|
3336
3344
|
}
|
|
3337
|
-
const finalArkTx =
|
|
3338
|
-
const serverPubkeyHex = base.hex.encode(
|
|
3345
|
+
const finalArkTx = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
3346
|
+
const serverPubkeyHex = base.hex.encode(chunkHL7EC2Z5_cjs.toXOnly(verify.serverPubkey, "server key"));
|
|
3339
3347
|
for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
|
|
3340
3348
|
assertServerSignedLeaf(
|
|
3341
3349
|
finalArkTx,
|
|
@@ -3391,12 +3399,12 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
3391
3399
|
return {
|
|
3392
3400
|
...identity,
|
|
3393
3401
|
sign: async (tx, inputIndexes) => {
|
|
3394
|
-
const signed =
|
|
3402
|
+
const signed = chunk6AFUNKK7_cjs.Transaction.fromPSBT(
|
|
3395
3403
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
3396
3404
|
);
|
|
3397
3405
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
3398
3406
|
for (const index of indexes) {
|
|
3399
|
-
|
|
3407
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(signed, index, chunk6AFUNKK7_cjs.ConditionWitness, [preimage]);
|
|
3400
3408
|
}
|
|
3401
3409
|
return signed;
|
|
3402
3410
|
}
|
|
@@ -3588,7 +3596,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3588
3596
|
};
|
|
3589
3597
|
}
|
|
3590
3598
|
function deriveContractTapscripts(contract) {
|
|
3591
|
-
const handler =
|
|
3599
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
3592
3600
|
if (!handler) {
|
|
3593
3601
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3594
3602
|
}
|
|
@@ -3659,13 +3667,13 @@ function getRandomId() {
|
|
|
3659
3667
|
}
|
|
3660
3668
|
function isValidArkAddress2(address) {
|
|
3661
3669
|
try {
|
|
3662
|
-
|
|
3670
|
+
chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
3663
3671
|
return true;
|
|
3664
3672
|
} catch (e) {
|
|
3665
3673
|
return false;
|
|
3666
3674
|
}
|
|
3667
3675
|
}
|
|
3668
|
-
function
|
|
3676
|
+
function assertRecipientArkadeAddress(encoded, address, context) {
|
|
3669
3677
|
if (address.hrp !== context.hrp) {
|
|
3670
3678
|
throw new Error(
|
|
3671
3679
|
`Invalid Arkade address ${encoded}: expected prefix "${context.hrp}", got "${address.hrp}"`
|
|
@@ -3687,7 +3695,7 @@ function assertRecipientArkAddress(encoded, address, context) {
|
|
|
3687
3695
|
function assertTapTreeDerivesAddress(encoded, tapTree, address) {
|
|
3688
3696
|
let derived;
|
|
3689
3697
|
try {
|
|
3690
|
-
derived =
|
|
3698
|
+
derived = chunk6AFUNKK7_cjs.VtxoScript.decode(tapTree).pkScript;
|
|
3691
3699
|
} catch (e) {
|
|
3692
3700
|
throw new Error(
|
|
3693
3701
|
`Invalid tapTree for ${encoded}: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -3704,11 +3712,11 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
3704
3712
|
for (const recipient of recipients) {
|
|
3705
3713
|
let address;
|
|
3706
3714
|
try {
|
|
3707
|
-
address =
|
|
3715
|
+
address = chunk6AFUNKK7_cjs.ArkAddress.decode(recipient.address);
|
|
3708
3716
|
} catch (e) {
|
|
3709
3717
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
3710
3718
|
}
|
|
3711
|
-
|
|
3719
|
+
assertRecipientArkadeAddress(recipient.address, address, context);
|
|
3712
3720
|
const amount = recipient.amount || dustAmount;
|
|
3713
3721
|
if (amount <= 0) {
|
|
3714
3722
|
throw new Error("Amount must be positive");
|
|
@@ -3729,7 +3737,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
3729
3737
|
|
|
3730
3738
|
// src/contracts/spendability.ts
|
|
3731
3739
|
function isContractGenericallySpendable(contract) {
|
|
3732
|
-
return
|
|
3740
|
+
return chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
3733
3741
|
}
|
|
3734
3742
|
function gatedContracts(contracts) {
|
|
3735
3743
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -3742,7 +3750,7 @@ function gateExclusion(gated) {
|
|
|
3742
3750
|
return (vtxo) => {
|
|
3743
3751
|
const type = vtxo.script === void 0 ? void 0 : gated.get(vtxo.script);
|
|
3744
3752
|
if (type === void 0) return void 0;
|
|
3745
|
-
if (!
|
|
3753
|
+
if (!chunkHL7EC2Z5_cjs.contractHandlers.has(type)) {
|
|
3746
3754
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
3747
3755
|
}
|
|
3748
3756
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -3778,7 +3786,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
3778
3786
|
continue;
|
|
3779
3787
|
}
|
|
3780
3788
|
for (const v of vtxos) {
|
|
3781
|
-
if (!
|
|
3789
|
+
if (!chunk6AFUNKK7_cjs.hasTerminalSpend(v) && !v.isSwept && !v.isUnrolled) {
|
|
3782
3790
|
out.add(`${v.txid}:${v.vout}`);
|
|
3783
3791
|
}
|
|
3784
3792
|
}
|
|
@@ -3813,10 +3821,10 @@ function byValueDescending(vtxos) {
|
|
|
3813
3821
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
3814
3822
|
}
|
|
3815
3823
|
async function fetchTimeHeight(wallet) {
|
|
3816
|
-
return
|
|
3824
|
+
return chunk6AFUNKK7_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
3817
3825
|
}
|
|
3818
3826
|
function canMigrateBySend(vtxo, now) {
|
|
3819
|
-
if (!
|
|
3827
|
+
if (!chunk6AFUNKK7_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
3820
3828
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
3821
3829
|
}
|
|
3822
3830
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -3824,7 +3832,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
3824
3832
|
if (vtxo.isSwept) return -Infinity;
|
|
3825
3833
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
3826
3834
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
3827
|
-
return
|
|
3835
|
+
return chunk6AFUNKK7_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
3828
3836
|
}
|
|
3829
3837
|
return Infinity;
|
|
3830
3838
|
};
|
|
@@ -3851,7 +3859,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
3851
3859
|
const payable = [];
|
|
3852
3860
|
const net = /* @__PURE__ */ new Map();
|
|
3853
3861
|
for (const vtxo of vtxos) {
|
|
3854
|
-
const inputFee = estimator.evalOffchainInput(
|
|
3862
|
+
const inputFee = estimator.evalOffchainInput(chunk6AFUNKK7_cjs.toOffchainInputFeeParams(vtxo));
|
|
3855
3863
|
if (inputFee.satoshis >= vtxo.value) {
|
|
3856
3864
|
continue;
|
|
3857
3865
|
}
|
|
@@ -3877,7 +3885,7 @@ function deductOffchainOutputFee(subtotal, estimator, arkAddress) {
|
|
|
3877
3885
|
}
|
|
3878
3886
|
const outputFee = estimator.evalOffchainOutput({
|
|
3879
3887
|
amount: subtotal,
|
|
3880
|
-
script: base.hex.encode(
|
|
3888
|
+
script: base.hex.encode(chunk6AFUNKK7_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
3881
3889
|
});
|
|
3882
3890
|
return subtotal - BigInt(outputFee.satoshis);
|
|
3883
3891
|
}
|
|
@@ -3895,10 +3903,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
3895
3903
|
};
|
|
3896
3904
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
3897
3905
|
return vtxos.filter((vtxo) => {
|
|
3898
|
-
if (
|
|
3906
|
+
if (chunk6AFUNKK7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
3899
3907
|
return true;
|
|
3900
3908
|
}
|
|
3901
|
-
if (
|
|
3909
|
+
if (chunk6AFUNKK7_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
3902
3910
|
return true;
|
|
3903
3911
|
}
|
|
3904
3912
|
return false;
|
|
@@ -3928,8 +3936,9 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
3928
3936
|
};
|
|
3929
3937
|
}
|
|
3930
3938
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
3939
|
+
if (vtxo.isUnrolled) return false;
|
|
3931
3940
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
3932
|
-
const expiresAt =
|
|
3941
|
+
const expiresAt = chunk6AFUNKK7_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
3933
3942
|
if (expiresAt === void 0) return false;
|
|
3934
3943
|
const now = Date.now();
|
|
3935
3944
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -3938,7 +3947,9 @@ function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
|
3938
3947
|
}
|
|
3939
3948
|
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
3940
3949
|
return vtxos.filter(
|
|
3941
|
-
|
|
3950
|
+
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
3951
|
+
// property and would otherwise re-admit an exited coin on its own.
|
|
3952
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunk6AFUNKK7_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
3942
3953
|
);
|
|
3943
3954
|
}
|
|
3944
3955
|
function isMigrationCapable(wallet) {
|
|
@@ -4537,11 +4548,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4537
4548
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
4538
4549
|
);
|
|
4539
4550
|
}
|
|
4540
|
-
const tx = new
|
|
4551
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction();
|
|
4541
4552
|
for (const utxo of expiredUtxos) {
|
|
4542
|
-
const utxoScript =
|
|
4553
|
+
const utxoScript = chunk6AFUNKK7_cjs.VtxoScript.decode(utxo.tapTree);
|
|
4543
4554
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
4544
|
-
(leaf) =>
|
|
4555
|
+
(leaf) => chunk6AFUNKK7_cjs.CSVMultisigTapscript.isScriptValid(chunk6AFUNKK7_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
4545
4556
|
);
|
|
4546
4557
|
if (!utxoExitLeaf) {
|
|
4547
4558
|
throw new Error(
|
|
@@ -4556,7 +4567,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4556
4567
|
amount: BigInt(utxo.value)
|
|
4557
4568
|
},
|
|
4558
4569
|
tapLeafScript: [utxoExitLeaf],
|
|
4559
|
-
sequence:
|
|
4570
|
+
sequence: chunk6AFUNKK7_cjs.getSequence(utxoExitLeaf)
|
|
4560
4571
|
});
|
|
4561
4572
|
}
|
|
4562
4573
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -4596,7 +4607,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4596
4607
|
}
|
|
4597
4608
|
/**
|
|
4598
4609
|
* Core migration routine shared by the manual API and the automatic poll
|
|
4599
|
-
* pass. Fetches a fresh {@link
|
|
4610
|
+
* pass. Fetches a fresh {@link ArkadeInfo}, applies a mid-session signer
|
|
4600
4611
|
* rotation when the wallet's own snapshot signer has been deprecated,
|
|
4601
4612
|
* selects spendable VTXOs under deprecated-signer contracts (cutoff-first),
|
|
4602
4613
|
* and settles them to the active-signer Ark address.
|
|
@@ -4799,8 +4810,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
4799
4810
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
4800
4811
|
if (cls.status === "CURRENT") continue;
|
|
4801
4812
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
4802
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
4803
|
-
const spendable = live.filter((v) => !
|
|
4813
|
+
const recoverable = live.filter((v) => v.isSwept && !chunk6AFUNKK7_cjs.hasTerminalSpend(v));
|
|
4814
|
+
const spendable = live.filter((v) => !chunk6AFUNKK7_cjs.hasTerminalSpend(v) && !v.isSwept);
|
|
4804
4815
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
4805
4816
|
let recoverableCount = 0;
|
|
4806
4817
|
let recoverableValue = 0;
|
|
@@ -4813,7 +4824,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4813
4824
|
awaitingSweepCount = spendable.length;
|
|
4814
4825
|
awaitingSweepValue = value;
|
|
4815
4826
|
for (const v of spendable) {
|
|
4816
|
-
const exp =
|
|
4827
|
+
const exp = chunk6AFUNKK7_cjs.toBatchExpiry(v);
|
|
4817
4828
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
4818
4829
|
nextSweepEta = exp;
|
|
4819
4830
|
}
|
|
@@ -5074,7 +5085,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5074
5085
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
5075
5086
|
getBoardingTimelock() {
|
|
5076
5087
|
const wallet = this.getSweepWallet();
|
|
5077
|
-
const exitScript =
|
|
5088
|
+
const exitScript = chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(
|
|
5078
5089
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
5079
5090
|
);
|
|
5080
5091
|
return exitScript.params.timelock;
|
|
@@ -5205,8 +5216,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5205
5216
|
* or doesn't carry the metadata.
|
|
5206
5217
|
*/
|
|
5207
5218
|
extractSpentOutpoint(error) {
|
|
5208
|
-
const ark =
|
|
5209
|
-
if (!
|
|
5219
|
+
const ark = chunk6AFUNKK7_cjs.maybeArkError(error);
|
|
5220
|
+
if (!chunk6AFUNKK7_cjs.isArkError(ark, chunk6AFUNKK7_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
5210
5221
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
5211
5222
|
if (typeof raw !== "string") return void 0;
|
|
5212
5223
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -5396,7 +5407,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5396
5407
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
5397
5408
|
break;
|
|
5398
5409
|
}
|
|
5399
|
-
const inputFee = estimator.evalOffchainInput(
|
|
5410
|
+
const inputFee = estimator.evalOffchainInput(chunk6AFUNKK7_cjs.toOffchainInputFeeParams(v));
|
|
5400
5411
|
if (inputFee.satoshis >= v.value) {
|
|
5401
5412
|
continue;
|
|
5402
5413
|
}
|
|
@@ -5416,7 +5427,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5416
5427
|
const arkAddress = await this.wallet.getAddress();
|
|
5417
5428
|
const outputFee = estimator.evalOffchainOutput({
|
|
5418
5429
|
amount: totalAmount,
|
|
5419
|
-
script: base.hex.encode(
|
|
5430
|
+
script: base.hex.encode(chunk6AFUNKK7_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
5420
5431
|
});
|
|
5421
5432
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
5422
5433
|
if (totalAmount < dustAmount) return;
|
|
@@ -5496,7 +5507,7 @@ var ArkNote = class _ArkNote {
|
|
|
5496
5507
|
this.value = value;
|
|
5497
5508
|
this.HRP = HRP;
|
|
5498
5509
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
5499
|
-
this.vtxoScript = new
|
|
5510
|
+
this.vtxoScript = new chunk6AFUNKK7_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
5500
5511
|
const leaf = this.vtxoScript.leaves[0];
|
|
5501
5512
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
5502
5513
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -5663,7 +5674,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5663
5674
|
const privateKey = data.slice(1, 33);
|
|
5664
5675
|
const serverPubKey = data.slice(33, 65);
|
|
5665
5676
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
5666
|
-
const csvTimelock =
|
|
5677
|
+
const csvTimelock = chunk6AFUNKK7_cjs.sequenceToTimelock(sequence);
|
|
5667
5678
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
5668
5679
|
}
|
|
5669
5680
|
toString() {
|
|
@@ -5671,7 +5682,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5671
5682
|
data[0] = _ArkadeCash.Version;
|
|
5672
5683
|
data.set(this._privateKey, 1);
|
|
5673
5684
|
data.set(this._serverPubKey, 33);
|
|
5674
|
-
const sequence =
|
|
5685
|
+
const sequence = chunk6AFUNKK7_cjs.timelockToSequence(this.csvTimelock);
|
|
5675
5686
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
5676
5687
|
const words = base.bech32m.toWords(data);
|
|
5677
5688
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -5680,7 +5691,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5680
5691
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
5681
5692
|
}
|
|
5682
5693
|
get vtxoScript() {
|
|
5683
|
-
return new
|
|
5694
|
+
return new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
5684
5695
|
pubKey: this._publicKey,
|
|
5685
5696
|
serverPubKey: this._serverPubKey,
|
|
5686
5697
|
csvTimelock: this.csvTimelock
|
|
@@ -5941,7 +5952,7 @@ async function captureExitBranch(params) {
|
|
|
5941
5952
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
5942
5953
|
if (nonCommitment.length > 0) {
|
|
5943
5954
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
5944
|
-
psbtByTxid.set(
|
|
5955
|
+
psbtByTxid.set(chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
5945
5956
|
}
|
|
5946
5957
|
}
|
|
5947
5958
|
}
|
|
@@ -5984,10 +5995,10 @@ var IndexerExitDataSource = class {
|
|
|
5984
5995
|
while (hasMore) {
|
|
5985
5996
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
5986
5997
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
5987
|
-
{ pageIndex, pageSize:
|
|
5998
|
+
{ pageIndex, pageSize: chunk6AFUNKK7_cjs.DEFAULT_PAGE_SIZE }
|
|
5988
5999
|
);
|
|
5989
6000
|
chain.push(...page);
|
|
5990
|
-
hasMore = meta ? page.length ===
|
|
6001
|
+
hasMore = meta ? page.length === chunk6AFUNKK7_cjs.DEFAULT_PAGE_SIZE : false;
|
|
5991
6002
|
pageIndex++;
|
|
5992
6003
|
}
|
|
5993
6004
|
return chain;
|
|
@@ -5999,12 +6010,12 @@ var IndexerExitDataSource = class {
|
|
|
5999
6010
|
while (hasMore) {
|
|
6000
6011
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
6001
6012
|
pageIndex,
|
|
6002
|
-
pageSize:
|
|
6013
|
+
pageSize: chunk6AFUNKK7_cjs.DEFAULT_PAGE_SIZE
|
|
6003
6014
|
});
|
|
6004
6015
|
for (const psbt of txs) {
|
|
6005
|
-
out.set(
|
|
6016
|
+
out.set(chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6006
6017
|
}
|
|
6007
|
-
hasMore = page ? txs.length ===
|
|
6018
|
+
hasMore = page ? txs.length === chunk6AFUNKK7_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6008
6019
|
pageIndex++;
|
|
6009
6020
|
}
|
|
6010
6021
|
return out;
|
|
@@ -6025,7 +6036,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
6025
6036
|
}
|
|
6026
6037
|
}
|
|
6027
6038
|
function psbtInputTxids(psbtBase64) {
|
|
6028
|
-
const tx =
|
|
6039
|
+
const tx = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
6029
6040
|
const ids = [];
|
|
6030
6041
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
6031
6042
|
const txid = tx.getInput(i).txid;
|
|
@@ -6379,15 +6390,15 @@ async function saveArkInfoSnapshot(repo, info, savedAt) {
|
|
|
6379
6390
|
}
|
|
6380
6391
|
}));
|
|
6381
6392
|
}
|
|
6382
|
-
async function resolveArkInfo(arkProvider, walletRepository) {
|
|
6393
|
+
async function resolveArkInfo(arkProvider, walletRepository, opts) {
|
|
6383
6394
|
let info;
|
|
6384
6395
|
try {
|
|
6385
6396
|
info = await arkProvider.getInfo();
|
|
6386
6397
|
} catch (err) {
|
|
6387
|
-
if (!
|
|
6398
|
+
if (opts?.requireLive || !chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
6388
6399
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
6389
6400
|
if (!snapshot) {
|
|
6390
|
-
throw new
|
|
6401
|
+
throw new chunk6AFUNKK7_cjs.ProviderUnavailableError(
|
|
6391
6402
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
6392
6403
|
{ cause: err }
|
|
6393
6404
|
);
|
|
@@ -6470,6 +6481,13 @@ var TxTree = class {
|
|
|
6470
6481
|
if (nbOfInputs !== 1) {
|
|
6471
6482
|
throw new Error(`unexpected number of inputs: ${nbOfInputs}, expected 1`);
|
|
6472
6483
|
}
|
|
6484
|
+
if (this.root.lockTime !== 0) {
|
|
6485
|
+
throw new Error(`unexpected locktime: ${this.root.lockTime}, expected 0`);
|
|
6486
|
+
}
|
|
6487
|
+
const sequence = this.root.getInput(0).sequence;
|
|
6488
|
+
if (sequence !== void 0 && sequence !== btcSigner.DEFAULT_SEQUENCE) {
|
|
6489
|
+
throw new Error(`unexpected sequence: ${sequence}, expected ${btcSigner.DEFAULT_SEQUENCE}`);
|
|
6490
|
+
}
|
|
6473
6491
|
if (this.children.size > nbOfOutputs - 1) {
|
|
6474
6492
|
throw new Error(
|
|
6475
6493
|
`unexpected number of children: ${this.children.size}, expected maximum ${nbOfOutputs - 1}`
|
|
@@ -6770,7 +6788,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos) {
|
|
|
6770
6788
|
return [...txids];
|
|
6771
6789
|
}
|
|
6772
6790
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt) {
|
|
6773
|
-
const fromOldestVtxo = vtxos.map(
|
|
6791
|
+
const fromOldestVtxo = vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
6774
6792
|
const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(fromOldestVtxo) : [];
|
|
6775
6793
|
const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
|
|
6776
6794
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
@@ -6934,7 +6952,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
6934
6952
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
6935
6953
|
withRecoverable: false
|
|
6936
6954
|
});
|
|
6937
|
-
const controlAssetRef = params.controlAssetId ?
|
|
6955
|
+
const controlAssetRef = params.controlAssetId ? chunkCZ32XADN_cjs.AssetRef.fromId(chunkCZ32XADN_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
6938
6956
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
6939
6957
|
let totalBtcSelected = 0n;
|
|
6940
6958
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -6947,8 +6965,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
6947
6965
|
}
|
|
6948
6966
|
}
|
|
6949
6967
|
const groups = [];
|
|
6950
|
-
const issuedAssetOutput =
|
|
6951
|
-
const issuedAssetGroup =
|
|
6968
|
+
const issuedAssetOutput = chunkCZ32XADN_cjs.AssetOutput.create(0, params.amount);
|
|
6969
|
+
const issuedAssetGroup = chunkCZ32XADN_cjs.AssetGroup.create(
|
|
6952
6970
|
null,
|
|
6953
6971
|
controlAssetRef,
|
|
6954
6972
|
[],
|
|
@@ -6963,28 +6981,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
6963
6981
|
for (const [inputIndex, assets] of assetInputs) {
|
|
6964
6982
|
for (const asset of assets) {
|
|
6965
6983
|
if (asset.assetId !== assetId) continue;
|
|
6966
|
-
changeInputs.push(
|
|
6984
|
+
changeInputs.push(chunkCZ32XADN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
6967
6985
|
}
|
|
6968
6986
|
}
|
|
6969
6987
|
groups.push(
|
|
6970
|
-
|
|
6971
|
-
|
|
6988
|
+
chunkCZ32XADN_cjs.AssetGroup.create(
|
|
6989
|
+
chunkCZ32XADN_cjs.AssetId.fromString(assetId),
|
|
6972
6990
|
null,
|
|
6973
6991
|
changeInputs,
|
|
6974
|
-
[
|
|
6992
|
+
[chunkCZ32XADN_cjs.AssetOutput.create(0, amount)],
|
|
6975
6993
|
[]
|
|
6976
6994
|
)
|
|
6977
6995
|
);
|
|
6978
6996
|
}
|
|
6979
6997
|
}
|
|
6980
6998
|
const address = await this.wallet.getAddress();
|
|
6981
|
-
const outputAddress =
|
|
6999
|
+
const outputAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
6982
7000
|
const outputs = [
|
|
6983
7001
|
{
|
|
6984
7002
|
script: outputAddress.pkScript,
|
|
6985
7003
|
amount: BigInt(totalBtcSelected)
|
|
6986
7004
|
},
|
|
6987
|
-
Extension.create([
|
|
7005
|
+
Extension.create([chunkCZ32XADN_cjs.Packet.create(groups)]).txOut()
|
|
6988
7006
|
];
|
|
6989
7007
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
6990
7008
|
coinSelection.inputs,
|
|
@@ -6992,7 +7010,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
6992
7010
|
);
|
|
6993
7011
|
return {
|
|
6994
7012
|
arkTxId: arkTxid,
|
|
6995
|
-
assetId:
|
|
7013
|
+
assetId: chunkCZ32XADN_cjs.AssetId.create(arkTxid, 0).toString()
|
|
6996
7014
|
};
|
|
6997
7015
|
}
|
|
6998
7016
|
/**
|
|
@@ -7064,16 +7082,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7064
7082
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7065
7083
|
for (const asset of assets) {
|
|
7066
7084
|
if (asset.assetId !== params.assetId) continue;
|
|
7067
|
-
reissueInputs.push(
|
|
7085
|
+
reissueInputs.push(chunkCZ32XADN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7068
7086
|
}
|
|
7069
7087
|
}
|
|
7070
7088
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
7071
|
-
const reissueAssetIdObj =
|
|
7072
|
-
const reissueAssetGroup =
|
|
7089
|
+
const reissueAssetIdObj = chunkCZ32XADN_cjs.AssetId.fromString(params.assetId);
|
|
7090
|
+
const reissueAssetGroup = chunkCZ32XADN_cjs.AssetGroup.create(
|
|
7073
7091
|
reissueAssetIdObj,
|
|
7074
7092
|
null,
|
|
7075
7093
|
reissueInputs,
|
|
7076
|
-
[
|
|
7094
|
+
[chunkCZ32XADN_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
7077
7095
|
[]
|
|
7078
7096
|
);
|
|
7079
7097
|
const groups = [reissueAssetGroup];
|
|
@@ -7082,27 +7100,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7082
7100
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7083
7101
|
for (const asset of assets) {
|
|
7084
7102
|
if (asset.assetId !== assetId) continue;
|
|
7085
|
-
changeInputs.push(
|
|
7103
|
+
changeInputs.push(chunkCZ32XADN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7086
7104
|
}
|
|
7087
7105
|
}
|
|
7088
7106
|
groups.push(
|
|
7089
|
-
|
|
7090
|
-
|
|
7107
|
+
chunkCZ32XADN_cjs.AssetGroup.create(
|
|
7108
|
+
chunkCZ32XADN_cjs.AssetId.fromString(assetId),
|
|
7091
7109
|
null,
|
|
7092
7110
|
changeInputs,
|
|
7093
|
-
[
|
|
7111
|
+
[chunkCZ32XADN_cjs.AssetOutput.create(0, amount)],
|
|
7094
7112
|
[]
|
|
7095
7113
|
)
|
|
7096
7114
|
);
|
|
7097
7115
|
}
|
|
7098
7116
|
const address = await this.wallet.getAddress();
|
|
7099
|
-
const outputAddress =
|
|
7117
|
+
const outputAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
7100
7118
|
const outputs = [
|
|
7101
7119
|
{
|
|
7102
7120
|
script: outputAddress.pkScript,
|
|
7103
7121
|
amount: BigInt(totalBtcSelected)
|
|
7104
7122
|
},
|
|
7105
|
-
Extension.create([
|
|
7123
|
+
Extension.create([chunkCZ32XADN_cjs.Packet.create(groups)]).txOut()
|
|
7106
7124
|
];
|
|
7107
7125
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7108
7126
|
return arkTxid;
|
|
@@ -7169,27 +7187,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7169
7187
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7170
7188
|
for (const asset of assets) {
|
|
7171
7189
|
if (asset.assetId !== assetId) continue;
|
|
7172
|
-
changeInputs.push(
|
|
7190
|
+
changeInputs.push(chunkCZ32XADN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7173
7191
|
}
|
|
7174
7192
|
}
|
|
7175
7193
|
groups.push(
|
|
7176
|
-
|
|
7177
|
-
|
|
7194
|
+
chunkCZ32XADN_cjs.AssetGroup.create(
|
|
7195
|
+
chunkCZ32XADN_cjs.AssetId.fromString(assetId),
|
|
7178
7196
|
null,
|
|
7179
7197
|
changeInputs,
|
|
7180
|
-
amount > 0n ? [
|
|
7198
|
+
amount > 0n ? [chunkCZ32XADN_cjs.AssetOutput.create(0, amount)] : [],
|
|
7181
7199
|
[]
|
|
7182
7200
|
)
|
|
7183
7201
|
);
|
|
7184
7202
|
}
|
|
7185
7203
|
const address = await this.wallet.getAddress();
|
|
7186
|
-
const outputAddress =
|
|
7204
|
+
const outputAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(address);
|
|
7187
7205
|
const outputs = [
|
|
7188
7206
|
{
|
|
7189
7207
|
script: outputAddress.pkScript,
|
|
7190
7208
|
amount: BigInt(totalBtcSelected)
|
|
7191
7209
|
},
|
|
7192
|
-
Extension.create([
|
|
7210
|
+
Extension.create([chunkCZ32XADN_cjs.Packet.create(groups)]).txOut()
|
|
7193
7211
|
];
|
|
7194
7212
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7195
7213
|
return arkTxid;
|
|
@@ -7214,7 +7232,7 @@ function castMetadata(metadata) {
|
|
|
7214
7232
|
} else {
|
|
7215
7233
|
throw new Error("Invalid metadata value type");
|
|
7216
7234
|
}
|
|
7217
|
-
md.push(
|
|
7235
|
+
md.push(chunkCZ32XADN_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
7218
7236
|
}
|
|
7219
7237
|
return md;
|
|
7220
7238
|
}
|
|
@@ -7235,10 +7253,10 @@ var DelegateManagerImpl = class {
|
|
|
7235
7253
|
if (vtxos.length === 0) {
|
|
7236
7254
|
return { delegated: [], failed: [] };
|
|
7237
7255
|
}
|
|
7238
|
-
const destinationScript =
|
|
7256
|
+
const destinationScript = chunk6AFUNKK7_cjs.ArkAddress.decode(destination).pkScript;
|
|
7239
7257
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
7240
7258
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
7241
|
-
const eligible = vtxos.map(
|
|
7259
|
+
const eligible = vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo).filter(
|
|
7242
7260
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
7243
7261
|
);
|
|
7244
7262
|
if (eligible.length === 0) {
|
|
@@ -7267,11 +7285,11 @@ var DelegateManagerImpl = class {
|
|
|
7267
7285
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
7268
7286
|
let recoverableVtxos = [];
|
|
7269
7287
|
for (const vtxo of eligible) {
|
|
7270
|
-
if (
|
|
7288
|
+
if (chunk6AFUNKK7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7271
7289
|
recoverableVtxos.push(vtxo);
|
|
7272
7290
|
continue;
|
|
7273
7291
|
}
|
|
7274
|
-
const expiry =
|
|
7292
|
+
const expiry = chunk6AFUNKK7_cjs.toBatchExpiry(vtxo);
|
|
7275
7293
|
if (!expiry) continue;
|
|
7276
7294
|
const dayKey = getDayTimestamp(expiry);
|
|
7277
7295
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -7336,7 +7354,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7336
7354
|
}
|
|
7337
7355
|
if (!delegateAt) {
|
|
7338
7356
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
7339
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
7357
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunk6AFUNKK7_cjs.canRecoverOnchain(coin, now) && chunk6AFUNKK7_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunk6AFUNKK7_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
|
|
7340
7358
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
7341
7359
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
7342
7360
|
} else {
|
|
@@ -7365,7 +7383,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7365
7383
|
let amount = 0n;
|
|
7366
7384
|
for (const coin of vtxos) {
|
|
7367
7385
|
const inputFee = estimator.evalOffchainInput({
|
|
7368
|
-
...
|
|
7386
|
+
...chunk6AFUNKK7_cjs.toOffchainInputFeeParams(coin),
|
|
7369
7387
|
type: "vtxo"
|
|
7370
7388
|
});
|
|
7371
7389
|
if (inputFee.value >= coin.value) {
|
|
@@ -7379,7 +7397,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7379
7397
|
const delegateFee = BigInt(Number(fee));
|
|
7380
7398
|
if (delegateFee > 0n) {
|
|
7381
7399
|
outputs.push({
|
|
7382
|
-
script:
|
|
7400
|
+
script: chunk6AFUNKK7_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
7383
7401
|
amount: delegateFee
|
|
7384
7402
|
});
|
|
7385
7403
|
}
|
|
@@ -7412,10 +7430,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7412
7430
|
destinationScript
|
|
7413
7431
|
);
|
|
7414
7432
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
7415
|
-
btcSigner.Address(
|
|
7433
|
+
btcSigner.Address(chunk6AFUNKK7_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
7416
7434
|
);
|
|
7417
7435
|
const forfeits = await Promise.all(
|
|
7418
|
-
vtxos.filter((v) => !
|
|
7436
|
+
vtxos.filter((v) => !chunk6AFUNKK7_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
7419
7437
|
const forfeit = await makeDelegateForfeitTx(
|
|
7420
7438
|
coin,
|
|
7421
7439
|
dust,
|
|
@@ -7440,7 +7458,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
7440
7458
|
index: input.vout,
|
|
7441
7459
|
witnessUtxo: {
|
|
7442
7460
|
amount: BigInt(input.value),
|
|
7443
|
-
script:
|
|
7461
|
+
script: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
7444
7462
|
},
|
|
7445
7463
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
7446
7464
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -7498,7 +7516,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
7498
7516
|
expire_at: 0,
|
|
7499
7517
|
cosigners_public_keys: cosignerPubKeys
|
|
7500
7518
|
};
|
|
7501
|
-
const proof =
|
|
7519
|
+
const proof = chunk6AFUNKK7_cjs.Intent.create(message, coins, outputs);
|
|
7502
7520
|
const signedProof = await identity.sign(proof);
|
|
7503
7521
|
return {
|
|
7504
7522
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -7516,10 +7534,10 @@ function getDayTimestamp(timestamp) {
|
|
|
7516
7534
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
7517
7535
|
if (!vtxo.tapTree) return void 0;
|
|
7518
7536
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
7519
|
-
const vtxoScript =
|
|
7537
|
+
const vtxoScript = chunk6AFUNKK7_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
7520
7538
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
7521
|
-
const arkTapscript =
|
|
7522
|
-
if (!
|
|
7539
|
+
const arkTapscript = chunk6AFUNKK7_cjs.decodeTapscript(chunk6AFUNKK7_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
7540
|
+
if (!chunk6AFUNKK7_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
7523
7541
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
7524
7542
|
});
|
|
7525
7543
|
}
|
|
@@ -7800,7 +7818,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
|
|
|
7800
7818
|
};
|
|
7801
7819
|
}
|
|
7802
7820
|
function scriptFromArkAddress(address) {
|
|
7803
|
-
return base.hex.encode(
|
|
7821
|
+
return base.hex.encode(chunk6AFUNKK7_cjs.ArkAddress.decode(address).pkScript);
|
|
7804
7822
|
}
|
|
7805
7823
|
|
|
7806
7824
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -8295,7 +8313,7 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
8295
8313
|
}
|
|
8296
8314
|
async function getVtxosForContract(repo, contract) {
|
|
8297
8315
|
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
8298
|
-
return vtxos.map(
|
|
8316
|
+
return vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
8299
8317
|
}
|
|
8300
8318
|
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
8301
8319
|
if (repo.saveVtxosForScript) {
|
|
@@ -8437,7 +8455,7 @@ function decodeArkContract(encoded) {
|
|
|
8437
8455
|
}
|
|
8438
8456
|
function contractFromArkContract(encoded, options = {}) {
|
|
8439
8457
|
const parsed = decodeArkContract(encoded);
|
|
8440
|
-
const handler =
|
|
8458
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(parsed.type);
|
|
8441
8459
|
if (!handler) {
|
|
8442
8460
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
8443
8461
|
}
|
|
@@ -8451,9 +8469,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
8451
8469
|
metadata: options.metadata
|
|
8452
8470
|
};
|
|
8453
8471
|
}
|
|
8454
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
8472
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk6AFUNKK7_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
8455
8473
|
const parsed = decodeArkContract(encoded);
|
|
8456
|
-
const handler =
|
|
8474
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
8457
8475
|
const params = parsed.data;
|
|
8458
8476
|
const vtxoScript = handler.createScript(params);
|
|
8459
8477
|
return {
|
|
@@ -8707,9 +8725,9 @@ var ContractWatcher = class {
|
|
|
8707
8725
|
this.connectionState = "connected";
|
|
8708
8726
|
this.reconnectAttempts = 0;
|
|
8709
8727
|
this.listenLoop().catch((e) => {
|
|
8710
|
-
if (
|
|
8728
|
+
if (chunk6AFUNKK7_cjs.isEventSourceError(e)) {
|
|
8711
8729
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8712
|
-
} else if (!
|
|
8730
|
+
} else if (!chunk6AFUNKK7_cjs.isEventSourceUnavailableError(e)) {
|
|
8713
8731
|
console.error(e);
|
|
8714
8732
|
}
|
|
8715
8733
|
this.connectionState = "disconnected";
|
|
@@ -8721,7 +8739,7 @@ var ContractWatcher = class {
|
|
|
8721
8739
|
this.scheduleReconnect();
|
|
8722
8740
|
});
|
|
8723
8741
|
} catch (error) {
|
|
8724
|
-
if (!
|
|
8742
|
+
if (!chunk6AFUNKK7_cjs.isEventSourceUnavailableError(error)) {
|
|
8725
8743
|
console.error("ContractWatcher connection failed:", error);
|
|
8726
8744
|
}
|
|
8727
8745
|
this.connectionState = "disconnected";
|
|
@@ -8747,7 +8765,7 @@ var ContractWatcher = class {
|
|
|
8747
8765
|
* slower; what it loses is push latency.
|
|
8748
8766
|
*/
|
|
8749
8767
|
reportEventSourceUnavailable(error) {
|
|
8750
|
-
if (!
|
|
8768
|
+
if (!chunk6AFUNKK7_cjs.isEventSourceUnavailableError(error)) return false;
|
|
8751
8769
|
if (!this.eventSourceReported) {
|
|
8752
8770
|
this.eventSourceReported = true;
|
|
8753
8771
|
console.warn(
|
|
@@ -8963,14 +8981,14 @@ var ContractWatcher = class {
|
|
|
8963
8981
|
const timestamp = Date.now();
|
|
8964
8982
|
if (update.newVtxos?.length) {
|
|
8965
8983
|
this.processSubscriptionVtxos(
|
|
8966
|
-
update.newVtxos.map(
|
|
8984
|
+
update.newVtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo),
|
|
8967
8985
|
"vtxo_received",
|
|
8968
8986
|
timestamp
|
|
8969
8987
|
);
|
|
8970
8988
|
}
|
|
8971
8989
|
if (update.spentVtxos?.length) {
|
|
8972
8990
|
this.processSubscriptionVtxos(
|
|
8973
|
-
update.spentVtxos.map(
|
|
8991
|
+
update.spentVtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo),
|
|
8974
8992
|
"vtxo_spent",
|
|
8975
8993
|
timestamp
|
|
8976
8994
|
);
|
|
@@ -9065,7 +9083,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
9065
9083
|
(s) => !isTerminalIntentState(s)
|
|
9066
9084
|
);
|
|
9067
9085
|
function isConsumed(vtxo) {
|
|
9068
|
-
return vtxo !== void 0 &&
|
|
9086
|
+
return vtxo !== void 0 && chunk6AFUNKK7_cjs.hasTerminalSpend(vtxo);
|
|
9069
9087
|
}
|
|
9070
9088
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
9071
9089
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -9108,7 +9126,7 @@ async function reconcileIntents(deps) {
|
|
|
9108
9126
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
9109
9127
|
if (outpoints.length > 0) {
|
|
9110
9128
|
try {
|
|
9111
|
-
const { vtxos } = await
|
|
9129
|
+
const { vtxos } = await chunk6AFUNKK7_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9112
9130
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9113
9131
|
} catch (e) {
|
|
9114
9132
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9282,7 +9300,7 @@ var ContractManager = class _ContractManager {
|
|
|
9282
9300
|
await this.reconcileWatched();
|
|
9283
9301
|
this.markSyncOnline();
|
|
9284
9302
|
} catch (err) {
|
|
9285
|
-
if (!
|
|
9303
|
+
if (!chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
9286
9304
|
this.markSyncDegraded(err);
|
|
9287
9305
|
}
|
|
9288
9306
|
this.initialized = true;
|
|
@@ -9414,7 +9432,7 @@ var ContractManager = class _ContractManager {
|
|
|
9414
9432
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
9415
9433
|
const to = watermark + lookAhead.size;
|
|
9416
9434
|
const deps = lookAhead.candidateDeps();
|
|
9417
|
-
const handlers =
|
|
9435
|
+
const handlers = chunkHL7EC2Z5_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkHL7EC2Z5_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
9418
9436
|
const band = /* @__PURE__ */ new Map();
|
|
9419
9437
|
for (let index = from; index <= to; index++) {
|
|
9420
9438
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -9425,7 +9443,7 @@ var ContractManager = class _ContractManager {
|
|
|
9425
9443
|
index,
|
|
9426
9444
|
params: {
|
|
9427
9445
|
...candidate,
|
|
9428
|
-
...
|
|
9446
|
+
...chunkHL7EC2Z5_cjs.speculativeReceiveMetadata(descriptor)
|
|
9429
9447
|
}
|
|
9430
9448
|
});
|
|
9431
9449
|
}
|
|
@@ -9487,7 +9505,7 @@ var ContractManager = class _ContractManager {
|
|
|
9487
9505
|
});
|
|
9488
9506
|
for (const entry of pending) entry.catchUpPending = false;
|
|
9489
9507
|
} catch (err) {
|
|
9490
|
-
if (!
|
|
9508
|
+
if (!chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
9491
9509
|
this.markSyncDegraded(err);
|
|
9492
9510
|
}
|
|
9493
9511
|
}
|
|
@@ -9537,7 +9555,7 @@ var ContractManager = class _ContractManager {
|
|
|
9537
9555
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
9538
9556
|
this.markSyncOnline();
|
|
9539
9557
|
} catch (err) {
|
|
9540
|
-
if (!
|
|
9558
|
+
if (!chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
9541
9559
|
this.markSyncDegraded(err);
|
|
9542
9560
|
}
|
|
9543
9561
|
await this.watcher.addContract(contract);
|
|
@@ -9574,7 +9592,7 @@ var ContractManager = class _ContractManager {
|
|
|
9574
9592
|
return result;
|
|
9575
9593
|
}
|
|
9576
9594
|
async upsertContractRow(params) {
|
|
9577
|
-
const handler =
|
|
9595
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(params.type);
|
|
9578
9596
|
if (!handler) {
|
|
9579
9597
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
9580
9598
|
}
|
|
@@ -9674,7 +9692,7 @@ var ContractManager = class _ContractManager {
|
|
|
9674
9692
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
9675
9693
|
);
|
|
9676
9694
|
}
|
|
9677
|
-
const registered =
|
|
9695
|
+
const registered = chunkHL7EC2Z5_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkHL7EC2Z5_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
9678
9696
|
const discoverables = [
|
|
9679
9697
|
...registered.filter((h) => h.type === "boarding"),
|
|
9680
9698
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -9809,7 +9827,7 @@ var ContractManager = class _ContractManager {
|
|
|
9809
9827
|
await this.syncContracts({ contracts, pageSize });
|
|
9810
9828
|
this.markSyncOnline();
|
|
9811
9829
|
} catch (err) {
|
|
9812
|
-
if (!
|
|
9830
|
+
if (!chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
9813
9831
|
this.markSyncDegraded(err);
|
|
9814
9832
|
}
|
|
9815
9833
|
const vtxos = await this.getVtxosForContracts(contracts);
|
|
@@ -9830,7 +9848,7 @@ var ContractManager = class _ContractManager {
|
|
|
9830
9848
|
}
|
|
9831
9849
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
9832
9850
|
return vtxos.map(
|
|
9833
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
9851
|
+
(vtxo) => extendVirtualCoinForContract(chunk6AFUNKK7_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
9834
9852
|
);
|
|
9835
9853
|
}
|
|
9836
9854
|
/** @inheritdoc */
|
|
@@ -9874,14 +9892,14 @@ var ContractManager = class _ContractManager {
|
|
|
9874
9892
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
9875
9893
|
const asking = vtxos.filter((vtxo) => {
|
|
9876
9894
|
const contract = byScript.get(vtxo.script);
|
|
9877
|
-
return contract !== void 0 &&
|
|
9895
|
+
return contract !== void 0 && chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
9878
9896
|
});
|
|
9879
9897
|
if (asking.length === 0) return refused;
|
|
9880
9898
|
const tip = await this.currentChainTip();
|
|
9881
9899
|
const walletKey = await walletPubKey?.();
|
|
9882
9900
|
for (const vtxo of asking) {
|
|
9883
9901
|
const contract = byScript.get(vtxo.script);
|
|
9884
|
-
const handler =
|
|
9902
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
9885
9903
|
if (!handler?.assertSpendableNow) continue;
|
|
9886
9904
|
const context = {
|
|
9887
9905
|
collaborative: true,
|
|
@@ -9896,7 +9914,7 @@ var ContractManager = class _ContractManager {
|
|
|
9896
9914
|
// the next handler to answer a CSV question would meet a
|
|
9897
9915
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
9898
9916
|
// really is one.
|
|
9899
|
-
vtxo:
|
|
9917
|
+
vtxo: chunk6AFUNKK7_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
9900
9918
|
};
|
|
9901
9919
|
try {
|
|
9902
9920
|
await handler.assertSpendableNow(
|
|
@@ -10052,7 +10070,7 @@ var ContractManager = class _ContractManager {
|
|
|
10052
10070
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
10053
10071
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10054
10072
|
if (!contract) return [];
|
|
10055
|
-
const handler =
|
|
10073
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
10056
10074
|
if (!handler) return [];
|
|
10057
10075
|
const script = handler.createScript(contract.params);
|
|
10058
10076
|
const tip = await this.currentChainTip();
|
|
@@ -10080,7 +10098,7 @@ var ContractManager = class _ContractManager {
|
|
|
10080
10098
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
10081
10099
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10082
10100
|
if (!contract) return [];
|
|
10083
|
-
const handler =
|
|
10101
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
10084
10102
|
if (!handler) return [];
|
|
10085
10103
|
const script = handler.createScript(contract.params);
|
|
10086
10104
|
const context = {
|
|
@@ -10136,7 +10154,7 @@ var ContractManager = class _ContractManager {
|
|
|
10136
10154
|
}
|
|
10137
10155
|
async refreshOutpoints(outpoints) {
|
|
10138
10156
|
if (outpoints.length === 0) return;
|
|
10139
|
-
const { vtxos } = await
|
|
10157
|
+
const { vtxos } = await chunk6AFUNKK7_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10140
10158
|
outpoints
|
|
10141
10159
|
});
|
|
10142
10160
|
if (vtxos.length === 0) return;
|
|
@@ -10215,7 +10233,7 @@ var ContractManager = class _ContractManager {
|
|
|
10215
10233
|
break;
|
|
10216
10234
|
}
|
|
10217
10235
|
} catch (err) {
|
|
10218
|
-
if (!
|
|
10236
|
+
if (!chunk6AFUNKK7_cjs.isRetryableProviderError(err)) throw err;
|
|
10219
10237
|
this.markSyncDegraded(err);
|
|
10220
10238
|
}
|
|
10221
10239
|
this.emitEvent(event);
|
|
@@ -10294,7 +10312,7 @@ var ContractManager = class _ContractManager {
|
|
|
10294
10312
|
*/
|
|
10295
10313
|
async reconcilePendingFrontier(contracts) {
|
|
10296
10314
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
10297
|
-
const vtxos = await
|
|
10315
|
+
const vtxos = await chunk6AFUNKK7_cjs.getAllNormalizedVtxos(
|
|
10298
10316
|
this.config.indexerProvider,
|
|
10299
10317
|
contracts.map((c) => c.script),
|
|
10300
10318
|
{ pendingOnly: true }
|
|
@@ -10377,7 +10395,7 @@ var ContractManager = class _ContractManager {
|
|
|
10377
10395
|
}
|
|
10378
10396
|
return result;
|
|
10379
10397
|
}
|
|
10380
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
10398
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunk6AFUNKK7_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
10381
10399
|
if (contracts.length === 0) {
|
|
10382
10400
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
10383
10401
|
}
|
|
@@ -10393,7 +10411,7 @@ var ContractManager = class _ContractManager {
|
|
|
10393
10411
|
before: syncWindow.before
|
|
10394
10412
|
}
|
|
10395
10413
|
} : {};
|
|
10396
|
-
const vtxos = await
|
|
10414
|
+
const vtxos = await chunk6AFUNKK7_cjs.getAllNormalizedVtxos(
|
|
10397
10415
|
this.config.indexerProvider,
|
|
10398
10416
|
contracts.map((c) => c.script),
|
|
10399
10417
|
{ ...windowOpts, pageSize }
|
|
@@ -10538,7 +10556,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
10538
10556
|
const s = base.hex.decode(t.s);
|
|
10539
10557
|
return [cb, s];
|
|
10540
10558
|
};
|
|
10541
|
-
var deserializeVtxo = (o) =>
|
|
10559
|
+
var deserializeVtxo = (o) => chunk6AFUNKK7_cjs.normalizeVtxo({
|
|
10542
10560
|
...o,
|
|
10543
10561
|
createdAt: new Date(o.createdAt),
|
|
10544
10562
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11361,7 +11379,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11361
11379
|
*/
|
|
11362
11380
|
materializeDescriptorAt(index) {
|
|
11363
11381
|
const descriptor = this.identity.descriptor;
|
|
11364
|
-
const network =
|
|
11382
|
+
const network = chunkHL7EC2Z5_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
11365
11383
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
11366
11384
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
11367
11385
|
if (!keyInfo?.keyExpression) {
|
|
@@ -11509,7 +11527,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
11509
11527
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
11510
11528
|
if (!provider) return void 0;
|
|
11511
11529
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
11512
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
11530
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
11513
11531
|
const factoryOpts = {
|
|
11514
11532
|
walletRepository: setup.walletRepository,
|
|
11515
11533
|
contractRepository: setup.contractRepository,
|
|
@@ -11710,7 +11728,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
11710
11728
|
};
|
|
11711
11729
|
function deriveLeafPubkey(descriptor) {
|
|
11712
11730
|
try {
|
|
11713
|
-
return
|
|
11731
|
+
return chunkHL7EC2Z5_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11714
11732
|
} catch (e) {
|
|
11715
11733
|
throw new NonRangeableDescriptorError(
|
|
11716
11734
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -11722,7 +11740,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
11722
11740
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
11723
11741
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
11724
11742
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
11725
|
-
const csvTimelock =
|
|
11743
|
+
const csvTimelock = chunk6AFUNKK7_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
11726
11744
|
const base$1 = {
|
|
11727
11745
|
script: base.hex.encode(tapscript.pkScript),
|
|
11728
11746
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -11733,11 +11751,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
11733
11751
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
11734
11752
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
11735
11753
|
metadata: {
|
|
11736
|
-
...tagSource && { source:
|
|
11754
|
+
...tagSource && { source: chunkHL7EC2Z5_cjs.WALLET_RECEIVE_SOURCE },
|
|
11737
11755
|
signingDescriptor: descriptor
|
|
11738
11756
|
}
|
|
11739
11757
|
};
|
|
11740
|
-
const params = tapscript instanceof
|
|
11758
|
+
const params = tapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? {
|
|
11741
11759
|
...base$1,
|
|
11742
11760
|
type: "delegate",
|
|
11743
11761
|
params: {
|
|
@@ -11758,10 +11776,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
11758
11776
|
return { tapscript, params };
|
|
11759
11777
|
}
|
|
11760
11778
|
function rebuildTapscript(current, pubKey) {
|
|
11761
|
-
if (current instanceof
|
|
11762
|
-
return new
|
|
11779
|
+
if (current instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script) {
|
|
11780
|
+
return new chunkHL7EC2Z5_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
11763
11781
|
}
|
|
11764
|
-
return new
|
|
11782
|
+
return new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
11765
11783
|
}
|
|
11766
11784
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
11767
11785
|
const candidates = await contractRepository.getContracts({
|
|
@@ -11770,7 +11788,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
11770
11788
|
});
|
|
11771
11789
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
11772
11790
|
const matching = candidates.filter(
|
|
11773
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
11791
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkHL7EC2Z5_cjs.WALLET_RECEIVE_SOURCE
|
|
11774
11792
|
).sort((a, b) => {
|
|
11775
11793
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
11776
11794
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -11826,7 +11844,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
11826
11844
|
}
|
|
11827
11845
|
};
|
|
11828
11846
|
for (const vtxo of vtxos) {
|
|
11829
|
-
if (
|
|
11847
|
+
if (chunk6AFUNKK7_cjs.hasTerminalSpend(vtxo)) continue;
|
|
11830
11848
|
addAssets(owned, vtxo);
|
|
11831
11849
|
if (vtxo.isUnrolled) {
|
|
11832
11850
|
unrolled += vtxo.value;
|
|
@@ -11836,11 +11854,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
11836
11854
|
pendingRecovery += vtxo.value;
|
|
11837
11855
|
continue;
|
|
11838
11856
|
}
|
|
11839
|
-
if (
|
|
11857
|
+
if (chunk6AFUNKK7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
11840
11858
|
recoverable += vtxo.value;
|
|
11841
11859
|
continue;
|
|
11842
11860
|
}
|
|
11843
|
-
if (!
|
|
11861
|
+
if (!chunk6AFUNKK7_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
11844
11862
|
if (vtxo.isPreconfirmed) {
|
|
11845
11863
|
preconfirmed += vtxo.value;
|
|
11846
11864
|
} else {
|
|
@@ -12010,12 +12028,12 @@ var InputSignerRouter = class {
|
|
|
12010
12028
|
};
|
|
12011
12029
|
|
|
12012
12030
|
// src/wallet/wallet.ts
|
|
12013
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
12031
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunk6AFUNKK7_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12014
12032
|
function intentProofJobs(coins) {
|
|
12015
12033
|
if (coins.length === 0) return [];
|
|
12016
12034
|
const coinJobs = coins.map((coin, i) => ({
|
|
12017
12035
|
index: i + 1,
|
|
12018
|
-
lookupScript:
|
|
12036
|
+
lookupScript: chunk6AFUNKK7_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12019
12037
|
}));
|
|
12020
12038
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12021
12039
|
}
|
|
@@ -12047,7 +12065,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12047
12065
|
const seen = /* @__PURE__ */ new Set();
|
|
12048
12066
|
const deduped = [];
|
|
12049
12067
|
for (const timelock of timelocks) {
|
|
12050
|
-
const sequence =
|
|
12068
|
+
const sequence = chunk6AFUNKK7_cjs.timelockToSequence(timelock).toString();
|
|
12051
12069
|
if (seen.has(sequence)) continue;
|
|
12052
12070
|
seen.add(sequence);
|
|
12053
12071
|
deduped.push(timelock);
|
|
@@ -12064,7 +12082,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12064
12082
|
state: "active"
|
|
12065
12083
|
});
|
|
12066
12084
|
const newest = candidates.filter(
|
|
12067
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12085
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkHL7EC2Z5_cjs.WALLET_RECEIVE_SOURCE
|
|
12068
12086
|
).sort((a, b) => {
|
|
12069
12087
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12070
12088
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12072,7 +12090,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12072
12090
|
if (!newest?.params.pubKey) return baseline;
|
|
12073
12091
|
try {
|
|
12074
12092
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12075
|
-
return new
|
|
12093
|
+
return new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12076
12094
|
} catch (e) {
|
|
12077
12095
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12078
12096
|
return baseline;
|
|
@@ -12091,16 +12109,17 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12091
12109
|
if (vtxo.isUnrolled) {
|
|
12092
12110
|
return !!f.withUnrolled;
|
|
12093
12111
|
}
|
|
12094
|
-
if (
|
|
12112
|
+
if (chunk6AFUNKK7_cjs.hasTerminalSpend(vtxo)) {
|
|
12095
12113
|
return false;
|
|
12096
12114
|
}
|
|
12097
|
-
if (!f.withRecoverable &&
|
|
12115
|
+
if (!f.withRecoverable && chunk6AFUNKK7_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12098
12116
|
return false;
|
|
12099
12117
|
}
|
|
12100
12118
|
return true;
|
|
12101
12119
|
});
|
|
12102
12120
|
}
|
|
12103
12121
|
var PENDING_RECOVERY_REASON = "is past its operator signer's rotation cutoff \u2014 the operator will not co-sign it until it recovers";
|
|
12122
|
+
var UNROLLED_REASON = "was unilaterally exited and lives onchain \u2014 `Unroll.completeUnroll` is the only spend that reaches it";
|
|
12104
12123
|
function omittedOutpoints(before, after) {
|
|
12105
12124
|
if (before.length === after.length) return /* @__PURE__ */ new Set();
|
|
12106
12125
|
const kept = new Set(after.map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
@@ -12143,10 +12162,11 @@ var ArkadeCashCreateError = class extends Error {
|
|
|
12143
12162
|
cause;
|
|
12144
12163
|
};
|
|
12145
12164
|
var ReadonlyWallet = class _ReadonlyWallet {
|
|
12146
|
-
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, walletContractTimelocks) {
|
|
12165
|
+
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, walletContractTimelocks) {
|
|
12147
12166
|
this.identity = identity;
|
|
12148
12167
|
this.network = network;
|
|
12149
12168
|
this.onchainProvider = onchainProvider;
|
|
12169
|
+
this.arkProvider = arkProvider;
|
|
12150
12170
|
this.indexerProvider = indexerProvider;
|
|
12151
12171
|
this.dustAmount = dustAmount;
|
|
12152
12172
|
this.walletRepository = walletRepository;
|
|
@@ -12172,6 +12192,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12172
12192
|
identity;
|
|
12173
12193
|
network;
|
|
12174
12194
|
onchainProvider;
|
|
12195
|
+
arkProvider;
|
|
12175
12196
|
indexerProvider;
|
|
12176
12197
|
dustAmount;
|
|
12177
12198
|
walletRepository;
|
|
@@ -12239,14 +12260,19 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12239
12260
|
*/
|
|
12240
12261
|
_arkServerPublicKey;
|
|
12241
12262
|
/**
|
|
12242
|
-
* Whether
|
|
12243
|
-
*
|
|
12244
|
-
* (`"cache"`).
|
|
12263
|
+
* Whether the LATEST server-info resolution answered live (`"live"`) or
|
|
12264
|
+
* from the cached snapshot because the operator was unreachable
|
|
12265
|
+
* (`"cache"`). Seeded at construction and updated by every
|
|
12266
|
+
* {@link getArkadeInfo} read, so a wallet that booted offline and
|
|
12267
|
+
* recovered stops reporting degraded — and one that just fell back stops
|
|
12268
|
+
* claiming online. Freshness signal for
|
|
12269
|
+
* {@link getProviderConnectionState}.
|
|
12245
12270
|
*/
|
|
12246
12271
|
_serverInfoSource = "live";
|
|
12247
12272
|
/**
|
|
12248
|
-
* Epoch-ms of the last known live operator contact:
|
|
12249
|
-
*
|
|
12273
|
+
* Epoch-ms of the last known live operator contact: the most recent live
|
|
12274
|
+
* resolution (construction or a later {@link getArkadeInfo}), or the
|
|
12275
|
+
* cached snapshot's `savedAt` when the latest resolution fell back.
|
|
12250
12276
|
*/
|
|
12251
12277
|
_serverInfoLastOnlineAt;
|
|
12252
12278
|
/** @see {@link _serverInfoSource} */
|
|
@@ -12254,13 +12280,15 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12254
12280
|
return this._serverInfoSource;
|
|
12255
12281
|
}
|
|
12256
12282
|
/**
|
|
12257
|
-
* Composed provider-connection freshness: the
|
|
12258
|
-
* (
|
|
12259
|
-
* manager
|
|
12260
|
-
*
|
|
12261
|
-
*
|
|
12283
|
+
* Composed provider-connection freshness: the LATEST server-info
|
|
12284
|
+
* resolution (boot, or any later {@link getArkadeInfo} read) combined with
|
|
12285
|
+
* the contract-manager's indexer-sync health, if the manager has been
|
|
12286
|
+
* initialized. Reads no live provider state — it never forces a
|
|
12287
|
+
* `ContractManager` to construct — so it is safe for readonly callers
|
|
12288
|
+
* that only use address/balance APIs.
|
|
12262
12289
|
*
|
|
12263
|
-
* -
|
|
12290
|
+
* - Latest resolution fell back to the cached snapshot → degraded on
|
|
12291
|
+
* `arkade` (`cache`).
|
|
12264
12292
|
* - Otherwise, if the contract manager has degraded to repository data →
|
|
12265
12293
|
* degraded on `indexer` (`repository`).
|
|
12266
12294
|
* - Otherwise online.
|
|
@@ -12306,7 +12334,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12306
12334
|
}
|
|
12307
12335
|
/**
|
|
12308
12336
|
* x-only hex of the operator's deprecated signer keys (from
|
|
12309
|
-
* `
|
|
12337
|
+
* `ArkadeInfo.deprecatedSigners`), cached for the OFFLINE read/watch paths.
|
|
12310
12338
|
* The boarding watch/history surfaces ({@link getBoardingAddresses},
|
|
12311
12339
|
* {@link getBoardingTxs}) fan out over {current} ∪ this set so a deposit at
|
|
12312
12340
|
* a boarding address minted under a now-rotated operator signer keeps being
|
|
@@ -12381,6 +12409,64 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12381
12409
|
get arkServerPublicKey() {
|
|
12382
12410
|
return this._arkServerPublicKey;
|
|
12383
12411
|
}
|
|
12412
|
+
/**
|
|
12413
|
+
* Server info for the Arkade server this wallet is connected to, resolved
|
|
12414
|
+
* exactly as construction resolves it: live wins, a retryable failure
|
|
12415
|
+
* falls back to the snapshot persisted at boot, a terminal one propagates.
|
|
12416
|
+
*
|
|
12417
|
+
* Live rather than the pinned boot snapshot because the fields callers
|
|
12418
|
+
* come here for — `signerPubkey`, `checkpointTapscript`, `fees` — are the
|
|
12419
|
+
* ones a mid-session rotation moves, and a covenant built against a
|
|
12420
|
+
* superseded signer is unspendable.
|
|
12421
|
+
*
|
|
12422
|
+
* One rotation caveat: reading does NOT re-pin the wallet —
|
|
12423
|
+
* {@link arkServerPublicKey}, {@link dustAmount} and the tapscripts move
|
|
12424
|
+
* only through `handleServerInfoChanged`/`rotateServerSigner` — so inside
|
|
12425
|
+
* a rotation window this can report epoch N+1 while the wallet still
|
|
12426
|
+
* spends on N. The window closes on its own: a read that observes a moved
|
|
12427
|
+
* digest makes the provider emit `onServerInfoChanged`, which is what
|
|
12428
|
+
* drives that rotation. A caller about to bind the answer into a covenant
|
|
12429
|
+
* passes `{ requireLive: true }` and fails closed instead of receiving
|
|
12430
|
+
* the boot snapshot.
|
|
12431
|
+
*
|
|
12432
|
+
* @returns The Arkade server's info
|
|
12433
|
+
* @see ArkadeInfo
|
|
12434
|
+
*/
|
|
12435
|
+
async getArkadeInfo(opts) {
|
|
12436
|
+
const { info, source, lastOnlineAt } = await resolveArkInfo(
|
|
12437
|
+
this.arkProvider,
|
|
12438
|
+
this.walletRepository,
|
|
12439
|
+
opts
|
|
12440
|
+
);
|
|
12441
|
+
this._serverInfoSource = source;
|
|
12442
|
+
if (source === "live") {
|
|
12443
|
+
this._serverInfoLastOnlineAt = Date.now();
|
|
12444
|
+
} else if (lastOnlineAt !== void 0) {
|
|
12445
|
+
this._serverInfoLastOnlineAt = lastOnlineAt;
|
|
12446
|
+
}
|
|
12447
|
+
return info;
|
|
12448
|
+
}
|
|
12449
|
+
/**
|
|
12450
|
+
* Chain reads against this wallet's server for scripts it does not own.
|
|
12451
|
+
*
|
|
12452
|
+
* Binds the wallet's own `indexerProvider` — which may be an Expo or
|
|
12453
|
+
* injected one that a caller's hand-built `RestIndexerProvider` would
|
|
12454
|
+
* silently bypass. `getVtxos` goes through
|
|
12455
|
+
* {@link getNormalizedVtxos}, which is what makes every VTXO leaving the
|
|
12456
|
+
* seam carry its canonical facts.
|
|
12457
|
+
*
|
|
12458
|
+
* A bound object rather than the provider itself, so an `IReadonlyWallet`
|
|
12459
|
+
* holder gets `getVtxos`/`getVirtualTxs` and nothing else at runtime.
|
|
12460
|
+
* (`indexerProvider` is still public on the concrete classes, unlike
|
|
12461
|
+
* `arkProvider`, so this narrows the interface rather than the field.)
|
|
12462
|
+
*/
|
|
12463
|
+
async getArkadeReader() {
|
|
12464
|
+
const indexer = this.indexerProvider;
|
|
12465
|
+
return {
|
|
12466
|
+
getVtxos: (opts) => chunk6AFUNKK7_cjs.getNormalizedVtxos(indexer, opts),
|
|
12467
|
+
getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
|
|
12468
|
+
};
|
|
12469
|
+
}
|
|
12384
12470
|
/**
|
|
12385
12471
|
* The wallet's current boarding tapscript (the on-chain onboarding
|
|
12386
12472
|
* target). Read-only from the outside; mutated only via
|
|
@@ -12433,7 +12519,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12433
12519
|
*/
|
|
12434
12520
|
static async setupWalletConfig(config, pubKey) {
|
|
12435
12521
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
12436
|
-
const arkProvider = config.arkProvider || new
|
|
12522
|
+
const arkProvider = config.arkProvider || new chunk6AFUNKK7_cjs.RestArkProvider(arkadeServerUrl);
|
|
12437
12523
|
let indexerProvider = config.indexerProvider;
|
|
12438
12524
|
if (!indexerProvider) {
|
|
12439
12525
|
let indexerUrl = config.indexerUrl;
|
|
@@ -12450,7 +12536,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12450
12536
|
indexerUrl = arkadeServerUrl;
|
|
12451
12537
|
}
|
|
12452
12538
|
}
|
|
12453
|
-
indexerProvider = new
|
|
12539
|
+
indexerProvider = new chunkCZ32XADN_cjs.RestIndexerProvider(indexerUrl);
|
|
12454
12540
|
}
|
|
12455
12541
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
12456
12542
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -12459,7 +12545,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12459
12545
|
source: serverInfoSource,
|
|
12460
12546
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
12461
12547
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
12462
|
-
const network =
|
|
12548
|
+
const network = chunk6AFUNKK7_cjs.networkFromArkadeInfo(info);
|
|
12463
12549
|
if ("descriptor" in config.identity) {
|
|
12464
12550
|
const descriptor = config.identity.descriptor;
|
|
12465
12551
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -12499,18 +12585,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12499
12585
|
value: info.boardingExitDelay,
|
|
12500
12586
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
12501
12587
|
};
|
|
12502
|
-
const serverPubKey =
|
|
12503
|
-
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) =>
|
|
12588
|
+
const serverPubKey = chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
12589
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
|
|
12504
12590
|
const offchainOptions = {
|
|
12505
12591
|
pubKey,
|
|
12506
12592
|
serverPubKey,
|
|
12507
12593
|
csvTimelock: exitTimelock
|
|
12508
12594
|
};
|
|
12509
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
12510
|
-
const boardingTapscript =
|
|
12595
|
+
const offchainTapscript = !delegatePubKey ? new chunkHL7EC2Z5_cjs.DefaultVtxo.Script(offchainOptions) : new chunkHL7EC2Z5_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
12596
|
+
const boardingTapscript = chunkHL7EC2Z5_cjs.BoardingContractHandler.createScript({
|
|
12511
12597
|
pubKey: base.hex.encode(pubKey),
|
|
12512
12598
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
12513
|
-
csvTimelock:
|
|
12599
|
+
csvTimelock: chunk6AFUNKK7_cjs.timelockToSequence(boardingTimelock).toString()
|
|
12514
12600
|
});
|
|
12515
12601
|
return {
|
|
12516
12602
|
arkProvider,
|
|
@@ -12549,6 +12635,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12549
12635
|
config.identity,
|
|
12550
12636
|
setup.network,
|
|
12551
12637
|
setup.onchainProvider,
|
|
12638
|
+
setup.arkProvider,
|
|
12552
12639
|
setup.indexerProvider,
|
|
12553
12640
|
setup.serverPubKey,
|
|
12554
12641
|
setup.offchainTapscript,
|
|
@@ -12673,6 +12760,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12673
12760
|
"is locked by an in-flight settlement intent"
|
|
12674
12761
|
)
|
|
12675
12762
|
]);
|
|
12763
|
+
if (!filter?.withUnrolled) {
|
|
12764
|
+
logExcludedVtxos(
|
|
12765
|
+
"getSpendableVtxos",
|
|
12766
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunk6AFUNKK7_cjs.hasTerminalSpend(vtxo)),
|
|
12767
|
+
[() => UNROLLED_REASON]
|
|
12768
|
+
);
|
|
12769
|
+
}
|
|
12676
12770
|
return unlocked;
|
|
12677
12771
|
}
|
|
12678
12772
|
/**
|
|
@@ -12812,7 +12906,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12812
12906
|
const response = await contractManager.getContractsWithVtxos();
|
|
12813
12907
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
12814
12908
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
12815
|
-
const resolveTxCreatedAt = (txids) =>
|
|
12909
|
+
const resolveTxCreatedAt = (txids) => chunk6AFUNKK7_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
12816
12910
|
return buildTransactionHistory(
|
|
12817
12911
|
allVtxos,
|
|
12818
12912
|
boardingTxs,
|
|
@@ -12906,7 +13000,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12906
13000
|
},
|
|
12907
13001
|
isUnrolled: true,
|
|
12908
13002
|
...boardingFacts,
|
|
12909
|
-
virtualStatus:
|
|
13003
|
+
virtualStatus: chunk6AFUNKK7_cjs.toVirtualStatus(boardingFacts),
|
|
12910
13004
|
spentBy: "",
|
|
12911
13005
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
12912
13006
|
script: scriptHex
|
|
@@ -12962,9 +13056,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12962
13056
|
async getBoardingTapscripts(allowedSigners) {
|
|
12963
13057
|
const byScript = /* @__PURE__ */ new Map();
|
|
12964
13058
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
12965
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13059
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkHL7EC2Z5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
12966
13060
|
add(
|
|
12967
|
-
new
|
|
13061
|
+
new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
12968
13062
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
12969
13063
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
12970
13064
|
csvTimelock: boardingCsv
|
|
@@ -12979,7 +13073,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12979
13073
|
for (const c of boardingContracts) {
|
|
12980
13074
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
12981
13075
|
try {
|
|
12982
|
-
add(
|
|
13076
|
+
add(chunkHL7EC2Z5_cjs.BoardingContractHandler.createScript(c.params));
|
|
12983
13077
|
} catch (e) {
|
|
12984
13078
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
12985
13079
|
}
|
|
@@ -13017,7 +13111,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13017
13111
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13018
13112
|
// not the wallet's current boarding timelock, which a signer
|
|
13019
13113
|
// rotation may have changed.
|
|
13020
|
-
csvTimelock:
|
|
13114
|
+
csvTimelock: chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13021
13115
|
coins: utxos
|
|
13022
13116
|
});
|
|
13023
13117
|
}
|
|
@@ -13150,7 +13244,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13150
13244
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13151
13245
|
async fetchPendingTxs() {
|
|
13152
13246
|
const scripts = await this.getWalletScripts();
|
|
13153
|
-
const vtxos = await
|
|
13247
|
+
const vtxos = await chunk6AFUNKK7_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13154
13248
|
return vtxos.filter(
|
|
13155
13249
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13156
13250
|
).map((_) => _.arkTxId);
|
|
@@ -13181,7 +13275,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13181
13275
|
});
|
|
13182
13276
|
for (const contract of contracts) {
|
|
13183
13277
|
if (map.has(contract.script)) continue;
|
|
13184
|
-
const handler =
|
|
13278
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
13185
13279
|
if (handler) {
|
|
13186
13280
|
const script = handler.createScript(contract.params);
|
|
13187
13281
|
map.set(contract.script, script);
|
|
@@ -13293,7 +13387,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13293
13387
|
}
|
|
13294
13388
|
});
|
|
13295
13389
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
13296
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
13390
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
13297
13391
|
const baselineSigners = [
|
|
13298
13392
|
this.offchainTapscript.options.serverPubKey,
|
|
13299
13393
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -13301,8 +13395,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13301
13395
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
13302
13396
|
for (const serverPubKey of baselineSigners) {
|
|
13303
13397
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
13304
|
-
const csvTimelockStr =
|
|
13305
|
-
const defaultScript = new
|
|
13398
|
+
const csvTimelockStr = chunk6AFUNKK7_cjs.timelockToSequence(csvTimelock).toString();
|
|
13399
|
+
const defaultScript = new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
13306
13400
|
pubKey: baselinePubkey,
|
|
13307
13401
|
serverPubKey,
|
|
13308
13402
|
csvTimelock
|
|
@@ -13323,7 +13417,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13323
13417
|
});
|
|
13324
13418
|
}
|
|
13325
13419
|
if (delegatePubKey) {
|
|
13326
|
-
const delegateScript = new
|
|
13420
|
+
const delegateScript = new chunkHL7EC2Z5_cjs.DelegateVtxo.Script({
|
|
13327
13421
|
pubKey: baselinePubkey,
|
|
13328
13422
|
serverPubKey,
|
|
13329
13423
|
delegatePubKey,
|
|
@@ -13347,9 +13441,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13347
13441
|
}
|
|
13348
13442
|
}
|
|
13349
13443
|
}
|
|
13350
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
13444
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkHL7EC2Z5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13351
13445
|
for (const serverPubKey of baselineSigners) {
|
|
13352
|
-
const baselineBoarding = new
|
|
13446
|
+
const baselineBoarding = new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
13353
13447
|
pubKey: baselinePubkey,
|
|
13354
13448
|
serverPubKey,
|
|
13355
13449
|
csvTimelock: boardingCsvTimelock
|
|
@@ -13362,7 +13456,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13362
13456
|
params: {
|
|
13363
13457
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
13364
13458
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13365
|
-
csvTimelock:
|
|
13459
|
+
csvTimelock: chunk6AFUNKK7_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
13366
13460
|
},
|
|
13367
13461
|
script: boardingScriptHex,
|
|
13368
13462
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -13389,6 +13483,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13389
13483
|
identity,
|
|
13390
13484
|
network,
|
|
13391
13485
|
onchainProvider,
|
|
13486
|
+
arkProvider,
|
|
13392
13487
|
indexerProvider,
|
|
13393
13488
|
arkServerPublicKey,
|
|
13394
13489
|
offchainTapscript,
|
|
@@ -13400,7 +13495,6 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13400
13495
|
watcherConfig,
|
|
13401
13496
|
walletContractTimelocks
|
|
13402
13497
|
);
|
|
13403
|
-
this.arkProvider = arkProvider;
|
|
13404
13498
|
this.forfeitOutputScript = forfeitOutputScript;
|
|
13405
13499
|
this.forfeitPubkey = forfeitPubkey;
|
|
13406
13500
|
this.batchExpiryPolicy = batchExpiryPolicy;
|
|
@@ -13434,7 +13528,6 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13434
13528
|
boardingPkScript: boardingTapscript.pkScript
|
|
13435
13529
|
});
|
|
13436
13530
|
}
|
|
13437
|
-
arkProvider;
|
|
13438
13531
|
forfeitOutputScript;
|
|
13439
13532
|
forfeitPubkey;
|
|
13440
13533
|
batchExpiryPolicy;
|
|
@@ -13562,7 +13655,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13562
13655
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
13563
13656
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
13564
13657
|
csvTimelocks: this.walletContractTimelocks,
|
|
13565
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
13658
|
+
delegatePubKey: this.offchainTapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
13566
13659
|
};
|
|
13567
13660
|
}
|
|
13568
13661
|
_signerRouter;
|
|
@@ -13597,7 +13690,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13597
13690
|
/**
|
|
13598
13691
|
* Output script for checkpoint transactions, decoded from the server's
|
|
13599
13692
|
* `checkpointTapscript`. Server-controlled state: pinned at construction
|
|
13600
|
-
* and re-sourced from a fresh `
|
|
13693
|
+
* and re-sourced from a fresh `ArkadeInfo` on server-signer rotation. Read it
|
|
13601
13694
|
* through {@link serverUnrollScript}; write it only through
|
|
13602
13695
|
* {@link setServerUnrollScriptForRotation}.
|
|
13603
13696
|
*/
|
|
@@ -13608,7 +13701,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13608
13701
|
/**
|
|
13609
13702
|
* @internal Sole write path for `serverUnrollScript` after construction.
|
|
13610
13703
|
* Called by {@link Wallet._doRotateServerSigner} with the checkpoint script
|
|
13611
|
-
* sourced from the fresh `
|
|
13704
|
+
* sourced from the fresh `ArkadeInfo` that triggered the rotation, so the send
|
|
13612
13705
|
* path builds checkpoints against the new server epoch. External code must
|
|
13613
13706
|
* treat `serverUnrollScript` as read-only.
|
|
13614
13707
|
*/
|
|
@@ -13807,7 +13900,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13807
13900
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
13808
13901
|
const persisted = row?.metadata?.signingDescriptor;
|
|
13809
13902
|
if (typeof persisted === "string") return persisted;
|
|
13810
|
-
return
|
|
13903
|
+
return chunkHL7EC2Z5_cjs.identityDescriptor(this.identity);
|
|
13811
13904
|
}
|
|
13812
13905
|
/**
|
|
13813
13906
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -13823,7 +13916,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13823
13916
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
13824
13917
|
if (type === "boarding") {
|
|
13825
13918
|
const built2 = this.buildBoardingContract(
|
|
13826
|
-
|
|
13919
|
+
chunkHL7EC2Z5_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
13827
13920
|
descriptor,
|
|
13828
13921
|
tagSource
|
|
13829
13922
|
);
|
|
@@ -13868,11 +13961,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13868
13961
|
* {@link buildReceiveContract}.
|
|
13869
13962
|
*/
|
|
13870
13963
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
13871
|
-
const tapscript = new
|
|
13964
|
+
const tapscript = new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
13872
13965
|
...this._boardingTapscript.options,
|
|
13873
13966
|
pubKey
|
|
13874
13967
|
});
|
|
13875
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
13968
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkHL7EC2Z5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13876
13969
|
return {
|
|
13877
13970
|
tapscript,
|
|
13878
13971
|
params: {
|
|
@@ -13880,13 +13973,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13880
13973
|
params: {
|
|
13881
13974
|
pubKey: base.hex.encode(pubKey),
|
|
13882
13975
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
13883
|
-
csvTimelock:
|
|
13976
|
+
csvTimelock: chunk6AFUNKK7_cjs.timelockToSequence(csvTimelock).toString()
|
|
13884
13977
|
},
|
|
13885
13978
|
script: base.hex.encode(tapscript.pkScript),
|
|
13886
13979
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
13887
13980
|
state: "active",
|
|
13888
13981
|
metadata: {
|
|
13889
|
-
...tagSource && { source:
|
|
13982
|
+
...tagSource && { source: chunkHL7EC2Z5_cjs.WALLET_RECEIVE_SOURCE },
|
|
13890
13983
|
signingDescriptor: descriptor
|
|
13891
13984
|
}
|
|
13892
13985
|
}
|
|
@@ -13915,7 +14008,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13915
14008
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
13916
14009
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
13917
14010
|
}
|
|
13918
|
-
return
|
|
14011
|
+
return chunkHL7EC2Z5_cjs.identityDescriptor(this.identity);
|
|
13919
14012
|
}
|
|
13920
14013
|
/**
|
|
13921
14014
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14011,7 +14104,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14011
14104
|
* the stable public API.
|
|
14012
14105
|
*/
|
|
14013
14106
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14014
|
-
const xonly =
|
|
14107
|
+
const xonly = chunkHL7EC2Z5_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14015
14108
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14016
14109
|
checkpointTapscript,
|
|
14017
14110
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14040,21 +14133,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14040
14133
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14041
14134
|
script: currentBoardingScript
|
|
14042
14135
|
});
|
|
14043
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14136
|
+
const newOffchain = this.offchainTapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? new chunkHL7EC2Z5_cjs.DelegateVtxo.Script({
|
|
14044
14137
|
...this.offchainTapscript.options,
|
|
14045
14138
|
serverPubKey: xonly
|
|
14046
|
-
}) : new
|
|
14139
|
+
}) : new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
14047
14140
|
...this.offchainTapscript.options,
|
|
14048
14141
|
serverPubKey: xonly
|
|
14049
14142
|
});
|
|
14050
|
-
const newBoarding = new
|
|
14143
|
+
const newBoarding = new chunkHL7EC2Z5_cjs.DefaultVtxo.Script({
|
|
14051
14144
|
...this._boardingTapscript.options,
|
|
14052
14145
|
serverPubKey: xonly
|
|
14053
14146
|
});
|
|
14054
|
-
const offchainCsv =
|
|
14147
|
+
const offchainCsv = chunk6AFUNKK7_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14055
14148
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14056
14149
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14057
|
-
if (newOffchain instanceof
|
|
14150
|
+
if (newOffchain instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script) {
|
|
14058
14151
|
await manager.createContract({
|
|
14059
14152
|
type: "delegate",
|
|
14060
14153
|
params: {
|
|
@@ -14082,13 +14175,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14082
14175
|
metadata: currentOffchainRow?.metadata
|
|
14083
14176
|
});
|
|
14084
14177
|
}
|
|
14085
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14178
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkHL7EC2Z5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14086
14179
|
await manager.createContract({
|
|
14087
14180
|
type: "boarding",
|
|
14088
14181
|
params: {
|
|
14089
14182
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14090
14183
|
serverPubKey: base.hex.encode(xonly),
|
|
14091
|
-
csvTimelock:
|
|
14184
|
+
csvTimelock: chunk6AFUNKK7_cjs.timelockToSequence(boardingCsv).toString()
|
|
14092
14185
|
},
|
|
14093
14186
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14094
14187
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14121,14 +14214,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14121
14214
|
_restoreInFlight;
|
|
14122
14215
|
_addPendingSpends(inputs) {
|
|
14123
14216
|
for (const input of inputs) {
|
|
14124
|
-
if (
|
|
14217
|
+
if (chunk6AFUNKK7_cjs.isVirtualCoin(input)) {
|
|
14125
14218
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14126
14219
|
}
|
|
14127
14220
|
}
|
|
14128
14221
|
}
|
|
14129
14222
|
_removePendingSpends(inputs) {
|
|
14130
14223
|
for (const input of inputs) {
|
|
14131
|
-
if (
|
|
14224
|
+
if (chunk6AFUNKK7_cjs.isVirtualCoin(input)) {
|
|
14132
14225
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14133
14226
|
}
|
|
14134
14227
|
}
|
|
@@ -14186,13 +14279,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14186
14279
|
const manager = await this.getContractManager();
|
|
14187
14280
|
const provider = this._descriptorProvider;
|
|
14188
14281
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14189
|
-
const staticDescriptor = hd ? void 0 : await
|
|
14282
|
+
const staticDescriptor = hd ? void 0 : await chunkHL7EC2Z5_cjs.identityDescriptor(this.identity);
|
|
14190
14283
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14191
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14284
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkHL7EC2Z5_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14192
14285
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14193
|
-
const currentSignerPubKey =
|
|
14286
|
+
const currentSignerPubKey = chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14194
14287
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14195
|
-
(s) =>
|
|
14288
|
+
(s) => chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14196
14289
|
);
|
|
14197
14290
|
const deps = {
|
|
14198
14291
|
indexerProvider: this.indexerProvider,
|
|
@@ -14207,7 +14300,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14207
14300
|
csvTimelocks: this.walletContractTimelocks,
|
|
14208
14301
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14209
14302
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14210
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
14303
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkHL7EC2Z5_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14211
14304
|
delegatePubKey
|
|
14212
14305
|
};
|
|
14213
14306
|
const result = await manager.scanContracts({
|
|
@@ -14240,6 +14333,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14240
14333
|
/** @deprecated Use settlementConfig instead */
|
|
14241
14334
|
renewalConfig;
|
|
14242
14335
|
settlementConfig;
|
|
14336
|
+
/**
|
|
14337
|
+
* Broadcast access bound to this wallet's server, so a plugin needs only
|
|
14338
|
+
* the wallet.
|
|
14339
|
+
*
|
|
14340
|
+
* Defined here and not on {@link ReadonlyWallet} for the same reason
|
|
14341
|
+
* `arkProvider` is protected there: a readonly wallet, and every
|
|
14342
|
+
* `toReadonly()` view, must not be able to submit.
|
|
14343
|
+
*/
|
|
14344
|
+
async getArkadeBroadcaster() {
|
|
14345
|
+
const ark = this.arkProvider;
|
|
14346
|
+
return {
|
|
14347
|
+
submitTx: (signedArkTx, checkpointTxs) => ark.submitTx(signedArkTx, checkpointTxs),
|
|
14348
|
+
finalizeTx: (arkTxid, finalCheckpointTxs) => ark.finalizeTx(arkTxid, finalCheckpointTxs)
|
|
14349
|
+
};
|
|
14350
|
+
}
|
|
14243
14351
|
get assetManager() {
|
|
14244
14352
|
this._walletAssetManager ??= new AssetManager(this);
|
|
14245
14353
|
return this._walletAssetManager;
|
|
@@ -14321,7 +14429,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14321
14429
|
throw new Error("Invalid configured public key");
|
|
14322
14430
|
}
|
|
14323
14431
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
14324
|
-
const forfeitPubkey =
|
|
14432
|
+
const forfeitPubkey = chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
14325
14433
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
14326
14434
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
14327
14435
|
const checkpointExitDelayOverrides = {
|
|
@@ -14419,6 +14527,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14419
14527
|
readonlyIdentity,
|
|
14420
14528
|
this.network,
|
|
14421
14529
|
this.onchainProvider,
|
|
14530
|
+
this.arkProvider,
|
|
14422
14531
|
this.indexerProvider,
|
|
14423
14532
|
this.arkServerPublicKey,
|
|
14424
14533
|
this.offchainTapscript,
|
|
@@ -14470,8 +14579,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14470
14579
|
inputs: params.selectedVtxos,
|
|
14471
14580
|
changeAmount: BigInt(changeAmount)
|
|
14472
14581
|
};
|
|
14473
|
-
const outputAddress =
|
|
14474
|
-
|
|
14582
|
+
const outputAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(params.address);
|
|
14583
|
+
assertRecipientArkadeAddress(
|
|
14475
14584
|
params.address,
|
|
14476
14585
|
outputAddress,
|
|
14477
14586
|
this.recipientAddressContext(serverPubKey)
|
|
@@ -14536,13 +14645,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14536
14645
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
14537
14646
|
}
|
|
14538
14647
|
const offchainAddress = await this.getAddress();
|
|
14539
|
-
const offchainPkScript =
|
|
14648
|
+
const offchainPkScript = chunk6AFUNKK7_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
14540
14649
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
14541
14650
|
if (!params) {
|
|
14542
14651
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
14543
14652
|
const estimator = new Estimator(fees.intentFee);
|
|
14544
14653
|
let amount = 0;
|
|
14545
|
-
const exitScript =
|
|
14654
|
+
const exitScript = chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(
|
|
14546
14655
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
14547
14656
|
);
|
|
14548
14657
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -14571,7 +14680,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14571
14680
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
14572
14681
|
break;
|
|
14573
14682
|
}
|
|
14574
|
-
const inputFee = estimator.evalOffchainInput(
|
|
14683
|
+
const inputFee = estimator.evalOffchainInput(chunk6AFUNKK7_cjs.toOffchainInputFeeParams(vtxo));
|
|
14575
14684
|
if (inputFee.satoshis >= vtxo.value) {
|
|
14576
14685
|
continue;
|
|
14577
14686
|
}
|
|
@@ -14618,13 +14727,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14618
14727
|
let script;
|
|
14619
14728
|
let arkAddress;
|
|
14620
14729
|
try {
|
|
14621
|
-
arkAddress =
|
|
14730
|
+
arkAddress = chunk6AFUNKK7_cjs.ArkAddress.decode(output.address);
|
|
14622
14731
|
} catch {
|
|
14623
14732
|
arkAddress = void 0;
|
|
14624
14733
|
}
|
|
14625
14734
|
if (arkAddress) {
|
|
14626
14735
|
recipientContext ??= this.recipientAddressContext();
|
|
14627
|
-
|
|
14736
|
+
assertRecipientArkadeAddress(output.address, arkAddress, recipientContext);
|
|
14628
14737
|
script = arkAddress.pkScript;
|
|
14629
14738
|
hasOffchainOutputs = true;
|
|
14630
14739
|
} else {
|
|
@@ -14708,7 +14817,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14708
14817
|
const abortController = new AbortController();
|
|
14709
14818
|
let stream;
|
|
14710
14819
|
let committedTxid;
|
|
14711
|
-
const settleInputVtxos = params.inputs.filter(
|
|
14820
|
+
const settleInputVtxos = params.inputs.filter(chunk6AFUNKK7_cjs.isVirtualCoin);
|
|
14712
14821
|
const contractManager = await this.getContractManager();
|
|
14713
14822
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
14714
14823
|
await contractManager.assertSpendableNow?.(
|
|
@@ -14820,7 +14929,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14820
14929
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
14821
14930
|
if (!this._descriptorProvider) return;
|
|
14822
14931
|
const consumedBoarding = inputs.some(
|
|
14823
|
-
(input) => typeof input !== "string" && !
|
|
14932
|
+
(input) => typeof input !== "string" && !chunk6AFUNKK7_cjs.isVirtualCoin(input)
|
|
14824
14933
|
);
|
|
14825
14934
|
if (!consumedBoarding) return;
|
|
14826
14935
|
try {
|
|
@@ -14844,7 +14953,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14844
14953
|
let connectorIndex = 0;
|
|
14845
14954
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
14846
14955
|
for (const input of inputs) {
|
|
14847
|
-
if (!
|
|
14956
|
+
if (!chunk6AFUNKK7_cjs.isVirtualCoin(input)) {
|
|
14848
14957
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
14849
14958
|
const settlementInput = settlementPsbt.getInput(i);
|
|
14850
14959
|
if (!settlementInput.txid || settlementInput.index === void 0) {
|
|
@@ -14875,7 +14984,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14875
14984
|
}
|
|
14876
14985
|
continue;
|
|
14877
14986
|
}
|
|
14878
|
-
if (
|
|
14987
|
+
if (chunk6AFUNKK7_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
14879
14988
|
continue;
|
|
14880
14989
|
}
|
|
14881
14990
|
if (connectorsLeaves.length === 0) {
|
|
@@ -14903,7 +15012,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14903
15012
|
index: input.vout,
|
|
14904
15013
|
witnessUtxo: {
|
|
14905
15014
|
amount: BigInt(input.value),
|
|
14906
|
-
script:
|
|
15015
|
+
script: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
14907
15016
|
},
|
|
14908
15017
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
14909
15018
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -14922,7 +15031,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14922
15031
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
14923
15032
|
{
|
|
14924
15033
|
index: 0,
|
|
14925
|
-
lookupScript:
|
|
15034
|
+
lookupScript: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
14926
15035
|
}
|
|
14927
15036
|
]);
|
|
14928
15037
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -14980,7 +15089,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14980
15089
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
14981
15090
|
);
|
|
14982
15091
|
await this.arkProvider.confirmRegistration(intentId);
|
|
14983
|
-
const sweepTapscript =
|
|
15092
|
+
const sweepTapscript = chunk6AFUNKK7_cjs.CSVMultisigTapscript.encode({
|
|
14984
15093
|
timelock,
|
|
14985
15094
|
pubkeys: [this.forfeitPubkey]
|
|
14986
15095
|
}).script;
|
|
@@ -14995,10 +15104,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14995
15104
|
throw new Error("Sweep tap tree root not set");
|
|
14996
15105
|
}
|
|
14997
15106
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
14998
|
-
(k) => base.hex.encode(
|
|
15107
|
+
(k) => base.hex.encode(chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
14999
15108
|
);
|
|
15000
15109
|
const signerPublicKey = await session.getPublicKey();
|
|
15001
|
-
const xonlySignerPublicKey =
|
|
15110
|
+
const xonlySignerPublicKey = chunkHL7EC2Z5_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15002
15111
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15003
15112
|
return { skip: true };
|
|
15004
15113
|
}
|
|
@@ -15088,9 +15197,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15088
15197
|
...existing ?? {},
|
|
15089
15198
|
intentTxId,
|
|
15090
15199
|
registerProof: intent.proof,
|
|
15091
|
-
registerProofMessage:
|
|
15200
|
+
registerProofMessage: chunk6AFUNKK7_cjs.Intent.encodeMessage(intent.message),
|
|
15092
15201
|
deleteProof: deleteIntent.proof,
|
|
15093
|
-
deleteProofMessage:
|
|
15202
|
+
deleteProofMessage: chunk6AFUNKK7_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15094
15203
|
intentVtxos: inputs.map((i) => ({
|
|
15095
15204
|
txid: i.txid,
|
|
15096
15205
|
vout: i.vout
|
|
@@ -15122,7 +15231,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15122
15231
|
try {
|
|
15123
15232
|
return await this.arkProvider.registerIntent(intent);
|
|
15124
15233
|
} catch (error) {
|
|
15125
|
-
if (error instanceof
|
|
15234
|
+
if (error instanceof chunk6AFUNKK7_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15126
15235
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15127
15236
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15128
15237
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15138,7 +15247,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15138
15247
|
expire_at: 0,
|
|
15139
15248
|
cosigners_public_keys: cosignerPubKeys
|
|
15140
15249
|
};
|
|
15141
|
-
const proof =
|
|
15250
|
+
const proof = chunk6AFUNKK7_cjs.Intent.create(message, coins, outputs);
|
|
15142
15251
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15143
15252
|
return {
|
|
15144
15253
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15150,7 +15259,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15150
15259
|
type: "delete",
|
|
15151
15260
|
expire_at: 0
|
|
15152
15261
|
};
|
|
15153
|
-
const proof =
|
|
15262
|
+
const proof = chunk6AFUNKK7_cjs.Intent.create(message, coins, []);
|
|
15154
15263
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15155
15264
|
return {
|
|
15156
15265
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15162,7 +15271,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15162
15271
|
type: "get-pending-tx",
|
|
15163
15272
|
expire_at: 0
|
|
15164
15273
|
};
|
|
15165
|
-
const proof =
|
|
15274
|
+
const proof = chunk6AFUNKK7_cjs.Intent.create(message, coins, []);
|
|
15166
15275
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15167
15276
|
return {
|
|
15168
15277
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15183,7 +15292,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15183
15292
|
if (!vtxos || vtxos.length === 0) {
|
|
15184
15293
|
const scriptMap = await this.getScriptMap();
|
|
15185
15294
|
const allExtended = [];
|
|
15186
|
-
const fetchedVtxos = await
|
|
15295
|
+
const fetchedVtxos = await chunk6AFUNKK7_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15187
15296
|
...scriptMap.keys()
|
|
15188
15297
|
]);
|
|
15189
15298
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -15225,9 +15334,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15225
15334
|
seen.add(pendingTx.arkTxid);
|
|
15226
15335
|
batchPending.push(pendingTx.arkTxid);
|
|
15227
15336
|
try {
|
|
15228
|
-
const checkpointTxs = pendingTx.signedCheckpointTxs.map(
|
|
15229
|
-
|
|
15230
|
-
|
|
15337
|
+
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
15338
|
+
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
15339
|
+
chunk6AFUNKK7_cjs.assertAllowedSighashTypes(tx);
|
|
15340
|
+
return tx;
|
|
15341
|
+
});
|
|
15231
15342
|
assertCheckpointsMatchInputs(
|
|
15232
15343
|
checkpointTxs,
|
|
15233
15344
|
checkpointInputs,
|
|
@@ -15297,11 +15408,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15297
15408
|
* against the current key alone would leave it pending forever.
|
|
15298
15409
|
*/
|
|
15299
15410
|
checkpointUnrollCandidates(info) {
|
|
15300
|
-
const current =
|
|
15411
|
+
const current = chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
15301
15412
|
const candidates = [this._serverUnrollScript, current];
|
|
15302
15413
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
15303
15414
|
candidates.push(
|
|
15304
|
-
|
|
15415
|
+
chunk6AFUNKK7_cjs.CSVMultisigTapscript.encode({
|
|
15305
15416
|
...current.params,
|
|
15306
15417
|
pubkeys: [base.hex.decode(deprecated)]
|
|
15307
15418
|
})
|
|
@@ -15392,10 +15503,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15392
15503
|
if (vtxos.length === 0) {
|
|
15393
15504
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
15394
15505
|
}
|
|
15395
|
-
const myPkScript =
|
|
15506
|
+
const myPkScript = chunk6AFUNKK7_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
15396
15507
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
15397
15508
|
let swept = 0;
|
|
15398
|
-
const drainable = vtxos.filter(
|
|
15509
|
+
const drainable = vtxos.filter(
|
|
15510
|
+
(vtxo) => !isSubdust(vtxo, this.dustAmount) && !vtxo.isUnrolled
|
|
15511
|
+
);
|
|
15399
15512
|
if (drainable.length > 0) {
|
|
15400
15513
|
let drained = { count: 0, swept: 0, claimed: /* @__PURE__ */ new Set() };
|
|
15401
15514
|
try {
|
|
@@ -15466,7 +15579,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15466
15579
|
const spendable = [];
|
|
15467
15580
|
const unclaimed = [];
|
|
15468
15581
|
for (const vtxo of vtxos) {
|
|
15469
|
-
if (
|
|
15582
|
+
if (chunk6AFUNKK7_cjs.hasTerminalSpend(vtxo)) {
|
|
15470
15583
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
15471
15584
|
} else if (vtxo.isUnrolled) {
|
|
15472
15585
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -15488,7 +15601,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15488
15601
|
const all = [];
|
|
15489
15602
|
const seen = /* @__PURE__ */ new Set();
|
|
15490
15603
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
15491
|
-
const { vtxos, page } = await
|
|
15604
|
+
const { vtxos, page } = await chunk6AFUNKK7_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
15492
15605
|
scripts,
|
|
15493
15606
|
pageIndex,
|
|
15494
15607
|
pageSize
|
|
@@ -15535,7 +15648,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15535
15648
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
15536
15649
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
15537
15650
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
15538
|
-
const proof =
|
|
15651
|
+
const proof = chunk6AFUNKK7_cjs.Intent.create(message, batch, []);
|
|
15539
15652
|
const signedProof = await identity.sign(
|
|
15540
15653
|
proof,
|
|
15541
15654
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -15555,9 +15668,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15555
15668
|
const unrollCandidates = this.checkpointUnrollCandidates(await this.arkProvider.getInfo());
|
|
15556
15669
|
for (const pendingTx of pendingTxs) {
|
|
15557
15670
|
try {
|
|
15558
|
-
const checkpointTxs = pendingTx.signedCheckpointTxs.map(
|
|
15559
|
-
|
|
15560
|
-
|
|
15671
|
+
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
15672
|
+
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
15673
|
+
chunk6AFUNKK7_cjs.assertAllowedSighashTypes(tx);
|
|
15674
|
+
return tx;
|
|
15675
|
+
});
|
|
15561
15676
|
assertCheckpointsMatchInputs(
|
|
15562
15677
|
checkpointTxs,
|
|
15563
15678
|
inputs.map((input) => ({
|
|
@@ -15754,7 +15869,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15754
15869
|
script: recipient.script,
|
|
15755
15870
|
amount: BigInt(recipient.amount),
|
|
15756
15871
|
// Already checked against the recipient address in `validateRecipients`.
|
|
15757
|
-
...recipient.tapTree ? { tapTree:
|
|
15872
|
+
...recipient.tapTree ? { tapTree: chunk6AFUNKK7_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
15758
15873
|
}));
|
|
15759
15874
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
15760
15875
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -15898,10 +16013,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15898
16013
|
const serverPubKey = this.arkServerPublicKey;
|
|
15899
16014
|
const serverUnrollScript = this.serverUnrollScript;
|
|
15900
16015
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
15901
|
-
const normalizedInputs = inputs.map(
|
|
15902
|
-
const at = now ?? await
|
|
16016
|
+
const normalizedInputs = inputs.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
16017
|
+
const at = now ?? await chunk6AFUNKK7_cjs.resolveTimeHeight(this.onchainProvider);
|
|
15903
16018
|
for (const input of normalizedInputs) {
|
|
15904
|
-
if (!
|
|
16019
|
+
if (!chunk6AFUNKK7_cjs.canSpendOffchain(input, at)) {
|
|
15905
16020
|
throw new Error(
|
|
15906
16021
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
15907
16022
|
);
|
|
@@ -15971,7 +16086,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15971
16086
|
);
|
|
15972
16087
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
15973
16088
|
index,
|
|
15974
|
-
lookupScript:
|
|
16089
|
+
lookupScript: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15975
16090
|
}));
|
|
15976
16091
|
const identity = this.identity;
|
|
15977
16092
|
const signer = {
|
|
@@ -16057,14 +16172,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16057
16172
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16058
16173
|
spentVtxos.push({
|
|
16059
16174
|
...spentFacts,
|
|
16060
|
-
virtualStatus:
|
|
16175
|
+
virtualStatus: chunk6AFUNKK7_cjs.toVirtualStatus(spentFacts),
|
|
16061
16176
|
...spentBy ? { spentBy } : {},
|
|
16062
16177
|
arkTxId: arkTxid
|
|
16063
16178
|
});
|
|
16064
16179
|
for (const id of vtxo.commitmentTxIds) {
|
|
16065
16180
|
commitmentTxIds.add(id);
|
|
16066
16181
|
}
|
|
16067
|
-
const vtxoExpiry =
|
|
16182
|
+
const vtxoExpiry = chunk6AFUNKK7_cjs.toBatchExpiry(vtxo);
|
|
16068
16183
|
if (vtxoExpiry) {
|
|
16069
16184
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16070
16185
|
}
|
|
@@ -16077,7 +16192,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16077
16192
|
isSwept: false,
|
|
16078
16193
|
isPreconfirmed: true,
|
|
16079
16194
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16080
|
-
...
|
|
16195
|
+
...chunk6AFUNKK7_cjs.parseLegacyExpiry(batchExpiry)
|
|
16081
16196
|
};
|
|
16082
16197
|
changeVtxo = {
|
|
16083
16198
|
txid: arkTxid,
|
|
@@ -16089,7 +16204,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16089
16204
|
tapTree: offchainTapscript.encode(),
|
|
16090
16205
|
value: Number(changeAmount),
|
|
16091
16206
|
...changeFacts,
|
|
16092
|
-
virtualStatus:
|
|
16207
|
+
virtualStatus: chunk6AFUNKK7_cjs.toVirtualStatus(changeFacts),
|
|
16093
16208
|
spentBy: "",
|
|
16094
16209
|
status: {
|
|
16095
16210
|
confirmed: false
|
|
@@ -16158,12 +16273,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16158
16273
|
const spentVtxos = [];
|
|
16159
16274
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16160
16275
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16161
|
-
const vtxoInputs = inputs.filter(
|
|
16276
|
+
const vtxoInputs = inputs.filter(chunk6AFUNKK7_cjs.isVirtualCoin);
|
|
16162
16277
|
const cm = await this.getContractManager();
|
|
16163
16278
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16164
16279
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16165
16280
|
for (const input of inputs) {
|
|
16166
|
-
if (
|
|
16281
|
+
if (chunk6AFUNKK7_cjs.isVirtualCoin(input)) {
|
|
16167
16282
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16168
16283
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16169
16284
|
if (!vtxo) {
|
|
@@ -16175,13 +16290,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16175
16290
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16176
16291
|
spentVtxos.push({
|
|
16177
16292
|
...settledFacts,
|
|
16178
|
-
virtualStatus:
|
|
16293
|
+
virtualStatus: chunk6AFUNKK7_cjs.toVirtualStatus(settledFacts),
|
|
16179
16294
|
settledBy: commitmentTxid
|
|
16180
16295
|
});
|
|
16181
16296
|
} else {
|
|
16182
16297
|
let sourceAddress;
|
|
16183
16298
|
try {
|
|
16184
|
-
sourceAddress =
|
|
16299
|
+
sourceAddress = chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16185
16300
|
this.network
|
|
16186
16301
|
);
|
|
16187
16302
|
} catch {
|
|
@@ -16239,9 +16354,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16239
16354
|
}
|
|
16240
16355
|
};
|
|
16241
16356
|
function selectVirtualCoins(coins, targetAmount) {
|
|
16242
|
-
const sortedCoins = coins.map(
|
|
16243
|
-
const expiryA =
|
|
16244
|
-
const expiryB =
|
|
16357
|
+
const sortedCoins = coins.map(chunk6AFUNKK7_cjs.normalizeVtxo).sort((a, b) => {
|
|
16358
|
+
const expiryA = chunk6AFUNKK7_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
16359
|
+
const expiryB = chunk6AFUNKK7_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
16245
16360
|
if (expiryA !== expiryB) {
|
|
16246
16361
|
return expiryA - expiryB;
|
|
16247
16362
|
}
|
|
@@ -16576,7 +16691,7 @@ var MessageBus = class {
|
|
|
16576
16691
|
this.initialized = true;
|
|
16577
16692
|
}
|
|
16578
16693
|
async buildServices(config) {
|
|
16579
|
-
const arkProvider = new
|
|
16694
|
+
const arkProvider = new chunk6AFUNKK7_cjs.RestArkProvider(config.arkServer.url);
|
|
16580
16695
|
const storage = {
|
|
16581
16696
|
walletRepository: this.walletRepository,
|
|
16582
16697
|
contractRepository: this.contractRepository,
|
|
@@ -16822,6 +16937,9 @@ var MessageBus = class {
|
|
|
16822
16937
|
});
|
|
16823
16938
|
return;
|
|
16824
16939
|
}
|
|
16940
|
+
if (response.error instanceof Error && !response.errorName) {
|
|
16941
|
+
response.errorName = response.error.name;
|
|
16942
|
+
}
|
|
16825
16943
|
source.postMessage(response);
|
|
16826
16944
|
}
|
|
16827
16945
|
/**
|
|
@@ -16918,7 +17036,7 @@ var offboardNetworkNames = [
|
|
|
16918
17036
|
function offboardDestinationScript(destinationAddress) {
|
|
16919
17037
|
for (const networkName of offboardNetworkNames) {
|
|
16920
17038
|
try {
|
|
16921
|
-
const network =
|
|
17039
|
+
const network = chunk6AFUNKK7_cjs.networks[networkName];
|
|
16922
17040
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
16923
17041
|
return btcSigner.OutScript.encode(addr);
|
|
16924
17042
|
} catch {
|
|
@@ -16982,7 +17100,7 @@ var Ramps = class {
|
|
|
16982
17100
|
}
|
|
16983
17101
|
amount = amount ?? totalAmount;
|
|
16984
17102
|
const offchainAddress = await this.wallet.getAddress();
|
|
16985
|
-
const offchainAddr =
|
|
17103
|
+
const offchainAddr = chunk6AFUNKK7_cjs.ArkAddress.decode(offchainAddress);
|
|
16986
17104
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
16987
17105
|
const outputFee = estimator.evalOffchainOutput({
|
|
16988
17106
|
amount,
|
|
@@ -17042,7 +17160,7 @@ var Ramps = class {
|
|
|
17042
17160
|
const filteredVtxos = [];
|
|
17043
17161
|
let totalAmount = 0n;
|
|
17044
17162
|
for (const vtxo of vtxos) {
|
|
17045
|
-
const inputFee = estimator.evalOffchainInput(
|
|
17163
|
+
const inputFee = estimator.evalOffchainInput(chunk6AFUNKK7_cjs.toOffchainInputFeeParams(vtxo));
|
|
17046
17164
|
if (inputFee.satoshis >= vtxo.value) {
|
|
17047
17165
|
continue;
|
|
17048
17166
|
}
|
|
@@ -17415,6 +17533,49 @@ var WalletMessageHandler = class {
|
|
|
17415
17533
|
payload: { address }
|
|
17416
17534
|
});
|
|
17417
17535
|
}
|
|
17536
|
+
case "GET_ARKADE_INFO": {
|
|
17537
|
+
const { payload } = message;
|
|
17538
|
+
const info = await this.readonlyWallet.getArkadeInfo(payload);
|
|
17539
|
+
return this.tagged({
|
|
17540
|
+
id,
|
|
17541
|
+
type: "ARKADE_INFO",
|
|
17542
|
+
payload: { info }
|
|
17543
|
+
});
|
|
17544
|
+
}
|
|
17545
|
+
case "INDEXER_GET_VTXOS": {
|
|
17546
|
+
const { opts } = message.payload;
|
|
17547
|
+
const reader = await this.readonlyWallet.getArkadeReader();
|
|
17548
|
+
return this.tagged({
|
|
17549
|
+
id,
|
|
17550
|
+
type: "INDEXER_VTXOS",
|
|
17551
|
+
payload: await reader.getVtxos(opts)
|
|
17552
|
+
});
|
|
17553
|
+
}
|
|
17554
|
+
case "INDEXER_GET_VIRTUAL_TXS": {
|
|
17555
|
+
const { txids, opts } = message.payload;
|
|
17556
|
+
const reader = await this.readonlyWallet.getArkadeReader();
|
|
17557
|
+
return this.tagged({
|
|
17558
|
+
id,
|
|
17559
|
+
type: "INDEXER_VIRTUAL_TXS",
|
|
17560
|
+
payload: await reader.getVirtualTxs(txids, opts)
|
|
17561
|
+
});
|
|
17562
|
+
}
|
|
17563
|
+
case "SUBMIT_TX": {
|
|
17564
|
+
const { signedArkTx, checkpointTxs } = message.payload;
|
|
17565
|
+
const broadcaster = await this.requireWallet().getArkadeBroadcaster();
|
|
17566
|
+
const result = await broadcaster.submitTx(signedArkTx, checkpointTxs);
|
|
17567
|
+
return this.tagged({
|
|
17568
|
+
id,
|
|
17569
|
+
type: "SUBMIT_TX_SUCCESS",
|
|
17570
|
+
payload: result
|
|
17571
|
+
});
|
|
17572
|
+
}
|
|
17573
|
+
case "FINALIZE_TX": {
|
|
17574
|
+
const { arkTxid, finalCheckpointTxs } = message.payload;
|
|
17575
|
+
const broadcaster = await this.requireWallet().getArkadeBroadcaster();
|
|
17576
|
+
await broadcaster.finalizeTx(arkTxid, finalCheckpointTxs);
|
|
17577
|
+
return this.tagged({ id, type: "FINALIZE_TX_SUCCESS" });
|
|
17578
|
+
}
|
|
17418
17579
|
case "GET_BALANCE": {
|
|
17419
17580
|
const balance = await this.handleGetBalance();
|
|
17420
17581
|
return this.tagged({
|
|
@@ -17878,7 +18039,7 @@ var WalletMessageHandler = class {
|
|
|
17878
18039
|
// Wallet methods
|
|
17879
18040
|
async handleInitWallet({ payload }) {
|
|
17880
18041
|
const { arkServerUrl } = payload;
|
|
17881
|
-
this.indexerProvider = new
|
|
18042
|
+
this.indexerProvider = new chunkCZ32XADN_cjs.RestIndexerProvider(arkServerUrl);
|
|
17882
18043
|
await this.onWalletInitialized();
|
|
17883
18044
|
}
|
|
17884
18045
|
/**
|
|
@@ -18167,7 +18328,7 @@ var WalletMessageHandler = class {
|
|
|
18167
18328
|
if (v.isUnrolled) {
|
|
18168
18329
|
return withUnrolled;
|
|
18169
18330
|
}
|
|
18170
|
-
if (
|
|
18331
|
+
if (chunk6AFUNKK7_cjs.hasTerminalSpend(v)) {
|
|
18171
18332
|
return false;
|
|
18172
18333
|
}
|
|
18173
18334
|
if (includeRecoverable) {
|
|
@@ -18176,10 +18337,10 @@ var WalletMessageHandler = class {
|
|
|
18176
18337
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
18177
18338
|
return false;
|
|
18178
18339
|
}
|
|
18179
|
-
if (
|
|
18340
|
+
if (chunk6AFUNKK7_cjs.isRecoverable(v)) {
|
|
18180
18341
|
return false;
|
|
18181
18342
|
}
|
|
18182
|
-
if (
|
|
18343
|
+
if (chunk6AFUNKK7_cjs.isExpired(v)) {
|
|
18183
18344
|
return false;
|
|
18184
18345
|
}
|
|
18185
18346
|
return true;
|
|
@@ -18277,7 +18438,7 @@ var WalletMessageHandler = class {
|
|
|
18277
18438
|
if (!this.readonlyWallet) return null;
|
|
18278
18439
|
const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
|
|
18279
18440
|
const indexerProvider = this.indexerProvider;
|
|
18280
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
18441
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunk6AFUNKK7_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
18281
18442
|
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, resolveTxCreatedAt);
|
|
18282
18443
|
}
|
|
18283
18444
|
async ensureContractEventBroadcasting() {
|
|
@@ -18306,6 +18467,13 @@ var WalletMessageHandler = class {
|
|
|
18306
18467
|
|
|
18307
18468
|
// src/wallet/serviceWorker/wallet.ts
|
|
18308
18469
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
18470
|
+
var restoreErrorName = (response) => {
|
|
18471
|
+
const error = response.error;
|
|
18472
|
+
if (response.errorName && error instanceof Error && error.name !== response.errorName) {
|
|
18473
|
+
error.name = response.errorName;
|
|
18474
|
+
}
|
|
18475
|
+
return error;
|
|
18476
|
+
};
|
|
18309
18477
|
var INIT_WAIT_BACKOFF_CAP_MS = 2e3;
|
|
18310
18478
|
var MAX_INIT_WAITS = 8;
|
|
18311
18479
|
var initWaitBackoffMs = (attempt) => Math.min(100 * 2 ** attempt, INIT_WAIT_BACKOFF_CAP_MS);
|
|
@@ -18328,6 +18496,14 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18328
18496
|
GET_USED_SIGNING_DESCRIPTORS: 2e4,
|
|
18329
18497
|
ADVANCE_SIGNING_DESCRIPTOR_WATERMARK: 1e4,
|
|
18330
18498
|
// Medium reads — may involve indexer queries
|
|
18499
|
+
// A live `/v1/info` fetch queued behind the same per-origin rate gate as
|
|
18500
|
+
// the indexer, not a repository read. Derived from the fetch's own abort
|
|
18501
|
+
// budget so the worker's snapshot fallback stays reachable before this
|
|
18502
|
+
// page deadline fires — lowering it below the budget would time the page
|
|
18503
|
+
// out while the worker is still seconds from answering from cache.
|
|
18504
|
+
GET_ARKADE_INFO: chunk6AFUNKK7_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
18505
|
+
INDEXER_GET_VTXOS: 2e4,
|
|
18506
|
+
INDEXER_GET_VIRTUAL_TXS: 2e4,
|
|
18331
18507
|
GET_VTXOS: 2e4,
|
|
18332
18508
|
GET_SPENDABLE_VTXOS: 2e4,
|
|
18333
18509
|
GET_BOARDING_UTXOS: 2e4,
|
|
@@ -18350,6 +18526,10 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18350
18526
|
SEND_BITCOIN: 5e4,
|
|
18351
18527
|
SEND: 5e4,
|
|
18352
18528
|
SETTLE: 5e4,
|
|
18529
|
+
// Broadcast: the server round-trip a spend ends in, so it belongs
|
|
18530
|
+
// with the writes rather than the reads above.
|
|
18531
|
+
SUBMIT_TX: 5e4,
|
|
18532
|
+
FINALIZE_TX: 5e4,
|
|
18353
18533
|
ISSUE: 5e4,
|
|
18354
18534
|
REISSUE: 5e4,
|
|
18355
18535
|
BURN: 5e4,
|
|
@@ -18376,6 +18556,9 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18376
18556
|
};
|
|
18377
18557
|
var DEDUPABLE_REQUEST_TYPES = /* @__PURE__ */ new Set([
|
|
18378
18558
|
"GET_ADDRESS",
|
|
18559
|
+
"GET_ARKADE_INFO",
|
|
18560
|
+
"INDEXER_GET_VTXOS",
|
|
18561
|
+
"INDEXER_GET_VIRTUAL_TXS",
|
|
18379
18562
|
"GET_BALANCE",
|
|
18380
18563
|
"GET_BOARDING_ADDRESS",
|
|
18381
18564
|
"GET_BOARDING_UTXOS",
|
|
@@ -18467,7 +18650,7 @@ var initializeMessageBus = (serviceWorker, config, timeoutMs = 2e3) => {
|
|
|
18467
18650
|
if (response?.id !== initCmd.id) return;
|
|
18468
18651
|
cleanup();
|
|
18469
18652
|
if (response.error) {
|
|
18470
|
-
reject(response
|
|
18653
|
+
reject(restoreErrorName(response));
|
|
18471
18654
|
} else {
|
|
18472
18655
|
resolve();
|
|
18473
18656
|
}
|
|
@@ -18639,7 +18822,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18639
18822
|
}
|
|
18640
18823
|
cleanup();
|
|
18641
18824
|
if (response.error) {
|
|
18642
|
-
reject(response
|
|
18825
|
+
reject(restoreErrorName(response));
|
|
18643
18826
|
} else {
|
|
18644
18827
|
resolve(response);
|
|
18645
18828
|
}
|
|
@@ -18665,7 +18848,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18665
18848
|
if (request.id !== response.id) return;
|
|
18666
18849
|
if (response.error) {
|
|
18667
18850
|
cleanup();
|
|
18668
|
-
reject(response
|
|
18851
|
+
reject(restoreErrorName(response));
|
|
18669
18852
|
return;
|
|
18670
18853
|
}
|
|
18671
18854
|
if (isComplete(response)) {
|
|
@@ -18891,6 +19074,68 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18891
19074
|
throw new Error(`Failed to get boarding address: ${error}`);
|
|
18892
19075
|
}
|
|
18893
19076
|
}
|
|
19077
|
+
/**
|
|
19078
|
+
* Delegated to the worker, which holds the wallet that owns the connection.
|
|
19079
|
+
* The payload crosses raw — see {@link ResponseGetArkadeInfo} for why.
|
|
19080
|
+
*/
|
|
19081
|
+
async getArkadeInfo(opts) {
|
|
19082
|
+
const message = {
|
|
19083
|
+
id: getRandomId(),
|
|
19084
|
+
tag: this.messageTag,
|
|
19085
|
+
type: "GET_ARKADE_INFO",
|
|
19086
|
+
// omitted entirely for the default read: wire-shape hygiene
|
|
19087
|
+
// toward workers built before the option existed. (Dedup is
|
|
19088
|
+
// unaffected either way — the key is JSON.stringify, which drops
|
|
19089
|
+
// undefined-valued properties.)
|
|
19090
|
+
...opts?.requireLive ? { payload: { requireLive: true } } : {}
|
|
19091
|
+
};
|
|
19092
|
+
try {
|
|
19093
|
+
const response = await this.sendMessage(message);
|
|
19094
|
+
return response.payload.info;
|
|
19095
|
+
} catch (error) {
|
|
19096
|
+
throw new Error(`Failed to get arkade info: ${error}`, { cause: error });
|
|
19097
|
+
}
|
|
19098
|
+
}
|
|
19099
|
+
/**
|
|
19100
|
+
* An {@link ArkadeReader} that speaks to the worker rather than to the
|
|
19101
|
+
* server. The page holds no provider, so a caller that built its own from a
|
|
19102
|
+
* URL would open a second connection outside the worker's rate gate and
|
|
19103
|
+
* caches — this proxy is what keeps chain reads in one place.
|
|
19104
|
+
*/
|
|
19105
|
+
async getArkadeReader() {
|
|
19106
|
+
return {
|
|
19107
|
+
getVtxos: async (opts) => {
|
|
19108
|
+
const message = {
|
|
19109
|
+
id: getRandomId(),
|
|
19110
|
+
tag: this.messageTag,
|
|
19111
|
+
type: "INDEXER_GET_VTXOS",
|
|
19112
|
+
payload: { opts }
|
|
19113
|
+
};
|
|
19114
|
+
try {
|
|
19115
|
+
const response = await this.sendMessage(message);
|
|
19116
|
+
const { vtxos, page } = response.payload;
|
|
19117
|
+
return { vtxos: vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo), page: page && { ...page } };
|
|
19118
|
+
} catch (error) {
|
|
19119
|
+
throw new Error(`Failed to get vtxos: ${error}`, { cause: error });
|
|
19120
|
+
}
|
|
19121
|
+
},
|
|
19122
|
+
getVirtualTxs: async (txids, opts) => {
|
|
19123
|
+
const message = {
|
|
19124
|
+
id: getRandomId(),
|
|
19125
|
+
tag: this.messageTag,
|
|
19126
|
+
type: "INDEXER_GET_VIRTUAL_TXS",
|
|
19127
|
+
payload: { txids, opts }
|
|
19128
|
+
};
|
|
19129
|
+
try {
|
|
19130
|
+
const response = await this.sendMessage(message);
|
|
19131
|
+
const { txs, page } = response.payload;
|
|
19132
|
+
return { txs: [...txs], page: page && { ...page } };
|
|
19133
|
+
} catch (error) {
|
|
19134
|
+
throw new Error(`Failed to get virtual txs: ${error}`, { cause: error });
|
|
19135
|
+
}
|
|
19136
|
+
}
|
|
19137
|
+
};
|
|
19138
|
+
}
|
|
18894
19139
|
async getBalance() {
|
|
18895
19140
|
const message = {
|
|
18896
19141
|
id: getRandomId(),
|
|
@@ -18973,7 +19218,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18973
19218
|
};
|
|
18974
19219
|
try {
|
|
18975
19220
|
const response = await this.sendMessage(message);
|
|
18976
|
-
return response.payload.vtxos.map(
|
|
19221
|
+
return response.payload.vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
18977
19222
|
} catch (error) {
|
|
18978
19223
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
18979
19224
|
}
|
|
@@ -18998,7 +19243,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18998
19243
|
};
|
|
18999
19244
|
try {
|
|
19000
19245
|
const response = await this.sendMessage(message);
|
|
19001
|
-
return response.payload.vtxos.map(
|
|
19246
|
+
return response.payload.vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
19002
19247
|
} catch (error) {
|
|
19003
19248
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
19004
19249
|
}
|
|
@@ -19129,7 +19374,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19129
19374
|
};
|
|
19130
19375
|
try {
|
|
19131
19376
|
const response = await sendContractMessage(message);
|
|
19132
|
-
return response.payload.vtxos.map(
|
|
19377
|
+
return response.payload.vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
19133
19378
|
} catch (e) {
|
|
19134
19379
|
throw new Error("Failed to annotate vtxos");
|
|
19135
19380
|
}
|
|
@@ -19547,6 +19792,43 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
19547
19792
|
async signerForDescriptor(descriptor) {
|
|
19548
19793
|
return resolveDescriptorSigner(descriptor, this.identity);
|
|
19549
19794
|
}
|
|
19795
|
+
/**
|
|
19796
|
+
* An {@link ArkadeBroadcaster} proxied to the worker, which holds the
|
|
19797
|
+
* provider. Only `ServiceWorkerWallet` offers one: a readonly worker
|
|
19798
|
+
* refuses `SUBMIT_TX`/`FINALIZE_TX` outright, so exposing it on the
|
|
19799
|
+
* readonly class would promise something the boundary rejects.
|
|
19800
|
+
*/
|
|
19801
|
+
async getArkadeBroadcaster() {
|
|
19802
|
+
return {
|
|
19803
|
+
submitTx: async (signedArkTx, checkpointTxs) => {
|
|
19804
|
+
const message = {
|
|
19805
|
+
id: getRandomId(),
|
|
19806
|
+
tag: this.messageTag,
|
|
19807
|
+
type: "SUBMIT_TX",
|
|
19808
|
+
payload: { signedArkTx, checkpointTxs }
|
|
19809
|
+
};
|
|
19810
|
+
try {
|
|
19811
|
+
const response = await this.sendMessage(message);
|
|
19812
|
+
return response.payload;
|
|
19813
|
+
} catch (error) {
|
|
19814
|
+
throw new Error(`Failed to submit tx: ${error}`, { cause: error });
|
|
19815
|
+
}
|
|
19816
|
+
},
|
|
19817
|
+
finalizeTx: async (arkTxid, finalCheckpointTxs) => {
|
|
19818
|
+
const message = {
|
|
19819
|
+
id: getRandomId(),
|
|
19820
|
+
tag: this.messageTag,
|
|
19821
|
+
type: "FINALIZE_TX",
|
|
19822
|
+
payload: { arkTxid, finalCheckpointTxs }
|
|
19823
|
+
};
|
|
19824
|
+
try {
|
|
19825
|
+
await this.sendMessage(message);
|
|
19826
|
+
} catch (error) {
|
|
19827
|
+
throw new Error(`Failed to finalize tx: ${error}`, { cause: error });
|
|
19828
|
+
}
|
|
19829
|
+
}
|
|
19830
|
+
};
|
|
19831
|
+
}
|
|
19550
19832
|
async sendBitcoin(params) {
|
|
19551
19833
|
const message = {
|
|
19552
19834
|
id: getRandomId(),
|
|
@@ -19730,7 +20012,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
19730
20012
|
};
|
|
19731
20013
|
try {
|
|
19732
20014
|
const response = await wallet.sendMessage(message);
|
|
19733
|
-
return response.payload.vtxos.map(
|
|
20015
|
+
return response.payload.vtxos.map(chunk6AFUNKK7_cjs.normalizeVtxo);
|
|
19734
20016
|
} catch (e) {
|
|
19735
20017
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
19736
20018
|
}
|
|
@@ -19842,12 +20124,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
19842
20124
|
* @returns Configured onchain wallet
|
|
19843
20125
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
19844
20126
|
*/
|
|
19845
|
-
static async create(identity, networkName =
|
|
20127
|
+
static async create(identity, networkName = chunk6AFUNKK7_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
19846
20128
|
const pubkey = await identity.xOnlyPublicKey();
|
|
19847
20129
|
if (!pubkey) {
|
|
19848
20130
|
throw new Error("Invalid configured public key");
|
|
19849
20131
|
}
|
|
19850
|
-
const network =
|
|
20132
|
+
const network = chunk6AFUNKK7_cjs.getNetwork(networkName);
|
|
19851
20133
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
19852
20134
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
19853
20135
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -19953,7 +20235,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
19953
20235
|
if (!inputs) {
|
|
19954
20236
|
throw new Error("Fee estimation failed");
|
|
19955
20237
|
}
|
|
19956
|
-
let tx = new
|
|
20238
|
+
let tx = new chunk6AFUNKK7_cjs.Transaction();
|
|
19957
20239
|
for (const input of inputs) {
|
|
19958
20240
|
tx.addInput({
|
|
19959
20241
|
txid: input.txid,
|
|
@@ -20011,7 +20293,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20011
20293
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
20012
20294
|
*/
|
|
20013
20295
|
async bumpAnchor(parentHex, feeRate) {
|
|
20014
|
-
const parent =
|
|
20296
|
+
const parent = chunk6AFUNKK7_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
20015
20297
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
20016
20298
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
20017
20299
|
return [parent.hex, child.hex];
|
|
@@ -20872,7 +21154,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
20872
21154
|
try {
|
|
20873
21155
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
20874
21156
|
for (const psbt of txs) {
|
|
20875
|
-
const tx =
|
|
21157
|
+
const tx = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
20876
21158
|
resolved.set(tx.id, tx.toBytes());
|
|
20877
21159
|
}
|
|
20878
21160
|
} catch (err) {
|
|
@@ -20905,7 +21187,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
20905
21187
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
20906
21188
|
const pending = [];
|
|
20907
21189
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
20908
|
-
if (
|
|
21190
|
+
if (chunk6AFUNKK7_cjs.getArkPsbtFields(tx, i, chunk6AFUNKK7_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
20909
21191
|
}
|
|
20910
21192
|
if (pending.length === 0) return;
|
|
20911
21193
|
const resolved = await resolvePrevTxs(
|
|
@@ -20914,13 +21196,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
20914
21196
|
onchain
|
|
20915
21197
|
);
|
|
20916
21198
|
for (const i of pending) {
|
|
20917
|
-
|
|
21199
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(tx, i, chunk6AFUNKK7_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
20918
21200
|
}
|
|
20919
21201
|
}
|
|
20920
21202
|
async function attachPrevoutTxs(tx, source) {
|
|
20921
21203
|
const pending = [];
|
|
20922
21204
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
20923
|
-
if (
|
|
21205
|
+
if (chunk6AFUNKK7_cjs.getArkPsbtFields(tx, i, chunk6AFUNKK7_cjs.PrevoutTxField).length > 0) continue;
|
|
20924
21206
|
const input = tx.getInput(i);
|
|
20925
21207
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
20926
21208
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -20931,7 +21213,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
20931
21213
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
20932
21214
|
}
|
|
20933
21215
|
for (const { index, txid } of pending) {
|
|
20934
|
-
|
|
21216
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(tx, index, chunk6AFUNKK7_cjs.PrevoutTxField, resolved.get(txid));
|
|
20935
21217
|
}
|
|
20936
21218
|
}
|
|
20937
21219
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -20957,7 +21239,7 @@ exports.BIP322 = void 0;
|
|
|
20957
21239
|
async function sign2(message, identity, network) {
|
|
20958
21240
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
20959
21241
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
20960
|
-
const toSpend =
|
|
21242
|
+
const toSpend = chunk6AFUNKK7_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
20961
21243
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
20962
21244
|
const signed = await identity.sign(toSign, [0]);
|
|
20963
21245
|
signed.finalizeIdx(0);
|
|
@@ -21015,7 +21297,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
21015
21297
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
21016
21298
|
return false;
|
|
21017
21299
|
}
|
|
21018
|
-
const toSpend =
|
|
21300
|
+
const toSpend = chunk6AFUNKK7_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21019
21301
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
21020
21302
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
21021
21303
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -21036,7 +21318,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
21036
21318
|
}
|
|
21037
21319
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
21038
21320
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
21039
|
-
const toSpend =
|
|
21321
|
+
const toSpend = chunk6AFUNKK7_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21040
21322
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
21041
21323
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
21042
21324
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -21089,7 +21371,7 @@ function encodeCompactSize(n) {
|
|
|
21089
21371
|
return buf;
|
|
21090
21372
|
}
|
|
21091
21373
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
21092
|
-
const tx = new
|
|
21374
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({ version: 0 });
|
|
21093
21375
|
tx.addInput({
|
|
21094
21376
|
txid: toSpend.id,
|
|
21095
21377
|
index: 0,
|
|
@@ -21103,12 +21385,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
21103
21385
|
});
|
|
21104
21386
|
tx.addOutput({
|
|
21105
21387
|
amount: 0n,
|
|
21106
|
-
script:
|
|
21388
|
+
script: chunk6AFUNKK7_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21107
21389
|
});
|
|
21108
21390
|
return tx;
|
|
21109
21391
|
}
|
|
21110
21392
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
21111
|
-
const tx = new
|
|
21393
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({ version: 0 });
|
|
21112
21394
|
tx.addInput({
|
|
21113
21395
|
txid: toSpend.id,
|
|
21114
21396
|
index: 0,
|
|
@@ -21120,7 +21402,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
21120
21402
|
});
|
|
21121
21403
|
tx.addOutput({
|
|
21122
21404
|
amount: 0n,
|
|
21123
|
-
script:
|
|
21405
|
+
script: chunk6AFUNKK7_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21124
21406
|
});
|
|
21125
21407
|
return tx;
|
|
21126
21408
|
}
|
|
@@ -21251,7 +21533,7 @@ var RestEmulatorProvider = class {
|
|
|
21251
21533
|
}
|
|
21252
21534
|
};
|
|
21253
21535
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
21254
|
-
const tx =
|
|
21536
|
+
const tx = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
21255
21537
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
21256
21538
|
const input = tx.getInput(0);
|
|
21257
21539
|
if (!input) {
|
|
@@ -21278,14 +21560,14 @@ var ExitPathError = class extends Error {
|
|
|
21278
21560
|
reason;
|
|
21279
21561
|
};
|
|
21280
21562
|
function delayWeight(sequence) {
|
|
21281
|
-
const t =
|
|
21563
|
+
const t = chunk6AFUNKK7_cjs.sequenceToTimelock(sequence);
|
|
21282
21564
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
21283
21565
|
}
|
|
21284
21566
|
async function resolveUnilateralPath(params) {
|
|
21285
21567
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
21286
21568
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
21287
21569
|
if (contract) {
|
|
21288
|
-
const handler =
|
|
21570
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
21289
21571
|
if (!handler) {
|
|
21290
21572
|
throw new ExitPathError(
|
|
21291
21573
|
"no-handler",
|
|
@@ -21308,12 +21590,12 @@ async function resolveUnilateralPath(params) {
|
|
|
21308
21590
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
21309
21591
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
21310
21592
|
}
|
|
21311
|
-
const decoded =
|
|
21593
|
+
const decoded = chunk6AFUNKK7_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
21312
21594
|
let best;
|
|
21313
21595
|
for (const exit of decoded.exitPaths()) {
|
|
21314
21596
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
21315
21597
|
if (!leaf) continue;
|
|
21316
|
-
const sequence =
|
|
21598
|
+
const sequence = chunk6AFUNKK7_cjs.timelockToSequence(exit.params.timelock);
|
|
21317
21599
|
const weight = delayWeight(sequence);
|
|
21318
21600
|
if (!best || weight < best.weight) {
|
|
21319
21601
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -21533,7 +21815,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
21533
21815
|
let totalAmount = 0n;
|
|
21534
21816
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
21535
21817
|
for (const vtxo of vtxos) {
|
|
21536
|
-
if (!
|
|
21818
|
+
if (!chunk6AFUNKK7_cjs.canSweepOnchain(vtxo)) {
|
|
21537
21819
|
throw new Error(
|
|
21538
21820
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
21539
21821
|
);
|
|
@@ -21544,14 +21826,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
21544
21826
|
}
|
|
21545
21827
|
const resolved = await resolveUnilateralPath({
|
|
21546
21828
|
vtxo,
|
|
21547
|
-
scriptHex: base.hex.encode(
|
|
21829
|
+
scriptHex: base.hex.encode(chunk6AFUNKK7_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
21548
21830
|
contractRepository: wallet.contractRepository,
|
|
21549
21831
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
21550
21832
|
currentTime: Date.now()
|
|
21551
21833
|
});
|
|
21552
21834
|
const spendingLeaf = resolved.selection.leaf;
|
|
21553
21835
|
const sequence = resolved.selection.sequence;
|
|
21554
|
-
const timelock =
|
|
21836
|
+
const timelock = chunk6AFUNKK7_cjs.sequenceToTimelock(sequence);
|
|
21555
21837
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
21556
21838
|
if (!elapsed) {
|
|
21557
21839
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -21564,7 +21846,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
21564
21846
|
sequence,
|
|
21565
21847
|
witnessUtxo: {
|
|
21566
21848
|
amount: BigInt(vtxo.value),
|
|
21567
|
-
script:
|
|
21849
|
+
script: chunk6AFUNKK7_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
21568
21850
|
},
|
|
21569
21851
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
21570
21852
|
});
|
|
@@ -21574,7 +21856,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
21574
21856
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
21575
21857
|
);
|
|
21576
21858
|
}
|
|
21577
|
-
const tx = new
|
|
21859
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({ version: 2 });
|
|
21578
21860
|
for (const input of inputs) {
|
|
21579
21861
|
tx.addInput(input);
|
|
21580
21862
|
}
|
|
@@ -21657,7 +21939,7 @@ async function buildSignedSweep(params) {
|
|
|
21657
21939
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
21658
21940
|
);
|
|
21659
21941
|
}
|
|
21660
|
-
const tx = new
|
|
21942
|
+
const tx = new chunk6AFUNKK7_cjs.Transaction({ version: 2 });
|
|
21661
21943
|
tx.addInput({
|
|
21662
21944
|
txid: vtxo.txid,
|
|
21663
21945
|
index: vtxo.vout,
|
|
@@ -21682,7 +21964,7 @@ async function buildSignedSweep(params) {
|
|
|
21682
21964
|
finalScriptWitness: [
|
|
21683
21965
|
tapScriptSig[0][1],
|
|
21684
21966
|
...path.extraWitness,
|
|
21685
|
-
|
|
21967
|
+
chunk6AFUNKK7_cjs.scriptFromTapLeafScript(path.leaf),
|
|
21686
21968
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
21687
21969
|
]
|
|
21688
21970
|
});
|
|
@@ -21712,7 +21994,7 @@ async function resolveFeeRate(opts) {
|
|
|
21712
21994
|
}
|
|
21713
21995
|
async function selectExitVtxos(opts) {
|
|
21714
21996
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
21715
|
-
const res = await
|
|
21997
|
+
const res = await chunk6AFUNKK7_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
21716
21998
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
21717
21999
|
const out = [];
|
|
21718
22000
|
for (const vtxo of res.vtxos) {
|
|
@@ -21727,7 +22009,7 @@ async function selectExitVtxos(opts) {
|
|
|
21727
22009
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
21728
22010
|
);
|
|
21729
22011
|
}
|
|
21730
|
-
const handler =
|
|
22012
|
+
const handler = chunkHL7EC2Z5_cjs.contractHandlers.get(contract.type);
|
|
21731
22013
|
if (!handler) {
|
|
21732
22014
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
21733
22015
|
}
|
|
@@ -21757,7 +22039,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
21757
22039
|
if (pendingNodes.length > 0) {
|
|
21758
22040
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
21759
22041
|
for (const psbt of txs) {
|
|
21760
|
-
psbts.set(
|
|
22042
|
+
psbts.set(chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
21761
22043
|
}
|
|
21762
22044
|
}
|
|
21763
22045
|
const childVsize = Number(
|
|
@@ -21793,7 +22075,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
21793
22075
|
try {
|
|
21794
22076
|
const resolved = await resolveUnilateralPath({
|
|
21795
22077
|
vtxo,
|
|
21796
|
-
scriptHex: base.hex.encode(
|
|
22078
|
+
scriptHex: base.hex.encode(chunk6AFUNKK7_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
21797
22079
|
contractRepository: wallet.contractRepository,
|
|
21798
22080
|
walletPubKeyHex,
|
|
21799
22081
|
currentTime: Date.now()
|
|
@@ -21812,7 +22094,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
21812
22094
|
});
|
|
21813
22095
|
continue;
|
|
21814
22096
|
}
|
|
21815
|
-
const t =
|
|
22097
|
+
const t = chunk6AFUNKK7_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
21816
22098
|
const delay = { type: t.type, value: Number(t.value) };
|
|
21817
22099
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
21818
22100
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -22213,7 +22495,7 @@ async function prepare(opts) {
|
|
|
22213
22495
|
txid: sweep.vtxo.txid,
|
|
22214
22496
|
vout: sweep.vtxo.vout,
|
|
22215
22497
|
value: sweep.vtxo.value,
|
|
22216
|
-
pkScript:
|
|
22498
|
+
pkScript: chunk6AFUNKK7_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
22217
22499
|
},
|
|
22218
22500
|
path: sweep.resolved.selection,
|
|
22219
22501
|
outputAddress: opts.sweepAddress,
|
|
@@ -22301,7 +22583,7 @@ async function prepare(opts) {
|
|
|
22301
22583
|
if (newFee <= splitterFee) break;
|
|
22302
22584
|
splitterFee = newFee;
|
|
22303
22585
|
}
|
|
22304
|
-
const splitter = new
|
|
22586
|
+
const splitter = new chunk6AFUNKK7_cjs.Transaction({ version: 2 });
|
|
22305
22587
|
for (const coin of selected.inputs) {
|
|
22306
22588
|
splitter.addInput({
|
|
22307
22589
|
txid: coin.txid,
|
|
@@ -22445,41 +22727,41 @@ var UnilateralExit = {
|
|
|
22445
22727
|
// src/arkade/index.ts
|
|
22446
22728
|
var arkade_exports = {};
|
|
22447
22729
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
22448
|
-
ARKADE_OP: () =>
|
|
22449
|
-
ARKADE_OPCODES: () =>
|
|
22450
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
22451
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
22452
|
-
ARKADE_OPS: () =>
|
|
22730
|
+
ARKADE_OP: () => chunkHL7EC2Z5_cjs.ARKADE_OP,
|
|
22731
|
+
ARKADE_OPCODES: () => chunkHL7EC2Z5_cjs.ARKADE_OPCODES,
|
|
22732
|
+
ARKADE_OPCODE_NAMES: () => chunkHL7EC2Z5_cjs.ARKADE_OPCODE_NAMES,
|
|
22733
|
+
ARKADE_OPCODE_VALUES: () => chunkHL7EC2Z5_cjs.ARKADE_OPCODE_VALUES,
|
|
22734
|
+
ARKADE_OPS: () => chunkHL7EC2Z5_cjs.ARKADE_OPS,
|
|
22453
22735
|
Arkade: () => Arkade,
|
|
22454
22736
|
ArkadeContract: () => ArkadeContract,
|
|
22455
|
-
ArkadeProgramScript: () =>
|
|
22456
|
-
ArkadeScript: () =>
|
|
22737
|
+
ArkadeProgramScript: () => chunkHL7EC2Z5_cjs.ArkadeProgramScript,
|
|
22738
|
+
ArkadeScript: () => chunkHL7EC2Z5_cjs.ArkadeScript,
|
|
22457
22739
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
22458
|
-
BigNum: () =>
|
|
22740
|
+
BigNum: () => chunkHL7EC2Z5_cjs.bignum_exports,
|
|
22459
22741
|
OP: () => btcSigner.OP,
|
|
22460
|
-
OPCODE_NAMES: () =>
|
|
22461
|
-
OPCODE_VALUES: () =>
|
|
22462
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
22742
|
+
OPCODE_NAMES: () => chunkHL7EC2Z5_cjs.OPCODE_NAMES,
|
|
22743
|
+
OPCODE_VALUES: () => chunkHL7EC2Z5_cjs.OPCODE_VALUES,
|
|
22744
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkHL7EC2Z5_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
22463
22745
|
Script: () => btcSigner.Script,
|
|
22464
|
-
arkadeScriptHash: () =>
|
|
22465
|
-
arkadeWitnessHash: () =>
|
|
22466
|
-
asmToBytes: () =>
|
|
22467
|
-
bytesToASM: () =>
|
|
22468
|
-
computeArkadeScriptPublicKey: () =>
|
|
22746
|
+
arkadeScriptHash: () => chunkHL7EC2Z5_cjs.arkadeScriptHash,
|
|
22747
|
+
arkadeWitnessHash: () => chunkHL7EC2Z5_cjs.arkadeWitnessHash,
|
|
22748
|
+
asmToBytes: () => chunkHL7EC2Z5_cjs.asmToBytes,
|
|
22749
|
+
bytesToASM: () => chunkHL7EC2Z5_cjs.bytesToASM,
|
|
22750
|
+
computeArkadeScriptPublicKey: () => chunkHL7EC2Z5_cjs.computeArkadeScriptPublicKey,
|
|
22469
22751
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
22470
|
-
deserializeArkadeContractParams: () =>
|
|
22471
|
-
fromASM: () =>
|
|
22472
|
-
getOpcodeName: () =>
|
|
22473
|
-
getOpcodeValue: () =>
|
|
22474
|
-
parseArtifact: () =>
|
|
22475
|
-
resolveAsm: () =>
|
|
22476
|
-
serializeArkadeContractParams: () =>
|
|
22477
|
-
stringifyArtifact: () =>
|
|
22478
|
-
toASM: () =>
|
|
22479
|
-
validateProgram: () =>
|
|
22480
|
-
witnessRefToBytes: () =>
|
|
22752
|
+
deserializeArkadeContractParams: () => chunkHL7EC2Z5_cjs.deserializeArkadeContractParams,
|
|
22753
|
+
fromASM: () => chunkHL7EC2Z5_cjs.fromASM,
|
|
22754
|
+
getOpcodeName: () => chunkHL7EC2Z5_cjs.getOpcodeName,
|
|
22755
|
+
getOpcodeValue: () => chunkHL7EC2Z5_cjs.getOpcodeValue,
|
|
22756
|
+
parseArtifact: () => chunkHL7EC2Z5_cjs.parseArtifact,
|
|
22757
|
+
resolveAsm: () => chunkHL7EC2Z5_cjs.resolveAsm,
|
|
22758
|
+
serializeArkadeContractParams: () => chunkHL7EC2Z5_cjs.serializeArkadeContractParams,
|
|
22759
|
+
stringifyArtifact: () => chunkHL7EC2Z5_cjs.stringifyArtifact,
|
|
22760
|
+
toASM: () => chunkHL7EC2Z5_cjs.toASM,
|
|
22761
|
+
validateProgram: () => chunkHL7EC2Z5_cjs.validateProgram,
|
|
22762
|
+
witnessRefToBytes: () => chunkHL7EC2Z5_cjs.witnessRefToBytes
|
|
22481
22763
|
});
|
|
22482
|
-
var isVtxoCoin = (input) =>
|
|
22764
|
+
var isVtxoCoin = (input) => chunk6AFUNKK7_cjs.isVirtualCoin(input);
|
|
22483
22765
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
22484
22766
|
let batchId;
|
|
22485
22767
|
let sweepTapTreeRoot;
|
|
@@ -22500,23 +22782,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
22500
22782
|
);
|
|
22501
22783
|
await arkProvider.confirmRegistration(intentId);
|
|
22502
22784
|
batchId = event.id;
|
|
22503
|
-
const sweepTapscript =
|
|
22785
|
+
const sweepTapscript = chunk6AFUNKK7_cjs.CSVMultisigTapscript.encode({
|
|
22504
22786
|
timelock,
|
|
22505
|
-
pubkeys: [
|
|
22787
|
+
pubkeys: [chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
22506
22788
|
}).script;
|
|
22507
22789
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
22508
22790
|
return { skip: false };
|
|
22509
22791
|
},
|
|
22510
22792
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
22511
22793
|
const signerPubKey = await session.getPublicKey();
|
|
22512
|
-
const xonlySignerPubKey =
|
|
22794
|
+
const xonlySignerPubKey = chunkHL7EC2Z5_cjs.toXOnly(signerPubKey, "signer key");
|
|
22513
22795
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
22514
|
-
(k) => base.hex.encode(
|
|
22796
|
+
(k) => base.hex.encode(chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
22515
22797
|
);
|
|
22516
22798
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
22517
22799
|
return { skip: true };
|
|
22518
22800
|
}
|
|
22519
|
-
const commitmentTx =
|
|
22801
|
+
const commitmentTx = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
22520
22802
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
22521
22803
|
if (recipients && recipients.length > 0) {
|
|
22522
22804
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -22548,7 +22830,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
22548
22830
|
if (connectorTree) {
|
|
22549
22831
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
22550
22832
|
}
|
|
22551
|
-
let commitmentPsbt =
|
|
22833
|
+
let commitmentPsbt = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
22552
22834
|
assertFinalCommitmentMatchesValidated(
|
|
22553
22835
|
commitmentPsbt,
|
|
22554
22836
|
validatedCommitmentTxid,
|
|
@@ -22583,7 +22865,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
22583
22865
|
boardingIndices.push(boardingIdx);
|
|
22584
22866
|
continue;
|
|
22585
22867
|
}
|
|
22586
|
-
if (
|
|
22868
|
+
if (chunk6AFUNKK7_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
22587
22869
|
continue;
|
|
22588
22870
|
}
|
|
22589
22871
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -22604,7 +22886,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
22604
22886
|
index: input.vout,
|
|
22605
22887
|
witnessUtxo: {
|
|
22606
22888
|
amount: BigInt(input.value),
|
|
22607
|
-
script:
|
|
22889
|
+
script: chunk6AFUNKK7_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
22608
22890
|
},
|
|
22609
22891
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
22610
22892
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -22695,16 +22977,16 @@ var Arkade = class _Arkade {
|
|
|
22695
22977
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
22696
22978
|
static async connect(opts) {
|
|
22697
22979
|
const info = await opts.arkade.getInfo();
|
|
22698
|
-
const serverKey =
|
|
22699
|
-
const checkpoint =
|
|
22700
|
-
const network = opts.network ??
|
|
22980
|
+
const serverKey = chunkHL7EC2Z5_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
22981
|
+
const checkpoint = chunk6AFUNKK7_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
22982
|
+
const network = opts.network ?? chunk6AFUNKK7_cjs.DEFAULT_NETWORK;
|
|
22701
22983
|
let emulatorKey;
|
|
22702
22984
|
if (opts.emulator) {
|
|
22703
|
-
emulatorKey = base.hex.decode(
|
|
22985
|
+
emulatorKey = base.hex.decode(chunk6AFUNKK7_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
22704
22986
|
}
|
|
22705
22987
|
let userKey;
|
|
22706
22988
|
if (opts.identity) {
|
|
22707
|
-
userKey =
|
|
22989
|
+
userKey = chunkHL7EC2Z5_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
22708
22990
|
}
|
|
22709
22991
|
return new _Arkade({
|
|
22710
22992
|
arkProvider: opts.arkade,
|
|
@@ -22730,7 +23012,7 @@ var Arkade = class _Arkade {
|
|
|
22730
23012
|
* key respectively; explicit args always win.
|
|
22731
23013
|
*/
|
|
22732
23014
|
contract(program, args = {}) {
|
|
22733
|
-
const declared = (program.params ?? []).map(
|
|
23015
|
+
const declared = (program.params ?? []).map(chunkHL7EC2Z5_cjs.inputName);
|
|
22734
23016
|
if (declared.includes("server") && args.server === void 0) {
|
|
22735
23017
|
args = { ...args, server: this.serverKey };
|
|
22736
23018
|
}
|
|
@@ -22750,7 +23032,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
22750
23032
|
userKey: client.userKey,
|
|
22751
23033
|
emulatorKey: client.emulatorKey
|
|
22752
23034
|
};
|
|
22753
|
-
this.vtxoScript = new
|
|
23035
|
+
this.vtxoScript = new chunkHL7EC2Z5_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
22754
23036
|
this.tapTree = this.vtxoScript.encode();
|
|
22755
23037
|
this.compiled = this.vtxoScript.compiled;
|
|
22756
23038
|
}
|
|
@@ -22778,7 +23060,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
22778
23060
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
22779
23061
|
);
|
|
22780
23062
|
}
|
|
22781
|
-
const typed =
|
|
23063
|
+
const typed = chunkHL7EC2Z5_cjs.deserializeArkadeContractParams(contract.params);
|
|
22782
23064
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
22783
23065
|
serverKey: typed.serverKey,
|
|
22784
23066
|
userKey: typed.userKey,
|
|
@@ -22819,7 +23101,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
22819
23101
|
toContractParams() {
|
|
22820
23102
|
return {
|
|
22821
23103
|
type: "arkade",
|
|
22822
|
-
params:
|
|
23104
|
+
params: chunkHL7EC2Z5_cjs.serializeArkadeContractParams({
|
|
22823
23105
|
program: this.program,
|
|
22824
23106
|
args: this.args,
|
|
22825
23107
|
serverKey: this.keys.serverKey,
|
|
@@ -22856,6 +23138,10 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
22856
23138
|
* When a `contractManager` is configured and this contract is registered,
|
|
22857
23139
|
* reads the repository-backed state (offline-first, kept fresh by the
|
|
22858
23140
|
* contract watcher). Otherwise falls back to a direct indexer query.
|
|
23141
|
+
*
|
|
23142
|
+
* Both branches refuse a spent or unilaterally exited output. They are not
|
|
23143
|
+
* otherwise interchangeable: the fallback asks `spendableOnly`, which also
|
|
23144
|
+
* drops swept coins — the manager branch keeps those.
|
|
22859
23145
|
*/
|
|
22860
23146
|
async getUtxos() {
|
|
22861
23147
|
const manager = this.client.contractManager;
|
|
@@ -22865,18 +23151,18 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
22865
23151
|
if (registered) {
|
|
22866
23152
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
22867
23153
|
return (withVtxos?.vtxos ?? []).filter(
|
|
22868
|
-
(v) => !
|
|
23154
|
+
(v) => !chunk6AFUNKK7_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
22869
23155
|
);
|
|
22870
23156
|
}
|
|
22871
23157
|
}
|
|
22872
23158
|
if (!this.client.indexer) {
|
|
22873
23159
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
22874
23160
|
}
|
|
22875
|
-
const { vtxos } = await
|
|
23161
|
+
const { vtxos } = await chunk6AFUNKK7_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
22876
23162
|
scripts: [scriptHex],
|
|
22877
23163
|
spendableOnly: true
|
|
22878
23164
|
});
|
|
22879
|
-
return vtxos;
|
|
23165
|
+
return vtxos.filter((v) => !chunk6AFUNKK7_cjs.hasTerminalSpend(v) && !v.isUnrolled);
|
|
22880
23166
|
}
|
|
22881
23167
|
/** Total spendable balance (requires an indexer). */
|
|
22882
23168
|
async getBalance() {
|
|
@@ -22974,7 +23260,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
22974
23260
|
this.contract.client.checkpoint
|
|
22975
23261
|
);
|
|
22976
23262
|
if (coin.sourceTx) {
|
|
22977
|
-
|
|
23263
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(arkTx, 0, chunk6AFUNKK7_cjs.PrevArkTxField, coin.sourceTx);
|
|
22978
23264
|
}
|
|
22979
23265
|
if (this.fn.arkadeScript) {
|
|
22980
23266
|
const indexer = this.contract.client.indexer;
|
|
@@ -22991,8 +23277,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
22991
23277
|
}
|
|
22992
23278
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
22993
23279
|
if (condition.length > 0) {
|
|
22994
|
-
|
|
22995
|
-
|
|
23280
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(arkTx, 0, chunk6AFUNKK7_cjs.ConditionWitness, condition);
|
|
23281
|
+
chunk6AFUNKK7_cjs.setArkPsbtField(checkpoints[0], 0, chunk6AFUNKK7_cjs.ConditionWitness, condition);
|
|
22996
23282
|
}
|
|
22997
23283
|
const packets = [];
|
|
22998
23284
|
if (this.assetSpecs.length > 0) {
|
|
@@ -23031,7 +23317,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23031
23317
|
base.base64.encode(signedArk2.toPSBT()),
|
|
23032
23318
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
23033
23319
|
);
|
|
23034
|
-
const txid =
|
|
23320
|
+
const txid = chunk6AFUNKK7_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
23035
23321
|
return {
|
|
23036
23322
|
txid,
|
|
23037
23323
|
signedArkTx: res2.signedArkTx,
|
|
@@ -23041,8 +23327,14 @@ var ArkadeTransactionBuilder = class {
|
|
|
23041
23327
|
if (!client.identity) {
|
|
23042
23328
|
throw new Error("a signing identity is required for non-covenant spends");
|
|
23043
23329
|
}
|
|
23330
|
+
const ark = client.arkProvider;
|
|
23331
|
+
if (!ark.submitTx || !ark.finalizeTx) {
|
|
23332
|
+
throw new Error(
|
|
23333
|
+
"broadcasting requires an `arkade` provider with `submitTx`/`finalizeTx` on the Arkade client"
|
|
23334
|
+
);
|
|
23335
|
+
}
|
|
23044
23336
|
const signedArk = await this.signArk(arkTx, userInputs);
|
|
23045
|
-
const res = await
|
|
23337
|
+
const res = await ark.submitTx(
|
|
23046
23338
|
base.base64.encode(signedArk.toPSBT()),
|
|
23047
23339
|
checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
23048
23340
|
);
|
|
@@ -23053,7 +23345,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23053
23345
|
async ({ server }) => base.base64.encode((await client.identity.sign(server, [0])).toPSBT())
|
|
23054
23346
|
)
|
|
23055
23347
|
);
|
|
23056
|
-
await
|
|
23348
|
+
await ark.finalizeTx(res.arkTxid, finalCps);
|
|
23057
23349
|
return {
|
|
23058
23350
|
txid: res.arkTxid,
|
|
23059
23351
|
signedArkTx: res.finalArkTx,
|
|
@@ -23090,23 +23382,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
23090
23382
|
}
|
|
23091
23383
|
buildAssetPacket() {
|
|
23092
23384
|
const groups = this.assetSpecs.map((s) => {
|
|
23093
|
-
const id = typeof s.assetId === "string" ?
|
|
23094
|
-
return
|
|
23385
|
+
const id = typeof s.assetId === "string" ? chunkCZ32XADN_cjs.AssetId.fromString(s.assetId) : chunkCZ32XADN_cjs.AssetId.fromBytes(s.assetId);
|
|
23386
|
+
return chunkCZ32XADN_cjs.AssetGroup.create(
|
|
23095
23387
|
id,
|
|
23096
23388
|
null,
|
|
23097
|
-
s.inputs.map((i) =>
|
|
23098
|
-
s.outputs.map((o) =>
|
|
23099
|
-
(s.metadata ?? []).map((m) =>
|
|
23389
|
+
s.inputs.map((i) => chunkCZ32XADN_cjs.AssetInput.create(i.vin, i.amount)),
|
|
23390
|
+
s.outputs.map((o) => chunkCZ32XADN_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
23391
|
+
(s.metadata ?? []).map((m) => chunkCZ32XADN_cjs.Metadata.create(m.key, m.value))
|
|
23100
23392
|
);
|
|
23101
23393
|
});
|
|
23102
|
-
return
|
|
23394
|
+
return chunkCZ32XADN_cjs.Packet.create(groups);
|
|
23103
23395
|
}
|
|
23104
23396
|
witnessBytes(ref) {
|
|
23105
|
-
return
|
|
23397
|
+
return chunkHL7EC2Z5_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
23106
23398
|
}
|
|
23107
23399
|
};
|
|
23108
23400
|
function bindInputs(fn, callArgs) {
|
|
23109
|
-
const names = (fn.def.inputs ?? []).map(
|
|
23401
|
+
const names = (fn.def.inputs ?? []).map(chunkHL7EC2Z5_cjs.inputName);
|
|
23110
23402
|
if (callArgs.length !== names.length) {
|
|
23111
23403
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
23112
23404
|
}
|
|
@@ -23141,6 +23433,7 @@ var BIP21Error = /* @__PURE__ */ ((BIP21Error2) => {
|
|
|
23141
23433
|
BIP21Error2["INVALID_ADDRESS"] = "Invalid address";
|
|
23142
23434
|
return BIP21Error2;
|
|
23143
23435
|
})(BIP21Error || {});
|
|
23436
|
+
var ARK_HRP = /^(?:t?ark|T?ARK)/;
|
|
23144
23437
|
var BIP21 = class _BIP21 {
|
|
23145
23438
|
/**
|
|
23146
23439
|
* Create a BIP21 URI from the provided parameters.
|
|
@@ -23164,7 +23457,7 @@ var BIP21 = class _BIP21 {
|
|
|
23164
23457
|
}
|
|
23165
23458
|
queryParams[key] = value;
|
|
23166
23459
|
} else if (key === "ark") {
|
|
23167
|
-
if (typeof value === "string" &&
|
|
23460
|
+
if (typeof value === "string" && ARK_HRP.test(value)) {
|
|
23168
23461
|
queryParams[key] = value;
|
|
23169
23462
|
} else {
|
|
23170
23463
|
console.warn("Invalid ARK address format");
|
|
@@ -23184,7 +23477,7 @@ var BIP21 = class _BIP21 {
|
|
|
23184
23477
|
Object.entries(queryParams).map(([k, v]) => [k, String(v)])
|
|
23185
23478
|
)
|
|
23186
23479
|
).toString() : "";
|
|
23187
|
-
return `bitcoin:${address
|
|
23480
|
+
return `bitcoin:${address ?? ""}${query}`;
|
|
23188
23481
|
}
|
|
23189
23482
|
/**
|
|
23190
23483
|
* Integer-sats amount encoded in a BIP21 URI (`amount=` is BTC), or
|
|
@@ -23217,7 +23510,7 @@ var BIP21 = class _BIP21 {
|
|
|
23217
23510
|
const [address, query] = withoutPrefix.split("?");
|
|
23218
23511
|
const params = {};
|
|
23219
23512
|
if (address) {
|
|
23220
|
-
params.address = address
|
|
23513
|
+
params.address = address;
|
|
23221
23514
|
}
|
|
23222
23515
|
if (query) {
|
|
23223
23516
|
const queryParams = new URLSearchParams(query);
|
|
@@ -23233,7 +23526,7 @@ var BIP21 = class _BIP21 {
|
|
|
23233
23526
|
}
|
|
23234
23527
|
params[key] = amount;
|
|
23235
23528
|
} else if (key === "ark") {
|
|
23236
|
-
if (
|
|
23529
|
+
if (ARK_HRP.test(value)) {
|
|
23237
23530
|
params[key] = value;
|
|
23238
23531
|
} else {
|
|
23239
23532
|
console.warn("Invalid ARK address format");
|
|
@@ -23485,7 +23778,7 @@ function onchainRail() {
|
|
|
23485
23778
|
function createDefaultPaymentRouter(wallet) {
|
|
23486
23779
|
return new PaymentRouter({
|
|
23487
23780
|
wallet,
|
|
23488
|
-
prefs: { priority: ["ark", "
|
|
23781
|
+
prefs: { priority: ["ark", "onchain"] }
|
|
23489
23782
|
}).use(arkRail()).use(onchainRail());
|
|
23490
23783
|
}
|
|
23491
23784
|
/*! Bundled license information:
|
|
@@ -23595,6 +23888,7 @@ exports.arkTarget = arkTarget;
|
|
|
23595
23888
|
exports.arkade_exports = arkade_exports;
|
|
23596
23889
|
exports.assertFinalCommitmentMatchesValidated = assertFinalCommitmentMatchesValidated;
|
|
23597
23890
|
exports.assertIntentIdUnique = assertIntentIdUnique;
|
|
23891
|
+
exports.assertRecipientArkadeAddress = assertRecipientArkadeAddress;
|
|
23598
23892
|
exports.assertSendableAmount = assertSendableAmount;
|
|
23599
23893
|
exports.assertSubmittedArkTxid = assertSubmittedArkTxid;
|
|
23600
23894
|
exports.assertValidBatchExpiry = assertValidBatchExpiry;
|
|
@@ -23711,5 +24005,5 @@ exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
|
23711
24005
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
23712
24006
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
23713
24007
|
exports.withPrevTxs = withPrevTxs;
|
|
23714
|
-
//# sourceMappingURL=chunk-
|
|
23715
|
-
//# sourceMappingURL=chunk-
|
|
24008
|
+
//# sourceMappingURL=chunk-5MJHZHG7.cjs.map
|
|
24009
|
+
//# sourceMappingURL=chunk-5MJHZHG7.cjs.map
|