@arkade-os/sdk 0.4.46 → 0.4.47
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-C9ognsOV.d.cts → ark-CoJgwTi_.d.cts} +26 -2
- package/dist/{ark-C9ognsOV.d.ts → ark-CoJgwTi_.d.ts} +26 -2
- package/dist/{asyncStorageTaskQueue-CmBYVlxw.d.cts → asyncStorageTaskQueue-Dowyo59a.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-BAKZ5cS5.d.ts → asyncStorageTaskQueue-Z3aFoXCl.d.ts} +2 -2
- package/dist/{chunk-R2SVAM5Q.js → chunk-3N5I6GT6.js} +3 -3
- package/dist/{chunk-R2SVAM5Q.js.map → chunk-3N5I6GT6.js.map} +1 -1
- package/dist/{chunk-JTCQ6QXQ.js → chunk-AJQ4AOT3.js} +4 -4
- package/dist/{chunk-JTCQ6QXQ.js.map → chunk-AJQ4AOT3.js.map} +1 -1
- package/dist/{chunk-FWG4TSPN.js → chunk-C7TXXTMS.js} +4 -5
- package/dist/chunk-C7TXXTMS.js.map +1 -0
- package/dist/{chunk-CWJ7ZCP7.js → chunk-CDDWXBEM.js} +87 -16
- package/dist/chunk-CDDWXBEM.js.map +1 -0
- package/dist/{chunk-7IYIFMF4.cjs → chunk-HHV5FPC6.cjs} +94 -20
- package/dist/chunk-HHV5FPC6.cjs.map +1 -0
- package/dist/{chunk-SOXGAA52.cjs → chunk-JAYOXOLT.cjs} +14 -14
- package/dist/{chunk-SOXGAA52.cjs.map → chunk-JAYOXOLT.cjs.map} +1 -1
- package/dist/{chunk-MQB5H4X5.cjs → chunk-L5ND2FJJ.cjs} +4 -5
- package/dist/chunk-L5ND2FJJ.cjs.map +1 -0
- package/dist/{chunk-P6VBP3CT.js → chunk-OCS5S3L3.js} +1010 -98
- package/dist/chunk-OCS5S3L3.js.map +1 -0
- package/dist/chunk-RQSA7ADZ.cjs +2286 -0
- package/dist/chunk-RQSA7ADZ.cjs.map +1 -0
- package/dist/{chunk-6TQJOD72.cjs → chunk-VE67GMGM.cjs} +7 -7
- package/dist/{chunk-6TQJOD72.cjs.map → chunk-VE67GMGM.cjs.map} +1 -1
- package/dist/{chunk-D46YDM36.cjs → chunk-WTTLIFS7.cjs} +1207 -285
- package/dist/chunk-WTTLIFS7.cjs.map +1 -0
- package/dist/chunk-XN3554FT.js +2244 -0
- package/dist/chunk-XN3554FT.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +11 -7
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-aOd5qINr.d.ts → delegate-CuaDqqQi.d.ts} +1 -1
- package/dist/{delegate-DVEgyRwI.d.cts → delegate-Dl87_zMA.d.cts} +1 -1
- package/dist/index-BC_G0VTh.d.cts +512 -0
- package/dist/index-CKwpZEpw.d.ts +512 -0
- package/dist/index.cjs +213 -161
- package/dist/index.d.cts +3097 -2090
- package/dist/index.d.ts +3097 -2090
- 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-B48-V-Pb.d.ts → taskRunner-Dz-TI4Rb.d.ts} +2 -2
- package/dist/{taskRunner-nNecmQ2C.d.cts → taskRunner-Dz47k0lp.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +14 -14
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +5 -5
- package/dist/{wallet-BUg3D4WJ.d.cts → wallet-Oxz_wLxo.d.cts} +13 -3
- package/dist/{wallet-DM0oShTu.d.ts → wallet-x7egmXq6.d.ts} +13 -3
- 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-4KXOCVXP.cjs +0 -973
- package/dist/chunk-4KXOCVXP.cjs.map +0 -1
- package/dist/chunk-7IYIFMF4.cjs.map +0 -1
- package/dist/chunk-CWJ7ZCP7.js.map +0 -1
- package/dist/chunk-D46YDM36.cjs.map +0 -1
- package/dist/chunk-FWG4TSPN.js.map +0 -1
- package/dist/chunk-MQB5H4X5.cjs.map +0 -1
- package/dist/chunk-P6VBP3CT.js.map +0 -1
- package/dist/chunk-QKC2T54O.js +0 -960
- package/dist/chunk-QKC2T54O.js.map +0 -1
- package/dist/index-CPzL4tqg.d.ts +0 -259
- package/dist/index-D8vmtWWO.d.cts +0 -259
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkHHV5FPC6_cjs = require('./chunk-HHV5FPC6.cjs');
|
|
4
|
+
var chunkRQSA7ADZ_cjs = require('./chunk-RQSA7ADZ.cjs');
|
|
5
|
+
var chunkL5ND2FJJ_cjs = require('./chunk-L5ND2FJJ.cjs');
|
|
6
|
+
var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
|
|
6
7
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
7
8
|
var btcSigner = require('@scure/btc-signer');
|
|
8
9
|
var base = require('@scure/base');
|
|
@@ -184,7 +185,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
184
185
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
185
186
|
const tx = this.graph.find(txid);
|
|
186
187
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
187
|
-
const cosigners =
|
|
188
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(tx.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey).map(
|
|
188
189
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
189
190
|
// xonly pubkey
|
|
190
191
|
);
|
|
@@ -236,7 +237,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
236
237
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
237
238
|
const prevoutAmounts = [];
|
|
238
239
|
const prevoutScripts = [];
|
|
239
|
-
const cosigners =
|
|
240
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(g.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey).map((c) => c.key);
|
|
240
241
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
241
242
|
taprootTweak: this.scriptRoot
|
|
242
243
|
});
|
|
@@ -415,7 +416,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
415
416
|
let network;
|
|
416
417
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
417
418
|
descriptor = opts.descriptor;
|
|
418
|
-
network =
|
|
419
|
+
network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
419
420
|
} else {
|
|
420
421
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
421
422
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -500,7 +501,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
500
501
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
501
502
|
*/
|
|
502
503
|
isOurs(descriptor) {
|
|
503
|
-
return
|
|
504
|
+
return chunkRQSA7ADZ_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
504
505
|
}
|
|
505
506
|
/**
|
|
506
507
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -537,7 +538,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
537
538
|
}
|
|
538
539
|
// ── internal helpers ─────────────────────────────────────────────
|
|
539
540
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
540
|
-
const network =
|
|
541
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
541
542
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
542
543
|
if (expansion.isRanged) {
|
|
543
544
|
throw new Error(
|
|
@@ -623,7 +624,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
623
624
|
*/
|
|
624
625
|
descriptor;
|
|
625
626
|
constructor(descriptor) {
|
|
626
|
-
const network =
|
|
627
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
627
628
|
let expansion;
|
|
628
629
|
try {
|
|
629
630
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -673,7 +674,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
673
674
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
674
675
|
*/
|
|
675
676
|
isOurs(descriptor) {
|
|
676
|
-
return
|
|
677
|
+
return chunkRQSA7ADZ_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
677
678
|
}
|
|
678
679
|
};
|
|
679
680
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -985,14 +986,14 @@ var RestDelegateProvider = class {
|
|
|
985
986
|
*/
|
|
986
987
|
async delegate(intent, forfeitTxs, options) {
|
|
987
988
|
const url = `${this.url}/v1/delegate`;
|
|
988
|
-
const response = await
|
|
989
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(url, {
|
|
989
990
|
method: "POST",
|
|
990
991
|
headers: {
|
|
991
992
|
"Content-Type": "application/json"
|
|
992
993
|
},
|
|
993
994
|
body: JSON.stringify({
|
|
994
995
|
intent: {
|
|
995
|
-
message:
|
|
996
|
+
message: chunkHHV5FPC6_cjs.Intent.encodeMessage(intent.message),
|
|
996
997
|
proof: intent.proof
|
|
997
998
|
},
|
|
998
999
|
forfeit_txs: forfeitTxs,
|
|
@@ -1012,7 +1013,7 @@ var RestDelegateProvider = class {
|
|
|
1012
1013
|
*/
|
|
1013
1014
|
async getDelegateInfo() {
|
|
1014
1015
|
const url = `${this.url}/v1/delegator/info`;
|
|
1015
|
-
const response = await
|
|
1016
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(url);
|
|
1016
1017
|
if (!response.ok) {
|
|
1017
1018
|
const errorText2 = await response.text();
|
|
1018
1019
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1039,7 +1040,7 @@ var ESPLORA_URL = {
|
|
|
1039
1040
|
regtest: "http://localhost:3000/api"
|
|
1040
1041
|
};
|
|
1041
1042
|
var EsploraProvider = class {
|
|
1042
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1043
|
+
constructor(baseUrl = ESPLORA_URL[chunkL5ND2FJJ_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1043
1044
|
this.baseUrl = baseUrl;
|
|
1044
1045
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1045
1046
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1048,14 +1049,14 @@ var EsploraProvider = class {
|
|
|
1048
1049
|
pollingInterval;
|
|
1049
1050
|
forcePolling;
|
|
1050
1051
|
async getCoins(address) {
|
|
1051
|
-
const response = await
|
|
1052
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1052
1053
|
if (!response.ok) {
|
|
1053
1054
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1054
1055
|
}
|
|
1055
1056
|
return response.json();
|
|
1056
1057
|
}
|
|
1057
1058
|
async getFeeRate() {
|
|
1058
|
-
const response = await
|
|
1059
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1059
1060
|
if (response.status === 404) {
|
|
1060
1061
|
return void 0;
|
|
1061
1062
|
}
|
|
@@ -1076,7 +1077,7 @@ var EsploraProvider = class {
|
|
|
1076
1077
|
}
|
|
1077
1078
|
}
|
|
1078
1079
|
async getTxOutspends(txid) {
|
|
1079
|
-
const response = await
|
|
1080
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1080
1081
|
if (!response.ok) {
|
|
1081
1082
|
const error = await response.text();
|
|
1082
1083
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1084,7 +1085,7 @@ var EsploraProvider = class {
|
|
|
1084
1085
|
return response.json();
|
|
1085
1086
|
}
|
|
1086
1087
|
async getTransactions(address) {
|
|
1087
|
-
const response = await
|
|
1088
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1088
1089
|
if (!response.ok) {
|
|
1089
1090
|
const error = await response.text();
|
|
1090
1091
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1092,7 +1093,7 @@ var EsploraProvider = class {
|
|
|
1092
1093
|
return response.json();
|
|
1093
1094
|
}
|
|
1094
1095
|
async getTxStatus(txid) {
|
|
1095
|
-
const txresponse = await
|
|
1096
|
+
const txresponse = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1096
1097
|
if (!txresponse.ok) {
|
|
1097
1098
|
throw new Error(txresponse.statusText);
|
|
1098
1099
|
}
|
|
@@ -1100,7 +1101,7 @@ var EsploraProvider = class {
|
|
|
1100
1101
|
if (!tx.status.confirmed) {
|
|
1101
1102
|
return { confirmed: false };
|
|
1102
1103
|
}
|
|
1103
|
-
const response = await
|
|
1104
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1104
1105
|
if (!response.ok) {
|
|
1105
1106
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1106
1107
|
}
|
|
@@ -1184,7 +1185,7 @@ var EsploraProvider = class {
|
|
|
1184
1185
|
return stopFunc;
|
|
1185
1186
|
}
|
|
1186
1187
|
async getChainTip() {
|
|
1187
|
-
const tipBlocks = await
|
|
1188
|
+
const tipBlocks = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
1188
1189
|
if (!tipBlocks.ok) {
|
|
1189
1190
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
1190
1191
|
}
|
|
@@ -1203,7 +1204,7 @@ var EsploraProvider = class {
|
|
|
1203
1204
|
};
|
|
1204
1205
|
}
|
|
1205
1206
|
async broadcastPackage(parent, child) {
|
|
1206
|
-
const response = await
|
|
1207
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
1207
1208
|
method: "POST",
|
|
1208
1209
|
headers: {
|
|
1209
1210
|
"Content-Type": "application/json"
|
|
@@ -1217,7 +1218,7 @@ var EsploraProvider = class {
|
|
|
1217
1218
|
return response.json();
|
|
1218
1219
|
}
|
|
1219
1220
|
async broadcastTx(tx) {
|
|
1220
|
-
const response = await
|
|
1221
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
1221
1222
|
method: "POST",
|
|
1222
1223
|
headers: {
|
|
1223
1224
|
"Content-Type": "text/plain"
|
|
@@ -1379,7 +1380,7 @@ function findP2AOutput(tx) {
|
|
|
1379
1380
|
var CHILD_DUST_AMOUNT = 546;
|
|
1380
1381
|
function buildAnchorChild(params) {
|
|
1381
1382
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
1382
|
-
const child = new
|
|
1383
|
+
const child = new chunkHHV5FPC6_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
1383
1384
|
child.addInput(findP2AOutput(parent));
|
|
1384
1385
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
1385
1386
|
for (const _ of fundingCoins) {
|
|
@@ -1427,7 +1428,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
1427
1428
|
);
|
|
1428
1429
|
}
|
|
1429
1430
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
1430
|
-
const tx = new
|
|
1431
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({
|
|
1431
1432
|
version: 3,
|
|
1432
1433
|
lockTime: txLocktime
|
|
1433
1434
|
});
|
|
@@ -1503,7 +1504,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
1503
1504
|
if (previousScriptKey.length !== 32) {
|
|
1504
1505
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
1505
1506
|
}
|
|
1506
|
-
const cosigners =
|
|
1507
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(child.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey);
|
|
1507
1508
|
if (cosigners.length === 0) {
|
|
1508
1509
|
throw ErrMissingCosignersPublicKeys;
|
|
1509
1510
|
}
|
|
@@ -1534,6 +1535,62 @@ var UnknownPacket = class {
|
|
|
1534
1535
|
}
|
|
1535
1536
|
};
|
|
1536
1537
|
|
|
1538
|
+
// src/extension/emulator/packet.ts
|
|
1539
|
+
var EmulatorPacket = class _EmulatorPacket {
|
|
1540
|
+
constructor(entries) {
|
|
1541
|
+
this.entries = entries;
|
|
1542
|
+
}
|
|
1543
|
+
entries;
|
|
1544
|
+
/** PACKET_TYPE is the 1-byte TLV type tag used in the Extension envelope. */
|
|
1545
|
+
static PACKET_TYPE = 1;
|
|
1546
|
+
static create(entries) {
|
|
1547
|
+
if (entries.length === 0) {
|
|
1548
|
+
throw new Error("empty emulator packet");
|
|
1549
|
+
}
|
|
1550
|
+
for (const entry of entries) {
|
|
1551
|
+
if (entry.script.length === 0) {
|
|
1552
|
+
throw new Error(`empty script for vin ${entry.vin}`);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1556
|
+
for (const entry of entries) {
|
|
1557
|
+
if (seen.has(entry.vin)) {
|
|
1558
|
+
throw new Error(`duplicate vin ${entry.vin}`);
|
|
1559
|
+
}
|
|
1560
|
+
seen.add(entry.vin);
|
|
1561
|
+
}
|
|
1562
|
+
return new _EmulatorPacket(entries);
|
|
1563
|
+
}
|
|
1564
|
+
static fromBytes(data) {
|
|
1565
|
+
const reader = new chunkHHV5FPC6_cjs.BufferReader(data);
|
|
1566
|
+
const entryCount = reader.readCompactSize();
|
|
1567
|
+
const entries = [];
|
|
1568
|
+
for (let i = 0; i < entryCount; i++) {
|
|
1569
|
+
const vin = reader.readUint16LE();
|
|
1570
|
+
const script = reader.readCompactSlice();
|
|
1571
|
+
const witness = reader.readCompactSlice();
|
|
1572
|
+
entries.push({ vin, script, witness });
|
|
1573
|
+
}
|
|
1574
|
+
if (reader.remaining() > 0) {
|
|
1575
|
+
throw new Error(`unexpected ${reader.remaining()} trailing bytes`);
|
|
1576
|
+
}
|
|
1577
|
+
return _EmulatorPacket.create(entries);
|
|
1578
|
+
}
|
|
1579
|
+
type() {
|
|
1580
|
+
return _EmulatorPacket.PACKET_TYPE;
|
|
1581
|
+
}
|
|
1582
|
+
serialize() {
|
|
1583
|
+
const writer = new chunkHHV5FPC6_cjs.BufferWriter();
|
|
1584
|
+
writer.writeCompactSize(this.entries.length);
|
|
1585
|
+
for (const entry of this.entries) {
|
|
1586
|
+
writer.writeUint16LE(entry.vin);
|
|
1587
|
+
writer.writeCompactSlice(entry.script);
|
|
1588
|
+
writer.writeCompactSlice(entry.witness ?? new Uint8Array(0));
|
|
1589
|
+
}
|
|
1590
|
+
return writer.toBytes();
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1537
1594
|
// src/extension/index.ts
|
|
1538
1595
|
var ARKADE_MAGIC = new Uint8Array([65, 82, 75]);
|
|
1539
1596
|
var ExtensionNotFoundError = class extends Error {
|
|
@@ -1553,10 +1610,14 @@ var Extension = class _Extension {
|
|
|
1553
1610
|
}
|
|
1554
1611
|
const seen = /* @__PURE__ */ new Set();
|
|
1555
1612
|
for (const p of packets) {
|
|
1556
|
-
|
|
1557
|
-
|
|
1613
|
+
const type = p.type();
|
|
1614
|
+
if (!Number.isInteger(type) || type < 0 || type > 255) {
|
|
1615
|
+
throw new Error(`invalid packet type ${type}: must be an integer in [0, 255]`);
|
|
1558
1616
|
}
|
|
1559
|
-
seen.
|
|
1617
|
+
if (seen.has(type)) {
|
|
1618
|
+
throw new Error(`duplicate packet type ${type}`);
|
|
1619
|
+
}
|
|
1620
|
+
seen.add(type);
|
|
1560
1621
|
}
|
|
1561
1622
|
return new _Extension(packets);
|
|
1562
1623
|
}
|
|
@@ -1606,7 +1667,7 @@ var Extension = class _Extension {
|
|
|
1606
1667
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
1607
1668
|
);
|
|
1608
1669
|
}
|
|
1609
|
-
const reader = new
|
|
1670
|
+
const reader = new chunkHHV5FPC6_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
1610
1671
|
const packets = [];
|
|
1611
1672
|
while (reader.remaining() > 0) {
|
|
1612
1673
|
const packetType = reader.readByte();
|
|
@@ -1680,18 +1741,51 @@ var Extension = class _Extension {
|
|
|
1680
1741
|
*/
|
|
1681
1742
|
getAssetPacket() {
|
|
1682
1743
|
for (const p of this.packets) {
|
|
1683
|
-
if (p instanceof
|
|
1744
|
+
if (p instanceof chunkHHV5FPC6_cjs.Packet) {
|
|
1684
1745
|
return p;
|
|
1685
1746
|
}
|
|
1686
1747
|
}
|
|
1687
1748
|
return null;
|
|
1688
1749
|
}
|
|
1750
|
+
/**
|
|
1751
|
+
* getEmulatorPacket returns the embedded EmulatorPacket, or null if not present.
|
|
1752
|
+
*/
|
|
1753
|
+
getEmulatorPacket() {
|
|
1754
|
+
for (const p of this.packets) {
|
|
1755
|
+
if (p instanceof EmulatorPacket) {
|
|
1756
|
+
return p;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
return null;
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* getPacketByType returns the first packet matching the given type tag, or null.
|
|
1763
|
+
*/
|
|
1764
|
+
getPacketByType(packetType) {
|
|
1765
|
+
for (const p of this.packets) {
|
|
1766
|
+
if (p.type() === packetType) {
|
|
1767
|
+
return p;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return null;
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Returns all embedded packets in insertion order. Used when callers need
|
|
1774
|
+
* to rebuild an Extension from an existing one (e.g. appending a new packet).
|
|
1775
|
+
*/
|
|
1776
|
+
getPackets() {
|
|
1777
|
+
return this.packets;
|
|
1778
|
+
}
|
|
1689
1779
|
};
|
|
1690
1780
|
function parsePacket(packetType, data) {
|
|
1691
|
-
|
|
1692
|
-
|
|
1781
|
+
switch (packetType) {
|
|
1782
|
+
case chunkHHV5FPC6_cjs.Packet.PACKET_TYPE:
|
|
1783
|
+
return chunkHHV5FPC6_cjs.Packet.fromBytes(data);
|
|
1784
|
+
case EmulatorPacket.PACKET_TYPE:
|
|
1785
|
+
return EmulatorPacket.fromBytes(data);
|
|
1786
|
+
default:
|
|
1787
|
+
return new UnknownPacket(packetType, data);
|
|
1693
1788
|
}
|
|
1694
|
-
return new UnknownPacket(packetType, data);
|
|
1695
1789
|
}
|
|
1696
1790
|
function encodeVarUint(value) {
|
|
1697
1791
|
const bytes = [];
|
|
@@ -1747,7 +1841,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
1747
1841
|
for (const recipient of recipients) {
|
|
1748
1842
|
let arkAddress;
|
|
1749
1843
|
try {
|
|
1750
|
-
arkAddress =
|
|
1844
|
+
arkAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(recipient.address);
|
|
1751
1845
|
} catch {
|
|
1752
1846
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
1753
1847
|
continue;
|
|
@@ -1997,7 +2091,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1997
2091
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
1998
2092
|
inputsByAssetId.set(asset.assetId, [
|
|
1999
2093
|
...existing ?? [],
|
|
2000
|
-
|
|
2094
|
+
chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
2001
2095
|
]);
|
|
2002
2096
|
}
|
|
2003
2097
|
}
|
|
@@ -2009,7 +2103,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2009
2103
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2010
2104
|
outputsByAssetId.set(asset.assetId, [
|
|
2011
2105
|
...existing ?? [],
|
|
2012
|
-
|
|
2106
|
+
chunkHHV5FPC6_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2013
2107
|
]);
|
|
2014
2108
|
}
|
|
2015
2109
|
}
|
|
@@ -2020,7 +2114,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2020
2114
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2021
2115
|
outputsByAssetId.set(asset.assetId, [
|
|
2022
2116
|
...existing ?? [],
|
|
2023
|
-
|
|
2117
|
+
chunkHHV5FPC6_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2024
2118
|
]);
|
|
2025
2119
|
}
|
|
2026
2120
|
}
|
|
@@ -2029,11 +2123,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2029
2123
|
for (const assetIdStr of allAssetIds) {
|
|
2030
2124
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2031
2125
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2032
|
-
const assetId =
|
|
2033
|
-
const group =
|
|
2126
|
+
const assetId = chunkHHV5FPC6_cjs.AssetId.fromString(assetIdStr);
|
|
2127
|
+
const group = chunkHHV5FPC6_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2034
2128
|
groups.push(group);
|
|
2035
2129
|
}
|
|
2036
|
-
return
|
|
2130
|
+
return chunkHHV5FPC6_cjs.Packet.create(groups);
|
|
2037
2131
|
}
|
|
2038
2132
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2039
2133
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2138,8 +2232,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
2138
2232
|
function buildVirtualTx(inputs, outputs) {
|
|
2139
2233
|
let lockTime = 0n;
|
|
2140
2234
|
for (const input of inputs) {
|
|
2141
|
-
const tapscript =
|
|
2142
|
-
if (
|
|
2235
|
+
const tapscript = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
2236
|
+
if (chunkL5ND2FJJ_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
2143
2237
|
if (lockTime !== 0n) {
|
|
2144
2238
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
2145
2239
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -2150,7 +2244,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2150
2244
|
}
|
|
2151
2245
|
}
|
|
2152
2246
|
}
|
|
2153
|
-
const tx = new
|
|
2247
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({
|
|
2154
2248
|
version: 3,
|
|
2155
2249
|
lockTime: Number(lockTime)
|
|
2156
2250
|
});
|
|
@@ -2160,12 +2254,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2160
2254
|
index: input.vout,
|
|
2161
2255
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
2162
2256
|
witnessUtxo: {
|
|
2163
|
-
script:
|
|
2257
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
2164
2258
|
amount: BigInt(input.value)
|
|
2165
2259
|
},
|
|
2166
2260
|
tapLeafScript: [input.tapLeafScript]
|
|
2167
2261
|
});
|
|
2168
|
-
|
|
2262
|
+
chunkHHV5FPC6_cjs.setArkPsbtField(tx, i, chunkHHV5FPC6_cjs.VtxoTaprootTree, input.tapTree);
|
|
2169
2263
|
}
|
|
2170
2264
|
for (const output of outputs) {
|
|
2171
2265
|
tx.addOutput(output);
|
|
@@ -2174,8 +2268,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2174
2268
|
return tx;
|
|
2175
2269
|
}
|
|
2176
2270
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
2177
|
-
const collaborativeClosure =
|
|
2178
|
-
const checkpointVtxoScript = new
|
|
2271
|
+
const collaborativeClosure = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
2272
|
+
const checkpointVtxoScript = new chunkL5ND2FJJ_cjs.VtxoScript([
|
|
2179
2273
|
serverUnrollScript.script,
|
|
2180
2274
|
collaborativeClosure.script
|
|
2181
2275
|
]);
|
|
@@ -2319,12 +2413,52 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
2319
2413
|
}
|
|
2320
2414
|
function isValidArkAddress(address) {
|
|
2321
2415
|
try {
|
|
2322
|
-
|
|
2416
|
+
chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
2323
2417
|
return true;
|
|
2324
2418
|
} catch (e) {
|
|
2325
2419
|
return false;
|
|
2326
2420
|
}
|
|
2327
2421
|
}
|
|
2422
|
+
async function submitOffchainTx(provider, offchainTx, signer, hooks) {
|
|
2423
|
+
const { arkTx: signedArkTx, userSignedCheckpoints } = await signer.signArkTx(
|
|
2424
|
+
offchainTx.arkTx,
|
|
2425
|
+
offchainTx.checkpoints
|
|
2426
|
+
);
|
|
2427
|
+
if (userSignedCheckpoints && userSignedCheckpoints.length !== offchainTx.checkpoints.length) {
|
|
2428
|
+
throw new Error(
|
|
2429
|
+
`signer returned ${userSignedCheckpoints.length} signed checkpoints, expected ${offchainTx.checkpoints.length}`
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
await hooks?.beforeSubmit?.();
|
|
2433
|
+
const { arkTxid, signedCheckpointTxs } = await provider.submitTx(
|
|
2434
|
+
base.base64.encode(signedArkTx.toPSBT()),
|
|
2435
|
+
offchainTx.checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
2436
|
+
);
|
|
2437
|
+
if (signedCheckpointTxs.length !== offchainTx.checkpoints.length) {
|
|
2438
|
+
throw new Error(
|
|
2439
|
+
`submitTx returned ${signedCheckpointTxs.length} checkpoints, expected ${offchainTx.checkpoints.length}`
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
let finalCheckpoints;
|
|
2443
|
+
if (userSignedCheckpoints) {
|
|
2444
|
+
finalCheckpoints = signedCheckpointTxs.map((c, i) => {
|
|
2445
|
+
const serverSigned = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2446
|
+
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
2447
|
+
return base.base64.encode(serverSigned.toPSBT());
|
|
2448
|
+
});
|
|
2449
|
+
} else {
|
|
2450
|
+
finalCheckpoints = await Promise.all(
|
|
2451
|
+
signedCheckpointTxs.map(async (c) => {
|
|
2452
|
+
const tx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
2453
|
+
const signed = await signer.signCheckpoint(tx);
|
|
2454
|
+
return base.base64.encode(signed.toPSBT());
|
|
2455
|
+
})
|
|
2456
|
+
);
|
|
2457
|
+
}
|
|
2458
|
+
await provider.finalizeTx(arkTxid, finalCheckpoints);
|
|
2459
|
+
await hooks?.afterFinalize?.();
|
|
2460
|
+
return { arkTxid, signedCheckpointTxs };
|
|
2461
|
+
}
|
|
2328
2462
|
var AmountVariableName = "amount";
|
|
2329
2463
|
var ExpiryVariableName = "expiry";
|
|
2330
2464
|
var BirthVariableName = "birth";
|
|
@@ -2480,6 +2614,14 @@ function parseProgram(text, env) {
|
|
|
2480
2614
|
}
|
|
2481
2615
|
return { program, text };
|
|
2482
2616
|
}
|
|
2617
|
+
|
|
2618
|
+
// src/contracts/types.ts
|
|
2619
|
+
function isDiscoverable(handler) {
|
|
2620
|
+
return !!handler && typeof handler.discoverAt === "function";
|
|
2621
|
+
}
|
|
2622
|
+
function isTapscriptDeriving(handler) {
|
|
2623
|
+
return !!handler && typeof handler.deriveTapscripts === "function";
|
|
2624
|
+
}
|
|
2483
2625
|
var DUST_AMOUNT = 546;
|
|
2484
2626
|
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
2485
2627
|
function getDustAmount(wallet) {
|
|
@@ -2494,15 +2636,19 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2494
2636
|
};
|
|
2495
2637
|
}
|
|
2496
2638
|
function deriveContractTapscripts(contract) {
|
|
2497
|
-
const handler =
|
|
2639
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
2498
2640
|
if (!handler) {
|
|
2499
2641
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2500
2642
|
}
|
|
2501
2643
|
const script = handler.createScript(contract.params);
|
|
2644
|
+
if (isTapscriptDeriving(handler)) {
|
|
2645
|
+
return handler.deriveTapscripts(script, contract);
|
|
2646
|
+
}
|
|
2647
|
+
const legacy = script;
|
|
2502
2648
|
return {
|
|
2503
|
-
forfeitTapLeafScript:
|
|
2504
|
-
intentTapLeafScript:
|
|
2505
|
-
tapTree:
|
|
2649
|
+
forfeitTapLeafScript: legacy.forfeit(),
|
|
2650
|
+
intentTapLeafScript: legacy.forfeit(),
|
|
2651
|
+
tapTree: legacy.encode()
|
|
2506
2652
|
};
|
|
2507
2653
|
}
|
|
2508
2654
|
function cloneTapLeafScript([
|
|
@@ -2564,7 +2710,7 @@ function validateRecipients(recipients, dustAmount) {
|
|
|
2564
2710
|
for (const recipient of recipients) {
|
|
2565
2711
|
let address;
|
|
2566
2712
|
try {
|
|
2567
|
-
address =
|
|
2713
|
+
address = chunkL5ND2FJJ_cjs.ArkAddress.decode(recipient.address);
|
|
2568
2714
|
} catch (e) {
|
|
2569
2715
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2570
2716
|
}
|
|
@@ -3171,11 +3317,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3171
3317
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3172
3318
|
);
|
|
3173
3319
|
}
|
|
3174
|
-
const tx = new
|
|
3320
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction();
|
|
3175
3321
|
for (const utxo of expiredUtxos) {
|
|
3176
|
-
const utxoScript =
|
|
3322
|
+
const utxoScript = chunkL5ND2FJJ_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3177
3323
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
3178
|
-
(leaf) =>
|
|
3324
|
+
(leaf) => chunkL5ND2FJJ_cjs.CSVMultisigTapscript.isScriptValid(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
3179
3325
|
);
|
|
3180
3326
|
if (!utxoExitLeaf) {
|
|
3181
3327
|
throw new Error(
|
|
@@ -3190,7 +3336,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3190
3336
|
amount: BigInt(utxo.value)
|
|
3191
3337
|
},
|
|
3192
3338
|
tapLeafScript: [utxoExitLeaf],
|
|
3193
|
-
sequence:
|
|
3339
|
+
sequence: chunkL5ND2FJJ_cjs.getSequence(utxoExitLeaf)
|
|
3194
3340
|
});
|
|
3195
3341
|
}
|
|
3196
3342
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -3679,7 +3825,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3679
3825
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
3680
3826
|
getBoardingTimelock() {
|
|
3681
3827
|
const wallet = this.getSweepWallet();
|
|
3682
|
-
const exitScript =
|
|
3828
|
+
const exitScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(
|
|
3683
3829
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
3684
3830
|
);
|
|
3685
3831
|
return exitScript.params.timelock;
|
|
@@ -3810,8 +3956,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3810
3956
|
* or doesn't carry the metadata.
|
|
3811
3957
|
*/
|
|
3812
3958
|
extractSpentOutpoint(error) {
|
|
3813
|
-
const ark =
|
|
3814
|
-
if (!
|
|
3959
|
+
const ark = chunkHHV5FPC6_cjs.maybeArkError(error);
|
|
3960
|
+
if (!chunkHHV5FPC6_cjs.isArkError(ark, chunkHHV5FPC6_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
3815
3961
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
3816
3962
|
if (typeof raw !== "string") return void 0;
|
|
3817
3963
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -4025,7 +4171,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4025
4171
|
const arkAddress = await this.wallet.getAddress();
|
|
4026
4172
|
const outputFee = estimator.evalOffchainOutput({
|
|
4027
4173
|
amount: totalAmount,
|
|
4028
|
-
script: base.hex.encode(
|
|
4174
|
+
script: base.hex.encode(chunkL5ND2FJJ_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4029
4175
|
});
|
|
4030
4176
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
4031
4177
|
if (totalAmount < dustAmount) return;
|
|
@@ -4105,7 +4251,7 @@ var ArkNote = class _ArkNote {
|
|
|
4105
4251
|
this.value = value;
|
|
4106
4252
|
this.HRP = HRP;
|
|
4107
4253
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
4108
|
-
this.vtxoScript = new
|
|
4254
|
+
this.vtxoScript = new chunkL5ND2FJJ_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
4109
4255
|
const leaf = this.vtxoScript.leaves[0];
|
|
4110
4256
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
4111
4257
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -4460,7 +4606,7 @@ async function captureExitBranch(params) {
|
|
|
4460
4606
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4461
4607
|
if (nonCommitment.length > 0) {
|
|
4462
4608
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4463
|
-
psbtByTxid.set(
|
|
4609
|
+
psbtByTxid.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4464
4610
|
}
|
|
4465
4611
|
}
|
|
4466
4612
|
}
|
|
@@ -4503,10 +4649,10 @@ var IndexerExitDataSource = class {
|
|
|
4503
4649
|
while (hasMore) {
|
|
4504
4650
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
4505
4651
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
4506
|
-
{ pageIndex, pageSize:
|
|
4652
|
+
{ pageIndex, pageSize: chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE }
|
|
4507
4653
|
);
|
|
4508
4654
|
chain.push(...page);
|
|
4509
|
-
hasMore = meta ? page.length ===
|
|
4655
|
+
hasMore = meta ? page.length === chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4510
4656
|
pageIndex++;
|
|
4511
4657
|
}
|
|
4512
4658
|
return chain;
|
|
@@ -4518,12 +4664,12 @@ var IndexerExitDataSource = class {
|
|
|
4518
4664
|
while (hasMore) {
|
|
4519
4665
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
4520
4666
|
pageIndex,
|
|
4521
|
-
pageSize:
|
|
4667
|
+
pageSize: chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE
|
|
4522
4668
|
});
|
|
4523
4669
|
for (const psbt of txs) {
|
|
4524
|
-
out.set(
|
|
4670
|
+
out.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4525
4671
|
}
|
|
4526
|
-
hasMore = page ? txs.length ===
|
|
4672
|
+
hasMore = page ? txs.length === chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4527
4673
|
pageIndex++;
|
|
4528
4674
|
}
|
|
4529
4675
|
return out;
|
|
@@ -4544,7 +4690,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4544
4690
|
}
|
|
4545
4691
|
}
|
|
4546
4692
|
function psbtInputTxids(psbtBase64) {
|
|
4547
|
-
const tx =
|
|
4693
|
+
const tx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4548
4694
|
const ids = [];
|
|
4549
4695
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4550
4696
|
const txid = tx.getInput(i).txid;
|
|
@@ -4647,7 +4793,7 @@ function createExitChainResolver(params) {
|
|
|
4647
4793
|
|
|
4648
4794
|
// src/providers/availability.ts
|
|
4649
4795
|
function isRetryableProviderError(error) {
|
|
4650
|
-
return error instanceof
|
|
4796
|
+
return error instanceof chunkHHV5FPC6_cjs.ProviderUnavailableError || error instanceof chunkHHV5FPC6_cjs.FetchError || chunkHHV5FPC6_cjs.isFetchTimeoutError(error);
|
|
4651
4797
|
}
|
|
4652
4798
|
|
|
4653
4799
|
// src/utils/syncCursors.ts
|
|
@@ -4900,7 +5046,7 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
4900
5046
|
if (!isRetryableProviderError(err)) throw err;
|
|
4901
5047
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
4902
5048
|
if (!snapshot) {
|
|
4903
|
-
throw new
|
|
5049
|
+
throw new chunkHHV5FPC6_cjs.ProviderUnavailableError(
|
|
4904
5050
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
4905
5051
|
{ cause: err }
|
|
4906
5052
|
);
|
|
@@ -5435,7 +5581,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5435
5581
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5436
5582
|
withRecoverable: false
|
|
5437
5583
|
});
|
|
5438
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5584
|
+
const controlAssetRef = params.controlAssetId ? chunkHHV5FPC6_cjs.AssetRef.fromId(chunkHHV5FPC6_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5439
5585
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5440
5586
|
let totalBtcSelected = 0n;
|
|
5441
5587
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5448,8 +5594,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5448
5594
|
}
|
|
5449
5595
|
}
|
|
5450
5596
|
const groups = [];
|
|
5451
|
-
const issuedAssetOutput =
|
|
5452
|
-
const issuedAssetGroup =
|
|
5597
|
+
const issuedAssetOutput = chunkHHV5FPC6_cjs.AssetOutput.create(0, params.amount);
|
|
5598
|
+
const issuedAssetGroup = chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5453
5599
|
null,
|
|
5454
5600
|
controlAssetRef,
|
|
5455
5601
|
[],
|
|
@@ -5464,28 +5610,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5464
5610
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5465
5611
|
for (const asset of assets) {
|
|
5466
5612
|
if (asset.assetId !== assetId) continue;
|
|
5467
|
-
changeInputs.push(
|
|
5613
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5468
5614
|
}
|
|
5469
5615
|
}
|
|
5470
5616
|
groups.push(
|
|
5471
|
-
|
|
5472
|
-
|
|
5617
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5618
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5473
5619
|
null,
|
|
5474
5620
|
changeInputs,
|
|
5475
|
-
[
|
|
5621
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)],
|
|
5476
5622
|
[]
|
|
5477
5623
|
)
|
|
5478
5624
|
);
|
|
5479
5625
|
}
|
|
5480
5626
|
}
|
|
5481
5627
|
const address = await this.wallet.getAddress();
|
|
5482
|
-
const outputAddress =
|
|
5628
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5483
5629
|
const outputs = [
|
|
5484
5630
|
{
|
|
5485
5631
|
script: outputAddress.pkScript,
|
|
5486
5632
|
amount: BigInt(totalBtcSelected)
|
|
5487
5633
|
},
|
|
5488
|
-
Extension.create([
|
|
5634
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5489
5635
|
];
|
|
5490
5636
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5491
5637
|
coinSelection.inputs,
|
|
@@ -5493,7 +5639,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5493
5639
|
);
|
|
5494
5640
|
return {
|
|
5495
5641
|
arkTxId: arkTxid,
|
|
5496
|
-
assetId:
|
|
5642
|
+
assetId: chunkHHV5FPC6_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5497
5643
|
};
|
|
5498
5644
|
}
|
|
5499
5645
|
/**
|
|
@@ -5565,16 +5711,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5565
5711
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5566
5712
|
for (const asset of assets) {
|
|
5567
5713
|
if (asset.assetId !== params.assetId) continue;
|
|
5568
|
-
reissueInputs.push(
|
|
5714
|
+
reissueInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5569
5715
|
}
|
|
5570
5716
|
}
|
|
5571
5717
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5572
|
-
const reissueAssetIdObj =
|
|
5573
|
-
const reissueAssetGroup =
|
|
5718
|
+
const reissueAssetIdObj = chunkHHV5FPC6_cjs.AssetId.fromString(params.assetId);
|
|
5719
|
+
const reissueAssetGroup = chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5574
5720
|
reissueAssetIdObj,
|
|
5575
5721
|
null,
|
|
5576
5722
|
reissueInputs,
|
|
5577
|
-
[
|
|
5723
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5578
5724
|
[]
|
|
5579
5725
|
);
|
|
5580
5726
|
const groups = [reissueAssetGroup];
|
|
@@ -5583,27 +5729,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5583
5729
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5584
5730
|
for (const asset of assets) {
|
|
5585
5731
|
if (asset.assetId !== assetId) continue;
|
|
5586
|
-
changeInputs.push(
|
|
5732
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5587
5733
|
}
|
|
5588
5734
|
}
|
|
5589
5735
|
groups.push(
|
|
5590
|
-
|
|
5591
|
-
|
|
5736
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5737
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5592
5738
|
null,
|
|
5593
5739
|
changeInputs,
|
|
5594
|
-
[
|
|
5740
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)],
|
|
5595
5741
|
[]
|
|
5596
5742
|
)
|
|
5597
5743
|
);
|
|
5598
5744
|
}
|
|
5599
5745
|
const address = await this.wallet.getAddress();
|
|
5600
|
-
const outputAddress =
|
|
5746
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5601
5747
|
const outputs = [
|
|
5602
5748
|
{
|
|
5603
5749
|
script: outputAddress.pkScript,
|
|
5604
5750
|
amount: BigInt(totalBtcSelected)
|
|
5605
5751
|
},
|
|
5606
|
-
Extension.create([
|
|
5752
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5607
5753
|
];
|
|
5608
5754
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5609
5755
|
return arkTxid;
|
|
@@ -5670,27 +5816,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5670
5816
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5671
5817
|
for (const asset of assets) {
|
|
5672
5818
|
if (asset.assetId !== assetId) continue;
|
|
5673
|
-
changeInputs.push(
|
|
5819
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5674
5820
|
}
|
|
5675
5821
|
}
|
|
5676
5822
|
groups.push(
|
|
5677
|
-
|
|
5678
|
-
|
|
5823
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5824
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5679
5825
|
null,
|
|
5680
5826
|
changeInputs,
|
|
5681
|
-
amount > 0n ? [
|
|
5827
|
+
amount > 0n ? [chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)] : [],
|
|
5682
5828
|
[]
|
|
5683
5829
|
)
|
|
5684
5830
|
);
|
|
5685
5831
|
}
|
|
5686
5832
|
const address = await this.wallet.getAddress();
|
|
5687
|
-
const outputAddress =
|
|
5833
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5688
5834
|
const outputs = [
|
|
5689
5835
|
{
|
|
5690
5836
|
script: outputAddress.pkScript,
|
|
5691
5837
|
amount: BigInt(totalBtcSelected)
|
|
5692
5838
|
},
|
|
5693
|
-
Extension.create([
|
|
5839
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5694
5840
|
];
|
|
5695
5841
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5696
5842
|
return arkTxid;
|
|
@@ -5715,7 +5861,7 @@ function castMetadata(metadata) {
|
|
|
5715
5861
|
} else {
|
|
5716
5862
|
throw new Error("Invalid metadata value type");
|
|
5717
5863
|
}
|
|
5718
|
-
md.push(
|
|
5864
|
+
md.push(chunkHHV5FPC6_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5719
5865
|
}
|
|
5720
5866
|
return md;
|
|
5721
5867
|
}
|
|
@@ -5736,7 +5882,7 @@ var DelegateManagerImpl = class {
|
|
|
5736
5882
|
if (vtxos.length === 0) {
|
|
5737
5883
|
return { delegated: [], failed: [] };
|
|
5738
5884
|
}
|
|
5739
|
-
const destinationScript =
|
|
5885
|
+
const destinationScript = chunkL5ND2FJJ_cjs.ArkAddress.decode(destination).pkScript;
|
|
5740
5886
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
5741
5887
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
5742
5888
|
const eligible = vtxos.filter(
|
|
@@ -5884,7 +6030,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5884
6030
|
const delegateFee = BigInt(Number(fee));
|
|
5885
6031
|
if (delegateFee > 0n) {
|
|
5886
6032
|
outputs.push({
|
|
5887
|
-
script:
|
|
6033
|
+
script: chunkL5ND2FJJ_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
5888
6034
|
amount: delegateFee
|
|
5889
6035
|
});
|
|
5890
6036
|
}
|
|
@@ -5917,7 +6063,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5917
6063
|
destinationScript
|
|
5918
6064
|
);
|
|
5919
6065
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
5920
|
-
btcSigner.Address(
|
|
6066
|
+
btcSigner.Address(chunkL5ND2FJJ_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
5921
6067
|
);
|
|
5922
6068
|
const forfeits = await Promise.all(
|
|
5923
6069
|
vtxos.filter((v) => !isRecoverable(v)).map(async (coin) => {
|
|
@@ -5945,7 +6091,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
5945
6091
|
index: input.vout,
|
|
5946
6092
|
witnessUtxo: {
|
|
5947
6093
|
amount: BigInt(input.value),
|
|
5948
|
-
script:
|
|
6094
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
5949
6095
|
},
|
|
5950
6096
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
5951
6097
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -6003,7 +6149,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
6003
6149
|
expire_at: 0,
|
|
6004
6150
|
cosigners_public_keys: cosignerPubKeys
|
|
6005
6151
|
};
|
|
6006
|
-
const proof =
|
|
6152
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, outputs);
|
|
6007
6153
|
const signedProof = await identity.sign(proof);
|
|
6008
6154
|
return {
|
|
6009
6155
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -6021,10 +6167,10 @@ function getDayTimestamp(timestamp) {
|
|
|
6021
6167
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
6022
6168
|
if (!vtxo.tapTree) return void 0;
|
|
6023
6169
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
6024
|
-
const vtxoScript =
|
|
6170
|
+
const vtxoScript = chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
6025
6171
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
6026
|
-
const arkTapscript =
|
|
6027
|
-
if (!
|
|
6172
|
+
const arkTapscript = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
6173
|
+
if (!chunkL5ND2FJJ_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
6028
6174
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
6029
6175
|
});
|
|
6030
6176
|
}
|
|
@@ -6212,7 +6358,7 @@ async function closeDatabase(dbName) {
|
|
|
6212
6358
|
return true;
|
|
6213
6359
|
}
|
|
6214
6360
|
function scriptFromArkAddress(address) {
|
|
6215
|
-
return base.hex.encode(
|
|
6361
|
+
return base.hex.encode(chunkL5ND2FJJ_cjs.ArkAddress.decode(address).pkScript);
|
|
6216
6362
|
}
|
|
6217
6363
|
|
|
6218
6364
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -7863,11 +8009,6 @@ var ContractRepositoryImpl = class {
|
|
|
7863
8009
|
}
|
|
7864
8010
|
};
|
|
7865
8011
|
|
|
7866
|
-
// src/contracts/types.ts
|
|
7867
|
-
function isDiscoverable(handler) {
|
|
7868
|
-
return !!handler && typeof handler.discoverAt === "function";
|
|
7869
|
-
}
|
|
7870
|
-
|
|
7871
8012
|
// src/contracts/contractWatcher.ts
|
|
7872
8013
|
function computeReconnectDelay(attempt, baseMs, maxMs) {
|
|
7873
8014
|
return Math.min(baseMs * Math.pow(2, attempt - 1), maxMs);
|
|
@@ -8091,7 +8232,7 @@ var ContractWatcher = class {
|
|
|
8091
8232
|
this.connectionState = "connected";
|
|
8092
8233
|
this.reconnectAttempts = 0;
|
|
8093
8234
|
this.listenLoop().catch((e) => {
|
|
8094
|
-
if (
|
|
8235
|
+
if (chunkHHV5FPC6_cjs.isEventSourceError(e)) {
|
|
8095
8236
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8096
8237
|
} else {
|
|
8097
8238
|
console.error(e);
|
|
@@ -8617,7 +8758,7 @@ var ContractManager = class _ContractManager {
|
|
|
8617
8758
|
* `persisted` is `true`.
|
|
8618
8759
|
*/
|
|
8619
8760
|
async upsertContract(params) {
|
|
8620
|
-
const handler =
|
|
8761
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(params.type);
|
|
8621
8762
|
if (!handler) {
|
|
8622
8763
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
8623
8764
|
}
|
|
@@ -8700,7 +8841,7 @@ var ContractManager = class _ContractManager {
|
|
|
8700
8841
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
8701
8842
|
);
|
|
8702
8843
|
}
|
|
8703
|
-
const registered =
|
|
8844
|
+
const registered = chunkRQSA7ADZ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkRQSA7ADZ_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
8704
8845
|
const discoverables = [
|
|
8705
8846
|
...registered.filter((h) => h.type === "boarding"),
|
|
8706
8847
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -8890,7 +9031,7 @@ var ContractManager = class _ContractManager {
|
|
|
8890
9031
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
8891
9032
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
8892
9033
|
if (!contract) return [];
|
|
8893
|
-
const handler =
|
|
9034
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
8894
9035
|
if (!handler) return [];
|
|
8895
9036
|
const script = handler.createScript(contract.params);
|
|
8896
9037
|
const context = {
|
|
@@ -8910,7 +9051,7 @@ var ContractManager = class _ContractManager {
|
|
|
8910
9051
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
8911
9052
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
8912
9053
|
if (!contract) return [];
|
|
8913
|
-
const handler =
|
|
9054
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
8914
9055
|
if (!handler) return [];
|
|
8915
9056
|
const script = handler.createScript(contract.params);
|
|
8916
9057
|
const context = {
|
|
@@ -9177,7 +9318,7 @@ var ContractManager = class _ContractManager {
|
|
|
9177
9318
|
}
|
|
9178
9319
|
return result;
|
|
9179
9320
|
}
|
|
9180
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
9321
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9181
9322
|
if (contracts.length === 0) {
|
|
9182
9323
|
return /* @__PURE__ */ new Map();
|
|
9183
9324
|
}
|
|
@@ -9355,7 +9496,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9355
9496
|
*/
|
|
9356
9497
|
materializeDescriptorAt(index) {
|
|
9357
9498
|
const descriptor = this.identity.descriptor;
|
|
9358
|
-
const network =
|
|
9499
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9359
9500
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9360
9501
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9361
9502
|
if (!keyInfo?.keyExpression) {
|
|
@@ -9499,7 +9640,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9499
9640
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
9500
9641
|
if (!provider) return void 0;
|
|
9501
9642
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
9502
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
9643
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
9503
9644
|
const factoryOpts = {
|
|
9504
9645
|
walletRepository: setup.walletRepository,
|
|
9505
9646
|
contractRepository: setup.contractRepository,
|
|
@@ -9682,7 +9823,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9682
9823
|
const newAddress = newTapscript.address(wallet.network.hrp, wallet.arkServerPublicKey).encode();
|
|
9683
9824
|
const manager = await wallet.getContractManager();
|
|
9684
9825
|
const csvTimelock = newTapscript.options.csvTimelock;
|
|
9685
|
-
const csvTimelockStr =
|
|
9826
|
+
const csvTimelockStr = chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString();
|
|
9686
9827
|
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
9687
9828
|
const baseParams = {
|
|
9688
9829
|
script: newScript,
|
|
@@ -9696,11 +9837,11 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9696
9837
|
// produce unsigned PSBTs that the server rejects with
|
|
9697
9838
|
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
9698
9839
|
metadata: {
|
|
9699
|
-
source:
|
|
9840
|
+
source: chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE,
|
|
9700
9841
|
signingDescriptor: descriptor
|
|
9701
9842
|
}
|
|
9702
9843
|
};
|
|
9703
|
-
if (newTapscript instanceof
|
|
9844
|
+
if (newTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
9704
9845
|
await manager.createContract({
|
|
9705
9846
|
...baseParams,
|
|
9706
9847
|
type: "delegate",
|
|
@@ -9732,7 +9873,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9732
9873
|
};
|
|
9733
9874
|
function deriveLeafPubkey(descriptor) {
|
|
9734
9875
|
try {
|
|
9735
|
-
return
|
|
9876
|
+
return chunkRQSA7ADZ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
9736
9877
|
} catch (e) {
|
|
9737
9878
|
throw new NonRangeableDescriptorError(
|
|
9738
9879
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -9741,10 +9882,10 @@ function deriveLeafPubkey(descriptor) {
|
|
|
9741
9882
|
}
|
|
9742
9883
|
}
|
|
9743
9884
|
function rebuildTapscript(current, pubKey) {
|
|
9744
|
-
if (current instanceof
|
|
9745
|
-
return new
|
|
9885
|
+
if (current instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
9886
|
+
return new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
9746
9887
|
}
|
|
9747
|
-
return new
|
|
9888
|
+
return new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
9748
9889
|
}
|
|
9749
9890
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
9750
9891
|
const candidates = await contractRepository.getContracts({
|
|
@@ -9753,7 +9894,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
9753
9894
|
});
|
|
9754
9895
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
9755
9896
|
const matching = candidates.filter(
|
|
9756
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
9897
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE
|
|
9757
9898
|
).sort((a, b) => {
|
|
9758
9899
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
9759
9900
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -9929,12 +10070,12 @@ var InputSignerRouter = class {
|
|
|
9929
10070
|
};
|
|
9930
10071
|
|
|
9931
10072
|
// src/wallet/wallet.ts
|
|
9932
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
10073
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkL5ND2FJJ_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
9933
10074
|
function intentProofJobs(coins) {
|
|
9934
10075
|
if (coins.length === 0) return [];
|
|
9935
10076
|
const coinJobs = coins.map((coin, i) => ({
|
|
9936
10077
|
index: i + 1,
|
|
9937
|
-
lookupScript:
|
|
10078
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
9938
10079
|
}));
|
|
9939
10080
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
9940
10081
|
}
|
|
@@ -9958,7 +10099,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
9958
10099
|
const seen = /* @__PURE__ */ new Set();
|
|
9959
10100
|
const deduped = [];
|
|
9960
10101
|
for (const timelock of timelocks) {
|
|
9961
|
-
const sequence =
|
|
10102
|
+
const sequence = chunkL5ND2FJJ_cjs.timelockToSequence(timelock).toString();
|
|
9962
10103
|
if (seen.has(sequence)) continue;
|
|
9963
10104
|
seen.add(sequence);
|
|
9964
10105
|
deduped.push(timelock);
|
|
@@ -9975,7 +10116,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
9975
10116
|
state: "active"
|
|
9976
10117
|
});
|
|
9977
10118
|
const newest = candidates.filter(
|
|
9978
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10119
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE
|
|
9979
10120
|
).sort((a, b) => {
|
|
9980
10121
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
9981
10122
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -9983,7 +10124,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
9983
10124
|
if (!newest?.params.pubKey) return baseline;
|
|
9984
10125
|
try {
|
|
9985
10126
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
9986
|
-
return new
|
|
10127
|
+
return new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
9987
10128
|
} catch (e) {
|
|
9988
10129
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
9989
10130
|
return baseline;
|
|
@@ -10285,7 +10426,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10285
10426
|
*/
|
|
10286
10427
|
static async setupWalletConfig(config, pubKey) {
|
|
10287
10428
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10288
|
-
const arkProvider = config.arkProvider || new
|
|
10429
|
+
const arkProvider = config.arkProvider || new chunkHHV5FPC6_cjs.RestArkProvider(arkadeServerUrl);
|
|
10289
10430
|
let indexerProvider = config.indexerProvider;
|
|
10290
10431
|
if (!indexerProvider) {
|
|
10291
10432
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10302,7 +10443,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10302
10443
|
indexerUrl = arkadeServerUrl;
|
|
10303
10444
|
}
|
|
10304
10445
|
}
|
|
10305
|
-
indexerProvider = new
|
|
10446
|
+
indexerProvider = new chunkHHV5FPC6_cjs.RestIndexerProvider(indexerUrl);
|
|
10306
10447
|
}
|
|
10307
10448
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10308
10449
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10311,7 +10452,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10311
10452
|
source: serverInfoSource,
|
|
10312
10453
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
10313
10454
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
10314
|
-
const network =
|
|
10455
|
+
const network = chunkL5ND2FJJ_cjs.getNetwork(info.network);
|
|
10315
10456
|
if ("descriptor" in config.identity) {
|
|
10316
10457
|
const descriptor = config.identity.descriptor;
|
|
10317
10458
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -10358,11 +10499,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10358
10499
|
serverPubKey,
|
|
10359
10500
|
csvTimelock: exitTimelock
|
|
10360
10501
|
};
|
|
10361
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10362
|
-
const boardingTapscript =
|
|
10502
|
+
const offchainTapscript = !delegatePubKey ? new chunkRQSA7ADZ_cjs.DefaultVtxo.Script(offchainOptions) : new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
10503
|
+
const boardingTapscript = chunkRQSA7ADZ_cjs.BoardingContractHandler.createScript({
|
|
10363
10504
|
pubKey: base.hex.encode(pubKey),
|
|
10364
10505
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10365
|
-
csvTimelock:
|
|
10506
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingTimelock).toString()
|
|
10366
10507
|
});
|
|
10367
10508
|
return {
|
|
10368
10509
|
arkProvider,
|
|
@@ -10696,9 +10837,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10696
10837
|
async getBoardingTapscripts(allowedSigners) {
|
|
10697
10838
|
const byScript = /* @__PURE__ */ new Map();
|
|
10698
10839
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
10699
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
10840
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
10700
10841
|
add(
|
|
10701
|
-
new
|
|
10842
|
+
new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
10702
10843
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
10703
10844
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
10704
10845
|
csvTimelock: boardingCsv
|
|
@@ -10713,7 +10854,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10713
10854
|
for (const c of boardingContracts) {
|
|
10714
10855
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
10715
10856
|
try {
|
|
10716
|
-
add(
|
|
10857
|
+
add(chunkRQSA7ADZ_cjs.BoardingContractHandler.createScript(c.params));
|
|
10717
10858
|
} catch (e) {
|
|
10718
10859
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
10719
10860
|
}
|
|
@@ -10751,7 +10892,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10751
10892
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
10752
10893
|
// not the wallet's current boarding timelock, which a signer
|
|
10753
10894
|
// rotation may have changed.
|
|
10754
|
-
csvTimelock:
|
|
10895
|
+
csvTimelock: chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
10755
10896
|
coins: utxos
|
|
10756
10897
|
});
|
|
10757
10898
|
}
|
|
@@ -10917,7 +11058,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10917
11058
|
});
|
|
10918
11059
|
for (const contract of contracts) {
|
|
10919
11060
|
if (map.has(contract.script)) continue;
|
|
10920
|
-
const handler =
|
|
11061
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
10921
11062
|
if (handler) {
|
|
10922
11063
|
const script = handler.createScript(contract.params);
|
|
10923
11064
|
map.set(contract.script, script);
|
|
@@ -11011,7 +11152,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11011
11152
|
watcherConfig: this.watcherConfig
|
|
11012
11153
|
});
|
|
11013
11154
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
11014
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11155
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11015
11156
|
const baselineSigners = [
|
|
11016
11157
|
this.offchainTapscript.options.serverPubKey,
|
|
11017
11158
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -11019,8 +11160,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11019
11160
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
11020
11161
|
for (const serverPubKey of baselineSigners) {
|
|
11021
11162
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
11022
|
-
const csvTimelockStr =
|
|
11023
|
-
const defaultScript = new
|
|
11163
|
+
const csvTimelockStr = chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString();
|
|
11164
|
+
const defaultScript = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11024
11165
|
pubKey: baselinePubkey,
|
|
11025
11166
|
serverPubKey,
|
|
11026
11167
|
csvTimelock
|
|
@@ -11041,7 +11182,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11041
11182
|
});
|
|
11042
11183
|
}
|
|
11043
11184
|
if (delegatePubKey) {
|
|
11044
|
-
const delegateScript = new
|
|
11185
|
+
const delegateScript = new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({
|
|
11045
11186
|
pubKey: baselinePubkey,
|
|
11046
11187
|
serverPubKey,
|
|
11047
11188
|
delegatePubKey,
|
|
@@ -11065,9 +11206,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11065
11206
|
}
|
|
11066
11207
|
}
|
|
11067
11208
|
}
|
|
11068
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11209
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11069
11210
|
for (const serverPubKey of baselineSigners) {
|
|
11070
|
-
const baselineBoarding = new
|
|
11211
|
+
const baselineBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11071
11212
|
pubKey: baselinePubkey,
|
|
11072
11213
|
serverPubKey,
|
|
11073
11214
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11080,7 +11221,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11080
11221
|
params: {
|
|
11081
11222
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
11082
11223
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
11083
|
-
csvTimelock:
|
|
11224
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
11084
11225
|
},
|
|
11085
11226
|
script: boardingScriptHex,
|
|
11086
11227
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -11303,25 +11444,25 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11303
11444
|
return this.getBoardingAddress();
|
|
11304
11445
|
}
|
|
11305
11446
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11306
|
-
const pubKey =
|
|
11307
|
-
const newBoarding = new
|
|
11447
|
+
const pubKey = chunkRQSA7ADZ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11448
|
+
const newBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11308
11449
|
...this._boardingTapscript.options,
|
|
11309
11450
|
pubKey
|
|
11310
11451
|
});
|
|
11311
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11452
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11312
11453
|
const manager = await this.getContractManager();
|
|
11313
11454
|
await manager.createContract({
|
|
11314
11455
|
type: "boarding",
|
|
11315
11456
|
params: {
|
|
11316
11457
|
pubKey: base.hex.encode(pubKey),
|
|
11317
11458
|
serverPubKey: base.hex.encode(newBoarding.options.serverPubKey),
|
|
11318
|
-
csvTimelock:
|
|
11459
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString()
|
|
11319
11460
|
},
|
|
11320
11461
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11321
11462
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11322
11463
|
state: "active",
|
|
11323
11464
|
metadata: {
|
|
11324
|
-
source:
|
|
11465
|
+
source: chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE,
|
|
11325
11466
|
signingDescriptor: descriptor
|
|
11326
11467
|
}
|
|
11327
11468
|
});
|
|
@@ -11360,7 +11501,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11360
11501
|
const xonly = toXOnlyPubKey(newServerPubKey);
|
|
11361
11502
|
let newServerUnrollScript;
|
|
11362
11503
|
try {
|
|
11363
|
-
newServerUnrollScript =
|
|
11504
|
+
newServerUnrollScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
11364
11505
|
} catch (e) {
|
|
11365
11506
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11366
11507
|
}
|
|
@@ -11388,21 +11529,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11388
11529
|
const [currentBoardingRow] = await manager.getContracts({
|
|
11389
11530
|
script: currentBoardingScript
|
|
11390
11531
|
});
|
|
11391
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
11532
|
+
const newOffchain = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({
|
|
11392
11533
|
...this.offchainTapscript.options,
|
|
11393
11534
|
serverPubKey: xonly
|
|
11394
|
-
}) : new
|
|
11535
|
+
}) : new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11395
11536
|
...this.offchainTapscript.options,
|
|
11396
11537
|
serverPubKey: xonly
|
|
11397
11538
|
});
|
|
11398
|
-
const newBoarding = new
|
|
11539
|
+
const newBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11399
11540
|
...this._boardingTapscript.options,
|
|
11400
11541
|
serverPubKey: xonly
|
|
11401
11542
|
});
|
|
11402
|
-
const offchainCsv =
|
|
11543
|
+
const offchainCsv = chunkL5ND2FJJ_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
11403
11544
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
11404
11545
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
11405
|
-
if (newOffchain instanceof
|
|
11546
|
+
if (newOffchain instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
11406
11547
|
await manager.createContract({
|
|
11407
11548
|
type: "delegate",
|
|
11408
11549
|
params: {
|
|
@@ -11430,13 +11571,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11430
11571
|
metadata: currentOffchainRow?.metadata
|
|
11431
11572
|
});
|
|
11432
11573
|
}
|
|
11433
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
11574
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11434
11575
|
await manager.createContract({
|
|
11435
11576
|
type: "boarding",
|
|
11436
11577
|
params: {
|
|
11437
11578
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
11438
11579
|
serverPubKey: base.hex.encode(xonly),
|
|
11439
|
-
csvTimelock:
|
|
11580
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingCsv).toString()
|
|
11440
11581
|
},
|
|
11441
11582
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11442
11583
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -11531,7 +11672,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11531
11672
|
const hd = provider instanceof HDDescriptorProvider;
|
|
11532
11673
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
11533
11674
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
11534
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11675
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11535
11676
|
const arkInfo = await this.arkProvider.getInfo();
|
|
11536
11677
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
11537
11678
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -11550,7 +11691,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11550
11691
|
csvTimelocks: this.walletContractTimelocks,
|
|
11551
11692
|
// Boarding-exit CSV so the boarding handler can build its
|
|
11552
11693
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
11553
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
11694
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
11554
11695
|
delegatePubKey
|
|
11555
11696
|
};
|
|
11556
11697
|
const result = await manager.scanContracts({
|
|
@@ -11654,7 +11795,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11654
11795
|
let serverUnrollScript;
|
|
11655
11796
|
try {
|
|
11656
11797
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
11657
|
-
serverUnrollScript =
|
|
11798
|
+
serverUnrollScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(raw);
|
|
11658
11799
|
} catch (e) {
|
|
11659
11800
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11660
11801
|
}
|
|
@@ -11791,7 +11932,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11791
11932
|
inputs: params.selectedVtxos,
|
|
11792
11933
|
changeAmount: BigInt(changeAmount)
|
|
11793
11934
|
};
|
|
11794
|
-
const outputAddress =
|
|
11935
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(params.address);
|
|
11795
11936
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
11796
11937
|
const outputs = [
|
|
11797
11938
|
{
|
|
@@ -11844,13 +11985,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11844
11985
|
}
|
|
11845
11986
|
}
|
|
11846
11987
|
const offchainAddress = await this.getAddress();
|
|
11847
|
-
const offchainPkScript =
|
|
11988
|
+
const offchainPkScript = chunkL5ND2FJJ_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
11848
11989
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
11849
11990
|
if (!params) {
|
|
11850
11991
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
11851
11992
|
const estimator = new Estimator(fees.intentFee);
|
|
11852
11993
|
let amount = 0;
|
|
11853
|
-
const exitScript =
|
|
11994
|
+
const exitScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(
|
|
11854
11995
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
11855
11996
|
);
|
|
11856
11997
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -11930,7 +12071,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11930
12071
|
for (const [index, output] of params.outputs.entries()) {
|
|
11931
12072
|
let script;
|
|
11932
12073
|
try {
|
|
11933
|
-
const addr =
|
|
12074
|
+
const addr = chunkL5ND2FJJ_cjs.ArkAddress.decode(output.address);
|
|
11934
12075
|
script = addr.pkScript;
|
|
11935
12076
|
hasOffchainOutputs = true;
|
|
11936
12077
|
} catch {
|
|
@@ -12192,7 +12333,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12192
12333
|
index: input.vout,
|
|
12193
12334
|
witnessUtxo: {
|
|
12194
12335
|
amount: BigInt(input.value),
|
|
12195
|
-
script:
|
|
12336
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12196
12337
|
},
|
|
12197
12338
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
12198
12339
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -12211,7 +12352,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12211
12352
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
12212
12353
|
{
|
|
12213
12354
|
index: 0,
|
|
12214
|
-
lookupScript:
|
|
12355
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12215
12356
|
}
|
|
12216
12357
|
]);
|
|
12217
12358
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -12269,7 +12410,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12269
12410
|
if (skip) {
|
|
12270
12411
|
return { skip };
|
|
12271
12412
|
}
|
|
12272
|
-
const sweepTapscript =
|
|
12413
|
+
const sweepTapscript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.encode({
|
|
12273
12414
|
timelock: {
|
|
12274
12415
|
value: event.batchExpiry,
|
|
12275
12416
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -12375,9 +12516,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12375
12516
|
...existing ?? {},
|
|
12376
12517
|
intentTxId,
|
|
12377
12518
|
registerProof: intent.proof,
|
|
12378
|
-
registerProofMessage:
|
|
12519
|
+
registerProofMessage: chunkHHV5FPC6_cjs.Intent.encodeMessage(intent.message),
|
|
12379
12520
|
deleteProof: deleteIntent.proof,
|
|
12380
|
-
deleteProofMessage:
|
|
12521
|
+
deleteProofMessage: chunkHHV5FPC6_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
12381
12522
|
intentVtxos: inputs.map((i) => ({
|
|
12382
12523
|
txid: i.txid,
|
|
12383
12524
|
vout: i.vout
|
|
@@ -12409,7 +12550,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12409
12550
|
try {
|
|
12410
12551
|
return await this.arkProvider.registerIntent(intent);
|
|
12411
12552
|
} catch (error) {
|
|
12412
|
-
if (error instanceof
|
|
12553
|
+
if (error instanceof chunkHHV5FPC6_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
12413
12554
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
12414
12555
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
12415
12556
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -12425,7 +12566,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12425
12566
|
expire_at: 0,
|
|
12426
12567
|
cosigners_public_keys: cosignerPubKeys
|
|
12427
12568
|
};
|
|
12428
|
-
const proof =
|
|
12569
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, outputs);
|
|
12429
12570
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12430
12571
|
return {
|
|
12431
12572
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12437,7 +12578,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12437
12578
|
type: "delete",
|
|
12438
12579
|
expire_at: 0
|
|
12439
12580
|
};
|
|
12440
|
-
const proof =
|
|
12581
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, []);
|
|
12441
12582
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12442
12583
|
return {
|
|
12443
12584
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12449,7 +12590,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12449
12590
|
type: "get-pending-tx",
|
|
12450
12591
|
expire_at: 0
|
|
12451
12592
|
};
|
|
12452
|
-
const proof =
|
|
12593
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, []);
|
|
12453
12594
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12454
12595
|
return {
|
|
12455
12596
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12726,9 +12867,24 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12726
12867
|
}
|
|
12727
12868
|
const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
|
|
12728
12869
|
const hasAssets = assetInputs.size > 0 || recipients.some((r) => r.assets && r.assets.length > 0);
|
|
12870
|
+
const customExtPackets = [];
|
|
12871
|
+
for (const r of args) {
|
|
12872
|
+
if (r.extensions) {
|
|
12873
|
+
for (const ext of r.extensions) {
|
|
12874
|
+
customExtPackets.push({
|
|
12875
|
+
type: () => ext.type,
|
|
12876
|
+
serialize: () => ext.payload
|
|
12877
|
+
});
|
|
12878
|
+
}
|
|
12879
|
+
}
|
|
12880
|
+
}
|
|
12881
|
+
const allExtPackets = [];
|
|
12729
12882
|
if (hasAssets) {
|
|
12730
|
-
|
|
12731
|
-
|
|
12883
|
+
allExtPackets.push(createAssetPacket(assetInputs, recipients, changeReceiver));
|
|
12884
|
+
}
|
|
12885
|
+
allExtPackets.push(...customExtPackets);
|
|
12886
|
+
if (allExtPackets.length > 0) {
|
|
12887
|
+
outputs.push(Extension.create(allExtPackets).txOut());
|
|
12732
12888
|
}
|
|
12733
12889
|
const sentAmount = recipients.reduce((sum, r) => sum + r.amount, 0);
|
|
12734
12890
|
return this._submitOffchainSpend(selectedCoins, outputs, {
|
|
@@ -12865,74 +13021,54 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12865
13021
|
);
|
|
12866
13022
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
12867
13023
|
index,
|
|
12868
|
-
lookupScript:
|
|
13024
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12869
13025
|
}));
|
|
12870
|
-
const checkpointJobs = offchainTx.checkpoints.map(
|
|
12871
|
-
(c) => this.inputSigningJobsFromWitnessUtxos(c)
|
|
12872
|
-
);
|
|
12873
|
-
let signedVirtualTx;
|
|
12874
|
-
let userSignedCheckpoints;
|
|
12875
13026
|
const identity = this.identity;
|
|
12876
|
-
const
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
tx: offchainTx.arkTx.clone(),
|
|
12881
|
-
inputIndexes: arkTxJobs.map((j) => j.index)
|
|
12882
|
-
},
|
|
12883
|
-
...offchainTx.checkpoints.map((c, i) => ({
|
|
12884
|
-
tx: c.clone(),
|
|
12885
|
-
inputIndexes: checkpointJobs[i].map((j) => j.index)
|
|
12886
|
-
}))
|
|
12887
|
-
];
|
|
12888
|
-
const signed = await identity.signMultiple(requests);
|
|
12889
|
-
if (signed.length !== requests.length) {
|
|
12890
|
-
throw new Error(
|
|
12891
|
-
`signMultiple returned ${signed.length} transactions, expected ${requests.length}`
|
|
12892
|
-
);
|
|
12893
|
-
}
|
|
12894
|
-
const [firstSignedTx, ...signedCheckpoints] = signed;
|
|
12895
|
-
signedVirtualTx = firstSignedTx;
|
|
12896
|
-
userSignedCheckpoints = signedCheckpoints;
|
|
12897
|
-
} else {
|
|
12898
|
-
signedVirtualTx = await this._signerRouter.sign(offchainTx.arkTx, arkTxJobs);
|
|
12899
|
-
}
|
|
12900
|
-
await this.setPendingTxFlag(true);
|
|
12901
|
-
const { arkTxid, signedCheckpointTxs } = await this.arkProvider.submitTx(
|
|
12902
|
-
base.base64.encode(signedVirtualTx.toPSBT()),
|
|
12903
|
-
offchainTx.checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
12904
|
-
);
|
|
12905
|
-
let finalCheckpoints;
|
|
12906
|
-
if (userSignedCheckpoints) {
|
|
12907
|
-
if (signedCheckpointTxs.length !== userSignedCheckpoints.length) {
|
|
12908
|
-
throw new Error(
|
|
12909
|
-
`submitTx returned ${signedCheckpointTxs.length} checkpoints, expected ${userSignedCheckpoints.length}`
|
|
13027
|
+
const signer = {
|
|
13028
|
+
signArkTx: async (arkTx, checkpoints) => {
|
|
13029
|
+
const checkpointJobs = checkpoints.map(
|
|
13030
|
+
(c) => this.inputSigningJobsFromWitnessUtxos(c)
|
|
12910
13031
|
);
|
|
13032
|
+
const batchEligible = isBatchSignable(identity) && await this._signerRouter.canBatch(arkTxJobs, ...checkpointJobs);
|
|
13033
|
+
if (batchEligible) {
|
|
13034
|
+
const requests = [
|
|
13035
|
+
{
|
|
13036
|
+
tx: arkTx.clone(),
|
|
13037
|
+
inputIndexes: arkTxJobs.map((j) => j.index)
|
|
13038
|
+
},
|
|
13039
|
+
...checkpoints.map((c, i) => ({
|
|
13040
|
+
tx: c.clone(),
|
|
13041
|
+
inputIndexes: checkpointJobs[i].map((j) => j.index)
|
|
13042
|
+
}))
|
|
13043
|
+
];
|
|
13044
|
+
const signed = await identity.signMultiple(requests);
|
|
13045
|
+
if (signed.length !== requests.length) {
|
|
13046
|
+
throw new Error(
|
|
13047
|
+
`signMultiple returned ${signed.length} transactions, expected ${requests.length}`
|
|
13048
|
+
);
|
|
13049
|
+
}
|
|
13050
|
+
const [firstSignedTx, ...signedCheckpoints] = signed;
|
|
13051
|
+
return { arkTx: firstSignedTx, userSignedCheckpoints: signedCheckpoints };
|
|
13052
|
+
}
|
|
13053
|
+
return { arkTx: await this._signerRouter.sign(arkTx, arkTxJobs) };
|
|
13054
|
+
},
|
|
13055
|
+
signCheckpoint: (checkpoint) => this._signerRouter.sign(
|
|
13056
|
+
checkpoint,
|
|
13057
|
+
this.inputSigningJobsFromWitnessUtxos(checkpoint)
|
|
13058
|
+
)
|
|
13059
|
+
};
|
|
13060
|
+
return submitOffchainTx(this.arkProvider, offchainTx, signer, {
|
|
13061
|
+
// Mark pending before submitting — if we crash between submit and
|
|
13062
|
+
// finalize, the next init recovers via finalizePendingTxs.
|
|
13063
|
+
beforeSubmit: () => this.setPendingTxFlag(true),
|
|
13064
|
+
afterFinalize: async () => {
|
|
13065
|
+
try {
|
|
13066
|
+
await this.setPendingTxFlag(false);
|
|
13067
|
+
} catch (error) {
|
|
13068
|
+
console.error("Failed to clear pending tx flag:", error);
|
|
13069
|
+
}
|
|
12911
13070
|
}
|
|
12912
|
-
|
|
12913
|
-
const serverSigned = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
12914
|
-
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
12915
|
-
return base.base64.encode(serverSigned.toPSBT());
|
|
12916
|
-
});
|
|
12917
|
-
} else {
|
|
12918
|
-
finalCheckpoints = await Promise.all(
|
|
12919
|
-
signedCheckpointTxs.map(async (c) => {
|
|
12920
|
-
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
12921
|
-
const signedCheckpoint = await this._signerRouter.sign(
|
|
12922
|
-
tx,
|
|
12923
|
-
this.inputSigningJobsFromWitnessUtxos(tx)
|
|
12924
|
-
);
|
|
12925
|
-
return base.base64.encode(signedCheckpoint.toPSBT());
|
|
12926
|
-
})
|
|
12927
|
-
);
|
|
12928
|
-
}
|
|
12929
|
-
await this.arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
12930
|
-
try {
|
|
12931
|
-
await this.setPendingTxFlag(false);
|
|
12932
|
-
} catch (error) {
|
|
12933
|
-
console.error("Failed to clear pending tx flag:", error);
|
|
12934
|
-
}
|
|
12935
|
-
return { arkTxid, signedCheckpointTxs };
|
|
13071
|
+
});
|
|
12936
13072
|
}
|
|
12937
13073
|
// mark virtual outputs as spent, save change outputs if any.
|
|
12938
13074
|
// `offchainTapscript` and `serverPubKey` are the epoch snapshot the
|
|
@@ -13098,7 +13234,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13098
13234
|
} else {
|
|
13099
13235
|
let sourceAddress;
|
|
13100
13236
|
try {
|
|
13101
|
-
sourceAddress =
|
|
13237
|
+
sourceAddress = chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
13102
13238
|
this.network
|
|
13103
13239
|
);
|
|
13104
13240
|
} catch {
|
|
@@ -13409,7 +13545,7 @@ var MessageBus = class {
|
|
|
13409
13545
|
this.initialized = true;
|
|
13410
13546
|
}
|
|
13411
13547
|
async buildServices(config) {
|
|
13412
|
-
const arkProvider = new
|
|
13548
|
+
const arkProvider = new chunkHHV5FPC6_cjs.RestArkProvider(config.arkServer.url);
|
|
13413
13549
|
const storage = {
|
|
13414
13550
|
walletRepository: this.walletRepository,
|
|
13415
13551
|
contractRepository: this.contractRepository
|
|
@@ -13792,7 +13928,7 @@ var Ramps = class {
|
|
|
13792
13928
|
}
|
|
13793
13929
|
amount = amount ?? totalAmount;
|
|
13794
13930
|
const offchainAddress = await this.wallet.getAddress();
|
|
13795
|
-
const offchainAddr =
|
|
13931
|
+
const offchainAddr = chunkL5ND2FJJ_cjs.ArkAddress.decode(offchainAddress);
|
|
13796
13932
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
13797
13933
|
const outputFee = estimator.evalOffchainOutput({
|
|
13798
13934
|
amount,
|
|
@@ -13890,7 +14026,7 @@ var Ramps = class {
|
|
|
13890
14026
|
let destinationScript;
|
|
13891
14027
|
for (const networkName of networkNames) {
|
|
13892
14028
|
try {
|
|
13893
|
-
const network =
|
|
14029
|
+
const network = chunkL5ND2FJJ_cjs.networks[networkName];
|
|
13894
14030
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
13895
14031
|
destinationScript = btcSigner.OutScript.encode(addr);
|
|
13896
14032
|
break;
|
|
@@ -14575,7 +14711,7 @@ var WalletMessageHandler = class {
|
|
|
14575
14711
|
// Wallet methods
|
|
14576
14712
|
async handleInitWallet({ payload }) {
|
|
14577
14713
|
const { arkServerUrl } = payload;
|
|
14578
|
-
this.indexerProvider = new
|
|
14714
|
+
this.indexerProvider = new chunkHHV5FPC6_cjs.RestIndexerProvider(arkServerUrl);
|
|
14579
14715
|
await this.onWalletInitialized();
|
|
14580
14716
|
}
|
|
14581
14717
|
async handleGetBalance() {
|
|
@@ -16330,12 +16466,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16330
16466
|
* @returns Configured onchain wallet
|
|
16331
16467
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
16332
16468
|
*/
|
|
16333
|
-
static async create(identity, networkName =
|
|
16469
|
+
static async create(identity, networkName = chunkL5ND2FJJ_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
16334
16470
|
const pubkey = await identity.xOnlyPublicKey();
|
|
16335
16471
|
if (!pubkey) {
|
|
16336
16472
|
throw new Error("Invalid configured public key");
|
|
16337
16473
|
}
|
|
16338
|
-
const network =
|
|
16474
|
+
const network = chunkL5ND2FJJ_cjs.getNetwork(networkName);
|
|
16339
16475
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
16340
16476
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
16341
16477
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -16441,7 +16577,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16441
16577
|
if (!inputs) {
|
|
16442
16578
|
throw new Error("Fee estimation failed");
|
|
16443
16579
|
}
|
|
16444
|
-
let tx = new
|
|
16580
|
+
let tx = new chunkHHV5FPC6_cjs.Transaction();
|
|
16445
16581
|
for (const input of inputs) {
|
|
16446
16582
|
tx.addInput({
|
|
16447
16583
|
txid: input.txid,
|
|
@@ -16499,7 +16635,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16499
16635
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
16500
16636
|
*/
|
|
16501
16637
|
async bumpAnchor(parentHex, feeRate) {
|
|
16502
|
-
const parent =
|
|
16638
|
+
const parent = chunkHHV5FPC6_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
16503
16639
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
16504
16640
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
16505
16641
|
return [parent.hex, child.hex];
|
|
@@ -17264,7 +17400,7 @@ exports.BIP322 = void 0;
|
|
|
17264
17400
|
async function sign2(message, identity, network) {
|
|
17265
17401
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
17266
17402
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
17267
|
-
const toSpend =
|
|
17403
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
17268
17404
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
17269
17405
|
const signed = await identity.sign(toSign, [0]);
|
|
17270
17406
|
signed.finalizeIdx(0);
|
|
@@ -17322,7 +17458,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
17322
17458
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
17323
17459
|
return false;
|
|
17324
17460
|
}
|
|
17325
|
-
const toSpend =
|
|
17461
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17326
17462
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
17327
17463
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
17328
17464
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -17343,7 +17479,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
17343
17479
|
}
|
|
17344
17480
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
17345
17481
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
17346
|
-
const toSpend =
|
|
17482
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17347
17483
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
17348
17484
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
17349
17485
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -17396,7 +17532,7 @@ function encodeCompactSize(n) {
|
|
|
17396
17532
|
return buf;
|
|
17397
17533
|
}
|
|
17398
17534
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
17399
|
-
const tx = new
|
|
17535
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 0 });
|
|
17400
17536
|
tx.addInput({
|
|
17401
17537
|
txid: toSpend.id,
|
|
17402
17538
|
index: 0,
|
|
@@ -17410,12 +17546,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
17410
17546
|
});
|
|
17411
17547
|
tx.addOutput({
|
|
17412
17548
|
amount: 0n,
|
|
17413
|
-
script:
|
|
17549
|
+
script: chunkHHV5FPC6_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17414
17550
|
});
|
|
17415
17551
|
return tx;
|
|
17416
17552
|
}
|
|
17417
17553
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
17418
|
-
const tx = new
|
|
17554
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 0 });
|
|
17419
17555
|
tx.addInput({
|
|
17420
17556
|
txid: toSpend.id,
|
|
17421
17557
|
index: 0,
|
|
@@ -17427,12 +17563,138 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
17427
17563
|
});
|
|
17428
17564
|
tx.addOutput({
|
|
17429
17565
|
amount: 0n,
|
|
17430
|
-
script:
|
|
17566
|
+
script: chunkHHV5FPC6_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17431
17567
|
});
|
|
17432
17568
|
return tx;
|
|
17433
17569
|
}
|
|
17570
|
+
|
|
17571
|
+
// src/providers/emulator.ts
|
|
17572
|
+
var RestEmulatorProvider = class {
|
|
17573
|
+
constructor(serverUrl) {
|
|
17574
|
+
this.serverUrl = serverUrl;
|
|
17575
|
+
}
|
|
17576
|
+
serverUrl;
|
|
17577
|
+
async getInfo() {
|
|
17578
|
+
const url = `${this.serverUrl}/v1/info`;
|
|
17579
|
+
const response = await fetch(url);
|
|
17580
|
+
if (!response.ok) {
|
|
17581
|
+
const errorText2 = await response.text();
|
|
17582
|
+
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
17583
|
+
}
|
|
17584
|
+
const data = await response.json();
|
|
17585
|
+
const signerPubkey = data.signerPubkey;
|
|
17586
|
+
if (typeof signerPubkey !== "string" || !signerPubkey) {
|
|
17587
|
+
throw new Error("Invalid emulator info response: missing signerPubkey");
|
|
17588
|
+
}
|
|
17589
|
+
return { signerPubkey };
|
|
17590
|
+
}
|
|
17591
|
+
async submitTx(arkTx, checkpointTxs) {
|
|
17592
|
+
const url = `${this.serverUrl}/v1/tx`;
|
|
17593
|
+
const response = await fetch(url, {
|
|
17594
|
+
method: "POST",
|
|
17595
|
+
headers: { "Content-Type": "application/json" },
|
|
17596
|
+
body: JSON.stringify({
|
|
17597
|
+
arkTx,
|
|
17598
|
+
checkpointTxs
|
|
17599
|
+
})
|
|
17600
|
+
});
|
|
17601
|
+
if (!response.ok) {
|
|
17602
|
+
const errorText2 = await response.text();
|
|
17603
|
+
throw new Error(`Failed to submit tx to emulator: ${errorText2}`);
|
|
17604
|
+
}
|
|
17605
|
+
const data = await response.json();
|
|
17606
|
+
if (typeof data.signedArkTx !== "string" || !data.signedArkTx) {
|
|
17607
|
+
throw new Error("Invalid emulator submitTx response: missing signedArkTx");
|
|
17608
|
+
}
|
|
17609
|
+
if (!Array.isArray(data.signedCheckpointTxs) || !data.signedCheckpointTxs.every((item) => typeof item === "string")) {
|
|
17610
|
+
throw new Error(
|
|
17611
|
+
"Invalid emulator submitTx response: signedCheckpointTxs must be an array of strings"
|
|
17612
|
+
);
|
|
17613
|
+
}
|
|
17614
|
+
return {
|
|
17615
|
+
signedArkTx: data.signedArkTx,
|
|
17616
|
+
signedCheckpointTxs: data.signedCheckpointTxs
|
|
17617
|
+
};
|
|
17618
|
+
}
|
|
17619
|
+
async submitIntent(intent) {
|
|
17620
|
+
const url = `${this.serverUrl}/v1/intent`;
|
|
17621
|
+
const response = await fetch(url, {
|
|
17622
|
+
method: "POST",
|
|
17623
|
+
headers: { "Content-Type": "application/json" },
|
|
17624
|
+
body: JSON.stringify({
|
|
17625
|
+
intent: {
|
|
17626
|
+
proof: intent.proof,
|
|
17627
|
+
message: JSON.stringify(intent.message)
|
|
17628
|
+
}
|
|
17629
|
+
})
|
|
17630
|
+
});
|
|
17631
|
+
if (!response.ok) {
|
|
17632
|
+
const errorText2 = await response.text();
|
|
17633
|
+
throw new Error(`Failed to submit intent to emulator: ${errorText2}`);
|
|
17634
|
+
}
|
|
17635
|
+
const data = await response.json();
|
|
17636
|
+
if (typeof data.signedProof !== "string" || !data.signedProof) {
|
|
17637
|
+
throw new Error("Invalid emulator submitIntent response: missing signedProof");
|
|
17638
|
+
}
|
|
17639
|
+
return data.signedProof;
|
|
17640
|
+
}
|
|
17641
|
+
async submitFinalization(intent, forfeits, connectorTree, commitmentTx) {
|
|
17642
|
+
const url = `${this.serverUrl}/v1/finalization`;
|
|
17643
|
+
const response = await fetch(url, {
|
|
17644
|
+
method: "POST",
|
|
17645
|
+
headers: { "Content-Type": "application/json" },
|
|
17646
|
+
// Uses "signedIntent" (not "intent") because the proof was already
|
|
17647
|
+
// co-signed by the emulator via submitIntent in a prior step.
|
|
17648
|
+
body: JSON.stringify({
|
|
17649
|
+
signedIntent: {
|
|
17650
|
+
proof: intent.proof,
|
|
17651
|
+
message: JSON.stringify(intent.message)
|
|
17652
|
+
},
|
|
17653
|
+
forfeits,
|
|
17654
|
+
connectorTree,
|
|
17655
|
+
commitmentTx
|
|
17656
|
+
})
|
|
17657
|
+
});
|
|
17658
|
+
if (!response.ok) {
|
|
17659
|
+
const errorText2 = await response.text();
|
|
17660
|
+
throw new Error(`Failed to submit finalization to emulator: ${errorText2}`);
|
|
17661
|
+
}
|
|
17662
|
+
const data = await response.json();
|
|
17663
|
+
if (!Array.isArray(data.signedForfeits) || !data.signedForfeits.every((item) => typeof item === "string")) {
|
|
17664
|
+
throw new Error(
|
|
17665
|
+
"Invalid emulator submitFinalization response: signedForfeits must be an array of strings"
|
|
17666
|
+
);
|
|
17667
|
+
}
|
|
17668
|
+
if ("signedCommitmentTx" in data && typeof data.signedCommitmentTx !== "string") {
|
|
17669
|
+
throw new Error(
|
|
17670
|
+
"Invalid emulator submitFinalization response: invalid signedCommitmentTx"
|
|
17671
|
+
);
|
|
17672
|
+
}
|
|
17673
|
+
return {
|
|
17674
|
+
signedForfeits: data.signedForfeits,
|
|
17675
|
+
signedCommitmentTx: data.signedCommitmentTx
|
|
17676
|
+
};
|
|
17677
|
+
}
|
|
17678
|
+
async submitOnchainTx(tx) {
|
|
17679
|
+
const url = `${this.serverUrl}/v1/onchain-tx`;
|
|
17680
|
+
const response = await fetch(url, {
|
|
17681
|
+
method: "POST",
|
|
17682
|
+
headers: { "Content-Type": "application/json" },
|
|
17683
|
+
body: JSON.stringify({ tx })
|
|
17684
|
+
});
|
|
17685
|
+
if (!response.ok) {
|
|
17686
|
+
const errorText2 = await response.text();
|
|
17687
|
+
throw new Error(`Failed to submit onchain tx to emulator: ${errorText2}`);
|
|
17688
|
+
}
|
|
17689
|
+
const data = await response.json();
|
|
17690
|
+
if (typeof data.signedTx !== "string" || !data.signedTx) {
|
|
17691
|
+
throw new Error("Invalid emulator submitOnchainTx response: missing signedTx");
|
|
17692
|
+
}
|
|
17693
|
+
return { signedTx: data.signedTx };
|
|
17694
|
+
}
|
|
17695
|
+
};
|
|
17434
17696
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
17435
|
-
const tx =
|
|
17697
|
+
const tx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
17436
17698
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
17437
17699
|
const input = tx.getInput(0);
|
|
17438
17700
|
if (!input) {
|
|
@@ -17459,14 +17721,14 @@ var ExitPathError = class extends Error {
|
|
|
17459
17721
|
reason;
|
|
17460
17722
|
};
|
|
17461
17723
|
function delayWeight(sequence) {
|
|
17462
|
-
const t =
|
|
17724
|
+
const t = chunkL5ND2FJJ_cjs.sequenceToTimelock(sequence);
|
|
17463
17725
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
17464
17726
|
}
|
|
17465
17727
|
async function resolveUnilateralPath(params) {
|
|
17466
17728
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
17467
17729
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
17468
17730
|
if (contract) {
|
|
17469
|
-
const handler =
|
|
17731
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
17470
17732
|
if (!handler) {
|
|
17471
17733
|
throw new ExitPathError(
|
|
17472
17734
|
"no-handler",
|
|
@@ -17489,12 +17751,12 @@ async function resolveUnilateralPath(params) {
|
|
|
17489
17751
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
17490
17752
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
17491
17753
|
}
|
|
17492
|
-
const decoded =
|
|
17754
|
+
const decoded = chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
17493
17755
|
let best;
|
|
17494
17756
|
for (const exit of decoded.exitPaths()) {
|
|
17495
17757
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
17496
17758
|
if (!leaf) continue;
|
|
17497
|
-
const sequence =
|
|
17759
|
+
const sequence = chunkL5ND2FJJ_cjs.timelockToSequence(exit.params.timelock);
|
|
17498
17760
|
const weight = delayWeight(sequence);
|
|
17499
17761
|
if (!best || weight < best.weight) {
|
|
17500
17762
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -17680,14 +17942,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17680
17942
|
}
|
|
17681
17943
|
const resolved = await resolveUnilateralPath({
|
|
17682
17944
|
vtxo,
|
|
17683
|
-
scriptHex: base.hex.encode(
|
|
17945
|
+
scriptHex: base.hex.encode(chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
17684
17946
|
contractRepository: wallet.contractRepository,
|
|
17685
17947
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
17686
17948
|
currentTime: Date.now()
|
|
17687
17949
|
});
|
|
17688
17950
|
const spendingLeaf = resolved.selection.leaf;
|
|
17689
17951
|
const sequence = resolved.selection.sequence;
|
|
17690
|
-
const timelock =
|
|
17952
|
+
const timelock = chunkL5ND2FJJ_cjs.sequenceToTimelock(sequence);
|
|
17691
17953
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
17692
17954
|
if (!elapsed) {
|
|
17693
17955
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -17700,7 +17962,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17700
17962
|
sequence,
|
|
17701
17963
|
witnessUtxo: {
|
|
17702
17964
|
amount: BigInt(vtxo.value),
|
|
17703
|
-
script:
|
|
17965
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
17704
17966
|
},
|
|
17705
17967
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
17706
17968
|
});
|
|
@@ -17710,7 +17972,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17710
17972
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
17711
17973
|
);
|
|
17712
17974
|
}
|
|
17713
|
-
const tx = new
|
|
17975
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
17714
17976
|
for (const input of inputs) {
|
|
17715
17977
|
tx.addInput(input);
|
|
17716
17978
|
}
|
|
@@ -17777,7 +18039,7 @@ async function buildSignedSweep(params) {
|
|
|
17777
18039
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
17778
18040
|
);
|
|
17779
18041
|
}
|
|
17780
|
-
const tx = new
|
|
18042
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
17781
18043
|
tx.addInput({
|
|
17782
18044
|
txid: vtxo.txid,
|
|
17783
18045
|
index: vtxo.vout,
|
|
@@ -17802,7 +18064,7 @@ async function buildSignedSweep(params) {
|
|
|
17802
18064
|
finalScriptWitness: [
|
|
17803
18065
|
tapScriptSig[0][1],
|
|
17804
18066
|
...path.extraWitness,
|
|
17805
|
-
|
|
18067
|
+
chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(path.leaf),
|
|
17806
18068
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
17807
18069
|
]
|
|
17808
18070
|
});
|
|
@@ -17847,7 +18109,7 @@ async function selectExitVtxos(opts) {
|
|
|
17847
18109
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
17848
18110
|
);
|
|
17849
18111
|
}
|
|
17850
|
-
const handler =
|
|
18112
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
17851
18113
|
if (!handler) {
|
|
17852
18114
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
17853
18115
|
}
|
|
@@ -17877,7 +18139,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17877
18139
|
if (pendingNodes.length > 0) {
|
|
17878
18140
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
17879
18141
|
for (const psbt of txs) {
|
|
17880
|
-
psbts.set(
|
|
18142
|
+
psbts.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
17881
18143
|
}
|
|
17882
18144
|
}
|
|
17883
18145
|
const childVsize = Number(
|
|
@@ -17913,7 +18175,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17913
18175
|
try {
|
|
17914
18176
|
const resolved = await resolveUnilateralPath({
|
|
17915
18177
|
vtxo,
|
|
17916
|
-
scriptHex: base.hex.encode(
|
|
18178
|
+
scriptHex: base.hex.encode(chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
17917
18179
|
contractRepository: wallet.contractRepository,
|
|
17918
18180
|
walletPubKeyHex,
|
|
17919
18181
|
currentTime: Date.now()
|
|
@@ -17932,7 +18194,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17932
18194
|
});
|
|
17933
18195
|
continue;
|
|
17934
18196
|
}
|
|
17935
|
-
const t =
|
|
18197
|
+
const t = chunkL5ND2FJJ_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
17936
18198
|
const delay = { type: t.type, value: Number(t.value) };
|
|
17937
18199
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
17938
18200
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -18239,7 +18501,7 @@ async function prepare(opts) {
|
|
|
18239
18501
|
txid: sweep.vtxo.txid,
|
|
18240
18502
|
vout: sweep.vtxo.vout,
|
|
18241
18503
|
value: sweep.vtxo.value,
|
|
18242
|
-
pkScript:
|
|
18504
|
+
pkScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
18243
18505
|
},
|
|
18244
18506
|
path: sweep.resolved.selection,
|
|
18245
18507
|
outputAddress: opts.sweepAddress,
|
|
@@ -18324,7 +18586,7 @@ async function prepare(opts) {
|
|
|
18324
18586
|
if (newFee <= splitterFee) break;
|
|
18325
18587
|
splitterFee = newFee;
|
|
18326
18588
|
}
|
|
18327
|
-
const splitter = new
|
|
18589
|
+
const splitter = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
18328
18590
|
for (const coin of selected.inputs) {
|
|
18329
18591
|
splitter.addInput({
|
|
18330
18592
|
txid: coin.txid,
|
|
@@ -18463,6 +18725,656 @@ var UnilateralExit = {
|
|
|
18463
18725
|
prepare,
|
|
18464
18726
|
Executor
|
|
18465
18727
|
};
|
|
18728
|
+
|
|
18729
|
+
// src/arkade/index.ts
|
|
18730
|
+
var arkade_exports = {};
|
|
18731
|
+
chunk5BLDMQED_cjs.__export(arkade_exports, {
|
|
18732
|
+
ARKADE_OP: () => chunkRQSA7ADZ_cjs.ARKADE_OP,
|
|
18733
|
+
ARKADE_OPCODES: () => chunkRQSA7ADZ_cjs.ARKADE_OPCODES,
|
|
18734
|
+
ARKADE_OPCODE_NAMES: () => chunkRQSA7ADZ_cjs.ARKADE_OPCODE_NAMES,
|
|
18735
|
+
ARKADE_OPCODE_VALUES: () => chunkRQSA7ADZ_cjs.ARKADE_OPCODE_VALUES,
|
|
18736
|
+
ARKADE_OPS: () => chunkRQSA7ADZ_cjs.ARKADE_OPS,
|
|
18737
|
+
Arkade: () => Arkade,
|
|
18738
|
+
ArkadeContract: () => ArkadeContract,
|
|
18739
|
+
ArkadeProgramScript: () => chunkRQSA7ADZ_cjs.ArkadeProgramScript,
|
|
18740
|
+
ArkadeScript: () => chunkRQSA7ADZ_cjs.ArkadeScript,
|
|
18741
|
+
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
18742
|
+
BigNum: () => chunkRQSA7ADZ_cjs.bignum_exports,
|
|
18743
|
+
OP: () => btcSigner.OP,
|
|
18744
|
+
OPCODE_NAMES: () => chunkRQSA7ADZ_cjs.OPCODE_NAMES,
|
|
18745
|
+
OPCODE_VALUES: () => chunkRQSA7ADZ_cjs.OPCODE_VALUES,
|
|
18746
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkRQSA7ADZ_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
18747
|
+
Script: () => btcSigner.Script,
|
|
18748
|
+
arkadeScriptHash: () => chunkRQSA7ADZ_cjs.arkadeScriptHash,
|
|
18749
|
+
arkadeWitnessHash: () => chunkRQSA7ADZ_cjs.arkadeWitnessHash,
|
|
18750
|
+
asmToBytes: () => chunkRQSA7ADZ_cjs.asmToBytes,
|
|
18751
|
+
bytesToASM: () => chunkRQSA7ADZ_cjs.bytesToASM,
|
|
18752
|
+
computeArkadeScriptPublicKey: () => chunkRQSA7ADZ_cjs.computeArkadeScriptPublicKey,
|
|
18753
|
+
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
18754
|
+
deserializeArkadeContractParams: () => chunkRQSA7ADZ_cjs.deserializeArkadeContractParams,
|
|
18755
|
+
fromASM: () => chunkRQSA7ADZ_cjs.fromASM,
|
|
18756
|
+
getOpcodeName: () => chunkRQSA7ADZ_cjs.getOpcodeName,
|
|
18757
|
+
getOpcodeValue: () => chunkRQSA7ADZ_cjs.getOpcodeValue,
|
|
18758
|
+
parseArtifact: () => chunkRQSA7ADZ_cjs.parseArtifact,
|
|
18759
|
+
resolveAsm: () => chunkRQSA7ADZ_cjs.resolveAsm,
|
|
18760
|
+
serializeArkadeContractParams: () => chunkRQSA7ADZ_cjs.serializeArkadeContractParams,
|
|
18761
|
+
stringifyArtifact: () => chunkRQSA7ADZ_cjs.stringifyArtifact,
|
|
18762
|
+
toASM: () => chunkRQSA7ADZ_cjs.toASM,
|
|
18763
|
+
validateProgram: () => chunkRQSA7ADZ_cjs.validateProgram,
|
|
18764
|
+
witnessRefToBytes: () => chunkRQSA7ADZ_cjs.witnessRefToBytes
|
|
18765
|
+
});
|
|
18766
|
+
var isVtxoCoin = (input) => "virtualStatus" in input;
|
|
18767
|
+
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients) {
|
|
18768
|
+
let batchId;
|
|
18769
|
+
let sweepTapTreeRoot;
|
|
18770
|
+
return {
|
|
18771
|
+
onBatchStarted: async (event) => {
|
|
18772
|
+
const utf8IntentId = new TextEncoder().encode(intentId);
|
|
18773
|
+
const intentIdHash = utils_js.sha256(utf8IntentId);
|
|
18774
|
+
const intentIdHashStr = base.hex.encode(intentIdHash);
|
|
18775
|
+
if (!event.intentIdHashes.includes(intentIdHashStr)) return { skip: true };
|
|
18776
|
+
await arkProvider.confirmRegistration(intentId);
|
|
18777
|
+
batchId = event.id;
|
|
18778
|
+
const sweepTapscript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.encode({
|
|
18779
|
+
timelock: {
|
|
18780
|
+
value: event.batchExpiry,
|
|
18781
|
+
// BIP-65: values >= 512 are interpreted as seconds, below as blocks
|
|
18782
|
+
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
18783
|
+
},
|
|
18784
|
+
pubkeys: [base.hex.decode((await arkProvider.getInfo()).forfeitPubkey).subarray(1)]
|
|
18785
|
+
}).script;
|
|
18786
|
+
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
18787
|
+
return { skip: false };
|
|
18788
|
+
},
|
|
18789
|
+
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
18790
|
+
const signerPubKey = await session.getPublicKey();
|
|
18791
|
+
const xonlySignerPubKey = signerPubKey.subarray(1);
|
|
18792
|
+
const xOnlyPubkeys = event.cosignersPublicKeys.map((k) => k.slice(2));
|
|
18793
|
+
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
18794
|
+
return { skip: true };
|
|
18795
|
+
}
|
|
18796
|
+
const commitmentTx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
18797
|
+
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
18798
|
+
if (recipients && recipients.length > 0) {
|
|
18799
|
+
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
18800
|
+
}
|
|
18801
|
+
const sharedOutput = commitmentTx.getOutput(0);
|
|
18802
|
+
if (!sharedOutput?.amount) {
|
|
18803
|
+
throw new Error("Shared output not found");
|
|
18804
|
+
}
|
|
18805
|
+
await session.init(vtxoTree, sweepTapTreeRoot, sharedOutput.amount);
|
|
18806
|
+
const pubkey = base.hex.encode(await session.getPublicKey());
|
|
18807
|
+
const nonces = await session.getNonces();
|
|
18808
|
+
await arkProvider.submitTreeNonces(batchId, pubkey, nonces);
|
|
18809
|
+
return { skip: false };
|
|
18810
|
+
},
|
|
18811
|
+
onTreeNonces: async (event) => {
|
|
18812
|
+
const { hasAllNonces } = await session.aggregatedNonces(event.txid, event.nonces);
|
|
18813
|
+
if (!hasAllNonces) return { fullySigned: false };
|
|
18814
|
+
const signatures = await session.sign();
|
|
18815
|
+
const pubkey = base.hex.encode(await session.getPublicKey());
|
|
18816
|
+
await arkProvider.submitTreeSignatures(batchId, pubkey, signatures);
|
|
18817
|
+
return { fullySigned: true };
|
|
18818
|
+
},
|
|
18819
|
+
onBatchFinalization: async (event, _vtxoTree, connectorTree) => {
|
|
18820
|
+
const info = await arkProvider.getInfo();
|
|
18821
|
+
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
18822
|
+
btcSigner.Address(network).decode(info.forfeitAddress)
|
|
18823
|
+
);
|
|
18824
|
+
if (connectorTree) {
|
|
18825
|
+
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
18826
|
+
}
|
|
18827
|
+
let commitmentPsbt = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
18828
|
+
const signedForfeits = [];
|
|
18829
|
+
let connectorIndex = 0;
|
|
18830
|
+
const connectorLeaves = connectorTree?.leaves() || [];
|
|
18831
|
+
const boardingIndices = [];
|
|
18832
|
+
for (const input of inputs) {
|
|
18833
|
+
if (!isVtxoCoin(input)) {
|
|
18834
|
+
let boardingIdx = null;
|
|
18835
|
+
for (let i = 0; i < commitmentPsbt.inputsLength; i++) {
|
|
18836
|
+
const psbtInput = commitmentPsbt.getInput(i);
|
|
18837
|
+
if (!psbtInput.txid) continue;
|
|
18838
|
+
if (base.hex.encode(psbtInput.txid) === input.txid && psbtInput.index === input.vout) {
|
|
18839
|
+
boardingIdx = i;
|
|
18840
|
+
break;
|
|
18841
|
+
}
|
|
18842
|
+
}
|
|
18843
|
+
if (boardingIdx === null) continue;
|
|
18844
|
+
commitmentPsbt.updateInput(boardingIdx, {
|
|
18845
|
+
tapLeafScript: [input.forfeitTapLeafScript]
|
|
18846
|
+
});
|
|
18847
|
+
boardingIndices.push(boardingIdx);
|
|
18848
|
+
continue;
|
|
18849
|
+
}
|
|
18850
|
+
if (isRecoverable(input) || isSubdust(input, info.dust)) {
|
|
18851
|
+
continue;
|
|
18852
|
+
}
|
|
18853
|
+
if (connectorIndex >= connectorLeaves.length) {
|
|
18854
|
+
throw new Error("not enough connectors received");
|
|
18855
|
+
}
|
|
18856
|
+
const connectorLeaf = connectorLeaves[connectorIndex++];
|
|
18857
|
+
const connectorTxId = connectorLeaf.id;
|
|
18858
|
+
const connectorOutput = connectorLeaf.getOutput(0);
|
|
18859
|
+
if (!connectorOutput?.amount || !connectorOutput?.script) {
|
|
18860
|
+
throw new Error(
|
|
18861
|
+
`Invalid connector output at index ${connectorIndex - 1}: missing amount or script`
|
|
18862
|
+
);
|
|
18863
|
+
}
|
|
18864
|
+
let forfeitTx = buildForfeitTx(
|
|
18865
|
+
[
|
|
18866
|
+
{
|
|
18867
|
+
txid: input.txid,
|
|
18868
|
+
index: input.vout,
|
|
18869
|
+
witnessUtxo: {
|
|
18870
|
+
amount: BigInt(input.value),
|
|
18871
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
18872
|
+
},
|
|
18873
|
+
sighashType: btcSigner.SigHash.DEFAULT,
|
|
18874
|
+
tapLeafScript: [input.forfeitTapLeafScript]
|
|
18875
|
+
},
|
|
18876
|
+
{
|
|
18877
|
+
txid: connectorTxId,
|
|
18878
|
+
index: 0,
|
|
18879
|
+
witnessUtxo: {
|
|
18880
|
+
amount: connectorOutput.amount,
|
|
18881
|
+
script: connectorOutput.script
|
|
18882
|
+
}
|
|
18883
|
+
}
|
|
18884
|
+
],
|
|
18885
|
+
forfeitOutputScript
|
|
18886
|
+
);
|
|
18887
|
+
forfeitTx = await signer.sign(forfeitTx, [0]);
|
|
18888
|
+
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
18889
|
+
}
|
|
18890
|
+
if (boardingIndices.length > 0) {
|
|
18891
|
+
commitmentPsbt = await signer.sign(commitmentPsbt, boardingIndices);
|
|
18892
|
+
}
|
|
18893
|
+
let connectorTreeNodes = null;
|
|
18894
|
+
if (connectorTree) {
|
|
18895
|
+
connectorTreeNodes = [];
|
|
18896
|
+
for (const subtree of connectorTree.iterator()) {
|
|
18897
|
+
const children = {};
|
|
18898
|
+
for (const [outputIndex, child] of subtree.children) {
|
|
18899
|
+
children[String(outputIndex)] = child.txid;
|
|
18900
|
+
}
|
|
18901
|
+
connectorTreeNodes.push({
|
|
18902
|
+
txid: subtree.txid,
|
|
18903
|
+
tx: base.base64.encode(subtree.root.toPSBT()),
|
|
18904
|
+
children
|
|
18905
|
+
});
|
|
18906
|
+
}
|
|
18907
|
+
}
|
|
18908
|
+
const hasBoardingInputs = boardingIndices.length > 0;
|
|
18909
|
+
const commitmentB64 = hasBoardingInputs ? base.base64.encode(commitmentPsbt.toPSBT()) : event.commitmentTx;
|
|
18910
|
+
const emuResult = await emulator.submitFinalization(
|
|
18911
|
+
{ proof: signedProof, message },
|
|
18912
|
+
signedForfeits,
|
|
18913
|
+
connectorTreeNodes,
|
|
18914
|
+
commitmentB64
|
|
18915
|
+
);
|
|
18916
|
+
await arkProvider.submitSignedForfeitTxs(
|
|
18917
|
+
emuResult.signedForfeits,
|
|
18918
|
+
emuResult.signedCommitmentTx || (hasBoardingInputs ? commitmentB64 : void 0)
|
|
18919
|
+
);
|
|
18920
|
+
}
|
|
18921
|
+
};
|
|
18922
|
+
}
|
|
18923
|
+
var Arkade = class _Arkade {
|
|
18924
|
+
arkProvider;
|
|
18925
|
+
/** The co-signing service, or undefined for emulator-less (pure tapscript) usage. */
|
|
18926
|
+
emulator;
|
|
18927
|
+
network;
|
|
18928
|
+
serverKey;
|
|
18929
|
+
/** The co-signer's x-only key, present only when an emulator is configured. */
|
|
18930
|
+
emulatorKey;
|
|
18931
|
+
checkpoint;
|
|
18932
|
+
indexer;
|
|
18933
|
+
identity;
|
|
18934
|
+
/** The signing identity's x-only public key, resolved at connect — identifies which inputs the wallet signs. */
|
|
18935
|
+
userKey;
|
|
18936
|
+
/** The wallet's contract manager, when contract persistence is wired up. */
|
|
18937
|
+
contractManager;
|
|
18938
|
+
constructor(fields) {
|
|
18939
|
+
this.arkProvider = fields.arkProvider;
|
|
18940
|
+
this.emulator = fields.emulator;
|
|
18941
|
+
this.network = fields.network;
|
|
18942
|
+
this.serverKey = fields.serverKey;
|
|
18943
|
+
this.emulatorKey = fields.emulatorKey;
|
|
18944
|
+
this.checkpoint = fields.checkpoint;
|
|
18945
|
+
this.indexer = fields.indexer;
|
|
18946
|
+
this.identity = fields.identity;
|
|
18947
|
+
this.userKey = fields.userKey;
|
|
18948
|
+
this.contractManager = fields.contractManager;
|
|
18949
|
+
}
|
|
18950
|
+
/** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
|
|
18951
|
+
static async connect(opts) {
|
|
18952
|
+
const info = await opts.arkade.getInfo();
|
|
18953
|
+
const serverKey = base.hex.decode(info.signerPubkey).slice(1);
|
|
18954
|
+
const checkpoint = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
18955
|
+
let emulatorKey;
|
|
18956
|
+
if (opts.emulator) {
|
|
18957
|
+
const eInfo = await opts.emulator.getInfo();
|
|
18958
|
+
emulatorKey = base.hex.decode(eInfo.signerPubkey);
|
|
18959
|
+
}
|
|
18960
|
+
let userKey;
|
|
18961
|
+
if (opts.identity) {
|
|
18962
|
+
const pub = await opts.identity.xOnlyPublicKey();
|
|
18963
|
+
userKey = pub.length === 33 ? pub.slice(1) : pub;
|
|
18964
|
+
}
|
|
18965
|
+
return new _Arkade({
|
|
18966
|
+
arkProvider: opts.arkade,
|
|
18967
|
+
emulator: opts.emulator,
|
|
18968
|
+
network: opts.network ?? chunkL5ND2FJJ_cjs.DEFAULT_NETWORK,
|
|
18969
|
+
serverKey,
|
|
18970
|
+
emulatorKey,
|
|
18971
|
+
checkpoint,
|
|
18972
|
+
indexer: opts.indexer,
|
|
18973
|
+
identity: opts.identity,
|
|
18974
|
+
userKey,
|
|
18975
|
+
contractManager: opts.contractManager
|
|
18976
|
+
});
|
|
18977
|
+
}
|
|
18978
|
+
/**
|
|
18979
|
+
* Instantiate a contract from a program and its constructor arguments. The
|
|
18980
|
+
* `program`'s literal type is preserved (`const` inference) so the resulting
|
|
18981
|
+
* contract's `functions` map is strongly typed — `functions.<name>(...)`
|
|
18982
|
+
* knows each argument's type from the function's `inputs` descriptors.
|
|
18983
|
+
*
|
|
18984
|
+
* When the program declares a `server` or `user` param and the caller does
|
|
18985
|
+
* not bind it, it defaults to the client's server key or the identity's
|
|
18986
|
+
* key respectively; explicit args always win.
|
|
18987
|
+
*/
|
|
18988
|
+
contract(program, args = {}) {
|
|
18989
|
+
const declared = (program.params ?? []).map(chunkRQSA7ADZ_cjs.inputName);
|
|
18990
|
+
if (declared.includes("server") && args.server === void 0) {
|
|
18991
|
+
args = { ...args, server: this.serverKey };
|
|
18992
|
+
}
|
|
18993
|
+
if (declared.includes("user") && args.user === void 0 && this.userKey) {
|
|
18994
|
+
args = { ...args, user: this.userKey };
|
|
18995
|
+
}
|
|
18996
|
+
return new ArkadeContract(this, program, args);
|
|
18997
|
+
}
|
|
18998
|
+
};
|
|
18999
|
+
var ArkadeContract = class _ArkadeContract {
|
|
19000
|
+
constructor(client, program, args = {}, keys) {
|
|
19001
|
+
this.client = client;
|
|
19002
|
+
this.program = program;
|
|
19003
|
+
this.args = args;
|
|
19004
|
+
this.keys = keys ?? {
|
|
19005
|
+
serverKey: client.serverKey,
|
|
19006
|
+
userKey: client.userKey,
|
|
19007
|
+
emulatorKey: client.emulatorKey
|
|
19008
|
+
};
|
|
19009
|
+
this.vtxoScript = new chunkRQSA7ADZ_cjs.ArkadeProgramScript(program, args, this.keys);
|
|
19010
|
+
this.tapTree = this.vtxoScript.encode();
|
|
19011
|
+
this.compiled = this.vtxoScript.compiled;
|
|
19012
|
+
}
|
|
19013
|
+
client;
|
|
19014
|
+
program;
|
|
19015
|
+
args;
|
|
19016
|
+
/** The compiled taproot tree of spending-path leaves. */
|
|
19017
|
+
vtxoScript;
|
|
19018
|
+
/** Encoded taproot tree (shared spend context for every path). */
|
|
19019
|
+
tapTree;
|
|
19020
|
+
/** The signer keys the program was compiled against. */
|
|
19021
|
+
keys;
|
|
19022
|
+
/** Spending paths in declaration order. */
|
|
19023
|
+
compiled;
|
|
19024
|
+
/**
|
|
19025
|
+
* Rebuild a callable contract from a persisted `"arkade"` contract row
|
|
19026
|
+
* (see {@link ArkadeContract.register}). The stored keys are used for
|
|
19027
|
+
* compilation — not the client's current ones — so the derived script and
|
|
19028
|
+
* address stay identical to the registered contract even after a server
|
|
19029
|
+
* signer rotation.
|
|
19030
|
+
*/
|
|
19031
|
+
static fromContract(client, contract) {
|
|
19032
|
+
if (contract.type !== "arkade") {
|
|
19033
|
+
throw new Error(
|
|
19034
|
+
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
19035
|
+
);
|
|
19036
|
+
}
|
|
19037
|
+
const typed = chunkRQSA7ADZ_cjs.deserializeArkadeContractParams(contract.params);
|
|
19038
|
+
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
19039
|
+
serverKey: typed.serverKey,
|
|
19040
|
+
userKey: typed.userKey,
|
|
19041
|
+
emulatorKey: typed.emulatorKey
|
|
19042
|
+
});
|
|
19043
|
+
}
|
|
19044
|
+
/** Resolve the {@link TapLeafScript} for a spending path by its index. */
|
|
19045
|
+
leafScript(index) {
|
|
19046
|
+
const fn = this.compiled[index];
|
|
19047
|
+
if (!fn) throw new Error(`leaf index ${index} out of range`);
|
|
19048
|
+
return fn.tapLeafScript;
|
|
19049
|
+
}
|
|
19050
|
+
/** Arkade funding address. */
|
|
19051
|
+
get address() {
|
|
19052
|
+
return this.vtxoScript.address(this.client.network.hrp, this.keys.serverKey).encode();
|
|
19053
|
+
}
|
|
19054
|
+
/** Taproot output script. */
|
|
19055
|
+
get pkScript() {
|
|
19056
|
+
return this.vtxoScript.pkScript;
|
|
19057
|
+
}
|
|
19058
|
+
/**
|
|
19059
|
+
* Callable spending paths: `contract.functions.<name>(...args)`. Strongly
|
|
19060
|
+
* typed from the program's literal type — each function's argument types are
|
|
19061
|
+
* derived from its `inputs` descriptors (see {@link ContractFunctions}).
|
|
19062
|
+
*/
|
|
19063
|
+
get functions() {
|
|
19064
|
+
const out = {};
|
|
19065
|
+
for (const fn of this.compiled) {
|
|
19066
|
+
out[fn.name] = (...callArgs) => new ArkadeTransactionBuilder(this, fn, bindInputs(fn, callArgs));
|
|
19067
|
+
}
|
|
19068
|
+
return out;
|
|
19069
|
+
}
|
|
19070
|
+
/**
|
|
19071
|
+
* The `createContract` payload for this contract — the serialized program,
|
|
19072
|
+
* args and keys plus the derived script/address. Useful when registering
|
|
19073
|
+
* through a manager the client does not hold.
|
|
19074
|
+
*/
|
|
19075
|
+
toContractParams() {
|
|
19076
|
+
return {
|
|
19077
|
+
type: "arkade",
|
|
19078
|
+
params: chunkRQSA7ADZ_cjs.serializeArkadeContractParams({
|
|
19079
|
+
program: this.program,
|
|
19080
|
+
args: this.args,
|
|
19081
|
+
serverKey: this.keys.serverKey,
|
|
19082
|
+
userKey: this.keys.userKey,
|
|
19083
|
+
emulatorKey: this.keys.emulatorKey
|
|
19084
|
+
}),
|
|
19085
|
+
script: base.hex.encode(this.pkScript),
|
|
19086
|
+
address: this.address
|
|
19087
|
+
};
|
|
19088
|
+
}
|
|
19089
|
+
/**
|
|
19090
|
+
* Persist this contract through the wallet's {@link IContractManager} so it
|
|
19091
|
+
* is tracked like any other contract type: stored in the contract
|
|
19092
|
+
* repository, watched for VTXO events, counted in repository-backed
|
|
19093
|
+
* balances, and re-derivable offline via the `"arkade"` contract handler.
|
|
19094
|
+
* Idempotent — re-registering the same script is a no-op.
|
|
19095
|
+
*/
|
|
19096
|
+
async register(options) {
|
|
19097
|
+
const manager = this.client.contractManager;
|
|
19098
|
+
if (!manager) {
|
|
19099
|
+
throw new Error(
|
|
19100
|
+
"ArkadeContract.register requires a `contractManager` on the Arkade client \u2014 pass one to Arkade.connect"
|
|
19101
|
+
);
|
|
19102
|
+
}
|
|
19103
|
+
return manager.createContract({
|
|
19104
|
+
...this.toContractParams(),
|
|
19105
|
+
label: options?.label,
|
|
19106
|
+
metadata: options?.metadata
|
|
19107
|
+
});
|
|
19108
|
+
}
|
|
19109
|
+
/**
|
|
19110
|
+
* Spendable VTXOs locked by this contract.
|
|
19111
|
+
*
|
|
19112
|
+
* When a `contractManager` is configured and this contract is registered,
|
|
19113
|
+
* reads the repository-backed state (offline-first, kept fresh by the
|
|
19114
|
+
* contract watcher). Otherwise falls back to a direct indexer query.
|
|
19115
|
+
*/
|
|
19116
|
+
async getUtxos() {
|
|
19117
|
+
const manager = this.client.contractManager;
|
|
19118
|
+
const scriptHex = base.hex.encode(this.pkScript);
|
|
19119
|
+
if (manager) {
|
|
19120
|
+
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
19121
|
+
if (registered) {
|
|
19122
|
+
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
19123
|
+
return (withVtxos?.vtxos ?? []).filter(isSpendable);
|
|
19124
|
+
}
|
|
19125
|
+
}
|
|
19126
|
+
if (!this.client.indexer) {
|
|
19127
|
+
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
19128
|
+
}
|
|
19129
|
+
const { vtxos } = await this.client.indexer.getVtxos({
|
|
19130
|
+
scripts: [scriptHex],
|
|
19131
|
+
spendableOnly: true
|
|
19132
|
+
});
|
|
19133
|
+
return vtxos;
|
|
19134
|
+
}
|
|
19135
|
+
/** Total spendable balance (requires an indexer). */
|
|
19136
|
+
async getBalance() {
|
|
19137
|
+
const utxos = await this.getUtxos();
|
|
19138
|
+
return utxos.reduce((sum, u) => sum + BigInt(u.value), 0n);
|
|
19139
|
+
}
|
|
19140
|
+
};
|
|
19141
|
+
var ArkadeTransactionBuilder = class {
|
|
19142
|
+
/** @internal */
|
|
19143
|
+
constructor(contract, fn, args) {
|
|
19144
|
+
this.contract = contract;
|
|
19145
|
+
this.fn = fn;
|
|
19146
|
+
this.args = args;
|
|
19147
|
+
}
|
|
19148
|
+
contract;
|
|
19149
|
+
fn;
|
|
19150
|
+
args;
|
|
19151
|
+
outputs = [];
|
|
19152
|
+
fundingCoins = [];
|
|
19153
|
+
assetSpecs = [];
|
|
19154
|
+
coin;
|
|
19155
|
+
changeScript;
|
|
19156
|
+
from(coin) {
|
|
19157
|
+
this.coin = coin;
|
|
19158
|
+
return this;
|
|
19159
|
+
}
|
|
19160
|
+
/**
|
|
19161
|
+
* Add extra inputs the caller funds (e.g. a taker's own coins in a swap).
|
|
19162
|
+
* These become inputs 1..n and are signed with the client identity.
|
|
19163
|
+
*/
|
|
19164
|
+
fund(coins) {
|
|
19165
|
+
this.fundingCoins.push(...coins);
|
|
19166
|
+
return this;
|
|
19167
|
+
}
|
|
19168
|
+
/** Transfer an asset group: which inputs supply it and which outputs receive it. */
|
|
19169
|
+
withAsset(spec) {
|
|
19170
|
+
this.assetSpecs.push(spec);
|
|
19171
|
+
return this;
|
|
19172
|
+
}
|
|
19173
|
+
/** Destination for any surplus (inputs − outputs). Required when the spend is not exact. */
|
|
19174
|
+
change(script) {
|
|
19175
|
+
this.changeScript = script;
|
|
19176
|
+
return this;
|
|
19177
|
+
}
|
|
19178
|
+
to(scriptOrOutputs, amount) {
|
|
19179
|
+
if (Array.isArray(scriptOrOutputs)) {
|
|
19180
|
+
for (const [i, out] of scriptOrOutputs.entries()) {
|
|
19181
|
+
if (out.amount === void 0) {
|
|
19182
|
+
throw new Error(`to(outputs): output ${i} is missing an amount`);
|
|
19183
|
+
}
|
|
19184
|
+
}
|
|
19185
|
+
this.outputs.push(...scriptOrOutputs);
|
|
19186
|
+
} else {
|
|
19187
|
+
if (amount === void 0) throw new Error("to(script, amount): amount is required");
|
|
19188
|
+
this.outputs.push({ script: scriptOrOutputs, amount });
|
|
19189
|
+
}
|
|
19190
|
+
return this;
|
|
19191
|
+
}
|
|
19192
|
+
/** Assemble the unsigned ark transaction and its checkpoints. */
|
|
19193
|
+
async build() {
|
|
19194
|
+
if (this.outputs.length === 0) {
|
|
19195
|
+
throw new Error("ArkadeTransactionBuilder: at least one output is required");
|
|
19196
|
+
}
|
|
19197
|
+
const outputsSum = this.outputs.reduce((s, o) => s + (o.amount ?? 0n), 0n);
|
|
19198
|
+
const coin = this.coin ?? await this.selectCoin(outputsSum);
|
|
19199
|
+
const def = this.fn.def;
|
|
19200
|
+
const outputs = [...this.outputs];
|
|
19201
|
+
const fundingSum = this.fundingCoins.reduce((s, f) => s + BigInt(f.value), 0n);
|
|
19202
|
+
const surplus = BigInt(coin.value) + fundingSum - outputsSum;
|
|
19203
|
+
if (surplus < 0n) {
|
|
19204
|
+
throw new Error(
|
|
19205
|
+
`ArkadeTransactionBuilder: insufficient inputs \u2014 outputs ${outputsSum} exceed inputs ${BigInt(coin.value) + fundingSum}`
|
|
19206
|
+
);
|
|
19207
|
+
}
|
|
19208
|
+
if (surplus > 0n) {
|
|
19209
|
+
if (!this.changeScript) {
|
|
19210
|
+
throw new Error(
|
|
19211
|
+
`ArkadeTransactionBuilder: ${surplus} sats surplus with no change output \u2014 call .change(script)`
|
|
19212
|
+
);
|
|
19213
|
+
}
|
|
19214
|
+
outputs.push({ script: this.changeScript, amount: surplus });
|
|
19215
|
+
}
|
|
19216
|
+
const { arkTx, checkpoints } = buildOffchainTx(
|
|
19217
|
+
[
|
|
19218
|
+
{
|
|
19219
|
+
txid: coin.txid,
|
|
19220
|
+
vout: coin.vout,
|
|
19221
|
+
value: coin.value,
|
|
19222
|
+
tapLeafScript: this.fn.tapLeafScript,
|
|
19223
|
+
tapTree: this.contract.tapTree
|
|
19224
|
+
},
|
|
19225
|
+
...this.fundingCoins
|
|
19226
|
+
],
|
|
19227
|
+
outputs,
|
|
19228
|
+
this.contract.client.checkpoint
|
|
19229
|
+
);
|
|
19230
|
+
if (coin.sourceTx) {
|
|
19231
|
+
chunkHHV5FPC6_cjs.setArkPsbtField(arkTx, 0, chunkHHV5FPC6_cjs.PrevArkTxField, coin.sourceTx);
|
|
19232
|
+
}
|
|
19233
|
+
const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19234
|
+
if (condition.length > 0) {
|
|
19235
|
+
chunkHHV5FPC6_cjs.setArkPsbtField(arkTx, 0, chunkHHV5FPC6_cjs.ConditionWitness, condition);
|
|
19236
|
+
chunkHHV5FPC6_cjs.setArkPsbtField(checkpoints[0], 0, chunkHHV5FPC6_cjs.ConditionWitness, condition);
|
|
19237
|
+
}
|
|
19238
|
+
const packets = [];
|
|
19239
|
+
if (this.assetSpecs.length > 0) {
|
|
19240
|
+
packets.push(this.buildAssetPacket());
|
|
19241
|
+
}
|
|
19242
|
+
const arkadeScript = this.fn.arkadeScript;
|
|
19243
|
+
if (arkadeScript) {
|
|
19244
|
+
const stack = (def.arkadeScript?.witness ?? []).map((w) => this.witnessBytes(w));
|
|
19245
|
+
packets.push(
|
|
19246
|
+
EmulatorPacket.create([
|
|
19247
|
+
{ vin: 0, script: arkadeScript, witness: btcSigner.RawWitness.encode(stack) }
|
|
19248
|
+
])
|
|
19249
|
+
);
|
|
19250
|
+
}
|
|
19251
|
+
if (packets.length > 0) {
|
|
19252
|
+
attachExtension(arkTx, packets);
|
|
19253
|
+
}
|
|
19254
|
+
return { arkTx, checkpoints };
|
|
19255
|
+
}
|
|
19256
|
+
/** Build, submit and return the finalized transaction. */
|
|
19257
|
+
async send() {
|
|
19258
|
+
const { arkTx, checkpoints } = await this.build();
|
|
19259
|
+
const client = this.contract.client;
|
|
19260
|
+
const userInputs = this.userInputIndexes();
|
|
19261
|
+
if (this.fn.arkadeScript) {
|
|
19262
|
+
if (!client.emulator) {
|
|
19263
|
+
throw new Error("covenant spends require an `emulator` on the Arkade client");
|
|
19264
|
+
}
|
|
19265
|
+
const signedArk2 = await this.signArk(arkTx, userInputs);
|
|
19266
|
+
const signedCps = userInputs.length > 0 ? await Promise.all(
|
|
19267
|
+
checkpoints.map(
|
|
19268
|
+
(c, i) => userInputs.includes(i) ? client.identity.sign(c, [0]) : c
|
|
19269
|
+
)
|
|
19270
|
+
) : checkpoints;
|
|
19271
|
+
const res2 = await client.emulator.submitTx(
|
|
19272
|
+
base.base64.encode(signedArk2.toPSBT()),
|
|
19273
|
+
signedCps.map((c) => base.base64.encode(c.toPSBT()))
|
|
19274
|
+
);
|
|
19275
|
+
const txid = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
|
|
19276
|
+
return {
|
|
19277
|
+
txid,
|
|
19278
|
+
signedArkTx: res2.signedArkTx,
|
|
19279
|
+
signedCheckpointTxs: res2.signedCheckpointTxs
|
|
19280
|
+
};
|
|
19281
|
+
}
|
|
19282
|
+
if (!client.identity) {
|
|
19283
|
+
throw new Error("a signing identity is required for non-covenant spends");
|
|
19284
|
+
}
|
|
19285
|
+
const signedArk = await this.signArk(arkTx, userInputs);
|
|
19286
|
+
const res = await client.arkProvider.submitTx(
|
|
19287
|
+
base.base64.encode(signedArk.toPSBT()),
|
|
19288
|
+
checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
19289
|
+
);
|
|
19290
|
+
const finalCps = await Promise.all(
|
|
19291
|
+
res.signedCheckpointTxs.map(
|
|
19292
|
+
async (b) => base.base64.encode(
|
|
19293
|
+
(await client.identity.sign(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(b)), [0])).toPSBT()
|
|
19294
|
+
)
|
|
19295
|
+
)
|
|
19296
|
+
);
|
|
19297
|
+
await client.arkProvider.finalizeTx(res.arkTxid, finalCps);
|
|
19298
|
+
return {
|
|
19299
|
+
txid: res.arkTxid,
|
|
19300
|
+
signedArkTx: res.finalArkTx,
|
|
19301
|
+
signedCheckpointTxs: res.signedCheckpointTxs
|
|
19302
|
+
};
|
|
19303
|
+
}
|
|
19304
|
+
/** Sign the client-owned inputs of the ark tx (no-op when there are none). */
|
|
19305
|
+
async signArk(arkTx, userInputs) {
|
|
19306
|
+
if (userInputs.length === 0) return arkTx;
|
|
19307
|
+
const { identity } = this.contract.client;
|
|
19308
|
+
if (!identity) {
|
|
19309
|
+
throw new Error("this spend requires an `identity` to sign its user/funding inputs");
|
|
19310
|
+
}
|
|
19311
|
+
return identity.sign(arkTx, userInputs);
|
|
19312
|
+
}
|
|
19313
|
+
/** Indexes of inputs the client owns and must sign (contract input + funded inputs). */
|
|
19314
|
+
userInputIndexes() {
|
|
19315
|
+
const idxs = [];
|
|
19316
|
+
const userKey = this.contract.keys.userKey;
|
|
19317
|
+
if (userKey && this.fn.signerKeys.some((k) => utils_js.equalBytes(k, userKey))) {
|
|
19318
|
+
idxs.push(0);
|
|
19319
|
+
}
|
|
19320
|
+
for (let i = 0; i < this.fundingCoins.length; i++) {
|
|
19321
|
+
idxs.push(i + 1);
|
|
19322
|
+
}
|
|
19323
|
+
return idxs;
|
|
19324
|
+
}
|
|
19325
|
+
async selectCoin(amount) {
|
|
19326
|
+
const utxos = await this.contract.getUtxos();
|
|
19327
|
+
if (utxos.length === 0) throw new Error("no spendable coins for this contract");
|
|
19328
|
+
const covering = utxos.filter((u) => BigInt(u.value) >= amount).sort((a, b) => a.value - b.value);
|
|
19329
|
+
if (covering.length > 0) return covering[0];
|
|
19330
|
+
return [...utxos].sort((a, b) => b.value - a.value)[0];
|
|
19331
|
+
}
|
|
19332
|
+
buildAssetPacket() {
|
|
19333
|
+
const groups = this.assetSpecs.map((s) => {
|
|
19334
|
+
const id = typeof s.assetId === "string" ? chunkHHV5FPC6_cjs.AssetId.fromString(s.assetId) : chunkHHV5FPC6_cjs.AssetId.fromBytes(s.assetId);
|
|
19335
|
+
return chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
19336
|
+
id,
|
|
19337
|
+
null,
|
|
19338
|
+
s.inputs.map((i) => chunkHHV5FPC6_cjs.AssetInput.create(i.vin, i.amount)),
|
|
19339
|
+
s.outputs.map((o) => chunkHHV5FPC6_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
19340
|
+
(s.metadata ?? []).map((m) => chunkHHV5FPC6_cjs.Metadata.create(m.key, m.value))
|
|
19341
|
+
);
|
|
19342
|
+
});
|
|
19343
|
+
return chunkHHV5FPC6_cjs.Packet.create(groups);
|
|
19344
|
+
}
|
|
19345
|
+
witnessBytes(ref) {
|
|
19346
|
+
return chunkRQSA7ADZ_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
|
|
19347
|
+
}
|
|
19348
|
+
};
|
|
19349
|
+
function bindInputs(fn, callArgs) {
|
|
19350
|
+
const names = (fn.def.inputs ?? []).map(chunkRQSA7ADZ_cjs.inputName);
|
|
19351
|
+
if (callArgs.length !== names.length) {
|
|
19352
|
+
throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
|
|
19353
|
+
}
|
|
19354
|
+
const bound = {};
|
|
19355
|
+
names.forEach((n, i) => bound[n] = callArgs[i]);
|
|
19356
|
+
return bound;
|
|
19357
|
+
}
|
|
19358
|
+
function attachExtension(tx, newPackets) {
|
|
19359
|
+
for (let i = 0; i < tx.outputsLength; i++) {
|
|
19360
|
+
const out = tx.getOutput(i);
|
|
19361
|
+
if (!out?.script || !Extension.isExtension(out.script)) continue;
|
|
19362
|
+
const existing = Extension.fromBytes(out.script);
|
|
19363
|
+
const merged = Extension.create([...existing.getPackets(), ...newPackets]);
|
|
19364
|
+
tx.updateOutput(i, { script: merged.serialize(), amount: 0n });
|
|
19365
|
+
return;
|
|
19366
|
+
}
|
|
19367
|
+
const ext = Extension.create(newPackets);
|
|
19368
|
+
const newOut = ext.txOut();
|
|
19369
|
+
const lastIdx = tx.outputsLength - 1;
|
|
19370
|
+
const lastOut = tx.getOutput(lastIdx);
|
|
19371
|
+
if (lastOut?.script && lastOut.script.length === ANCHOR_PKSCRIPT.length && lastOut.script.every((b, j) => b === ANCHOR_PKSCRIPT[j])) {
|
|
19372
|
+
tx.updateOutput(lastIdx, { script: newOut.script, amount: newOut.amount });
|
|
19373
|
+
tx.addOutput({ script: lastOut.script, amount: lastOut.amount ?? 0n });
|
|
19374
|
+
return;
|
|
19375
|
+
}
|
|
19376
|
+
tx.addOutput({ script: newOut.script, amount: newOut.amount });
|
|
19377
|
+
}
|
|
18466
19378
|
var ARKCONTRACT_PREFIX = "arkcontract";
|
|
18467
19379
|
function encodeArkContract(contract) {
|
|
18468
19380
|
const params = new URLSearchParams();
|
|
@@ -18488,7 +19400,7 @@ function decodeArkContract(encoded) {
|
|
|
18488
19400
|
}
|
|
18489
19401
|
function contractFromArkContract(encoded, options = {}) {
|
|
18490
19402
|
const parsed = decodeArkContract(encoded);
|
|
18491
|
-
const handler =
|
|
19403
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(parsed.type);
|
|
18492
19404
|
if (!handler) {
|
|
18493
19405
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
18494
19406
|
}
|
|
@@ -18502,9 +19414,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
18502
19414
|
metadata: options.metadata
|
|
18503
19415
|
};
|
|
18504
19416
|
}
|
|
18505
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
19417
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkL5ND2FJJ_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
18506
19418
|
const parsed = decodeArkContract(encoded);
|
|
18507
|
-
const handler =
|
|
19419
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
18508
19420
|
const params = parsed.data;
|
|
18509
19421
|
const vtxoScript = handler.createScript(params);
|
|
18510
19422
|
return {
|
|
@@ -18522,6 +19434,7 @@ function isArkContract(str) {
|
|
|
18522
19434
|
return str.startsWith(ARKCONTRACT_PREFIX + "=");
|
|
18523
19435
|
}
|
|
18524
19436
|
|
|
19437
|
+
exports.ARKADE_MAGIC = ARKADE_MAGIC;
|
|
18525
19438
|
exports.ActivityRegistry = ActivityRegistry;
|
|
18526
19439
|
exports.ArkNote = ArkNote;
|
|
18527
19440
|
exports.AssetManager = AssetManager;
|
|
@@ -18541,8 +19454,11 @@ exports.ELECTRUM_TCP_HOST = ELECTRUM_TCP_HOST;
|
|
|
18541
19454
|
exports.ELECTRUM_WS_URL = ELECTRUM_WS_URL;
|
|
18542
19455
|
exports.ESPLORA_URL = ESPLORA_URL;
|
|
18543
19456
|
exports.ElectrumOnchainProvider = ElectrumOnchainProvider;
|
|
19457
|
+
exports.EmulatorPacket = EmulatorPacket;
|
|
18544
19458
|
exports.EsploraProvider = EsploraProvider;
|
|
18545
19459
|
exports.Estimator = Estimator;
|
|
19460
|
+
exports.Extension = Extension;
|
|
19461
|
+
exports.ExtensionNotFoundError = ExtensionNotFoundError;
|
|
18546
19462
|
exports.HDDescriptorProvider = HDDescriptorProvider;
|
|
18547
19463
|
exports.INTENT_TERMINAL_STATES = INTENT_TERMINAL_STATES;
|
|
18548
19464
|
exports.InMemoryContractRepository = InMemoryContractRepository;
|
|
@@ -18571,6 +19487,7 @@ exports.ReadonlyWallet = ReadonlyWallet;
|
|
|
18571
19487
|
exports.ReadonlyWalletError = ReadonlyWalletError;
|
|
18572
19488
|
exports.RestDelegateProvider = RestDelegateProvider;
|
|
18573
19489
|
exports.RestDelegatorProvider = RestDelegatorProvider;
|
|
19490
|
+
exports.RestEmulatorProvider = RestEmulatorProvider;
|
|
18574
19491
|
exports.SeedIdentity = SeedIdentity;
|
|
18575
19492
|
exports.ServiceWorkerReadonlyWallet = ServiceWorkerReadonlyWallet;
|
|
18576
19493
|
exports.ServiceWorkerTimeoutError = ServiceWorkerTimeoutError;
|
|
@@ -18580,12 +19497,14 @@ exports.TxTree = TxTree;
|
|
|
18580
19497
|
exports.TxType = TxType;
|
|
18581
19498
|
exports.TxWeightEstimator = TxWeightEstimator;
|
|
18582
19499
|
exports.UnilateralExit = UnilateralExit;
|
|
19500
|
+
exports.UnknownPacket = UnknownPacket;
|
|
18583
19501
|
exports.VtxoManager = VtxoManager;
|
|
18584
19502
|
exports.Wallet = Wallet2;
|
|
18585
19503
|
exports.WalletMessageHandler = WalletMessageHandler;
|
|
18586
19504
|
exports.WalletNotInitializedError = WalletNotInitializedError;
|
|
18587
19505
|
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
|
18588
19506
|
exports.WsElectrumChainSource = WsElectrumChainSource;
|
|
19507
|
+
exports.arkade_exports = arkade_exports;
|
|
18589
19508
|
exports.assertIntentIdUnique = assertIntentIdUnique;
|
|
18590
19509
|
exports.boardingResolver = boardingResolver;
|
|
18591
19510
|
exports.buildForfeitTx = buildForfeitTx;
|
|
@@ -18596,6 +19515,7 @@ exports.closeDatabase = closeDatabase;
|
|
|
18596
19515
|
exports.combineTapscriptSigs = combineTapscriptSigs;
|
|
18597
19516
|
exports.contractFromArkContract = contractFromArkContract;
|
|
18598
19517
|
exports.contractFromArkContractWithAddress = contractFromArkContractWithAddress;
|
|
19518
|
+
exports.createAssetPacket = createAssetPacket;
|
|
18599
19519
|
exports.createDefaultActivityRegistry = createDefaultActivityRegistry;
|
|
18600
19520
|
exports.createExitChainResolver = createExitChainResolver;
|
|
18601
19521
|
exports.decodeArkContract = decodeArkContract;
|
|
@@ -18630,6 +19550,8 @@ exports.requiresMigration = requiresMigration;
|
|
|
18630
19550
|
exports.rollbackMigration = rollbackMigration;
|
|
18631
19551
|
exports.saveVtxosForContract = saveVtxosForContract;
|
|
18632
19552
|
exports.scriptFromArkAddress = scriptFromArkAddress;
|
|
19553
|
+
exports.selectCoinsWithAsset = selectCoinsWithAsset;
|
|
19554
|
+
exports.selectVirtualCoins = selectVirtualCoins;
|
|
18633
19555
|
exports.serializeAssets = serializeAssets;
|
|
18634
19556
|
exports.serializeExitPackage = serializeExitPackage;
|
|
18635
19557
|
exports.serializeUtxo = serializeUtxo;
|
|
@@ -18642,5 +19564,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
18642
19564
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
18643
19565
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
18644
19566
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
18645
|
-
//# sourceMappingURL=chunk-
|
|
18646
|
-
//# sourceMappingURL=chunk-
|
|
19567
|
+
//# sourceMappingURL=chunk-WTTLIFS7.cjs.map
|
|
19568
|
+
//# sourceMappingURL=chunk-WTTLIFS7.cjs.map
|