@arkade-os/sdk 0.4.47 → 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-Dowyo59a.d.cts → asyncStorageTaskQueue-CeLZhZFU.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-Z3aFoXCl.d.ts → asyncStorageTaskQueue-D9SOPMPC.d.ts} +2 -2
- 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-CDDWXBEM.js → chunk-BHHLRZCS.js} +169 -42
- package/dist/chunk-BHHLRZCS.js.map +1 -0
- package/dist/{chunk-HHV5FPC6.cjs → chunk-EB3ALGTM.cjs} +178 -50
- package/dist/chunk-EB3ALGTM.cjs.map +1 -0
- package/dist/{chunk-JAYOXOLT.cjs → chunk-ENDNQPZA.cjs} +17 -44
- package/dist/chunk-ENDNQPZA.cjs.map +1 -0
- package/dist/{chunk-WTTLIFS7.cjs → chunk-ENZ4YPR2.cjs} +944 -544
- package/dist/chunk-ENZ4YPR2.cjs.map +1 -0
- package/dist/{chunk-3N5I6GT6.js → chunk-G6J6AEMH.js} +5 -4
- package/dist/chunk-G6J6AEMH.js.map +1 -0
- package/dist/{chunk-OCS5S3L3.js → chunk-NYR5H6GR.js} +685 -284
- package/dist/chunk-NYR5H6GR.js.map +1 -0
- package/dist/{chunk-VE67GMGM.cjs → chunk-SYDANBJI.cjs} +9 -8
- package/dist/chunk-SYDANBJI.cjs.map +1 -0
- package/dist/{chunk-AJQ4AOT3.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 +211 -183
- package/dist/index.d.cts +61 -11
- package/dist/index.d.ts +61 -11
- 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-Dz-TI4Rb.d.ts → taskRunner-B-2MHCYG.d.ts} +2 -2
- package/dist/{taskRunner-Dz47k0lp.d.cts → taskRunner-Brnak0Rc.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +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-Oxz_wLxo.d.cts → wallet-B5bwixQa.d.ts} +130 -7
- package/dist/{wallet-x7egmXq6.d.ts → wallet-DiOrtYic.d.cts} +130 -7
- 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-3N5I6GT6.js.map +0 -1
- package/dist/chunk-AJQ4AOT3.js.map +0 -1
- package/dist/chunk-C7TXXTMS.js.map +0 -1
- package/dist/chunk-CDDWXBEM.js.map +0 -1
- package/dist/chunk-HHV5FPC6.cjs.map +0 -1
- package/dist/chunk-JAYOXOLT.cjs.map +0 -1
- package/dist/chunk-L5ND2FJJ.cjs.map +0 -1
- package/dist/chunk-OCS5S3L3.js.map +0 -1
- package/dist/chunk-RQSA7ADZ.cjs.map +0 -1
- package/dist/chunk-VE67GMGM.cjs.map +0 -1
- package/dist/chunk-WTTLIFS7.cjs.map +0 -1
- package/dist/chunk-XN3554FT.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
|
})
|
|
@@ -2459,6 +2445,15 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks) {
|
|
|
2459
2445
|
await hooks?.afterFinalize?.();
|
|
2460
2446
|
return { arkTxid, signedCheckpointTxs };
|
|
2461
2447
|
}
|
|
2448
|
+
async function signAndSubmitOffchainTx(params) {
|
|
2449
|
+
const offchainTx = buildOffchainTx(params.inputs, params.outputs, params.serverUnrollScript);
|
|
2450
|
+
const signer = {
|
|
2451
|
+
signArkTx: async (arkTx) => ({ arkTx: await params.identity.sign(arkTx) }),
|
|
2452
|
+
signCheckpoint: (checkpoint) => params.identity.sign(checkpoint)
|
|
2453
|
+
};
|
|
2454
|
+
const { arkTxid } = await submitOffchainTx(params.provider, offchainTx, signer);
|
|
2455
|
+
return arkTxid;
|
|
2456
|
+
}
|
|
2462
2457
|
var AmountVariableName = "amount";
|
|
2463
2458
|
var ExpiryVariableName = "expiry";
|
|
2464
2459
|
var BirthVariableName = "birth";
|
|
@@ -2636,7 +2631,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2636
2631
|
};
|
|
2637
2632
|
}
|
|
2638
2633
|
function deriveContractTapscripts(contract) {
|
|
2639
|
-
const handler =
|
|
2634
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
2640
2635
|
if (!handler) {
|
|
2641
2636
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2642
2637
|
}
|
|
@@ -2710,7 +2705,7 @@ function validateRecipients(recipients, dustAmount) {
|
|
|
2710
2705
|
for (const recipient of recipients) {
|
|
2711
2706
|
let address;
|
|
2712
2707
|
try {
|
|
2713
|
-
address =
|
|
2708
|
+
address = chunk7TXSPRN5_cjs.ArkAddress.decode(recipient.address);
|
|
2714
2709
|
} catch (e) {
|
|
2715
2710
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2716
2711
|
}
|
|
@@ -2738,7 +2733,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
2738
2733
|
continue;
|
|
2739
2734
|
}
|
|
2740
2735
|
for (const v of vtxos) {
|
|
2741
|
-
if (
|
|
2736
|
+
if (!chunk7TXSPRN5_cjs.hasTerminalSpend(v) && !v.isSwept) out.add(`${v.txid}:${v.vout}`);
|
|
2742
2737
|
}
|
|
2743
2738
|
}
|
|
2744
2739
|
return out;
|
|
@@ -2766,19 +2761,32 @@ async function runWithCrossInstanceLock(name, fn) {
|
|
|
2766
2761
|
});
|
|
2767
2762
|
}
|
|
2768
2763
|
var MAX_VTXOS_PER_SETTLEMENT = 50;
|
|
2764
|
+
var MAX_INPUTS_PER_INTENT = 20;
|
|
2769
2765
|
function byValueDescending(vtxos) {
|
|
2770
2766
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
2771
2767
|
}
|
|
2772
|
-
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) {
|
|
2773
2776
|
const expiryKey = (vtxo) => {
|
|
2774
|
-
if (
|
|
2775
|
-
|
|
2776
|
-
if (
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
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;
|
|
2780
2783
|
};
|
|
2781
|
-
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
|
+
});
|
|
2782
2790
|
}
|
|
2783
2791
|
function capSettlementBatch(sorted, maxAmount) {
|
|
2784
2792
|
const batch = [];
|
|
@@ -2804,22 +2812,19 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
2804
2812
|
pollIntervalMs: 6e4,
|
|
2805
2813
|
deprecatedSignerMigration: true
|
|
2806
2814
|
};
|
|
2807
|
-
function getRecoverableVtxos(vtxos, dustAmount) {
|
|
2815
|
+
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
2808
2816
|
return vtxos.filter((vtxo) => {
|
|
2809
|
-
if (
|
|
2817
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
2810
2818
|
return true;
|
|
2811
2819
|
}
|
|
2812
|
-
if (
|
|
2813
|
-
return true;
|
|
2814
|
-
}
|
|
2815
|
-
if (vtxo.virtualStatus.state === "preconfirmed" && isSubdust(vtxo, dustAmount)) {
|
|
2820
|
+
if (chunk7TXSPRN5_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
2816
2821
|
return true;
|
|
2817
2822
|
}
|
|
2818
2823
|
return false;
|
|
2819
2824
|
});
|
|
2820
2825
|
}
|
|
2821
|
-
function getRecoverableWithSubdust(vtxos, dustAmount) {
|
|
2822
|
-
const recoverableVtxos = getRecoverableVtxos(vtxos, dustAmount);
|
|
2826
|
+
function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
2827
|
+
const recoverableVtxos = getRecoverableVtxos(vtxos, dustAmount, now);
|
|
2823
2828
|
const subdust = [];
|
|
2824
2829
|
const regular = [];
|
|
2825
2830
|
for (const vtxo of recoverableVtxos) {
|
|
@@ -2843,17 +2848,16 @@ function getRecoverableWithSubdust(vtxos, dustAmount) {
|
|
|
2843
2848
|
}
|
|
2844
2849
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
2845
2850
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
2846
|
-
const
|
|
2847
|
-
if (
|
|
2848
|
-
const expireAt = new Date(batchExpiry);
|
|
2849
|
-
if (expireAt.getFullYear() < 2025) return false;
|
|
2851
|
+
const expiresAt = chunk7TXSPRN5_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
2852
|
+
if (expiresAt === void 0) return false;
|
|
2850
2853
|
const now = Date.now();
|
|
2854
|
+
const batchExpiry = expiresAt.getTime();
|
|
2851
2855
|
if (batchExpiry <= now) return false;
|
|
2852
2856
|
return batchExpiry - now <= realThresholdMs;
|
|
2853
2857
|
}
|
|
2854
|
-
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount) {
|
|
2858
|
+
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
2855
2859
|
return vtxos.filter(
|
|
2856
|
-
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
2860
|
+
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) || chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount)
|
|
2857
2861
|
);
|
|
2858
2862
|
}
|
|
2859
2863
|
function isMigrationCapable(wallet) {
|
|
@@ -3002,7 +3006,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3002
3006
|
withUnrolled: false
|
|
3003
3007
|
});
|
|
3004
3008
|
const dustAmount = getDustAmount(this.wallet);
|
|
3005
|
-
|
|
3009
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3010
|
+
let { vtxosToRecover, totalAmount } = getRecoverableWithSubdust(allVtxos, dustAmount, now);
|
|
3006
3011
|
if (vtxosToRecover.length === 0) {
|
|
3007
3012
|
throw new Error("No recoverable VTXOs found");
|
|
3008
3013
|
}
|
|
@@ -3011,7 +3016,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3011
3016
|
const capped = capSettlementBatch(byValueDescending(vtxosToRecover), vtxoMaxAmount);
|
|
3012
3017
|
if (capped.length < vtxosToRecover.length) {
|
|
3013
3018
|
const recoverableCount = vtxosToRecover.length;
|
|
3014
|
-
({ vtxosToRecover, totalAmount } = getRecoverableWithSubdust(capped, dustAmount));
|
|
3019
|
+
({ vtxosToRecover, totalAmount } = getRecoverableWithSubdust(capped, dustAmount, now));
|
|
3015
3020
|
if (vtxosToRecover.length === 0) {
|
|
3016
3021
|
throw new Error(
|
|
3017
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}`
|
|
@@ -3063,7 +3068,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3063
3068
|
const dustAmount = getDustAmount(this.wallet);
|
|
3064
3069
|
const { vtxosToRecover, includesSubdust, totalAmount } = getRecoverableWithSubdust(
|
|
3065
3070
|
allVtxos,
|
|
3066
|
-
dustAmount
|
|
3071
|
+
dustAmount,
|
|
3072
|
+
await fetchTimeHeight(this.wallet)
|
|
3067
3073
|
);
|
|
3068
3074
|
const subdustAmount = vtxosToRecover.filter((v) => BigInt(v.value) < dustAmount).reduce((sum, v) => sum + BigInt(v.value), 0n);
|
|
3069
3075
|
return {
|
|
@@ -3097,6 +3103,16 @@ var VtxoManager = class _VtxoManager {
|
|
|
3097
3103
|
* ```
|
|
3098
3104
|
*/
|
|
3099
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) {
|
|
3100
3116
|
if (this.settlementConfig === false && thresholdMs === void 0) {
|
|
3101
3117
|
return [];
|
|
3102
3118
|
}
|
|
@@ -3109,7 +3125,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
3109
3125
|
} else {
|
|
3110
3126
|
threshold = this.renewalConfig?.thresholdMs ?? DEFAULT_RENEWAL_CONFIG.thresholdMs;
|
|
3111
3127
|
}
|
|
3112
|
-
return getExpiringAndRecoverableVtxos(
|
|
3128
|
+
return getExpiringAndRecoverableVtxos(
|
|
3129
|
+
vtxos,
|
|
3130
|
+
threshold,
|
|
3131
|
+
getDustAmount(this.wallet),
|
|
3132
|
+
now ?? await fetchTimeHeight(this.wallet)
|
|
3133
|
+
);
|
|
3113
3134
|
}
|
|
3114
3135
|
/**
|
|
3115
3136
|
* Renew expiring virtual outputs by settling them back to the wallet's address
|
|
@@ -3162,17 +3183,18 @@ var VtxoManager = class _VtxoManager {
|
|
|
3162
3183
|
} else {
|
|
3163
3184
|
threshold = DEFAULT_RENEWAL_CONFIG.thresholdMs;
|
|
3164
3185
|
}
|
|
3165
|
-
|
|
3186
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3187
|
+
let vtxos = await this.selectExpiringVtxos(threshold, now);
|
|
3166
3188
|
if (vtxos.length === 0) {
|
|
3167
3189
|
throw new Error("No VTXOs available to renew");
|
|
3168
3190
|
}
|
|
3169
|
-
vtxos = await this.revalidateBeforeSettle(vtxos, threshold);
|
|
3191
|
+
vtxos = await this.revalidateBeforeSettle(vtxos, threshold, now);
|
|
3170
3192
|
if (vtxos.length === 0) {
|
|
3171
3193
|
throw new Error("No VTXOs available to renew");
|
|
3172
3194
|
}
|
|
3173
3195
|
const info = await this.getInfoProvider()?.getInfo();
|
|
3174
3196
|
const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
|
|
3175
|
-
const capped = capSettlementBatch(byExpiryAscending(vtxos), vtxoMaxAmount);
|
|
3197
|
+
const capped = capSettlementBatch(byExpiryAscending(vtxos, now), vtxoMaxAmount);
|
|
3176
3198
|
if (vtxoMaxAmount >= 0n) {
|
|
3177
3199
|
const oversized = vtxos.filter((vtxo) => BigInt(vtxo.value) > vtxoMaxAmount);
|
|
3178
3200
|
if (oversized.length > 0) {
|
|
@@ -3317,11 +3339,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3317
3339
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3318
3340
|
);
|
|
3319
3341
|
}
|
|
3320
|
-
const tx = new
|
|
3342
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction();
|
|
3321
3343
|
for (const utxo of expiredUtxos) {
|
|
3322
|
-
const utxoScript =
|
|
3344
|
+
const utxoScript = chunk7TXSPRN5_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3323
3345
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
3324
|
-
(leaf) =>
|
|
3346
|
+
(leaf) => chunk7TXSPRN5_cjs.CSVMultisigTapscript.isScriptValid(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
3325
3347
|
);
|
|
3326
3348
|
if (!utxoExitLeaf) {
|
|
3327
3349
|
throw new Error(
|
|
@@ -3336,7 +3358,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3336
3358
|
amount: BigInt(utxo.value)
|
|
3337
3359
|
},
|
|
3338
3360
|
tapLeafScript: [utxoExitLeaf],
|
|
3339
|
-
sequence:
|
|
3361
|
+
sequence: chunk7TXSPRN5_cjs.getSequence(utxoExitLeaf)
|
|
3340
3362
|
});
|
|
3341
3363
|
}
|
|
3342
3364
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -3433,6 +3455,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3433
3455
|
signers: reports
|
|
3434
3456
|
};
|
|
3435
3457
|
if (vtxoMigratable.length > 0) {
|
|
3458
|
+
const now = await fetchTimeHeight(this.wallet);
|
|
3436
3459
|
report.vtxos = await this.runMigrationLeg(
|
|
3437
3460
|
vtxoMigratable,
|
|
3438
3461
|
(c) => c.vtxo.value,
|
|
@@ -3440,7 +3463,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3440
3463
|
vtxoMaxAmount,
|
|
3441
3464
|
dustAmount,
|
|
3442
3465
|
"VTXO",
|
|
3443
|
-
(capped) => wallet.sendSelectedVtxosToSelf(
|
|
3466
|
+
(capped) => wallet.sendSelectedVtxosToSelf(
|
|
3467
|
+
capped.map((c) => c.vtxo),
|
|
3468
|
+
now
|
|
3469
|
+
),
|
|
3470
|
+
(c) => canMigrateBySend(c.vtxo, now)
|
|
3444
3471
|
);
|
|
3445
3472
|
}
|
|
3446
3473
|
if (boardingMigratable.length > 0) {
|
|
@@ -3480,10 +3507,22 @@ var VtxoManager = class _VtxoManager {
|
|
|
3480
3507
|
* the server ceiling by the cap). The dust floor guards the degenerate cases
|
|
3481
3508
|
* where every input was oversized or the whole holding sums below dust.
|
|
3482
3509
|
*/
|
|
3483
|
-
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 } : {};
|
|
3484
3523
|
const oversizedRefs = [];
|
|
3485
3524
|
const sized = [];
|
|
3486
|
-
for (const c of
|
|
3525
|
+
for (const c of migratable) {
|
|
3487
3526
|
if (vtxoMaxAmount >= 0n && BigInt(valueOf(c)) > vtxoMaxAmount) {
|
|
3488
3527
|
oversizedRefs.push(toRef(c));
|
|
3489
3528
|
} else {
|
|
@@ -3503,11 +3542,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
3503
3542
|
const deferred = sized.length - capped.length;
|
|
3504
3543
|
const totalAmount = capped.reduce((sum, c) => sum + BigInt(valueOf(c)), 0n);
|
|
3505
3544
|
if (totalAmount < dustAmount) {
|
|
3506
|
-
const
|
|
3545
|
+
const skipped = sized.length > 0 ? "below-dust" : oversizedRefs.length > 0 ? "oversized-only" : notSpendableRefs.length > 0 ? "not-spendable-only" : "below-dust";
|
|
3507
3546
|
return {
|
|
3508
3547
|
migrated: [],
|
|
3509
|
-
skipped
|
|
3510
|
-
...oversizedField
|
|
3548
|
+
skipped,
|
|
3549
|
+
...oversizedField,
|
|
3550
|
+
...notSpendableField
|
|
3511
3551
|
};
|
|
3512
3552
|
}
|
|
3513
3553
|
try {
|
|
@@ -3516,13 +3556,15 @@ var VtxoManager = class _VtxoManager {
|
|
|
3516
3556
|
txid,
|
|
3517
3557
|
migrated: capped.map(toRef),
|
|
3518
3558
|
...deferred > 0 ? { deferred } : {},
|
|
3519
|
-
...oversizedField
|
|
3559
|
+
...oversizedField,
|
|
3560
|
+
...notSpendableField
|
|
3520
3561
|
};
|
|
3521
3562
|
} catch (e) {
|
|
3522
3563
|
return {
|
|
3523
3564
|
migrated: [],
|
|
3524
3565
|
error: e instanceof Error ? e.message : String(e),
|
|
3525
|
-
...oversizedField
|
|
3566
|
+
...oversizedField,
|
|
3567
|
+
...notSpendableField
|
|
3526
3568
|
};
|
|
3527
3569
|
}
|
|
3528
3570
|
}
|
|
@@ -3550,8 +3592,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3550
3592
|
if (!serverPubKey) continue;
|
|
3551
3593
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
3552
3594
|
if (cls.status === "CURRENT") continue;
|
|
3553
|
-
const recoverable = vtxos.filter((v) =>
|
|
3554
|
-
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);
|
|
3555
3597
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
3556
3598
|
let recoverableCount = 0;
|
|
3557
3599
|
let recoverableValue = 0;
|
|
@@ -3564,7 +3606,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3564
3606
|
awaitingSweepCount = spendable.length;
|
|
3565
3607
|
awaitingSweepValue = value;
|
|
3566
3608
|
for (const v of spendable) {
|
|
3567
|
-
const exp = v
|
|
3609
|
+
const exp = chunk7TXSPRN5_cjs.toBatchExpiry(v);
|
|
3568
3610
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
3569
3611
|
nextSweepEta = exp;
|
|
3570
3612
|
}
|
|
@@ -3600,7 +3642,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3600
3642
|
}
|
|
3601
3643
|
if (isCooperativelyMigratable(cls.status)) {
|
|
3602
3644
|
for (const v of spendable) {
|
|
3603
|
-
if (
|
|
3645
|
+
if (v.expiresAt === void 0 && v.expiresAtHeight === void 0) continue;
|
|
3604
3646
|
migratable.push({ vtxo: v, classification: cls });
|
|
3605
3647
|
}
|
|
3606
3648
|
} else if (cls.status === "EXPIRED") {
|
|
@@ -3825,7 +3867,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3825
3867
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
3826
3868
|
getBoardingTimelock() {
|
|
3827
3869
|
const wallet = this.getSweepWallet();
|
|
3828
|
-
const exitScript =
|
|
3870
|
+
const exitScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
3829
3871
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
3830
3872
|
);
|
|
3831
3873
|
return exitScript.params.timelock;
|
|
@@ -3956,8 +3998,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3956
3998
|
* or doesn't carry the metadata.
|
|
3957
3999
|
*/
|
|
3958
4000
|
extractSpentOutpoint(error) {
|
|
3959
|
-
const ark =
|
|
3960
|
-
if (!
|
|
4001
|
+
const ark = chunkEB3ALGTM_cjs.maybeArkError(error);
|
|
4002
|
+
if (!chunkEB3ALGTM_cjs.isArkError(ark, chunkEB3ALGTM_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
3961
4003
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
3962
4004
|
if (typeof raw !== "string") return void 0;
|
|
3963
4005
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -3978,7 +4020,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3978
4020
|
* candidates and lets the post-submit `VTXO_ALREADY_SPENT` recovery
|
|
3979
4021
|
* handle whatever slipped through.
|
|
3980
4022
|
*/
|
|
3981
|
-
async revalidateBeforeSettle(candidates, thresholdMs) {
|
|
4023
|
+
async revalidateBeforeSettle(candidates, thresholdMs, now) {
|
|
3982
4024
|
if (candidates.length === 0) return candidates;
|
|
3983
4025
|
try {
|
|
3984
4026
|
const cm = await this.wallet.getContractManager();
|
|
@@ -3988,7 +4030,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3988
4030
|
return candidates;
|
|
3989
4031
|
}
|
|
3990
4032
|
try {
|
|
3991
|
-
const refreshed = await this.
|
|
4033
|
+
const refreshed = await this.selectExpiringVtxos(thresholdMs, now);
|
|
3992
4034
|
const candidateKeys = new Set(candidates.map((v) => `${v.txid}:${v.vout}`));
|
|
3993
4035
|
return refreshed.filter((v) => candidateKeys.has(`${v.txid}:${v.vout}`));
|
|
3994
4036
|
} catch (e) {
|
|
@@ -4106,10 +4148,12 @@ var VtxoManager = class _VtxoManager {
|
|
|
4106
4148
|
(u) => u.status.confirmed && !this.knownBoardingUtxos.has(`${u.txid}:${u.vout}`) && !expiredSet.has(`${u.txid}:${u.vout}`)
|
|
4107
4149
|
);
|
|
4108
4150
|
let expiringVtxos = [];
|
|
4151
|
+
let now;
|
|
4109
4152
|
if (!this.renewalInProgress) {
|
|
4110
4153
|
try {
|
|
4111
|
-
|
|
4112
|
-
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);
|
|
4113
4157
|
} catch (e) {
|
|
4114
4158
|
console.error("Error fetching expiring VTXOs:", e);
|
|
4115
4159
|
}
|
|
@@ -4141,17 +4185,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
4141
4185
|
totalAmount += BigInt(u.value) - BigInt(inputFee.satoshis);
|
|
4142
4186
|
}
|
|
4143
4187
|
const filteredVtxos = [];
|
|
4144
|
-
for (const v of byExpiryAscending(expiringVtxos)) {
|
|
4188
|
+
for (const v of byExpiryAscending(expiringVtxos, now ?? { timestamp: /* @__PURE__ */ new Date() })) {
|
|
4145
4189
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
4146
4190
|
break;
|
|
4147
4191
|
}
|
|
4148
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4149
|
-
amount: BigInt(v.value),
|
|
4150
|
-
type: v.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
4151
|
-
weight: 0,
|
|
4152
|
-
birth: v.createdAt,
|
|
4153
|
-
expiry: v.virtualStatus.batchExpiry ? new Date(v.virtualStatus.batchExpiry) : void 0
|
|
4154
|
-
});
|
|
4192
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(v));
|
|
4155
4193
|
if (inputFee.satoshis >= v.value) {
|
|
4156
4194
|
continue;
|
|
4157
4195
|
}
|
|
@@ -4171,7 +4209,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4171
4209
|
const arkAddress = await this.wallet.getAddress();
|
|
4172
4210
|
const outputFee = estimator.evalOffchainOutput({
|
|
4173
4211
|
amount: totalAmount,
|
|
4174
|
-
script: base.hex.encode(
|
|
4212
|
+
script: base.hex.encode(chunk7TXSPRN5_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4175
4213
|
});
|
|
4176
4214
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
4177
4215
|
if (totalAmount < dustAmount) return;
|
|
@@ -4251,7 +4289,7 @@ var ArkNote = class _ArkNote {
|
|
|
4251
4289
|
this.value = value;
|
|
4252
4290
|
this.HRP = HRP;
|
|
4253
4291
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
4254
|
-
this.vtxoScript = new
|
|
4292
|
+
this.vtxoScript = new chunk7TXSPRN5_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
4255
4293
|
const leaf = this.vtxoScript.leaves[0];
|
|
4256
4294
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
4257
4295
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -4355,6 +4393,96 @@ function readUInt32BE(array, offset) {
|
|
|
4355
4393
|
function noteTapscript(preimageHash) {
|
|
4356
4394
|
return btcSigner.Script.encode(["SHA256", preimageHash, "EQUAL"]);
|
|
4357
4395
|
}
|
|
4396
|
+
var ArkadeCash = class _ArkadeCash {
|
|
4397
|
+
constructor(privateKey, serverPubKey, csvTimelock, hrp = _ArkadeCash.DefaultHRP) {
|
|
4398
|
+
this.csvTimelock = csvTimelock;
|
|
4399
|
+
this.hrp = hrp;
|
|
4400
|
+
if (privateKey.length !== 32) {
|
|
4401
|
+
throw new Error(
|
|
4402
|
+
`Invalid private key length: expected 32 bytes, got ${privateKey.length}`
|
|
4403
|
+
);
|
|
4404
|
+
}
|
|
4405
|
+
if (serverPubKey.length !== 32) {
|
|
4406
|
+
throw new Error(
|
|
4407
|
+
`Invalid server public key length: expected 32 bytes, got ${serverPubKey.length}`
|
|
4408
|
+
);
|
|
4409
|
+
}
|
|
4410
|
+
this._privateKey = privateKey.slice();
|
|
4411
|
+
this._serverPubKey = serverPubKey.slice();
|
|
4412
|
+
this._publicKey = utils_js.pubSchnorr(this._privateKey);
|
|
4413
|
+
}
|
|
4414
|
+
csvTimelock;
|
|
4415
|
+
hrp;
|
|
4416
|
+
static DefaultHRP = "arkadecash";
|
|
4417
|
+
static Version = 0;
|
|
4418
|
+
static PayloadLength = 1 + 32 + 32 + 4;
|
|
4419
|
+
// 69 bytes
|
|
4420
|
+
// Keys are held as private copies so a caller mutating the array it passed
|
|
4421
|
+
// in — or one it reads back from a getter — cannot alter this note's
|
|
4422
|
+
// identity or the outputs derived from it.
|
|
4423
|
+
_privateKey;
|
|
4424
|
+
_serverPubKey;
|
|
4425
|
+
_publicKey;
|
|
4426
|
+
/** The note's private key. Returns a fresh copy; mutating it is a no-op. */
|
|
4427
|
+
get privateKey() {
|
|
4428
|
+
return this._privateKey.slice();
|
|
4429
|
+
}
|
|
4430
|
+
/** The server's public key. Returns a fresh copy; mutating it is a no-op. */
|
|
4431
|
+
get serverPubKey() {
|
|
4432
|
+
return this._serverPubKey.slice();
|
|
4433
|
+
}
|
|
4434
|
+
/** The note's public key. Returns a fresh copy; mutating it is a no-op. */
|
|
4435
|
+
get publicKey() {
|
|
4436
|
+
return this._publicKey.slice();
|
|
4437
|
+
}
|
|
4438
|
+
static generate(serverPubKey, csvTimelock, hrp) {
|
|
4439
|
+
return new _ArkadeCash(utils_js.randomPrivateKeyBytes(), serverPubKey, csvTimelock, hrp);
|
|
4440
|
+
}
|
|
4441
|
+
static fromString(encoded) {
|
|
4442
|
+
const decoded = base.bech32m.decodeUnsafe(encoded.trim().toLowerCase(), 1023);
|
|
4443
|
+
if (!decoded) {
|
|
4444
|
+
throw new Error("Invalid arkadeCash string: failed to decode bech32m");
|
|
4445
|
+
}
|
|
4446
|
+
const data = new Uint8Array(base.bech32m.fromWords(decoded.words));
|
|
4447
|
+
if (data.length !== _ArkadeCash.PayloadLength) {
|
|
4448
|
+
throw new Error(
|
|
4449
|
+
`Invalid arkadeCash data length: expected ${_ArkadeCash.PayloadLength} bytes, got ${data.length}`
|
|
4450
|
+
);
|
|
4451
|
+
}
|
|
4452
|
+
const version = data[0];
|
|
4453
|
+
if (version !== _ArkadeCash.Version) {
|
|
4454
|
+
throw new Error(`Unsupported arkadeCash version: ${version}`);
|
|
4455
|
+
}
|
|
4456
|
+
const privateKey = data.slice(1, 33);
|
|
4457
|
+
const serverPubKey = data.slice(33, 65);
|
|
4458
|
+
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
4459
|
+
const csvTimelock = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
4460
|
+
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
4461
|
+
}
|
|
4462
|
+
toString() {
|
|
4463
|
+
const data = new Uint8Array(_ArkadeCash.PayloadLength);
|
|
4464
|
+
data[0] = _ArkadeCash.Version;
|
|
4465
|
+
data.set(this._privateKey, 1);
|
|
4466
|
+
data.set(this._serverPubKey, 33);
|
|
4467
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(this.csvTimelock);
|
|
4468
|
+
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
4469
|
+
const words = base.bech32m.toWords(data);
|
|
4470
|
+
return base.bech32m.encode(this.hrp, words, 1023);
|
|
4471
|
+
}
|
|
4472
|
+
get identity() {
|
|
4473
|
+
return SingleKey.fromPrivateKey(this._privateKey);
|
|
4474
|
+
}
|
|
4475
|
+
get vtxoScript() {
|
|
4476
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
4477
|
+
pubKey: this._publicKey,
|
|
4478
|
+
serverPubKey: this._serverPubKey,
|
|
4479
|
+
csvTimelock: this.csvTimelock
|
|
4480
|
+
});
|
|
4481
|
+
}
|
|
4482
|
+
address(addressHrp) {
|
|
4483
|
+
return this.vtxoScript.address(addressHrp, this._serverPubKey);
|
|
4484
|
+
}
|
|
4485
|
+
};
|
|
4358
4486
|
|
|
4359
4487
|
// src/repositories/intentRepository.ts
|
|
4360
4488
|
var ALL_INTENT_STATES = [
|
|
@@ -4606,7 +4734,7 @@ async function captureExitBranch(params) {
|
|
|
4606
4734
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4607
4735
|
if (nonCommitment.length > 0) {
|
|
4608
4736
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4609
|
-
psbtByTxid.set(
|
|
4737
|
+
psbtByTxid.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4610
4738
|
}
|
|
4611
4739
|
}
|
|
4612
4740
|
}
|
|
@@ -4649,10 +4777,10 @@ var IndexerExitDataSource = class {
|
|
|
4649
4777
|
while (hasMore) {
|
|
4650
4778
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
4651
4779
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
4652
|
-
{ pageIndex, pageSize:
|
|
4780
|
+
{ pageIndex, pageSize: chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE }
|
|
4653
4781
|
);
|
|
4654
4782
|
chain.push(...page);
|
|
4655
|
-
hasMore = meta ? page.length ===
|
|
4783
|
+
hasMore = meta ? page.length === chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4656
4784
|
pageIndex++;
|
|
4657
4785
|
}
|
|
4658
4786
|
return chain;
|
|
@@ -4664,12 +4792,12 @@ var IndexerExitDataSource = class {
|
|
|
4664
4792
|
while (hasMore) {
|
|
4665
4793
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
4666
4794
|
pageIndex,
|
|
4667
|
-
pageSize:
|
|
4795
|
+
pageSize: chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE
|
|
4668
4796
|
});
|
|
4669
4797
|
for (const psbt of txs) {
|
|
4670
|
-
out.set(
|
|
4798
|
+
out.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4671
4799
|
}
|
|
4672
|
-
hasMore = page ? txs.length ===
|
|
4800
|
+
hasMore = page ? txs.length === chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4673
4801
|
pageIndex++;
|
|
4674
4802
|
}
|
|
4675
4803
|
return out;
|
|
@@ -4690,7 +4818,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4690
4818
|
}
|
|
4691
4819
|
}
|
|
4692
4820
|
function psbtInputTxids(psbtBase64) {
|
|
4693
|
-
const tx =
|
|
4821
|
+
const tx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4694
4822
|
const ids = [];
|
|
4695
4823
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4696
4824
|
const txid = tx.getInput(i).txid;
|
|
@@ -4793,7 +4921,7 @@ function createExitChainResolver(params) {
|
|
|
4793
4921
|
|
|
4794
4922
|
// src/providers/availability.ts
|
|
4795
4923
|
function isRetryableProviderError(error) {
|
|
4796
|
-
return error instanceof
|
|
4924
|
+
return error instanceof chunkEB3ALGTM_cjs.ProviderUnavailableError || error instanceof chunkEB3ALGTM_cjs.FetchError || chunkEB3ALGTM_cjs.isFetchTimeoutError(error);
|
|
4797
4925
|
}
|
|
4798
4926
|
|
|
4799
4927
|
// src/utils/syncCursors.ts
|
|
@@ -5046,7 +5174,7 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
5046
5174
|
if (!isRetryableProviderError(err)) throw err;
|
|
5047
5175
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
5048
5176
|
if (!snapshot) {
|
|
5049
|
-
throw new
|
|
5177
|
+
throw new chunkEB3ALGTM_cjs.ProviderUnavailableError(
|
|
5050
5178
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
5051
5179
|
{ cause: err }
|
|
5052
5180
|
);
|
|
@@ -5419,13 +5547,13 @@ function subtractAssets(spent, change) {
|
|
|
5419
5547
|
return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
|
|
5420
5548
|
}
|
|
5421
5549
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, getTxCreatedAt) {
|
|
5422
|
-
const fromOldestVtxo =
|
|
5550
|
+
const fromOldestVtxo = vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
5423
5551
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
5424
5552
|
const sent = [];
|
|
5425
5553
|
let received = [];
|
|
5426
5554
|
for (const vtxo of fromOldestVtxo) {
|
|
5427
5555
|
if (vtxo.status.isLeaf) {
|
|
5428
|
-
const commitmentTxid = vtxo.
|
|
5556
|
+
const commitmentTxid = vtxo.commitmentTxIds[0];
|
|
5429
5557
|
const vtxoCreatedAt = vtxo.createdAt.getTime();
|
|
5430
5558
|
const ignoredCommitment = commitmentsToIgnore.has(commitmentTxid) || !!vtxo.settledBy && commitmentsToIgnore.has(vtxo.settledBy);
|
|
5431
5559
|
if (ignoredCommitment) {
|
|
@@ -5433,7 +5561,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5433
5561
|
unmatchedSettledBoardingTxs,
|
|
5434
5562
|
(tx) => tx.createdAt <= vtxoCreatedAt && (tx.key.commitmentTxid === commitmentTxid || tx.key.commitmentTxid === vtxo.settledBy)
|
|
5435
5563
|
);
|
|
5436
|
-
} else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.
|
|
5564
|
+
} else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.commitmentTxIds[0]).length === 0) {
|
|
5437
5565
|
const duplicateBoardingReceive = consumeBoardingReceive(
|
|
5438
5566
|
unmatchedSettledBoardingTxs,
|
|
5439
5567
|
(tx) => tx.amount === vtxo.value && tx.createdAt <= vtxoCreatedAt
|
|
@@ -5496,7 +5624,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5496
5624
|
}
|
|
5497
5625
|
if (vtxo.settledBy && !commitmentsToIgnore.has(vtxo.settledBy) && !sent.some((s) => s.key.commitmentTxid === vtxo.settledBy)) {
|
|
5498
5626
|
const changes = fromOldestVtxo.filter(
|
|
5499
|
-
(v) => v.status.isLeaf && v.
|
|
5627
|
+
(v) => v.status.isLeaf && v.commitmentTxIds.length > 0 && v.commitmentTxIds.every((_) => vtxo.settledBy === _)
|
|
5500
5628
|
);
|
|
5501
5629
|
const forfeitVtxos = fromOldestVtxo.filter((v) => v.settledBy === vtxo.settledBy);
|
|
5502
5630
|
const forfeitAmount = forfeitVtxos.reduce((acc, v) => acc + v.value, 0);
|
|
@@ -5581,7 +5709,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5581
5709
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5582
5710
|
withRecoverable: false
|
|
5583
5711
|
});
|
|
5584
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5712
|
+
const controlAssetRef = params.controlAssetId ? chunkEB3ALGTM_cjs.AssetRef.fromId(chunkEB3ALGTM_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5585
5713
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5586
5714
|
let totalBtcSelected = 0n;
|
|
5587
5715
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5594,8 +5722,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5594
5722
|
}
|
|
5595
5723
|
}
|
|
5596
5724
|
const groups = [];
|
|
5597
|
-
const issuedAssetOutput =
|
|
5598
|
-
const issuedAssetGroup =
|
|
5725
|
+
const issuedAssetOutput = chunkEB3ALGTM_cjs.AssetOutput.create(0, params.amount);
|
|
5726
|
+
const issuedAssetGroup = chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5599
5727
|
null,
|
|
5600
5728
|
controlAssetRef,
|
|
5601
5729
|
[],
|
|
@@ -5610,28 +5738,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5610
5738
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5611
5739
|
for (const asset of assets) {
|
|
5612
5740
|
if (asset.assetId !== assetId) continue;
|
|
5613
|
-
changeInputs.push(
|
|
5741
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5614
5742
|
}
|
|
5615
5743
|
}
|
|
5616
5744
|
groups.push(
|
|
5617
|
-
|
|
5618
|
-
|
|
5745
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5746
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5619
5747
|
null,
|
|
5620
5748
|
changeInputs,
|
|
5621
|
-
[
|
|
5749
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)],
|
|
5622
5750
|
[]
|
|
5623
5751
|
)
|
|
5624
5752
|
);
|
|
5625
5753
|
}
|
|
5626
5754
|
}
|
|
5627
5755
|
const address = await this.wallet.getAddress();
|
|
5628
|
-
const outputAddress =
|
|
5756
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5629
5757
|
const outputs = [
|
|
5630
5758
|
{
|
|
5631
5759
|
script: outputAddress.pkScript,
|
|
5632
5760
|
amount: BigInt(totalBtcSelected)
|
|
5633
5761
|
},
|
|
5634
|
-
Extension.create([
|
|
5762
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5635
5763
|
];
|
|
5636
5764
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5637
5765
|
coinSelection.inputs,
|
|
@@ -5639,7 +5767,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5639
5767
|
);
|
|
5640
5768
|
return {
|
|
5641
5769
|
arkTxId: arkTxid,
|
|
5642
|
-
assetId:
|
|
5770
|
+
assetId: chunkEB3ALGTM_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5643
5771
|
};
|
|
5644
5772
|
}
|
|
5645
5773
|
/**
|
|
@@ -5711,16 +5839,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5711
5839
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5712
5840
|
for (const asset of assets) {
|
|
5713
5841
|
if (asset.assetId !== params.assetId) continue;
|
|
5714
|
-
reissueInputs.push(
|
|
5842
|
+
reissueInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5715
5843
|
}
|
|
5716
5844
|
}
|
|
5717
5845
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5718
|
-
const reissueAssetIdObj =
|
|
5719
|
-
const reissueAssetGroup =
|
|
5846
|
+
const reissueAssetIdObj = chunkEB3ALGTM_cjs.AssetId.fromString(params.assetId);
|
|
5847
|
+
const reissueAssetGroup = chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5720
5848
|
reissueAssetIdObj,
|
|
5721
5849
|
null,
|
|
5722
5850
|
reissueInputs,
|
|
5723
|
-
[
|
|
5851
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5724
5852
|
[]
|
|
5725
5853
|
);
|
|
5726
5854
|
const groups = [reissueAssetGroup];
|
|
@@ -5729,27 +5857,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5729
5857
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5730
5858
|
for (const asset of assets) {
|
|
5731
5859
|
if (asset.assetId !== assetId) continue;
|
|
5732
|
-
changeInputs.push(
|
|
5860
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5733
5861
|
}
|
|
5734
5862
|
}
|
|
5735
5863
|
groups.push(
|
|
5736
|
-
|
|
5737
|
-
|
|
5864
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5865
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5738
5866
|
null,
|
|
5739
5867
|
changeInputs,
|
|
5740
|
-
[
|
|
5868
|
+
[chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)],
|
|
5741
5869
|
[]
|
|
5742
5870
|
)
|
|
5743
5871
|
);
|
|
5744
5872
|
}
|
|
5745
5873
|
const address = await this.wallet.getAddress();
|
|
5746
|
-
const outputAddress =
|
|
5874
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5747
5875
|
const outputs = [
|
|
5748
5876
|
{
|
|
5749
5877
|
script: outputAddress.pkScript,
|
|
5750
5878
|
amount: BigInt(totalBtcSelected)
|
|
5751
5879
|
},
|
|
5752
|
-
Extension.create([
|
|
5880
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5753
5881
|
];
|
|
5754
5882
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5755
5883
|
return arkTxid;
|
|
@@ -5816,27 +5944,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5816
5944
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5817
5945
|
for (const asset of assets) {
|
|
5818
5946
|
if (asset.assetId !== assetId) continue;
|
|
5819
|
-
changeInputs.push(
|
|
5947
|
+
changeInputs.push(chunkEB3ALGTM_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5820
5948
|
}
|
|
5821
5949
|
}
|
|
5822
5950
|
groups.push(
|
|
5823
|
-
|
|
5824
|
-
|
|
5951
|
+
chunkEB3ALGTM_cjs.AssetGroup.create(
|
|
5952
|
+
chunkEB3ALGTM_cjs.AssetId.fromString(assetId),
|
|
5825
5953
|
null,
|
|
5826
5954
|
changeInputs,
|
|
5827
|
-
amount > 0n ? [
|
|
5955
|
+
amount > 0n ? [chunkEB3ALGTM_cjs.AssetOutput.create(0, amount)] : [],
|
|
5828
5956
|
[]
|
|
5829
5957
|
)
|
|
5830
5958
|
);
|
|
5831
5959
|
}
|
|
5832
5960
|
const address = await this.wallet.getAddress();
|
|
5833
|
-
const outputAddress =
|
|
5961
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(address);
|
|
5834
5962
|
const outputs = [
|
|
5835
5963
|
{
|
|
5836
5964
|
script: outputAddress.pkScript,
|
|
5837
5965
|
amount: BigInt(totalBtcSelected)
|
|
5838
5966
|
},
|
|
5839
|
-
Extension.create([
|
|
5967
|
+
Extension.create([chunkEB3ALGTM_cjs.Packet.create(groups)]).txOut()
|
|
5840
5968
|
];
|
|
5841
5969
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5842
5970
|
return arkTxid;
|
|
@@ -5861,7 +5989,7 @@ function castMetadata(metadata) {
|
|
|
5861
5989
|
} else {
|
|
5862
5990
|
throw new Error("Invalid metadata value type");
|
|
5863
5991
|
}
|
|
5864
|
-
md.push(
|
|
5992
|
+
md.push(chunkEB3ALGTM_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5865
5993
|
}
|
|
5866
5994
|
return md;
|
|
5867
5995
|
}
|
|
@@ -5882,10 +6010,10 @@ var DelegateManagerImpl = class {
|
|
|
5882
6010
|
if (vtxos.length === 0) {
|
|
5883
6011
|
return { delegated: [], failed: [] };
|
|
5884
6012
|
}
|
|
5885
|
-
const destinationScript =
|
|
6013
|
+
const destinationScript = chunk7TXSPRN5_cjs.ArkAddress.decode(destination).pkScript;
|
|
5886
6014
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
5887
6015
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
5888
|
-
const eligible = vtxos.filter(
|
|
6016
|
+
const eligible = vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo).filter(
|
|
5889
6017
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
5890
6018
|
);
|
|
5891
6019
|
if (eligible.length === 0) {
|
|
@@ -5910,14 +6038,15 @@ var DelegateManagerImpl = class {
|
|
|
5910
6038
|
}
|
|
5911
6039
|
return { delegated: eligible, failed: [] };
|
|
5912
6040
|
}
|
|
6041
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
5913
6042
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
5914
6043
|
let recoverableVtxos = [];
|
|
5915
6044
|
for (const vtxo of eligible) {
|
|
5916
|
-
if (
|
|
6045
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
5917
6046
|
recoverableVtxos.push(vtxo);
|
|
5918
6047
|
continue;
|
|
5919
6048
|
}
|
|
5920
|
-
const expiry = vtxo
|
|
6049
|
+
const expiry = chunk7TXSPRN5_cjs.toBatchExpiry(vtxo);
|
|
5921
6050
|
if (!expiry) continue;
|
|
5922
6051
|
const dayKey = getDayTimestamp(expiry);
|
|
5923
6052
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -5981,10 +6110,8 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5981
6110
|
throw new Error("unable to delegate: delegate provider not configured");
|
|
5982
6111
|
}
|
|
5983
6112
|
if (!delegateAt) {
|
|
5984
|
-
const
|
|
5985
|
-
|
|
5986
|
-
Number.MAX_SAFE_INTEGER
|
|
5987
|
-
);
|
|
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);
|
|
5988
6115
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
5989
6116
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
5990
6117
|
} else {
|
|
@@ -6013,11 +6140,8 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6013
6140
|
let amount = 0n;
|
|
6014
6141
|
for (const coin of vtxos) {
|
|
6015
6142
|
const inputFee = estimator.evalOffchainInput({
|
|
6016
|
-
|
|
6017
|
-
type: "vtxo"
|
|
6018
|
-
weight: 0,
|
|
6019
|
-
birth: coin.createdAt,
|
|
6020
|
-
expiry: coin.virtualStatus.batchExpiry ? new Date(coin.virtualStatus.batchExpiry) : void 0
|
|
6143
|
+
...chunk7TXSPRN5_cjs.toOffchainInputFeeParams(coin),
|
|
6144
|
+
type: "vtxo"
|
|
6021
6145
|
});
|
|
6022
6146
|
if (inputFee.value >= coin.value) {
|
|
6023
6147
|
continue;
|
|
@@ -6030,7 +6154,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6030
6154
|
const delegateFee = BigInt(Number(fee));
|
|
6031
6155
|
if (delegateFee > 0n) {
|
|
6032
6156
|
outputs.push({
|
|
6033
|
-
script:
|
|
6157
|
+
script: chunk7TXSPRN5_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
6034
6158
|
amount: delegateFee
|
|
6035
6159
|
});
|
|
6036
6160
|
}
|
|
@@ -6063,10 +6187,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6063
6187
|
destinationScript
|
|
6064
6188
|
);
|
|
6065
6189
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
6066
|
-
btcSigner.Address(
|
|
6190
|
+
btcSigner.Address(chunk7TXSPRN5_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
6067
6191
|
);
|
|
6068
6192
|
const forfeits = await Promise.all(
|
|
6069
|
-
vtxos.filter((v) => !
|
|
6193
|
+
vtxos.filter((v) => !chunk7TXSPRN5_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
6070
6194
|
const forfeit = await makeDelegateForfeitTx(
|
|
6071
6195
|
coin,
|
|
6072
6196
|
dust,
|
|
@@ -6091,7 +6215,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
6091
6215
|
index: input.vout,
|
|
6092
6216
|
witnessUtxo: {
|
|
6093
6217
|
amount: BigInt(input.value),
|
|
6094
|
-
script:
|
|
6218
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
6095
6219
|
},
|
|
6096
6220
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
6097
6221
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -6149,7 +6273,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
6149
6273
|
expire_at: 0,
|
|
6150
6274
|
cosigners_public_keys: cosignerPubKeys
|
|
6151
6275
|
};
|
|
6152
|
-
const proof =
|
|
6276
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, outputs);
|
|
6153
6277
|
const signedProof = await identity.sign(proof);
|
|
6154
6278
|
return {
|
|
6155
6279
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -6167,10 +6291,10 @@ function getDayTimestamp(timestamp) {
|
|
|
6167
6291
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
6168
6292
|
if (!vtxo.tapTree) return void 0;
|
|
6169
6293
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
6170
|
-
const vtxoScript =
|
|
6294
|
+
const vtxoScript = chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
6171
6295
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
6172
|
-
const arkTapscript =
|
|
6173
|
-
if (!
|
|
6296
|
+
const arkTapscript = chunk7TXSPRN5_cjs.decodeTapscript(chunk7TXSPRN5_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
6297
|
+
if (!chunk7TXSPRN5_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
6174
6298
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
6175
6299
|
});
|
|
6176
6300
|
}
|
|
@@ -6358,7 +6482,7 @@ async function closeDatabase(dbName) {
|
|
|
6358
6482
|
return true;
|
|
6359
6483
|
}
|
|
6360
6484
|
function scriptFromArkAddress(address) {
|
|
6361
|
-
return base.hex.encode(
|
|
6485
|
+
return base.hex.encode(chunk7TXSPRN5_cjs.ArkAddress.decode(address).pkScript);
|
|
6362
6486
|
}
|
|
6363
6487
|
|
|
6364
6488
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -6854,7 +6978,8 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
6854
6978
|
);
|
|
6855
6979
|
}
|
|
6856
6980
|
async function getVtxosForContract(repo, contract) {
|
|
6857
|
-
|
|
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);
|
|
6858
6983
|
}
|
|
6859
6984
|
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
6860
6985
|
if (repo.saveVtxosForScript) {
|
|
@@ -7058,7 +7183,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
7058
7183
|
const s = base.hex.decode(t.s);
|
|
7059
7184
|
return [cb, s];
|
|
7060
7185
|
};
|
|
7061
|
-
var deserializeVtxo = (o) => ({
|
|
7186
|
+
var deserializeVtxo = (o) => chunk7TXSPRN5_cjs.normalizeVtxo({
|
|
7062
7187
|
...o,
|
|
7063
7188
|
createdAt: new Date(o.createdAt),
|
|
7064
7189
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -7657,50 +7782,12 @@ function getLifecycleWeight(v) {
|
|
|
7657
7782
|
if (v.arkTxId) weight += 2;
|
|
7658
7783
|
return weight;
|
|
7659
7784
|
}
|
|
7785
|
+
|
|
7786
|
+
// src/repositories/migrations/walletRepositoryImpl.ts
|
|
7660
7787
|
var getVtxosStorageKey = (address) => `vtxos:${address}`;
|
|
7661
7788
|
var getUtxosStorageKey = (address) => `utxos:${address}`;
|
|
7662
7789
|
var getTransactionsStorageKey = (address) => `tx:${address}`;
|
|
7663
7790
|
var walletStateStorageKey = "wallet:state";
|
|
7664
|
-
var serializeVtxo2 = (v) => ({
|
|
7665
|
-
...v,
|
|
7666
|
-
tapTree: base.hex.encode(v.tapTree),
|
|
7667
|
-
forfeitTapLeafScript: serializeTapLeaf2(v.forfeitTapLeafScript),
|
|
7668
|
-
intentTapLeafScript: serializeTapLeaf2(v.intentTapLeafScript),
|
|
7669
|
-
extraWitness: v.extraWitness?.map(base.hex.encode),
|
|
7670
|
-
assets: serializeAssets(v.assets)
|
|
7671
|
-
});
|
|
7672
|
-
var serializeUtxo2 = (u) => ({
|
|
7673
|
-
...u,
|
|
7674
|
-
tapTree: base.hex.encode(u.tapTree),
|
|
7675
|
-
forfeitTapLeafScript: serializeTapLeaf2(u.forfeitTapLeafScript),
|
|
7676
|
-
intentTapLeafScript: serializeTapLeaf2(u.intentTapLeafScript),
|
|
7677
|
-
extraWitness: u.extraWitness?.map(base.hex.encode)
|
|
7678
|
-
});
|
|
7679
|
-
var deserializeVtxo2 = (o) => ({
|
|
7680
|
-
...o,
|
|
7681
|
-
createdAt: new Date(o.createdAt),
|
|
7682
|
-
tapTree: base.hex.decode(o.tapTree),
|
|
7683
|
-
forfeitTapLeafScript: deserializeTapLeaf2(o.forfeitTapLeafScript),
|
|
7684
|
-
intentTapLeafScript: deserializeTapLeaf2(o.intentTapLeafScript),
|
|
7685
|
-
extraWitness: o.extraWitness?.map(base.hex.decode),
|
|
7686
|
-
assets: deserializeAssets(o.assets)
|
|
7687
|
-
});
|
|
7688
|
-
var deserializeUtxo2 = (o) => ({
|
|
7689
|
-
...o,
|
|
7690
|
-
tapTree: base.hex.decode(o.tapTree),
|
|
7691
|
-
forfeitTapLeafScript: deserializeTapLeaf2(o.forfeitTapLeafScript),
|
|
7692
|
-
intentTapLeafScript: deserializeTapLeaf2(o.intentTapLeafScript),
|
|
7693
|
-
extraWitness: o.extraWitness?.map(base.hex.decode)
|
|
7694
|
-
});
|
|
7695
|
-
var serializeTapLeaf2 = ([cb, s]) => ({
|
|
7696
|
-
cb: base.hex.encode(btcSigner.TaprootControlBlock.encode(cb)),
|
|
7697
|
-
s: base.hex.encode(s)
|
|
7698
|
-
});
|
|
7699
|
-
var deserializeTapLeaf2 = (t) => {
|
|
7700
|
-
const cb = btcSigner.TaprootControlBlock.decode(base.hex.decode(t.cb));
|
|
7701
|
-
const s = base.hex.decode(t.s);
|
|
7702
|
-
return [cb, s];
|
|
7703
|
-
};
|
|
7704
7791
|
var WalletRepositoryImpl = class {
|
|
7705
7792
|
version = 1;
|
|
7706
7793
|
storage;
|
|
@@ -7712,7 +7799,7 @@ var WalletRepositoryImpl = class {
|
|
|
7712
7799
|
if (!stored) return [];
|
|
7713
7800
|
try {
|
|
7714
7801
|
const parsed = JSON.parse(stored);
|
|
7715
|
-
return parsed.map(
|
|
7802
|
+
return parsed.map(deserializeVtxo);
|
|
7716
7803
|
} catch (error) {
|
|
7717
7804
|
console.error(`Failed to parse VTXOs for address ${address}:`, error);
|
|
7718
7805
|
return [];
|
|
@@ -7732,7 +7819,7 @@ var WalletRepositoryImpl = class {
|
|
|
7732
7819
|
}
|
|
7733
7820
|
await this.storage.setItem(
|
|
7734
7821
|
getVtxosStorageKey(address),
|
|
7735
|
-
JSON.stringify(storedVtxos.map(
|
|
7822
|
+
JSON.stringify(storedVtxos.map(serializeVtxo))
|
|
7736
7823
|
);
|
|
7737
7824
|
}
|
|
7738
7825
|
async clearVtxos(address) {
|
|
@@ -7746,7 +7833,7 @@ var WalletRepositoryImpl = class {
|
|
|
7746
7833
|
if (!stored) return [];
|
|
7747
7834
|
try {
|
|
7748
7835
|
const parsed = JSON.parse(stored);
|
|
7749
|
-
return parsed.map(
|
|
7836
|
+
return parsed.map(deserializeUtxo);
|
|
7750
7837
|
} catch (error) {
|
|
7751
7838
|
console.error(`Failed to parse UTXOs for address ${address}:`, error);
|
|
7752
7839
|
return [];
|
|
@@ -7766,7 +7853,7 @@ var WalletRepositoryImpl = class {
|
|
|
7766
7853
|
});
|
|
7767
7854
|
await this.storage.setItem(
|
|
7768
7855
|
getUtxosStorageKey(address),
|
|
7769
|
-
JSON.stringify(storedUtxos.map(
|
|
7856
|
+
JSON.stringify(storedUtxos.map(serializeUtxo))
|
|
7770
7857
|
);
|
|
7771
7858
|
}
|
|
7772
7859
|
async clearUtxos(address) {
|
|
@@ -8232,7 +8319,7 @@ var ContractWatcher = class {
|
|
|
8232
8319
|
this.connectionState = "connected";
|
|
8233
8320
|
this.reconnectAttempts = 0;
|
|
8234
8321
|
this.listenLoop().catch((e) => {
|
|
8235
|
-
if (
|
|
8322
|
+
if (chunkEB3ALGTM_cjs.isEventSourceError(e)) {
|
|
8236
8323
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8237
8324
|
} else {
|
|
8238
8325
|
console.error(e);
|
|
@@ -8418,15 +8505,27 @@ var ContractWatcher = class {
|
|
|
8418
8505
|
}
|
|
8419
8506
|
/**
|
|
8420
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.
|
|
8421
8512
|
*/
|
|
8422
8513
|
handleSubscriptionUpdate(update) {
|
|
8423
8514
|
if (!this.eventCallback) return;
|
|
8424
8515
|
const timestamp = Date.now();
|
|
8425
8516
|
if (update.newVtxos?.length) {
|
|
8426
|
-
this.processSubscriptionVtxos(
|
|
8517
|
+
this.processSubscriptionVtxos(
|
|
8518
|
+
update.newVtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo),
|
|
8519
|
+
"vtxo_received",
|
|
8520
|
+
timestamp
|
|
8521
|
+
);
|
|
8427
8522
|
}
|
|
8428
8523
|
if (update.spentVtxos?.length) {
|
|
8429
|
-
this.processSubscriptionVtxos(
|
|
8524
|
+
this.processSubscriptionVtxos(
|
|
8525
|
+
update.spentVtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo),
|
|
8526
|
+
"vtxo_spent",
|
|
8527
|
+
timestamp
|
|
8528
|
+
);
|
|
8430
8529
|
}
|
|
8431
8530
|
}
|
|
8432
8531
|
/**
|
|
@@ -8556,7 +8655,7 @@ async function reconcileIntents(deps) {
|
|
|
8556
8655
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
8557
8656
|
if (outpoints.length > 0) {
|
|
8558
8657
|
try {
|
|
8559
|
-
const { vtxos } = await deps.indexerProvider
|
|
8658
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
8560
8659
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
8561
8660
|
} catch (e) {
|
|
8562
8661
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -8758,7 +8857,7 @@ var ContractManager = class _ContractManager {
|
|
|
8758
8857
|
* `persisted` is `true`.
|
|
8759
8858
|
*/
|
|
8760
8859
|
async upsertContract(params) {
|
|
8761
|
-
const handler =
|
|
8860
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(params.type);
|
|
8762
8861
|
if (!handler) {
|
|
8763
8862
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
8764
8863
|
}
|
|
@@ -8809,9 +8908,10 @@ var ContractManager = class _ContractManager {
|
|
|
8809
8908
|
* Safety-critical invariants (spec §2.C / §4):
|
|
8810
8909
|
* - `opts.materialize(i)` throwing is structural/fatal: it is NOT
|
|
8811
8910
|
* wrapped — it propagates and aborts the scan.
|
|
8812
|
-
* - A `discoverAt` rejection is collected into `handlerErrors` and
|
|
8813
|
-
*
|
|
8814
|
-
*
|
|
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.
|
|
8815
8915
|
* - `persistAndWatchContract` rejecting is operational/fatal and
|
|
8816
8916
|
* propagates (only `discoverAt` is guarded).
|
|
8817
8917
|
* - Within an index the handler probes run concurrently (independent
|
|
@@ -8825,8 +8925,12 @@ var ContractManager = class _ContractManager {
|
|
|
8825
8925
|
* over-scanned, nothing is discarded, and `materialize`/`discoverAt` are
|
|
8826
8926
|
* invoked on exactly the same index set. The window's hits are still
|
|
8827
8927
|
* processed strictly in ascending index order, so the discovered set,
|
|
8828
|
-
* persisted rows, `
|
|
8829
|
-
* 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.
|
|
8830
8934
|
*/
|
|
8831
8935
|
async scanContracts(opts) {
|
|
8832
8936
|
const gapLimit = opts.gapLimit ?? 20;
|
|
@@ -8841,14 +8945,15 @@ var ContractManager = class _ContractManager {
|
|
|
8841
8945
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
8842
8946
|
);
|
|
8843
8947
|
}
|
|
8844
|
-
const registered =
|
|
8948
|
+
const registered = chunk5XMVTK5S_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk5XMVTK5S_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
8845
8949
|
const discoverables = [
|
|
8846
8950
|
...registered.filter((h) => h.type === "boarding"),
|
|
8847
8951
|
...registered.filter((h) => h.type !== "boarding")
|
|
8848
8952
|
];
|
|
8849
8953
|
const maxIdx = opts.hd ? SCAN_MAX_INDEX : 0;
|
|
8850
8954
|
const handlerErrors = [];
|
|
8851
|
-
let
|
|
8955
|
+
let highestConfirmedUsedIndex = -1;
|
|
8956
|
+
let truncatedAt;
|
|
8852
8957
|
let unused = 0;
|
|
8853
8958
|
let i = 0;
|
|
8854
8959
|
const probeIndex = async (index) => {
|
|
@@ -8875,6 +8980,7 @@ var ContractManager = class _ContractManager {
|
|
|
8875
8980
|
const index = windowIndices[w];
|
|
8876
8981
|
const probes = windowProbes[w];
|
|
8877
8982
|
let hitAtThisIndex = false;
|
|
8983
|
+
let indeterminate = false;
|
|
8878
8984
|
for (let h = 0; h < discoverables.length; h++) {
|
|
8879
8985
|
const probe = probes[h];
|
|
8880
8986
|
if (!probe.ok) {
|
|
@@ -8883,6 +8989,7 @@ var ContractManager = class _ContractManager {
|
|
|
8883
8989
|
index,
|
|
8884
8990
|
error: probe.error
|
|
8885
8991
|
});
|
|
8992
|
+
indeterminate = true;
|
|
8886
8993
|
continue;
|
|
8887
8994
|
}
|
|
8888
8995
|
for (const c of probe.found) {
|
|
@@ -8890,21 +8997,26 @@ var ContractManager = class _ContractManager {
|
|
|
8890
8997
|
hitAtThisIndex = true;
|
|
8891
8998
|
}
|
|
8892
8999
|
}
|
|
8893
|
-
if (
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
}
|
|
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;
|
|
8899
9005
|
}
|
|
9006
|
+
if (truncatedAt !== void 0) break;
|
|
8900
9007
|
i = windowEnd + 1;
|
|
8901
9008
|
}
|
|
8902
|
-
if (opts.hd && i > maxIdx && unused < gapLimit) {
|
|
9009
|
+
if (opts.hd && truncatedAt === void 0 && i > maxIdx && unused < gapLimit) {
|
|
8903
9010
|
throw new Error(
|
|
8904
9011
|
`scanContracts: reached SCAN_MAX_INDEX (${SCAN_MAX_INDEX}) without closing the ${gapLimit}-index gap window; a Discoverable handler may be returning unconditional hits`
|
|
8905
9012
|
);
|
|
8906
9013
|
}
|
|
8907
|
-
return {
|
|
9014
|
+
return {
|
|
9015
|
+
lastIndexUsed: highestConfirmedUsedIndex,
|
|
9016
|
+
highestConfirmedUsedIndex,
|
|
9017
|
+
...truncatedAt !== void 0 && { truncatedAt },
|
|
9018
|
+
handlerErrors
|
|
9019
|
+
};
|
|
8908
9020
|
}
|
|
8909
9021
|
/**
|
|
8910
9022
|
* Get contracts with optional filters.
|
|
@@ -8951,7 +9063,9 @@ var ContractManager = class _ContractManager {
|
|
|
8951
9063
|
byScript.set(contract.script, contract);
|
|
8952
9064
|
}
|
|
8953
9065
|
const tapscriptCache = /* @__PURE__ */ new Map();
|
|
8954
|
-
return vtxos.map(
|
|
9066
|
+
return vtxos.map(
|
|
9067
|
+
(vtxo) => extendVirtualCoinForContract(chunk7TXSPRN5_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
9068
|
+
);
|
|
8955
9069
|
}
|
|
8956
9070
|
buildContractsDbFilter(filter) {
|
|
8957
9071
|
return {
|
|
@@ -9031,7 +9145,7 @@ var ContractManager = class _ContractManager {
|
|
|
9031
9145
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
9032
9146
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9033
9147
|
if (!contract) return [];
|
|
9034
|
-
const handler =
|
|
9148
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
9035
9149
|
if (!handler) return [];
|
|
9036
9150
|
const script = handler.createScript(contract.params);
|
|
9037
9151
|
const context = {
|
|
@@ -9051,7 +9165,7 @@ var ContractManager = class _ContractManager {
|
|
|
9051
9165
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
9052
9166
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9053
9167
|
if (!contract) return [];
|
|
9054
|
-
const handler =
|
|
9168
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
9055
9169
|
if (!handler) return [];
|
|
9056
9170
|
const script = handler.createScript(contract.params);
|
|
9057
9171
|
const context = {
|
|
@@ -9119,7 +9233,7 @@ var ContractManager = class _ContractManager {
|
|
|
9119
9233
|
}
|
|
9120
9234
|
async refreshOutpoints(outpoints) {
|
|
9121
9235
|
if (outpoints.length === 0) return;
|
|
9122
|
-
const { vtxos } = await this.config.indexerProvider
|
|
9236
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9123
9237
|
outpoints
|
|
9124
9238
|
});
|
|
9125
9239
|
if (vtxos.length === 0) return;
|
|
@@ -9247,7 +9361,7 @@ var ContractManager = class _ContractManager {
|
|
|
9247
9361
|
async reconcilePendingFrontier(contracts) {
|
|
9248
9362
|
const scripts = contracts.map((c) => c.script);
|
|
9249
9363
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
9250
|
-
const { vtxos } = await this.config.indexerProvider
|
|
9364
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9251
9365
|
scripts,
|
|
9252
9366
|
pendingOnly: true
|
|
9253
9367
|
});
|
|
@@ -9318,7 +9432,7 @@ var ContractManager = class _ContractManager {
|
|
|
9318
9432
|
}
|
|
9319
9433
|
return result;
|
|
9320
9434
|
}
|
|
9321
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
9435
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunk5XMVTK5S_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9322
9436
|
if (contracts.length === 0) {
|
|
9323
9437
|
return /* @__PURE__ */ new Map();
|
|
9324
9438
|
}
|
|
@@ -9338,7 +9452,7 @@ var ContractManager = class _ContractManager {
|
|
|
9338
9452
|
let pageIndex = 0;
|
|
9339
9453
|
let hasMore = true;
|
|
9340
9454
|
while (hasMore) {
|
|
9341
|
-
const { vtxos, page } = await this.config.indexerProvider
|
|
9455
|
+
const { vtxos, page } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9342
9456
|
scripts,
|
|
9343
9457
|
...windowOpts,
|
|
9344
9458
|
pageIndex,
|
|
@@ -9496,7 +9610,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9496
9610
|
*/
|
|
9497
9611
|
materializeDescriptorAt(index) {
|
|
9498
9612
|
const descriptor = this.identity.descriptor;
|
|
9499
|
-
const network =
|
|
9613
|
+
const network = chunk5XMVTK5S_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9500
9614
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9501
9615
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9502
9616
|
if (!keyInfo?.keyExpression) {
|
|
@@ -9640,7 +9754,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9640
9754
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
9641
9755
|
if (!provider) return void 0;
|
|
9642
9756
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
9643
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
9757
|
+
const expectedContractType = setup.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
9644
9758
|
const factoryOpts = {
|
|
9645
9759
|
walletRepository: setup.walletRepository,
|
|
9646
9760
|
contractRepository: setup.contractRepository,
|
|
@@ -9823,7 +9937,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9823
9937
|
const newAddress = newTapscript.address(wallet.network.hrp, wallet.arkServerPublicKey).encode();
|
|
9824
9938
|
const manager = await wallet.getContractManager();
|
|
9825
9939
|
const csvTimelock = newTapscript.options.csvTimelock;
|
|
9826
|
-
const csvTimelockStr =
|
|
9940
|
+
const csvTimelockStr = chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString();
|
|
9827
9941
|
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
9828
9942
|
const baseParams = {
|
|
9829
9943
|
script: newScript,
|
|
@@ -9837,11 +9951,11 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9837
9951
|
// produce unsigned PSBTs that the server rejects with
|
|
9838
9952
|
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
9839
9953
|
metadata: {
|
|
9840
|
-
source:
|
|
9954
|
+
source: chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE,
|
|
9841
9955
|
signingDescriptor: descriptor
|
|
9842
9956
|
}
|
|
9843
9957
|
};
|
|
9844
|
-
if (newTapscript instanceof
|
|
9958
|
+
if (newTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
9845
9959
|
await manager.createContract({
|
|
9846
9960
|
...baseParams,
|
|
9847
9961
|
type: "delegate",
|
|
@@ -9873,7 +9987,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9873
9987
|
};
|
|
9874
9988
|
function deriveLeafPubkey(descriptor) {
|
|
9875
9989
|
try {
|
|
9876
|
-
return
|
|
9990
|
+
return chunk5XMVTK5S_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
9877
9991
|
} catch (e) {
|
|
9878
9992
|
throw new NonRangeableDescriptorError(
|
|
9879
9993
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -9882,10 +9996,10 @@ function deriveLeafPubkey(descriptor) {
|
|
|
9882
9996
|
}
|
|
9883
9997
|
}
|
|
9884
9998
|
function rebuildTapscript(current, pubKey) {
|
|
9885
|
-
if (current instanceof
|
|
9886
|
-
return new
|
|
9999
|
+
if (current instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
10000
|
+
return new chunk5XMVTK5S_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
9887
10001
|
}
|
|
9888
|
-
return new
|
|
10002
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
9889
10003
|
}
|
|
9890
10004
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
9891
10005
|
const candidates = await contractRepository.getContracts({
|
|
@@ -9894,7 +10008,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
9894
10008
|
});
|
|
9895
10009
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
9896
10010
|
const matching = candidates.filter(
|
|
9897
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10011
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE
|
|
9898
10012
|
).sort((a, b) => {
|
|
9899
10013
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
9900
10014
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10070,12 +10184,12 @@ var InputSignerRouter = class {
|
|
|
10070
10184
|
};
|
|
10071
10185
|
|
|
10072
10186
|
// src/wallet/wallet.ts
|
|
10073
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
10187
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunk7TXSPRN5_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
10074
10188
|
function intentProofJobs(coins) {
|
|
10075
10189
|
if (coins.length === 0) return [];
|
|
10076
10190
|
const coinJobs = coins.map((coin, i) => ({
|
|
10077
10191
|
index: i + 1,
|
|
10078
|
-
lookupScript:
|
|
10192
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
10079
10193
|
}));
|
|
10080
10194
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
10081
10195
|
}
|
|
@@ -10099,7 +10213,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
10099
10213
|
const seen = /* @__PURE__ */ new Set();
|
|
10100
10214
|
const deduped = [];
|
|
10101
10215
|
for (const timelock of timelocks) {
|
|
10102
|
-
const sequence =
|
|
10216
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(timelock).toString();
|
|
10103
10217
|
if (seen.has(sequence)) continue;
|
|
10104
10218
|
seen.add(sequence);
|
|
10105
10219
|
deduped.push(timelock);
|
|
@@ -10116,7 +10230,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10116
10230
|
state: "active"
|
|
10117
10231
|
});
|
|
10118
10232
|
const newest = candidates.filter(
|
|
10119
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10233
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE
|
|
10120
10234
|
).sort((a, b) => {
|
|
10121
10235
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10122
10236
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10124,7 +10238,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10124
10238
|
if (!newest?.params.pubKey) return baseline;
|
|
10125
10239
|
try {
|
|
10126
10240
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
10127
|
-
return new
|
|
10241
|
+
return new chunk5XMVTK5S_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
10128
10242
|
} catch (e) {
|
|
10129
10243
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
10130
10244
|
return baseline;
|
|
@@ -10149,6 +10263,24 @@ async function spendableVtxosExcludingLocked(vtxos, intentRepository) {
|
|
|
10149
10263
|
}
|
|
10150
10264
|
return excludeLockedOutpoints(vtxos, locked);
|
|
10151
10265
|
}
|
|
10266
|
+
var cashReport = (vtxo, reason) => ({
|
|
10267
|
+
txid: vtxo.txid,
|
|
10268
|
+
vout: vtxo.vout,
|
|
10269
|
+
value: vtxo.value,
|
|
10270
|
+
reason
|
|
10271
|
+
});
|
|
10272
|
+
var ArkadeCashCreateError = class extends Error {
|
|
10273
|
+
constructor(cash, cause) {
|
|
10274
|
+
super(
|
|
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.`
|
|
10276
|
+
);
|
|
10277
|
+
this.cash = cash;
|
|
10278
|
+
this.cause = cause;
|
|
10279
|
+
this.name = "ArkadeCashCreateError";
|
|
10280
|
+
}
|
|
10281
|
+
cash;
|
|
10282
|
+
cause;
|
|
10283
|
+
};
|
|
10152
10284
|
var ReadonlyWallet = class _ReadonlyWallet {
|
|
10153
10285
|
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, walletContractTimelocks) {
|
|
10154
10286
|
this.identity = identity;
|
|
@@ -10426,7 +10558,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10426
10558
|
*/
|
|
10427
10559
|
static async setupWalletConfig(config, pubKey) {
|
|
10428
10560
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10429
|
-
const arkProvider = config.arkProvider || new
|
|
10561
|
+
const arkProvider = config.arkProvider || new chunkEB3ALGTM_cjs.RestArkProvider(arkadeServerUrl);
|
|
10430
10562
|
let indexerProvider = config.indexerProvider;
|
|
10431
10563
|
if (!indexerProvider) {
|
|
10432
10564
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10443,7 +10575,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10443
10575
|
indexerUrl = arkadeServerUrl;
|
|
10444
10576
|
}
|
|
10445
10577
|
}
|
|
10446
|
-
indexerProvider = new
|
|
10578
|
+
indexerProvider = new chunkEB3ALGTM_cjs.RestIndexerProvider(indexerUrl);
|
|
10447
10579
|
}
|
|
10448
10580
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10449
10581
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10452,7 +10584,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10452
10584
|
source: serverInfoSource,
|
|
10453
10585
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
10454
10586
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
10455
|
-
const network =
|
|
10587
|
+
const network = chunk7TXSPRN5_cjs.getNetwork(info.network);
|
|
10456
10588
|
if ("descriptor" in config.identity) {
|
|
10457
10589
|
const descriptor = config.identity.descriptor;
|
|
10458
10590
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -10499,11 +10631,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10499
10631
|
serverPubKey,
|
|
10500
10632
|
csvTimelock: exitTimelock
|
|
10501
10633
|
};
|
|
10502
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10503
|
-
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({
|
|
10504
10636
|
pubKey: base.hex.encode(pubKey),
|
|
10505
10637
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10506
|
-
csvTimelock:
|
|
10638
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingTimelock).toString()
|
|
10507
10639
|
});
|
|
10508
10640
|
return {
|
|
10509
10641
|
arkProvider,
|
|
@@ -10607,20 +10739,21 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10607
10739
|
}
|
|
10608
10740
|
let recoverable = 0;
|
|
10609
10741
|
let pendingRecovery = 0;
|
|
10610
|
-
const
|
|
10611
|
-
const
|
|
10612
|
-
(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)
|
|
10613
10745
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
10614
|
-
const
|
|
10615
|
-
(coin) => (coin
|
|
10746
|
+
const preconfirmed = vtxos.filter(
|
|
10747
|
+
(coin) => chunk7TXSPRN5_cjs.canSpendOffchain(coin, now) && coin.isPreconfirmed && !isPendingRecovery(coin)
|
|
10616
10748
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
10617
|
-
|
|
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);
|
|
10618
10751
|
pendingRecovery = vtxos.filter(isPendingRecovery).reduce((sum, coin) => sum + coin.value, 0);
|
|
10619
10752
|
const totalBoarding = confirmed + unconfirmed;
|
|
10620
10753
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
10621
10754
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
10622
10755
|
for (const vtxo of vtxos) {
|
|
10623
|
-
if (
|
|
10756
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
10624
10757
|
if (vtxo.assets) {
|
|
10625
10758
|
for (const a of vtxo.assets) {
|
|
10626
10759
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -10656,12 +10789,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10656
10789
|
const f = filter ?? { withRecoverable: true, withUnrolled: false };
|
|
10657
10790
|
const contractManager = await this.getContractManager();
|
|
10658
10791
|
const vtxos = await contractManager.getContractsWithVtxos();
|
|
10792
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
10659
10793
|
return vtxos.flatMap((_) => _.vtxos).filter((vtxo) => {
|
|
10660
10794
|
if (this._pendingSpendOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
10661
10795
|
return false;
|
|
10662
10796
|
}
|
|
10663
|
-
if (
|
|
10664
|
-
if (!f.withRecoverable && (
|
|
10797
|
+
if (!chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) {
|
|
10798
|
+
if (!f.withRecoverable && chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
10665
10799
|
return false;
|
|
10666
10800
|
}
|
|
10667
10801
|
return true;
|
|
@@ -10694,7 +10828,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10694
10828
|
const response = await contractManager.getContractsWithVtxos();
|
|
10695
10829
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
10696
10830
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
10697
|
-
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) => {
|
|
10698
10832
|
if (isRetryableProviderError(err)) return void 0;
|
|
10699
10833
|
throw err;
|
|
10700
10834
|
});
|
|
@@ -10770,6 +10904,12 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10770
10904
|
if (spent && commitmentTxid) {
|
|
10771
10905
|
commitmentsToIgnore.add(commitmentTxid);
|
|
10772
10906
|
}
|
|
10907
|
+
const boardingFacts = {
|
|
10908
|
+
isSpent: spent,
|
|
10909
|
+
isSwept: false,
|
|
10910
|
+
isPreconfirmed: false,
|
|
10911
|
+
commitmentTxIds: spent && commitmentTxid ? [commitmentTxid] : []
|
|
10912
|
+
};
|
|
10773
10913
|
utxos.push({
|
|
10774
10914
|
txid: tx.txid,
|
|
10775
10915
|
vout: i,
|
|
@@ -10779,10 +10919,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10779
10919
|
block_time: tx.status.block_time
|
|
10780
10920
|
},
|
|
10781
10921
|
isUnrolled: true,
|
|
10782
|
-
|
|
10783
|
-
|
|
10784
|
-
|
|
10785
|
-
},
|
|
10922
|
+
...boardingFacts,
|
|
10923
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(boardingFacts),
|
|
10924
|
+
spentBy: "",
|
|
10786
10925
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
10787
10926
|
script: scriptHex
|
|
10788
10927
|
});
|
|
@@ -10796,12 +10935,12 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10796
10935
|
const tx = {
|
|
10797
10936
|
key: {
|
|
10798
10937
|
boardingTxid: utxo.txid,
|
|
10799
|
-
commitmentTxid: utxo.
|
|
10938
|
+
commitmentTxid: utxo.commitmentTxIds[0] ?? "",
|
|
10800
10939
|
arkTxid: ""
|
|
10801
10940
|
},
|
|
10802
10941
|
amount: utxo.value,
|
|
10803
10942
|
type: "RECEIVED" /* TxReceived */,
|
|
10804
|
-
settled: utxo.
|
|
10943
|
+
settled: utxo.isSpent,
|
|
10805
10944
|
createdAt: utxo.status.block_time ? new Date(utxo.status.block_time * 1e3).getTime() : 0
|
|
10806
10945
|
};
|
|
10807
10946
|
if (!utxo.status.block_time) {
|
|
@@ -10837,9 +10976,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10837
10976
|
async getBoardingTapscripts(allowedSigners) {
|
|
10838
10977
|
const byScript = /* @__PURE__ */ new Map();
|
|
10839
10978
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
10840
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
10979
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
10841
10980
|
add(
|
|
10842
|
-
new
|
|
10981
|
+
new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
10843
10982
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
10844
10983
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
10845
10984
|
csvTimelock: boardingCsv
|
|
@@ -10854,7 +10993,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10854
10993
|
for (const c of boardingContracts) {
|
|
10855
10994
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
10856
10995
|
try {
|
|
10857
|
-
add(
|
|
10996
|
+
add(chunk5XMVTK5S_cjs.BoardingContractHandler.createScript(c.params));
|
|
10858
10997
|
} catch (e) {
|
|
10859
10998
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
10860
10999
|
}
|
|
@@ -10892,7 +11031,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10892
11031
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
10893
11032
|
// not the wallet's current boarding timelock, which a signer
|
|
10894
11033
|
// rotation may have changed.
|
|
10895
|
-
csvTimelock:
|
|
11034
|
+
csvTimelock: chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
10896
11035
|
coins: utxos
|
|
10897
11036
|
});
|
|
10898
11037
|
}
|
|
@@ -11025,11 +11164,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11025
11164
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
11026
11165
|
async fetchPendingTxs() {
|
|
11027
11166
|
const scripts = await this.getWalletScripts();
|
|
11028
|
-
let { vtxos } = await this.indexerProvider
|
|
11167
|
+
let { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
11029
11168
|
scripts
|
|
11030
11169
|
});
|
|
11031
11170
|
return vtxos.filter(
|
|
11032
|
-
(vtxo) => vtxo.
|
|
11171
|
+
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
11033
11172
|
).map((_) => _.arkTxId);
|
|
11034
11173
|
}
|
|
11035
11174
|
// ========================================================================
|
|
@@ -11058,7 +11197,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11058
11197
|
});
|
|
11059
11198
|
for (const contract of contracts) {
|
|
11060
11199
|
if (map.has(contract.script)) continue;
|
|
11061
|
-
const handler =
|
|
11200
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
11062
11201
|
if (handler) {
|
|
11063
11202
|
const script = handler.createScript(contract.params);
|
|
11064
11203
|
map.set(contract.script, script);
|
|
@@ -11128,7 +11267,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11128
11267
|
});
|
|
11129
11268
|
onVtxosPersisted = async (_contract, vtxos) => {
|
|
11130
11269
|
for (const v of vtxos) {
|
|
11131
|
-
if (v.
|
|
11270
|
+
if (v.isSpent) continue;
|
|
11132
11271
|
await captureExitBranch({
|
|
11133
11272
|
resolver,
|
|
11134
11273
|
repository: virtualTxRepository,
|
|
@@ -11152,7 +11291,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11152
11291
|
watcherConfig: this.watcherConfig
|
|
11153
11292
|
});
|
|
11154
11293
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
11155
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11294
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11156
11295
|
const baselineSigners = [
|
|
11157
11296
|
this.offchainTapscript.options.serverPubKey,
|
|
11158
11297
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -11160,8 +11299,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11160
11299
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
11161
11300
|
for (const serverPubKey of baselineSigners) {
|
|
11162
11301
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
11163
|
-
const csvTimelockStr =
|
|
11164
|
-
const defaultScript = new
|
|
11302
|
+
const csvTimelockStr = chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString();
|
|
11303
|
+
const defaultScript = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11165
11304
|
pubKey: baselinePubkey,
|
|
11166
11305
|
serverPubKey,
|
|
11167
11306
|
csvTimelock
|
|
@@ -11182,7 +11321,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11182
11321
|
});
|
|
11183
11322
|
}
|
|
11184
11323
|
if (delegatePubKey) {
|
|
11185
|
-
const delegateScript = new
|
|
11324
|
+
const delegateScript = new chunk5XMVTK5S_cjs.DelegateVtxo.Script({
|
|
11186
11325
|
pubKey: baselinePubkey,
|
|
11187
11326
|
serverPubKey,
|
|
11188
11327
|
delegatePubKey,
|
|
@@ -11206,9 +11345,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11206
11345
|
}
|
|
11207
11346
|
}
|
|
11208
11347
|
}
|
|
11209
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11348
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11210
11349
|
for (const serverPubKey of baselineSigners) {
|
|
11211
|
-
const baselineBoarding = new
|
|
11350
|
+
const baselineBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11212
11351
|
pubKey: baselinePubkey,
|
|
11213
11352
|
serverPubKey,
|
|
11214
11353
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11221,7 +11360,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11221
11360
|
params: {
|
|
11222
11361
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
11223
11362
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
11224
|
-
csvTimelock:
|
|
11363
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
11225
11364
|
},
|
|
11226
11365
|
script: boardingScriptHex,
|
|
11227
11366
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -11444,25 +11583,25 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11444
11583
|
return this.getBoardingAddress();
|
|
11445
11584
|
}
|
|
11446
11585
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11447
|
-
const pubKey =
|
|
11448
|
-
const newBoarding = new
|
|
11586
|
+
const pubKey = chunk5XMVTK5S_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11587
|
+
const newBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11449
11588
|
...this._boardingTapscript.options,
|
|
11450
11589
|
pubKey
|
|
11451
11590
|
});
|
|
11452
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11591
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11453
11592
|
const manager = await this.getContractManager();
|
|
11454
11593
|
await manager.createContract({
|
|
11455
11594
|
type: "boarding",
|
|
11456
11595
|
params: {
|
|
11457
11596
|
pubKey: base.hex.encode(pubKey),
|
|
11458
11597
|
serverPubKey: base.hex.encode(newBoarding.options.serverPubKey),
|
|
11459
|
-
csvTimelock:
|
|
11598
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(csvTimelock).toString()
|
|
11460
11599
|
},
|
|
11461
11600
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11462
11601
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11463
11602
|
state: "active",
|
|
11464
11603
|
metadata: {
|
|
11465
|
-
source:
|
|
11604
|
+
source: chunk5XMVTK5S_cjs.WALLET_RECEIVE_SOURCE,
|
|
11466
11605
|
signingDescriptor: descriptor
|
|
11467
11606
|
}
|
|
11468
11607
|
});
|
|
@@ -11501,7 +11640,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11501
11640
|
const xonly = toXOnlyPubKey(newServerPubKey);
|
|
11502
11641
|
let newServerUnrollScript;
|
|
11503
11642
|
try {
|
|
11504
|
-
newServerUnrollScript =
|
|
11643
|
+
newServerUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
11505
11644
|
} catch (e) {
|
|
11506
11645
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11507
11646
|
}
|
|
@@ -11529,21 +11668,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11529
11668
|
const [currentBoardingRow] = await manager.getContracts({
|
|
11530
11669
|
script: currentBoardingScript
|
|
11531
11670
|
});
|
|
11532
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
11671
|
+
const newOffchain = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? new chunk5XMVTK5S_cjs.DelegateVtxo.Script({
|
|
11533
11672
|
...this.offchainTapscript.options,
|
|
11534
11673
|
serverPubKey: xonly
|
|
11535
|
-
}) : new
|
|
11674
|
+
}) : new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11536
11675
|
...this.offchainTapscript.options,
|
|
11537
11676
|
serverPubKey: xonly
|
|
11538
11677
|
});
|
|
11539
|
-
const newBoarding = new
|
|
11678
|
+
const newBoarding = new chunk5XMVTK5S_cjs.DefaultVtxo.Script({
|
|
11540
11679
|
...this._boardingTapscript.options,
|
|
11541
11680
|
serverPubKey: xonly
|
|
11542
11681
|
});
|
|
11543
|
-
const offchainCsv =
|
|
11682
|
+
const offchainCsv = chunk7TXSPRN5_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
11544
11683
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
11545
11684
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
11546
|
-
if (newOffchain instanceof
|
|
11685
|
+
if (newOffchain instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script) {
|
|
11547
11686
|
await manager.createContract({
|
|
11548
11687
|
type: "delegate",
|
|
11549
11688
|
params: {
|
|
@@ -11571,13 +11710,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11571
11710
|
metadata: currentOffchainRow?.metadata
|
|
11572
11711
|
});
|
|
11573
11712
|
}
|
|
11574
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
11713
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11575
11714
|
await manager.createContract({
|
|
11576
11715
|
type: "boarding",
|
|
11577
11716
|
params: {
|
|
11578
11717
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
11579
11718
|
serverPubKey: base.hex.encode(xonly),
|
|
11580
|
-
csvTimelock:
|
|
11719
|
+
csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(boardingCsv).toString()
|
|
11581
11720
|
},
|
|
11582
11721
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11583
11722
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -11605,14 +11744,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11605
11744
|
_restoreInFlight;
|
|
11606
11745
|
_addPendingSpends(inputs) {
|
|
11607
11746
|
for (const input of inputs) {
|
|
11608
|
-
if (
|
|
11747
|
+
if (chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
11609
11748
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
11610
11749
|
}
|
|
11611
11750
|
}
|
|
11612
11751
|
}
|
|
11613
11752
|
_removePendingSpends(inputs) {
|
|
11614
11753
|
for (const input of inputs) {
|
|
11615
|
-
if (
|
|
11754
|
+
if (chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
11616
11755
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
11617
11756
|
}
|
|
11618
11757
|
}
|
|
@@ -11672,7 +11811,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11672
11811
|
const hd = provider instanceof HDDescriptorProvider;
|
|
11673
11812
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
11674
11813
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
11675
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11814
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk5XMVTK5S_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11676
11815
|
const arkInfo = await this.arkProvider.getInfo();
|
|
11677
11816
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
11678
11817
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -11691,7 +11830,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11691
11830
|
csvTimelocks: this.walletContractTimelocks,
|
|
11692
11831
|
// Boarding-exit CSV so the boarding handler can build its
|
|
11693
11832
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
11694
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
11833
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunk5XMVTK5S_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
11695
11834
|
delegatePubKey
|
|
11696
11835
|
};
|
|
11697
11836
|
const result = await manager.scanContracts({
|
|
@@ -11700,15 +11839,22 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11700
11839
|
materialize,
|
|
11701
11840
|
deps
|
|
11702
11841
|
});
|
|
11703
|
-
if (hd && result.
|
|
11704
|
-
await provider.advanceLastIndexUsed(result.
|
|
11842
|
+
if (hd && result.highestConfirmedUsedIndex >= 0) {
|
|
11843
|
+
await provider.advanceLastIndexUsed(result.highestConfirmedUsedIndex);
|
|
11705
11844
|
}
|
|
11706
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
|
+
}
|
|
11707
11855
|
if (result.handlerErrors.length > 0) {
|
|
11708
11856
|
throw new AggregateError(
|
|
11709
|
-
|
|
11710
|
-
(e) => e.error instanceof Error ? e.error : new Error(String(e.error))
|
|
11711
|
-
),
|
|
11857
|
+
causes,
|
|
11712
11858
|
`restore: ${result.handlerErrors.length} discovery handler(s) failed; the gap window may have closed early \u2014 retry is safe (idempotent).`
|
|
11713
11859
|
);
|
|
11714
11860
|
}
|
|
@@ -11795,7 +11941,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11795
11941
|
let serverUnrollScript;
|
|
11796
11942
|
try {
|
|
11797
11943
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
11798
|
-
serverUnrollScript =
|
|
11944
|
+
serverUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(raw);
|
|
11799
11945
|
} catch (e) {
|
|
11800
11946
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11801
11947
|
}
|
|
@@ -11932,7 +12078,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11932
12078
|
inputs: params.selectedVtxos,
|
|
11933
12079
|
changeAmount: BigInt(changeAmount)
|
|
11934
12080
|
};
|
|
11935
|
-
const outputAddress =
|
|
12081
|
+
const outputAddress = chunk7TXSPRN5_cjs.ArkAddress.decode(params.address);
|
|
11936
12082
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
11937
12083
|
const outputs = [
|
|
11938
12084
|
{
|
|
@@ -11985,13 +12131,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11985
12131
|
}
|
|
11986
12132
|
}
|
|
11987
12133
|
const offchainAddress = await this.getAddress();
|
|
11988
|
-
const offchainPkScript =
|
|
12134
|
+
const offchainPkScript = chunk7TXSPRN5_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
11989
12135
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
11990
12136
|
if (!params) {
|
|
11991
12137
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
11992
12138
|
const estimator = new Estimator(fees.intentFee);
|
|
11993
12139
|
let amount = 0;
|
|
11994
|
-
const exitScript =
|
|
12140
|
+
const exitScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
11995
12141
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
11996
12142
|
);
|
|
11997
12143
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -12020,13 +12166,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12020
12166
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
12021
12167
|
break;
|
|
12022
12168
|
}
|
|
12023
|
-
const inputFee = estimator.evalOffchainInput(
|
|
12024
|
-
amount: BigInt(vtxo.value),
|
|
12025
|
-
type: vtxo.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
12026
|
-
weight: 0,
|
|
12027
|
-
birth: vtxo.createdAt,
|
|
12028
|
-
expiry: vtxo.virtualStatus.batchExpiry ? new Date(vtxo.virtualStatus.batchExpiry) : void 0
|
|
12029
|
-
});
|
|
12169
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(vtxo));
|
|
12030
12170
|
if (inputFee.satoshis >= vtxo.value) {
|
|
12031
12171
|
continue;
|
|
12032
12172
|
}
|
|
@@ -12071,7 +12211,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12071
12211
|
for (const [index, output] of params.outputs.entries()) {
|
|
12072
12212
|
let script;
|
|
12073
12213
|
try {
|
|
12074
|
-
const addr =
|
|
12214
|
+
const addr = chunk7TXSPRN5_cjs.ArkAddress.decode(output.address);
|
|
12075
12215
|
script = addr.pkScript;
|
|
12076
12216
|
hasOffchainOutputs = true;
|
|
12077
12217
|
} catch {
|
|
@@ -12242,9 +12382,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12242
12382
|
* renewal / offboard) is not a board and leaves the boarding address
|
|
12243
12383
|
* untouched.
|
|
12244
12384
|
*
|
|
12245
|
-
* Boarding inputs are the non-VTXO coins (no `
|
|
12385
|
+
* Boarding inputs are the non-VTXO coins (no `script`), the same
|
|
12246
12386
|
* discriminator {@link handleSettlementFinalizationEvent} uses; the
|
|
12247
|
-
* `typeof` guard skips arknote
|
|
12387
|
+
* `typeof` guard skips the arknote strings settle also accepts.
|
|
12248
12388
|
*
|
|
12249
12389
|
* No-ops for static / `auto` wallets (no descriptor provider — boarding
|
|
12250
12390
|
* stays on its fixed index-0 address). Best-effort and non-fatal: the
|
|
@@ -12257,7 +12397,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12257
12397
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
12258
12398
|
if (!this._descriptorProvider) return;
|
|
12259
12399
|
const consumedBoarding = inputs.some(
|
|
12260
|
-
(input) => typeof input !== "string" && !(
|
|
12400
|
+
(input) => typeof input !== "string" && !chunk7TXSPRN5_cjs.isVirtualCoin(input)
|
|
12261
12401
|
);
|
|
12262
12402
|
if (!consumedBoarding) return;
|
|
12263
12403
|
try {
|
|
@@ -12268,13 +12408,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12268
12408
|
}
|
|
12269
12409
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
|
|
12270
12410
|
const signedForfeits = [];
|
|
12271
|
-
const isVtxo = (input) => "virtualStatus" in input;
|
|
12272
12411
|
let settlementPsbt = btcSigner.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
12273
12412
|
let hasBoardingUtxos = false;
|
|
12274
12413
|
let connectorIndex = 0;
|
|
12275
12414
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
12276
12415
|
for (const input of inputs) {
|
|
12277
|
-
if (!
|
|
12416
|
+
if (!chunk7TXSPRN5_cjs.isVirtualCoin(input)) {
|
|
12278
12417
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
12279
12418
|
const settlementInput = settlementPsbt.getInput(i);
|
|
12280
12419
|
if (!settlementInput.txid || settlementInput.index === void 0) {
|
|
@@ -12305,7 +12444,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12305
12444
|
}
|
|
12306
12445
|
continue;
|
|
12307
12446
|
}
|
|
12308
|
-
if (
|
|
12447
|
+
if (chunk7TXSPRN5_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
12309
12448
|
continue;
|
|
12310
12449
|
}
|
|
12311
12450
|
if (connectorsLeaves.length === 0) {
|
|
@@ -12333,7 +12472,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12333
12472
|
index: input.vout,
|
|
12334
12473
|
witnessUtxo: {
|
|
12335
12474
|
amount: BigInt(input.value),
|
|
12336
|
-
script:
|
|
12475
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12337
12476
|
},
|
|
12338
12477
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
12339
12478
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -12352,7 +12491,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12352
12491
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
12353
12492
|
{
|
|
12354
12493
|
index: 0,
|
|
12355
|
-
lookupScript:
|
|
12494
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12356
12495
|
}
|
|
12357
12496
|
]);
|
|
12358
12497
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -12410,7 +12549,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12410
12549
|
if (skip) {
|
|
12411
12550
|
return { skip };
|
|
12412
12551
|
}
|
|
12413
|
-
const sweepTapscript =
|
|
12552
|
+
const sweepTapscript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
|
|
12414
12553
|
timelock: {
|
|
12415
12554
|
value: event.batchExpiry,
|
|
12416
12555
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -12516,9 +12655,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12516
12655
|
...existing ?? {},
|
|
12517
12656
|
intentTxId,
|
|
12518
12657
|
registerProof: intent.proof,
|
|
12519
|
-
registerProofMessage:
|
|
12658
|
+
registerProofMessage: chunkEB3ALGTM_cjs.Intent.encodeMessage(intent.message),
|
|
12520
12659
|
deleteProof: deleteIntent.proof,
|
|
12521
|
-
deleteProofMessage:
|
|
12660
|
+
deleteProofMessage: chunkEB3ALGTM_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
12522
12661
|
intentVtxos: inputs.map((i) => ({
|
|
12523
12662
|
txid: i.txid,
|
|
12524
12663
|
vout: i.vout
|
|
@@ -12550,7 +12689,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12550
12689
|
try {
|
|
12551
12690
|
return await this.arkProvider.registerIntent(intent);
|
|
12552
12691
|
} catch (error) {
|
|
12553
|
-
if (error instanceof
|
|
12692
|
+
if (error instanceof chunkEB3ALGTM_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
12554
12693
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
12555
12694
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
12556
12695
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -12566,7 +12705,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12566
12705
|
expire_at: 0,
|
|
12567
12706
|
cosigners_public_keys: cosignerPubKeys
|
|
12568
12707
|
};
|
|
12569
|
-
const proof =
|
|
12708
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, outputs);
|
|
12570
12709
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12571
12710
|
return {
|
|
12572
12711
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12578,7 +12717,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12578
12717
|
type: "delete",
|
|
12579
12718
|
expire_at: 0
|
|
12580
12719
|
};
|
|
12581
|
-
const proof =
|
|
12720
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, []);
|
|
12582
12721
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12583
12722
|
return {
|
|
12584
12723
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12590,7 +12729,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12590
12729
|
type: "get-pending-tx",
|
|
12591
12730
|
expire_at: 0
|
|
12592
12731
|
};
|
|
12593
|
-
const proof =
|
|
12732
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, coins, []);
|
|
12594
12733
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12595
12734
|
return {
|
|
12596
12735
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12608,18 +12747,17 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12608
12747
|
if (!hasPending) {
|
|
12609
12748
|
return { finalized: [], pending: [] };
|
|
12610
12749
|
}
|
|
12611
|
-
const MAX_INPUTS_PER_INTENT = 20;
|
|
12612
12750
|
if (!vtxos || vtxos.length === 0) {
|
|
12613
12751
|
const scriptMap = await this.getScriptMap();
|
|
12614
12752
|
const allExtended = [];
|
|
12615
12753
|
const allScripts = [...scriptMap.keys()];
|
|
12616
|
-
const { vtxos: fetchedVtxos } = await this.indexerProvider
|
|
12754
|
+
const { vtxos: fetchedVtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
12617
12755
|
scripts: allScripts
|
|
12618
12756
|
});
|
|
12619
12757
|
for (const vtxo of fetchedVtxos) {
|
|
12620
12758
|
const vtxoScript = scriptMap.get(vtxo.script);
|
|
12621
12759
|
if (!vtxoScript) continue;
|
|
12622
|
-
if (vtxo.
|
|
12760
|
+
if (!vtxo.isSpent && !(vtxo.isPreconfirmed && !vtxo.isSwept)) {
|
|
12623
12761
|
continue;
|
|
12624
12762
|
}
|
|
12625
12763
|
allExtended.push({
|
|
@@ -12718,6 +12856,271 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12718
12856
|
settings: { ...state.settings, hasPendingTx: value }
|
|
12719
12857
|
}));
|
|
12720
12858
|
}
|
|
12859
|
+
/**
|
|
12860
|
+
* Create an ArkadeCash bearer instrument.
|
|
12861
|
+
*
|
|
12862
|
+
* Generates a fresh keypair, sends the specified amount to a DefaultVtxo
|
|
12863
|
+
* controlled by the new key, and returns the encoded arkadeCash string.
|
|
12864
|
+
* The receiver can claim the funds using `claimCash()` without ever
|
|
12865
|
+
* sharing their address.
|
|
12866
|
+
*
|
|
12867
|
+
* ArkadeCash is a short-lived instrument: it carries a private key, so it is
|
|
12868
|
+
* meant to be handed over and claimed promptly, not held. A note left
|
|
12869
|
+
* unclaimed past its batch expiry is swept by the server and `claimCash`
|
|
12870
|
+
* can only report it, not move it.
|
|
12871
|
+
*
|
|
12872
|
+
* @param amount - Amount in satoshis to send. Must be a whole number of
|
|
12873
|
+
* sats at or above the dust threshold — a below-dust amount would mint an
|
|
12874
|
+
* OP_RETURN output that is unspendable as cash.
|
|
12875
|
+
* @returns The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
12876
|
+
*/
|
|
12877
|
+
async createCash(amount) {
|
|
12878
|
+
if (!Number.isSafeInteger(amount) || amount < Number(this.dustAmount)) {
|
|
12879
|
+
throw new Error(
|
|
12880
|
+
`Invalid ArkadeCash amount ${amount}: must be a whole number of sats >= dust (${this.dustAmount})`
|
|
12881
|
+
);
|
|
12882
|
+
}
|
|
12883
|
+
const cashHrp = this.network.hrp.replace(/ark$/, "arkadecash");
|
|
12884
|
+
const cash = ArkadeCash.generate(
|
|
12885
|
+
this.arkServerPublicKey,
|
|
12886
|
+
this.offchainTapscript.options.csvTimelock,
|
|
12887
|
+
cashHrp
|
|
12888
|
+
);
|
|
12889
|
+
const address = cash.address(this.network.hrp).encode();
|
|
12890
|
+
const cashStr = cash.toString();
|
|
12891
|
+
try {
|
|
12892
|
+
await this.send({ address, amount });
|
|
12893
|
+
} catch (error) {
|
|
12894
|
+
throw new ArkadeCashCreateError(cashStr, error);
|
|
12895
|
+
}
|
|
12896
|
+
return cashStr;
|
|
12897
|
+
}
|
|
12898
|
+
/**
|
|
12899
|
+
* Claim an ArkadeCash bearer instrument: sweep what can be swept, report the
|
|
12900
|
+
* rest.
|
|
12901
|
+
*
|
|
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
|
|
12904
|
+
* string. Nothing is ever persisted: no contract is imported, and the
|
|
12905
|
+
* arkadeCash key is not stored. Anything that cannot be swept — server-swept,
|
|
12906
|
+
* subdust, already claimed, or asset-bearing — is returned in `unclaimed`
|
|
12907
|
+
* with a per-VTXO reason and otherwise ignored.
|
|
12908
|
+
*
|
|
12909
|
+
* The arkadeCash string is the recovery token: a claim interrupted between
|
|
12910
|
+
* submit and finalize is completed by simply re-running `claimCash`, which
|
|
12911
|
+
* drains any pending arkadeCash transaction on the server before sweeping.
|
|
12912
|
+
*
|
|
12913
|
+
* @param cashStr - The encoded arkadeCash string (e.g., "arkadecash1...")
|
|
12914
|
+
* @returns The swept total and the report of what was left behind. The
|
|
12915
|
+
* shape is open: further buckets may be added alongside `unclaimed`.
|
|
12916
|
+
*/
|
|
12917
|
+
async claimCash(cashStr) {
|
|
12918
|
+
const cash = ArkadeCash.fromString(cashStr);
|
|
12919
|
+
const cashScript = cash.vtxoScript;
|
|
12920
|
+
const cashPkScript = base.hex.encode(cashScript.pkScript);
|
|
12921
|
+
const scripts = [cashPkScript];
|
|
12922
|
+
let vtxos = await this.fetchAllVtxos(scripts);
|
|
12923
|
+
if (vtxos.length === 0) {
|
|
12924
|
+
throw new Error("No VTXOs found for this arkadeCash");
|
|
12925
|
+
}
|
|
12926
|
+
const myPkScript = chunk7TXSPRN5_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
12927
|
+
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
12928
|
+
let swept = 0;
|
|
12929
|
+
const drainable = vtxos.filter((vtxo) => !isSubdust(vtxo, this.dustAmount));
|
|
12930
|
+
if (drainable.length > 0) {
|
|
12931
|
+
let drained = { count: 0, swept: 0, claimed: /* @__PURE__ */ new Set() };
|
|
12932
|
+
try {
|
|
12933
|
+
drained = await this.finalizePendingCashTxs(
|
|
12934
|
+
cash,
|
|
12935
|
+
drainable,
|
|
12936
|
+
cashScript,
|
|
12937
|
+
myPkScript
|
|
12938
|
+
);
|
|
12939
|
+
} catch (error) {
|
|
12940
|
+
console.error("Failed to drain pending arkadeCash txs:", error);
|
|
12941
|
+
}
|
|
12942
|
+
if (drained.count > 0) {
|
|
12943
|
+
vtxos = await this.fetchAllVtxos(scripts);
|
|
12944
|
+
({ spendable, unclaimed } = this.classifyCashVtxos(vtxos));
|
|
12945
|
+
swept += drained.swept;
|
|
12946
|
+
unclaimed = unclaimed.filter(
|
|
12947
|
+
(vtxo) => !drained.claimed.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
12948
|
+
);
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
12951
|
+
if (spendable.length > 0) {
|
|
12952
|
+
const info = await this.arkProvider.getInfo();
|
|
12953
|
+
const serverUnrollScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(
|
|
12954
|
+
base.hex.decode(info.checkpointTapscript)
|
|
12955
|
+
);
|
|
12956
|
+
for (const vtxo of spendable) {
|
|
12957
|
+
try {
|
|
12958
|
+
await signAndSubmitOffchainTx({
|
|
12959
|
+
identity: cash.identity,
|
|
12960
|
+
provider: this.arkProvider,
|
|
12961
|
+
inputs: [
|
|
12962
|
+
{
|
|
12963
|
+
txid: vtxo.txid,
|
|
12964
|
+
vout: vtxo.vout,
|
|
12965
|
+
value: vtxo.value,
|
|
12966
|
+
tapLeafScript: cashScript.forfeit(),
|
|
12967
|
+
tapTree: cashScript.encode()
|
|
12968
|
+
}
|
|
12969
|
+
],
|
|
12970
|
+
outputs: [{ script: myPkScript, amount: BigInt(vtxo.value) }],
|
|
12971
|
+
serverUnrollScript
|
|
12972
|
+
});
|
|
12973
|
+
swept += vtxo.value;
|
|
12974
|
+
} catch (error) {
|
|
12975
|
+
console.error(
|
|
12976
|
+
`Failed to sweep arkadeCash VTXO ${vtxo.txid}:${vtxo.vout}:`,
|
|
12977
|
+
error
|
|
12978
|
+
);
|
|
12979
|
+
unclaimed.push(cashReport(vtxo, "sweep-failed"));
|
|
12980
|
+
}
|
|
12981
|
+
}
|
|
12982
|
+
}
|
|
12983
|
+
return {
|
|
12984
|
+
swept,
|
|
12985
|
+
unclaimed: {
|
|
12986
|
+
amount: unclaimed.reduce((total, vtxo) => total + vtxo.value, 0),
|
|
12987
|
+
vtxos: unclaimed
|
|
12988
|
+
}
|
|
12989
|
+
};
|
|
12990
|
+
}
|
|
12991
|
+
/**
|
|
12992
|
+
* Split the VTXOs at an arkadeCash address into the ones the thin sweep can
|
|
12993
|
+
* move and the ones it can only report.
|
|
12994
|
+
*/
|
|
12995
|
+
classifyCashVtxos(vtxos) {
|
|
12996
|
+
const spendable = [];
|
|
12997
|
+
const unclaimed = [];
|
|
12998
|
+
for (const vtxo of vtxos) {
|
|
12999
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) {
|
|
13000
|
+
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
13001
|
+
} else if (isSubdust(vtxo, this.dustAmount)) {
|
|
13002
|
+
unclaimed.push(cashReport(vtxo, "subdust"));
|
|
13003
|
+
} else if (vtxo.isSwept) {
|
|
13004
|
+
unclaimed.push(cashReport(vtxo, "swept"));
|
|
13005
|
+
} else if (vtxo.assets && vtxo.assets.length > 0) {
|
|
13006
|
+
unclaimed.push(cashReport(vtxo, "has-assets"));
|
|
13007
|
+
} else {
|
|
13008
|
+
spendable.push(vtxo);
|
|
13009
|
+
}
|
|
13010
|
+
}
|
|
13011
|
+
return { spendable, unclaimed };
|
|
13012
|
+
}
|
|
13013
|
+
/** Read every page of an unfiltered VTXO query for the given scripts. */
|
|
13014
|
+
async fetchAllVtxos(scripts) {
|
|
13015
|
+
const pageSize = 100;
|
|
13016
|
+
const all = [];
|
|
13017
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13018
|
+
for (let pageIndex = 0; ; pageIndex++) {
|
|
13019
|
+
const { vtxos, page } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
13020
|
+
scripts,
|
|
13021
|
+
pageIndex,
|
|
13022
|
+
pageSize
|
|
13023
|
+
});
|
|
13024
|
+
for (const vtxo of vtxos) {
|
|
13025
|
+
const outpoint = `${vtxo.txid}:${vtxo.vout}`;
|
|
13026
|
+
if (seen.has(outpoint)) continue;
|
|
13027
|
+
seen.add(outpoint);
|
|
13028
|
+
all.push(vtxo);
|
|
13029
|
+
}
|
|
13030
|
+
if (!page || vtxos.length < pageSize) return all;
|
|
13031
|
+
}
|
|
13032
|
+
}
|
|
13033
|
+
/**
|
|
13034
|
+
* Complete any sweep a previous `claimCash` registered but never finalized.
|
|
13035
|
+
* A thin variant of {@link finalizePendingTxs}, scoped to the arkadeCash key:
|
|
13036
|
+
* the intent is signed with it, and so are the returned checkpoints.
|
|
13037
|
+
*
|
|
13038
|
+
* A drained sweep is not automatically *ours*. Whoever registered it chose
|
|
13039
|
+
* the destination, so a tx a different claimer left half-finished pays that
|
|
13040
|
+
* claimer — finalizing it is still right (the input is spent either way, and
|
|
13041
|
+
* completing it unsticks the funds), but only the value it actually pays to
|
|
13042
|
+
* `myPkScript` may be counted as claimed here.
|
|
13043
|
+
*
|
|
13044
|
+
* @param vtxos - VTXOs at the arkadeCash contract's own pkScript, spent ones
|
|
13045
|
+
* included (a registered sweep marks its input spent). Any other outpoint —
|
|
13046
|
+
* subdust above all — would make the proof invalid, since it describes every
|
|
13047
|
+
* input by that pkScript.
|
|
13048
|
+
* @returns The number of pending txs finalized, the sats among them paid to
|
|
13049
|
+
* this wallet, and the outpoints those txs consumed to pay it.
|
|
13050
|
+
*/
|
|
13051
|
+
async finalizePendingCashTxs(cash, vtxos, cashScript, myPkScript) {
|
|
13052
|
+
const result = { count: 0, swept: 0, claimed: /* @__PURE__ */ new Set() };
|
|
13053
|
+
const inputs = vtxos.map((vtxo) => ({
|
|
13054
|
+
...vtxo,
|
|
13055
|
+
forfeitTapLeafScript: cashScript.forfeit(),
|
|
13056
|
+
intentTapLeafScript: cashScript.forfeit(),
|
|
13057
|
+
tapTree: cashScript.encode()
|
|
13058
|
+
}));
|
|
13059
|
+
if (inputs.length === 0) return result;
|
|
13060
|
+
const identity = cash.identity;
|
|
13061
|
+
const seenTxids = /* @__PURE__ */ new Set();
|
|
13062
|
+
const pendingTxs = [];
|
|
13063
|
+
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
13064
|
+
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
13065
|
+
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
13066
|
+
const proof = chunkEB3ALGTM_cjs.Intent.create(message, batch, []);
|
|
13067
|
+
const signedProof = await identity.sign(
|
|
13068
|
+
proof,
|
|
13069
|
+
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
13070
|
+
);
|
|
13071
|
+
const batchPending = await this.arkProvider.getPendingTxs({
|
|
13072
|
+
proof: base.base64.encode(signedProof.toPSBT()),
|
|
13073
|
+
message
|
|
13074
|
+
});
|
|
13075
|
+
for (const pendingTx of batchPending) {
|
|
13076
|
+
if (seenTxids.has(pendingTx.arkTxid)) continue;
|
|
13077
|
+
seenTxids.add(pendingTx.arkTxid);
|
|
13078
|
+
pendingTxs.push(pendingTx);
|
|
13079
|
+
}
|
|
13080
|
+
}
|
|
13081
|
+
const myPkScriptHex = base.hex.encode(myPkScript);
|
|
13082
|
+
for (const pendingTx of pendingTxs) {
|
|
13083
|
+
try {
|
|
13084
|
+
const checkpointTxs = pendingTx.signedCheckpointTxs.map(
|
|
13085
|
+
(checkpoint) => btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint))
|
|
13086
|
+
);
|
|
13087
|
+
const finalCheckpoints = await Promise.all(
|
|
13088
|
+
checkpointTxs.map(
|
|
13089
|
+
async (checkpoint) => base.base64.encode((await identity.sign(checkpoint)).toPSBT())
|
|
13090
|
+
)
|
|
13091
|
+
);
|
|
13092
|
+
await this.arkProvider.finalizeTx(pendingTx.arkTxid, finalCheckpoints);
|
|
13093
|
+
result.count++;
|
|
13094
|
+
const paidToMe = this.arkTxAmountPaidTo(pendingTx.finalArkTx, myPkScriptHex);
|
|
13095
|
+
if (paidToMe === 0) continue;
|
|
13096
|
+
result.swept += paidToMe;
|
|
13097
|
+
for (const checkpoint of checkpointTxs) {
|
|
13098
|
+
for (let i = 0; i < checkpoint.inputsLength; i++) {
|
|
13099
|
+
const input = checkpoint.getInput(i);
|
|
13100
|
+
if (!input.txid) continue;
|
|
13101
|
+
result.claimed.add(`${base.hex.encode(input.txid)}:${input.index}`);
|
|
13102
|
+
}
|
|
13103
|
+
}
|
|
13104
|
+
} catch (error) {
|
|
13105
|
+
console.error(
|
|
13106
|
+
`Failed to finalize pending arkadeCash tx ${pendingTx.arkTxid}:`,
|
|
13107
|
+
error
|
|
13108
|
+
);
|
|
13109
|
+
}
|
|
13110
|
+
}
|
|
13111
|
+
return result;
|
|
13112
|
+
}
|
|
13113
|
+
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
13114
|
+
arkTxAmountPaidTo(arkTxPsbt, pkScriptHex) {
|
|
13115
|
+
const arkTx = btcSigner.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
|
|
13116
|
+
let total = 0;
|
|
13117
|
+
for (let i = 0; i < arkTx.outputsLength; i++) {
|
|
13118
|
+
const output = arkTx.getOutput(i);
|
|
13119
|
+
if (!output.script || output.amount === void 0) continue;
|
|
13120
|
+
if (base.hex.encode(output.script) === pkScriptHex) total += Number(output.amount);
|
|
13121
|
+
}
|
|
13122
|
+
return total;
|
|
13123
|
+
}
|
|
12721
13124
|
/**
|
|
12722
13125
|
* Send BTC and/or assets to one or more recipients.
|
|
12723
13126
|
*
|
|
@@ -12946,7 +13349,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12946
13349
|
* there is no separate change output. It records no `TxSent` history — the
|
|
12947
13350
|
* funds never leave the wallet.
|
|
12948
13351
|
*/
|
|
12949
|
-
async sendSelectedVtxosToSelf(inputs) {
|
|
13352
|
+
async sendSelectedVtxosToSelf(inputs, now) {
|
|
12950
13353
|
if (inputs.length === 0) {
|
|
12951
13354
|
throw new Error("sendSelectedVtxosToSelf: no inputs");
|
|
12952
13355
|
}
|
|
@@ -12955,26 +13358,28 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12955
13358
|
const serverPubKey = this.arkServerPublicKey;
|
|
12956
13359
|
const serverUnrollScript = this.serverUnrollScript;
|
|
12957
13360
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
12958
|
-
|
|
12959
|
-
|
|
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)) {
|
|
12960
13365
|
throw new Error(
|
|
12961
13366
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
12962
13367
|
);
|
|
12963
13368
|
}
|
|
12964
|
-
if (
|
|
13369
|
+
if (input.expiresAt === void 0 && input.expiresAtHeight === void 0) {
|
|
12965
13370
|
throw new Error(
|
|
12966
|
-
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} has no
|
|
13371
|
+
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} has no batch expiry`
|
|
12967
13372
|
);
|
|
12968
13373
|
}
|
|
12969
13374
|
}
|
|
12970
|
-
const total =
|
|
13375
|
+
const total = normalizedInputs.reduce((sum, c) => sum + BigInt(c.value), 0n);
|
|
12971
13376
|
const outputs = [
|
|
12972
13377
|
{
|
|
12973
13378
|
script: total < this.dustAmount ? arkAddress.subdustPkScript : arkAddress.pkScript,
|
|
12974
13379
|
amount: total
|
|
12975
13380
|
}
|
|
12976
13381
|
];
|
|
12977
|
-
const assetInputs = selectedCoinsToAssetInputs(
|
|
13382
|
+
const assetInputs = selectedCoinsToAssetInputs(normalizedInputs);
|
|
12978
13383
|
let selfAssets;
|
|
12979
13384
|
if (assetInputs.size > 0) {
|
|
12980
13385
|
const totals = /* @__PURE__ */ new Map();
|
|
@@ -12991,7 +13396,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12991
13396
|
const packet = createAssetPacket(assetInputs, [], selfReceiver);
|
|
12992
13397
|
outputs.push(Extension.create([packet]).txOut());
|
|
12993
13398
|
}
|
|
12994
|
-
return this._submitOffchainSpend(
|
|
13399
|
+
return this._submitOffchainSpend(normalizedInputs, outputs, {
|
|
12995
13400
|
sentAmount: 0,
|
|
12996
13401
|
changeAmount: total,
|
|
12997
13402
|
changeVout: 0,
|
|
@@ -13021,7 +13426,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13021
13426
|
);
|
|
13022
13427
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
13023
13428
|
index,
|
|
13024
|
-
lookupScript:
|
|
13429
|
+
lookupScript: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
13025
13430
|
}));
|
|
13026
13431
|
const identity = this.identity;
|
|
13027
13432
|
const signer = {
|
|
@@ -13092,43 +13497,42 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13092
13497
|
const cm = await this.getContractManager();
|
|
13093
13498
|
const annotatedInputs = await cm.annotateVtxos(inputs);
|
|
13094
13499
|
for (const [inputIndex, vtxo] of annotatedInputs.entries()) {
|
|
13500
|
+
const spentFacts = { ...vtxo, isSpent: true };
|
|
13095
13501
|
if (inputIndex < safeLength && signedCheckpointTxs[inputIndex]) {
|
|
13096
13502
|
const checkpoint = btcSigner.Transaction.fromPSBT(
|
|
13097
13503
|
base.base64.decode(signedCheckpointTxs[inputIndex])
|
|
13098
13504
|
);
|
|
13099
13505
|
spentVtxos.push({
|
|
13100
|
-
...
|
|
13101
|
-
virtualStatus:
|
|
13102
|
-
...vtxo.virtualStatus,
|
|
13103
|
-
state: "spent"
|
|
13104
|
-
},
|
|
13506
|
+
...spentFacts,
|
|
13507
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(spentFacts),
|
|
13105
13508
|
spentBy: checkpoint.id,
|
|
13106
|
-
arkTxId: arkTxid
|
|
13107
|
-
isSpent: true
|
|
13509
|
+
arkTxId: arkTxid
|
|
13108
13510
|
});
|
|
13109
13511
|
} else {
|
|
13110
13512
|
spentVtxos.push({
|
|
13111
|
-
...
|
|
13112
|
-
virtualStatus:
|
|
13113
|
-
|
|
13114
|
-
state: "spent"
|
|
13115
|
-
},
|
|
13116
|
-
arkTxId: arkTxid,
|
|
13117
|
-
isSpent: true
|
|
13513
|
+
...spentFacts,
|
|
13514
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(spentFacts),
|
|
13515
|
+
arkTxId: arkTxid
|
|
13118
13516
|
});
|
|
13119
13517
|
}
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
commitmentTxIds.add(id);
|
|
13123
|
-
}
|
|
13518
|
+
for (const id of vtxo.commitmentTxIds) {
|
|
13519
|
+
commitmentTxIds.add(id);
|
|
13124
13520
|
}
|
|
13125
|
-
|
|
13126
|
-
|
|
13521
|
+
const vtxoExpiry = chunk7TXSPRN5_cjs.toBatchExpiry(vtxo);
|
|
13522
|
+
if (vtxoExpiry) {
|
|
13523
|
+
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
13127
13524
|
}
|
|
13128
13525
|
}
|
|
13129
13526
|
const createdAt = Date.now();
|
|
13130
13527
|
let changeVtxo;
|
|
13131
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
|
+
};
|
|
13132
13536
|
changeVtxo = {
|
|
13133
13537
|
txid: arkTxid,
|
|
13134
13538
|
vout: changeVout,
|
|
@@ -13136,14 +13540,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13136
13540
|
forfeitTapLeafScript: offchainTapscript.forfeit(),
|
|
13137
13541
|
intentTapLeafScript: offchainTapscript.forfeit(),
|
|
13138
13542
|
isUnrolled: false,
|
|
13139
|
-
isSpent: false,
|
|
13140
13543
|
tapTree: offchainTapscript.encode(),
|
|
13141
13544
|
value: Number(changeAmount),
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
batchExpiry
|
|
13146
|
-
},
|
|
13545
|
+
...changeFacts,
|
|
13546
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(changeFacts),
|
|
13547
|
+
spentBy: "",
|
|
13147
13548
|
status: {
|
|
13148
13549
|
confirmed: false
|
|
13149
13550
|
},
|
|
@@ -13211,30 +13612,30 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13211
13612
|
const spentVtxos = [];
|
|
13212
13613
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
13213
13614
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
13214
|
-
const
|
|
13215
|
-
const vtxoInputs = inputs.filter(isVtxo);
|
|
13615
|
+
const vtxoInputs = inputs.filter(chunk7TXSPRN5_cjs.isVirtualCoin);
|
|
13216
13616
|
const cm = await this.getContractManager();
|
|
13217
13617
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
13218
13618
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
13219
13619
|
for (const input of inputs) {
|
|
13220
|
-
if (
|
|
13221
|
-
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
|
+
}
|
|
13222
13626
|
if (vtxo.arkTxId) {
|
|
13223
13627
|
inputArkTxIds.add(vtxo.arkTxId);
|
|
13224
13628
|
}
|
|
13629
|
+
const settledFacts = { ...vtxo, isSpent: true };
|
|
13225
13630
|
spentVtxos.push({
|
|
13226
|
-
...
|
|
13227
|
-
virtualStatus:
|
|
13228
|
-
|
|
13229
|
-
state: "settled"
|
|
13230
|
-
},
|
|
13231
|
-
settledBy: commitmentTxid,
|
|
13232
|
-
isSpent: true
|
|
13631
|
+
...settledFacts,
|
|
13632
|
+
virtualStatus: chunk7TXSPRN5_cjs.toVirtualStatus(settledFacts),
|
|
13633
|
+
settledBy: commitmentTxid
|
|
13233
13634
|
});
|
|
13234
13635
|
} else {
|
|
13235
13636
|
let sourceAddress;
|
|
13236
13637
|
try {
|
|
13237
|
-
sourceAddress =
|
|
13638
|
+
sourceAddress = chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
13238
13639
|
this.network
|
|
13239
13640
|
);
|
|
13240
13641
|
} catch {
|
|
@@ -13292,9 +13693,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13292
13693
|
}
|
|
13293
13694
|
};
|
|
13294
13695
|
function selectVirtualCoins(coins, targetAmount) {
|
|
13295
|
-
const sortedCoins =
|
|
13296
|
-
const expiryA = a
|
|
13297
|
-
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;
|
|
13298
13699
|
if (expiryA !== expiryB) {
|
|
13299
13700
|
return expiryA - expiryB;
|
|
13300
13701
|
}
|
|
@@ -13545,7 +13946,7 @@ var MessageBus = class {
|
|
|
13545
13946
|
this.initialized = true;
|
|
13546
13947
|
}
|
|
13547
13948
|
async buildServices(config) {
|
|
13548
|
-
const arkProvider = new
|
|
13949
|
+
const arkProvider = new chunkEB3ALGTM_cjs.RestArkProvider(config.arkServer.url);
|
|
13549
13950
|
const storage = {
|
|
13550
13951
|
walletRepository: this.walletRepository,
|
|
13551
13952
|
contractRepository: this.contractRepository
|
|
@@ -13928,7 +14329,7 @@ var Ramps = class {
|
|
|
13928
14329
|
}
|
|
13929
14330
|
amount = amount ?? totalAmount;
|
|
13930
14331
|
const offchainAddress = await this.wallet.getAddress();
|
|
13931
|
-
const offchainAddr =
|
|
14332
|
+
const offchainAddr = chunk7TXSPRN5_cjs.ArkAddress.decode(offchainAddress);
|
|
13932
14333
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
13933
14334
|
const outputFee = estimator.evalOffchainOutput({
|
|
13934
14335
|
amount,
|
|
@@ -13988,13 +14389,7 @@ var Ramps = class {
|
|
|
13988
14389
|
const filteredVtxos = [];
|
|
13989
14390
|
let totalAmount = 0n;
|
|
13990
14391
|
for (const vtxo of vtxos) {
|
|
13991
|
-
const inputFee = estimator.evalOffchainInput(
|
|
13992
|
-
amount: BigInt(vtxo.value),
|
|
13993
|
-
type: vtxo.virtualStatus.state === "swept" ? "recoverable" : "vtxo",
|
|
13994
|
-
weight: 0,
|
|
13995
|
-
birth: vtxo.createdAt,
|
|
13996
|
-
expiry: vtxo.virtualStatus.batchExpiry ? new Date(vtxo.virtualStatus.batchExpiry) : void 0
|
|
13997
|
-
});
|
|
14392
|
+
const inputFee = estimator.evalOffchainInput(chunk7TXSPRN5_cjs.toOffchainInputFeeParams(vtxo));
|
|
13998
14393
|
if (inputFee.satoshis >= vtxo.value) {
|
|
13999
14394
|
continue;
|
|
14000
14395
|
}
|
|
@@ -14026,7 +14421,7 @@ var Ramps = class {
|
|
|
14026
14421
|
let destinationScript;
|
|
14027
14422
|
for (const networkName of networkNames) {
|
|
14028
14423
|
try {
|
|
14029
|
-
const network =
|
|
14424
|
+
const network = chunk7TXSPRN5_cjs.networks[networkName];
|
|
14030
14425
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
14031
14426
|
destinationScript = btcSigner.OutScript.encode(addr);
|
|
14032
14427
|
break;
|
|
@@ -14711,7 +15106,7 @@ var WalletMessageHandler = class {
|
|
|
14711
15106
|
// Wallet methods
|
|
14712
15107
|
async handleInitWallet({ payload }) {
|
|
14713
15108
|
const { arkServerUrl } = payload;
|
|
14714
|
-
this.indexerProvider = new
|
|
15109
|
+
this.indexerProvider = new chunkEB3ALGTM_cjs.RestIndexerProvider(arkServerUrl);
|
|
14715
15110
|
await this.onWalletInitialized();
|
|
14716
15111
|
}
|
|
14717
15112
|
async handleGetBalance() {
|
|
@@ -14729,30 +15124,30 @@ var WalletMessageHandler = class {
|
|
|
14729
15124
|
unconfirmed += utxo.value;
|
|
14730
15125
|
}
|
|
14731
15126
|
}
|
|
14732
|
-
const
|
|
14733
|
-
const sweptVtxos = allVtxos.filter((vtxo) => vtxo.virtualStatus.state === "swept");
|
|
15127
|
+
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
14734
15128
|
let settled = 0;
|
|
14735
15129
|
let preconfirmed = 0;
|
|
14736
15130
|
let recoverable = 0;
|
|
14737
15131
|
let pendingRecovery = 0;
|
|
14738
|
-
for (const vtxo of
|
|
15132
|
+
for (const vtxo of allVtxos) {
|
|
15133
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
14739
15134
|
if (pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
14740
15135
|
pendingRecovery += vtxo.value;
|
|
14741
|
-
} else if (vtxo
|
|
14742
|
-
settled += vtxo.value;
|
|
14743
|
-
} else if (vtxo.virtualStatus.state === "preconfirmed") {
|
|
14744
|
-
preconfirmed += vtxo.value;
|
|
14745
|
-
}
|
|
14746
|
-
}
|
|
14747
|
-
for (const vtxo of sweptVtxos) {
|
|
14748
|
-
if (isSpendable(vtxo)) {
|
|
15136
|
+
} else if (chunk7TXSPRN5_cjs.canRecoverOnchain(vtxo, now)) {
|
|
14749
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
|
+
}
|
|
14750
15144
|
}
|
|
14751
15145
|
}
|
|
14752
15146
|
const totalBoarding = confirmed + unconfirmed;
|
|
14753
15147
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
14754
15148
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
14755
|
-
for (const vtxo of
|
|
15149
|
+
for (const vtxo of allVtxos) {
|
|
15150
|
+
if (chunk7TXSPRN5_cjs.hasTerminalSpend(vtxo)) continue;
|
|
14756
15151
|
if (vtxo.assets) {
|
|
14757
15152
|
for (const a of vtxo.assets) {
|
|
14758
15153
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -14788,7 +15183,7 @@ var WalletMessageHandler = class {
|
|
|
14788
15183
|
*/
|
|
14789
15184
|
async getSpendableVtxos() {
|
|
14790
15185
|
const vtxos = await this.getVtxosFromRepo();
|
|
14791
|
-
return vtxos.filter(
|
|
15186
|
+
return vtxos.filter((v) => !chunk7TXSPRN5_cjs.hasTerminalSpend(v));
|
|
14792
15187
|
}
|
|
14793
15188
|
async onWalletInitialized() {
|
|
14794
15189
|
if (!this.readonlyWallet || !this.arkProvider || !this.indexerProvider || !this.walletRepository) {
|
|
@@ -14800,9 +15195,7 @@ var WalletMessageHandler = class {
|
|
|
14800
15195
|
try {
|
|
14801
15196
|
const vtxos = await this.getVtxosFromRepo();
|
|
14802
15197
|
const { pending, finalized } = await this.wallet.finalizePendingTxs(
|
|
14803
|
-
vtxos.filter(
|
|
14804
|
-
(vtxo) => vtxo.virtualStatus.state !== "swept" && vtxo.virtualStatus.state !== "settled"
|
|
14805
|
-
)
|
|
15198
|
+
vtxos.filter((vtxo) => vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept)
|
|
14806
15199
|
);
|
|
14807
15200
|
console.info(
|
|
14808
15201
|
`Recovered ${finalized.length}/${pending.length} pending transactions: ${finalized.join(", ")}`
|
|
@@ -15002,10 +15395,10 @@ var WalletMessageHandler = class {
|
|
|
15002
15395
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
15003
15396
|
return false;
|
|
15004
15397
|
}
|
|
15005
|
-
if (isRecoverable(v)) {
|
|
15398
|
+
if (chunk7TXSPRN5_cjs.isRecoverable(v)) {
|
|
15006
15399
|
return false;
|
|
15007
15400
|
}
|
|
15008
|
-
if (isExpired(v)) {
|
|
15401
|
+
if (chunk7TXSPRN5_cjs.isExpired(v)) {
|
|
15009
15402
|
return false;
|
|
15010
15403
|
}
|
|
15011
15404
|
return true;
|
|
@@ -15061,8 +15454,12 @@ var WalletMessageHandler = class {
|
|
|
15061
15454
|
`WalletMessageHandler.getVtxosFromRepo: failed to derive script from wallet address ${walletAddress}: ${e instanceof Error ? e.message : String(e)}`
|
|
15062
15455
|
);
|
|
15063
15456
|
}
|
|
15064
|
-
|
|
15065
|
-
|
|
15457
|
+
addVtxos(
|
|
15458
|
+
await getVtxosForContract(this.walletRepository, {
|
|
15459
|
+
script: walletScript,
|
|
15460
|
+
address: walletAddress
|
|
15461
|
+
})
|
|
15462
|
+
);
|
|
15066
15463
|
return allVtxos;
|
|
15067
15464
|
}
|
|
15068
15465
|
/**
|
|
@@ -15094,7 +15491,7 @@ var WalletMessageHandler = class {
|
|
|
15094
15491
|
}));
|
|
15095
15492
|
const BATCH_SIZE = 100;
|
|
15096
15493
|
for (let i = 0; i < outpoints.length; i += BATCH_SIZE) {
|
|
15097
|
-
const res = await this.indexerProvider
|
|
15494
|
+
const res = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
15098
15495
|
outpoints: outpoints.slice(i, i + BATCH_SIZE)
|
|
15099
15496
|
});
|
|
15100
15497
|
for (const v of res.vtxos) {
|
|
@@ -15796,7 +16193,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
15796
16193
|
};
|
|
15797
16194
|
try {
|
|
15798
16195
|
const response = await this.sendMessage(message);
|
|
15799
|
-
return response.payload.vtxos;
|
|
16196
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
15800
16197
|
} catch (error) {
|
|
15801
16198
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
15802
16199
|
}
|
|
@@ -15909,7 +16306,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
15909
16306
|
};
|
|
15910
16307
|
try {
|
|
15911
16308
|
const response = await sendContractMessage(message);
|
|
15912
|
-
return response.payload.vtxos;
|
|
16309
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
15913
16310
|
} catch (e) {
|
|
15914
16311
|
throw new Error("Failed to annotate vtxos");
|
|
15915
16312
|
}
|
|
@@ -16354,7 +16751,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
16354
16751
|
};
|
|
16355
16752
|
try {
|
|
16356
16753
|
const response = await wallet.sendMessage(message);
|
|
16357
|
-
return response.payload.vtxos;
|
|
16754
|
+
return response.payload.vtxos.map(chunk7TXSPRN5_cjs.normalizeVtxo);
|
|
16358
16755
|
} catch (e) {
|
|
16359
16756
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
16360
16757
|
}
|
|
@@ -16466,12 +16863,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16466
16863
|
* @returns Configured onchain wallet
|
|
16467
16864
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
16468
16865
|
*/
|
|
16469
|
-
static async create(identity, networkName =
|
|
16866
|
+
static async create(identity, networkName = chunk7TXSPRN5_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
16470
16867
|
const pubkey = await identity.xOnlyPublicKey();
|
|
16471
16868
|
if (!pubkey) {
|
|
16472
16869
|
throw new Error("Invalid configured public key");
|
|
16473
16870
|
}
|
|
16474
|
-
const network =
|
|
16871
|
+
const network = chunk7TXSPRN5_cjs.getNetwork(networkName);
|
|
16475
16872
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
16476
16873
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
16477
16874
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -16577,7 +16974,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16577
16974
|
if (!inputs) {
|
|
16578
16975
|
throw new Error("Fee estimation failed");
|
|
16579
16976
|
}
|
|
16580
|
-
let tx = new
|
|
16977
|
+
let tx = new chunkEB3ALGTM_cjs.Transaction();
|
|
16581
16978
|
for (const input of inputs) {
|
|
16582
16979
|
tx.addInput({
|
|
16583
16980
|
txid: input.txid,
|
|
@@ -16635,7 +17032,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16635
17032
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
16636
17033
|
*/
|
|
16637
17034
|
async bumpAnchor(parentHex, feeRate) {
|
|
16638
|
-
const parent =
|
|
17035
|
+
const parent = chunkEB3ALGTM_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
16639
17036
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
16640
17037
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
16641
17038
|
return [parent.hex, child.hex];
|
|
@@ -17400,7 +17797,7 @@ exports.BIP322 = void 0;
|
|
|
17400
17797
|
async function sign2(message, identity, network) {
|
|
17401
17798
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
17402
17799
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
17403
|
-
const toSpend =
|
|
17800
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
17404
17801
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
17405
17802
|
const signed = await identity.sign(toSign, [0]);
|
|
17406
17803
|
signed.finalizeIdx(0);
|
|
@@ -17458,7 +17855,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
17458
17855
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
17459
17856
|
return false;
|
|
17460
17857
|
}
|
|
17461
|
-
const toSpend =
|
|
17858
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17462
17859
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
17463
17860
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
17464
17861
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -17479,7 +17876,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
17479
17876
|
}
|
|
17480
17877
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
17481
17878
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
17482
|
-
const toSpend =
|
|
17879
|
+
const toSpend = chunkEB3ALGTM_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17483
17880
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
17484
17881
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
17485
17882
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -17532,7 +17929,7 @@ function encodeCompactSize(n) {
|
|
|
17532
17929
|
return buf;
|
|
17533
17930
|
}
|
|
17534
17931
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
17535
|
-
const tx = new
|
|
17932
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 0 });
|
|
17536
17933
|
tx.addInput({
|
|
17537
17934
|
txid: toSpend.id,
|
|
17538
17935
|
index: 0,
|
|
@@ -17546,12 +17943,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
17546
17943
|
});
|
|
17547
17944
|
tx.addOutput({
|
|
17548
17945
|
amount: 0n,
|
|
17549
|
-
script:
|
|
17946
|
+
script: chunkEB3ALGTM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17550
17947
|
});
|
|
17551
17948
|
return tx;
|
|
17552
17949
|
}
|
|
17553
17950
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
17554
|
-
const tx = new
|
|
17951
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 0 });
|
|
17555
17952
|
tx.addInput({
|
|
17556
17953
|
txid: toSpend.id,
|
|
17557
17954
|
index: 0,
|
|
@@ -17563,7 +17960,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
17563
17960
|
});
|
|
17564
17961
|
tx.addOutput({
|
|
17565
17962
|
amount: 0n,
|
|
17566
|
-
script:
|
|
17963
|
+
script: chunkEB3ALGTM_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17567
17964
|
});
|
|
17568
17965
|
return tx;
|
|
17569
17966
|
}
|
|
@@ -17694,7 +18091,7 @@ var RestEmulatorProvider = class {
|
|
|
17694
18091
|
}
|
|
17695
18092
|
};
|
|
17696
18093
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
17697
|
-
const tx =
|
|
18094
|
+
const tx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
17698
18095
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
17699
18096
|
const input = tx.getInput(0);
|
|
17700
18097
|
if (!input) {
|
|
@@ -17721,14 +18118,14 @@ var ExitPathError = class extends Error {
|
|
|
17721
18118
|
reason;
|
|
17722
18119
|
};
|
|
17723
18120
|
function delayWeight(sequence) {
|
|
17724
|
-
const t =
|
|
18121
|
+
const t = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
17725
18122
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
17726
18123
|
}
|
|
17727
18124
|
async function resolveUnilateralPath(params) {
|
|
17728
18125
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
17729
18126
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
17730
18127
|
if (contract) {
|
|
17731
|
-
const handler =
|
|
18128
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
17732
18129
|
if (!handler) {
|
|
17733
18130
|
throw new ExitPathError(
|
|
17734
18131
|
"no-handler",
|
|
@@ -17751,12 +18148,12 @@ async function resolveUnilateralPath(params) {
|
|
|
17751
18148
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
17752
18149
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
17753
18150
|
}
|
|
17754
|
-
const decoded =
|
|
18151
|
+
const decoded = chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
17755
18152
|
let best;
|
|
17756
18153
|
for (const exit of decoded.exitPaths()) {
|
|
17757
18154
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
17758
18155
|
if (!leaf) continue;
|
|
17759
|
-
const sequence =
|
|
18156
|
+
const sequence = chunk7TXSPRN5_cjs.timelockToSequence(exit.params.timelock);
|
|
17760
18157
|
const weight = delayWeight(sequence);
|
|
17761
18158
|
if (!best || weight < best.weight) {
|
|
17762
18159
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -17942,14 +18339,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17942
18339
|
}
|
|
17943
18340
|
const resolved = await resolveUnilateralPath({
|
|
17944
18341
|
vtxo,
|
|
17945
|
-
scriptHex: base.hex.encode(
|
|
18342
|
+
scriptHex: base.hex.encode(chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
17946
18343
|
contractRepository: wallet.contractRepository,
|
|
17947
18344
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
17948
18345
|
currentTime: Date.now()
|
|
17949
18346
|
});
|
|
17950
18347
|
const spendingLeaf = resolved.selection.leaf;
|
|
17951
18348
|
const sequence = resolved.selection.sequence;
|
|
17952
|
-
const timelock =
|
|
18349
|
+
const timelock = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
|
|
17953
18350
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
17954
18351
|
if (!elapsed) {
|
|
17955
18352
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -17962,7 +18359,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17962
18359
|
sequence,
|
|
17963
18360
|
witnessUtxo: {
|
|
17964
18361
|
amount: BigInt(vtxo.value),
|
|
17965
|
-
script:
|
|
18362
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
17966
18363
|
},
|
|
17967
18364
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
17968
18365
|
});
|
|
@@ -17972,7 +18369,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17972
18369
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
17973
18370
|
);
|
|
17974
18371
|
}
|
|
17975
|
-
const tx = new
|
|
18372
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
17976
18373
|
for (const input of inputs) {
|
|
17977
18374
|
tx.addInput(input);
|
|
17978
18375
|
}
|
|
@@ -18039,7 +18436,7 @@ async function buildSignedSweep(params) {
|
|
|
18039
18436
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
18040
18437
|
);
|
|
18041
18438
|
}
|
|
18042
|
-
const tx = new
|
|
18439
|
+
const tx = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
18043
18440
|
tx.addInput({
|
|
18044
18441
|
txid: vtxo.txid,
|
|
18045
18442
|
index: vtxo.vout,
|
|
@@ -18064,7 +18461,7 @@ async function buildSignedSweep(params) {
|
|
|
18064
18461
|
finalScriptWitness: [
|
|
18065
18462
|
tapScriptSig[0][1],
|
|
18066
18463
|
...path.extraWitness,
|
|
18067
|
-
|
|
18464
|
+
chunk7TXSPRN5_cjs.scriptFromTapLeafScript(path.leaf),
|
|
18068
18465
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
18069
18466
|
]
|
|
18070
18467
|
});
|
|
@@ -18094,7 +18491,7 @@ async function resolveFeeRate(opts) {
|
|
|
18094
18491
|
}
|
|
18095
18492
|
async function selectExitVtxos(opts) {
|
|
18096
18493
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
18097
|
-
const res = await opts.wallet.indexerProvider
|
|
18494
|
+
const res = await chunk7TXSPRN5_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
18098
18495
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
18099
18496
|
const out = [];
|
|
18100
18497
|
for (const vtxo of res.vtxos) {
|
|
@@ -18109,7 +18506,7 @@ async function selectExitVtxos(opts) {
|
|
|
18109
18506
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
18110
18507
|
);
|
|
18111
18508
|
}
|
|
18112
|
-
const handler =
|
|
18509
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(contract.type);
|
|
18113
18510
|
if (!handler) {
|
|
18114
18511
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
18115
18512
|
}
|
|
@@ -18139,7 +18536,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18139
18536
|
if (pendingNodes.length > 0) {
|
|
18140
18537
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
18141
18538
|
for (const psbt of txs) {
|
|
18142
|
-
psbts.set(
|
|
18539
|
+
psbts.set(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
18143
18540
|
}
|
|
18144
18541
|
}
|
|
18145
18542
|
const childVsize = Number(
|
|
@@ -18175,7 +18572,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18175
18572
|
try {
|
|
18176
18573
|
const resolved = await resolveUnilateralPath({
|
|
18177
18574
|
vtxo,
|
|
18178
|
-
scriptHex: base.hex.encode(
|
|
18575
|
+
scriptHex: base.hex.encode(chunk7TXSPRN5_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
18179
18576
|
contractRepository: wallet.contractRepository,
|
|
18180
18577
|
walletPubKeyHex,
|
|
18181
18578
|
currentTime: Date.now()
|
|
@@ -18194,7 +18591,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18194
18591
|
});
|
|
18195
18592
|
continue;
|
|
18196
18593
|
}
|
|
18197
|
-
const t =
|
|
18594
|
+
const t = chunk7TXSPRN5_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
18198
18595
|
const delay = { type: t.type, value: Number(t.value) };
|
|
18199
18596
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
18200
18597
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -18501,7 +18898,7 @@ async function prepare(opts) {
|
|
|
18501
18898
|
txid: sweep.vtxo.txid,
|
|
18502
18899
|
vout: sweep.vtxo.vout,
|
|
18503
18900
|
value: sweep.vtxo.value,
|
|
18504
|
-
pkScript:
|
|
18901
|
+
pkScript: chunk7TXSPRN5_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
18505
18902
|
},
|
|
18506
18903
|
path: sweep.resolved.selection,
|
|
18507
18904
|
outputAddress: opts.sweepAddress,
|
|
@@ -18586,7 +18983,7 @@ async function prepare(opts) {
|
|
|
18586
18983
|
if (newFee <= splitterFee) break;
|
|
18587
18984
|
splitterFee = newFee;
|
|
18588
18985
|
}
|
|
18589
|
-
const splitter = new
|
|
18986
|
+
const splitter = new chunkEB3ALGTM_cjs.Transaction({ version: 2 });
|
|
18590
18987
|
for (const coin of selected.inputs) {
|
|
18591
18988
|
splitter.addInput({
|
|
18592
18989
|
txid: coin.txid,
|
|
@@ -18729,41 +19126,41 @@ var UnilateralExit = {
|
|
|
18729
19126
|
// src/arkade/index.ts
|
|
18730
19127
|
var arkade_exports = {};
|
|
18731
19128
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
18732
|
-
ARKADE_OP: () =>
|
|
18733
|
-
ARKADE_OPCODES: () =>
|
|
18734
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
18735
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
18736
|
-
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,
|
|
18737
19134
|
Arkade: () => Arkade,
|
|
18738
19135
|
ArkadeContract: () => ArkadeContract,
|
|
18739
|
-
ArkadeProgramScript: () =>
|
|
18740
|
-
ArkadeScript: () =>
|
|
19136
|
+
ArkadeProgramScript: () => chunk5XMVTK5S_cjs.ArkadeProgramScript,
|
|
19137
|
+
ArkadeScript: () => chunk5XMVTK5S_cjs.ArkadeScript,
|
|
18741
19138
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
18742
|
-
BigNum: () =>
|
|
19139
|
+
BigNum: () => chunk5XMVTK5S_cjs.bignum_exports,
|
|
18743
19140
|
OP: () => btcSigner.OP,
|
|
18744
|
-
OPCODE_NAMES: () =>
|
|
18745
|
-
OPCODE_VALUES: () =>
|
|
18746
|
-
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,
|
|
18747
19144
|
Script: () => btcSigner.Script,
|
|
18748
|
-
arkadeScriptHash: () =>
|
|
18749
|
-
arkadeWitnessHash: () =>
|
|
18750
|
-
asmToBytes: () =>
|
|
18751
|
-
bytesToASM: () =>
|
|
18752
|
-
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,
|
|
18753
19150
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
18754
|
-
deserializeArkadeContractParams: () =>
|
|
18755
|
-
fromASM: () =>
|
|
18756
|
-
getOpcodeName: () =>
|
|
18757
|
-
getOpcodeValue: () =>
|
|
18758
|
-
parseArtifact: () =>
|
|
18759
|
-
resolveAsm: () =>
|
|
18760
|
-
serializeArkadeContractParams: () =>
|
|
18761
|
-
stringifyArtifact: () =>
|
|
18762
|
-
toASM: () =>
|
|
18763
|
-
validateProgram: () =>
|
|
18764
|
-
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
|
|
18765
19162
|
});
|
|
18766
|
-
var isVtxoCoin = (input) =>
|
|
19163
|
+
var isVtxoCoin = (input) => chunk7TXSPRN5_cjs.isVirtualCoin(input);
|
|
18767
19164
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients) {
|
|
18768
19165
|
let batchId;
|
|
18769
19166
|
let sweepTapTreeRoot;
|
|
@@ -18775,7 +19172,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
18775
19172
|
if (!event.intentIdHashes.includes(intentIdHashStr)) return { skip: true };
|
|
18776
19173
|
await arkProvider.confirmRegistration(intentId);
|
|
18777
19174
|
batchId = event.id;
|
|
18778
|
-
const sweepTapscript =
|
|
19175
|
+
const sweepTapscript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
|
|
18779
19176
|
timelock: {
|
|
18780
19177
|
value: event.batchExpiry,
|
|
18781
19178
|
// BIP-65: values >= 512 are interpreted as seconds, below as blocks
|
|
@@ -18793,7 +19190,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
18793
19190
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
18794
19191
|
return { skip: true };
|
|
18795
19192
|
}
|
|
18796
|
-
const commitmentTx =
|
|
19193
|
+
const commitmentTx = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
18797
19194
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
18798
19195
|
if (recipients && recipients.length > 0) {
|
|
18799
19196
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -18824,7 +19221,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
18824
19221
|
if (connectorTree) {
|
|
18825
19222
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
18826
19223
|
}
|
|
18827
|
-
let commitmentPsbt =
|
|
19224
|
+
let commitmentPsbt = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
18828
19225
|
const signedForfeits = [];
|
|
18829
19226
|
let connectorIndex = 0;
|
|
18830
19227
|
const connectorLeaves = connectorTree?.leaves() || [];
|
|
@@ -18840,14 +19237,18 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
18840
19237
|
break;
|
|
18841
19238
|
}
|
|
18842
19239
|
}
|
|
18843
|
-
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
|
+
}
|
|
18844
19245
|
commitmentPsbt.updateInput(boardingIdx, {
|
|
18845
19246
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
18846
19247
|
});
|
|
18847
19248
|
boardingIndices.push(boardingIdx);
|
|
18848
19249
|
continue;
|
|
18849
19250
|
}
|
|
18850
|
-
if (isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
19251
|
+
if (chunk7TXSPRN5_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
18851
19252
|
continue;
|
|
18852
19253
|
}
|
|
18853
19254
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -18868,7 +19269,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
18868
19269
|
index: input.vout,
|
|
18869
19270
|
witnessUtxo: {
|
|
18870
19271
|
amount: BigInt(input.value),
|
|
18871
|
-
script:
|
|
19272
|
+
script: chunk7TXSPRN5_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
18872
19273
|
},
|
|
18873
19274
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
18874
19275
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -18951,7 +19352,7 @@ var Arkade = class _Arkade {
|
|
|
18951
19352
|
static async connect(opts) {
|
|
18952
19353
|
const info = await opts.arkade.getInfo();
|
|
18953
19354
|
const serverKey = base.hex.decode(info.signerPubkey).slice(1);
|
|
18954
|
-
const checkpoint =
|
|
19355
|
+
const checkpoint = chunk7TXSPRN5_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
18955
19356
|
let emulatorKey;
|
|
18956
19357
|
if (opts.emulator) {
|
|
18957
19358
|
const eInfo = await opts.emulator.getInfo();
|
|
@@ -18965,7 +19366,7 @@ var Arkade = class _Arkade {
|
|
|
18965
19366
|
return new _Arkade({
|
|
18966
19367
|
arkProvider: opts.arkade,
|
|
18967
19368
|
emulator: opts.emulator,
|
|
18968
|
-
network: opts.network ??
|
|
19369
|
+
network: opts.network ?? chunk7TXSPRN5_cjs.DEFAULT_NETWORK,
|
|
18969
19370
|
serverKey,
|
|
18970
19371
|
emulatorKey,
|
|
18971
19372
|
checkpoint,
|
|
@@ -18986,7 +19387,7 @@ var Arkade = class _Arkade {
|
|
|
18986
19387
|
* key respectively; explicit args always win.
|
|
18987
19388
|
*/
|
|
18988
19389
|
contract(program, args = {}) {
|
|
18989
|
-
const declared = (program.params ?? []).map(
|
|
19390
|
+
const declared = (program.params ?? []).map(chunk5XMVTK5S_cjs.inputName);
|
|
18990
19391
|
if (declared.includes("server") && args.server === void 0) {
|
|
18991
19392
|
args = { ...args, server: this.serverKey };
|
|
18992
19393
|
}
|
|
@@ -19006,7 +19407,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19006
19407
|
userKey: client.userKey,
|
|
19007
19408
|
emulatorKey: client.emulatorKey
|
|
19008
19409
|
};
|
|
19009
|
-
this.vtxoScript = new
|
|
19410
|
+
this.vtxoScript = new chunk5XMVTK5S_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
19010
19411
|
this.tapTree = this.vtxoScript.encode();
|
|
19011
19412
|
this.compiled = this.vtxoScript.compiled;
|
|
19012
19413
|
}
|
|
@@ -19034,7 +19435,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19034
19435
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
19035
19436
|
);
|
|
19036
19437
|
}
|
|
19037
|
-
const typed =
|
|
19438
|
+
const typed = chunk5XMVTK5S_cjs.deserializeArkadeContractParams(contract.params);
|
|
19038
19439
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
19039
19440
|
serverKey: typed.serverKey,
|
|
19040
19441
|
userKey: typed.userKey,
|
|
@@ -19075,7 +19476,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19075
19476
|
toContractParams() {
|
|
19076
19477
|
return {
|
|
19077
19478
|
type: "arkade",
|
|
19078
|
-
params:
|
|
19479
|
+
params: chunk5XMVTK5S_cjs.serializeArkadeContractParams({
|
|
19079
19480
|
program: this.program,
|
|
19080
19481
|
args: this.args,
|
|
19081
19482
|
serverKey: this.keys.serverKey,
|
|
@@ -19120,13 +19521,13 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19120
19521
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
19121
19522
|
if (registered) {
|
|
19122
19523
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
19123
|
-
return (withVtxos?.vtxos ?? []).filter(
|
|
19524
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunk7TXSPRN5_cjs.hasTerminalSpend(v));
|
|
19124
19525
|
}
|
|
19125
19526
|
}
|
|
19126
19527
|
if (!this.client.indexer) {
|
|
19127
19528
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
19128
19529
|
}
|
|
19129
|
-
const { vtxos } = await this.client.indexer
|
|
19530
|
+
const { vtxos } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
19130
19531
|
scripts: [scriptHex],
|
|
19131
19532
|
spendableOnly: true
|
|
19132
19533
|
});
|
|
@@ -19228,12 +19629,12 @@ var ArkadeTransactionBuilder = class {
|
|
|
19228
19629
|
this.contract.client.checkpoint
|
|
19229
19630
|
);
|
|
19230
19631
|
if (coin.sourceTx) {
|
|
19231
|
-
|
|
19632
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(arkTx, 0, chunkEB3ALGTM_cjs.PrevArkTxField, coin.sourceTx);
|
|
19232
19633
|
}
|
|
19233
19634
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19234
19635
|
if (condition.length > 0) {
|
|
19235
|
-
|
|
19236
|
-
|
|
19636
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(arkTx, 0, chunkEB3ALGTM_cjs.ConditionWitness, condition);
|
|
19637
|
+
chunkEB3ALGTM_cjs.setArkPsbtField(checkpoints[0], 0, chunkEB3ALGTM_cjs.ConditionWitness, condition);
|
|
19237
19638
|
}
|
|
19238
19639
|
const packets = [];
|
|
19239
19640
|
if (this.assetSpecs.length > 0) {
|
|
@@ -19272,7 +19673,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19272
19673
|
base.base64.encode(signedArk2.toPSBT()),
|
|
19273
19674
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
19274
19675
|
);
|
|
19275
|
-
const txid =
|
|
19676
|
+
const txid = chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
19276
19677
|
return {
|
|
19277
19678
|
txid,
|
|
19278
19679
|
signedArkTx: res2.signedArkTx,
|
|
@@ -19290,7 +19691,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
19290
19691
|
const finalCps = await Promise.all(
|
|
19291
19692
|
res.signedCheckpointTxs.map(
|
|
19292
19693
|
async (b) => base.base64.encode(
|
|
19293
|
-
(await client.identity.sign(
|
|
19694
|
+
(await client.identity.sign(chunkEB3ALGTM_cjs.Transaction.fromPSBT(base.base64.decode(b)), [0])).toPSBT()
|
|
19294
19695
|
)
|
|
19295
19696
|
)
|
|
19296
19697
|
);
|
|
@@ -19331,23 +19732,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
19331
19732
|
}
|
|
19332
19733
|
buildAssetPacket() {
|
|
19333
19734
|
const groups = this.assetSpecs.map((s) => {
|
|
19334
|
-
const id = typeof s.assetId === "string" ?
|
|
19335
|
-
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(
|
|
19336
19737
|
id,
|
|
19337
19738
|
null,
|
|
19338
|
-
s.inputs.map((i) =>
|
|
19339
|
-
s.outputs.map((o) =>
|
|
19340
|
-
(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))
|
|
19341
19742
|
);
|
|
19342
19743
|
});
|
|
19343
|
-
return
|
|
19744
|
+
return chunkEB3ALGTM_cjs.Packet.create(groups);
|
|
19344
19745
|
}
|
|
19345
19746
|
witnessBytes(ref) {
|
|
19346
|
-
return
|
|
19747
|
+
return chunk5XMVTK5S_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
19347
19748
|
}
|
|
19348
19749
|
};
|
|
19349
19750
|
function bindInputs(fn, callArgs) {
|
|
19350
|
-
const names = (fn.def.inputs ?? []).map(
|
|
19751
|
+
const names = (fn.def.inputs ?? []).map(chunk5XMVTK5S_cjs.inputName);
|
|
19351
19752
|
if (callArgs.length !== names.length) {
|
|
19352
19753
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
19353
19754
|
}
|
|
@@ -19400,7 +19801,7 @@ function decodeArkContract(encoded) {
|
|
|
19400
19801
|
}
|
|
19401
19802
|
function contractFromArkContract(encoded, options = {}) {
|
|
19402
19803
|
const parsed = decodeArkContract(encoded);
|
|
19403
|
-
const handler =
|
|
19804
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.get(parsed.type);
|
|
19404
19805
|
if (!handler) {
|
|
19405
19806
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
19406
19807
|
}
|
|
@@ -19414,9 +19815,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
19414
19815
|
metadata: options.metadata
|
|
19415
19816
|
};
|
|
19416
19817
|
}
|
|
19417
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
19818
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk7TXSPRN5_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
19418
19819
|
const parsed = decodeArkContract(encoded);
|
|
19419
|
-
const handler =
|
|
19820
|
+
const handler = chunk5XMVTK5S_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
19420
19821
|
const params = parsed.data;
|
|
19421
19822
|
const vtxoScript = handler.createScript(params);
|
|
19422
19823
|
return {
|
|
@@ -19437,6 +19838,8 @@ function isArkContract(str) {
|
|
|
19437
19838
|
exports.ARKADE_MAGIC = ARKADE_MAGIC;
|
|
19438
19839
|
exports.ActivityRegistry = ActivityRegistry;
|
|
19439
19840
|
exports.ArkNote = ArkNote;
|
|
19841
|
+
exports.ArkadeCash = ArkadeCash;
|
|
19842
|
+
exports.ArkadeCashCreateError = ArkadeCashCreateError;
|
|
19440
19843
|
exports.AssetManager = AssetManager;
|
|
19441
19844
|
exports.ChainedTxType = ChainedTxType;
|
|
19442
19845
|
exports.ContractManager = ContractManager;
|
|
@@ -19534,10 +19937,7 @@ exports.isArkContract = isArkContract;
|
|
|
19534
19937
|
exports.isBatchSignable = isBatchSignable;
|
|
19535
19938
|
exports.isCooperativelyMigratable = isCooperativelyMigratable;
|
|
19536
19939
|
exports.isDiscoverable = isDiscoverable;
|
|
19537
|
-
exports.isExpired = isExpired;
|
|
19538
|
-
exports.isRecoverable = isRecoverable;
|
|
19539
19940
|
exports.isRetryableProviderError = isRetryableProviderError;
|
|
19540
|
-
exports.isSpendable = isSpendable;
|
|
19541
19941
|
exports.isSubdust = isSubdust;
|
|
19542
19942
|
exports.isTerminalIntentState = isTerminalIntentState;
|
|
19543
19943
|
exports.isValidArkAddress = isValidArkAddress;
|
|
@@ -19564,5 +19964,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
19564
19964
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
19565
19965
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
19566
19966
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
19567
|
-
//# sourceMappingURL=chunk-
|
|
19568
|
-
//# sourceMappingURL=chunk-
|
|
19967
|
+
//# sourceMappingURL=chunk-ENZ4YPR2.cjs.map
|
|
19968
|
+
//# sourceMappingURL=chunk-ENZ4YPR2.cjs.map
|