@arkade-os/sdk 0.4.45 → 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-C-PjOngm.d.cts → ark-CoJgwTi_.d.cts} +31 -3
- package/dist/{ark-C-PjOngm.d.ts → ark-CoJgwTi_.d.ts} +31 -3
- package/dist/{asyncStorageTaskQueue-BmBPvTyh.d.cts → asyncStorageTaskQueue-Dowyo59a.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-CHpI3moJ.d.ts → asyncStorageTaskQueue-Z3aFoXCl.d.ts} +2 -2
- package/dist/{chunk-QZ6HZZZK.js → chunk-3N5I6GT6.js} +3 -3
- package/dist/{chunk-QZ6HZZZK.js.map → chunk-3N5I6GT6.js.map} +1 -1
- package/dist/{chunk-BOA4SHCD.js → chunk-AJQ4AOT3.js} +4 -4
- package/dist/{chunk-BOA4SHCD.js.map → chunk-AJQ4AOT3.js.map} +1 -1
- package/dist/{chunk-BE5MUB7T.js → chunk-C7TXXTMS.js} +9 -5
- package/dist/chunk-C7TXXTMS.js.map +1 -0
- package/dist/{chunk-YBQV7XBC.js → chunk-CDDWXBEM.js} +139 -21
- package/dist/chunk-CDDWXBEM.js.map +1 -0
- package/dist/{chunk-UHOHLN3C.cjs → chunk-HHV5FPC6.cjs} +148 -25
- package/dist/chunk-HHV5FPC6.cjs.map +1 -0
- package/dist/{chunk-HZ7VIN7P.cjs → chunk-JAYOXOLT.cjs} +14 -14
- package/dist/{chunk-HZ7VIN7P.cjs.map → chunk-JAYOXOLT.cjs.map} +1 -1
- package/dist/{chunk-HXDZ2QTW.cjs → chunk-L5ND2FJJ.cjs} +9 -5
- package/dist/chunk-L5ND2FJJ.cjs.map +1 -0
- package/dist/{chunk-TGRJ5WAX.js → chunk-OCS5S3L3.js} +1085 -103
- 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-OFQGANH2.cjs → chunk-VE67GMGM.cjs} +7 -7
- package/dist/{chunk-OFQGANH2.cjs.map → chunk-VE67GMGM.cjs.map} +1 -1
- package/dist/{chunk-SRCWBFSZ.cjs → chunk-WTTLIFS7.cjs} +1281 -289
- 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-BKNqva1j.d.ts → delegate-CuaDqqQi.d.ts} +1 -1
- package/dist/{delegate-DOEobYwH.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 +219 -159
- 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 +23 -19
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +9 -5
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +22 -18
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +9 -5
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-BngWSFMi.d.ts → taskRunner-Dz-TI4Rb.d.ts} +2 -2
- package/dist/{taskRunner-DOiyRuJa.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 +18 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +9 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-DBjumS42.d.cts → wallet-Oxz_wLxo.d.cts} +47 -3
- package/dist/{wallet-B3awP1Nj.d.ts → wallet-x7egmXq6.d.ts} +47 -3
- package/dist/worker/expo/index.cjs +10 -9
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +6 -5
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-32YKLQPS.cjs +0 -970
- package/dist/chunk-32YKLQPS.cjs.map +0 -1
- package/dist/chunk-BE5MUB7T.js.map +0 -1
- package/dist/chunk-HXDZ2QTW.cjs.map +0 -1
- package/dist/chunk-SRCWBFSZ.cjs.map +0 -1
- package/dist/chunk-TGRJ5WAX.js.map +0 -1
- package/dist/chunk-UHOHLN3C.cjs.map +0 -1
- package/dist/chunk-YBQV7XBC.js.map +0 -1
- package/dist/chunk-YNEDJTX2.js +0 -957
- package/dist/chunk-YNEDJTX2.js.map +0 -1
- package/dist/index-BlW4I30l.d.cts +0 -259
- package/dist/index-Cm2fGeox.d.ts +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');
|
|
@@ -84,6 +85,8 @@ var PartialSig = class _PartialSig {
|
|
|
84
85
|
throw new PartialSignatureError("Invalid R length");
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
s;
|
|
89
|
+
R;
|
|
87
90
|
/**
|
|
88
91
|
* Encodes the partial signature into bytes
|
|
89
92
|
* Returns a 32-byte array containing just the s value
|
|
@@ -133,6 +136,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
133
136
|
constructor(secretKey) {
|
|
134
137
|
this.secretKey = secretKey;
|
|
135
138
|
}
|
|
139
|
+
secretKey;
|
|
136
140
|
static NOT_INITIALIZED = new Error("session not initialized, call init method");
|
|
137
141
|
myNonces = null;
|
|
138
142
|
aggregateNonces = null;
|
|
@@ -181,7 +185,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
181
185
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
182
186
|
const tx = this.graph.find(txid);
|
|
183
187
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
184
|
-
const cosigners =
|
|
188
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(tx.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey).map(
|
|
185
189
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
186
190
|
// xonly pubkey
|
|
187
191
|
);
|
|
@@ -233,7 +237,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
233
237
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
234
238
|
const prevoutAmounts = [];
|
|
235
239
|
const prevoutScripts = [];
|
|
236
|
-
const cosigners =
|
|
240
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(g.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey).map((c) => c.key);
|
|
237
241
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
238
242
|
taprootTweak: this.scriptRoot
|
|
239
243
|
});
|
|
@@ -359,6 +363,7 @@ var ReadonlySingleKey = class _ReadonlySingleKey {
|
|
|
359
363
|
throw new Error("Invalid public key length");
|
|
360
364
|
}
|
|
361
365
|
}
|
|
366
|
+
publicKey;
|
|
362
367
|
/**
|
|
363
368
|
* Create a ReadonlySingleKey from a compressed public key.
|
|
364
369
|
*
|
|
@@ -411,7 +416,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
411
416
|
let network;
|
|
412
417
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
413
418
|
descriptor = opts.descriptor;
|
|
414
|
-
network =
|
|
419
|
+
network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
415
420
|
} else {
|
|
416
421
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
417
422
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -496,7 +501,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
496
501
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
497
502
|
*/
|
|
498
503
|
isOurs(descriptor) {
|
|
499
|
-
return
|
|
504
|
+
return chunkRQSA7ADZ_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
500
505
|
}
|
|
501
506
|
/**
|
|
502
507
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -533,7 +538,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
533
538
|
}
|
|
534
539
|
// ── internal helpers ─────────────────────────────────────────────
|
|
535
540
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
536
|
-
const network =
|
|
541
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
537
542
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
538
543
|
if (expansion.isRanged) {
|
|
539
544
|
throw new Error(
|
|
@@ -619,7 +624,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
619
624
|
*/
|
|
620
625
|
descriptor;
|
|
621
626
|
constructor(descriptor) {
|
|
622
|
-
const network =
|
|
627
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
623
628
|
let expansion;
|
|
624
629
|
try {
|
|
625
630
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -669,7 +674,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
669
674
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
670
675
|
*/
|
|
671
676
|
isOurs(descriptor) {
|
|
672
|
-
return
|
|
677
|
+
return chunkRQSA7ADZ_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
673
678
|
}
|
|
674
679
|
};
|
|
675
680
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -970,6 +975,7 @@ var RestDelegateProvider = class {
|
|
|
970
975
|
constructor(url) {
|
|
971
976
|
this.url = url;
|
|
972
977
|
}
|
|
978
|
+
url;
|
|
973
979
|
/**
|
|
974
980
|
* Submit a delegation request to the remote delegation service.
|
|
975
981
|
*
|
|
@@ -980,14 +986,14 @@ var RestDelegateProvider = class {
|
|
|
980
986
|
*/
|
|
981
987
|
async delegate(intent, forfeitTxs, options) {
|
|
982
988
|
const url = `${this.url}/v1/delegate`;
|
|
983
|
-
const response = await
|
|
989
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(url, {
|
|
984
990
|
method: "POST",
|
|
985
991
|
headers: {
|
|
986
992
|
"Content-Type": "application/json"
|
|
987
993
|
},
|
|
988
994
|
body: JSON.stringify({
|
|
989
995
|
intent: {
|
|
990
|
-
message:
|
|
996
|
+
message: chunkHHV5FPC6_cjs.Intent.encodeMessage(intent.message),
|
|
991
997
|
proof: intent.proof
|
|
992
998
|
},
|
|
993
999
|
forfeit_txs: forfeitTxs,
|
|
@@ -1007,7 +1013,7 @@ var RestDelegateProvider = class {
|
|
|
1007
1013
|
*/
|
|
1008
1014
|
async getDelegateInfo() {
|
|
1009
1015
|
const url = `${this.url}/v1/delegator/info`;
|
|
1010
|
-
const response = await
|
|
1016
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(url);
|
|
1011
1017
|
if (!response.ok) {
|
|
1012
1018
|
const errorText2 = await response.text();
|
|
1013
1019
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1034,22 +1040,23 @@ var ESPLORA_URL = {
|
|
|
1034
1040
|
regtest: "http://localhost:3000/api"
|
|
1035
1041
|
};
|
|
1036
1042
|
var EsploraProvider = class {
|
|
1037
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1043
|
+
constructor(baseUrl = ESPLORA_URL[chunkL5ND2FJJ_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1038
1044
|
this.baseUrl = baseUrl;
|
|
1039
1045
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1040
1046
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
1041
1047
|
}
|
|
1048
|
+
baseUrl;
|
|
1042
1049
|
pollingInterval;
|
|
1043
1050
|
forcePolling;
|
|
1044
1051
|
async getCoins(address) {
|
|
1045
|
-
const response = await
|
|
1052
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1046
1053
|
if (!response.ok) {
|
|
1047
1054
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1048
1055
|
}
|
|
1049
1056
|
return response.json();
|
|
1050
1057
|
}
|
|
1051
1058
|
async getFeeRate() {
|
|
1052
|
-
const response = await
|
|
1059
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
|
|
1053
1060
|
if (response.status === 404) {
|
|
1054
1061
|
return void 0;
|
|
1055
1062
|
}
|
|
@@ -1070,7 +1077,7 @@ var EsploraProvider = class {
|
|
|
1070
1077
|
}
|
|
1071
1078
|
}
|
|
1072
1079
|
async getTxOutspends(txid) {
|
|
1073
|
-
const response = await
|
|
1080
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1074
1081
|
if (!response.ok) {
|
|
1075
1082
|
const error = await response.text();
|
|
1076
1083
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1078,7 +1085,7 @@ var EsploraProvider = class {
|
|
|
1078
1085
|
return response.json();
|
|
1079
1086
|
}
|
|
1080
1087
|
async getTransactions(address) {
|
|
1081
|
-
const response = await
|
|
1088
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1082
1089
|
if (!response.ok) {
|
|
1083
1090
|
const error = await response.text();
|
|
1084
1091
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1086,7 +1093,7 @@ var EsploraProvider = class {
|
|
|
1086
1093
|
return response.json();
|
|
1087
1094
|
}
|
|
1088
1095
|
async getTxStatus(txid) {
|
|
1089
|
-
const txresponse = await
|
|
1096
|
+
const txresponse = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1090
1097
|
if (!txresponse.ok) {
|
|
1091
1098
|
throw new Error(txresponse.statusText);
|
|
1092
1099
|
}
|
|
@@ -1094,7 +1101,7 @@ var EsploraProvider = class {
|
|
|
1094
1101
|
if (!tx.status.confirmed) {
|
|
1095
1102
|
return { confirmed: false };
|
|
1096
1103
|
}
|
|
1097
|
-
const response = await
|
|
1104
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1098
1105
|
if (!response.ok) {
|
|
1099
1106
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1100
1107
|
}
|
|
@@ -1178,7 +1185,7 @@ var EsploraProvider = class {
|
|
|
1178
1185
|
return stopFunc;
|
|
1179
1186
|
}
|
|
1180
1187
|
async getChainTip() {
|
|
1181
|
-
const tipBlocks = await
|
|
1188
|
+
const tipBlocks = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
1182
1189
|
if (!tipBlocks.ok) {
|
|
1183
1190
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
1184
1191
|
}
|
|
@@ -1197,7 +1204,7 @@ var EsploraProvider = class {
|
|
|
1197
1204
|
};
|
|
1198
1205
|
}
|
|
1199
1206
|
async broadcastPackage(parent, child) {
|
|
1200
|
-
const response = await
|
|
1207
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
1201
1208
|
method: "POST",
|
|
1202
1209
|
headers: {
|
|
1203
1210
|
"Content-Type": "application/json"
|
|
@@ -1211,7 +1218,7 @@ var EsploraProvider = class {
|
|
|
1211
1218
|
return response.json();
|
|
1212
1219
|
}
|
|
1213
1220
|
async broadcastTx(tx) {
|
|
1214
|
-
const response = await
|
|
1221
|
+
const response = await chunkHHV5FPC6_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
1215
1222
|
method: "POST",
|
|
1216
1223
|
headers: {
|
|
1217
1224
|
"Content-Type": "text/plain"
|
|
@@ -1373,7 +1380,7 @@ function findP2AOutput(tx) {
|
|
|
1373
1380
|
var CHILD_DUST_AMOUNT = 546;
|
|
1374
1381
|
function buildAnchorChild(params) {
|
|
1375
1382
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
1376
|
-
const child = new
|
|
1383
|
+
const child = new chunkHHV5FPC6_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
1377
1384
|
child.addInput(findP2AOutput(parent));
|
|
1378
1385
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
1379
1386
|
for (const _ of fundingCoins) {
|
|
@@ -1421,7 +1428,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
1421
1428
|
);
|
|
1422
1429
|
}
|
|
1423
1430
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
1424
|
-
const tx = new
|
|
1431
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({
|
|
1425
1432
|
version: 3,
|
|
1426
1433
|
lockTime: txLocktime
|
|
1427
1434
|
});
|
|
@@ -1497,7 +1504,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
1497
1504
|
if (previousScriptKey.length !== 32) {
|
|
1498
1505
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
1499
1506
|
}
|
|
1500
|
-
const cosigners =
|
|
1507
|
+
const cosigners = chunkHHV5FPC6_cjs.getArkPsbtFields(child.root, 0, chunkHHV5FPC6_cjs.CosignerPublicKey);
|
|
1501
1508
|
if (cosigners.length === 0) {
|
|
1502
1509
|
throw ErrMissingCosignersPublicKeys;
|
|
1503
1510
|
}
|
|
@@ -1518,6 +1525,8 @@ var UnknownPacket = class {
|
|
|
1518
1525
|
this.packetType = packetType;
|
|
1519
1526
|
this.data = data;
|
|
1520
1527
|
}
|
|
1528
|
+
packetType;
|
|
1529
|
+
data;
|
|
1521
1530
|
type() {
|
|
1522
1531
|
return this.packetType;
|
|
1523
1532
|
}
|
|
@@ -1526,6 +1535,62 @@ var UnknownPacket = class {
|
|
|
1526
1535
|
}
|
|
1527
1536
|
};
|
|
1528
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
|
+
|
|
1529
1594
|
// src/extension/index.ts
|
|
1530
1595
|
var ARKADE_MAGIC = new Uint8Array([65, 82, 75]);
|
|
1531
1596
|
var ExtensionNotFoundError = class extends Error {
|
|
@@ -1538,16 +1603,21 @@ var Extension = class _Extension {
|
|
|
1538
1603
|
constructor(packets) {
|
|
1539
1604
|
this.packets = packets;
|
|
1540
1605
|
}
|
|
1606
|
+
packets;
|
|
1541
1607
|
static create(packets) {
|
|
1542
1608
|
if (packets.length === 0) {
|
|
1543
1609
|
throw new Error("missing packets");
|
|
1544
1610
|
}
|
|
1545
1611
|
const seen = /* @__PURE__ */ new Set();
|
|
1546
1612
|
for (const p of packets) {
|
|
1547
|
-
|
|
1548
|
-
|
|
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]`);
|
|
1549
1616
|
}
|
|
1550
|
-
seen.
|
|
1617
|
+
if (seen.has(type)) {
|
|
1618
|
+
throw new Error(`duplicate packet type ${type}`);
|
|
1619
|
+
}
|
|
1620
|
+
seen.add(type);
|
|
1551
1621
|
}
|
|
1552
1622
|
return new _Extension(packets);
|
|
1553
1623
|
}
|
|
@@ -1597,7 +1667,7 @@ var Extension = class _Extension {
|
|
|
1597
1667
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
1598
1668
|
);
|
|
1599
1669
|
}
|
|
1600
|
-
const reader = new
|
|
1670
|
+
const reader = new chunkHHV5FPC6_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
1601
1671
|
const packets = [];
|
|
1602
1672
|
while (reader.remaining() > 0) {
|
|
1603
1673
|
const packetType = reader.readByte();
|
|
@@ -1671,18 +1741,51 @@ var Extension = class _Extension {
|
|
|
1671
1741
|
*/
|
|
1672
1742
|
getAssetPacket() {
|
|
1673
1743
|
for (const p of this.packets) {
|
|
1674
|
-
if (p instanceof
|
|
1744
|
+
if (p instanceof chunkHHV5FPC6_cjs.Packet) {
|
|
1675
1745
|
return p;
|
|
1676
1746
|
}
|
|
1677
1747
|
}
|
|
1678
1748
|
return null;
|
|
1679
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
|
+
}
|
|
1680
1779
|
};
|
|
1681
1780
|
function parsePacket(packetType, data) {
|
|
1682
|
-
|
|
1683
|
-
|
|
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);
|
|
1684
1788
|
}
|
|
1685
|
-
return new UnknownPacket(packetType, data);
|
|
1686
1789
|
}
|
|
1687
1790
|
function encodeVarUint(value) {
|
|
1688
1791
|
const bytes = [];
|
|
@@ -1738,7 +1841,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
1738
1841
|
for (const recipient of recipients) {
|
|
1739
1842
|
let arkAddress;
|
|
1740
1843
|
try {
|
|
1741
|
-
arkAddress =
|
|
1844
|
+
arkAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(recipient.address);
|
|
1742
1845
|
} catch {
|
|
1743
1846
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
1744
1847
|
continue;
|
|
@@ -1976,6 +2079,7 @@ function isExpired(vtxo) {
|
|
|
1976
2079
|
return expiry <= Date.now();
|
|
1977
2080
|
}
|
|
1978
2081
|
function isSubdust(vtxo, dust) {
|
|
2082
|
+
if (typeof vtxo === "bigint") return vtxo < dust;
|
|
1979
2083
|
return vtxo.value < dust;
|
|
1980
2084
|
}
|
|
1981
2085
|
|
|
@@ -1987,7 +2091,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1987
2091
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
1988
2092
|
inputsByAssetId.set(asset.assetId, [
|
|
1989
2093
|
...existing ?? [],
|
|
1990
|
-
|
|
2094
|
+
chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
1991
2095
|
]);
|
|
1992
2096
|
}
|
|
1993
2097
|
}
|
|
@@ -1999,7 +2103,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1999
2103
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2000
2104
|
outputsByAssetId.set(asset.assetId, [
|
|
2001
2105
|
...existing ?? [],
|
|
2002
|
-
|
|
2106
|
+
chunkHHV5FPC6_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2003
2107
|
]);
|
|
2004
2108
|
}
|
|
2005
2109
|
}
|
|
@@ -2010,7 +2114,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2010
2114
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
2011
2115
|
outputsByAssetId.set(asset.assetId, [
|
|
2012
2116
|
...existing ?? [],
|
|
2013
|
-
|
|
2117
|
+
chunkHHV5FPC6_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
2014
2118
|
]);
|
|
2015
2119
|
}
|
|
2016
2120
|
}
|
|
@@ -2019,11 +2123,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
2019
2123
|
for (const assetIdStr of allAssetIds) {
|
|
2020
2124
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
2021
2125
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
2022
|
-
const assetId =
|
|
2023
|
-
const group =
|
|
2126
|
+
const assetId = chunkHHV5FPC6_cjs.AssetId.fromString(assetIdStr);
|
|
2127
|
+
const group = chunkHHV5FPC6_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
2024
2128
|
groups.push(group);
|
|
2025
2129
|
}
|
|
2026
|
-
return
|
|
2130
|
+
return chunkHHV5FPC6_cjs.Packet.create(groups);
|
|
2027
2131
|
}
|
|
2028
2132
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
2029
2133
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -2128,8 +2232,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
2128
2232
|
function buildVirtualTx(inputs, outputs) {
|
|
2129
2233
|
let lockTime = 0n;
|
|
2130
2234
|
for (const input of inputs) {
|
|
2131
|
-
const tapscript =
|
|
2132
|
-
if (
|
|
2235
|
+
const tapscript = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
2236
|
+
if (chunkL5ND2FJJ_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
2133
2237
|
if (lockTime !== 0n) {
|
|
2134
2238
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
2135
2239
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -2140,7 +2244,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2140
2244
|
}
|
|
2141
2245
|
}
|
|
2142
2246
|
}
|
|
2143
|
-
const tx = new
|
|
2247
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({
|
|
2144
2248
|
version: 3,
|
|
2145
2249
|
lockTime: Number(lockTime)
|
|
2146
2250
|
});
|
|
@@ -2150,12 +2254,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2150
2254
|
index: input.vout,
|
|
2151
2255
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
2152
2256
|
witnessUtxo: {
|
|
2153
|
-
script:
|
|
2257
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
2154
2258
|
amount: BigInt(input.value)
|
|
2155
2259
|
},
|
|
2156
2260
|
tapLeafScript: [input.tapLeafScript]
|
|
2157
2261
|
});
|
|
2158
|
-
|
|
2262
|
+
chunkHHV5FPC6_cjs.setArkPsbtField(tx, i, chunkHHV5FPC6_cjs.VtxoTaprootTree, input.tapTree);
|
|
2159
2263
|
}
|
|
2160
2264
|
for (const output of outputs) {
|
|
2161
2265
|
tx.addOutput(output);
|
|
@@ -2164,8 +2268,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
2164
2268
|
return tx;
|
|
2165
2269
|
}
|
|
2166
2270
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
2167
|
-
const collaborativeClosure =
|
|
2168
|
-
const checkpointVtxoScript = new
|
|
2271
|
+
const collaborativeClosure = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
2272
|
+
const checkpointVtxoScript = new chunkL5ND2FJJ_cjs.VtxoScript([
|
|
2169
2273
|
serverUnrollScript.script,
|
|
2170
2274
|
collaborativeClosure.script
|
|
2171
2275
|
]);
|
|
@@ -2309,12 +2413,52 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
2309
2413
|
}
|
|
2310
2414
|
function isValidArkAddress(address) {
|
|
2311
2415
|
try {
|
|
2312
|
-
|
|
2416
|
+
chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
2313
2417
|
return true;
|
|
2314
2418
|
} catch (e) {
|
|
2315
2419
|
return false;
|
|
2316
2420
|
}
|
|
2317
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
|
+
}
|
|
2318
2462
|
var AmountVariableName = "amount";
|
|
2319
2463
|
var ExpiryVariableName = "expiry";
|
|
2320
2464
|
var BirthVariableName = "birth";
|
|
@@ -2334,6 +2478,7 @@ var FeeAmount = class _FeeAmount {
|
|
|
2334
2478
|
constructor(value) {
|
|
2335
2479
|
this.value = value;
|
|
2336
2480
|
}
|
|
2481
|
+
value;
|
|
2337
2482
|
static ZERO = new _FeeAmount(0);
|
|
2338
2483
|
/** Returns the fee amount rounded up to whole satoshis. */
|
|
2339
2484
|
get satoshis() {
|
|
@@ -2358,6 +2503,7 @@ var Estimator = class {
|
|
|
2358
2503
|
this.intentOffchainOutput = config.offchainOutput ? parseProgram(config.offchainOutput, IntentOutputEnv) : void 0;
|
|
2359
2504
|
this.intentOnchainOutput = config.onchainOutput ? parseProgram(config.onchainOutput, IntentOutputEnv) : void 0;
|
|
2360
2505
|
}
|
|
2506
|
+
config;
|
|
2361
2507
|
intentOffchainInput;
|
|
2362
2508
|
intentOnchainInput;
|
|
2363
2509
|
intentOffchainOutput;
|
|
@@ -2468,6 +2614,14 @@ function parseProgram(text, env) {
|
|
|
2468
2614
|
}
|
|
2469
2615
|
return { program, text };
|
|
2470
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
|
+
}
|
|
2471
2625
|
var DUST_AMOUNT = 546;
|
|
2472
2626
|
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
2473
2627
|
function getDustAmount(wallet) {
|
|
@@ -2482,15 +2636,19 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
2482
2636
|
};
|
|
2483
2637
|
}
|
|
2484
2638
|
function deriveContractTapscripts(contract) {
|
|
2485
|
-
const handler =
|
|
2639
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
2486
2640
|
if (!handler) {
|
|
2487
2641
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2488
2642
|
}
|
|
2489
2643
|
const script = handler.createScript(contract.params);
|
|
2644
|
+
if (isTapscriptDeriving(handler)) {
|
|
2645
|
+
return handler.deriveTapscripts(script, contract);
|
|
2646
|
+
}
|
|
2647
|
+
const legacy = script;
|
|
2490
2648
|
return {
|
|
2491
|
-
forfeitTapLeafScript:
|
|
2492
|
-
intentTapLeafScript:
|
|
2493
|
-
tapTree:
|
|
2649
|
+
forfeitTapLeafScript: legacy.forfeit(),
|
|
2650
|
+
intentTapLeafScript: legacy.forfeit(),
|
|
2651
|
+
tapTree: legacy.encode()
|
|
2494
2652
|
};
|
|
2495
2653
|
}
|
|
2496
2654
|
function cloneTapLeafScript([
|
|
@@ -2552,7 +2710,7 @@ function validateRecipients(recipients, dustAmount) {
|
|
|
2552
2710
|
for (const recipient of recipients) {
|
|
2553
2711
|
let address;
|
|
2554
2712
|
try {
|
|
2555
|
-
address =
|
|
2713
|
+
address = chunkL5ND2FJJ_cjs.ArkAddress.decode(recipient.address);
|
|
2556
2714
|
} catch (e) {
|
|
2557
2715
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2558
2716
|
}
|
|
@@ -2760,6 +2918,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
2760
2918
|
}
|
|
2761
2919
|
this.contractEventsSubscriptionReady = this.initializeSubscription();
|
|
2762
2920
|
}
|
|
2921
|
+
wallet;
|
|
2922
|
+
renewalConfig;
|
|
2763
2923
|
settlementConfig;
|
|
2764
2924
|
contractEventsSubscriptionReady;
|
|
2765
2925
|
disposePromise;
|
|
@@ -3157,11 +3317,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
3157
3317
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
3158
3318
|
);
|
|
3159
3319
|
}
|
|
3160
|
-
const tx = new
|
|
3320
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction();
|
|
3161
3321
|
for (const utxo of expiredUtxos) {
|
|
3162
|
-
const utxoScript =
|
|
3322
|
+
const utxoScript = chunkL5ND2FJJ_cjs.VtxoScript.decode(utxo.tapTree);
|
|
3163
3323
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
3164
|
-
(leaf) =>
|
|
3324
|
+
(leaf) => chunkL5ND2FJJ_cjs.CSVMultisigTapscript.isScriptValid(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
3165
3325
|
);
|
|
3166
3326
|
if (!utxoExitLeaf) {
|
|
3167
3327
|
throw new Error(
|
|
@@ -3176,7 +3336,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3176
3336
|
amount: BigInt(utxo.value)
|
|
3177
3337
|
},
|
|
3178
3338
|
tapLeafScript: [utxoExitLeaf],
|
|
3179
|
-
sequence:
|
|
3339
|
+
sequence: chunkL5ND2FJJ_cjs.getSequence(utxoExitLeaf)
|
|
3180
3340
|
});
|
|
3181
3341
|
}
|
|
3182
3342
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -3665,7 +3825,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3665
3825
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
3666
3826
|
getBoardingTimelock() {
|
|
3667
3827
|
const wallet = this.getSweepWallet();
|
|
3668
|
-
const exitScript =
|
|
3828
|
+
const exitScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(
|
|
3669
3829
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
3670
3830
|
);
|
|
3671
3831
|
return exitScript.params.timelock;
|
|
@@ -3796,8 +3956,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
3796
3956
|
* or doesn't carry the metadata.
|
|
3797
3957
|
*/
|
|
3798
3958
|
extractSpentOutpoint(error) {
|
|
3799
|
-
const ark =
|
|
3800
|
-
if (!ark
|
|
3959
|
+
const ark = chunkHHV5FPC6_cjs.maybeArkError(error);
|
|
3960
|
+
if (!chunkHHV5FPC6_cjs.isArkError(ark, chunkHHV5FPC6_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
3801
3961
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
3802
3962
|
if (typeof raw !== "string") return void 0;
|
|
3803
3963
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -4011,7 +4171,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4011
4171
|
const arkAddress = await this.wallet.getAddress();
|
|
4012
4172
|
const outputFee = estimator.evalOffchainOutput({
|
|
4013
4173
|
amount: totalAmount,
|
|
4014
|
-
script: base.hex.encode(
|
|
4174
|
+
script: base.hex.encode(chunkL5ND2FJJ_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4015
4175
|
});
|
|
4016
4176
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
4017
4177
|
if (totalAmount < dustAmount) return;
|
|
@@ -4091,7 +4251,7 @@ var ArkNote = class _ArkNote {
|
|
|
4091
4251
|
this.value = value;
|
|
4092
4252
|
this.HRP = HRP;
|
|
4093
4253
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
4094
|
-
this.vtxoScript = new
|
|
4254
|
+
this.vtxoScript = new chunkL5ND2FJJ_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
4095
4255
|
const leaf = this.vtxoScript.leaves[0];
|
|
4096
4256
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
4097
4257
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -4101,6 +4261,9 @@ var ArkNote = class _ArkNote {
|
|
|
4101
4261
|
this.status = { confirmed: true };
|
|
4102
4262
|
this.extraWitness = [this.preimage];
|
|
4103
4263
|
}
|
|
4264
|
+
preimage;
|
|
4265
|
+
value;
|
|
4266
|
+
HRP;
|
|
4104
4267
|
static DefaultHRP = "arknote";
|
|
4105
4268
|
static PreimageLength = 32;
|
|
4106
4269
|
// 32 bytes for the preimage
|
|
@@ -4443,7 +4606,7 @@ async function captureExitBranch(params) {
|
|
|
4443
4606
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
4444
4607
|
if (nonCommitment.length > 0) {
|
|
4445
4608
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
4446
|
-
psbtByTxid.set(
|
|
4609
|
+
psbtByTxid.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4447
4610
|
}
|
|
4448
4611
|
}
|
|
4449
4612
|
}
|
|
@@ -4477,6 +4640,7 @@ var IndexerExitDataSource = class {
|
|
|
4477
4640
|
constructor(indexer) {
|
|
4478
4641
|
this.indexer = indexer;
|
|
4479
4642
|
}
|
|
4643
|
+
indexer;
|
|
4480
4644
|
name = "indexer";
|
|
4481
4645
|
async getVtxoChain(vtxo) {
|
|
4482
4646
|
const chain = [];
|
|
@@ -4485,10 +4649,10 @@ var IndexerExitDataSource = class {
|
|
|
4485
4649
|
while (hasMore) {
|
|
4486
4650
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
4487
4651
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
4488
|
-
{ pageIndex, pageSize:
|
|
4652
|
+
{ pageIndex, pageSize: chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE }
|
|
4489
4653
|
);
|
|
4490
4654
|
chain.push(...page);
|
|
4491
|
-
hasMore = meta ? page.length ===
|
|
4655
|
+
hasMore = meta ? page.length === chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4492
4656
|
pageIndex++;
|
|
4493
4657
|
}
|
|
4494
4658
|
return chain;
|
|
@@ -4500,12 +4664,12 @@ var IndexerExitDataSource = class {
|
|
|
4500
4664
|
while (hasMore) {
|
|
4501
4665
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
4502
4666
|
pageIndex,
|
|
4503
|
-
pageSize:
|
|
4667
|
+
pageSize: chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE
|
|
4504
4668
|
});
|
|
4505
4669
|
for (const psbt of txs) {
|
|
4506
|
-
out.set(
|
|
4670
|
+
out.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
4507
4671
|
}
|
|
4508
|
-
hasMore = page ? txs.length ===
|
|
4672
|
+
hasMore = page ? txs.length === chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE : false;
|
|
4509
4673
|
pageIndex++;
|
|
4510
4674
|
}
|
|
4511
4675
|
return out;
|
|
@@ -4526,7 +4690,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
4526
4690
|
}
|
|
4527
4691
|
}
|
|
4528
4692
|
function psbtInputTxids(psbtBase64) {
|
|
4529
|
-
const tx =
|
|
4693
|
+
const tx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
4530
4694
|
const ids = [];
|
|
4531
4695
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
4532
4696
|
const txid = tx.getInput(i).txid;
|
|
@@ -4538,6 +4702,7 @@ var RepositoryExitDataSource = class {
|
|
|
4538
4702
|
constructor(repo) {
|
|
4539
4703
|
this.repo = repo;
|
|
4540
4704
|
}
|
|
4705
|
+
repo;
|
|
4541
4706
|
name = "repository";
|
|
4542
4707
|
async getVtxoChain(vtxo) {
|
|
4543
4708
|
const branch = await this.repo.getBranch(vtxo);
|
|
@@ -4575,6 +4740,8 @@ var OrderedExitChainResolver = class {
|
|
|
4575
4740
|
this.sources = sources;
|
|
4576
4741
|
this.persist = persist;
|
|
4577
4742
|
}
|
|
4743
|
+
sources;
|
|
4744
|
+
persist;
|
|
4578
4745
|
async getVtxoChain(vtxo) {
|
|
4579
4746
|
let lastErr;
|
|
4580
4747
|
for (const source of this.sources) {
|
|
@@ -4626,7 +4793,7 @@ function createExitChainResolver(params) {
|
|
|
4626
4793
|
|
|
4627
4794
|
// src/providers/availability.ts
|
|
4628
4795
|
function isRetryableProviderError(error) {
|
|
4629
|
-
return error instanceof
|
|
4796
|
+
return error instanceof chunkHHV5FPC6_cjs.ProviderUnavailableError || error instanceof chunkHHV5FPC6_cjs.FetchError || chunkHHV5FPC6_cjs.isFetchTimeoutError(error);
|
|
4630
4797
|
}
|
|
4631
4798
|
|
|
4632
4799
|
// src/utils/syncCursors.ts
|
|
@@ -4879,7 +5046,7 @@ async function resolveArkInfo(arkProvider, walletRepository) {
|
|
|
4879
5046
|
if (!isRetryableProviderError(err)) throw err;
|
|
4880
5047
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
4881
5048
|
if (!snapshot) {
|
|
4882
|
-
throw new
|
|
5049
|
+
throw new chunkHHV5FPC6_cjs.ProviderUnavailableError(
|
|
4883
5050
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
4884
5051
|
{ cause: err }
|
|
4885
5052
|
);
|
|
@@ -4900,6 +5067,8 @@ var TxTree = class {
|
|
|
4900
5067
|
this.root = root;
|
|
4901
5068
|
this.children = children;
|
|
4902
5069
|
}
|
|
5070
|
+
root;
|
|
5071
|
+
children;
|
|
4903
5072
|
static create(chunks) {
|
|
4904
5073
|
if (chunks.length === 0) {
|
|
4905
5074
|
throw new Error("empty chunks");
|
|
@@ -5371,6 +5540,7 @@ var ReadonlyAssetManager = class {
|
|
|
5371
5540
|
constructor(indexer) {
|
|
5372
5541
|
this.indexer = indexer;
|
|
5373
5542
|
}
|
|
5543
|
+
indexer;
|
|
5374
5544
|
async getAssetDetails(assetId) {
|
|
5375
5545
|
return this.indexer.getAssetDetails(assetId);
|
|
5376
5546
|
}
|
|
@@ -5380,6 +5550,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5380
5550
|
super(wallet.indexerProvider);
|
|
5381
5551
|
this.wallet = wallet;
|
|
5382
5552
|
}
|
|
5553
|
+
wallet;
|
|
5383
5554
|
/**
|
|
5384
5555
|
* Issue a new asset.
|
|
5385
5556
|
* @param params - Parameters for asset issuance
|
|
@@ -5410,7 +5581,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5410
5581
|
const virtualCoins = await this.wallet.getVtxos({
|
|
5411
5582
|
withRecoverable: false
|
|
5412
5583
|
});
|
|
5413
|
-
const controlAssetRef = params.controlAssetId ?
|
|
5584
|
+
const controlAssetRef = params.controlAssetId ? chunkHHV5FPC6_cjs.AssetRef.fromId(chunkHHV5FPC6_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
5414
5585
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
5415
5586
|
let totalBtcSelected = 0n;
|
|
5416
5587
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -5423,8 +5594,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5423
5594
|
}
|
|
5424
5595
|
}
|
|
5425
5596
|
const groups = [];
|
|
5426
|
-
const issuedAssetOutput =
|
|
5427
|
-
const issuedAssetGroup =
|
|
5597
|
+
const issuedAssetOutput = chunkHHV5FPC6_cjs.AssetOutput.create(0, params.amount);
|
|
5598
|
+
const issuedAssetGroup = chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5428
5599
|
null,
|
|
5429
5600
|
controlAssetRef,
|
|
5430
5601
|
[],
|
|
@@ -5439,28 +5610,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5439
5610
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5440
5611
|
for (const asset of assets) {
|
|
5441
5612
|
if (asset.assetId !== assetId) continue;
|
|
5442
|
-
changeInputs.push(
|
|
5613
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5443
5614
|
}
|
|
5444
5615
|
}
|
|
5445
5616
|
groups.push(
|
|
5446
|
-
|
|
5447
|
-
|
|
5617
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5618
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5448
5619
|
null,
|
|
5449
5620
|
changeInputs,
|
|
5450
|
-
[
|
|
5621
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)],
|
|
5451
5622
|
[]
|
|
5452
5623
|
)
|
|
5453
5624
|
);
|
|
5454
5625
|
}
|
|
5455
5626
|
}
|
|
5456
5627
|
const address = await this.wallet.getAddress();
|
|
5457
|
-
const outputAddress =
|
|
5628
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5458
5629
|
const outputs = [
|
|
5459
5630
|
{
|
|
5460
5631
|
script: outputAddress.pkScript,
|
|
5461
5632
|
amount: BigInt(totalBtcSelected)
|
|
5462
5633
|
},
|
|
5463
|
-
Extension.create([
|
|
5634
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5464
5635
|
];
|
|
5465
5636
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
5466
5637
|
coinSelection.inputs,
|
|
@@ -5468,7 +5639,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5468
5639
|
);
|
|
5469
5640
|
return {
|
|
5470
5641
|
arkTxId: arkTxid,
|
|
5471
|
-
assetId:
|
|
5642
|
+
assetId: chunkHHV5FPC6_cjs.AssetId.create(arkTxid, 0).toString()
|
|
5472
5643
|
};
|
|
5473
5644
|
}
|
|
5474
5645
|
/**
|
|
@@ -5540,16 +5711,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5540
5711
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5541
5712
|
for (const asset of assets) {
|
|
5542
5713
|
if (asset.assetId !== params.assetId) continue;
|
|
5543
|
-
reissueInputs.push(
|
|
5714
|
+
reissueInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5544
5715
|
}
|
|
5545
5716
|
}
|
|
5546
5717
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
5547
|
-
const reissueAssetIdObj =
|
|
5548
|
-
const reissueAssetGroup =
|
|
5718
|
+
const reissueAssetIdObj = chunkHHV5FPC6_cjs.AssetId.fromString(params.assetId);
|
|
5719
|
+
const reissueAssetGroup = chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5549
5720
|
reissueAssetIdObj,
|
|
5550
5721
|
null,
|
|
5551
5722
|
reissueInputs,
|
|
5552
|
-
[
|
|
5723
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
5553
5724
|
[]
|
|
5554
5725
|
);
|
|
5555
5726
|
const groups = [reissueAssetGroup];
|
|
@@ -5558,27 +5729,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5558
5729
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5559
5730
|
for (const asset of assets) {
|
|
5560
5731
|
if (asset.assetId !== assetId) continue;
|
|
5561
|
-
changeInputs.push(
|
|
5732
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5562
5733
|
}
|
|
5563
5734
|
}
|
|
5564
5735
|
groups.push(
|
|
5565
|
-
|
|
5566
|
-
|
|
5736
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5737
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5567
5738
|
null,
|
|
5568
5739
|
changeInputs,
|
|
5569
|
-
[
|
|
5740
|
+
[chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)],
|
|
5570
5741
|
[]
|
|
5571
5742
|
)
|
|
5572
5743
|
);
|
|
5573
5744
|
}
|
|
5574
5745
|
const address = await this.wallet.getAddress();
|
|
5575
|
-
const outputAddress =
|
|
5746
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5576
5747
|
const outputs = [
|
|
5577
5748
|
{
|
|
5578
5749
|
script: outputAddress.pkScript,
|
|
5579
5750
|
amount: BigInt(totalBtcSelected)
|
|
5580
5751
|
},
|
|
5581
|
-
Extension.create([
|
|
5752
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5582
5753
|
];
|
|
5583
5754
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5584
5755
|
return arkTxid;
|
|
@@ -5645,27 +5816,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
5645
5816
|
for (const [inputIndex, assets] of assetInputs) {
|
|
5646
5817
|
for (const asset of assets) {
|
|
5647
5818
|
if (asset.assetId !== assetId) continue;
|
|
5648
|
-
changeInputs.push(
|
|
5819
|
+
changeInputs.push(chunkHHV5FPC6_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
5649
5820
|
}
|
|
5650
5821
|
}
|
|
5651
5822
|
groups.push(
|
|
5652
|
-
|
|
5653
|
-
|
|
5823
|
+
chunkHHV5FPC6_cjs.AssetGroup.create(
|
|
5824
|
+
chunkHHV5FPC6_cjs.AssetId.fromString(assetId),
|
|
5654
5825
|
null,
|
|
5655
5826
|
changeInputs,
|
|
5656
|
-
amount > 0n ? [
|
|
5827
|
+
amount > 0n ? [chunkHHV5FPC6_cjs.AssetOutput.create(0, amount)] : [],
|
|
5657
5828
|
[]
|
|
5658
5829
|
)
|
|
5659
5830
|
);
|
|
5660
5831
|
}
|
|
5661
5832
|
const address = await this.wallet.getAddress();
|
|
5662
|
-
const outputAddress =
|
|
5833
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(address);
|
|
5663
5834
|
const outputs = [
|
|
5664
5835
|
{
|
|
5665
5836
|
script: outputAddress.pkScript,
|
|
5666
5837
|
amount: BigInt(totalBtcSelected)
|
|
5667
5838
|
},
|
|
5668
|
-
Extension.create([
|
|
5839
|
+
Extension.create([chunkHHV5FPC6_cjs.Packet.create(groups)]).txOut()
|
|
5669
5840
|
];
|
|
5670
5841
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
5671
5842
|
return arkTxid;
|
|
@@ -5690,7 +5861,7 @@ function castMetadata(metadata) {
|
|
|
5690
5861
|
} else {
|
|
5691
5862
|
throw new Error("Invalid metadata value type");
|
|
5692
5863
|
}
|
|
5693
|
-
md.push(
|
|
5864
|
+
md.push(chunkHHV5FPC6_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
5694
5865
|
}
|
|
5695
5866
|
return md;
|
|
5696
5867
|
}
|
|
@@ -5701,6 +5872,9 @@ var DelegateManagerImpl = class {
|
|
|
5701
5872
|
this.arkInfoProvider = arkInfoProvider;
|
|
5702
5873
|
this.identity = identity;
|
|
5703
5874
|
}
|
|
5875
|
+
delegateProvider;
|
|
5876
|
+
arkInfoProvider;
|
|
5877
|
+
identity;
|
|
5704
5878
|
async getDelegateInfo() {
|
|
5705
5879
|
return this.delegateProvider.getDelegateInfo();
|
|
5706
5880
|
}
|
|
@@ -5708,7 +5882,7 @@ var DelegateManagerImpl = class {
|
|
|
5708
5882
|
if (vtxos.length === 0) {
|
|
5709
5883
|
return { delegated: [], failed: [] };
|
|
5710
5884
|
}
|
|
5711
|
-
const destinationScript =
|
|
5885
|
+
const destinationScript = chunkL5ND2FJJ_cjs.ArkAddress.decode(destination).pkScript;
|
|
5712
5886
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
5713
5887
|
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
5714
5888
|
const eligible = vtxos.filter(
|
|
@@ -5856,7 +6030,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5856
6030
|
const delegateFee = BigInt(Number(fee));
|
|
5857
6031
|
if (delegateFee > 0n) {
|
|
5858
6032
|
outputs.push({
|
|
5859
|
-
script:
|
|
6033
|
+
script: chunkL5ND2FJJ_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
5860
6034
|
amount: delegateFee
|
|
5861
6035
|
});
|
|
5862
6036
|
}
|
|
@@ -5867,12 +6041,12 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5867
6041
|
script: base.hex.encode(output.script)
|
|
5868
6042
|
}).satoshis;
|
|
5869
6043
|
}, 0);
|
|
5870
|
-
if (amount - BigInt(outputFee)
|
|
6044
|
+
if (isSubdust(amount - BigInt(outputFee), dust)) {
|
|
5871
6045
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
5872
6046
|
}
|
|
5873
6047
|
amount -= BigInt(outputFee);
|
|
5874
6048
|
amount -= delegateFee;
|
|
5875
|
-
if (amount
|
|
6049
|
+
if (isSubdust(amount, dust)) {
|
|
5876
6050
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
5877
6051
|
}
|
|
5878
6052
|
outputs.push({
|
|
@@ -5889,7 +6063,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
5889
6063
|
destinationScript
|
|
5890
6064
|
);
|
|
5891
6065
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
5892
|
-
btcSigner.Address(
|
|
6066
|
+
btcSigner.Address(chunkL5ND2FJJ_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
5893
6067
|
);
|
|
5894
6068
|
const forfeits = await Promise.all(
|
|
5895
6069
|
vtxos.filter((v) => !isRecoverable(v)).map(async (coin) => {
|
|
@@ -5917,7 +6091,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
5917
6091
|
index: input.vout,
|
|
5918
6092
|
witnessUtxo: {
|
|
5919
6093
|
amount: BigInt(input.value),
|
|
5920
|
-
script:
|
|
6094
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
5921
6095
|
},
|
|
5922
6096
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
5923
6097
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -5975,7 +6149,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
5975
6149
|
expire_at: 0,
|
|
5976
6150
|
cosigners_public_keys: cosignerPubKeys
|
|
5977
6151
|
};
|
|
5978
|
-
const proof =
|
|
6152
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, outputs);
|
|
5979
6153
|
const signedProof = await identity.sign(proof);
|
|
5980
6154
|
return {
|
|
5981
6155
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -5993,10 +6167,10 @@ function getDayTimestamp(timestamp) {
|
|
|
5993
6167
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
5994
6168
|
if (!vtxo.tapTree) return void 0;
|
|
5995
6169
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
5996
|
-
const vtxoScript =
|
|
6170
|
+
const vtxoScript = chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
5997
6171
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
5998
|
-
const arkTapscript =
|
|
5999
|
-
if (!
|
|
6172
|
+
const arkTapscript = chunkL5ND2FJJ_cjs.decodeTapscript(chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
6173
|
+
if (!chunkL5ND2FJJ_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
6000
6174
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
6001
6175
|
});
|
|
6002
6176
|
}
|
|
@@ -6184,7 +6358,7 @@ async function closeDatabase(dbName) {
|
|
|
6184
6358
|
return true;
|
|
6185
6359
|
}
|
|
6186
6360
|
function scriptFromArkAddress(address) {
|
|
6187
|
-
return base.hex.encode(
|
|
6361
|
+
return base.hex.encode(chunkL5ND2FJJ_cjs.ArkAddress.decode(address).pkScript);
|
|
6188
6362
|
}
|
|
6189
6363
|
|
|
6190
6364
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -6469,6 +6643,7 @@ var IndexedDBVirtualTxRepository = class {
|
|
|
6469
6643
|
constructor(dbName = DEFAULT_DB_NAME) {
|
|
6470
6644
|
this.dbName = dbName;
|
|
6471
6645
|
}
|
|
6646
|
+
dbName;
|
|
6472
6647
|
version = 1;
|
|
6473
6648
|
db = null;
|
|
6474
6649
|
async getDB() {
|
|
@@ -6598,6 +6773,7 @@ var IndexedDBIntentRepository = class {
|
|
|
6598
6773
|
constructor(dbName = DEFAULT_DB_NAME) {
|
|
6599
6774
|
this.dbName = dbName;
|
|
6600
6775
|
}
|
|
6776
|
+
dbName;
|
|
6601
6777
|
version = 1;
|
|
6602
6778
|
db = null;
|
|
6603
6779
|
async getDB() {
|
|
@@ -6908,6 +7084,7 @@ var IndexedDBContractRepository = class {
|
|
|
6908
7084
|
constructor(dbName = DEFAULT_DB_NAME) {
|
|
6909
7085
|
this.dbName = dbName;
|
|
6910
7086
|
}
|
|
7087
|
+
dbName;
|
|
6911
7088
|
version = 1;
|
|
6912
7089
|
db = null;
|
|
6913
7090
|
async clear() {
|
|
@@ -7074,6 +7251,7 @@ var IndexedDBWalletRepository = class {
|
|
|
7074
7251
|
constructor(dbName = DEFAULT_DB_NAME) {
|
|
7075
7252
|
this.dbName = dbName;
|
|
7076
7253
|
}
|
|
7254
|
+
dbName;
|
|
7077
7255
|
version = 1;
|
|
7078
7256
|
db = null;
|
|
7079
7257
|
async clear() {
|
|
@@ -7831,11 +8009,6 @@ var ContractRepositoryImpl = class {
|
|
|
7831
8009
|
}
|
|
7832
8010
|
};
|
|
7833
8011
|
|
|
7834
|
-
// src/contracts/types.ts
|
|
7835
|
-
function isDiscoverable(handler) {
|
|
7836
|
-
return !!handler && typeof handler.discoverAt === "function";
|
|
7837
|
-
}
|
|
7838
|
-
|
|
7839
8012
|
// src/contracts/contractWatcher.ts
|
|
7840
8013
|
function computeReconnectDelay(attempt, baseMs, maxMs) {
|
|
7841
8014
|
return Math.min(baseMs * Math.pow(2, attempt - 1), maxMs);
|
|
@@ -8059,7 +8232,7 @@ var ContractWatcher = class {
|
|
|
8059
8232
|
this.connectionState = "connected";
|
|
8060
8233
|
this.reconnectAttempts = 0;
|
|
8061
8234
|
this.listenLoop().catch((e) => {
|
|
8062
|
-
if (
|
|
8235
|
+
if (chunkHHV5FPC6_cjs.isEventSourceError(e)) {
|
|
8063
8236
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
8064
8237
|
} else {
|
|
8065
8238
|
console.error(e);
|
|
@@ -8585,7 +8758,7 @@ var ContractManager = class _ContractManager {
|
|
|
8585
8758
|
* `persisted` is `true`.
|
|
8586
8759
|
*/
|
|
8587
8760
|
async upsertContract(params) {
|
|
8588
|
-
const handler =
|
|
8761
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(params.type);
|
|
8589
8762
|
if (!handler) {
|
|
8590
8763
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
8591
8764
|
}
|
|
@@ -8668,7 +8841,7 @@ var ContractManager = class _ContractManager {
|
|
|
8668
8841
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
8669
8842
|
);
|
|
8670
8843
|
}
|
|
8671
|
-
const registered =
|
|
8844
|
+
const registered = chunkRQSA7ADZ_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkRQSA7ADZ_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
8672
8845
|
const discoverables = [
|
|
8673
8846
|
...registered.filter((h) => h.type === "boarding"),
|
|
8674
8847
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -8858,7 +9031,7 @@ var ContractManager = class _ContractManager {
|
|
|
8858
9031
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
8859
9032
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
8860
9033
|
if (!contract) return [];
|
|
8861
|
-
const handler =
|
|
9034
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
8862
9035
|
if (!handler) return [];
|
|
8863
9036
|
const script = handler.createScript(contract.params);
|
|
8864
9037
|
const context = {
|
|
@@ -8878,7 +9051,7 @@ var ContractManager = class _ContractManager {
|
|
|
8878
9051
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
8879
9052
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
8880
9053
|
if (!contract) return [];
|
|
8881
|
-
const handler =
|
|
9054
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
8882
9055
|
if (!handler) return [];
|
|
8883
9056
|
const script = handler.createScript(contract.params);
|
|
8884
9057
|
const context = {
|
|
@@ -9145,7 +9318,7 @@ var ContractManager = class _ContractManager {
|
|
|
9145
9318
|
}
|
|
9146
9319
|
return result;
|
|
9147
9320
|
}
|
|
9148
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
9321
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkRQSA7ADZ_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
9149
9322
|
if (contracts.length === 0) {
|
|
9150
9323
|
return /* @__PURE__ */ new Map();
|
|
9151
9324
|
}
|
|
@@ -9219,6 +9392,8 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9219
9392
|
this.identity = identity;
|
|
9220
9393
|
this.walletRepository = walletRepository;
|
|
9221
9394
|
}
|
|
9395
|
+
identity;
|
|
9396
|
+
walletRepository;
|
|
9222
9397
|
/**
|
|
9223
9398
|
* Construct an HDDescriptorProvider. No I/O is performed here;
|
|
9224
9399
|
* persisted state is read lazily on the first call to
|
|
@@ -9321,7 +9496,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
9321
9496
|
*/
|
|
9322
9497
|
materializeDescriptorAt(index) {
|
|
9323
9498
|
const descriptor = this.identity.descriptor;
|
|
9324
|
-
const network =
|
|
9499
|
+
const network = chunkRQSA7ADZ_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
9325
9500
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
9326
9501
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
9327
9502
|
if (!keyInfo?.keyExpression) {
|
|
@@ -9411,6 +9586,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9411
9586
|
this.currentTaggedScript = priorTaggedScript;
|
|
9412
9587
|
this.logger = logger ?? console;
|
|
9413
9588
|
}
|
|
9589
|
+
provider;
|
|
9414
9590
|
unsubscribe;
|
|
9415
9591
|
chain = Promise.resolve();
|
|
9416
9592
|
/**
|
|
@@ -9464,7 +9640,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9464
9640
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
9465
9641
|
if (!provider) return void 0;
|
|
9466
9642
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
9467
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
9643
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
9468
9644
|
const factoryOpts = {
|
|
9469
9645
|
walletRepository: setup.walletRepository,
|
|
9470
9646
|
contractRepository: setup.contractRepository,
|
|
@@ -9647,7 +9823,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9647
9823
|
const newAddress = newTapscript.address(wallet.network.hrp, wallet.arkServerPublicKey).encode();
|
|
9648
9824
|
const manager = await wallet.getContractManager();
|
|
9649
9825
|
const csvTimelock = newTapscript.options.csvTimelock;
|
|
9650
|
-
const csvTimelockStr =
|
|
9826
|
+
const csvTimelockStr = chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString();
|
|
9651
9827
|
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
9652
9828
|
const baseParams = {
|
|
9653
9829
|
script: newScript,
|
|
@@ -9661,11 +9837,11 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9661
9837
|
// produce unsigned PSBTs that the server rejects with
|
|
9662
9838
|
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
9663
9839
|
metadata: {
|
|
9664
|
-
source:
|
|
9840
|
+
source: chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE,
|
|
9665
9841
|
signingDescriptor: descriptor
|
|
9666
9842
|
}
|
|
9667
9843
|
};
|
|
9668
|
-
if (newTapscript instanceof
|
|
9844
|
+
if (newTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
9669
9845
|
await manager.createContract({
|
|
9670
9846
|
...baseParams,
|
|
9671
9847
|
type: "delegate",
|
|
@@ -9697,7 +9873,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
9697
9873
|
};
|
|
9698
9874
|
function deriveLeafPubkey(descriptor) {
|
|
9699
9875
|
try {
|
|
9700
|
-
return
|
|
9876
|
+
return chunkRQSA7ADZ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
9701
9877
|
} catch (e) {
|
|
9702
9878
|
throw new NonRangeableDescriptorError(
|
|
9703
9879
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -9706,10 +9882,10 @@ function deriveLeafPubkey(descriptor) {
|
|
|
9706
9882
|
}
|
|
9707
9883
|
}
|
|
9708
9884
|
function rebuildTapscript(current, pubKey) {
|
|
9709
|
-
if (current instanceof
|
|
9710
|
-
return new
|
|
9885
|
+
if (current instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
9886
|
+
return new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
9711
9887
|
}
|
|
9712
|
-
return new
|
|
9888
|
+
return new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
9713
9889
|
}
|
|
9714
9890
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
9715
9891
|
const candidates = await contractRepository.getContracts({
|
|
@@ -9718,7 +9894,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
9718
9894
|
});
|
|
9719
9895
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
9720
9896
|
const matching = candidates.filter(
|
|
9721
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
9897
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE
|
|
9722
9898
|
).sort((a, b) => {
|
|
9723
9899
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
9724
9900
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -9764,6 +9940,8 @@ var MissingSigningDescriptorError = class extends Error {
|
|
|
9764
9940
|
this.contractScript = contractScript;
|
|
9765
9941
|
this.contractType = contractType;
|
|
9766
9942
|
}
|
|
9943
|
+
contractScript;
|
|
9944
|
+
contractType;
|
|
9767
9945
|
name = "MissingSigningDescriptorError";
|
|
9768
9946
|
};
|
|
9769
9947
|
var DescriptorSigningProviderMissingError = class extends Error {
|
|
@@ -9779,6 +9957,7 @@ var InputSignerRouter = class {
|
|
|
9779
9957
|
constructor(deps) {
|
|
9780
9958
|
this.deps = deps;
|
|
9781
9959
|
}
|
|
9960
|
+
deps;
|
|
9782
9961
|
/**
|
|
9783
9962
|
* Resolve each job to its target signer without invoking signing. The
|
|
9784
9963
|
* returned plan is the single source of truth for both {@link sign} and
|
|
@@ -9891,12 +10070,12 @@ var InputSignerRouter = class {
|
|
|
9891
10070
|
};
|
|
9892
10071
|
|
|
9893
10072
|
// src/wallet/wallet.ts
|
|
9894
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
10073
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkL5ND2FJJ_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
9895
10074
|
function intentProofJobs(coins) {
|
|
9896
10075
|
if (coins.length === 0) return [];
|
|
9897
10076
|
const coinJobs = coins.map((coin, i) => ({
|
|
9898
10077
|
index: i + 1,
|
|
9899
|
-
lookupScript:
|
|
10078
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
9900
10079
|
}));
|
|
9901
10080
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
9902
10081
|
}
|
|
@@ -9920,7 +10099,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
9920
10099
|
const seen = /* @__PURE__ */ new Set();
|
|
9921
10100
|
const deduped = [];
|
|
9922
10101
|
for (const timelock of timelocks) {
|
|
9923
|
-
const sequence =
|
|
10102
|
+
const sequence = chunkL5ND2FJJ_cjs.timelockToSequence(timelock).toString();
|
|
9924
10103
|
if (seen.has(sequence)) continue;
|
|
9925
10104
|
seen.add(sequence);
|
|
9926
10105
|
deduped.push(timelock);
|
|
@@ -9937,7 +10116,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
9937
10116
|
state: "active"
|
|
9938
10117
|
});
|
|
9939
10118
|
const newest = candidates.filter(
|
|
9940
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
10119
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE
|
|
9941
10120
|
).sort((a, b) => {
|
|
9942
10121
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
9943
10122
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -9945,7 +10124,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
9945
10124
|
if (!newest?.params.pubKey) return baseline;
|
|
9946
10125
|
try {
|
|
9947
10126
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
9948
|
-
return new
|
|
10127
|
+
return new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
9949
10128
|
} catch (e) {
|
|
9950
10129
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
9951
10130
|
return baseline;
|
|
@@ -9997,6 +10176,14 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
9997
10176
|
this._assetManager = new ReadonlyAssetManager(this.indexerProvider);
|
|
9998
10177
|
this.walletContractTimelocks = walletContractTimelocks && walletContractTimelocks.length > 0 ? dedupeTimelocks(walletContractTimelocks) : [this.offchainTapscript.options.csvTimelock];
|
|
9999
10178
|
}
|
|
10179
|
+
identity;
|
|
10180
|
+
network;
|
|
10181
|
+
onchainProvider;
|
|
10182
|
+
indexerProvider;
|
|
10183
|
+
dustAmount;
|
|
10184
|
+
walletRepository;
|
|
10185
|
+
contractRepository;
|
|
10186
|
+
delegateProvider;
|
|
10000
10187
|
_contractManager;
|
|
10001
10188
|
_contractManagerInitializing;
|
|
10002
10189
|
watcherConfig;
|
|
@@ -10239,7 +10426,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10239
10426
|
*/
|
|
10240
10427
|
static async setupWalletConfig(config, pubKey) {
|
|
10241
10428
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
10242
|
-
const arkProvider = config.arkProvider || new
|
|
10429
|
+
const arkProvider = config.arkProvider || new chunkHHV5FPC6_cjs.RestArkProvider(arkadeServerUrl);
|
|
10243
10430
|
let indexerProvider = config.indexerProvider;
|
|
10244
10431
|
if (!indexerProvider) {
|
|
10245
10432
|
let indexerUrl = config.indexerUrl;
|
|
@@ -10256,7 +10443,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10256
10443
|
indexerUrl = arkadeServerUrl;
|
|
10257
10444
|
}
|
|
10258
10445
|
}
|
|
10259
|
-
indexerProvider = new
|
|
10446
|
+
indexerProvider = new chunkHHV5FPC6_cjs.RestIndexerProvider(indexerUrl);
|
|
10260
10447
|
}
|
|
10261
10448
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
10262
10449
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
@@ -10265,7 +10452,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10265
10452
|
source: serverInfoSource,
|
|
10266
10453
|
lastOnlineAt: serverInfoLastOnlineAt
|
|
10267
10454
|
} = await resolveArkInfo(arkProvider, walletRepository);
|
|
10268
|
-
const network =
|
|
10455
|
+
const network = chunkL5ND2FJJ_cjs.getNetwork(info.network);
|
|
10269
10456
|
if ("descriptor" in config.identity) {
|
|
10270
10457
|
const descriptor = config.identity.descriptor;
|
|
10271
10458
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -10312,11 +10499,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10312
10499
|
serverPubKey,
|
|
10313
10500
|
csvTimelock: exitTimelock
|
|
10314
10501
|
};
|
|
10315
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
10316
|
-
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({
|
|
10317
10504
|
pubKey: base.hex.encode(pubKey),
|
|
10318
10505
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
10319
|
-
csvTimelock:
|
|
10506
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingTimelock).toString()
|
|
10320
10507
|
});
|
|
10321
10508
|
return {
|
|
10322
10509
|
arkProvider,
|
|
@@ -10650,9 +10837,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10650
10837
|
async getBoardingTapscripts(allowedSigners) {
|
|
10651
10838
|
const byScript = /* @__PURE__ */ new Map();
|
|
10652
10839
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
10653
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
10840
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
10654
10841
|
add(
|
|
10655
|
-
new
|
|
10842
|
+
new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
10656
10843
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
10657
10844
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
10658
10845
|
csvTimelock: boardingCsv
|
|
@@ -10667,7 +10854,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10667
10854
|
for (const c of boardingContracts) {
|
|
10668
10855
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
10669
10856
|
try {
|
|
10670
|
-
add(
|
|
10857
|
+
add(chunkRQSA7ADZ_cjs.BoardingContractHandler.createScript(c.params));
|
|
10671
10858
|
} catch (e) {
|
|
10672
10859
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
10673
10860
|
}
|
|
@@ -10705,7 +10892,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10705
10892
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
10706
10893
|
// not the wallet's current boarding timelock, which a signer
|
|
10707
10894
|
// rotation may have changed.
|
|
10708
|
-
csvTimelock:
|
|
10895
|
+
csvTimelock: chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
10709
10896
|
coins: utxos
|
|
10710
10897
|
});
|
|
10711
10898
|
}
|
|
@@ -10871,7 +11058,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10871
11058
|
});
|
|
10872
11059
|
for (const contract of contracts) {
|
|
10873
11060
|
if (map.has(contract.script)) continue;
|
|
10874
|
-
const handler =
|
|
11061
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
10875
11062
|
if (handler) {
|
|
10876
11063
|
const script = handler.createScript(contract.params);
|
|
10877
11064
|
map.set(contract.script, script);
|
|
@@ -10965,7 +11152,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10965
11152
|
watcherConfig: this.watcherConfig
|
|
10966
11153
|
});
|
|
10967
11154
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
10968
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11155
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
10969
11156
|
const baselineSigners = [
|
|
10970
11157
|
this.offchainTapscript.options.serverPubKey,
|
|
10971
11158
|
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
@@ -10973,8 +11160,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10973
11160
|
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
10974
11161
|
for (const serverPubKey of baselineSigners) {
|
|
10975
11162
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
10976
|
-
const csvTimelockStr =
|
|
10977
|
-
const defaultScript = new
|
|
11163
|
+
const csvTimelockStr = chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString();
|
|
11164
|
+
const defaultScript = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
10978
11165
|
pubKey: baselinePubkey,
|
|
10979
11166
|
serverPubKey,
|
|
10980
11167
|
csvTimelock
|
|
@@ -10995,7 +11182,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
10995
11182
|
});
|
|
10996
11183
|
}
|
|
10997
11184
|
if (delegatePubKey) {
|
|
10998
|
-
const delegateScript = new
|
|
11185
|
+
const delegateScript = new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({
|
|
10999
11186
|
pubKey: baselinePubkey,
|
|
11000
11187
|
serverPubKey,
|
|
11001
11188
|
delegatePubKey,
|
|
@@ -11019,9 +11206,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11019
11206
|
}
|
|
11020
11207
|
}
|
|
11021
11208
|
}
|
|
11022
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ??
|
|
11209
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11023
11210
|
for (const serverPubKey of baselineSigners) {
|
|
11024
|
-
const baselineBoarding = new
|
|
11211
|
+
const baselineBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11025
11212
|
pubKey: baselinePubkey,
|
|
11026
11213
|
serverPubKey,
|
|
11027
11214
|
csvTimelock: boardingCsvTimelock
|
|
@@ -11034,7 +11221,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
11034
11221
|
params: {
|
|
11035
11222
|
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
11036
11223
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
11037
|
-
csvTimelock:
|
|
11224
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
11038
11225
|
},
|
|
11039
11226
|
script: boardingScriptHex,
|
|
11040
11227
|
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
@@ -11103,6 +11290,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11103
11290
|
boardingPkScript: boardingTapscript.pkScript
|
|
11104
11291
|
});
|
|
11105
11292
|
}
|
|
11293
|
+
arkProvider;
|
|
11294
|
+
forfeitOutputScript;
|
|
11295
|
+
forfeitPubkey;
|
|
11106
11296
|
static MIN_FEE_RATE = 1;
|
|
11107
11297
|
// sats/vbyte
|
|
11108
11298
|
identity;
|
|
@@ -11254,25 +11444,25 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11254
11444
|
return this.getBoardingAddress();
|
|
11255
11445
|
}
|
|
11256
11446
|
const descriptor = await provider.getNextSigningDescriptor();
|
|
11257
|
-
const pubKey =
|
|
11258
|
-
const newBoarding = new
|
|
11447
|
+
const pubKey = chunkRQSA7ADZ_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
11448
|
+
const newBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11259
11449
|
...this._boardingTapscript.options,
|
|
11260
11450
|
pubKey
|
|
11261
11451
|
});
|
|
11262
|
-
const csvTimelock = newBoarding.options.csvTimelock ??
|
|
11452
|
+
const csvTimelock = newBoarding.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11263
11453
|
const manager = await this.getContractManager();
|
|
11264
11454
|
await manager.createContract({
|
|
11265
11455
|
type: "boarding",
|
|
11266
11456
|
params: {
|
|
11267
11457
|
pubKey: base.hex.encode(pubKey),
|
|
11268
11458
|
serverPubKey: base.hex.encode(newBoarding.options.serverPubKey),
|
|
11269
|
-
csvTimelock:
|
|
11459
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(csvTimelock).toString()
|
|
11270
11460
|
},
|
|
11271
11461
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11272
11462
|
address: newBoarding.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
11273
11463
|
state: "active",
|
|
11274
11464
|
metadata: {
|
|
11275
|
-
source:
|
|
11465
|
+
source: chunkRQSA7ADZ_cjs.WALLET_RECEIVE_SOURCE,
|
|
11276
11466
|
signingDescriptor: descriptor
|
|
11277
11467
|
}
|
|
11278
11468
|
});
|
|
@@ -11311,7 +11501,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11311
11501
|
const xonly = toXOnlyPubKey(newServerPubKey);
|
|
11312
11502
|
let newServerUnrollScript;
|
|
11313
11503
|
try {
|
|
11314
|
-
newServerUnrollScript =
|
|
11504
|
+
newServerUnrollScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
11315
11505
|
} catch (e) {
|
|
11316
11506
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11317
11507
|
}
|
|
@@ -11339,21 +11529,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11339
11529
|
const [currentBoardingRow] = await manager.getContracts({
|
|
11340
11530
|
script: currentBoardingScript
|
|
11341
11531
|
});
|
|
11342
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
11532
|
+
const newOffchain = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? new chunkRQSA7ADZ_cjs.DelegateVtxo.Script({
|
|
11343
11533
|
...this.offchainTapscript.options,
|
|
11344
11534
|
serverPubKey: xonly
|
|
11345
|
-
}) : new
|
|
11535
|
+
}) : new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11346
11536
|
...this.offchainTapscript.options,
|
|
11347
11537
|
serverPubKey: xonly
|
|
11348
11538
|
});
|
|
11349
|
-
const newBoarding = new
|
|
11539
|
+
const newBoarding = new chunkRQSA7ADZ_cjs.DefaultVtxo.Script({
|
|
11350
11540
|
...this._boardingTapscript.options,
|
|
11351
11541
|
serverPubKey: xonly
|
|
11352
11542
|
});
|
|
11353
|
-
const offchainCsv =
|
|
11543
|
+
const offchainCsv = chunkL5ND2FJJ_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
11354
11544
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
11355
11545
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
11356
|
-
if (newOffchain instanceof
|
|
11546
|
+
if (newOffchain instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script) {
|
|
11357
11547
|
await manager.createContract({
|
|
11358
11548
|
type: "delegate",
|
|
11359
11549
|
params: {
|
|
@@ -11381,13 +11571,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11381
11571
|
metadata: currentOffchainRow?.metadata
|
|
11382
11572
|
});
|
|
11383
11573
|
}
|
|
11384
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
11574
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
11385
11575
|
await manager.createContract({
|
|
11386
11576
|
type: "boarding",
|
|
11387
11577
|
params: {
|
|
11388
11578
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
11389
11579
|
serverPubKey: base.hex.encode(xonly),
|
|
11390
|
-
csvTimelock:
|
|
11580
|
+
csvTimelock: chunkL5ND2FJJ_cjs.timelockToSequence(boardingCsv).toString()
|
|
11391
11581
|
},
|
|
11392
11582
|
script: base.hex.encode(newBoarding.pkScript),
|
|
11393
11583
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -11482,7 +11672,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11482
11672
|
const hd = provider instanceof HDDescriptorProvider;
|
|
11483
11673
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
11484
11674
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
11485
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
11675
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkRQSA7ADZ_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
11486
11676
|
const arkInfo = await this.arkProvider.getInfo();
|
|
11487
11677
|
const currentSignerPubKey = toXOnlyPubKey(base.hex.decode(arkInfo.signerPubkey));
|
|
11488
11678
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
@@ -11501,7 +11691,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11501
11691
|
csvTimelocks: this.walletContractTimelocks,
|
|
11502
11692
|
// Boarding-exit CSV so the boarding handler can build its
|
|
11503
11693
|
// candidate script (distinct from the unilateral-exit matrix).
|
|
11504
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
11694
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkRQSA7ADZ_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
11505
11695
|
delegatePubKey
|
|
11506
11696
|
};
|
|
11507
11697
|
const result = await manager.scanContracts({
|
|
@@ -11605,7 +11795,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11605
11795
|
let serverUnrollScript;
|
|
11606
11796
|
try {
|
|
11607
11797
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
11608
|
-
serverUnrollScript =
|
|
11798
|
+
serverUnrollScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(raw);
|
|
11609
11799
|
} catch (e) {
|
|
11610
11800
|
throw new Error("Invalid checkpointTapscript from server");
|
|
11611
11801
|
}
|
|
@@ -11742,7 +11932,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11742
11932
|
inputs: params.selectedVtxos,
|
|
11743
11933
|
changeAmount: BigInt(changeAmount)
|
|
11744
11934
|
};
|
|
11745
|
-
const outputAddress =
|
|
11935
|
+
const outputAddress = chunkL5ND2FJJ_cjs.ArkAddress.decode(params.address);
|
|
11746
11936
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
11747
11937
|
const outputs = [
|
|
11748
11938
|
{
|
|
@@ -11795,13 +11985,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11795
11985
|
}
|
|
11796
11986
|
}
|
|
11797
11987
|
const offchainAddress = await this.getAddress();
|
|
11798
|
-
const offchainPkScript =
|
|
11988
|
+
const offchainPkScript = chunkL5ND2FJJ_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
11799
11989
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
11800
11990
|
if (!params) {
|
|
11801
11991
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
11802
11992
|
const estimator = new Estimator(fees.intentFee);
|
|
11803
11993
|
let amount = 0;
|
|
11804
|
-
const exitScript =
|
|
11994
|
+
const exitScript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.decode(
|
|
11805
11995
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
11806
11996
|
);
|
|
11807
11997
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -11867,7 +12057,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11867
12057
|
script: offchainOutputScript
|
|
11868
12058
|
});
|
|
11869
12059
|
output.amount -= BigInt(outputFee.satoshis);
|
|
11870
|
-
if (output.amount
|
|
12060
|
+
if (isSubdust(output.amount, this.dustAmount)) {
|
|
11871
12061
|
throw new Error("Output amount is below dust limit");
|
|
11872
12062
|
}
|
|
11873
12063
|
params = {
|
|
@@ -11881,7 +12071,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
11881
12071
|
for (const [index, output] of params.outputs.entries()) {
|
|
11882
12072
|
let script;
|
|
11883
12073
|
try {
|
|
11884
|
-
const addr =
|
|
12074
|
+
const addr = chunkL5ND2FJJ_cjs.ArkAddress.decode(output.address);
|
|
11885
12075
|
script = addr.pkScript;
|
|
11886
12076
|
hasOffchainOutputs = true;
|
|
11887
12077
|
} catch {
|
|
@@ -12115,7 +12305,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12115
12305
|
}
|
|
12116
12306
|
continue;
|
|
12117
12307
|
}
|
|
12118
|
-
if (isRecoverable(input) || isSubdust(input, this.dustAmount)) {
|
|
12308
|
+
if (isRecoverable(input) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
12119
12309
|
continue;
|
|
12120
12310
|
}
|
|
12121
12311
|
if (connectorsLeaves.length === 0) {
|
|
@@ -12143,7 +12333,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12143
12333
|
index: input.vout,
|
|
12144
12334
|
witnessUtxo: {
|
|
12145
12335
|
amount: BigInt(input.value),
|
|
12146
|
-
script:
|
|
12336
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12147
12337
|
},
|
|
12148
12338
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
12149
12339
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -12162,7 +12352,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12162
12352
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
12163
12353
|
{
|
|
12164
12354
|
index: 0,
|
|
12165
|
-
lookupScript:
|
|
12355
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12166
12356
|
}
|
|
12167
12357
|
]);
|
|
12168
12358
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -12220,7 +12410,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12220
12410
|
if (skip) {
|
|
12221
12411
|
return { skip };
|
|
12222
12412
|
}
|
|
12223
|
-
const sweepTapscript =
|
|
12413
|
+
const sweepTapscript = chunkL5ND2FJJ_cjs.CSVMultisigTapscript.encode({
|
|
12224
12414
|
timelock: {
|
|
12225
12415
|
value: event.batchExpiry,
|
|
12226
12416
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -12326,9 +12516,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12326
12516
|
...existing ?? {},
|
|
12327
12517
|
intentTxId,
|
|
12328
12518
|
registerProof: intent.proof,
|
|
12329
|
-
registerProofMessage:
|
|
12519
|
+
registerProofMessage: chunkHHV5FPC6_cjs.Intent.encodeMessage(intent.message),
|
|
12330
12520
|
deleteProof: deleteIntent.proof,
|
|
12331
|
-
deleteProofMessage:
|
|
12521
|
+
deleteProofMessage: chunkHHV5FPC6_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
12332
12522
|
intentVtxos: inputs.map((i) => ({
|
|
12333
12523
|
txid: i.txid,
|
|
12334
12524
|
vout: i.vout
|
|
@@ -12360,7 +12550,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12360
12550
|
try {
|
|
12361
12551
|
return await this.arkProvider.registerIntent(intent);
|
|
12362
12552
|
} catch (error) {
|
|
12363
|
-
if (error instanceof
|
|
12553
|
+
if (error instanceof chunkHHV5FPC6_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
12364
12554
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
12365
12555
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
12366
12556
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -12376,7 +12566,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12376
12566
|
expire_at: 0,
|
|
12377
12567
|
cosigners_public_keys: cosignerPubKeys
|
|
12378
12568
|
};
|
|
12379
|
-
const proof =
|
|
12569
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, outputs);
|
|
12380
12570
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12381
12571
|
return {
|
|
12382
12572
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12388,7 +12578,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12388
12578
|
type: "delete",
|
|
12389
12579
|
expire_at: 0
|
|
12390
12580
|
};
|
|
12391
|
-
const proof =
|
|
12581
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, []);
|
|
12392
12582
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12393
12583
|
return {
|
|
12394
12584
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12400,7 +12590,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12400
12590
|
type: "get-pending-tx",
|
|
12401
12591
|
expire_at: 0
|
|
12402
12592
|
};
|
|
12403
|
-
const proof =
|
|
12593
|
+
const proof = chunkHHV5FPC6_cjs.Intent.create(message, coins, []);
|
|
12404
12594
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
12405
12595
|
return {
|
|
12406
12596
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -12677,9 +12867,24 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12677
12867
|
}
|
|
12678
12868
|
const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
|
|
12679
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 = [];
|
|
12680
12882
|
if (hasAssets) {
|
|
12681
|
-
|
|
12682
|
-
|
|
12883
|
+
allExtPackets.push(createAssetPacket(assetInputs, recipients, changeReceiver));
|
|
12884
|
+
}
|
|
12885
|
+
allExtPackets.push(...customExtPackets);
|
|
12886
|
+
if (allExtPackets.length > 0) {
|
|
12887
|
+
outputs.push(Extension.create(allExtPackets).txOut());
|
|
12683
12888
|
}
|
|
12684
12889
|
const sentAmount = recipients.reduce((sum, r) => sum + r.amount, 0);
|
|
12685
12890
|
return this._submitOffchainSpend(selectedCoins, outputs, {
|
|
@@ -12816,74 +13021,54 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
12816
13021
|
);
|
|
12817
13022
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
12818
13023
|
index,
|
|
12819
|
-
lookupScript:
|
|
13024
|
+
lookupScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
12820
13025
|
}));
|
|
12821
|
-
const checkpointJobs = offchainTx.checkpoints.map(
|
|
12822
|
-
(c) => this.inputSigningJobsFromWitnessUtxos(c)
|
|
12823
|
-
);
|
|
12824
|
-
let signedVirtualTx;
|
|
12825
|
-
let userSignedCheckpoints;
|
|
12826
13026
|
const identity = this.identity;
|
|
12827
|
-
const
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
tx: offchainTx.arkTx.clone(),
|
|
12832
|
-
inputIndexes: arkTxJobs.map((j) => j.index)
|
|
12833
|
-
},
|
|
12834
|
-
...offchainTx.checkpoints.map((c, i) => ({
|
|
12835
|
-
tx: c.clone(),
|
|
12836
|
-
inputIndexes: checkpointJobs[i].map((j) => j.index)
|
|
12837
|
-
}))
|
|
12838
|
-
];
|
|
12839
|
-
const signed = await identity.signMultiple(requests);
|
|
12840
|
-
if (signed.length !== requests.length) {
|
|
12841
|
-
throw new Error(
|
|
12842
|
-
`signMultiple returned ${signed.length} transactions, expected ${requests.length}`
|
|
12843
|
-
);
|
|
12844
|
-
}
|
|
12845
|
-
const [firstSignedTx, ...signedCheckpoints] = signed;
|
|
12846
|
-
signedVirtualTx = firstSignedTx;
|
|
12847
|
-
userSignedCheckpoints = signedCheckpoints;
|
|
12848
|
-
} else {
|
|
12849
|
-
signedVirtualTx = await this._signerRouter.sign(offchainTx.arkTx, arkTxJobs);
|
|
12850
|
-
}
|
|
12851
|
-
await this.setPendingTxFlag(true);
|
|
12852
|
-
const { arkTxid, signedCheckpointTxs } = await this.arkProvider.submitTx(
|
|
12853
|
-
base.base64.encode(signedVirtualTx.toPSBT()),
|
|
12854
|
-
offchainTx.checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
12855
|
-
);
|
|
12856
|
-
let finalCheckpoints;
|
|
12857
|
-
if (userSignedCheckpoints) {
|
|
12858
|
-
if (signedCheckpointTxs.length !== userSignedCheckpoints.length) {
|
|
12859
|
-
throw new Error(
|
|
12860
|
-
`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)
|
|
12861
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
|
+
}
|
|
12862
13070
|
}
|
|
12863
|
-
|
|
12864
|
-
const serverSigned = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
12865
|
-
combineTapscriptSigs(userSignedCheckpoints[i], serverSigned);
|
|
12866
|
-
return base.base64.encode(serverSigned.toPSBT());
|
|
12867
|
-
});
|
|
12868
|
-
} else {
|
|
12869
|
-
finalCheckpoints = await Promise.all(
|
|
12870
|
-
signedCheckpointTxs.map(async (c) => {
|
|
12871
|
-
const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
|
|
12872
|
-
const signedCheckpoint = await this._signerRouter.sign(
|
|
12873
|
-
tx,
|
|
12874
|
-
this.inputSigningJobsFromWitnessUtxos(tx)
|
|
12875
|
-
);
|
|
12876
|
-
return base.base64.encode(signedCheckpoint.toPSBT());
|
|
12877
|
-
})
|
|
12878
|
-
);
|
|
12879
|
-
}
|
|
12880
|
-
await this.arkProvider.finalizeTx(arkTxid, finalCheckpoints);
|
|
12881
|
-
try {
|
|
12882
|
-
await this.setPendingTxFlag(false);
|
|
12883
|
-
} catch (error) {
|
|
12884
|
-
console.error("Failed to clear pending tx flag:", error);
|
|
12885
|
-
}
|
|
12886
|
-
return { arkTxid, signedCheckpointTxs };
|
|
13071
|
+
});
|
|
12887
13072
|
}
|
|
12888
13073
|
// mark virtual outputs as spent, save change outputs if any.
|
|
12889
13074
|
// `offchainTapscript` and `serverPubKey` are the epoch snapshot the
|
|
@@ -13049,7 +13234,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
13049
13234
|
} else {
|
|
13050
13235
|
let sourceAddress;
|
|
13051
13236
|
try {
|
|
13052
|
-
sourceAddress =
|
|
13237
|
+
sourceAddress = chunkL5ND2FJJ_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
13053
13238
|
this.network
|
|
13054
13239
|
);
|
|
13055
13240
|
} catch {
|
|
@@ -13194,6 +13379,8 @@ var MessageBus = class {
|
|
|
13194
13379
|
this.debug = debug;
|
|
13195
13380
|
this.buildServicesFn = buildServices ?? this.buildServices.bind(this);
|
|
13196
13381
|
}
|
|
13382
|
+
walletRepository;
|
|
13383
|
+
contractRepository;
|
|
13197
13384
|
handlers;
|
|
13198
13385
|
tickIntervalMs;
|
|
13199
13386
|
messageTimeoutMs;
|
|
@@ -13358,7 +13545,7 @@ var MessageBus = class {
|
|
|
13358
13545
|
this.initialized = true;
|
|
13359
13546
|
}
|
|
13360
13547
|
async buildServices(config) {
|
|
13361
|
-
const arkProvider = new
|
|
13548
|
+
const arkProvider = new chunkHHV5FPC6_cjs.RestArkProvider(config.arkServer.url);
|
|
13362
13549
|
const storage = {
|
|
13363
13550
|
walletRepository: this.walletRepository,
|
|
13364
13551
|
contractRepository: this.contractRepository
|
|
@@ -13695,6 +13882,7 @@ var Ramps = class {
|
|
|
13695
13882
|
constructor(wallet) {
|
|
13696
13883
|
this.wallet = wallet;
|
|
13697
13884
|
}
|
|
13885
|
+
wallet;
|
|
13698
13886
|
/**
|
|
13699
13887
|
* Onboard boarding inputs.
|
|
13700
13888
|
*
|
|
@@ -13740,7 +13928,7 @@ var Ramps = class {
|
|
|
13740
13928
|
}
|
|
13741
13929
|
amount = amount ?? totalAmount;
|
|
13742
13930
|
const offchainAddress = await this.wallet.getAddress();
|
|
13743
|
-
const offchainAddr =
|
|
13931
|
+
const offchainAddr = chunkL5ND2FJJ_cjs.ArkAddress.decode(offchainAddress);
|
|
13744
13932
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
13745
13933
|
const outputFee = estimator.evalOffchainOutput({
|
|
13746
13934
|
amount,
|
|
@@ -13838,7 +14026,7 @@ var Ramps = class {
|
|
|
13838
14026
|
let destinationScript;
|
|
13839
14027
|
for (const networkName of networkNames) {
|
|
13840
14028
|
try {
|
|
13841
|
-
const network =
|
|
14029
|
+
const network = chunkL5ND2FJJ_cjs.networks[networkName];
|
|
13842
14030
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
13843
14031
|
destinationScript = btcSigner.OutScript.encode(addr);
|
|
13844
14032
|
break;
|
|
@@ -14523,7 +14711,7 @@ var WalletMessageHandler = class {
|
|
|
14523
14711
|
// Wallet methods
|
|
14524
14712
|
async handleInitWallet({ payload }) {
|
|
14525
14713
|
const { arkServerUrl } = payload;
|
|
14526
|
-
this.indexerProvider = new
|
|
14714
|
+
this.indexerProvider = new chunkHHV5FPC6_cjs.RestIndexerProvider(arkServerUrl);
|
|
14527
14715
|
await this.onWalletInitialized();
|
|
14528
14716
|
}
|
|
14529
14717
|
async handleGetBalance() {
|
|
@@ -15041,6 +15229,8 @@ var ServiceWorkerReadonlyAssetManager = class {
|
|
|
15041
15229
|
this.sendMessage = sendMessage;
|
|
15042
15230
|
this.messageTag = messageTag;
|
|
15043
15231
|
}
|
|
15232
|
+
sendMessage;
|
|
15233
|
+
messageTag;
|
|
15044
15234
|
async getAssetDetails(assetId) {
|
|
15045
15235
|
const message = {
|
|
15046
15236
|
tag: this.messageTag,
|
|
@@ -15125,6 +15315,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
15125
15315
|
messageTag
|
|
15126
15316
|
);
|
|
15127
15317
|
}
|
|
15318
|
+
serviceWorker;
|
|
15319
|
+
messageTag;
|
|
15128
15320
|
walletRepository;
|
|
15129
15321
|
contractRepository;
|
|
15130
15322
|
identity;
|
|
@@ -15877,6 +16069,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
15877
16069
|
);
|
|
15878
16070
|
this.hasDelegate = hasDelegate;
|
|
15879
16071
|
}
|
|
16072
|
+
serviceWorker;
|
|
15880
16073
|
walletRepository;
|
|
15881
16074
|
contractRepository;
|
|
15882
16075
|
identity;
|
|
@@ -16258,6 +16451,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16258
16451
|
this.onchainP2TR = onchainP2TR;
|
|
16259
16452
|
this.provider = provider;
|
|
16260
16453
|
}
|
|
16454
|
+
identity;
|
|
16261
16455
|
static MIN_FEE_RATE = 1;
|
|
16262
16456
|
// sat/vbyte
|
|
16263
16457
|
onchainP2TR;
|
|
@@ -16272,12 +16466,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16272
16466
|
* @returns Configured onchain wallet
|
|
16273
16467
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
16274
16468
|
*/
|
|
16275
|
-
static async create(identity, networkName =
|
|
16469
|
+
static async create(identity, networkName = chunkL5ND2FJJ_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
16276
16470
|
const pubkey = await identity.xOnlyPublicKey();
|
|
16277
16471
|
if (!pubkey) {
|
|
16278
16472
|
throw new Error("Invalid configured public key");
|
|
16279
16473
|
}
|
|
16280
|
-
const network =
|
|
16474
|
+
const network = chunkL5ND2FJJ_cjs.getNetwork(networkName);
|
|
16281
16475
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
16282
16476
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
16283
16477
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -16383,7 +16577,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16383
16577
|
if (!inputs) {
|
|
16384
16578
|
throw new Error("Fee estimation failed");
|
|
16385
16579
|
}
|
|
16386
|
-
let tx = new
|
|
16580
|
+
let tx = new chunkHHV5FPC6_cjs.Transaction();
|
|
16387
16581
|
for (const input of inputs) {
|
|
16388
16582
|
tx.addInput({
|
|
16389
16583
|
txid: input.txid,
|
|
@@ -16441,7 +16635,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
16441
16635
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
16442
16636
|
*/
|
|
16443
16637
|
async bumpAnchor(parentHex, feeRate) {
|
|
16444
|
-
const parent =
|
|
16638
|
+
const parent = chunkHHV5FPC6_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
16445
16639
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
16446
16640
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
16447
16641
|
return [parent.hex, child.hex];
|
|
@@ -16559,6 +16753,8 @@ var WsElectrumChainSource = class {
|
|
|
16559
16753
|
this.ws = ws;
|
|
16560
16754
|
this.network = network;
|
|
16561
16755
|
}
|
|
16756
|
+
ws;
|
|
16757
|
+
network;
|
|
16562
16758
|
// Cached chain tip kept fresh by the headers subscription. Initialized
|
|
16563
16759
|
// lazily on first call to subscribeHeaders().
|
|
16564
16760
|
cachedTip = null;
|
|
@@ -16841,6 +17037,8 @@ var ElectrumOnchainProvider = class {
|
|
|
16841
17037
|
this.network = network;
|
|
16842
17038
|
this.chain = new WsElectrumChainSource(ws, network);
|
|
16843
17039
|
}
|
|
17040
|
+
ws;
|
|
17041
|
+
network;
|
|
16844
17042
|
chain;
|
|
16845
17043
|
async getCoins(address) {
|
|
16846
17044
|
const script = this.encodeAddress(address);
|
|
@@ -17202,7 +17400,7 @@ exports.BIP322 = void 0;
|
|
|
17202
17400
|
async function sign2(message, identity, network) {
|
|
17203
17401
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
17204
17402
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
17205
|
-
const toSpend =
|
|
17403
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
17206
17404
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
17207
17405
|
const signed = await identity.sign(toSign, [0]);
|
|
17208
17406
|
signed.finalizeIdx(0);
|
|
@@ -17260,7 +17458,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
17260
17458
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
17261
17459
|
return false;
|
|
17262
17460
|
}
|
|
17263
|
-
const toSpend =
|
|
17461
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17264
17462
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
17265
17463
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
17266
17464
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -17281,7 +17479,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
17281
17479
|
}
|
|
17282
17480
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
17283
17481
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
17284
|
-
const toSpend =
|
|
17482
|
+
const toSpend = chunkHHV5FPC6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
17285
17483
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
17286
17484
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
17287
17485
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -17334,7 +17532,7 @@ function encodeCompactSize(n) {
|
|
|
17334
17532
|
return buf;
|
|
17335
17533
|
}
|
|
17336
17534
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
17337
|
-
const tx = new
|
|
17535
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 0 });
|
|
17338
17536
|
tx.addInput({
|
|
17339
17537
|
txid: toSpend.id,
|
|
17340
17538
|
index: 0,
|
|
@@ -17348,12 +17546,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
17348
17546
|
});
|
|
17349
17547
|
tx.addOutput({
|
|
17350
17548
|
amount: 0n,
|
|
17351
|
-
script:
|
|
17549
|
+
script: chunkHHV5FPC6_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17352
17550
|
});
|
|
17353
17551
|
return tx;
|
|
17354
17552
|
}
|
|
17355
17553
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
17356
|
-
const tx = new
|
|
17554
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 0 });
|
|
17357
17555
|
tx.addInput({
|
|
17358
17556
|
txid: toSpend.id,
|
|
17359
17557
|
index: 0,
|
|
@@ -17365,12 +17563,138 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
17365
17563
|
});
|
|
17366
17564
|
tx.addOutput({
|
|
17367
17565
|
amount: 0n,
|
|
17368
|
-
script:
|
|
17566
|
+
script: chunkHHV5FPC6_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
17369
17567
|
});
|
|
17370
17568
|
return tx;
|
|
17371
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
|
+
};
|
|
17372
17696
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
17373
|
-
const tx =
|
|
17697
|
+
const tx = chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
17374
17698
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
17375
17699
|
const input = tx.getInput(0);
|
|
17376
17700
|
if (!input) {
|
|
@@ -17394,16 +17718,17 @@ var ExitPathError = class extends Error {
|
|
|
17394
17718
|
this.reason = reason;
|
|
17395
17719
|
this.name = "ExitPathError";
|
|
17396
17720
|
}
|
|
17721
|
+
reason;
|
|
17397
17722
|
};
|
|
17398
17723
|
function delayWeight(sequence) {
|
|
17399
|
-
const t =
|
|
17724
|
+
const t = chunkL5ND2FJJ_cjs.sequenceToTimelock(sequence);
|
|
17400
17725
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
17401
17726
|
}
|
|
17402
17727
|
async function resolveUnilateralPath(params) {
|
|
17403
17728
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
17404
17729
|
const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
|
|
17405
17730
|
if (contract) {
|
|
17406
|
-
const handler =
|
|
17731
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
17407
17732
|
if (!handler) {
|
|
17408
17733
|
throw new ExitPathError(
|
|
17409
17734
|
"no-handler",
|
|
@@ -17426,12 +17751,12 @@ async function resolveUnilateralPath(params) {
|
|
|
17426
17751
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
17427
17752
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
17428
17753
|
}
|
|
17429
|
-
const decoded =
|
|
17754
|
+
const decoded = chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
17430
17755
|
let best;
|
|
17431
17756
|
for (const exit of decoded.exitPaths()) {
|
|
17432
17757
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
17433
17758
|
if (!leaf) continue;
|
|
17434
|
-
const sequence =
|
|
17759
|
+
const sequence = chunkL5ND2FJJ_cjs.timelockToSequence(exit.params.timelock);
|
|
17435
17760
|
const weight = delayWeight(sequence);
|
|
17436
17761
|
if (!best || weight < best.weight) {
|
|
17437
17762
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -17477,6 +17802,11 @@ exports.Unroll = void 0;
|
|
|
17477
17802
|
this.indexer = indexer;
|
|
17478
17803
|
this.virtualTxRepository = virtualTxRepository;
|
|
17479
17804
|
}
|
|
17805
|
+
toUnroll;
|
|
17806
|
+
bumper;
|
|
17807
|
+
explorer;
|
|
17808
|
+
indexer;
|
|
17809
|
+
virtualTxRepository;
|
|
17480
17810
|
/** Create an unroll session by loading the virtual output chain from the indexer. */
|
|
17481
17811
|
static async create(toUnroll, bumper, explorer, indexer, virtualTxRepository) {
|
|
17482
17812
|
const { chain } = await indexer.getVtxoChain(toUnroll);
|
|
@@ -17612,14 +17942,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17612
17942
|
}
|
|
17613
17943
|
const resolved = await resolveUnilateralPath({
|
|
17614
17944
|
vtxo,
|
|
17615
|
-
scriptHex: base.hex.encode(
|
|
17945
|
+
scriptHex: base.hex.encode(chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
17616
17946
|
contractRepository: wallet.contractRepository,
|
|
17617
17947
|
walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
|
|
17618
17948
|
currentTime: Date.now()
|
|
17619
17949
|
});
|
|
17620
17950
|
const spendingLeaf = resolved.selection.leaf;
|
|
17621
17951
|
const sequence = resolved.selection.sequence;
|
|
17622
|
-
const timelock =
|
|
17952
|
+
const timelock = chunkL5ND2FJJ_cjs.sequenceToTimelock(sequence);
|
|
17623
17953
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
17624
17954
|
if (!elapsed) {
|
|
17625
17955
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -17632,7 +17962,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17632
17962
|
sequence,
|
|
17633
17963
|
witnessUtxo: {
|
|
17634
17964
|
amount: BigInt(vtxo.value),
|
|
17635
|
-
script:
|
|
17965
|
+
script: chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
17636
17966
|
},
|
|
17637
17967
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
17638
17968
|
});
|
|
@@ -17642,7 +17972,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
17642
17972
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
17643
17973
|
);
|
|
17644
17974
|
}
|
|
17645
|
-
const tx = new
|
|
17975
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
17646
17976
|
for (const input of inputs) {
|
|
17647
17977
|
tx.addInput(input);
|
|
17648
17978
|
}
|
|
@@ -17709,7 +18039,7 @@ async function buildSignedSweep(params) {
|
|
|
17709
18039
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
17710
18040
|
);
|
|
17711
18041
|
}
|
|
17712
|
-
const tx = new
|
|
18042
|
+
const tx = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
17713
18043
|
tx.addInput({
|
|
17714
18044
|
txid: vtxo.txid,
|
|
17715
18045
|
index: vtxo.vout,
|
|
@@ -17734,7 +18064,7 @@ async function buildSignedSweep(params) {
|
|
|
17734
18064
|
finalScriptWitness: [
|
|
17735
18065
|
tapScriptSig[0][1],
|
|
17736
18066
|
...path.extraWitness,
|
|
17737
|
-
|
|
18067
|
+
chunkL5ND2FJJ_cjs.scriptFromTapLeafScript(path.leaf),
|
|
17738
18068
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
17739
18069
|
]
|
|
17740
18070
|
});
|
|
@@ -17779,7 +18109,7 @@ async function selectExitVtxos(opts) {
|
|
|
17779
18109
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
17780
18110
|
);
|
|
17781
18111
|
}
|
|
17782
|
-
const handler =
|
|
18112
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(contract.type);
|
|
17783
18113
|
if (!handler) {
|
|
17784
18114
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
17785
18115
|
}
|
|
@@ -17809,7 +18139,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17809
18139
|
if (pendingNodes.length > 0) {
|
|
17810
18140
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
17811
18141
|
for (const psbt of txs) {
|
|
17812
|
-
psbts.set(
|
|
18142
|
+
psbts.set(chunkHHV5FPC6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
17813
18143
|
}
|
|
17814
18144
|
}
|
|
17815
18145
|
const childVsize = Number(
|
|
@@ -17845,7 +18175,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17845
18175
|
try {
|
|
17846
18176
|
const resolved = await resolveUnilateralPath({
|
|
17847
18177
|
vtxo,
|
|
17848
|
-
scriptHex: base.hex.encode(
|
|
18178
|
+
scriptHex: base.hex.encode(chunkL5ND2FJJ_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
17849
18179
|
contractRepository: wallet.contractRepository,
|
|
17850
18180
|
walletPubKeyHex,
|
|
17851
18181
|
currentTime: Date.now()
|
|
@@ -17864,7 +18194,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
17864
18194
|
});
|
|
17865
18195
|
continue;
|
|
17866
18196
|
}
|
|
17867
|
-
const t =
|
|
18197
|
+
const t = chunkL5ND2FJJ_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
17868
18198
|
const delay = { type: t.type, value: Number(t.value) };
|
|
17869
18199
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
17870
18200
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -17957,6 +18287,8 @@ var Executor = class {
|
|
|
17957
18287
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
17958
18288
|
this.feeWallet = opts?.feeWallet;
|
|
17959
18289
|
}
|
|
18290
|
+
pkg;
|
|
18291
|
+
provider;
|
|
17960
18292
|
pollIntervalMs;
|
|
17961
18293
|
feeWallet;
|
|
17962
18294
|
sleep() {
|
|
@@ -18169,7 +18501,7 @@ async function prepare(opts) {
|
|
|
18169
18501
|
txid: sweep.vtxo.txid,
|
|
18170
18502
|
vout: sweep.vtxo.vout,
|
|
18171
18503
|
value: sweep.vtxo.value,
|
|
18172
|
-
pkScript:
|
|
18504
|
+
pkScript: chunkL5ND2FJJ_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
18173
18505
|
},
|
|
18174
18506
|
path: sweep.resolved.selection,
|
|
18175
18507
|
outputAddress: opts.sweepAddress,
|
|
@@ -18254,7 +18586,7 @@ async function prepare(opts) {
|
|
|
18254
18586
|
if (newFee <= splitterFee) break;
|
|
18255
18587
|
splitterFee = newFee;
|
|
18256
18588
|
}
|
|
18257
|
-
const splitter = new
|
|
18589
|
+
const splitter = new chunkHHV5FPC6_cjs.Transaction({ version: 2 });
|
|
18258
18590
|
for (const coin of selected.inputs) {
|
|
18259
18591
|
splitter.addInput({
|
|
18260
18592
|
txid: coin.txid,
|
|
@@ -18393,6 +18725,656 @@ var UnilateralExit = {
|
|
|
18393
18725
|
prepare,
|
|
18394
18726
|
Executor
|
|
18395
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
|
+
}
|
|
18396
19378
|
var ARKCONTRACT_PREFIX = "arkcontract";
|
|
18397
19379
|
function encodeArkContract(contract) {
|
|
18398
19380
|
const params = new URLSearchParams();
|
|
@@ -18418,7 +19400,7 @@ function decodeArkContract(encoded) {
|
|
|
18418
19400
|
}
|
|
18419
19401
|
function contractFromArkContract(encoded, options = {}) {
|
|
18420
19402
|
const parsed = decodeArkContract(encoded);
|
|
18421
|
-
const handler =
|
|
19403
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.get(parsed.type);
|
|
18422
19404
|
if (!handler) {
|
|
18423
19405
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
18424
19406
|
}
|
|
@@ -18432,9 +19414,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
18432
19414
|
metadata: options.metadata
|
|
18433
19415
|
};
|
|
18434
19416
|
}
|
|
18435
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
19417
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkL5ND2FJJ_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
18436
19418
|
const parsed = decodeArkContract(encoded);
|
|
18437
|
-
const handler =
|
|
19419
|
+
const handler = chunkRQSA7ADZ_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
18438
19420
|
const params = parsed.data;
|
|
18439
19421
|
const vtxoScript = handler.createScript(params);
|
|
18440
19422
|
return {
|
|
@@ -18452,6 +19434,7 @@ function isArkContract(str) {
|
|
|
18452
19434
|
return str.startsWith(ARKCONTRACT_PREFIX + "=");
|
|
18453
19435
|
}
|
|
18454
19436
|
|
|
19437
|
+
exports.ARKADE_MAGIC = ARKADE_MAGIC;
|
|
18455
19438
|
exports.ActivityRegistry = ActivityRegistry;
|
|
18456
19439
|
exports.ArkNote = ArkNote;
|
|
18457
19440
|
exports.AssetManager = AssetManager;
|
|
@@ -18471,8 +19454,11 @@ exports.ELECTRUM_TCP_HOST = ELECTRUM_TCP_HOST;
|
|
|
18471
19454
|
exports.ELECTRUM_WS_URL = ELECTRUM_WS_URL;
|
|
18472
19455
|
exports.ESPLORA_URL = ESPLORA_URL;
|
|
18473
19456
|
exports.ElectrumOnchainProvider = ElectrumOnchainProvider;
|
|
19457
|
+
exports.EmulatorPacket = EmulatorPacket;
|
|
18474
19458
|
exports.EsploraProvider = EsploraProvider;
|
|
18475
19459
|
exports.Estimator = Estimator;
|
|
19460
|
+
exports.Extension = Extension;
|
|
19461
|
+
exports.ExtensionNotFoundError = ExtensionNotFoundError;
|
|
18476
19462
|
exports.HDDescriptorProvider = HDDescriptorProvider;
|
|
18477
19463
|
exports.INTENT_TERMINAL_STATES = INTENT_TERMINAL_STATES;
|
|
18478
19464
|
exports.InMemoryContractRepository = InMemoryContractRepository;
|
|
@@ -18501,6 +19487,7 @@ exports.ReadonlyWallet = ReadonlyWallet;
|
|
|
18501
19487
|
exports.ReadonlyWalletError = ReadonlyWalletError;
|
|
18502
19488
|
exports.RestDelegateProvider = RestDelegateProvider;
|
|
18503
19489
|
exports.RestDelegatorProvider = RestDelegatorProvider;
|
|
19490
|
+
exports.RestEmulatorProvider = RestEmulatorProvider;
|
|
18504
19491
|
exports.SeedIdentity = SeedIdentity;
|
|
18505
19492
|
exports.ServiceWorkerReadonlyWallet = ServiceWorkerReadonlyWallet;
|
|
18506
19493
|
exports.ServiceWorkerTimeoutError = ServiceWorkerTimeoutError;
|
|
@@ -18510,12 +19497,14 @@ exports.TxTree = TxTree;
|
|
|
18510
19497
|
exports.TxType = TxType;
|
|
18511
19498
|
exports.TxWeightEstimator = TxWeightEstimator;
|
|
18512
19499
|
exports.UnilateralExit = UnilateralExit;
|
|
19500
|
+
exports.UnknownPacket = UnknownPacket;
|
|
18513
19501
|
exports.VtxoManager = VtxoManager;
|
|
18514
19502
|
exports.Wallet = Wallet2;
|
|
18515
19503
|
exports.WalletMessageHandler = WalletMessageHandler;
|
|
18516
19504
|
exports.WalletNotInitializedError = WalletNotInitializedError;
|
|
18517
19505
|
exports.WalletRepositoryImpl = WalletRepositoryImpl;
|
|
18518
19506
|
exports.WsElectrumChainSource = WsElectrumChainSource;
|
|
19507
|
+
exports.arkade_exports = arkade_exports;
|
|
18519
19508
|
exports.assertIntentIdUnique = assertIntentIdUnique;
|
|
18520
19509
|
exports.boardingResolver = boardingResolver;
|
|
18521
19510
|
exports.buildForfeitTx = buildForfeitTx;
|
|
@@ -18526,6 +19515,7 @@ exports.closeDatabase = closeDatabase;
|
|
|
18526
19515
|
exports.combineTapscriptSigs = combineTapscriptSigs;
|
|
18527
19516
|
exports.contractFromArkContract = contractFromArkContract;
|
|
18528
19517
|
exports.contractFromArkContractWithAddress = contractFromArkContractWithAddress;
|
|
19518
|
+
exports.createAssetPacket = createAssetPacket;
|
|
18529
19519
|
exports.createDefaultActivityRegistry = createDefaultActivityRegistry;
|
|
18530
19520
|
exports.createExitChainResolver = createExitChainResolver;
|
|
18531
19521
|
exports.decodeArkContract = decodeArkContract;
|
|
@@ -18560,6 +19550,8 @@ exports.requiresMigration = requiresMigration;
|
|
|
18560
19550
|
exports.rollbackMigration = rollbackMigration;
|
|
18561
19551
|
exports.saveVtxosForContract = saveVtxosForContract;
|
|
18562
19552
|
exports.scriptFromArkAddress = scriptFromArkAddress;
|
|
19553
|
+
exports.selectCoinsWithAsset = selectCoinsWithAsset;
|
|
19554
|
+
exports.selectVirtualCoins = selectVirtualCoins;
|
|
18563
19555
|
exports.serializeAssets = serializeAssets;
|
|
18564
19556
|
exports.serializeExitPackage = serializeExitPackage;
|
|
18565
19557
|
exports.serializeUtxo = serializeUtxo;
|
|
@@ -18572,5 +19564,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
18572
19564
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
18573
19565
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
18574
19566
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
18575
|
-
//# sourceMappingURL=chunk-
|
|
18576
|
-
//# sourceMappingURL=chunk-
|
|
19567
|
+
//# sourceMappingURL=chunk-WTTLIFS7.cjs.map
|
|
19568
|
+
//# sourceMappingURL=chunk-WTTLIFS7.cjs.map
|