@arkade-os/sdk 0.5.0-rc.3 → 0.5.0-rc.5
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 +12 -67
- package/dist/adapters/expo.cjs +5 -6
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -4
- package/dist/{asyncStorageTaskQueue-DqGRG66E.d.cts → asyncStorageTaskQueue-AZkDlEZ0.d.cts} +1 -1
- package/dist/{asyncStorageTaskQueue-DAs_n1xr.d.ts → asyncStorageTaskQueue-BVcOhuOc.d.ts} +1 -1
- package/dist/{chunk-7W6FHWYN.js → chunk-3ZIEFYL3.js} +14 -38
- package/dist/chunk-3ZIEFYL3.js.map +1 -0
- package/dist/{chunk-UCSTNXB4.cjs → chunk-AEDYZK7T.cjs} +61 -85
- package/dist/chunk-AEDYZK7T.cjs.map +1 -0
- package/dist/{chunk-43XGA362.cjs → chunk-BUYG7QK3.cjs} +17 -17
- package/dist/{chunk-43XGA362.cjs.map → chunk-BUYG7QK3.cjs.map} +1 -1
- package/dist/{chunk-G4UPMCKW.js → chunk-FLPP5KNW.js} +4 -4
- package/dist/{chunk-G4UPMCKW.js.map → chunk-FLPP5KNW.js.map} +1 -1
- package/dist/{chunk-ERUAQGYF.js → chunk-FZ2BTDWY.js} +3 -4
- package/dist/chunk-FZ2BTDWY.js.map +1 -0
- package/dist/{chunk-FSF2PGTR.cjs → chunk-GQWHCQLD.cjs} +850 -1153
- package/dist/chunk-GQWHCQLD.cjs.map +1 -0
- package/dist/{chunk-L4HZK4KK.cjs → chunk-NEVMOIQL.cjs} +18 -19
- package/dist/chunk-NEVMOIQL.cjs.map +1 -0
- package/dist/{chunk-HSG2GQTM.js → chunk-NPG5FAOW.js} +24 -66
- package/dist/chunk-NPG5FAOW.js.map +1 -0
- package/dist/{chunk-BCT7DT2J.cjs → chunk-OMJIILNG.cjs} +10 -10
- package/dist/{chunk-BCT7DT2J.cjs.map → chunk-OMJIILNG.cjs.map} +1 -1
- package/dist/{chunk-VQCDDGRW.js → chunk-ORRKOSQK.js} +433 -728
- package/dist/chunk-ORRKOSQK.js.map +1 -0
- package/dist/{chunk-UJTYUYY4.cjs → chunk-QWWOD7M2.cjs} +25 -71
- package/dist/chunk-QWWOD7M2.cjs.map +1 -0
- package/dist/{chunk-ROD5H7RX.js → chunk-YFILTMLF.js} +4 -4
- package/dist/{chunk-ROD5H7RX.js.map → chunk-YFILTMLF.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +9 -10
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -3
- package/dist/{delegate-CZzIduW4.d.cts → delegate-B5cd_m9h.d.cts} +1 -1
- package/dist/{delegate-B9Bmrns7.d.ts → delegate-BeAa3vil.d.ts} +1 -1
- package/dist/{hdWalletCapable-Cr5nGpK5.d.ts → hdWalletCapable-CqJnNn-i.d.ts} +6 -24
- package/dist/{hdWalletCapable-BIl3yLVM.d.cts → hdWalletCapable-DjjIw6-Q.d.cts} +6 -24
- package/dist/{index-Ci5MmNnK.d.cts → index-BNybgFmf.d.cts} +2 -2
- package/dist/{index-DQ1Hb2w_.d.ts → index-Cg8_sNpz.d.ts} +2 -2
- package/dist/{index-DnNIOqHS.d.cts → index-KCU4cxhL.d.cts} +118 -221
- package/dist/{index-DnNIOqHS.d.ts → index-KCU4cxhL.d.ts} +118 -221
- package/dist/index.cjs +295 -340
- package/dist/index.d.cts +93 -223
- package/dist/index.d.ts +93 -223
- package/dist/index.js +4 -5
- package/dist/repositories/realm/index.cjs +57 -24
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +12 -4
- package/dist/repositories/realm/index.d.ts +12 -4
- package/dist/repositories/realm/index.js +43 -10
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +103 -33
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +12 -2
- package/dist/repositories/sqlite/index.d.ts +12 -2
- package/dist/repositories/sqlite/index.js +90 -20
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-F7wNJcF3.d.ts → taskRunner-BywoLcvo.d.ts} +1 -1
- package/dist/{taskRunner-BDb5Ee2J.d.cts → taskRunner-CRetv4-8.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +14 -15
- package/dist/wallet/expo/background.cjs.map +1 -1
- 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 -7
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +15 -23
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +4 -7
- package/dist/wallet/expo/index.d.ts +4 -7
- package/dist/wallet/expo/index.js +7 -15
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +9 -10
- package/dist/worker/expo/index.cjs.map +1 -1
- 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 -6
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +4 -42
- package/dist/adapters/asyncStorage.cjs +0 -48
- package/dist/adapters/asyncStorage.cjs.map +0 -1
- package/dist/adapters/asyncStorage.d.cts +0 -16
- package/dist/adapters/asyncStorage.d.ts +0 -16
- package/dist/adapters/asyncStorage.js +0 -46
- package/dist/adapters/asyncStorage.js.map +0 -1
- package/dist/adapters/fileSystem.cjs +0 -116
- package/dist/adapters/fileSystem.cjs.map +0 -1
- package/dist/adapters/fileSystem.d.cts +0 -17
- package/dist/adapters/fileSystem.d.ts +0 -17
- package/dist/adapters/fileSystem.js +0 -93
- package/dist/adapters/fileSystem.js.map +0 -1
- package/dist/adapters/indexedDB.cjs +0 -103
- package/dist/adapters/indexedDB.cjs.map +0 -1
- package/dist/adapters/indexedDB.d.cts +0 -18
- package/dist/adapters/indexedDB.d.ts +0 -18
- package/dist/adapters/indexedDB.js +0 -101
- package/dist/adapters/indexedDB.js.map +0 -1
- package/dist/adapters/localStorage.cjs +0 -50
- package/dist/adapters/localStorage.cjs.map +0 -1
- package/dist/adapters/localStorage.d.cts +0 -14
- package/dist/adapters/localStorage.d.ts +0 -14
- package/dist/adapters/localStorage.js +0 -48
- package/dist/adapters/localStorage.js.map +0 -1
- package/dist/chunk-5BLDMQED.cjs +0 -18
- package/dist/chunk-5BLDMQED.cjs.map +0 -1
- package/dist/chunk-7W6FHWYN.js.map +0 -1
- package/dist/chunk-ERUAQGYF.js.map +0 -1
- package/dist/chunk-FSF2PGTR.cjs.map +0 -1
- package/dist/chunk-HSG2GQTM.js.map +0 -1
- package/dist/chunk-L4HZK4KK.cjs.map +0 -1
- package/dist/chunk-NSBPE2FW.js +0 -15
- package/dist/chunk-NSBPE2FW.js.map +0 -1
- package/dist/chunk-UCSTNXB4.cjs.map +0 -1
- package/dist/chunk-UJTYUYY4.cjs.map +0 -1
- package/dist/chunk-VQCDDGRW.js.map +0 -1
- package/dist/index-C0IanN1m.d.cts +0 -11
- package/dist/index-C0IanN1m.d.ts +0 -11
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
3
|
+
var chunkNEVMOIQL_cjs = require('./chunk-NEVMOIQL.cjs');
|
|
4
|
+
var chunkAEDYZK7T_cjs = require('./chunk-AEDYZK7T.cjs');
|
|
5
|
+
var chunkQWWOD7M2_cjs = require('./chunk-QWWOD7M2.cjs');
|
|
7
6
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
8
7
|
var btcSigner = require('@scure/btc-signer');
|
|
9
8
|
var base = require('@scure/base');
|
|
@@ -188,7 +187,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
188
187
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
189
188
|
const tx = this.graph.find(txid);
|
|
190
189
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
191
|
-
const cosigners =
|
|
190
|
+
const cosigners = chunkQWWOD7M2_cjs.getArkPsbtFields(tx.root, 0, chunkQWWOD7M2_cjs.CosignerPublicKey).map(
|
|
192
191
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
193
192
|
// xonly pubkey
|
|
194
193
|
);
|
|
@@ -240,7 +239,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
240
239
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
241
240
|
const prevoutAmounts = [];
|
|
242
241
|
const prevoutScripts = [];
|
|
243
|
-
const cosigners =
|
|
242
|
+
const cosigners = chunkQWWOD7M2_cjs.getArkPsbtFields(g.root, 0, chunkQWWOD7M2_cjs.CosignerPublicKey).map((c) => c.key);
|
|
244
243
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
245
244
|
taprootTweak: this.scriptRoot
|
|
246
245
|
});
|
|
@@ -323,7 +322,7 @@ var SingleKey = class _SingleKey {
|
|
|
323
322
|
async sign(tx, inputIndexes) {
|
|
324
323
|
const txCpy = tx.clone();
|
|
325
324
|
if (!inputIndexes) {
|
|
326
|
-
|
|
325
|
+
chunkQWWOD7M2_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
|
|
327
326
|
try {
|
|
328
327
|
if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
|
|
329
328
|
throw new Error("Failed to sign transaction");
|
|
@@ -432,7 +431,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
432
431
|
let network;
|
|
433
432
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
434
433
|
descriptor = opts.descriptor;
|
|
435
|
-
network =
|
|
434
|
+
network = chunkAEDYZK7T_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
436
435
|
} else {
|
|
437
436
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
438
437
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -520,29 +519,17 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
520
519
|
async toReadonly() {
|
|
521
520
|
return ReadonlyDescriptorIdentity.fromDescriptor(this.descriptor);
|
|
522
521
|
}
|
|
523
|
-
/**
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
* match by raw pubkey. See {@link descriptorIsOurs}.
|
|
527
|
-
*
|
|
528
|
-
* @deprecated Prefer `DescriptorProvider.isOurs()` via
|
|
529
|
-
* `HDDescriptorProvider` for rotating HD wallets or
|
|
530
|
-
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
531
|
-
*/
|
|
532
|
-
isOurs(descriptor) {
|
|
533
|
-
return chunkUCSTNXB4_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
522
|
+
/** Returns true when `descriptor` is derived from this identity's seed. */
|
|
523
|
+
ownsDescriptor(descriptor) {
|
|
524
|
+
return chunkAEDYZK7T_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
534
525
|
}
|
|
535
526
|
/**
|
|
536
527
|
* Signs each request with the key derived from its descriptor.
|
|
537
|
-
* Each descriptor must share this identity's seed ({@link
|
|
538
|
-
*
|
|
539
|
-
* @deprecated Prefer `DescriptorProvider.signWithDescriptor()` via
|
|
540
|
-
* `HDDescriptorProvider` or `StaticDescriptorProvider`. Identities keep
|
|
541
|
-
* this method only as backing implementation for descriptor providers.
|
|
528
|
+
* Each descriptor must share this identity's seed ({@link ownsDescriptor}).
|
|
542
529
|
*/
|
|
543
|
-
async
|
|
530
|
+
async signDescriptorTransactions(requests) {
|
|
544
531
|
return requests.map((request) => {
|
|
545
|
-
if (!this.
|
|
532
|
+
if (!this.ownsDescriptor(request.descriptor)) {
|
|
546
533
|
throw new Error(
|
|
547
534
|
`Descriptor ${request.descriptor} does not belong to this identity`
|
|
548
535
|
);
|
|
@@ -551,15 +538,9 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
551
538
|
return this.signTxWithKey(request.tx, key, request.inputIndexes);
|
|
552
539
|
});
|
|
553
540
|
}
|
|
554
|
-
/**
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
* @deprecated Prefer `DescriptorProvider.signMessageWithDescriptor()` via
|
|
558
|
-
* `HDDescriptorProvider` or `StaticDescriptorProvider`. Identities keep
|
|
559
|
-
* this method only as backing implementation for descriptor providers.
|
|
560
|
-
*/
|
|
561
|
-
async signMessageWithDescriptor(descriptor, message, signatureType = "schnorr") {
|
|
562
|
-
if (!this.isOurs(descriptor)) {
|
|
541
|
+
/** Signs a message with the key derived from `descriptor`. */
|
|
542
|
+
async signDescriptorMessage(descriptor, message, signatureType = "schnorr") {
|
|
543
|
+
if (!this.ownsDescriptor(descriptor)) {
|
|
563
544
|
throw new Error(`Descriptor ${descriptor} does not belong to this identity`);
|
|
564
545
|
}
|
|
565
546
|
const key = this.derivePrivateKeyForDescriptor(descriptor);
|
|
@@ -571,7 +552,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
571
552
|
* which swap preimage derivation reads through.
|
|
572
553
|
*/
|
|
573
554
|
async signSchnorrDeterministicWithDescriptor(descriptor, messageHash) {
|
|
574
|
-
if (!this.
|
|
555
|
+
if (!this.ownsDescriptor(descriptor)) {
|
|
575
556
|
throw new Error(`Descriptor ${descriptor} does not belong to this identity`);
|
|
576
557
|
}
|
|
577
558
|
const key = this.derivePrivateKeyForDescriptor(descriptor);
|
|
@@ -579,7 +560,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
579
560
|
}
|
|
580
561
|
// ── internal helpers ─────────────────────────────────────────────
|
|
581
562
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
582
|
-
const network =
|
|
563
|
+
const network = chunkAEDYZK7T_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
583
564
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
584
565
|
if (expansion.isRanged) {
|
|
585
566
|
throw new Error(
|
|
@@ -604,7 +585,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
604
585
|
signTxWithKey(tx, key, inputIndexes) {
|
|
605
586
|
const txCpy = tx.clone();
|
|
606
587
|
if (!inputIndexes) {
|
|
607
|
-
|
|
588
|
+
chunkQWWOD7M2_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
|
|
608
589
|
try {
|
|
609
590
|
if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
|
|
610
591
|
throw new Error("Failed to sign transaction");
|
|
@@ -666,7 +647,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
666
647
|
*/
|
|
667
648
|
descriptor;
|
|
668
649
|
constructor(descriptor) {
|
|
669
|
-
const network =
|
|
650
|
+
const network = chunkAEDYZK7T_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
670
651
|
let expansion;
|
|
671
652
|
try {
|
|
672
653
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -705,18 +686,9 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
705
686
|
}
|
|
706
687
|
return bip32.publicKey;
|
|
707
688
|
}
|
|
708
|
-
/**
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
* fall back to comparing against the index-0 x-only pubkey. See
|
|
712
|
-
* {@link descriptorIsOurs}.
|
|
713
|
-
*
|
|
714
|
-
* @deprecated Prefer `DescriptorProvider.isOurs()` via
|
|
715
|
-
* `HDDescriptorProvider` for rotating HD wallets or
|
|
716
|
-
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
717
|
-
*/
|
|
718
|
-
isOurs(descriptor) {
|
|
719
|
-
return chunkUCSTNXB4_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
689
|
+
/** Returns true when `descriptor` derives from this identity's xpub. */
|
|
690
|
+
ownsDescriptor(descriptor) {
|
|
691
|
+
return chunkAEDYZK7T_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
720
692
|
}
|
|
721
693
|
};
|
|
722
694
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -805,25 +777,9 @@ function hydrateIdentity(s) {
|
|
|
805
777
|
);
|
|
806
778
|
}
|
|
807
779
|
}
|
|
808
|
-
var warnedLegacyShape = false;
|
|
809
780
|
function normalizeSerializedIdentity(shape) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
return shape;
|
|
813
|
-
}
|
|
814
|
-
if (!warnedLegacyShape) {
|
|
815
|
-
warnedLegacyShape = true;
|
|
816
|
-
console.warn(
|
|
817
|
-
"[ts-sdk] Received legacy serialized identity shape (privateKey/publicKey). Upgrade the page build to the latest @arkade-os/sdk \u2014 this compatibility path will be removed in the next major."
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
if ("privateKey" in shape && typeof shape.privateKey === "string") {
|
|
821
|
-
return { type: "single-key", privateKey: shape.privateKey };
|
|
822
|
-
}
|
|
823
|
-
if ("publicKey" in shape && typeof shape.publicKey === "string") {
|
|
824
|
-
return { type: "readonly-single-key", publicKey: shape.publicKey };
|
|
825
|
-
}
|
|
826
|
-
throw new Error("Unrecognized serialized identity shape");
|
|
781
|
+
assertValidSerializedIdentity(shape);
|
|
782
|
+
return shape;
|
|
827
783
|
}
|
|
828
784
|
function assertValidSerializedIdentity(s) {
|
|
829
785
|
const kind = s.type;
|
|
@@ -878,10 +834,10 @@ var DescriptorIdentity = class {
|
|
|
878
834
|
this.base = base;
|
|
879
835
|
}
|
|
880
836
|
async xOnlyPublicKey() {
|
|
881
|
-
return
|
|
837
|
+
return chunkAEDYZK7T_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
882
838
|
}
|
|
883
839
|
async compressedPublicKey() {
|
|
884
|
-
return
|
|
840
|
+
return chunkAEDYZK7T_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
|
|
885
841
|
}
|
|
886
842
|
async sign(tx, inputIndexes) {
|
|
887
843
|
const [signed] = await this.signer.signWithDescriptor([
|
|
@@ -921,7 +877,7 @@ var DescriptorIdentity = class {
|
|
|
921
877
|
function isHDCapableIdentity(value) {
|
|
922
878
|
if (typeof value !== "object" || value === null) return false;
|
|
923
879
|
const v = value;
|
|
924
|
-
return typeof v.descriptor === "string" && typeof v.
|
|
880
|
+
return typeof v.descriptor === "string" && typeof v.ownsDescriptor === "function" && typeof v.signDescriptorTransactions === "function" && typeof v.signDescriptorMessage === "function";
|
|
925
881
|
}
|
|
926
882
|
|
|
927
883
|
// src/identity/index.ts
|
|
@@ -948,13 +904,18 @@ var WalletCannotAllocateAddressError = class extends Error {
|
|
|
948
904
|
}
|
|
949
905
|
};
|
|
950
906
|
async function resolveDescriptorSigner(descriptor, identity, provider) {
|
|
951
|
-
const
|
|
952
|
-
|
|
907
|
+
const providerOwner = provider?.isOurs(descriptor) ? provider : void 0;
|
|
908
|
+
const identityOwner = !providerOwner && isHDCapableIdentity(identity) && identity.ownsDescriptor(descriptor) ? {
|
|
909
|
+
signWithDescriptor: (requests) => identity.signDescriptorTransactions(requests),
|
|
910
|
+
signMessageWithDescriptor: (ownedDescriptor, message, signatureType) => identity.signDescriptorMessage(ownedDescriptor, message, signatureType)
|
|
911
|
+
} : void 0;
|
|
912
|
+
const owner = providerOwner ?? identityOwner;
|
|
913
|
+
if (owner && chunkAEDYZK7T_cjs.parseHDDescriptor(descriptor)) {
|
|
953
914
|
return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
|
|
954
915
|
}
|
|
955
916
|
let key;
|
|
956
917
|
try {
|
|
957
|
-
key =
|
|
918
|
+
key = chunkAEDYZK7T_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
958
919
|
} catch {
|
|
959
920
|
throw new ForeignDescriptorError(descriptor);
|
|
960
921
|
}
|
|
@@ -1329,14 +1290,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
|
|
|
1329
1290
|
}
|
|
1330
1291
|
var PREIMAGE_INDEX = 0;
|
|
1331
1292
|
function isPerArtifactDescriptor(descriptor) {
|
|
1332
|
-
return
|
|
1293
|
+
return chunkAEDYZK7T_cjs.parseHDDescriptor(descriptor) !== null;
|
|
1333
1294
|
}
|
|
1334
1295
|
async function provisionDescriptor(wallet) {
|
|
1335
1296
|
const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
|
|
1336
|
-
return allocated ?? await
|
|
1297
|
+
return allocated ?? await chunkAEDYZK7T_cjs.identityDescriptor(wallet.identity);
|
|
1337
1298
|
}
|
|
1338
1299
|
async function provisionRefundKey(wallet) {
|
|
1339
|
-
const descriptor = await
|
|
1300
|
+
const descriptor = await chunkAEDYZK7T_cjs.identityDescriptor(wallet.identity);
|
|
1340
1301
|
const signer = await contractSigner(wallet, descriptor);
|
|
1341
1302
|
const pubkey = await signer.xOnlyPublicKey();
|
|
1342
1303
|
const identityPubkey = await wallet.identity.xOnlyPublicKey();
|
|
@@ -1346,7 +1307,7 @@ async function provisionRefundKey(wallet) {
|
|
|
1346
1307
|
);
|
|
1347
1308
|
}
|
|
1348
1309
|
const address = await wallet.getAddress();
|
|
1349
|
-
const { pkScript } =
|
|
1310
|
+
const { pkScript } = chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
1350
1311
|
return { descriptor, pubkey, pkScript, address };
|
|
1351
1312
|
}
|
|
1352
1313
|
async function provisionClaimSecret(wallet, opts = {}) {
|
|
@@ -1392,7 +1353,7 @@ async function contractSigner(wallet, descriptor) {
|
|
|
1392
1353
|
const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
|
|
1393
1354
|
let expected;
|
|
1394
1355
|
try {
|
|
1395
|
-
expected =
|
|
1356
|
+
expected = chunkAEDYZK7T_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1396
1357
|
} catch (cause) {
|
|
1397
1358
|
throw new ForeignDescriptorError(descriptor, { cause });
|
|
1398
1359
|
}
|
|
@@ -1611,14 +1572,14 @@ var RestDelegateProvider = class {
|
|
|
1611
1572
|
*/
|
|
1612
1573
|
async delegate(intent, forfeitTxs, options) {
|
|
1613
1574
|
const url = `${this.url}/v1/delegate`;
|
|
1614
|
-
const response = await
|
|
1575
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(url, {
|
|
1615
1576
|
method: "POST",
|
|
1616
1577
|
headers: {
|
|
1617
1578
|
"Content-Type": "application/json"
|
|
1618
1579
|
},
|
|
1619
1580
|
body: JSON.stringify({
|
|
1620
1581
|
intent: {
|
|
1621
|
-
message:
|
|
1582
|
+
message: chunkQWWOD7M2_cjs.Intent.encodeMessage(intent.message),
|
|
1622
1583
|
proof: intent.proof
|
|
1623
1584
|
},
|
|
1624
1585
|
forfeit_txs: forfeitTxs,
|
|
@@ -1638,7 +1599,7 @@ var RestDelegateProvider = class {
|
|
|
1638
1599
|
*/
|
|
1639
1600
|
async getDelegateInfo() {
|
|
1640
1601
|
const url = `${this.url}/v1/delegator/info`;
|
|
1641
|
-
const response = await
|
|
1602
|
+
const response = await chunkQWWOD7M2_cjs.rateGate.runHttp(url, () => chunkQWWOD7M2_cjs.baseFetch(url));
|
|
1642
1603
|
if (!response.ok) {
|
|
1643
1604
|
const errorText2 = await response.text();
|
|
1644
1605
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1647,13 +1608,11 @@ var RestDelegateProvider = class {
|
|
|
1647
1608
|
if (!isDelegateInfo(data)) {
|
|
1648
1609
|
throw new Error("Invalid delegate info");
|
|
1649
1610
|
}
|
|
1650
|
-
|
|
1651
|
-
return { ...data, delegateAddress };
|
|
1611
|
+
return data;
|
|
1652
1612
|
}
|
|
1653
1613
|
};
|
|
1654
|
-
var RestDelegatorProvider = RestDelegateProvider;
|
|
1655
1614
|
function isDelegateInfo(data) {
|
|
1656
|
-
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && typeof data.pubkey === "string" && typeof data.fee === "string" && data.pubkey !== "" && data.fee !== "" &&
|
|
1615
|
+
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && typeof data.pubkey === "string" && typeof data.fee === "string" && data.pubkey !== "" && data.fee !== "" && typeof data.delegateAddress === "string" && data.delegateAddress !== "";
|
|
1657
1616
|
}
|
|
1658
1617
|
var ESPLORA_URL = {
|
|
1659
1618
|
bitcoin: "https://mempool.arkade.sh/api",
|
|
@@ -1663,7 +1622,7 @@ var ESPLORA_URL = {
|
|
|
1663
1622
|
regtest: "http://localhost:3000/api"
|
|
1664
1623
|
};
|
|
1665
1624
|
var EsploraProvider = class {
|
|
1666
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1625
|
+
constructor(baseUrl = ESPLORA_URL[chunkQWWOD7M2_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1667
1626
|
this.baseUrl = baseUrl;
|
|
1668
1627
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1669
1628
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1682,14 +1641,14 @@ var EsploraProvider = class {
|
|
|
1682
1641
|
*/
|
|
1683
1642
|
addressWatches = /* @__PURE__ */ new Map();
|
|
1684
1643
|
async getCoins(address) {
|
|
1685
|
-
const response = await
|
|
1644
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1686
1645
|
if (!response.ok) {
|
|
1687
1646
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1688
1647
|
}
|
|
1689
1648
|
return response.json();
|
|
1690
1649
|
}
|
|
1691
1650
|
async getFeeRate() {
|
|
1692
|
-
const response = await
|
|
1651
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1693
1652
|
if (response.status === 404) {
|
|
1694
1653
|
return void 0;
|
|
1695
1654
|
}
|
|
@@ -1710,7 +1669,7 @@ var EsploraProvider = class {
|
|
|
1710
1669
|
}
|
|
1711
1670
|
}
|
|
1712
1671
|
async getTxOutspends(txid) {
|
|
1713
|
-
const response = await
|
|
1672
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1714
1673
|
if (!response.ok) {
|
|
1715
1674
|
const error = await response.text();
|
|
1716
1675
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1718,7 +1677,7 @@ var EsploraProvider = class {
|
|
|
1718
1677
|
return response.json();
|
|
1719
1678
|
}
|
|
1720
1679
|
async getTransactions(address) {
|
|
1721
|
-
const response = await
|
|
1680
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1722
1681
|
if (!response.ok) {
|
|
1723
1682
|
const error = await response.text();
|
|
1724
1683
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1731,14 +1690,14 @@ var EsploraProvider = class {
|
|
|
1731
1690
|
* usable as a change probe for the polling fallback.
|
|
1732
1691
|
*/
|
|
1733
1692
|
async getAddressStats(address) {
|
|
1734
|
-
const response = await
|
|
1693
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
|
|
1735
1694
|
if (!response.ok) {
|
|
1736
1695
|
throw new Error(`Failed to get address stats: ${response.statusText}`);
|
|
1737
1696
|
}
|
|
1738
1697
|
return response.json();
|
|
1739
1698
|
}
|
|
1740
1699
|
async getRawTransaction(txid) {
|
|
1741
|
-
const response = await
|
|
1700
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
1742
1701
|
if (!response.ok) {
|
|
1743
1702
|
const error = await response.text();
|
|
1744
1703
|
throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
|
|
@@ -1746,7 +1705,7 @@ var EsploraProvider = class {
|
|
|
1746
1705
|
return base.hex.decode((await response.text()).trim());
|
|
1747
1706
|
}
|
|
1748
1707
|
async getTxStatus(txid) {
|
|
1749
|
-
const txresponse = await
|
|
1708
|
+
const txresponse = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1750
1709
|
if (!txresponse.ok) {
|
|
1751
1710
|
throw new Error(txresponse.statusText);
|
|
1752
1711
|
}
|
|
@@ -1754,7 +1713,7 @@ var EsploraProvider = class {
|
|
|
1754
1713
|
if (!tx.status.confirmed) {
|
|
1755
1714
|
return { confirmed: false };
|
|
1756
1715
|
}
|
|
1757
|
-
const response = await
|
|
1716
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1758
1717
|
if (!response.ok) {
|
|
1759
1718
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1760
1719
|
}
|
|
@@ -2038,7 +1997,10 @@ var EsploraProvider = class {
|
|
|
2038
1997
|
return { subscribers, teardown, started };
|
|
2039
1998
|
}
|
|
2040
1999
|
async getChainTip() {
|
|
2041
|
-
|
|
2000
|
+
let tipBlocks = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2001
|
+
if (tipBlocks.status === 404) {
|
|
2002
|
+
tipBlocks = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
|
|
2003
|
+
}
|
|
2042
2004
|
if (!tipBlocks.ok) {
|
|
2043
2005
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
2044
2006
|
}
|
|
@@ -2059,7 +2021,7 @@ var EsploraProvider = class {
|
|
|
2059
2021
|
};
|
|
2060
2022
|
}
|
|
2061
2023
|
async broadcastPackage(parent, child) {
|
|
2062
|
-
const response = await
|
|
2024
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
2063
2025
|
method: "POST",
|
|
2064
2026
|
headers: {
|
|
2065
2027
|
"Content-Type": "application/json"
|
|
@@ -2075,7 +2037,7 @@ var EsploraProvider = class {
|
|
|
2075
2037
|
return result;
|
|
2076
2038
|
}
|
|
2077
2039
|
async broadcastTx(tx) {
|
|
2078
|
-
const response = await
|
|
2040
|
+
const response = await chunkQWWOD7M2_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
2079
2041
|
method: "POST",
|
|
2080
2042
|
headers: {
|
|
2081
2043
|
"Content-Type": "text/plain"
|
|
@@ -2258,7 +2220,7 @@ function findP2AOutput(tx) {
|
|
|
2258
2220
|
var CHILD_DUST_AMOUNT = 546;
|
|
2259
2221
|
function buildAnchorChild(params) {
|
|
2260
2222
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2261
|
-
const child = new
|
|
2223
|
+
const child = new chunkQWWOD7M2_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2262
2224
|
child.addInput(findP2AOutput(parent));
|
|
2263
2225
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
2264
2226
|
for (const _ of fundingCoins) {
|
|
@@ -2306,7 +2268,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
2306
2268
|
);
|
|
2307
2269
|
}
|
|
2308
2270
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
2309
|
-
const tx = new
|
|
2271
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({
|
|
2310
2272
|
version: 3,
|
|
2311
2273
|
lockTime: txLocktime
|
|
2312
2274
|
});
|
|
@@ -2382,7 +2344,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
2382
2344
|
if (previousScriptKey.length !== 32) {
|
|
2383
2345
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
2384
2346
|
}
|
|
2385
|
-
const cosigners =
|
|
2347
|
+
const cosigners = chunkQWWOD7M2_cjs.getArkPsbtFields(child.root, 0, chunkQWWOD7M2_cjs.CosignerPublicKey);
|
|
2386
2348
|
if (cosigners.length === 0) {
|
|
2387
2349
|
throw ErrMissingCosignersPublicKeys;
|
|
2388
2350
|
}
|
|
@@ -2440,7 +2402,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2440
2402
|
return new _EmulatorPacket(entries);
|
|
2441
2403
|
}
|
|
2442
2404
|
static fromBytes(data) {
|
|
2443
|
-
const reader = new
|
|
2405
|
+
const reader = new chunkNEVMOIQL_cjs.BufferReader(data);
|
|
2444
2406
|
const entryCount = reader.readCompactSize();
|
|
2445
2407
|
const entries = [];
|
|
2446
2408
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -2458,7 +2420,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2458
2420
|
return _EmulatorPacket.PACKET_TYPE;
|
|
2459
2421
|
}
|
|
2460
2422
|
serialize() {
|
|
2461
|
-
const writer = new
|
|
2423
|
+
const writer = new chunkNEVMOIQL_cjs.BufferWriter();
|
|
2462
2424
|
writer.writeCompactSize(this.entries.length);
|
|
2463
2425
|
for (const entry of this.entries) {
|
|
2464
2426
|
writer.writeUint16LE(entry.vin);
|
|
@@ -2545,7 +2507,7 @@ var Extension = class _Extension {
|
|
|
2545
2507
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
2546
2508
|
);
|
|
2547
2509
|
}
|
|
2548
|
-
const reader = new
|
|
2510
|
+
const reader = new chunkNEVMOIQL_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
2549
2511
|
const packets = [];
|
|
2550
2512
|
while (reader.remaining() > 0) {
|
|
2551
2513
|
const packetType = reader.readByte();
|
|
@@ -2619,7 +2581,7 @@ var Extension = class _Extension {
|
|
|
2619
2581
|
*/
|
|
2620
2582
|
getAssetPacket() {
|
|
2621
2583
|
for (const p of this.packets) {
|
|
2622
|
-
if (p instanceof
|
|
2584
|
+
if (p instanceof chunkNEVMOIQL_cjs.Packet) {
|
|
2623
2585
|
return p;
|
|
2624
2586
|
}
|
|
2625
2587
|
}
|
|
@@ -2657,8 +2619,8 @@ var Extension = class _Extension {
|
|
|
2657
2619
|
};
|
|
2658
2620
|
function parsePacket(packetType, data) {
|
|
2659
2621
|
switch (packetType) {
|
|
2660
|
-
case
|
|
2661
|
-
return
|
|
2622
|
+
case chunkNEVMOIQL_cjs.Packet.PACKET_TYPE:
|
|
2623
|
+
return chunkNEVMOIQL_cjs.Packet.fromBytes(data);
|
|
2662
2624
|
case EmulatorPacket.PACKET_TYPE:
|
|
2663
2625
|
return EmulatorPacket.fromBytes(data);
|
|
2664
2626
|
default:
|
|
@@ -2705,16 +2667,16 @@ function buildOpReturnScript(data) {
|
|
|
2705
2667
|
}
|
|
2706
2668
|
return script;
|
|
2707
2669
|
}
|
|
2708
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
2709
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
2670
|
+
var ErrOffchainOutputNotFound = (address) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2671
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
2710
2672
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
2711
2673
|
);
|
|
2712
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
2713
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
2674
|
+
var ErrAssetGroupNotFound = (assetId) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2675
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
2714
2676
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
2715
2677
|
);
|
|
2716
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
2717
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
2678
|
+
var ErrOnchainOutputNotFound = (address) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2679
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
2718
2680
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
2719
2681
|
);
|
|
2720
2682
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
@@ -2723,7 +2685,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
2723
2685
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
2724
2686
|
if (!validatedCommitmentTxid) return;
|
|
2725
2687
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
2726
|
-
throw new
|
|
2688
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
2727
2689
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
2728
2690
|
);
|
|
2729
2691
|
}
|
|
@@ -2733,7 +2695,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
2733
2695
|
for (const recipient of recipients) {
|
|
2734
2696
|
let arkAddress;
|
|
2735
2697
|
try {
|
|
2736
|
-
arkAddress =
|
|
2698
|
+
arkAddress = chunkQWWOD7M2_cjs.ArkAddress.decode(recipient.address);
|
|
2737
2699
|
} catch {
|
|
2738
2700
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2739
2701
|
continue;
|
|
@@ -2745,7 +2707,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2745
2707
|
const usedOnchainOutputs = /* @__PURE__ */ new Set();
|
|
2746
2708
|
for (const recipient of recipients) {
|
|
2747
2709
|
try {
|
|
2748
|
-
|
|
2710
|
+
chunkQWWOD7M2_cjs.ArkAddress.decode(recipient.address);
|
|
2749
2711
|
} catch {
|
|
2750
2712
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2751
2713
|
continue;
|
|
@@ -2978,7 +2940,7 @@ function assetMintResolver() {
|
|
|
2978
2940
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
2979
2941
|
const minted = tx.assets.filter((a) => {
|
|
2980
2942
|
try {
|
|
2981
|
-
return base.hex.encode(
|
|
2943
|
+
return base.hex.encode(chunkNEVMOIQL_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
2982
2944
|
} catch {
|
|
2983
2945
|
return false;
|
|
2984
2946
|
}
|
|
@@ -3021,7 +2983,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3021
2983
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
3022
2984
|
inputsByAssetId.set(asset.assetId, [
|
|
3023
2985
|
...existing ?? [],
|
|
3024
|
-
|
|
2986
|
+
chunkNEVMOIQL_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
3025
2987
|
]);
|
|
3026
2988
|
}
|
|
3027
2989
|
}
|
|
@@ -3033,7 +2995,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3033
2995
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3034
2996
|
outputsByAssetId.set(asset.assetId, [
|
|
3035
2997
|
...existing ?? [],
|
|
3036
|
-
|
|
2998
|
+
chunkNEVMOIQL_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3037
2999
|
]);
|
|
3038
3000
|
}
|
|
3039
3001
|
}
|
|
@@ -3044,7 +3006,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3044
3006
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3045
3007
|
outputsByAssetId.set(asset.assetId, [
|
|
3046
3008
|
...existing ?? [],
|
|
3047
|
-
|
|
3009
|
+
chunkNEVMOIQL_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3048
3010
|
]);
|
|
3049
3011
|
}
|
|
3050
3012
|
}
|
|
@@ -3053,11 +3015,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3053
3015
|
for (const assetIdStr of allAssetIds) {
|
|
3054
3016
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
3055
3017
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
3056
|
-
const assetId =
|
|
3057
|
-
const group =
|
|
3018
|
+
const assetId = chunkNEVMOIQL_cjs.AssetId.fromString(assetIdStr);
|
|
3019
|
+
const group = chunkNEVMOIQL_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3058
3020
|
groups.push(group);
|
|
3059
3021
|
}
|
|
3060
|
-
return
|
|
3022
|
+
return chunkNEVMOIQL_cjs.Packet.create(groups);
|
|
3061
3023
|
}
|
|
3062
3024
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
3063
3025
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -3094,7 +3056,7 @@ function selectedCoinsToAssetInputs(selectedCoins) {
|
|
|
3094
3056
|
}
|
|
3095
3057
|
function toXOnlySignerHex(pubkeyHex) {
|
|
3096
3058
|
const bytes = base.hex.decode(pubkeyHex);
|
|
3097
|
-
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(
|
|
3059
|
+
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunkAEDYZK7T_cjs.toXOnly(bytes, "signer key"));
|
|
3098
3060
|
throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes.length}`);
|
|
3099
3061
|
}
|
|
3100
3062
|
function signerSetFromInfo(info) {
|
|
@@ -3141,13 +3103,13 @@ var toTimelock = (value) => ({
|
|
|
3141
3103
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
3142
3104
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
3143
3105
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
3144
|
-
throw new
|
|
3106
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3145
3107
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
3146
3108
|
);
|
|
3147
3109
|
}
|
|
3148
3110
|
const seconds = toSeconds(timelock);
|
|
3149
3111
|
if (seconds < policy.minSeconds) {
|
|
3150
|
-
throw new
|
|
3112
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3151
3113
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it`
|
|
3152
3114
|
);
|
|
3153
3115
|
}
|
|
@@ -3168,7 +3130,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
3168
3130
|
}
|
|
3169
3131
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
3170
3132
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
3171
|
-
throw new
|
|
3133
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3172
3134
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
3173
3135
|
);
|
|
3174
3136
|
}
|
|
@@ -3198,21 +3160,21 @@ function resolveCheckpointExitDelayPolicy(network, overrides) {
|
|
|
3198
3160
|
function assertValidServerUnrollScript(checkpointTapscript, policy) {
|
|
3199
3161
|
let script;
|
|
3200
3162
|
try {
|
|
3201
|
-
script =
|
|
3163
|
+
script = chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
3202
3164
|
} catch (e) {
|
|
3203
|
-
throw new
|
|
3165
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3204
3166
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
3205
3167
|
);
|
|
3206
3168
|
}
|
|
3207
3169
|
if (policy.advertisedForfeitPubkey !== void 0) {
|
|
3208
3170
|
const { pubkeys } = script.params;
|
|
3209
3171
|
if (pubkeys.length !== 1) {
|
|
3210
|
-
throw new
|
|
3172
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3211
3173
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
3212
3174
|
);
|
|
3213
3175
|
}
|
|
3214
3176
|
if (!utils_js.equalBytes(pubkeys[0], policy.advertisedForfeitPubkey)) {
|
|
3215
|
-
throw new
|
|
3177
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3216
3178
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(policy.advertisedForfeitPubkey)}`
|
|
3217
3179
|
);
|
|
3218
3180
|
}
|
|
@@ -3256,8 +3218,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
3256
3218
|
function buildVirtualTx(inputs, outputs) {
|
|
3257
3219
|
let lockTime = 0n;
|
|
3258
3220
|
for (const input of inputs) {
|
|
3259
|
-
const tapscript =
|
|
3260
|
-
if (
|
|
3221
|
+
const tapscript = chunkQWWOD7M2_cjs.decodeTapscript(chunkQWWOD7M2_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3222
|
+
if (chunkQWWOD7M2_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
3261
3223
|
if (lockTime !== 0n) {
|
|
3262
3224
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
3263
3225
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -3268,7 +3230,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3268
3230
|
}
|
|
3269
3231
|
}
|
|
3270
3232
|
}
|
|
3271
|
-
const tx = new
|
|
3233
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({
|
|
3272
3234
|
version: 3,
|
|
3273
3235
|
lockTime: Number(lockTime)
|
|
3274
3236
|
});
|
|
@@ -3278,12 +3240,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3278
3240
|
index: input.vout,
|
|
3279
3241
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
3280
3242
|
witnessUtxo: {
|
|
3281
|
-
script:
|
|
3243
|
+
script: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3282
3244
|
amount: BigInt(input.value)
|
|
3283
3245
|
},
|
|
3284
3246
|
tapLeafScript: [input.tapLeafScript]
|
|
3285
3247
|
});
|
|
3286
|
-
|
|
3248
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(tx, i, chunkQWWOD7M2_cjs.VtxoTaprootTree, input.tapTree);
|
|
3287
3249
|
}
|
|
3288
3250
|
for (const output of outputs) {
|
|
3289
3251
|
tx.addOutput(output);
|
|
@@ -3292,8 +3254,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3292
3254
|
return tx;
|
|
3293
3255
|
}
|
|
3294
3256
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
3295
|
-
const collaborativeClosure =
|
|
3296
|
-
const checkpointVtxoScript = new
|
|
3257
|
+
const collaborativeClosure = chunkQWWOD7M2_cjs.decodeTapscript(chunkQWWOD7M2_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3258
|
+
const checkpointVtxoScript = new chunkQWWOD7M2_cjs.VtxoScript([
|
|
3297
3259
|
serverUnrollScript.script,
|
|
3298
3260
|
collaborativeClosure.script
|
|
3299
3261
|
]);
|
|
@@ -3369,7 +3331,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
3369
3331
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
3370
3332
|
const sig = signature.subarray(0, 64);
|
|
3371
3333
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
3372
|
-
const sighashName =
|
|
3334
|
+
const sighashName = chunkQWWOD7M2_cjs.formatSighash(sighashType);
|
|
3373
3335
|
throw new Error(
|
|
3374
3336
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
3375
3337
|
);
|
|
@@ -3443,7 +3405,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
3443
3405
|
}
|
|
3444
3406
|
function isValidArkAddress(address) {
|
|
3445
3407
|
try {
|
|
3446
|
-
|
|
3408
|
+
chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
3447
3409
|
return true;
|
|
3448
3410
|
} catch (e) {
|
|
3449
3411
|
return false;
|
|
@@ -3451,16 +3413,16 @@ function isValidArkAddress(address) {
|
|
|
3451
3413
|
}
|
|
3452
3414
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
3453
3415
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
3454
|
-
throw new
|
|
3416
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3455
3417
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
3456
3418
|
);
|
|
3457
3419
|
}
|
|
3458
3420
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
3459
3421
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
3460
|
-
const server =
|
|
3422
|
+
const server = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
3461
3423
|
const local = byTxid.get(server.id);
|
|
3462
3424
|
if (!local) {
|
|
3463
|
-
throw new
|
|
3425
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3464
3426
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
3465
3427
|
);
|
|
3466
3428
|
}
|
|
@@ -3470,14 +3432,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
3470
3432
|
}
|
|
3471
3433
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
3472
3434
|
if (response.arkTxid !== signedArkTx.id) {
|
|
3473
|
-
throw new
|
|
3435
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3474
3436
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
3475
3437
|
);
|
|
3476
3438
|
}
|
|
3477
3439
|
if (response.finalArkTx === void 0) return;
|
|
3478
|
-
const finalTxid =
|
|
3440
|
+
const finalTxid = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3479
3441
|
if (finalTxid !== signedArkTx.id) {
|
|
3480
|
-
throw new
|
|
3442
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3481
3443
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
3482
3444
|
);
|
|
3483
3445
|
}
|
|
@@ -3496,10 +3458,10 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeyHex,
|
|
|
3496
3458
|
[serverPubkeyHex],
|
|
3497
3459
|
void 0,
|
|
3498
3460
|
void 0,
|
|
3499
|
-
payment_js.tapLeafHash(
|
|
3461
|
+
payment_js.tapLeafHash(chunkQWWOD7M2_cjs.scriptFromTapLeafScript(leaf))
|
|
3500
3462
|
);
|
|
3501
3463
|
} catch (error) {
|
|
3502
|
-
throw new
|
|
3464
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3503
3465
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
3504
3466
|
);
|
|
3505
3467
|
}
|
|
@@ -3508,20 +3470,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3508
3470
|
const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
|
|
3509
3471
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
3510
3472
|
if (checkpoint.inputsLength !== 1) {
|
|
3511
|
-
throw new
|
|
3473
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3512
3474
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
3513
3475
|
);
|
|
3514
3476
|
}
|
|
3515
3477
|
const spent = checkpoint.getInput(0);
|
|
3516
3478
|
if (!spent.txid || spent.index === void 0) {
|
|
3517
|
-
throw new
|
|
3479
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3518
3480
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
3519
3481
|
);
|
|
3520
3482
|
}
|
|
3521
3483
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
3522
3484
|
const input = byOutpoint.get(outpoint);
|
|
3523
3485
|
if (!input) {
|
|
3524
|
-
throw new
|
|
3486
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3525
3487
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
3526
3488
|
);
|
|
3527
3489
|
}
|
|
@@ -3529,7 +3491,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3529
3491
|
(unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
|
|
3530
3492
|
);
|
|
3531
3493
|
if (!rebuilt) {
|
|
3532
|
-
throw new
|
|
3494
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3533
3495
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
3534
3496
|
);
|
|
3535
3497
|
}
|
|
@@ -3555,9 +3517,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3555
3517
|
const matched = matchServerCheckpoints(signedCheckpointTxs, offchainTx.checkpoints, "submitTx");
|
|
3556
3518
|
matched.forEach(({ server }, index) => {
|
|
3557
3519
|
try {
|
|
3558
|
-
|
|
3520
|
+
chunkQWWOD7M2_cjs.assertAllowedSighashTypes(server);
|
|
3559
3521
|
} catch (error) {
|
|
3560
|
-
throw new
|
|
3522
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3561
3523
|
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
3562
3524
|
);
|
|
3563
3525
|
}
|
|
@@ -3565,12 +3527,12 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3565
3527
|
const verify = options?.verifyServerSignatures;
|
|
3566
3528
|
if (verify) {
|
|
3567
3529
|
if (response.finalArkTx === void 0) {
|
|
3568
|
-
throw new
|
|
3530
|
+
throw new chunkQWWOD7M2_cjs.ServerResponseMismatchError(
|
|
3569
3531
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
3570
3532
|
);
|
|
3571
3533
|
}
|
|
3572
|
-
const finalArkTx =
|
|
3573
|
-
const serverPubkeyHex = base.hex.encode(
|
|
3534
|
+
const finalArkTx = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
3535
|
+
const serverPubkeyHex = base.hex.encode(chunkAEDYZK7T_cjs.toXOnly(verify.serverPubkey, "server key"));
|
|
3574
3536
|
for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
|
|
3575
3537
|
assertServerSignedLeaf(
|
|
3576
3538
|
finalArkTx,
|
|
@@ -3626,17 +3588,37 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
3626
3588
|
return {
|
|
3627
3589
|
...identity,
|
|
3628
3590
|
sign: async (tx, inputIndexes) => {
|
|
3629
|
-
const signed =
|
|
3591
|
+
const signed = chunkQWWOD7M2_cjs.Transaction.fromPSBT(
|
|
3630
3592
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
3631
3593
|
);
|
|
3632
3594
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
3633
3595
|
for (const index of indexes) {
|
|
3634
|
-
|
|
3596
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(signed, index, chunkQWWOD7M2_cjs.ConditionWitness, [preimage]);
|
|
3635
3597
|
}
|
|
3636
3598
|
return signed;
|
|
3637
3599
|
}
|
|
3638
3600
|
};
|
|
3639
3601
|
}
|
|
3602
|
+
|
|
3603
|
+
// src/contracts/types.ts
|
|
3604
|
+
function watchStateOf(contract) {
|
|
3605
|
+
return contract.watch ?? "watched";
|
|
3606
|
+
}
|
|
3607
|
+
function isWatchedContract(contract) {
|
|
3608
|
+
return watchStateOf(contract) !== "retained";
|
|
3609
|
+
}
|
|
3610
|
+
function hasCandidates(handler) {
|
|
3611
|
+
return !!handler && typeof handler.candidatesAt === "function";
|
|
3612
|
+
}
|
|
3613
|
+
function isDiscoverable(handler) {
|
|
3614
|
+
return !!handler && typeof handler.discoverAt === "function";
|
|
3615
|
+
}
|
|
3616
|
+
function isTapscriptDeriving(handler) {
|
|
3617
|
+
return !!handler && typeof handler.deriveTapscripts === "function";
|
|
3618
|
+
}
|
|
3619
|
+
function isContractVtxoEvent(event) {
|
|
3620
|
+
return "contract" in event && event.contract !== void 0;
|
|
3621
|
+
}
|
|
3640
3622
|
var AmountVariableName = "amount";
|
|
3641
3623
|
var ExpiryVariableName = "expiry";
|
|
3642
3624
|
var BirthVariableName = "birth";
|
|
@@ -3792,23 +3774,6 @@ function parseProgram(text, env) {
|
|
|
3792
3774
|
}
|
|
3793
3775
|
return { program, text };
|
|
3794
3776
|
}
|
|
3795
|
-
|
|
3796
|
-
// src/contracts/types.ts
|
|
3797
|
-
function watchStateOf(contract) {
|
|
3798
|
-
return contract.watch ?? "watched";
|
|
3799
|
-
}
|
|
3800
|
-
function isWatchedContract(contract) {
|
|
3801
|
-
return watchStateOf(contract) !== "retained";
|
|
3802
|
-
}
|
|
3803
|
-
function hasCandidates(handler) {
|
|
3804
|
-
return !!handler && typeof handler.candidatesAt === "function";
|
|
3805
|
-
}
|
|
3806
|
-
function isDiscoverable(handler) {
|
|
3807
|
-
return !!handler && typeof handler.discoverAt === "function";
|
|
3808
|
-
}
|
|
3809
|
-
function isTapscriptDeriving(handler) {
|
|
3810
|
-
return !!handler && typeof handler.deriveTapscripts === "function";
|
|
3811
|
-
}
|
|
3812
3777
|
var DUST_AMOUNT = 546;
|
|
3813
3778
|
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
3814
3779
|
function getDustAmount(wallet) {
|
|
@@ -3823,7 +3788,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
3823
3788
|
};
|
|
3824
3789
|
}
|
|
3825
3790
|
function deriveContractTapscripts(contract) {
|
|
3826
|
-
const handler =
|
|
3791
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
3827
3792
|
if (!handler) {
|
|
3828
3793
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3829
3794
|
}
|
|
@@ -3894,7 +3859,7 @@ function getRandomId() {
|
|
|
3894
3859
|
}
|
|
3895
3860
|
function isValidArkAddress2(address) {
|
|
3896
3861
|
try {
|
|
3897
|
-
|
|
3862
|
+
chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
3898
3863
|
return true;
|
|
3899
3864
|
} catch (e) {
|
|
3900
3865
|
return false;
|
|
@@ -3922,7 +3887,7 @@ function assertRecipientArkadeAddress(encoded, address, context) {
|
|
|
3922
3887
|
function assertTapTreeDerivesAddress(encoded, tapTree, address) {
|
|
3923
3888
|
let derived;
|
|
3924
3889
|
try {
|
|
3925
|
-
derived =
|
|
3890
|
+
derived = chunkQWWOD7M2_cjs.VtxoScript.decode(tapTree).pkScript;
|
|
3926
3891
|
} catch (e) {
|
|
3927
3892
|
throw new Error(
|
|
3928
3893
|
`Invalid tapTree for ${encoded}: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -3939,7 +3904,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
3939
3904
|
for (const recipient of recipients) {
|
|
3940
3905
|
let address;
|
|
3941
3906
|
try {
|
|
3942
|
-
address =
|
|
3907
|
+
address = chunkQWWOD7M2_cjs.ArkAddress.decode(recipient.address);
|
|
3943
3908
|
} catch (e) {
|
|
3944
3909
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
3945
3910
|
}
|
|
@@ -3964,7 +3929,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
3964
3929
|
|
|
3965
3930
|
// src/contracts/spendability.ts
|
|
3966
3931
|
function isContractGenericallySpendable(contract) {
|
|
3967
|
-
return
|
|
3932
|
+
return chunkAEDYZK7T_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
3968
3933
|
}
|
|
3969
3934
|
function gatedContracts(contracts) {
|
|
3970
3935
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -3977,7 +3942,7 @@ function gateExclusion(gated) {
|
|
|
3977
3942
|
return (vtxo) => {
|
|
3978
3943
|
const type = vtxo.script === void 0 ? void 0 : gated.get(vtxo.script);
|
|
3979
3944
|
if (type === void 0) return void 0;
|
|
3980
|
-
if (!
|
|
3945
|
+
if (!chunkAEDYZK7T_cjs.contractHandlers.has(type)) {
|
|
3981
3946
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
3982
3947
|
}
|
|
3983
3948
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -4013,7 +3978,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
4013
3978
|
continue;
|
|
4014
3979
|
}
|
|
4015
3980
|
for (const v of vtxos) {
|
|
4016
|
-
if (!
|
|
3981
|
+
if (!chunkQWWOD7M2_cjs.hasTerminalSpend(v) && !v.isSwept && !v.isUnrolled) {
|
|
4017
3982
|
out.add(`${v.txid}:${v.vout}`);
|
|
4018
3983
|
}
|
|
4019
3984
|
}
|
|
@@ -4048,10 +4013,10 @@ function byValueDescending(vtxos) {
|
|
|
4048
4013
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
4049
4014
|
}
|
|
4050
4015
|
async function fetchTimeHeight(wallet) {
|
|
4051
|
-
return
|
|
4016
|
+
return chunkQWWOD7M2_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
4052
4017
|
}
|
|
4053
4018
|
function canMigrateBySend(vtxo, now) {
|
|
4054
|
-
if (!
|
|
4019
|
+
if (!chunkQWWOD7M2_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
4055
4020
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
4056
4021
|
}
|
|
4057
4022
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -4059,7 +4024,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
4059
4024
|
if (vtxo.isSwept) return -Infinity;
|
|
4060
4025
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
4061
4026
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
4062
|
-
return
|
|
4027
|
+
return chunkQWWOD7M2_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
4063
4028
|
}
|
|
4064
4029
|
return Infinity;
|
|
4065
4030
|
};
|
|
@@ -4086,7 +4051,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
4086
4051
|
const payable = [];
|
|
4087
4052
|
const net = /* @__PURE__ */ new Map();
|
|
4088
4053
|
for (const vtxo of vtxos) {
|
|
4089
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4054
|
+
const inputFee = estimator.evalOffchainInput(chunkQWWOD7M2_cjs.toOffchainInputFeeParams(vtxo));
|
|
4090
4055
|
if (inputFee.satoshis >= vtxo.value) {
|
|
4091
4056
|
continue;
|
|
4092
4057
|
}
|
|
@@ -4112,16 +4077,12 @@ function deductOffchainOutputFee(subtotal, estimator, arkAddress) {
|
|
|
4112
4077
|
}
|
|
4113
4078
|
const outputFee = estimator.evalOffchainOutput({
|
|
4114
4079
|
amount: subtotal,
|
|
4115
|
-
script: base.hex.encode(
|
|
4080
|
+
script: base.hex.encode(chunkQWWOD7M2_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4116
4081
|
});
|
|
4117
4082
|
return subtotal - BigInt(outputFee.satoshis);
|
|
4118
4083
|
}
|
|
4119
4084
|
var DEFAULT_THRESHOLD_SECONDS = 259200;
|
|
4120
4085
|
var DEFAULT_THRESHOLD_MS = DEFAULT_THRESHOLD_SECONDS * 1e3;
|
|
4121
|
-
var DEFAULT_RENEWAL_CONFIG = {
|
|
4122
|
-
thresholdMs: DEFAULT_THRESHOLD_MS
|
|
4123
|
-
// 3 days
|
|
4124
|
-
};
|
|
4125
4086
|
var DEFAULT_SETTLEMENT_CONFIG = {
|
|
4126
4087
|
vtxoThreshold: DEFAULT_THRESHOLD_SECONDS,
|
|
4127
4088
|
boardingUtxoSweep: true,
|
|
@@ -4130,10 +4091,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
4130
4091
|
};
|
|
4131
4092
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
4132
4093
|
return vtxos.filter((vtxo) => {
|
|
4133
|
-
if (
|
|
4094
|
+
if (chunkQWWOD7M2_cjs.canRecoverOnchain(vtxo, now)) {
|
|
4134
4095
|
return true;
|
|
4135
4096
|
}
|
|
4136
|
-
if (
|
|
4097
|
+
if (chunkQWWOD7M2_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
4137
4098
|
return true;
|
|
4138
4099
|
}
|
|
4139
4100
|
return false;
|
|
@@ -4165,7 +4126,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
4165
4126
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
4166
4127
|
if (vtxo.isUnrolled) return false;
|
|
4167
4128
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
4168
|
-
const expiresAt =
|
|
4129
|
+
const expiresAt = chunkQWWOD7M2_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
4169
4130
|
if (expiresAt === void 0) return false;
|
|
4170
4131
|
const now = Date.now();
|
|
4171
4132
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -4176,7 +4137,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
|
4176
4137
|
return vtxos.filter(
|
|
4177
4138
|
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
4178
4139
|
// property and would otherwise re-admit an exited coin on its own.
|
|
4179
|
-
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
4140
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkQWWOD7M2_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
4180
4141
|
);
|
|
4181
4142
|
}
|
|
4182
4143
|
function isMigrationCapable(wallet) {
|
|
@@ -4225,24 +4186,12 @@ function mergeSignerReports(...reportLists) {
|
|
|
4225
4186
|
return Array.from(bySigner.values());
|
|
4226
4187
|
}
|
|
4227
4188
|
var VtxoManager = class _VtxoManager {
|
|
4228
|
-
constructor(wallet,
|
|
4189
|
+
constructor(wallet, settlementConfig) {
|
|
4229
4190
|
this.wallet = wallet;
|
|
4230
|
-
this.
|
|
4231
|
-
if (settlementConfig !== void 0) {
|
|
4232
|
-
this.settlementConfig = settlementConfig;
|
|
4233
|
-
} else if (renewalConfig && renewalConfig.enabled) {
|
|
4234
|
-
this.settlementConfig = {
|
|
4235
|
-
vtxoThreshold: renewalConfig.thresholdMs ? renewalConfig.thresholdMs / 1e3 : void 0
|
|
4236
|
-
};
|
|
4237
|
-
} else if (renewalConfig) {
|
|
4238
|
-
this.settlementConfig = false;
|
|
4239
|
-
} else {
|
|
4240
|
-
this.settlementConfig = { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
4241
|
-
}
|
|
4191
|
+
this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
4242
4192
|
this.contractEventsSubscriptionReady = this.initializeSubscription();
|
|
4243
4193
|
}
|
|
4244
4194
|
wallet;
|
|
4245
|
-
renewalConfig;
|
|
4246
4195
|
settlementConfig;
|
|
4247
4196
|
contractEventsSubscriptionReady;
|
|
4248
4197
|
disposePromise;
|
|
@@ -4547,7 +4496,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4547
4496
|
} else if (this.settlementConfig !== false && this.settlementConfig && this.settlementConfig.vtxoThreshold !== void 0) {
|
|
4548
4497
|
threshold = this.settlementConfig.vtxoThreshold * 1e3;
|
|
4549
4498
|
} else {
|
|
4550
|
-
threshold =
|
|
4499
|
+
threshold = DEFAULT_THRESHOLD_MS;
|
|
4551
4500
|
}
|
|
4552
4501
|
return getExpiringAndRecoverableVtxos(
|
|
4553
4502
|
vtxos,
|
|
@@ -4605,7 +4554,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4605
4554
|
} else if (this.settlementConfig !== false && this.settlementConfig?.vtxoThreshold !== void 0) {
|
|
4606
4555
|
threshold = this.settlementConfig.vtxoThreshold * 1e3;
|
|
4607
4556
|
} else {
|
|
4608
|
-
threshold =
|
|
4557
|
+
threshold = DEFAULT_THRESHOLD_MS;
|
|
4609
4558
|
}
|
|
4610
4559
|
const now = await fetchTimeHeight(this.wallet);
|
|
4611
4560
|
let vtxos = await this.selectExpiringVtxos(threshold, now);
|
|
@@ -4775,11 +4724,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4775
4724
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
4776
4725
|
);
|
|
4777
4726
|
}
|
|
4778
|
-
const tx = new
|
|
4727
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction();
|
|
4779
4728
|
for (const utxo of expiredUtxos) {
|
|
4780
|
-
const utxoScript =
|
|
4729
|
+
const utxoScript = chunkQWWOD7M2_cjs.VtxoScript.decode(utxo.tapTree);
|
|
4781
4730
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
4782
|
-
(leaf) =>
|
|
4731
|
+
(leaf) => chunkQWWOD7M2_cjs.CSVMultisigTapscript.isScriptValid(chunkQWWOD7M2_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
4783
4732
|
);
|
|
4784
4733
|
if (!utxoExitLeaf) {
|
|
4785
4734
|
throw new Error(
|
|
@@ -4794,7 +4743,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4794
4743
|
amount: BigInt(utxo.value)
|
|
4795
4744
|
},
|
|
4796
4745
|
tapLeafScript: [utxoExitLeaf],
|
|
4797
|
-
sequence:
|
|
4746
|
+
sequence: chunkQWWOD7M2_cjs.getSequence(utxoExitLeaf)
|
|
4798
4747
|
});
|
|
4799
4748
|
}
|
|
4800
4749
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -5037,8 +4986,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5037
4986
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
5038
4987
|
if (cls.status === "CURRENT") continue;
|
|
5039
4988
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
5040
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
5041
|
-
const spendable = live.filter((v) => !
|
|
4989
|
+
const recoverable = live.filter((v) => v.isSwept && !chunkQWWOD7M2_cjs.hasTerminalSpend(v));
|
|
4990
|
+
const spendable = live.filter((v) => !chunkQWWOD7M2_cjs.hasTerminalSpend(v) && !v.isSwept);
|
|
5042
4991
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
5043
4992
|
let recoverableCount = 0;
|
|
5044
4993
|
let recoverableValue = 0;
|
|
@@ -5051,7 +5000,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5051
5000
|
awaitingSweepCount = spendable.length;
|
|
5052
5001
|
awaitingSweepValue = value;
|
|
5053
5002
|
for (const v of spendable) {
|
|
5054
|
-
const exp =
|
|
5003
|
+
const exp = v.expiresAt?.getTime();
|
|
5055
5004
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
5056
5005
|
nextSweepEta = exp;
|
|
5057
5006
|
}
|
|
@@ -5312,7 +5261,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5312
5261
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
5313
5262
|
getBoardingTimelock() {
|
|
5314
5263
|
const wallet = this.getSweepWallet();
|
|
5315
|
-
const exitScript =
|
|
5264
|
+
const exitScript = chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(
|
|
5316
5265
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
5317
5266
|
);
|
|
5318
5267
|
return exitScript.params.timelock;
|
|
@@ -5358,7 +5307,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5358
5307
|
this.wallet.getAddress()
|
|
5359
5308
|
]);
|
|
5360
5309
|
const stopWatching = contractManager.onContractEvent((event) => {
|
|
5361
|
-
if (event.type !== "vtxo_received") {
|
|
5310
|
+
if (event.type !== "vtxo_received" || !isContractVtxoEvent(event)) {
|
|
5362
5311
|
return;
|
|
5363
5312
|
}
|
|
5364
5313
|
const msSinceLastRenewal = Date.now() - this.lastRenewalTimestamp;
|
|
@@ -5443,8 +5392,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5443
5392
|
* or doesn't carry the metadata.
|
|
5444
5393
|
*/
|
|
5445
5394
|
extractSpentOutpoint(error) {
|
|
5446
|
-
const ark =
|
|
5447
|
-
if (!
|
|
5395
|
+
const ark = chunkQWWOD7M2_cjs.maybeArkError(error);
|
|
5396
|
+
if (!chunkQWWOD7M2_cjs.isArkError(ark, chunkQWWOD7M2_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
5448
5397
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
5449
5398
|
if (typeof raw !== "string") return void 0;
|
|
5450
5399
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -5634,7 +5583,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5634
5583
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
5635
5584
|
break;
|
|
5636
5585
|
}
|
|
5637
|
-
const inputFee = estimator.evalOffchainInput(
|
|
5586
|
+
const inputFee = estimator.evalOffchainInput(chunkQWWOD7M2_cjs.toOffchainInputFeeParams(v));
|
|
5638
5587
|
if (inputFee.satoshis >= v.value) {
|
|
5639
5588
|
continue;
|
|
5640
5589
|
}
|
|
@@ -5654,7 +5603,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5654
5603
|
const arkAddress = await this.wallet.getAddress();
|
|
5655
5604
|
const outputFee = estimator.evalOffchainOutput({
|
|
5656
5605
|
amount: totalAmount,
|
|
5657
|
-
script: base.hex.encode(
|
|
5606
|
+
script: base.hex.encode(chunkQWWOD7M2_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
5658
5607
|
});
|
|
5659
5608
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
5660
5609
|
if (totalAmount < dustAmount) return;
|
|
@@ -5734,7 +5683,7 @@ var ArkNote = class _ArkNote {
|
|
|
5734
5683
|
this.value = value;
|
|
5735
5684
|
this.HRP = HRP;
|
|
5736
5685
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
5737
|
-
this.vtxoScript = new
|
|
5686
|
+
this.vtxoScript = new chunkQWWOD7M2_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
5738
5687
|
const leaf = this.vtxoScript.leaves[0];
|
|
5739
5688
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
5740
5689
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -5901,7 +5850,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5901
5850
|
const privateKey = data.slice(1, 33);
|
|
5902
5851
|
const serverPubKey = data.slice(33, 65);
|
|
5903
5852
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
5904
|
-
const csvTimelock =
|
|
5853
|
+
const csvTimelock = chunkQWWOD7M2_cjs.sequenceToTimelock(sequence);
|
|
5905
5854
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
5906
5855
|
}
|
|
5907
5856
|
toString() {
|
|
@@ -5909,7 +5858,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5909
5858
|
data[0] = _ArkadeCash.Version;
|
|
5910
5859
|
data.set(this._privateKey, 1);
|
|
5911
5860
|
data.set(this._serverPubKey, 33);
|
|
5912
|
-
const sequence =
|
|
5861
|
+
const sequence = chunkQWWOD7M2_cjs.timelockToSequence(this.csvTimelock);
|
|
5913
5862
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
5914
5863
|
const words = base.bech32m.toWords(data);
|
|
5915
5864
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -5918,7 +5867,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
5918
5867
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
5919
5868
|
}
|
|
5920
5869
|
get vtxoScript() {
|
|
5921
|
-
return new
|
|
5870
|
+
return new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
5922
5871
|
pubKey: this._publicKey,
|
|
5923
5872
|
serverPubKey: this._serverPubKey,
|
|
5924
5873
|
csvTimelock: this.csvTimelock
|
|
@@ -6179,7 +6128,7 @@ async function captureExitBranch(params) {
|
|
|
6179
6128
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
6180
6129
|
if (nonCommitment.length > 0) {
|
|
6181
6130
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
6182
|
-
psbtByTxid.set(
|
|
6131
|
+
psbtByTxid.set(chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6183
6132
|
}
|
|
6184
6133
|
}
|
|
6185
6134
|
}
|
|
@@ -6222,10 +6171,10 @@ var IndexerExitDataSource = class {
|
|
|
6222
6171
|
while (hasMore) {
|
|
6223
6172
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
6224
6173
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
6225
|
-
{ pageIndex, pageSize:
|
|
6174
|
+
{ pageIndex, pageSize: chunkQWWOD7M2_cjs.DEFAULT_PAGE_SIZE }
|
|
6226
6175
|
);
|
|
6227
6176
|
chain.push(...page);
|
|
6228
|
-
hasMore = meta ? page.length ===
|
|
6177
|
+
hasMore = meta ? page.length === chunkQWWOD7M2_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6229
6178
|
pageIndex++;
|
|
6230
6179
|
}
|
|
6231
6180
|
return chain;
|
|
@@ -6237,12 +6186,12 @@ var IndexerExitDataSource = class {
|
|
|
6237
6186
|
while (hasMore) {
|
|
6238
6187
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
6239
6188
|
pageIndex,
|
|
6240
|
-
pageSize:
|
|
6189
|
+
pageSize: chunkQWWOD7M2_cjs.DEFAULT_PAGE_SIZE
|
|
6241
6190
|
});
|
|
6242
6191
|
for (const psbt of txs) {
|
|
6243
|
-
out.set(
|
|
6192
|
+
out.set(chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6244
6193
|
}
|
|
6245
|
-
hasMore = page ? txs.length ===
|
|
6194
|
+
hasMore = page ? txs.length === chunkQWWOD7M2_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6246
6195
|
pageIndex++;
|
|
6247
6196
|
}
|
|
6248
6197
|
return out;
|
|
@@ -6263,7 +6212,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
6263
6212
|
}
|
|
6264
6213
|
}
|
|
6265
6214
|
function psbtInputTxids(psbtBase64) {
|
|
6266
|
-
const tx =
|
|
6215
|
+
const tx = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
6267
6216
|
const ids = [];
|
|
6268
6217
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
6269
6218
|
const txid = tx.getInput(i).txid;
|
|
@@ -6622,10 +6571,10 @@ async function resolveArkInfo(arkProvider, walletRepository, opts) {
|
|
|
6622
6571
|
try {
|
|
6623
6572
|
info = await arkProvider.getInfo();
|
|
6624
6573
|
} catch (err) {
|
|
6625
|
-
if (opts?.requireLive || !
|
|
6574
|
+
if (opts?.requireLive || !chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
6626
6575
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
6627
6576
|
if (!snapshot) {
|
|
6628
|
-
throw new
|
|
6577
|
+
throw new chunkQWWOD7M2_cjs.ProviderUnavailableError(
|
|
6629
6578
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
6630
6579
|
{ cause: err }
|
|
6631
6580
|
);
|
|
@@ -7015,7 +6964,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos) {
|
|
|
7015
6964
|
return [...txids];
|
|
7016
6965
|
}
|
|
7017
6966
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt) {
|
|
7018
|
-
const fromOldestVtxo = vtxos.map(
|
|
6967
|
+
const fromOldestVtxo = vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
7019
6968
|
const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(fromOldestVtxo) : [];
|
|
7020
6969
|
const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
|
|
7021
6970
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
@@ -7179,7 +7128,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7179
7128
|
const virtualCoins = await this.wallet.getSpendableVtxos({
|
|
7180
7129
|
withRecoverable: false
|
|
7181
7130
|
});
|
|
7182
|
-
const controlAssetRef = params.controlAssetId ?
|
|
7131
|
+
const controlAssetRef = params.controlAssetId ? chunkNEVMOIQL_cjs.AssetRef.fromId(chunkNEVMOIQL_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
7183
7132
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
7184
7133
|
let totalBtcSelected = 0n;
|
|
7185
7134
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -7192,8 +7141,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7192
7141
|
}
|
|
7193
7142
|
}
|
|
7194
7143
|
const groups = [];
|
|
7195
|
-
const issuedAssetOutput =
|
|
7196
|
-
const issuedAssetGroup =
|
|
7144
|
+
const issuedAssetOutput = chunkNEVMOIQL_cjs.AssetOutput.create(0, params.amount);
|
|
7145
|
+
const issuedAssetGroup = chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
7197
7146
|
null,
|
|
7198
7147
|
controlAssetRef,
|
|
7199
7148
|
[],
|
|
@@ -7208,28 +7157,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7208
7157
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7209
7158
|
for (const asset of assets) {
|
|
7210
7159
|
if (asset.assetId !== assetId) continue;
|
|
7211
|
-
changeInputs.push(
|
|
7160
|
+
changeInputs.push(chunkNEVMOIQL_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7212
7161
|
}
|
|
7213
7162
|
}
|
|
7214
7163
|
groups.push(
|
|
7215
|
-
|
|
7216
|
-
|
|
7164
|
+
chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
7165
|
+
chunkNEVMOIQL_cjs.AssetId.fromString(assetId),
|
|
7217
7166
|
null,
|
|
7218
7167
|
changeInputs,
|
|
7219
|
-
[
|
|
7168
|
+
[chunkNEVMOIQL_cjs.AssetOutput.create(0, amount)],
|
|
7220
7169
|
[]
|
|
7221
7170
|
)
|
|
7222
7171
|
);
|
|
7223
7172
|
}
|
|
7224
7173
|
}
|
|
7225
7174
|
const address = await this.wallet.getAddress();
|
|
7226
|
-
const outputAddress =
|
|
7175
|
+
const outputAddress = chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
7227
7176
|
const outputs = [
|
|
7228
7177
|
{
|
|
7229
7178
|
script: outputAddress.pkScript,
|
|
7230
7179
|
amount: BigInt(totalBtcSelected)
|
|
7231
7180
|
},
|
|
7232
|
-
Extension.create([
|
|
7181
|
+
Extension.create([chunkNEVMOIQL_cjs.Packet.create(groups)]).txOut()
|
|
7233
7182
|
];
|
|
7234
7183
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
7235
7184
|
coinSelection.inputs,
|
|
@@ -7237,7 +7186,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7237
7186
|
);
|
|
7238
7187
|
return {
|
|
7239
7188
|
arkTxId: arkTxid,
|
|
7240
|
-
assetId:
|
|
7189
|
+
assetId: chunkNEVMOIQL_cjs.AssetId.create(arkTxid, 0).toString()
|
|
7241
7190
|
};
|
|
7242
7191
|
}
|
|
7243
7192
|
/**
|
|
@@ -7309,16 +7258,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7309
7258
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7310
7259
|
for (const asset of assets) {
|
|
7311
7260
|
if (asset.assetId !== params.assetId) continue;
|
|
7312
|
-
reissueInputs.push(
|
|
7261
|
+
reissueInputs.push(chunkNEVMOIQL_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7313
7262
|
}
|
|
7314
7263
|
}
|
|
7315
7264
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
7316
|
-
const reissueAssetIdObj =
|
|
7317
|
-
const reissueAssetGroup =
|
|
7265
|
+
const reissueAssetIdObj = chunkNEVMOIQL_cjs.AssetId.fromString(params.assetId);
|
|
7266
|
+
const reissueAssetGroup = chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
7318
7267
|
reissueAssetIdObj,
|
|
7319
7268
|
null,
|
|
7320
7269
|
reissueInputs,
|
|
7321
|
-
[
|
|
7270
|
+
[chunkNEVMOIQL_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
7322
7271
|
[]
|
|
7323
7272
|
);
|
|
7324
7273
|
const groups = [reissueAssetGroup];
|
|
@@ -7327,27 +7276,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7327
7276
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7328
7277
|
for (const asset of assets) {
|
|
7329
7278
|
if (asset.assetId !== assetId) continue;
|
|
7330
|
-
changeInputs.push(
|
|
7279
|
+
changeInputs.push(chunkNEVMOIQL_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7331
7280
|
}
|
|
7332
7281
|
}
|
|
7333
7282
|
groups.push(
|
|
7334
|
-
|
|
7335
|
-
|
|
7283
|
+
chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
7284
|
+
chunkNEVMOIQL_cjs.AssetId.fromString(assetId),
|
|
7336
7285
|
null,
|
|
7337
7286
|
changeInputs,
|
|
7338
|
-
[
|
|
7287
|
+
[chunkNEVMOIQL_cjs.AssetOutput.create(0, amount)],
|
|
7339
7288
|
[]
|
|
7340
7289
|
)
|
|
7341
7290
|
);
|
|
7342
7291
|
}
|
|
7343
7292
|
const address = await this.wallet.getAddress();
|
|
7344
|
-
const outputAddress =
|
|
7293
|
+
const outputAddress = chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
7345
7294
|
const outputs = [
|
|
7346
7295
|
{
|
|
7347
7296
|
script: outputAddress.pkScript,
|
|
7348
7297
|
amount: BigInt(totalBtcSelected)
|
|
7349
7298
|
},
|
|
7350
|
-
Extension.create([
|
|
7299
|
+
Extension.create([chunkNEVMOIQL_cjs.Packet.create(groups)]).txOut()
|
|
7351
7300
|
];
|
|
7352
7301
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7353
7302
|
return arkTxid;
|
|
@@ -7414,27 +7363,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7414
7363
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7415
7364
|
for (const asset of assets) {
|
|
7416
7365
|
if (asset.assetId !== assetId) continue;
|
|
7417
|
-
changeInputs.push(
|
|
7366
|
+
changeInputs.push(chunkNEVMOIQL_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7418
7367
|
}
|
|
7419
7368
|
}
|
|
7420
7369
|
groups.push(
|
|
7421
|
-
|
|
7422
|
-
|
|
7370
|
+
chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
7371
|
+
chunkNEVMOIQL_cjs.AssetId.fromString(assetId),
|
|
7423
7372
|
null,
|
|
7424
7373
|
changeInputs,
|
|
7425
|
-
amount > 0n ? [
|
|
7374
|
+
amount > 0n ? [chunkNEVMOIQL_cjs.AssetOutput.create(0, amount)] : [],
|
|
7426
7375
|
[]
|
|
7427
7376
|
)
|
|
7428
7377
|
);
|
|
7429
7378
|
}
|
|
7430
7379
|
const address = await this.wallet.getAddress();
|
|
7431
|
-
const outputAddress =
|
|
7380
|
+
const outputAddress = chunkQWWOD7M2_cjs.ArkAddress.decode(address);
|
|
7432
7381
|
const outputs = [
|
|
7433
7382
|
{
|
|
7434
7383
|
script: outputAddress.pkScript,
|
|
7435
7384
|
amount: BigInt(totalBtcSelected)
|
|
7436
7385
|
},
|
|
7437
|
-
Extension.create([
|
|
7386
|
+
Extension.create([chunkNEVMOIQL_cjs.Packet.create(groups)]).txOut()
|
|
7438
7387
|
];
|
|
7439
7388
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
7440
7389
|
return arkTxid;
|
|
@@ -7459,7 +7408,7 @@ function castMetadata(metadata) {
|
|
|
7459
7408
|
} else {
|
|
7460
7409
|
throw new Error("Invalid metadata value type");
|
|
7461
7410
|
}
|
|
7462
|
-
md.push(
|
|
7411
|
+
md.push(chunkNEVMOIQL_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
7463
7412
|
}
|
|
7464
7413
|
return md;
|
|
7465
7414
|
}
|
|
@@ -7480,10 +7429,10 @@ var DelegateManagerImpl = class {
|
|
|
7480
7429
|
if (vtxos.length === 0) {
|
|
7481
7430
|
return { delegated: [], failed: [] };
|
|
7482
7431
|
}
|
|
7483
|
-
const destinationScript =
|
|
7432
|
+
const destinationScript = chunkQWWOD7M2_cjs.ArkAddress.decode(destination).pkScript;
|
|
7484
7433
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
7485
7434
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
7486
|
-
const eligible = vtxos.map(
|
|
7435
|
+
const eligible = vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo).filter(
|
|
7487
7436
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
7488
7437
|
);
|
|
7489
7438
|
if (eligible.length === 0) {
|
|
@@ -7512,11 +7461,11 @@ var DelegateManagerImpl = class {
|
|
|
7512
7461
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
7513
7462
|
let recoverableVtxos = [];
|
|
7514
7463
|
for (const vtxo of eligible) {
|
|
7515
|
-
if (
|
|
7464
|
+
if (chunkQWWOD7M2_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7516
7465
|
recoverableVtxos.push(vtxo);
|
|
7517
7466
|
continue;
|
|
7518
7467
|
}
|
|
7519
|
-
const expiry =
|
|
7468
|
+
const expiry = vtxo.expiresAt?.getTime();
|
|
7520
7469
|
if (!expiry) continue;
|
|
7521
7470
|
const dayKey = getDayTimestamp(expiry);
|
|
7522
7471
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -7571,7 +7520,6 @@ var DelegateManagerImpl = class {
|
|
|
7571
7520
|
return { delegated, failed };
|
|
7572
7521
|
}
|
|
7573
7522
|
};
|
|
7574
|
-
var DelegatorManagerImpl = DelegateManagerImpl;
|
|
7575
7523
|
async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos, destinationScript, delegateAt) {
|
|
7576
7524
|
if (vtxos.length === 0) {
|
|
7577
7525
|
throw new Error("unable to delegate: no vtxos provided");
|
|
@@ -7581,7 +7529,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7581
7529
|
}
|
|
7582
7530
|
if (!delegateAt) {
|
|
7583
7531
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
7584
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
7532
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkQWWOD7M2_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
|
|
7533
|
+
(min, coin) => Math.min(min, coin.expiresAt.getTime()),
|
|
7534
|
+
Number.MAX_SAFE_INTEGER
|
|
7535
|
+
);
|
|
7585
7536
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
7586
7537
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
7587
7538
|
} else {
|
|
@@ -7610,7 +7561,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7610
7561
|
let amount = 0n;
|
|
7611
7562
|
for (const coin of vtxos) {
|
|
7612
7563
|
const inputFee = estimator.evalOffchainInput({
|
|
7613
|
-
...
|
|
7564
|
+
...chunkQWWOD7M2_cjs.toOffchainInputFeeParams(coin),
|
|
7614
7565
|
type: "vtxo"
|
|
7615
7566
|
});
|
|
7616
7567
|
if (inputFee.value >= coin.value) {
|
|
@@ -7624,7 +7575,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7624
7575
|
const delegateFee = BigInt(Number(fee));
|
|
7625
7576
|
if (delegateFee > 0n) {
|
|
7626
7577
|
outputs.push({
|
|
7627
|
-
script:
|
|
7578
|
+
script: chunkQWWOD7M2_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
7628
7579
|
amount: delegateFee
|
|
7629
7580
|
});
|
|
7630
7581
|
}
|
|
@@ -7657,10 +7608,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
7657
7608
|
destinationScript
|
|
7658
7609
|
);
|
|
7659
7610
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
7660
|
-
btcSigner.Address(
|
|
7611
|
+
btcSigner.Address(chunkQWWOD7M2_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
7661
7612
|
);
|
|
7662
7613
|
const forfeits = await Promise.all(
|
|
7663
|
-
vtxos.filter((v) => !
|
|
7614
|
+
vtxos.filter((v) => !chunkQWWOD7M2_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
7664
7615
|
const forfeit = await makeDelegateForfeitTx(
|
|
7665
7616
|
coin,
|
|
7666
7617
|
dust,
|
|
@@ -7685,7 +7636,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
7685
7636
|
index: input.vout,
|
|
7686
7637
|
witnessUtxo: {
|
|
7687
7638
|
amount: BigInt(input.value),
|
|
7688
|
-
script:
|
|
7639
|
+
script: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
7689
7640
|
},
|
|
7690
7641
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
7691
7642
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -7743,7 +7694,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
7743
7694
|
expire_at: 0,
|
|
7744
7695
|
cosigners_public_keys: cosignerPubKeys
|
|
7745
7696
|
};
|
|
7746
|
-
const proof =
|
|
7697
|
+
const proof = chunkQWWOD7M2_cjs.Intent.create(message, coins, outputs);
|
|
7747
7698
|
const signedProof = await identity.sign(proof);
|
|
7748
7699
|
return {
|
|
7749
7700
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -7761,10 +7712,10 @@ function getDayTimestamp(timestamp) {
|
|
|
7761
7712
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
7762
7713
|
if (!vtxo.tapTree) return void 0;
|
|
7763
7714
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
7764
|
-
const vtxoScript =
|
|
7715
|
+
const vtxoScript = chunkQWWOD7M2_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
7765
7716
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
7766
|
-
const arkTapscript =
|
|
7767
|
-
if (!
|
|
7717
|
+
const arkTapscript = chunkQWWOD7M2_cjs.decodeTapscript(chunkQWWOD7M2_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
7718
|
+
if (!chunkQWWOD7M2_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
7768
7719
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
7769
7720
|
});
|
|
7770
7721
|
}
|
|
@@ -8045,7 +7996,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
|
|
|
8045
7996
|
};
|
|
8046
7997
|
}
|
|
8047
7998
|
function scriptFromArkAddress(address) {
|
|
8048
|
-
return base.hex.encode(
|
|
7999
|
+
return base.hex.encode(chunkQWWOD7M2_cjs.ArkAddress.decode(address).pkScript);
|
|
8049
8000
|
}
|
|
8050
8001
|
|
|
8051
8002
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -8057,7 +8008,6 @@ var STORE_CONTRACTS = "contracts";
|
|
|
8057
8008
|
var STORE_INTENTS = "intents";
|
|
8058
8009
|
var STORE_VIRTUAL_TXS = "virtualTxs";
|
|
8059
8010
|
var STORE_VTXO_BRANCHES = "vtxoBranches";
|
|
8060
|
-
var LEGACY_STORE_CONTRACT_COLLECTIONS = "contractsCollections";
|
|
8061
8011
|
var DB_VERSION = 3;
|
|
8062
8012
|
var INTENT_DB_VERSION = 5;
|
|
8063
8013
|
function initDatabase(db, oldVersion, transaction) {
|
|
@@ -8081,11 +8031,6 @@ function initDatabase(db, oldVersion, transaction) {
|
|
|
8081
8031
|
unique: false
|
|
8082
8032
|
});
|
|
8083
8033
|
}
|
|
8084
|
-
if (!vtxosStore.indexNames.contains("virtualStatus")) {
|
|
8085
|
-
vtxosStore.createIndex("virtualStatus", "virtualStatus", {
|
|
8086
|
-
unique: false
|
|
8087
|
-
});
|
|
8088
|
-
}
|
|
8089
8034
|
if (!vtxosStore.indexNames.contains("createdAt")) {
|
|
8090
8035
|
vtxosStore.createIndex("createdAt", "createdAt", {
|
|
8091
8036
|
unique: false
|
|
@@ -8198,11 +8143,6 @@ function initDatabase(db, oldVersion, transaction) {
|
|
|
8198
8143
|
});
|
|
8199
8144
|
}
|
|
8200
8145
|
}
|
|
8201
|
-
if (!db.objectStoreNames.contains(LEGACY_STORE_CONTRACT_COLLECTIONS)) {
|
|
8202
|
-
db.createObjectStore(LEGACY_STORE_CONTRACT_COLLECTIONS, {
|
|
8203
|
-
keyPath: "key"
|
|
8204
|
-
});
|
|
8205
|
-
}
|
|
8206
8146
|
if (oldVersion >= 1 && oldVersion < 3 && transaction) {
|
|
8207
8147
|
const vtxosStore = transaction.objectStore(STORE_VTXOS);
|
|
8208
8148
|
if (!vtxosStore.indexNames.contains("script")) {
|
|
@@ -8540,7 +8480,7 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
8540
8480
|
}
|
|
8541
8481
|
async function getVtxosForContract(repo, contract) {
|
|
8542
8482
|
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
8543
|
-
return vtxos.map(
|
|
8483
|
+
return vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
8544
8484
|
}
|
|
8545
8485
|
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
8546
8486
|
if (repo.saveVtxosForScript) {
|
|
@@ -8682,7 +8622,7 @@ function decodeArkContract(encoded) {
|
|
|
8682
8622
|
}
|
|
8683
8623
|
function contractFromArkContract(encoded, options = {}) {
|
|
8684
8624
|
const parsed = decodeArkContract(encoded);
|
|
8685
|
-
const handler =
|
|
8625
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(parsed.type);
|
|
8686
8626
|
if (!handler) {
|
|
8687
8627
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
8688
8628
|
}
|
|
@@ -8696,9 +8636,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
8696
8636
|
metadata: options.metadata
|
|
8697
8637
|
};
|
|
8698
8638
|
}
|
|
8699
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
8639
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkQWWOD7M2_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
8700
8640
|
const parsed = decodeArkContract(encoded);
|
|
8701
|
-
const handler =
|
|
8641
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
8702
8642
|
const params = parsed.data;
|
|
8703
8643
|
const vtxoScript = handler.createScript(params);
|
|
8704
8644
|
return {
|
|
@@ -8730,6 +8670,8 @@ var DEFAULT_CONTRACT_WATCHER_CONFIG = {
|
|
|
8730
8670
|
var ContractWatcher = class {
|
|
8731
8671
|
config;
|
|
8732
8672
|
contracts = /* @__PURE__ */ new Map();
|
|
8673
|
+
/** In-memory and process-lifetime; never persisted. */
|
|
8674
|
+
watchedScripts = /* @__PURE__ */ new Map();
|
|
8733
8675
|
subscriptionId;
|
|
8734
8676
|
abortController;
|
|
8735
8677
|
isWatching = false;
|
|
@@ -8850,6 +8792,47 @@ var ContractWatcher = class {
|
|
|
8850
8792
|
getWatchedContracts() {
|
|
8851
8793
|
return this.getAllContracts().filter(isWatchedContract);
|
|
8852
8794
|
}
|
|
8795
|
+
/**
|
|
8796
|
+
* Every script the subscription must carry. Wider than
|
|
8797
|
+
* {@link getWatchedContracts}, which stays the sync scope.
|
|
8798
|
+
*/
|
|
8799
|
+
getSubscribedScripts() {
|
|
8800
|
+
const scripts = new Set(this.getWatchedContracts().map((c) => c.script));
|
|
8801
|
+
for (const script of this.watchedScripts.keys()) {
|
|
8802
|
+
scripts.add(script);
|
|
8803
|
+
}
|
|
8804
|
+
return Array.from(scripts);
|
|
8805
|
+
}
|
|
8806
|
+
/** @see IContractManager.watchScript for the delivery and filter contract. */
|
|
8807
|
+
async addWatchedScript(script, options) {
|
|
8808
|
+
const existing = this.watchedScripts.get(script);
|
|
8809
|
+
if (existing) {
|
|
8810
|
+
if (options?.label !== void 0) existing.label = options.label;
|
|
8811
|
+
return;
|
|
8812
|
+
}
|
|
8813
|
+
this.watchedScripts.set(script, {
|
|
8814
|
+
label: options?.label,
|
|
8815
|
+
lastKnownVtxos: /* @__PURE__ */ new Map()
|
|
8816
|
+
});
|
|
8817
|
+
if (this.isWatching) {
|
|
8818
|
+
await this.pollWatchedScripts([script]);
|
|
8819
|
+
await this.tryUpdateSubscription();
|
|
8820
|
+
}
|
|
8821
|
+
}
|
|
8822
|
+
/** Stop watching a script added by {@link addWatchedScript}. */
|
|
8823
|
+
async removeWatchedScript(script) {
|
|
8824
|
+
if (!this.watchedScripts.delete(script)) return;
|
|
8825
|
+
if (this.isWatching) {
|
|
8826
|
+
await this.tryUpdateSubscription();
|
|
8827
|
+
}
|
|
8828
|
+
}
|
|
8829
|
+
/** Every script registered via {@link addWatchedScript}. */
|
|
8830
|
+
getWatchedScripts() {
|
|
8831
|
+
return Array.from(this.watchedScripts.entries()).map(([script, state]) => ({
|
|
8832
|
+
script,
|
|
8833
|
+
label: state.label
|
|
8834
|
+
}));
|
|
8835
|
+
}
|
|
8853
8836
|
/**
|
|
8854
8837
|
* Get virtual outputs for contracts, grouped by contract script.
|
|
8855
8838
|
* @see WalletRepository for `repo`
|
|
@@ -8952,9 +8935,9 @@ var ContractWatcher = class {
|
|
|
8952
8935
|
this.connectionState = "connected";
|
|
8953
8936
|
this.reconnectAttempts = 0;
|
|
8954
8937
|
this.listenLoop().catch((e) => {
|
|
8955
|
-
if (
|
|
8938
|
+
if (chunkQWWOD7M2_cjs.isEventSourceError(e)) {
|
|
8956
8939
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8957
|
-
} else if (!
|
|
8940
|
+
} else if (!chunkQWWOD7M2_cjs.isEventSourceUnavailableError(e)) {
|
|
8958
8941
|
console.error(e);
|
|
8959
8942
|
}
|
|
8960
8943
|
this.connectionState = "disconnected";
|
|
@@ -8966,7 +8949,7 @@ var ContractWatcher = class {
|
|
|
8966
8949
|
this.scheduleReconnect();
|
|
8967
8950
|
});
|
|
8968
8951
|
} catch (error) {
|
|
8969
|
-
if (!
|
|
8952
|
+
if (!chunkQWWOD7M2_cjs.isEventSourceUnavailableError(error)) {
|
|
8970
8953
|
console.error("ContractWatcher connection failed:", error);
|
|
8971
8954
|
}
|
|
8972
8955
|
this.connectionState = "disconnected";
|
|
@@ -8992,7 +8975,7 @@ var ContractWatcher = class {
|
|
|
8992
8975
|
* slower; what it loses is push latency.
|
|
8993
8976
|
*/
|
|
8994
8977
|
reportEventSourceUnavailable(error) {
|
|
8995
|
-
if (!
|
|
8978
|
+
if (!chunkQWWOD7M2_cjs.isEventSourceUnavailableError(error)) return false;
|
|
8996
8979
|
if (!this.eventSourceReported) {
|
|
8997
8980
|
this.eventSourceReported = true;
|
|
8998
8981
|
console.warn(
|
|
@@ -9041,8 +9024,72 @@ var ContractWatcher = class {
|
|
|
9041
9024
|
}
|
|
9042
9025
|
async pollAllContracts() {
|
|
9043
9026
|
const scripts = this.getWatchedContracts().map((c) => c.script);
|
|
9027
|
+
if (scripts.length > 0) {
|
|
9028
|
+
await this.pollContracts(scripts);
|
|
9029
|
+
}
|
|
9030
|
+
await this.pollWatchedScripts(Array.from(this.watchedScripts.keys()));
|
|
9031
|
+
}
|
|
9032
|
+
/**
|
|
9033
|
+
* Poll watch-only scripts against the indexer and emit the delta.
|
|
9034
|
+
*
|
|
9035
|
+
* Separate from {@link pollContracts} because that one diffs the wallet
|
|
9036
|
+
* repository, which is permanently empty for a script this wallet does not
|
|
9037
|
+
* own — reusing it would report every live output as spent on every tick.
|
|
9038
|
+
* Not a second poll loop: same timer and callers, different source.
|
|
9039
|
+
*/
|
|
9040
|
+
async pollWatchedScripts(candidates) {
|
|
9041
|
+
if (!this.eventCallback) return;
|
|
9042
|
+
const scripts = candidates.filter((s) => {
|
|
9043
|
+
const state = this.contracts.get(s);
|
|
9044
|
+
return this.watchedScripts.has(s) && (state === void 0 || !isWatchedContract(state.contract));
|
|
9045
|
+
});
|
|
9044
9046
|
if (scripts.length === 0) return;
|
|
9045
|
-
|
|
9047
|
+
const now = Date.now();
|
|
9048
|
+
let current;
|
|
9049
|
+
try {
|
|
9050
|
+
current = await chunkQWWOD7M2_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
9051
|
+
spendableOnly: true
|
|
9052
|
+
});
|
|
9053
|
+
} catch (error) {
|
|
9054
|
+
console.error("ContractWatcher watch-only poll failed:", error);
|
|
9055
|
+
return;
|
|
9056
|
+
}
|
|
9057
|
+
const byScript = /* @__PURE__ */ new Map();
|
|
9058
|
+
for (const vtxo of current) {
|
|
9059
|
+
let bucket = byScript.get(vtxo.script);
|
|
9060
|
+
if (!bucket) {
|
|
9061
|
+
bucket = [];
|
|
9062
|
+
byScript.set(vtxo.script, bucket);
|
|
9063
|
+
}
|
|
9064
|
+
bucket.push(vtxo);
|
|
9065
|
+
}
|
|
9066
|
+
for (const script of scripts) {
|
|
9067
|
+
const state = this.watchedScripts.get(script);
|
|
9068
|
+
if (!state) continue;
|
|
9069
|
+
const currentVtxos = byScript.get(script) || [];
|
|
9070
|
+
const currentKeys = new Set(currentVtxos.map((v) => `${v.txid}:${v.vout}`));
|
|
9071
|
+
const newVtxos = [];
|
|
9072
|
+
for (const vtxo of currentVtxos) {
|
|
9073
|
+
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
9074
|
+
if (!state.lastKnownVtxos.has(key)) {
|
|
9075
|
+
newVtxos.push(vtxo);
|
|
9076
|
+
state.lastKnownVtxos.set(key, vtxo);
|
|
9077
|
+
}
|
|
9078
|
+
}
|
|
9079
|
+
const spentVtxos = [];
|
|
9080
|
+
for (const [key, vtxo] of state.lastKnownVtxos) {
|
|
9081
|
+
if (!currentKeys.has(key)) {
|
|
9082
|
+
spentVtxos.push(vtxo);
|
|
9083
|
+
state.lastKnownVtxos.delete(key);
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
if (newVtxos.length > 0) {
|
|
9087
|
+
this.emitWatchedScriptEvent(script, newVtxos, "vtxo_received", now);
|
|
9088
|
+
}
|
|
9089
|
+
if (spentVtxos.length > 0) {
|
|
9090
|
+
this.emitWatchedScriptEvent(script, spentVtxos, "vtxo_spent", now);
|
|
9091
|
+
}
|
|
9092
|
+
}
|
|
9046
9093
|
}
|
|
9047
9094
|
/**
|
|
9048
9095
|
* Poll specific contracts and emit events for changes.
|
|
@@ -9143,10 +9190,10 @@ var ContractWatcher = class {
|
|
|
9143
9190
|
/**
|
|
9144
9191
|
* Update the subscription with scripts that should be watched.
|
|
9145
9192
|
*
|
|
9146
|
-
* @see
|
|
9193
|
+
* @see getSubscribedScripts
|
|
9147
9194
|
*/
|
|
9148
9195
|
async updateSubscription() {
|
|
9149
|
-
const scriptsToWatch = this.
|
|
9196
|
+
const scriptsToWatch = this.getSubscribedScripts();
|
|
9150
9197
|
if (scriptsToWatch.length === 0) {
|
|
9151
9198
|
if (this.subscriptionId) {
|
|
9152
9199
|
try {
|
|
@@ -9208,14 +9255,14 @@ var ContractWatcher = class {
|
|
|
9208
9255
|
const timestamp = Date.now();
|
|
9209
9256
|
if (update.newVtxos?.length) {
|
|
9210
9257
|
this.processSubscriptionVtxos(
|
|
9211
|
-
update.newVtxos.map(
|
|
9258
|
+
update.newVtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo),
|
|
9212
9259
|
"vtxo_received",
|
|
9213
9260
|
timestamp
|
|
9214
9261
|
);
|
|
9215
9262
|
}
|
|
9216
9263
|
if (update.spentVtxos?.length) {
|
|
9217
9264
|
this.processSubscriptionVtxos(
|
|
9218
|
-
update.spentVtxos.map(
|
|
9265
|
+
update.spentVtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo),
|
|
9219
9266
|
"vtxo_spent",
|
|
9220
9267
|
timestamp
|
|
9221
9268
|
);
|
|
@@ -9230,16 +9277,26 @@ var ContractWatcher = class {
|
|
|
9230
9277
|
*/
|
|
9231
9278
|
processSubscriptionVtxos(vtxos, eventType, timestamp) {
|
|
9232
9279
|
const byContract = /* @__PURE__ */ new Map();
|
|
9280
|
+
const byWatchedScript = /* @__PURE__ */ new Map();
|
|
9233
9281
|
let unknownScript = 0;
|
|
9282
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
9234
9283
|
for (const vtxo of vtxos) {
|
|
9235
|
-
|
|
9284
|
+
const state = this.contracts.get(vtxo.script);
|
|
9285
|
+
const watchOnly = this.watchedScripts.has(vtxo.script);
|
|
9286
|
+
const preferContract = state !== void 0 && (!watchOnly || isWatchedContract(state.contract));
|
|
9287
|
+
const target = preferContract ? byContract : watchOnly ? byWatchedScript : void 0;
|
|
9288
|
+
if (!target) {
|
|
9236
9289
|
unknownScript++;
|
|
9237
9290
|
continue;
|
|
9238
9291
|
}
|
|
9239
|
-
|
|
9292
|
+
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
9293
|
+
const n = chunkQWWOD7M2_cjs.normalizeVtxo(vtxo);
|
|
9294
|
+
if (chunkQWWOD7M2_cjs.hasTerminalSpend(n) || n.isSwept || chunkQWWOD7M2_cjs.isPastExpiry(n, now)) continue;
|
|
9295
|
+
}
|
|
9296
|
+
let bucket = target.get(vtxo.script);
|
|
9240
9297
|
if (!bucket) {
|
|
9241
9298
|
bucket = [];
|
|
9242
|
-
|
|
9299
|
+
target.set(vtxo.script, bucket);
|
|
9243
9300
|
}
|
|
9244
9301
|
bucket.push(vtxo);
|
|
9245
9302
|
}
|
|
@@ -9262,6 +9319,29 @@ var ContractWatcher = class {
|
|
|
9262
9319
|
}
|
|
9263
9320
|
this.emitVtxoEvent(contractScript, bucketVtxos, eventType, timestamp);
|
|
9264
9321
|
}
|
|
9322
|
+
for (const [script, bucketVtxos] of byWatchedScript) {
|
|
9323
|
+
const state = this.watchedScripts.get(script);
|
|
9324
|
+
if (state) {
|
|
9325
|
+
for (const vtxo of bucketVtxos) {
|
|
9326
|
+
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
9327
|
+
if (eventType === "vtxo_received") {
|
|
9328
|
+
state.lastKnownVtxos.set(key, vtxo);
|
|
9329
|
+
} else {
|
|
9330
|
+
state.lastKnownVtxos.delete(key);
|
|
9331
|
+
}
|
|
9332
|
+
}
|
|
9333
|
+
}
|
|
9334
|
+
this.emitWatchedScriptEvent(script, bucketVtxos, eventType, timestamp);
|
|
9335
|
+
}
|
|
9336
|
+
}
|
|
9337
|
+
/** As {@link emitVtxoEvent}, less the `contract` and the annotation. */
|
|
9338
|
+
emitWatchedScriptEvent(script, vtxos, eventType, timestamp) {
|
|
9339
|
+
if (!this.eventCallback) return;
|
|
9340
|
+
if (eventType === "vtxo_received") {
|
|
9341
|
+
this.eventCallback({ type: "vtxo_received", contractScript: script, vtxos, timestamp });
|
|
9342
|
+
return;
|
|
9343
|
+
}
|
|
9344
|
+
this.eventCallback({ type: "vtxo_spent", contractScript: script, vtxos, timestamp });
|
|
9265
9345
|
}
|
|
9266
9346
|
/**
|
|
9267
9347
|
* Emit a virtual output event for a contract.
|
|
@@ -9310,7 +9390,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
9310
9390
|
(s) => !isTerminalIntentState(s)
|
|
9311
9391
|
);
|
|
9312
9392
|
function isConsumed(vtxo) {
|
|
9313
|
-
return vtxo !== void 0 &&
|
|
9393
|
+
return vtxo !== void 0 && chunkQWWOD7M2_cjs.hasTerminalSpend(vtxo);
|
|
9314
9394
|
}
|
|
9315
9395
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
9316
9396
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -9353,7 +9433,7 @@ async function reconcileIntents(deps) {
|
|
|
9353
9433
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
9354
9434
|
if (outpoints.length > 0) {
|
|
9355
9435
|
try {
|
|
9356
|
-
const { vtxos } = await
|
|
9436
|
+
const { vtxos } = await chunkQWWOD7M2_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
9357
9437
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
9358
9438
|
} catch (e) {
|
|
9359
9439
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -9527,7 +9607,7 @@ var ContractManager = class _ContractManager {
|
|
|
9527
9607
|
await this.reconcileWatched();
|
|
9528
9608
|
this.markSyncOnline();
|
|
9529
9609
|
} catch (err) {
|
|
9530
|
-
if (!
|
|
9610
|
+
if (!chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
9531
9611
|
this.markSyncDegraded(err);
|
|
9532
9612
|
}
|
|
9533
9613
|
this.initialized = true;
|
|
@@ -9659,7 +9739,7 @@ var ContractManager = class _ContractManager {
|
|
|
9659
9739
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
9660
9740
|
const to = watermark + lookAhead.size;
|
|
9661
9741
|
const deps = lookAhead.candidateDeps();
|
|
9662
|
-
const handlers =
|
|
9742
|
+
const handlers = chunkAEDYZK7T_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkAEDYZK7T_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
9663
9743
|
const band = /* @__PURE__ */ new Map();
|
|
9664
9744
|
for (let index = from; index <= to; index++) {
|
|
9665
9745
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -9670,7 +9750,7 @@ var ContractManager = class _ContractManager {
|
|
|
9670
9750
|
index,
|
|
9671
9751
|
params: {
|
|
9672
9752
|
...candidate,
|
|
9673
|
-
...
|
|
9753
|
+
...chunkAEDYZK7T_cjs.speculativeReceiveMetadata(descriptor)
|
|
9674
9754
|
}
|
|
9675
9755
|
});
|
|
9676
9756
|
}
|
|
@@ -9732,15 +9812,14 @@ var ContractManager = class _ContractManager {
|
|
|
9732
9812
|
});
|
|
9733
9813
|
for (const entry of pending) entry.catchUpPending = false;
|
|
9734
9814
|
} catch (err) {
|
|
9735
|
-
if (!
|
|
9815
|
+
if (!chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
9736
9816
|
this.markSyncDegraded(err);
|
|
9737
9817
|
}
|
|
9738
9818
|
}
|
|
9739
9819
|
async advanceLookAheadWatermark(index) {
|
|
9740
9820
|
const lookAhead = this.config.lookAhead;
|
|
9741
9821
|
if (!lookAhead) return;
|
|
9742
|
-
|
|
9743
|
-
await advance?.(index);
|
|
9822
|
+
await lookAhead.advanceWatermark?.(index);
|
|
9744
9823
|
}
|
|
9745
9824
|
/**
|
|
9746
9825
|
* Promote every look-ahead entry funded by `vtxos` into a real repository
|
|
@@ -9782,7 +9861,7 @@ var ContractManager = class _ContractManager {
|
|
|
9782
9861
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
9783
9862
|
this.markSyncOnline();
|
|
9784
9863
|
} catch (err) {
|
|
9785
|
-
if (!
|
|
9864
|
+
if (!chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
9786
9865
|
this.markSyncDegraded(err);
|
|
9787
9866
|
}
|
|
9788
9867
|
await this.watcher.addContract(contract);
|
|
@@ -9819,7 +9898,7 @@ var ContractManager = class _ContractManager {
|
|
|
9819
9898
|
return result;
|
|
9820
9899
|
}
|
|
9821
9900
|
async upsertContractRow(params) {
|
|
9822
|
-
const handler =
|
|
9901
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(params.type);
|
|
9823
9902
|
if (!handler) {
|
|
9824
9903
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
9825
9904
|
}
|
|
@@ -9919,7 +9998,7 @@ var ContractManager = class _ContractManager {
|
|
|
9919
9998
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
9920
9999
|
);
|
|
9921
10000
|
}
|
|
9922
|
-
const registered =
|
|
10001
|
+
const registered = chunkAEDYZK7T_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkAEDYZK7T_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
9923
10002
|
const discoverables = [
|
|
9924
10003
|
...registered.filter((h) => h.type === "boarding"),
|
|
9925
10004
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -9949,7 +10028,7 @@ var ContractManager = class _ContractManager {
|
|
|
9949
10028
|
);
|
|
9950
10029
|
} catch (error) {
|
|
9951
10030
|
probe.indeterminate.add(index);
|
|
9952
|
-
probe.errors.set(index, { handler: h.type, index, error });
|
|
10031
|
+
probe.errors.set(index, { handler: h.type, fromIndex: index, error });
|
|
9953
10032
|
}
|
|
9954
10033
|
})
|
|
9955
10034
|
);
|
|
@@ -9961,7 +10040,7 @@ var ContractManager = class _ContractManager {
|
|
|
9961
10040
|
for (const e of entries) probe.indeterminate.add(e.index);
|
|
9962
10041
|
probe.errors.set(from, {
|
|
9963
10042
|
handler: h.type,
|
|
9964
|
-
|
|
10043
|
+
fromIndex: from,
|
|
9965
10044
|
...to > from && { toIndex: to },
|
|
9966
10045
|
error
|
|
9967
10046
|
});
|
|
@@ -10023,7 +10102,6 @@ var ContractManager = class _ContractManager {
|
|
|
10023
10102
|
);
|
|
10024
10103
|
}
|
|
10025
10104
|
return {
|
|
10026
|
-
lastIndexUsed: highestConfirmedUsedIndex,
|
|
10027
10105
|
highestConfirmedUsedIndex,
|
|
10028
10106
|
...truncatedAt !== void 0 && { truncatedAt },
|
|
10029
10107
|
handlerErrors
|
|
@@ -10054,7 +10132,7 @@ var ContractManager = class _ContractManager {
|
|
|
10054
10132
|
await this.syncContracts({ contracts, pageSize });
|
|
10055
10133
|
this.markSyncOnline();
|
|
10056
10134
|
} catch (err) {
|
|
10057
|
-
if (!
|
|
10135
|
+
if (!chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
10058
10136
|
this.markSyncDegraded(err);
|
|
10059
10137
|
}
|
|
10060
10138
|
const vtxos = await this.getVtxosForContracts(contracts);
|
|
@@ -10075,7 +10153,7 @@ var ContractManager = class _ContractManager {
|
|
|
10075
10153
|
}
|
|
10076
10154
|
const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
|
|
10077
10155
|
return vtxos.map(
|
|
10078
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
10156
|
+
(vtxo) => extendVirtualCoinForContract(chunkQWWOD7M2_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
10079
10157
|
);
|
|
10080
10158
|
}
|
|
10081
10159
|
/** @inheritdoc */
|
|
@@ -10101,8 +10179,8 @@ var ContractManager = class _ContractManager {
|
|
|
10101
10179
|
);
|
|
10102
10180
|
}
|
|
10103
10181
|
/** @inheritdoc */
|
|
10104
|
-
async assertSpendableNow(vtxos,
|
|
10105
|
-
const refused = await this.unspendableNowReasons(vtxos,
|
|
10182
|
+
async assertSpendableNow(vtxos, walletDescriptor) {
|
|
10183
|
+
const refused = await this.unspendableNowReasons(vtxos, walletDescriptor);
|
|
10106
10184
|
if (refused.size === 0) return;
|
|
10107
10185
|
if (refused.size === 1) throw new Error([...refused.values()][0]);
|
|
10108
10186
|
throw new Error(
|
|
@@ -10110,7 +10188,7 @@ var ContractManager = class _ContractManager {
|
|
|
10110
10188
|
);
|
|
10111
10189
|
}
|
|
10112
10190
|
/** @inheritdoc */
|
|
10113
|
-
async unspendableNowReasons(vtxos,
|
|
10191
|
+
async unspendableNowReasons(vtxos, walletDescriptor) {
|
|
10114
10192
|
const refused = /* @__PURE__ */ new Map();
|
|
10115
10193
|
if (vtxos.length === 0) return refused;
|
|
10116
10194
|
const contracts = await this.config.contractRepository.getContracts({
|
|
@@ -10119,21 +10197,21 @@ var ContractManager = class _ContractManager {
|
|
|
10119
10197
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10120
10198
|
const asking = vtxos.filter((vtxo) => {
|
|
10121
10199
|
const contract = byScript.get(vtxo.script);
|
|
10122
|
-
return contract !== void 0 &&
|
|
10200
|
+
return contract !== void 0 && chunkAEDYZK7T_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10123
10201
|
});
|
|
10124
10202
|
if (asking.length === 0) return refused;
|
|
10125
10203
|
const tip = await this.currentChainTip();
|
|
10126
|
-
const
|
|
10204
|
+
const walletDescriptorValue = await walletDescriptor?.();
|
|
10127
10205
|
for (const vtxo of asking) {
|
|
10128
10206
|
const contract = byScript.get(vtxo.script);
|
|
10129
|
-
const handler =
|
|
10207
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
10130
10208
|
if (!handler?.assertSpendableNow) continue;
|
|
10131
10209
|
const context = {
|
|
10132
10210
|
collaborative: true,
|
|
10133
10211
|
currentTime: Date.now(),
|
|
10134
10212
|
blockHeight: tip?.height,
|
|
10135
10213
|
chainTime: tip?.time,
|
|
10136
|
-
|
|
10214
|
+
walletDescriptor: walletDescriptorValue,
|
|
10137
10215
|
// `isVirtualCoin` alone is too weak here: it only asks for a
|
|
10138
10216
|
// string `script`, which every AssertSpendableInput has, so a
|
|
10139
10217
|
// bare outpoint would be published as a coin with no `status`.
|
|
@@ -10141,7 +10219,7 @@ var ContractManager = class _ContractManager {
|
|
|
10141
10219
|
// the next handler to answer a CSV question would meet a
|
|
10142
10220
|
// TypeError instead of a `false`. Carry the coin only when it
|
|
10143
10221
|
// really is one.
|
|
10144
|
-
vtxo:
|
|
10222
|
+
vtxo: chunkQWWOD7M2_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10145
10223
|
};
|
|
10146
10224
|
try {
|
|
10147
10225
|
await handler.assertSpendableNow(
|
|
@@ -10294,10 +10372,10 @@ var ContractManager = class _ContractManager {
|
|
|
10294
10372
|
* @param options - Options for getting spendable paths
|
|
10295
10373
|
*/
|
|
10296
10374
|
async getSpendablePaths(options) {
|
|
10297
|
-
const { contractScript, collaborative = true,
|
|
10375
|
+
const { contractScript, collaborative = true, walletDescriptor, vtxo } = options;
|
|
10298
10376
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10299
10377
|
if (!contract) return [];
|
|
10300
|
-
const handler =
|
|
10378
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
10301
10379
|
if (!handler) return [];
|
|
10302
10380
|
const script = handler.createScript(contract.params);
|
|
10303
10381
|
const tip = await this.currentChainTip();
|
|
@@ -10306,7 +10384,7 @@ var ContractManager = class _ContractManager {
|
|
|
10306
10384
|
currentTime: Date.now(),
|
|
10307
10385
|
blockHeight: tip?.height,
|
|
10308
10386
|
chainTime: tip?.time,
|
|
10309
|
-
|
|
10387
|
+
walletDescriptor,
|
|
10310
10388
|
vtxo
|
|
10311
10389
|
};
|
|
10312
10390
|
return handler.getSpendablePaths(script, contract, context);
|
|
@@ -10322,16 +10400,16 @@ var ContractManager = class _ContractManager {
|
|
|
10322
10400
|
* @param options - Options for getting spending paths
|
|
10323
10401
|
*/
|
|
10324
10402
|
async getAllSpendingPaths(options) {
|
|
10325
|
-
const { contractScript, collaborative = true,
|
|
10403
|
+
const { contractScript, collaborative = true, walletDescriptor } = options;
|
|
10326
10404
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10327
10405
|
if (!contract) return [];
|
|
10328
|
-
const handler =
|
|
10406
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
10329
10407
|
if (!handler) return [];
|
|
10330
10408
|
const script = handler.createScript(contract.params);
|
|
10331
10409
|
const context = {
|
|
10332
10410
|
collaborative,
|
|
10333
10411
|
currentTime: Date.now(),
|
|
10334
|
-
|
|
10412
|
+
walletDescriptor
|
|
10335
10413
|
};
|
|
10336
10414
|
return handler.getAllSpendingPaths(script, contract, context);
|
|
10337
10415
|
}
|
|
@@ -10381,7 +10459,7 @@ var ContractManager = class _ContractManager {
|
|
|
10381
10459
|
}
|
|
10382
10460
|
async refreshOutpoints(outpoints) {
|
|
10383
10461
|
if (outpoints.length === 0) return;
|
|
10384
|
-
const { vtxos } = await
|
|
10462
|
+
const { vtxos } = await chunkQWWOD7M2_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10385
10463
|
outpoints
|
|
10386
10464
|
});
|
|
10387
10465
|
if (vtxos.length === 0) return;
|
|
@@ -10417,6 +10495,18 @@ var ContractManager = class _ContractManager {
|
|
|
10417
10495
|
async isWatching() {
|
|
10418
10496
|
return this.watcher.isCurrentlyWatching();
|
|
10419
10497
|
}
|
|
10498
|
+
/** @see IContractManager.watchScript */
|
|
10499
|
+
async watchScript(script, options) {
|
|
10500
|
+
await this.watcher.addWatchedScript(script, options);
|
|
10501
|
+
}
|
|
10502
|
+
/** @see IContractManager.unwatchScript */
|
|
10503
|
+
async unwatchScript(script) {
|
|
10504
|
+
await this.watcher.removeWatchedScript(script);
|
|
10505
|
+
}
|
|
10506
|
+
/** @see IContractManager.getWatchedScripts */
|
|
10507
|
+
async getWatchedScripts() {
|
|
10508
|
+
return this.watcher.getWatchedScripts();
|
|
10509
|
+
}
|
|
10420
10510
|
/**
|
|
10421
10511
|
* Emit an event to all registered callbacks.
|
|
10422
10512
|
*/
|
|
@@ -10437,11 +10527,15 @@ var ContractManager = class _ContractManager {
|
|
|
10437
10527
|
try {
|
|
10438
10528
|
switch (event.type) {
|
|
10439
10529
|
// Delta-sync only the changed virtual outputs for this contract.
|
|
10530
|
+
// The guard below is the ownership boundary: a watch-only script
|
|
10531
|
+
// reports these same types, so it must precede `syncContracts`.
|
|
10440
10532
|
case "vtxo_received":
|
|
10533
|
+
if (!isContractVtxoEvent(event)) break;
|
|
10441
10534
|
await this.syncContracts({ contracts: [event.contract] });
|
|
10442
10535
|
this.markSyncOnline();
|
|
10443
10536
|
break;
|
|
10444
10537
|
case "vtxo_spent":
|
|
10538
|
+
if (!isContractVtxoEvent(event)) break;
|
|
10445
10539
|
await this.syncContracts({ contracts: [event.contract] });
|
|
10446
10540
|
this.markSyncOnline();
|
|
10447
10541
|
if (this.config.onVtxosSpent) {
|
|
@@ -10460,7 +10554,7 @@ var ContractManager = class _ContractManager {
|
|
|
10460
10554
|
break;
|
|
10461
10555
|
}
|
|
10462
10556
|
} catch (err) {
|
|
10463
|
-
if (!
|
|
10557
|
+
if (!chunkQWWOD7M2_cjs.isRetryableProviderError(err)) throw err;
|
|
10464
10558
|
this.markSyncDegraded(err);
|
|
10465
10559
|
}
|
|
10466
10560
|
this.emitEvent(event);
|
|
@@ -10539,7 +10633,7 @@ var ContractManager = class _ContractManager {
|
|
|
10539
10633
|
*/
|
|
10540
10634
|
async reconcilePendingFrontier(contracts) {
|
|
10541
10635
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
10542
|
-
const vtxos = await
|
|
10636
|
+
const vtxos = await chunkQWWOD7M2_cjs.getAllNormalizedVtxos(
|
|
10543
10637
|
this.config.indexerProvider,
|
|
10544
10638
|
contracts.map((c) => c.script),
|
|
10545
10639
|
{ pendingOnly: true }
|
|
@@ -10622,7 +10716,7 @@ var ContractManager = class _ContractManager {
|
|
|
10622
10716
|
}
|
|
10623
10717
|
return result;
|
|
10624
10718
|
}
|
|
10625
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
10719
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkQWWOD7M2_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
10626
10720
|
if (contracts.length === 0) {
|
|
10627
10721
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
10628
10722
|
}
|
|
@@ -10638,7 +10732,7 @@ var ContractManager = class _ContractManager {
|
|
|
10638
10732
|
before: syncWindow.before
|
|
10639
10733
|
}
|
|
10640
10734
|
} : {};
|
|
10641
|
-
const vtxos = await
|
|
10735
|
+
const vtxos = await chunkQWWOD7M2_cjs.getAllNormalizedVtxos(
|
|
10642
10736
|
this.config.indexerProvider,
|
|
10643
10737
|
contracts.map((c) => c.script),
|
|
10644
10738
|
{ ...windowOpts, pageSize }
|
|
@@ -10774,16 +10868,12 @@ var serializeUtxo = (u) => ({
|
|
|
10774
10868
|
intentTapLeafScript: serializeTapLeaf(u.intentTapLeafScript),
|
|
10775
10869
|
extraWitness: u.extraWitness?.map(base.hex.encode)
|
|
10776
10870
|
});
|
|
10777
|
-
var serializeTransaction = (t) => ({
|
|
10778
|
-
...t,
|
|
10779
|
-
assets: serializeAssets(t.assets)
|
|
10780
|
-
});
|
|
10781
10871
|
var deserializeTapLeaf = (t) => {
|
|
10782
10872
|
const cb = btcSigner.TaprootControlBlock.decode(base.hex.decode(t.cb));
|
|
10783
10873
|
const s = base.hex.decode(t.s);
|
|
10784
10874
|
return [cb, s];
|
|
10785
10875
|
};
|
|
10786
|
-
var deserializeVtxo = (o) =>
|
|
10876
|
+
var deserializeVtxo = (o) => chunkQWWOD7M2_cjs.normalizeVtxo({
|
|
10787
10877
|
...o,
|
|
10788
10878
|
createdAt: new Date(o.createdAt),
|
|
10789
10879
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -10799,10 +10889,6 @@ var deserializeUtxo = (o) => ({
|
|
|
10799
10889
|
intentTapLeafScript: deserializeTapLeaf(o.intentTapLeafScript),
|
|
10800
10890
|
extraWitness: o.extraWitness?.map(base.hex.decode)
|
|
10801
10891
|
});
|
|
10802
|
-
var deserializeTransaction = (o) => ({
|
|
10803
|
-
...o,
|
|
10804
|
-
assets: deserializeAssets(o.assets)
|
|
10805
|
-
});
|
|
10806
10892
|
|
|
10807
10893
|
// src/repositories/indexedDB/contractRepository.ts
|
|
10808
10894
|
var IndexedDBContractRepository = class {
|
|
@@ -10917,6 +11003,37 @@ function normalizeFilter(filter) {
|
|
|
10917
11003
|
return res;
|
|
10918
11004
|
}
|
|
10919
11005
|
|
|
11006
|
+
// src/repositories/legacyVtxoFacts.ts
|
|
11007
|
+
function parseLegacyExpiry(batchExpiry) {
|
|
11008
|
+
if (typeof batchExpiry !== "number" || !Number.isFinite(batchExpiry) || batchExpiry <= 0) {
|
|
11009
|
+
return {};
|
|
11010
|
+
}
|
|
11011
|
+
if (batchExpiry >= chunkQWWOD7M2_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
|
|
11012
|
+
return { expiresAtHeight: batchExpiry / 1e3 };
|
|
11013
|
+
}
|
|
11014
|
+
function legacyVtxoFacts(status) {
|
|
11015
|
+
let blob = status;
|
|
11016
|
+
if (typeof blob === "string") {
|
|
11017
|
+
try {
|
|
11018
|
+
blob = JSON.parse(blob);
|
|
11019
|
+
} catch {
|
|
11020
|
+
return void 0;
|
|
11021
|
+
}
|
|
11022
|
+
}
|
|
11023
|
+
if (typeof blob !== "object" || blob === null) return void 0;
|
|
11024
|
+
const { state, commitmentTxIds, batchExpiry } = blob;
|
|
11025
|
+
if (state === void 0 && commitmentTxIds === void 0 && batchExpiry === void 0) {
|
|
11026
|
+
return void 0;
|
|
11027
|
+
}
|
|
11028
|
+
return {
|
|
11029
|
+
isSpent: state === "spent",
|
|
11030
|
+
isSwept: state === "swept",
|
|
11031
|
+
isPreconfirmed: state === "preconfirmed",
|
|
11032
|
+
commitmentTxIds: Array.isArray(commitmentTxIds) ? commitmentTxIds : void 0,
|
|
11033
|
+
...parseLegacyExpiry(batchExpiry)
|
|
11034
|
+
};
|
|
11035
|
+
}
|
|
11036
|
+
|
|
10920
11037
|
// src/repositories/indexedDB/walletRepository.ts
|
|
10921
11038
|
var IndexedDBWalletRepository = class {
|
|
10922
11039
|
version = 1;
|
|
@@ -11138,6 +11255,20 @@ function deserializeVtxoWithBackfill(o) {
|
|
|
11138
11255
|
if (!o.script) {
|
|
11139
11256
|
o = { ...o, script: scriptFromArkAddress(o.address) };
|
|
11140
11257
|
}
|
|
11258
|
+
if (o.isSwept === void 0 && o.isPreconfirmed === void 0) {
|
|
11259
|
+
const facts = legacyVtxoFacts(o.virtualStatus);
|
|
11260
|
+
if (facts) {
|
|
11261
|
+
o = {
|
|
11262
|
+
...o,
|
|
11263
|
+
isSpent: o.isSpent ?? facts.isSpent,
|
|
11264
|
+
isSwept: facts.isSwept,
|
|
11265
|
+
isPreconfirmed: facts.isPreconfirmed,
|
|
11266
|
+
commitmentTxIds: o.commitmentTxIds ?? facts.commitmentTxIds,
|
|
11267
|
+
expiresAt: o.expiresAt ?? facts.expiresAt,
|
|
11268
|
+
expiresAtHeight: o.expiresAtHeight ?? facts.expiresAtHeight
|
|
11269
|
+
};
|
|
11270
|
+
}
|
|
11271
|
+
}
|
|
11141
11272
|
return deserializeVtxo(o);
|
|
11142
11273
|
}
|
|
11143
11274
|
function isCanonicalRow(row) {
|
|
@@ -11166,323 +11297,6 @@ function getLifecycleWeight(v) {
|
|
|
11166
11297
|
if (v.arkTxId) weight += 2;
|
|
11167
11298
|
return weight;
|
|
11168
11299
|
}
|
|
11169
|
-
|
|
11170
|
-
// src/repositories/migrations/walletRepositoryImpl.ts
|
|
11171
|
-
var getVtxosStorageKey = (address) => `vtxos:${address}`;
|
|
11172
|
-
var getUtxosStorageKey = (address) => `utxos:${address}`;
|
|
11173
|
-
var getTransactionsStorageKey = (address) => `tx:${address}`;
|
|
11174
|
-
var walletStateStorageKey = "wallet:state";
|
|
11175
|
-
var WalletRepositoryImpl = class {
|
|
11176
|
-
version = 1;
|
|
11177
|
-
storage;
|
|
11178
|
-
constructor(storage) {
|
|
11179
|
-
this.storage = storage;
|
|
11180
|
-
}
|
|
11181
|
-
async getVtxos(address) {
|
|
11182
|
-
const stored = await this.storage.getItem(getVtxosStorageKey(address));
|
|
11183
|
-
if (!stored) return [];
|
|
11184
|
-
try {
|
|
11185
|
-
const parsed = JSON.parse(stored);
|
|
11186
|
-
return parsed.map(deserializeVtxo);
|
|
11187
|
-
} catch (error) {
|
|
11188
|
-
console.error(`Failed to parse VTXOs for address ${address}:`, error);
|
|
11189
|
-
return [];
|
|
11190
|
-
}
|
|
11191
|
-
}
|
|
11192
|
-
async saveVtxos(address, vtxos) {
|
|
11193
|
-
const storedVtxos = await this.getVtxos(address);
|
|
11194
|
-
for (const vtxo of vtxos) {
|
|
11195
|
-
const existing = storedVtxos.findIndex(
|
|
11196
|
-
(v) => v.txid === vtxo.txid && v.vout === vtxo.vout
|
|
11197
|
-
);
|
|
11198
|
-
if (existing !== -1) {
|
|
11199
|
-
storedVtxos[existing] = vtxo;
|
|
11200
|
-
} else {
|
|
11201
|
-
storedVtxos.push(vtxo);
|
|
11202
|
-
}
|
|
11203
|
-
}
|
|
11204
|
-
await this.storage.setItem(
|
|
11205
|
-
getVtxosStorageKey(address),
|
|
11206
|
-
JSON.stringify(storedVtxos.map(serializeVtxo))
|
|
11207
|
-
);
|
|
11208
|
-
}
|
|
11209
|
-
async clearVtxos(address) {
|
|
11210
|
-
return this.deleteVtxos(address);
|
|
11211
|
-
}
|
|
11212
|
-
async deleteVtxos(address) {
|
|
11213
|
-
await this.storage.removeItem(getVtxosStorageKey(address));
|
|
11214
|
-
}
|
|
11215
|
-
async getUtxos(address) {
|
|
11216
|
-
const stored = await this.storage.getItem(getUtxosStorageKey(address));
|
|
11217
|
-
if (!stored) return [];
|
|
11218
|
-
try {
|
|
11219
|
-
const parsed = JSON.parse(stored);
|
|
11220
|
-
return parsed.map(deserializeUtxo);
|
|
11221
|
-
} catch (error) {
|
|
11222
|
-
console.error(`Failed to parse UTXOs for address ${address}:`, error);
|
|
11223
|
-
return [];
|
|
11224
|
-
}
|
|
11225
|
-
}
|
|
11226
|
-
async saveUtxos(address, utxos) {
|
|
11227
|
-
const storedUtxos = await this.getUtxos(address);
|
|
11228
|
-
utxos.forEach((utxo) => {
|
|
11229
|
-
const existing = storedUtxos.findIndex(
|
|
11230
|
-
(u) => u.txid === utxo.txid && u.vout === utxo.vout
|
|
11231
|
-
);
|
|
11232
|
-
if (existing !== -1) {
|
|
11233
|
-
storedUtxos[existing] = utxo;
|
|
11234
|
-
} else {
|
|
11235
|
-
storedUtxos.push(utxo);
|
|
11236
|
-
}
|
|
11237
|
-
});
|
|
11238
|
-
await this.storage.setItem(
|
|
11239
|
-
getUtxosStorageKey(address),
|
|
11240
|
-
JSON.stringify(storedUtxos.map(serializeUtxo))
|
|
11241
|
-
);
|
|
11242
|
-
}
|
|
11243
|
-
async clearUtxos(address) {
|
|
11244
|
-
return this.deleteVtxos(address);
|
|
11245
|
-
}
|
|
11246
|
-
async deleteUtxos(address) {
|
|
11247
|
-
await this.storage.removeItem(getUtxosStorageKey(address));
|
|
11248
|
-
}
|
|
11249
|
-
async getTransactionHistory(address) {
|
|
11250
|
-
const storageKey = getTransactionsStorageKey(address);
|
|
11251
|
-
const stored = await this.storage.getItem(storageKey);
|
|
11252
|
-
if (!stored) return [];
|
|
11253
|
-
try {
|
|
11254
|
-
const parsed = JSON.parse(stored);
|
|
11255
|
-
return parsed.map(deserializeTransaction);
|
|
11256
|
-
} catch (error) {
|
|
11257
|
-
console.error(`Failed to parse transactions for address ${address}:`, error);
|
|
11258
|
-
return [];
|
|
11259
|
-
}
|
|
11260
|
-
}
|
|
11261
|
-
async saveTransactions(address, txs) {
|
|
11262
|
-
const storedTransactions = await this.getTransactionHistory(address);
|
|
11263
|
-
for (const tx of txs) {
|
|
11264
|
-
const existing = storedTransactions.findIndex(
|
|
11265
|
-
(t) => t.key.boardingTxid === tx.key.boardingTxid && t.key.commitmentTxid === tx.key.commitmentTxid && t.key.arkTxid === tx.key.arkTxid
|
|
11266
|
-
);
|
|
11267
|
-
if (existing !== -1) {
|
|
11268
|
-
storedTransactions[existing] = tx;
|
|
11269
|
-
} else {
|
|
11270
|
-
storedTransactions.push(tx);
|
|
11271
|
-
}
|
|
11272
|
-
}
|
|
11273
|
-
await this.storage.setItem(
|
|
11274
|
-
getTransactionsStorageKey(address),
|
|
11275
|
-
JSON.stringify(storedTransactions.map(serializeTransaction))
|
|
11276
|
-
);
|
|
11277
|
-
}
|
|
11278
|
-
async clearTransactions(address) {
|
|
11279
|
-
return this.deleteTransactions(address);
|
|
11280
|
-
}
|
|
11281
|
-
async deleteTransactions(address) {
|
|
11282
|
-
await this.storage.removeItem(getTransactionsStorageKey(address));
|
|
11283
|
-
}
|
|
11284
|
-
async getWalletState() {
|
|
11285
|
-
const stored = await this.storage.getItem(walletStateStorageKey);
|
|
11286
|
-
if (!stored) return null;
|
|
11287
|
-
try {
|
|
11288
|
-
const state = JSON.parse(stored);
|
|
11289
|
-
return state;
|
|
11290
|
-
} catch (error) {
|
|
11291
|
-
console.error("Failed to parse wallet state:", error);
|
|
11292
|
-
return null;
|
|
11293
|
-
}
|
|
11294
|
-
}
|
|
11295
|
-
async saveWalletState(state) {
|
|
11296
|
-
await this.storage.setItem(walletStateStorageKey, JSON.stringify(state));
|
|
11297
|
-
}
|
|
11298
|
-
// New method added in V2, not implemented for legacy
|
|
11299
|
-
async clear() {
|
|
11300
|
-
throw new Error("Method not implemented.");
|
|
11301
|
-
}
|
|
11302
|
-
async [Symbol.asyncDispose]() {
|
|
11303
|
-
return;
|
|
11304
|
-
}
|
|
11305
|
-
};
|
|
11306
|
-
|
|
11307
|
-
// src/repositories/migrations/fromStorageAdapter.ts
|
|
11308
|
-
var MIGRATION_KEY = (repoType) => `migration-from-storage-adapter-${repoType}`;
|
|
11309
|
-
async function getMigrationStatus(repoType, storageAdapter) {
|
|
11310
|
-
try {
|
|
11311
|
-
const migration = await storageAdapter.getItem(MIGRATION_KEY(repoType));
|
|
11312
|
-
if (migration === "done") return "done";
|
|
11313
|
-
if (migration === "in-progress") return "in-progress";
|
|
11314
|
-
return "pending";
|
|
11315
|
-
} catch (e) {
|
|
11316
|
-
if (e instanceof DOMException && e.name === "NotFoundError") return "not-needed";
|
|
11317
|
-
throw e;
|
|
11318
|
-
}
|
|
11319
|
-
}
|
|
11320
|
-
async function requiresMigration(repoType, storageAdapter) {
|
|
11321
|
-
const status = await getMigrationStatus(repoType, storageAdapter);
|
|
11322
|
-
return status === "pending" || status === "in-progress";
|
|
11323
|
-
}
|
|
11324
|
-
async function rollbackMigration(repoType, storageAdapter) {
|
|
11325
|
-
await storageAdapter.removeItem(MIGRATION_KEY(repoType));
|
|
11326
|
-
}
|
|
11327
|
-
async function migrateWalletRepository(storageAdapter, fresh, addresses) {
|
|
11328
|
-
const migrate = await requiresMigration("wallet", storageAdapter);
|
|
11329
|
-
if (!migrate) return;
|
|
11330
|
-
await storageAdapter.setItem(MIGRATION_KEY("wallet"), "in-progress");
|
|
11331
|
-
const old = new WalletRepositoryImpl(storageAdapter);
|
|
11332
|
-
const walletData = await old.getWalletState();
|
|
11333
|
-
const onchainAddrData = await Promise.all(
|
|
11334
|
-
addresses.onchain.map(async (address) => {
|
|
11335
|
-
const utxos = await old.getUtxos(address);
|
|
11336
|
-
return { address, utxos };
|
|
11337
|
-
})
|
|
11338
|
-
);
|
|
11339
|
-
const offchainAddrData = await Promise.all(
|
|
11340
|
-
addresses.offchain.map(async (address) => {
|
|
11341
|
-
const vtxos = await old.getVtxos(address);
|
|
11342
|
-
const txs = await old.getTransactionHistory(address);
|
|
11343
|
-
return { address, vtxos, txs };
|
|
11344
|
-
})
|
|
11345
|
-
);
|
|
11346
|
-
await Promise.all([
|
|
11347
|
-
walletData && fresh.saveWalletState(walletData),
|
|
11348
|
-
...offchainAddrData.map(
|
|
11349
|
-
(addressData) => Promise.all([
|
|
11350
|
-
fresh.saveVtxos(addressData.address, addressData.vtxos),
|
|
11351
|
-
fresh.saveTransactions(addressData.address, addressData.txs)
|
|
11352
|
-
])
|
|
11353
|
-
),
|
|
11354
|
-
...onchainAddrData.map(
|
|
11355
|
-
(addressData) => fresh.saveUtxos(addressData.address, addressData.utxos)
|
|
11356
|
-
)
|
|
11357
|
-
]);
|
|
11358
|
-
await storageAdapter.setItem(MIGRATION_KEY("wallet"), "done");
|
|
11359
|
-
}
|
|
11360
|
-
|
|
11361
|
-
// src/repositories/migrations/contractRepositoryImpl.ts
|
|
11362
|
-
var getContractStorageKey = (id, key) => `contract:${id}:${key}`;
|
|
11363
|
-
var getCollectionStorageKey = (type) => `collection:${type}`;
|
|
11364
|
-
var ContractRepositoryImpl = class {
|
|
11365
|
-
storage;
|
|
11366
|
-
constructor(storage) {
|
|
11367
|
-
this.storage = storage;
|
|
11368
|
-
}
|
|
11369
|
-
get version() {
|
|
11370
|
-
throw new TypeError(
|
|
11371
|
-
"ContractRepositoryImpl is a migration shim and does not implement contract rows."
|
|
11372
|
-
);
|
|
11373
|
-
}
|
|
11374
|
-
async getContractData(contractId, key) {
|
|
11375
|
-
const stored = await this.storage.getItem(getContractStorageKey(contractId, key));
|
|
11376
|
-
if (!stored) return null;
|
|
11377
|
-
try {
|
|
11378
|
-
const data = JSON.parse(stored);
|
|
11379
|
-
return data;
|
|
11380
|
-
} catch (error) {
|
|
11381
|
-
console.error(`Failed to parse contract data for ${contractId}:${key}:`, error);
|
|
11382
|
-
return null;
|
|
11383
|
-
}
|
|
11384
|
-
}
|
|
11385
|
-
async setContractData(contractId, key, data) {
|
|
11386
|
-
try {
|
|
11387
|
-
await this.storage.setItem(
|
|
11388
|
-
getContractStorageKey(contractId, key),
|
|
11389
|
-
JSON.stringify(data)
|
|
11390
|
-
);
|
|
11391
|
-
} catch (error) {
|
|
11392
|
-
console.error(`Failed to persist contract data for ${contractId}:${key}:`, error);
|
|
11393
|
-
throw error;
|
|
11394
|
-
}
|
|
11395
|
-
}
|
|
11396
|
-
async deleteContractData(contractId, key) {
|
|
11397
|
-
try {
|
|
11398
|
-
await this.storage.removeItem(getContractStorageKey(contractId, key));
|
|
11399
|
-
} catch (error) {
|
|
11400
|
-
console.error(`Failed to remove contract data for ${contractId}:${key}:`, error);
|
|
11401
|
-
throw error;
|
|
11402
|
-
}
|
|
11403
|
-
}
|
|
11404
|
-
async getContractCollection(contractType) {
|
|
11405
|
-
const stored = await this.storage.getItem(getCollectionStorageKey(contractType));
|
|
11406
|
-
if (!stored) return [];
|
|
11407
|
-
try {
|
|
11408
|
-
const collection = JSON.parse(stored);
|
|
11409
|
-
return collection;
|
|
11410
|
-
} catch (error) {
|
|
11411
|
-
console.error(`Failed to parse contract collection ${contractType}:`, error);
|
|
11412
|
-
return [];
|
|
11413
|
-
}
|
|
11414
|
-
}
|
|
11415
|
-
async saveToContractCollection(contractType, item, idField) {
|
|
11416
|
-
const collection = await this.getContractCollection(contractType);
|
|
11417
|
-
const itemId = item[idField];
|
|
11418
|
-
if (itemId === void 0 || itemId === null) {
|
|
11419
|
-
throw new Error(`Item is missing required field '${String(idField)}'`);
|
|
11420
|
-
}
|
|
11421
|
-
const existingIndex = collection.findIndex((i) => i[idField] === itemId);
|
|
11422
|
-
let newCollection;
|
|
11423
|
-
if (existingIndex !== -1) {
|
|
11424
|
-
newCollection = [
|
|
11425
|
-
...collection.slice(0, existingIndex),
|
|
11426
|
-
item,
|
|
11427
|
-
...collection.slice(existingIndex + 1)
|
|
11428
|
-
];
|
|
11429
|
-
} else {
|
|
11430
|
-
newCollection = [...collection, item];
|
|
11431
|
-
}
|
|
11432
|
-
try {
|
|
11433
|
-
await this.storage.setItem(
|
|
11434
|
-
getCollectionStorageKey(contractType),
|
|
11435
|
-
JSON.stringify(newCollection)
|
|
11436
|
-
);
|
|
11437
|
-
} catch (error) {
|
|
11438
|
-
console.error(`Failed to persist contract collection ${contractType}:`, error);
|
|
11439
|
-
throw error;
|
|
11440
|
-
}
|
|
11441
|
-
}
|
|
11442
|
-
async removeFromContractCollection(contractType, id, idField) {
|
|
11443
|
-
if (id === void 0 || id === null) {
|
|
11444
|
-
throw new Error(`Invalid id provided for removal: ${String(id)}`);
|
|
11445
|
-
}
|
|
11446
|
-
const collection = await this.getContractCollection(contractType);
|
|
11447
|
-
const filtered = collection.filter((item) => item[idField] !== id);
|
|
11448
|
-
try {
|
|
11449
|
-
await this.storage.setItem(
|
|
11450
|
-
getCollectionStorageKey(contractType),
|
|
11451
|
-
JSON.stringify(filtered)
|
|
11452
|
-
);
|
|
11453
|
-
} catch (error) {
|
|
11454
|
-
console.error(
|
|
11455
|
-
`Failed to persist contract collection removal for ${contractType}:`,
|
|
11456
|
-
error
|
|
11457
|
-
);
|
|
11458
|
-
throw error;
|
|
11459
|
-
}
|
|
11460
|
-
}
|
|
11461
|
-
// The following methods are implemented for compatibility with the new ContractRepository interface
|
|
11462
|
-
// but aren't used.
|
|
11463
|
-
async getContracts(_) {
|
|
11464
|
-
throw new TypeError(
|
|
11465
|
-
"Method not implemented, this is a legacy class and should only be used for migrating data."
|
|
11466
|
-
);
|
|
11467
|
-
}
|
|
11468
|
-
async saveContract(_) {
|
|
11469
|
-
throw new TypeError(
|
|
11470
|
-
"Method not implemented, this is a legacy class and should only be used for migrating data."
|
|
11471
|
-
);
|
|
11472
|
-
}
|
|
11473
|
-
async deleteContract(_) {
|
|
11474
|
-
throw new TypeError(
|
|
11475
|
-
"Method not implemented, this is a legacy class and should only be used for migrating data."
|
|
11476
|
-
);
|
|
11477
|
-
}
|
|
11478
|
-
// used only for tests
|
|
11479
|
-
async clear() {
|
|
11480
|
-
await this.storage.clear();
|
|
11481
|
-
}
|
|
11482
|
-
async [Symbol.asyncDispose]() {
|
|
11483
|
-
return;
|
|
11484
|
-
}
|
|
11485
|
-
};
|
|
11486
11300
|
var HD_SETTINGS_KEY = "hd";
|
|
11487
11301
|
var HARDENED_INDEX_OFFSET = 2147483648;
|
|
11488
11302
|
var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
@@ -11569,7 +11383,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11569
11383
|
* simple `tr(pubkey)` descriptors.
|
|
11570
11384
|
*/
|
|
11571
11385
|
isOurs(descriptor) {
|
|
11572
|
-
return this.identity.
|
|
11386
|
+
return this.identity.ownsDescriptor(descriptor);
|
|
11573
11387
|
}
|
|
11574
11388
|
/**
|
|
11575
11389
|
* Signs each request with the key derived from its descriptor. Delegates
|
|
@@ -11577,11 +11391,11 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11577
11391
|
* holds the seed.
|
|
11578
11392
|
*/
|
|
11579
11393
|
async signWithDescriptor(requests) {
|
|
11580
|
-
return this.identity.
|
|
11394
|
+
return this.identity.signDescriptorTransactions(requests);
|
|
11581
11395
|
}
|
|
11582
11396
|
/** Signs a message using the key derived from `descriptor`. */
|
|
11583
11397
|
async signMessageWithDescriptor(descriptor, message, signatureType = "schnorr") {
|
|
11584
|
-
return this.identity.
|
|
11398
|
+
return this.identity.signDescriptorMessage(descriptor, message, signatureType);
|
|
11585
11399
|
}
|
|
11586
11400
|
/**
|
|
11587
11401
|
* HD providers participate in receive rotation. The default
|
|
@@ -11606,7 +11420,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
11606
11420
|
*/
|
|
11607
11421
|
materializeDescriptorAt(index) {
|
|
11608
11422
|
const descriptor = this.identity.descriptor;
|
|
11609
|
-
const network =
|
|
11423
|
+
const network = chunkAEDYZK7T_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
11610
11424
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
11611
11425
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
11612
11426
|
if (!keyInfo?.keyExpression) {
|
|
@@ -11754,7 +11568,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
11754
11568
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
11755
11569
|
if (!provider) return void 0;
|
|
11756
11570
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
11757
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
11571
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
11758
11572
|
const factoryOpts = {
|
|
11759
11573
|
walletRepository: setup.walletRepository,
|
|
11760
11574
|
contractRepository: setup.contractRepository,
|
|
@@ -11955,7 +11769,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
11955
11769
|
};
|
|
11956
11770
|
function deriveLeafPubkey(descriptor) {
|
|
11957
11771
|
try {
|
|
11958
|
-
return
|
|
11772
|
+
return chunkAEDYZK7T_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11959
11773
|
} catch (e) {
|
|
11960
11774
|
throw new NonRangeableDescriptorError(
|
|
11961
11775
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -11967,7 +11781,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
11967
11781
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
11968
11782
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
11969
11783
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
11970
|
-
const csvTimelock =
|
|
11784
|
+
const csvTimelock = chunkQWWOD7M2_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
11971
11785
|
const base$1 = {
|
|
11972
11786
|
script: base.hex.encode(tapscript.pkScript),
|
|
11973
11787
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -11978,11 +11792,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
11978
11792
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
11979
11793
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
11980
11794
|
metadata: {
|
|
11981
|
-
...tagSource && { source:
|
|
11795
|
+
...tagSource && { source: chunkAEDYZK7T_cjs.WALLET_RECEIVE_SOURCE },
|
|
11982
11796
|
signingDescriptor: descriptor
|
|
11983
11797
|
}
|
|
11984
11798
|
};
|
|
11985
|
-
const params = tapscript instanceof
|
|
11799
|
+
const params = tapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? {
|
|
11986
11800
|
...base$1,
|
|
11987
11801
|
type: "delegate",
|
|
11988
11802
|
params: {
|
|
@@ -12003,10 +11817,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12003
11817
|
return { tapscript, params };
|
|
12004
11818
|
}
|
|
12005
11819
|
function rebuildTapscript(current, pubKey) {
|
|
12006
|
-
if (current instanceof
|
|
12007
|
-
return new
|
|
11820
|
+
if (current instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script) {
|
|
11821
|
+
return new chunkAEDYZK7T_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12008
11822
|
}
|
|
12009
|
-
return new
|
|
11823
|
+
return new chunkAEDYZK7T_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12010
11824
|
}
|
|
12011
11825
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12012
11826
|
const candidates = await contractRepository.getContracts({
|
|
@@ -12015,7 +11829,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
12015
11829
|
});
|
|
12016
11830
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
12017
11831
|
const matching = candidates.filter(
|
|
12018
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
11832
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkAEDYZK7T_cjs.WALLET_RECEIVE_SOURCE
|
|
12019
11833
|
).sort((a, b) => {
|
|
12020
11834
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12021
11835
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12071,7 +11885,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12071
11885
|
}
|
|
12072
11886
|
};
|
|
12073
11887
|
for (const vtxo of vtxos) {
|
|
12074
|
-
if (
|
|
11888
|
+
if (chunkQWWOD7M2_cjs.hasTerminalSpend(vtxo)) continue;
|
|
12075
11889
|
addAssets(owned, vtxo);
|
|
12076
11890
|
if (vtxo.isUnrolled) {
|
|
12077
11891
|
unrolled += vtxo.value;
|
|
@@ -12081,11 +11895,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12081
11895
|
pendingRecovery += vtxo.value;
|
|
12082
11896
|
continue;
|
|
12083
11897
|
}
|
|
12084
|
-
if (
|
|
11898
|
+
if (chunkQWWOD7M2_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12085
11899
|
recoverable += vtxo.value;
|
|
12086
11900
|
continue;
|
|
12087
11901
|
}
|
|
12088
|
-
if (!
|
|
11902
|
+
if (!chunkQWWOD7M2_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12089
11903
|
if (vtxo.isPreconfirmed) {
|
|
12090
11904
|
preconfirmed += vtxo.value;
|
|
12091
11905
|
} else {
|
|
@@ -12255,12 +12069,11 @@ var InputSignerRouter = class {
|
|
|
12255
12069
|
};
|
|
12256
12070
|
|
|
12257
12071
|
// src/wallet/wallet.ts
|
|
12258
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkUJTYUYY4_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12259
12072
|
function intentProofJobs(coins) {
|
|
12260
12073
|
if (coins.length === 0) return [];
|
|
12261
12074
|
const coinJobs = coins.map((coin, i) => ({
|
|
12262
12075
|
index: i + 1,
|
|
12263
|
-
lookupScript:
|
|
12076
|
+
lookupScript: chunkQWWOD7M2_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
12264
12077
|
}));
|
|
12265
12078
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
12266
12079
|
}
|
|
@@ -12292,7 +12105,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
12292
12105
|
const seen = /* @__PURE__ */ new Set();
|
|
12293
12106
|
const deduped = [];
|
|
12294
12107
|
for (const timelock of timelocks) {
|
|
12295
|
-
const sequence =
|
|
12108
|
+
const sequence = chunkQWWOD7M2_cjs.timelockToSequence(timelock).toString();
|
|
12296
12109
|
if (seen.has(sequence)) continue;
|
|
12297
12110
|
seen.add(sequence);
|
|
12298
12111
|
deduped.push(timelock);
|
|
@@ -12309,7 +12122,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12309
12122
|
state: "active"
|
|
12310
12123
|
});
|
|
12311
12124
|
const newest = candidates.filter(
|
|
12312
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12125
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkAEDYZK7T_cjs.WALLET_RECEIVE_SOURCE
|
|
12313
12126
|
).sort((a, b) => {
|
|
12314
12127
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12315
12128
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12317,7 +12130,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
12317
12130
|
if (!newest?.params.pubKey) return baseline;
|
|
12318
12131
|
try {
|
|
12319
12132
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
12320
|
-
return new
|
|
12133
|
+
return new chunkAEDYZK7T_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
12321
12134
|
} catch (e) {
|
|
12322
12135
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
12323
12136
|
return baseline;
|
|
@@ -12336,10 +12149,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
|
|
|
12336
12149
|
if (vtxo.isUnrolled) {
|
|
12337
12150
|
return !!f.withUnrolled;
|
|
12338
12151
|
}
|
|
12339
|
-
if (
|
|
12152
|
+
if (chunkQWWOD7M2_cjs.hasTerminalSpend(vtxo)) {
|
|
12340
12153
|
return false;
|
|
12341
12154
|
}
|
|
12342
|
-
if (!f.withRecoverable &&
|
|
12155
|
+
if (!f.withRecoverable && chunkQWWOD7M2_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12343
12156
|
return false;
|
|
12344
12157
|
}
|
|
12345
12158
|
return true;
|
|
@@ -12690,7 +12503,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12690
12503
|
async getArkadeReader() {
|
|
12691
12504
|
const indexer = this.indexerProvider;
|
|
12692
12505
|
return {
|
|
12693
|
-
getVtxos: (opts) =>
|
|
12506
|
+
getVtxos: (opts) => chunkQWWOD7M2_cjs.getNormalizedVtxos(indexer, opts),
|
|
12694
12507
|
getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
|
|
12695
12508
|
};
|
|
12696
12509
|
}
|
|
@@ -12745,25 +12558,16 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12745
12558
|
* Extracts common logic used by both ReadonlyWallet.create() and Wallet.create().
|
|
12746
12559
|
*/
|
|
12747
12560
|
static async setupWalletConfig(config, pubKey) {
|
|
12748
|
-
const
|
|
12749
|
-
const arkProvider = config.arkProvider || new chunkUJTYUYY4_cjs.RestArkProvider(arkadeServerUrl);
|
|
12561
|
+
const arkProvider = config.arkProvider || new chunkQWWOD7M2_cjs.RestArkProvider();
|
|
12750
12562
|
let indexerProvider = config.indexerProvider;
|
|
12751
12563
|
if (!indexerProvider) {
|
|
12752
|
-
|
|
12753
|
-
if (!
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
throw new Error(
|
|
12758
|
-
"indexerUrl is required when arkProvider is provided without a discoverable serverUrl"
|
|
12759
|
-
);
|
|
12760
|
-
}
|
|
12761
|
-
indexerUrl = derived;
|
|
12762
|
-
} else {
|
|
12763
|
-
indexerUrl = arkadeServerUrl;
|
|
12764
|
-
}
|
|
12564
|
+
const derived = extractArkProviderUrl(arkProvider);
|
|
12565
|
+
if (!derived && config.arkProvider) {
|
|
12566
|
+
throw new Error(
|
|
12567
|
+
"indexerProvider is required when arkProvider is provided without a discoverable serverUrl"
|
|
12568
|
+
);
|
|
12765
12569
|
}
|
|
12766
|
-
indexerProvider = new
|
|
12570
|
+
indexerProvider = new chunkNEVMOIQL_cjs.RestIndexerProvider(derived ?? chunkQWWOD7M2_cjs.DEFAULT_ARKADE_SERVER_URL);
|
|
12767
12571
|
}
|
|
12768
12572
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
12769
12573
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -12772,7 +12576,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12772
12576
|
source: serverInfoSource,
|
|
12773
12577
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
12774
12578
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
12775
|
-
const network =
|
|
12579
|
+
const network = chunkQWWOD7M2_cjs.networkFromArkadeInfo(info);
|
|
12776
12580
|
if ("descriptor" in config.identity) {
|
|
12777
12581
|
const descriptor = config.identity.descriptor;
|
|
12778
12582
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -12788,8 +12592,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12788
12592
|
);
|
|
12789
12593
|
}
|
|
12790
12594
|
}
|
|
12791
|
-
const
|
|
12792
|
-
const onchainProvider = config.onchainProvider || new EsploraProvider(esploraUrl);
|
|
12595
|
+
const onchainProvider = config.onchainProvider || new EsploraProvider(ESPLORA_URL[info.network]);
|
|
12793
12596
|
if (config.exitTimelock) {
|
|
12794
12597
|
const { value, type } = config.exitTimelock;
|
|
12795
12598
|
if (value < 512n && type !== "blocks" || value >= 512n && type !== "seconds") {
|
|
@@ -12812,18 +12615,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12812
12615
|
value: info.boardingExitDelay,
|
|
12813
12616
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
12814
12617
|
};
|
|
12815
|
-
const serverPubKey =
|
|
12816
|
-
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) =>
|
|
12618
|
+
const serverPubKey = chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
12619
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
|
|
12817
12620
|
const offchainOptions = {
|
|
12818
12621
|
pubKey,
|
|
12819
12622
|
serverPubKey,
|
|
12820
12623
|
csvTimelock: exitTimelock
|
|
12821
12624
|
};
|
|
12822
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
12823
|
-
const boardingTapscript =
|
|
12625
|
+
const offchainTapscript = !delegatePubKey ? new chunkAEDYZK7T_cjs.DefaultVtxo.Script(offchainOptions) : new chunkAEDYZK7T_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
12626
|
+
const boardingTapscript = chunkAEDYZK7T_cjs.BoardingContractHandler.createScript({
|
|
12824
12627
|
pubKey: base.hex.encode(pubKey),
|
|
12825
12628
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
12826
|
-
csvTimelock:
|
|
12629
|
+
csvTimelock: chunkQWWOD7M2_cjs.timelockToSequence(boardingTimelock).toString()
|
|
12827
12630
|
});
|
|
12828
12631
|
return {
|
|
12829
12632
|
arkProvider,
|
|
@@ -12840,9 +12643,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12840
12643
|
info,
|
|
12841
12644
|
serverInfoSource,
|
|
12842
12645
|
serverInfoLastOnlineAt,
|
|
12843
|
-
delegateProvider: config.delegateProvider
|
|
12844
|
-
/** @deprecated alias for `delegateProvider` */
|
|
12845
|
-
delegatorProvider: config.delegateProvider || config.delegatorProvider,
|
|
12646
|
+
delegateProvider: config.delegateProvider,
|
|
12846
12647
|
walletContractTimelocks
|
|
12847
12648
|
};
|
|
12848
12649
|
}
|
|
@@ -12870,7 +12671,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12870
12671
|
setup.dustAmount,
|
|
12871
12672
|
setup.walletRepository,
|
|
12872
12673
|
setup.contractRepository,
|
|
12873
|
-
setup.delegateProvider
|
|
12674
|
+
setup.delegateProvider,
|
|
12874
12675
|
config.watcherConfig,
|
|
12875
12676
|
setup.walletContractTimelocks
|
|
12876
12677
|
);
|
|
@@ -12958,7 +12759,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12958
12759
|
* The raw reporting/recovery read: escrowed, locked and awaiting-recovery
|
|
12959
12760
|
* funds are all present. Coin selection must use
|
|
12960
12761
|
* {@link getSpendableVtxos} instead — feeding this straight into
|
|
12961
|
-
* `settle({ inputs })` or `
|
|
12762
|
+
* `settle({ inputs })` or `send({ selectedVtxos })` bypasses the
|
|
12962
12763
|
* generic-spending gate.
|
|
12963
12764
|
*
|
|
12964
12765
|
* @param filter - Optional flags controlling whether recoverable or unrolled VTXOs are included
|
|
@@ -12990,7 +12791,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
12990
12791
|
if (!filter?.withUnrolled) {
|
|
12991
12792
|
logExcludedVtxos(
|
|
12992
12793
|
"getSpendableVtxos",
|
|
12993
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
12794
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkQWWOD7M2_cjs.hasTerminalSpend(vtxo)),
|
|
12994
12795
|
[() => UNROLLED_REASON]
|
|
12995
12796
|
);
|
|
12996
12797
|
}
|
|
@@ -13133,7 +12934,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13133
12934
|
const response = await contractManager.getContractsWithVtxos();
|
|
13134
12935
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
13135
12936
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
13136
|
-
const resolveTxCreatedAt = (txids) =>
|
|
12937
|
+
const resolveTxCreatedAt = (txids) => chunkQWWOD7M2_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13137
12938
|
return buildTransactionHistory(
|
|
13138
12939
|
allVtxos,
|
|
13139
12940
|
boardingTxs,
|
|
@@ -13227,7 +13028,6 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13227
13028
|
},
|
|
13228
13029
|
isUnrolled: true,
|
|
13229
13030
|
...boardingFacts,
|
|
13230
|
-
virtualStatus: chunkUJTYUYY4_cjs.toVirtualStatus(boardingFacts),
|
|
13231
13031
|
spentBy: "",
|
|
13232
13032
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
13233
13033
|
script: scriptHex
|
|
@@ -13283,9 +13083,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13283
13083
|
async getBoardingTapscripts(allowedSigners) {
|
|
13284
13084
|
const byScript = /* @__PURE__ */ new Map();
|
|
13285
13085
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
13286
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
13086
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkAEDYZK7T_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13287
13087
|
add(
|
|
13288
|
-
new
|
|
13088
|
+
new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
13289
13089
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
13290
13090
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
13291
13091
|
csvTimelock: boardingCsv
|
|
@@ -13300,7 +13100,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13300
13100
|
for (const c of boardingContracts) {
|
|
13301
13101
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
13302
13102
|
try {
|
|
13303
|
-
add(
|
|
13103
|
+
add(chunkAEDYZK7T_cjs.BoardingContractHandler.createScript(c.params));
|
|
13304
13104
|
} catch (e) {
|
|
13305
13105
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
13306
13106
|
}
|
|
@@ -13338,7 +13138,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13338
13138
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
13339
13139
|
// not the wallet's current boarding timelock, which a signer
|
|
13340
13140
|
// rotation may have changed.
|
|
13341
|
-
csvTimelock:
|
|
13141
|
+
csvTimelock: chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
13342
13142
|
coins: utxos
|
|
13343
13143
|
});
|
|
13344
13144
|
}
|
|
@@ -13436,7 +13236,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13436
13236
|
const cm = await this.getContractManager();
|
|
13437
13237
|
let annotationQueue = Promise.resolve();
|
|
13438
13238
|
indexerStopFunc = cm.onContractEvent((event) => {
|
|
13439
|
-
if (event
|
|
13239
|
+
if (!isContractVtxoEvent(event)) {
|
|
13440
13240
|
return;
|
|
13441
13241
|
}
|
|
13442
13242
|
if (event.contract.type !== "default" && event.contract.type !== "delegate") {
|
|
@@ -13471,7 +13271,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13471
13271
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
13472
13272
|
async fetchPendingTxs() {
|
|
13473
13273
|
const scripts = await this.getWalletScripts();
|
|
13474
|
-
const vtxos = await
|
|
13274
|
+
const vtxos = await chunkQWWOD7M2_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
13475
13275
|
return vtxos.filter(
|
|
13476
13276
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
13477
13277
|
).map((_) => _.arkTxId);
|
|
@@ -13502,7 +13302,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13502
13302
|
});
|
|
13503
13303
|
for (const contract of contracts) {
|
|
13504
13304
|
if (map.has(contract.script)) continue;
|
|
13505
|
-
const handler =
|
|
13305
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
13506
13306
|
if (handler) {
|
|
13507
13307
|
const script = handler.createScript(contract.params);
|
|
13508
13308
|
map.set(contract.script, script);
|
|
@@ -13614,7 +13414,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13614
13414
|
}
|
|
13615
13415
|
});
|
|
13616
13416
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
13617
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
13417
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
13618
13418
|
const baselineSigners = [
|
|
13619
13419
|
this.offchainTapscript.options.serverPubKey,
|
|
13620
13420
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -13622,8 +13422,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13622
13422
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
13623
13423
|
for (const serverPubKey of baselineSigners) {
|
|
13624
13424
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
13625
|
-
const csvTimelockStr =
|
|
13626
|
-
const defaultScript = new
|
|
13425
|
+
const csvTimelockStr = chunkQWWOD7M2_cjs.timelockToSequence(csvTimelock).toString();
|
|
13426
|
+
const defaultScript = new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
13627
13427
|
pubKey: baselinePubkey,
|
|
13628
13428
|
serverPubKey,
|
|
13629
13429
|
csvTimelock
|
|
@@ -13644,7 +13444,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13644
13444
|
});
|
|
13645
13445
|
}
|
|
13646
13446
|
if (delegatePubKey) {
|
|
13647
|
-
const delegateScript = new
|
|
13447
|
+
const delegateScript = new chunkAEDYZK7T_cjs.DelegateVtxo.Script({
|
|
13648
13448
|
pubKey: baselinePubkey,
|
|
13649
13449
|
serverPubKey,
|
|
13650
13450
|
delegatePubKey,
|
|
@@ -13668,9 +13468,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13668
13468
|
}
|
|
13669
13469
|
}
|
|
13670
13470
|
}
|
|
13671
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
13471
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkAEDYZK7T_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
13672
13472
|
for (const serverPubKey of baselineSigners) {
|
|
13673
|
-
const baselineBoarding = new
|
|
13473
|
+
const baselineBoarding = new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
13674
13474
|
pubKey: baselinePubkey,
|
|
13675
13475
|
serverPubKey,
|
|
13676
13476
|
csvTimelock: boardingCsvTimelock
|
|
@@ -13683,7 +13483,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13683
13483
|
params: {
|
|
13684
13484
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
13685
13485
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13686
|
-
csvTimelock:
|
|
13486
|
+
csvTimelock: chunkQWWOD7M2_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
13687
13487
|
},
|
|
13688
13488
|
script: boardingScriptHex,
|
|
13689
13489
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -13705,7 +13505,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13705
13505
|
}
|
|
13706
13506
|
};
|
|
13707
13507
|
var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
13708
|
-
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository,
|
|
13508
|
+
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, settlementConfig, walletContractTimelocks, receiveRotator, descriptorProvider, lookAheadWindow, batchExpiryPolicy, checkpointExitDelayPolicy) {
|
|
13709
13509
|
super(
|
|
13710
13510
|
identity,
|
|
13711
13511
|
network,
|
|
@@ -13727,22 +13527,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13727
13527
|
this.batchExpiryPolicy = batchExpiryPolicy;
|
|
13728
13528
|
this.checkpointExitDelayPolicy = checkpointExitDelayPolicy;
|
|
13729
13529
|
this.identity = identity;
|
|
13730
|
-
this.
|
|
13731
|
-
enabled: renewalConfig?.enabled ?? false,
|
|
13732
|
-
...DEFAULT_RENEWAL_CONFIG,
|
|
13733
|
-
...renewalConfig
|
|
13734
|
-
};
|
|
13735
|
-
if (settlementConfig !== void 0) {
|
|
13736
|
-
this.settlementConfig = settlementConfig;
|
|
13737
|
-
} else if (renewalConfig && this.renewalConfig.enabled) {
|
|
13738
|
-
this.settlementConfig = {
|
|
13739
|
-
vtxoThreshold: renewalConfig.thresholdMs ? renewalConfig.thresholdMs / 1e3 : void 0
|
|
13740
|
-
};
|
|
13741
|
-
} else if (renewalConfig) {
|
|
13742
|
-
this.settlementConfig = false;
|
|
13743
|
-
} else {
|
|
13744
|
-
this.settlementConfig = { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
13745
|
-
}
|
|
13530
|
+
this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
13746
13531
|
this._delegateManager = delegateProvider ? new DelegateManagerImpl(delegateProvider, arkProvider, identity) : void 0;
|
|
13747
13532
|
this._serverUnrollScript = serverUnrollScript;
|
|
13748
13533
|
this._receiveRotator = receiveRotator;
|
|
@@ -13882,7 +13667,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13882
13667
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
13883
13668
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
13884
13669
|
csvTimelocks: this.walletContractTimelocks,
|
|
13885
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
13670
|
+
delegatePubKey: this.offchainTapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
13886
13671
|
};
|
|
13887
13672
|
}
|
|
13888
13673
|
_signerRouter;
|
|
@@ -14127,7 +13912,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14127
13912
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14128
13913
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14129
13914
|
if (typeof persisted === "string") return persisted;
|
|
14130
|
-
return
|
|
13915
|
+
return chunkAEDYZK7T_cjs.identityDescriptor(this.identity);
|
|
14131
13916
|
}
|
|
14132
13917
|
/**
|
|
14133
13918
|
* Build, persist and shape one address of `type` owned by `descriptor` —
|
|
@@ -14143,7 +13928,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14143
13928
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14144
13929
|
if (type === "boarding") {
|
|
14145
13930
|
const built2 = this.buildBoardingContract(
|
|
14146
|
-
|
|
13931
|
+
chunkAEDYZK7T_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14147
13932
|
descriptor,
|
|
14148
13933
|
tagSource
|
|
14149
13934
|
);
|
|
@@ -14188,11 +13973,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14188
13973
|
* {@link buildReceiveContract}.
|
|
14189
13974
|
*/
|
|
14190
13975
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14191
|
-
const tapscript = new
|
|
13976
|
+
const tapscript = new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
14192
13977
|
...this._boardingTapscript.options,
|
|
14193
13978
|
pubKey
|
|
14194
13979
|
});
|
|
14195
|
-
const csvTimelock = tapscript.options.csvTimelock ??
|
|
13980
|
+
const csvTimelock = tapscript.options.csvTimelock ?? chunkAEDYZK7T_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14196
13981
|
return {
|
|
14197
13982
|
tapscript,
|
|
14198
13983
|
params: {
|
|
@@ -14200,13 +13985,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14200
13985
|
params: {
|
|
14201
13986
|
pubKey: base.hex.encode(pubKey),
|
|
14202
13987
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14203
|
-
csvTimelock:
|
|
13988
|
+
csvTimelock: chunkQWWOD7M2_cjs.timelockToSequence(csvTimelock).toString()
|
|
14204
13989
|
},
|
|
14205
13990
|
script: base.hex.encode(tapscript.pkScript),
|
|
14206
13991
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14207
13992
|
state: "active",
|
|
14208
13993
|
metadata: {
|
|
14209
|
-
...tagSource && { source:
|
|
13994
|
+
...tagSource && { source: chunkAEDYZK7T_cjs.WALLET_RECEIVE_SOURCE },
|
|
14210
13995
|
signingDescriptor: descriptor
|
|
14211
13996
|
}
|
|
14212
13997
|
}
|
|
@@ -14235,7 +14020,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14235
14020
|
if (this._descriptorProvider instanceof HDDescriptorProvider) {
|
|
14236
14021
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14237
14022
|
}
|
|
14238
|
-
return
|
|
14023
|
+
return chunkAEDYZK7T_cjs.identityDescriptor(this.identity);
|
|
14239
14024
|
}
|
|
14240
14025
|
/**
|
|
14241
14026
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14331,7 +14116,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14331
14116
|
* the stable public API.
|
|
14332
14117
|
*/
|
|
14333
14118
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14334
|
-
const xonly =
|
|
14119
|
+
const xonly = chunkAEDYZK7T_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14335
14120
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14336
14121
|
checkpointTapscript,
|
|
14337
14122
|
resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
|
|
@@ -14360,21 +14145,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14360
14145
|
const [currentBoardingRow] = await manager.getContracts({
|
|
14361
14146
|
script: currentBoardingScript
|
|
14362
14147
|
});
|
|
14363
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
14148
|
+
const newOffchain = this.offchainTapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? new chunkAEDYZK7T_cjs.DelegateVtxo.Script({
|
|
14364
14149
|
...this.offchainTapscript.options,
|
|
14365
14150
|
serverPubKey: xonly
|
|
14366
|
-
}) : new
|
|
14151
|
+
}) : new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
14367
14152
|
...this.offchainTapscript.options,
|
|
14368
14153
|
serverPubKey: xonly
|
|
14369
14154
|
});
|
|
14370
|
-
const newBoarding = new
|
|
14155
|
+
const newBoarding = new chunkAEDYZK7T_cjs.DefaultVtxo.Script({
|
|
14371
14156
|
...this._boardingTapscript.options,
|
|
14372
14157
|
serverPubKey: xonly
|
|
14373
14158
|
});
|
|
14374
|
-
const offchainCsv =
|
|
14159
|
+
const offchainCsv = chunkQWWOD7M2_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
14375
14160
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
14376
14161
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
14377
|
-
if (newOffchain instanceof
|
|
14162
|
+
if (newOffchain instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script) {
|
|
14378
14163
|
await manager.createContract({
|
|
14379
14164
|
type: "delegate",
|
|
14380
14165
|
params: {
|
|
@@ -14402,13 +14187,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14402
14187
|
metadata: currentOffchainRow?.metadata
|
|
14403
14188
|
});
|
|
14404
14189
|
}
|
|
14405
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
14190
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkAEDYZK7T_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14406
14191
|
await manager.createContract({
|
|
14407
14192
|
type: "boarding",
|
|
14408
14193
|
params: {
|
|
14409
14194
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
14410
14195
|
serverPubKey: base.hex.encode(xonly),
|
|
14411
|
-
csvTimelock:
|
|
14196
|
+
csvTimelock: chunkQWWOD7M2_cjs.timelockToSequence(boardingCsv).toString()
|
|
14412
14197
|
},
|
|
14413
14198
|
script: base.hex.encode(newBoarding.pkScript),
|
|
14414
14199
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -14427,7 +14212,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14427
14212
|
}
|
|
14428
14213
|
/**
|
|
14429
14214
|
* Async mutex that serializes all operations submitting VTXOs to the Arkade
|
|
14430
|
-
* server (`settle`, `send
|
|
14215
|
+
* server (`settle`, `send`). This prevents VtxoManager's
|
|
14431
14216
|
* background renewal from racing with user-initiated transactions for the
|
|
14432
14217
|
* same VTXO inputs.
|
|
14433
14218
|
*/
|
|
@@ -14441,14 +14226,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14441
14226
|
_restoreInFlight;
|
|
14442
14227
|
_addPendingSpends(inputs) {
|
|
14443
14228
|
for (const input of inputs) {
|
|
14444
|
-
if (
|
|
14229
|
+
if (chunkQWWOD7M2_cjs.isVirtualCoin(input)) {
|
|
14445
14230
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
14446
14231
|
}
|
|
14447
14232
|
}
|
|
14448
14233
|
}
|
|
14449
14234
|
_removePendingSpends(inputs) {
|
|
14450
14235
|
for (const input of inputs) {
|
|
14451
|
-
if (
|
|
14236
|
+
if (chunkQWWOD7M2_cjs.isVirtualCoin(input)) {
|
|
14452
14237
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
14453
14238
|
}
|
|
14454
14239
|
}
|
|
@@ -14506,13 +14291,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14506
14291
|
const manager = await this.getContractManager();
|
|
14507
14292
|
const provider = this._descriptorProvider;
|
|
14508
14293
|
const hd = provider instanceof HDDescriptorProvider;
|
|
14509
|
-
const staticDescriptor = hd ? void 0 : await
|
|
14294
|
+
const staticDescriptor = hd ? void 0 : await chunkAEDYZK7T_cjs.identityDescriptor(this.identity);
|
|
14510
14295
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
14511
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
14296
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkAEDYZK7T_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14512
14297
|
const arkInfo = await this.arkProvider.getInfo();
|
|
14513
|
-
const currentSignerPubKey =
|
|
14298
|
+
const currentSignerPubKey = chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
14514
14299
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
14515
|
-
(s) =>
|
|
14300
|
+
(s) => chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
14516
14301
|
);
|
|
14517
14302
|
const deps = {
|
|
14518
14303
|
indexerProvider: this.indexerProvider,
|
|
@@ -14527,7 +14312,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14527
14312
|
csvTimelocks: this.walletContractTimelocks,
|
|
14528
14313
|
// Boarding-exit CSV so the boarding handler can build its
|
|
14529
14314
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
14530
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
14315
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkAEDYZK7T_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
14531
14316
|
delegatePubKey
|
|
14532
14317
|
};
|
|
14533
14318
|
const result = await manager.scanContracts({
|
|
@@ -14557,8 +14342,6 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14557
14342
|
);
|
|
14558
14343
|
}
|
|
14559
14344
|
}
|
|
14560
|
-
/** @deprecated Use settlementConfig instead */
|
|
14561
|
-
renewalConfig;
|
|
14562
14345
|
settlementConfig;
|
|
14563
14346
|
/**
|
|
14564
14347
|
* Broadcast access bound to this wallet's server, so a plugin needs only
|
|
@@ -14587,7 +14370,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14587
14370
|
return this._vtxoManagerInitializing;
|
|
14588
14371
|
}
|
|
14589
14372
|
this._vtxoManagerInitializing = Promise.resolve(
|
|
14590
|
-
new VtxoManager(this, this.
|
|
14373
|
+
new VtxoManager(this, this.settlementConfig)
|
|
14591
14374
|
);
|
|
14592
14375
|
try {
|
|
14593
14376
|
const manager = await this._vtxoManagerInitializing;
|
|
@@ -14656,7 +14439,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14656
14439
|
throw new Error("Invalid configured public key");
|
|
14657
14440
|
}
|
|
14658
14441
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
14659
|
-
const forfeitPubkey =
|
|
14442
|
+
const forfeitPubkey = chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
14660
14443
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
14661
14444
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
14662
14445
|
const checkpointExitDelayOverrides = {
|
|
@@ -14683,8 +14466,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14683
14466
|
setup.dustAmount,
|
|
14684
14467
|
setup.walletRepository,
|
|
14685
14468
|
setup.contractRepository,
|
|
14686
|
-
config.
|
|
14687
|
-
config.delegateProvider || config.delegatorProvider,
|
|
14469
|
+
config.delegateProvider,
|
|
14688
14470
|
config.watcherConfig,
|
|
14689
14471
|
config.settlementConfig,
|
|
14690
14472
|
setup.walletContractTimelocks,
|
|
@@ -14773,74 +14555,6 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14773
14555
|
async getDelegateManager() {
|
|
14774
14556
|
return this._delegateManager;
|
|
14775
14557
|
}
|
|
14776
|
-
/** @deprecated alias for @see Wallet.getDelegateManager */
|
|
14777
|
-
async getDelegatorManager() {
|
|
14778
|
-
return this.getDelegateManager();
|
|
14779
|
-
}
|
|
14780
|
-
/**
|
|
14781
|
-
* Send bitcoin to an Arkade address.
|
|
14782
|
-
*
|
|
14783
|
-
* @deprecated Use `send`.
|
|
14784
|
-
* @param params - Send parameters
|
|
14785
|
-
*/
|
|
14786
|
-
async sendBitcoin(params) {
|
|
14787
|
-
if (params.amount <= 0) {
|
|
14788
|
-
throw new Error("Amount must be positive");
|
|
14789
|
-
}
|
|
14790
|
-
if (!isValidArkAddress(params.address)) {
|
|
14791
|
-
throw new Error("Invalid Arkade address " + params.address);
|
|
14792
|
-
}
|
|
14793
|
-
if (params.selectedVtxos && params.selectedVtxos.length > 0) {
|
|
14794
|
-
void this.logUngatedInputs("sendBitcoin({ selectedVtxos })", params.selectedVtxos);
|
|
14795
|
-
return this._withTxLock(async () => {
|
|
14796
|
-
const offchainTapscript = this.offchainTapscript;
|
|
14797
|
-
const serverPubKey = this.arkServerPublicKey;
|
|
14798
|
-
const serverUnrollScript = this.serverUnrollScript;
|
|
14799
|
-
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
14800
|
-
const selectedVtxoSum = params.selectedVtxos.map((v) => v.value).reduce((a, b) => a + b, 0);
|
|
14801
|
-
if (selectedVtxoSum < params.amount) {
|
|
14802
|
-
throw new Error("Selected VTXOs do not cover specified amount");
|
|
14803
|
-
}
|
|
14804
|
-
const changeAmount = selectedVtxoSum - params.amount;
|
|
14805
|
-
const selected = {
|
|
14806
|
-
inputs: params.selectedVtxos,
|
|
14807
|
-
changeAmount: BigInt(changeAmount)
|
|
14808
|
-
};
|
|
14809
|
-
const outputAddress = chunkUJTYUYY4_cjs.ArkAddress.decode(params.address);
|
|
14810
|
-
assertRecipientArkadeAddress(
|
|
14811
|
-
params.address,
|
|
14812
|
-
outputAddress,
|
|
14813
|
-
this.recipientAddressContext(serverPubKey)
|
|
14814
|
-
);
|
|
14815
|
-
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
14816
|
-
const outputs = [
|
|
14817
|
-
{
|
|
14818
|
-
script: outputScript,
|
|
14819
|
-
amount: BigInt(params.amount)
|
|
14820
|
-
}
|
|
14821
|
-
];
|
|
14822
|
-
if (selected.changeAmount > 0n) {
|
|
14823
|
-
const changeOutputScript = selected.changeAmount < this.dustAmount ? arkAddress.subdustPkScript : arkAddress.pkScript;
|
|
14824
|
-
outputs.push({
|
|
14825
|
-
script: changeOutputScript,
|
|
14826
|
-
amount: BigInt(selected.changeAmount)
|
|
14827
|
-
});
|
|
14828
|
-
}
|
|
14829
|
-
return this._submitOffchainSpend(selected.inputs, outputs, {
|
|
14830
|
-
sentAmount: params.amount,
|
|
14831
|
-
changeAmount: selected.changeAmount,
|
|
14832
|
-
changeVout: selected.changeAmount > 0n ? outputs.length - 1 : 0,
|
|
14833
|
-
offchainTapscript,
|
|
14834
|
-
serverPubKey,
|
|
14835
|
-
serverUnrollScript
|
|
14836
|
-
});
|
|
14837
|
-
});
|
|
14838
|
-
}
|
|
14839
|
-
return this.send({
|
|
14840
|
-
address: params.address,
|
|
14841
|
-
amount: params.amount
|
|
14842
|
-
});
|
|
14843
|
-
}
|
|
14844
14558
|
/**
|
|
14845
14559
|
* Settle boarding inputs and/or virtual outputs into a finalized mainnet transaction.
|
|
14846
14560
|
*
|
|
@@ -14872,13 +14586,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14872
14586
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
14873
14587
|
}
|
|
14874
14588
|
const offchainAddress = await this.getAddress();
|
|
14875
|
-
const offchainPkScript =
|
|
14589
|
+
const offchainPkScript = chunkQWWOD7M2_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
14876
14590
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
14877
14591
|
if (!params) {
|
|
14878
14592
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
14879
14593
|
const estimator = new Estimator(fees.intentFee);
|
|
14880
14594
|
let amount = 0;
|
|
14881
|
-
const exitScript =
|
|
14595
|
+
const exitScript = chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(
|
|
14882
14596
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
14883
14597
|
);
|
|
14884
14598
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -14907,7 +14621,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14907
14621
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
14908
14622
|
break;
|
|
14909
14623
|
}
|
|
14910
|
-
const inputFee = estimator.evalOffchainInput(
|
|
14624
|
+
const inputFee = estimator.evalOffchainInput(chunkQWWOD7M2_cjs.toOffchainInputFeeParams(vtxo));
|
|
14911
14625
|
if (inputFee.satoshis >= vtxo.value) {
|
|
14912
14626
|
continue;
|
|
14913
14627
|
}
|
|
@@ -14954,7 +14668,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14954
14668
|
let script;
|
|
14955
14669
|
let arkAddress;
|
|
14956
14670
|
try {
|
|
14957
|
-
arkAddress =
|
|
14671
|
+
arkAddress = chunkQWWOD7M2_cjs.ArkAddress.decode(output.address);
|
|
14958
14672
|
} catch {
|
|
14959
14673
|
arkAddress = void 0;
|
|
14960
14674
|
}
|
|
@@ -15044,7 +14758,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15044
14758
|
const abortController = new AbortController();
|
|
15045
14759
|
let stream;
|
|
15046
14760
|
let committedTxid;
|
|
15047
|
-
const settleInputVtxos = params.inputs.filter(
|
|
14761
|
+
const settleInputVtxos = params.inputs.filter(chunkQWWOD7M2_cjs.isVirtualCoin);
|
|
15048
14762
|
const contractManager = await this.getContractManager();
|
|
15049
14763
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15050
14764
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15156,7 +14870,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15156
14870
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15157
14871
|
if (!this._descriptorProvider) return;
|
|
15158
14872
|
const consumedBoarding = inputs.some(
|
|
15159
|
-
(input) => typeof input !== "string" && !
|
|
14873
|
+
(input) => typeof input !== "string" && !chunkQWWOD7M2_cjs.isVirtualCoin(input)
|
|
15160
14874
|
);
|
|
15161
14875
|
if (!consumedBoarding) return;
|
|
15162
14876
|
try {
|
|
@@ -15180,7 +14894,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15180
14894
|
let connectorIndex = 0;
|
|
15181
14895
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15182
14896
|
for (const input of inputs) {
|
|
15183
|
-
if (!
|
|
14897
|
+
if (!chunkQWWOD7M2_cjs.isVirtualCoin(input)) {
|
|
15184
14898
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15185
14899
|
const settlementInput = settlementPsbt.getInput(i);
|
|
15186
14900
|
if (!settlementInput.txid || settlementInput.index === void 0) {
|
|
@@ -15211,7 +14925,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15211
14925
|
}
|
|
15212
14926
|
continue;
|
|
15213
14927
|
}
|
|
15214
|
-
if (
|
|
14928
|
+
if (chunkQWWOD7M2_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15215
14929
|
continue;
|
|
15216
14930
|
}
|
|
15217
14931
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15239,7 +14953,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15239
14953
|
index: input.vout,
|
|
15240
14954
|
witnessUtxo: {
|
|
15241
14955
|
amount: BigInt(input.value),
|
|
15242
|
-
script:
|
|
14956
|
+
script: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15243
14957
|
},
|
|
15244
14958
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15245
14959
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15258,7 +14972,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15258
14972
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15259
14973
|
{
|
|
15260
14974
|
index: 0,
|
|
15261
|
-
lookupScript:
|
|
14975
|
+
lookupScript: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15262
14976
|
}
|
|
15263
14977
|
]);
|
|
15264
14978
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15316,7 +15030,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15316
15030
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15317
15031
|
);
|
|
15318
15032
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15319
|
-
const sweepTapscript =
|
|
15033
|
+
const sweepTapscript = chunkQWWOD7M2_cjs.CSVMultisigTapscript.encode({
|
|
15320
15034
|
timelock,
|
|
15321
15035
|
pubkeys: [this.forfeitPubkey]
|
|
15322
15036
|
}).script;
|
|
@@ -15331,10 +15045,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15331
15045
|
throw new Error("Sweep tap tree root not set");
|
|
15332
15046
|
}
|
|
15333
15047
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15334
|
-
(k) => base.hex.encode(
|
|
15048
|
+
(k) => base.hex.encode(chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15335
15049
|
);
|
|
15336
15050
|
const signerPublicKey = await session.getPublicKey();
|
|
15337
|
-
const xonlySignerPublicKey =
|
|
15051
|
+
const xonlySignerPublicKey = chunkAEDYZK7T_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15338
15052
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15339
15053
|
return { skip: true };
|
|
15340
15054
|
}
|
|
@@ -15424,9 +15138,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15424
15138
|
...existing ?? {},
|
|
15425
15139
|
intentTxId,
|
|
15426
15140
|
registerProof: intent.proof,
|
|
15427
|
-
registerProofMessage:
|
|
15141
|
+
registerProofMessage: chunkQWWOD7M2_cjs.Intent.encodeMessage(intent.message),
|
|
15428
15142
|
deleteProof: deleteIntent.proof,
|
|
15429
|
-
deleteProofMessage:
|
|
15143
|
+
deleteProofMessage: chunkQWWOD7M2_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
15430
15144
|
intentVtxos: inputs.map((i) => ({
|
|
15431
15145
|
txid: i.txid,
|
|
15432
15146
|
vout: i.vout
|
|
@@ -15458,7 +15172,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15458
15172
|
try {
|
|
15459
15173
|
return await this.arkProvider.registerIntent(intent);
|
|
15460
15174
|
} catch (error) {
|
|
15461
|
-
if (error instanceof
|
|
15175
|
+
if (error instanceof chunkQWWOD7M2_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
15462
15176
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
15463
15177
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
15464
15178
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -15474,7 +15188,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15474
15188
|
expire_at: 0,
|
|
15475
15189
|
cosigners_public_keys: cosignerPubKeys
|
|
15476
15190
|
};
|
|
15477
|
-
const proof =
|
|
15191
|
+
const proof = chunkQWWOD7M2_cjs.Intent.create(message, coins, outputs);
|
|
15478
15192
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15479
15193
|
return {
|
|
15480
15194
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15486,7 +15200,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15486
15200
|
type: "delete",
|
|
15487
15201
|
expire_at: 0
|
|
15488
15202
|
};
|
|
15489
|
-
const proof =
|
|
15203
|
+
const proof = chunkQWWOD7M2_cjs.Intent.create(message, coins, []);
|
|
15490
15204
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15491
15205
|
return {
|
|
15492
15206
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15498,7 +15212,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15498
15212
|
type: "get-pending-tx",
|
|
15499
15213
|
expire_at: 0
|
|
15500
15214
|
};
|
|
15501
|
-
const proof =
|
|
15215
|
+
const proof = chunkQWWOD7M2_cjs.Intent.create(message, coins, []);
|
|
15502
15216
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
15503
15217
|
return {
|
|
15504
15218
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -15519,7 +15233,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15519
15233
|
if (!vtxos || vtxos.length === 0) {
|
|
15520
15234
|
const scriptMap = await this.getScriptMap();
|
|
15521
15235
|
const allExtended = [];
|
|
15522
|
-
const fetchedVtxos = await
|
|
15236
|
+
const fetchedVtxos = await chunkQWWOD7M2_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
15523
15237
|
...scriptMap.keys()
|
|
15524
15238
|
]);
|
|
15525
15239
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -15563,7 +15277,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15563
15277
|
try {
|
|
15564
15278
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
15565
15279
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
15566
|
-
|
|
15280
|
+
chunkQWWOD7M2_cjs.assertAllowedSighashTypes(tx);
|
|
15567
15281
|
return tx;
|
|
15568
15282
|
});
|
|
15569
15283
|
assertCheckpointsMatchInputs(
|
|
@@ -15635,11 +15349,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15635
15349
|
* against the current key alone would leave it pending forever.
|
|
15636
15350
|
*/
|
|
15637
15351
|
checkpointUnrollCandidates(info) {
|
|
15638
|
-
const current =
|
|
15352
|
+
const current = chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
15639
15353
|
const candidates = [this._serverUnrollScript, current];
|
|
15640
15354
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
15641
15355
|
candidates.push(
|
|
15642
|
-
|
|
15356
|
+
chunkQWWOD7M2_cjs.CSVMultisigTapscript.encode({
|
|
15643
15357
|
...current.params,
|
|
15644
15358
|
pubkeys: [base.hex.decode(deprecated)]
|
|
15645
15359
|
})
|
|
@@ -15730,7 +15444,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15730
15444
|
if (vtxos.length === 0) {
|
|
15731
15445
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
15732
15446
|
}
|
|
15733
|
-
const myPkScript =
|
|
15447
|
+
const myPkScript = chunkQWWOD7M2_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
15734
15448
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
15735
15449
|
let swept = 0;
|
|
15736
15450
|
const drainable = vtxos.filter(
|
|
@@ -15806,7 +15520,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15806
15520
|
const spendable = [];
|
|
15807
15521
|
const unclaimed = [];
|
|
15808
15522
|
for (const vtxo of vtxos) {
|
|
15809
|
-
if (
|
|
15523
|
+
if (chunkQWWOD7M2_cjs.hasTerminalSpend(vtxo)) {
|
|
15810
15524
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
15811
15525
|
} else if (vtxo.isUnrolled) {
|
|
15812
15526
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -15828,7 +15542,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15828
15542
|
const all = [];
|
|
15829
15543
|
const seen = /* @__PURE__ */ new Set();
|
|
15830
15544
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
15831
|
-
const { vtxos, page } = await
|
|
15545
|
+
const { vtxos, page } = await chunkQWWOD7M2_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
15832
15546
|
scripts,
|
|
15833
15547
|
pageIndex,
|
|
15834
15548
|
pageSize
|
|
@@ -15875,7 +15589,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15875
15589
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
15876
15590
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
15877
15591
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
15878
|
-
const proof =
|
|
15592
|
+
const proof = chunkQWWOD7M2_cjs.Intent.create(message, batch, []);
|
|
15879
15593
|
const signedProof = await identity.sign(
|
|
15880
15594
|
proof,
|
|
15881
15595
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -15897,7 +15611,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
15897
15611
|
try {
|
|
15898
15612
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
15899
15613
|
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
15900
|
-
|
|
15614
|
+
chunkQWWOD7M2_cjs.assertAllowedSighashTypes(tx);
|
|
15901
15615
|
return tx;
|
|
15902
15616
|
});
|
|
15903
15617
|
assertCheckpointsMatchInputs(
|
|
@@ -16096,7 +15810,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16096
15810
|
script: recipient.script,
|
|
16097
15811
|
amount: BigInt(recipient.amount),
|
|
16098
15812
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16099
|
-
...recipient.tapTree ? { tapTree:
|
|
15813
|
+
...recipient.tapTree ? { tapTree: chunkQWWOD7M2_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
|
|
16100
15814
|
}));
|
|
16101
15815
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16102
15816
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -16184,7 +15898,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16184
15898
|
}
|
|
16185
15899
|
/**
|
|
16186
15900
|
* Shared tail of every Ark-transaction spend path (`send`, selected-VTXO
|
|
16187
|
-
* `
|
|
15901
|
+
* `send`, and {@link sendSelectedVtxosToSelf}): hide the inputs from
|
|
16188
15902
|
* concurrent `getVtxos()`, build+submit the offchain tx, persist the spent
|
|
16189
15903
|
* inputs and any wallet-owned (change / self) output, then release the
|
|
16190
15904
|
* pending-spend hold. Callers own coin selection, output construction, and
|
|
@@ -16240,10 +15954,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16240
15954
|
const serverPubKey = this.arkServerPublicKey;
|
|
16241
15955
|
const serverUnrollScript = this.serverUnrollScript;
|
|
16242
15956
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
16243
|
-
const normalizedInputs = inputs.map(
|
|
16244
|
-
const at = now ?? await
|
|
15957
|
+
const normalizedInputs = inputs.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
15958
|
+
const at = now ?? await chunkQWWOD7M2_cjs.resolveTimeHeight(this.onchainProvider);
|
|
16245
15959
|
for (const input of normalizedInputs) {
|
|
16246
|
-
if (!
|
|
15960
|
+
if (!chunkQWWOD7M2_cjs.canSpendOffchain(input, at)) {
|
|
16247
15961
|
throw new Error(
|
|
16248
15962
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
16249
15963
|
);
|
|
@@ -16313,7 +16027,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16313
16027
|
);
|
|
16314
16028
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
16315
16029
|
index,
|
|
16316
|
-
lookupScript:
|
|
16030
|
+
lookupScript: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
16317
16031
|
}));
|
|
16318
16032
|
const identity = this.identity;
|
|
16319
16033
|
const signer = {
|
|
@@ -16399,14 +16113,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16399
16113
|
const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
|
|
16400
16114
|
spentVtxos.push({
|
|
16401
16115
|
...spentFacts,
|
|
16402
|
-
virtualStatus: chunkUJTYUYY4_cjs.toVirtualStatus(spentFacts),
|
|
16403
16116
|
...spentBy ? { spentBy } : {},
|
|
16404
16117
|
arkTxId: arkTxid
|
|
16405
16118
|
});
|
|
16406
16119
|
for (const id of vtxo.commitmentTxIds) {
|
|
16407
16120
|
commitmentTxIds.add(id);
|
|
16408
16121
|
}
|
|
16409
|
-
const vtxoExpiry =
|
|
16122
|
+
const vtxoExpiry = vtxo.expiresAt?.getTime();
|
|
16410
16123
|
if (vtxoExpiry) {
|
|
16411
16124
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
16412
16125
|
}
|
|
@@ -16419,7 +16132,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16419
16132
|
isSwept: false,
|
|
16420
16133
|
isPreconfirmed: true,
|
|
16421
16134
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
16422
|
-
|
|
16135
|
+
expiresAt: new Date(batchExpiry)
|
|
16423
16136
|
};
|
|
16424
16137
|
changeVtxo = {
|
|
16425
16138
|
txid: arkTxid,
|
|
@@ -16431,7 +16144,6 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16431
16144
|
tapTree: offchainTapscript.encode(),
|
|
16432
16145
|
value: Number(changeAmount),
|
|
16433
16146
|
...changeFacts,
|
|
16434
|
-
virtualStatus: chunkUJTYUYY4_cjs.toVirtualStatus(changeFacts),
|
|
16435
16147
|
spentBy: "",
|
|
16436
16148
|
status: {
|
|
16437
16149
|
confirmed: false
|
|
@@ -16500,12 +16212,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16500
16212
|
const spentVtxos = [];
|
|
16501
16213
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
16502
16214
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
16503
|
-
const vtxoInputs = inputs.filter(
|
|
16215
|
+
const vtxoInputs = inputs.filter(chunkQWWOD7M2_cjs.isVirtualCoin);
|
|
16504
16216
|
const cm = await this.getContractManager();
|
|
16505
16217
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
16506
16218
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
16507
16219
|
for (const input of inputs) {
|
|
16508
|
-
if (
|
|
16220
|
+
if (chunkQWWOD7M2_cjs.isVirtualCoin(input)) {
|
|
16509
16221
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
16510
16222
|
const vtxo = annotatedByKey.get(outpoint);
|
|
16511
16223
|
if (!vtxo) {
|
|
@@ -16517,13 +16229,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16517
16229
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
16518
16230
|
spentVtxos.push({
|
|
16519
16231
|
...settledFacts,
|
|
16520
|
-
virtualStatus: chunkUJTYUYY4_cjs.toVirtualStatus(settledFacts),
|
|
16521
16232
|
settledBy: commitmentTxid
|
|
16522
16233
|
});
|
|
16523
16234
|
} else {
|
|
16524
16235
|
let sourceAddress;
|
|
16525
16236
|
try {
|
|
16526
|
-
sourceAddress =
|
|
16237
|
+
sourceAddress = chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
16527
16238
|
this.network
|
|
16528
16239
|
);
|
|
16529
16240
|
} catch {
|
|
@@ -16581,9 +16292,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
16581
16292
|
}
|
|
16582
16293
|
};
|
|
16583
16294
|
function selectVirtualCoins(coins, targetAmount) {
|
|
16584
|
-
const sortedCoins = coins.map(
|
|
16585
|
-
const expiryA =
|
|
16586
|
-
const expiryB =
|
|
16295
|
+
const sortedCoins = coins.map(chunkQWWOD7M2_cjs.normalizeVtxo).sort((a, b) => {
|
|
16296
|
+
const expiryA = a.expiresAt?.getTime() || Number.MAX_SAFE_INTEGER;
|
|
16297
|
+
const expiryB = b.expiresAt?.getTime() || Number.MAX_SAFE_INTEGER;
|
|
16587
16298
|
if (expiryA !== expiryB) {
|
|
16588
16299
|
return expiryA - expiryB;
|
|
16589
16300
|
}
|
|
@@ -16952,22 +16663,22 @@ var MessageBus = class {
|
|
|
16952
16663
|
this.initialized = true;
|
|
16953
16664
|
}
|
|
16954
16665
|
async buildServices(config) {
|
|
16955
|
-
const arkProvider = new
|
|
16666
|
+
const arkProvider = new chunkQWWOD7M2_cjs.RestArkProvider(config.arkServer.url);
|
|
16956
16667
|
const storage = {
|
|
16957
16668
|
walletRepository: this.walletRepository,
|
|
16958
16669
|
contractRepository: this.contractRepository,
|
|
16959
16670
|
...this.intentRepository && { intentRepository: this.intentRepository }
|
|
16960
16671
|
};
|
|
16961
|
-
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) :
|
|
16672
|
+
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : void 0;
|
|
16673
|
+
const indexerProvider = new chunkNEVMOIQL_cjs.RestIndexerProvider(config.arkServer.url);
|
|
16962
16674
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
16963
16675
|
if (isSigningSerialized(serialized)) {
|
|
16964
16676
|
const identity2 = hydrateIdentity(serialized);
|
|
16965
16677
|
const wallet = await Wallet2.create({
|
|
16966
16678
|
identity: identity2,
|
|
16967
|
-
|
|
16679
|
+
arkProvider,
|
|
16968
16680
|
arkServerPublicKey: config.arkServer.publicKey,
|
|
16969
|
-
|
|
16970
|
-
esploraUrl: config.esploraUrl,
|
|
16681
|
+
indexerProvider,
|
|
16971
16682
|
storage,
|
|
16972
16683
|
delegateProvider,
|
|
16973
16684
|
settlementConfig: config.settlementConfig,
|
|
@@ -16982,10 +16693,9 @@ var MessageBus = class {
|
|
|
16982
16693
|
const identity = hydrateIdentity(serialized);
|
|
16983
16694
|
const readonlyWallet = await ReadonlyWallet.create({
|
|
16984
16695
|
identity,
|
|
16985
|
-
|
|
16696
|
+
arkProvider,
|
|
16986
16697
|
arkServerPublicKey: config.arkServer.publicKey,
|
|
16987
|
-
|
|
16988
|
-
esploraUrl: config.esploraUrl,
|
|
16698
|
+
indexerProvider,
|
|
16989
16699
|
storage,
|
|
16990
16700
|
delegateProvider,
|
|
16991
16701
|
watcherConfig: config.watcherConfig
|
|
@@ -17297,7 +17007,7 @@ var offboardNetworkNames = [
|
|
|
17297
17007
|
function offboardDestinationScript(destinationAddress) {
|
|
17298
17008
|
for (const networkName of offboardNetworkNames) {
|
|
17299
17009
|
try {
|
|
17300
|
-
const network =
|
|
17010
|
+
const network = chunkQWWOD7M2_cjs.networks[networkName];
|
|
17301
17011
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
17302
17012
|
return btcSigner.OutScript.encode(addr);
|
|
17303
17013
|
} catch {
|
|
@@ -17361,7 +17071,7 @@ var Ramps = class {
|
|
|
17361
17071
|
}
|
|
17362
17072
|
amount = amount ?? totalAmount;
|
|
17363
17073
|
const offchainAddress = await this.wallet.getAddress();
|
|
17364
|
-
const offchainAddr =
|
|
17074
|
+
const offchainAddr = chunkQWWOD7M2_cjs.ArkAddress.decode(offchainAddress);
|
|
17365
17075
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
17366
17076
|
const outputFee = estimator.evalOffchainOutput({
|
|
17367
17077
|
amount,
|
|
@@ -17421,7 +17131,7 @@ var Ramps = class {
|
|
|
17421
17131
|
const filteredVtxos = [];
|
|
17422
17132
|
let totalAmount = 0n;
|
|
17423
17133
|
for (const vtxo of vtxos) {
|
|
17424
|
-
const inputFee = estimator.evalOffchainInput(
|
|
17134
|
+
const inputFee = estimator.evalOffchainInput(chunkQWWOD7M2_cjs.toOffchainInputFeeParams(vtxo));
|
|
17425
17135
|
if (inputFee.satoshis >= vtxo.value) {
|
|
17426
17136
|
continue;
|
|
17427
17137
|
}
|
|
@@ -17524,8 +17234,10 @@ var DelegateNotConfiguredError = class extends Error {
|
|
|
17524
17234
|
this.name = "DelegateNotConfiguredError";
|
|
17525
17235
|
}
|
|
17526
17236
|
};
|
|
17527
|
-
var DelegatorNotConfiguredError = DelegateNotConfiguredError;
|
|
17528
17237
|
var DEFAULT_MESSAGE_TAG = "WALLET_UPDATER";
|
|
17238
|
+
function unsupportedByManager(method) {
|
|
17239
|
+
return new Error(`Contract manager does not support ${method}`);
|
|
17240
|
+
}
|
|
17529
17241
|
var serializeMigrationVtxoRef = (ref) => ({
|
|
17530
17242
|
txid: ref.txid,
|
|
17531
17243
|
vout: ref.vout,
|
|
@@ -17771,13 +17483,6 @@ var WalletMessageHandler = class {
|
|
|
17771
17483
|
...response
|
|
17772
17484
|
});
|
|
17773
17485
|
}
|
|
17774
|
-
case "SEND_BITCOIN": {
|
|
17775
|
-
const response = await this.handleSendBitcoin(message);
|
|
17776
|
-
return this.tagged({
|
|
17777
|
-
id,
|
|
17778
|
-
...response
|
|
17779
|
-
});
|
|
17780
|
-
}
|
|
17781
17486
|
case "GET_ADDRESS": {
|
|
17782
17487
|
const address = await this.readonlyWallet.getAddress();
|
|
17783
17488
|
return this.tagged({
|
|
@@ -17953,6 +17658,39 @@ var WalletMessageHandler = class {
|
|
|
17953
17658
|
payload: { contracts }
|
|
17954
17659
|
});
|
|
17955
17660
|
}
|
|
17661
|
+
case "WATCH_SCRIPT": {
|
|
17662
|
+
const manager = await this.readonlyWallet.getContractManager();
|
|
17663
|
+
if (!manager.watchScript) throw unsupportedByManager("watchScript");
|
|
17664
|
+
await manager.watchScript(message.payload.script, {
|
|
17665
|
+
label: message.payload.label
|
|
17666
|
+
});
|
|
17667
|
+
return this.tagged({
|
|
17668
|
+
id,
|
|
17669
|
+
type: "SCRIPT_WATCHED",
|
|
17670
|
+
payload: { script: message.payload.script }
|
|
17671
|
+
});
|
|
17672
|
+
}
|
|
17673
|
+
case "UNWATCH_SCRIPT": {
|
|
17674
|
+
const manager = await this.readonlyWallet.getContractManager();
|
|
17675
|
+
if (!manager.unwatchScript) throw unsupportedByManager("unwatchScript");
|
|
17676
|
+
await manager.unwatchScript(message.payload.script);
|
|
17677
|
+
return this.tagged({
|
|
17678
|
+
id,
|
|
17679
|
+
type: "SCRIPT_UNWATCHED",
|
|
17680
|
+
payload: { script: message.payload.script }
|
|
17681
|
+
});
|
|
17682
|
+
}
|
|
17683
|
+
case "GET_WATCHED_SCRIPTS": {
|
|
17684
|
+
const manager = await this.readonlyWallet.getContractManager();
|
|
17685
|
+
if (!manager.getWatchedScripts) {
|
|
17686
|
+
throw unsupportedByManager("getWatchedScripts");
|
|
17687
|
+
}
|
|
17688
|
+
return this.tagged({
|
|
17689
|
+
id,
|
|
17690
|
+
type: "WATCHED_SCRIPTS",
|
|
17691
|
+
payload: { scripts: await manager.getWatchedScripts() }
|
|
17692
|
+
});
|
|
17693
|
+
}
|
|
17956
17694
|
case "ANNOTATE_VTXOS": {
|
|
17957
17695
|
const manager = await this.readonlyWallet.getContractManager();
|
|
17958
17696
|
const annotated = await manager.annotateVtxos(message.payload.vtxos);
|
|
@@ -18097,8 +17835,9 @@ var WalletMessageHandler = class {
|
|
|
18097
17835
|
});
|
|
18098
17836
|
}
|
|
18099
17837
|
case "SEND": {
|
|
17838
|
+
const wallet = this.requireWallet();
|
|
18100
17839
|
const { recipients, selectedVtxos } = message.payload;
|
|
18101
|
-
const txid = await (selectedVtxos ?
|
|
17840
|
+
const txid = await (selectedVtxos ? wallet.send({ recipients, selectedVtxos }) : wallet.send(...recipients));
|
|
18102
17841
|
return this.tagged({
|
|
18103
17842
|
id,
|
|
18104
17843
|
type: "SEND_SUCCESS",
|
|
@@ -18116,7 +17855,7 @@ var WalletMessageHandler = class {
|
|
|
18116
17855
|
}
|
|
18117
17856
|
case "ISSUE": {
|
|
18118
17857
|
const { params } = message.payload;
|
|
18119
|
-
const result = await this.
|
|
17858
|
+
const result = await this.requireWallet().assetManager.issue(params);
|
|
18120
17859
|
return this.tagged({
|
|
18121
17860
|
id,
|
|
18122
17861
|
type: "ISSUE_SUCCESS",
|
|
@@ -18125,7 +17864,7 @@ var WalletMessageHandler = class {
|
|
|
18125
17864
|
}
|
|
18126
17865
|
case "REISSUE": {
|
|
18127
17866
|
const { params } = message.payload;
|
|
18128
|
-
const txid = await this.
|
|
17867
|
+
const txid = await this.requireWallet().assetManager.reissue(params);
|
|
18129
17868
|
return this.tagged({
|
|
18130
17869
|
id,
|
|
18131
17870
|
type: "REISSUE_SUCCESS",
|
|
@@ -18134,7 +17873,7 @@ var WalletMessageHandler = class {
|
|
|
18134
17873
|
}
|
|
18135
17874
|
case "BURN": {
|
|
18136
17875
|
const { params } = message.payload;
|
|
18137
|
-
const txid = await this.
|
|
17876
|
+
const txid = await this.requireWallet().assetManager.burn(params);
|
|
18138
17877
|
return this.tagged({
|
|
18139
17878
|
id,
|
|
18140
17879
|
type: "BURN_SUCCESS",
|
|
@@ -18300,7 +18039,7 @@ var WalletMessageHandler = class {
|
|
|
18300
18039
|
// Wallet methods
|
|
18301
18040
|
async handleInitWallet({ payload }) {
|
|
18302
18041
|
const { arkServerUrl } = payload;
|
|
18303
|
-
this.indexerProvider = new
|
|
18042
|
+
this.indexerProvider = new chunkNEVMOIQL_cjs.RestIndexerProvider(arkServerUrl);
|
|
18304
18043
|
await this.onWalletInitialized();
|
|
18305
18044
|
}
|
|
18306
18045
|
/**
|
|
@@ -18517,17 +18256,6 @@ var WalletMessageHandler = class {
|
|
|
18517
18256
|
}
|
|
18518
18257
|
return { type: "SETTLE_SUCCESS", payload: { txid } };
|
|
18519
18258
|
}
|
|
18520
|
-
async handleSendBitcoin(message) {
|
|
18521
|
-
const wallet = this.requireWallet();
|
|
18522
|
-
const txid = await wallet.sendBitcoin(message.payload);
|
|
18523
|
-
if (!txid) {
|
|
18524
|
-
throw new Error("Send bitcoin failed");
|
|
18525
|
-
}
|
|
18526
|
-
return {
|
|
18527
|
-
type: "SEND_BITCOIN_SUCCESS",
|
|
18528
|
-
payload: { txid }
|
|
18529
|
-
};
|
|
18530
|
-
}
|
|
18531
18259
|
async handleSignTransaction(message) {
|
|
18532
18260
|
const wallet = this.requireWallet();
|
|
18533
18261
|
const { tx, inputIndexes } = message.payload;
|
|
@@ -18589,7 +18317,7 @@ var WalletMessageHandler = class {
|
|
|
18589
18317
|
if (v.isUnrolled) {
|
|
18590
18318
|
return withUnrolled;
|
|
18591
18319
|
}
|
|
18592
|
-
if (
|
|
18320
|
+
if (chunkQWWOD7M2_cjs.hasTerminalSpend(v)) {
|
|
18593
18321
|
return false;
|
|
18594
18322
|
}
|
|
18595
18323
|
if (includeRecoverable) {
|
|
@@ -18598,13 +18326,7 @@ var WalletMessageHandler = class {
|
|
|
18598
18326
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
18599
18327
|
return false;
|
|
18600
18328
|
}
|
|
18601
|
-
|
|
18602
|
-
return false;
|
|
18603
|
-
}
|
|
18604
|
-
if (chunkUJTYUYY4_cjs.isExpired(v)) {
|
|
18605
|
-
return false;
|
|
18606
|
-
}
|
|
18607
|
-
return true;
|
|
18329
|
+
return chunkQWWOD7M2_cjs.canSpendOffchain(v, { timestamp: /* @__PURE__ */ new Date() });
|
|
18608
18330
|
});
|
|
18609
18331
|
}
|
|
18610
18332
|
/** Tear down handler subscriptions, then delegate the full wipe to the wallet. */
|
|
@@ -18699,7 +18421,7 @@ var WalletMessageHandler = class {
|
|
|
18699
18421
|
if (!this.readonlyWallet) return null;
|
|
18700
18422
|
const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
|
|
18701
18423
|
const indexerProvider = this.indexerProvider;
|
|
18702
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
18424
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkQWWOD7M2_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
18703
18425
|
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, resolveTxCreatedAt);
|
|
18704
18426
|
}
|
|
18705
18427
|
async ensureContractEventBroadcasting() {
|
|
@@ -18762,7 +18484,7 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18762
18484
|
// budget so the worker's snapshot fallback stays reachable before this
|
|
18763
18485
|
// page deadline fires — lowering it below the budget would time the page
|
|
18764
18486
|
// out while the worker is still seconds from answering from cache.
|
|
18765
|
-
GET_ARKADE_INFO:
|
|
18487
|
+
GET_ARKADE_INFO: chunkQWWOD7M2_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
18766
18488
|
INDEXER_GET_VTXOS: 2e4,
|
|
18767
18489
|
INDEXER_GET_VIRTUAL_TXS: 2e4,
|
|
18768
18490
|
GET_VTXOS: 2e4,
|
|
@@ -18771,6 +18493,7 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18771
18493
|
GET_TRANSACTION_HISTORY: 2e4,
|
|
18772
18494
|
GET_CONTRACTS: 2e4,
|
|
18773
18495
|
GET_CONTRACTS_WITH_VTXOS: 2e4,
|
|
18496
|
+
GET_WATCHED_SCRIPTS: 1e4,
|
|
18774
18497
|
ANNOTATE_VTXOS: 2e4,
|
|
18775
18498
|
GET_SPENDABLE_PATHS: 2e4,
|
|
18776
18499
|
GET_ALL_SPENDING_PATHS: 2e4,
|
|
@@ -18784,7 +18507,6 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18784
18507
|
// SETTLE / RECOVER_VTXOS / RENEW_VTXOS go through the streaming path and
|
|
18785
18508
|
// are treated as long-running on both sides of the bus: the values below
|
|
18786
18509
|
// are retained only for type completeness and are never enforced.
|
|
18787
|
-
SEND_BITCOIN: 5e4,
|
|
18788
18510
|
SEND: 5e4,
|
|
18789
18511
|
SETTLE: 5e4,
|
|
18790
18512
|
// Broadcast: the server round-trip a spend ends in, so it belongs
|
|
@@ -18811,6 +18533,10 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
18811
18533
|
SIGN_TRANSACTION: 3e4,
|
|
18812
18534
|
CREATE_CONTRACT: 3e4,
|
|
18813
18535
|
UPDATE_CONTRACT: 3e4,
|
|
18536
|
+
// Registering a watch is an in-memory map write plus one subscription
|
|
18537
|
+
// update — no indexer round trip on the request path.
|
|
18538
|
+
WATCH_SCRIPT: 1e4,
|
|
18539
|
+
UNWATCH_SCRIPT: 1e4,
|
|
18814
18540
|
DELETE_CONTRACT: 1e4,
|
|
18815
18541
|
REFRESH_VTXOS: 3e4,
|
|
18816
18542
|
REFRESH_OUTPOINTS: 3e4
|
|
@@ -18834,6 +18560,7 @@ var DEDUPABLE_REQUEST_TYPES = /* @__PURE__ */ new Set([
|
|
|
18834
18560
|
"GET_SPENDABLE_VTXOS",
|
|
18835
18561
|
"GET_CONTRACTS",
|
|
18836
18562
|
"GET_CONTRACTS_WITH_VTXOS",
|
|
18563
|
+
"GET_WATCHED_SCRIPTS",
|
|
18837
18564
|
"ANNOTATE_VTXOS",
|
|
18838
18565
|
"GET_SPENDABLE_PATHS",
|
|
18839
18566
|
"GET_ALL_SPENDING_PATHS",
|
|
@@ -18950,13 +18677,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18950
18677
|
// Denormalized from options so buildInitConfig() can rebuild the init
|
|
18951
18678
|
// envelope on demand for SDK-factory-created wallets. `create()` sets
|
|
18952
18679
|
// these immediately after construction.
|
|
18953
|
-
|
|
18954
|
-
arkServerPublicKey;
|
|
18680
|
+
arkServer;
|
|
18955
18681
|
delegateUrl;
|
|
18956
|
-
/** @deprecated alias for @see ServiceWorkerReadonlyWallet.delegateUrl */
|
|
18957
|
-
delegatorUrl;
|
|
18958
|
-
indexerUrl;
|
|
18959
|
-
esploraUrl;
|
|
18960
18682
|
watcherConfig;
|
|
18961
18683
|
settlementConfig;
|
|
18962
18684
|
reinitPromise = null;
|
|
@@ -18987,16 +18709,10 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
18987
18709
|
messageTag
|
|
18988
18710
|
);
|
|
18989
18711
|
const serializedWallet = await serializeReadonlyIdentity(options.identity);
|
|
18990
|
-
const
|
|
18712
|
+
const arkServer = options.arkServer ?? { url: "https://arkade.computer" };
|
|
18991
18713
|
const initWalletPayload = {
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
arkServerPublicKey: options.arkServerPublicKey,
|
|
18995
|
-
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
18996
|
-
// Keep the deprecated field populated so pre-#519 service workers
|
|
18997
|
-
// (which only read delegatorUrl) keep delegating until they activate
|
|
18998
|
-
// a newer version.
|
|
18999
|
-
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
18714
|
+
arkServerUrl: arkServer.url,
|
|
18715
|
+
arkServerPublicKey: arkServer.publicKey
|
|
19000
18716
|
};
|
|
19001
18717
|
const messageTimeouts = options.messageTimeouts ? {
|
|
19002
18718
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -19004,17 +18720,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19004
18720
|
} : DEFAULT_MESSAGE_TIMEOUTS;
|
|
19005
18721
|
const busInitConfig = {
|
|
19006
18722
|
wallet: serializedWallet,
|
|
19007
|
-
arkServer
|
|
19008
|
-
|
|
19009
|
-
publicKey: options.arkServerPublicKey
|
|
19010
|
-
},
|
|
19011
|
-
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
19012
|
-
// Keep the deprecated field populated so pre-#519 service workers
|
|
19013
|
-
// (which only read delegatorUrl) keep delegating until they activate
|
|
19014
|
-
// a newer version.
|
|
19015
|
-
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
19016
|
-
indexerUrl: options.indexerUrl,
|
|
19017
|
-
esploraUrl: options.esploraUrl,
|
|
18723
|
+
arkServer,
|
|
18724
|
+
delegateUrl: options.delegateUrl,
|
|
19018
18725
|
watcherConfig: options.watcherConfig,
|
|
19019
18726
|
messageTimeouts
|
|
19020
18727
|
};
|
|
@@ -19047,7 +18754,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19047
18754
|
* ```typescript
|
|
19048
18755
|
* const wallet = await ServiceWorkerReadonlyWallet.setup({
|
|
19049
18756
|
* serviceWorkerPath: '/service-worker.js',
|
|
19050
|
-
*
|
|
18757
|
+
* arkServer: { url: 'https://arkade.computer' },
|
|
19051
18758
|
* identity: ReadonlySingleKey.fromPublicKey('your_public_key_hex')
|
|
19052
18759
|
* });
|
|
19053
18760
|
* ```
|
|
@@ -19216,23 +18923,14 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19216
18923
|
*/
|
|
19217
18924
|
async buildInitConfig() {
|
|
19218
18925
|
if (this.initConfig) return this.initConfig;
|
|
19219
|
-
if (!this.
|
|
18926
|
+
if (!this.arkServer) {
|
|
19220
18927
|
throw new Error("Cannot re-initialize: wallet was not initialized via the SDK factory");
|
|
19221
18928
|
}
|
|
19222
18929
|
const wallet = await this.serializeIdentity();
|
|
19223
18930
|
this.initConfig = {
|
|
19224
18931
|
wallet,
|
|
19225
|
-
arkServer:
|
|
19226
|
-
|
|
19227
|
-
publicKey: this.arkServerPublicKey
|
|
19228
|
-
},
|
|
19229
|
-
delegateUrl: this.delegateUrl || this.delegatorUrl,
|
|
19230
|
-
// Keep the deprecated field populated so pre-#519 service workers
|
|
19231
|
-
// (which only read delegatorUrl) keep delegating until they activate
|
|
19232
|
-
// a newer version.
|
|
19233
|
-
delegatorUrl: this.delegateUrl || this.delegatorUrl,
|
|
19234
|
-
indexerUrl: this.indexerUrl,
|
|
19235
|
-
esploraUrl: this.esploraUrl,
|
|
18932
|
+
arkServer: this.arkServer,
|
|
18933
|
+
delegateUrl: this.delegateUrl,
|
|
19236
18934
|
watcherConfig: this.watcherConfig,
|
|
19237
18935
|
settlementConfig: this.settlementConfig
|
|
19238
18936
|
};
|
|
@@ -19241,14 +18939,12 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19241
18939
|
/** Minimal INIT_WALLET payload used on reinitialize when the cache is gone. */
|
|
19242
18940
|
buildInitWalletPayload() {
|
|
19243
18941
|
if (this.initWalletPayload) return this.initWalletPayload;
|
|
19244
|
-
if (!this.
|
|
18942
|
+
if (!this.arkServer) {
|
|
19245
18943
|
throw new Error("Cannot re-initialize: wallet was not initialized via the SDK factory");
|
|
19246
18944
|
}
|
|
19247
18945
|
this.initWalletPayload = {
|
|
19248
|
-
|
|
19249
|
-
|
|
19250
|
-
arkServerUrl: this.arkServerUrl,
|
|
19251
|
-
arkServerPublicKey: this.arkServerPublicKey
|
|
18946
|
+
arkServerUrl: this.arkServer.url,
|
|
18947
|
+
arkServerPublicKey: this.arkServer.publicKey
|
|
19252
18948
|
};
|
|
19253
18949
|
return this.initWalletPayload;
|
|
19254
18950
|
}
|
|
@@ -19375,7 +19071,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19375
19071
|
try {
|
|
19376
19072
|
const response = await this.sendMessage(message);
|
|
19377
19073
|
const { vtxos, page } = response.payload;
|
|
19378
|
-
return { vtxos: vtxos.map(
|
|
19074
|
+
return { vtxos: vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo), page: page && { ...page } };
|
|
19379
19075
|
} catch (error) {
|
|
19380
19076
|
throw new Error(`Failed to get vtxos: ${error}`, { cause: error });
|
|
19381
19077
|
}
|
|
@@ -19479,7 +19175,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19479
19175
|
};
|
|
19480
19176
|
try {
|
|
19481
19177
|
const response = await this.sendMessage(message);
|
|
19482
|
-
return response.payload.vtxos.map(
|
|
19178
|
+
return response.payload.vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
19483
19179
|
} catch (error) {
|
|
19484
19180
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
19485
19181
|
}
|
|
@@ -19504,7 +19200,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19504
19200
|
};
|
|
19505
19201
|
try {
|
|
19506
19202
|
const response = await this.sendMessage(message);
|
|
19507
|
-
return response.payload.vtxos.map(
|
|
19203
|
+
return response.payload.vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
19508
19204
|
} catch (error) {
|
|
19509
19205
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
19510
19206
|
}
|
|
@@ -19604,6 +19300,46 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19604
19300
|
throw new Error("Failed to get contracts with vtxos");
|
|
19605
19301
|
}
|
|
19606
19302
|
},
|
|
19303
|
+
async watchScript(script, options) {
|
|
19304
|
+
const message = {
|
|
19305
|
+
type: "WATCH_SCRIPT",
|
|
19306
|
+
id: getRandomId(),
|
|
19307
|
+
tag: messageTag,
|
|
19308
|
+
payload: { script, label: options?.label }
|
|
19309
|
+
};
|
|
19310
|
+
try {
|
|
19311
|
+
await sendContractMessage(message);
|
|
19312
|
+
} catch (e) {
|
|
19313
|
+
throw new Error("Failed to watch script");
|
|
19314
|
+
}
|
|
19315
|
+
},
|
|
19316
|
+
async unwatchScript(script) {
|
|
19317
|
+
const message = {
|
|
19318
|
+
type: "UNWATCH_SCRIPT",
|
|
19319
|
+
id: getRandomId(),
|
|
19320
|
+
tag: messageTag,
|
|
19321
|
+
payload: { script }
|
|
19322
|
+
};
|
|
19323
|
+
try {
|
|
19324
|
+
await sendContractMessage(message);
|
|
19325
|
+
} catch (e) {
|
|
19326
|
+
throw new Error("Failed to unwatch script");
|
|
19327
|
+
}
|
|
19328
|
+
},
|
|
19329
|
+
async getWatchedScripts() {
|
|
19330
|
+
const message = {
|
|
19331
|
+
type: "GET_WATCHED_SCRIPTS",
|
|
19332
|
+
id: getRandomId(),
|
|
19333
|
+
tag: messageTag,
|
|
19334
|
+
payload: {}
|
|
19335
|
+
};
|
|
19336
|
+
try {
|
|
19337
|
+
const response = await sendContractMessage(message);
|
|
19338
|
+
return response.payload.scripts;
|
|
19339
|
+
} catch (e) {
|
|
19340
|
+
throw new Error("Failed to get watched scripts");
|
|
19341
|
+
}
|
|
19342
|
+
},
|
|
19607
19343
|
getSyncState() {
|
|
19608
19344
|
return syncState;
|
|
19609
19345
|
},
|
|
@@ -19635,7 +19371,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
19635
19371
|
};
|
|
19636
19372
|
try {
|
|
19637
19373
|
const response = await sendContractMessage(message);
|
|
19638
|
-
return response.payload.vtxos.map(
|
|
19374
|
+
return response.payload.vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
19639
19375
|
} catch (e) {
|
|
19640
19376
|
throw new Error("Failed to annotate vtxos");
|
|
19641
19377
|
}
|
|
@@ -19862,18 +19598,12 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
19862
19598
|
walletRepository,
|
|
19863
19599
|
contractRepository,
|
|
19864
19600
|
messageTag,
|
|
19865
|
-
!!
|
|
19601
|
+
!!options.delegateUrl
|
|
19866
19602
|
);
|
|
19867
|
-
const
|
|
19603
|
+
const arkServer = options.arkServer ?? { url: "https://arkade.computer" };
|
|
19868
19604
|
const initWalletPayload = {
|
|
19869
|
-
|
|
19870
|
-
|
|
19871
|
-
arkServerPublicKey: options.arkServerPublicKey,
|
|
19872
|
-
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
19873
|
-
// Keep the deprecated field populated so pre-#519 service workers
|
|
19874
|
-
// (which only read delegatorUrl) keep delegating until they activate
|
|
19875
|
-
// a newer version.
|
|
19876
|
-
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
19605
|
+
arkServerUrl: arkServer.url,
|
|
19606
|
+
arkServerPublicKey: arkServer.publicKey
|
|
19877
19607
|
};
|
|
19878
19608
|
const messageTimeouts = options.messageTimeouts ? {
|
|
19879
19609
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -19881,17 +19611,8 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
19881
19611
|
} : DEFAULT_MESSAGE_TIMEOUTS;
|
|
19882
19612
|
const busInitConfig = {
|
|
19883
19613
|
wallet: serializedWallet,
|
|
19884
|
-
arkServer
|
|
19885
|
-
|
|
19886
|
-
publicKey: options.arkServerPublicKey
|
|
19887
|
-
},
|
|
19888
|
-
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
19889
|
-
// Keep the deprecated field populated so pre-#519 service workers
|
|
19890
|
-
// (which only read delegatorUrl) keep delegating until they activate
|
|
19891
|
-
// a newer version.
|
|
19892
|
-
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
19893
|
-
indexerUrl: options.indexerUrl,
|
|
19894
|
-
esploraUrl: options.esploraUrl,
|
|
19614
|
+
arkServer,
|
|
19615
|
+
delegateUrl: options.delegateUrl,
|
|
19895
19616
|
settlementConfig: options.settlementConfig,
|
|
19896
19617
|
walletMode: options.walletMode,
|
|
19897
19618
|
watcherConfig: options.watcherConfig,
|
|
@@ -19927,7 +19648,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
19927
19648
|
* ```typescript
|
|
19928
19649
|
* const wallet = await ServiceWorkerWallet.setup({
|
|
19929
19650
|
* serviceWorkerPath: '/service-worker.js',
|
|
19930
|
-
*
|
|
19651
|
+
* arkServer: { url: 'https://arkade.computer' },
|
|
19931
19652
|
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...')
|
|
19932
19653
|
* });
|
|
19933
19654
|
* ```
|
|
@@ -20090,20 +19811,6 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20090
19811
|
}
|
|
20091
19812
|
};
|
|
20092
19813
|
}
|
|
20093
|
-
async sendBitcoin(params) {
|
|
20094
|
-
const message = {
|
|
20095
|
-
id: getRandomId(),
|
|
20096
|
-
tag: this.messageTag,
|
|
20097
|
-
type: "SEND_BITCOIN",
|
|
20098
|
-
payload: params
|
|
20099
|
-
};
|
|
20100
|
-
try {
|
|
20101
|
-
const response = await this.sendMessage(message);
|
|
20102
|
-
return response.payload.txid;
|
|
20103
|
-
} catch (error) {
|
|
20104
|
-
throw new Error(`Failed to send bitcoin: ${error}`);
|
|
20105
|
-
}
|
|
20106
|
-
}
|
|
20107
19814
|
async settle(params, callback) {
|
|
20108
19815
|
const message = {
|
|
20109
19816
|
id: getRandomId(),
|
|
@@ -20221,10 +19928,6 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20221
19928
|
};
|
|
20222
19929
|
return manager;
|
|
20223
19930
|
}
|
|
20224
|
-
/** @deprecated alias for @see ServiceWorkerWallet.getDelegateManager */
|
|
20225
|
-
async getDelegatorManager() {
|
|
20226
|
-
return await this.getDelegateManager();
|
|
20227
|
-
}
|
|
20228
19931
|
async getVtxoManager() {
|
|
20229
19932
|
const wallet = this;
|
|
20230
19933
|
const messageTag = this.messageTag;
|
|
@@ -20273,7 +19976,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
20273
19976
|
};
|
|
20274
19977
|
try {
|
|
20275
19978
|
const response = await wallet.sendMessage(message);
|
|
20276
|
-
return response.payload.vtxos.map(
|
|
19979
|
+
return response.payload.vtxos.map(chunkQWWOD7M2_cjs.normalizeVtxo);
|
|
20277
19980
|
} catch (e) {
|
|
20278
19981
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
20279
19982
|
}
|
|
@@ -20385,12 +20088,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20385
20088
|
* @returns Configured onchain wallet
|
|
20386
20089
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
20387
20090
|
*/
|
|
20388
|
-
static async create(identity, networkName =
|
|
20091
|
+
static async create(identity, networkName = chunkQWWOD7M2_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
20389
20092
|
const pubkey = await identity.xOnlyPublicKey();
|
|
20390
20093
|
if (!pubkey) {
|
|
20391
20094
|
throw new Error("Invalid configured public key");
|
|
20392
20095
|
}
|
|
20393
|
-
const network =
|
|
20096
|
+
const network = chunkQWWOD7M2_cjs.getNetwork(networkName);
|
|
20394
20097
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
20395
20098
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
20396
20099
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -20496,7 +20199,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20496
20199
|
if (!inputs) {
|
|
20497
20200
|
throw new Error("Fee estimation failed");
|
|
20498
20201
|
}
|
|
20499
|
-
let tx = new
|
|
20202
|
+
let tx = new chunkQWWOD7M2_cjs.Transaction();
|
|
20500
20203
|
for (const input of inputs) {
|
|
20501
20204
|
tx.addInput({
|
|
20502
20205
|
txid: input.txid,
|
|
@@ -20554,7 +20257,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
20554
20257
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
20555
20258
|
*/
|
|
20556
20259
|
async bumpAnchor(parentHex, feeRate) {
|
|
20557
|
-
const parent =
|
|
20260
|
+
const parent = chunkQWWOD7M2_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
20558
20261
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
20559
20262
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
20560
20263
|
return [parent.hex, child.hex];
|
|
@@ -21461,7 +21164,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21461
21164
|
try {
|
|
21462
21165
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
21463
21166
|
for (const psbt of txs) {
|
|
21464
|
-
const tx =
|
|
21167
|
+
const tx = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
21465
21168
|
resolved.set(tx.id, tx.toBytes());
|
|
21466
21169
|
}
|
|
21467
21170
|
} catch (err) {
|
|
@@ -21494,7 +21197,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
21494
21197
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
21495
21198
|
const pending = [];
|
|
21496
21199
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21497
|
-
if (
|
|
21200
|
+
if (chunkQWWOD7M2_cjs.getArkPsbtFields(tx, i, chunkQWWOD7M2_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
21498
21201
|
}
|
|
21499
21202
|
if (pending.length === 0) return;
|
|
21500
21203
|
const resolved = await resolvePrevTxs(
|
|
@@ -21503,13 +21206,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
21503
21206
|
onchain
|
|
21504
21207
|
);
|
|
21505
21208
|
for (const i of pending) {
|
|
21506
|
-
|
|
21209
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(tx, i, chunkQWWOD7M2_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
21507
21210
|
}
|
|
21508
21211
|
}
|
|
21509
21212
|
async function attachPrevoutTxs(tx, source) {
|
|
21510
21213
|
const pending = [];
|
|
21511
21214
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
21512
|
-
if (
|
|
21215
|
+
if (chunkQWWOD7M2_cjs.getArkPsbtFields(tx, i, chunkQWWOD7M2_cjs.PrevoutTxField).length > 0) continue;
|
|
21513
21216
|
const input = tx.getInput(i);
|
|
21514
21217
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
21515
21218
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -21520,7 +21223,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
21520
21223
|
resolved.set(txid, await source.getRawTransaction(txid));
|
|
21521
21224
|
}
|
|
21522
21225
|
for (const { index, txid } of pending) {
|
|
21523
|
-
|
|
21226
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(tx, index, chunkQWWOD7M2_cjs.PrevoutTxField, resolved.get(txid));
|
|
21524
21227
|
}
|
|
21525
21228
|
}
|
|
21526
21229
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -21546,7 +21249,7 @@ exports.BIP322 = void 0;
|
|
|
21546
21249
|
async function sign2(message, identity, network) {
|
|
21547
21250
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
21548
21251
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
21549
|
-
const toSpend =
|
|
21252
|
+
const toSpend = chunkQWWOD7M2_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
21550
21253
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
21551
21254
|
const signed = await identity.sign(toSign, [0]);
|
|
21552
21255
|
signed.finalizeIdx(0);
|
|
@@ -21604,7 +21307,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
21604
21307
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
21605
21308
|
return false;
|
|
21606
21309
|
}
|
|
21607
|
-
const toSpend =
|
|
21310
|
+
const toSpend = chunkQWWOD7M2_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21608
21311
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
21609
21312
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
21610
21313
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -21625,7 +21328,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
21625
21328
|
}
|
|
21626
21329
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
21627
21330
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
21628
|
-
const toSpend =
|
|
21331
|
+
const toSpend = chunkQWWOD7M2_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
21629
21332
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
21630
21333
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
21631
21334
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -21678,7 +21381,7 @@ function encodeCompactSize(n) {
|
|
|
21678
21381
|
return buf;
|
|
21679
21382
|
}
|
|
21680
21383
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
21681
|
-
const tx = new
|
|
21384
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({ version: 0 });
|
|
21682
21385
|
tx.addInput({
|
|
21683
21386
|
txid: toSpend.id,
|
|
21684
21387
|
index: 0,
|
|
@@ -21692,12 +21395,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
21692
21395
|
});
|
|
21693
21396
|
tx.addOutput({
|
|
21694
21397
|
amount: 0n,
|
|
21695
|
-
script:
|
|
21398
|
+
script: chunkQWWOD7M2_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21696
21399
|
});
|
|
21697
21400
|
return tx;
|
|
21698
21401
|
}
|
|
21699
21402
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
21700
|
-
const tx = new
|
|
21403
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({ version: 0 });
|
|
21701
21404
|
tx.addInput({
|
|
21702
21405
|
txid: toSpend.id,
|
|
21703
21406
|
index: 0,
|
|
@@ -21709,7 +21412,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
21709
21412
|
});
|
|
21710
21413
|
tx.addOutput({
|
|
21711
21414
|
amount: 0n,
|
|
21712
|
-
script:
|
|
21415
|
+
script: chunkQWWOD7M2_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
21713
21416
|
});
|
|
21714
21417
|
return tx;
|
|
21715
21418
|
}
|
|
@@ -21840,7 +21543,7 @@ var RestEmulatorProvider = class {
|
|
|
21840
21543
|
}
|
|
21841
21544
|
};
|
|
21842
21545
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
21843
|
-
const tx =
|
|
21546
|
+
const tx = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
21844
21547
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
21845
21548
|
const input = tx.getInput(0);
|
|
21846
21549
|
if (!input) {
|
|
@@ -21867,14 +21570,14 @@ var ExitPathError = class extends Error {
|
|
|
21867
21570
|
reason;
|
|
21868
21571
|
};
|
|
21869
21572
|
function delayWeight(sequence) {
|
|
21870
|
-
const t =
|
|
21573
|
+
const t = chunkQWWOD7M2_cjs.sequenceToTimelock(sequence);
|
|
21871
21574
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
21872
21575
|
}
|
|
21873
21576
|
async function resolveUnilateralPath(params) {
|
|
21874
21577
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
21875
21578
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
21876
21579
|
if (contract) {
|
|
21877
|
-
const handler =
|
|
21580
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
21878
21581
|
if (!handler) {
|
|
21879
21582
|
throw new ExitPathError(
|
|
21880
21583
|
"no-handler",
|
|
@@ -21885,8 +21588,7 @@ async function resolveUnilateralPath(params) {
|
|
|
21885
21588
|
const paths = handler.getAllSpendingPaths(script, contract, {
|
|
21886
21589
|
collaborative: false,
|
|
21887
21590
|
currentTime: params.currentTime,
|
|
21888
|
-
walletDescriptor: params.walletDescriptor
|
|
21889
|
-
walletPubKey: params.walletPubKeyHex
|
|
21591
|
+
walletDescriptor: params.walletDescriptor
|
|
21890
21592
|
}).filter((p) => p.sequence !== void 0);
|
|
21891
21593
|
if (paths.length === 0) {
|
|
21892
21594
|
throw new ExitPathError(
|
|
@@ -21897,12 +21599,12 @@ async function resolveUnilateralPath(params) {
|
|
|
21897
21599
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
21898
21600
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
21899
21601
|
}
|
|
21900
|
-
const decoded =
|
|
21602
|
+
const decoded = chunkQWWOD7M2_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
21901
21603
|
let best;
|
|
21902
21604
|
for (const exit of decoded.exitPaths()) {
|
|
21903
21605
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
21904
21606
|
if (!leaf) continue;
|
|
21905
|
-
const sequence =
|
|
21607
|
+
const sequence = chunkQWWOD7M2_cjs.timelockToSequence(exit.params.timelock);
|
|
21906
21608
|
const weight = delayWeight(sequence);
|
|
21907
21609
|
if (!best || weight < best.weight) {
|
|
21908
21610
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -22122,7 +21824,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22122
21824
|
let totalAmount = 0n;
|
|
22123
21825
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
22124
21826
|
for (const vtxo of vtxos) {
|
|
22125
|
-
if (!
|
|
21827
|
+
if (!chunkQWWOD7M2_cjs.canSweepOnchain(vtxo)) {
|
|
22126
21828
|
throw new Error(
|
|
22127
21829
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
22128
21830
|
);
|
|
@@ -22133,14 +21835,13 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22133
21835
|
}
|
|
22134
21836
|
const resolved = await resolveUnilateralPath({
|
|
22135
21837
|
vtxo,
|
|
22136
|
-
scriptHex: base.hex.encode(
|
|
21838
|
+
scriptHex: base.hex.encode(chunkQWWOD7M2_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22137
21839
|
contractRepository: wallet.contractRepository,
|
|
22138
|
-
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
22139
21840
|
currentTime: Date.now()
|
|
22140
21841
|
});
|
|
22141
21842
|
const spendingLeaf = resolved.selection.leaf;
|
|
22142
21843
|
const sequence = resolved.selection.sequence;
|
|
22143
|
-
const timelock =
|
|
21844
|
+
const timelock = chunkQWWOD7M2_cjs.sequenceToTimelock(sequence);
|
|
22144
21845
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
22145
21846
|
if (!elapsed) {
|
|
22146
21847
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -22153,7 +21854,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22153
21854
|
sequence,
|
|
22154
21855
|
witnessUtxo: {
|
|
22155
21856
|
amount: BigInt(vtxo.value),
|
|
22156
|
-
script:
|
|
21857
|
+
script: chunkQWWOD7M2_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
22157
21858
|
},
|
|
22158
21859
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
22159
21860
|
});
|
|
@@ -22163,7 +21864,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
22163
21864
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
22164
21865
|
);
|
|
22165
21866
|
}
|
|
22166
|
-
const tx = new
|
|
21867
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({ version: 2 });
|
|
22167
21868
|
for (const input of inputs) {
|
|
22168
21869
|
tx.addInput(input);
|
|
22169
21870
|
}
|
|
@@ -22246,7 +21947,7 @@ async function buildSignedSweep(params) {
|
|
|
22246
21947
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
22247
21948
|
);
|
|
22248
21949
|
}
|
|
22249
|
-
const tx = new
|
|
21950
|
+
const tx = new chunkQWWOD7M2_cjs.Transaction({ version: 2 });
|
|
22250
21951
|
tx.addInput({
|
|
22251
21952
|
txid: vtxo.txid,
|
|
22252
21953
|
index: vtxo.vout,
|
|
@@ -22271,7 +21972,7 @@ async function buildSignedSweep(params) {
|
|
|
22271
21972
|
finalScriptWitness: [
|
|
22272
21973
|
tapScriptSig[0][1],
|
|
22273
21974
|
...path.extraWitness,
|
|
22274
|
-
|
|
21975
|
+
chunkQWWOD7M2_cjs.scriptFromTapLeafScript(path.leaf),
|
|
22275
21976
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
22276
21977
|
]
|
|
22277
21978
|
});
|
|
@@ -22301,7 +22002,7 @@ async function resolveFeeRate(opts) {
|
|
|
22301
22002
|
}
|
|
22302
22003
|
async function selectExitVtxos(opts) {
|
|
22303
22004
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
22304
|
-
const res = await
|
|
22005
|
+
const res = await chunkQWWOD7M2_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
22305
22006
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
22306
22007
|
const out = [];
|
|
22307
22008
|
for (const vtxo of res.vtxos) {
|
|
@@ -22316,7 +22017,7 @@ async function selectExitVtxos(opts) {
|
|
|
22316
22017
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
22317
22018
|
);
|
|
22318
22019
|
}
|
|
22319
|
-
const handler =
|
|
22020
|
+
const handler = chunkAEDYZK7T_cjs.contractHandlers.get(contract.type);
|
|
22320
22021
|
if (!handler) {
|
|
22321
22022
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
22322
22023
|
}
|
|
@@ -22346,7 +22047,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22346
22047
|
if (pendingNodes.length > 0) {
|
|
22347
22048
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
22348
22049
|
for (const psbt of txs) {
|
|
22349
|
-
psbts.set(
|
|
22050
|
+
psbts.set(chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
22350
22051
|
}
|
|
22351
22052
|
}
|
|
22352
22053
|
const childVsize = Number(
|
|
@@ -22374,7 +22075,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22374
22075
|
(s) => s.parent.id,
|
|
22375
22076
|
(s) => parentInputTxids(s.parent)
|
|
22376
22077
|
);
|
|
22377
|
-
const
|
|
22078
|
+
const walletDescriptor = base.hex.encode(await wallet.identity.xOnlyPublicKey());
|
|
22378
22079
|
const infos = [];
|
|
22379
22080
|
const sweeps = [];
|
|
22380
22081
|
for (const vtxo of vtxos) {
|
|
@@ -22382,9 +22083,9 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22382
22083
|
try {
|
|
22383
22084
|
const resolved = await resolveUnilateralPath({
|
|
22384
22085
|
vtxo,
|
|
22385
|
-
scriptHex: base.hex.encode(
|
|
22086
|
+
scriptHex: base.hex.encode(chunkQWWOD7M2_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
22386
22087
|
contractRepository: wallet.contractRepository,
|
|
22387
|
-
|
|
22088
|
+
walletDescriptor,
|
|
22388
22089
|
currentTime: Date.now()
|
|
22389
22090
|
});
|
|
22390
22091
|
const sweepFee = sweepFeeFor(
|
|
@@ -22401,7 +22102,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
22401
22102
|
});
|
|
22402
22103
|
continue;
|
|
22403
22104
|
}
|
|
22404
|
-
const t =
|
|
22105
|
+
const t = chunkQWWOD7M2_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
22405
22106
|
const delay = { type: t.type, value: Number(t.value) };
|
|
22406
22107
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
22407
22108
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -22802,7 +22503,7 @@ async function prepare(opts) {
|
|
|
22802
22503
|
txid: sweep.vtxo.txid,
|
|
22803
22504
|
vout: sweep.vtxo.vout,
|
|
22804
22505
|
value: sweep.vtxo.value,
|
|
22805
|
-
pkScript:
|
|
22506
|
+
pkScript: chunkQWWOD7M2_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
22806
22507
|
},
|
|
22807
22508
|
path: sweep.resolved.selection,
|
|
22808
22509
|
outputAddress: opts.sweepAddress,
|
|
@@ -22890,7 +22591,7 @@ async function prepare(opts) {
|
|
|
22890
22591
|
if (newFee <= splitterFee) break;
|
|
22891
22592
|
splitterFee = newFee;
|
|
22892
22593
|
}
|
|
22893
|
-
const splitter = new
|
|
22594
|
+
const splitter = new chunkQWWOD7M2_cjs.Transaction({ version: 2 });
|
|
22894
22595
|
for (const coin of selected.inputs) {
|
|
22895
22596
|
splitter.addInput({
|
|
22896
22597
|
txid: coin.txid,
|
|
@@ -23033,42 +22734,42 @@ var UnilateralExit = {
|
|
|
23033
22734
|
|
|
23034
22735
|
// src/arkade/index.ts
|
|
23035
22736
|
var arkade_exports = {};
|
|
23036
|
-
|
|
23037
|
-
ARKADE_OP: () =>
|
|
23038
|
-
ARKADE_OPCODES: () =>
|
|
23039
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
23040
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
23041
|
-
ARKADE_OPS: () =>
|
|
22737
|
+
chunkQWWOD7M2_cjs.__export(arkade_exports, {
|
|
22738
|
+
ARKADE_OP: () => chunkAEDYZK7T_cjs.ARKADE_OP,
|
|
22739
|
+
ARKADE_OPCODES: () => chunkAEDYZK7T_cjs.ARKADE_OPCODES,
|
|
22740
|
+
ARKADE_OPCODE_NAMES: () => chunkAEDYZK7T_cjs.ARKADE_OPCODE_NAMES,
|
|
22741
|
+
ARKADE_OPCODE_VALUES: () => chunkAEDYZK7T_cjs.ARKADE_OPCODE_VALUES,
|
|
22742
|
+
ARKADE_OPS: () => chunkAEDYZK7T_cjs.ARKADE_OPS,
|
|
23042
22743
|
Arkade: () => Arkade,
|
|
23043
22744
|
ArkadeContract: () => ArkadeContract,
|
|
23044
|
-
ArkadeProgramScript: () =>
|
|
23045
|
-
ArkadeScript: () =>
|
|
22745
|
+
ArkadeProgramScript: () => chunkAEDYZK7T_cjs.ArkadeProgramScript,
|
|
22746
|
+
ArkadeScript: () => chunkAEDYZK7T_cjs.ArkadeScript,
|
|
23046
22747
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
23047
|
-
BigNum: () =>
|
|
22748
|
+
BigNum: () => chunkAEDYZK7T_cjs.bignum_exports,
|
|
23048
22749
|
OP: () => btcSigner.OP,
|
|
23049
|
-
OPCODE_NAMES: () =>
|
|
23050
|
-
OPCODE_VALUES: () =>
|
|
23051
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
22750
|
+
OPCODE_NAMES: () => chunkAEDYZK7T_cjs.OPCODE_NAMES,
|
|
22751
|
+
OPCODE_VALUES: () => chunkAEDYZK7T_cjs.OPCODE_VALUES,
|
|
22752
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkAEDYZK7T_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
23052
22753
|
Script: () => btcSigner.Script,
|
|
23053
|
-
arkadeScriptHash: () =>
|
|
23054
|
-
arkadeWitnessHash: () =>
|
|
23055
|
-
asmToBytes: () =>
|
|
23056
|
-
bytesToASM: () =>
|
|
23057
|
-
computeArkadeScriptPublicKey: () =>
|
|
22754
|
+
arkadeScriptHash: () => chunkAEDYZK7T_cjs.arkadeScriptHash,
|
|
22755
|
+
arkadeWitnessHash: () => chunkAEDYZK7T_cjs.arkadeWitnessHash,
|
|
22756
|
+
asmToBytes: () => chunkAEDYZK7T_cjs.asmToBytes,
|
|
22757
|
+
bytesToASM: () => chunkAEDYZK7T_cjs.bytesToASM,
|
|
22758
|
+
computeArkadeScriptPublicKey: () => chunkAEDYZK7T_cjs.computeArkadeScriptPublicKey,
|
|
23058
22759
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
23059
|
-
deserializeArkadeContractParams: () =>
|
|
23060
|
-
fromASM: () =>
|
|
23061
|
-
getOpcodeName: () =>
|
|
23062
|
-
getOpcodeValue: () =>
|
|
23063
|
-
parseArtifact: () =>
|
|
23064
|
-
resolveAsm: () =>
|
|
23065
|
-
serializeArkadeContractParams: () =>
|
|
23066
|
-
stringifyArtifact: () =>
|
|
23067
|
-
toASM: () =>
|
|
23068
|
-
validateProgram: () =>
|
|
23069
|
-
witnessRefToBytes: () =>
|
|
22760
|
+
deserializeArkadeContractParams: () => chunkAEDYZK7T_cjs.deserializeArkadeContractParams,
|
|
22761
|
+
fromASM: () => chunkAEDYZK7T_cjs.fromASM,
|
|
22762
|
+
getOpcodeName: () => chunkAEDYZK7T_cjs.getOpcodeName,
|
|
22763
|
+
getOpcodeValue: () => chunkAEDYZK7T_cjs.getOpcodeValue,
|
|
22764
|
+
parseArtifact: () => chunkAEDYZK7T_cjs.parseArtifact,
|
|
22765
|
+
resolveAsm: () => chunkAEDYZK7T_cjs.resolveAsm,
|
|
22766
|
+
serializeArkadeContractParams: () => chunkAEDYZK7T_cjs.serializeArkadeContractParams,
|
|
22767
|
+
stringifyArtifact: () => chunkAEDYZK7T_cjs.stringifyArtifact,
|
|
22768
|
+
toASM: () => chunkAEDYZK7T_cjs.toASM,
|
|
22769
|
+
validateProgram: () => chunkAEDYZK7T_cjs.validateProgram,
|
|
22770
|
+
witnessRefToBytes: () => chunkAEDYZK7T_cjs.witnessRefToBytes
|
|
23070
22771
|
});
|
|
23071
|
-
var isVtxoCoin = (input) =>
|
|
22772
|
+
var isVtxoCoin = (input) => chunkQWWOD7M2_cjs.isVirtualCoin(input);
|
|
23072
22773
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
23073
22774
|
let batchId;
|
|
23074
22775
|
let sweepTapTreeRoot;
|
|
@@ -23089,23 +22790,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23089
22790
|
);
|
|
23090
22791
|
await arkProvider.confirmRegistration(intentId);
|
|
23091
22792
|
batchId = event.id;
|
|
23092
|
-
const sweepTapscript =
|
|
22793
|
+
const sweepTapscript = chunkQWWOD7M2_cjs.CSVMultisigTapscript.encode({
|
|
23093
22794
|
timelock,
|
|
23094
|
-
pubkeys: [
|
|
22795
|
+
pubkeys: [chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
23095
22796
|
}).script;
|
|
23096
22797
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
23097
22798
|
return { skip: false };
|
|
23098
22799
|
},
|
|
23099
22800
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
23100
22801
|
const signerPubKey = await session.getPublicKey();
|
|
23101
|
-
const xonlySignerPubKey =
|
|
22802
|
+
const xonlySignerPubKey = chunkAEDYZK7T_cjs.toXOnly(signerPubKey, "signer key");
|
|
23102
22803
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
23103
|
-
(k) => base.hex.encode(
|
|
22804
|
+
(k) => base.hex.encode(chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
23104
22805
|
);
|
|
23105
22806
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
23106
22807
|
return { skip: true };
|
|
23107
22808
|
}
|
|
23108
|
-
const commitmentTx =
|
|
22809
|
+
const commitmentTx = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
23109
22810
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
23110
22811
|
if (recipients && recipients.length > 0) {
|
|
23111
22812
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -23137,7 +22838,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23137
22838
|
if (connectorTree) {
|
|
23138
22839
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
23139
22840
|
}
|
|
23140
|
-
let commitmentPsbt =
|
|
22841
|
+
let commitmentPsbt = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
23141
22842
|
assertFinalCommitmentMatchesValidated(
|
|
23142
22843
|
commitmentPsbt,
|
|
23143
22844
|
validatedCommitmentTxid,
|
|
@@ -23172,7 +22873,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23172
22873
|
boardingIndices.push(boardingIdx);
|
|
23173
22874
|
continue;
|
|
23174
22875
|
}
|
|
23175
|
-
if (
|
|
22876
|
+
if (chunkQWWOD7M2_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust(input, info.dust)) {
|
|
23176
22877
|
continue;
|
|
23177
22878
|
}
|
|
23178
22879
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -23193,7 +22894,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
23193
22894
|
index: input.vout,
|
|
23194
22895
|
witnessUtxo: {
|
|
23195
22896
|
amount: BigInt(input.value),
|
|
23196
|
-
script:
|
|
22897
|
+
script: chunkQWWOD7M2_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
23197
22898
|
},
|
|
23198
22899
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
23199
22900
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -23284,16 +22985,16 @@ var Arkade = class _Arkade {
|
|
|
23284
22985
|
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
23285
22986
|
static async connect(opts) {
|
|
23286
22987
|
const info = await opts.arkade.getInfo();
|
|
23287
|
-
const serverKey =
|
|
23288
|
-
const checkpoint =
|
|
23289
|
-
const network = opts.network ??
|
|
22988
|
+
const serverKey = chunkAEDYZK7T_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
22989
|
+
const checkpoint = chunkQWWOD7M2_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
22990
|
+
const network = opts.network ?? chunkQWWOD7M2_cjs.DEFAULT_NETWORK;
|
|
23290
22991
|
let emulatorKey;
|
|
23291
22992
|
if (opts.emulator) {
|
|
23292
|
-
emulatorKey = base.hex.decode(
|
|
22993
|
+
emulatorKey = base.hex.decode(chunkQWWOD7M2_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
23293
22994
|
}
|
|
23294
22995
|
let userKey;
|
|
23295
22996
|
if (opts.identity) {
|
|
23296
|
-
userKey =
|
|
22997
|
+
userKey = chunkAEDYZK7T_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
23297
22998
|
}
|
|
23298
22999
|
return new _Arkade({
|
|
23299
23000
|
arkProvider: opts.arkade,
|
|
@@ -23319,7 +23020,7 @@ var Arkade = class _Arkade {
|
|
|
23319
23020
|
* key respectively; explicit args always win.
|
|
23320
23021
|
*/
|
|
23321
23022
|
contract(program, args = {}) {
|
|
23322
|
-
const declared = (program.params ?? []).map(
|
|
23023
|
+
const declared = (program.params ?? []).map(chunkAEDYZK7T_cjs.inputName);
|
|
23323
23024
|
if (declared.includes("server") && args.server === void 0) {
|
|
23324
23025
|
args = { ...args, server: this.serverKey };
|
|
23325
23026
|
}
|
|
@@ -23339,7 +23040,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23339
23040
|
userKey: client.userKey,
|
|
23340
23041
|
emulatorKey: client.emulatorKey
|
|
23341
23042
|
};
|
|
23342
|
-
this.vtxoScript = new
|
|
23043
|
+
this.vtxoScript = new chunkAEDYZK7T_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
23343
23044
|
this.tapTree = this.vtxoScript.encode();
|
|
23344
23045
|
this.compiled = this.vtxoScript.compiled;
|
|
23345
23046
|
}
|
|
@@ -23367,7 +23068,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23367
23068
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
23368
23069
|
);
|
|
23369
23070
|
}
|
|
23370
|
-
const typed =
|
|
23071
|
+
const typed = chunkAEDYZK7T_cjs.deserializeArkadeContractParams(contract.params);
|
|
23371
23072
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
23372
23073
|
serverKey: typed.serverKey,
|
|
23373
23074
|
userKey: typed.userKey,
|
|
@@ -23408,7 +23109,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23408
23109
|
toContractParams() {
|
|
23409
23110
|
return {
|
|
23410
23111
|
type: "arkade",
|
|
23411
|
-
params:
|
|
23112
|
+
params: chunkAEDYZK7T_cjs.serializeArkadeContractParams({
|
|
23412
23113
|
program: this.program,
|
|
23413
23114
|
args: this.args,
|
|
23414
23115
|
serverKey: this.keys.serverKey,
|
|
@@ -23458,18 +23159,18 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
23458
23159
|
if (registered) {
|
|
23459
23160
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
23460
23161
|
return (withVtxos?.vtxos ?? []).filter(
|
|
23461
|
-
(v) => !
|
|
23162
|
+
(v) => !chunkQWWOD7M2_cjs.hasTerminalSpend(v) && !v.isUnrolled
|
|
23462
23163
|
);
|
|
23463
23164
|
}
|
|
23464
23165
|
}
|
|
23465
23166
|
if (!this.client.indexer) {
|
|
23466
23167
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
23467
23168
|
}
|
|
23468
|
-
const { vtxos } = await
|
|
23169
|
+
const { vtxos } = await chunkQWWOD7M2_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
23469
23170
|
scripts: [scriptHex],
|
|
23470
23171
|
spendableOnly: true
|
|
23471
23172
|
});
|
|
23472
|
-
return vtxos.filter((v) => !
|
|
23173
|
+
return vtxos.filter((v) => !chunkQWWOD7M2_cjs.hasTerminalSpend(v) && !v.isUnrolled);
|
|
23473
23174
|
}
|
|
23474
23175
|
/** Total spendable balance (requires an indexer). */
|
|
23475
23176
|
async getBalance() {
|
|
@@ -23567,7 +23268,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23567
23268
|
this.contract.client.checkpoint
|
|
23568
23269
|
);
|
|
23569
23270
|
if (coin.sourceTx) {
|
|
23570
|
-
|
|
23271
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(arkTx, 0, chunkQWWOD7M2_cjs.PrevArkTxField, coin.sourceTx);
|
|
23571
23272
|
}
|
|
23572
23273
|
if (this.fn.arkadeScript) {
|
|
23573
23274
|
const indexer = this.contract.client.indexer;
|
|
@@ -23584,8 +23285,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
23584
23285
|
}
|
|
23585
23286
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
23586
23287
|
if (condition.length > 0) {
|
|
23587
|
-
|
|
23588
|
-
|
|
23288
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(arkTx, 0, chunkQWWOD7M2_cjs.ConditionWitness, condition);
|
|
23289
|
+
chunkQWWOD7M2_cjs.setArkPsbtField(checkpoints[0], 0, chunkQWWOD7M2_cjs.ConditionWitness, condition);
|
|
23589
23290
|
}
|
|
23590
23291
|
const packets = [];
|
|
23591
23292
|
if (this.assetSpecs.length > 0) {
|
|
@@ -23624,7 +23325,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
23624
23325
|
base.base64.encode(signedArk2.toPSBT()),
|
|
23625
23326
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
23626
23327
|
);
|
|
23627
|
-
const txid =
|
|
23328
|
+
const txid = chunkQWWOD7M2_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
23628
23329
|
return {
|
|
23629
23330
|
txid,
|
|
23630
23331
|
signedArkTx: res2.signedArkTx,
|
|
@@ -23689,23 +23390,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
23689
23390
|
}
|
|
23690
23391
|
buildAssetPacket() {
|
|
23691
23392
|
const groups = this.assetSpecs.map((s) => {
|
|
23692
|
-
const id = typeof s.assetId === "string" ?
|
|
23693
|
-
return
|
|
23393
|
+
const id = typeof s.assetId === "string" ? chunkNEVMOIQL_cjs.AssetId.fromString(s.assetId) : chunkNEVMOIQL_cjs.AssetId.fromBytes(s.assetId);
|
|
23394
|
+
return chunkNEVMOIQL_cjs.AssetGroup.create(
|
|
23694
23395
|
id,
|
|
23695
23396
|
null,
|
|
23696
|
-
s.inputs.map((i) =>
|
|
23697
|
-
s.outputs.map((o) =>
|
|
23698
|
-
(s.metadata ?? []).map((m) =>
|
|
23397
|
+
s.inputs.map((i) => chunkNEVMOIQL_cjs.AssetInput.create(i.vin, i.amount)),
|
|
23398
|
+
s.outputs.map((o) => chunkNEVMOIQL_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
23399
|
+
(s.metadata ?? []).map((m) => chunkNEVMOIQL_cjs.Metadata.create(m.key, m.value))
|
|
23699
23400
|
);
|
|
23700
23401
|
});
|
|
23701
|
-
return
|
|
23402
|
+
return chunkNEVMOIQL_cjs.Packet.create(groups);
|
|
23702
23403
|
}
|
|
23703
23404
|
witnessBytes(ref) {
|
|
23704
|
-
return
|
|
23405
|
+
return chunkAEDYZK7T_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
23705
23406
|
}
|
|
23706
23407
|
};
|
|
23707
23408
|
function bindInputs(fn, callArgs) {
|
|
23708
|
-
const names = (fn.def.inputs ?? []).map(
|
|
23409
|
+
const names = (fn.def.inputs ?? []).map(chunkAEDYZK7T_cjs.inputName);
|
|
23709
23410
|
if (callArgs.length !== names.length) {
|
|
23710
23411
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
23711
23412
|
}
|
|
@@ -24102,6 +23803,7 @@ function arkAssetRail() {
|
|
|
24102
23803
|
}
|
|
24103
23804
|
};
|
|
24104
23805
|
}
|
|
23806
|
+
var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo()).fees;
|
|
24105
23807
|
var GROSS_UP_MAX_ROUNDS = 8;
|
|
24106
23808
|
function grossUpOffboard(net, feeInfo, script) {
|
|
24107
23809
|
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
@@ -24114,7 +23816,10 @@ function grossUpOffboard(net, feeInfo, script) {
|
|
|
24114
23816
|
}
|
|
24115
23817
|
return { gross, fee: gross - net };
|
|
24116
23818
|
}
|
|
24117
|
-
function onchainRail() {
|
|
23819
|
+
function onchainRail(deps) {
|
|
23820
|
+
if (typeof deps?.feeInfo !== "function") {
|
|
23821
|
+
throw new Error("onchain rail: a feeInfo source is required");
|
|
23822
|
+
}
|
|
24118
23823
|
return {
|
|
24119
23824
|
id: "onchain",
|
|
24120
23825
|
match: (req) => btcTarget(req.raw) !== void 0,
|
|
@@ -24124,7 +23829,7 @@ function onchainRail() {
|
|
|
24124
23829
|
assertNoAssets("onchain", req);
|
|
24125
23830
|
const address = btcTarget(req.raw);
|
|
24126
23831
|
const amt = resolveSendAmount("onchain", req.raw, req.amount);
|
|
24127
|
-
const
|
|
23832
|
+
const fees = await deps.feeInfo();
|
|
24128
23833
|
const script = base.hex.encode(offboardDestinationScript(address));
|
|
24129
23834
|
const { gross, fee } = grossUpOffboard(amt, fees, script);
|
|
24130
23835
|
return {
|
|
@@ -24152,7 +23857,7 @@ function createDefaultPaymentRouter(wallet) {
|
|
|
24152
23857
|
return new PaymentRouter({
|
|
24153
23858
|
wallet,
|
|
24154
23859
|
prefs: { priority: ["ark", "ark-asset", "onchain"] }
|
|
24155
|
-
}).use(arkRail()).use(arkAssetRail()).use(onchainRail());
|
|
23860
|
+
}).use(arkRail()).use(arkAssetRail()).use(onchainRail({ feeInfo: walletFeeSource(wallet) }));
|
|
24156
23861
|
}
|
|
24157
23862
|
/*! Bundled license information:
|
|
24158
23863
|
|
|
@@ -24178,17 +23883,13 @@ exports.CachingArkProvider = CachingArkProvider;
|
|
|
24178
23883
|
exports.ChainedTxType = ChainedTxType;
|
|
24179
23884
|
exports.ConnectionDisposedError = ConnectionDisposedError;
|
|
24180
23885
|
exports.ContractManager = ContractManager;
|
|
24181
|
-
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
24182
23886
|
exports.ContractWatcher = ContractWatcher;
|
|
24183
|
-
exports.DB_VERSION = DB_VERSION;
|
|
24184
23887
|
exports.DEFAULT_MESSAGE_TIMEOUTS = DEFAULT_MESSAGE_TIMEOUTS;
|
|
24185
23888
|
exports.DEFAULT_MIN_BATCH_EXPIRY_SECONDS = DEFAULT_MIN_BATCH_EXPIRY_SECONDS;
|
|
24186
23889
|
exports.DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS = DEFAULT_MIN_CHECKPOINT_EXIT_DELAY_SECONDS;
|
|
24187
23890
|
exports.DatabaseUpgradeBlockedError = DatabaseUpgradeBlockedError;
|
|
24188
23891
|
exports.DelegateManagerImpl = DelegateManagerImpl;
|
|
24189
23892
|
exports.DelegateNotConfiguredError = DelegateNotConfiguredError;
|
|
24190
|
-
exports.DelegatorManagerImpl = DelegatorManagerImpl;
|
|
24191
|
-
exports.DelegatorNotConfiguredError = DelegatorNotConfiguredError;
|
|
24192
23893
|
exports.DescriptorIdentity = DescriptorIdentity;
|
|
24193
23894
|
exports.DescriptorSigningProviderMissingError = DescriptorSigningProviderMissingError;
|
|
24194
23895
|
exports.DustChangeError = DustChangeError;
|
|
@@ -24215,7 +23916,6 @@ exports.IndexedDBWalletRepository = IndexedDBWalletRepository;
|
|
|
24215
23916
|
exports.MAX_USED_SIGNING_DESCRIPTORS_LOOK_AHEAD = MAX_USED_SIGNING_DESCRIPTORS_LOOK_AHEAD;
|
|
24216
23917
|
exports.MESSAGE_BUS_INITIALIZING = MESSAGE_BUS_INITIALIZING;
|
|
24217
23918
|
exports.MESSAGE_BUS_NOT_INITIALIZED = MESSAGE_BUS_NOT_INITIALIZED;
|
|
24218
|
-
exports.MIGRATION_KEY = MIGRATION_KEY;
|
|
24219
23919
|
exports.MUTINYNET_MIN_CHECKPOINT_EXIT_DELAY_SECONDS = MUTINYNET_MIN_CHECKPOINT_EXIT_DELAY_SECONDS;
|
|
24220
23920
|
exports.MessageBus = MessageBus;
|
|
24221
23921
|
exports.MessageBusInitializingError = MessageBusInitializingError;
|
|
@@ -24235,7 +23935,6 @@ exports.ReadonlySingleKey = ReadonlySingleKey;
|
|
|
24235
23935
|
exports.ReadonlyWallet = ReadonlyWallet;
|
|
24236
23936
|
exports.ReadonlyWalletError = ReadonlyWalletError;
|
|
24237
23937
|
exports.RestDelegateProvider = RestDelegateProvider;
|
|
24238
|
-
exports.RestDelegatorProvider = RestDelegatorProvider;
|
|
24239
23938
|
exports.RestEmulatorProvider = RestEmulatorProvider;
|
|
24240
23939
|
exports.SIGNET_MIN_CHECKPOINT_EXIT_DELAY_SECONDS = SIGNET_MIN_CHECKPOINT_EXIT_DELAY_SECONDS;
|
|
24241
23940
|
exports.SeedIdentity = SeedIdentity;
|
|
@@ -24255,7 +23954,6 @@ exports.WalletCannotAllocateAddressError = WalletCannotAllocateAddressError;
|
|
|
24255
23954
|
exports.WalletCannotSignError = WalletCannotSignError;
|
|
24256
23955
|
exports.WalletMessageHandler = WalletMessageHandler;
|
|
24257
23956
|
exports.WalletNotInitializedError = WalletNotInitializedError;
|
|
24258
|
-
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
|
24259
23957
|
exports.WsElectrumChainSource = WsElectrumChainSource;
|
|
24260
23958
|
exports.adoptContractDescriptor = adoptContractDescriptor;
|
|
24261
23959
|
exports.arkAssetRail = arkAssetRail;
|
|
@@ -24311,7 +24009,6 @@ exports.extractArkProviderUrl = extractArkProviderUrl;
|
|
|
24311
24009
|
exports.gateExclusion = gateExclusion;
|
|
24312
24010
|
exports.gatedContracts = gatedContracts;
|
|
24313
24011
|
exports.getAllByIndexValues = getAllByIndexValues;
|
|
24314
|
-
exports.getMigrationStatus = getMigrationStatus;
|
|
24315
24012
|
exports.getRandomId = getRandomId;
|
|
24316
24013
|
exports.hasBoardingTxExpired = hasBoardingTxExpired;
|
|
24317
24014
|
exports.hasCandidates = hasCandidates;
|
|
@@ -24323,6 +24020,7 @@ exports.isArkContract = isArkContract;
|
|
|
24323
24020
|
exports.isBatchSignable = isBatchSignable;
|
|
24324
24021
|
exports.isBtcAddress = isBtcAddress;
|
|
24325
24022
|
exports.isContractGenericallySpendable = isContractGenericallySpendable;
|
|
24023
|
+
exports.isContractVtxoEvent = isContractVtxoEvent;
|
|
24326
24024
|
exports.isCooperativelyMigratable = isCooperativelyMigratable;
|
|
24327
24025
|
exports.isDeterministicSigner = isDeterministicSigner;
|
|
24328
24026
|
exports.isDiscoverable = isDiscoverable;
|
|
@@ -24341,11 +24039,11 @@ exports.isValidArkAddress = isValidArkAddress;
|
|
|
24341
24039
|
exports.isVtxoExpiringSoon = isVtxoExpiringSoon;
|
|
24342
24040
|
exports.isVtxoForScript = isVtxoForScript;
|
|
24343
24041
|
exports.isWatchedContract = isWatchedContract;
|
|
24042
|
+
exports.legacyVtxoFacts = legacyVtxoFacts;
|
|
24344
24043
|
exports.logExcludedVtxos = logExcludedVtxos;
|
|
24345
24044
|
exports.makeHandle = makeHandle;
|
|
24346
24045
|
exports.matchServerCheckpoints = matchServerCheckpoints;
|
|
24347
24046
|
exports.mergeChainedTxType = mergeChainedTxType;
|
|
24348
|
-
exports.migrateWalletRepository = migrateWalletRepository;
|
|
24349
24047
|
exports.notifyExitObserved = notifyExitObserved;
|
|
24350
24048
|
exports.onchainRail = onchainRail;
|
|
24351
24049
|
exports.openDatabase = openDatabase;
|
|
@@ -24354,14 +24052,12 @@ exports.outpointReasons = outpointReasons;
|
|
|
24354
24052
|
exports.promisifyRequest = promisifyRequest;
|
|
24355
24053
|
exports.provisionClaimSecret = provisionClaimSecret;
|
|
24356
24054
|
exports.provisionRefundKey = provisionRefundKey;
|
|
24357
|
-
exports.requiresMigration = requiresMigration;
|
|
24358
24055
|
exports.resolveAssetAmount = resolveAssetAmount;
|
|
24359
24056
|
exports.resolveBatchExpiryPolicy = resolveBatchExpiryPolicy;
|
|
24360
24057
|
exports.resolveCheckpointExitDelayPolicy = resolveCheckpointExitDelayPolicy;
|
|
24361
24058
|
exports.resolveDescriptorSigner = resolveDescriptorSigner;
|
|
24362
24059
|
exports.resolvePrevTxs = resolvePrevTxs;
|
|
24363
24060
|
exports.resolveSendAmount = resolveSendAmount;
|
|
24364
|
-
exports.rollbackMigration = rollbackMigration;
|
|
24365
24061
|
exports.saveVtxosForContract = saveVtxosForContract;
|
|
24366
24062
|
exports.scriptFromArkAddress = scriptFromArkAddress;
|
|
24367
24063
|
exports.selectCoinsWithAsset = selectCoinsWithAsset;
|
|
@@ -24382,7 +24078,8 @@ exports.validateConnectorsTxGraph = validateConnectorsTxGraph;
|
|
|
24382
24078
|
exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
24383
24079
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
24384
24080
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
24081
|
+
exports.walletFeeSource = walletFeeSource;
|
|
24385
24082
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
24386
24083
|
exports.withPrevTxs = withPrevTxs;
|
|
24387
|
-
//# sourceMappingURL=chunk-
|
|
24388
|
-
//# sourceMappingURL=chunk-
|
|
24084
|
+
//# sourceMappingURL=chunk-GQWHCQLD.cjs.map
|
|
24085
|
+
//# sourceMappingURL=chunk-GQWHCQLD.cjs.map
|