@arkade-os/swap 0.0.2 → 0.0.4
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/README.md +115 -83
- package/dist/{chunk-C5P7R7JT.js → chunk-DLM6BVTB.js} +80 -252
- package/dist/index.cjs +163 -303
- package/dist/index.d.cts +207 -22
- package/dist/index.d.ts +207 -22
- package/dist/index.js +95 -76
- package/dist/nostr.cjs +10 -14
- package/dist/nostr.d.cts +1 -2
- package/dist/nostr.d.ts +1 -2
- package/dist/nostr.js +2 -2
- package/dist/{rfq-CRgIOQ_y.d.cts → rfq-DjZlesr4.d.cts} +32 -352
- package/dist/{rfq-CRgIOQ_y.d.ts → rfq-DjZlesr4.d.ts} +32 -352
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -16,31 +16,24 @@ import {
|
|
|
16
16
|
ONCHAIN_RECEIVE_PAIR,
|
|
17
17
|
ONCHAIN_SECONDS_PER_BLOCK,
|
|
18
18
|
ONCHAIN_SEND_PAIR,
|
|
19
|
-
RFQ_PREIMAGE_TAG,
|
|
20
19
|
RFQ_TERMINAL_STATES,
|
|
21
|
-
RefundNotLocallyPossibleError,
|
|
22
20
|
SWAP_LOCKUP_CONTRACT_KIND,
|
|
23
21
|
SWAP_LOCKUP_CONTRACT_LABEL,
|
|
24
22
|
SWAP_LOCKUP_CONTRACT_TYPE,
|
|
25
23
|
SwapRefusal,
|
|
26
|
-
adoptSwapDescriptor,
|
|
27
24
|
arkadeSwapRequest,
|
|
28
25
|
assertFundable,
|
|
29
26
|
assertReceivable,
|
|
30
27
|
awaitOnchainFill,
|
|
31
28
|
buildHtlcClaim,
|
|
32
29
|
buildHtlcRefund,
|
|
33
|
-
buildPreimageMessage,
|
|
34
30
|
claimOnchainFill,
|
|
35
31
|
classifyOnchainHtlc,
|
|
36
32
|
deriveLightningReceive,
|
|
37
33
|
deriveOnchainReceive,
|
|
38
34
|
deriveOnchainSend,
|
|
39
|
-
derivePreimage,
|
|
40
|
-
deriveSwapSecrets,
|
|
41
35
|
extractPreimage,
|
|
42
36
|
httpTransport,
|
|
43
|
-
isDeterministicSigner,
|
|
44
37
|
lightningReceiveRequest,
|
|
45
38
|
lightningSendRequest,
|
|
46
39
|
lightningSendVtxoScript,
|
|
@@ -51,8 +44,6 @@ import {
|
|
|
51
44
|
onchainReceiveRequest,
|
|
52
45
|
onchainSendRequest,
|
|
53
46
|
paymentHashOf,
|
|
54
|
-
preimageForRfqSecrets,
|
|
55
|
-
randomSwapSecrets,
|
|
56
47
|
receiveVtxoScript,
|
|
57
48
|
registerLockupContract,
|
|
58
49
|
relayTransport,
|
|
@@ -61,21 +52,16 @@ import {
|
|
|
61
52
|
requestOnchainReceive,
|
|
62
53
|
requestOnchainSend,
|
|
63
54
|
rfqPair,
|
|
64
|
-
rfqSecretsOfRecord,
|
|
65
|
-
rfqSecretsToRecord,
|
|
66
55
|
sealClaimPacket,
|
|
67
|
-
senderIdentityForRfqSecrets,
|
|
68
|
-
senderIdentityForSwapRecord,
|
|
69
|
-
senderPubkeyForRfqSecrets,
|
|
70
56
|
unilateralClaimDelay,
|
|
71
57
|
unilateralRefundDelay,
|
|
72
58
|
unilateralRefundWithoutReceiverDelay,
|
|
73
59
|
verifyLockupAddress,
|
|
74
60
|
verifyReceiveInvoice
|
|
75
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-DLM6BVTB.js";
|
|
76
62
|
|
|
77
63
|
// src/offer.ts
|
|
78
|
-
import { hex } from "@scure/base";
|
|
64
|
+
import { hex as hex2 } from "@scure/base";
|
|
79
65
|
import { concatBytes } from "@scure/btc-signer/utils.js";
|
|
80
66
|
import {
|
|
81
67
|
ArkAddress,
|
|
@@ -83,7 +69,9 @@ import {
|
|
|
83
69
|
RestIndexerProvider,
|
|
84
70
|
arkade,
|
|
85
71
|
asset,
|
|
86
|
-
getNetwork
|
|
72
|
+
getNetwork,
|
|
73
|
+
resolveEmulatorPubkey,
|
|
74
|
+
toXOnlySignerHex
|
|
87
75
|
} from "@arkade-os/sdk";
|
|
88
76
|
|
|
89
77
|
// src/swap-want-asset.program.json
|
|
@@ -214,6 +202,7 @@ async function retireSettledOfferContracts(manager, swaps) {
|
|
|
214
202
|
}
|
|
215
203
|
|
|
216
204
|
// src/store.ts
|
|
205
|
+
import { hex } from "@scure/base";
|
|
217
206
|
var BTC_ASSET_ID = "btc";
|
|
218
207
|
var byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
219
208
|
var getAssetSwapsOrThrow = async (repository) => {
|
|
@@ -266,6 +255,10 @@ var updateAssetSwapBestEffort = async (repository, id, changes) => {
|
|
|
266
255
|
return { swaps, persisted: false };
|
|
267
256
|
}
|
|
268
257
|
};
|
|
258
|
+
var swapSecretsToRecord = (secrets) => ({
|
|
259
|
+
signingDescriptor: secrets.descriptor,
|
|
260
|
+
..."mustPersistPreimage" in secrets && secrets.mustPersistPreimage ? { preimageHex: hex.encode(secrets.preimage) } : {}
|
|
261
|
+
});
|
|
269
262
|
|
|
270
263
|
// src/offer.ts
|
|
271
264
|
var swapPrograms = {
|
|
@@ -311,14 +304,6 @@ var FIELDS = {
|
|
|
311
304
|
offerAsset: { tag: 11, width: void 0 }
|
|
312
305
|
};
|
|
313
306
|
var NAMES = Object.fromEntries(Object.entries(FIELDS).map(([k, f]) => [f.tag, k]));
|
|
314
|
-
var XONLY_LEN = 32;
|
|
315
|
-
var xOnly = (key, label) => {
|
|
316
|
-
if (key.length === XONLY_LEN) return key;
|
|
317
|
-
if (key.length !== 33 || key[0] !== 2 && key[0] !== 3) {
|
|
318
|
-
throw new Error(`${label} is not a compressed or x-only public key`);
|
|
319
|
-
}
|
|
320
|
-
return key.slice(1);
|
|
321
|
-
};
|
|
322
307
|
function tlv(type, value) {
|
|
323
308
|
if (value.length > 65535) throw new Error("TLV value exceeds the u16 length field");
|
|
324
309
|
return concatBytes(Uint8Array.of(type, value.length >> 8 & 255, value.length & 255), value);
|
|
@@ -411,16 +396,16 @@ async function registerOfferContract(wallet, arkServerUrl, network, binding, ser
|
|
|
411
396
|
contractManager
|
|
412
397
|
});
|
|
413
398
|
const contract = new arkade.ArkadeContract(client, program, args, keys);
|
|
414
|
-
if (
|
|
399
|
+
if (hex2.encode(contract.pkScript) !== hex2.encode(expectedPkScript)) {
|
|
415
400
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
416
401
|
}
|
|
417
402
|
await contract.register({
|
|
418
403
|
label: OFFER_CONTRACT_LABEL,
|
|
419
404
|
metadata: { genericallySpendable: false, kind: OFFER_CONTRACT_KIND }
|
|
420
405
|
});
|
|
421
|
-
await promoteOfferContract(contractManager,
|
|
406
|
+
await promoteOfferContract(contractManager, hex2.encode(expectedPkScript));
|
|
422
407
|
}
|
|
423
|
-
async function createOffer(wallet, arkServerUrl,
|
|
408
|
+
async function createOffer(wallet, arkServerUrl, params) {
|
|
424
409
|
if (Boolean(params.wantAsset) === Boolean(params.offerAsset)) {
|
|
425
410
|
throw new Error("set exactly one of wantAsset (BTC->asset) or offerAsset (asset->BTC)");
|
|
426
411
|
}
|
|
@@ -429,8 +414,11 @@ async function createOffer(wallet, arkServerUrl, emulatorPubkey, params) {
|
|
|
429
414
|
wallet.getAddress(),
|
|
430
415
|
wallet.identity.xOnlyPublicKey()
|
|
431
416
|
]);
|
|
432
|
-
const serverPubKey =
|
|
433
|
-
const
|
|
417
|
+
const serverPubKey = hex2.decode(toXOnlySignerHex(info.signerPubkey));
|
|
418
|
+
const network = getNetwork(info.network);
|
|
419
|
+
const emuKey = hex2.decode(
|
|
420
|
+
toXOnlySignerHex(resolveEmulatorPubkey(network, params.emulatorPubkey))
|
|
421
|
+
);
|
|
434
422
|
const binding = {
|
|
435
423
|
wantAmount: params.wantAmount,
|
|
436
424
|
wantAsset: params.wantAsset,
|
|
@@ -451,17 +439,17 @@ async function createOffer(wallet, arkServerUrl, emulatorPubkey, params) {
|
|
|
451
439
|
);
|
|
452
440
|
const payload = encodeOffer(offer);
|
|
453
441
|
return {
|
|
454
|
-
offerHex:
|
|
442
|
+
offerHex: hex2.encode(payload),
|
|
455
443
|
extension: { type: OFFER_PACKET_TYPE, payload },
|
|
456
444
|
// VtxoScript.address owns address construction; assembling an ArkAddress
|
|
457
445
|
// from tweakedPublicKey here would silently miss any future step it gains
|
|
458
|
-
address: script.address(
|
|
446
|
+
address: script.address(network.hrp, serverPubKey).encode(),
|
|
459
447
|
swapPkScript: script.pkScript
|
|
460
448
|
};
|
|
461
449
|
}
|
|
462
450
|
async function cancelOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
463
451
|
const { repository, fundingTxid, swapAddress } = opts;
|
|
464
|
-
const offer = decodeOffer(
|
|
452
|
+
const offer = decodeOffer(hex2.decode(offerHex));
|
|
465
453
|
const contractManager = await wallet.getContractManager();
|
|
466
454
|
const client = await arkade.Arkade.connect({
|
|
467
455
|
arkade: new RestArkProvider(arkServerUrl),
|
|
@@ -478,7 +466,7 @@ async function cancelOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
478
466
|
const serverKey = swapAddress ? ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
479
467
|
const { program, args, keys } = swapProgramBinding(offer, serverKey);
|
|
480
468
|
const rebuilt = new arkade.ArkadeProgramScript(program, args, keys);
|
|
481
|
-
if (
|
|
469
|
+
if (hex2.encode(rebuilt.pkScript) !== hex2.encode(offer.swapPkScript)) {
|
|
482
470
|
throw new Error(
|
|
483
471
|
"rebuilt covenant does not match the offer's swapPkScript \u2014 the server signing key has likely rotated since funding; pass swapAddress (the funded address) to pin the original key"
|
|
484
472
|
);
|
|
@@ -511,7 +499,7 @@ async function cancelOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
511
499
|
spentTxid: txid
|
|
512
500
|
});
|
|
513
501
|
if (persisted) {
|
|
514
|
-
await retireOfferContract(contractManager, swaps,
|
|
502
|
+
await retireOfferContract(contractManager, swaps, hex2.encode(offer.swapPkScript));
|
|
515
503
|
}
|
|
516
504
|
}
|
|
517
505
|
return txid;
|
|
@@ -782,7 +770,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
782
770
|
};
|
|
783
771
|
|
|
784
772
|
// src/restore.ts
|
|
785
|
-
import { base64, hex as
|
|
773
|
+
import { base64, hex as hex3 } from "@scure/base";
|
|
786
774
|
import {
|
|
787
775
|
Extension,
|
|
788
776
|
Transaction,
|
|
@@ -818,7 +806,7 @@ function classifySpend(offer, serverPubkey, spendTx, deposit) {
|
|
|
818
806
|
let leaves;
|
|
819
807
|
try {
|
|
820
808
|
const script = offerVtxoScript(offer, serverPubkey);
|
|
821
|
-
if (
|
|
809
|
+
if (hex3.encode(script.pkScript) !== hex3.encode(offer.swapPkScript)) return "indeterminate";
|
|
822
810
|
leaves = {
|
|
823
811
|
cancel: script.functionByName("cancel")?.leafScript,
|
|
824
812
|
fulfill: script.functionByName("fulfill")?.leafScript
|
|
@@ -829,11 +817,11 @@ function classifySpend(offer, serverPubkey, spendTx, deposit) {
|
|
|
829
817
|
for (let i = 0; i < spendTx.inputsLength; i++) {
|
|
830
818
|
const input = spendTx.getInput(i);
|
|
831
819
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
832
|
-
if (
|
|
820
|
+
if (hex3.encode(input.txid) !== deposit.txid) continue;
|
|
833
821
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
834
|
-
const spent =
|
|
835
|
-
if (leaves.cancel && spent ===
|
|
836
|
-
if (leaves.fulfill && spent ===
|
|
822
|
+
const spent = hex3.encode(scriptFromTapLeafScript(leaf));
|
|
823
|
+
if (leaves.cancel && spent === hex3.encode(leaves.cancel)) return "cancelled";
|
|
824
|
+
if (leaves.fulfill && spent === hex3.encode(leaves.fulfill)) return "fulfilled";
|
|
837
825
|
}
|
|
838
826
|
}
|
|
839
827
|
return "indeterminate";
|
|
@@ -868,13 +856,13 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
868
856
|
found.push({
|
|
869
857
|
fundingTx,
|
|
870
858
|
offer: decodeOffer(payload),
|
|
871
|
-
offerHex:
|
|
859
|
+
offerHex: hex3.encode(payload)
|
|
872
860
|
});
|
|
873
861
|
} catch {
|
|
874
862
|
}
|
|
875
863
|
}
|
|
876
864
|
if (found.length === 0) return { restored: [], scannedTxids: fetchedTxids };
|
|
877
|
-
const scripts = [...new Set(found.map((f) =>
|
|
865
|
+
const scripts = [...new Set(found.map((f) => hex3.encode(f.offer.swapPkScript)))];
|
|
878
866
|
const { vtxos } = await indexer.getVtxos({ scripts });
|
|
879
867
|
const vtxoByScriptAndTxid = new Map(vtxos.map((v) => [`${v.script}:${v.txid}`, v]));
|
|
880
868
|
const txByAnyId = /* @__PURE__ */ new Map();
|
|
@@ -886,7 +874,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
886
874
|
const spendTxids = /* @__PURE__ */ new Set();
|
|
887
875
|
for (const { fundingTx, offer } of found) {
|
|
888
876
|
const vtxo = vtxoByScriptAndTxid.get(
|
|
889
|
-
`${
|
|
877
|
+
`${hex3.encode(offer.swapPkScript)}:${fundingTx.redeemTxid}`
|
|
890
878
|
);
|
|
891
879
|
if (vtxo?.virtualStatus.state !== "spent") continue;
|
|
892
880
|
for (const txid of spendTxidsOf(vtxo)) spendTxids.add(txid);
|
|
@@ -895,7 +883,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
895
883
|
const restored = [];
|
|
896
884
|
const unresolved = /* @__PURE__ */ new Set();
|
|
897
885
|
for (const { fundingTx, offer, offerHex } of found) {
|
|
898
|
-
const swapPkScript =
|
|
886
|
+
const swapPkScript = hex3.encode(offer.swapPkScript);
|
|
899
887
|
const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
|
|
900
888
|
if (!vtxo) {
|
|
901
889
|
unresolved.add(fundingTx.redeemTxid);
|
|
@@ -952,7 +940,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
952
940
|
}
|
|
953
941
|
|
|
954
942
|
// src/watch.ts
|
|
955
|
-
import { base64 as base642, hex as
|
|
943
|
+
import { base64 as base642, hex as hex4 } from "@scure/base";
|
|
956
944
|
import {
|
|
957
945
|
ArkAddress as ArkAddress2,
|
|
958
946
|
RestIndexerProvider as RestIndexerProvider3,
|
|
@@ -991,7 +979,7 @@ async function watchOfferSwaps({
|
|
|
991
979
|
if (candidates.length === 0) return "indeterminate";
|
|
992
980
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
993
981
|
return classifyDepositSpend(
|
|
994
|
-
decodeOffer(
|
|
982
|
+
decodeOffer(hex4.decode(swap.offerHex)),
|
|
995
983
|
serverPubkey,
|
|
996
984
|
txs.map((psbt) => Transaction2.fromPSBT(base642.decode(psbt))),
|
|
997
985
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
@@ -1035,7 +1023,7 @@ async function watchOfferSwaps({
|
|
|
1035
1023
|
}
|
|
1036
1024
|
|
|
1037
1025
|
// src/claim.ts
|
|
1038
|
-
import { hex as
|
|
1026
|
+
import { hex as hex6 } from "@scure/base";
|
|
1039
1027
|
import { ripemd160 } from "@noble/hashes/legacy.js";
|
|
1040
1028
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
1041
1029
|
import {
|
|
@@ -1045,7 +1033,7 @@ import {
|
|
|
1045
1033
|
} from "@arkade-os/sdk";
|
|
1046
1034
|
|
|
1047
1035
|
// src/refund.ts
|
|
1048
|
-
import { base64 as base643, hex as
|
|
1036
|
+
import { base64 as base643, hex as hex5 } from "@scure/base";
|
|
1049
1037
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
1050
1038
|
import {
|
|
1051
1039
|
CSVMultisigTapscript,
|
|
@@ -1102,7 +1090,7 @@ var LockupNeedsRecoveryError = class extends Error {
|
|
|
1102
1090
|
}
|
|
1103
1091
|
};
|
|
1104
1092
|
async function findLockupVtxos(indexer, swapPkScript) {
|
|
1105
|
-
const scripts = [
|
|
1093
|
+
const scripts = [hex5.encode(swapPkScript)];
|
|
1106
1094
|
const [spendable, recoverable] = await Promise.all([
|
|
1107
1095
|
indexer.getVtxos({ scripts, spendableOnly: true }),
|
|
1108
1096
|
indexer.getVtxos({ scripts, recoverableOnly: true })
|
|
@@ -1127,13 +1115,13 @@ async function findLockupVtxos(indexer, swapPkScript) {
|
|
|
1127
1115
|
}
|
|
1128
1116
|
return out;
|
|
1129
1117
|
}
|
|
1130
|
-
var hashesTo = (candidate, paymentHash) =>
|
|
1118
|
+
var hashesTo = (candidate, paymentHash) => hex5.encode(sha256(candidate)) === paymentHash;
|
|
1131
1119
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
1132
1120
|
...getArkPsbtFields(tx, inputIndex, ConditionWitness).flat(),
|
|
1133
1121
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
1134
1122
|
];
|
|
1135
1123
|
async function readLockupFate(indexer, input) {
|
|
1136
|
-
const { vtxos } = await indexer.getVtxos({ scripts: [
|
|
1124
|
+
const { vtxos } = await indexer.getVtxos({ scripts: [hex5.encode(input.swapPkScript)] });
|
|
1137
1125
|
const all = vtxos ?? [];
|
|
1138
1126
|
if (all.length === 0) return { fate: "unknown" };
|
|
1139
1127
|
const spentBy = /* @__PURE__ */ new Set();
|
|
@@ -1156,7 +1144,7 @@ async function readLockupFate(indexer, input) {
|
|
|
1156
1144
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
1157
1145
|
const spent = tx.getInput(i);
|
|
1158
1146
|
if (!spent.txid) continue;
|
|
1159
|
-
const txid =
|
|
1147
|
+
const txid = hex5.encode(spent.txid);
|
|
1160
1148
|
if (!all.some((vtxo) => vtxo.txid === txid && vtxo.vout === spent.index)) continue;
|
|
1161
1149
|
for (const candidate of candidateWitnessItems(tx, i)) {
|
|
1162
1150
|
if (hashesTo(candidate, input.paymentHash)) {
|
|
@@ -1185,7 +1173,7 @@ async function pushRefundWithoutReceiver(ark, input) {
|
|
|
1185
1173
|
const info = await ark.getInfo();
|
|
1186
1174
|
let serverUnrollScript;
|
|
1187
1175
|
try {
|
|
1188
|
-
serverUnrollScript = CSVMultisigTapscript.decode(
|
|
1176
|
+
serverUnrollScript = CSVMultisigTapscript.decode(hex5.decode(info.checkpointTapscript));
|
|
1189
1177
|
} catch {
|
|
1190
1178
|
throw new Error("invalid checkpointTapscript from the Arkade server");
|
|
1191
1179
|
}
|
|
@@ -1296,13 +1284,13 @@ async function pushClaim(ark, input) {
|
|
|
1296
1284
|
}
|
|
1297
1285
|
}
|
|
1298
1286
|
const committed = input.script.options.preimageHash;
|
|
1299
|
-
if (
|
|
1287
|
+
if (hex6.encode(ripemd160(sha2562(input.preimage))) !== hex6.encode(committed)) {
|
|
1300
1288
|
throw new Error("preimage does not match the covenant's payment hash");
|
|
1301
1289
|
}
|
|
1302
1290
|
const info = await ark.getInfo();
|
|
1303
1291
|
let serverUnrollScript;
|
|
1304
1292
|
try {
|
|
1305
|
-
serverUnrollScript = CSVMultisigTapscript2.decode(
|
|
1293
|
+
serverUnrollScript = CSVMultisigTapscript2.decode(hex6.decode(info.checkpointTapscript));
|
|
1306
1294
|
} catch {
|
|
1307
1295
|
throw new Error("invalid checkpointTapscript from the Arkade server");
|
|
1308
1296
|
}
|
|
@@ -1355,8 +1343,50 @@ async function claimReceiveLockup(indexer, ark, input) {
|
|
|
1355
1343
|
});
|
|
1356
1344
|
}
|
|
1357
1345
|
|
|
1346
|
+
// src/refundBlocked.ts
|
|
1347
|
+
import {
|
|
1348
|
+
ForeignDescriptorError,
|
|
1349
|
+
WalletCannotSignError,
|
|
1350
|
+
contractSigner
|
|
1351
|
+
} from "@arkade-os/sdk";
|
|
1352
|
+
var RefundNotLocallyPossibleError = class extends Error {
|
|
1353
|
+
constructor(reason, message, options) {
|
|
1354
|
+
super(message, options);
|
|
1355
|
+
this.reason = reason;
|
|
1356
|
+
}
|
|
1357
|
+
reason;
|
|
1358
|
+
name = "RefundNotLocallyPossibleError";
|
|
1359
|
+
};
|
|
1360
|
+
async function senderIdentityForSwapRecord(wallet, record) {
|
|
1361
|
+
if (!record.signingDescriptor) {
|
|
1362
|
+
throw new RefundNotLocallyPossibleError(
|
|
1363
|
+
"no-secrets",
|
|
1364
|
+
"this swap record carries no signing descriptor"
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
try {
|
|
1368
|
+
return await contractSigner(wallet, record.signingDescriptor);
|
|
1369
|
+
} catch (cause) {
|
|
1370
|
+
if (cause instanceof WalletCannotSignError) {
|
|
1371
|
+
throw new RefundNotLocallyPossibleError(
|
|
1372
|
+
"unsignable-wallet",
|
|
1373
|
+
`this wallet holds ${record.signingDescriptor} but cannot sign with it; attach its signer`,
|
|
1374
|
+
{ cause }
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1377
|
+
if (cause instanceof ForeignDescriptorError) {
|
|
1378
|
+
throw new RefundNotLocallyPossibleError(
|
|
1379
|
+
"foreign-descriptor",
|
|
1380
|
+
`this wallet cannot derive ${record.signingDescriptor}; the swap was created on another wallet`,
|
|
1381
|
+
{ cause }
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
throw cause;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1358
1388
|
// src/swapManager.ts
|
|
1359
|
-
import { hex as
|
|
1389
|
+
import { hex as hex7 } from "@scure/base";
|
|
1360
1390
|
var RFQ_SWAP_TERMINAL_STATES = ["settled", "refunded", "failed"];
|
|
1361
1391
|
var isRfqSwapTerminal = (state) => RFQ_SWAP_TERMINAL_STATES.includes(state);
|
|
1362
1392
|
function nextOnchainAction(input) {
|
|
@@ -1624,7 +1654,7 @@ var RfqSwapManager = class {
|
|
|
1624
1654
|
// ── internals ────────────────────────────────────────────────────────────
|
|
1625
1655
|
track(swap) {
|
|
1626
1656
|
this.monitored.set(swap.rfqId, swap);
|
|
1627
|
-
this.byLockupScript.set(
|
|
1657
|
+
this.byLockupScript.set(hex7.encode(swap.lockupPkScript), swap);
|
|
1628
1658
|
}
|
|
1629
1659
|
/** Drops the swap from BOTH indexes. The event index is the one that stops
|
|
1630
1660
|
* a late event finding a swap that is gone; `pollSwap`'s own
|
|
@@ -1633,7 +1663,7 @@ var RfqSwapManager = class {
|
|
|
1633
1663
|
* them from silently re-driving a cancelled swap. */
|
|
1634
1664
|
untrack(rfqId) {
|
|
1635
1665
|
const swap = this.monitored.get(rfqId);
|
|
1636
|
-
if (swap) this.byLockupScript.delete(
|
|
1666
|
+
if (swap) this.byLockupScript.delete(hex7.encode(swap.lockupPkScript));
|
|
1637
1667
|
this.monitored.delete(rfqId);
|
|
1638
1668
|
this.refundRefused.delete(rfqId);
|
|
1639
1669
|
this.lastClaimError.delete(rfqId);
|
|
@@ -1695,7 +1725,7 @@ var RfqSwapManager = class {
|
|
|
1695
1725
|
if (!lockup) {
|
|
1696
1726
|
try {
|
|
1697
1727
|
const [existing] = await contracts.getContracts({
|
|
1698
|
-
script:
|
|
1728
|
+
script: hex7.encode(swap.lockupPkScript)
|
|
1699
1729
|
});
|
|
1700
1730
|
if (existing) {
|
|
1701
1731
|
this.registered.set(swap.rfqId, true);
|
|
@@ -1714,13 +1744,13 @@ var RfqSwapManager = class {
|
|
|
1714
1744
|
);
|
|
1715
1745
|
return;
|
|
1716
1746
|
}
|
|
1717
|
-
const script =
|
|
1718
|
-
if (script !==
|
|
1747
|
+
const script = hex7.encode(lockup.script.pkScript);
|
|
1748
|
+
if (script !== hex7.encode(swap.lockupPkScript)) {
|
|
1719
1749
|
this.registered.set(swap.rfqId, false);
|
|
1720
1750
|
this.emitFailed(
|
|
1721
1751
|
swap,
|
|
1722
1752
|
new Error(
|
|
1723
|
-
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${
|
|
1753
|
+
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${hex7.encode(swap.lockupPkScript)}`
|
|
1724
1754
|
)
|
|
1725
1755
|
);
|
|
1726
1756
|
return;
|
|
@@ -1739,7 +1769,7 @@ var RfqSwapManager = class {
|
|
|
1739
1769
|
* script for its whole life. Best-effort — the swap is over either way. */
|
|
1740
1770
|
retireContract(swap) {
|
|
1741
1771
|
if (!this.deps.contracts || !this.registered.get(swap.rfqId)) return;
|
|
1742
|
-
void this.deps.contracts.setContractWatchState(
|
|
1772
|
+
void this.deps.contracts.setContractWatchState(hex7.encode(swap.lockupPkScript), "retained").catch((error) => this.emitFailed(swap, error));
|
|
1743
1773
|
}
|
|
1744
1774
|
arm() {
|
|
1745
1775
|
if (!this.running) return;
|
|
@@ -2147,7 +2177,6 @@ export {
|
|
|
2147
2177
|
ONCHAIN_SEND_PAIR,
|
|
2148
2178
|
QUOTE_OPTIONS,
|
|
2149
2179
|
REFUND_MTP_LAG_SECONDS,
|
|
2150
|
-
RFQ_PREIMAGE_TAG,
|
|
2151
2180
|
RFQ_RESOLVED_STATES,
|
|
2152
2181
|
RFQ_SWAP_TERMINAL_STATES,
|
|
2153
2182
|
RFQ_TERMINAL_STATES,
|
|
@@ -2158,7 +2187,6 @@ export {
|
|
|
2158
2187
|
SWAP_LOCKUP_CONTRACT_TYPE,
|
|
2159
2188
|
SwapRefusal,
|
|
2160
2189
|
addAssetSwap,
|
|
2161
|
-
adoptSwapDescriptor,
|
|
2162
2190
|
arkadeSwapRequest,
|
|
2163
2191
|
assertFundable,
|
|
2164
2192
|
assertReceivable,
|
|
@@ -2167,7 +2195,6 @@ export {
|
|
|
2167
2195
|
awaitRfqResolution,
|
|
2168
2196
|
buildHtlcClaim,
|
|
2169
2197
|
buildHtlcRefund,
|
|
2170
|
-
buildPreimageMessage,
|
|
2171
2198
|
cancelOffer,
|
|
2172
2199
|
claimOnchainFill,
|
|
2173
2200
|
claimReceiveLockup,
|
|
@@ -2179,8 +2206,6 @@ export {
|
|
|
2179
2206
|
deriveLightningReceive,
|
|
2180
2207
|
deriveOnchainReceive,
|
|
2181
2208
|
deriveOnchainSend,
|
|
2182
|
-
derivePreimage,
|
|
2183
|
-
deriveSwapSecrets,
|
|
2184
2209
|
discoverMarkets,
|
|
2185
2210
|
encodeOffer,
|
|
2186
2211
|
extractPreimage,
|
|
@@ -2189,7 +2214,6 @@ export {
|
|
|
2189
2214
|
getAssetSwaps,
|
|
2190
2215
|
getAssetSwapsOrThrow,
|
|
2191
2216
|
httpTransport,
|
|
2192
|
-
isDeterministicSigner,
|
|
2193
2217
|
isRfqSwapTerminal,
|
|
2194
2218
|
isRfqTerminal,
|
|
2195
2219
|
lightningReceiveRequest,
|
|
@@ -2205,10 +2229,8 @@ export {
|
|
|
2205
2229
|
onchainReceiveRequest,
|
|
2206
2230
|
onchainSendRequest,
|
|
2207
2231
|
paymentHashOf,
|
|
2208
|
-
preimageForRfqSecrets,
|
|
2209
2232
|
pushClaim,
|
|
2210
2233
|
pushRefundWithoutReceiver,
|
|
2211
|
-
randomSwapSecrets,
|
|
2212
2234
|
readLockupFate,
|
|
2213
2235
|
receiveVtxoScript,
|
|
2214
2236
|
refundIfUnresolved,
|
|
@@ -2221,15 +2243,12 @@ export {
|
|
|
2221
2243
|
restoreAssetSwaps,
|
|
2222
2244
|
retireSettledOfferContracts,
|
|
2223
2245
|
rfqPair,
|
|
2224
|
-
rfqSecretsOfRecord,
|
|
2225
|
-
rfqSecretsToRecord,
|
|
2226
2246
|
sealClaimPacket,
|
|
2227
|
-
senderIdentityForRfqSecrets,
|
|
2228
2247
|
senderIdentityForSwapRecord,
|
|
2229
|
-
senderPubkeyForRfqSecrets,
|
|
2230
2248
|
spendTxidsOf,
|
|
2231
2249
|
spendUpdate,
|
|
2232
2250
|
swapPrograms,
|
|
2251
|
+
swapSecretsToRecord,
|
|
2233
2252
|
unilateralClaimDelay,
|
|
2234
2253
|
unilateralRefundDelay,
|
|
2235
2254
|
unilateralRefundWithoutReceiverDelay,
|
package/dist/nostr.cjs
CHANGED
|
@@ -38,9 +38,9 @@ __export(nostr_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(nostr_exports);
|
|
39
39
|
|
|
40
40
|
// src/rfq.ts
|
|
41
|
-
var
|
|
41
|
+
var import_base4 = require("@scure/base");
|
|
42
42
|
var import_legacy2 = require("@noble/hashes/legacy.js");
|
|
43
|
-
var
|
|
43
|
+
var import_sdk2 = require("@arkade-os/sdk");
|
|
44
44
|
|
|
45
45
|
// src/onchainHtlc.ts
|
|
46
46
|
var import_base = require("@scure/base");
|
|
@@ -56,23 +56,19 @@ var L1_NETWORKS = {
|
|
|
56
56
|
regtest: { ...btc.TEST_NETWORK, bech32: "bcrt" }
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
// src/
|
|
60
|
-
var
|
|
61
|
-
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
62
|
-
var import_utils = require("@noble/hashes/utils.js");
|
|
63
|
-
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
64
|
-
var import_sdk = require("@arkade-os/sdk");
|
|
59
|
+
// src/rfq.ts
|
|
60
|
+
var import_sdk3 = require("@arkade-os/sdk");
|
|
65
61
|
|
|
66
62
|
// src/claimPacket.ts
|
|
67
|
-
var
|
|
68
|
-
var
|
|
63
|
+
var import_base2 = require("@scure/base");
|
|
64
|
+
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
69
65
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
70
|
-
var
|
|
66
|
+
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
71
67
|
var HKDF_INFO = new TextEncoder().encode("covclaimd/preimage/v1");
|
|
72
68
|
|
|
73
69
|
// src/lockupContract.ts
|
|
74
|
-
var
|
|
75
|
-
var
|
|
70
|
+
var import_base3 = require("@scure/base");
|
|
71
|
+
var import_sdk = require("@arkade-os/sdk");
|
|
76
72
|
|
|
77
73
|
// src/rfq.ts
|
|
78
74
|
var ARKADE_BTC = "arkade:BTC";
|
|
@@ -208,9 +204,9 @@ var nostrRfqTransport = (options) => {
|
|
|
208
204
|
},
|
|
209
205
|
async close() {
|
|
210
206
|
closed = true;
|
|
211
|
-
subscription.close();
|
|
212
207
|
waiters.clear();
|
|
213
208
|
if (ownsPool) pool.close(relays);
|
|
209
|
+
else subscription.close();
|
|
214
210
|
}
|
|
215
211
|
};
|
|
216
212
|
};
|
package/dist/nostr.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as RfqTransport } from './rfq-DjZlesr4.cjs';
|
|
2
2
|
import { SimplePool } from 'nostr-tools';
|
|
3
3
|
import '@arkade-os/sdk';
|
|
4
|
-
import '@arkade-os/solver-discovery';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* The Nostr RFQ transport — the PRODUCTION one (docs/rfq-protocol.md § 3.1 in
|
package/dist/nostr.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as RfqTransport } from './rfq-DjZlesr4.js';
|
|
2
2
|
import { SimplePool } from 'nostr-tools';
|
|
3
3
|
import '@arkade-os/sdk';
|
|
4
|
-
import '@arkade-os/solver-discovery';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* The Nostr RFQ transport — the PRODUCTION one (docs/rfq-protocol.md § 3.1 in
|
package/dist/nostr.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SwapRefusal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DLM6BVTB.js";
|
|
4
4
|
|
|
5
5
|
// src/nostr.ts
|
|
6
6
|
import {
|
|
@@ -120,9 +120,9 @@ var nostrRfqTransport = (options) => {
|
|
|
120
120
|
},
|
|
121
121
|
async close() {
|
|
122
122
|
closed = true;
|
|
123
|
-
subscription.close();
|
|
124
123
|
waiters.clear();
|
|
125
124
|
if (ownsPool) pool.close(relays);
|
|
125
|
+
else subscription.close();
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
};
|