@arkade-os/sdk 0.4.53 → 0.4.54
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-B69ugeJw.d.cts → ark-acFuA57I.d.cts} +2 -1
- package/dist/{ark-B69ugeJw.d.ts → ark-acFuA57I.d.ts} +2 -1
- package/dist/{asyncStorageTaskQueue-B0SUQMXw.d.cts → asyncStorageTaskQueue-BO3cvMpP.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-DWqxuIAs.d.ts → asyncStorageTaskQueue-DACXtP0I.d.ts} +2 -2
- package/dist/chunk-4EIKOJLD.js +2319 -0
- package/dist/chunk-4EIKOJLD.js.map +1 -0
- package/dist/{chunk-IEMPH7J6.cjs → chunk-53XNU2EL.cjs} +40 -40
- package/dist/{chunk-IEMPH7J6.cjs.map → chunk-53XNU2EL.cjs.map} +1 -1
- package/dist/{chunk-B4WZOJAI.js → chunk-7L3P3EP5.js} +4 -4
- package/dist/{chunk-B4WZOJAI.js.map → chunk-7L3P3EP5.js.map} +1 -1
- package/dist/{chunk-UZLQUWYP.js → chunk-A37WVZ5T.js} +3 -3
- package/dist/{chunk-UZLQUWYP.js.map → chunk-A37WVZ5T.js.map} +1 -1
- package/dist/{chunk-4GB73TRR.cjs → chunk-BYJJIITU.cjs} +17 -17
- package/dist/{chunk-4GB73TRR.cjs.map → chunk-BYJJIITU.cjs.map} +1 -1
- package/dist/{chunk-3YC3LQ2E.cjs → chunk-D5LUPJJP.cjs} +829 -431
- package/dist/chunk-D5LUPJJP.cjs.map +1 -0
- package/dist/chunk-GMUVWKOK.cjs +2407 -0
- package/dist/chunk-GMUVWKOK.cjs.map +1 -0
- package/dist/{chunk-3XWDMLOI.js → chunk-QY2YVFZT.js} +4 -4
- package/dist/{chunk-3XWDMLOI.js.map → chunk-QY2YVFZT.js.map} +1 -1
- package/dist/{chunk-RNMLFY2V.cjs → chunk-RNECH3TA.cjs} +19 -1367
- package/dist/chunk-RNECH3TA.cjs.map +1 -0
- package/dist/{chunk-3MMUKLCI.js → chunk-TEHJCEF3.js} +467 -85
- package/dist/chunk-TEHJCEF3.js.map +1 -0
- package/dist/{chunk-CZTQLA55.cjs → chunk-YRLBZJYO.cjs} +9 -9
- package/dist/{chunk-CZTQLA55.cjs.map → chunk-YRLBZJYO.cjs.map} +1 -1
- package/dist/{chunk-LHYNNDY6.js → chunk-ZOY5JSVA.js} +8 -1327
- package/dist/chunk-ZOY5JSVA.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-C_Y2YrXC.d.cts → delegate-Ca_wXiYE.d.cts} +1 -1
- package/dist/{delegate-BU-Cpyjw.d.ts → delegate-DjwZZi6L.d.ts} +1 -1
- package/dist/{index-tzAInyiX.d.cts → index-DFfefdpc.d.cts} +2 -2
- package/dist/{index-BWF-C9eh.d.ts → index-Ddq0mIKX.d.ts} +2 -2
- package/dist/index.cjs +315 -243
- package/dist/index.d.cts +298 -12
- package/dist/index.d.ts +298 -12
- 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-B7svzMhT.d.cts → taskRunner-DEwlrgId.d.cts} +2 -2
- package/dist/{taskRunner-nzJFH8qb.d.ts → taskRunner-DbCNRP31.d.ts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +5 -5
- package/dist/{wallet-CuHAI-eW.d.ts → wallet-B9rpddG2.d.ts} +2 -2
- package/dist/{wallet-B6Xiferv.d.cts → wallet-ByjM6L20.d.cts} +2 -2
- 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 +1 -1
- package/dist/chunk-3MMUKLCI.js.map +0 -1
- package/dist/chunk-3YC3LQ2E.cjs.map +0 -1
- package/dist/chunk-E7HB3GKK.cjs +0 -1030
- package/dist/chunk-E7HB3GKK.cjs.map +0 -1
- package/dist/chunk-EFNLTS6Q.js +0 -976
- package/dist/chunk-EFNLTS6Q.js.map +0 -1
- package/dist/chunk-LHYNNDY6.js.map +0 -1
- package/dist/chunk-RNMLFY2V.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkRNECH3TA_cjs = require('./chunk-RNECH3TA.cjs');
|
|
4
|
+
var chunk53XNU2EL_cjs = require('./chunk-53XNU2EL.cjs');
|
|
5
|
+
var chunkGMUVWKOK_cjs = require('./chunk-GMUVWKOK.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');
|
|
@@ -47,8 +47,8 @@ function aggregateNonces(pubNonces) {
|
|
|
47
47
|
return musig2__namespace.nonceAggregate(pubNonces);
|
|
48
48
|
}
|
|
49
49
|
function aggregateKeys(publicKeys, sort, options = {}) {
|
|
50
|
-
{
|
|
51
|
-
publicKeys = musig2__namespace.sortKeys(publicKeys);
|
|
50
|
+
if (sort) {
|
|
51
|
+
publicKeys = musig2__namespace.sortKeys([...publicKeys]);
|
|
52
52
|
}
|
|
53
53
|
const { aggPublicKey: preTweakedKey } = musig2__namespace.keyAggregate(publicKeys);
|
|
54
54
|
if (!options.taprootTweak) {
|
|
@@ -110,24 +110,27 @@ var PartialSig = class _PartialSig {
|
|
|
110
110
|
return new _PartialSig(bytes, R);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
|
-
function
|
|
113
|
+
function createSession(combinedNonce, publicKeys, message, options) {
|
|
114
|
+
const keys = musig2__namespace.sortKeys([...publicKeys]) ;
|
|
114
115
|
let tweakBytes;
|
|
115
116
|
if (options?.taprootTweak !== void 0) {
|
|
116
|
-
const { preTweakedKey } = aggregateKeys(
|
|
117
|
-
musig2__namespace.sortKeys(publicKeys) );
|
|
117
|
+
const { preTweakedKey } = aggregateKeys(keys, false);
|
|
118
118
|
tweakBytes = secp256k1_js.schnorr.utils.taggedHash(
|
|
119
119
|
"TapTweak",
|
|
120
120
|
preTweakedKey.subarray(1),
|
|
121
121
|
options.taprootTweak
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
return new musig2__namespace.Session(
|
|
125
125
|
combinedNonce,
|
|
126
|
-
|
|
126
|
+
keys,
|
|
127
127
|
message,
|
|
128
128
|
tweakBytes ? [tweakBytes] : void 0,
|
|
129
129
|
tweakBytes ? [true] : void 0
|
|
130
130
|
);
|
|
131
|
+
}
|
|
132
|
+
function sign(secNonce, privateKey, combinedNonce, publicKeys, message, options) {
|
|
133
|
+
const session = createSession(combinedNonce, publicKeys, message, options);
|
|
131
134
|
const partialSig = session.sign(secNonce, privateKey);
|
|
132
135
|
return PartialSig.decode(partialSig);
|
|
133
136
|
}
|
|
@@ -185,7 +188,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
185
188
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
186
189
|
const tx = this.graph.find(txid);
|
|
187
190
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
188
|
-
const cosigners =
|
|
191
|
+
const cosigners = chunkGMUVWKOK_cjs.getArkPsbtFields(tx.root, 0, chunkGMUVWKOK_cjs.CosignerPublicKey).map(
|
|
189
192
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
190
193
|
// xonly pubkey
|
|
191
194
|
);
|
|
@@ -237,7 +240,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
237
240
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
238
241
|
const prevoutAmounts = [];
|
|
239
242
|
const prevoutScripts = [];
|
|
240
|
-
const cosigners =
|
|
243
|
+
const cosigners = chunkGMUVWKOK_cjs.getArkPsbtFields(g.root, 0, chunkGMUVWKOK_cjs.CosignerPublicKey).map((c) => c.key);
|
|
241
244
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
242
245
|
taprootTweak: this.scriptRoot
|
|
243
246
|
});
|
|
@@ -416,7 +419,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
416
419
|
let network;
|
|
417
420
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
418
421
|
descriptor = opts.descriptor;
|
|
419
|
-
network =
|
|
422
|
+
network = chunk53XNU2EL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
420
423
|
} else {
|
|
421
424
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
422
425
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -501,7 +504,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
501
504
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
502
505
|
*/
|
|
503
506
|
isOurs(descriptor) {
|
|
504
|
-
return
|
|
507
|
+
return chunk53XNU2EL_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
505
508
|
}
|
|
506
509
|
/**
|
|
507
510
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -538,7 +541,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
538
541
|
}
|
|
539
542
|
// ── internal helpers ─────────────────────────────────────────────
|
|
540
543
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
541
|
-
const network =
|
|
544
|
+
const network = chunk53XNU2EL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
542
545
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
543
546
|
if (expansion.isRanged) {
|
|
544
547
|
throw new Error(
|
|
@@ -624,7 +627,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
624
627
|
*/
|
|
625
628
|
descriptor;
|
|
626
629
|
constructor(descriptor) {
|
|
627
|
-
const network =
|
|
630
|
+
const network = chunk53XNU2EL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
628
631
|
let expansion;
|
|
629
632
|
try {
|
|
630
633
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -674,7 +677,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
674
677
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
675
678
|
*/
|
|
676
679
|
isOurs(descriptor) {
|
|
677
|
-
return
|
|
680
|
+
return chunk53XNU2EL_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
678
681
|
}
|
|
679
682
|
};
|
|
680
683
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -986,14 +989,14 @@ var RestDelegateProvider = class {
|
|
|
986
989
|
*/
|
|
987
990
|
async delegate(intent, forfeitTxs, options) {
|
|
988
991
|
const url = `${this.url}/v1/delegate`;
|
|
989
|
-
const response = await
|
|
992
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(url, {
|
|
990
993
|
method: "POST",
|
|
991
994
|
headers: {
|
|
992
995
|
"Content-Type": "application/json"
|
|
993
996
|
},
|
|
994
997
|
body: JSON.stringify({
|
|
995
998
|
intent: {
|
|
996
|
-
message:
|
|
999
|
+
message: chunkGMUVWKOK_cjs.Intent.encodeMessage(intent.message),
|
|
997
1000
|
proof: intent.proof
|
|
998
1001
|
},
|
|
999
1002
|
forfeit_txs: forfeitTxs,
|
|
@@ -1013,7 +1016,7 @@ var RestDelegateProvider = class {
|
|
|
1013
1016
|
*/
|
|
1014
1017
|
async getDelegateInfo() {
|
|
1015
1018
|
const url = `${this.url}/v1/delegator/info`;
|
|
1016
|
-
const response = await
|
|
1019
|
+
const response = await chunkGMUVWKOK_cjs.rateGate.runHttp(url, () => chunkGMUVWKOK_cjs.baseFetch(url));
|
|
1017
1020
|
if (!response.ok) {
|
|
1018
1021
|
const errorText2 = await response.text();
|
|
1019
1022
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1040,7 +1043,7 @@ var ESPLORA_URL = {
|
|
|
1040
1043
|
regtest: "http://localhost:3000/api"
|
|
1041
1044
|
};
|
|
1042
1045
|
var EsploraProvider = class {
|
|
1043
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1046
|
+
constructor(baseUrl = ESPLORA_URL[chunkGMUVWKOK_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1044
1047
|
this.baseUrl = baseUrl;
|
|
1045
1048
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1046
1049
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1049,14 +1052,14 @@ var EsploraProvider = class {
|
|
|
1049
1052
|
pollingInterval;
|
|
1050
1053
|
forcePolling;
|
|
1051
1054
|
async getCoins(address) {
|
|
1052
|
-
const response = await
|
|
1055
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1053
1056
|
if (!response.ok) {
|
|
1054
1057
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1055
1058
|
}
|
|
1056
1059
|
return response.json();
|
|
1057
1060
|
}
|
|
1058
1061
|
async getFeeRate() {
|
|
1059
|
-
const response = await
|
|
1062
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1060
1063
|
if (response.status === 404) {
|
|
1061
1064
|
return void 0;
|
|
1062
1065
|
}
|
|
@@ -1077,7 +1080,7 @@ var EsploraProvider = class {
|
|
|
1077
1080
|
}
|
|
1078
1081
|
}
|
|
1079
1082
|
async getTxOutspends(txid) {
|
|
1080
|
-
const response = await
|
|
1083
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1081
1084
|
if (!response.ok) {
|
|
1082
1085
|
const error = await response.text();
|
|
1083
1086
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1085,7 +1088,7 @@ var EsploraProvider = class {
|
|
|
1085
1088
|
return response.json();
|
|
1086
1089
|
}
|
|
1087
1090
|
async getTransactions(address) {
|
|
1088
|
-
const response = await
|
|
1091
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1089
1092
|
if (!response.ok) {
|
|
1090
1093
|
const error = await response.text();
|
|
1091
1094
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1093,7 +1096,7 @@ var EsploraProvider = class {
|
|
|
1093
1096
|
return response.json();
|
|
1094
1097
|
}
|
|
1095
1098
|
async getTxStatus(txid) {
|
|
1096
|
-
const txresponse = await
|
|
1099
|
+
const txresponse = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1097
1100
|
if (!txresponse.ok) {
|
|
1098
1101
|
throw new Error(txresponse.statusText);
|
|
1099
1102
|
}
|
|
@@ -1101,7 +1104,7 @@ var EsploraProvider = class {
|
|
|
1101
1104
|
if (!tx.status.confirmed) {
|
|
1102
1105
|
return { confirmed: false };
|
|
1103
1106
|
}
|
|
1104
|
-
const response = await
|
|
1107
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1105
1108
|
if (!response.ok) {
|
|
1106
1109
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1107
1110
|
}
|
|
@@ -1185,7 +1188,7 @@ var EsploraProvider = class {
|
|
|
1185
1188
|
return stopFunc;
|
|
1186
1189
|
}
|
|
1187
1190
|
async getChainTip() {
|
|
1188
|
-
const tipBlocks = await
|
|
1191
|
+
const tipBlocks = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
1189
1192
|
if (!tipBlocks.ok) {
|
|
1190
1193
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
1191
1194
|
}
|
|
@@ -1204,7 +1207,7 @@ var EsploraProvider = class {
|
|
|
1204
1207
|
};
|
|
1205
1208
|
}
|
|
1206
1209
|
async broadcastPackage(parent, child) {
|
|
1207
|
-
const response = await
|
|
1210
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
1208
1211
|
method: "POST",
|
|
1209
1212
|
headers: {
|
|
1210
1213
|
"Content-Type": "application/json"
|
|
@@ -1218,7 +1221,7 @@ var EsploraProvider = class {
|
|
|
1218
1221
|
return response.json();
|
|
1219
1222
|
}
|
|
1220
1223
|
async broadcastTx(tx) {
|
|
1221
|
-
const response = await
|
|
1224
|
+
const response = await chunkGMUVWKOK_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
1222
1225
|
method: "POST",
|
|
1223
1226
|
headers: {
|
|
1224
1227
|
"Content-Type": "text/plain"
|
|
@@ -1380,7 +1383,7 @@ function findP2AOutput(tx) {
|
|
|
1380
1383
|
var CHILD_DUST_AMOUNT = 546;
|
|
1381
1384
|
function buildAnchorChild(params) {
|
|
1382
1385
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
1383
|
-
const child = new
|
|
1386
|
+
const child = new chunkGMUVWKOK_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
1384
1387
|
child.addInput(findP2AOutput(parent));
|
|
1385
1388
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
1386
1389
|
for (const _ of fundingCoins) {
|
|
@@ -1428,7 +1431,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
1428
1431
|
);
|
|
1429
1432
|
}
|
|
1430
1433
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
1431
|
-
const tx = new
|
|
1434
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({
|
|
1432
1435
|
version: 3,
|
|
1433
1436
|
lockTime: txLocktime
|
|
1434
1437
|
});
|
|
@@ -1504,7 +1507,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
1504
1507
|
if (previousScriptKey.length !== 32) {
|
|
1505
1508
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
1506
1509
|
}
|
|
1507
|
-
const cosigners =
|
|
1510
|
+
const cosigners = chunkGMUVWKOK_cjs.getArkPsbtFields(child.root, 0, chunkGMUVWKOK_cjs.CosignerPublicKey);
|
|
1508
1511
|
if (cosigners.length === 0) {
|
|
1509
1512
|
throw ErrMissingCosignersPublicKeys;
|
|
1510
1513
|
}
|
|
@@ -1562,7 +1565,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
1562
1565
|
return new _EmulatorPacket(entries);
|
|
1563
1566
|
}
|
|
1564
1567
|
static fromBytes(data) {
|
|
1565
|
-
const reader = new
|
|
1568
|
+
const reader = new chunkRNECH3TA_cjs.BufferReader(data);
|
|
1566
1569
|
const entryCount = reader.readCompactSize();
|
|
1567
1570
|
const entries = [];
|
|
1568
1571
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -1580,7 +1583,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
1580
1583
|
return _EmulatorPacket.PACKET_TYPE;
|
|
1581
1584
|
}
|
|
1582
1585
|
serialize() {
|
|
1583
|
-
const writer = new
|
|
1586
|
+
const writer = new chunkRNECH3TA_cjs.BufferWriter();
|
|
1584
1587
|
writer.writeCompactSize(this.entries.length);
|
|
1585
1588
|
for (const entry of this.entries) {
|
|
1586
1589
|
writer.writeUint16LE(entry.vin);
|
|
@@ -1667,7 +1670,7 @@ var Extension = class _Extension {
|
|
|
1667
1670
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
1668
1671
|
);
|
|
1669
1672
|
}
|
|
1670
|
-
const reader = new
|
|
1673
|
+
const reader = new chunkRNECH3TA_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
1671
1674
|
const packets = [];
|
|
1672
1675
|
while (reader.remaining() > 0) {
|
|
1673
1676
|
const packetType = reader.readByte();
|
|
@@ -1741,7 +1744,7 @@ var Extension = class _Extension {
|
|
|
1741
1744
|
*/
|
|
1742
1745
|
getAssetPacket() {
|
|
1743
1746
|
for (const p of this.packets) {
|
|
1744
|
-
if (p instanceof
|
|
1747
|
+
if (p instanceof chunkRNECH3TA_cjs.Packet) {
|
|
1745
1748
|
return p;
|
|
1746
1749
|
}
|
|
1747
1750
|
}
|
|
@@ -1779,8 +1782,8 @@ var Extension = class _Extension {
|
|
|
1779
1782
|
};
|
|
1780
1783
|
function parsePacket(packetType, data) {
|
|
1781
1784
|
switch (packetType) {
|
|
1782
|
-
case
|
|
1783
|
-
return
|
|
1785
|
+
case chunkRNECH3TA_cjs.Packet.PACKET_TYPE:
|
|
1786
|
+
return chunkRNECH3TA_cjs.Packet.fromBytes(data);
|
|
1784
1787
|
case EmulatorPacket.PACKET_TYPE:
|
|
1785
1788
|
return EmulatorPacket.fromBytes(data);
|
|
1786
1789
|
default:
|
|
@@ -1841,7 +1844,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
1841
1844
|
for (const recipient of recipients) {
|
|
1842
1845
|
let arkAddress;
|
|
1843
1846
|
try {
|
|
1844
|
-
arkAddress =
|
|
1847
|
+
arkAddress = chunkGMUVWKOK_cjs.ArkAddress.decode(recipient.address);
|
|
1845
1848
|
} catch {
|
|
1846
1849
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
1847
1850
|
continue;
|
|
@@ -2077,7 +2080,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2077
2080
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
2078
2081
|
inputsByAssetId.set(asset.assetId, [
|
|
2079
2082
|
...existing ?? [],
|
|
2080
|
-
|
|
2083
|
+
chunkRNECH3TA_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
2081
2084
|
]);
|
|
2082
2085
|
}
|
|
2083
2086
|
}
|
|
@@ -2089,7 +2092,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2089
2092
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2090
2093
|
outputsByAssetId.set(asset.assetId, [
|
|
2091
2094
|
...existing ?? [],
|
|
2092
|
-
|
|
2095
|
+
chunkRNECH3TA_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2093
2096
|
]);
|
|
2094
2097
|
}
|
|
2095
2098
|
}
|
|
@@ -2100,7 +2103,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2100
2103
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2101
2104
|
outputsByAssetId.set(asset.assetId, [
|
|
2102
2105
|
...existing ?? [],
|
|
2103
|
-
|
|
2106
|
+
chunkRNECH3TA_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2104
2107
|
]);
|
|
2105
2108
|
}
|
|
2106
2109
|
}
|
|
@@ -2109,11 +2112,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2109
2112
|
for (const assetIdStr of allAssetIds) {
|
|
2110
2113
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2111
2114
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2112
|
-
const assetId =
|
|
2113
|
-
const group =
|
|
2115
|
+
const assetId = chunkRNECH3TA_cjs.AssetId.fromString(assetIdStr);
|
|
2116
|
+
const group = chunkRNECH3TA_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2114
2117
|
groups.push(group);
|
|
2115
2118
|
}
|
|
2116
|
-
return
|
|
2119
|
+
return chunkRNECH3TA_cjs.Packet.create(groups);
|
|
2117
2120
|
}
|
|
2118
2121
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2119
2122
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2218,8 +2221,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
2218
2221
|
function buildVirtualTx(inputs, outputs) {
|
|
2219
2222
|
let lockTime = 0n;
|
|
2220
2223
|
for (const input of inputs) {
|
|
2221
|
-
const tapscript =
|
|
2222
|
-
if (
|
|
2224
|
+
const tapscript = chunkGMUVWKOK_cjs.decodeTapscript(chunkGMUVWKOK_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
2225
|
+
if (chunkGMUVWKOK_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
2223
2226
|
if (lockTime !== 0n) {
|
|
2224
2227
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
2225
2228
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -2230,7 +2233,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2230
2233
|
}
|
|
2231
2234
|
}
|
|
2232
2235
|
}
|
|
2233
|
-
const tx = new
|
|
2236
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({
|
|
2234
2237
|
version: 3,
|
|
2235
2238
|
lockTime: Number(lockTime)
|
|
2236
2239
|
});
|
|
@@ -2240,12 +2243,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2240
2243
|
index: input.vout,
|
|
2241
2244
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
2242
2245
|
witnessUtxo: {
|
|
2243
|
-
script:
|
|
2246
|
+
script: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
2244
2247
|
amount: BigInt(input.value)
|
|
2245
2248
|
},
|
|
2246
2249
|
tapLeafScript: [input.tapLeafScript]
|
|
2247
2250
|
});
|
|
2248
|
-
|
|
2251
|
+
chunkGMUVWKOK_cjs.setArkPsbtField(tx, i, chunkGMUVWKOK_cjs.VtxoTaprootTree, input.tapTree);
|
|
2249
2252
|
}
|
|
2250
2253
|
for (const output of outputs) {
|
|
2251
2254
|
tx.addOutput(output);
|
|
@@ -2254,8 +2257,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2254
2257
|
return tx;
|
|
2255
2258
|
}
|
|
2256
2259
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
2257
|
-
const collaborativeClosure =
|
|
2258
|
-
const checkpointVtxoScript = new
|
|
2260
|
+
const collaborativeClosure = chunkGMUVWKOK_cjs.decodeTapscript(chunkGMUVWKOK_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
2261
|
+
const checkpointVtxoScript = new chunkGMUVWKOK_cjs.VtxoScript([
|
|
2259
2262
|
serverUnrollScript.script,
|
|
2260
2263
|
collaborativeClosure.script
|
|
2261
2264
|
]);
|
|
@@ -2301,7 +2304,7 @@ function hasBoardingTxExpired(coin, boardingTimelock, chainTipHeight) {
|
|
|
2301
2304
|
function formatSighash(type) {
|
|
2302
2305
|
return `0x${type.toString(16).padStart(2, "0")}`;
|
|
2303
2306
|
}
|
|
2304
|
-
function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [btcSigner.SigHash.DEFAULT]) {
|
|
2307
|
+
function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [btcSigner.SigHash.DEFAULT], expectedLeafHash) {
|
|
2305
2308
|
const input = tx.getInput(inputIndex);
|
|
2306
2309
|
const prevoutScripts = [];
|
|
2307
2310
|
const prevoutAmounts = [];
|
|
@@ -2316,12 +2319,21 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
2316
2319
|
if (!input.tapScriptSig || input.tapScriptSig.length === 0) {
|
|
2317
2320
|
throw new Error(`Input ${inputIndex} is missing tapScriptSig`);
|
|
2318
2321
|
}
|
|
2322
|
+
const expectedLeafHashHex = expectedLeafHash ? base.hex.encode(expectedLeafHash) : void 0;
|
|
2319
2323
|
for (const [tapScriptSigData, signature] of input.tapScriptSig) {
|
|
2320
2324
|
const pubKey = tapScriptSigData.pubKey;
|
|
2321
2325
|
const pubKeyHex = base.hex.encode(pubKey);
|
|
2322
2326
|
if (excludePubkeys.includes(pubKeyHex)) {
|
|
2323
2327
|
continue;
|
|
2324
2328
|
}
|
|
2329
|
+
if (expectedLeafHashHex !== void 0) {
|
|
2330
|
+
const signedLeafHex = base.hex.encode(tapScriptSigData.leafHash);
|
|
2331
|
+
if (signedLeafHex !== expectedLeafHashHex) {
|
|
2332
|
+
throw new Error(
|
|
2333
|
+
`Input ${inputIndex}: signature from ${pubKeyHex} commits to leaf ${signedLeafHex}, expected ${expectedLeafHashHex}`
|
|
2334
|
+
);
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2325
2337
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
2326
2338
|
const sig = signature.subarray(0, 64);
|
|
2327
2339
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
@@ -2399,7 +2411,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
2399
2411
|
}
|
|
2400
2412
|
function isValidArkAddress(address) {
|
|
2401
2413
|
try {
|
|
2402
|
-
|
|
2414
|
+
chunkGMUVWKOK_cjs.ArkAddress.decode(address);
|
|
2403
2415
|
return true;
|
|
2404
2416
|
} catch (e) {
|
|
2405
2417
|
return false;
|
|
@@ -2428,14 +2440,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks) {
|
|
|
2428
2440
|
let finalCheckpoints;
|
|
2429
2441
|
if (userSignedCheckpoints) {
|
|
2430
2442
|
finalCheckpoints = signedCheckpointTxs.map((c, i) => {
|
|
2431
|
-
const serverSigned =
|
|
2443
|
+
const serverSigned = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2432
2444
|
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
2433
2445
|
return base.base64.encode(serverSigned.toPSBT());
|
|
2434
2446
|
});
|
|
2435
2447
|
} else {
|
|
2436
2448
|
finalCheckpoints = await Promise.all(
|
|
2437
2449
|
signedCheckpointTxs.map(async (c) => {
|
|
2438
|
-
const tx =
|
|
2450
|
+
const tx = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2439
2451
|
const signed = await signer.signCheckpoint(tx);
|
|
2440
2452
|
return base.base64.encode(signed.toPSBT());
|
|
2441
2453
|
})
|
|
@@ -2634,7 +2646,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2634
2646
|
};
|
|
2635
2647
|
}
|
|
2636
2648
|
function deriveContractTapscripts(contract) {
|
|
2637
|
-
const handler =
|
|
2649
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
2638
2650
|
if (!handler) {
|
|
2639
2651
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2640
2652
|
}
|
|
@@ -2703,12 +2715,20 @@ function getRandomId() {
|
|
|
2703
2715
|
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
2704
2716
|
return base.hex.encode(randomValue);
|
|
2705
2717
|
}
|
|
2718
|
+
function isValidArkAddress2(address) {
|
|
2719
|
+
try {
|
|
2720
|
+
chunkGMUVWKOK_cjs.ArkAddress.decode(address);
|
|
2721
|
+
return true;
|
|
2722
|
+
} catch (e) {
|
|
2723
|
+
return false;
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2706
2726
|
function validateRecipients(recipients, dustAmount) {
|
|
2707
2727
|
const validatedRecipients = [];
|
|
2708
2728
|
for (const recipient of recipients) {
|
|
2709
2729
|
let address;
|
|
2710
2730
|
try {
|
|
2711
|
-
address =
|
|
2731
|
+
address = chunkGMUVWKOK_cjs.ArkAddress.decode(recipient.address);
|
|
2712
2732
|
} catch (e) {
|
|
2713
2733
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2714
2734
|
}
|
|
@@ -2736,7 +2756,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
2736
2756
|
continue;
|
|
2737
2757
|
}
|
|
2738
2758
|
for (const v of vtxos) {
|
|
2739
|
-
if (!
|
|
2759
|
+
if (!chunkGMUVWKOK_cjs.hasTerminalSpend(v) && !v.isSwept) out.add(`${v.txid}:${v.vout}`);
|
|
2740
2760
|
}
|
|
2741
2761
|
}
|
|
2742
2762
|
return out;
|
|
@@ -2769,10 +2789,10 @@ function byValueDescending(vtxos) {
|
|
|
2769
2789
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
2770
2790
|
}
|
|
2771
2791
|
async function fetchTimeHeight(wallet) {
|
|
2772
|
-
return
|
|
2792
|
+
return chunkGMUVWKOK_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
2773
2793
|
}
|
|
2774
2794
|
function canMigrateBySend(vtxo, now) {
|
|
2775
|
-
if (!
|
|
2795
|
+
if (!chunkGMUVWKOK_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
2776
2796
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
2777
2797
|
}
|
|
2778
2798
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -2780,7 +2800,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
2780
2800
|
if (vtxo.isSwept) return -Infinity;
|
|
2781
2801
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
2782
2802
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
2783
|
-
return
|
|
2803
|
+
return chunkGMUVWKOK_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
2784
2804
|
}
|
|
2785
2805
|
return Infinity;
|
|
2786
2806
|
};
|
|
@@ -2817,10 +2837,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
2817
2837
|
};
|
|
2818
2838
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
2819
2839
|
return vtxos.filter((vtxo) => {
|
|
2820
|
-
if (
|
|
2840
|
+
if (chunkGMUVWKOK_cjs.canRecoverOnchain(vtxo, now)) {
|
|
2821
2841
|
return true;
|
|
2822
2842
|
}
|
|
2823
|
-
if (
|
|
2843
|
+
if (chunkGMUVWKOK_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
2824
2844
|
return true;
|
|
2825
2845
|
}
|
|
2826
2846
|
return false;
|
|
@@ -2851,7 +2871,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
2851
2871
|
}
|
|
2852
2872
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
2853
2873
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
2854
|
-
const expiresAt =
|
|
2874
|
+
const expiresAt = chunkGMUVWKOK_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
2855
2875
|
if (expiresAt === void 0) return false;
|
|
2856
2876
|
const now = Date.now();
|
|
2857
2877
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -2860,7 +2880,7 @@ function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
|
2860
2880
|
}
|
|
2861
2881
|
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
2862
2882
|
return vtxos.filter(
|
|
2863
|
-
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
2883
|
+
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) || chunkGMUVWKOK_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount)
|
|
2864
2884
|
);
|
|
2865
2885
|
}
|
|
2866
2886
|
function isMigrationCapable(wallet) {
|
|
@@ -3342,11 +3362,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3342
3362
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3343
3363
|
);
|
|
3344
3364
|
}
|
|
3345
|
-
const tx = new
|
|
3365
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction();
|
|
3346
3366
|
for (const utxo of expiredUtxos) {
|
|
3347
|
-
const utxoScript =
|
|
3367
|
+
const utxoScript = chunkGMUVWKOK_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3348
3368
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
3349
|
-
(leaf) =>
|
|
3369
|
+
(leaf) => chunkGMUVWKOK_cjs.CSVMultisigTapscript.isScriptValid(chunkGMUVWKOK_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
3350
3370
|
);
|
|
3351
3371
|
if (!utxoExitLeaf) {
|
|
3352
3372
|
throw new Error(
|
|
@@ -3361,7 +3381,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3361
3381
|
amount: BigInt(utxo.value)
|
|
3362
3382
|
},
|
|
3363
3383
|
tapLeafScript: [utxoExitLeaf],
|
|
3364
|
-
sequence:
|
|
3384
|
+
sequence: chunkGMUVWKOK_cjs.getSequence(utxoExitLeaf)
|
|
3365
3385
|
});
|
|
3366
3386
|
}
|
|
3367
3387
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -3595,8 +3615,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3595
3615
|
if (!serverPubKey) continue;
|
|
3596
3616
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
3597
3617
|
if (cls.status === "CURRENT") continue;
|
|
3598
|
-
const recoverable = vtxos.filter((v) => v.isSwept && !
|
|
3599
|
-
const spendable = vtxos.filter((v) => !
|
|
3618
|
+
const recoverable = vtxos.filter((v) => v.isSwept && !chunkGMUVWKOK_cjs.hasTerminalSpend(v));
|
|
3619
|
+
const spendable = vtxos.filter((v) => !chunkGMUVWKOK_cjs.hasTerminalSpend(v) && !v.isSwept);
|
|
3600
3620
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
3601
3621
|
let recoverableCount = 0;
|
|
3602
3622
|
let recoverableValue = 0;
|
|
@@ -3609,7 +3629,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3609
3629
|
awaitingSweepCount = spendable.length;
|
|
3610
3630
|
awaitingSweepValue = value;
|
|
3611
3631
|
for (const v of spendable) {
|
|
3612
|
-
const exp =
|
|
3632
|
+
const exp = chunkGMUVWKOK_cjs.toBatchExpiry(v);
|
|
3613
3633
|
if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
|
|
3614
3634
|
nextSweepEta = exp;
|
|
3615
3635
|
}
|
|
@@ -3870,7 +3890,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3870
3890
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
3871
3891
|
getBoardingTimelock() {
|
|
3872
3892
|
const wallet = this.getSweepWallet();
|
|
3873
|
-
const exitScript =
|
|
3893
|
+
const exitScript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(
|
|
3874
3894
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
3875
3895
|
);
|
|
3876
3896
|
return exitScript.params.timelock;
|
|
@@ -4001,8 +4021,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
4001
4021
|
* or doesn't carry the metadata.
|
|
4002
4022
|
*/
|
|
4003
4023
|
extractSpentOutpoint(error) {
|
|
4004
|
-
const ark =
|
|
4005
|
-
if (!
|
|
4024
|
+
const ark = chunkGMUVWKOK_cjs.maybeArkError(error);
|
|
4025
|
+
if (!chunkGMUVWKOK_cjs.isArkError(ark, chunkGMUVWKOK_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
4006
4026
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
4007
4027
|
if (typeof raw !== "string") return void 0;
|
|
4008
4028
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -4192,7 +4212,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4192
4212
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
4193
4213
|
break;
|
|
4194
4214
|
}
|
|
4195
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4215
|
+
const inputFee = estimator.evalOffchainInput(chunkGMUVWKOK_cjs.toOffchainInputFeeParams(v));
|
|
4196
4216
|
if (inputFee.satoshis >= v.value) {
|
|
4197
4217
|
continue;
|
|
4198
4218
|
}
|
|
@@ -4212,7 +4232,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4212
4232
|
const arkAddress = await this.wallet.getAddress();
|
|
4213
4233
|
const outputFee = estimator.evalOffchainOutput({
|
|
4214
4234
|
amount: totalAmount,
|
|
4215
|
-
script: base.hex.encode(
|
|
4235
|
+
script: base.hex.encode(chunkGMUVWKOK_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4216
4236
|
});
|
|
4217
4237
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
4218
4238
|
if (totalAmount < dustAmount) return;
|
|
@@ -4292,7 +4312,7 @@ var ArkNote = class _ArkNote {
|
|
|
4292
4312
|
this.value = value;
|
|
4293
4313
|
this.HRP = HRP;
|
|
4294
4314
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
4295
|
-
this.vtxoScript = new
|
|
4315
|
+
this.vtxoScript = new chunkGMUVWKOK_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
4296
4316
|
const leaf = this.vtxoScript.leaves[0];
|
|
4297
4317
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
4298
4318
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -4459,7 +4479,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
4459
4479
|
const privateKey = data.slice(1, 33);
|
|
4460
4480
|
const serverPubKey = data.slice(33, 65);
|
|
4461
4481
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
4462
|
-
const csvTimelock =
|
|
4482
|
+
const csvTimelock = chunkGMUVWKOK_cjs.sequenceToTimelock(sequence);
|
|
4463
4483
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
|
|
4464
4484
|
}
|
|
4465
4485
|
toString() {
|
|
@@ -4467,7 +4487,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
4467
4487
|
data[0] = _ArkadeCash.Version;
|
|
4468
4488
|
data.set(this._privateKey, 1);
|
|
4469
4489
|
data.set(this._serverPubKey, 33);
|
|
4470
|
-
const sequence =
|
|
4490
|
+
const sequence = chunkGMUVWKOK_cjs.timelockToSequence(this.csvTimelock);
|
|
4471
4491
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
4472
4492
|
const words = base.bech32m.toWords(data);
|
|
4473
4493
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -4476,7 +4496,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
4476
4496
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
4477
4497
|
}
|
|
4478
4498
|
get vtxoScript() {
|
|
4479
|
-
return new
|
|
4499
|
+
return new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
4480
4500
|
pubKey: this._publicKey,
|
|
4481
4501
|
serverPubKey: this._serverPubKey,
|
|
4482
4502
|
csvTimelock: this.csvTimelock
|
|
@@ -4737,7 +4757,7 @@ async function captureExitBranch(params) {
|
|
|
4737
4757
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4738
4758
|
if (nonCommitment.length > 0) {
|
|
4739
4759
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4740
|
-
psbtByTxid.set(
|
|
4760
|
+
psbtByTxid.set(chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4741
4761
|
}
|
|
4742
4762
|
}
|
|
4743
4763
|
}
|
|
@@ -4780,10 +4800,10 @@ var IndexerExitDataSource = class {
|
|
|
4780
4800
|
while (hasMore) {
|
|
4781
4801
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
4782
4802
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
4783
|
-
{ pageIndex, pageSize:
|
|
4803
|
+
{ pageIndex, pageSize: chunkGMUVWKOK_cjs.DEFAULT_PAGE_SIZE }
|
|
4784
4804
|
);
|
|
4785
4805
|
chain.push(...page);
|
|
4786
|
-
hasMore = meta ? page.length ===
|
|
4806
|
+
hasMore = meta ? page.length === chunkGMUVWKOK_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4787
4807
|
pageIndex++;
|
|
4788
4808
|
}
|
|
4789
4809
|
return chain;
|
|
@@ -4795,12 +4815,12 @@ var IndexerExitDataSource = class {
|
|
|
4795
4815
|
while (hasMore) {
|
|
4796
4816
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
4797
4817
|
pageIndex,
|
|
4798
|
-
pageSize:
|
|
4818
|
+
pageSize: chunkGMUVWKOK_cjs.DEFAULT_PAGE_SIZE
|
|
4799
4819
|
});
|
|
4800
4820
|
for (const psbt of txs) {
|
|
4801
|
-
out.set(
|
|
4821
|
+
out.set(chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4802
4822
|
}
|
|
4803
|
-
hasMore = page ? txs.length ===
|
|
4823
|
+
hasMore = page ? txs.length === chunkGMUVWKOK_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4804
4824
|
pageIndex++;
|
|
4805
4825
|
}
|
|
4806
4826
|
return out;
|
|
@@ -4821,7 +4841,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4821
4841
|
}
|
|
4822
4842
|
}
|
|
4823
4843
|
function psbtInputTxids(psbtBase64) {
|
|
4824
|
-
const tx =
|
|
4844
|
+
const tx = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4825
4845
|
const ids = [];
|
|
4826
4846
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4827
4847
|
const txid = tx.getInput(i).txid;
|
|
@@ -4922,11 +4942,6 @@ function createExitChainResolver(params) {
|
|
|
4922
4942
|
return new OrderedExitChainResolver(sources, params.repository);
|
|
4923
4943
|
}
|
|
4924
4944
|
|
|
4925
|
-
// src/providers/availability.ts
|
|
4926
|
-
function isRetryableProviderError(error) {
|
|
4927
|
-
return error instanceof chunkRNMLFY2V_cjs.ProviderUnavailableError || error instanceof chunkRNMLFY2V_cjs.FetchError || chunkRNMLFY2V_cjs.isFetchTimeoutError(error);
|
|
4928
|
-
}
|
|
4929
|
-
|
|
4930
4945
|
// src/utils/syncCursors.ts
|
|
4931
4946
|
var SAFETY_LAG_MS = 3e4;
|
|
4932
4947
|
var OVERLAP_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -5174,10 +5189,10 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
5174
5189
|
try {
|
|
5175
5190
|
info = await arkProvider.getInfo();
|
|
5176
5191
|
} catch (err) {
|
|
5177
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
5192
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
5178
5193
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
5179
5194
|
if (!snapshot) {
|
|
5180
|
-
throw new
|
|
5195
|
+
throw new chunkGMUVWKOK_cjs.ProviderUnavailableError(
|
|
5181
5196
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
5182
5197
|
{ cause: err }
|
|
5183
5198
|
);
|
|
@@ -5549,8 +5564,20 @@ function subtractAssets(spent, change) {
|
|
|
5549
5564
|
if (map.size === 0) return void 0;
|
|
5550
5565
|
return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
|
|
5551
5566
|
}
|
|
5552
|
-
|
|
5553
|
-
const
|
|
5567
|
+
function collectArkTxidsNeedingCreatedAt(vtxos) {
|
|
5568
|
+
const ownTxids = new Set(vtxos.map((v) => v.txid));
|
|
5569
|
+
const txids = /* @__PURE__ */ new Set();
|
|
5570
|
+
for (const vtxo of vtxos) {
|
|
5571
|
+
if (vtxo.isSpent && vtxo.arkTxId && !ownTxids.has(vtxo.arkTxId)) {
|
|
5572
|
+
txids.add(vtxo.arkTxId);
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
return [...txids];
|
|
5576
|
+
}
|
|
5577
|
+
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt) {
|
|
5578
|
+
const fromOldestVtxo = vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
5579
|
+
const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(fromOldestVtxo) : [];
|
|
5580
|
+
const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
|
|
5554
5581
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
5555
5582
|
const sent = [];
|
|
5556
5583
|
let received = [];
|
|
@@ -5610,7 +5637,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
5610
5637
|
txTime = changes[0].createdAt.getTime();
|
|
5611
5638
|
} else {
|
|
5612
5639
|
txAmount = spentAmount;
|
|
5613
|
-
txTime =
|
|
5640
|
+
txTime = resolvedCreatedAt.get(vtxo.arkTxId) ?? vtxo.createdAt.getTime() + 1;
|
|
5614
5641
|
}
|
|
5615
5642
|
const assets = subtractAssets(allSpent, changes);
|
|
5616
5643
|
if (txAmount !== 0 || assets) {
|
|
@@ -5712,7 +5739,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5712
5739
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5713
5740
|
withRecoverable: false
|
|
5714
5741
|
});
|
|
5715
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5742
|
+
const controlAssetRef = params.controlAssetId ? chunkRNECH3TA_cjs.AssetRef.fromId(chunkRNECH3TA_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5716
5743
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5717
5744
|
let totalBtcSelected = 0n;
|
|
5718
5745
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5725,8 +5752,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5725
5752
|
}
|
|
5726
5753
|
}
|
|
5727
5754
|
const groups = [];
|
|
5728
|
-
const issuedAssetOutput =
|
|
5729
|
-
const issuedAssetGroup =
|
|
5755
|
+
const issuedAssetOutput = chunkRNECH3TA_cjs.AssetOutput.create(0, params.amount);
|
|
5756
|
+
const issuedAssetGroup = chunkRNECH3TA_cjs.AssetGroup.create(
|
|
5730
5757
|
null,
|
|
5731
5758
|
controlAssetRef,
|
|
5732
5759
|
[],
|
|
@@ -5741,28 +5768,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5741
5768
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5742
5769
|
for (const asset of assets) {
|
|
5743
5770
|
if (asset.assetId !== assetId) continue;
|
|
5744
|
-
changeInputs.push(
|
|
5771
|
+
changeInputs.push(chunkRNECH3TA_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5745
5772
|
}
|
|
5746
5773
|
}
|
|
5747
5774
|
groups.push(
|
|
5748
|
-
|
|
5749
|
-
|
|
5775
|
+
chunkRNECH3TA_cjs.AssetGroup.create(
|
|
5776
|
+
chunkRNECH3TA_cjs.AssetId.fromString(assetId),
|
|
5750
5777
|
null,
|
|
5751
5778
|
changeInputs,
|
|
5752
|
-
[
|
|
5779
|
+
[chunkRNECH3TA_cjs.AssetOutput.create(0, amount)],
|
|
5753
5780
|
[]
|
|
5754
5781
|
)
|
|
5755
5782
|
);
|
|
5756
5783
|
}
|
|
5757
5784
|
}
|
|
5758
5785
|
const address = await this.wallet.getAddress();
|
|
5759
|
-
const outputAddress =
|
|
5786
|
+
const outputAddress = chunkGMUVWKOK_cjs.ArkAddress.decode(address);
|
|
5760
5787
|
const outputs = [
|
|
5761
5788
|
{
|
|
5762
5789
|
script: outputAddress.pkScript,
|
|
5763
5790
|
amount: BigInt(totalBtcSelected)
|
|
5764
5791
|
},
|
|
5765
|
-
Extension.create([
|
|
5792
|
+
Extension.create([chunkRNECH3TA_cjs.Packet.create(groups)]).txOut()
|
|
5766
5793
|
];
|
|
5767
5794
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5768
5795
|
coinSelection.inputs,
|
|
@@ -5770,7 +5797,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5770
5797
|
);
|
|
5771
5798
|
return {
|
|
5772
5799
|
arkTxId: arkTxid,
|
|
5773
|
-
assetId:
|
|
5800
|
+
assetId: chunkRNECH3TA_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5774
5801
|
};
|
|
5775
5802
|
}
|
|
5776
5803
|
/**
|
|
@@ -5842,16 +5869,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5842
5869
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5843
5870
|
for (const asset of assets) {
|
|
5844
5871
|
if (asset.assetId !== params.assetId) continue;
|
|
5845
|
-
reissueInputs.push(
|
|
5872
|
+
reissueInputs.push(chunkRNECH3TA_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5846
5873
|
}
|
|
5847
5874
|
}
|
|
5848
5875
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5849
|
-
const reissueAssetIdObj =
|
|
5850
|
-
const reissueAssetGroup =
|
|
5876
|
+
const reissueAssetIdObj = chunkRNECH3TA_cjs.AssetId.fromString(params.assetId);
|
|
5877
|
+
const reissueAssetGroup = chunkRNECH3TA_cjs.AssetGroup.create(
|
|
5851
5878
|
reissueAssetIdObj,
|
|
5852
5879
|
null,
|
|
5853
5880
|
reissueInputs,
|
|
5854
|
-
[
|
|
5881
|
+
[chunkRNECH3TA_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5855
5882
|
[]
|
|
5856
5883
|
);
|
|
5857
5884
|
const groups = [reissueAssetGroup];
|
|
@@ -5860,27 +5887,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5860
5887
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5861
5888
|
for (const asset of assets) {
|
|
5862
5889
|
if (asset.assetId !== assetId) continue;
|
|
5863
|
-
changeInputs.push(
|
|
5890
|
+
changeInputs.push(chunkRNECH3TA_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5864
5891
|
}
|
|
5865
5892
|
}
|
|
5866
5893
|
groups.push(
|
|
5867
|
-
|
|
5868
|
-
|
|
5894
|
+
chunkRNECH3TA_cjs.AssetGroup.create(
|
|
5895
|
+
chunkRNECH3TA_cjs.AssetId.fromString(assetId),
|
|
5869
5896
|
null,
|
|
5870
5897
|
changeInputs,
|
|
5871
|
-
[
|
|
5898
|
+
[chunkRNECH3TA_cjs.AssetOutput.create(0, amount)],
|
|
5872
5899
|
[]
|
|
5873
5900
|
)
|
|
5874
5901
|
);
|
|
5875
5902
|
}
|
|
5876
5903
|
const address = await this.wallet.getAddress();
|
|
5877
|
-
const outputAddress =
|
|
5904
|
+
const outputAddress = chunkGMUVWKOK_cjs.ArkAddress.decode(address);
|
|
5878
5905
|
const outputs = [
|
|
5879
5906
|
{
|
|
5880
5907
|
script: outputAddress.pkScript,
|
|
5881
5908
|
amount: BigInt(totalBtcSelected)
|
|
5882
5909
|
},
|
|
5883
|
-
Extension.create([
|
|
5910
|
+
Extension.create([chunkRNECH3TA_cjs.Packet.create(groups)]).txOut()
|
|
5884
5911
|
];
|
|
5885
5912
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5886
5913
|
return arkTxid;
|
|
@@ -5947,27 +5974,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5947
5974
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5948
5975
|
for (const asset of assets) {
|
|
5949
5976
|
if (asset.assetId !== assetId) continue;
|
|
5950
|
-
changeInputs.push(
|
|
5977
|
+
changeInputs.push(chunkRNECH3TA_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5951
5978
|
}
|
|
5952
5979
|
}
|
|
5953
5980
|
groups.push(
|
|
5954
|
-
|
|
5955
|
-
|
|
5981
|
+
chunkRNECH3TA_cjs.AssetGroup.create(
|
|
5982
|
+
chunkRNECH3TA_cjs.AssetId.fromString(assetId),
|
|
5956
5983
|
null,
|
|
5957
5984
|
changeInputs,
|
|
5958
|
-
amount > 0n ? [
|
|
5985
|
+
amount > 0n ? [chunkRNECH3TA_cjs.AssetOutput.create(0, amount)] : [],
|
|
5959
5986
|
[]
|
|
5960
5987
|
)
|
|
5961
5988
|
);
|
|
5962
5989
|
}
|
|
5963
5990
|
const address = await this.wallet.getAddress();
|
|
5964
|
-
const outputAddress =
|
|
5991
|
+
const outputAddress = chunkGMUVWKOK_cjs.ArkAddress.decode(address);
|
|
5965
5992
|
const outputs = [
|
|
5966
5993
|
{
|
|
5967
5994
|
script: outputAddress.pkScript,
|
|
5968
5995
|
amount: BigInt(totalBtcSelected)
|
|
5969
5996
|
},
|
|
5970
|
-
Extension.create([
|
|
5997
|
+
Extension.create([chunkRNECH3TA_cjs.Packet.create(groups)]).txOut()
|
|
5971
5998
|
];
|
|
5972
5999
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5973
6000
|
return arkTxid;
|
|
@@ -5992,7 +6019,7 @@ function castMetadata(metadata) {
|
|
|
5992
6019
|
} else {
|
|
5993
6020
|
throw new Error("Invalid metadata value type");
|
|
5994
6021
|
}
|
|
5995
|
-
md.push(
|
|
6022
|
+
md.push(chunkRNECH3TA_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5996
6023
|
}
|
|
5997
6024
|
return md;
|
|
5998
6025
|
}
|
|
@@ -6013,10 +6040,10 @@ var DelegateManagerImpl = class {
|
|
|
6013
6040
|
if (vtxos.length === 0) {
|
|
6014
6041
|
return { delegated: [], failed: [] };
|
|
6015
6042
|
}
|
|
6016
|
-
const destinationScript =
|
|
6043
|
+
const destinationScript = chunkGMUVWKOK_cjs.ArkAddress.decode(destination).pkScript;
|
|
6017
6044
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
6018
6045
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
6019
|
-
const eligible = vtxos.map(
|
|
6046
|
+
const eligible = vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo).filter(
|
|
6020
6047
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
6021
6048
|
);
|
|
6022
6049
|
if (eligible.length === 0) {
|
|
@@ -6045,11 +6072,11 @@ var DelegateManagerImpl = class {
|
|
|
6045
6072
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
6046
6073
|
let recoverableVtxos = [];
|
|
6047
6074
|
for (const vtxo of eligible) {
|
|
6048
|
-
if (
|
|
6075
|
+
if (chunkGMUVWKOK_cjs.canRecoverOnchain(vtxo, now)) {
|
|
6049
6076
|
recoverableVtxos.push(vtxo);
|
|
6050
6077
|
continue;
|
|
6051
6078
|
}
|
|
6052
|
-
const expiry =
|
|
6079
|
+
const expiry = chunkGMUVWKOK_cjs.toBatchExpiry(vtxo);
|
|
6053
6080
|
if (!expiry) continue;
|
|
6054
6081
|
const dayKey = getDayTimestamp(expiry);
|
|
6055
6082
|
groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
|
|
@@ -6114,7 +6141,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6114
6141
|
}
|
|
6115
6142
|
if (!delegateAt) {
|
|
6116
6143
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
6117
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
6144
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkGMUVWKOK_cjs.canRecoverOnchain(coin, now) && chunkGMUVWKOK_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunkGMUVWKOK_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
|
|
6118
6145
|
if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
|
|
6119
6146
|
delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
|
|
6120
6147
|
} else {
|
|
@@ -6143,7 +6170,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6143
6170
|
let amount = 0n;
|
|
6144
6171
|
for (const coin of vtxos) {
|
|
6145
6172
|
const inputFee = estimator.evalOffchainInput({
|
|
6146
|
-
...
|
|
6173
|
+
...chunkGMUVWKOK_cjs.toOffchainInputFeeParams(coin),
|
|
6147
6174
|
type: "vtxo"
|
|
6148
6175
|
});
|
|
6149
6176
|
if (inputFee.value >= coin.value) {
|
|
@@ -6157,7 +6184,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6157
6184
|
const delegateFee = BigInt(Number(fee));
|
|
6158
6185
|
if (delegateFee > 0n) {
|
|
6159
6186
|
outputs.push({
|
|
6160
|
-
script:
|
|
6187
|
+
script: chunkGMUVWKOK_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
6161
6188
|
amount: delegateFee
|
|
6162
6189
|
});
|
|
6163
6190
|
}
|
|
@@ -6190,10 +6217,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
6190
6217
|
destinationScript
|
|
6191
6218
|
);
|
|
6192
6219
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
6193
|
-
btcSigner.Address(
|
|
6220
|
+
btcSigner.Address(chunkGMUVWKOK_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
6194
6221
|
);
|
|
6195
6222
|
const forfeits = await Promise.all(
|
|
6196
|
-
vtxos.filter((v) => !
|
|
6223
|
+
vtxos.filter((v) => !chunkGMUVWKOK_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
|
|
6197
6224
|
const forfeit = await makeDelegateForfeitTx(
|
|
6198
6225
|
coin,
|
|
6199
6226
|
dust,
|
|
@@ -6218,7 +6245,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
6218
6245
|
index: input.vout,
|
|
6219
6246
|
witnessUtxo: {
|
|
6220
6247
|
amount: BigInt(input.value),
|
|
6221
|
-
script:
|
|
6248
|
+
script: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
6222
6249
|
},
|
|
6223
6250
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
6224
6251
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -6276,7 +6303,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
6276
6303
|
expire_at: 0,
|
|
6277
6304
|
cosigners_public_keys: cosignerPubKeys
|
|
6278
6305
|
};
|
|
6279
|
-
const proof =
|
|
6306
|
+
const proof = chunkGMUVWKOK_cjs.Intent.create(message, coins, outputs);
|
|
6280
6307
|
const signedProof = await identity.sign(proof);
|
|
6281
6308
|
return {
|
|
6282
6309
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -6294,10 +6321,10 @@ function getDayTimestamp(timestamp) {
|
|
|
6294
6321
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
6295
6322
|
if (!vtxo.tapTree) return void 0;
|
|
6296
6323
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
6297
|
-
const vtxoScript =
|
|
6324
|
+
const vtxoScript = chunkGMUVWKOK_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
6298
6325
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
6299
|
-
const arkTapscript =
|
|
6300
|
-
if (!
|
|
6326
|
+
const arkTapscript = chunkGMUVWKOK_cjs.decodeTapscript(chunkGMUVWKOK_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
6327
|
+
if (!chunkGMUVWKOK_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
6301
6328
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
6302
6329
|
});
|
|
6303
6330
|
}
|
|
@@ -6485,7 +6512,7 @@ async function closeDatabase(dbName) {
|
|
|
6485
6512
|
return true;
|
|
6486
6513
|
}
|
|
6487
6514
|
function scriptFromArkAddress(address) {
|
|
6488
|
-
return base.hex.encode(
|
|
6515
|
+
return base.hex.encode(chunkGMUVWKOK_cjs.ArkAddress.decode(address).pkScript);
|
|
6489
6516
|
}
|
|
6490
6517
|
|
|
6491
6518
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -6982,7 +7009,7 @@ function validateVtxosForScript(vtxos, script, context) {
|
|
|
6982
7009
|
}
|
|
6983
7010
|
async function getVtxosForContract(repo, contract) {
|
|
6984
7011
|
const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
|
|
6985
|
-
return vtxos.map(
|
|
7012
|
+
return vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo);
|
|
6986
7013
|
}
|
|
6987
7014
|
async function saveVtxosForContract(repo, contract, vtxos) {
|
|
6988
7015
|
if (repo.saveVtxosForScript) {
|
|
@@ -7186,7 +7213,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
7186
7213
|
const s = base.hex.decode(t.s);
|
|
7187
7214
|
return [cb, s];
|
|
7188
7215
|
};
|
|
7189
|
-
var deserializeVtxo = (o) =>
|
|
7216
|
+
var deserializeVtxo = (o) => chunkGMUVWKOK_cjs.normalizeVtxo({
|
|
7190
7217
|
...o,
|
|
7191
7218
|
createdAt: new Date(o.createdAt),
|
|
7192
7219
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -8325,7 +8352,7 @@ var ContractWatcher = class {
|
|
|
8325
8352
|
this.connectionState = "connected";
|
|
8326
8353
|
this.reconnectAttempts = 0;
|
|
8327
8354
|
this.listenLoop().catch((e) => {
|
|
8328
|
-
if (
|
|
8355
|
+
if (chunkGMUVWKOK_cjs.isEventSourceError(e)) {
|
|
8329
8356
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8330
8357
|
} else {
|
|
8331
8358
|
console.error(e);
|
|
@@ -8554,14 +8581,14 @@ var ContractWatcher = class {
|
|
|
8554
8581
|
const timestamp = Date.now();
|
|
8555
8582
|
if (update.newVtxos?.length) {
|
|
8556
8583
|
this.processSubscriptionVtxos(
|
|
8557
|
-
update.newVtxos.map(
|
|
8584
|
+
update.newVtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo),
|
|
8558
8585
|
"vtxo_received",
|
|
8559
8586
|
timestamp
|
|
8560
8587
|
);
|
|
8561
8588
|
}
|
|
8562
8589
|
if (update.spentVtxos?.length) {
|
|
8563
8590
|
this.processSubscriptionVtxos(
|
|
8564
|
-
update.spentVtxos.map(
|
|
8591
|
+
update.spentVtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo),
|
|
8565
8592
|
"vtxo_spent",
|
|
8566
8593
|
timestamp
|
|
8567
8594
|
);
|
|
@@ -8694,7 +8721,7 @@ async function reconcileIntents(deps) {
|
|
|
8694
8721
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
8695
8722
|
if (outpoints.length > 0) {
|
|
8696
8723
|
try {
|
|
8697
|
-
const { vtxos } = await
|
|
8724
|
+
const { vtxos } = await chunkGMUVWKOK_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
8698
8725
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
8699
8726
|
} catch (e) {
|
|
8700
8727
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -8814,7 +8841,7 @@ var ContractManager = class _ContractManager {
|
|
|
8814
8841
|
await this.reconcileWatched();
|
|
8815
8842
|
this.markSyncOnline();
|
|
8816
8843
|
} catch (err) {
|
|
8817
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
8844
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
8818
8845
|
this.markSyncDegraded(err);
|
|
8819
8846
|
}
|
|
8820
8847
|
this.initialized = true;
|
|
@@ -8926,7 +8953,7 @@ var ContractManager = class _ContractManager {
|
|
|
8926
8953
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
8927
8954
|
const to = watermark + lookAhead.size;
|
|
8928
8955
|
const deps = lookAhead.candidateDeps();
|
|
8929
|
-
const handlers =
|
|
8956
|
+
const handlers = chunk53XNU2EL_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk53XNU2EL_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
8930
8957
|
const band = /* @__PURE__ */ new Map();
|
|
8931
8958
|
for (let index = from; index <= to; index++) {
|
|
8932
8959
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -8937,7 +8964,7 @@ var ContractManager = class _ContractManager {
|
|
|
8937
8964
|
index,
|
|
8938
8965
|
params: {
|
|
8939
8966
|
...candidate,
|
|
8940
|
-
...
|
|
8967
|
+
...chunk53XNU2EL_cjs.speculativeReceiveMetadata(descriptor)
|
|
8941
8968
|
}
|
|
8942
8969
|
});
|
|
8943
8970
|
}
|
|
@@ -8997,7 +9024,7 @@ var ContractManager = class _ContractManager {
|
|
|
8997
9024
|
});
|
|
8998
9025
|
for (const entry of pending) entry.catchUpPending = false;
|
|
8999
9026
|
} catch (err) {
|
|
9000
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
9027
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
9001
9028
|
this.markSyncDegraded(err);
|
|
9002
9029
|
}
|
|
9003
9030
|
}
|
|
@@ -9041,7 +9068,7 @@ var ContractManager = class _ContractManager {
|
|
|
9041
9068
|
await this.fetchContractVxosFromIndexer([contract]);
|
|
9042
9069
|
this.markSyncOnline();
|
|
9043
9070
|
} catch (err) {
|
|
9044
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
9071
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
9045
9072
|
this.markSyncDegraded(err);
|
|
9046
9073
|
}
|
|
9047
9074
|
await this.watcher.addContract(contract);
|
|
@@ -9078,7 +9105,7 @@ var ContractManager = class _ContractManager {
|
|
|
9078
9105
|
return result;
|
|
9079
9106
|
}
|
|
9080
9107
|
async upsertContractRow(params) {
|
|
9081
|
-
const handler =
|
|
9108
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(params.type);
|
|
9082
9109
|
if (!handler) {
|
|
9083
9110
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
9084
9111
|
}
|
|
@@ -9178,7 +9205,7 @@ var ContractManager = class _ContractManager {
|
|
|
9178
9205
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
9179
9206
|
);
|
|
9180
9207
|
}
|
|
9181
|
-
const registered =
|
|
9208
|
+
const registered = chunk53XNU2EL_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk53XNU2EL_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
9182
9209
|
const discoverables = [
|
|
9183
9210
|
...registered.filter((h) => h.type === "boarding"),
|
|
9184
9211
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -9313,7 +9340,7 @@ var ContractManager = class _ContractManager {
|
|
|
9313
9340
|
await this.syncContracts({ contracts, pageSize });
|
|
9314
9341
|
this.markSyncOnline();
|
|
9315
9342
|
} catch (err) {
|
|
9316
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
9343
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
9317
9344
|
this.markSyncDegraded(err);
|
|
9318
9345
|
}
|
|
9319
9346
|
const vtxos = await this.getVtxosForContracts(contracts);
|
|
@@ -9334,7 +9361,7 @@ var ContractManager = class _ContractManager {
|
|
|
9334
9361
|
}
|
|
9335
9362
|
const tapscriptCache = /* @__PURE__ */ new Map();
|
|
9336
9363
|
return vtxos.map(
|
|
9337
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
9364
|
+
(vtxo) => extendVirtualCoinForContract(chunkGMUVWKOK_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
|
|
9338
9365
|
);
|
|
9339
9366
|
}
|
|
9340
9367
|
buildContractsDbFilter(filter) {
|
|
@@ -9419,7 +9446,7 @@ var ContractManager = class _ContractManager {
|
|
|
9419
9446
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
9420
9447
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9421
9448
|
if (!contract) return [];
|
|
9422
|
-
const handler =
|
|
9449
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
9423
9450
|
if (!handler) return [];
|
|
9424
9451
|
const script = handler.createScript(contract.params);
|
|
9425
9452
|
const context = {
|
|
@@ -9439,7 +9466,7 @@ var ContractManager = class _ContractManager {
|
|
|
9439
9466
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
9440
9467
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
9441
9468
|
if (!contract) return [];
|
|
9442
|
-
const handler =
|
|
9469
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
9443
9470
|
if (!handler) return [];
|
|
9444
9471
|
const script = handler.createScript(contract.params);
|
|
9445
9472
|
const context = {
|
|
@@ -9495,7 +9522,7 @@ var ContractManager = class _ContractManager {
|
|
|
9495
9522
|
}
|
|
9496
9523
|
async refreshOutpoints(outpoints) {
|
|
9497
9524
|
if (outpoints.length === 0) return;
|
|
9498
|
-
const { vtxos } = await
|
|
9525
|
+
const { vtxos } = await chunkGMUVWKOK_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
9499
9526
|
outpoints
|
|
9500
9527
|
});
|
|
9501
9528
|
if (vtxos.length === 0) return;
|
|
@@ -9573,7 +9600,7 @@ var ContractManager = class _ContractManager {
|
|
|
9573
9600
|
break;
|
|
9574
9601
|
}
|
|
9575
9602
|
} catch (err) {
|
|
9576
|
-
if (!isRetryableProviderError(err)) throw err;
|
|
9603
|
+
if (!chunkGMUVWKOK_cjs.isRetryableProviderError(err)) throw err;
|
|
9577
9604
|
this.markSyncDegraded(err);
|
|
9578
9605
|
}
|
|
9579
9606
|
this.emitEvent(event);
|
|
@@ -9622,7 +9649,7 @@ var ContractManager = class _ContractManager {
|
|
|
9622
9649
|
*/
|
|
9623
9650
|
async reconcilePendingFrontier(contracts) {
|
|
9624
9651
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
9625
|
-
const vtxos = await
|
|
9652
|
+
const vtxos = await chunkGMUVWKOK_cjs.getAllNormalizedVtxos(
|
|
9626
9653
|
this.config.indexerProvider,
|
|
9627
9654
|
contracts.map((c) => c.script),
|
|
9628
9655
|
{ pendingOnly: true }
|
|
@@ -9703,7 +9730,7 @@ var ContractManager = class _ContractManager {
|
|
|
9703
9730
|
}
|
|
9704
9731
|
return result;
|
|
9705
9732
|
}
|
|
9706
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
9733
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkGMUVWKOK_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9707
9734
|
if (contracts.length === 0) {
|
|
9708
9735
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
9709
9736
|
}
|
|
@@ -9719,7 +9746,7 @@ var ContractManager = class _ContractManager {
|
|
|
9719
9746
|
before: syncWindow.before
|
|
9720
9747
|
}
|
|
9721
9748
|
} : {};
|
|
9722
|
-
const vtxos = await
|
|
9749
|
+
const vtxos = await chunkGMUVWKOK_cjs.getAllNormalizedVtxos(
|
|
9723
9750
|
this.config.indexerProvider,
|
|
9724
9751
|
contracts.map((c) => c.script),
|
|
9725
9752
|
{ ...windowOpts, pageSize }
|
|
@@ -9886,7 +9913,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9886
9913
|
*/
|
|
9887
9914
|
materializeDescriptorAt(index) {
|
|
9888
9915
|
const descriptor = this.identity.descriptor;
|
|
9889
|
-
const network =
|
|
9916
|
+
const network = chunk53XNU2EL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9890
9917
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9891
9918
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9892
9919
|
if (!keyInfo?.keyExpression) {
|
|
@@ -10030,7 +10057,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
10030
10057
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
10031
10058
|
if (!provider) return void 0;
|
|
10032
10059
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
10033
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
10060
|
+
const expectedContractType = setup.offchainTapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
10034
10061
|
const factoryOpts = {
|
|
10035
10062
|
walletRepository: setup.walletRepository,
|
|
10036
10063
|
contractRepository: setup.contractRepository,
|
|
@@ -10229,7 +10256,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
10229
10256
|
};
|
|
10230
10257
|
function deriveLeafPubkey(descriptor) {
|
|
10231
10258
|
try {
|
|
10232
|
-
return
|
|
10259
|
+
return chunk53XNU2EL_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
10233
10260
|
} catch (e) {
|
|
10234
10261
|
throw new NonRangeableDescriptorError(
|
|
10235
10262
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -10241,7 +10268,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
10241
10268
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
10242
10269
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
10243
10270
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
10244
|
-
const csvTimelock =
|
|
10271
|
+
const csvTimelock = chunkGMUVWKOK_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
10245
10272
|
const base$1 = {
|
|
10246
10273
|
script: base.hex.encode(tapscript.pkScript),
|
|
10247
10274
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -10252,11 +10279,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
10252
10279
|
// index-0 key. Without it, spends produce unsigned PSBTs that the
|
|
10253
10280
|
// server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
10254
10281
|
metadata: {
|
|
10255
|
-
...{ source:
|
|
10282
|
+
...{ source: chunk53XNU2EL_cjs.WALLET_RECEIVE_SOURCE },
|
|
10256
10283
|
signingDescriptor: descriptor
|
|
10257
10284
|
}
|
|
10258
10285
|
};
|
|
10259
|
-
const params = tapscript instanceof
|
|
10286
|
+
const params = tapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? {
|
|
10260
10287
|
...base$1,
|
|
10261
10288
|
type: "delegate",
|
|
10262
10289
|
params: {
|
|
@@ -10277,10 +10304,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
10277
10304
|
return { tapscript, params };
|
|
10278
10305
|
}
|
|
10279
10306
|
function rebuildTapscript(current, pubKey) {
|
|
10280
|
-
if (current instanceof
|
|
10281
|
-
return new
|
|
10307
|
+
if (current instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script) {
|
|
10308
|
+
return new chunk53XNU2EL_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
10282
10309
|
}
|
|
10283
|
-
return new
|
|
10310
|
+
return new chunk53XNU2EL_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
10284
10311
|
}
|
|
10285
10312
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
10286
10313
|
const candidates = await contractRepository.getContracts({
|
|
@@ -10289,7 +10316,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
10289
10316
|
});
|
|
10290
10317
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
10291
10318
|
const matching = candidates.filter(
|
|
10292
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10319
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk53XNU2EL_cjs.WALLET_RECEIVE_SOURCE
|
|
10293
10320
|
).sort((a, b) => {
|
|
10294
10321
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10295
10322
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10465,12 +10492,12 @@ var InputSignerRouter = class {
|
|
|
10465
10492
|
};
|
|
10466
10493
|
|
|
10467
10494
|
// src/wallet/wallet.ts
|
|
10468
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
10495
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkGMUVWKOK_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
10469
10496
|
function intentProofJobs(coins) {
|
|
10470
10497
|
if (coins.length === 0) return [];
|
|
10471
10498
|
const coinJobs = coins.map((coin, i) => ({
|
|
10472
10499
|
index: i + 1,
|
|
10473
|
-
lookupScript:
|
|
10500
|
+
lookupScript: chunkGMUVWKOK_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
10474
10501
|
}));
|
|
10475
10502
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
10476
10503
|
}
|
|
@@ -10495,7 +10522,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
10495
10522
|
const seen = /* @__PURE__ */ new Set();
|
|
10496
10523
|
const deduped = [];
|
|
10497
10524
|
for (const timelock of timelocks) {
|
|
10498
|
-
const sequence =
|
|
10525
|
+
const sequence = chunkGMUVWKOK_cjs.timelockToSequence(timelock).toString();
|
|
10499
10526
|
if (seen.has(sequence)) continue;
|
|
10500
10527
|
seen.add(sequence);
|
|
10501
10528
|
deduped.push(timelock);
|
|
@@ -10512,7 +10539,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10512
10539
|
state: "active"
|
|
10513
10540
|
});
|
|
10514
10541
|
const newest = candidates.filter(
|
|
10515
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10542
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk53XNU2EL_cjs.WALLET_RECEIVE_SOURCE
|
|
10516
10543
|
).sort((a, b) => {
|
|
10517
10544
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
10518
10545
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -10520,7 +10547,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
10520
10547
|
if (!newest?.params.pubKey) return baseline;
|
|
10521
10548
|
try {
|
|
10522
10549
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
10523
|
-
return new
|
|
10550
|
+
return new chunk53XNU2EL_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
10524
10551
|
} catch (e) {
|
|
10525
10552
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
10526
10553
|
return baseline;
|
|
@@ -10840,7 +10867,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10840
10867
|
*/
|
|
10841
10868
|
static async setupWalletConfig(config, pubKey) {
|
|
10842
10869
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10843
|
-
const arkProvider = config.arkProvider || new
|
|
10870
|
+
const arkProvider = config.arkProvider || new chunkGMUVWKOK_cjs.RestArkProvider(arkadeServerUrl);
|
|
10844
10871
|
let indexerProvider = config.indexerProvider;
|
|
10845
10872
|
if (!indexerProvider) {
|
|
10846
10873
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10857,7 +10884,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10857
10884
|
indexerUrl = arkadeServerUrl;
|
|
10858
10885
|
}
|
|
10859
10886
|
}
|
|
10860
|
-
indexerProvider = new
|
|
10887
|
+
indexerProvider = new chunkRNECH3TA_cjs.RestIndexerProvider(indexerUrl);
|
|
10861
10888
|
}
|
|
10862
10889
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10863
10890
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10866,7 +10893,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10866
10893
|
source: serverInfoSource,
|
|
10867
10894
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
10868
10895
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
10869
|
-
const network =
|
|
10896
|
+
const network = chunkGMUVWKOK_cjs.getNetwork(info.network);
|
|
10870
10897
|
if ("descriptor" in config.identity) {
|
|
10871
10898
|
const descriptor = config.identity.descriptor;
|
|
10872
10899
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -10913,11 +10940,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10913
10940
|
serverPubKey,
|
|
10914
10941
|
csvTimelock: exitTimelock
|
|
10915
10942
|
};
|
|
10916
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10917
|
-
const boardingTapscript =
|
|
10943
|
+
const offchainTapscript = !delegatePubKey ? new chunk53XNU2EL_cjs.DefaultVtxo.Script(offchainOptions) : new chunk53XNU2EL_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
10944
|
+
const boardingTapscript = chunk53XNU2EL_cjs.BoardingContractHandler.createScript({
|
|
10918
10945
|
pubKey: base.hex.encode(pubKey),
|
|
10919
10946
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10920
|
-
csvTimelock:
|
|
10947
|
+
csvTimelock: chunkGMUVWKOK_cjs.timelockToSequence(boardingTimelock).toString()
|
|
10921
10948
|
});
|
|
10922
10949
|
return {
|
|
10923
10950
|
arkProvider,
|
|
@@ -11023,19 +11050,19 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11023
11050
|
let pendingRecovery = 0;
|
|
11024
11051
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
11025
11052
|
const settled = vtxos.filter(
|
|
11026
|
-
(coin) =>
|
|
11053
|
+
(coin) => chunkGMUVWKOK_cjs.canSpendOffchain(coin, now) && !coin.isPreconfirmed && !isPendingRecovery(coin)
|
|
11027
11054
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
11028
11055
|
const preconfirmed = vtxos.filter(
|
|
11029
|
-
(coin) =>
|
|
11056
|
+
(coin) => chunkGMUVWKOK_cjs.canSpendOffchain(coin, now) && coin.isPreconfirmed && !isPendingRecovery(coin)
|
|
11030
11057
|
).reduce((sum, coin) => sum + coin.value, 0);
|
|
11031
|
-
const available = unlockedVtxos.filter((coin) =>
|
|
11032
|
-
recoverable = vtxos.filter((coin) =>
|
|
11058
|
+
const available = unlockedVtxos.filter((coin) => chunkGMUVWKOK_cjs.canSpendOffchain(coin, now) && !isPendingRecovery(coin)).reduce((sum, coin) => sum + coin.value, 0);
|
|
11059
|
+
recoverable = vtxos.filter((coin) => chunkGMUVWKOK_cjs.canRecoverOnchain(coin, now) && !isPendingRecovery(coin)).reduce((sum, coin) => sum + coin.value, 0);
|
|
11033
11060
|
pendingRecovery = vtxos.filter(isPendingRecovery).reduce((sum, coin) => sum + coin.value, 0);
|
|
11034
11061
|
const totalBoarding = confirmed + unconfirmed;
|
|
11035
11062
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
11036
11063
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
11037
11064
|
for (const vtxo of vtxos) {
|
|
11038
|
-
if (
|
|
11065
|
+
if (chunkGMUVWKOK_cjs.hasTerminalSpend(vtxo)) continue;
|
|
11039
11066
|
if (vtxo.assets) {
|
|
11040
11067
|
for (const a of vtxo.assets) {
|
|
11041
11068
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -11076,8 +11103,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11076
11103
|
if (this._pendingSpendOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
11077
11104
|
return false;
|
|
11078
11105
|
}
|
|
11079
|
-
if (!
|
|
11080
|
-
if (!f.withRecoverable &&
|
|
11106
|
+
if (!chunkGMUVWKOK_cjs.hasTerminalSpend(vtxo)) {
|
|
11107
|
+
if (!f.withRecoverable && chunkGMUVWKOK_cjs.canRecoverOnchain(vtxo, now)) {
|
|
11081
11108
|
return false;
|
|
11082
11109
|
}
|
|
11083
11110
|
return true;
|
|
@@ -11110,11 +11137,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11110
11137
|
const response = await contractManager.getContractsWithVtxos();
|
|
11111
11138
|
const allVtxos = response.flatMap((_) => _.vtxos);
|
|
11112
11139
|
const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
|
|
11113
|
-
const
|
|
11114
|
-
|
|
11115
|
-
|
|
11116
|
-
|
|
11117
|
-
|
|
11140
|
+
const resolveTxCreatedAt = (txids) => chunkGMUVWKOK_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
11141
|
+
return buildTransactionHistory(
|
|
11142
|
+
allVtxos,
|
|
11143
|
+
boardingTxs,
|
|
11144
|
+
commitmentsToIgnore,
|
|
11145
|
+
resolveTxCreatedAt
|
|
11146
|
+
);
|
|
11118
11147
|
}
|
|
11119
11148
|
/**
|
|
11120
11149
|
* Wallet history grouped by registered activity resolvers. With no resolver match,
|
|
@@ -11202,7 +11231,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11202
11231
|
},
|
|
11203
11232
|
isUnrolled: true,
|
|
11204
11233
|
...boardingFacts,
|
|
11205
|
-
virtualStatus:
|
|
11234
|
+
virtualStatus: chunkGMUVWKOK_cjs.toVirtualStatus(boardingFacts),
|
|
11206
11235
|
spentBy: "",
|
|
11207
11236
|
createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
|
|
11208
11237
|
script: scriptHex
|
|
@@ -11258,9 +11287,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11258
11287
|
async getBoardingTapscripts(allowedSigners) {
|
|
11259
11288
|
const byScript = /* @__PURE__ */ new Map();
|
|
11260
11289
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
11261
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
11290
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunk53XNU2EL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11262
11291
|
add(
|
|
11263
|
-
new
|
|
11292
|
+
new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
11264
11293
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
11265
11294
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
11266
11295
|
csvTimelock: boardingCsv
|
|
@@ -11275,7 +11304,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11275
11304
|
for (const c of boardingContracts) {
|
|
11276
11305
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
11277
11306
|
try {
|
|
11278
|
-
add(
|
|
11307
|
+
add(chunk53XNU2EL_cjs.BoardingContractHandler.createScript(c.params));
|
|
11279
11308
|
} catch (e) {
|
|
11280
11309
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
11281
11310
|
}
|
|
@@ -11313,7 +11342,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11313
11342
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
11314
11343
|
// not the wallet's current boarding timelock, which a signer
|
|
11315
11344
|
// rotation may have changed.
|
|
11316
|
-
csvTimelock:
|
|
11345
|
+
csvTimelock: chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
11317
11346
|
coins: utxos
|
|
11318
11347
|
});
|
|
11319
11348
|
}
|
|
@@ -11446,7 +11475,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11446
11475
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
11447
11476
|
async fetchPendingTxs() {
|
|
11448
11477
|
const scripts = await this.getWalletScripts();
|
|
11449
|
-
const vtxos = await
|
|
11478
|
+
const vtxos = await chunkGMUVWKOK_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
11450
11479
|
return vtxos.filter(
|
|
11451
11480
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
11452
11481
|
).map((_) => _.arkTxId);
|
|
@@ -11477,7 +11506,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11477
11506
|
});
|
|
11478
11507
|
for (const contract of contracts) {
|
|
11479
11508
|
if (map.has(contract.script)) continue;
|
|
11480
|
-
const handler =
|
|
11509
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
11481
11510
|
if (handler) {
|
|
11482
11511
|
const script = handler.createScript(contract.params);
|
|
11483
11512
|
map.set(contract.script, script);
|
|
@@ -11580,7 +11609,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11580
11609
|
lookAhead: this.lookAheadConfig()
|
|
11581
11610
|
});
|
|
11582
11611
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
11583
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11612
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11584
11613
|
const baselineSigners = [
|
|
11585
11614
|
this.offchainTapscript.options.serverPubKey,
|
|
11586
11615
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -11588,8 +11617,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11588
11617
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
11589
11618
|
for (const serverPubKey of baselineSigners) {
|
|
11590
11619
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
11591
|
-
const csvTimelockStr =
|
|
11592
|
-
const defaultScript = new
|
|
11620
|
+
const csvTimelockStr = chunkGMUVWKOK_cjs.timelockToSequence(csvTimelock).toString();
|
|
11621
|
+
const defaultScript = new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
11593
11622
|
pubKey: baselinePubkey,
|
|
11594
11623
|
serverPubKey,
|
|
11595
11624
|
csvTimelock
|
|
@@ -11610,7 +11639,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11610
11639
|
});
|
|
11611
11640
|
}
|
|
11612
11641
|
if (delegatePubKey) {
|
|
11613
|
-
const delegateScript = new
|
|
11642
|
+
const delegateScript = new chunk53XNU2EL_cjs.DelegateVtxo.Script({
|
|
11614
11643
|
pubKey: baselinePubkey,
|
|
11615
11644
|
serverPubKey,
|
|
11616
11645
|
delegatePubKey,
|
|
@@ -11634,9 +11663,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11634
11663
|
}
|
|
11635
11664
|
}
|
|
11636
11665
|
}
|
|
11637
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11666
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunk53XNU2EL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11638
11667
|
for (const serverPubKey of baselineSigners) {
|
|
11639
|
-
const baselineBoarding = new
|
|
11668
|
+
const baselineBoarding = new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
11640
11669
|
pubKey: baselinePubkey,
|
|
11641
11670
|
serverPubKey,
|
|
11642
11671
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11649,7 +11678,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11649
11678
|
params: {
|
|
11650
11679
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
11651
11680
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
11652
|
-
csvTimelock:
|
|
11681
|
+
csvTimelock: chunkGMUVWKOK_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
11653
11682
|
},
|
|
11654
11683
|
script: boardingScriptHex,
|
|
11655
11684
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -11823,7 +11852,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11823
11852
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
11824
11853
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
11825
11854
|
csvTimelocks: this.walletContractTimelocks,
|
|
11826
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
11855
|
+
delegatePubKey: this.offchainTapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
11827
11856
|
};
|
|
11828
11857
|
}
|
|
11829
11858
|
_signerRouter;
|
|
@@ -11915,25 +11944,25 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11915
11944
|
return this.getBoardingAddress();
|
|
11916
11945
|
}
|
|
11917
11946
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11918
|
-
const pubKey =
|
|
11919
|
-
const newBoarding = new
|
|
11947
|
+
const pubKey = chunk53XNU2EL_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11948
|
+
const newBoarding = new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
11920
11949
|
...this._boardingTapscript.options,
|
|
11921
11950
|
pubKey
|
|
11922
11951
|
});
|
|
11923
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11952
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunk53XNU2EL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11924
11953
|
const manager = await this.getContractManager();
|
|
11925
11954
|
await manager.createContract({
|
|
11926
11955
|
type: "boarding",
|
|
11927
11956
|
params: {
|
|
11928
11957
|
pubKey: base.hex.encode(pubKey),
|
|
11929
11958
|
serverPubKey: base.hex.encode(newBoarding.options.serverPubKey),
|
|
11930
|
-
csvTimelock:
|
|
11959
|
+
csvTimelock: chunkGMUVWKOK_cjs.timelockToSequence(csvTimelock).toString()
|
|
11931
11960
|
},
|
|
11932
11961
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11933
11962
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11934
11963
|
state: "active",
|
|
11935
11964
|
metadata: {
|
|
11936
|
-
source:
|
|
11965
|
+
source: chunk53XNU2EL_cjs.WALLET_RECEIVE_SOURCE,
|
|
11937
11966
|
signingDescriptor: descriptor
|
|
11938
11967
|
}
|
|
11939
11968
|
});
|
|
@@ -11977,7 +12006,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11977
12006
|
const xonly = toXOnlyPubKey(newServerPubKey);
|
|
11978
12007
|
let newServerUnrollScript;
|
|
11979
12008
|
try {
|
|
11980
|
-
newServerUnrollScript =
|
|
12009
|
+
newServerUnrollScript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
11981
12010
|
} catch (e) {
|
|
11982
12011
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11983
12012
|
}
|
|
@@ -12005,21 +12034,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12005
12034
|
const [currentBoardingRow] = await manager.getContracts({
|
|
12006
12035
|
script: currentBoardingScript
|
|
12007
12036
|
});
|
|
12008
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
12037
|
+
const newOffchain = this.offchainTapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? new chunk53XNU2EL_cjs.DelegateVtxo.Script({
|
|
12009
12038
|
...this.offchainTapscript.options,
|
|
12010
12039
|
serverPubKey: xonly
|
|
12011
|
-
}) : new
|
|
12040
|
+
}) : new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
12012
12041
|
...this.offchainTapscript.options,
|
|
12013
12042
|
serverPubKey: xonly
|
|
12014
12043
|
});
|
|
12015
|
-
const newBoarding = new
|
|
12044
|
+
const newBoarding = new chunk53XNU2EL_cjs.DefaultVtxo.Script({
|
|
12016
12045
|
...this._boardingTapscript.options,
|
|
12017
12046
|
serverPubKey: xonly
|
|
12018
12047
|
});
|
|
12019
|
-
const offchainCsv =
|
|
12048
|
+
const offchainCsv = chunkGMUVWKOK_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
12020
12049
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
12021
12050
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
12022
|
-
if (newOffchain instanceof
|
|
12051
|
+
if (newOffchain instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script) {
|
|
12023
12052
|
await manager.createContract({
|
|
12024
12053
|
type: "delegate",
|
|
12025
12054
|
params: {
|
|
@@ -12047,13 +12076,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12047
12076
|
metadata: currentOffchainRow?.metadata
|
|
12048
12077
|
});
|
|
12049
12078
|
}
|
|
12050
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
12079
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunk53XNU2EL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
12051
12080
|
await manager.createContract({
|
|
12052
12081
|
type: "boarding",
|
|
12053
12082
|
params: {
|
|
12054
12083
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
12055
12084
|
serverPubKey: base.hex.encode(xonly),
|
|
12056
|
-
csvTimelock:
|
|
12085
|
+
csvTimelock: chunkGMUVWKOK_cjs.timelockToSequence(boardingCsv).toString()
|
|
12057
12086
|
},
|
|
12058
12087
|
script: base.hex.encode(newBoarding.pkScript),
|
|
12059
12088
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -12086,14 +12115,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12086
12115
|
_restoreInFlight;
|
|
12087
12116
|
_addPendingSpends(inputs) {
|
|
12088
12117
|
for (const input of inputs) {
|
|
12089
|
-
if (
|
|
12118
|
+
if (chunkGMUVWKOK_cjs.isVirtualCoin(input)) {
|
|
12090
12119
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
12091
12120
|
}
|
|
12092
12121
|
}
|
|
12093
12122
|
}
|
|
12094
12123
|
_removePendingSpends(inputs) {
|
|
12095
12124
|
for (const input of inputs) {
|
|
12096
|
-
if (
|
|
12125
|
+
if (chunkGMUVWKOK_cjs.isVirtualCoin(input)) {
|
|
12097
12126
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
12098
12127
|
}
|
|
12099
12128
|
}
|
|
@@ -12153,7 +12182,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12153
12182
|
const hd = provider instanceof HDDescriptorProvider;
|
|
12154
12183
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
12155
12184
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
12156
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
12185
|
+
const delegatePubKey = this.offchainTapscript instanceof chunk53XNU2EL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
12157
12186
|
const arkInfo = await this.arkProvider.getInfo();
|
|
12158
12187
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
12159
12188
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -12172,7 +12201,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12172
12201
|
csvTimelocks: this.walletContractTimelocks,
|
|
12173
12202
|
// Boarding-exit CSV so the boarding handler can build its
|
|
12174
12203
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
12175
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
12204
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunk53XNU2EL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
12176
12205
|
delegatePubKey
|
|
12177
12206
|
};
|
|
12178
12207
|
const result = await manager.scanContracts({
|
|
@@ -12289,7 +12318,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12289
12318
|
let serverUnrollScript;
|
|
12290
12319
|
try {
|
|
12291
12320
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
12292
|
-
serverUnrollScript =
|
|
12321
|
+
serverUnrollScript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(raw);
|
|
12293
12322
|
} catch (e) {
|
|
12294
12323
|
throw new Error("Invalid checkpointTapscript from server");
|
|
12295
12324
|
}
|
|
@@ -12427,7 +12456,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12427
12456
|
inputs: params.selectedVtxos,
|
|
12428
12457
|
changeAmount: BigInt(changeAmount)
|
|
12429
12458
|
};
|
|
12430
|
-
const outputAddress =
|
|
12459
|
+
const outputAddress = chunkGMUVWKOK_cjs.ArkAddress.decode(params.address);
|
|
12431
12460
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
12432
12461
|
const outputs = [
|
|
12433
12462
|
{
|
|
@@ -12480,13 +12509,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12480
12509
|
}
|
|
12481
12510
|
}
|
|
12482
12511
|
const offchainAddress = await this.getAddress();
|
|
12483
|
-
const offchainPkScript =
|
|
12512
|
+
const offchainPkScript = chunkGMUVWKOK_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
12484
12513
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
12485
12514
|
if (!params) {
|
|
12486
12515
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
12487
12516
|
const estimator = new Estimator(fees.intentFee);
|
|
12488
12517
|
let amount = 0;
|
|
12489
|
-
const exitScript =
|
|
12518
|
+
const exitScript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(
|
|
12490
12519
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
12491
12520
|
);
|
|
12492
12521
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -12515,7 +12544,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12515
12544
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
12516
12545
|
break;
|
|
12517
12546
|
}
|
|
12518
|
-
const inputFee = estimator.evalOffchainInput(
|
|
12547
|
+
const inputFee = estimator.evalOffchainInput(chunkGMUVWKOK_cjs.toOffchainInputFeeParams(vtxo));
|
|
12519
12548
|
if (inputFee.satoshis >= vtxo.value) {
|
|
12520
12549
|
continue;
|
|
12521
12550
|
}
|
|
@@ -12560,7 +12589,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12560
12589
|
for (const [index, output] of params.outputs.entries()) {
|
|
12561
12590
|
let script;
|
|
12562
12591
|
try {
|
|
12563
|
-
const addr =
|
|
12592
|
+
const addr = chunkGMUVWKOK_cjs.ArkAddress.decode(output.address);
|
|
12564
12593
|
script = addr.pkScript;
|
|
12565
12594
|
hasOffchainOutputs = true;
|
|
12566
12595
|
} catch {
|
|
@@ -12746,7 +12775,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12746
12775
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
12747
12776
|
if (!this._descriptorProvider) return;
|
|
12748
12777
|
const consumedBoarding = inputs.some(
|
|
12749
|
-
(input) => typeof input !== "string" && !
|
|
12778
|
+
(input) => typeof input !== "string" && !chunkGMUVWKOK_cjs.isVirtualCoin(input)
|
|
12750
12779
|
);
|
|
12751
12780
|
if (!consumedBoarding) return;
|
|
12752
12781
|
try {
|
|
@@ -12762,7 +12791,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12762
12791
|
let connectorIndex = 0;
|
|
12763
12792
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
12764
12793
|
for (const input of inputs) {
|
|
12765
|
-
if (!
|
|
12794
|
+
if (!chunkGMUVWKOK_cjs.isVirtualCoin(input)) {
|
|
12766
12795
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
12767
12796
|
const settlementInput = settlementPsbt.getInput(i);
|
|
12768
12797
|
if (!settlementInput.txid || settlementInput.index === void 0) {
|
|
@@ -12793,7 +12822,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12793
12822
|
}
|
|
12794
12823
|
continue;
|
|
12795
12824
|
}
|
|
12796
|
-
if (
|
|
12825
|
+
if (chunkGMUVWKOK_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
12797
12826
|
continue;
|
|
12798
12827
|
}
|
|
12799
12828
|
if (connectorsLeaves.length === 0) {
|
|
@@ -12821,7 +12850,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12821
12850
|
index: input.vout,
|
|
12822
12851
|
witnessUtxo: {
|
|
12823
12852
|
amount: BigInt(input.value),
|
|
12824
|
-
script:
|
|
12853
|
+
script: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12825
12854
|
},
|
|
12826
12855
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
12827
12856
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -12840,7 +12869,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12840
12869
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
12841
12870
|
{
|
|
12842
12871
|
index: 0,
|
|
12843
|
-
lookupScript:
|
|
12872
|
+
lookupScript: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12844
12873
|
}
|
|
12845
12874
|
]);
|
|
12846
12875
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -12898,7 +12927,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12898
12927
|
if (skip) {
|
|
12899
12928
|
return { skip };
|
|
12900
12929
|
}
|
|
12901
|
-
const sweepTapscript =
|
|
12930
|
+
const sweepTapscript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.encode({
|
|
12902
12931
|
timelock: {
|
|
12903
12932
|
value: event.batchExpiry,
|
|
12904
12933
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -13004,9 +13033,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13004
13033
|
...existing ?? {},
|
|
13005
13034
|
intentTxId,
|
|
13006
13035
|
registerProof: intent.proof,
|
|
13007
|
-
registerProofMessage:
|
|
13036
|
+
registerProofMessage: chunkGMUVWKOK_cjs.Intent.encodeMessage(intent.message),
|
|
13008
13037
|
deleteProof: deleteIntent.proof,
|
|
13009
|
-
deleteProofMessage:
|
|
13038
|
+
deleteProofMessage: chunkGMUVWKOK_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
13010
13039
|
intentVtxos: inputs.map((i) => ({
|
|
13011
13040
|
txid: i.txid,
|
|
13012
13041
|
vout: i.vout
|
|
@@ -13038,7 +13067,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13038
13067
|
try {
|
|
13039
13068
|
return await this.arkProvider.registerIntent(intent);
|
|
13040
13069
|
} catch (error) {
|
|
13041
|
-
if (error instanceof
|
|
13070
|
+
if (error instanceof chunkGMUVWKOK_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
13042
13071
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
13043
13072
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
13044
13073
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -13054,7 +13083,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13054
13083
|
expire_at: 0,
|
|
13055
13084
|
cosigners_public_keys: cosignerPubKeys
|
|
13056
13085
|
};
|
|
13057
|
-
const proof =
|
|
13086
|
+
const proof = chunkGMUVWKOK_cjs.Intent.create(message, coins, outputs);
|
|
13058
13087
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
13059
13088
|
return {
|
|
13060
13089
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -13066,7 +13095,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13066
13095
|
type: "delete",
|
|
13067
13096
|
expire_at: 0
|
|
13068
13097
|
};
|
|
13069
|
-
const proof =
|
|
13098
|
+
const proof = chunkGMUVWKOK_cjs.Intent.create(message, coins, []);
|
|
13070
13099
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
13071
13100
|
return {
|
|
13072
13101
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -13078,7 +13107,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13078
13107
|
type: "get-pending-tx",
|
|
13079
13108
|
expire_at: 0
|
|
13080
13109
|
};
|
|
13081
|
-
const proof =
|
|
13110
|
+
const proof = chunkGMUVWKOK_cjs.Intent.create(message, coins, []);
|
|
13082
13111
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
13083
13112
|
return {
|
|
13084
13113
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -13099,7 +13128,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13099
13128
|
if (!vtxos || vtxos.length === 0) {
|
|
13100
13129
|
const scriptMap = await this.getScriptMap();
|
|
13101
13130
|
const allExtended = [];
|
|
13102
|
-
const fetchedVtxos = await
|
|
13131
|
+
const fetchedVtxos = await chunkGMUVWKOK_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
13103
13132
|
...scriptMap.keys()
|
|
13104
13133
|
]);
|
|
13105
13134
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -13271,7 +13300,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13271
13300
|
if (vtxos.length === 0) {
|
|
13272
13301
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
13273
13302
|
}
|
|
13274
|
-
const myPkScript =
|
|
13303
|
+
const myPkScript = chunkGMUVWKOK_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
13275
13304
|
let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
13276
13305
|
let swept = 0;
|
|
13277
13306
|
const drainable = vtxos.filter((vtxo) => !isSubdust(vtxo, this.dustAmount));
|
|
@@ -13298,7 +13327,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13298
13327
|
}
|
|
13299
13328
|
if (spendable.length > 0) {
|
|
13300
13329
|
const info = await this.arkProvider.getInfo();
|
|
13301
|
-
const serverUnrollScript =
|
|
13330
|
+
const serverUnrollScript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(
|
|
13302
13331
|
base.hex.decode(info.checkpointTapscript)
|
|
13303
13332
|
);
|
|
13304
13333
|
for (const vtxo of spendable) {
|
|
@@ -13344,7 +13373,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13344
13373
|
const spendable = [];
|
|
13345
13374
|
const unclaimed = [];
|
|
13346
13375
|
for (const vtxo of vtxos) {
|
|
13347
|
-
if (
|
|
13376
|
+
if (chunkGMUVWKOK_cjs.hasTerminalSpend(vtxo)) {
|
|
13348
13377
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
13349
13378
|
} else if (isSubdust(vtxo, this.dustAmount)) {
|
|
13350
13379
|
unclaimed.push(cashReport(vtxo, "subdust"));
|
|
@@ -13364,7 +13393,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13364
13393
|
const all = [];
|
|
13365
13394
|
const seen = /* @__PURE__ */ new Set();
|
|
13366
13395
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
13367
|
-
const { vtxos, page } = await
|
|
13396
|
+
const { vtxos, page } = await chunkGMUVWKOK_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
13368
13397
|
scripts,
|
|
13369
13398
|
pageIndex,
|
|
13370
13399
|
pageSize
|
|
@@ -13411,7 +13440,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13411
13440
|
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
|
|
13412
13441
|
const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
|
|
13413
13442
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
13414
|
-
const proof =
|
|
13443
|
+
const proof = chunkGMUVWKOK_cjs.Intent.create(message, batch, []);
|
|
13415
13444
|
const signedProof = await identity.sign(
|
|
13416
13445
|
proof,
|
|
13417
13446
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -13706,10 +13735,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13706
13735
|
const serverPubKey = this.arkServerPublicKey;
|
|
13707
13736
|
const serverUnrollScript = this.serverUnrollScript;
|
|
13708
13737
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
13709
|
-
const normalizedInputs = inputs.map(
|
|
13710
|
-
const at = now ?? await
|
|
13738
|
+
const normalizedInputs = inputs.map(chunkGMUVWKOK_cjs.normalizeVtxo);
|
|
13739
|
+
const at = now ?? await chunkGMUVWKOK_cjs.resolveTimeHeight(this.onchainProvider);
|
|
13711
13740
|
for (const input of normalizedInputs) {
|
|
13712
|
-
if (!
|
|
13741
|
+
if (!chunkGMUVWKOK_cjs.canSpendOffchain(input, at)) {
|
|
13713
13742
|
throw new Error(
|
|
13714
13743
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
13715
13744
|
);
|
|
@@ -13774,7 +13803,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13774
13803
|
);
|
|
13775
13804
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
13776
13805
|
index,
|
|
13777
|
-
lookupScript:
|
|
13806
|
+
lookupScript: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
13778
13807
|
}));
|
|
13779
13808
|
const identity = this.identity;
|
|
13780
13809
|
const signer = {
|
|
@@ -13852,21 +13881,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13852
13881
|
);
|
|
13853
13882
|
spentVtxos.push({
|
|
13854
13883
|
...spentFacts,
|
|
13855
|
-
virtualStatus:
|
|
13884
|
+
virtualStatus: chunkGMUVWKOK_cjs.toVirtualStatus(spentFacts),
|
|
13856
13885
|
spentBy: checkpoint.id,
|
|
13857
13886
|
arkTxId: arkTxid
|
|
13858
13887
|
});
|
|
13859
13888
|
} else {
|
|
13860
13889
|
spentVtxos.push({
|
|
13861
13890
|
...spentFacts,
|
|
13862
|
-
virtualStatus:
|
|
13891
|
+
virtualStatus: chunkGMUVWKOK_cjs.toVirtualStatus(spentFacts),
|
|
13863
13892
|
arkTxId: arkTxid
|
|
13864
13893
|
});
|
|
13865
13894
|
}
|
|
13866
13895
|
for (const id of vtxo.commitmentTxIds) {
|
|
13867
13896
|
commitmentTxIds.add(id);
|
|
13868
13897
|
}
|
|
13869
|
-
const vtxoExpiry =
|
|
13898
|
+
const vtxoExpiry = chunkGMUVWKOK_cjs.toBatchExpiry(vtxo);
|
|
13870
13899
|
if (vtxoExpiry) {
|
|
13871
13900
|
batchExpiry = Math.min(batchExpiry, vtxoExpiry);
|
|
13872
13901
|
}
|
|
@@ -13879,7 +13908,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13879
13908
|
isSwept: false,
|
|
13880
13909
|
isPreconfirmed: true,
|
|
13881
13910
|
commitmentTxIds: Array.from(commitmentTxIds),
|
|
13882
|
-
...
|
|
13911
|
+
...chunkGMUVWKOK_cjs.parseLegacyExpiry(batchExpiry)
|
|
13883
13912
|
};
|
|
13884
13913
|
changeVtxo = {
|
|
13885
13914
|
txid: arkTxid,
|
|
@@ -13891,7 +13920,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13891
13920
|
tapTree: offchainTapscript.encode(),
|
|
13892
13921
|
value: Number(changeAmount),
|
|
13893
13922
|
...changeFacts,
|
|
13894
|
-
virtualStatus:
|
|
13923
|
+
virtualStatus: chunkGMUVWKOK_cjs.toVirtualStatus(changeFacts),
|
|
13895
13924
|
spentBy: "",
|
|
13896
13925
|
status: {
|
|
13897
13926
|
confirmed: false
|
|
@@ -13960,12 +13989,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13960
13989
|
const spentVtxos = [];
|
|
13961
13990
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
13962
13991
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
13963
|
-
const vtxoInputs = inputs.filter(
|
|
13992
|
+
const vtxoInputs = inputs.filter(chunkGMUVWKOK_cjs.isVirtualCoin);
|
|
13964
13993
|
const cm = await this.getContractManager();
|
|
13965
13994
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
13966
13995
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
13967
13996
|
for (const input of inputs) {
|
|
13968
|
-
if (
|
|
13997
|
+
if (chunkGMUVWKOK_cjs.isVirtualCoin(input)) {
|
|
13969
13998
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
13970
13999
|
const vtxo = annotatedByKey.get(outpoint);
|
|
13971
14000
|
if (!vtxo) {
|
|
@@ -13977,13 +14006,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13977
14006
|
const settledFacts = { ...vtxo, isSpent: true };
|
|
13978
14007
|
spentVtxos.push({
|
|
13979
14008
|
...settledFacts,
|
|
13980
|
-
virtualStatus:
|
|
14009
|
+
virtualStatus: chunkGMUVWKOK_cjs.toVirtualStatus(settledFacts),
|
|
13981
14010
|
settledBy: commitmentTxid
|
|
13982
14011
|
});
|
|
13983
14012
|
} else {
|
|
13984
14013
|
let sourceAddress;
|
|
13985
14014
|
try {
|
|
13986
|
-
sourceAddress =
|
|
14015
|
+
sourceAddress = chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
13987
14016
|
this.network
|
|
13988
14017
|
);
|
|
13989
14018
|
} catch {
|
|
@@ -14041,9 +14070,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
14041
14070
|
}
|
|
14042
14071
|
};
|
|
14043
14072
|
function selectVirtualCoins(coins, targetAmount) {
|
|
14044
|
-
const sortedCoins = coins.map(
|
|
14045
|
-
const expiryA =
|
|
14046
|
-
const expiryB =
|
|
14073
|
+
const sortedCoins = coins.map(chunkGMUVWKOK_cjs.normalizeVtxo).sort((a, b) => {
|
|
14074
|
+
const expiryA = chunkGMUVWKOK_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
|
|
14075
|
+
const expiryB = chunkGMUVWKOK_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
|
|
14047
14076
|
if (expiryA !== expiryB) {
|
|
14048
14077
|
return expiryA - expiryB;
|
|
14049
14078
|
}
|
|
@@ -14300,7 +14329,7 @@ var MessageBus = class {
|
|
|
14300
14329
|
this.initialized = true;
|
|
14301
14330
|
}
|
|
14302
14331
|
async buildServices(config) {
|
|
14303
|
-
const arkProvider = new
|
|
14332
|
+
const arkProvider = new chunkGMUVWKOK_cjs.RestArkProvider(config.arkServer.url);
|
|
14304
14333
|
const storage = {
|
|
14305
14334
|
walletRepository: this.walletRepository,
|
|
14306
14335
|
contractRepository: this.contractRepository
|
|
@@ -14629,6 +14658,25 @@ var DustChangeError = class extends Error {
|
|
|
14629
14658
|
this.dustAmount = dustAmount;
|
|
14630
14659
|
}
|
|
14631
14660
|
};
|
|
14661
|
+
var offboardNetworkNames = [
|
|
14662
|
+
"bitcoin",
|
|
14663
|
+
"regtest",
|
|
14664
|
+
"testnet",
|
|
14665
|
+
"signet",
|
|
14666
|
+
"mutinynet"
|
|
14667
|
+
];
|
|
14668
|
+
function offboardDestinationScript(destinationAddress) {
|
|
14669
|
+
for (const networkName of offboardNetworkNames) {
|
|
14670
|
+
try {
|
|
14671
|
+
const network = chunkGMUVWKOK_cjs.networks[networkName];
|
|
14672
|
+
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
14673
|
+
return btcSigner.OutScript.encode(addr);
|
|
14674
|
+
} catch {
|
|
14675
|
+
continue;
|
|
14676
|
+
}
|
|
14677
|
+
}
|
|
14678
|
+
throw new Error(`Failed to decode destination address: ${destinationAddress}`);
|
|
14679
|
+
}
|
|
14632
14680
|
var Ramps = class {
|
|
14633
14681
|
/**
|
|
14634
14682
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -14684,7 +14732,7 @@ var Ramps = class {
|
|
|
14684
14732
|
}
|
|
14685
14733
|
amount = amount ?? totalAmount;
|
|
14686
14734
|
const offchainAddress = await this.wallet.getAddress();
|
|
14687
|
-
const offchainAddr =
|
|
14735
|
+
const offchainAddr = chunkGMUVWKOK_cjs.ArkAddress.decode(offchainAddress);
|
|
14688
14736
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
14689
14737
|
const outputFee = estimator.evalOffchainOutput({
|
|
14690
14738
|
amount,
|
|
@@ -14744,7 +14792,7 @@ var Ramps = class {
|
|
|
14744
14792
|
const filteredVtxos = [];
|
|
14745
14793
|
let totalAmount = 0n;
|
|
14746
14794
|
for (const vtxo of vtxos) {
|
|
14747
|
-
const inputFee = estimator.evalOffchainInput(
|
|
14795
|
+
const inputFee = estimator.evalOffchainInput(chunkGMUVWKOK_cjs.toOffchainInputFeeParams(vtxo));
|
|
14748
14796
|
if (inputFee.satoshis >= vtxo.value) {
|
|
14749
14797
|
continue;
|
|
14750
14798
|
}
|
|
@@ -14766,27 +14814,7 @@ var Ramps = class {
|
|
|
14766
14814
|
throw new DustChangeError(change, dustAmount);
|
|
14767
14815
|
}
|
|
14768
14816
|
amount = amount ?? totalAmount;
|
|
14769
|
-
const
|
|
14770
|
-
"bitcoin",
|
|
14771
|
-
"regtest",
|
|
14772
|
-
"testnet",
|
|
14773
|
-
"signet",
|
|
14774
|
-
"mutinynet"
|
|
14775
|
-
];
|
|
14776
|
-
let destinationScript;
|
|
14777
|
-
for (const networkName of networkNames) {
|
|
14778
|
-
try {
|
|
14779
|
-
const network = chunkE7HB3GKK_cjs.networks[networkName];
|
|
14780
|
-
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
14781
|
-
destinationScript = btcSigner.OutScript.encode(addr);
|
|
14782
|
-
break;
|
|
14783
|
-
} catch {
|
|
14784
|
-
continue;
|
|
14785
|
-
}
|
|
14786
|
-
}
|
|
14787
|
-
if (!destinationScript) {
|
|
14788
|
-
throw new Error(`Failed to decode destination address: ${destinationAddress}`);
|
|
14789
|
-
}
|
|
14817
|
+
const destinationScript = offboardDestinationScript(destinationAddress);
|
|
14790
14818
|
const outputFee = estimator.evalOnchainOutput({
|
|
14791
14819
|
amount,
|
|
14792
14820
|
script: base.hex.encode(destinationScript)
|
|
@@ -15461,7 +15489,7 @@ var WalletMessageHandler = class {
|
|
|
15461
15489
|
// Wallet methods
|
|
15462
15490
|
async handleInitWallet({ payload }) {
|
|
15463
15491
|
const { arkServerUrl } = payload;
|
|
15464
|
-
this.indexerProvider = new
|
|
15492
|
+
this.indexerProvider = new chunkRNECH3TA_cjs.RestIndexerProvider(arkServerUrl);
|
|
15465
15493
|
await this.onWalletInitialized();
|
|
15466
15494
|
}
|
|
15467
15495
|
async handleGetBalance() {
|
|
@@ -15485,12 +15513,12 @@ var WalletMessageHandler = class {
|
|
|
15485
15513
|
let recoverable = 0;
|
|
15486
15514
|
let pendingRecovery = 0;
|
|
15487
15515
|
for (const vtxo of allVtxos) {
|
|
15488
|
-
if (
|
|
15516
|
+
if (chunkGMUVWKOK_cjs.hasTerminalSpend(vtxo)) continue;
|
|
15489
15517
|
if (pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
15490
15518
|
pendingRecovery += vtxo.value;
|
|
15491
|
-
} else if (
|
|
15519
|
+
} else if (chunkGMUVWKOK_cjs.canRecoverOnchain(vtxo, now)) {
|
|
15492
15520
|
recoverable += vtxo.value;
|
|
15493
|
-
} else if (
|
|
15521
|
+
} else if (chunkGMUVWKOK_cjs.canSpendOffchain(vtxo, now)) {
|
|
15494
15522
|
if (vtxo.isPreconfirmed) {
|
|
15495
15523
|
preconfirmed += vtxo.value;
|
|
15496
15524
|
} else {
|
|
@@ -15502,7 +15530,7 @@ var WalletMessageHandler = class {
|
|
|
15502
15530
|
const totalOffchain = settled + preconfirmed + recoverable + pendingRecovery;
|
|
15503
15531
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
15504
15532
|
for (const vtxo of allVtxos) {
|
|
15505
|
-
if (
|
|
15533
|
+
if (chunkGMUVWKOK_cjs.hasTerminalSpend(vtxo)) continue;
|
|
15506
15534
|
if (vtxo.assets) {
|
|
15507
15535
|
for (const a of vtxo.assets) {
|
|
15508
15536
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -15538,7 +15566,7 @@ var WalletMessageHandler = class {
|
|
|
15538
15566
|
*/
|
|
15539
15567
|
async getSpendableVtxos() {
|
|
15540
15568
|
const vtxos = await this.getVtxosFromRepo();
|
|
15541
|
-
return vtxos.filter((v) => !
|
|
15569
|
+
return vtxos.filter((v) => !chunkGMUVWKOK_cjs.hasTerminalSpend(v));
|
|
15542
15570
|
}
|
|
15543
15571
|
async onWalletInitialized() {
|
|
15544
15572
|
if (!this.readonlyWallet || !this.arkProvider || !this.indexerProvider || !this.walletRepository) {
|
|
@@ -15750,10 +15778,10 @@ var WalletMessageHandler = class {
|
|
|
15750
15778
|
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
15751
15779
|
return false;
|
|
15752
15780
|
}
|
|
15753
|
-
if (
|
|
15781
|
+
if (chunkGMUVWKOK_cjs.isRecoverable(v)) {
|
|
15754
15782
|
return false;
|
|
15755
15783
|
}
|
|
15756
|
-
if (
|
|
15784
|
+
if (chunkGMUVWKOK_cjs.isExpired(v)) {
|
|
15757
15785
|
return false;
|
|
15758
15786
|
}
|
|
15759
15787
|
return true;
|
|
@@ -15818,47 +15846,15 @@ var WalletMessageHandler = class {
|
|
|
15818
15846
|
return allVtxos;
|
|
15819
15847
|
}
|
|
15820
15848
|
/**
|
|
15821
|
-
* Build transaction history from cached virtual outputs
|
|
15822
|
-
*
|
|
15849
|
+
* Build transaction history from cached virtual outputs, hitting the indexer only for
|
|
15850
|
+
* uncached timestamps. Best-effort, like the plain Wallet path.
|
|
15823
15851
|
*/
|
|
15824
15852
|
async buildTransactionHistoryFromCache(vtxos) {
|
|
15825
15853
|
if (!this.readonlyWallet) return null;
|
|
15826
15854
|
const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
|
|
15827
|
-
const
|
|
15828
|
-
|
|
15829
|
-
|
|
15830
|
-
const ts = vtxo.createdAt.getTime();
|
|
15831
|
-
if (existing === void 0 || ts < existing) {
|
|
15832
|
-
vtxoCreatedAt.set(vtxo.txid, ts);
|
|
15833
|
-
}
|
|
15834
|
-
}
|
|
15835
|
-
if (this.indexerProvider) {
|
|
15836
|
-
const uncachedTxids = /* @__PURE__ */ new Set();
|
|
15837
|
-
for (const vtxo of vtxos) {
|
|
15838
|
-
if (vtxo.isSpent && vtxo.arkTxId && !vtxoCreatedAt.has(vtxo.arkTxId) && !vtxos.some((v) => v.txid === vtxo.arkTxId)) {
|
|
15839
|
-
uncachedTxids.add(vtxo.arkTxId);
|
|
15840
|
-
}
|
|
15841
|
-
}
|
|
15842
|
-
if (uncachedTxids.size > 0) {
|
|
15843
|
-
const outpoints = [...uncachedTxids].map((txid) => ({
|
|
15844
|
-
txid,
|
|
15845
|
-
vout: 0
|
|
15846
|
-
}));
|
|
15847
|
-
const BATCH_SIZE = 100;
|
|
15848
|
-
for (let i = 0; i < outpoints.length; i += BATCH_SIZE) {
|
|
15849
|
-
const res = await chunkE7HB3GKK_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
15850
|
-
outpoints: outpoints.slice(i, i + BATCH_SIZE)
|
|
15851
|
-
});
|
|
15852
|
-
for (const v of res.vtxos) {
|
|
15853
|
-
vtxoCreatedAt.set(v.txid, v.createdAt.getTime());
|
|
15854
|
-
}
|
|
15855
|
-
}
|
|
15856
|
-
}
|
|
15857
|
-
}
|
|
15858
|
-
const getTxCreatedAt = async (txid) => {
|
|
15859
|
-
return vtxoCreatedAt.get(txid);
|
|
15860
|
-
};
|
|
15861
|
-
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, getTxCreatedAt);
|
|
15855
|
+
const indexerProvider = this.indexerProvider;
|
|
15856
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkGMUVWKOK_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
15857
|
+
return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, resolveTxCreatedAt);
|
|
15862
15858
|
}
|
|
15863
15859
|
async ensureContractEventBroadcasting() {
|
|
15864
15860
|
if (!this.readonlyWallet) return;
|
|
@@ -16542,7 +16538,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
16542
16538
|
};
|
|
16543
16539
|
try {
|
|
16544
16540
|
const response = await this.sendMessage(message);
|
|
16545
|
-
return response.payload.vtxos.map(
|
|
16541
|
+
return response.payload.vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo);
|
|
16546
16542
|
} catch (error) {
|
|
16547
16543
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
16548
16544
|
}
|
|
@@ -16655,7 +16651,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
16655
16651
|
};
|
|
16656
16652
|
try {
|
|
16657
16653
|
const response = await sendContractMessage(message);
|
|
16658
|
-
return response.payload.vtxos.map(
|
|
16654
|
+
return response.payload.vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo);
|
|
16659
16655
|
} catch (e) {
|
|
16660
16656
|
throw new Error("Failed to annotate vtxos");
|
|
16661
16657
|
}
|
|
@@ -17109,7 +17105,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
17109
17105
|
};
|
|
17110
17106
|
try {
|
|
17111
17107
|
const response = await wallet.sendMessage(message);
|
|
17112
|
-
return response.payload.vtxos.map(
|
|
17108
|
+
return response.payload.vtxos.map(chunkGMUVWKOK_cjs.normalizeVtxo);
|
|
17113
17109
|
} catch (e) {
|
|
17114
17110
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
17115
17111
|
}
|
|
@@ -17221,12 +17217,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17221
17217
|
* @returns Configured onchain wallet
|
|
17222
17218
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
17223
17219
|
*/
|
|
17224
|
-
static async create(identity, networkName =
|
|
17220
|
+
static async create(identity, networkName = chunkGMUVWKOK_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
17225
17221
|
const pubkey = await identity.xOnlyPublicKey();
|
|
17226
17222
|
if (!pubkey) {
|
|
17227
17223
|
throw new Error("Invalid configured public key");
|
|
17228
17224
|
}
|
|
17229
|
-
const network =
|
|
17225
|
+
const network = chunkGMUVWKOK_cjs.getNetwork(networkName);
|
|
17230
17226
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
17231
17227
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
17232
17228
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -17332,7 +17328,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17332
17328
|
if (!inputs) {
|
|
17333
17329
|
throw new Error("Fee estimation failed");
|
|
17334
17330
|
}
|
|
17335
|
-
let tx = new
|
|
17331
|
+
let tx = new chunkGMUVWKOK_cjs.Transaction();
|
|
17336
17332
|
for (const input of inputs) {
|
|
17337
17333
|
tx.addInput({
|
|
17338
17334
|
txid: input.txid,
|
|
@@ -17390,7 +17386,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
17390
17386
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
17391
17387
|
*/
|
|
17392
17388
|
async bumpAnchor(parentHex, feeRate) {
|
|
17393
|
-
const parent =
|
|
17389
|
+
const parent = chunkGMUVWKOK_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
17394
17390
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
17395
17391
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
17396
17392
|
return [parent.hex, child.hex];
|
|
@@ -18155,7 +18151,7 @@ exports.BIP322 = void 0;
|
|
|
18155
18151
|
async function sign2(message, identity, network) {
|
|
18156
18152
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
18157
18153
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
18158
|
-
const toSpend =
|
|
18154
|
+
const toSpend = chunkGMUVWKOK_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
18159
18155
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
18160
18156
|
const signed = await identity.sign(toSign, [0]);
|
|
18161
18157
|
signed.finalizeIdx(0);
|
|
@@ -18213,7 +18209,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
18213
18209
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
18214
18210
|
return false;
|
|
18215
18211
|
}
|
|
18216
|
-
const toSpend =
|
|
18212
|
+
const toSpend = chunkGMUVWKOK_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
18217
18213
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
18218
18214
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
18219
18215
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -18234,7 +18230,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
18234
18230
|
}
|
|
18235
18231
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
18236
18232
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
18237
|
-
const toSpend =
|
|
18233
|
+
const toSpend = chunkGMUVWKOK_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
18238
18234
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
18239
18235
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
18240
18236
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -18287,7 +18283,7 @@ function encodeCompactSize(n) {
|
|
|
18287
18283
|
return buf;
|
|
18288
18284
|
}
|
|
18289
18285
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
18290
|
-
const tx = new
|
|
18286
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({ version: 0 });
|
|
18291
18287
|
tx.addInput({
|
|
18292
18288
|
txid: toSpend.id,
|
|
18293
18289
|
index: 0,
|
|
@@ -18301,12 +18297,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
18301
18297
|
});
|
|
18302
18298
|
tx.addOutput({
|
|
18303
18299
|
amount: 0n,
|
|
18304
|
-
script:
|
|
18300
|
+
script: chunkGMUVWKOK_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
18305
18301
|
});
|
|
18306
18302
|
return tx;
|
|
18307
18303
|
}
|
|
18308
18304
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
18309
|
-
const tx = new
|
|
18305
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({ version: 0 });
|
|
18310
18306
|
tx.addInput({
|
|
18311
18307
|
txid: toSpend.id,
|
|
18312
18308
|
index: 0,
|
|
@@ -18318,7 +18314,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
18318
18314
|
});
|
|
18319
18315
|
tx.addOutput({
|
|
18320
18316
|
amount: 0n,
|
|
18321
|
-
script:
|
|
18317
|
+
script: chunkGMUVWKOK_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
18322
18318
|
});
|
|
18323
18319
|
return tx;
|
|
18324
18320
|
}
|
|
@@ -18449,7 +18445,7 @@ var RestEmulatorProvider = class {
|
|
|
18449
18445
|
}
|
|
18450
18446
|
};
|
|
18451
18447
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
18452
|
-
const tx =
|
|
18448
|
+
const tx = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
18453
18449
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
18454
18450
|
const input = tx.getInput(0);
|
|
18455
18451
|
if (!input) {
|
|
@@ -18476,14 +18472,14 @@ var ExitPathError = class extends Error {
|
|
|
18476
18472
|
reason;
|
|
18477
18473
|
};
|
|
18478
18474
|
function delayWeight(sequence) {
|
|
18479
|
-
const t =
|
|
18475
|
+
const t = chunkGMUVWKOK_cjs.sequenceToTimelock(sequence);
|
|
18480
18476
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
18481
18477
|
}
|
|
18482
18478
|
async function resolveUnilateralPath(params) {
|
|
18483
18479
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
18484
18480
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
18485
18481
|
if (contract) {
|
|
18486
|
-
const handler =
|
|
18482
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
18487
18483
|
if (!handler) {
|
|
18488
18484
|
throw new ExitPathError(
|
|
18489
18485
|
"no-handler",
|
|
@@ -18506,12 +18502,12 @@ async function resolveUnilateralPath(params) {
|
|
|
18506
18502
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
18507
18503
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
18508
18504
|
}
|
|
18509
|
-
const decoded =
|
|
18505
|
+
const decoded = chunkGMUVWKOK_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
18510
18506
|
let best;
|
|
18511
18507
|
for (const exit of decoded.exitPaths()) {
|
|
18512
18508
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
18513
18509
|
if (!leaf) continue;
|
|
18514
|
-
const sequence =
|
|
18510
|
+
const sequence = chunkGMUVWKOK_cjs.timelockToSequence(exit.params.timelock);
|
|
18515
18511
|
const weight = delayWeight(sequence);
|
|
18516
18512
|
if (!best || weight < best.weight) {
|
|
18517
18513
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -18697,14 +18693,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18697
18693
|
}
|
|
18698
18694
|
const resolved = await resolveUnilateralPath({
|
|
18699
18695
|
vtxo,
|
|
18700
|
-
scriptHex: base.hex.encode(
|
|
18696
|
+
scriptHex: base.hex.encode(chunkGMUVWKOK_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
18701
18697
|
contractRepository: wallet.contractRepository,
|
|
18702
18698
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
18703
18699
|
currentTime: Date.now()
|
|
18704
18700
|
});
|
|
18705
18701
|
const spendingLeaf = resolved.selection.leaf;
|
|
18706
18702
|
const sequence = resolved.selection.sequence;
|
|
18707
|
-
const timelock =
|
|
18703
|
+
const timelock = chunkGMUVWKOK_cjs.sequenceToTimelock(sequence);
|
|
18708
18704
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
18709
18705
|
if (!elapsed) {
|
|
18710
18706
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -18717,7 +18713,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18717
18713
|
sequence,
|
|
18718
18714
|
witnessUtxo: {
|
|
18719
18715
|
amount: BigInt(vtxo.value),
|
|
18720
|
-
script:
|
|
18716
|
+
script: chunkGMUVWKOK_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
18721
18717
|
},
|
|
18722
18718
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
18723
18719
|
});
|
|
@@ -18727,7 +18723,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
18727
18723
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
18728
18724
|
);
|
|
18729
18725
|
}
|
|
18730
|
-
const tx = new
|
|
18726
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({ version: 2 });
|
|
18731
18727
|
for (const input of inputs) {
|
|
18732
18728
|
tx.addInput(input);
|
|
18733
18729
|
}
|
|
@@ -18794,7 +18790,7 @@ async function buildSignedSweep(params) {
|
|
|
18794
18790
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
18795
18791
|
);
|
|
18796
18792
|
}
|
|
18797
|
-
const tx = new
|
|
18793
|
+
const tx = new chunkGMUVWKOK_cjs.Transaction({ version: 2 });
|
|
18798
18794
|
tx.addInput({
|
|
18799
18795
|
txid: vtxo.txid,
|
|
18800
18796
|
index: vtxo.vout,
|
|
@@ -18819,7 +18815,7 @@ async function buildSignedSweep(params) {
|
|
|
18819
18815
|
finalScriptWitness: [
|
|
18820
18816
|
tapScriptSig[0][1],
|
|
18821
18817
|
...path.extraWitness,
|
|
18822
|
-
|
|
18818
|
+
chunkGMUVWKOK_cjs.scriptFromTapLeafScript(path.leaf),
|
|
18823
18819
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
18824
18820
|
]
|
|
18825
18821
|
});
|
|
@@ -18849,7 +18845,7 @@ async function resolveFeeRate(opts) {
|
|
|
18849
18845
|
}
|
|
18850
18846
|
async function selectExitVtxos(opts) {
|
|
18851
18847
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
18852
|
-
const res = await
|
|
18848
|
+
const res = await chunkGMUVWKOK_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
18853
18849
|
const tapTrees = /* @__PURE__ */ new Map();
|
|
18854
18850
|
const out = [];
|
|
18855
18851
|
for (const vtxo of res.vtxos) {
|
|
@@ -18864,7 +18860,7 @@ async function selectExitVtxos(opts) {
|
|
|
18864
18860
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
18865
18861
|
);
|
|
18866
18862
|
}
|
|
18867
|
-
const handler =
|
|
18863
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(contract.type);
|
|
18868
18864
|
if (!handler) {
|
|
18869
18865
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
18870
18866
|
}
|
|
@@ -18894,7 +18890,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18894
18890
|
if (pendingNodes.length > 0) {
|
|
18895
18891
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
18896
18892
|
for (const psbt of txs) {
|
|
18897
|
-
psbts.set(
|
|
18893
|
+
psbts.set(chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
18898
18894
|
}
|
|
18899
18895
|
}
|
|
18900
18896
|
const childVsize = Number(
|
|
@@ -18930,7 +18926,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18930
18926
|
try {
|
|
18931
18927
|
const resolved = await resolveUnilateralPath({
|
|
18932
18928
|
vtxo,
|
|
18933
|
-
scriptHex: base.hex.encode(
|
|
18929
|
+
scriptHex: base.hex.encode(chunkGMUVWKOK_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
18934
18930
|
contractRepository: wallet.contractRepository,
|
|
18935
18931
|
walletPubKeyHex,
|
|
18936
18932
|
currentTime: Date.now()
|
|
@@ -18949,7 +18945,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
18949
18945
|
});
|
|
18950
18946
|
continue;
|
|
18951
18947
|
}
|
|
18952
|
-
const t =
|
|
18948
|
+
const t = chunkGMUVWKOK_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
18953
18949
|
const delay = { type: t.type, value: Number(t.value) };
|
|
18954
18950
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
18955
18951
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -19035,19 +19031,48 @@ async function estimate(opts) {
|
|
|
19035
19031
|
}
|
|
19036
19032
|
|
|
19037
19033
|
// src/wallet/exit/executor.ts
|
|
19034
|
+
function abortErrorFor(signal) {
|
|
19035
|
+
if (signal.reason !== void 0) return signal.reason;
|
|
19036
|
+
const e = new Error("The operation was aborted");
|
|
19037
|
+
e.name = "AbortError";
|
|
19038
|
+
return e;
|
|
19039
|
+
}
|
|
19040
|
+
function throwIfAborted(signal) {
|
|
19041
|
+
if (signal?.aborted) throw abortErrorFor(signal);
|
|
19042
|
+
}
|
|
19038
19043
|
var Executor = class {
|
|
19039
19044
|
constructor(pkg, provider, opts) {
|
|
19040
19045
|
this.pkg = pkg;
|
|
19041
19046
|
this.provider = provider;
|
|
19042
19047
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
19043
19048
|
this.feeWallet = opts?.feeWallet;
|
|
19049
|
+
this.signal = opts?.signal;
|
|
19044
19050
|
}
|
|
19045
19051
|
pkg;
|
|
19046
19052
|
provider;
|
|
19047
19053
|
pollIntervalMs;
|
|
19048
19054
|
feeWallet;
|
|
19055
|
+
signal;
|
|
19056
|
+
/**
|
|
19057
|
+
* Poll delay. Nearly all wall-clock time is spent here, so it must be the
|
|
19058
|
+
* thing that reacts to abort — checking only between polls would leave
|
|
19059
|
+
* cancellation up to a full interval late and the timer still pending.
|
|
19060
|
+
*/
|
|
19049
19061
|
sleep() {
|
|
19050
|
-
|
|
19062
|
+
const signal = this.signal;
|
|
19063
|
+
if (!signal) return new Promise((r) => setTimeout(r, this.pollIntervalMs));
|
|
19064
|
+
return new Promise((resolve, reject) => {
|
|
19065
|
+
if (signal.aborted) return reject(abortErrorFor(signal));
|
|
19066
|
+
const onAbort = () => {
|
|
19067
|
+
clearTimeout(timer);
|
|
19068
|
+
reject(abortErrorFor(signal));
|
|
19069
|
+
};
|
|
19070
|
+
const timer = setTimeout(() => {
|
|
19071
|
+
signal.removeEventListener("abort", onAbort);
|
|
19072
|
+
resolve();
|
|
19073
|
+
}, this.pollIntervalMs);
|
|
19074
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
19075
|
+
});
|
|
19051
19076
|
}
|
|
19052
19077
|
async status(txid) {
|
|
19053
19078
|
try {
|
|
@@ -19060,10 +19085,12 @@ var Executor = class {
|
|
|
19060
19085
|
for (; ; ) {
|
|
19061
19086
|
const s = await this.status(txid);
|
|
19062
19087
|
if (s?.confirmed) return s;
|
|
19088
|
+
throwIfAborted(this.signal);
|
|
19063
19089
|
await this.sleep();
|
|
19064
19090
|
}
|
|
19065
19091
|
}
|
|
19066
19092
|
async *[Symbol.asyncIterator]() {
|
|
19093
|
+
throwIfAborted(this.signal);
|
|
19067
19094
|
const dead = /* @__PURE__ */ new Set();
|
|
19068
19095
|
if (this.pkg.validUntil && Date.now() / 1e3 > this.pkg.validUntil) {
|
|
19069
19096
|
yield {
|
|
@@ -19175,6 +19202,7 @@ var Executor = class {
|
|
|
19175
19202
|
while (done.size < pending.length) {
|
|
19176
19203
|
for (const { index, step } of pending) {
|
|
19177
19204
|
if (done.has(index)) continue;
|
|
19205
|
+
throwIfAborted(this.signal);
|
|
19178
19206
|
const swept = await this.status(step.txid);
|
|
19179
19207
|
if (swept?.confirmed) {
|
|
19180
19208
|
done.add(index);
|
|
@@ -19256,7 +19284,7 @@ async function prepare(opts) {
|
|
|
19256
19284
|
txid: sweep.vtxo.txid,
|
|
19257
19285
|
vout: sweep.vtxo.vout,
|
|
19258
19286
|
value: sweep.vtxo.value,
|
|
19259
|
-
pkScript:
|
|
19287
|
+
pkScript: chunkGMUVWKOK_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
19260
19288
|
},
|
|
19261
19289
|
path: sweep.resolved.selection,
|
|
19262
19290
|
outputAddress: opts.sweepAddress,
|
|
@@ -19341,7 +19369,7 @@ async function prepare(opts) {
|
|
|
19341
19369
|
if (newFee <= splitterFee) break;
|
|
19342
19370
|
splitterFee = newFee;
|
|
19343
19371
|
}
|
|
19344
|
-
const splitter = new
|
|
19372
|
+
const splitter = new chunkGMUVWKOK_cjs.Transaction({ version: 2 });
|
|
19345
19373
|
for (const coin of selected.inputs) {
|
|
19346
19374
|
splitter.addInput({
|
|
19347
19375
|
txid: coin.txid,
|
|
@@ -19484,41 +19512,41 @@ var UnilateralExit = {
|
|
|
19484
19512
|
// src/arkade/index.ts
|
|
19485
19513
|
var arkade_exports = {};
|
|
19486
19514
|
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
19487
|
-
ARKADE_OP: () =>
|
|
19488
|
-
ARKADE_OPCODES: () =>
|
|
19489
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
19490
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
19491
|
-
ARKADE_OPS: () =>
|
|
19515
|
+
ARKADE_OP: () => chunk53XNU2EL_cjs.ARKADE_OP,
|
|
19516
|
+
ARKADE_OPCODES: () => chunk53XNU2EL_cjs.ARKADE_OPCODES,
|
|
19517
|
+
ARKADE_OPCODE_NAMES: () => chunk53XNU2EL_cjs.ARKADE_OPCODE_NAMES,
|
|
19518
|
+
ARKADE_OPCODE_VALUES: () => chunk53XNU2EL_cjs.ARKADE_OPCODE_VALUES,
|
|
19519
|
+
ARKADE_OPS: () => chunk53XNU2EL_cjs.ARKADE_OPS,
|
|
19492
19520
|
Arkade: () => Arkade,
|
|
19493
19521
|
ArkadeContract: () => ArkadeContract,
|
|
19494
|
-
ArkadeProgramScript: () =>
|
|
19495
|
-
ArkadeScript: () =>
|
|
19522
|
+
ArkadeProgramScript: () => chunk53XNU2EL_cjs.ArkadeProgramScript,
|
|
19523
|
+
ArkadeScript: () => chunk53XNU2EL_cjs.ArkadeScript,
|
|
19496
19524
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
19497
|
-
BigNum: () =>
|
|
19525
|
+
BigNum: () => chunk53XNU2EL_cjs.bignum_exports,
|
|
19498
19526
|
OP: () => btcSigner.OP,
|
|
19499
|
-
OPCODE_NAMES: () =>
|
|
19500
|
-
OPCODE_VALUES: () =>
|
|
19501
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
19527
|
+
OPCODE_NAMES: () => chunk53XNU2EL_cjs.OPCODE_NAMES,
|
|
19528
|
+
OPCODE_VALUES: () => chunk53XNU2EL_cjs.OPCODE_VALUES,
|
|
19529
|
+
SUPPORTED_PROGRAM_VERSION: () => chunk53XNU2EL_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
19502
19530
|
Script: () => btcSigner.Script,
|
|
19503
|
-
arkadeScriptHash: () =>
|
|
19504
|
-
arkadeWitnessHash: () =>
|
|
19505
|
-
asmToBytes: () =>
|
|
19506
|
-
bytesToASM: () =>
|
|
19507
|
-
computeArkadeScriptPublicKey: () =>
|
|
19531
|
+
arkadeScriptHash: () => chunk53XNU2EL_cjs.arkadeScriptHash,
|
|
19532
|
+
arkadeWitnessHash: () => chunk53XNU2EL_cjs.arkadeWitnessHash,
|
|
19533
|
+
asmToBytes: () => chunk53XNU2EL_cjs.asmToBytes,
|
|
19534
|
+
bytesToASM: () => chunk53XNU2EL_cjs.bytesToASM,
|
|
19535
|
+
computeArkadeScriptPublicKey: () => chunk53XNU2EL_cjs.computeArkadeScriptPublicKey,
|
|
19508
19536
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
19509
|
-
deserializeArkadeContractParams: () =>
|
|
19510
|
-
fromASM: () =>
|
|
19511
|
-
getOpcodeName: () =>
|
|
19512
|
-
getOpcodeValue: () =>
|
|
19513
|
-
parseArtifact: () =>
|
|
19514
|
-
resolveAsm: () =>
|
|
19515
|
-
serializeArkadeContractParams: () =>
|
|
19516
|
-
stringifyArtifact: () =>
|
|
19517
|
-
toASM: () =>
|
|
19518
|
-
validateProgram: () =>
|
|
19519
|
-
witnessRefToBytes: () =>
|
|
19537
|
+
deserializeArkadeContractParams: () => chunk53XNU2EL_cjs.deserializeArkadeContractParams,
|
|
19538
|
+
fromASM: () => chunk53XNU2EL_cjs.fromASM,
|
|
19539
|
+
getOpcodeName: () => chunk53XNU2EL_cjs.getOpcodeName,
|
|
19540
|
+
getOpcodeValue: () => chunk53XNU2EL_cjs.getOpcodeValue,
|
|
19541
|
+
parseArtifact: () => chunk53XNU2EL_cjs.parseArtifact,
|
|
19542
|
+
resolveAsm: () => chunk53XNU2EL_cjs.resolveAsm,
|
|
19543
|
+
serializeArkadeContractParams: () => chunk53XNU2EL_cjs.serializeArkadeContractParams,
|
|
19544
|
+
stringifyArtifact: () => chunk53XNU2EL_cjs.stringifyArtifact,
|
|
19545
|
+
toASM: () => chunk53XNU2EL_cjs.toASM,
|
|
19546
|
+
validateProgram: () => chunk53XNU2EL_cjs.validateProgram,
|
|
19547
|
+
witnessRefToBytes: () => chunk53XNU2EL_cjs.witnessRefToBytes
|
|
19520
19548
|
});
|
|
19521
|
-
var isVtxoCoin = (input) =>
|
|
19549
|
+
var isVtxoCoin = (input) => chunkGMUVWKOK_cjs.isVirtualCoin(input);
|
|
19522
19550
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients) {
|
|
19523
19551
|
let batchId;
|
|
19524
19552
|
let sweepTapTreeRoot;
|
|
@@ -19530,7 +19558,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19530
19558
|
if (!event.intentIdHashes.includes(intentIdHashStr)) return { skip: true };
|
|
19531
19559
|
await arkProvider.confirmRegistration(intentId);
|
|
19532
19560
|
batchId = event.id;
|
|
19533
|
-
const sweepTapscript =
|
|
19561
|
+
const sweepTapscript = chunkGMUVWKOK_cjs.CSVMultisigTapscript.encode({
|
|
19534
19562
|
timelock: {
|
|
19535
19563
|
value: event.batchExpiry,
|
|
19536
19564
|
// BIP-65: values >= 512 are interpreted as seconds, below as blocks
|
|
@@ -19548,7 +19576,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19548
19576
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
19549
19577
|
return { skip: true };
|
|
19550
19578
|
}
|
|
19551
|
-
const commitmentTx =
|
|
19579
|
+
const commitmentTx = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
19552
19580
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
19553
19581
|
if (recipients && recipients.length > 0) {
|
|
19554
19582
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -19579,7 +19607,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19579
19607
|
if (connectorTree) {
|
|
19580
19608
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
19581
19609
|
}
|
|
19582
|
-
let commitmentPsbt =
|
|
19610
|
+
let commitmentPsbt = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
19583
19611
|
const signedForfeits = [];
|
|
19584
19612
|
let connectorIndex = 0;
|
|
19585
19613
|
const connectorLeaves = connectorTree?.leaves() || [];
|
|
@@ -19606,7 +19634,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19606
19634
|
boardingIndices.push(boardingIdx);
|
|
19607
19635
|
continue;
|
|
19608
19636
|
}
|
|
19609
|
-
if (
|
|
19637
|
+
if (chunkGMUVWKOK_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
19610
19638
|
continue;
|
|
19611
19639
|
}
|
|
19612
19640
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -19627,7 +19655,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
19627
19655
|
index: input.vout,
|
|
19628
19656
|
witnessUtxo: {
|
|
19629
19657
|
amount: BigInt(input.value),
|
|
19630
|
-
script:
|
|
19658
|
+
script: chunkGMUVWKOK_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
19631
19659
|
},
|
|
19632
19660
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
19633
19661
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -19710,7 +19738,7 @@ var Arkade = class _Arkade {
|
|
|
19710
19738
|
static async connect(opts) {
|
|
19711
19739
|
const info = await opts.arkade.getInfo();
|
|
19712
19740
|
const serverKey = base.hex.decode(info.signerPubkey).slice(1);
|
|
19713
|
-
const checkpoint =
|
|
19741
|
+
const checkpoint = chunkGMUVWKOK_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
19714
19742
|
let emulatorKey;
|
|
19715
19743
|
if (opts.emulator) {
|
|
19716
19744
|
const eInfo = await opts.emulator.getInfo();
|
|
@@ -19724,7 +19752,7 @@ var Arkade = class _Arkade {
|
|
|
19724
19752
|
return new _Arkade({
|
|
19725
19753
|
arkProvider: opts.arkade,
|
|
19726
19754
|
emulator: opts.emulator,
|
|
19727
|
-
network: opts.network ??
|
|
19755
|
+
network: opts.network ?? chunkGMUVWKOK_cjs.DEFAULT_NETWORK,
|
|
19728
19756
|
serverKey,
|
|
19729
19757
|
emulatorKey,
|
|
19730
19758
|
checkpoint,
|
|
@@ -19745,7 +19773,7 @@ var Arkade = class _Arkade {
|
|
|
19745
19773
|
* key respectively; explicit args always win.
|
|
19746
19774
|
*/
|
|
19747
19775
|
contract(program, args = {}) {
|
|
19748
|
-
const declared = (program.params ?? []).map(
|
|
19776
|
+
const declared = (program.params ?? []).map(chunk53XNU2EL_cjs.inputName);
|
|
19749
19777
|
if (declared.includes("server") && args.server === void 0) {
|
|
19750
19778
|
args = { ...args, server: this.serverKey };
|
|
19751
19779
|
}
|
|
@@ -19765,7 +19793,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19765
19793
|
userKey: client.userKey,
|
|
19766
19794
|
emulatorKey: client.emulatorKey
|
|
19767
19795
|
};
|
|
19768
|
-
this.vtxoScript = new
|
|
19796
|
+
this.vtxoScript = new chunk53XNU2EL_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
19769
19797
|
this.tapTree = this.vtxoScript.encode();
|
|
19770
19798
|
this.compiled = this.vtxoScript.compiled;
|
|
19771
19799
|
}
|
|
@@ -19793,7 +19821,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19793
19821
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
19794
19822
|
);
|
|
19795
19823
|
}
|
|
19796
|
-
const typed =
|
|
19824
|
+
const typed = chunk53XNU2EL_cjs.deserializeArkadeContractParams(contract.params);
|
|
19797
19825
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
19798
19826
|
serverKey: typed.serverKey,
|
|
19799
19827
|
userKey: typed.userKey,
|
|
@@ -19834,7 +19862,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19834
19862
|
toContractParams() {
|
|
19835
19863
|
return {
|
|
19836
19864
|
type: "arkade",
|
|
19837
|
-
params:
|
|
19865
|
+
params: chunk53XNU2EL_cjs.serializeArkadeContractParams({
|
|
19838
19866
|
program: this.program,
|
|
19839
19867
|
args: this.args,
|
|
19840
19868
|
serverKey: this.keys.serverKey,
|
|
@@ -19879,13 +19907,13 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
19879
19907
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
19880
19908
|
if (registered) {
|
|
19881
19909
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
19882
|
-
return (withVtxos?.vtxos ?? []).filter((v) => !
|
|
19910
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunkGMUVWKOK_cjs.hasTerminalSpend(v));
|
|
19883
19911
|
}
|
|
19884
19912
|
}
|
|
19885
19913
|
if (!this.client.indexer) {
|
|
19886
19914
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
19887
19915
|
}
|
|
19888
|
-
const { vtxos } = await
|
|
19916
|
+
const { vtxos } = await chunkGMUVWKOK_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
19889
19917
|
scripts: [scriptHex],
|
|
19890
19918
|
spendableOnly: true
|
|
19891
19919
|
});
|
|
@@ -19987,12 +20015,12 @@ var ArkadeTransactionBuilder = class {
|
|
|
19987
20015
|
this.contract.client.checkpoint
|
|
19988
20016
|
);
|
|
19989
20017
|
if (coin.sourceTx) {
|
|
19990
|
-
|
|
20018
|
+
chunkGMUVWKOK_cjs.setArkPsbtField(arkTx, 0, chunkGMUVWKOK_cjs.PrevArkTxField, coin.sourceTx);
|
|
19991
20019
|
}
|
|
19992
20020
|
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19993
20021
|
if (condition.length > 0) {
|
|
19994
|
-
|
|
19995
|
-
|
|
20022
|
+
chunkGMUVWKOK_cjs.setArkPsbtField(arkTx, 0, chunkGMUVWKOK_cjs.ConditionWitness, condition);
|
|
20023
|
+
chunkGMUVWKOK_cjs.setArkPsbtField(checkpoints[0], 0, chunkGMUVWKOK_cjs.ConditionWitness, condition);
|
|
19996
20024
|
}
|
|
19997
20025
|
const packets = [];
|
|
19998
20026
|
if (this.assetSpecs.length > 0) {
|
|
@@ -20031,7 +20059,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
20031
20059
|
base.base64.encode(signedArk2.toPSBT()),
|
|
20032
20060
|
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
20033
20061
|
);
|
|
20034
|
-
const txid =
|
|
20062
|
+
const txid = chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
20035
20063
|
return {
|
|
20036
20064
|
txid,
|
|
20037
20065
|
signedArkTx: res2.signedArkTx,
|
|
@@ -20049,7 +20077,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
20049
20077
|
const finalCps = await Promise.all(
|
|
20050
20078
|
res.signedCheckpointTxs.map(
|
|
20051
20079
|
async (b) => base.base64.encode(
|
|
20052
|
-
(await client.identity.sign(
|
|
20080
|
+
(await client.identity.sign(chunkGMUVWKOK_cjs.Transaction.fromPSBT(base.base64.decode(b)), [0])).toPSBT()
|
|
20053
20081
|
)
|
|
20054
20082
|
)
|
|
20055
20083
|
);
|
|
@@ -20090,23 +20118,23 @@ var ArkadeTransactionBuilder = class {
|
|
|
20090
20118
|
}
|
|
20091
20119
|
buildAssetPacket() {
|
|
20092
20120
|
const groups = this.assetSpecs.map((s) => {
|
|
20093
|
-
const id = typeof s.assetId === "string" ?
|
|
20094
|
-
return
|
|
20121
|
+
const id = typeof s.assetId === "string" ? chunkRNECH3TA_cjs.AssetId.fromString(s.assetId) : chunkRNECH3TA_cjs.AssetId.fromBytes(s.assetId);
|
|
20122
|
+
return chunkRNECH3TA_cjs.AssetGroup.create(
|
|
20095
20123
|
id,
|
|
20096
20124
|
null,
|
|
20097
|
-
s.inputs.map((i) =>
|
|
20098
|
-
s.outputs.map((o) =>
|
|
20099
|
-
(s.metadata ?? []).map((m) =>
|
|
20125
|
+
s.inputs.map((i) => chunkRNECH3TA_cjs.AssetInput.create(i.vin, i.amount)),
|
|
20126
|
+
s.outputs.map((o) => chunkRNECH3TA_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
20127
|
+
(s.metadata ?? []).map((m) => chunkRNECH3TA_cjs.Metadata.create(m.key, m.value))
|
|
20100
20128
|
);
|
|
20101
20129
|
});
|
|
20102
|
-
return
|
|
20130
|
+
return chunkRNECH3TA_cjs.Packet.create(groups);
|
|
20103
20131
|
}
|
|
20104
20132
|
witnessBytes(ref) {
|
|
20105
|
-
return
|
|
20133
|
+
return chunk53XNU2EL_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
20106
20134
|
}
|
|
20107
20135
|
};
|
|
20108
20136
|
function bindInputs(fn, callArgs) {
|
|
20109
|
-
const names = (fn.def.inputs ?? []).map(
|
|
20137
|
+
const names = (fn.def.inputs ?? []).map(chunk53XNU2EL_cjs.inputName);
|
|
20110
20138
|
if (callArgs.length !== names.length) {
|
|
20111
20139
|
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
20112
20140
|
}
|
|
@@ -20134,6 +20162,360 @@ function attachExtension(tx, newPackets) {
|
|
|
20134
20162
|
}
|
|
20135
20163
|
tx.addOutput({ script: newOut.script, amount: newOut.amount });
|
|
20136
20164
|
}
|
|
20165
|
+
|
|
20166
|
+
// src/utils/bip21.ts
|
|
20167
|
+
var BIP21Error = /* @__PURE__ */ ((BIP21Error2) => {
|
|
20168
|
+
BIP21Error2["INVALID_URI"] = "Invalid BIP21 URI";
|
|
20169
|
+
BIP21Error2["INVALID_ADDRESS"] = "Invalid address";
|
|
20170
|
+
return BIP21Error2;
|
|
20171
|
+
})(BIP21Error || {});
|
|
20172
|
+
var BIP21 = class _BIP21 {
|
|
20173
|
+
/**
|
|
20174
|
+
* Create a BIP21 URI from the provided parameters.
|
|
20175
|
+
*
|
|
20176
|
+
* @param params - BIP21 parameters to encode
|
|
20177
|
+
* @returns Encoded BIP21 URI
|
|
20178
|
+
*/
|
|
20179
|
+
static create(params) {
|
|
20180
|
+
const { address, ...options } = params;
|
|
20181
|
+
const queryParams = {};
|
|
20182
|
+
for (const [key, value] of Object.entries(options)) {
|
|
20183
|
+
if (value === void 0) continue;
|
|
20184
|
+
if (key === "amount") {
|
|
20185
|
+
const amount = value;
|
|
20186
|
+
if (!isFinite(amount) || !Number.isSafeInteger(Math.trunc(amount))) {
|
|
20187
|
+
console.warn("Invalid amount");
|
|
20188
|
+
continue;
|
|
20189
|
+
}
|
|
20190
|
+
if (amount < 0) {
|
|
20191
|
+
continue;
|
|
20192
|
+
}
|
|
20193
|
+
queryParams[key] = value;
|
|
20194
|
+
} else if (key === "ark") {
|
|
20195
|
+
if (typeof value === "string" && (value.startsWith("ark") || value.startsWith("tark"))) {
|
|
20196
|
+
queryParams[key] = value;
|
|
20197
|
+
} else {
|
|
20198
|
+
console.warn("Invalid ARK address format");
|
|
20199
|
+
}
|
|
20200
|
+
} else if (key === "sp") {
|
|
20201
|
+
if (typeof value === "string" && value.startsWith("sp")) {
|
|
20202
|
+
queryParams[key] = value;
|
|
20203
|
+
} else {
|
|
20204
|
+
console.warn("Invalid Silent Payment address format");
|
|
20205
|
+
}
|
|
20206
|
+
} else if (typeof value === "string" || typeof value === "number") {
|
|
20207
|
+
queryParams[key] = value;
|
|
20208
|
+
}
|
|
20209
|
+
}
|
|
20210
|
+
const query = Object.keys(queryParams).length > 0 ? "?" + new URLSearchParams(
|
|
20211
|
+
Object.fromEntries(
|
|
20212
|
+
Object.entries(queryParams).map(([k, v]) => [k, String(v)])
|
|
20213
|
+
)
|
|
20214
|
+
).toString() : "";
|
|
20215
|
+
return `bitcoin:${address ? address.toLowerCase() : ""}${query}`;
|
|
20216
|
+
}
|
|
20217
|
+
/**
|
|
20218
|
+
* Integer-sats amount encoded in a BIP21 URI (`amount=` is BTC), or
|
|
20219
|
+
* `undefined` when absent or the URI is unparseable. Shared by the payment
|
|
20220
|
+
* rails, which accept either a bare address or a BIP21 URI.
|
|
20221
|
+
*
|
|
20222
|
+
* @param uri - BIP21 URI (or bare address) to read the amount from
|
|
20223
|
+
* @returns The amount in satoshis, or `undefined`
|
|
20224
|
+
*/
|
|
20225
|
+
static amountSats(uri) {
|
|
20226
|
+
try {
|
|
20227
|
+
const btc = _BIP21.parse(uri).params.amount;
|
|
20228
|
+
return typeof btc === "number" ? Math.round(btc * 1e8) : void 0;
|
|
20229
|
+
} catch {
|
|
20230
|
+
return void 0;
|
|
20231
|
+
}
|
|
20232
|
+
}
|
|
20233
|
+
/**
|
|
20234
|
+
* Parse a BIP21 URI and return its decoded parameters.
|
|
20235
|
+
*
|
|
20236
|
+
* @param uri - BIP21 URI to parse
|
|
20237
|
+
* @returns Parsed BIP21 URI data
|
|
20238
|
+
* @throws Error if the URI does not start with the `bitcoin:` scheme
|
|
20239
|
+
*/
|
|
20240
|
+
static parse(uri) {
|
|
20241
|
+
if (!uri.toLowerCase().startsWith("bitcoin:")) {
|
|
20242
|
+
throw new Error("Invalid BIP21 URI" /* INVALID_URI */);
|
|
20243
|
+
}
|
|
20244
|
+
const withoutPrefix = uri.slice(uri.toLowerCase().indexOf("bitcoin:") + 8);
|
|
20245
|
+
const [address, query] = withoutPrefix.split("?");
|
|
20246
|
+
const params = {};
|
|
20247
|
+
if (address) {
|
|
20248
|
+
params.address = address.toLowerCase();
|
|
20249
|
+
}
|
|
20250
|
+
if (query) {
|
|
20251
|
+
const queryParams = new URLSearchParams(query);
|
|
20252
|
+
for (const [key, value] of queryParams.entries()) {
|
|
20253
|
+
if (!value) continue;
|
|
20254
|
+
if (key === "amount") {
|
|
20255
|
+
if (!/^(?:\d+\.?\d*|\.\d+)$/.test(value)) {
|
|
20256
|
+
continue;
|
|
20257
|
+
}
|
|
20258
|
+
const amount = Number(value);
|
|
20259
|
+
if (!isFinite(amount) || !Number.isSafeInteger(Math.trunc(amount))) {
|
|
20260
|
+
continue;
|
|
20261
|
+
}
|
|
20262
|
+
params[key] = amount;
|
|
20263
|
+
} else if (key === "ark") {
|
|
20264
|
+
if (value.startsWith("ark") || value.startsWith("tark")) {
|
|
20265
|
+
params[key] = value;
|
|
20266
|
+
} else {
|
|
20267
|
+
console.warn("Invalid ARK address format");
|
|
20268
|
+
}
|
|
20269
|
+
} else if (key === "sp") {
|
|
20270
|
+
if (value.startsWith("sp")) {
|
|
20271
|
+
params[key] = value;
|
|
20272
|
+
} else {
|
|
20273
|
+
console.warn("Invalid Silent Payment address format");
|
|
20274
|
+
}
|
|
20275
|
+
} else {
|
|
20276
|
+
params[key] = value;
|
|
20277
|
+
}
|
|
20278
|
+
}
|
|
20279
|
+
}
|
|
20280
|
+
return {
|
|
20281
|
+
originalString: uri,
|
|
20282
|
+
params
|
|
20283
|
+
};
|
|
20284
|
+
}
|
|
20285
|
+
};
|
|
20286
|
+
|
|
20287
|
+
// src/payment/predicates.ts
|
|
20288
|
+
var isLightningInvoice = (raw) => /^ln(bcrt|bc|tbs|tb|sb)[0-9a-z]+$/i.test(raw.replace(/^lightning:/i, ""));
|
|
20289
|
+
var isLnurl = (raw) => /^lnurl/i.test(raw) || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(raw);
|
|
20290
|
+
var BECH32_BTC = /^(bc1|tb1|bcrt1)[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{6,90}$/;
|
|
20291
|
+
var isBech32Btc = (raw) => (raw === raw.toLowerCase() || raw === raw.toUpperCase()) && BECH32_BTC.test(raw.toLowerCase());
|
|
20292
|
+
var isBtcAddress = (raw) => isBech32Btc(raw) || /^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,39}$/.test(raw);
|
|
20293
|
+
|
|
20294
|
+
// src/payment/targets.ts
|
|
20295
|
+
var fromBip21 = (raw, key, accept) => {
|
|
20296
|
+
try {
|
|
20297
|
+
const v = BIP21.parse(raw).params[key];
|
|
20298
|
+
return typeof v === "string" && accept(v) ? v : void 0;
|
|
20299
|
+
} catch {
|
|
20300
|
+
return void 0;
|
|
20301
|
+
}
|
|
20302
|
+
};
|
|
20303
|
+
var arkTarget = (raw) => isValidArkAddress2(raw) ? raw : fromBip21(raw, "ark", isValidArkAddress2);
|
|
20304
|
+
var btcTarget = (raw) => isBtcAddress(raw) ? raw : fromBip21(raw, "address", isBtcAddress);
|
|
20305
|
+
var invoiceTarget = (raw) => {
|
|
20306
|
+
const invoice = isLightningInvoice(raw) ? raw : fromBip21(raw, "lightning", isLightningInvoice);
|
|
20307
|
+
return invoice?.replace(/^lightning:/i, "");
|
|
20308
|
+
};
|
|
20309
|
+
|
|
20310
|
+
// src/payment/amount.ts
|
|
20311
|
+
function assertSendableAmount(railId, amt) {
|
|
20312
|
+
if (!Number.isInteger(amt) || amt <= 0) {
|
|
20313
|
+
throw new Error(`${railId}: invalid amount ${amt} sats (expected a positive integer)`);
|
|
20314
|
+
}
|
|
20315
|
+
}
|
|
20316
|
+
function resolveSendAmount(railId, raw, amount) {
|
|
20317
|
+
const amt = amount ?? BIP21.amountSats(raw);
|
|
20318
|
+
if (amt === void 0) {
|
|
20319
|
+
throw new Error(
|
|
20320
|
+
`${railId}: an amount is required (none provided or encoded in the request)`
|
|
20321
|
+
);
|
|
20322
|
+
}
|
|
20323
|
+
assertSendableAmount(railId, amt);
|
|
20324
|
+
return amt;
|
|
20325
|
+
}
|
|
20326
|
+
function tryResolveSendAmount(raw, amount) {
|
|
20327
|
+
const amt = amount ?? BIP21.amountSats(raw);
|
|
20328
|
+
return amt !== void 0 && Number.isInteger(amt) && amt > 0 ? amt : void 0;
|
|
20329
|
+
}
|
|
20330
|
+
|
|
20331
|
+
// src/payment/handle.ts
|
|
20332
|
+
function makeHandle(id, run) {
|
|
20333
|
+
let status = "pending";
|
|
20334
|
+
let last = { status };
|
|
20335
|
+
const subs = /* @__PURE__ */ new Set();
|
|
20336
|
+
const notify = (f, u) => {
|
|
20337
|
+
try {
|
|
20338
|
+
f(u);
|
|
20339
|
+
} catch {
|
|
20340
|
+
}
|
|
20341
|
+
};
|
|
20342
|
+
const isTerminal = (s) => s === "settled" || s === "failed";
|
|
20343
|
+
const emit = (u) => {
|
|
20344
|
+
status = u.status;
|
|
20345
|
+
last = u;
|
|
20346
|
+
for (const f of subs) notify(f, u);
|
|
20347
|
+
if (isTerminal(u.status)) subs.clear();
|
|
20348
|
+
};
|
|
20349
|
+
const done = run(emit);
|
|
20350
|
+
done.catch((error) => {
|
|
20351
|
+
if (status !== "settled") emit({ status: "failed", error });
|
|
20352
|
+
});
|
|
20353
|
+
return {
|
|
20354
|
+
id,
|
|
20355
|
+
get status() {
|
|
20356
|
+
return status;
|
|
20357
|
+
},
|
|
20358
|
+
subscribe(fn) {
|
|
20359
|
+
notify(fn, last);
|
|
20360
|
+
if (isTerminal(status)) return () => {
|
|
20361
|
+
};
|
|
20362
|
+
subs.add(fn);
|
|
20363
|
+
return () => subs.delete(fn);
|
|
20364
|
+
},
|
|
20365
|
+
settled(opts) {
|
|
20366
|
+
if (!opts?.timeoutMs) return done;
|
|
20367
|
+
let timer;
|
|
20368
|
+
return Promise.race([
|
|
20369
|
+
done,
|
|
20370
|
+
new Promise((_, rej) => {
|
|
20371
|
+
timer = setTimeout(() => rej(new Error("settle timeout")), opts.timeoutMs);
|
|
20372
|
+
})
|
|
20373
|
+
]).finally(() => clearTimeout(timer));
|
|
20374
|
+
}
|
|
20375
|
+
};
|
|
20376
|
+
}
|
|
20377
|
+
|
|
20378
|
+
// src/payment/router.ts
|
|
20379
|
+
var AmbiguousRouteError = class extends Error {
|
|
20380
|
+
constructor(railIds) {
|
|
20381
|
+
super(`ambiguous route: ${railIds.join(", ")}`);
|
|
20382
|
+
this.railIds = railIds;
|
|
20383
|
+
this.name = "AmbiguousRouteError";
|
|
20384
|
+
}
|
|
20385
|
+
railIds;
|
|
20386
|
+
};
|
|
20387
|
+
var PaymentRouter = class {
|
|
20388
|
+
constructor(ctx) {
|
|
20389
|
+
this.ctx = ctx;
|
|
20390
|
+
}
|
|
20391
|
+
ctx;
|
|
20392
|
+
rails = /* @__PURE__ */ new Map();
|
|
20393
|
+
/** Register a rail (or overwrite one with the same id). */
|
|
20394
|
+
use(rail) {
|
|
20395
|
+
this.rails.set(rail.id, rail);
|
|
20396
|
+
return this;
|
|
20397
|
+
}
|
|
20398
|
+
/** Remove a rail by id. */
|
|
20399
|
+
remove(id) {
|
|
20400
|
+
this.rails.delete(id);
|
|
20401
|
+
return this;
|
|
20402
|
+
}
|
|
20403
|
+
/** Rails matching `req`, filtered by `disabled`/`available()`, ranked by
|
|
20404
|
+
* `priority` (unlisted rails keep insertion order, after listed ones). */
|
|
20405
|
+
async options(req, prefs) {
|
|
20406
|
+
const merged = { ...this.ctx.prefs, ...prefs };
|
|
20407
|
+
const ctx = { ...this.ctx, prefs: merged };
|
|
20408
|
+
const matched = [...this.rails.values()].filter(
|
|
20409
|
+
(rail) => !merged.disabled?.includes(rail.id) && rail.match(req, ctx)
|
|
20410
|
+
);
|
|
20411
|
+
const available = (await Promise.all(
|
|
20412
|
+
matched.map(async (rail) => {
|
|
20413
|
+
try {
|
|
20414
|
+
return await rail.available?.(req, ctx) ?? true ? rail : null;
|
|
20415
|
+
} catch (e) {
|
|
20416
|
+
console.warn(`payment rail "${rail.id}": available() threw`, e);
|
|
20417
|
+
return null;
|
|
20418
|
+
}
|
|
20419
|
+
})
|
|
20420
|
+
)).filter((rail) => rail !== null);
|
|
20421
|
+
const rank = (id) => {
|
|
20422
|
+
const i = merged.priority?.indexOf(id) ?? -1;
|
|
20423
|
+
return i < 0 ? Number.MAX_SAFE_INTEGER : i;
|
|
20424
|
+
};
|
|
20425
|
+
available.sort((a, b) => rank(a.id) - rank(b.id));
|
|
20426
|
+
return available.map((rail) => ({
|
|
20427
|
+
railId: rail.id,
|
|
20428
|
+
quote: () => rail.quote(req, ctx)
|
|
20429
|
+
}));
|
|
20430
|
+
}
|
|
20431
|
+
/** Top-ranked option's quote. Throws when nothing routes, or
|
|
20432
|
+
* {@link AmbiguousRouteError} when `tieBreak` is `"require-choice"` and
|
|
20433
|
+
* more than one option survives. */
|
|
20434
|
+
async route(req, prefs) {
|
|
20435
|
+
const options = await this.options(req, prefs);
|
|
20436
|
+
if (options.length === 0) {
|
|
20437
|
+
throw new Error(`no rail for: ${req.raw}`);
|
|
20438
|
+
}
|
|
20439
|
+
const tieBreak = { ...this.ctx.prefs, ...prefs }.tieBreak ?? "first";
|
|
20440
|
+
if (tieBreak === "require-choice" && options.length > 1) {
|
|
20441
|
+
throw new AmbiguousRouteError(options.map((o) => o.railId));
|
|
20442
|
+
}
|
|
20443
|
+
return options[0].quote();
|
|
20444
|
+
}
|
|
20445
|
+
};
|
|
20446
|
+
|
|
20447
|
+
// src/payment/rails/ark.ts
|
|
20448
|
+
function arkRail() {
|
|
20449
|
+
return {
|
|
20450
|
+
id: "ark",
|
|
20451
|
+
match: (req) => arkTarget(req.raw) !== void 0,
|
|
20452
|
+
quote: async (req, ctx) => {
|
|
20453
|
+
const address = arkTarget(req.raw);
|
|
20454
|
+
const amt = resolveSendAmount("ark", req.raw, req.amount);
|
|
20455
|
+
return {
|
|
20456
|
+
railId: "ark",
|
|
20457
|
+
amount: amt,
|
|
20458
|
+
fee: 0,
|
|
20459
|
+
total: amt,
|
|
20460
|
+
send: async () => makeHandle("ark", async (emit) => {
|
|
20461
|
+
const txid = await ctx.wallet.send({ address, amount: amt });
|
|
20462
|
+
const result = { railId: "ark", txid };
|
|
20463
|
+
emit({ status: "settled", result });
|
|
20464
|
+
return result;
|
|
20465
|
+
})
|
|
20466
|
+
};
|
|
20467
|
+
}
|
|
20468
|
+
};
|
|
20469
|
+
}
|
|
20470
|
+
var GROSS_UP_MAX_ROUNDS = 8;
|
|
20471
|
+
function grossUpOffboard(net, feeInfo, script) {
|
|
20472
|
+
const estimator = new Estimator(feeInfo?.intentFee ?? {});
|
|
20473
|
+
const feeAt = (amount) => estimator.evalOnchainOutput({ amount: BigInt(amount), script }).satoshis;
|
|
20474
|
+
let gross = net;
|
|
20475
|
+
for (let i = 0; i < GROSS_UP_MAX_ROUNDS; i++) {
|
|
20476
|
+
const next = net + feeAt(gross);
|
|
20477
|
+
if (next === gross) break;
|
|
20478
|
+
gross = next;
|
|
20479
|
+
}
|
|
20480
|
+
return { gross, fee: gross - net };
|
|
20481
|
+
}
|
|
20482
|
+
function onchainRail() {
|
|
20483
|
+
return {
|
|
20484
|
+
id: "onchain",
|
|
20485
|
+
match: (req) => btcTarget(req.raw) !== void 0,
|
|
20486
|
+
quote: async (req, ctx) => {
|
|
20487
|
+
const address = btcTarget(req.raw);
|
|
20488
|
+
const amt = resolveSendAmount("onchain", req.raw, req.amount);
|
|
20489
|
+
const { fees } = await ctx.wallet.arkProvider.getInfo();
|
|
20490
|
+
const script = base.hex.encode(offboardDestinationScript(address));
|
|
20491
|
+
const { gross, fee } = grossUpOffboard(amt, fees, script);
|
|
20492
|
+
return {
|
|
20493
|
+
railId: "onchain",
|
|
20494
|
+
amount: amt,
|
|
20495
|
+
fee,
|
|
20496
|
+
total: gross,
|
|
20497
|
+
send: async () => makeHandle("onchain", async (emit) => {
|
|
20498
|
+
const txid = await new Ramps(ctx.wallet).offboard(
|
|
20499
|
+
address,
|
|
20500
|
+
fees,
|
|
20501
|
+
BigInt(gross)
|
|
20502
|
+
);
|
|
20503
|
+
const result = { railId: "onchain", txid };
|
|
20504
|
+
emit({ status: "settled", result });
|
|
20505
|
+
return result;
|
|
20506
|
+
})
|
|
20507
|
+
};
|
|
20508
|
+
}
|
|
20509
|
+
};
|
|
20510
|
+
}
|
|
20511
|
+
|
|
20512
|
+
// src/payment/index.ts
|
|
20513
|
+
function createDefaultPaymentRouter(wallet) {
|
|
20514
|
+
return new PaymentRouter({
|
|
20515
|
+
wallet,
|
|
20516
|
+
prefs: { priority: ["ark", "lightning", "onchain"] }
|
|
20517
|
+
}).use(arkRail()).use(onchainRail());
|
|
20518
|
+
}
|
|
20137
20519
|
var ARKCONTRACT_PREFIX = "arkcontract";
|
|
20138
20520
|
function encodeArkContract(contract) {
|
|
20139
20521
|
const params = new URLSearchParams();
|
|
@@ -20159,7 +20541,7 @@ function decodeArkContract(encoded) {
|
|
|
20159
20541
|
}
|
|
20160
20542
|
function contractFromArkContract(encoded, options = {}) {
|
|
20161
20543
|
const parsed = decodeArkContract(encoded);
|
|
20162
|
-
const handler =
|
|
20544
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.get(parsed.type);
|
|
20163
20545
|
if (!handler) {
|
|
20164
20546
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
20165
20547
|
}
|
|
@@ -20173,9 +20555,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
20173
20555
|
metadata: options.metadata
|
|
20174
20556
|
};
|
|
20175
20557
|
}
|
|
20176
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
20558
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkGMUVWKOK_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
20177
20559
|
const parsed = decodeArkContract(encoded);
|
|
20178
|
-
const handler =
|
|
20560
|
+
const handler = chunk53XNU2EL_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
20179
20561
|
const params = parsed.data;
|
|
20180
20562
|
const vtxoScript = handler.createScript(params);
|
|
20181
20563
|
return {
|
|
@@ -20195,10 +20577,13 @@ function isArkContract(str) {
|
|
|
20195
20577
|
|
|
20196
20578
|
exports.ARKADE_MAGIC = ARKADE_MAGIC;
|
|
20197
20579
|
exports.ActivityRegistry = ActivityRegistry;
|
|
20580
|
+
exports.AmbiguousRouteError = AmbiguousRouteError;
|
|
20198
20581
|
exports.ArkNote = ArkNote;
|
|
20199
20582
|
exports.ArkadeCash = ArkadeCash;
|
|
20200
20583
|
exports.ArkadeCashCreateError = ArkadeCashCreateError;
|
|
20201
20584
|
exports.AssetManager = AssetManager;
|
|
20585
|
+
exports.BIP21 = BIP21;
|
|
20586
|
+
exports.BIP21Error = BIP21Error;
|
|
20202
20587
|
exports.ChainedTxType = ChainedTxType;
|
|
20203
20588
|
exports.ContractManager = ContractManager;
|
|
20204
20589
|
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
@@ -20240,6 +20625,7 @@ exports.MissingSigningDescriptorError = MissingSigningDescriptorError;
|
|
|
20240
20625
|
exports.MnemonicIdentity = MnemonicIdentity;
|
|
20241
20626
|
exports.OnchainWallet = OnchainWallet;
|
|
20242
20627
|
exports.P2A = P2A;
|
|
20628
|
+
exports.PaymentRouter = PaymentRouter;
|
|
20243
20629
|
exports.Ramps = Ramps;
|
|
20244
20630
|
exports.ReadonlyAssetManager = ReadonlyAssetManager;
|
|
20245
20631
|
exports.ReadonlyDescriptorIdentity = ReadonlyDescriptorIdentity;
|
|
@@ -20265,9 +20651,13 @@ exports.WalletMessageHandler = WalletMessageHandler;
|
|
|
20265
20651
|
exports.WalletNotInitializedError = WalletNotInitializedError;
|
|
20266
20652
|
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
|
20267
20653
|
exports.WsElectrumChainSource = WsElectrumChainSource;
|
|
20654
|
+
exports.arkRail = arkRail;
|
|
20655
|
+
exports.arkTarget = arkTarget;
|
|
20268
20656
|
exports.arkade_exports = arkade_exports;
|
|
20269
20657
|
exports.assertIntentIdUnique = assertIntentIdUnique;
|
|
20658
|
+
exports.assertSendableAmount = assertSendableAmount;
|
|
20270
20659
|
exports.boardingResolver = boardingResolver;
|
|
20660
|
+
exports.btcTarget = btcTarget;
|
|
20271
20661
|
exports.buildForfeitTx = buildForfeitTx;
|
|
20272
20662
|
exports.buildOffchainTx = buildOffchainTx;
|
|
20273
20663
|
exports.classifyAgainstSignerSet = classifyAgainstSignerSet;
|
|
@@ -20278,6 +20668,7 @@ exports.contractFromArkContract = contractFromArkContract;
|
|
|
20278
20668
|
exports.contractFromArkContractWithAddress = contractFromArkContractWithAddress;
|
|
20279
20669
|
exports.createAssetPacket = createAssetPacket;
|
|
20280
20670
|
exports.createDefaultActivityRegistry = createDefaultActivityRegistry;
|
|
20671
|
+
exports.createDefaultPaymentRouter = createDefaultPaymentRouter;
|
|
20281
20672
|
exports.createExitChainResolver = createExitChainResolver;
|
|
20282
20673
|
exports.decodeArkContract = decodeArkContract;
|
|
20283
20674
|
exports.deserializeAssets = deserializeAssets;
|
|
@@ -20292,22 +20683,28 @@ exports.hasBoardingTxExpired = hasBoardingTxExpired;
|
|
|
20292
20683
|
exports.hasCandidates = hasCandidates;
|
|
20293
20684
|
exports.intentMatchesFilter = intentMatchesFilter;
|
|
20294
20685
|
exports.intentPageBounds = intentPageBounds;
|
|
20686
|
+
exports.invoiceTarget = invoiceTarget;
|
|
20295
20687
|
exports.isArkContract = isArkContract;
|
|
20296
20688
|
exports.isBatchSignable = isBatchSignable;
|
|
20689
|
+
exports.isBtcAddress = isBtcAddress;
|
|
20297
20690
|
exports.isCooperativelyMigratable = isCooperativelyMigratable;
|
|
20298
20691
|
exports.isDiscoverable = isDiscoverable;
|
|
20692
|
+
exports.isLightningInvoice = isLightningInvoice;
|
|
20693
|
+
exports.isLnurl = isLnurl;
|
|
20299
20694
|
exports.isMessageBusInitializingError = isMessageBusInitializingError;
|
|
20300
20695
|
exports.isMessageBusNotInitializedError = isMessageBusNotInitializedError;
|
|
20301
|
-
exports.isRetryableProviderError = isRetryableProviderError;
|
|
20302
20696
|
exports.isSubdust = isSubdust;
|
|
20303
20697
|
exports.isTerminalIntentState = isTerminalIntentState;
|
|
20304
20698
|
exports.isValidArkAddress = isValidArkAddress;
|
|
20305
20699
|
exports.isVtxoExpiringSoon = isVtxoExpiringSoon;
|
|
20306
20700
|
exports.isVtxoForScript = isVtxoForScript;
|
|
20701
|
+
exports.makeHandle = makeHandle;
|
|
20307
20702
|
exports.mergeChainedTxType = mergeChainedTxType;
|
|
20308
20703
|
exports.migrateWalletRepository = migrateWalletRepository;
|
|
20704
|
+
exports.onchainRail = onchainRail;
|
|
20309
20705
|
exports.openDatabase = openDatabase;
|
|
20310
20706
|
exports.requiresMigration = requiresMigration;
|
|
20707
|
+
exports.resolveSendAmount = resolveSendAmount;
|
|
20311
20708
|
exports.rollbackMigration = rollbackMigration;
|
|
20312
20709
|
exports.saveVtxosForContract = saveVtxosForContract;
|
|
20313
20710
|
exports.scriptFromArkAddress = scriptFromArkAddress;
|
|
@@ -20320,10 +20717,11 @@ exports.serializeVtxo = serializeVtxo;
|
|
|
20320
20717
|
exports.setupServiceWorker = setupServiceWorker;
|
|
20321
20718
|
exports.signerSetFromInfo = signerSetFromInfo;
|
|
20322
20719
|
exports.toXOnlySignerHex = toXOnlySignerHex;
|
|
20720
|
+
exports.tryResolveSendAmount = tryResolveSendAmount;
|
|
20323
20721
|
exports.validateConnectorsTxGraph = validateConnectorsTxGraph;
|
|
20324
20722
|
exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
20325
20723
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
20326
20724
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
20327
20725
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
20328
|
-
//# sourceMappingURL=chunk-
|
|
20329
|
-
//# sourceMappingURL=chunk-
|
|
20726
|
+
//# sourceMappingURL=chunk-D5LUPJJP.cjs.map
|
|
20727
|
+
//# sourceMappingURL=chunk-D5LUPJJP.cjs.map
|