@arkade-os/sdk 0.4.48-rc.0 → 0.4.48
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/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-CoJgwTi_.d.cts → ark-CjE0KkGp.d.cts} +405 -250
- package/dist/{ark-CoJgwTi_.d.ts → ark-CjE0KkGp.d.ts} +405 -250
- package/dist/{asyncStorageTaskQueue-CwknfM_j.d.cts → asyncStorageTaskQueue-CeLZhZFU.d.cts} +1 -1
- package/dist/{asyncStorageTaskQueue-D2Zl7yAB.d.ts → asyncStorageTaskQueue-D9SOPMPC.d.ts} +1 -1
- package/dist/{chunk-XN3554FT.js → chunk-4VVTRPH3.js} +4 -4
- package/dist/chunk-4VVTRPH3.js.map +1 -0
- package/dist/{chunk-RQSA7ADZ.cjs → chunk-5XMVTK5S.cjs} +37 -37
- package/dist/chunk-5XMVTK5S.cjs.map +1 -0
- package/dist/{chunk-L5ND2FJJ.cjs → chunk-7TXSPRN5.cjs} +161 -2
- package/dist/chunk-7TXSPRN5.cjs.map +1 -0
- package/dist/{chunk-GM6JRQP5.js → chunk-BHHLRZCS.js} +169 -42
- package/dist/chunk-BHHLRZCS.js.map +1 -0
- package/dist/{chunk-CFQO5MCM.cjs → chunk-EB3ALGTM.cjs} +178 -50
- package/dist/chunk-EB3ALGTM.cjs.map +1 -0
- package/dist/{chunk-3HUZAIKI.cjs → chunk-ENDNQPZA.cjs} +17 -44
- package/dist/chunk-ENDNQPZA.cjs.map +1 -0
- package/dist/{chunk-RJMFTTRJ.cjs → chunk-ENZ4YPR2.cjs} +614 -592
- package/dist/chunk-ENZ4YPR2.cjs.map +1 -0
- package/dist/{chunk-4AIHKC65.js → chunk-G6J6AEMH.js} +5 -4
- package/dist/chunk-G6J6AEMH.js.map +1 -0
- package/dist/{chunk-SV4PCGKM.js → chunk-NYR5H6GR.js} +348 -323
- package/dist/chunk-NYR5H6GR.js.map +1 -0
- package/dist/{chunk-EA3IWZ4W.cjs → chunk-SYDANBJI.cjs} +9 -8
- package/dist/chunk-SYDANBJI.cjs.map +1 -0
- package/dist/{chunk-ZRY2KSK5.js → chunk-XFMGIFBL.js} +4 -31
- package/dist/chunk-XFMGIFBL.js.map +1 -0
- package/dist/{chunk-C7TXXTMS.js → chunk-ZDDBTFVO.js} +146 -3
- package/dist/chunk-ZDDBTFVO.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +8 -8
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-Dl87_zMA.d.cts → delegate-D3dY-2vS.d.cts} +1 -1
- package/dist/{delegate-CuaDqqQi.d.ts → delegate-DhGZk1r2.d.ts} +1 -1
- package/dist/{index-BC_G0VTh.d.cts → index-D6RQROds.d.cts} +2 -2
- package/dist/{index-CKwpZEpw.d.ts → index-DK4_iWYy.d.ts} +2 -2
- package/dist/index.cjs +208 -188
- package/dist/index.d.cts +35 -18
- package/dist/index.d.ts +35 -18
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +19 -19
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/sqlite/index.cjs +18 -18
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +5 -5
- package/dist/{taskRunner-Df8YQpn1.d.ts → taskRunner-B-2MHCYG.d.ts} +1 -1
- package/dist/{taskRunner-RYihSj9E.d.cts → taskRunner-Brnak0Rc.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +5 -5
- package/dist/wallet/expo/index.d.ts +5 -5
- package/dist/wallet/expo/index.js +5 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-B6s7_5bJ.d.cts → wallet-B5bwixQa.d.ts} +31 -31
- package/dist/{wallet-C61huH8i.d.ts → wallet-DiOrtYic.d.cts} +31 -31
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +3 -2
- package/dist/chunk-3HUZAIKI.cjs.map +0 -1
- package/dist/chunk-4AIHKC65.js.map +0 -1
- package/dist/chunk-C7TXXTMS.js.map +0 -1
- package/dist/chunk-CFQO5MCM.cjs.map +0 -1
- package/dist/chunk-EA3IWZ4W.cjs.map +0 -1
- package/dist/chunk-GM6JRQP5.js.map +0 -1
- package/dist/chunk-L5ND2FJJ.cjs.map +0 -1
- package/dist/chunk-RJMFTTRJ.cjs.map +0 -1
- package/dist/chunk-RQSA7ADZ.cjs.map +0 -1
- package/dist/chunk-SV4PCGKM.js.map +0 -1
- package/dist/chunk-XN3554FT.js.map +0 -1
- package/dist/chunk-ZRY2KSK5.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkEB3ALGTM_cjs = require('./chunk-EB3ALGTM.cjs');
|
|
4
|
+
var chunk5XMVTK5S_cjs = require('./chunk-5XMVTK5S.cjs');
|
|
5
|
+
var chunk7TXSPRN5_cjs = require('./chunk-7TXSPRN5.cjs');
|
|
6
6
|
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
7
7
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
8
8
|
var btcSigner = require('@scure/btc-signer');
|
|
@@ -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 = chunkEB3ALGTM_cjs.getArkPsbtFields(tx.root, 0, chunkEB3ALGTM_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 = chunkEB3ALGTM_cjs.getArkPsbtFields(g.root, 0, chunkEB3ALGTM_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 = chunk5XMVTK5S_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 chunk5XMVTK5S_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 = chunk5XMVTK5S_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 = chunk5XMVTK5S_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 chunk5XMVTK5S_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 chunkEB3ALGTM_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: chunkEB3ALGTM_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 chunkEB3ALGTM_cjs.rateGate.runHttp(url, () => chunkEB3ALGTM_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}`);
|
|
@@ -1040,7 +1040,7 @@ var ESPLORA_URL = {
|
|
|
1040
1040
|
regtest: "http://localhost:3000/api"
|
|
1041
1041
|
};
|
|
1042
1042
|
var EsploraProvider = class {
|
|
1043
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1043
|
+
constructor(baseUrl = ESPLORA_URL[chunk7TXSPRN5_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1044
1044
|
this.baseUrl = baseUrl;
|
|
1045
1045
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1046
1046
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 = chunkEB3ALGTM_cjs.getArkPsbtFields(child.root, 0, chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_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 chunkEB3ALGTM_cjs.Packet.PACKET_TYPE:
|
|
1783
|
+
return chunkEB3ALGTM_cjs.Packet.fromBytes(data);
|
|
1784
1784
|
case EmulatorPacket.PACKET_TYPE:
|
|
1785
1785
|
return EmulatorPacket.fromBytes(data);
|
|
1786
1786
|
default:
|
|
@@ -1841,7 +1841,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
1841
1841
|
for (const recipient of recipients) {
|
|
1842
1842
|
let arkAddress;
|
|
1843
1843
|
try {
|
|
1844
|
-
arkAddress =
|
|
1844
|
+
arkAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(recipient.address);
|
|
1845
1845
|
} catch {
|
|
1846
1846
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
1847
1847
|
continue;
|
|
@@ -2064,20 +2064,6 @@ var TxType = /* @__PURE__ */ ((TxType2) => {
|
|
|
2064
2064
|
TxType2["TxReceived"] = "RECEIVED";
|
|
2065
2065
|
return TxType2;
|
|
2066
2066
|
})(TxType || {});
|
|
2067
|
-
function isSpendable(vtxo) {
|
|
2068
|
-
return !vtxo.isSpent;
|
|
2069
|
-
}
|
|
2070
|
-
function isRecoverable(vtxo) {
|
|
2071
|
-
return vtxo.virtualStatus.state === "swept" && isSpendable(vtxo);
|
|
2072
|
-
}
|
|
2073
|
-
function isExpired(vtxo) {
|
|
2074
|
-
if (vtxo.virtualStatus.state === "swept") return true;
|
|
2075
|
-
const expiry = vtxo.virtualStatus.batchExpiry;
|
|
2076
|
-
if (!expiry) return false;
|
|
2077
|
-
const expireAt = new Date(expiry);
|
|
2078
|
-
if (expireAt.getFullYear() < 2025) return false;
|
|
2079
|
-
return expiry <= Date.now();
|
|
2080
|
-
}
|
|
2081
2067
|
function isSubdust(vtxo, dust) {
|
|
2082
2068
|
if (typeof vtxo === "bigint") return vtxo < dust;
|
|
2083
2069
|
return vtxo.value < dust;
|
|
@@ -2091,7 +2077,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2091
2077
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
2092
2078
|
inputsByAssetId.set(asset.assetId, [
|
|
2093
2079
|
...existing ?? [],
|
|
2094
|
-
|
|
2080
|
+
chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
2095
2081
|
]);
|
|
2096
2082
|
}
|
|
2097
2083
|
}
|
|
@@ -2103,7 +2089,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2103
2089
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2104
2090
|
outputsByAssetId.set(asset.assetId, [
|
|
2105
2091
|
...existing ?? [],
|
|
2106
|
-
|
|
2092
|
+
chunkEB3ALGTM_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2107
2093
|
]);
|
|
2108
2094
|
}
|
|
2109
2095
|
}
|
|
@@ -2114,7 +2100,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2114
2100
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2115
2101
|
outputsByAssetId.set(asset.assetId, [
|
|
2116
2102
|
...existing ?? [],
|
|
2117
|
-
|
|
2103
|
+
chunkEB3ALGTM_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2118
2104
|
]);
|
|
2119
2105
|
}
|
|
2120
2106
|
}
|
|
@@ -2123,11 +2109,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2123
2109
|
for (const assetIdStr of allAssetIds) {
|
|
2124
2110
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2125
2111
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2126
|
-
const assetId =
|
|
2127
|
-
const group =
|
|
2112
|
+
const assetId = chunkEB3ALGTM_cjs.AssetId.fromString(assetIdStr);
|
|
2113
|
+
const group = chunkEB3ALGTM_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2128
2114
|
groups.push(group);
|
|
2129
2115
|
}
|
|
2130
|
-
return
|
|
2116
|
+
return chunkEB3ALGTM_cjs.Packet.create(groups);
|
|
2131
2117
|
}
|
|
2132
2118
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2133
2119
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2232,8 +2218,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
2232
2218
|
function buildVirtualTx(inputs, outputs) {
|
|
2233
2219
|
let lockTime = 0n;
|
|
2234
2220
|
for (const input of inputs) {
|
|
2235
|
-
const tapscript =
|
|
2236
|
-
if (
|
|
2221
|
+
const tapscript = chunk7TXSPRN5_cjs.decodeTapscript(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
2222
|
+
if (chunk7TXSPRN5_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
2237
2223
|
if (lockTime !== 0n) {
|
|
2238
2224
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
2239
2225
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -2244,7 +2230,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2244
2230
|
}
|
|
2245
2231
|
}
|
|
2246
2232
|
}
|
|
2247
|
-
const tx = new
|
|
2233
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({
|
|
2248
2234
|
version: 3,
|
|
2249
2235
|
lockTime: Number(lockTime)
|
|
2250
2236
|
});
|
|
@@ -2254,12 +2240,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2254
2240
|
index: input.vout,
|
|
2255
2241
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
2256
2242
|
witnessUtxo: {
|
|
2257
|
-
script:
|
|
2243
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
2258
2244
|
amount: BigInt(input.value)
|
|
2259
2245
|
},
|
|
2260
2246
|
tapLeafScript: [input.tapLeafScript]
|
|
2261
2247
|
});
|
|
2262
|
-
|
|
2248
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(tx, i, chunkEB3ALGTM_cjs.VtxoTaprootTree, input.tapTree);
|
|
2263
2249
|
}
|
|
2264
2250
|
for (const output of outputs) {
|
|
2265
2251
|
tx.addOutput(output);
|
|
@@ -2268,8 +2254,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2268
2254
|
return tx;
|
|
2269
2255
|
}
|
|
2270
2256
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
2271
|
-
const collaborativeClosure =
|
|
2272
|
-
const checkpointVtxoScript = new
|
|
2257
|
+
const collaborativeClosure = chunk7TXSPRN5_cjs.decodeTapscript(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
2258
|
+
const checkpointVtxoScript = new chunk7TXSPRN5_cjs.VtxoScript([
|
|
2273
2259
|
serverUnrollScript.script,
|
|
2274
2260
|
collaborativeClosure.script
|
|
2275
2261
|
]);
|
|
@@ -2413,7 +2399,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
2413
2399
|
}
|
|
2414
2400
|
function isValidArkAddress(address) {
|
|
2415
2401
|
try {
|
|
2416
|
-
|
|
2402
|
+
chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
2417
2403
|
return true;
|
|
2418
2404
|
} catch (e) {
|
|
2419
2405
|
return false;
|
|
@@ -2442,14 +2428,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks) {
|
|
|
2442
2428
|
let finalCheckpoints;
|
|
2443
2429
|
if (userSignedCheckpoints) {
|
|
2444
2430
|
finalCheckpoints = signedCheckpointTxs.map((c, i) => {
|
|
2445
|
-
const serverSigned =
|
|
2431
|
+
const serverSigned = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2446
2432
|
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
2447
2433
|
return base.base64.encode(serverSigned.toPSBT());
|
|
2448
2434
|
});
|
|
2449
2435
|
} else {
|
|
2450
2436
|
finalCheckpoints = await Promise.all(
|
|
2451
2437
|
signedCheckpointTxs.map(async (c) => {
|
|
2452
|
-
const tx =
|
|
2438
|
+
const tx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2453
2439
|
const signed = await signer.signCheckpoint(tx);
|
|
2454
2440
|
return base.base64.encode(signed.toPSBT());
|
|
2455
2441
|
})
|
|
@@ -2645,7 +2631,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2645
2631
|
};
|
|
2646
2632
|
}
|
|
2647
2633
|
function deriveContractTapscripts(contract) {
|
|
2648
|
-
const handler =
|
|
2634
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
2649
2635
|
if (!handler) {
|
|
2650
2636
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2651
2637
|
}
|
|
@@ -2719,7 +2705,7 @@ function validateRecipients(recipients, dustAmount) {
|
|
|
2719
2705
|
for (const recipient of recipients) {
|
|
2720
2706
|
let address;
|
|
2721
2707
|
try {
|
|
2722
|
-
address =
|
|
2708
|
+
address = chunk7TXSPRN5_cjs.ArkAddress.decode(recipient.address);
|
|
2723
2709
|
} catch (e) {
|
|
2724
2710
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2725
2711
|
}
|
|
@@ -2747,7 +2733,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
2747
2733
|
continue;
|
|
2748
2734
|
}
|
|
2749
2735
|
for (const v of vtxos) {
|
|
2750
|
-
if (
|
|
2736
|
+
if (!chunk7TXSPRN5_cjs.hasTerminalSpend(v) && !v.isSwept) out.add(`${v.txid}:${v.vout}`);
|
|
2751
2737
|
}
|
|
2752
2738
|
}
|
|
2753
2739
|
return out;
|
|
@@ -2779,16 +2765,28 @@ var MAX_INPUTS_PER_INTENT = 20;
|
|
|
2779
2765
|
function byValueDescending(vtxos) {
|
|
2780
2766
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
2781
2767
|
}
|
|
2782
|
-
function
|
|
2768
|
+
async function fetchTimeHeight(wallet) {
|
|
2769
|
+
return chunk7TXSPRN5_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
2770
|
+
}
|
|
2771
|
+
function canMigrateBySend(vtxo, now) {
|
|
2772
|
+
if (!chunk7TXSPRN5_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
2773
|
+
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
2774
|
+
}
|
|
2775
|
+
function byExpiryAscending(vtxos, now) {
|
|
2783
2776
|
const expiryKey = (vtxo) => {
|
|
2784
|
-
if (
|
|
2785
|
-
|
|
2786
|
-
if (
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
return
|
|
2777
|
+
if (vtxo.isSwept) return -Infinity;
|
|
2778
|
+
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
2779
|
+
if (vtxo.expiresAtHeight !== void 0) {
|
|
2780
|
+
return chunk7TXSPRN5_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
2781
|
+
}
|
|
2782
|
+
return Infinity;
|
|
2790
2783
|
};
|
|
2791
|
-
return [...vtxos].sort((a, b) =>
|
|
2784
|
+
return [...vtxos].sort((a, b) => {
|
|
2785
|
+
const ka = expiryKey(a);
|
|
2786
|
+
const kb = expiryKey(b);
|
|
2787
|
+
if (ka === kb) return 0;
|
|
2788
|
+
return ka < kb ? -1 : 1;
|
|
2789
|
+
});
|
|
2792
2790
|
}
|
|
2793
2791
|
function capSettlementBatch(sorted, maxAmount) {
|
|
2794
2792
|
const batch = [];
|
|
@@ -2814,22 +2812,19 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
2814
2812
|
pollIntervalMs: 6e4,
|
|
2815
2813
|
deprecatedSignerMigration: true
|
|
2816
2814
|
};
|
|
2817
|
-
function getRecoverableVtxos(vtxos, dustAmount) {
|
|
2815
|
+
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
2818
2816
|
return vtxos.filter((vtxo) => {
|
|
2819
|
-
if (
|
|
2820
|
-
return true;
|
|
2821
|
-
}
|
|
2822
|
-
if (isSpendable(vtxo) && isExpired(vtxo)) {
|
|
2817
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
2823
2818
|
return true;
|
|
2824
2819
|
}
|
|
2825
|
-
if (vtxo
|
|
2820
|
+
if (chunk7TXSPRN5_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
2826
2821
|
return true;
|
|
2827
2822
|
}
|
|
2828
2823
|
return false;
|
|
2829
2824
|
});
|
|
2830
2825
|
}
|
|
2831
|
-
function getRecoverableWithSubdust(vtxos, dustAmount) {
|
|
2832
|
-
const recoverableVtxos = getRecoverableVtxos(vtxos, dustAmount);
|
|
2826
|
+
function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
2827
|
+
const recoverableVtxos = getRecoverableVtxos(vtxos, dustAmount, now);
|
|
2833
2828
|
const subdust = [];
|
|
2834
2829
|
const regular = [];
|
|
2835
2830
|
for (const vtxo of recoverableVtxos) {
|
|
@@ -2853,17 +2848,16 @@ function getRecoverableWithSubdust(vtxos, dustAmount) {
|
|
|
2853
2848
|
}
|
|
2854
2849
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
2855
2850
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
2856
|
-
const
|
|
2857
|
-
if (
|
|
2858
|
-
const expireAt = new Date(batchExpiry);
|
|
2859
|
-
if (expireAt.getFullYear() < 2025) return false;
|
|
2851
|
+
const expiresAt = chunk7TXSPRN5_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
2852
|
+
if (expiresAt === void 0) return false;
|
|
2860
2853
|
const now = Date.now();
|
|
2854
|
+
const batchExpiry = expiresAt.getTime();
|
|
2861
2855
|
if (batchExpiry <= now) return false;
|
|
2862
2856
|
return batchExpiry - now <= realThresholdMs;
|
|
2863
2857
|
}
|
|
2864
|
-
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount) {
|
|
2858
|
+
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
2865
2859
|
return vtxos.filter(
|
|
2866
|
-
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
2860
|
+
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) || chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount)
|
|
2867
2861
|
);
|
|
2868
2862
|
}
|
|
2869
2863
|
function isMigrationCapable(wallet) {
|
|
@@ -3012,7 +3006,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3012
3006
|
withUnrolled: false
|
|
3013
3007
|
});
|
|
3014
3008
|
const dustAmount = getDustAmount(this.wallet);
|
|
3015
|
-
|
|
3009
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3010
|
+
let { vtxosToRecover, totalAmount } = getRecoverableWithSubdust(allVtxos, dustAmount, now);
|
|
3016
3011
|
if (vtxosToRecover.length === 0) {
|
|
3017
3012
|
throw new Error("No recoverable VTXOs found");
|
|
3018
3013
|
}
|
|
@@ -3021,7 +3016,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3021
3016
|
const capped = capSettlementBatch(byValueDescending(vtxosToRecover), vtxoMaxAmount);
|
|
3022
3017
|
if (capped.length < vtxosToRecover.length) {
|
|
3023
3018
|
const recoverableCount = vtxosToRecover.length;
|
|
3024
|
-
({ vtxosToRecover, totalAmount } = getRecoverableWithSubdust(capped, dustAmount));
|
|
3019
|
+
({ vtxosToRecover, totalAmount } = getRecoverableWithSubdust(capped, dustAmount, now));
|
|
3025
3020
|
if (vtxosToRecover.length === 0) {
|
|
3026
3021
|
throw new Error(
|
|
3027
3022
|
`Capped recovery batch (highest-value subset of ${recoverableCount} recoverable VTXOs within the ${MAX_VTXOS_PER_SETTLEMENT}-input and ${vtxoMaxAmount}-sat limits) is below the dust threshold ${dustAmount}`
|
|
@@ -3073,7 +3068,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3073
3068
|
const dustAmount = getDustAmount(this.wallet);
|
|
3074
3069
|
const { vtxosToRecover, includesSubdust, totalAmount } = getRecoverableWithSubdust(
|
|
3075
3070
|
allVtxos,
|
|
3076
|
-
dustAmount
|
|
3071
|
+
dustAmount,
|
|
3072
|
+
await fetchTimeHeight(this.wallet)
|
|
3077
3073
|
);
|
|
3078
3074
|
const subdustAmount = vtxosToRecover.filter((v) => BigInt(v.value) < dustAmount).reduce((sum, v) => sum + BigInt(v.value), 0n);
|
|
3079
3075
|
return {
|
|
@@ -3107,6 +3103,16 @@ var VtxoManager = class _VtxoManager {
|
|
|
3107
3103
|
* ```
|
|
3108
3104
|
*/
|
|
3109
3105
|
async getExpiringVtxos(thresholdMs) {
|
|
3106
|
+
return this.selectExpiringVtxos(thresholdMs);
|
|
3107
|
+
}
|
|
3108
|
+
/**
|
|
3109
|
+
* {@link getExpiringVtxos}, against a caller-supplied chain tip.
|
|
3110
|
+
*
|
|
3111
|
+
* The settle paths select, re-select after pre-flight, and sort by expiry within one pass;
|
|
3112
|
+
* each of those judges expiry, so they share one tip rather than fetching (and possibly
|
|
3113
|
+
* disagreeing on) one apiece. Fetches its own when `now` is omitted.
|
|
3114
|
+
*/
|
|
3115
|
+
async selectExpiringVtxos(thresholdMs, now) {
|
|
3110
3116
|
if (this.settlementConfig === false && thresholdMs === void 0) {
|
|
3111
3117
|
return [];
|
|
3112
3118
|
}
|
|
@@ -3119,7 +3125,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
3119
3125
|
} else {
|
|
3120
3126
|
threshold = this.renewalConfig?.thresholdMs ?? DEFAULT_RENEWAL_CONFIG.thresholdMs;
|
|
3121
3127
|
}
|
|
3122
|
-
return getExpiringAndRecoverableVtxos(
|
|
3128
|
+
return getExpiringAndRecoverableVtxos(
|
|
3129
|
+
vtxos,
|
|
3130
|
+
threshold,
|
|
3131
|
+
getDustAmount(this.wallet),
|
|
3132
|
+
now ?? await fetchTimeHeight(this.wallet)
|
|
3133
|
+
);
|
|
3123
3134
|
}
|
|
3124
3135
|
/**
|
|
3125
3136
|
* Renew expiring virtual outputs by settling them back to the wallet's address
|
|
@@ -3172,17 +3183,18 @@ var VtxoManager = class _VtxoManager {
|
|
|
3172
3183
|
} else {
|
|
3173
3184
|
threshold = DEFAULT_RENEWAL_CONFIG.thresholdMs;
|
|
3174
3185
|
}
|
|
3175
|
-
|
|
3186
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3187
|
+
let vtxos = await this.selectExpiringVtxos(threshold, now);
|
|
3176
3188
|
if (vtxos.length === 0) {
|
|
3177
3189
|
throw new Error("No VTXOs available to renew");
|
|
3178
3190
|
}
|
|
3179
|
-
vtxos = await this.revalidateBeforeSettle(vtxos, threshold);
|
|
3191
|
+
vtxos = await this.revalidateBeforeSettle(vtxos, threshold, now);
|
|
3180
3192
|
if (vtxos.length === 0) {
|
|
3181
3193
|
throw new Error("No VTXOs available to renew");
|
|
3182
3194
|
}
|
|
3183
3195
|
const info = await this.getInfoProvider()?.getInfo();
|
|
3184
3196
|
const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
|
|
3185
|
-
const capped = capSettlementBatch(byExpiryAscending(vtxos), vtxoMaxAmount);
|
|
3197
|
+
const capped = capSettlementBatch(byExpiryAscending(vtxos, now), vtxoMaxAmount);
|
|
3186
3198
|
if (vtxoMaxAmount >= 0n) {
|
|
3187
3199
|
const oversized = vtxos.filter((vtxo) => BigInt(vtxo.value) > vtxoMaxAmount);
|
|
3188
3200
|
if (oversized.length > 0) {
|
|
@@ -3327,11 +3339,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3327
3339
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3328
3340
|
);
|
|
3329
3341
|
}
|
|
3330
|
-
const tx = new
|
|
3342
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction();
|
|
3331
3343
|
for (const utxo of expiredUtxos) {
|
|
3332
|
-
const utxoScript =
|
|
3344
|
+
const utxoScript = chunk7TXSPRN5_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3333
3345
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
3334
|
-
(leaf) =>
|
|
3346
|
+
(leaf) => chunk7TXSPRN5_cjs.CSVMultisigTapscript.isScriptValid(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
3335
3347
|
);
|
|
3336
3348
|
if (!utxoExitLeaf) {
|
|
3337
3349
|
throw new Error(
|
|
@@ -3346,7 +3358,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3346
3358
|
amount: BigInt(utxo.value)
|
|
3347
3359
|
},
|
|
3348
3360
|
tapLeafScript: [utxoExitLeaf],
|
|
3349
|
-
sequence:
|
|
3361
|
+
sequence: chunk7TXSPRN5_cjs.getSequence(utxoExitLeaf)
|
|
3350
3362
|
});
|
|
3351
3363
|
}
|
|
3352
3364
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -3443,6 +3455,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3443
3455
|
signers: reports
|
|
3444
3456
|
};
|
|
3445
3457
|
if (vtxoMigratable.length > 0) {
|
|
3458
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3446
3459
|
report.vtxos = await this.runMigrationLeg(
|
|
3447
3460
|
vtxoMigratable,
|
|
3448
3461
|
(c) => c.vtxo.value,
|
|
@@ -3450,7 +3463,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3450
3463
|
vtxoMaxAmount,
|
|
3451
3464
|
dustAmount,
|
|
3452
3465
|
"VTXO",
|
|
3453
|
-
(capped) => wallet.sendSelectedVtxosToSelf(
|
|
3466
|
+
(capped) => wallet.sendSelectedVtxosToSelf(
|
|
3467
|
+
capped.map((c) => c.vtxo),
|
|
3468
|
+
now
|
|
3469
|
+
),
|
|
3470
|
+
(c) => canMigrateBySend(c.vtxo, now)
|
|
3454
3471
|
);
|
|
3455
3472
|
}
|
|
3456
3473
|
if (boardingMigratable.length > 0) {
|
|
@@ -3490,10 +3507,22 @@ var VtxoManager = class _VtxoManager {
|
|
|
3490
3507
|
* the server ceiling by the cap). The dust floor guards the degenerate cases
|
|
3491
3508
|
* where every input was oversized or the whole holding sums below dust.
|
|
3492
3509
|
*/
|
|
3493
|
-
async runMigrationLeg(candidates, valueOf, toRef, vtxoMaxAmount, dustAmount, legName, submit) {
|
|
3510
|
+
async runMigrationLeg(candidates, valueOf, toRef, vtxoMaxAmount, dustAmount, legName, submit, eligible) {
|
|
3511
|
+
const notSpendableRefs = [];
|
|
3512
|
+
const migratable = eligible ? candidates.filter((c) => {
|
|
3513
|
+
if (eligible(c)) return true;
|
|
3514
|
+
notSpendableRefs.push(toRef(c));
|
|
3515
|
+
return false;
|
|
3516
|
+
}) : candidates;
|
|
3517
|
+
if (notSpendableRefs.length > 0) {
|
|
3518
|
+
console.warn(
|
|
3519
|
+
`Deprecated-signer migration (${legName}): ${notSpendableRefs.length} input(s) are no longer cooperatively spendable at the current chain tip and were excluded; they recover through the sweep/recovery path instead.`
|
|
3520
|
+
);
|
|
3521
|
+
}
|
|
3522
|
+
const notSpendableField = notSpendableRefs.length > 0 ? { notSpendableOffchain: notSpendableRefs } : {};
|
|
3494
3523
|
const oversizedRefs = [];
|
|
3495
3524
|
const sized = [];
|
|
3496
|
-
for (const c of
|
|
3525
|
+
for (const c of migratable) {
|
|
3497
3526
|
if (vtxoMaxAmount >= 0n && BigInt(valueOf(c)) > vtxoMaxAmount) {
|
|
3498
3527
|
oversizedRefs.push(toRef(c));
|
|
3499
3528
|
} else {
|
|
@@ -3513,11 +3542,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
3513
3542
|
const deferred = sized.length - capped.length;
|
|
3514
3543
|
const totalAmount = capped.reduce((sum, c) => sum + BigInt(valueOf(c)), 0n);
|
|
3515
3544
|
if (totalAmount < dustAmount) {
|
|
3516
|
-
const
|
|
3545
|
+
const skipped = sized.length > 0 ? "below-dust" : oversizedRefs.length > 0 ? "oversized-only" : notSpendableRefs.length > 0 ? "not-spendable-only" : "below-dust";
|
|
3517
3546
|
return {
|
|
3518
3547
|
migrated: [],
|
|
3519
|
-
skipped
|
|
3520
|
-
...oversizedField
|
|
3548
|
+
skipped,
|
|
3549
|
+
...oversizedField,
|
|
3550
|
+
...notSpendableField
|
|
3521
3551
|
};
|
|
3522
3552
|
}
|
|
3523
3553
|
try {
|
|
@@ -3526,13 +3556,15 @@ var VtxoManager = class _VtxoManager {
|
|
|
3526
3556
|
txid,
|
|
3527
3557
|
migrated: capped.map(toRef),
|
|
3528
3558
|
...deferred > 0 ? { deferred } : {},
|
|
3529
|
-
...oversizedField
|
|
3559
|
+
...oversizedField,
|
|
3560
|
+
...notSpendableField
|
|
3530
3561
|
};
|
|
3531
3562
|
} catch (e) {
|
|
3532
3563
|
return {
|
|
3533
3564
|
migrated: [],
|
|
3534
3565
|
error: e instanceof Error ? e.message : String(e),
|
|
3535
|
-
...oversizedField
|
|
3566
|
+
...oversizedField,
|
|
3567
|
+
...notSpendableField
|
|
3536
3568
|
};
|
|
3537
3569
|
}
|
|
3538
3570
|
}
|
|
@@ -3560,8 +3592,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3560
3592
|
if (!serverPubKey) continue;
|
|
3561
3593
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
3562
3594
|
if (cls.status === "CURRENT") continue;
|
|
3563
|
-
const recoverable = vtxos.filter((v) =>
|
|
3564
|
-
const spendable = vtxos.filter((v) =>
|
|
3595
|
+
const recoverable = vtxos.filter((v) => v.isSwept && !chunk7TXSPRN5_cjs.hasTerminalSpend(v));
|
|
3596
|
+
const spendable = vtxos.filter((v) => !chunk7TXSPRN5_cjs.hasTerminalSpend(v) && !v.isSwept);
|
|
3565
3597
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
3566
3598
|
let recoverableCount = 0;
|
|
3567
3599
|
let recoverableValue = 0;
|
|
@@ -3574,7 +3606,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3574
3606
|
awaitingSweepCount = spendable.length;
|
|
3575
3607
|
awaitingSweepValue = value;
|
|
3576
3608
|
for (const v of spendable) {
|
|
3577
|
-
const exp = v
|
|
3609
|
+
const exp = chunk7TXSPRN5_cjs.toBatchExpiry(v);
|
|
3578
3610
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
3579
3611
|
nextSweepEta = exp;
|
|
3580
3612
|
}
|
|
@@ -3610,7 +3642,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3610
3642
|
}
|
|
3611
3643
|
if (isCooperativelyMigratable(cls.status)) {
|
|
3612
3644
|
for (const v of spendable) {
|
|
3613
|
-
if (
|
|
3645
|
+
if (v.expiresAt === void 0 && v.expiresAtHeight === void 0) continue;
|
|
3614
3646
|
migratable.push({ vtxo: v, classification: cls });
|
|
3615
3647
|
}
|
|
3616
3648
|
} else if (cls.status === "EXPIRED") {
|
|
@@ -3835,7 +3867,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3835
3867
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
3836
3868
|
getBoardingTimelock() {
|
|
3837
3869
|
const wallet = this.getSweepWallet();
|
|
3838
|
-
const exitScript =
|
|
3870
|
+
const exitScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
3839
3871
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
3840
3872
|
);
|
|
3841
3873
|
return exitScript.params.timelock;
|
|
@@ -3966,8 +3998,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3966
3998
|
* or doesn't carry the metadata.
|
|
3967
3999
|
*/
|
|
3968
4000
|
extractSpentOutpoint(error) {
|
|
3969
|
-
const ark =
|
|
3970
|
-
if (!
|
|
4001
|
+
const ark = chunkEB3ALGTM_cjs.maybeArkError(error);
|
|
4002
|
+
if (!chunkEB3ALGTM_cjs.isArkError(ark, chunkEB3ALGTM_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
3971
4003
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
3972
4004
|
if (typeof raw !== "string") return void 0;
|
|
3973
4005
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -3988,7 +4020,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3988
4020
|
* candidates and lets the post-submit `VTXO_ALREADY_SPENT` recovery
|
|
3989
4021
|
* handle whatever slipped through.
|
|
3990
4022
|
*/
|
|
3991
|
-
async revalidateBeforeSettle(candidates, thresholdMs) {
|
|
4023
|
+
async revalidateBeforeSettle(candidates, thresholdMs, now) {
|
|
3992
4024
|
if (candidates.length === 0) return candidates;
|
|
3993
4025
|
try {
|
|
3994
4026
|
const cm = await this.wallet.getContractManager();
|
|
@@ -3998,7 +4030,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3998
4030
|
return candidates;
|
|
3999
4031
|
}
|
|
4000
4032
|
try {
|
|
4001
|
-
const refreshed = await this.
|
|
4033
|
+
const refreshed = await this.selectExpiringVtxos(thresholdMs, now);
|
|
4002
4034
|
const candidateKeys = new Set(candidates.map((v) => `${v.txid}:${v.vout}`));
|
|
4003
4035
|
return refreshed.filter((v) => candidateKeys.has(`${v.txid}:${v.vout}`));
|
|
4004
4036
|
} catch (e) {
|
|
@@ -4116,10 +4148,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
4116
4148
|
(u) => u.status.confirmed && !this.knownBoardingUtxos.has(`${u.txid}:${u.vout}`) && !expiredSet.has(`${u.txid}:${u.vout}`)
|
|
4117
4149
|
);
|
|
4118
4150
|
let expiringVtxos = [];
|
|
4151
|
+
let now;
|
|
4119
4152
|
if (!this.renewalInProgress) {
|
|
4120
4153
|
try {
|
|
4121
|
-
|
|
4122
|
-
expiringVtxos = await this.
|
|
4154
|
+
now = await fetchTimeHeight(this.wallet);
|
|
4155
|
+
expiringVtxos = await this.selectExpiringVtxos(void 0, now);
|
|
4156
|
+
expiringVtxos = await this.revalidateBeforeSettle(expiringVtxos, void 0, now);
|
|
4123
4157
|
} catch (e) {
|
|
4124
4158
|
console.error("Error fetching expiring VTXOs:", e);
|
|
4125
4159
|
}
|
|
@@ -4151,17 +4185,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4151
4185
|
totalAmount += BigInt(u.value) - BigInt(inputFee.satoshis);
|
|
4152
4186
|
}
|
|
4153
4187
|
const filteredVtxos = [];
|
|
4154
|
-
for (const v of byExpiryAscending(expiringVtxos)) {
|
|
4188
|
+
for (const v of byExpiryAscending(expiringVtxos, now ?? { timestamp: /* @__PURE__ */ new Date() })) {
|
|
4155
4189
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
4156
4190
|
break;
|
|
4157
4191
|
}
|
|
4158
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4159
|
-
amount: BigInt(v.value),
|
|
4160
|
-
type: v.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
4161
|
-
weight: 0,
|
|
4162
|
-
birth: v.createdAt,
|
|
4163
|
-
expiry: v.virtualStatus.batchExpiry ? new Date(v.virtualStatus.batchExpiry) : void 0
|
|
4164
|
-
});
|
|
4192
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(v));
|
|
4165
4193
|
if (inputFee.satoshis >= v.value) {
|
|
4166
4194
|
continue;
|
|
4167
4195
|
}
|
|
@@ -4181,7 +4209,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4181
4209
|
const arkAddress = await this.wallet.getAddress();
|
|
4182
4210
|
const outputFee = estimator.evalOffchainOutput({
|
|
4183
4211
|
amount: totalAmount,
|
|
4184
|
-
script: base.hex.encode(
|
|
4212
|
+
script: base.hex.encode(chunk7TXSPRN5_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4185
4213
|
});
|
|
4186
4214
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
4187
4215
|
if (totalAmount < dustAmount) return;
|
|
@@ -4261,7 +4289,7 @@ var ArkNote = class _ArkNote {
|
|
|
4261
4289
|
this.value = value;
|
|
4262
4290
|
this.HRP = HRP;
|
|
4263
4291
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
4264
|
-
this.vtxoScript = new
|
|
4292
|
+
this.vtxoScript = new chunk7TXSPRN5_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
4265
4293
|
const leaf = this.vtxoScript.leaves[0];
|
|
4266
4294
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
4267
4295
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -4365,8 +4393,8 @@ function readUInt32BE(array, offset) {
|
|
|
4365
4393
|
function noteTapscript(preimageHash) {
|
|
4366
4394
|
return btcSigner.Script.encode(["SHA256", preimageHash, "EQUAL"]);
|
|
4367
4395
|
}
|
|
4368
|
-
var
|
|
4369
|
-
constructor(privateKey, serverPubKey, csvTimelock, hrp =
|
|
4396
|
+
var ArkadeCash = class _ArkadeCash {
|
|
4397
|
+
constructor(privateKey, serverPubKey, csvTimelock, hrp = _ArkadeCash.DefaultHRP) {
|
|
4370
4398
|
this.csvTimelock = csvTimelock;
|
|
4371
4399
|
this.hrp = hrp;
|
|
4372
4400
|
if (privateKey.length !== 32) {
|
|
@@ -4385,7 +4413,7 @@ var ArkCash = class _ArkCash {
|
|
|
4385
4413
|
}
|
|
4386
4414
|
csvTimelock;
|
|
4387
4415
|
hrp;
|
|
4388
|
-
static DefaultHRP = "
|
|
4416
|
+
static DefaultHRP = "arkadecash";
|
|
4389
4417
|
static Version = 0;
|
|
4390
4418
|
static PayloadLength = 1 + 32 + 32 + 4;
|
|
4391
4419
|
// 69 bytes
|
|
@@ -4408,35 +4436,35 @@ var ArkCash = class _ArkCash {
|
|
|
4408
4436
|
return this._publicKey.slice();
|
|
4409
4437
|
}
|
|
4410
4438
|
static generate(serverPubKey, csvTimelock, hrp) {
|
|
4411
|
-
return new
|
|
4439
|
+
return new _ArkadeCash(utils_js.randomPrivateKeyBytes(), serverPubKey, csvTimelock, hrp);
|
|
4412
4440
|
}
|
|
4413
4441
|
static fromString(encoded) {
|
|
4414
4442
|
const decoded = base.bech32m.decodeUnsafe(encoded.trim().toLowerCase(), 1023);
|
|
4415
4443
|
if (!decoded) {
|
|
4416
|
-
throw new Error("Invalid
|
|
4444
|
+
throw new Error("Invalid arkadeCash string: failed to decode bech32m");
|
|
4417
4445
|
}
|
|
4418
4446
|
const data = new Uint8Array(base.bech32m.fromWords(decoded.words));
|
|
4419
|
-
if (data.length !==
|
|
4447
|
+
if (data.length !== _ArkadeCash.PayloadLength) {
|
|
4420
4448
|
throw new Error(
|
|
4421
|
-
`Invalid
|
|
4449
|
+
`Invalid arkadeCash data length: expected ${_ArkadeCash.PayloadLength} bytes, got ${data.length}`
|
|
4422
4450
|
);
|
|
4423
4451
|
}
|
|
4424
4452
|
const version = data[0];
|
|
4425
|
-
if (version !==
|
|
4426
|
-
throw new Error(`Unsupported
|
|
4453
|
+
if (version !== _ArkadeCash.Version) {
|
|
4454
|
+
throw new Error(`Unsupported arkadeCash version: ${version}`);
|
|
4427
4455
|
}
|
|
4428
4456
|
const privateKey = data.slice(1, 33);
|
|
4429
4457
|
const serverPubKey = data.slice(33, 65);
|
|
4430
4458
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
4431
|
-
const csvTimelock =
|
|
4432
|
-
return new
|
|
4459
|
+
const csvTimelock = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
4460
|
+
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
4433
4461
|
}
|
|
4434
4462
|
toString() {
|
|
4435
|
-
const data = new Uint8Array(
|
|
4436
|
-
data[0] =
|
|
4463
|
+
const data = new Uint8Array(_ArkadeCash.PayloadLength);
|
|
4464
|
+
data[0] = _ArkadeCash.Version;
|
|
4437
4465
|
data.set(this._privateKey, 1);
|
|
4438
4466
|
data.set(this._serverPubKey, 33);
|
|
4439
|
-
const sequence =
|
|
4467
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(this.csvTimelock);
|
|
4440
4468
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
4441
4469
|
const words = base.bech32m.toWords(data);
|
|
4442
4470
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -4445,7 +4473,7 @@ var ArkCash = class _ArkCash {
|
|
|
4445
4473
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
4446
4474
|
}
|
|
4447
4475
|
get vtxoScript() {
|
|
4448
|
-
return new
|
|
4476
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
4449
4477
|
pubKey: this._publicKey,
|
|
4450
4478
|
serverPubKey: this._serverPubKey,
|
|
4451
4479
|
csvTimelock: this.csvTimelock
|
|
@@ -4706,7 +4734,7 @@ async function captureExitBranch(params) {
|
|
|
4706
4734
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4707
4735
|
if (nonCommitment.length > 0) {
|
|
4708
4736
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4709
|
-
psbtByTxid.set(
|
|
4737
|
+
psbtByTxid.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4710
4738
|
}
|
|
4711
4739
|
}
|
|
4712
4740
|
}
|
|
@@ -4749,10 +4777,10 @@ var IndexerExitDataSource = class {
|
|
|
4749
4777
|
while (hasMore) {
|
|
4750
4778
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
4751
4779
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
4752
|
-
{ pageIndex, pageSize:
|
|
4780
|
+
{ pageIndex, pageSize: chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE }
|
|
4753
4781
|
);
|
|
4754
4782
|
chain.push(...page);
|
|
4755
|
-
hasMore = meta ? page.length ===
|
|
4783
|
+
hasMore = meta ? page.length === chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4756
4784
|
pageIndex++;
|
|
4757
4785
|
}
|
|
4758
4786
|
return chain;
|
|
@@ -4764,12 +4792,12 @@ var IndexerExitDataSource = class {
|
|
|
4764
4792
|
while (hasMore) {
|
|
4765
4793
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
4766
4794
|
pageIndex,
|
|
4767
|
-
pageSize:
|
|
4795
|
+
pageSize: chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE
|
|
4768
4796
|
});
|
|
4769
4797
|
for (const psbt of txs) {
|
|
4770
|
-
out.set(
|
|
4798
|
+
out.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4771
4799
|
}
|
|
4772
|
-
hasMore = page ? txs.length ===
|
|
4800
|
+
hasMore = page ? txs.length === chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4773
4801
|
pageIndex++;
|
|
4774
4802
|
}
|
|
4775
4803
|
return out;
|
|
@@ -4790,7 +4818,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4790
4818
|
}
|
|
4791
4819
|
}
|
|
4792
4820
|
function psbtInputTxids(psbtBase64) {
|
|
4793
|
-
const tx =
|
|
4821
|
+
const tx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4794
4822
|
const ids = [];
|
|
4795
4823
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4796
4824
|
const txid = tx.getInput(i).txid;
|
|
@@ -4893,7 +4921,7 @@ function createExitChainResolver(params) {
|
|
|
4893
4921
|
|
|
4894
4922
|
// src/providers/availability.ts
|
|
4895
4923
|
function isRetryableProviderError(error) {
|
|
4896
|
-
return error instanceof
|
|
4924
|
+
return error instanceof chunkEB3ALGTM_cjs.ProviderUnavailableError || error instanceof chunkEB3ALGTM_cjs.FetchError || chunkEB3ALGTM_cjs.isFetchTimeoutError(error);
|
|
4897
4925
|
}
|
|
4898
4926
|
|
|
4899
4927
|
// src/utils/syncCursors.ts
|
|
@@ -5146,7 +5174,7 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
5146
5174
|
if (!isRetryableProviderError(err)) throw err;
|
|
5147
5175
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
5148
5176
|
if (!snapshot) {
|
|
5149
|
-
throw new
|
|
5177
|
+
throw new chunkEB3ALGTM_cjs.ProviderUnavailableError(
|
|
5150
5178
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
5151
5179
|
{ cause: err }
|
|
5152
5180
|
);
|
|
@@ -5519,13 +5547,13 @@ function subtractAssets(spent, change) {
|
|
|
5519
5547
|
return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
|
|
5520
5548
|
}
|
|
5521
5549
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, getTxCreatedAt) {
|
|
5522
|
-
const fromOldestVtxo =
|
|
5550
|
+
const fromOldestVtxo = vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
5523
5551
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
5524
5552
|
const sent = [];
|
|
5525
5553
|
let received = [];
|
|
5526
5554
|
for (const vtxo of fromOldestVtxo) {
|
|
5527
5555
|
if (vtxo.status.isLeaf) {
|
|
5528
|
-
const commitmentTxid = vtxo.
|
|
5556
|
+
const commitmentTxid = vtxo.commitmentTxIds[0];
|
|
5529
5557
|
const vtxoCreatedAt = vtxo.createdAt.getTime();
|
|
5530
5558
|
const ignoredCommitment = commitmentsToIgnore.has(commitmentTxid) || !!vtxo.settledBy && commitmentsToIgnore.has(vtxo.settledBy);
|
|
5531
5559
|
if (ignoredCommitment) {
|
|
@@ -5533,7 +5561,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5533
5561
|
unmatchedSettledBoardingTxs,
|
|
5534
5562
|
(tx) => tx.createdAt <= vtxoCreatedAt && (tx.key.commitmentTxid === commitmentTxid || tx.key.commitmentTxid === vtxo.settledBy)
|
|
5535
5563
|
);
|
|
5536
|
-
} else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.
|
|
5564
|
+
} else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.commitmentTxIds[0]).length === 0) {
|
|
5537
5565
|
const duplicateBoardingReceive = consumeBoardingReceive(
|
|
5538
5566
|
unmatchedSettledBoardingTxs,
|
|
5539
5567
|
(tx) => tx.amount === vtxo.value && tx.createdAt <= vtxoCreatedAt
|
|
@@ -5596,7 +5624,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5596
5624
|
}
|
|
5597
5625
|
if (vtxo.settledBy && !commitmentsToIgnore.has(vtxo.settledBy) && !sent.some((s) => s.key.commitmentTxid === vtxo.settledBy)) {
|
|
5598
5626
|
const changes = fromOldestVtxo.filter(
|
|
5599
|
-
(v) => v.status.isLeaf && v.
|
|
5627
|
+
(v) => v.status.isLeaf && v.commitmentTxIds.length > 0 && v.commitmentTxIds.every((_) => vtxo.settledBy === _)
|
|
5600
5628
|
);
|
|
5601
5629
|
const forfeitVtxos = fromOldestVtxo.filter((v) => v.settledBy === vtxo.settledBy);
|
|
5602
5630
|
const forfeitAmount = forfeitVtxos.reduce((acc, v) => acc + v.value, 0);
|
|
@@ -5681,7 +5709,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5681
5709
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5682
5710
|
withRecoverable: false
|
|
5683
5711
|
});
|
|
5684
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5712
|
+
const controlAssetRef = params.controlAssetId ? chunkEB3ALGTM_cjs.AssetRef.fromId(chunkEB3ALGTM_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5685
5713
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5686
5714
|
let totalBtcSelected = 0n;
|
|
5687
5715
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5694,8 +5722,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5694
5722
|
}
|
|
5695
5723
|
}
|
|
5696
5724
|
const groups = [];
|
|
5697
|
-
const issuedAssetOutput =
|
|
5698
|
-
const issuedAssetGroup =
|
|
5725
|
+
const issuedAssetOutput = chunkEB3ALGTM_cjs.AssetOutput.create(0, params.amount);
|
|
5726
|
+
const issuedAssetGroup = chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5699
5727
|
null,
|
|
5700
5728
|
controlAssetRef,
|
|
5701
5729
|
[],
|
|
@@ -5710,28 +5738,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5710
5738
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5711
5739
|
for (const asset of assets) {
|
|
5712
5740
|
if (asset.assetId !== assetId) continue;
|
|
5713
|
-
changeInputs.push(
|
|
5741
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5714
5742
|
}
|
|
5715
5743
|
}
|
|
5716
5744
|
groups.push(
|
|
5717
|
-
|
|
5718
|
-
|
|
5745
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5746
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5719
5747
|
null,
|
|
5720
5748
|
changeInputs,
|
|
5721
|
-
[
|
|
5749
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)],
|
|
5722
5750
|
[]
|
|
5723
5751
|
)
|
|
5724
5752
|
);
|
|
5725
5753
|
}
|
|
5726
5754
|
}
|
|
5727
5755
|
const address = await this.wallet.getAddress();
|
|
5728
|
-
const outputAddress =
|
|
5756
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5729
5757
|
const outputs = [
|
|
5730
5758
|
{
|
|
5731
5759
|
script: outputAddress.pkScript,
|
|
5732
5760
|
amount: BigInt(totalBtcSelected)
|
|
5733
5761
|
},
|
|
5734
|
-
Extension.create([
|
|
5762
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5735
5763
|
];
|
|
5736
5764
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5737
5765
|
coinSelection.inputs,
|
|
@@ -5739,7 +5767,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5739
5767
|
);
|
|
5740
5768
|
return {
|
|
5741
5769
|
arkTxId: arkTxid,
|
|
5742
|
-
assetId:
|
|
5770
|
+
assetId: chunkEB3ALGTM_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5743
5771
|
};
|
|
5744
5772
|
}
|
|
5745
5773
|
/**
|
|
@@ -5811,16 +5839,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5811
5839
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5812
5840
|
for (const asset of assets) {
|
|
5813
5841
|
if (asset.assetId !== params.assetId) continue;
|
|
5814
|
-
reissueInputs.push(
|
|
5842
|
+
reissueInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5815
5843
|
}
|
|
5816
5844
|
}
|
|
5817
5845
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5818
|
-
const reissueAssetIdObj =
|
|
5819
|
-
const reissueAssetGroup =
|
|
5846
|
+
const reissueAssetIdObj = chunkEB3ALGTM_cjs.AssetId.fromString(params.assetId);
|
|
5847
|
+
const reissueAssetGroup = chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5820
5848
|
reissueAssetIdObj,
|
|
5821
5849
|
null,
|
|
5822
5850
|
reissueInputs,
|
|
5823
|
-
[
|
|
5851
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5824
5852
|
[]
|
|
5825
5853
|
);
|
|
5826
5854
|
const groups = [reissueAssetGroup];
|
|
@@ -5829,27 +5857,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5829
5857
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5830
5858
|
for (const asset of assets) {
|
|
5831
5859
|
if (asset.assetId !== assetId) continue;
|
|
5832
|
-
changeInputs.push(
|
|
5860
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5833
5861
|
}
|
|
5834
5862
|
}
|
|
5835
5863
|
groups.push(
|
|
5836
|
-
|
|
5837
|
-
|
|
5864
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5865
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5838
5866
|
null,
|
|
5839
5867
|
changeInputs,
|
|
5840
|
-
[
|
|
5868
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)],
|
|
5841
5869
|
[]
|
|
5842
5870
|
)
|
|
5843
5871
|
);
|
|
5844
5872
|
}
|
|
5845
5873
|
const address = await this.wallet.getAddress();
|
|
5846
|
-
const outputAddress =
|
|
5874
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5847
5875
|
const outputs = [
|
|
5848
5876
|
{
|
|
5849
5877
|
script: outputAddress.pkScript,
|
|
5850
5878
|
amount: BigInt(totalBtcSelected)
|
|
5851
5879
|
},
|
|
5852
|
-
Extension.create([
|
|
5880
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5853
5881
|
];
|
|
5854
5882
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5855
5883
|
return arkTxid;
|
|
@@ -5916,27 +5944,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5916
5944
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5917
5945
|
for (const asset of assets) {
|
|
5918
5946
|
if (asset.assetId !== assetId) continue;
|
|
5919
|
-
changeInputs.push(
|
|
5947
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5920
5948
|
}
|
|
5921
5949
|
}
|
|
5922
5950
|
groups.push(
|
|
5923
|
-
|
|
5924
|
-
|
|
5951
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5952
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5925
5953
|
null,
|
|
5926
5954
|
changeInputs,
|
|
5927
|
-
amount > 0n ? [
|
|
5955
|
+
amount > 0n ? [chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)] : [],
|
|
5928
5956
|
[]
|
|
5929
5957
|
)
|
|
5930
5958
|
);
|
|
5931
5959
|
}
|
|
5932
5960
|
const address = await this.wallet.getAddress();
|
|
5933
|
-
const outputAddress =
|
|
5961
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5934
5962
|
const outputs = [
|
|
5935
5963
|
{
|
|
5936
5964
|
script: outputAddress.pkScript,
|
|
5937
5965
|
amount: BigInt(totalBtcSelected)
|
|
5938
5966
|
},
|
|
5939
|
-
Extension.create([
|
|
5967
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5940
5968
|
];
|
|
5941
5969
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5942
5970
|
return arkTxid;
|
|
@@ -5961,7 +5989,7 @@ function castMetadata(metadata) {
|
|
|
5961
5989
|
} else {
|
|
5962
5990
|
throw new Error("Invalid metadata value type");
|
|
5963
5991
|
}
|
|
5964
|
-
md.push(
|
|
5992
|
+
md.push(chunkEB3ALGTM_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5965
5993
|
}
|
|
5966
5994
|
return md;
|
|
5967
5995
|
}
|
|
@@ -5982,10 +6010,10 @@ var DelegateManagerImpl = class {
|
|
|
5982
6010
|
if (vtxos.length === 0) {
|
|
5983
6011
|
return { delegated: [], failed: [] };
|
|
5984
6012
|
}
|
|
5985
|
-
const destinationScript =
|
|
6013
|
+
const destinationScript = chunk7TXSPRN5_cjs.ArkAddress.decode(destination).pkScript;
|
|
5986
6014
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
5987
6015
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
5988
|
-
const eligible = vtxos.filter(
|
|
6016
|
+
const eligible = vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo).filter(
|
|
5989
6017
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
5990
6018
|
);
|
|
5991
6019
|
if (eligible.length === 0) {
|
|
@@ -6010,14 +6038,15 @@ var DelegateManagerImpl = class {
|
|
|
6010
6038
|
}
|
|
6011
6039
|
return { delegated: eligible, failed: [] };
|
|
6012
6040
|
}
|
|
6041
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
6013
6042
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
6014
6043
|
let recoverableVtxos = [];
|
|
6015
6044
|
for (const vtxo of eligible) {
|
|
6016
|
-
if (
|
|
6045
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
6017
6046
|
recoverableVtxos.push(vtxo);
|
|
6018
6047
|
continue;
|
|
6019
6048
|
}
|
|
6020
|
-
const expiry = vtxo
|
|
6049
|
+
const expiry = chunk7TXSPRN5_cjs.toBatchExpiry(vtxo);
|
|
6021
6050
|
if (!expiry) continue;
|
|
6022
6051
|
const dayKey = getDayTimestamp(expiry);
|
|
6023
6052
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -6081,10 +6110,8 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6081
6110
|
throw new Error("unable to delegate: delegate provider not configured");
|
|
6082
6111
|
}
|
|
6083
6112
|
if (!delegateAt) {
|
|
6084
|
-
const
|
|
6085
|
-
|
|
6086
|
-
Number.MAX_SAFE_INTEGER
|
|
6087
|
-
);
|
|
6113
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
6114
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunk7TXSPRN5_cjs.canRecoverOnchain(coin, now) && chunk7TXSPRN5_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunk7TXSPRN5_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
|
|
6088
6115
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
6089
6116
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
6090
6117
|
} else {
|
|
@@ -6113,11 +6140,8 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6113
6140
|
let amount = 0n;
|
|
6114
6141
|
for (const coin of vtxos) {
|
|
6115
6142
|
const inputFee = estimator.evalOffchainInput({
|
|
6116
|
-
|
|
6117
|
-
type: "vtxo"
|
|
6118
|
-
weight: 0,
|
|
6119
|
-
birth: coin.createdAt,
|
|
6120
|
-
expiry: coin.virtualStatus.batchExpiry ? new Date(coin.virtualStatus.batchExpiry) : void 0
|
|
6143
|
+
...chunk7TXSPRN5_cjs.toOffchainInputFeeParams(coin),
|
|
6144
|
+
type: "vtxo"
|
|
6121
6145
|
});
|
|
6122
6146
|
if (inputFee.value >= coin.value) {
|
|
6123
6147
|
continue;
|
|
@@ -6130,7 +6154,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6130
6154
|
const delegateFee = BigInt(Number(fee));
|
|
6131
6155
|
if (delegateFee > 0n) {
|
|
6132
6156
|
outputs.push({
|
|
6133
|
-
script:
|
|
6157
|
+
script: chunk7TXSPRN5_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
6134
6158
|
amount: delegateFee
|
|
6135
6159
|
});
|
|
6136
6160
|
}
|
|
@@ -6163,10 +6187,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6163
6187
|
destinationScript
|
|
6164
6188
|
);
|
|
6165
6189
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
6166
|
-
btcSigner.Address(
|
|
6190
|
+
btcSigner.Address(chunk7TXSPRN5_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
6167
6191
|
);
|
|
6168
6192
|
const forfeits = await Promise.all(
|
|
6169
|
-
vtxos.filter((v) => !
|
|
6193
|
+
vtxos.filter((v) => !chunk7TXSPRN5_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
6170
6194
|
const forfeit = await makeDelegateForfeitTx(
|
|
6171
6195
|
coin,
|
|
6172
6196
|
dust,
|
|
@@ -6191,7 +6215,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
6191
6215
|
index: input.vout,
|
|
6192
6216
|
witnessUtxo: {
|
|
6193
6217
|
amount: BigInt(input.value),
|
|
6194
|
-
script:
|
|
6218
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
6195
6219
|
},
|
|
6196
6220
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
6197
6221
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -6249,7 +6273,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
6249
6273
|
expire_at: 0,
|
|
6250
6274
|
cosigners_public_keys: cosignerPubKeys
|
|
6251
6275
|
};
|
|
6252
|
-
const proof =
|
|
6276
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, outputs);
|
|
6253
6277
|
const signedProof = await identity.sign(proof);
|
|
6254
6278
|
return {
|
|
6255
6279
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -6267,10 +6291,10 @@ function getDayTimestamp(timestamp) {
|
|
|
6267
6291
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
6268
6292
|
if (!vtxo.tapTree) return void 0;
|
|
6269
6293
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
6270
|
-
const vtxoScript =
|
|
6294
|
+
const vtxoScript = chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
6271
6295
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
6272
|
-
const arkTapscript =
|
|
6273
|
-
if (!
|
|
6296
|
+
const arkTapscript = chunk7TXSPRN5_cjs.decodeTapscript(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
6297
|
+
if (!chunk7TXSPRN5_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
6274
6298
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
6275
6299
|
});
|
|
6276
6300
|
}
|
|
@@ -6458,7 +6482,7 @@ async function closeDatabase(dbName) {
|
|
|
6458
6482
|
return true;
|
|
6459
6483
|
}
|
|
6460
6484
|
function scriptFromArkAddress(address) {
|
|
6461
|
-
return base.hex.encode(
|
|
6485
|
+
return base.hex.encode(chunk7TXSPRN5_cjs.ArkAddress.decode(address).pkScript);
|
|
6462
6486
|
}
|
|
6463
6487
|
|
|
6464
6488
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -6954,7 +6978,8 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
6954
6978
|
);
|
|
6955
6979
|
}
|
|
6956
6980
|
async function getVtxosForContract(repo, contract) {
|
|
6957
|
-
|
|
6981
|
+
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
6982
|
+
return vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
6958
6983
|
}
|
|
6959
6984
|
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
6960
6985
|
if (repo.saveVtxosForScript) {
|
|
@@ -7158,7 +7183,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
7158
7183
|
const s = base.hex.decode(t.s);
|
|
7159
7184
|
return [cb, s];
|
|
7160
7185
|
};
|
|
7161
|
-
var deserializeVtxo = (o) => ({
|
|
7186
|
+
var deserializeVtxo = (o) => chunk7TXSPRN5_cjs.normalizeVtxo({
|
|
7162
7187
|
...o,
|
|
7163
7188
|
createdAt: new Date(o.createdAt),
|
|
7164
7189
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -7757,50 +7782,12 @@ function getLifecycleWeight(v) {
|
|
|
7757
7782
|
if (v.arkTxId) weight += 2;
|
|
7758
7783
|
return weight;
|
|
7759
7784
|
}
|
|
7785
|
+
|
|
7786
|
+
// src/repositories/migrations/walletRepositoryImpl.ts
|
|
7760
7787
|
var getVtxosStorageKey = (address) => `vtxos:${address}`;
|
|
7761
7788
|
var getUtxosStorageKey = (address) => `utxos:${address}`;
|
|
7762
7789
|
var getTransactionsStorageKey = (address) => `tx:${address}`;
|
|
7763
7790
|
var walletStateStorageKey = "wallet:state";
|
|
7764
|
-
var serializeVtxo2 = (v) => ({
|
|
7765
|
-
...v,
|
|
7766
|
-
tapTree: base.hex.encode(v.tapTree),
|
|
7767
|
-
forfeitTapLeafScript: serializeTapLeaf2(v.forfeitTapLeafScript),
|
|
7768
|
-
intentTapLeafScript: serializeTapLeaf2(v.intentTapLeafScript),
|
|
7769
|
-
extraWitness: v.extraWitness?.map(base.hex.encode),
|
|
7770
|
-
assets: serializeAssets(v.assets)
|
|
7771
|
-
});
|
|
7772
|
-
var serializeUtxo2 = (u) => ({
|
|
7773
|
-
...u,
|
|
7774
|
-
tapTree: base.hex.encode(u.tapTree),
|
|
7775
|
-
forfeitTapLeafScript: serializeTapLeaf2(u.forfeitTapLeafScript),
|
|
7776
|
-
intentTapLeafScript: serializeTapLeaf2(u.intentTapLeafScript),
|
|
7777
|
-
extraWitness: u.extraWitness?.map(base.hex.encode)
|
|
7778
|
-
});
|
|
7779
|
-
var deserializeVtxo2 = (o) => ({
|
|
7780
|
-
...o,
|
|
7781
|
-
createdAt: new Date(o.createdAt),
|
|
7782
|
-
tapTree: base.hex.decode(o.tapTree),
|
|
7783
|
-
forfeitTapLeafScript: deserializeTapLeaf2(o.forfeitTapLeafScript),
|
|
7784
|
-
intentTapLeafScript: deserializeTapLeaf2(o.intentTapLeafScript),
|
|
7785
|
-
extraWitness: o.extraWitness?.map(base.hex.decode),
|
|
7786
|
-
assets: deserializeAssets(o.assets)
|
|
7787
|
-
});
|
|
7788
|
-
var deserializeUtxo2 = (o) => ({
|
|
7789
|
-
...o,
|
|
7790
|
-
tapTree: base.hex.decode(o.tapTree),
|
|
7791
|
-
forfeitTapLeafScript: deserializeTapLeaf2(o.forfeitTapLeafScript),
|
|
7792
|
-
intentTapLeafScript: deserializeTapLeaf2(o.intentTapLeafScript),
|
|
7793
|
-
extraWitness: o.extraWitness?.map(base.hex.decode)
|
|
7794
|
-
});
|
|
7795
|
-
var serializeTapLeaf2 = ([cb, s]) => ({
|
|
7796
|
-
cb: base.hex.encode(btcSigner.TaprootControlBlock.encode(cb)),
|
|
7797
|
-
s: base.hex.encode(s)
|
|
7798
|
-
});
|
|
7799
|
-
var deserializeTapLeaf2 = (t) => {
|
|
7800
|
-
const cb = btcSigner.TaprootControlBlock.decode(base.hex.decode(t.cb));
|
|
7801
|
-
const s = base.hex.decode(t.s);
|
|
7802
|
-
return [cb, s];
|
|
7803
|
-
};
|
|
7804
7791
|
var WalletRepositoryImpl = class {
|
|
7805
7792
|
version = 1;
|
|
7806
7793
|
storage;
|
|
@@ -7812,7 +7799,7 @@ var WalletRepositoryImpl = class {
|
|
|
7812
7799
|
if (!stored) return [];
|
|
7813
7800
|
try {
|
|
7814
7801
|
const parsed = JSON.parse(stored);
|
|
7815
|
-
return parsed.map(
|
|
7802
|
+
return parsed.map(deserializeVtxo);
|
|
7816
7803
|
} catch (error) {
|
|
7817
7804
|
console.error(`Failed to parse VTXOs for address ${address}:`, error);
|
|
7818
7805
|
return [];
|
|
@@ -7832,7 +7819,7 @@ var WalletRepositoryImpl = class {
|
|
|
7832
7819
|
}
|
|
7833
7820
|
await this.storage.setItem(
|
|
7834
7821
|
getVtxosStorageKey(address),
|
|
7835
|
-
JSON.stringify(storedVtxos.map(
|
|
7822
|
+
JSON.stringify(storedVtxos.map(serializeVtxo))
|
|
7836
7823
|
);
|
|
7837
7824
|
}
|
|
7838
7825
|
async clearVtxos(address) {
|
|
@@ -7846,7 +7833,7 @@ var WalletRepositoryImpl = class {
|
|
|
7846
7833
|
if (!stored) return [];
|
|
7847
7834
|
try {
|
|
7848
7835
|
const parsed = JSON.parse(stored);
|
|
7849
|
-
return parsed.map(
|
|
7836
|
+
return parsed.map(deserializeUtxo);
|
|
7850
7837
|
} catch (error) {
|
|
7851
7838
|
console.error(`Failed to parse UTXOs for address ${address}:`, error);
|
|
7852
7839
|
return [];
|
|
@@ -7866,7 +7853,7 @@ var WalletRepositoryImpl = class {
|
|
|
7866
7853
|
});
|
|
7867
7854
|
await this.storage.setItem(
|
|
7868
7855
|
getUtxosStorageKey(address),
|
|
7869
|
-
JSON.stringify(storedUtxos.map(
|
|
7856
|
+
JSON.stringify(storedUtxos.map(serializeUtxo))
|
|
7870
7857
|
);
|
|
7871
7858
|
}
|
|
7872
7859
|
async clearUtxos(address) {
|
|
@@ -8332,7 +8319,7 @@ var ContractWatcher = class {
|
|
|
8332
8319
|
this.connectionState = "connected";
|
|
8333
8320
|
this.reconnectAttempts = 0;
|
|
8334
8321
|
this.listenLoop().catch((e) => {
|
|
8335
|
-
if (
|
|
8322
|
+
if (chunkEB3ALGTM_cjs.isEventSourceError(e)) {
|
|
8336
8323
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8337
8324
|
} else {
|
|
8338
8325
|
console.error(e);
|
|
@@ -8518,15 +8505,27 @@ var ContractWatcher = class {
|
|
|
8518
8505
|
}
|
|
8519
8506
|
/**
|
|
8520
8507
|
* Handle a subscription update.
|
|
8508
|
+
*
|
|
8509
|
+
* Normalization boundary: `getSubscription` is part of the public `IndexerProvider` interface,
|
|
8510
|
+
* so a consumer implementation may yield legacy-shaped VTXOs. Normalizing on ingest also fixes
|
|
8511
|
+
* the shape of the payloads emitted to external event consumers.
|
|
8521
8512
|
*/
|
|
8522
8513
|
handleSubscriptionUpdate(update) {
|
|
8523
8514
|
if (!this.eventCallback) return;
|
|
8524
8515
|
const timestamp = Date.now();
|
|
8525
8516
|
if (update.newVtxos?.length) {
|
|
8526
|
-
this.processSubscriptionVtxos(
|
|
8517
|
+
this.processSubscriptionVtxos(
|
|
8518
|
+
update.newVtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo),
|
|
8519
|
+
"vtxo_received",
|
|
8520
|
+
timestamp
|
|
8521
|
+
);
|
|
8527
8522
|
}
|
|
8528
8523
|
if (update.spentVtxos?.length) {
|
|
8529
|
-
this.processSubscriptionVtxos(
|
|
8524
|
+
this.processSubscriptionVtxos(
|
|
8525
|
+
update.spentVtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo),
|
|
8526
|
+
"vtxo_spent",
|
|
8527
|
+
timestamp
|
|
8528
|
+
);
|
|
8530
8529
|
}
|
|
8531
8530
|
}
|
|
8532
8531
|
/**
|
|
@@ -8656,7 +8655,7 @@ async function reconcileIntents(deps) {
|
|
|
8656
8655
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
8657
8656
|
if (outpoints.length > 0) {
|
|
8658
8657
|
try {
|
|
8659
|
-
const { vtxos } = await deps.indexerProvider
|
|
8658
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
8660
8659
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
8661
8660
|
} catch (e) {
|
|
8662
8661
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -8858,7 +8857,7 @@ var ContractManager = class _ContractManager {
|
|
|
8858
8857
|
* `persisted` is `true`.
|
|
8859
8858
|
*/
|
|
8860
8859
|
async upsertContract(params) {
|
|
8861
|
-
const handler =
|
|
8860
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(params.type);
|
|
8862
8861
|
if (!handler) {
|
|
8863
8862
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
8864
8863
|
}
|
|
@@ -8909,9 +8908,10 @@ var ContractManager = class _ContractManager {
|
|
|
8909
8908
|
* Safety-critical invariants (spec §2.C / §4):
|
|
8910
8909
|
* - `opts.materialize(i)` throwing is structural/fatal: it is NOT
|
|
8911
8910
|
* wrapped — it propagates and aborts the scan.
|
|
8912
|
-
* - A `discoverAt` rejection is collected into `handlerErrors` and
|
|
8913
|
-
*
|
|
8914
|
-
*
|
|
8911
|
+
* - A `discoverAt` rejection is collected into `handlerErrors` and makes
|
|
8912
|
+
* its index *indeterminate*: it does NOT advance the gap counter, and
|
|
8913
|
+
* the scan stops verifying there, reporting `truncatedAt`. Only an index
|
|
8914
|
+
* every handler answered for can be a confirmed miss.
|
|
8915
8915
|
* - `persistAndWatchContract` rejecting is operational/fatal and
|
|
8916
8916
|
* propagates (only `discoverAt` is guarded).
|
|
8917
8917
|
* - Within an index the handler probes run concurrently (independent
|
|
@@ -8925,8 +8925,12 @@ var ContractManager = class _ContractManager {
|
|
|
8925
8925
|
* over-scanned, nothing is discarded, and `materialize`/`discoverAt` are
|
|
8926
8926
|
* invoked on exactly the same index set. The window's hits are still
|
|
8927
8927
|
* processed strictly in ascending index order, so the discovered set,
|
|
8928
|
-
* persisted rows, `
|
|
8929
|
-
* identical to the serial path — only the wall-clock
|
|
8928
|
+
* persisted rows, `highestConfirmedUsedIndex`, and `handlerErrors` are
|
|
8929
|
+
* byte-for-byte identical to the serial path — only the wall-clock
|
|
8930
|
+
* differs. Truncation is the one exception: a window's concurrent probes
|
|
8931
|
+
* can surface hits above the failed index that a serial scan would never
|
|
8932
|
+
* have reached, so a truncated batched scan discovers a superset — never
|
|
8933
|
+
* a subset — of the serial one.
|
|
8930
8934
|
*/
|
|
8931
8935
|
async scanContracts(opts) {
|
|
8932
8936
|
const gapLimit = opts.gapLimit ?? 20;
|
|
@@ -8941,14 +8945,15 @@ var ContractManager = class _ContractManager {
|
|
|
8941
8945
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
8942
8946
|
);
|
|
8943
8947
|
}
|
|
8944
|
-
const registered =
|
|
8948
|
+
const registered = chunk5XMVTK5S_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk5XMVTK5S_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
8945
8949
|
const discoverables = [
|
|
8946
8950
|
...registered.filter((h) => h.type === "boarding"),
|
|
8947
8951
|
...registered.filter((h) => h.type !== "boarding")
|
|
8948
8952
|
];
|
|
8949
8953
|
const maxIdx = opts.hd ? SCAN_MAX_INDEX : 0;
|
|
8950
8954
|
const handlerErrors = [];
|
|
8951
|
-
let
|
|
8955
|
+
let highestConfirmedUsedIndex = -1;
|
|
8956
|
+
let truncatedAt;
|
|
8952
8957
|
let unused = 0;
|
|
8953
8958
|
let i = 0;
|
|
8954
8959
|
const probeIndex = async (index) => {
|
|
@@ -8975,6 +8980,7 @@ var ContractManager = class _ContractManager {
|
|
|
8975
8980
|
const index = windowIndices[w];
|
|
8976
8981
|
const probes = windowProbes[w];
|
|
8977
8982
|
let hitAtThisIndex = false;
|
|
8983
|
+
let indeterminate = false;
|
|
8978
8984
|
for (let h = 0; h < discoverables.length; h++) {
|
|
8979
8985
|
const probe = probes[h];
|
|
8980
8986
|
if (!probe.ok) {
|
|
@@ -8983,6 +8989,7 @@ var ContractManager = class _ContractManager {
|
|
|
8983
8989
|
index,
|
|
8984
8990
|
error: probe.error
|
|
8985
8991
|
});
|
|
8992
|
+
indeterminate = true;
|
|
8986
8993
|
continue;
|
|
8987
8994
|
}
|
|
8988
8995
|
for (const c of probe.found) {
|
|
@@ -8990,21 +8997,26 @@ var ContractManager = class _ContractManager {
|
|
|
8990
8997
|
hitAtThisIndex = true;
|
|
8991
8998
|
}
|
|
8992
8999
|
}
|
|
8993
|
-
if (
|
|
8994
|
-
|
|
8995
|
-
|
|
8996
|
-
|
|
8997
|
-
|
|
8998
|
-
}
|
|
9000
|
+
if (indeterminate && truncatedAt === void 0) truncatedAt = index;
|
|
9001
|
+
if (hitAtThisIndex) highestConfirmedUsedIndex = index;
|
|
9002
|
+
if (truncatedAt !== void 0) continue;
|
|
9003
|
+
if (hitAtThisIndex) unused = 0;
|
|
9004
|
+
else unused += 1;
|
|
8999
9005
|
}
|
|
9006
|
+
if (truncatedAt !== void 0) break;
|
|
9000
9007
|
i = windowEnd + 1;
|
|
9001
9008
|
}
|
|
9002
|
-
if (opts.hd && i > maxIdx && unused < gapLimit) {
|
|
9009
|
+
if (opts.hd && truncatedAt === void 0 && i > maxIdx && unused < gapLimit) {
|
|
9003
9010
|
throw new Error(
|
|
9004
9011
|
`scanContracts: reached SCAN_MAX_INDEX (${SCAN_MAX_INDEX}) without closing the ${gapLimit}-index gap window; a Discoverable handler may be returning unconditional hits`
|
|
9005
9012
|
);
|
|
9006
9013
|
}
|
|
9007
|
-
return {
|
|
9014
|
+
return {
|
|
9015
|
+
lastIndexUsed: highestConfirmedUsedIndex,
|
|
9016
|
+
highestConfirmedUsedIndex,
|
|
9017
|
+
...truncatedAt !== void 0 && { truncatedAt },
|
|
9018
|
+
handlerErrors
|
|
9019
|
+
};
|
|
9008
9020
|
}
|
|
9009
9021
|
/**
|
|
9010
9022
|
* Get contracts with optional filters.
|
|
@@ -9051,7 +9063,9 @@ var ContractManager = class _ContractManager {
|
|
|
9051
9063
|
byScript.set(contract.script, contract);
|
|
9052
9064
|
}
|
|
9053
9065
|
const tapscriptCache = /* @__PURE__ */ new Map();
|
|
9054
|
-
return vtxos.map(
|
|
9066
|
+
return vtxos.map(
|
|
9067
|
+
(vtxo) => extendVirtualCoinForContract(chunk7TXSPRN5_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
9068
|
+
);
|
|
9055
9069
|
}
|
|
9056
9070
|
buildContractsDbFilter(filter) {
|
|
9057
9071
|
return {
|
|
@@ -9131,7 +9145,7 @@ var ContractManager = class _ContractManager {
|
|
|
9131
9145
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
9132
9146
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9133
9147
|
if (!contract) return [];
|
|
9134
|
-
const handler =
|
|
9148
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
9135
9149
|
if (!handler) return [];
|
|
9136
9150
|
const script = handler.createScript(contract.params);
|
|
9137
9151
|
const context = {
|
|
@@ -9151,7 +9165,7 @@ var ContractManager = class _ContractManager {
|
|
|
9151
9165
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
9152
9166
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9153
9167
|
if (!contract) return [];
|
|
9154
|
-
const handler =
|
|
9168
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
9155
9169
|
if (!handler) return [];
|
|
9156
9170
|
const script = handler.createScript(contract.params);
|
|
9157
9171
|
const context = {
|
|
@@ -9219,7 +9233,7 @@ var ContractManager = class _ContractManager {
|
|
|
9219
9233
|
}
|
|
9220
9234
|
async refreshOutpoints(outpoints) {
|
|
9221
9235
|
if (outpoints.length === 0) return;
|
|
9222
|
-
const { vtxos } = await this.config.indexerProvider
|
|
9236
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9223
9237
|
outpoints
|
|
9224
9238
|
});
|
|
9225
9239
|
if (vtxos.length === 0) return;
|
|
@@ -9347,7 +9361,7 @@ var ContractManager = class _ContractManager {
|
|
|
9347
9361
|
async reconcilePendingFrontier(contracts) {
|
|
9348
9362
|
const scripts = contracts.map((c) => c.script);
|
|
9349
9363
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
9350
|
-
const { vtxos } = await this.config.indexerProvider
|
|
9364
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9351
9365
|
scripts,
|
|
9352
9366
|
pendingOnly: true
|
|
9353
9367
|
});
|
|
@@ -9418,7 +9432,7 @@ var ContractManager = class _ContractManager {
|
|
|
9418
9432
|
}
|
|
9419
9433
|
return result;
|
|
9420
9434
|
}
|
|
9421
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
9435
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9422
9436
|
if (contracts.length === 0) {
|
|
9423
9437
|
return /* @__PURE__ */ new Map();
|
|
9424
9438
|
}
|
|
@@ -9438,7 +9452,7 @@ var ContractManager = class _ContractManager {
|
|
|
9438
9452
|
let pageIndex = 0;
|
|
9439
9453
|
let hasMore = true;
|
|
9440
9454
|
while (hasMore) {
|
|
9441
|
-
const { vtxos, page } = await this.config.indexerProvider
|
|
9455
|
+
const { vtxos, page } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9442
9456
|
scripts,
|
|
9443
9457
|
...windowOpts,
|
|
9444
9458
|
pageIndex,
|
|
@@ -9596,7 +9610,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9596
9610
|
*/
|
|
9597
9611
|
materializeDescriptorAt(index) {
|
|
9598
9612
|
const descriptor = this.identity.descriptor;
|
|
9599
|
-
const network =
|
|
9613
|
+
const network = chunk5XMVTK5S_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9600
9614
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9601
9615
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9602
9616
|
if (!keyInfo?.keyExpression) {
|
|
@@ -9740,7 +9754,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9740
9754
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
9741
9755
|
if (!provider) return void 0;
|
|
9742
9756
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
9743
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
9757
|
+
const expectedContractType = setup.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
9744
9758
|
const factoryOpts = {
|
|
9745
9759
|
walletRepository: setup.walletRepository,
|
|
9746
9760
|
contractRepository: setup.contractRepository,
|
|
@@ -9923,7 +9937,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9923
9937
|
const newAddress = newTapscript.address(wallet.network.hrp, wallet.arkServerPublicKey).encode();
|
|
9924
9938
|
const manager = await wallet.getContractManager();
|
|
9925
9939
|
const csvTimelock = newTapscript.options.csvTimelock;
|
|
9926
|
-
const csvTimelockStr =
|
|
9940
|
+
const csvTimelockStr = chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString();
|
|
9927
9941
|
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
9928
9942
|
const baseParams = {
|
|
9929
9943
|
script: newScript,
|
|
@@ -9937,11 +9951,11 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9937
9951
|
// produce unsigned PSBTs that the server rejects with
|
|
9938
9952
|
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
9939
9953
|
metadata: {
|
|
9940
|
-
source:
|
|
9954
|
+
source: chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE,
|
|
9941
9955
|
signingDescriptor: descriptor
|
|
9942
9956
|
}
|
|
9943
9957
|
};
|
|
9944
|
-
if (newTapscript instanceof
|
|
9958
|
+
if (newTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
9945
9959
|
await manager.createContract({
|
|
9946
9960
|
...baseParams,
|
|
9947
9961
|
type: "delegate",
|
|
@@ -9973,7 +9987,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9973
9987
|
};
|
|
9974
9988
|
function deriveLeafPubkey(descriptor) {
|
|
9975
9989
|
try {
|
|
9976
|
-
return
|
|
9990
|
+
return chunk5XMVTK5S_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
9977
9991
|
} catch (e) {
|
|
9978
9992
|
throw new NonRangeableDescriptorError(
|
|
9979
9993
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -9982,10 +9996,10 @@ function deriveLeafPubkey(descriptor) {
|
|
|
9982
9996
|
}
|
|
9983
9997
|
}
|
|
9984
9998
|
function rebuildTapscript(current, pubKey) {
|
|
9985
|
-
if (current instanceof
|
|
9986
|
-
return new
|
|
9999
|
+
if (current instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
10000
|
+
return new chunk5XMVTK5S_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
9987
10001
|
}
|
|
9988
|
-
return new
|
|
10002
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
9989
10003
|
}
|
|
9990
10004
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
9991
10005
|
const candidates = await contractRepository.getContracts({
|
|
@@ -9994,7 +10008,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
9994
10008
|
});
|
|
9995
10009
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
9996
10010
|
const matching = candidates.filter(
|
|
9997
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10011
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE
|
|
9998
10012
|
).sort((a, b) => {
|
|
9999
10013
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10000
10014
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10170,12 +10184,12 @@ var InputSignerRouter = class {
|
|
|
10170
10184
|
};
|
|
10171
10185
|
|
|
10172
10186
|
// src/wallet/wallet.ts
|
|
10173
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
10187
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunk7TXSPRN5_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
10174
10188
|
function intentProofJobs(coins) {
|
|
10175
10189
|
if (coins.length === 0) return [];
|
|
10176
10190
|
const coinJobs = coins.map((coin, i) => ({
|
|
10177
10191
|
index: i + 1,
|
|
10178
|
-
lookupScript:
|
|
10192
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
10179
10193
|
}));
|
|
10180
10194
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
10181
10195
|
}
|
|
@@ -10199,7 +10213,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
10199
10213
|
const seen = /* @__PURE__ */ new Set();
|
|
10200
10214
|
const deduped = [];
|
|
10201
10215
|
for (const timelock of timelocks) {
|
|
10202
|
-
const sequence =
|
|
10216
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(timelock).toString();
|
|
10203
10217
|
if (seen.has(sequence)) continue;
|
|
10204
10218
|
seen.add(sequence);
|
|
10205
10219
|
deduped.push(timelock);
|
|
@@ -10216,7 +10230,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10216
10230
|
state: "active"
|
|
10217
10231
|
});
|
|
10218
10232
|
const newest = candidates.filter(
|
|
10219
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10233
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE
|
|
10220
10234
|
).sort((a, b) => {
|
|
10221
10235
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10222
10236
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10224,7 +10238,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10224
10238
|
if (!newest?.params.pubKey) return baseline;
|
|
10225
10239
|
try {
|
|
10226
10240
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
10227
|
-
return new
|
|
10241
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
10228
10242
|
} catch (e) {
|
|
10229
10243
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
10230
10244
|
return baseline;
|
|
@@ -10255,14 +10269,14 @@ var cashReport = (vtxo, reason) => ({
|
|
|
10255
10269
|
value: vtxo.value,
|
|
10256
10270
|
reason
|
|
10257
10271
|
});
|
|
10258
|
-
var
|
|
10272
|
+
var ArkadeCashCreateError = class extends Error {
|
|
10259
10273
|
constructor(cash, cause) {
|
|
10260
10274
|
super(
|
|
10261
|
-
`Failed to create
|
|
10275
|
+
`Failed to create ArkadeCash: send failed after the note may have been submitted. Recover with claimCash using the token on this error's \`cash\` field.`
|
|
10262
10276
|
);
|
|
10263
10277
|
this.cash = cash;
|
|
10264
10278
|
this.cause = cause;
|
|
10265
|
-
this.name = "
|
|
10279
|
+
this.name = "ArkadeCashCreateError";
|
|
10266
10280
|
}
|
|
10267
10281
|
cash;
|
|
10268
10282
|
cause;
|
|
@@ -10544,7 +10558,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10544
10558
|
*/
|
|
10545
10559
|
static async setupWalletConfig(config, pubKey) {
|
|
10546
10560
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10547
|
-
const arkProvider = config.arkProvider || new
|
|
10561
|
+
const arkProvider = config.arkProvider || new chunkEB3ALGTM_cjs.RestArkProvider(arkadeServerUrl);
|
|
10548
10562
|
let indexerProvider = config.indexerProvider;
|
|
10549
10563
|
if (!indexerProvider) {
|
|
10550
10564
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10561,7 +10575,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10561
10575
|
indexerUrl = arkadeServerUrl;
|
|
10562
10576
|
}
|
|
10563
10577
|
}
|
|
10564
|
-
indexerProvider = new
|
|
10578
|
+
indexerProvider = new chunkEB3ALGTM_cjs.RestIndexerProvider(indexerUrl);
|
|
10565
10579
|
}
|
|
10566
10580
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10567
10581
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10570,7 +10584,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10570
10584
|
source: serverInfoSource,
|
|
10571
10585
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
10572
10586
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
10573
|
-
const network =
|
|
10587
|
+
const network = chunk7TXSPRN5_cjs.getNetwork(info.network);
|
|
10574
10588
|
if ("descriptor" in config.identity) {
|
|
10575
10589
|
const descriptor = config.identity.descriptor;
|
|
10576
10590
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -10617,11 +10631,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10617
10631
|
serverPubKey,
|
|
10618
10632
|
csvTimelock: exitTimelock
|
|
10619
10633
|
};
|
|
10620
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10621
|
-
const boardingTapscript =
|
|
10634
|
+
const offchainTapscript = !delegatePubKey ? new chunk5XMVTK5S_cjs.DefaultVtxo.Script(offchainOptions) : new chunk5XMVTK5S_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
10635
|
+
const boardingTapscript = chunk5XMVTK5S_cjs.BoardingContractHandler.createScript({
|
|
10622
10636
|
pubKey: base.hex.encode(pubKey),
|
|
10623
10637
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10624
|
-
csvTimelock:
|
|
10638
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingTimelock).toString()
|
|
10625
10639
|
});
|
|
10626
10640
|
return {
|
|
10627
10641
|
arkProvider,
|
|
@@ -10725,20 +10739,21 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10725
10739
|
}
|
|
10726
10740
|
let recoverable = 0;
|
|
10727
10741
|
let pendingRecovery = 0;
|
|
10728
|
-
const
|
|
10729
|
-
const
|
|
10730
|
-
(coin) => coin
|
|
10742
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
10743
|
+
const settled = vtxos.filter(
|
|
10744
|
+
(coin) => chunk7TXSPRN5_cjs.canSpendOffchain(coin, now) && !coin.isPreconfirmed && !isPendingRecovery(coin)
|
|
10731
10745
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
10732
|
-
const
|
|
10733
|
-
(coin) => (coin
|
|
10746
|
+
const preconfirmed = vtxos.filter(
|
|
10747
|
+
(coin) => chunk7TXSPRN5_cjs.canSpendOffchain(coin, now) && coin.isPreconfirmed && !isPendingRecovery(coin)
|
|
10734
10748
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
10735
|
-
|
|
10749
|
+
const available = unlockedVtxos.filter((coin) => chunk7TXSPRN5_cjs.canSpendOffchain(coin, now) && !isPendingRecovery(coin)).reduce((sum, coin) => sum + coin.value, 0);
|
|
10750
|
+
recoverable = vtxos.filter((coin) => chunk7TXSPRN5_cjs.canRecoverOnchain(coin, now) && !isPendingRecovery(coin)).reduce((sum, coin) => sum + coin.value, 0);
|
|
10736
10751
|
pendingRecovery = vtxos.filter(isPendingRecovery).reduce((sum, coin) => sum + coin.value, 0);
|
|
10737
10752
|
const totalBoarding = confirmed + unconfirmed;
|
|
10738
10753
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
10739
10754
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
10740
10755
|
for (const vtxo of vtxos) {
|
|
10741
|
-
if (
|
|
10756
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
10742
10757
|
if (vtxo.assets) {
|
|
10743
10758
|
for (const a of vtxo.assets) {
|
|
10744
10759
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -10774,12 +10789,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10774
10789
|
const f = filter ?? { withRecoverable: true, withUnrolled: false };
|
|
10775
10790
|
const contractManager = await this.getContractManager();
|
|
10776
10791
|
const vtxos = await contractManager.getContractsWithVtxos();
|
|
10792
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
10777
10793
|
return vtxos.flatMap((_) => _.vtxos).filter((vtxo) => {
|
|
10778
10794
|
if (this._pendingSpendOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
10779
10795
|
return false;
|
|
10780
10796
|
}
|
|
10781
|
-
if (
|
|
10782
|
-
if (!f.withRecoverable && (
|
|
10797
|
+
if (!chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) {
|
|
10798
|
+
if (!f.withRecoverable && chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
10783
10799
|
return false;
|
|
10784
10800
|
}
|
|
10785
10801
|
return true;
|
|
@@ -10812,7 +10828,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10812
10828
|
const response = await contractManager.getContractsWithVtxos();
|
|
10813
10829
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
10814
10830
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
10815
|
-
const getTxCreatedAt = (txid) => this.indexerProvider
|
|
10831
|
+
const getTxCreatedAt = (txid) => chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, { outpoints: [{ txid, vout: 0 }] }).then((res) => res.vtxos[0]?.createdAt.getTime()).catch((err) => {
|
|
10816
10832
|
if (isRetryableProviderError(err)) return void 0;
|
|
10817
10833
|
throw err;
|
|
10818
10834
|
});
|
|
@@ -10888,6 +10904,12 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10888
10904
|
if (spent && commitmentTxid) {
|
|
10889
10905
|
commitmentsToIgnore.add(commitmentTxid);
|
|
10890
10906
|
}
|
|
10907
|
+
const boardingFacts = {
|
|
10908
|
+
isSpent: spent,
|
|
10909
|
+
isSwept: false,
|
|
10910
|
+
isPreconfirmed: false,
|
|
10911
|
+
commitmentTxIds: spent && commitmentTxid ? [commitmentTxid] : []
|
|
10912
|
+
};
|
|
10891
10913
|
utxos.push({
|
|
10892
10914
|
txid: tx.txid,
|
|
10893
10915
|
vout: i,
|
|
@@ -10897,10 +10919,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10897
10919
|
block_time: tx.status.block_time
|
|
10898
10920
|
},
|
|
10899
10921
|
isUnrolled: true,
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
},
|
|
10922
|
+
...boardingFacts,
|
|
10923
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(boardingFacts),
|
|
10924
|
+
spentBy: "",
|
|
10904
10925
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
10905
10926
|
script: scriptHex
|
|
10906
10927
|
});
|
|
@@ -10914,12 +10935,12 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10914
10935
|
const tx = {
|
|
10915
10936
|
key: {
|
|
10916
10937
|
boardingTxid: utxo.txid,
|
|
10917
|
-
commitmentTxid: utxo.
|
|
10938
|
+
commitmentTxid: utxo.commitmentTxIds[0] ?? "",
|
|
10918
10939
|
arkTxid: ""
|
|
10919
10940
|
},
|
|
10920
10941
|
amount: utxo.value,
|
|
10921
10942
|
type: "RECEIVED" /* TxReceived */,
|
|
10922
|
-
settled: utxo.
|
|
10943
|
+
settled: utxo.isSpent,
|
|
10923
10944
|
createdAt: utxo.status.block_time ? new Date(utxo.status.block_time * 1e3).getTime() : 0
|
|
10924
10945
|
};
|
|
10925
10946
|
if (!utxo.status.block_time) {
|
|
@@ -10955,9 +10976,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10955
10976
|
async getBoardingTapscripts(allowedSigners) {
|
|
10956
10977
|
const byScript = /* @__PURE__ */ new Map();
|
|
10957
10978
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
10958
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
10979
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
10959
10980
|
add(
|
|
10960
|
-
new
|
|
10981
|
+
new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
10961
10982
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
10962
10983
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
10963
10984
|
csvTimelock: boardingCsv
|
|
@@ -10972,7 +10993,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10972
10993
|
for (const c of boardingContracts) {
|
|
10973
10994
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
10974
10995
|
try {
|
|
10975
|
-
add(
|
|
10996
|
+
add(chunk5XMVTK5S_cjs.BoardingContractHandler.createScript(c.params));
|
|
10976
10997
|
} catch (e) {
|
|
10977
10998
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
10978
10999
|
}
|
|
@@ -11010,7 +11031,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11010
11031
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
11011
11032
|
// not the wallet's current boarding timelock, which a signer
|
|
11012
11033
|
// rotation may have changed.
|
|
11013
|
-
csvTimelock:
|
|
11034
|
+
csvTimelock: chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
11014
11035
|
coins: utxos
|
|
11015
11036
|
});
|
|
11016
11037
|
}
|
|
@@ -11143,11 +11164,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11143
11164
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
11144
11165
|
async fetchPendingTxs() {
|
|
11145
11166
|
const scripts = await this.getWalletScripts();
|
|
11146
|
-
let { vtxos } = await this.indexerProvider
|
|
11167
|
+
let { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
11147
11168
|
scripts
|
|
11148
11169
|
});
|
|
11149
11170
|
return vtxos.filter(
|
|
11150
|
-
(vtxo) => vtxo.
|
|
11171
|
+
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
11151
11172
|
).map((_) => _.arkTxId);
|
|
11152
11173
|
}
|
|
11153
11174
|
// ========================================================================
|
|
@@ -11176,7 +11197,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11176
11197
|
});
|
|
11177
11198
|
for (const contract of contracts) {
|
|
11178
11199
|
if (map.has(contract.script)) continue;
|
|
11179
|
-
const handler =
|
|
11200
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
11180
11201
|
if (handler) {
|
|
11181
11202
|
const script = handler.createScript(contract.params);
|
|
11182
11203
|
map.set(contract.script, script);
|
|
@@ -11246,7 +11267,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11246
11267
|
});
|
|
11247
11268
|
onVtxosPersisted = async (_contract, vtxos) => {
|
|
11248
11269
|
for (const v of vtxos) {
|
|
11249
|
-
if (v.
|
|
11270
|
+
if (v.isSpent) continue;
|
|
11250
11271
|
await captureExitBranch({
|
|
11251
11272
|
resolver,
|
|
11252
11273
|
repository: virtualTxRepository,
|
|
@@ -11270,7 +11291,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11270
11291
|
watcherConfig: this.watcherConfig
|
|
11271
11292
|
});
|
|
11272
11293
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
11273
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11294
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11274
11295
|
const baselineSigners = [
|
|
11275
11296
|
this.offchainTapscript.options.serverPubKey,
|
|
11276
11297
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -11278,8 +11299,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11278
11299
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
11279
11300
|
for (const serverPubKey of baselineSigners) {
|
|
11280
11301
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
11281
|
-
const csvTimelockStr =
|
|
11282
|
-
const defaultScript = new
|
|
11302
|
+
const csvTimelockStr = chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString();
|
|
11303
|
+
const defaultScript = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11283
11304
|
pubKey: baselinePubkey,
|
|
11284
11305
|
serverPubKey,
|
|
11285
11306
|
csvTimelock
|
|
@@ -11300,7 +11321,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11300
11321
|
});
|
|
11301
11322
|
}
|
|
11302
11323
|
if (delegatePubKey) {
|
|
11303
|
-
const delegateScript = new
|
|
11324
|
+
const delegateScript = new chunk5XMVTK5S_cjs.DelegateVtxo.Script({
|
|
11304
11325
|
pubKey: baselinePubkey,
|
|
11305
11326
|
serverPubKey,
|
|
11306
11327
|
delegatePubKey,
|
|
@@ -11324,9 +11345,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11324
11345
|
}
|
|
11325
11346
|
}
|
|
11326
11347
|
}
|
|
11327
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11348
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11328
11349
|
for (const serverPubKey of baselineSigners) {
|
|
11329
|
-
const baselineBoarding = new
|
|
11350
|
+
const baselineBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11330
11351
|
pubKey: baselinePubkey,
|
|
11331
11352
|
serverPubKey,
|
|
11332
11353
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11339,7 +11360,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11339
11360
|
params: {
|
|
11340
11361
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
11341
11362
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
11342
|
-
csvTimelock:
|
|
11363
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
11343
11364
|
},
|
|
11344
11365
|
script: boardingScriptHex,
|
|
11345
11366
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -11562,25 +11583,25 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11562
11583
|
return this.getBoardingAddress();
|
|
11563
11584
|
}
|
|
11564
11585
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11565
|
-
const pubKey =
|
|
11566
|
-
const newBoarding = new
|
|
11586
|
+
const pubKey = chunk5XMVTK5S_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11587
|
+
const newBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11567
11588
|
...this._boardingTapscript.options,
|
|
11568
11589
|
pubKey
|
|
11569
11590
|
});
|
|
11570
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11591
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11571
11592
|
const manager = await this.getContractManager();
|
|
11572
11593
|
await manager.createContract({
|
|
11573
11594
|
type: "boarding",
|
|
11574
11595
|
params: {
|
|
11575
11596
|
pubKey: base.hex.encode(pubKey),
|
|
11576
11597
|
serverPubKey: base.hex.encode(newBoarding.options.serverPubKey),
|
|
11577
|
-
csvTimelock:
|
|
11598
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString()
|
|
11578
11599
|
},
|
|
11579
11600
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11580
11601
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11581
11602
|
state: "active",
|
|
11582
11603
|
metadata: {
|
|
11583
|
-
source:
|
|
11604
|
+
source: chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE,
|
|
11584
11605
|
signingDescriptor: descriptor
|
|
11585
11606
|
}
|
|
11586
11607
|
});
|
|
@@ -11619,7 +11640,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11619
11640
|
const xonly = toXOnlyPubKey(newServerPubKey);
|
|
11620
11641
|
let newServerUnrollScript;
|
|
11621
11642
|
try {
|
|
11622
|
-
newServerUnrollScript =
|
|
11643
|
+
newServerUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
11623
11644
|
} catch (e) {
|
|
11624
11645
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11625
11646
|
}
|
|
@@ -11647,21 +11668,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11647
11668
|
const [currentBoardingRow] = await manager.getContracts({
|
|
11648
11669
|
script: currentBoardingScript
|
|
11649
11670
|
});
|
|
11650
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
11671
|
+
const newOffchain = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? new chunk5XMVTK5S_cjs.DelegateVtxo.Script({
|
|
11651
11672
|
...this.offchainTapscript.options,
|
|
11652
11673
|
serverPubKey: xonly
|
|
11653
|
-
}) : new
|
|
11674
|
+
}) : new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11654
11675
|
...this.offchainTapscript.options,
|
|
11655
11676
|
serverPubKey: xonly
|
|
11656
11677
|
});
|
|
11657
|
-
const newBoarding = new
|
|
11678
|
+
const newBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11658
11679
|
...this._boardingTapscript.options,
|
|
11659
11680
|
serverPubKey: xonly
|
|
11660
11681
|
});
|
|
11661
|
-
const offchainCsv =
|
|
11682
|
+
const offchainCsv = chunk7TXSPRN5_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
11662
11683
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
11663
11684
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
11664
|
-
if (newOffchain instanceof
|
|
11685
|
+
if (newOffchain instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
11665
11686
|
await manager.createContract({
|
|
11666
11687
|
type: "delegate",
|
|
11667
11688
|
params: {
|
|
@@ -11689,13 +11710,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11689
11710
|
metadata: currentOffchainRow?.metadata
|
|
11690
11711
|
});
|
|
11691
11712
|
}
|
|
11692
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
11713
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11693
11714
|
await manager.createContract({
|
|
11694
11715
|
type: "boarding",
|
|
11695
11716
|
params: {
|
|
11696
11717
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
11697
11718
|
serverPubKey: base.hex.encode(xonly),
|
|
11698
|
-
csvTimelock:
|
|
11719
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingCsv).toString()
|
|
11699
11720
|
},
|
|
11700
11721
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11701
11722
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -11723,14 +11744,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11723
11744
|
_restoreInFlight;
|
|
11724
11745
|
_addPendingSpends(inputs) {
|
|
11725
11746
|
for (const input of inputs) {
|
|
11726
|
-
if (
|
|
11747
|
+
if (chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
11727
11748
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
11728
11749
|
}
|
|
11729
11750
|
}
|
|
11730
11751
|
}
|
|
11731
11752
|
_removePendingSpends(inputs) {
|
|
11732
11753
|
for (const input of inputs) {
|
|
11733
|
-
if (
|
|
11754
|
+
if (chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
11734
11755
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
11735
11756
|
}
|
|
11736
11757
|
}
|
|
@@ -11790,7 +11811,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11790
11811
|
const hd = provider instanceof HDDescriptorProvider;
|
|
11791
11812
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
11792
11813
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
11793
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11814
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11794
11815
|
const arkInfo = await this.arkProvider.getInfo();
|
|
11795
11816
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
11796
11817
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -11809,7 +11830,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11809
11830
|
csvTimelocks: this.walletContractTimelocks,
|
|
11810
11831
|
// Boarding-exit CSV so the boarding handler can build its
|
|
11811
11832
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
11812
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
11833
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
11813
11834
|
delegatePubKey
|
|
11814
11835
|
};
|
|
11815
11836
|
const result = await manager.scanContracts({
|
|
@@ -11818,15 +11839,22 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11818
11839
|
materialize,
|
|
11819
11840
|
deps
|
|
11820
11841
|
});
|
|
11821
|
-
if (hd && result.
|
|
11822
|
-
await provider.advanceLastIndexUsed(result.
|
|
11842
|
+
if (hd && result.highestConfirmedUsedIndex >= 0) {
|
|
11843
|
+
await provider.advanceLastIndexUsed(result.highestConfirmedUsedIndex);
|
|
11823
11844
|
}
|
|
11824
11845
|
await manager.refreshVtxos({ includeInactive: true });
|
|
11846
|
+
const causes = result.handlerErrors.map(
|
|
11847
|
+
(e) => e.error instanceof Error ? e.error : new Error(String(e.error))
|
|
11848
|
+
);
|
|
11849
|
+
if (result.truncatedAt !== void 0) {
|
|
11850
|
+
throw new AggregateError(
|
|
11851
|
+
causes,
|
|
11852
|
+
`restore: scan truncated at index ${result.truncatedAt}; indices >= ${result.truncatedAt} are unverified (${result.handlerErrors.length} discovery handler failure(s)). Retry is safe (idempotent).`
|
|
11853
|
+
);
|
|
11854
|
+
}
|
|
11825
11855
|
if (result.handlerErrors.length > 0) {
|
|
11826
11856
|
throw new AggregateError(
|
|
11827
|
-
|
|
11828
|
-
(e) => e.error instanceof Error ? e.error : new Error(String(e.error))
|
|
11829
|
-
),
|
|
11857
|
+
causes,
|
|
11830
11858
|
`restore: ${result.handlerErrors.length} discovery handler(s) failed; the gap window may have closed early \u2014 retry is safe (idempotent).`
|
|
11831
11859
|
);
|
|
11832
11860
|
}
|
|
@@ -11913,7 +11941,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11913
11941
|
let serverUnrollScript;
|
|
11914
11942
|
try {
|
|
11915
11943
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
11916
|
-
serverUnrollScript =
|
|
11944
|
+
serverUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(raw);
|
|
11917
11945
|
} catch (e) {
|
|
11918
11946
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11919
11947
|
}
|
|
@@ -12050,7 +12078,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12050
12078
|
inputs: params.selectedVtxos,
|
|
12051
12079
|
changeAmount: BigInt(changeAmount)
|
|
12052
12080
|
};
|
|
12053
|
-
const outputAddress =
|
|
12081
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(params.address);
|
|
12054
12082
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
12055
12083
|
const outputs = [
|
|
12056
12084
|
{
|
|
@@ -12103,13 +12131,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12103
12131
|
}
|
|
12104
12132
|
}
|
|
12105
12133
|
const offchainAddress = await this.getAddress();
|
|
12106
|
-
const offchainPkScript =
|
|
12134
|
+
const offchainPkScript = chunk7TXSPRN5_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
12107
12135
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
12108
12136
|
if (!params) {
|
|
12109
12137
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
12110
12138
|
const estimator = new Estimator(fees.intentFee);
|
|
12111
12139
|
let amount = 0;
|
|
12112
|
-
const exitScript =
|
|
12140
|
+
const exitScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
12113
12141
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
12114
12142
|
);
|
|
12115
12143
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -12138,13 +12166,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12138
12166
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
12139
12167
|
break;
|
|
12140
12168
|
}
|
|
12141
|
-
const inputFee = estimator.evalOffchainInput(
|
|
12142
|
-
amount: BigInt(vtxo.value),
|
|
12143
|
-
type: vtxo.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
12144
|
-
weight: 0,
|
|
12145
|
-
birth: vtxo.createdAt,
|
|
12146
|
-
expiry: vtxo.virtualStatus.batchExpiry ? new Date(vtxo.virtualStatus.batchExpiry) : void 0
|
|
12147
|
-
});
|
|
12169
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(vtxo));
|
|
12148
12170
|
if (inputFee.satoshis >= vtxo.value) {
|
|
12149
12171
|
continue;
|
|
12150
12172
|
}
|
|
@@ -12189,7 +12211,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12189
12211
|
for (const [index, output] of params.outputs.entries()) {
|
|
12190
12212
|
let script;
|
|
12191
12213
|
try {
|
|
12192
|
-
const addr =
|
|
12214
|
+
const addr = chunk7TXSPRN5_cjs.ArkAddress.decode(output.address);
|
|
12193
12215
|
script = addr.pkScript;
|
|
12194
12216
|
hasOffchainOutputs = true;
|
|
12195
12217
|
} catch {
|
|
@@ -12360,9 +12382,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12360
12382
|
* renewal / offboard) is not a board and leaves the boarding address
|
|
12361
12383
|
* untouched.
|
|
12362
12384
|
*
|
|
12363
|
-
* Boarding inputs are the non-VTXO coins (no `
|
|
12385
|
+
* Boarding inputs are the non-VTXO coins (no `script`), the same
|
|
12364
12386
|
* discriminator {@link handleSettlementFinalizationEvent} uses; the
|
|
12365
|
-
* `typeof` guard skips arknote
|
|
12387
|
+
* `typeof` guard skips the arknote strings settle also accepts.
|
|
12366
12388
|
*
|
|
12367
12389
|
* No-ops for static / `auto` wallets (no descriptor provider — boarding
|
|
12368
12390
|
* stays on its fixed index-0 address). Best-effort and non-fatal: the
|
|
@@ -12375,7 +12397,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12375
12397
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
12376
12398
|
if (!this._descriptorProvider) return;
|
|
12377
12399
|
const consumedBoarding = inputs.some(
|
|
12378
|
-
(input) => typeof input !== "string" && !(
|
|
12400
|
+
(input) => typeof input !== "string" && !chunk7TXSPRN5_cjs.isVirtualCoin(input)
|
|
12379
12401
|
);
|
|
12380
12402
|
if (!consumedBoarding) return;
|
|
12381
12403
|
try {
|
|
@@ -12386,13 +12408,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12386
12408
|
}
|
|
12387
12409
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
|
|
12388
12410
|
const signedForfeits = [];
|
|
12389
|
-
const isVtxo = (input) => "virtualStatus" in input;
|
|
12390
12411
|
let settlementPsbt = btcSigner.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
12391
12412
|
let hasBoardingUtxos = false;
|
|
12392
12413
|
let connectorIndex = 0;
|
|
12393
12414
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
12394
12415
|
for (const input of inputs) {
|
|
12395
|
-
if (!
|
|
12416
|
+
if (!chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
12396
12417
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
12397
12418
|
const settlementInput = settlementPsbt.getInput(i);
|
|
12398
12419
|
if (!settlementInput.txid || settlementInput.index === void 0) {
|
|
@@ -12423,7 +12444,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12423
12444
|
}
|
|
12424
12445
|
continue;
|
|
12425
12446
|
}
|
|
12426
|
-
if (
|
|
12447
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
12427
12448
|
continue;
|
|
12428
12449
|
}
|
|
12429
12450
|
if (connectorsLeaves.length === 0) {
|
|
@@ -12451,7 +12472,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12451
12472
|
index: input.vout,
|
|
12452
12473
|
witnessUtxo: {
|
|
12453
12474
|
amount: BigInt(input.value),
|
|
12454
|
-
script:
|
|
12475
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12455
12476
|
},
|
|
12456
12477
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
12457
12478
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -12470,7 +12491,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12470
12491
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
12471
12492
|
{
|
|
12472
12493
|
index: 0,
|
|
12473
|
-
lookupScript:
|
|
12494
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12474
12495
|
}
|
|
12475
12496
|
]);
|
|
12476
12497
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -12528,7 +12549,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12528
12549
|
if (skip) {
|
|
12529
12550
|
return { skip };
|
|
12530
12551
|
}
|
|
12531
|
-
const sweepTapscript =
|
|
12552
|
+
const sweepTapscript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
|
|
12532
12553
|
timelock: {
|
|
12533
12554
|
value: event.batchExpiry,
|
|
12534
12555
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -12634,9 +12655,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12634
12655
|
...existing ?? {},
|
|
12635
12656
|
intentTxId,
|
|
12636
12657
|
registerProof: intent.proof,
|
|
12637
|
-
registerProofMessage:
|
|
12658
|
+
registerProofMessage: chunkEB3ALGTM_cjs.Intent.encodeMessage(intent.message),
|
|
12638
12659
|
deleteProof: deleteIntent.proof,
|
|
12639
|
-
deleteProofMessage:
|
|
12660
|
+
deleteProofMessage: chunkEB3ALGTM_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
12640
12661
|
intentVtxos: inputs.map((i) => ({
|
|
12641
12662
|
txid: i.txid,
|
|
12642
12663
|
vout: i.vout
|
|
@@ -12668,7 +12689,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12668
12689
|
try {
|
|
12669
12690
|
return await this.arkProvider.registerIntent(intent);
|
|
12670
12691
|
} catch (error) {
|
|
12671
|
-
if (error instanceof
|
|
12692
|
+
if (error instanceof chunkEB3ALGTM_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
12672
12693
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
12673
12694
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
12674
12695
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -12684,7 +12705,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12684
12705
|
expire_at: 0,
|
|
12685
12706
|
cosigners_public_keys: cosignerPubKeys
|
|
12686
12707
|
};
|
|
12687
|
-
const proof =
|
|
12708
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, outputs);
|
|
12688
12709
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12689
12710
|
return {
|
|
12690
12711
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12696,7 +12717,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12696
12717
|
type: "delete",
|
|
12697
12718
|
expire_at: 0
|
|
12698
12719
|
};
|
|
12699
|
-
const proof =
|
|
12720
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, []);
|
|
12700
12721
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12701
12722
|
return {
|
|
12702
12723
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12708,7 +12729,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12708
12729
|
type: "get-pending-tx",
|
|
12709
12730
|
expire_at: 0
|
|
12710
12731
|
};
|
|
12711
|
-
const proof =
|
|
12732
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, []);
|
|
12712
12733
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12713
12734
|
return {
|
|
12714
12735
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12730,13 +12751,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12730
12751
|
const scriptMap = await this.getScriptMap();
|
|
12731
12752
|
const allExtended = [];
|
|
12732
12753
|
const allScripts = [...scriptMap.keys()];
|
|
12733
|
-
const { vtxos: fetchedVtxos } = await this.indexerProvider
|
|
12754
|
+
const { vtxos: fetchedVtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
12734
12755
|
scripts: allScripts
|
|
12735
12756
|
});
|
|
12736
12757
|
for (const vtxo of fetchedVtxos) {
|
|
12737
12758
|
const vtxoScript = scriptMap.get(vtxo.script);
|
|
12738
12759
|
if (!vtxoScript) continue;
|
|
12739
|
-
if (vtxo.
|
|
12760
|
+
if (!vtxo.isSpent && !(vtxo.isPreconfirmed && !vtxo.isSwept)) {
|
|
12740
12761
|
continue;
|
|
12741
12762
|
}
|
|
12742
12763
|
allExtended.push({
|
|
@@ -12836,14 +12857,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12836
12857
|
}));
|
|
12837
12858
|
}
|
|
12838
12859
|
/**
|
|
12839
|
-
* Create an
|
|
12860
|
+
* Create an ArkadeCash bearer instrument.
|
|
12840
12861
|
*
|
|
12841
12862
|
* Generates a fresh keypair, sends the specified amount to a DefaultVtxo
|
|
12842
|
-
* controlled by the new key, and returns the encoded
|
|
12863
|
+
* controlled by the new key, and returns the encoded arkadeCash string.
|
|
12843
12864
|
* The receiver can claim the funds using `claimCash()` without ever
|
|
12844
12865
|
* sharing their address.
|
|
12845
12866
|
*
|
|
12846
|
-
*
|
|
12867
|
+
* ArkadeCash is a short-lived instrument: it carries a private key, so it is
|
|
12847
12868
|
* meant to be handed over and claimed promptly, not held. A note left
|
|
12848
12869
|
* unclaimed past its batch expiry is swept by the server and `claimCash`
|
|
12849
12870
|
* can only report it, not move it.
|
|
@@ -12851,16 +12872,16 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12851
12872
|
* @param amount - Amount in satoshis to send. Must be a whole number of
|
|
12852
12873
|
* sats at or above the dust threshold — a below-dust amount would mint an
|
|
12853
12874
|
* OP_RETURN output that is unspendable as cash.
|
|
12854
|
-
* @returns The encoded
|
|
12875
|
+
* @returns The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
12855
12876
|
*/
|
|
12856
12877
|
async createCash(amount) {
|
|
12857
12878
|
if (!Number.isSafeInteger(amount) || amount < Number(this.dustAmount)) {
|
|
12858
12879
|
throw new Error(
|
|
12859
|
-
`Invalid
|
|
12880
|
+
`Invalid ArkadeCash amount ${amount}: must be a whole number of sats >= dust (${this.dustAmount})`
|
|
12860
12881
|
);
|
|
12861
12882
|
}
|
|
12862
|
-
const cashHrp = this.network.hrp.replace(/ark$/, "
|
|
12863
|
-
const cash =
|
|
12883
|
+
const cashHrp = this.network.hrp.replace(/ark$/, "arkadecash");
|
|
12884
|
+
const cash = ArkadeCash.generate(
|
|
12864
12885
|
this.arkServerPublicKey,
|
|
12865
12886
|
this.offchainTapscript.options.csvTimelock,
|
|
12866
12887
|
cashHrp
|
|
@@ -12870,39 +12891,39 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12870
12891
|
try {
|
|
12871
12892
|
await this.send({ address, amount });
|
|
12872
12893
|
} catch (error) {
|
|
12873
|
-
throw new
|
|
12894
|
+
throw new ArkadeCashCreateError(cashStr, error);
|
|
12874
12895
|
}
|
|
12875
12896
|
return cashStr;
|
|
12876
12897
|
}
|
|
12877
12898
|
/**
|
|
12878
|
-
* Claim an
|
|
12899
|
+
* Claim an ArkadeCash bearer instrument: sweep what can be swept, report the
|
|
12879
12900
|
* rest.
|
|
12880
12901
|
*
|
|
12881
|
-
* Every spendable VTXO at the
|
|
12882
|
-
* its own offchain transaction, signed with the key carried by the
|
|
12902
|
+
* Every spendable VTXO at the arkadeCash address is swept to this wallet in
|
|
12903
|
+
* its own offchain transaction, signed with the key carried by the arkadeCash
|
|
12883
12904
|
* string. Nothing is ever persisted: no contract is imported, and the
|
|
12884
|
-
*
|
|
12905
|
+
* arkadeCash key is not stored. Anything that cannot be swept — server-swept,
|
|
12885
12906
|
* subdust, already claimed, or asset-bearing — is returned in `unclaimed`
|
|
12886
12907
|
* with a per-VTXO reason and otherwise ignored.
|
|
12887
12908
|
*
|
|
12888
|
-
* The
|
|
12909
|
+
* The arkadeCash string is the recovery token: a claim interrupted between
|
|
12889
12910
|
* submit and finalize is completed by simply re-running `claimCash`, which
|
|
12890
|
-
* drains any pending
|
|
12911
|
+
* drains any pending arkadeCash transaction on the server before sweeping.
|
|
12891
12912
|
*
|
|
12892
|
-
* @param cashStr - The encoded
|
|
12913
|
+
* @param cashStr - The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
12893
12914
|
* @returns The swept total and the report of what was left behind. The
|
|
12894
12915
|
* shape is open: further buckets may be added alongside `unclaimed`.
|
|
12895
12916
|
*/
|
|
12896
12917
|
async claimCash(cashStr) {
|
|
12897
|
-
const cash =
|
|
12918
|
+
const cash = ArkadeCash.fromString(cashStr);
|
|
12898
12919
|
const cashScript = cash.vtxoScript;
|
|
12899
12920
|
const cashPkScript = base.hex.encode(cashScript.pkScript);
|
|
12900
12921
|
const scripts = [cashPkScript];
|
|
12901
12922
|
let vtxos = await this.fetchAllVtxos(scripts);
|
|
12902
12923
|
if (vtxos.length === 0) {
|
|
12903
|
-
throw new Error("No VTXOs found for this
|
|
12924
|
+
throw new Error("No VTXOs found for this arkadeCash");
|
|
12904
12925
|
}
|
|
12905
|
-
const myPkScript =
|
|
12926
|
+
const myPkScript = chunk7TXSPRN5_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
12906
12927
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
12907
12928
|
let swept = 0;
|
|
12908
12929
|
const drainable = vtxos.filter((vtxo) => !isSubdust(vtxo, this.dustAmount));
|
|
@@ -12916,7 +12937,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12916
12937
|
myPkScript
|
|
12917
12938
|
);
|
|
12918
12939
|
} catch (error) {
|
|
12919
|
-
console.error("Failed to drain pending
|
|
12940
|
+
console.error("Failed to drain pending arkadeCash txs:", error);
|
|
12920
12941
|
}
|
|
12921
12942
|
if (drained.count > 0) {
|
|
12922
12943
|
vtxos = await this.fetchAllVtxos(scripts);
|
|
@@ -12929,7 +12950,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12929
12950
|
}
|
|
12930
12951
|
if (spendable.length > 0) {
|
|
12931
12952
|
const info = await this.arkProvider.getInfo();
|
|
12932
|
-
const serverUnrollScript =
|
|
12953
|
+
const serverUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
12933
12954
|
base.hex.decode(info.checkpointTapscript)
|
|
12934
12955
|
);
|
|
12935
12956
|
for (const vtxo of spendable) {
|
|
@@ -12951,7 +12972,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12951
12972
|
});
|
|
12952
12973
|
swept += vtxo.value;
|
|
12953
12974
|
} catch (error) {
|
|
12954
|
-
console.error(
|
|
12975
|
+
console.error(
|
|
12976
|
+
`Failed to sweep arkadeCash VTXO ${vtxo.txid}:${vtxo.vout}:`,
|
|
12977
|
+
error
|
|
12978
|
+
);
|
|
12955
12979
|
unclaimed.push(cashReport(vtxo, "sweep-failed"));
|
|
12956
12980
|
}
|
|
12957
12981
|
}
|
|
@@ -12965,18 +12989,18 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12965
12989
|
};
|
|
12966
12990
|
}
|
|
12967
12991
|
/**
|
|
12968
|
-
* Split the VTXOs at an
|
|
12992
|
+
* Split the VTXOs at an arkadeCash address into the ones the thin sweep can
|
|
12969
12993
|
* move and the ones it can only report.
|
|
12970
12994
|
*/
|
|
12971
12995
|
classifyCashVtxos(vtxos) {
|
|
12972
12996
|
const spendable = [];
|
|
12973
12997
|
const unclaimed = [];
|
|
12974
12998
|
for (const vtxo of vtxos) {
|
|
12975
|
-
if (
|
|
12999
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) {
|
|
12976
13000
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
12977
13001
|
} else if (isSubdust(vtxo, this.dustAmount)) {
|
|
12978
13002
|
unclaimed.push(cashReport(vtxo, "subdust"));
|
|
12979
|
-
} else if (
|
|
13003
|
+
} else if (vtxo.isSwept) {
|
|
12980
13004
|
unclaimed.push(cashReport(vtxo, "swept"));
|
|
12981
13005
|
} else if (vtxo.assets && vtxo.assets.length > 0) {
|
|
12982
13006
|
unclaimed.push(cashReport(vtxo, "has-assets"));
|
|
@@ -12992,7 +13016,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12992
13016
|
const all = [];
|
|
12993
13017
|
const seen = /* @__PURE__ */ new Set();
|
|
12994
13018
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
12995
|
-
const { vtxos, page } = await this.indexerProvider
|
|
13019
|
+
const { vtxos, page } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
12996
13020
|
scripts,
|
|
12997
13021
|
pageIndex,
|
|
12998
13022
|
pageSize
|
|
@@ -13008,7 +13032,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13008
13032
|
}
|
|
13009
13033
|
/**
|
|
13010
13034
|
* Complete any sweep a previous `claimCash` registered but never finalized.
|
|
13011
|
-
* A thin variant of {@link finalizePendingTxs}, scoped to the
|
|
13035
|
+
* A thin variant of {@link finalizePendingTxs}, scoped to the arkadeCash key:
|
|
13012
13036
|
* the intent is signed with it, and so are the returned checkpoints.
|
|
13013
13037
|
*
|
|
13014
13038
|
* A drained sweep is not automatically *ours*. Whoever registered it chose
|
|
@@ -13017,7 +13041,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13017
13041
|
* completing it unsticks the funds), but only the value it actually pays to
|
|
13018
13042
|
* `myPkScript` may be counted as claimed here.
|
|
13019
13043
|
*
|
|
13020
|
-
* @param vtxos - VTXOs at the
|
|
13044
|
+
* @param vtxos - VTXOs at the arkadeCash contract's own pkScript, spent ones
|
|
13021
13045
|
* included (a registered sweep marks its input spent). Any other outpoint —
|
|
13022
13046
|
* subdust above all — would make the proof invalid, since it describes every
|
|
13023
13047
|
* input by that pkScript.
|
|
@@ -13039,7 +13063,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13039
13063
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
13040
13064
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
13041
13065
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
13042
|
-
const proof =
|
|
13066
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, batch, []);
|
|
13043
13067
|
const signedProof = await identity.sign(
|
|
13044
13068
|
proof,
|
|
13045
13069
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -13078,7 +13102,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13078
13102
|
}
|
|
13079
13103
|
}
|
|
13080
13104
|
} catch (error) {
|
|
13081
|
-
console.error(
|
|
13105
|
+
console.error(
|
|
13106
|
+
`Failed to finalize pending arkadeCash tx ${pendingTx.arkTxid}:`,
|
|
13107
|
+
error
|
|
13108
|
+
);
|
|
13082
13109
|
}
|
|
13083
13110
|
}
|
|
13084
13111
|
return result;
|
|
@@ -13322,7 +13349,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13322
13349
|
* there is no separate change output. It records no `TxSent` history — the
|
|
13323
13350
|
* funds never leave the wallet.
|
|
13324
13351
|
*/
|
|
13325
|
-
async sendSelectedVtxosToSelf(inputs) {
|
|
13352
|
+
async sendSelectedVtxosToSelf(inputs, now) {
|
|
13326
13353
|
if (inputs.length === 0) {
|
|
13327
13354
|
throw new Error("sendSelectedVtxosToSelf: no inputs");
|
|
13328
13355
|
}
|
|
@@ -13331,26 +13358,28 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13331
13358
|
const serverPubKey = this.arkServerPublicKey;
|
|
13332
13359
|
const serverUnrollScript = this.serverUnrollScript;
|
|
13333
13360
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
13334
|
-
|
|
13335
|
-
|
|
13361
|
+
const normalizedInputs = inputs.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
13362
|
+
const at = now ?? await chunk7TXSPRN5_cjs.resolveTimeHeight(this.onchainProvider);
|
|
13363
|
+
for (const input of normalizedInputs) {
|
|
13364
|
+
if (!chunk7TXSPRN5_cjs.canSpendOffchain(input, at)) {
|
|
13336
13365
|
throw new Error(
|
|
13337
13366
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
13338
13367
|
);
|
|
13339
13368
|
}
|
|
13340
|
-
if (
|
|
13369
|
+
if (input.expiresAt === void 0 && input.expiresAtHeight === void 0) {
|
|
13341
13370
|
throw new Error(
|
|
13342
|
-
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} has no
|
|
13371
|
+
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} has no batch expiry`
|
|
13343
13372
|
);
|
|
13344
13373
|
}
|
|
13345
13374
|
}
|
|
13346
|
-
const total =
|
|
13375
|
+
const total = normalizedInputs.reduce((sum, c) => sum + BigInt(c.value), 0n);
|
|
13347
13376
|
const outputs = [
|
|
13348
13377
|
{
|
|
13349
13378
|
script: total < this.dustAmount ? arkAddress.subdustPkScript : arkAddress.pkScript,
|
|
13350
13379
|
amount: total
|
|
13351
13380
|
}
|
|
13352
13381
|
];
|
|
13353
|
-
const assetInputs = selectedCoinsToAssetInputs(
|
|
13382
|
+
const assetInputs = selectedCoinsToAssetInputs(normalizedInputs);
|
|
13354
13383
|
let selfAssets;
|
|
13355
13384
|
if (assetInputs.size > 0) {
|
|
13356
13385
|
const totals = /* @__PURE__ */ new Map();
|
|
@@ -13367,7 +13396,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13367
13396
|
const packet = createAssetPacket(assetInputs, [], selfReceiver);
|
|
13368
13397
|
outputs.push(Extension.create([packet]).txOut());
|
|
13369
13398
|
}
|
|
13370
|
-
return this._submitOffchainSpend(
|
|
13399
|
+
return this._submitOffchainSpend(normalizedInputs, outputs, {
|
|
13371
13400
|
sentAmount: 0,
|
|
13372
13401
|
changeAmount: total,
|
|
13373
13402
|
changeVout: 0,
|
|
@@ -13397,7 +13426,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13397
13426
|
);
|
|
13398
13427
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
13399
13428
|
index,
|
|
13400
|
-
lookupScript:
|
|
13429
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
13401
13430
|
}));
|
|
13402
13431
|
const identity = this.identity;
|
|
13403
13432
|
const signer = {
|
|
@@ -13468,43 +13497,42 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13468
13497
|
const cm = await this.getContractManager();
|
|
13469
13498
|
const annotatedInputs = await cm.annotateVtxos(inputs);
|
|
13470
13499
|
for (const [inputIndex, vtxo] of annotatedInputs.entries()) {
|
|
13500
|
+
const spentFacts = { ...vtxo, isSpent: true };
|
|
13471
13501
|
if (inputIndex < safeLength && signedCheckpointTxs[inputIndex]) {
|
|
13472
13502
|
const checkpoint = btcSigner.Transaction.fromPSBT(
|
|
13473
13503
|
base.base64.decode(signedCheckpointTxs[inputIndex])
|
|
13474
13504
|
);
|
|
13475
13505
|
spentVtxos.push({
|
|
13476
|
-
...
|
|
13477
|
-
virtualStatus:
|
|
13478
|
-
...vtxo.virtualStatus,
|
|
13479
|
-
state: "spent"
|
|
13480
|
-
},
|
|
13506
|
+
...spentFacts,
|
|
13507
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(spentFacts),
|
|
13481
13508
|
spentBy: checkpoint.id,
|
|
13482
|
-
arkTxId: arkTxid
|
|
13483
|
-
isSpent: true
|
|
13509
|
+
arkTxId: arkTxid
|
|
13484
13510
|
});
|
|
13485
13511
|
} else {
|
|
13486
13512
|
spentVtxos.push({
|
|
13487
|
-
...
|
|
13488
|
-
virtualStatus:
|
|
13489
|
-
|
|
13490
|
-
state: "spent"
|
|
13491
|
-
},
|
|
13492
|
-
arkTxId: arkTxid,
|
|
13493
|
-
isSpent: true
|
|
13513
|
+
...spentFacts,
|
|
13514
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(spentFacts),
|
|
13515
|
+
arkTxId: arkTxid
|
|
13494
13516
|
});
|
|
13495
13517
|
}
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
commitmentTxIds.add(id);
|
|
13499
|
-
}
|
|
13518
|
+
for (const id of vtxo.commitmentTxIds) {
|
|
13519
|
+
commitmentTxIds.add(id);
|
|
13500
13520
|
}
|
|
13501
|
-
|
|
13502
|
-
|
|
13521
|
+
const vtxoExpiry = chunk7TXSPRN5_cjs.toBatchExpiry(vtxo);
|
|
13522
|
+
if (vtxoExpiry) {
|
|
13523
|
+
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
13503
13524
|
}
|
|
13504
13525
|
}
|
|
13505
13526
|
const createdAt = Date.now();
|
|
13506
13527
|
let changeVtxo;
|
|
13507
13528
|
if (changeAmount > 0n && batchExpiry !== Number.MAX_SAFE_INTEGER) {
|
|
13529
|
+
const changeFacts = {
|
|
13530
|
+
isSpent: false,
|
|
13531
|
+
isSwept: false,
|
|
13532
|
+
isPreconfirmed: true,
|
|
13533
|
+
commitmentTxIds: Array.from(commitmentTxIds),
|
|
13534
|
+
...chunk7TXSPRN5_cjs.parseLegacyExpiry(batchExpiry)
|
|
13535
|
+
};
|
|
13508
13536
|
changeVtxo = {
|
|
13509
13537
|
txid: arkTxid,
|
|
13510
13538
|
vout: changeVout,
|
|
@@ -13512,14 +13540,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13512
13540
|
forfeitTapLeafScript: offchainTapscript.forfeit(),
|
|
13513
13541
|
intentTapLeafScript: offchainTapscript.forfeit(),
|
|
13514
13542
|
isUnrolled: false,
|
|
13515
|
-
isSpent: false,
|
|
13516
13543
|
tapTree: offchainTapscript.encode(),
|
|
13517
13544
|
value: Number(changeAmount),
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
batchExpiry
|
|
13522
|
-
},
|
|
13545
|
+
...changeFacts,
|
|
13546
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(changeFacts),
|
|
13547
|
+
spentBy: "",
|
|
13523
13548
|
status: {
|
|
13524
13549
|
confirmed: false
|
|
13525
13550
|
},
|
|
@@ -13587,30 +13612,30 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13587
13612
|
const spentVtxos = [];
|
|
13588
13613
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
13589
13614
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
13590
|
-
const
|
|
13591
|
-
const vtxoInputs = inputs.filter(isVtxo);
|
|
13615
|
+
const vtxoInputs = inputs.filter(chunk7TXSPRN5_cjs.isVirtualCoin);
|
|
13592
13616
|
const cm = await this.getContractManager();
|
|
13593
13617
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
13594
13618
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
13595
13619
|
for (const input of inputs) {
|
|
13596
|
-
if (
|
|
13597
|
-
const
|
|
13620
|
+
if (chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
13621
|
+
const outpoint = `${input.txid}:${input.vout}`;
|
|
13622
|
+
const vtxo = annotatedByKey.get(outpoint);
|
|
13623
|
+
if (!vtxo) {
|
|
13624
|
+
throw new Error(`missing annotation for virtual coin ${outpoint}`);
|
|
13625
|
+
}
|
|
13598
13626
|
if (vtxo.arkTxId) {
|
|
13599
13627
|
inputArkTxIds.add(vtxo.arkTxId);
|
|
13600
13628
|
}
|
|
13629
|
+
const settledFacts = { ...vtxo, isSpent: true };
|
|
13601
13630
|
spentVtxos.push({
|
|
13602
|
-
...
|
|
13603
|
-
virtualStatus:
|
|
13604
|
-
|
|
13605
|
-
state: "settled"
|
|
13606
|
-
},
|
|
13607
|
-
settledBy: commitmentTxid,
|
|
13608
|
-
isSpent: true
|
|
13631
|
+
...settledFacts,
|
|
13632
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(settledFacts),
|
|
13633
|
+
settledBy: commitmentTxid
|
|
13609
13634
|
});
|
|
13610
13635
|
} else {
|
|
13611
13636
|
let sourceAddress;
|
|
13612
13637
|
try {
|
|
13613
|
-
sourceAddress =
|
|
13638
|
+
sourceAddress = chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
13614
13639
|
this.network
|
|
13615
13640
|
);
|
|
13616
13641
|
} catch {
|
|
@@ -13668,9 +13693,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13668
13693
|
}
|
|
13669
13694
|
};
|
|
13670
13695
|
function selectVirtualCoins(coins, targetAmount) {
|
|
13671
|
-
const sortedCoins =
|
|
13672
|
-
const expiryA = a
|
|
13673
|
-
const expiryB = b
|
|
13696
|
+
const sortedCoins = coins.map(chunk7TXSPRN5_cjs.normalizeVtxo).sort((a, b) => {
|
|
13697
|
+
const expiryA = chunk7TXSPRN5_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
13698
|
+
const expiryB = chunk7TXSPRN5_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
13674
13699
|
if (expiryA !== expiryB) {
|
|
13675
13700
|
return expiryA - expiryB;
|
|
13676
13701
|
}
|
|
@@ -13921,7 +13946,7 @@ var MessageBus = class {
|
|
|
13921
13946
|
this.initialized = true;
|
|
13922
13947
|
}
|
|
13923
13948
|
async buildServices(config) {
|
|
13924
|
-
const arkProvider = new
|
|
13949
|
+
const arkProvider = new chunkEB3ALGTM_cjs.RestArkProvider(config.arkServer.url);
|
|
13925
13950
|
const storage = {
|
|
13926
13951
|
walletRepository: this.walletRepository,
|
|
13927
13952
|
contractRepository: this.contractRepository
|
|
@@ -14304,7 +14329,7 @@ var Ramps = class {
|
|
|
14304
14329
|
}
|
|
14305
14330
|
amount = amount ?? totalAmount;
|
|
14306
14331
|
const offchainAddress = await this.wallet.getAddress();
|
|
14307
|
-
const offchainAddr =
|
|
14332
|
+
const offchainAddr = chunk7TXSPRN5_cjs.ArkAddress.decode(offchainAddress);
|
|
14308
14333
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
14309
14334
|
const outputFee = estimator.evalOffchainOutput({
|
|
14310
14335
|
amount,
|
|
@@ -14364,13 +14389,7 @@ var Ramps = class {
|
|
|
14364
14389
|
const filteredVtxos = [];
|
|
14365
14390
|
let totalAmount = 0n;
|
|
14366
14391
|
for (const vtxo of vtxos) {
|
|
14367
|
-
const inputFee = estimator.evalOffchainInput(
|
|
14368
|
-
amount: BigInt(vtxo.value),
|
|
14369
|
-
type: vtxo.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
14370
|
-
weight: 0,
|
|
14371
|
-
birth: vtxo.createdAt,
|
|
14372
|
-
expiry: vtxo.virtualStatus.batchExpiry ? new Date(vtxo.virtualStatus.batchExpiry) : void 0
|
|
14373
|
-
});
|
|
14392
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(vtxo));
|
|
14374
14393
|
if (inputFee.satoshis >= vtxo.value) {
|
|
14375
14394
|
continue;
|
|
14376
14395
|
}
|
|
@@ -14402,7 +14421,7 @@ var Ramps = class {
|
|
|
14402
14421
|
let destinationScript;
|
|
14403
14422
|
for (const networkName of networkNames) {
|
|
14404
14423
|
try {
|
|
14405
|
-
const network =
|
|
14424
|
+
const network = chunk7TXSPRN5_cjs.networks[networkName];
|
|
14406
14425
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
14407
14426
|
destinationScript = btcSigner.OutScript.encode(addr);
|
|
14408
14427
|
break;
|
|
@@ -15087,7 +15106,7 @@ var WalletMessageHandler = class {
|
|
|
15087
15106
|
// Wallet methods
|
|
15088
15107
|
async handleInitWallet({ payload }) {
|
|
15089
15108
|
const { arkServerUrl } = payload;
|
|
15090
|
-
this.indexerProvider = new
|
|
15109
|
+
this.indexerProvider = new chunkEB3ALGTM_cjs.RestIndexerProvider(arkServerUrl);
|
|
15091
15110
|
await this.onWalletInitialized();
|
|
15092
15111
|
}
|
|
15093
15112
|
async handleGetBalance() {
|
|
@@ -15105,30 +15124,30 @@ var WalletMessageHandler = class {
|
|
|
15105
15124
|
unconfirmed += utxo.value;
|
|
15106
15125
|
}
|
|
15107
15126
|
}
|
|
15108
|
-
const
|
|
15109
|
-
const sweptVtxos = allVtxos.filter((vtxo) => vtxo.virtualStatus.state === "swept");
|
|
15127
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
15110
15128
|
let settled = 0;
|
|
15111
15129
|
let preconfirmed = 0;
|
|
15112
15130
|
let recoverable = 0;
|
|
15113
15131
|
let pendingRecovery = 0;
|
|
15114
|
-
for (const vtxo of
|
|
15132
|
+
for (const vtxo of allVtxos) {
|
|
15133
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
15115
15134
|
if (pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
15116
15135
|
pendingRecovery += vtxo.value;
|
|
15117
|
-
} else if (vtxo
|
|
15118
|
-
settled += vtxo.value;
|
|
15119
|
-
} else if (vtxo.virtualStatus.state === "preconfirmed") {
|
|
15120
|
-
preconfirmed += vtxo.value;
|
|
15121
|
-
}
|
|
15122
|
-
}
|
|
15123
|
-
for (const vtxo of sweptVtxos) {
|
|
15124
|
-
if (isSpendable(vtxo)) {
|
|
15136
|
+
} else if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15125
15137
|
recoverable += vtxo.value;
|
|
15138
|
+
} else if (chunk7TXSPRN5_cjs.canSpendOffchain(vtxo, now)) {
|
|
15139
|
+
if (vtxo.isPreconfirmed) {
|
|
15140
|
+
preconfirmed += vtxo.value;
|
|
15141
|
+
} else {
|
|
15142
|
+
settled += vtxo.value;
|
|
15143
|
+
}
|
|
15126
15144
|
}
|
|
15127
15145
|
}
|
|
15128
15146
|
const totalBoarding = confirmed + unconfirmed;
|
|
15129
15147
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
15130
15148
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
15131
|
-
for (const vtxo of
|
|
15149
|
+
for (const vtxo of allVtxos) {
|
|
15150
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
15132
15151
|
if (vtxo.assets) {
|
|
15133
15152
|
for (const a of vtxo.assets) {
|
|
15134
15153
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -15164,7 +15183,7 @@ var WalletMessageHandler = class {
|
|
|
15164
15183
|
*/
|
|
15165
15184
|
async getSpendableVtxos() {
|
|
15166
15185
|
const vtxos = await this.getVtxosFromRepo();
|
|
15167
|
-
return vtxos.filter(
|
|
15186
|
+
return vtxos.filter((v) => !chunk7TXSPRN5_cjs.hasTerminalSpend(v));
|
|
15168
15187
|
}
|
|
15169
15188
|
async onWalletInitialized() {
|
|
15170
15189
|
if (!this.readonlyWallet || !this.arkProvider || !this.indexerProvider || !this.walletRepository) {
|
|
@@ -15176,9 +15195,7 @@ var WalletMessageHandler = class {
|
|
|
15176
15195
|
try {
|
|
15177
15196
|
const vtxos = await this.getVtxosFromRepo();
|
|
15178
15197
|
const { pending, finalized } = await this.wallet.finalizePendingTxs(
|
|
15179
|
-
vtxos.filter(
|
|
15180
|
-
(vtxo) => vtxo.virtualStatus.state !== "swept" && vtxo.virtualStatus.state !== "settled"
|
|
15181
|
-
)
|
|
15198
|
+
vtxos.filter((vtxo) => vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept)
|
|
15182
15199
|
);
|
|
15183
15200
|
console.info(
|
|
15184
15201
|
`Recovered ${finalized.length}/${pending.length} pending transactions: ${finalized.join(", ")}`
|
|
@@ -15378,10 +15395,10 @@ var WalletMessageHandler = class {
|
|
|
15378
15395
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
15379
15396
|
return false;
|
|
15380
15397
|
}
|
|
15381
|
-
if (isRecoverable(v)) {
|
|
15398
|
+
if (chunk7TXSPRN5_cjs.isRecoverable(v)) {
|
|
15382
15399
|
return false;
|
|
15383
15400
|
}
|
|
15384
|
-
if (isExpired(v)) {
|
|
15401
|
+
if (chunk7TXSPRN5_cjs.isExpired(v)) {
|
|
15385
15402
|
return false;
|
|
15386
15403
|
}
|
|
15387
15404
|
return true;
|
|
@@ -15437,8 +15454,12 @@ var WalletMessageHandler = class {
|
|
|
15437
15454
|
`WalletMessageHandler.getVtxosFromRepo: failed to derive script from wallet address ${walletAddress}: ${e instanceof Error ? e.message : String(e)}`
|
|
15438
15455
|
);
|
|
15439
15456
|
}
|
|
15440
|
-
|
|
15441
|
-
|
|
15457
|
+
addVtxos(
|
|
15458
|
+
await getVtxosForContract(this.walletRepository, {
|
|
15459
|
+
script: walletScript,
|
|
15460
|
+
address: walletAddress
|
|
15461
|
+
})
|
|
15462
|
+
);
|
|
15442
15463
|
return allVtxos;
|
|
15443
15464
|
}
|
|
15444
15465
|
/**
|
|
@@ -15470,7 +15491,7 @@ var WalletMessageHandler = class {
|
|
|
15470
15491
|
}));
|
|
15471
15492
|
const BATCH_SIZE = 100;
|
|
15472
15493
|
for (let i = 0; i < outpoints.length; i += BATCH_SIZE) {
|
|
15473
|
-
const res = await this.indexerProvider
|
|
15494
|
+
const res = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
15474
15495
|
outpoints: outpoints.slice(i, i + BATCH_SIZE)
|
|
15475
15496
|
});
|
|
15476
15497
|
for (const v of res.vtxos) {
|
|
@@ -16172,7 +16193,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
16172
16193
|
};
|
|
16173
16194
|
try {
|
|
16174
16195
|
const response = await this.sendMessage(message);
|
|
16175
|
-
return response.payload.vtxos;
|
|
16196
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
16176
16197
|
} catch (error) {
|
|
16177
16198
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
16178
16199
|
}
|
|
@@ -16285,7 +16306,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
16285
16306
|
};
|
|
16286
16307
|
try {
|
|
16287
16308
|
const response = await sendContractMessage(message);
|
|
16288
|
-
return response.payload.vtxos;
|
|
16309
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
16289
16310
|
} catch (e) {
|
|
16290
16311
|
throw new Error("Failed to annotate vtxos");
|
|
16291
16312
|
}
|
|
@@ -16730,7 +16751,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
16730
16751
|
};
|
|
16731
16752
|
try {
|
|
16732
16753
|
const response = await wallet.sendMessage(message);
|
|
16733
|
-
return response.payload.vtxos;
|
|
16754
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
16734
16755
|
} catch (e) {
|
|
16735
16756
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
16736
16757
|
}
|
|
@@ -16842,12 +16863,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16842
16863
|
* @returns Configured onchain wallet
|
|
16843
16864
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
16844
16865
|
*/
|
|
16845
|
-
static async create(identity, networkName =
|
|
16866
|
+
static async create(identity, networkName = chunk7TXSPRN5_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
16846
16867
|
const pubkey = await identity.xOnlyPublicKey();
|
|
16847
16868
|
if (!pubkey) {
|
|
16848
16869
|
throw new Error("Invalid configured public key");
|
|
16849
16870
|
}
|
|
16850
|
-
const network =
|
|
16871
|
+
const network = chunk7TXSPRN5_cjs.getNetwork(networkName);
|
|
16851
16872
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
16852
16873
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
16853
16874
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -16953,7 +16974,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16953
16974
|
if (!inputs) {
|
|
16954
16975
|
throw new Error("Fee estimation failed");
|
|
16955
16976
|
}
|
|
16956
|
-
let tx = new
|
|
16977
|
+
let tx = new chunkEB3ALGTM_cjs.Transaction();
|
|
16957
16978
|
for (const input of inputs) {
|
|
16958
16979
|
tx.addInput({
|
|
16959
16980
|
txid: input.txid,
|
|
@@ -17011,7 +17032,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17011
17032
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
17012
17033
|
*/
|
|
17013
17034
|
async bumpAnchor(parentHex, feeRate) {
|
|
17014
|
-
const parent =
|
|
17035
|
+
const parent = chunkEB3ALGTM_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
17015
17036
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
17016
17037
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
17017
17038
|
return [parent.hex, child.hex];
|
|
@@ -17776,7 +17797,7 @@ exports.BIP322 = void 0;
|
|
|
17776
17797
|
async function sign2(message, identity, network) {
|
|
17777
17798
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
17778
17799
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
17779
|
-
const toSpend =
|
|
17800
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
17780
17801
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
17781
17802
|
const signed = await identity.sign(toSign, [0]);
|
|
17782
17803
|
signed.finalizeIdx(0);
|
|
@@ -17834,7 +17855,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
17834
17855
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
17835
17856
|
return false;
|
|
17836
17857
|
}
|
|
17837
|
-
const toSpend =
|
|
17858
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17838
17859
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
17839
17860
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
17840
17861
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -17855,7 +17876,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
17855
17876
|
}
|
|
17856
17877
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
17857
17878
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
17858
|
-
const toSpend =
|
|
17879
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17859
17880
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
17860
17881
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
17861
17882
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -17908,7 +17929,7 @@ function encodeCompactSize(n) {
|
|
|
17908
17929
|
return buf;
|
|
17909
17930
|
}
|
|
17910
17931
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
17911
|
-
const tx = new
|
|
17932
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 0 });
|
|
17912
17933
|
tx.addInput({
|
|
17913
17934
|
txid: toSpend.id,
|
|
17914
17935
|
index: 0,
|
|
@@ -17922,12 +17943,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
17922
17943
|
});
|
|
17923
17944
|
tx.addOutput({
|
|
17924
17945
|
amount: 0n,
|
|
17925
|
-
script:
|
|
17946
|
+
script: chunkEB3ALGTM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17926
17947
|
});
|
|
17927
17948
|
return tx;
|
|
17928
17949
|
}
|
|
17929
17950
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
17930
|
-
const tx = new
|
|
17951
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 0 });
|
|
17931
17952
|
tx.addInput({
|
|
17932
17953
|
txid: toSpend.id,
|
|
17933
17954
|
index: 0,
|
|
@@ -17939,7 +17960,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
17939
17960
|
});
|
|
17940
17961
|
tx.addOutput({
|
|
17941
17962
|
amount: 0n,
|
|
17942
|
-
script:
|
|
17963
|
+
script: chunkEB3ALGTM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17943
17964
|
});
|
|
17944
17965
|
return tx;
|
|
17945
17966
|
}
|
|
@@ -18070,7 +18091,7 @@ var RestEmulatorProvider = class {
|
|
|
18070
18091
|
}
|
|
18071
18092
|
};
|
|
18072
18093
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
18073
|
-
const tx =
|
|
18094
|
+
const tx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
18074
18095
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
18075
18096
|
const input = tx.getInput(0);
|
|
18076
18097
|
if (!input) {
|
|
@@ -18097,14 +18118,14 @@ var ExitPathError = class extends Error {
|
|
|
18097
18118
|
reason;
|
|
18098
18119
|
};
|
|
18099
18120
|
function delayWeight(sequence) {
|
|
18100
|
-
const t =
|
|
18121
|
+
const t = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
18101
18122
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
18102
18123
|
}
|
|
18103
18124
|
async function resolveUnilateralPath(params) {
|
|
18104
18125
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
18105
18126
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
18106
18127
|
if (contract) {
|
|
18107
|
-
const handler =
|
|
18128
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
18108
18129
|
if (!handler) {
|
|
18109
18130
|
throw new ExitPathError(
|
|
18110
18131
|
"no-handler",
|
|
@@ -18127,12 +18148,12 @@ async function resolveUnilateralPath(params) {
|
|
|
18127
18148
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
18128
18149
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
18129
18150
|
}
|
|
18130
|
-
const decoded =
|
|
18151
|
+
const decoded = chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
18131
18152
|
let best;
|
|
18132
18153
|
for (const exit of decoded.exitPaths()) {
|
|
18133
18154
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
18134
18155
|
if (!leaf) continue;
|
|
18135
|
-
const sequence =
|
|
18156
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(exit.params.timelock);
|
|
18136
18157
|
const weight = delayWeight(sequence);
|
|
18137
18158
|
if (!best || weight < best.weight) {
|
|
18138
18159
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -18318,14 +18339,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18318
18339
|
}
|
|
18319
18340
|
const resolved = await resolveUnilateralPath({
|
|
18320
18341
|
vtxo,
|
|
18321
|
-
scriptHex: base.hex.encode(
|
|
18342
|
+
scriptHex: base.hex.encode(chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
18322
18343
|
contractRepository: wallet.contractRepository,
|
|
18323
18344
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
18324
18345
|
currentTime: Date.now()
|
|
18325
18346
|
});
|
|
18326
18347
|
const spendingLeaf = resolved.selection.leaf;
|
|
18327
18348
|
const sequence = resolved.selection.sequence;
|
|
18328
|
-
const timelock =
|
|
18349
|
+
const timelock = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
18329
18350
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
18330
18351
|
if (!elapsed) {
|
|
18331
18352
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -18338,7 +18359,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18338
18359
|
sequence,
|
|
18339
18360
|
witnessUtxo: {
|
|
18340
18361
|
amount: BigInt(vtxo.value),
|
|
18341
|
-
script:
|
|
18362
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
18342
18363
|
},
|
|
18343
18364
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
18344
18365
|
});
|
|
@@ -18348,7 +18369,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18348
18369
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
18349
18370
|
);
|
|
18350
18371
|
}
|
|
18351
|
-
const tx = new
|
|
18372
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
18352
18373
|
for (const input of inputs) {
|
|
18353
18374
|
tx.addInput(input);
|
|
18354
18375
|
}
|
|
@@ -18415,7 +18436,7 @@ async function buildSignedSweep(params) {
|
|
|
18415
18436
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
18416
18437
|
);
|
|
18417
18438
|
}
|
|
18418
|
-
const tx = new
|
|
18439
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
18419
18440
|
tx.addInput({
|
|
18420
18441
|
txid: vtxo.txid,
|
|
18421
18442
|
index: vtxo.vout,
|
|
@@ -18440,7 +18461,7 @@ async function buildSignedSweep(params) {
|
|
|
18440
18461
|
finalScriptWitness: [
|
|
18441
18462
|
tapScriptSig[0][1],
|
|
18442
18463
|
...path.extraWitness,
|
|
18443
|
-
|
|
18464
|
+
chunk7TXSPRN5_cjs.scriptFromTapLeafScript(path.leaf),
|
|
18444
18465
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
18445
18466
|
]
|
|
18446
18467
|
});
|
|
@@ -18470,7 +18491,7 @@ async function resolveFeeRate(opts) {
|
|
|
18470
18491
|
}
|
|
18471
18492
|
async function selectExitVtxos(opts) {
|
|
18472
18493
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
18473
|
-
const res = await opts.wallet.indexerProvider
|
|
18494
|
+
const res = await chunk7TXSPRN5_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
18474
18495
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
18475
18496
|
const out = [];
|
|
18476
18497
|
for (const vtxo of res.vtxos) {
|
|
@@ -18485,7 +18506,7 @@ async function selectExitVtxos(opts) {
|
|
|
18485
18506
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
18486
18507
|
);
|
|
18487
18508
|
}
|
|
18488
|
-
const handler =
|
|
18509
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
18489
18510
|
if (!handler) {
|
|
18490
18511
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
18491
18512
|
}
|
|
@@ -18515,7 +18536,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18515
18536
|
if (pendingNodes.length > 0) {
|
|
18516
18537
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
18517
18538
|
for (const psbt of txs) {
|
|
18518
|
-
psbts.set(
|
|
18539
|
+
psbts.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
18519
18540
|
}
|
|
18520
18541
|
}
|
|
18521
18542
|
const childVsize = Number(
|
|
@@ -18551,7 +18572,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18551
18572
|
try {
|
|
18552
18573
|
const resolved = await resolveUnilateralPath({
|
|
18553
18574
|
vtxo,
|
|
18554
|
-
scriptHex: base.hex.encode(
|
|
18575
|
+
scriptHex: base.hex.encode(chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
18555
18576
|
contractRepository: wallet.contractRepository,
|
|
18556
18577
|
walletPubKeyHex,
|
|
18557
18578
|
currentTime: Date.now()
|
|
@@ -18570,7 +18591,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18570
18591
|
});
|
|
18571
18592
|
continue;
|
|
18572
18593
|
}
|
|
18573
|
-
const t =
|
|
18594
|
+
const t = chunk7TXSPRN5_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
18574
18595
|
const delay = { type: t.type, value: Number(t.value) };
|
|
18575
18596
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
18576
18597
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -18877,7 +18898,7 @@ async function prepare(opts) {
|
|
|
18877
18898
|
txid: sweep.vtxo.txid,
|
|
18878
18899
|
vout: sweep.vtxo.vout,
|
|
18879
18900
|
value: sweep.vtxo.value,
|
|
18880
|
-
pkScript:
|
|
18901
|
+
pkScript: chunk7TXSPRN5_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
18881
18902
|
},
|
|
18882
18903
|
path: sweep.resolved.selection,
|
|
18883
18904
|
outputAddress: opts.sweepAddress,
|
|
@@ -18962,7 +18983,7 @@ async function prepare(opts) {
|
|
|
18962
18983
|
if (newFee <= splitterFee) break;
|
|
18963
18984
|
splitterFee = newFee;
|
|
18964
18985
|
}
|
|
18965
|
-
const splitter = new
|
|
18986
|
+
const splitter = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
18966
18987
|
for (const coin of selected.inputs) {
|
|
18967
18988
|
splitter.addInput({
|
|
18968
18989
|
txid: coin.txid,
|
|
@@ -19105,41 +19126,41 @@ var UnilateralExit = {
|
|
|
19105
19126
|
// src/arkade/index.ts
|
|
19106
19127
|
var arkade_exports = {};
|
|
19107
19128
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
19108
|
-
ARKADE_OP: () =>
|
|
19109
|
-
ARKADE_OPCODES: () =>
|
|
19110
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
19111
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
19112
|
-
ARKADE_OPS: () =>
|
|
19129
|
+
ARKADE_OP: () => chunk5XMVTK5S_cjs.ARKADE_OP,
|
|
19130
|
+
ARKADE_OPCODES: () => chunk5XMVTK5S_cjs.ARKADE_OPCODES,
|
|
19131
|
+
ARKADE_OPCODE_NAMES: () => chunk5XMVTK5S_cjs.ARKADE_OPCODE_NAMES,
|
|
19132
|
+
ARKADE_OPCODE_VALUES: () => chunk5XMVTK5S_cjs.ARKADE_OPCODE_VALUES,
|
|
19133
|
+
ARKADE_OPS: () => chunk5XMVTK5S_cjs.ARKADE_OPS,
|
|
19113
19134
|
Arkade: () => Arkade,
|
|
19114
19135
|
ArkadeContract: () => ArkadeContract,
|
|
19115
|
-
ArkadeProgramScript: () =>
|
|
19116
|
-
ArkadeScript: () =>
|
|
19136
|
+
ArkadeProgramScript: () => chunk5XMVTK5S_cjs.ArkadeProgramScript,
|
|
19137
|
+
ArkadeScript: () => chunk5XMVTK5S_cjs.ArkadeScript,
|
|
19117
19138
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
19118
|
-
BigNum: () =>
|
|
19139
|
+
BigNum: () => chunk5XMVTK5S_cjs.bignum_exports,
|
|
19119
19140
|
OP: () => btcSigner.OP,
|
|
19120
|
-
OPCODE_NAMES: () =>
|
|
19121
|
-
OPCODE_VALUES: () =>
|
|
19122
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
19141
|
+
OPCODE_NAMES: () => chunk5XMVTK5S_cjs.OPCODE_NAMES,
|
|
19142
|
+
OPCODE_VALUES: () => chunk5XMVTK5S_cjs.OPCODE_VALUES,
|
|
19143
|
+
SUPPORTED_PROGRAM_VERSION: () => chunk5XMVTK5S_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
19123
19144
|
Script: () => btcSigner.Script,
|
|
19124
|
-
arkadeScriptHash: () =>
|
|
19125
|
-
arkadeWitnessHash: () =>
|
|
19126
|
-
asmToBytes: () =>
|
|
19127
|
-
bytesToASM: () =>
|
|
19128
|
-
computeArkadeScriptPublicKey: () =>
|
|
19145
|
+
arkadeScriptHash: () => chunk5XMVTK5S_cjs.arkadeScriptHash,
|
|
19146
|
+
arkadeWitnessHash: () => chunk5XMVTK5S_cjs.arkadeWitnessHash,
|
|
19147
|
+
asmToBytes: () => chunk5XMVTK5S_cjs.asmToBytes,
|
|
19148
|
+
bytesToASM: () => chunk5XMVTK5S_cjs.bytesToASM,
|
|
19149
|
+
computeArkadeScriptPublicKey: () => chunk5XMVTK5S_cjs.computeArkadeScriptPublicKey,
|
|
19129
19150
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
19130
|
-
deserializeArkadeContractParams: () =>
|
|
19131
|
-
fromASM: () =>
|
|
19132
|
-
getOpcodeName: () =>
|
|
19133
|
-
getOpcodeValue: () =>
|
|
19134
|
-
parseArtifact: () =>
|
|
19135
|
-
resolveAsm: () =>
|
|
19136
|
-
serializeArkadeContractParams: () =>
|
|
19137
|
-
stringifyArtifact: () =>
|
|
19138
|
-
toASM: () =>
|
|
19139
|
-
validateProgram: () =>
|
|
19140
|
-
witnessRefToBytes: () =>
|
|
19151
|
+
deserializeArkadeContractParams: () => chunk5XMVTK5S_cjs.deserializeArkadeContractParams,
|
|
19152
|
+
fromASM: () => chunk5XMVTK5S_cjs.fromASM,
|
|
19153
|
+
getOpcodeName: () => chunk5XMVTK5S_cjs.getOpcodeName,
|
|
19154
|
+
getOpcodeValue: () => chunk5XMVTK5S_cjs.getOpcodeValue,
|
|
19155
|
+
parseArtifact: () => chunk5XMVTK5S_cjs.parseArtifact,
|
|
19156
|
+
resolveAsm: () => chunk5XMVTK5S_cjs.resolveAsm,
|
|
19157
|
+
serializeArkadeContractParams: () => chunk5XMVTK5S_cjs.serializeArkadeContractParams,
|
|
19158
|
+
stringifyArtifact: () => chunk5XMVTK5S_cjs.stringifyArtifact,
|
|
19159
|
+
toASM: () => chunk5XMVTK5S_cjs.toASM,
|
|
19160
|
+
validateProgram: () => chunk5XMVTK5S_cjs.validateProgram,
|
|
19161
|
+
witnessRefToBytes: () => chunk5XMVTK5S_cjs.witnessRefToBytes
|
|
19141
19162
|
});
|
|
19142
|
-
var isVtxoCoin = (input) =>
|
|
19163
|
+
var isVtxoCoin = (input) => chunk7TXSPRN5_cjs.isVirtualCoin(input);
|
|
19143
19164
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients) {
|
|
19144
19165
|
let batchId;
|
|
19145
19166
|
let sweepTapTreeRoot;
|
|
@@ -19151,7 +19172,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19151
19172
|
if (!event.intentIdHashes.includes(intentIdHashStr)) return { skip: true };
|
|
19152
19173
|
await arkProvider.confirmRegistration(intentId);
|
|
19153
19174
|
batchId = event.id;
|
|
19154
|
-
const sweepTapscript =
|
|
19175
|
+
const sweepTapscript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
|
|
19155
19176
|
timelock: {
|
|
19156
19177
|
value: event.batchExpiry,
|
|
19157
19178
|
// BIP-65: values >= 512 are interpreted as seconds, below as blocks
|
|
@@ -19169,7 +19190,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19169
19190
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
19170
19191
|
return { skip: true };
|
|
19171
19192
|
}
|
|
19172
|
-
const commitmentTx =
|
|
19193
|
+
const commitmentTx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
19173
19194
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
19174
19195
|
if (recipients && recipients.length > 0) {
|
|
19175
19196
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -19200,7 +19221,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19200
19221
|
if (connectorTree) {
|
|
19201
19222
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
19202
19223
|
}
|
|
19203
|
-
let commitmentPsbt =
|
|
19224
|
+
let commitmentPsbt = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
19204
19225
|
const signedForfeits = [];
|
|
19205
19226
|
let connectorIndex = 0;
|
|
19206
19227
|
const connectorLeaves = connectorTree?.leaves() || [];
|
|
@@ -19216,14 +19237,18 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19216
19237
|
break;
|
|
19217
19238
|
}
|
|
19218
19239
|
}
|
|
19219
|
-
if (boardingIdx === null)
|
|
19240
|
+
if (boardingIdx === null) {
|
|
19241
|
+
throw new Error(
|
|
19242
|
+
`input ${input.txid}:${input.vout} is neither a virtual output nor an input of the commitment tx; a virtual output must carry its \`script\``
|
|
19243
|
+
);
|
|
19244
|
+
}
|
|
19220
19245
|
commitmentPsbt.updateInput(boardingIdx, {
|
|
19221
19246
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
19222
19247
|
});
|
|
19223
19248
|
boardingIndices.push(boardingIdx);
|
|
19224
19249
|
continue;
|
|
19225
19250
|
}
|
|
19226
|
-
if (isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
19251
|
+
if (chunk7TXSPRN5_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
19227
19252
|
continue;
|
|
19228
19253
|
}
|
|
19229
19254
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -19244,7 +19269,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19244
19269
|
index: input.vout,
|
|
19245
19270
|
witnessUtxo: {
|
|
19246
19271
|
amount: BigInt(input.value),
|
|
19247
|
-
script:
|
|
19272
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
19248
19273
|
},
|
|
19249
19274
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
19250
19275
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -19327,7 +19352,7 @@ var Arkade = class _Arkade {
|
|
|
19327
19352
|
static async connect(opts) {
|
|
19328
19353
|
const info = await opts.arkade.getInfo();
|
|
19329
19354
|
const serverKey = base.hex.decode(info.signerPubkey).slice(1);
|
|
19330
|
-
const checkpoint =
|
|
19355
|
+
const checkpoint = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
19331
19356
|
let emulatorKey;
|
|
19332
19357
|
if (opts.emulator) {
|
|
19333
19358
|
const eInfo = await opts.emulator.getInfo();
|
|
@@ -19341,7 +19366,7 @@ var Arkade = class _Arkade {
|
|
|
19341
19366
|
return new _Arkade({
|
|
19342
19367
|
arkProvider: opts.arkade,
|
|
19343
19368
|
emulator: opts.emulator,
|
|
19344
|
-
network: opts.network ??
|
|
19369
|
+
network: opts.network ?? chunk7TXSPRN5_cjs.DEFAULT_NETWORK,
|
|
19345
19370
|
serverKey,
|
|
19346
19371
|
emulatorKey,
|
|
19347
19372
|
checkpoint,
|
|
@@ -19362,7 +19387,7 @@ var Arkade = class _Arkade {
|
|
|
19362
19387
|
* key respectively; explicit args always win.
|
|
19363
19388
|
*/
|
|
19364
19389
|
contract(program, args = {}) {
|
|
19365
|
-
const declared = (program.params ?? []).map(
|
|
19390
|
+
const declared = (program.params ?? []).map(chunk5XMVTK5S_cjs.inputName);
|
|
19366
19391
|
if (declared.includes("server") && args.server === void 0) {
|
|
19367
19392
|
args = { ...args, server: this.serverKey };
|
|
19368
19393
|
}
|
|
@@ -19382,7 +19407,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19382
19407
|
userKey: client.userKey,
|
|
19383
19408
|
emulatorKey: client.emulatorKey
|
|
19384
19409
|
};
|
|
19385
|
-
this.vtxoScript = new
|
|
19410
|
+
this.vtxoScript = new chunk5XMVTK5S_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
19386
19411
|
this.tapTree = this.vtxoScript.encode();
|
|
19387
19412
|
this.compiled = this.vtxoScript.compiled;
|
|
19388
19413
|
}
|
|
@@ -19410,7 +19435,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19410
19435
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
19411
19436
|
);
|
|
19412
19437
|
}
|
|
19413
|
-
const typed =
|
|
19438
|
+
const typed = chunk5XMVTK5S_cjs.deserializeArkadeContractParams(contract.params);
|
|
19414
19439
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
19415
19440
|
serverKey: typed.serverKey,
|
|
19416
19441
|
userKey: typed.userKey,
|
|
@@ -19451,7 +19476,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19451
19476
|
toContractParams() {
|
|
19452
19477
|
return {
|
|
19453
19478
|
type: "arkade",
|
|
19454
|
-
params:
|
|
19479
|
+
params: chunk5XMVTK5S_cjs.serializeArkadeContractParams({
|
|
19455
19480
|
program: this.program,
|
|
19456
19481
|
args: this.args,
|
|
19457
19482
|
serverKey: this.keys.serverKey,
|
|
@@ -19496,13 +19521,13 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19496
19521
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
19497
19522
|
if (registered) {
|
|
19498
19523
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
19499
|
-
return (withVtxos?.vtxos ?? []).filter(
|
|
19524
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunk7TXSPRN5_cjs.hasTerminalSpend(v));
|
|
19500
19525
|
}
|
|
19501
19526
|
}
|
|
19502
19527
|
if (!this.client.indexer) {
|
|
19503
19528
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
19504
19529
|
}
|
|
19505
|
-
const { vtxos } = await this.client.indexer
|
|
19530
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
19506
19531
|
scripts: [scriptHex],
|
|
19507
19532
|
spendableOnly: true
|
|
19508
19533
|
});
|
|
@@ -19604,12 +19629,12 @@ var ArkadeTransactionBuilder = class {
|
|
|
19604
19629
|
this.contract.client.checkpoint
|
|
19605
19630
|
);
|
|
19606
19631
|
if (coin.sourceTx) {
|
|
19607
|
-
|
|
19632
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(arkTx, 0, chunkEB3ALGTM_cjs.PrevArkTxField, coin.sourceTx);
|
|
19608
19633
|
}
|
|
19609
19634
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19610
19635
|
if (condition.length > 0) {
|
|
19611
|
-
|
|
19612
|
-
|
|
19636
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(arkTx, 0, chunkEB3ALGTM_cjs.ConditionWitness, condition);
|
|
19637
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(checkpoints[0], 0, chunkEB3ALGTM_cjs.ConditionWitness, condition);
|
|
19613
19638
|
}
|
|
19614
19639
|
const packets = [];
|
|
19615
19640
|
if (this.assetSpecs.length > 0) {
|
|
@@ -19648,7 +19673,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19648
19673
|
base.base64.encode(signedArk2.toPSBT()),
|
|
19649
19674
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
19650
19675
|
);
|
|
19651
|
-
const txid =
|
|
19676
|
+
const txid = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
19652
19677
|
return {
|
|
19653
19678
|
txid,
|
|
19654
19679
|
signedArkTx: res2.signedArkTx,
|
|
@@ -19666,7 +19691,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19666
19691
|
const finalCps = await Promise.all(
|
|
19667
19692
|
res.signedCheckpointTxs.map(
|
|
19668
19693
|
async (b) => base.base64.encode(
|
|
19669
|
-
(await client.identity.sign(
|
|
19694
|
+
(await client.identity.sign(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(b)), [0])).toPSBT()
|
|
19670
19695
|
)
|
|
19671
19696
|
)
|
|
19672
19697
|
);
|
|
@@ -19707,23 +19732,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
19707
19732
|
}
|
|
19708
19733
|
buildAssetPacket() {
|
|
19709
19734
|
const groups = this.assetSpecs.map((s) => {
|
|
19710
|
-
const id = typeof s.assetId === "string" ?
|
|
19711
|
-
return
|
|
19735
|
+
const id = typeof s.assetId === "string" ? chunkEB3ALGTM_cjs.AssetId.fromString(s.assetId) : chunkEB3ALGTM_cjs.AssetId.fromBytes(s.assetId);
|
|
19736
|
+
return chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
19712
19737
|
id,
|
|
19713
19738
|
null,
|
|
19714
|
-
s.inputs.map((i) =>
|
|
19715
|
-
s.outputs.map((o) =>
|
|
19716
|
-
(s.metadata ?? []).map((m) =>
|
|
19739
|
+
s.inputs.map((i) => chunkEB3ALGTM_cjs.AssetInput.create(i.vin, i.amount)),
|
|
19740
|
+
s.outputs.map((o) => chunkEB3ALGTM_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
19741
|
+
(s.metadata ?? []).map((m) => chunkEB3ALGTM_cjs.Metadata.create(m.key, m.value))
|
|
19717
19742
|
);
|
|
19718
19743
|
});
|
|
19719
|
-
return
|
|
19744
|
+
return chunkEB3ALGTM_cjs.Packet.create(groups);
|
|
19720
19745
|
}
|
|
19721
19746
|
witnessBytes(ref) {
|
|
19722
|
-
return
|
|
19747
|
+
return chunk5XMVTK5S_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
19723
19748
|
}
|
|
19724
19749
|
};
|
|
19725
19750
|
function bindInputs(fn, callArgs) {
|
|
19726
|
-
const names = (fn.def.inputs ?? []).map(
|
|
19751
|
+
const names = (fn.def.inputs ?? []).map(chunk5XMVTK5S_cjs.inputName);
|
|
19727
19752
|
if (callArgs.length !== names.length) {
|
|
19728
19753
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
19729
19754
|
}
|
|
@@ -19776,7 +19801,7 @@ function decodeArkContract(encoded) {
|
|
|
19776
19801
|
}
|
|
19777
19802
|
function contractFromArkContract(encoded, options = {}) {
|
|
19778
19803
|
const parsed = decodeArkContract(encoded);
|
|
19779
|
-
const handler =
|
|
19804
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(parsed.type);
|
|
19780
19805
|
if (!handler) {
|
|
19781
19806
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
19782
19807
|
}
|
|
@@ -19790,9 +19815,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
19790
19815
|
metadata: options.metadata
|
|
19791
19816
|
};
|
|
19792
19817
|
}
|
|
19793
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
19818
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk7TXSPRN5_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
19794
19819
|
const parsed = decodeArkContract(encoded);
|
|
19795
|
-
const handler =
|
|
19820
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
19796
19821
|
const params = parsed.data;
|
|
19797
19822
|
const vtxoScript = handler.createScript(params);
|
|
19798
19823
|
return {
|
|
@@ -19812,9 +19837,9 @@ function isArkContract(str) {
|
|
|
19812
19837
|
|
|
19813
19838
|
exports.ARKADE_MAGIC = ARKADE_MAGIC;
|
|
19814
19839
|
exports.ActivityRegistry = ActivityRegistry;
|
|
19815
|
-
exports.ArkCash = ArkCash;
|
|
19816
|
-
exports.ArkCashCreateError = ArkCashCreateError;
|
|
19817
19840
|
exports.ArkNote = ArkNote;
|
|
19841
|
+
exports.ArkadeCash = ArkadeCash;
|
|
19842
|
+
exports.ArkadeCashCreateError = ArkadeCashCreateError;
|
|
19818
19843
|
exports.AssetManager = AssetManager;
|
|
19819
19844
|
exports.ChainedTxType = ChainedTxType;
|
|
19820
19845
|
exports.ContractManager = ContractManager;
|
|
@@ -19912,10 +19937,7 @@ exports.isArkContract = isArkContract;
|
|
|
19912
19937
|
exports.isBatchSignable = isBatchSignable;
|
|
19913
19938
|
exports.isCooperativelyMigratable = isCooperativelyMigratable;
|
|
19914
19939
|
exports.isDiscoverable = isDiscoverable;
|
|
19915
|
-
exports.isExpired = isExpired;
|
|
19916
|
-
exports.isRecoverable = isRecoverable;
|
|
19917
19940
|
exports.isRetryableProviderError = isRetryableProviderError;
|
|
19918
|
-
exports.isSpendable = isSpendable;
|
|
19919
19941
|
exports.isSubdust = isSubdust;
|
|
19920
19942
|
exports.isTerminalIntentState = isTerminalIntentState;
|
|
19921
19943
|
exports.isValidArkAddress = isValidArkAddress;
|
|
@@ -19942,5 +19964,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
19942
19964
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
19943
19965
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
19944
19966
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
19945
|
-
//# sourceMappingURL=chunk-
|
|
19946
|
-
//# sourceMappingURL=chunk-
|
|
19967
|
+
//# sourceMappingURL=chunk-ENZ4YPR2.cjs.map
|
|
19968
|
+
//# sourceMappingURL=chunk-ENZ4YPR2.cjs.map
|