@arkade-os/swap 0.0.4 → 0.0.5
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 +125 -31
- package/dist/{chunk-DLM6BVTB.js → chunk-Q4FAYBXS.js} +6 -4
- package/dist/index.cjs +155 -93
- package/dist/index.d.cts +106 -25
- package/dist/index.d.ts +106 -25
- package/dist/index.js +67 -8
- package/dist/nostr.cjs +11 -0
- package/dist/nostr.d.cts +14 -2
- package/dist/nostr.d.ts +14 -2
- package/dist/nostr.js +9 -1
- package/dist/{rfq-DjZlesr4.d.cts → rfq-BH2yvo3O.d.cts} +36 -13
- package/dist/{rfq-DjZlesr4.d.ts → rfq-BH2yvo3O.d.ts} +36 -13
- package/package.json +2 -2
package/dist/nostr.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SwapRefusal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q4FAYBXS.js";
|
|
4
4
|
|
|
5
5
|
// src/nostr.ts
|
|
6
6
|
import {
|
|
@@ -21,6 +21,12 @@ var RelayUnavailable = class extends Error {
|
|
|
21
21
|
this.reasons = reasons;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
+
var TransportClosed = class extends Error {
|
|
25
|
+
constructor() {
|
|
26
|
+
super("transport closed before the solver replied");
|
|
27
|
+
this.name = "TransportClosed";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
24
30
|
var closeReasons = (raw) => raw.map((entry) => {
|
|
25
31
|
if (typeof entry === "string") return entry;
|
|
26
32
|
const { url, reason } = entry ?? {};
|
|
@@ -120,6 +126,7 @@ var nostrRfqTransport = (options) => {
|
|
|
120
126
|
},
|
|
121
127
|
async close() {
|
|
122
128
|
closed = true;
|
|
129
|
+
for (const waiter of waiters.values()) waiter.reject(new TransportClosed());
|
|
123
130
|
waiters.clear();
|
|
124
131
|
if (ownsPool) pool.close(relays);
|
|
125
132
|
else subscription.close();
|
|
@@ -130,5 +137,6 @@ export {
|
|
|
130
137
|
RFQ_AD_KIND,
|
|
131
138
|
RFQ_DIRECTED_KIND,
|
|
132
139
|
RelayUnavailable,
|
|
140
|
+
TransportClosed,
|
|
133
141
|
nostrRfqTransport
|
|
134
142
|
};
|
|
@@ -355,20 +355,38 @@ declare const relayTransport: (relayUrl: string, options: {
|
|
|
355
355
|
WebSocketCtor?: new (url: string) => RelaySocket;
|
|
356
356
|
timeoutMs?: number;
|
|
357
357
|
}) => RfqTransport;
|
|
358
|
+
/**
|
|
359
|
+
* How long the sender's SOLO refund opens after the receiver's claim, seconds.
|
|
360
|
+
*
|
|
361
|
+
* This is the window in which a claimant holding the preimage must be able to
|
|
362
|
+
* finish taking their money before the funder could take it back. On a live
|
|
363
|
+
* Arkade server that is one collaborative spend; with the server gone it is a
|
|
364
|
+
* full unilateral exit — an unroll broadcast per chain step, each waiting on a
|
|
365
|
+
* confirmation, then the CSV spend.
|
|
366
|
+
*
|
|
367
|
+
* 4096s (eight 512s units, ~68 minutes) is sized for that worst case. It is
|
|
368
|
+
* REASONED, not measured, and it mirrors `SOLO_REFUND_HEADROOM_SECONDS` in the
|
|
369
|
+
* reference solver's `src/core/timelocks.ts` — the two must move together or a
|
|
370
|
+
* trader derives an address the solver never quoted.
|
|
371
|
+
*
|
|
372
|
+
* A multiple of the granularity on purpose: BIP68 would round anything else,
|
|
373
|
+
* making the encoded timelock differ from the number written here.
|
|
374
|
+
*/
|
|
375
|
+
declare const SOLO_REFUND_HEADROOM_SECONDS: number;
|
|
358
376
|
/** The solver's unilateral-claim delay, derived from the Ark server's reported
|
|
359
377
|
* exit delay exactly as the reference solver derives it — both sides read the
|
|
360
378
|
* SAME server, so the derivation (not a quote field) is what keeps the two
|
|
361
379
|
* scripts identical. */
|
|
362
380
|
declare const unilateralClaimDelay: (serverExitDelaySeconds: number) => number;
|
|
363
|
-
/** VHTLC's `unilateralRefund` tier: sender +
|
|
364
|
-
*
|
|
365
|
-
* and
|
|
366
|
-
*
|
|
367
|
-
* produces — one rounding, shared across all three tiers. */
|
|
381
|
+
/** VHTLC's `unilateralRefund` tier: sender + receiver, no server — LEVEL with
|
|
382
|
+
* `claimDelay`, not above it. Neither party can spend a two-signature leaf
|
|
383
|
+
* alone, so separating it buys no safety, and every second spent separating it
|
|
384
|
+
* is a second taken off the headroom that does matter. */
|
|
368
385
|
declare const unilateralRefundDelay: (claimDelay: number) => number;
|
|
369
|
-
/** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone,
|
|
370
|
-
* nobody
|
|
371
|
-
*
|
|
386
|
+
/** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone, needing
|
|
387
|
+
* nobody. The only leaf whose timing can steal — a funder able to refund
|
|
388
|
+
* before the claimant can claim takes money from someone holding the preimage
|
|
389
|
+
* — so it opens last, by {@link SOLO_REFUND_HEADROOM_SECONDS}. */
|
|
372
390
|
declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => number;
|
|
373
391
|
/** Compile the lightning-send VHTLC from the quote's binding fields plus the
|
|
374
392
|
* trader's own data. `paymentHash` is the BOLT11 payment hash (`sha256(P)`,
|
|
@@ -631,8 +649,9 @@ declare function requestOnchainSend(wallet: IWallet, arkServerUrl: string, trans
|
|
|
631
649
|
htlc: OnchainHtlc;
|
|
632
650
|
/** The VHTLC `sender` x-only key, bound into the covenant. Public. */
|
|
633
651
|
senderPubkey: Uint8Array;
|
|
634
|
-
/** How the preimage and the `sender` key are recovered later
|
|
635
|
-
*
|
|
652
|
+
/** How the preimage and the `sender` key are recovered later — map it
|
|
653
|
+
* through `swapSecretsToRecord` and persist BEFORE funding. Public unless
|
|
654
|
+
* `mustPersistPreimage` says the wallet could not derive P. */
|
|
636
655
|
secrets: ProvisionedClaimSecret;
|
|
637
656
|
}>;
|
|
638
657
|
/** Default floor for the window between the last moment the hold invoice can
|
|
@@ -820,8 +839,9 @@ declare function requestLightningReceive(wallet: IWallet, arkServerUrl: string,
|
|
|
820
839
|
payoutAddress: string;
|
|
821
840
|
/** The trader's covenant `receiver` key, bound into the tree. Public. */
|
|
822
841
|
payoutPubkey: Uint8Array;
|
|
823
|
-
/** How the preimage and the payout key are recovered later
|
|
824
|
-
*
|
|
842
|
+
/** How the preimage and the payout key are recovered later — map it
|
|
843
|
+
* through `swapSecretsToRecord` and persist BEFORE paying the invoice.
|
|
844
|
+
* Public unless `mustPersistPreimage` says the wallet could not derive P. */
|
|
825
845
|
secrets: ProvisionedClaimSecret;
|
|
826
846
|
}>;
|
|
827
847
|
/**
|
|
@@ -893,7 +913,10 @@ declare function requestOnchainReceive(wallet: IWallet, arkServerUrl: string, tr
|
|
|
893
913
|
htlc: OnchainHtlc;
|
|
894
914
|
payoutAddress: string;
|
|
895
915
|
payoutPubkey: Uint8Array;
|
|
916
|
+
/** How the preimage and the payout key are recovered later — map it
|
|
917
|
+
* through `swapSecretsToRecord` and persist BEFORE funding. Public unless
|
|
918
|
+
* `mustPersistPreimage` says the wallet could not derive P. */
|
|
896
919
|
secrets: ProvisionedClaimSecret;
|
|
897
920
|
}>;
|
|
898
921
|
|
|
899
|
-
export {
|
|
922
|
+
export { onchainSendRequest as $, ARKADE_ASSET as A, awaitOnchainFill as B, type ChainSource as C, buildHtlcClaim as D, buildHtlcRefund as E, claimOnchainFill as F, classifyOnchainHtlc as G, type HtlcUtxo as H, type InvoiceFacts as I, deriveLightningReceive as J, deriveOnchainReceive as K, LIGHTNING_BTC as L, MAX_MIN_CONFIRMATIONS as M, deriveOnchainSend as N, type OnchainHtlc as O, extractPreimage as P, httpTransport as Q, type RfqStatus as R, SOLO_REFUND_HEADROOM_SECONDS as S, lightningReceiveRequest as T, lightningSendRequest as U, lightningSendVtxoScript as V, newPreimage as W, newRfqId as X, offerTermsFromQuote as Y, onchainHtlcScript as Z, onchainReceiveRequest as _, type RfqTransport as a, paymentHashOf as a0, receiveVtxoScript as a1, relayTransport as a2, requestLightningReceive as a3, requestLightningSend as a4, requestOnchainReceive as a5, requestOnchainSend as a6, rfqPair as a7, unilateralClaimDelay as a8, unilateralRefundDelay as a9, unilateralRefundWithoutReceiverDelay as aa, verifyLockupAddress as ab, verifyReceiveInvoice as ac, type ChainUtxo as b, type OnchainHtlcPhase as c, ARKADE_BTC as d, AddressMismatch as e, LIGHTNING_RECEIVE_PAIR as f, LIGHTNING_SEND_PAIR as g, MIN_CLAIM_WINDOW_SECONDS as h, MIN_HEADROOM_SECONDS as i, ONCHAIN_BTC as j, ONCHAIN_CLAIM_MARGIN_SECONDS as k, ONCHAIN_DUST_SATS as l, ONCHAIN_ORDER_MARGIN_SECONDS as m, ONCHAIN_RECEIVE_PAIR as n, ONCHAIN_SECONDS_PER_BLOCK as o, ONCHAIN_SEND_PAIR as p, type OnchainHtlcParams as q, type OnchainNetwork as r, RFQ_TERMINAL_STATES as s, type RelaySocket as t, type RfqQuote as u, type RfqRefusalReason as v, SwapRefusal as w, arkadeSwapRequest as x, assertFundable as y, assertReceivable as z };
|
|
@@ -355,20 +355,38 @@ declare const relayTransport: (relayUrl: string, options: {
|
|
|
355
355
|
WebSocketCtor?: new (url: string) => RelaySocket;
|
|
356
356
|
timeoutMs?: number;
|
|
357
357
|
}) => RfqTransport;
|
|
358
|
+
/**
|
|
359
|
+
* How long the sender's SOLO refund opens after the receiver's claim, seconds.
|
|
360
|
+
*
|
|
361
|
+
* This is the window in which a claimant holding the preimage must be able to
|
|
362
|
+
* finish taking their money before the funder could take it back. On a live
|
|
363
|
+
* Arkade server that is one collaborative spend; with the server gone it is a
|
|
364
|
+
* full unilateral exit — an unroll broadcast per chain step, each waiting on a
|
|
365
|
+
* confirmation, then the CSV spend.
|
|
366
|
+
*
|
|
367
|
+
* 4096s (eight 512s units, ~68 minutes) is sized for that worst case. It is
|
|
368
|
+
* REASONED, not measured, and it mirrors `SOLO_REFUND_HEADROOM_SECONDS` in the
|
|
369
|
+
* reference solver's `src/core/timelocks.ts` — the two must move together or a
|
|
370
|
+
* trader derives an address the solver never quoted.
|
|
371
|
+
*
|
|
372
|
+
* A multiple of the granularity on purpose: BIP68 would round anything else,
|
|
373
|
+
* making the encoded timelock differ from the number written here.
|
|
374
|
+
*/
|
|
375
|
+
declare const SOLO_REFUND_HEADROOM_SECONDS: number;
|
|
358
376
|
/** The solver's unilateral-claim delay, derived from the Ark server's reported
|
|
359
377
|
* exit delay exactly as the reference solver derives it — both sides read the
|
|
360
378
|
* SAME server, so the derivation (not a quote field) is what keeps the two
|
|
361
379
|
* scripts identical. */
|
|
362
380
|
declare const unilateralClaimDelay: (serverExitDelaySeconds: number) => number;
|
|
363
|
-
/** VHTLC's `unilateralRefund` tier: sender +
|
|
364
|
-
*
|
|
365
|
-
* and
|
|
366
|
-
*
|
|
367
|
-
* produces — one rounding, shared across all three tiers. */
|
|
381
|
+
/** VHTLC's `unilateralRefund` tier: sender + receiver, no server — LEVEL with
|
|
382
|
+
* `claimDelay`, not above it. Neither party can spend a two-signature leaf
|
|
383
|
+
* alone, so separating it buys no safety, and every second spent separating it
|
|
384
|
+
* is a second taken off the headroom that does matter. */
|
|
368
385
|
declare const unilateralRefundDelay: (claimDelay: number) => number;
|
|
369
|
-
/** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone,
|
|
370
|
-
* nobody
|
|
371
|
-
*
|
|
386
|
+
/** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone, needing
|
|
387
|
+
* nobody. The only leaf whose timing can steal — a funder able to refund
|
|
388
|
+
* before the claimant can claim takes money from someone holding the preimage
|
|
389
|
+
* — so it opens last, by {@link SOLO_REFUND_HEADROOM_SECONDS}. */
|
|
372
390
|
declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => number;
|
|
373
391
|
/** Compile the lightning-send VHTLC from the quote's binding fields plus the
|
|
374
392
|
* trader's own data. `paymentHash` is the BOLT11 payment hash (`sha256(P)`,
|
|
@@ -631,8 +649,9 @@ declare function requestOnchainSend(wallet: IWallet, arkServerUrl: string, trans
|
|
|
631
649
|
htlc: OnchainHtlc;
|
|
632
650
|
/** The VHTLC `sender` x-only key, bound into the covenant. Public. */
|
|
633
651
|
senderPubkey: Uint8Array;
|
|
634
|
-
/** How the preimage and the `sender` key are recovered later
|
|
635
|
-
*
|
|
652
|
+
/** How the preimage and the `sender` key are recovered later — map it
|
|
653
|
+
* through `swapSecretsToRecord` and persist BEFORE funding. Public unless
|
|
654
|
+
* `mustPersistPreimage` says the wallet could not derive P. */
|
|
636
655
|
secrets: ProvisionedClaimSecret;
|
|
637
656
|
}>;
|
|
638
657
|
/** Default floor for the window between the last moment the hold invoice can
|
|
@@ -820,8 +839,9 @@ declare function requestLightningReceive(wallet: IWallet, arkServerUrl: string,
|
|
|
820
839
|
payoutAddress: string;
|
|
821
840
|
/** The trader's covenant `receiver` key, bound into the tree. Public. */
|
|
822
841
|
payoutPubkey: Uint8Array;
|
|
823
|
-
/** How the preimage and the payout key are recovered later
|
|
824
|
-
*
|
|
842
|
+
/** How the preimage and the payout key are recovered later — map it
|
|
843
|
+
* through `swapSecretsToRecord` and persist BEFORE paying the invoice.
|
|
844
|
+
* Public unless `mustPersistPreimage` says the wallet could not derive P. */
|
|
825
845
|
secrets: ProvisionedClaimSecret;
|
|
826
846
|
}>;
|
|
827
847
|
/**
|
|
@@ -893,7 +913,10 @@ declare function requestOnchainReceive(wallet: IWallet, arkServerUrl: string, tr
|
|
|
893
913
|
htlc: OnchainHtlc;
|
|
894
914
|
payoutAddress: string;
|
|
895
915
|
payoutPubkey: Uint8Array;
|
|
916
|
+
/** How the preimage and the payout key are recovered later — map it
|
|
917
|
+
* through `swapSecretsToRecord` and persist BEFORE funding. Public unless
|
|
918
|
+
* `mustPersistPreimage` says the wallet could not derive P. */
|
|
896
919
|
secrets: ProvisionedClaimSecret;
|
|
897
920
|
}>;
|
|
898
921
|
|
|
899
|
-
export {
|
|
922
|
+
export { onchainSendRequest as $, ARKADE_ASSET as A, awaitOnchainFill as B, type ChainSource as C, buildHtlcClaim as D, buildHtlcRefund as E, claimOnchainFill as F, classifyOnchainHtlc as G, type HtlcUtxo as H, type InvoiceFacts as I, deriveLightningReceive as J, deriveOnchainReceive as K, LIGHTNING_BTC as L, MAX_MIN_CONFIRMATIONS as M, deriveOnchainSend as N, type OnchainHtlc as O, extractPreimage as P, httpTransport as Q, type RfqStatus as R, SOLO_REFUND_HEADROOM_SECONDS as S, lightningReceiveRequest as T, lightningSendRequest as U, lightningSendVtxoScript as V, newPreimage as W, newRfqId as X, offerTermsFromQuote as Y, onchainHtlcScript as Z, onchainReceiveRequest as _, type RfqTransport as a, paymentHashOf as a0, receiveVtxoScript as a1, relayTransport as a2, requestLightningReceive as a3, requestLightningSend as a4, requestOnchainReceive as a5, requestOnchainSend as a6, rfqPair as a7, unilateralClaimDelay as a8, unilateralRefundDelay as a9, unilateralRefundWithoutReceiverDelay as aa, verifyLockupAddress as ab, verifyReceiveInvoice as ac, type ChainUtxo as b, type OnchainHtlcPhase as c, ARKADE_BTC as d, AddressMismatch as e, LIGHTNING_RECEIVE_PAIR as f, LIGHTNING_SEND_PAIR as g, MIN_CLAIM_WINDOW_SECONDS as h, MIN_HEADROOM_SECONDS as i, ONCHAIN_BTC as j, ONCHAIN_CLAIM_MARGIN_SECONDS as k, ONCHAIN_DUST_SATS as l, ONCHAIN_ORDER_MARGIN_SECONDS as m, ONCHAIN_RECEIVE_PAIR as n, ONCHAIN_SECONDS_PER_BLOCK as o, ONCHAIN_SEND_PAIR as p, type OnchainHtlcParams as q, type OnchainNetwork as r, RFQ_TERMINAL_STATES as s, type RelaySocket as t, type RfqQuote as u, type RfqRefusalReason as v, SwapRefusal as w, arkadeSwapRequest as x, assertFundable as y, assertReceivable as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkade-os/swap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Client-side Arkade Intents asset swaps: discover markets, quote, create/track/cancel offers, restore from chain.",
|
|
6
6
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@noble/hashes": "2.0.1",
|
|
50
50
|
"@scure/base": "2.0.0",
|
|
51
51
|
"@scure/btc-signer": "2.0.1",
|
|
52
|
-
"@arkade-os/sdk": "0.4.
|
|
52
|
+
"@arkade-os/sdk": "0.4.62"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"nostr-tools": "^2.12.0"
|