@arkade-os/sdk 0.4.50 → 0.4.52
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 +35 -8
- package/dist/adapters/expo.cjs +4 -4
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +2 -2
- package/dist/adapters/indexedDB.cjs +4 -4
- package/dist/adapters/indexedDB.js +3 -3
- package/dist/{ark-ApoclKQZ.d.cts → ark-B69ugeJw.d.cts} +133 -1
- package/dist/{ark-ApoclKQZ.d.ts → ark-B69ugeJw.d.ts} +133 -1
- package/dist/{asyncStorageTaskQueue-BCWmdVg8.d.ts → asyncStorageTaskQueue-BImF14sj.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-CIjgv1co.d.cts → asyncStorageTaskQueue-DScPdQAy.d.cts} +2 -2
- package/dist/{chunk-Q4K2RSMY.cjs → chunk-3Z5HK35D.cjs} +7 -7
- package/dist/{chunk-Q4K2RSMY.cjs.map → chunk-3Z5HK35D.cjs.map} +1 -1
- package/dist/{chunk-7WSVP7DK.js → chunk-3ZGANANS.js} +3 -3
- package/dist/{chunk-7WSVP7DK.js.map → chunk-3ZGANANS.js.map} +1 -1
- package/dist/{chunk-SNTSB6M2.js → chunk-AXCKRS2D.js} +354 -60
- package/dist/chunk-AXCKRS2D.js.map +1 -0
- package/dist/{chunk-TO3SR7TY.cjs → chunk-E6RT5XYB.cjs} +11 -11
- package/dist/{chunk-TO3SR7TY.cjs.map → chunk-E6RT5XYB.cjs.map} +1 -1
- package/dist/{chunk-SIAVTHMZ.cjs → chunk-FZPYPEWN.cjs} +3 -3
- package/dist/{chunk-SIAVTHMZ.cjs.map → chunk-FZPYPEWN.cjs.map} +1 -1
- package/dist/{chunk-LJQ2VQBE.cjs → chunk-IEMPH7J6.cjs} +52 -44
- package/dist/chunk-IEMPH7J6.cjs.map +1 -0
- package/dist/{chunk-6BQTROB4.cjs → chunk-ML33GFCH.cjs} +538 -243
- package/dist/chunk-ML33GFCH.cjs.map +1 -0
- package/dist/{chunk-MBSYQ3WX.js → chunk-UZLQUWYP.js} +52 -45
- package/dist/chunk-UZLQUWYP.js.map +1 -0
- package/dist/{chunk-ZXRSSBCF.js → chunk-WIVQWYPZ.js} +3 -3
- package/dist/{chunk-ZXRSSBCF.js.map → chunk-WIVQWYPZ.js.map} +1 -1
- package/dist/{chunk-AA4Q2J57.js → chunk-ZK3JITHP.js} +3 -3
- package/dist/{chunk-AA4Q2J57.js.map → chunk-ZK3JITHP.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +7 -7
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +1 -1
- package/dist/{delegate-hJYMZN1D.d.ts → delegate-BU-Cpyjw.d.ts} +1 -1
- package/dist/{delegate-CCHPwQft.d.cts → delegate-C_Y2YrXC.d.cts} +1 -1
- package/dist/{index-5Y9h9OnO.d.ts → index-BWF-C9eh.d.ts} +2 -2
- package/dist/{index-8jE1XJpT.d.cts → index-tzAInyiX.d.cts} +2 -2
- package/dist/index.cjs +161 -157
- package/dist/index.d.cts +24 -8
- package/dist/index.d.ts +24 -8
- package/dist/index.js +3 -3
- package/dist/repositories/realm/index.cjs +18 -18
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +4 -4
- package/dist/repositories/sqlite/index.cjs +17 -17
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +4 -4
- package/dist/{taskRunner-ChvV6Xrh.d.ts → taskRunner-Cf80BqSy.d.ts} +2 -2
- package/dist/{taskRunner-C3YLaM2x.d.cts → taskRunner-ClwI8jU8.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +13 -13
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +5 -5
- package/dist/wallet/expo/index.cjs +13 -13
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +4 -4
- package/dist/{wallet-DIH0gVfW.d.ts → wallet-B6Xiferv.d.cts} +33 -3
- package/dist/{wallet-B260BTJs.d.cts → wallet-CuHAI-eW.d.ts} +33 -3
- package/dist/worker/expo/index.cjs +8 -8
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-6BQTROB4.cjs.map +0 -1
- package/dist/chunk-LJQ2VQBE.cjs.map +0 -1
- package/dist/chunk-MBSYQ3WX.js.map +0 -1
- package/dist/chunk-SNTSB6M2.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkFZPYPEWN_cjs = require('./chunk-FZPYPEWN.cjs');
|
|
4
|
+
var chunkIEMPH7J6_cjs = require('./chunk-IEMPH7J6.cjs');
|
|
5
5
|
var chunkE7HB3GKK_cjs = require('./chunk-E7HB3GKK.cjs');
|
|
6
6
|
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
7
7
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
@@ -185,7 +185,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
185
185
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
186
186
|
const tx = this.graph.find(txid);
|
|
187
187
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
188
|
-
const cosigners =
|
|
188
|
+
const cosigners = chunkFZPYPEWN_cjs.getArkPsbtFields(tx.root, 0, chunkFZPYPEWN_cjs.CosignerPublicKey).map(
|
|
189
189
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
190
190
|
// xonly pubkey
|
|
191
191
|
);
|
|
@@ -237,7 +237,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
237
237
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
238
238
|
const prevoutAmounts = [];
|
|
239
239
|
const prevoutScripts = [];
|
|
240
|
-
const cosigners =
|
|
240
|
+
const cosigners = chunkFZPYPEWN_cjs.getArkPsbtFields(g.root, 0, chunkFZPYPEWN_cjs.CosignerPublicKey).map((c) => c.key);
|
|
241
241
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
242
242
|
taprootTweak: this.scriptRoot
|
|
243
243
|
});
|
|
@@ -416,7 +416,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
416
416
|
let network;
|
|
417
417
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
418
418
|
descriptor = opts.descriptor;
|
|
419
|
-
network =
|
|
419
|
+
network = chunkIEMPH7J6_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
420
420
|
} else {
|
|
421
421
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
422
422
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -501,7 +501,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
501
501
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
502
502
|
*/
|
|
503
503
|
isOurs(descriptor) {
|
|
504
|
-
return
|
|
504
|
+
return chunkIEMPH7J6_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
505
505
|
}
|
|
506
506
|
/**
|
|
507
507
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -538,7 +538,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
538
538
|
}
|
|
539
539
|
// ── internal helpers ─────────────────────────────────────────────
|
|
540
540
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
541
|
-
const network =
|
|
541
|
+
const network = chunkIEMPH7J6_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
542
542
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
543
543
|
if (expansion.isRanged) {
|
|
544
544
|
throw new Error(
|
|
@@ -624,7 +624,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
624
624
|
*/
|
|
625
625
|
descriptor;
|
|
626
626
|
constructor(descriptor) {
|
|
627
|
-
const network =
|
|
627
|
+
const network = chunkIEMPH7J6_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
628
628
|
let expansion;
|
|
629
629
|
try {
|
|
630
630
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -674,7 +674,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
674
674
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
675
675
|
*/
|
|
676
676
|
isOurs(descriptor) {
|
|
677
|
-
return
|
|
677
|
+
return chunkIEMPH7J6_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
678
678
|
}
|
|
679
679
|
};
|
|
680
680
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -986,14 +986,14 @@ var RestDelegateProvider = class {
|
|
|
986
986
|
*/
|
|
987
987
|
async delegate(intent, forfeitTxs, options) {
|
|
988
988
|
const url = `${this.url}/v1/delegate`;
|
|
989
|
-
const response = await
|
|
989
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(url, {
|
|
990
990
|
method: "POST",
|
|
991
991
|
headers: {
|
|
992
992
|
"Content-Type": "application/json"
|
|
993
993
|
},
|
|
994
994
|
body: JSON.stringify({
|
|
995
995
|
intent: {
|
|
996
|
-
message:
|
|
996
|
+
message: chunkFZPYPEWN_cjs.Intent.encodeMessage(intent.message),
|
|
997
997
|
proof: intent.proof
|
|
998
998
|
},
|
|
999
999
|
forfeit_txs: forfeitTxs,
|
|
@@ -1013,7 +1013,7 @@ var RestDelegateProvider = class {
|
|
|
1013
1013
|
*/
|
|
1014
1014
|
async getDelegateInfo() {
|
|
1015
1015
|
const url = `${this.url}/v1/delegator/info`;
|
|
1016
|
-
const response = await
|
|
1016
|
+
const response = await chunkFZPYPEWN_cjs.rateGate.runHttp(url, () => chunkFZPYPEWN_cjs.baseFetch(url));
|
|
1017
1017
|
if (!response.ok) {
|
|
1018
1018
|
const errorText2 = await response.text();
|
|
1019
1019
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1049,14 +1049,14 @@ var EsploraProvider = class {
|
|
|
1049
1049
|
pollingInterval;
|
|
1050
1050
|
forcePolling;
|
|
1051
1051
|
async getCoins(address) {
|
|
1052
|
-
const response = await
|
|
1052
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1053
1053
|
if (!response.ok) {
|
|
1054
1054
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1055
1055
|
}
|
|
1056
1056
|
return response.json();
|
|
1057
1057
|
}
|
|
1058
1058
|
async getFeeRate() {
|
|
1059
|
-
const response = await
|
|
1059
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1060
1060
|
if (response.status === 404) {
|
|
1061
1061
|
return void 0;
|
|
1062
1062
|
}
|
|
@@ -1077,7 +1077,7 @@ var EsploraProvider = class {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
1079
|
async getTxOutspends(txid) {
|
|
1080
|
-
const response = await
|
|
1080
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1081
1081
|
if (!response.ok) {
|
|
1082
1082
|
const error = await response.text();
|
|
1083
1083
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1085,7 +1085,7 @@ var EsploraProvider = class {
|
|
|
1085
1085
|
return response.json();
|
|
1086
1086
|
}
|
|
1087
1087
|
async getTransactions(address) {
|
|
1088
|
-
const response = await
|
|
1088
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1089
1089
|
if (!response.ok) {
|
|
1090
1090
|
const error = await response.text();
|
|
1091
1091
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1093,7 +1093,7 @@ var EsploraProvider = class {
|
|
|
1093
1093
|
return response.json();
|
|
1094
1094
|
}
|
|
1095
1095
|
async getTxStatus(txid) {
|
|
1096
|
-
const txresponse = await
|
|
1096
|
+
const txresponse = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1097
1097
|
if (!txresponse.ok) {
|
|
1098
1098
|
throw new Error(txresponse.statusText);
|
|
1099
1099
|
}
|
|
@@ -1101,7 +1101,7 @@ var EsploraProvider = class {
|
|
|
1101
1101
|
if (!tx.status.confirmed) {
|
|
1102
1102
|
return { confirmed: false };
|
|
1103
1103
|
}
|
|
1104
|
-
const response = await
|
|
1104
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1105
1105
|
if (!response.ok) {
|
|
1106
1106
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1107
1107
|
}
|
|
@@ -1185,7 +1185,7 @@ var EsploraProvider = class {
|
|
|
1185
1185
|
return stopFunc;
|
|
1186
1186
|
}
|
|
1187
1187
|
async getChainTip() {
|
|
1188
|
-
const tipBlocks = await
|
|
1188
|
+
const tipBlocks = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
1189
1189
|
if (!tipBlocks.ok) {
|
|
1190
1190
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
1191
1191
|
}
|
|
@@ -1204,7 +1204,7 @@ var EsploraProvider = class {
|
|
|
1204
1204
|
};
|
|
1205
1205
|
}
|
|
1206
1206
|
async broadcastPackage(parent, child) {
|
|
1207
|
-
const response = await
|
|
1207
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
1208
1208
|
method: "POST",
|
|
1209
1209
|
headers: {
|
|
1210
1210
|
"Content-Type": "application/json"
|
|
@@ -1218,7 +1218,7 @@ var EsploraProvider = class {
|
|
|
1218
1218
|
return response.json();
|
|
1219
1219
|
}
|
|
1220
1220
|
async broadcastTx(tx) {
|
|
1221
|
-
const response = await
|
|
1221
|
+
const response = await chunkFZPYPEWN_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
1222
1222
|
method: "POST",
|
|
1223
1223
|
headers: {
|
|
1224
1224
|
"Content-Type": "text/plain"
|
|
@@ -1380,7 +1380,7 @@ function findP2AOutput(tx) {
|
|
|
1380
1380
|
var CHILD_DUST_AMOUNT = 546;
|
|
1381
1381
|
function buildAnchorChild(params) {
|
|
1382
1382
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
1383
|
-
const child = new
|
|
1383
|
+
const child = new chunkFZPYPEWN_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
1384
1384
|
child.addInput(findP2AOutput(parent));
|
|
1385
1385
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
1386
1386
|
for (const _ of fundingCoins) {
|
|
@@ -1428,7 +1428,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
1428
1428
|
);
|
|
1429
1429
|
}
|
|
1430
1430
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
1431
|
-
const tx = new
|
|
1431
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({
|
|
1432
1432
|
version: 3,
|
|
1433
1433
|
lockTime: txLocktime
|
|
1434
1434
|
});
|
|
@@ -1504,7 +1504,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
1504
1504
|
if (previousScriptKey.length !== 32) {
|
|
1505
1505
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
1506
1506
|
}
|
|
1507
|
-
const cosigners =
|
|
1507
|
+
const cosigners = chunkFZPYPEWN_cjs.getArkPsbtFields(child.root, 0, chunkFZPYPEWN_cjs.CosignerPublicKey);
|
|
1508
1508
|
if (cosigners.length === 0) {
|
|
1509
1509
|
throw ErrMissingCosignersPublicKeys;
|
|
1510
1510
|
}
|
|
@@ -1562,7 +1562,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
1562
1562
|
return new _EmulatorPacket(entries);
|
|
1563
1563
|
}
|
|
1564
1564
|
static fromBytes(data) {
|
|
1565
|
-
const reader = new
|
|
1565
|
+
const reader = new chunkFZPYPEWN_cjs.BufferReader(data);
|
|
1566
1566
|
const entryCount = reader.readCompactSize();
|
|
1567
1567
|
const entries = [];
|
|
1568
1568
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -1580,7 +1580,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
1580
1580
|
return _EmulatorPacket.PACKET_TYPE;
|
|
1581
1581
|
}
|
|
1582
1582
|
serialize() {
|
|
1583
|
-
const writer = new
|
|
1583
|
+
const writer = new chunkFZPYPEWN_cjs.BufferWriter();
|
|
1584
1584
|
writer.writeCompactSize(this.entries.length);
|
|
1585
1585
|
for (const entry of this.entries) {
|
|
1586
1586
|
writer.writeUint16LE(entry.vin);
|
|
@@ -1667,7 +1667,7 @@ var Extension = class _Extension {
|
|
|
1667
1667
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
1668
1668
|
);
|
|
1669
1669
|
}
|
|
1670
|
-
const reader = new
|
|
1670
|
+
const reader = new chunkFZPYPEWN_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
1671
1671
|
const packets = [];
|
|
1672
1672
|
while (reader.remaining() > 0) {
|
|
1673
1673
|
const packetType = reader.readByte();
|
|
@@ -1741,7 +1741,7 @@ var Extension = class _Extension {
|
|
|
1741
1741
|
*/
|
|
1742
1742
|
getAssetPacket() {
|
|
1743
1743
|
for (const p of this.packets) {
|
|
1744
|
-
if (p instanceof
|
|
1744
|
+
if (p instanceof chunkFZPYPEWN_cjs.Packet) {
|
|
1745
1745
|
return p;
|
|
1746
1746
|
}
|
|
1747
1747
|
}
|
|
@@ -1779,8 +1779,8 @@ var Extension = class _Extension {
|
|
|
1779
1779
|
};
|
|
1780
1780
|
function parsePacket(packetType, data) {
|
|
1781
1781
|
switch (packetType) {
|
|
1782
|
-
case
|
|
1783
|
-
return
|
|
1782
|
+
case chunkFZPYPEWN_cjs.Packet.PACKET_TYPE:
|
|
1783
|
+
return chunkFZPYPEWN_cjs.Packet.fromBytes(data);
|
|
1784
1784
|
case EmulatorPacket.PACKET_TYPE:
|
|
1785
1785
|
return EmulatorPacket.fromBytes(data);
|
|
1786
1786
|
default:
|
|
@@ -2077,7 +2077,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2077
2077
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
2078
2078
|
inputsByAssetId.set(asset.assetId, [
|
|
2079
2079
|
...existing ?? [],
|
|
2080
|
-
|
|
2080
|
+
chunkFZPYPEWN_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
2081
2081
|
]);
|
|
2082
2082
|
}
|
|
2083
2083
|
}
|
|
@@ -2089,7 +2089,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2089
2089
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2090
2090
|
outputsByAssetId.set(asset.assetId, [
|
|
2091
2091
|
...existing ?? [],
|
|
2092
|
-
|
|
2092
|
+
chunkFZPYPEWN_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2093
2093
|
]);
|
|
2094
2094
|
}
|
|
2095
2095
|
}
|
|
@@ -2100,7 +2100,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2100
2100
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2101
2101
|
outputsByAssetId.set(asset.assetId, [
|
|
2102
2102
|
...existing ?? [],
|
|
2103
|
-
|
|
2103
|
+
chunkFZPYPEWN_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2104
2104
|
]);
|
|
2105
2105
|
}
|
|
2106
2106
|
}
|
|
@@ -2109,11 +2109,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2109
2109
|
for (const assetIdStr of allAssetIds) {
|
|
2110
2110
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2111
2111
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2112
|
-
const assetId =
|
|
2113
|
-
const group =
|
|
2112
|
+
const assetId = chunkFZPYPEWN_cjs.AssetId.fromString(assetIdStr);
|
|
2113
|
+
const group = chunkFZPYPEWN_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2114
2114
|
groups.push(group);
|
|
2115
2115
|
}
|
|
2116
|
-
return
|
|
2116
|
+
return chunkFZPYPEWN_cjs.Packet.create(groups);
|
|
2117
2117
|
}
|
|
2118
2118
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2119
2119
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2230,7 +2230,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2230
2230
|
}
|
|
2231
2231
|
}
|
|
2232
2232
|
}
|
|
2233
|
-
const tx = new
|
|
2233
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({
|
|
2234
2234
|
version: 3,
|
|
2235
2235
|
lockTime: Number(lockTime)
|
|
2236
2236
|
});
|
|
@@ -2245,7 +2245,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2245
2245
|
},
|
|
2246
2246
|
tapLeafScript: [input.tapLeafScript]
|
|
2247
2247
|
});
|
|
2248
|
-
|
|
2248
|
+
chunkFZPYPEWN_cjs.setArkPsbtField(tx, i, chunkFZPYPEWN_cjs.VtxoTaprootTree, input.tapTree);
|
|
2249
2249
|
}
|
|
2250
2250
|
for (const output of outputs) {
|
|
2251
2251
|
tx.addOutput(output);
|
|
@@ -2428,14 +2428,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks) {
|
|
|
2428
2428
|
let finalCheckpoints;
|
|
2429
2429
|
if (userSignedCheckpoints) {
|
|
2430
2430
|
finalCheckpoints = signedCheckpointTxs.map((c, i) => {
|
|
2431
|
-
const serverSigned =
|
|
2431
|
+
const serverSigned = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2432
2432
|
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
2433
2433
|
return base.base64.encode(serverSigned.toPSBT());
|
|
2434
2434
|
});
|
|
2435
2435
|
} else {
|
|
2436
2436
|
finalCheckpoints = await Promise.all(
|
|
2437
2437
|
signedCheckpointTxs.map(async (c) => {
|
|
2438
|
-
const tx =
|
|
2438
|
+
const tx = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2439
2439
|
const signed = await signer.signCheckpoint(tx);
|
|
2440
2440
|
return base.base64.encode(signed.toPSBT());
|
|
2441
2441
|
})
|
|
@@ -2611,6 +2611,9 @@ function parseProgram(text, env) {
|
|
|
2611
2611
|
}
|
|
2612
2612
|
|
|
2613
2613
|
// src/contracts/types.ts
|
|
2614
|
+
function hasCandidates(handler) {
|
|
2615
|
+
return !!handler && typeof handler.candidatesAt === "function";
|
|
2616
|
+
}
|
|
2614
2617
|
function isDiscoverable(handler) {
|
|
2615
2618
|
return !!handler && typeof handler.discoverAt === "function";
|
|
2616
2619
|
}
|
|
@@ -2631,7 +2634,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2631
2634
|
};
|
|
2632
2635
|
}
|
|
2633
2636
|
function deriveContractTapscripts(contract) {
|
|
2634
|
-
const handler =
|
|
2637
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
2635
2638
|
if (!handler) {
|
|
2636
2639
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2637
2640
|
}
|
|
@@ -3339,7 +3342,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3339
3342
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3340
3343
|
);
|
|
3341
3344
|
}
|
|
3342
|
-
const tx = new
|
|
3345
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction();
|
|
3343
3346
|
for (const utxo of expiredUtxos) {
|
|
3344
3347
|
const utxoScript = chunkE7HB3GKK_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3345
3348
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
@@ -3998,8 +4001,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3998
4001
|
* or doesn't carry the metadata.
|
|
3999
4002
|
*/
|
|
4000
4003
|
extractSpentOutpoint(error) {
|
|
4001
|
-
const ark =
|
|
4002
|
-
if (!
|
|
4004
|
+
const ark = chunkFZPYPEWN_cjs.maybeArkError(error);
|
|
4005
|
+
if (!chunkFZPYPEWN_cjs.isArkError(ark, chunkFZPYPEWN_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
4003
4006
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
4004
4007
|
if (typeof raw !== "string") return void 0;
|
|
4005
4008
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -4473,7 +4476,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
4473
4476
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
4474
4477
|
}
|
|
4475
4478
|
get vtxoScript() {
|
|
4476
|
-
return new
|
|
4479
|
+
return new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
4477
4480
|
pubKey: this._publicKey,
|
|
4478
4481
|
serverPubKey: this._serverPubKey,
|
|
4479
4482
|
csvTimelock: this.csvTimelock
|
|
@@ -4734,7 +4737,7 @@ async function captureExitBranch(params) {
|
|
|
4734
4737
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4735
4738
|
if (nonCommitment.length > 0) {
|
|
4736
4739
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4737
|
-
psbtByTxid.set(
|
|
4740
|
+
psbtByTxid.set(chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4738
4741
|
}
|
|
4739
4742
|
}
|
|
4740
4743
|
}
|
|
@@ -4795,7 +4798,7 @@ var IndexerExitDataSource = class {
|
|
|
4795
4798
|
pageSize: chunkE7HB3GKK_cjs.DEFAULT_PAGE_SIZE
|
|
4796
4799
|
});
|
|
4797
4800
|
for (const psbt of txs) {
|
|
4798
|
-
out.set(
|
|
4801
|
+
out.set(chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4799
4802
|
}
|
|
4800
4803
|
hasMore = page ? txs.length === chunkE7HB3GKK_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4801
4804
|
pageIndex++;
|
|
@@ -4818,7 +4821,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4818
4821
|
}
|
|
4819
4822
|
}
|
|
4820
4823
|
function psbtInputTxids(psbtBase64) {
|
|
4821
|
-
const tx =
|
|
4824
|
+
const tx = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4822
4825
|
const ids = [];
|
|
4823
4826
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4824
4827
|
const txid = tx.getInput(i).txid;
|
|
@@ -4921,7 +4924,7 @@ function createExitChainResolver(params) {
|
|
|
4921
4924
|
|
|
4922
4925
|
// src/providers/availability.ts
|
|
4923
4926
|
function isRetryableProviderError(error) {
|
|
4924
|
-
return error instanceof
|
|
4927
|
+
return error instanceof chunkFZPYPEWN_cjs.ProviderUnavailableError || error instanceof chunkFZPYPEWN_cjs.FetchError || chunkFZPYPEWN_cjs.isFetchTimeoutError(error);
|
|
4925
4928
|
}
|
|
4926
4929
|
|
|
4927
4930
|
// src/utils/syncCursors.ts
|
|
@@ -5174,7 +5177,7 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
5174
5177
|
if (!isRetryableProviderError(err)) throw err;
|
|
5175
5178
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
5176
5179
|
if (!snapshot) {
|
|
5177
|
-
throw new
|
|
5180
|
+
throw new chunkFZPYPEWN_cjs.ProviderUnavailableError(
|
|
5178
5181
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
5179
5182
|
{ cause: err }
|
|
5180
5183
|
);
|
|
@@ -5709,7 +5712,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5709
5712
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5710
5713
|
withRecoverable: false
|
|
5711
5714
|
});
|
|
5712
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5715
|
+
const controlAssetRef = params.controlAssetId ? chunkFZPYPEWN_cjs.AssetRef.fromId(chunkFZPYPEWN_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5713
5716
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5714
5717
|
let totalBtcSelected = 0n;
|
|
5715
5718
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5722,8 +5725,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5722
5725
|
}
|
|
5723
5726
|
}
|
|
5724
5727
|
const groups = [];
|
|
5725
|
-
const issuedAssetOutput =
|
|
5726
|
-
const issuedAssetGroup =
|
|
5728
|
+
const issuedAssetOutput = chunkFZPYPEWN_cjs.AssetOutput.create(0, params.amount);
|
|
5729
|
+
const issuedAssetGroup = chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
5727
5730
|
null,
|
|
5728
5731
|
controlAssetRef,
|
|
5729
5732
|
[],
|
|
@@ -5738,15 +5741,15 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5738
5741
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5739
5742
|
for (const asset of assets) {
|
|
5740
5743
|
if (asset.assetId !== assetId) continue;
|
|
5741
|
-
changeInputs.push(
|
|
5744
|
+
changeInputs.push(chunkFZPYPEWN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5742
5745
|
}
|
|
5743
5746
|
}
|
|
5744
5747
|
groups.push(
|
|
5745
|
-
|
|
5746
|
-
|
|
5748
|
+
chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
5749
|
+
chunkFZPYPEWN_cjs.AssetId.fromString(assetId),
|
|
5747
5750
|
null,
|
|
5748
5751
|
changeInputs,
|
|
5749
|
-
[
|
|
5752
|
+
[chunkFZPYPEWN_cjs.AssetOutput.create(0, amount)],
|
|
5750
5753
|
[]
|
|
5751
5754
|
)
|
|
5752
5755
|
);
|
|
@@ -5759,7 +5762,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5759
5762
|
script: outputAddress.pkScript,
|
|
5760
5763
|
amount: BigInt(totalBtcSelected)
|
|
5761
5764
|
},
|
|
5762
|
-
Extension.create([
|
|
5765
|
+
Extension.create([chunkFZPYPEWN_cjs.Packet.create(groups)]).txOut()
|
|
5763
5766
|
];
|
|
5764
5767
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5765
5768
|
coinSelection.inputs,
|
|
@@ -5767,7 +5770,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5767
5770
|
);
|
|
5768
5771
|
return {
|
|
5769
5772
|
arkTxId: arkTxid,
|
|
5770
|
-
assetId:
|
|
5773
|
+
assetId: chunkFZPYPEWN_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5771
5774
|
};
|
|
5772
5775
|
}
|
|
5773
5776
|
/**
|
|
@@ -5839,16 +5842,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5839
5842
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5840
5843
|
for (const asset of assets) {
|
|
5841
5844
|
if (asset.assetId !== params.assetId) continue;
|
|
5842
|
-
reissueInputs.push(
|
|
5845
|
+
reissueInputs.push(chunkFZPYPEWN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5843
5846
|
}
|
|
5844
5847
|
}
|
|
5845
5848
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5846
|
-
const reissueAssetIdObj =
|
|
5847
|
-
const reissueAssetGroup =
|
|
5849
|
+
const reissueAssetIdObj = chunkFZPYPEWN_cjs.AssetId.fromString(params.assetId);
|
|
5850
|
+
const reissueAssetGroup = chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
5848
5851
|
reissueAssetIdObj,
|
|
5849
5852
|
null,
|
|
5850
5853
|
reissueInputs,
|
|
5851
|
-
[
|
|
5854
|
+
[chunkFZPYPEWN_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5852
5855
|
[]
|
|
5853
5856
|
);
|
|
5854
5857
|
const groups = [reissueAssetGroup];
|
|
@@ -5857,15 +5860,15 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5857
5860
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5858
5861
|
for (const asset of assets) {
|
|
5859
5862
|
if (asset.assetId !== assetId) continue;
|
|
5860
|
-
changeInputs.push(
|
|
5863
|
+
changeInputs.push(chunkFZPYPEWN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5861
5864
|
}
|
|
5862
5865
|
}
|
|
5863
5866
|
groups.push(
|
|
5864
|
-
|
|
5865
|
-
|
|
5867
|
+
chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
5868
|
+
chunkFZPYPEWN_cjs.AssetId.fromString(assetId),
|
|
5866
5869
|
null,
|
|
5867
5870
|
changeInputs,
|
|
5868
|
-
[
|
|
5871
|
+
[chunkFZPYPEWN_cjs.AssetOutput.create(0, amount)],
|
|
5869
5872
|
[]
|
|
5870
5873
|
)
|
|
5871
5874
|
);
|
|
@@ -5877,7 +5880,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5877
5880
|
script: outputAddress.pkScript,
|
|
5878
5881
|
amount: BigInt(totalBtcSelected)
|
|
5879
5882
|
},
|
|
5880
|
-
Extension.create([
|
|
5883
|
+
Extension.create([chunkFZPYPEWN_cjs.Packet.create(groups)]).txOut()
|
|
5881
5884
|
];
|
|
5882
5885
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5883
5886
|
return arkTxid;
|
|
@@ -5944,15 +5947,15 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5944
5947
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5945
5948
|
for (const asset of assets) {
|
|
5946
5949
|
if (asset.assetId !== assetId) continue;
|
|
5947
|
-
changeInputs.push(
|
|
5950
|
+
changeInputs.push(chunkFZPYPEWN_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5948
5951
|
}
|
|
5949
5952
|
}
|
|
5950
5953
|
groups.push(
|
|
5951
|
-
|
|
5952
|
-
|
|
5954
|
+
chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
5955
|
+
chunkFZPYPEWN_cjs.AssetId.fromString(assetId),
|
|
5953
5956
|
null,
|
|
5954
5957
|
changeInputs,
|
|
5955
|
-
amount > 0n ? [
|
|
5958
|
+
amount > 0n ? [chunkFZPYPEWN_cjs.AssetOutput.create(0, amount)] : [],
|
|
5956
5959
|
[]
|
|
5957
5960
|
)
|
|
5958
5961
|
);
|
|
@@ -5964,7 +5967,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5964
5967
|
script: outputAddress.pkScript,
|
|
5965
5968
|
amount: BigInt(totalBtcSelected)
|
|
5966
5969
|
},
|
|
5967
|
-
Extension.create([
|
|
5970
|
+
Extension.create([chunkFZPYPEWN_cjs.Packet.create(groups)]).txOut()
|
|
5968
5971
|
];
|
|
5969
5972
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5970
5973
|
return arkTxid;
|
|
@@ -5989,7 +5992,7 @@ function castMetadata(metadata) {
|
|
|
5989
5992
|
} else {
|
|
5990
5993
|
throw new Error("Invalid metadata value type");
|
|
5991
5994
|
}
|
|
5992
|
-
md.push(
|
|
5995
|
+
md.push(chunkFZPYPEWN_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5993
5996
|
}
|
|
5994
5997
|
return md;
|
|
5995
5998
|
}
|
|
@@ -6273,7 +6276,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
6273
6276
|
expire_at: 0,
|
|
6274
6277
|
cosigners_public_keys: cosignerPubKeys
|
|
6275
6278
|
};
|
|
6276
|
-
const proof =
|
|
6279
|
+
const proof = chunkFZPYPEWN_cjs.Intent.create(message, coins, outputs);
|
|
6277
6280
|
const signedProof = await identity.sign(proof);
|
|
6278
6281
|
return {
|
|
6279
6282
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -8322,7 +8325,7 @@ var ContractWatcher = class {
|
|
|
8322
8325
|
this.connectionState = "connected";
|
|
8323
8326
|
this.reconnectAttempts = 0;
|
|
8324
8327
|
this.listenLoop().catch((e) => {
|
|
8325
|
-
if (
|
|
8328
|
+
if (chunkFZPYPEWN_cjs.isEventSourceError(e)) {
|
|
8326
8329
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8327
8330
|
} else {
|
|
8328
8331
|
console.error(e);
|
|
@@ -8735,6 +8738,9 @@ function dedupeOutpoints(outpoints) {
|
|
|
8735
8738
|
function areCoalescibleContractTypes(a, b) {
|
|
8736
8739
|
return a === "default" && b === "boarding" || a === "boarding" && b === "default";
|
|
8737
8740
|
}
|
|
8741
|
+
function toWatchOnlyContract(params) {
|
|
8742
|
+
return { ...params, state: params.state ?? "active", createdAt: Date.now() };
|
|
8743
|
+
}
|
|
8738
8744
|
var SCAN_MAX_INDEX = 1e4;
|
|
8739
8745
|
var DEFAULT_SCAN_BATCH = 10;
|
|
8740
8746
|
var ContractManager = class _ContractManager {
|
|
@@ -8747,6 +8753,12 @@ var ContractManager = class _ContractManager {
|
|
|
8747
8753
|
syncDegradedReason;
|
|
8748
8754
|
/** Epoch-ms of the last successful provider sync, if any. */
|
|
8749
8755
|
lastSyncedAt;
|
|
8756
|
+
/** Speculative look-ahead scripts, keyed by script. @see LookAheadEntry */
|
|
8757
|
+
lookAheadEntries = /* @__PURE__ */ new Map();
|
|
8758
|
+
/** In-flight look-ahead drain, if any. @see scheduleLookAheadDrain */
|
|
8759
|
+
lookAheadDrain;
|
|
8760
|
+
/** A refill was requested while a drain was running. */
|
|
8761
|
+
lookAheadDirty = false;
|
|
8750
8762
|
constructor(config) {
|
|
8751
8763
|
this.config = config;
|
|
8752
8764
|
this.watcher = new ContractWatcher({
|
|
@@ -8797,6 +8809,7 @@ var ContractManager = class _ContractManager {
|
|
|
8797
8809
|
for (const contract of contracts) {
|
|
8798
8810
|
await this.watcher.addContract(contract);
|
|
8799
8811
|
}
|
|
8812
|
+
await this.scheduleLookAheadDrain();
|
|
8800
8813
|
try {
|
|
8801
8814
|
await this.reconcileWatched();
|
|
8802
8815
|
this.markSyncOnline();
|
|
@@ -8848,6 +8861,173 @@ var ContractManager = class _ContractManager {
|
|
|
8848
8861
|
console.error("ContractManager: intent reconciliation failed", e);
|
|
8849
8862
|
}
|
|
8850
8863
|
}
|
|
8864
|
+
/** @see IContractManager.refillLookAhead */
|
|
8865
|
+
refillLookAhead() {
|
|
8866
|
+
return this.scheduleLookAheadDrain();
|
|
8867
|
+
}
|
|
8868
|
+
/**
|
|
8869
|
+
* Serialized drain of the look-ahead band: concurrent callers join the
|
|
8870
|
+
* active drain and mark it dirty, an idle call starts a new one. Promotion
|
|
8871
|
+
* can uncover more funded indices, and boot / SSE / rotate / reconnect can
|
|
8872
|
+
* all request a refill at once, so the loop coalesces them instead of
|
|
8873
|
+
* recursing.
|
|
8874
|
+
*/
|
|
8875
|
+
scheduleLookAheadDrain() {
|
|
8876
|
+
if (!this.config.lookAhead) return Promise.resolve();
|
|
8877
|
+
if (this.lookAheadDrain) {
|
|
8878
|
+
this.lookAheadDirty = true;
|
|
8879
|
+
return this.lookAheadDrain;
|
|
8880
|
+
}
|
|
8881
|
+
const drain = (async () => {
|
|
8882
|
+
do {
|
|
8883
|
+
this.lookAheadDirty = false;
|
|
8884
|
+
await this.ensureLookAhead();
|
|
8885
|
+
} while (this.lookAheadDirty);
|
|
8886
|
+
})().finally(() => {
|
|
8887
|
+
this.lookAheadDrain = void 0;
|
|
8888
|
+
});
|
|
8889
|
+
this.lookAheadDrain = drain;
|
|
8890
|
+
return drain;
|
|
8891
|
+
}
|
|
8892
|
+
/**
|
|
8893
|
+
* Request a drain without awaiting it. Used from inside a sync (promotion),
|
|
8894
|
+
* where awaiting the drain that the sync itself is part of would deadlock.
|
|
8895
|
+
*/
|
|
8896
|
+
requestLookAheadDrain() {
|
|
8897
|
+
if (!this.config.lookAhead) return;
|
|
8898
|
+
if (this.lookAheadDrain) {
|
|
8899
|
+
this.lookAheadDirty = true;
|
|
8900
|
+
return;
|
|
8901
|
+
}
|
|
8902
|
+
void this.scheduleLookAheadDrain().catch((err) => {
|
|
8903
|
+
console.error("ContractManager: look-ahead refill failed", err);
|
|
8904
|
+
});
|
|
8905
|
+
}
|
|
8906
|
+
/**
|
|
8907
|
+
* Rebuild the speculative watch band around the allocation watermark.
|
|
8908
|
+
*
|
|
8909
|
+
* NArk needs no analogue because it *is* the address issuer: it persists a
|
|
8910
|
+
* contract row at derivation time, so its watched set is a superset of
|
|
8911
|
+
* every address it ever advertised. This SDK, when a third party issues
|
|
8912
|
+
* addresses from the shared seed, cannot observe those allocations at all —
|
|
8913
|
+
* the window is how a non-issuer compensates.
|
|
8914
|
+
*
|
|
8915
|
+
* Entries are registered with the watcher but NOT persisted: they become
|
|
8916
|
+
* repository rows only once funded (see {@link promoteLookAheadHits}).
|
|
8917
|
+
*
|
|
8918
|
+
* Each index contributes every {@link Discoverable.candidatesAt} candidate —
|
|
8919
|
+
* the same set `restore()`'s gap scan probes, since the wallet cannot know
|
|
8920
|
+
* which variant a third-party issuer handed out.
|
|
8921
|
+
*/
|
|
8922
|
+
async ensureLookAhead() {
|
|
8923
|
+
const lookAhead = this.config.lookAhead;
|
|
8924
|
+
if (!lookAhead) return;
|
|
8925
|
+
const watermark = await lookAhead.currentWatermark();
|
|
8926
|
+
const from = Math.max(0, watermark - lookAhead.size);
|
|
8927
|
+
const to = watermark + lookAhead.size;
|
|
8928
|
+
const deps = lookAhead.candidateDeps();
|
|
8929
|
+
const handlers = chunkIEMPH7J6_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkIEMPH7J6_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
8930
|
+
const band = /* @__PURE__ */ new Map();
|
|
8931
|
+
for (let index = from; index <= to; index++) {
|
|
8932
|
+
const descriptor = lookAhead.materialize(index);
|
|
8933
|
+
for (const handler of handlers) {
|
|
8934
|
+
for (const candidate of handler.candidatesAt(index, descriptor, deps)) {
|
|
8935
|
+
if (band.has(candidate.script)) continue;
|
|
8936
|
+
band.set(candidate.script, {
|
|
8937
|
+
index,
|
|
8938
|
+
params: {
|
|
8939
|
+
...candidate,
|
|
8940
|
+
...chunkIEMPH7J6_cjs.speculativeReceiveMetadata(descriptor)
|
|
8941
|
+
}
|
|
8942
|
+
});
|
|
8943
|
+
}
|
|
8944
|
+
}
|
|
8945
|
+
}
|
|
8946
|
+
await this.watcher.withCoalescedSubscription(async () => {
|
|
8947
|
+
const persisted = await this.config.contractRepository.getContracts({
|
|
8948
|
+
script: [...band.keys()]
|
|
8949
|
+
});
|
|
8950
|
+
const persistedScripts = new Set(persisted.map((c) => c.script));
|
|
8951
|
+
for (const [script, { index, params }] of band) {
|
|
8952
|
+
if (persistedScripts.has(script)) {
|
|
8953
|
+
this.lookAheadEntries.delete(script);
|
|
8954
|
+
continue;
|
|
8955
|
+
}
|
|
8956
|
+
if (this.lookAheadEntries.has(script)) continue;
|
|
8957
|
+
const contract = toWatchOnlyContract(params);
|
|
8958
|
+
this.lookAheadEntries.set(script, {
|
|
8959
|
+
index,
|
|
8960
|
+
params,
|
|
8961
|
+
contract,
|
|
8962
|
+
catchUpPending: true
|
|
8963
|
+
});
|
|
8964
|
+
await this.watcher.addContract(contract);
|
|
8965
|
+
}
|
|
8966
|
+
const stale = [...this.lookAheadEntries.keys()].filter((s) => !band.has(s));
|
|
8967
|
+
if (stale.length > 0) {
|
|
8968
|
+
const rows = await this.config.contractRepository.getContracts({ script: stale });
|
|
8969
|
+
const nowPersisted = new Set(rows.map((c) => c.script));
|
|
8970
|
+
for (const script of stale) {
|
|
8971
|
+
this.lookAheadEntries.delete(script);
|
|
8972
|
+
if (!nowPersisted.has(script)) await this.watcher.removeContract(script);
|
|
8973
|
+
}
|
|
8974
|
+
}
|
|
8975
|
+
});
|
|
8976
|
+
await this.runLookAheadCatchUp();
|
|
8977
|
+
}
|
|
8978
|
+
/**
|
|
8979
|
+
* One-time full-history sync for speculative entries the manager has not
|
|
8980
|
+
* successfully caught up on yet.
|
|
8981
|
+
*
|
|
8982
|
+
* Every normal sync uses the cursor-derived delta window and SSE only
|
|
8983
|
+
* delivers events after a script is subscribed, so a script first
|
|
8984
|
+
* registered after its funding time would otherwise be skipped forever
|
|
8985
|
+
* (upgrade migration, or a band that slid over an already-funded index).
|
|
8986
|
+
* The entries are passed as in-memory contracts because `refreshVtxos`
|
|
8987
|
+
* resolves scripts through the repository, where they deliberately do not
|
|
8988
|
+
* exist. Targeted + explicitly windowed, so the global cursor stays put.
|
|
8989
|
+
*/
|
|
8990
|
+
async runLookAheadCatchUp() {
|
|
8991
|
+
const pending = [...this.lookAheadEntries.values()].filter((e) => e.catchUpPending);
|
|
8992
|
+
if (pending.length === 0) return;
|
|
8993
|
+
try {
|
|
8994
|
+
await this.syncContracts({
|
|
8995
|
+
contracts: pending.map((e) => e.contract),
|
|
8996
|
+
window: { after: 0 }
|
|
8997
|
+
});
|
|
8998
|
+
for (const entry of pending) entry.catchUpPending = false;
|
|
8999
|
+
} catch (err) {
|
|
9000
|
+
if (!isRetryableProviderError(err)) throw err;
|
|
9001
|
+
this.markSyncDegraded(err);
|
|
9002
|
+
}
|
|
9003
|
+
}
|
|
9004
|
+
/**
|
|
9005
|
+
* Promote every look-ahead entry funded by `vtxos` into a real repository
|
|
9006
|
+
* row, returning the persisted rows keyed by script.
|
|
9007
|
+
*
|
|
9008
|
+
* MUST run on each raw indexer fetch before `annotateVtxos`:
|
|
9009
|
+
* `extendVirtualCoinForContract` throws when a VTXO's script has no
|
|
9010
|
+
* contract row, so a funded window entry has to be persisted before its
|
|
9011
|
+
* VTXOs are annotated and saved. Callers also swap the returned rows into
|
|
9012
|
+
* the local contract maps they built pre-promotion, so `saveVtxosForContract`
|
|
9013
|
+
* and `onVtxosPersisted` never see the synthetic watcher object.
|
|
9014
|
+
*/
|
|
9015
|
+
async promoteLookAheadHits(vtxos) {
|
|
9016
|
+
const promoted = /* @__PURE__ */ new Map();
|
|
9017
|
+
if (this.lookAheadEntries.size === 0) return promoted;
|
|
9018
|
+
const hits = /* @__PURE__ */ new Map();
|
|
9019
|
+
for (const vtxo of vtxos) {
|
|
9020
|
+
const entry = this.lookAheadEntries.get(vtxo.script);
|
|
9021
|
+
if (entry) hits.set(vtxo.script, entry);
|
|
9022
|
+
}
|
|
9023
|
+
if (hits.size === 0) return promoted;
|
|
9024
|
+
for (const [script, entry] of hits) {
|
|
9025
|
+
promoted.set(script, await this.persistAndWatchContract(entry.params));
|
|
9026
|
+
await this.config.lookAhead?.onPromoted?.(entry.index);
|
|
9027
|
+
}
|
|
9028
|
+
this.requestLookAheadDrain();
|
|
9029
|
+
return promoted;
|
|
9030
|
+
}
|
|
8851
9031
|
/**
|
|
8852
9032
|
* Create and register a new contract.
|
|
8853
9033
|
*
|
|
@@ -8893,7 +9073,12 @@ var ContractManager = class _ContractManager {
|
|
|
8893
9073
|
* `persisted` is `true`.
|
|
8894
9074
|
*/
|
|
8895
9075
|
async upsertContract(params) {
|
|
8896
|
-
const
|
|
9076
|
+
const result = await this.upsertContractRow(params);
|
|
9077
|
+
this.lookAheadEntries.delete(params.script);
|
|
9078
|
+
return result;
|
|
9079
|
+
}
|
|
9080
|
+
async upsertContractRow(params) {
|
|
9081
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(params.type);
|
|
8897
9082
|
if (!handler) {
|
|
8898
9083
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
8899
9084
|
}
|
|
@@ -8993,7 +9178,7 @@ var ContractManager = class _ContractManager {
|
|
|
8993
9178
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
8994
9179
|
);
|
|
8995
9180
|
}
|
|
8996
|
-
const registered =
|
|
9181
|
+
const registered = chunkIEMPH7J6_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkIEMPH7J6_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
8997
9182
|
const discoverables = [
|
|
8998
9183
|
...registered.filter((h) => h.type === "boarding"),
|
|
8999
9184
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -9234,7 +9419,7 @@ var ContractManager = class _ContractManager {
|
|
|
9234
9419
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
9235
9420
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9236
9421
|
if (!contract) return [];
|
|
9237
|
-
const handler =
|
|
9422
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
9238
9423
|
if (!handler) return [];
|
|
9239
9424
|
const script = handler.createScript(contract.params);
|
|
9240
9425
|
const context = {
|
|
@@ -9254,7 +9439,7 @@ var ContractManager = class _ContractManager {
|
|
|
9254
9439
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
9255
9440
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9256
9441
|
if (!contract) return [];
|
|
9257
|
-
const handler =
|
|
9442
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
9258
9443
|
if (!handler) return [];
|
|
9259
9444
|
const script = handler.createScript(contract.params);
|
|
9260
9445
|
const context = {
|
|
@@ -9382,6 +9567,7 @@ var ContractManager = class _ContractManager {
|
|
|
9382
9567
|
}
|
|
9383
9568
|
break;
|
|
9384
9569
|
case "connection_reset":
|
|
9570
|
+
await this.scheduleLookAheadDrain();
|
|
9385
9571
|
await this.reconcileWatched();
|
|
9386
9572
|
this.markSyncOnline();
|
|
9387
9573
|
break;
|
|
@@ -9441,11 +9627,16 @@ var ContractManager = class _ContractManager {
|
|
|
9441
9627
|
contracts.map((c) => c.script),
|
|
9442
9628
|
{ pendingOnly: true }
|
|
9443
9629
|
);
|
|
9630
|
+
for (const [script, contract] of await this.promoteLookAheadHits(vtxos)) {
|
|
9631
|
+
scriptToContract.set(script, contract);
|
|
9632
|
+
}
|
|
9444
9633
|
const owned = vtxos.filter((v) => scriptToContract.has(v.script));
|
|
9445
9634
|
const annotated = await this.annotateVtxos(owned);
|
|
9446
9635
|
const byContract = /* @__PURE__ */ new Map();
|
|
9636
|
+
const contractByAddress = /* @__PURE__ */ new Map();
|
|
9447
9637
|
for (const vtxo of annotated) {
|
|
9448
9638
|
const contract = scriptToContract.get(vtxo.script);
|
|
9639
|
+
contractByAddress.set(contract.address, contract);
|
|
9449
9640
|
let arr = byContract.get(contract.address);
|
|
9450
9641
|
if (!arr) {
|
|
9451
9642
|
arr = [];
|
|
@@ -9457,7 +9648,7 @@ var ContractManager = class _ContractManager {
|
|
|
9457
9648
|
});
|
|
9458
9649
|
}
|
|
9459
9650
|
for (const [addr, contractVtxos] of byContract) {
|
|
9460
|
-
const contract =
|
|
9651
|
+
const contract = contractByAddress.get(addr);
|
|
9461
9652
|
const filtered = warnAndFilterVtxosForScript(
|
|
9462
9653
|
contractVtxos,
|
|
9463
9654
|
contract.script,
|
|
@@ -9478,11 +9669,15 @@ var ContractManager = class _ContractManager {
|
|
|
9478
9669
|
}
|
|
9479
9670
|
}
|
|
9480
9671
|
async fetchContractVxosFromIndexer(contracts, pageSize, syncWindow) {
|
|
9481
|
-
const
|
|
9672
|
+
const { vtxosByScript, promoted } = await this.fetchContractVtxosBulk(
|
|
9673
|
+
contracts,
|
|
9674
|
+
pageSize,
|
|
9675
|
+
syncWindow
|
|
9676
|
+
);
|
|
9482
9677
|
const result = /* @__PURE__ */ new Map();
|
|
9483
|
-
for (const [contractScript, vtxos] of
|
|
9678
|
+
for (const [contractScript, vtxos] of vtxosByScript) {
|
|
9484
9679
|
result.set(contractScript, vtxos);
|
|
9485
|
-
const contract = contracts.find((c) => c.script === contractScript);
|
|
9680
|
+
const contract = promoted.get(contractScript) ?? contracts.find((c) => c.script === contractScript);
|
|
9486
9681
|
if (contract) {
|
|
9487
9682
|
const filtered = warnAndFilterVtxosForScript(
|
|
9488
9683
|
vtxos,
|
|
@@ -9510,7 +9705,7 @@ var ContractManager = class _ContractManager {
|
|
|
9510
9705
|
}
|
|
9511
9706
|
async fetchContractVtxosBulk(contracts, pageSize = chunkE7HB3GKK_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9512
9707
|
if (contracts.length === 0) {
|
|
9513
|
-
return /* @__PURE__ */ new Map();
|
|
9708
|
+
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
9514
9709
|
}
|
|
9515
9710
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
9516
9711
|
const result = new Map(
|
|
@@ -9529,6 +9724,10 @@ var ContractManager = class _ContractManager {
|
|
|
9529
9724
|
contracts.map((c) => c.script),
|
|
9530
9725
|
{ ...windowOpts, pageSize }
|
|
9531
9726
|
);
|
|
9727
|
+
const promoted = await this.promoteLookAheadHits(vtxos);
|
|
9728
|
+
for (const [script, contract] of promoted) {
|
|
9729
|
+
scriptToContract.set(script, contract);
|
|
9730
|
+
}
|
|
9532
9731
|
const owned = vtxos.filter((v) => scriptToContract.has(v.script));
|
|
9533
9732
|
const annotated = await this.annotateVtxos(owned);
|
|
9534
9733
|
for (const vtxo of annotated) {
|
|
@@ -9537,7 +9736,7 @@ var ContractManager = class _ContractManager {
|
|
|
9537
9736
|
contractScript: vtxo.script
|
|
9538
9737
|
});
|
|
9539
9738
|
}
|
|
9540
|
-
return result;
|
|
9739
|
+
return { vtxosByScript: result, promoted };
|
|
9541
9740
|
}
|
|
9542
9741
|
/**
|
|
9543
9742
|
* Dispose of the ContractManager and release all resources.
|
|
@@ -9551,6 +9750,7 @@ var ContractManager = class _ContractManager {
|
|
|
9551
9750
|
this.stopWatcherFn?.();
|
|
9552
9751
|
this.stopWatcherFn = void 0;
|
|
9553
9752
|
this.eventCallbacks.clear();
|
|
9753
|
+
this.lookAheadEntries.clear();
|
|
9554
9754
|
this.initialized = false;
|
|
9555
9755
|
}
|
|
9556
9756
|
/**
|
|
@@ -9616,6 +9816,15 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9616
9816
|
if (settings.lastIndexUsed === void 0) return void 0;
|
|
9617
9817
|
return this.materializeDescriptorAt(settings.lastIndexUsed);
|
|
9618
9818
|
}
|
|
9819
|
+
/**
|
|
9820
|
+
* The most recently allocated index, or `undefined` when nothing has ever
|
|
9821
|
+
* been allocated on this repo. Read-only peek at the watermark that
|
|
9822
|
+
* {@link getNextSigningDescriptor} advances.
|
|
9823
|
+
*/
|
|
9824
|
+
async getLastIndexUsed() {
|
|
9825
|
+
const state = await this.walletRepository.getWalletState();
|
|
9826
|
+
return this.parseSettings(state ?? {}).lastIndexUsed;
|
|
9827
|
+
}
|
|
9619
9828
|
/**
|
|
9620
9829
|
* Monotonically advance the allocation watermark so the next
|
|
9621
9830
|
* `getNextSigningDescriptor()` skips indices discovered by a restore
|
|
@@ -9677,7 +9886,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9677
9886
|
*/
|
|
9678
9887
|
materializeDescriptorAt(index) {
|
|
9679
9888
|
const descriptor = this.identity.descriptor;
|
|
9680
|
-
const network =
|
|
9889
|
+
const network = chunkIEMPH7J6_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9681
9890
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9682
9891
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9683
9892
|
if (!keyInfo?.keyExpression) {
|
|
@@ -9821,7 +10030,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9821
10030
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
9822
10031
|
if (!provider) return void 0;
|
|
9823
10032
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
9824
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
10033
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
9825
10034
|
const factoryOpts = {
|
|
9826
10035
|
walletRepository: setup.walletRepository,
|
|
9827
10036
|
contractRepository: setup.contractRepository,
|
|
@@ -9998,63 +10207,29 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9998
10207
|
*/
|
|
9999
10208
|
async rotate(wallet) {
|
|
10000
10209
|
const descriptor = await this.provider.getNextSigningDescriptor();
|
|
10001
|
-
const
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10210
|
+
const { tapscript: newTapscript, params } = buildReceiveContract(
|
|
10211
|
+
wallet.offchainTapscript,
|
|
10212
|
+
descriptor,
|
|
10213
|
+
wallet.network.hrp);
|
|
10214
|
+
const newScript = params.script;
|
|
10005
10215
|
const manager = await wallet.getContractManager();
|
|
10006
|
-
|
|
10007
|
-
const csvTimelockStr = chunkE7HB3GKK_cjs.timelockToSequence(csvTimelock).toString();
|
|
10008
|
-
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
10009
|
-
const baseParams = {
|
|
10010
|
-
script: newScript,
|
|
10011
|
-
address: newAddress,
|
|
10012
|
-
state: "active",
|
|
10013
|
-
// Persist the materialized signing descriptor alongside the
|
|
10014
|
-
// source tag. The wallet's spending paths read this at sign
|
|
10015
|
-
// time to route inputs locked by a rotated pubkey through
|
|
10016
|
-
// `DescriptorProvider.signWithDescriptor` instead of the
|
|
10017
|
-
// identity's index-0 key. Without it, post-rotation sends
|
|
10018
|
-
// produce unsigned PSBTs that the server rejects with
|
|
10019
|
-
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
10020
|
-
metadata: {
|
|
10021
|
-
source: chunkLJQ2VQBE_cjs.WALLET_RECEIVE_SOURCE,
|
|
10022
|
-
signingDescriptor: descriptor
|
|
10023
|
-
}
|
|
10024
|
-
};
|
|
10025
|
-
if (newTapscript instanceof chunkLJQ2VQBE_cjs.DelegateVtxo.Script) {
|
|
10026
|
-
await manager.createContract({
|
|
10027
|
-
...baseParams,
|
|
10028
|
-
type: "delegate",
|
|
10029
|
-
params: {
|
|
10030
|
-
pubKey: base.hex.encode(pubKey),
|
|
10031
|
-
serverPubKey: serverPubKeyHex,
|
|
10032
|
-
delegatePubKey: base.hex.encode(newTapscript.options.delegatePubKey),
|
|
10033
|
-
csvTimelock: csvTimelockStr
|
|
10034
|
-
}
|
|
10035
|
-
});
|
|
10036
|
-
} else {
|
|
10037
|
-
await manager.createContract({
|
|
10038
|
-
...baseParams,
|
|
10039
|
-
type: "default",
|
|
10040
|
-
params: {
|
|
10041
|
-
pubKey: base.hex.encode(pubKey),
|
|
10042
|
-
serverPubKey: serverPubKeyHex,
|
|
10043
|
-
csvTimelock: csvTimelockStr
|
|
10044
|
-
}
|
|
10045
|
-
});
|
|
10046
|
-
}
|
|
10216
|
+
await manager.createContract(params);
|
|
10047
10217
|
wallet.setOffchainTapscriptForRotation(newTapscript);
|
|
10048
10218
|
const previousTagged = this.currentTaggedScript;
|
|
10049
10219
|
if (previousTagged !== void 0 && previousTagged !== newScript) {
|
|
10050
10220
|
await manager.setContractState(previousTagged, "inactive");
|
|
10051
10221
|
}
|
|
10052
10222
|
this.currentTaggedScript = newScript;
|
|
10223
|
+
try {
|
|
10224
|
+
await manager.refillLookAhead();
|
|
10225
|
+
} catch (err) {
|
|
10226
|
+
this.logger.error("WalletReceiveRotator: look-ahead refill failed", err);
|
|
10227
|
+
}
|
|
10053
10228
|
}
|
|
10054
10229
|
};
|
|
10055
10230
|
function deriveLeafPubkey(descriptor) {
|
|
10056
10231
|
try {
|
|
10057
|
-
return
|
|
10232
|
+
return chunkIEMPH7J6_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
10058
10233
|
} catch (e) {
|
|
10059
10234
|
throw new NonRangeableDescriptorError(
|
|
10060
10235
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -10062,11 +10237,50 @@ function deriveLeafPubkey(descriptor) {
|
|
|
10062
10237
|
);
|
|
10063
10238
|
}
|
|
10064
10239
|
}
|
|
10240
|
+
function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
10241
|
+
const pubKey = deriveLeafPubkey(descriptor);
|
|
10242
|
+
const tapscript = rebuildTapscript(current, pubKey);
|
|
10243
|
+
const serverPubKey = tapscript.options.serverPubKey;
|
|
10244
|
+
const csvTimelock = chunkE7HB3GKK_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
10245
|
+
const base$1 = {
|
|
10246
|
+
script: base.hex.encode(tapscript.pkScript),
|
|
10247
|
+
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
10248
|
+
state: "active",
|
|
10249
|
+
// The materialized signing descriptor is read at sign time to route
|
|
10250
|
+
// inputs locked by a rotated pubkey through
|
|
10251
|
+
// `DescriptorProvider.signWithDescriptor` instead of the identity's
|
|
10252
|
+
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
10253
|
+
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
10254
|
+
metadata: {
|
|
10255
|
+
...{ source: chunkIEMPH7J6_cjs.WALLET_RECEIVE_SOURCE },
|
|
10256
|
+
signingDescriptor: descriptor
|
|
10257
|
+
}
|
|
10258
|
+
};
|
|
10259
|
+
const params = tapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? {
|
|
10260
|
+
...base$1,
|
|
10261
|
+
type: "delegate",
|
|
10262
|
+
params: {
|
|
10263
|
+
pubKey: base.hex.encode(pubKey),
|
|
10264
|
+
serverPubKey: base.hex.encode(serverPubKey),
|
|
10265
|
+
delegatePubKey: base.hex.encode(tapscript.options.delegatePubKey),
|
|
10266
|
+
csvTimelock
|
|
10267
|
+
}
|
|
10268
|
+
} : {
|
|
10269
|
+
...base$1,
|
|
10270
|
+
type: "default",
|
|
10271
|
+
params: {
|
|
10272
|
+
pubKey: base.hex.encode(pubKey),
|
|
10273
|
+
serverPubKey: base.hex.encode(serverPubKey),
|
|
10274
|
+
csvTimelock
|
|
10275
|
+
}
|
|
10276
|
+
};
|
|
10277
|
+
return { tapscript, params };
|
|
10278
|
+
}
|
|
10065
10279
|
function rebuildTapscript(current, pubKey) {
|
|
10066
|
-
if (current instanceof
|
|
10067
|
-
return new
|
|
10280
|
+
if (current instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script) {
|
|
10281
|
+
return new chunkIEMPH7J6_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
10068
10282
|
}
|
|
10069
|
-
return new
|
|
10283
|
+
return new chunkIEMPH7J6_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
10070
10284
|
}
|
|
10071
10285
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
10072
10286
|
const candidates = await contractRepository.getContracts({
|
|
@@ -10075,7 +10289,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
10075
10289
|
});
|
|
10076
10290
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
10077
10291
|
const matching = candidates.filter(
|
|
10078
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10292
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkIEMPH7J6_cjs.WALLET_RECEIVE_SOURCE
|
|
10079
10293
|
).sort((a, b) => {
|
|
10080
10294
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10081
10295
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10264,6 +10478,7 @@ function extractArkProviderUrl(provider) {
|
|
|
10264
10478
|
const serverUrl = provider.serverUrl;
|
|
10265
10479
|
return typeof serverUrl === "string" && serverUrl.length > 0 ? serverUrl : void 0;
|
|
10266
10480
|
}
|
|
10481
|
+
var DEFAULT_LOOK_AHEAD_WINDOW = 20;
|
|
10267
10482
|
var MAINNET_UNILATERAL_EXIT_DELAY = 605184n;
|
|
10268
10483
|
function toXOnlyPubKey(pubkey) {
|
|
10269
10484
|
if (pubkey.length === 33) return pubkey.slice(1);
|
|
@@ -10297,7 +10512,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10297
10512
|
state: "active"
|
|
10298
10513
|
});
|
|
10299
10514
|
const newest = candidates.filter(
|
|
10300
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10515
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkIEMPH7J6_cjs.WALLET_RECEIVE_SOURCE
|
|
10301
10516
|
).sort((a, b) => {
|
|
10302
10517
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10303
10518
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10305,7 +10520,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10305
10520
|
if (!newest?.params.pubKey) return baseline;
|
|
10306
10521
|
try {
|
|
10307
10522
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
10308
|
-
return new
|
|
10523
|
+
return new chunkIEMPH7J6_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
10309
10524
|
} catch (e) {
|
|
10310
10525
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
10311
10526
|
return baseline;
|
|
@@ -10625,7 +10840,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10625
10840
|
*/
|
|
10626
10841
|
static async setupWalletConfig(config, pubKey) {
|
|
10627
10842
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10628
|
-
const arkProvider = config.arkProvider || new
|
|
10843
|
+
const arkProvider = config.arkProvider || new chunkFZPYPEWN_cjs.RestArkProvider(arkadeServerUrl);
|
|
10629
10844
|
let indexerProvider = config.indexerProvider;
|
|
10630
10845
|
if (!indexerProvider) {
|
|
10631
10846
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10642,7 +10857,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10642
10857
|
indexerUrl = arkadeServerUrl;
|
|
10643
10858
|
}
|
|
10644
10859
|
}
|
|
10645
|
-
indexerProvider = new
|
|
10860
|
+
indexerProvider = new chunkFZPYPEWN_cjs.RestIndexerProvider(indexerUrl);
|
|
10646
10861
|
}
|
|
10647
10862
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10648
10863
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10698,8 +10913,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10698
10913
|
serverPubKey,
|
|
10699
10914
|
csvTimelock: exitTimelock
|
|
10700
10915
|
};
|
|
10701
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10702
|
-
const boardingTapscript =
|
|
10916
|
+
const offchainTapscript = !delegatePubKey ? new chunkIEMPH7J6_cjs.DefaultVtxo.Script(offchainOptions) : new chunkIEMPH7J6_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
10917
|
+
const boardingTapscript = chunkIEMPH7J6_cjs.BoardingContractHandler.createScript({
|
|
10703
10918
|
pubKey: base.hex.encode(pubKey),
|
|
10704
10919
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10705
10920
|
csvTimelock: chunkE7HB3GKK_cjs.timelockToSequence(boardingTimelock).toString()
|
|
@@ -11043,9 +11258,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11043
11258
|
async getBoardingTapscripts(allowedSigners) {
|
|
11044
11259
|
const byScript = /* @__PURE__ */ new Map();
|
|
11045
11260
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
11046
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
11261
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkIEMPH7J6_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11047
11262
|
add(
|
|
11048
|
-
new
|
|
11263
|
+
new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11049
11264
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
11050
11265
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
11051
11266
|
csvTimelock: boardingCsv
|
|
@@ -11060,7 +11275,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11060
11275
|
for (const c of boardingContracts) {
|
|
11061
11276
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
11062
11277
|
try {
|
|
11063
|
-
add(
|
|
11278
|
+
add(chunkIEMPH7J6_cjs.BoardingContractHandler.createScript(c.params));
|
|
11064
11279
|
} catch (e) {
|
|
11065
11280
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
11066
11281
|
}
|
|
@@ -11262,7 +11477,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11262
11477
|
});
|
|
11263
11478
|
for (const contract of contracts) {
|
|
11264
11479
|
if (map.has(contract.script)) continue;
|
|
11265
|
-
const handler =
|
|
11480
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
11266
11481
|
if (handler) {
|
|
11267
11482
|
const script = handler.createScript(contract.params);
|
|
11268
11483
|
map.set(contract.script, script);
|
|
@@ -11319,6 +11534,14 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11319
11534
|
this._contractManagerInitializing = void 0;
|
|
11320
11535
|
}
|
|
11321
11536
|
}
|
|
11537
|
+
/**
|
|
11538
|
+
* HD look-ahead configuration for the contract manager. Readonly wallets
|
|
11539
|
+
* have no descriptor provider, hence no watermark to look ahead of.
|
|
11540
|
+
* @see Wallet.lookAheadConfig
|
|
11541
|
+
*/
|
|
11542
|
+
lookAheadConfig() {
|
|
11543
|
+
return void 0;
|
|
11544
|
+
}
|
|
11322
11545
|
async initializeContractManager() {
|
|
11323
11546
|
const virtualTxRepository = this.virtualTxRepository;
|
|
11324
11547
|
let onVtxosPersisted;
|
|
@@ -11353,10 +11576,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11353
11576
|
intentRepository: this.intentRepository,
|
|
11354
11577
|
onVtxosPersisted,
|
|
11355
11578
|
onVtxosSpent,
|
|
11356
|
-
watcherConfig: this.watcherConfig
|
|
11579
|
+
watcherConfig: this.watcherConfig,
|
|
11580
|
+
lookAhead: this.lookAheadConfig()
|
|
11357
11581
|
});
|
|
11358
11582
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
11359
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11583
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11360
11584
|
const baselineSigners = [
|
|
11361
11585
|
this.offchainTapscript.options.serverPubKey,
|
|
11362
11586
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -11365,7 +11589,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11365
11589
|
for (const serverPubKey of baselineSigners) {
|
|
11366
11590
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
11367
11591
|
const csvTimelockStr = chunkE7HB3GKK_cjs.timelockToSequence(csvTimelock).toString();
|
|
11368
|
-
const defaultScript = new
|
|
11592
|
+
const defaultScript = new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11369
11593
|
pubKey: baselinePubkey,
|
|
11370
11594
|
serverPubKey,
|
|
11371
11595
|
csvTimelock
|
|
@@ -11386,7 +11610,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11386
11610
|
});
|
|
11387
11611
|
}
|
|
11388
11612
|
if (delegatePubKey) {
|
|
11389
|
-
const delegateScript = new
|
|
11613
|
+
const delegateScript = new chunkIEMPH7J6_cjs.DelegateVtxo.Script({
|
|
11390
11614
|
pubKey: baselinePubkey,
|
|
11391
11615
|
serverPubKey,
|
|
11392
11616
|
delegatePubKey,
|
|
@@ -11410,9 +11634,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11410
11634
|
}
|
|
11411
11635
|
}
|
|
11412
11636
|
}
|
|
11413
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11637
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkIEMPH7J6_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11414
11638
|
for (const serverPubKey of baselineSigners) {
|
|
11415
|
-
const baselineBoarding = new
|
|
11639
|
+
const baselineBoarding = new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11416
11640
|
pubKey: baselinePubkey,
|
|
11417
11641
|
serverPubKey,
|
|
11418
11642
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11447,7 +11671,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11447
11671
|
}
|
|
11448
11672
|
};
|
|
11449
11673
|
var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
11450
|
-
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig, delegateProvider, watcherConfig, settlementConfig, walletContractTimelocks, receiveRotator, descriptorProvider) {
|
|
11674
|
+
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig, delegateProvider, watcherConfig, settlementConfig, walletContractTimelocks, receiveRotator, descriptorProvider, lookAheadWindow) {
|
|
11451
11675
|
super(
|
|
11452
11676
|
identity,
|
|
11453
11677
|
network,
|
|
@@ -11487,6 +11711,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11487
11711
|
this._serverUnrollScript = serverUnrollScript;
|
|
11488
11712
|
this._receiveRotator = receiveRotator;
|
|
11489
11713
|
this._descriptorProvider = descriptorProvider;
|
|
11714
|
+
this._lookAheadWindow = lookAheadWindow ?? DEFAULT_LOOK_AHEAD_WINDOW;
|
|
11490
11715
|
this._signerRouter = new InputSignerRouter({
|
|
11491
11716
|
identity,
|
|
11492
11717
|
contractRepository,
|
|
@@ -11559,6 +11784,48 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11559
11784
|
* paths only ever take the identity-sign branch.
|
|
11560
11785
|
*/
|
|
11561
11786
|
_descriptorProvider;
|
|
11787
|
+
/** Per-side width of the HD look-ahead band. @see WalletConfig.lookAheadWindow */
|
|
11788
|
+
_lookAheadWindow;
|
|
11789
|
+
/**
|
|
11790
|
+
* Watch a band of missing offchain receive scripts around the HD watermark
|
|
11791
|
+
* so payments to an externally-issued address land without a `restore()`.
|
|
11792
|
+
* Only HD wallets have a watermark to look ahead of; static / `auto`
|
|
11793
|
+
* wallets keep a single index-0 receive address, so the feature stays off.
|
|
11794
|
+
*
|
|
11795
|
+
* `candidateDeps` is read at refill time, so a band rebuilt after
|
|
11796
|
+
* {@link rotateServerSigner} fans the active signer set (persisted
|
|
11797
|
+
* old-signer rows stay watched through the repository).
|
|
11798
|
+
*/
|
|
11799
|
+
lookAheadConfig() {
|
|
11800
|
+
const provider = this._descriptorProvider;
|
|
11801
|
+
if (!(provider instanceof HDDescriptorProvider)) return void 0;
|
|
11802
|
+
return {
|
|
11803
|
+
size: this._lookAheadWindow,
|
|
11804
|
+
currentWatermark: async () => await provider.getLastIndexUsed() ?? -1,
|
|
11805
|
+
materialize: (index) => provider.materializeDescriptorAt(index),
|
|
11806
|
+
candidateDeps: () => this.receiveCandidateDeps(),
|
|
11807
|
+
onPromoted: (index) => provider.advanceLastIndexUsed(index)
|
|
11808
|
+
};
|
|
11809
|
+
}
|
|
11810
|
+
/**
|
|
11811
|
+
* Every axis an externally issued receive script could be anchored to, not
|
|
11812
|
+
* just the wallet's own current shape: an issuer sharing the seed (NArk, a
|
|
11813
|
+
* merchant backend) picks its own contract type, and a band derived from one
|
|
11814
|
+
* variant silently misses the rest until a `restore()`.
|
|
11815
|
+
*
|
|
11816
|
+
* Read from cached state, not a fresh `getInfo`, to stay synchronous and
|
|
11817
|
+
* offline-safe; {@link refreshDeprecatedSigners} and
|
|
11818
|
+
* {@link rotateServerSigner} keep it current and re-trigger a refill.
|
|
11819
|
+
*/
|
|
11820
|
+
receiveCandidateDeps() {
|
|
11821
|
+
return {
|
|
11822
|
+
network: { hrp: this.network.hrp },
|
|
11823
|
+
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
11824
|
+
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
11825
|
+
csvTimelocks: this.walletContractTimelocks,
|
|
11826
|
+
delegatePubKey: this.offchainTapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
11827
|
+
};
|
|
11828
|
+
}
|
|
11562
11829
|
_signerRouter;
|
|
11563
11830
|
/**
|
|
11564
11831
|
* @internal Sole write path for `offchainTapscript` after construction.
|
|
@@ -11648,12 +11915,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11648
11915
|
return this.getBoardingAddress();
|
|
11649
11916
|
}
|
|
11650
11917
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11651
|
-
const pubKey =
|
|
11652
|
-
const newBoarding = new
|
|
11918
|
+
const pubKey = chunkIEMPH7J6_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11919
|
+
const newBoarding = new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11653
11920
|
...this._boardingTapscript.options,
|
|
11654
11921
|
pubKey
|
|
11655
11922
|
});
|
|
11656
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11923
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunkIEMPH7J6_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11657
11924
|
const manager = await this.getContractManager();
|
|
11658
11925
|
await manager.createContract({
|
|
11659
11926
|
type: "boarding",
|
|
@@ -11666,11 +11933,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11666
11933
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11667
11934
|
state: "active",
|
|
11668
11935
|
metadata: {
|
|
11669
|
-
source:
|
|
11936
|
+
source: chunkIEMPH7J6_cjs.WALLET_RECEIVE_SOURCE,
|
|
11670
11937
|
signingDescriptor: descriptor
|
|
11671
11938
|
}
|
|
11672
11939
|
});
|
|
11673
11940
|
this.setBoardingTapscriptForRotation(newBoarding);
|
|
11941
|
+
try {
|
|
11942
|
+
await manager.refillLookAhead();
|
|
11943
|
+
} catch (e) {
|
|
11944
|
+
console.warn("look-ahead refill after boarding allocation failed", e);
|
|
11945
|
+
}
|
|
11674
11946
|
return newBoarding.onchainAddress(this.network);
|
|
11675
11947
|
}
|
|
11676
11948
|
/**
|
|
@@ -11733,21 +12005,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11733
12005
|
const [currentBoardingRow] = await manager.getContracts({
|
|
11734
12006
|
script: currentBoardingScript
|
|
11735
12007
|
});
|
|
11736
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
12008
|
+
const newOffchain = this.offchainTapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? new chunkIEMPH7J6_cjs.DelegateVtxo.Script({
|
|
11737
12009
|
...this.offchainTapscript.options,
|
|
11738
12010
|
serverPubKey: xonly
|
|
11739
|
-
}) : new
|
|
12011
|
+
}) : new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11740
12012
|
...this.offchainTapscript.options,
|
|
11741
12013
|
serverPubKey: xonly
|
|
11742
12014
|
});
|
|
11743
|
-
const newBoarding = new
|
|
12015
|
+
const newBoarding = new chunkIEMPH7J6_cjs.DefaultVtxo.Script({
|
|
11744
12016
|
...this._boardingTapscript.options,
|
|
11745
12017
|
serverPubKey: xonly
|
|
11746
12018
|
});
|
|
11747
12019
|
const offchainCsv = chunkE7HB3GKK_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
11748
12020
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
11749
12021
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
11750
|
-
if (newOffchain instanceof
|
|
12022
|
+
if (newOffchain instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script) {
|
|
11751
12023
|
await manager.createContract({
|
|
11752
12024
|
type: "delegate",
|
|
11753
12025
|
params: {
|
|
@@ -11775,7 +12047,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11775
12047
|
metadata: currentOffchainRow?.metadata
|
|
11776
12048
|
});
|
|
11777
12049
|
}
|
|
11778
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
12050
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkIEMPH7J6_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11779
12051
|
await manager.createContract({
|
|
11780
12052
|
type: "boarding",
|
|
11781
12053
|
params: {
|
|
@@ -11792,6 +12064,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11792
12064
|
this.setBoardingTapscriptForRotation(newBoarding);
|
|
11793
12065
|
this.setArkServerPublicKeyForRotation(xonly);
|
|
11794
12066
|
this.setServerUnrollScriptForRotation(newServerUnrollScript);
|
|
12067
|
+
try {
|
|
12068
|
+
await manager.refillLookAhead();
|
|
12069
|
+
} catch (e) {
|
|
12070
|
+
console.warn("look-ahead refill after server-signer rotation failed", e);
|
|
12071
|
+
}
|
|
11795
12072
|
}
|
|
11796
12073
|
/**
|
|
11797
12074
|
* Async mutex that serializes all operations submitting VTXOs to the Arkade
|
|
@@ -11876,7 +12153,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11876
12153
|
const hd = provider instanceof HDDescriptorProvider;
|
|
11877
12154
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
11878
12155
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
11879
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
12156
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkIEMPH7J6_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11880
12157
|
const arkInfo = await this.arkProvider.getInfo();
|
|
11881
12158
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
11882
12159
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -11895,7 +12172,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11895
12172
|
csvTimelocks: this.walletContractTimelocks,
|
|
11896
12173
|
// Boarding-exit CSV so the boarding handler can build its
|
|
11897
12174
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
11898
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
12175
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkIEMPH7J6_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
11899
12176
|
delegatePubKey
|
|
11900
12177
|
};
|
|
11901
12178
|
const result = await manager.scanContracts({
|
|
@@ -11907,6 +12184,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11907
12184
|
if (hd && result.highestConfirmedUsedIndex >= 0) {
|
|
11908
12185
|
await provider.advanceLastIndexUsed(result.highestConfirmedUsedIndex);
|
|
11909
12186
|
}
|
|
12187
|
+
await manager.refillLookAhead();
|
|
11910
12188
|
await manager.refreshVtxos({ includeInactive: true, after: 0 });
|
|
11911
12189
|
const causes = result.handlerErrors.map(
|
|
11912
12190
|
(e) => e.error instanceof Error ? e.error : new Error(String(e.error))
|
|
@@ -11998,6 +12276,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11998
12276
|
* ```
|
|
11999
12277
|
*/
|
|
12000
12278
|
static async create(config) {
|
|
12279
|
+
if (config.lookAheadWindow !== void 0 && (!Number.isInteger(config.lookAheadWindow) || config.lookAheadWindow <= 0)) {
|
|
12280
|
+
throw new Error(
|
|
12281
|
+
`lookAheadWindow must be a positive integer (got ${String(config.lookAheadWindow)})`
|
|
12282
|
+
);
|
|
12283
|
+
}
|
|
12001
12284
|
const pubkey = await config.identity.xOnlyPublicKey();
|
|
12002
12285
|
if (!pubkey) {
|
|
12003
12286
|
throw new Error("Invalid configured public key");
|
|
@@ -12035,7 +12318,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12035
12318
|
config.settlementConfig,
|
|
12036
12319
|
setup.walletContractTimelocks,
|
|
12037
12320
|
boot?.rotator,
|
|
12038
|
-
boot?.provider
|
|
12321
|
+
boot?.provider,
|
|
12322
|
+
config.lookAheadWindow
|
|
12039
12323
|
);
|
|
12040
12324
|
wallet._serverInfoSource = setup.serverInfoSource;
|
|
12041
12325
|
if (setup.serverInfoSource === "live") {
|
|
@@ -12720,9 +13004,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12720
13004
|
...existing ?? {},
|
|
12721
13005
|
intentTxId,
|
|
12722
13006
|
registerProof: intent.proof,
|
|
12723
|
-
registerProofMessage:
|
|
13007
|
+
registerProofMessage: chunkFZPYPEWN_cjs.Intent.encodeMessage(intent.message),
|
|
12724
13008
|
deleteProof: deleteIntent.proof,
|
|
12725
|
-
deleteProofMessage:
|
|
13009
|
+
deleteProofMessage: chunkFZPYPEWN_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
12726
13010
|
intentVtxos: inputs.map((i) => ({
|
|
12727
13011
|
txid: i.txid,
|
|
12728
13012
|
vout: i.vout
|
|
@@ -12754,7 +13038,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12754
13038
|
try {
|
|
12755
13039
|
return await this.arkProvider.registerIntent(intent);
|
|
12756
13040
|
} catch (error) {
|
|
12757
|
-
if (error instanceof
|
|
13041
|
+
if (error instanceof chunkFZPYPEWN_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
12758
13042
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
12759
13043
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
12760
13044
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -12770,7 +13054,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12770
13054
|
expire_at: 0,
|
|
12771
13055
|
cosigners_public_keys: cosignerPubKeys
|
|
12772
13056
|
};
|
|
12773
|
-
const proof =
|
|
13057
|
+
const proof = chunkFZPYPEWN_cjs.Intent.create(message, coins, outputs);
|
|
12774
13058
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12775
13059
|
return {
|
|
12776
13060
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12782,7 +13066,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12782
13066
|
type: "delete",
|
|
12783
13067
|
expire_at: 0
|
|
12784
13068
|
};
|
|
12785
|
-
const proof =
|
|
13069
|
+
const proof = chunkFZPYPEWN_cjs.Intent.create(message, coins, []);
|
|
12786
13070
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12787
13071
|
return {
|
|
12788
13072
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12794,7 +13078,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12794
13078
|
type: "get-pending-tx",
|
|
12795
13079
|
expire_at: 0
|
|
12796
13080
|
};
|
|
12797
|
-
const proof =
|
|
13081
|
+
const proof = chunkFZPYPEWN_cjs.Intent.create(message, coins, []);
|
|
12798
13082
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12799
13083
|
return {
|
|
12800
13084
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -13127,7 +13411,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13127
13411
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
13128
13412
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
13129
13413
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
13130
|
-
const proof =
|
|
13414
|
+
const proof = chunkFZPYPEWN_cjs.Intent.create(message, batch, []);
|
|
13131
13415
|
const signedProof = await identity.sign(
|
|
13132
13416
|
proof,
|
|
13133
13417
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -14010,7 +14294,7 @@ var MessageBus = class {
|
|
|
14010
14294
|
this.initialized = true;
|
|
14011
14295
|
}
|
|
14012
14296
|
async buildServices(config) {
|
|
14013
|
-
const arkProvider = new
|
|
14297
|
+
const arkProvider = new chunkFZPYPEWN_cjs.RestArkProvider(config.arkServer.url);
|
|
14014
14298
|
const storage = {
|
|
14015
14299
|
walletRepository: this.walletRepository,
|
|
14016
14300
|
contractRepository: this.contractRepository
|
|
@@ -14029,7 +14313,8 @@ var MessageBus = class {
|
|
|
14029
14313
|
delegateProvider,
|
|
14030
14314
|
settlementConfig: config.settlementConfig,
|
|
14031
14315
|
walletMode: config.walletMode,
|
|
14032
|
-
watcherConfig: config.watcherConfig
|
|
14316
|
+
watcherConfig: config.watcherConfig,
|
|
14317
|
+
lookAheadWindow: config.lookAheadWindow
|
|
14033
14318
|
});
|
|
14034
14319
|
return { wallet, arkProvider, readonlyWallet: wallet };
|
|
14035
14320
|
}
|
|
@@ -15170,7 +15455,7 @@ var WalletMessageHandler = class {
|
|
|
15170
15455
|
// Wallet methods
|
|
15171
15456
|
async handleInitWallet({ payload }) {
|
|
15172
15457
|
const { arkServerUrl } = payload;
|
|
15173
|
-
this.indexerProvider = new
|
|
15458
|
+
this.indexerProvider = new chunkFZPYPEWN_cjs.RestIndexerProvider(arkServerUrl);
|
|
15174
15459
|
await this.onWalletInitialized();
|
|
15175
15460
|
}
|
|
15176
15461
|
async handleGetBalance() {
|
|
@@ -16494,6 +16779,9 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
16494
16779
|
)
|
|
16495
16780
|
);
|
|
16496
16781
|
},
|
|
16782
|
+
refillLookAhead() {
|
|
16783
|
+
return Promise.resolve();
|
|
16784
|
+
},
|
|
16497
16785
|
async isWatching() {
|
|
16498
16786
|
const message = {
|
|
16499
16787
|
type: "IS_CONTRACT_MANAGER_WATCHING",
|
|
@@ -16543,6 +16831,11 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
16543
16831
|
return serializeSigningIdentity(this.identity);
|
|
16544
16832
|
}
|
|
16545
16833
|
static async create(options) {
|
|
16834
|
+
if (options.lookAheadWindow !== void 0 && (!Number.isInteger(options.lookAheadWindow) || options.lookAheadWindow <= 0)) {
|
|
16835
|
+
throw new Error(
|
|
16836
|
+
`lookAheadWindow must be a positive integer (got ${String(options.lookAheadWindow)})`
|
|
16837
|
+
);
|
|
16838
|
+
}
|
|
16546
16839
|
const walletRepository = options.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
16547
16840
|
const contractRepository = options.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
16548
16841
|
if (!isSigningCapable(options.identity)) {
|
|
@@ -16592,6 +16885,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
16592
16885
|
settlementConfig: options.settlementConfig,
|
|
16593
16886
|
walletMode: options.walletMode,
|
|
16594
16887
|
watcherConfig: options.watcherConfig,
|
|
16888
|
+
lookAheadWindow: options.lookAheadWindow,
|
|
16595
16889
|
messageTimeouts
|
|
16596
16890
|
};
|
|
16597
16891
|
await initializeMessageBus(
|
|
@@ -17038,7 +17332,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17038
17332
|
if (!inputs) {
|
|
17039
17333
|
throw new Error("Fee estimation failed");
|
|
17040
17334
|
}
|
|
17041
|
-
let tx = new
|
|
17335
|
+
let tx = new chunkFZPYPEWN_cjs.Transaction();
|
|
17042
17336
|
for (const input of inputs) {
|
|
17043
17337
|
tx.addInput({
|
|
17044
17338
|
txid: input.txid,
|
|
@@ -17096,7 +17390,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17096
17390
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
17097
17391
|
*/
|
|
17098
17392
|
async bumpAnchor(parentHex, feeRate) {
|
|
17099
|
-
const parent =
|
|
17393
|
+
const parent = chunkFZPYPEWN_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
17100
17394
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
17101
17395
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
17102
17396
|
return [parent.hex, child.hex];
|
|
@@ -17861,7 +18155,7 @@ exports.BIP322 = void 0;
|
|
|
17861
18155
|
async function sign2(message, identity, network) {
|
|
17862
18156
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
17863
18157
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
17864
|
-
const toSpend =
|
|
18158
|
+
const toSpend = chunkFZPYPEWN_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
17865
18159
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
17866
18160
|
const signed = await identity.sign(toSign, [0]);
|
|
17867
18161
|
signed.finalizeIdx(0);
|
|
@@ -17919,7 +18213,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
17919
18213
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
17920
18214
|
return false;
|
|
17921
18215
|
}
|
|
17922
|
-
const toSpend =
|
|
18216
|
+
const toSpend = chunkFZPYPEWN_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17923
18217
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
17924
18218
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
17925
18219
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -17940,7 +18234,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
17940
18234
|
}
|
|
17941
18235
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
17942
18236
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
17943
|
-
const toSpend =
|
|
18237
|
+
const toSpend = chunkFZPYPEWN_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17944
18238
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
17945
18239
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
17946
18240
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -17993,7 +18287,7 @@ function encodeCompactSize(n) {
|
|
|
17993
18287
|
return buf;
|
|
17994
18288
|
}
|
|
17995
18289
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
17996
|
-
const tx = new
|
|
18290
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({ version: 0 });
|
|
17997
18291
|
tx.addInput({
|
|
17998
18292
|
txid: toSpend.id,
|
|
17999
18293
|
index: 0,
|
|
@@ -18007,12 +18301,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
18007
18301
|
});
|
|
18008
18302
|
tx.addOutput({
|
|
18009
18303
|
amount: 0n,
|
|
18010
|
-
script:
|
|
18304
|
+
script: chunkFZPYPEWN_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
18011
18305
|
});
|
|
18012
18306
|
return tx;
|
|
18013
18307
|
}
|
|
18014
18308
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
18015
|
-
const tx = new
|
|
18309
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({ version: 0 });
|
|
18016
18310
|
tx.addInput({
|
|
18017
18311
|
txid: toSpend.id,
|
|
18018
18312
|
index: 0,
|
|
@@ -18024,7 +18318,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
18024
18318
|
});
|
|
18025
18319
|
tx.addOutput({
|
|
18026
18320
|
amount: 0n,
|
|
18027
|
-
script:
|
|
18321
|
+
script: chunkFZPYPEWN_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
18028
18322
|
});
|
|
18029
18323
|
return tx;
|
|
18030
18324
|
}
|
|
@@ -18155,7 +18449,7 @@ var RestEmulatorProvider = class {
|
|
|
18155
18449
|
}
|
|
18156
18450
|
};
|
|
18157
18451
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
18158
|
-
const tx =
|
|
18452
|
+
const tx = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
18159
18453
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
18160
18454
|
const input = tx.getInput(0);
|
|
18161
18455
|
if (!input) {
|
|
@@ -18189,7 +18483,7 @@ async function resolveUnilateralPath(params) {
|
|
|
18189
18483
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
18190
18484
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
18191
18485
|
if (contract) {
|
|
18192
|
-
const handler =
|
|
18486
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
18193
18487
|
if (!handler) {
|
|
18194
18488
|
throw new ExitPathError(
|
|
18195
18489
|
"no-handler",
|
|
@@ -18433,7 +18727,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18433
18727
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
18434
18728
|
);
|
|
18435
18729
|
}
|
|
18436
|
-
const tx = new
|
|
18730
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({ version: 2 });
|
|
18437
18731
|
for (const input of inputs) {
|
|
18438
18732
|
tx.addInput(input);
|
|
18439
18733
|
}
|
|
@@ -18500,7 +18794,7 @@ async function buildSignedSweep(params) {
|
|
|
18500
18794
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
18501
18795
|
);
|
|
18502
18796
|
}
|
|
18503
|
-
const tx = new
|
|
18797
|
+
const tx = new chunkFZPYPEWN_cjs.Transaction({ version: 2 });
|
|
18504
18798
|
tx.addInput({
|
|
18505
18799
|
txid: vtxo.txid,
|
|
18506
18800
|
index: vtxo.vout,
|
|
@@ -18570,7 +18864,7 @@ async function selectExitVtxos(opts) {
|
|
|
18570
18864
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
18571
18865
|
);
|
|
18572
18866
|
}
|
|
18573
|
-
const handler =
|
|
18867
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(contract.type);
|
|
18574
18868
|
if (!handler) {
|
|
18575
18869
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
18576
18870
|
}
|
|
@@ -18600,7 +18894,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18600
18894
|
if (pendingNodes.length > 0) {
|
|
18601
18895
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
18602
18896
|
for (const psbt of txs) {
|
|
18603
|
-
psbts.set(
|
|
18897
|
+
psbts.set(chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
18604
18898
|
}
|
|
18605
18899
|
}
|
|
18606
18900
|
const childVsize = Number(
|
|
@@ -19047,7 +19341,7 @@ async function prepare(opts) {
|
|
|
19047
19341
|
if (newFee <= splitterFee) break;
|
|
19048
19342
|
splitterFee = newFee;
|
|
19049
19343
|
}
|
|
19050
|
-
const splitter = new
|
|
19344
|
+
const splitter = new chunkFZPYPEWN_cjs.Transaction({ version: 2 });
|
|
19051
19345
|
for (const coin of selected.inputs) {
|
|
19052
19346
|
splitter.addInput({
|
|
19053
19347
|
txid: coin.txid,
|
|
@@ -19190,39 +19484,39 @@ var UnilateralExit = {
|
|
|
19190
19484
|
// src/arkade/index.ts
|
|
19191
19485
|
var arkade_exports = {};
|
|
19192
19486
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
19193
|
-
ARKADE_OP: () =>
|
|
19194
|
-
ARKADE_OPCODES: () =>
|
|
19195
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
19196
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
19197
|
-
ARKADE_OPS: () =>
|
|
19487
|
+
ARKADE_OP: () => chunkIEMPH7J6_cjs.ARKADE_OP,
|
|
19488
|
+
ARKADE_OPCODES: () => chunkIEMPH7J6_cjs.ARKADE_OPCODES,
|
|
19489
|
+
ARKADE_OPCODE_NAMES: () => chunkIEMPH7J6_cjs.ARKADE_OPCODE_NAMES,
|
|
19490
|
+
ARKADE_OPCODE_VALUES: () => chunkIEMPH7J6_cjs.ARKADE_OPCODE_VALUES,
|
|
19491
|
+
ARKADE_OPS: () => chunkIEMPH7J6_cjs.ARKADE_OPS,
|
|
19198
19492
|
Arkade: () => Arkade,
|
|
19199
19493
|
ArkadeContract: () => ArkadeContract,
|
|
19200
|
-
ArkadeProgramScript: () =>
|
|
19201
|
-
ArkadeScript: () =>
|
|
19494
|
+
ArkadeProgramScript: () => chunkIEMPH7J6_cjs.ArkadeProgramScript,
|
|
19495
|
+
ArkadeScript: () => chunkIEMPH7J6_cjs.ArkadeScript,
|
|
19202
19496
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
19203
|
-
BigNum: () =>
|
|
19497
|
+
BigNum: () => chunkIEMPH7J6_cjs.bignum_exports,
|
|
19204
19498
|
OP: () => btcSigner.OP,
|
|
19205
|
-
OPCODE_NAMES: () =>
|
|
19206
|
-
OPCODE_VALUES: () =>
|
|
19207
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
19499
|
+
OPCODE_NAMES: () => chunkIEMPH7J6_cjs.OPCODE_NAMES,
|
|
19500
|
+
OPCODE_VALUES: () => chunkIEMPH7J6_cjs.OPCODE_VALUES,
|
|
19501
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkIEMPH7J6_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
19208
19502
|
Script: () => btcSigner.Script,
|
|
19209
|
-
arkadeScriptHash: () =>
|
|
19210
|
-
arkadeWitnessHash: () =>
|
|
19211
|
-
asmToBytes: () =>
|
|
19212
|
-
bytesToASM: () =>
|
|
19213
|
-
computeArkadeScriptPublicKey: () =>
|
|
19503
|
+
arkadeScriptHash: () => chunkIEMPH7J6_cjs.arkadeScriptHash,
|
|
19504
|
+
arkadeWitnessHash: () => chunkIEMPH7J6_cjs.arkadeWitnessHash,
|
|
19505
|
+
asmToBytes: () => chunkIEMPH7J6_cjs.asmToBytes,
|
|
19506
|
+
bytesToASM: () => chunkIEMPH7J6_cjs.bytesToASM,
|
|
19507
|
+
computeArkadeScriptPublicKey: () => chunkIEMPH7J6_cjs.computeArkadeScriptPublicKey,
|
|
19214
19508
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
19215
|
-
deserializeArkadeContractParams: () =>
|
|
19216
|
-
fromASM: () =>
|
|
19217
|
-
getOpcodeName: () =>
|
|
19218
|
-
getOpcodeValue: () =>
|
|
19219
|
-
parseArtifact: () =>
|
|
19220
|
-
resolveAsm: () =>
|
|
19221
|
-
serializeArkadeContractParams: () =>
|
|
19222
|
-
stringifyArtifact: () =>
|
|
19223
|
-
toASM: () =>
|
|
19224
|
-
validateProgram: () =>
|
|
19225
|
-
witnessRefToBytes: () =>
|
|
19509
|
+
deserializeArkadeContractParams: () => chunkIEMPH7J6_cjs.deserializeArkadeContractParams,
|
|
19510
|
+
fromASM: () => chunkIEMPH7J6_cjs.fromASM,
|
|
19511
|
+
getOpcodeName: () => chunkIEMPH7J6_cjs.getOpcodeName,
|
|
19512
|
+
getOpcodeValue: () => chunkIEMPH7J6_cjs.getOpcodeValue,
|
|
19513
|
+
parseArtifact: () => chunkIEMPH7J6_cjs.parseArtifact,
|
|
19514
|
+
resolveAsm: () => chunkIEMPH7J6_cjs.resolveAsm,
|
|
19515
|
+
serializeArkadeContractParams: () => chunkIEMPH7J6_cjs.serializeArkadeContractParams,
|
|
19516
|
+
stringifyArtifact: () => chunkIEMPH7J6_cjs.stringifyArtifact,
|
|
19517
|
+
toASM: () => chunkIEMPH7J6_cjs.toASM,
|
|
19518
|
+
validateProgram: () => chunkIEMPH7J6_cjs.validateProgram,
|
|
19519
|
+
witnessRefToBytes: () => chunkIEMPH7J6_cjs.witnessRefToBytes
|
|
19226
19520
|
});
|
|
19227
19521
|
var isVtxoCoin = (input) => chunkE7HB3GKK_cjs.isVirtualCoin(input);
|
|
19228
19522
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients) {
|
|
@@ -19254,7 +19548,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19254
19548
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
19255
19549
|
return { skip: true };
|
|
19256
19550
|
}
|
|
19257
|
-
const commitmentTx =
|
|
19551
|
+
const commitmentTx = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
19258
19552
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
19259
19553
|
if (recipients && recipients.length > 0) {
|
|
19260
19554
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -19285,7 +19579,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19285
19579
|
if (connectorTree) {
|
|
19286
19580
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
19287
19581
|
}
|
|
19288
|
-
let commitmentPsbt =
|
|
19582
|
+
let commitmentPsbt = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
19289
19583
|
const signedForfeits = [];
|
|
19290
19584
|
let connectorIndex = 0;
|
|
19291
19585
|
const connectorLeaves = connectorTree?.leaves() || [];
|
|
@@ -19451,7 +19745,7 @@ var Arkade = class _Arkade {
|
|
|
19451
19745
|
* key respectively; explicit args always win.
|
|
19452
19746
|
*/
|
|
19453
19747
|
contract(program, args = {}) {
|
|
19454
|
-
const declared = (program.params ?? []).map(
|
|
19748
|
+
const declared = (program.params ?? []).map(chunkIEMPH7J6_cjs.inputName);
|
|
19455
19749
|
if (declared.includes("server") && args.server === void 0) {
|
|
19456
19750
|
args = { ...args, server: this.serverKey };
|
|
19457
19751
|
}
|
|
@@ -19471,7 +19765,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19471
19765
|
userKey: client.userKey,
|
|
19472
19766
|
emulatorKey: client.emulatorKey
|
|
19473
19767
|
};
|
|
19474
|
-
this.vtxoScript = new
|
|
19768
|
+
this.vtxoScript = new chunkIEMPH7J6_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
19475
19769
|
this.tapTree = this.vtxoScript.encode();
|
|
19476
19770
|
this.compiled = this.vtxoScript.compiled;
|
|
19477
19771
|
}
|
|
@@ -19499,7 +19793,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19499
19793
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
19500
19794
|
);
|
|
19501
19795
|
}
|
|
19502
|
-
const typed =
|
|
19796
|
+
const typed = chunkIEMPH7J6_cjs.deserializeArkadeContractParams(contract.params);
|
|
19503
19797
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
19504
19798
|
serverKey: typed.serverKey,
|
|
19505
19799
|
userKey: typed.userKey,
|
|
@@ -19540,7 +19834,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19540
19834
|
toContractParams() {
|
|
19541
19835
|
return {
|
|
19542
19836
|
type: "arkade",
|
|
19543
|
-
params:
|
|
19837
|
+
params: chunkIEMPH7J6_cjs.serializeArkadeContractParams({
|
|
19544
19838
|
program: this.program,
|
|
19545
19839
|
args: this.args,
|
|
19546
19840
|
serverKey: this.keys.serverKey,
|
|
@@ -19693,12 +19987,12 @@ var ArkadeTransactionBuilder = class {
|
|
|
19693
19987
|
this.contract.client.checkpoint
|
|
19694
19988
|
);
|
|
19695
19989
|
if (coin.sourceTx) {
|
|
19696
|
-
|
|
19990
|
+
chunkFZPYPEWN_cjs.setArkPsbtField(arkTx, 0, chunkFZPYPEWN_cjs.PrevArkTxField, coin.sourceTx);
|
|
19697
19991
|
}
|
|
19698
19992
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19699
19993
|
if (condition.length > 0) {
|
|
19700
|
-
|
|
19701
|
-
|
|
19994
|
+
chunkFZPYPEWN_cjs.setArkPsbtField(arkTx, 0, chunkFZPYPEWN_cjs.ConditionWitness, condition);
|
|
19995
|
+
chunkFZPYPEWN_cjs.setArkPsbtField(checkpoints[0], 0, chunkFZPYPEWN_cjs.ConditionWitness, condition);
|
|
19702
19996
|
}
|
|
19703
19997
|
const packets = [];
|
|
19704
19998
|
if (this.assetSpecs.length > 0) {
|
|
@@ -19737,7 +20031,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19737
20031
|
base.base64.encode(signedArk2.toPSBT()),
|
|
19738
20032
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
19739
20033
|
);
|
|
19740
|
-
const txid =
|
|
20034
|
+
const txid = chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
19741
20035
|
return {
|
|
19742
20036
|
txid,
|
|
19743
20037
|
signedArkTx: res2.signedArkTx,
|
|
@@ -19755,7 +20049,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19755
20049
|
const finalCps = await Promise.all(
|
|
19756
20050
|
res.signedCheckpointTxs.map(
|
|
19757
20051
|
async (b) => base.base64.encode(
|
|
19758
|
-
(await client.identity.sign(
|
|
20052
|
+
(await client.identity.sign(chunkFZPYPEWN_cjs.Transaction.fromPSBT(base.base64.decode(b)), [0])).toPSBT()
|
|
19759
20053
|
)
|
|
19760
20054
|
)
|
|
19761
20055
|
);
|
|
@@ -19796,23 +20090,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
19796
20090
|
}
|
|
19797
20091
|
buildAssetPacket() {
|
|
19798
20092
|
const groups = this.assetSpecs.map((s) => {
|
|
19799
|
-
const id = typeof s.assetId === "string" ?
|
|
19800
|
-
return
|
|
20093
|
+
const id = typeof s.assetId === "string" ? chunkFZPYPEWN_cjs.AssetId.fromString(s.assetId) : chunkFZPYPEWN_cjs.AssetId.fromBytes(s.assetId);
|
|
20094
|
+
return chunkFZPYPEWN_cjs.AssetGroup.create(
|
|
19801
20095
|
id,
|
|
19802
20096
|
null,
|
|
19803
|
-
s.inputs.map((i) =>
|
|
19804
|
-
s.outputs.map((o) =>
|
|
19805
|
-
(s.metadata ?? []).map((m) =>
|
|
20097
|
+
s.inputs.map((i) => chunkFZPYPEWN_cjs.AssetInput.create(i.vin, i.amount)),
|
|
20098
|
+
s.outputs.map((o) => chunkFZPYPEWN_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
20099
|
+
(s.metadata ?? []).map((m) => chunkFZPYPEWN_cjs.Metadata.create(m.key, m.value))
|
|
19806
20100
|
);
|
|
19807
20101
|
});
|
|
19808
|
-
return
|
|
20102
|
+
return chunkFZPYPEWN_cjs.Packet.create(groups);
|
|
19809
20103
|
}
|
|
19810
20104
|
witnessBytes(ref) {
|
|
19811
|
-
return
|
|
20105
|
+
return chunkIEMPH7J6_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
19812
20106
|
}
|
|
19813
20107
|
};
|
|
19814
20108
|
function bindInputs(fn, callArgs) {
|
|
19815
|
-
const names = (fn.def.inputs ?? []).map(
|
|
20109
|
+
const names = (fn.def.inputs ?? []).map(chunkIEMPH7J6_cjs.inputName);
|
|
19816
20110
|
if (callArgs.length !== names.length) {
|
|
19817
20111
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
19818
20112
|
}
|
|
@@ -19865,7 +20159,7 @@ function decodeArkContract(encoded) {
|
|
|
19865
20159
|
}
|
|
19866
20160
|
function contractFromArkContract(encoded, options = {}) {
|
|
19867
20161
|
const parsed = decodeArkContract(encoded);
|
|
19868
|
-
const handler =
|
|
20162
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.get(parsed.type);
|
|
19869
20163
|
if (!handler) {
|
|
19870
20164
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
19871
20165
|
}
|
|
@@ -19881,7 +20175,7 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
19881
20175
|
}
|
|
19882
20176
|
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkE7HB3GKK_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
19883
20177
|
const parsed = decodeArkContract(encoded);
|
|
19884
|
-
const handler =
|
|
20178
|
+
const handler = chunkIEMPH7J6_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
19885
20179
|
const params = parsed.data;
|
|
19886
20180
|
const vtxoScript = handler.createScript(params);
|
|
19887
20181
|
return {
|
|
@@ -19995,6 +20289,7 @@ exports.extendVirtualCoinForContract = extendVirtualCoinForContract;
|
|
|
19995
20289
|
exports.getMigrationStatus = getMigrationStatus;
|
|
19996
20290
|
exports.getRandomId = getRandomId;
|
|
19997
20291
|
exports.hasBoardingTxExpired = hasBoardingTxExpired;
|
|
20292
|
+
exports.hasCandidates = hasCandidates;
|
|
19998
20293
|
exports.intentMatchesFilter = intentMatchesFilter;
|
|
19999
20294
|
exports.intentPageBounds = intentPageBounds;
|
|
20000
20295
|
exports.isArkContract = isArkContract;
|
|
@@ -20028,5 +20323,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
20028
20323
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
20029
20324
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
20030
20325
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
20031
|
-
//# sourceMappingURL=chunk-
|
|
20032
|
-
//# sourceMappingURL=chunk-
|
|
20326
|
+
//# sourceMappingURL=chunk-ML33GFCH.cjs.map
|
|
20327
|
+
//# sourceMappingURL=chunk-ML33GFCH.cjs.map
|