@arkade-os/swap 0.1.0-rc.29 → 0.1.0-rc.30
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/advanced.cjs +130 -77
- package/dist/advanced.d.cts +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +2 -2
- package/dist/{chunk-E7EF65MO.js → chunk-7V254T53.js} +78 -28
- package/dist/{chunk-PTAJYT2M.js → chunk-KIXAIAUC.js} +5 -3
- package/dist/index.cjs +144 -91
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{offerFillPlan-qBRemU32.d.cts → offerFillPlan-D-krqw0z.d.cts} +5 -3
- package/dist/{offerFillPlan-CgvrM3fS.d.ts → offerFillPlan-D4Oy5_yZ.d.ts} +5 -3
- package/dist/protocol.js +4 -53
- package/package.json +2 -2
package/dist/advanced.cjs
CHANGED
|
@@ -4716,7 +4716,7 @@ var scopedToRail = (table, rail) => ({
|
|
|
4716
4716
|
});
|
|
4717
4717
|
|
|
4718
4718
|
// src/client/client.ts
|
|
4719
|
-
var
|
|
4719
|
+
var import_base22 = require("@scure/base");
|
|
4720
4720
|
var import_sdk36 = require("@arkade-os/sdk");
|
|
4721
4721
|
init_repository();
|
|
4722
4722
|
|
|
@@ -4955,6 +4955,58 @@ var arkadeCorridor = Object.assign(
|
|
|
4955
4955
|
|
|
4956
4956
|
// src/client/corridors/deps.ts
|
|
4957
4957
|
var import_sdk17 = require("@arkade-os/sdk");
|
|
4958
|
+
|
|
4959
|
+
// src/chainSource.ts
|
|
4960
|
+
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
4961
|
+
var import_base11 = require("@scure/base");
|
|
4962
|
+
init_onchainHtlc();
|
|
4963
|
+
var addressOf = (pkScript, network) => btc3.Address(L1_NETWORKS[network]).encode(btc3.OutScript.decode(pkScript));
|
|
4964
|
+
var chainSourceFrom = (provider, network) => {
|
|
4965
|
+
const spenderFromHistory = async (txid, vout, pkScript) => {
|
|
4966
|
+
const txs = await provider.getTransactions(addressOf(pkScript, network));
|
|
4967
|
+
return txs.find((tx) => tx.vin?.some((i) => i.txid === txid && i.vout === vout))?.txid;
|
|
4968
|
+
};
|
|
4969
|
+
return {
|
|
4970
|
+
async getScriptUtxos(pkScript) {
|
|
4971
|
+
const address = addressOf(pkScript, network);
|
|
4972
|
+
const [coins, tip] = await Promise.all([
|
|
4973
|
+
provider.getCoins(address),
|
|
4974
|
+
provider.getChainTip()
|
|
4975
|
+
]);
|
|
4976
|
+
return coins.map((coin) => ({
|
|
4977
|
+
txid: coin.txid,
|
|
4978
|
+
vout: coin.vout,
|
|
4979
|
+
amount: BigInt(coin.value),
|
|
4980
|
+
// Zero, not one: calling a mempool output "1 deep" would let a
|
|
4981
|
+
// 1-confirmation policy claim against a replaceable transaction.
|
|
4982
|
+
confirmations: coin.status.confirmed && typeof coin.status.block_height === "number" ? Math.max(0, tip.height - coin.status.block_height + 1) : 0
|
|
4983
|
+
}));
|
|
4984
|
+
},
|
|
4985
|
+
async getSpendingTx(txid, vout, pkScript) {
|
|
4986
|
+
const outspends = await provider.getTxOutspends(txid);
|
|
4987
|
+
const outspend = outspends[vout];
|
|
4988
|
+
if (!outspend?.spent) return null;
|
|
4989
|
+
const spender = outspend.txid || await spenderFromHistory(txid, vout, pkScript);
|
|
4990
|
+
if (!spender) return null;
|
|
4991
|
+
const raw = await provider.getRawTransaction(spender);
|
|
4992
|
+
return { txHex: import_base11.hex.encode(raw) };
|
|
4993
|
+
},
|
|
4994
|
+
broadcast(txHex) {
|
|
4995
|
+
return provider.broadcastTransaction(txHex);
|
|
4996
|
+
},
|
|
4997
|
+
async getMtp() {
|
|
4998
|
+
return (await provider.getChainTip()).time;
|
|
4999
|
+
},
|
|
5000
|
+
async getTxStatus(txid) {
|
|
5001
|
+
return (await provider.getTxStatus(txid)).confirmed ? "confirmed" : "unconfirmed";
|
|
5002
|
+
},
|
|
5003
|
+
getFeeRate() {
|
|
5004
|
+
return provider.getFeeRate();
|
|
5005
|
+
}
|
|
5006
|
+
};
|
|
5007
|
+
};
|
|
5008
|
+
|
|
5009
|
+
// src/client/corridors/deps.ts
|
|
4958
5010
|
init_onchainHtlc();
|
|
4959
5011
|
init_rfq();
|
|
4960
5012
|
|
|
@@ -4985,10 +5037,10 @@ var decodeBolt11 = (invoice) => {
|
|
|
4985
5037
|
};
|
|
4986
5038
|
|
|
4987
5039
|
// src/client/corridors/chainSource.ts
|
|
4988
|
-
var
|
|
4989
|
-
var
|
|
5040
|
+
var import_base12 = require("@scure/base");
|
|
5041
|
+
var btc4 = __toESM(require("@scure/btc-signer"), 1);
|
|
4990
5042
|
var import_sdk16 = require("@arkade-os/sdk");
|
|
4991
|
-
var addressOfScript = (script, network) =>
|
|
5043
|
+
var addressOfScript = (script, network) => btc4.Address(network).encode(btc4.OutScript.decode(script));
|
|
4992
5044
|
var chainSourceOver = (backend, network) => {
|
|
4993
5045
|
const spenderFromVins = async (txid, vout, pkScript) => {
|
|
4994
5046
|
let address;
|
|
@@ -5025,7 +5077,7 @@ var chainSourceOver = (backend, network) => {
|
|
|
5025
5077
|
if (!outspend?.spent) return null;
|
|
5026
5078
|
const spender = outspend.txid || await spenderFromVins(txid, vout, pkScript);
|
|
5027
5079
|
if (!spender) return null;
|
|
5028
|
-
return { txHex:
|
|
5080
|
+
return { txHex: import_base12.hex.encode(await backend.provider.getRawTransaction(spender)) };
|
|
5029
5081
|
},
|
|
5030
5082
|
broadcast(txHex) {
|
|
5031
5083
|
return backend.provider.broadcastTransaction(txHex);
|
|
@@ -5131,11 +5183,12 @@ function resolveCorridorDeps(corridor, overrides, base) {
|
|
|
5131
5183
|
);
|
|
5132
5184
|
const claimFeeRateSatVb = feeRateOverride === null ? void 0 : feeRateOverride ?? ONCHAIN_CLAIM_FEE_RATE_SATVB[base.networkName];
|
|
5133
5185
|
const claimVsize = refusedIfMalformed(overrides?.onchain?.claimVsize, "L1 claim vsize") ?? ONCHAIN_CLAIM_VSIZE;
|
|
5186
|
+
const l1Network = l1NetworkFromArk(base.networkName);
|
|
5134
5187
|
return {
|
|
5135
5188
|
networkName: base.networkName,
|
|
5136
|
-
chain: esploraChainSource({
|
|
5189
|
+
chain: chain && "provider" in chain ? chainSourceFrom(chain.provider, l1Network) : esploraChainSource({
|
|
5137
5190
|
esploraUrl: chain?.esploraUrl ?? import_sdk17.ESPLORA_URL[base.networkName],
|
|
5138
|
-
network: L1_NETWORKS[
|
|
5191
|
+
network: L1_NETWORKS[l1Network],
|
|
5139
5192
|
fetchImpl: base.fetchImpl
|
|
5140
5193
|
}),
|
|
5141
5194
|
...claim === void 0 ? {} : { claim },
|
|
@@ -5491,13 +5544,13 @@ var discoveryIndex = (input) => {
|
|
|
5491
5544
|
};
|
|
5492
5545
|
|
|
5493
5546
|
// src/client/cancel.ts
|
|
5494
|
-
var
|
|
5547
|
+
var import_base16 = require("@scure/base");
|
|
5495
5548
|
var import_sdk24 = require("@arkade-os/sdk");
|
|
5496
5549
|
init_coverage();
|
|
5497
5550
|
init_offer();
|
|
5498
5551
|
|
|
5499
5552
|
// src/restore.ts
|
|
5500
|
-
var
|
|
5553
|
+
var import_base13 = require("@scure/base");
|
|
5501
5554
|
var import_sdk21 = require("@arkade-os/sdk");
|
|
5502
5555
|
init_offer();
|
|
5503
5556
|
init_store();
|
|
@@ -5523,7 +5576,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
5523
5576
|
if (result.status !== "fulfilled") continue;
|
|
5524
5577
|
for (const psbt of result.value) {
|
|
5525
5578
|
try {
|
|
5526
|
-
const parsed = import_sdk21.Transaction.fromPSBT(
|
|
5579
|
+
const parsed = import_sdk21.Transaction.fromPSBT(import_base13.base64.decode(psbt));
|
|
5527
5580
|
parsedByTxid.set(parsed.id, parsed);
|
|
5528
5581
|
} catch {
|
|
5529
5582
|
}
|
|
@@ -5538,7 +5591,7 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
5538
5591
|
let leaves;
|
|
5539
5592
|
try {
|
|
5540
5593
|
const script = offerContract(offer, operatorPubkey);
|
|
5541
|
-
if (
|
|
5594
|
+
if (import_base13.hex.encode(script.pkScript) !== import_base13.hex.encode(offer.swapPkScript)) return "indeterminate";
|
|
5542
5595
|
leaves = {
|
|
5543
5596
|
// `exit` is absent on an offer with no exit closure, and drops out here
|
|
5544
5597
|
returned: ["cancel", "exit"].map((name) => script.functionByName(name)?.leafScript).filter((leaf) => leaf !== void 0),
|
|
@@ -5550,11 +5603,11 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
5550
5603
|
for (let i = 0; i < spendTx.inputsLength; i++) {
|
|
5551
5604
|
const input = spendTx.getInput(i);
|
|
5552
5605
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
5553
|
-
if (
|
|
5606
|
+
if (import_base13.hex.encode(input.txid) !== deposit.txid) continue;
|
|
5554
5607
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
5555
|
-
const spent =
|
|
5556
|
-
if (leaves.returned.some((back) => spent ===
|
|
5557
|
-
if (leaves.fulfill && spent ===
|
|
5608
|
+
const spent = import_base13.hex.encode((0, import_sdk21.scriptFromTapLeafScript)(leaf));
|
|
5609
|
+
if (leaves.returned.some((back) => spent === import_base13.hex.encode(back))) return "cancelled";
|
|
5610
|
+
if (leaves.fulfill && spent === import_base13.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
5558
5611
|
}
|
|
5559
5612
|
}
|
|
5560
5613
|
return "indeterminate";
|
|
@@ -5580,7 +5633,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5580
5633
|
try {
|
|
5581
5634
|
reopened.push({
|
|
5582
5635
|
fundingTx: { type: "sent", redeemTxid: swap.fundingTxid },
|
|
5583
|
-
offer: decodeOffer(
|
|
5636
|
+
offer: decodeOffer(import_base13.hex.decode(swap.offerHex)),
|
|
5584
5637
|
offerHex: swap.offerHex,
|
|
5585
5638
|
existing: swap
|
|
5586
5639
|
});
|
|
@@ -5612,13 +5665,13 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5612
5665
|
found.push({
|
|
5613
5666
|
fundingTx,
|
|
5614
5667
|
offer: decodeOffer(payload),
|
|
5615
|
-
offerHex:
|
|
5668
|
+
offerHex: import_base13.hex.encode(payload)
|
|
5616
5669
|
});
|
|
5617
5670
|
} catch {
|
|
5618
5671
|
}
|
|
5619
5672
|
}
|
|
5620
5673
|
if (found.length === 0) return { restored: [], scannedTxids: fetchedTxids };
|
|
5621
|
-
const scripts = [...new Set(found.map((f) =>
|
|
5674
|
+
const scripts = [...new Set(found.map((f) => import_base13.hex.encode(f.offer.swapPkScript)))];
|
|
5622
5675
|
const { vtxos } = await indexer.getVtxos({ scripts });
|
|
5623
5676
|
const vtxoByScriptAndTxid = new Map(vtxos.map((v) => [`${v.script}:${v.txid}`, v]));
|
|
5624
5677
|
const txByAnyId = /* @__PURE__ */ new Map();
|
|
@@ -5630,7 +5683,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5630
5683
|
const spendTxids = /* @__PURE__ */ new Set();
|
|
5631
5684
|
for (const { fundingTx, offer } of found) {
|
|
5632
5685
|
const vtxo = vtxoByScriptAndTxid.get(
|
|
5633
|
-
`${
|
|
5686
|
+
`${import_base13.hex.encode(offer.swapPkScript)}:${fundingTx.redeemTxid}`
|
|
5634
5687
|
);
|
|
5635
5688
|
if (!vtxo?.isSpent) continue;
|
|
5636
5689
|
for (const txid of spendTxidsOf(vtxo)) spendTxids.add(txid);
|
|
@@ -5639,7 +5692,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5639
5692
|
const restored = [];
|
|
5640
5693
|
const unresolved = /* @__PURE__ */ new Set();
|
|
5641
5694
|
for (const { fundingTx, offer, offerHex, existing } of found) {
|
|
5642
|
-
const swapPkScript =
|
|
5695
|
+
const swapPkScript = import_base13.hex.encode(offer.swapPkScript);
|
|
5643
5696
|
const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
|
|
5644
5697
|
if (!vtxo) {
|
|
5645
5698
|
unresolved.add(fundingTx.redeemTxid);
|
|
@@ -5686,7 +5739,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5686
5739
|
let swapAddress = "";
|
|
5687
5740
|
try {
|
|
5688
5741
|
const compiled = offerContract(offer, operatorPubkey);
|
|
5689
|
-
if (
|
|
5742
|
+
if (import_base13.hex.encode(compiled.pkScript) !== swapPkScript) {
|
|
5690
5743
|
unresolved.add(fundingTx.redeemTxid);
|
|
5691
5744
|
continue;
|
|
5692
5745
|
}
|
|
@@ -5724,7 +5777,7 @@ init_repository();
|
|
|
5724
5777
|
|
|
5725
5778
|
// src/rfqRecord.ts
|
|
5726
5779
|
var import_sdk22 = require("@arkade-os/sdk");
|
|
5727
|
-
var
|
|
5780
|
+
var import_base14 = require("@scure/base");
|
|
5728
5781
|
|
|
5729
5782
|
// src/rfqSwapState.ts
|
|
5730
5783
|
var RFQ_SWAP_TERMINAL_STATES = ["settled", "refunded", "failed"];
|
|
@@ -5779,8 +5832,8 @@ function assertSameSwap(origin, swap) {
|
|
|
5779
5832
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
5780
5833
|
);
|
|
5781
5834
|
}
|
|
5782
|
-
const funded =
|
|
5783
|
-
const watched =
|
|
5835
|
+
const funded = import_base14.hex.encode(import_sdk22.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
5836
|
+
const watched = import_base14.hex.encode(swap.lockupPkScript);
|
|
5784
5837
|
if (funded !== watched) {
|
|
5785
5838
|
throw new Error(
|
|
5786
5839
|
`rfq swap record's lockup address holds ${funded}, but the swap watches ${watched} \u2014 these are not the same swap`
|
|
@@ -5828,9 +5881,9 @@ function rfqSwapOriginOf(record) {
|
|
|
5828
5881
|
function lockupScript(params, lockupAddress) {
|
|
5829
5882
|
const script = import_sdk22.VHTLCV2ContractHandler.createScript(params);
|
|
5830
5883
|
const funded = import_sdk22.ArkAddress.decode(lockupAddress).pkScript;
|
|
5831
|
-
if (
|
|
5884
|
+
if (import_base14.hex.encode(funded) !== import_base14.hex.encode(script.pkScript)) {
|
|
5832
5885
|
throw new Error(
|
|
5833
|
-
`rfq swap covenant params derive ${
|
|
5886
|
+
`rfq swap covenant params derive ${import_base14.hex.encode(script.pkScript)}, but the record's lockup address holds ${import_base14.hex.encode(funded)} \u2014 these params are not this swap's`
|
|
5834
5887
|
);
|
|
5835
5888
|
}
|
|
5836
5889
|
return script;
|
|
@@ -5866,7 +5919,7 @@ function shouldRetainRfqSwap(record, now) {
|
|
|
5866
5919
|
init_store();
|
|
5867
5920
|
var import_sdk23 = require("@arkade-os/sdk");
|
|
5868
5921
|
var import_sha25 = require("@noble/hashes/sha2.js");
|
|
5869
|
-
var
|
|
5922
|
+
var import_base15 = require("@scure/base");
|
|
5870
5923
|
var splitRecords = (records) => {
|
|
5871
5924
|
const corridor = [];
|
|
5872
5925
|
const offer = [];
|
|
@@ -6067,7 +6120,7 @@ var RESTORED_CORRIDORS = {
|
|
|
6067
6120
|
var restoredCorridorRecord = (stored, network, refundLocktime) => {
|
|
6068
6121
|
const v1 = normalizeRfqSwapRecord(stored);
|
|
6069
6122
|
const hashlock = v1.profile.hashlock;
|
|
6070
|
-
const hash = typeof hashlock?.paymentHash === "string" ? hashlock.paymentHash : v1.settlementPreimageHex === void 0 ? void 0 :
|
|
6123
|
+
const hash = typeof hashlock?.paymentHash === "string" ? hashlock.paymentHash : v1.settlementPreimageHex === void 0 ? void 0 : import_base15.hex.encode((0, import_sha25.sha256)(import_base15.hex.decode(v1.settlementPreimageHex)));
|
|
6071
6124
|
if (hash === void 0) throw new Error(`v1 rfq swap ${v1.rfqId} has no payment hash`);
|
|
6072
6125
|
const [giveCorridor, takeCorridor] = RESTORED_CORRIDORS[v1.kind];
|
|
6073
6126
|
const give = btcOn(railOfCorridor(giveCorridor), network);
|
|
@@ -6089,7 +6142,7 @@ var restoredCorridorRecord = (stored, network, refundLocktime) => {
|
|
|
6089
6142
|
kind: v1.kind,
|
|
6090
6143
|
rfqId: v1.rfqId,
|
|
6091
6144
|
lockupAddress: v1.lockupAddress,
|
|
6092
|
-
lockupPkScript:
|
|
6145
|
+
lockupPkScript: import_base15.hex.encode(import_sdk23.ArkAddress.decode(v1.lockupAddress).pkScript),
|
|
6093
6146
|
lock: { hash },
|
|
6094
6147
|
refundLocktime,
|
|
6095
6148
|
profile: v1.profile,
|
|
@@ -6173,7 +6226,7 @@ var cancelSwap = async (input) => {
|
|
|
6173
6226
|
return { outcome: "cancelled" };
|
|
6174
6227
|
};
|
|
6175
6228
|
var reconcileDepositSpend = async (record, indexer) => {
|
|
6176
|
-
const offer = decodeOffer(
|
|
6229
|
+
const offer = decodeOffer(import_base16.hex.decode(record.offerHex));
|
|
6177
6230
|
const { vtxos } = await indexer.getVtxos({ scripts: [record.swapPkScript] });
|
|
6178
6231
|
const all = vtxos ?? [];
|
|
6179
6232
|
const deposit = record.fundingTxid === void 0 ? all.length === 1 ? all[0] : void 0 : all.find((vtxo) => vtxo.txid === record.fundingTxid);
|
|
@@ -6185,7 +6238,7 @@ var reconcileDepositSpend = async (record, indexer) => {
|
|
|
6185
6238
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
6186
6239
|
const parsed = txs.map((psbt) => {
|
|
6187
6240
|
try {
|
|
6188
|
-
return import_sdk24.Transaction.fromPSBT(
|
|
6241
|
+
return import_sdk24.Transaction.fromPSBT(import_base16.base64.decode(psbt));
|
|
6189
6242
|
} catch {
|
|
6190
6243
|
return void 0;
|
|
6191
6244
|
}
|
|
@@ -6230,7 +6283,7 @@ var retireOfferScripts = async (wallet, repository, record) => {
|
|
|
6230
6283
|
|
|
6231
6284
|
// src/client/drive.ts
|
|
6232
6285
|
var import_sdk30 = require("@arkade-os/sdk");
|
|
6233
|
-
var
|
|
6286
|
+
var import_base19 = require("@scure/base");
|
|
6234
6287
|
|
|
6235
6288
|
// src/claim.ts
|
|
6236
6289
|
var import_sdk25 = require("@arkade-os/sdk");
|
|
@@ -6369,7 +6422,7 @@ init_store();
|
|
|
6369
6422
|
init_repository();
|
|
6370
6423
|
|
|
6371
6424
|
// src/swapManager.ts
|
|
6372
|
-
var
|
|
6425
|
+
var import_base17 = require("@scure/base");
|
|
6373
6426
|
var import_sdk27 = require("@arkade-os/sdk");
|
|
6374
6427
|
init_onchainHtlc();
|
|
6375
6428
|
init_lockupContract();
|
|
@@ -6816,13 +6869,13 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6816
6869
|
// ── internals ────────────────────────────────────────────────────────────
|
|
6817
6870
|
track(swap) {
|
|
6818
6871
|
this.monitored.set(swap.rfqId, swap);
|
|
6819
|
-
this.byLockupScript.set(
|
|
6872
|
+
this.byLockupScript.set(import_base17.hex.encode(swap.lockupPkScript), swap);
|
|
6820
6873
|
}
|
|
6821
6874
|
/** Drops the swap from BOTH indexes. `pollSwap`'s `monitored` check also stops a late
|
|
6822
6875
|
* event, deliberately redundant so neither change alone re-drives a removed swap. */
|
|
6823
6876
|
untrack(rfqId) {
|
|
6824
6877
|
const swap = this.monitored.get(rfqId);
|
|
6825
|
-
if (swap) this.byLockupScript.delete(
|
|
6878
|
+
if (swap) this.byLockupScript.delete(import_base17.hex.encode(swap.lockupPkScript));
|
|
6826
6879
|
this.monitored.delete(rfqId);
|
|
6827
6880
|
this.refundRefused.delete(rfqId);
|
|
6828
6881
|
this.claimedOutpoints.delete(rfqId);
|
|
@@ -6868,7 +6921,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6868
6921
|
if (!lockup) {
|
|
6869
6922
|
try {
|
|
6870
6923
|
const [existing] = await contracts.getContracts({
|
|
6871
|
-
script:
|
|
6924
|
+
script: import_base17.hex.encode(swap.lockupPkScript)
|
|
6872
6925
|
});
|
|
6873
6926
|
if (existing) {
|
|
6874
6927
|
this.registered.set(swap.rfqId, true);
|
|
@@ -6887,13 +6940,13 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6887
6940
|
);
|
|
6888
6941
|
return;
|
|
6889
6942
|
}
|
|
6890
|
-
const script =
|
|
6891
|
-
if (script !==
|
|
6943
|
+
const script = import_base17.hex.encode(lockup.script.pkScript);
|
|
6944
|
+
if (script !== import_base17.hex.encode(swap.lockupPkScript)) {
|
|
6892
6945
|
this.registered.set(swap.rfqId, false);
|
|
6893
6946
|
this.emitFailed(
|
|
6894
6947
|
swap,
|
|
6895
6948
|
new Error(
|
|
6896
|
-
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${
|
|
6949
|
+
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${import_base17.hex.encode(swap.lockupPkScript)}`
|
|
6897
6950
|
)
|
|
6898
6951
|
);
|
|
6899
6952
|
return;
|
|
@@ -6910,7 +6963,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6910
6963
|
retireContract(swap) {
|
|
6911
6964
|
if (!this.deps.contracts || !this.registered.get(swap.rfqId)) return;
|
|
6912
6965
|
if (!LOCKUP_RETIRABLE.includes(swap.state)) return;
|
|
6913
|
-
void this.deps.contracts.setContractWatchState(
|
|
6966
|
+
void this.deps.contracts.setContractWatchState(import_base17.hex.encode(swap.lockupPkScript), "retained").catch((error) => this.emitFailed(swap, error));
|
|
6914
6967
|
}
|
|
6915
6968
|
arm() {
|
|
6916
6969
|
if (!this.running) return;
|
|
@@ -7442,7 +7495,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7442
7495
|
*/
|
|
7443
7496
|
stampSettlementPreimage(swap, preimage) {
|
|
7444
7497
|
if (swap.kind !== "lightning_send") return;
|
|
7445
|
-
swap.settlementPreimageHex =
|
|
7498
|
+
swap.settlementPreimageHex = import_base17.hex.encode(preimage);
|
|
7446
7499
|
this.touch(swap);
|
|
7447
7500
|
}
|
|
7448
7501
|
touch(swap) {
|
|
@@ -7565,7 +7618,7 @@ var errorMessage = (error) => error instanceof Error ? error.message : String(er
|
|
|
7565
7618
|
var outpointKey = (vtxo) => `${vtxo.txid}:${vtxo.vout}`;
|
|
7566
7619
|
|
|
7567
7620
|
// src/watch.ts
|
|
7568
|
-
var
|
|
7621
|
+
var import_base18 = require("@scure/base");
|
|
7569
7622
|
var import_sdk28 = require("@arkade-os/sdk");
|
|
7570
7623
|
init_coverage();
|
|
7571
7624
|
init_offer();
|
|
@@ -7614,9 +7667,9 @@ async function watchOfferSwaps({
|
|
|
7614
7667
|
if (candidates.length === 0) return "indeterminate";
|
|
7615
7668
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
7616
7669
|
return classifyDepositSpend(
|
|
7617
|
-
decodeOffer(
|
|
7670
|
+
decodeOffer(import_base18.hex.decode(swap.offerHex)),
|
|
7618
7671
|
operatorPubkey,
|
|
7619
|
-
txs.map((psbt) => import_sdk28.Transaction.fromPSBT(
|
|
7672
|
+
txs.map((psbt) => import_sdk28.Transaction.fromPSBT(import_base18.base64.decode(psbt))),
|
|
7620
7673
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
7621
7674
|
);
|
|
7622
7675
|
} catch {
|
|
@@ -7928,7 +7981,7 @@ var createSwapDrive = (config) => {
|
|
|
7928
7981
|
const signer = await (0, import_sdk30.contractSigner)(wallet, await (0, import_sdk30.identityDescriptor)(wallet.identity));
|
|
7929
7982
|
const claimKey = record.profile.claimKey;
|
|
7930
7983
|
if (typeof claimKey === "string") {
|
|
7931
|
-
const held =
|
|
7984
|
+
const held = import_base19.hex.encode(await signer.xOnlyPublicKey());
|
|
7932
7985
|
if (held !== claimKey) {
|
|
7933
7986
|
throw new Error(
|
|
7934
7987
|
`this wallet's identity key ${held} is not the payout key ${claimKey} rfq swap ${swap.rfqId} was quoted against \u2014 a wrong seed, or key provisioning has drifted from the identity key`
|
|
@@ -7972,7 +8025,7 @@ var createSwapDrive = (config) => {
|
|
|
7972
8025
|
);
|
|
7973
8026
|
}
|
|
7974
8027
|
const signer = await (0, import_sdk30.contractSigner)(wallet, descriptor);
|
|
7975
|
-
const held =
|
|
8028
|
+
const held = import_base19.hex.encode(await signer.xOnlyPublicKey());
|
|
7976
8029
|
if (held !== record.profile.refundKey) {
|
|
7977
8030
|
throw new Error(
|
|
7978
8031
|
`the key behind ${descriptor} is ${held}, not the refund key ${String(record.profile.refundKey)} rfq swap ${swap.rfqId}'s HTLC was derived with`
|
|
@@ -8350,7 +8403,7 @@ var createSwapDrive = (config) => {
|
|
|
8350
8403
|
id
|
|
8351
8404
|
);
|
|
8352
8405
|
}
|
|
8353
|
-
const script =
|
|
8406
|
+
const script = import_base19.hex.decode(record.lockupPkScript);
|
|
8354
8407
|
const before = await recoverableAt(script);
|
|
8355
8408
|
if (before.length === 0) {
|
|
8356
8409
|
throw new SwapDriveRefusedError(
|
|
@@ -8994,12 +9047,12 @@ var verifyPlanLegs = (plan, legs, give) => {
|
|
|
8994
9047
|
};
|
|
8995
9048
|
|
|
8996
9049
|
// src/client/quoteRfq.ts
|
|
8997
|
-
var
|
|
9050
|
+
var import_base21 = require("@scure/base");
|
|
8998
9051
|
var import_sdk34 = require("@arkade-os/sdk");
|
|
8999
9052
|
var import_solver_discovery12 = require("@arkade-os/solver-discovery");
|
|
9000
9053
|
|
|
9001
9054
|
// src/jointGraph.ts
|
|
9002
|
-
var
|
|
9055
|
+
var import_base20 = require("@scure/base");
|
|
9003
9056
|
var import_sha26 = require("@noble/hashes/sha2.js");
|
|
9004
9057
|
var import_sdk31 = require("@arkade-os/sdk");
|
|
9005
9058
|
function digestJointGraph(plan, template) {
|
|
@@ -9035,7 +9088,7 @@ function digestJointGraph(plan, template) {
|
|
|
9035
9088
|
preimage.set(part, at2);
|
|
9036
9089
|
at2 += part.length;
|
|
9037
9090
|
}
|
|
9038
|
-
return
|
|
9091
|
+
return import_base20.hex.encode((0, import_sha26.sha256)(preimage));
|
|
9039
9092
|
}
|
|
9040
9093
|
function verifyJointGraph(plan, template) {
|
|
9041
9094
|
try {
|
|
@@ -9063,7 +9116,7 @@ function verifyJointGraph(plan, template) {
|
|
|
9063
9116
|
}
|
|
9064
9117
|
}
|
|
9065
9118
|
function parseGraphTx(psbt) {
|
|
9066
|
-
return import_sdk31.Transaction.fromPSBT(
|
|
9119
|
+
return import_sdk31.Transaction.fromPSBT(import_base20.base64.decode(psbt));
|
|
9067
9120
|
}
|
|
9068
9121
|
function deepFreeze(value) {
|
|
9069
9122
|
if (value !== null && typeof value === "object") {
|
|
@@ -9152,10 +9205,10 @@ var covenantInputs = (input) => {
|
|
|
9152
9205
|
const network = (0, import_sdk34.networkFromArkadeInfo)(input.info);
|
|
9153
9206
|
const arkade2 = input.corridors.get("arkade").deps;
|
|
9154
9207
|
return {
|
|
9155
|
-
operatorPubkey: (0, import_sdk34.toXOnly)(
|
|
9208
|
+
operatorPubkey: (0, import_sdk34.toXOnly)(import_base21.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9156
9209
|
// The resolved per-network pin, never operator-reported: it lands in a covenant leaf
|
|
9157
9210
|
// that decides who can move the funds.
|
|
9158
|
-
emulatorPubkey: (0, import_sdk34.toXOnly)(
|
|
9211
|
+
emulatorPubkey: (0, import_sdk34.toXOnly)(import_base21.hex.decode(arkade2.emulatorPubkey), "emulator signer key"),
|
|
9159
9212
|
claimDelay: unilateralClaimDelay(Number(input.info.unilateralExitDelay)),
|
|
9160
9213
|
hrp: network.hrp
|
|
9161
9214
|
};
|
|
@@ -9163,7 +9216,7 @@ var covenantInputs = (input) => {
|
|
|
9163
9216
|
var sealingKey = (deps) => {
|
|
9164
9217
|
const configured = deps.covclaimd?.pubkey;
|
|
9165
9218
|
if (configured === void 0) return void 0;
|
|
9166
|
-
const key =
|
|
9219
|
+
const key = import_base21.hex.decode(configured);
|
|
9167
9220
|
if (key.length !== 33) {
|
|
9168
9221
|
throw new Error(
|
|
9169
9222
|
`the covclaimd deployment key must be 33-byte compressed hex, got ${key.length} bytes`
|
|
@@ -9220,7 +9273,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9220
9273
|
receiveAddress,
|
|
9221
9274
|
maker.pkScript,
|
|
9222
9275
|
(0, import_sdk34.networkFromArkadeInfo)(input.info).hrp,
|
|
9223
|
-
(0, import_sdk34.toXOnly)(
|
|
9276
|
+
(0, import_sdk34.toXOnly)(import_base21.hex.decode(input.info.signerPubkey), "ark signer key")
|
|
9224
9277
|
);
|
|
9225
9278
|
const choice = payment?.carrier;
|
|
9226
9279
|
const carrierRequest = choice === void 0 ? void 0 : choice.mode === "purchase" ? { mode: "purchase" } : {
|
|
@@ -9232,7 +9285,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9232
9285
|
if (choice?.mode === "recycleReceiver") {
|
|
9233
9286
|
if (choice.quote.assetId !== sides.wantAsset?.toString())
|
|
9234
9287
|
throw new Error("carrier quote assetId differs from requested asset");
|
|
9235
|
-
if (choice.quote.senderKey !==
|
|
9288
|
+
if (choice.quote.senderKey !== import_base21.hex.encode(maker.publicKey))
|
|
9236
9289
|
throw new Error("carrier quote senderKey differs from wallet identity");
|
|
9237
9290
|
if (input.now >= choice.quote.expiresAt - 30)
|
|
9238
9291
|
throw new Error("carrier quote expired before RFQ");
|
|
@@ -9285,7 +9338,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9285
9338
|
if (input.now >= validUntil) throw new Error("asset payment terms lapsed before funding");
|
|
9286
9339
|
assetPayment = {
|
|
9287
9340
|
receiveAddress: receiveAddress ?? new import_sdk34.ArkAddress(
|
|
9288
|
-
(0, import_sdk34.toXOnly)(
|
|
9341
|
+
(0, import_sdk34.toXOnly)(import_base21.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9289
9342
|
maker.pkScript.slice(2),
|
|
9290
9343
|
(0, import_sdk34.networkFromArkadeInfo)(input.info).hrp
|
|
9291
9344
|
).encode(),
|
|
@@ -9459,7 +9512,7 @@ var quoteLightningReceive = async (input) => {
|
|
|
9459
9512
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
9460
9513
|
const rfqId = newRfqId();
|
|
9461
9514
|
const secrets = await (0, import_sdk34.provisionClaimSecret)(input.wallet);
|
|
9462
|
-
const paymentHash =
|
|
9515
|
+
const paymentHash = import_base21.hex.encode(secrets.paymentHash);
|
|
9463
9516
|
const payoutAddress = await input.wallet.getAddress();
|
|
9464
9517
|
const lightning = input.corridors.get("lightning").deps;
|
|
9465
9518
|
const sealTo = sealingKey(lightning);
|
|
@@ -9572,7 +9625,7 @@ var quoteOnchainSend = async (input) => {
|
|
|
9572
9625
|
const quoted = claimFee === void 0 ? pinned : { on: pinned.on, value: pinned.value + claimFee, source: pinned.source };
|
|
9573
9626
|
const secrets = await (0, import_sdk34.provisionClaimSecret)(input.wallet);
|
|
9574
9627
|
const payoutKey = await (0, import_sdk34.provisionRefundKey)(input.wallet);
|
|
9575
|
-
const paymentHash =
|
|
9628
|
+
const paymentHash = import_base21.hex.encode(secrets.paymentHash);
|
|
9576
9629
|
const wire = await input.transport.requestQuote(
|
|
9577
9630
|
withCanonicalAmount(
|
|
9578
9631
|
onchainSendRequest({
|
|
@@ -9678,7 +9731,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
9678
9731
|
const l1Network = l1NetworkFromArk(input.info.network);
|
|
9679
9732
|
const secrets = await (0, import_sdk34.provisionClaimSecret)(input.wallet);
|
|
9680
9733
|
const refundKey = await (0, import_sdk34.provisionRefundKey)(input.wallet);
|
|
9681
|
-
const paymentHash =
|
|
9734
|
+
const paymentHash = import_base21.hex.encode(secrets.paymentHash);
|
|
9682
9735
|
const payoutAddress = await input.wallet.getAddress();
|
|
9683
9736
|
const refundPkScript = l1ScriptForAddress(await input.wallet.getBoardingAddress(), l1Network);
|
|
9684
9737
|
const wire = await input.transport.requestQuote(
|
|
@@ -9879,7 +9932,7 @@ var nostrTransportFactory = createNostrTransportFactory();
|
|
|
9879
9932
|
|
|
9880
9933
|
// src/client/client.ts
|
|
9881
9934
|
var PREPARATIONS_HELD = 64;
|
|
9882
|
-
var mintQuoteId = () =>
|
|
9935
|
+
var mintQuoteId = () => import_base22.hex.encode(crypto.getRandomValues(new Uint8Array(16)));
|
|
9883
9936
|
var createSwapClient = (config) => {
|
|
9884
9937
|
const { wallet } = config;
|
|
9885
9938
|
const operator = config.operator ?? walletOperator(wallet);
|
|
@@ -10134,7 +10187,7 @@ var createSwapClient = (config) => {
|
|
|
10134
10187
|
};
|
|
10135
10188
|
|
|
10136
10189
|
// src/reveal.ts
|
|
10137
|
-
var
|
|
10190
|
+
var import_base23 = require("@scure/base");
|
|
10138
10191
|
var import_sdk37 = require("@arkade-os/sdk");
|
|
10139
10192
|
init_claimPacket();
|
|
10140
10193
|
init_onchainHtlc();
|
|
@@ -10154,7 +10207,7 @@ var decodeKey = (value, field) => {
|
|
|
10154
10207
|
if (typeof value !== "string") throw new Error(`covclaimd info: ${field} is not a string`);
|
|
10155
10208
|
let bytes;
|
|
10156
10209
|
try {
|
|
10157
|
-
bytes =
|
|
10210
|
+
bytes = import_base23.hex.decode(value);
|
|
10158
10211
|
} catch {
|
|
10159
10212
|
throw new Error(`covclaimd info: ${field} is not hex`);
|
|
10160
10213
|
}
|
|
@@ -10215,7 +10268,7 @@ var covclaimdClient = (baseUrl, options = {}) => {
|
|
|
10215
10268
|
const body = await readJson("info", response);
|
|
10216
10269
|
return {
|
|
10217
10270
|
covclaimdPubkey: decodeKey(body?.covclaimd_pub_key, "covclaimd_pub_key"),
|
|
10218
|
-
emulatorPubkey:
|
|
10271
|
+
emulatorPubkey: import_base23.hex.encode(decodeKey(body?.emulator_pub_key, "emulator_pub_key"))
|
|
10219
10272
|
};
|
|
10220
10273
|
},
|
|
10221
10274
|
async reveal(params) {
|
|
@@ -10236,13 +10289,13 @@ function revealFieldsFromScript(script) {
|
|
|
10236
10289
|
throw new Error("this covenant has no non-interactive claim leaf to reveal against");
|
|
10237
10290
|
}
|
|
10238
10291
|
return {
|
|
10239
|
-
arkadeScript:
|
|
10240
|
-
taptree:
|
|
10292
|
+
arkadeScript: import_base23.base64.encode(script.nonInteractiveClaimArkadeScript),
|
|
10293
|
+
taptree: import_base23.hex.encode(script.encode())
|
|
10241
10294
|
};
|
|
10242
10295
|
}
|
|
10243
10296
|
async function revealClaimPacket(client, input) {
|
|
10244
10297
|
const fields = revealFieldsFromScript(input.script);
|
|
10245
|
-
if (
|
|
10298
|
+
if (import_base23.hex.encode(import_sdk37.ArkAddress.decode(input.address).pkScript) !== import_base23.hex.encode(input.script.pkScript)) {
|
|
10246
10299
|
throw new Error("address does not belong to this covenant");
|
|
10247
10300
|
}
|
|
10248
10301
|
assertPreimageMatches(input.preimage, input.script.options.preimageHash);
|
|
@@ -10255,7 +10308,7 @@ async function revealClaimPacket(client, input) {
|
|
|
10255
10308
|
}
|
|
10256
10309
|
|
|
10257
10310
|
// src/offerFillPlan.ts
|
|
10258
|
-
var
|
|
10311
|
+
var import_base24 = require("@scure/base");
|
|
10259
10312
|
var import_sdk38 = require("@arkade-os/sdk");
|
|
10260
10313
|
init_offer();
|
|
10261
10314
|
var OFFER_FILL_TEMPLATE = "offer-fill/1";
|
|
@@ -10270,7 +10323,7 @@ async function buildOfferFillPlan(wallet, arkServerUrl, offerHex, opts) {
|
|
|
10270
10323
|
assetCarrierSats = ASSET_CARRIER_SATS,
|
|
10271
10324
|
sponsor
|
|
10272
10325
|
} = opts;
|
|
10273
|
-
const offer = decodeOffer(
|
|
10326
|
+
const offer = decodeOffer(import_base24.hex.decode(offerHex));
|
|
10274
10327
|
const contract = await connectFillContract(wallet, arkServerUrl, offer, { swapAddress });
|
|
10275
10328
|
const vtxos = await contract.getUtxos();
|
|
10276
10329
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
@@ -10319,7 +10372,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10319
10372
|
}
|
|
10320
10373
|
layout.inputs.forEach((input, i) => {
|
|
10321
10374
|
const spent = checkpoints[i].getInput(0);
|
|
10322
|
-
if (!(spent.txid instanceof Uint8Array) ||
|
|
10375
|
+
if (!(spent.txid instanceof Uint8Array) || import_base24.hex.encode(spent.txid) !== input.txid || spent.index !== input.vout) {
|
|
10323
10376
|
throw new Error(`fill plan checkpoint ${i} does not spend ${input.txid}:${input.vout}`);
|
|
10324
10377
|
}
|
|
10325
10378
|
});
|
|
@@ -10331,7 +10384,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10331
10384
|
}
|
|
10332
10385
|
layout.outputs.forEach((expected, i) => {
|
|
10333
10386
|
const out = arkTx.getOutput(i);
|
|
10334
|
-
if (!out?.script ||
|
|
10387
|
+
if (!out?.script || import_base24.hex.encode(out.script) !== import_base24.hex.encode(expected.script)) {
|
|
10335
10388
|
throw new Error(`fill plan output ${i} is not the ${expected.role} script`);
|
|
10336
10389
|
}
|
|
10337
10390
|
if (out.amount !== expected.sats) {
|
|
@@ -10345,7 +10398,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10345
10398
|
throw new Error(`fill plan output ${payments} is not the extension packet`);
|
|
10346
10399
|
}
|
|
10347
10400
|
const anchor = arkTx.getOutput(payments + 1);
|
|
10348
|
-
if (!anchor?.script ||
|
|
10401
|
+
if (!anchor?.script || import_base24.hex.encode(anchor.script) !== import_base24.hex.encode(import_sdk38.P2A.script) || anchor.amount !== import_sdk38.P2A.amount) {
|
|
10349
10402
|
throw new Error(`fill plan output ${payments + 1} is not the anchor`);
|
|
10350
10403
|
}
|
|
10351
10404
|
const packet = import_sdk38.Extension.fromTx(arkTx).getAssetPacket();
|
|
@@ -10377,8 +10430,8 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10377
10430
|
);
|
|
10378
10431
|
}
|
|
10379
10432
|
}
|
|
10380
|
-
const arkTxPsbt =
|
|
10381
|
-
const checkpointPsbts = checkpoints.map((c) =>
|
|
10433
|
+
const arkTxPsbt = import_base24.base64.encode(arkTx.toPSBT());
|
|
10434
|
+
const checkpointPsbts = checkpoints.map((c) => import_base24.base64.encode(c.toPSBT()));
|
|
10382
10435
|
const inputOwners = layout.inputs.map((input) => input.owner);
|
|
10383
10436
|
const graph = {
|
|
10384
10437
|
arkTx: arkTxPsbt,
|
|
@@ -10399,7 +10452,7 @@ function verifyOfferFillPlan(plan) {
|
|
|
10399
10452
|
}
|
|
10400
10453
|
|
|
10401
10454
|
// src/evmRfq.ts
|
|
10402
|
-
var
|
|
10455
|
+
var import_base25 = require("@scure/base");
|
|
10403
10456
|
init_rfq();
|
|
10404
10457
|
var EVM_CHAIN = "ethereum";
|
|
10405
10458
|
var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
@@ -10464,7 +10517,7 @@ var evmSendRequest = (input) => {
|
|
|
10464
10517
|
payment_hash: input.paymentHash,
|
|
10465
10518
|
evm_claim_address: assertEvmAddress(input.evmClaimAddress, "evmClaimAddress"),
|
|
10466
10519
|
refund_address: input.refundAddress,
|
|
10467
|
-
client_refund_pubkey:
|
|
10520
|
+
client_refund_pubkey: import_base25.hex.encode(input.senderPubkey)
|
|
10468
10521
|
}
|
|
10469
10522
|
};
|
|
10470
10523
|
};
|
|
@@ -10488,7 +10541,7 @@ var evmReceiveRequest = (input) => {
|
|
|
10488
10541
|
evm_timeout_block: input.evmTimeoutBlock,
|
|
10489
10542
|
evm_refund_address: assertEvmAddress(input.evmRefundAddress, "evmRefundAddress"),
|
|
10490
10543
|
payout_address: input.payoutAddress,
|
|
10491
|
-
payout_pubkey:
|
|
10544
|
+
payout_pubkey: import_base25.hex.encode(input.payoutPubkey)
|
|
10492
10545
|
}
|
|
10493
10546
|
};
|
|
10494
10547
|
};
|