@arkade-os/swap 0.0.11 → 0.1.0-rc.0
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 +42 -15
- package/dist/{chunk-RIC5ZTZK.js → chunk-AM3NNUMR.js} +59 -53
- package/dist/index.cjs +585 -202
- package/dist/index.d.cts +127 -36
- package/dist/index.d.ts +127 -36
- package/dist/index.js +528 -157
- package/dist/nostr.cjs +4 -1
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +1 -1
- package/dist/repositories/realm/index.d.cts +4 -4
- package/dist/repositories/realm/index.d.ts +4 -4
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/{repository-CfE18Fif.d.ts → repository-BWP1UstE.d.cts} +84 -56
- package/dist/{repository-B02vsgcV.d.cts → repository-DLpH41ZO.d.ts} +84 -56
- package/dist/{rfq-DkckzRKK.d.ts → rfq-CzCGjICq.d.cts} +42 -32
- package/dist/{rfq-DkckzRKK.d.cts → rfq-CzCGjICq.d.ts} +42 -32
- package/package.json +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VHTLC,
|
|
1
|
+
import { VHTLC, IWallet, ProvisionedClaimSecret, ProvisionedKey, asset } from '@arkade-os/sdk';
|
|
2
2
|
|
|
3
3
|
/** L1 confirmation-depth and reorg margin between dependent timelocks. */
|
|
4
4
|
declare const ONCHAIN_ORDER_MARGIN_SECONDS: number;
|
|
@@ -251,6 +251,10 @@ type RfqRefusalReason = "unsupported_pair" | "unsupported_payload" | "amount_out
|
|
|
251
251
|
declare const RFQ_TERMINAL_STATES: readonly ["settled", "refused", "expired", "refunded", "stuck"];
|
|
252
252
|
/** A refusal from the solver, carrying its closed-set reason. */
|
|
253
253
|
declare class SwapRefusal extends Error {
|
|
254
|
+
/** Literal-typed so the v2 error taxonomy's union discriminates on `name`
|
|
255
|
+
* — a `string` here collapses the discriminant for every member. Same value
|
|
256
|
+
* the constructor has always set, moved to a field initializer. */
|
|
257
|
+
readonly name = "SwapRefusal";
|
|
254
258
|
readonly reason: string;
|
|
255
259
|
readonly rfqId: string | undefined;
|
|
256
260
|
constructor(reason: string, rfqId?: string);
|
|
@@ -297,7 +301,7 @@ interface RfqStatus {
|
|
|
297
301
|
/** The rfq_request for the lightning send profile. A BOLT11 profile is always
|
|
298
302
|
* exact-out: the invoice fixes the amount, so none is restated here.
|
|
299
303
|
* `senderPubkey` is the trader's own key for the VHTLC's sender-side leaves
|
|
300
|
-
* (see {@link
|
|
304
|
+
* (see {@link lightningSendContract}) — required, never sent anywhere else,
|
|
301
305
|
* never trusted by the solver as anything but a pubkey to bind into the
|
|
302
306
|
* script. On the wire it's `client_refund_pubkey` (the payload schemas are
|
|
303
307
|
* public at https://docs.arkadeos.com/intents/reference/rfq — the solver's schema
|
|
@@ -416,7 +420,7 @@ declare const SOLO_REFUND_HEADROOM_SECONDS: number;
|
|
|
416
420
|
* exit delay exactly as the reference solver derives it — both sides read the
|
|
417
421
|
* SAME server, so the derivation (not a quote field) is what keeps the two
|
|
418
422
|
* scripts identical. */
|
|
419
|
-
declare const unilateralClaimDelay: (
|
|
423
|
+
declare const unilateralClaimDelay: (operatorExitDelaySeconds: number) => number;
|
|
420
424
|
/** VHTLC's `unilateralRefund` tier: sender + receiver, no server — LEVEL with
|
|
421
425
|
* `claimDelay`, not above it. Neither party can spend a two-signature leaf
|
|
422
426
|
* alone, so separating it buys no safety, and every second spent separating it
|
|
@@ -444,13 +448,13 @@ declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => numb
|
|
|
444
448
|
* needing no participant at all). Nine leaves in all, unless `legacy` says
|
|
445
449
|
* otherwise.
|
|
446
450
|
*/
|
|
447
|
-
declare function
|
|
451
|
+
declare function lightningSendContract(params: {
|
|
448
452
|
/** Binding field #1: the solver's x-only key, from the quote. */
|
|
449
453
|
solverPubkey: Uint8Array;
|
|
450
454
|
/** Binding field #2: when the trader's refund path opens, from the quote. */
|
|
451
455
|
refundLocktime: number;
|
|
452
456
|
/** The Ark server's x-only key — the trader's OWN connection. */
|
|
453
|
-
|
|
457
|
+
operatorPubkey: Uint8Array;
|
|
454
458
|
/** BOLT11 payment hash, hex — from the trader's OWN invoice decode. */
|
|
455
459
|
paymentHash: string;
|
|
456
460
|
/** From {@link unilateralClaimDelay} over the trader's OWN server info.
|
|
@@ -477,9 +481,9 @@ declare function lightningSendVtxoScript(params: {
|
|
|
477
481
|
* the quote's own address says the solver quoted that shape. */
|
|
478
482
|
legacy?: "preTimelockedRefund";
|
|
479
483
|
}): InstanceType<typeof VHTLC.ScriptV2>;
|
|
480
|
-
/** Every input {@link
|
|
484
|
+
/** Every input {@link lightningSendContract} builds from. Derived from the
|
|
481
485
|
* builder rather than restated, so the two cannot drift. */
|
|
482
|
-
type
|
|
486
|
+
type LightningSendContractParams = Parameters<typeof lightningSendContract>[0];
|
|
483
487
|
/** The BOLT11 facts the trader read from its OWN decode — this module takes
|
|
484
488
|
* the facts, not the decoder, so any wallet's existing decoder serves. */
|
|
485
489
|
interface InvoiceFacts {
|
|
@@ -513,14 +517,15 @@ interface InvoiceFacts {
|
|
|
513
517
|
* throws while nothing is funded. `RfqSwapManager` re-registers as a backstop
|
|
514
518
|
* for older records; a repeat write is a no-op.
|
|
515
519
|
*
|
|
516
|
-
* The `sender` key is the wallet's identity key,
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* cooperation, not just
|
|
520
|
+
* The `sender` key is the wallet's identity key, as {@link provisionRefundKey}
|
|
521
|
+
* pins it — returned as `senderPubkey` plus `secrets`. `secrets` holds only a
|
|
522
|
+
* public descriptor; the signer re-derives from the wallet, so nothing secret
|
|
523
|
+
* is at rest. Persist `secrets` with the record anyway: it is how the refund
|
|
524
|
+
* signer is found again. `nonInteractiveRefund` recovers the funds even
|
|
525
|
+
* without it — but it needs the SOLVER's active cooperation, not just
|
|
526
|
+
* infrastructure uptime.
|
|
522
527
|
*/
|
|
523
|
-
declare function requestLightningSend(wallet: IWallet,
|
|
528
|
+
declare function requestLightningSend(wallet: IWallet, transport: RfqTransport, params: {
|
|
524
529
|
invoice: InvoiceFacts;
|
|
525
530
|
rfqId?: string;
|
|
526
531
|
/** Co-signer key override (33-byte compressed hex); see
|
|
@@ -553,7 +558,7 @@ declare function requestLightningSend(wallet: IWallet, arkServerUrl: string, tra
|
|
|
553
558
|
*
|
|
554
559
|
* Returned so a consumer can persist the swap without re-deriving any of
|
|
555
560
|
* it. Half of these are not on the quote: `serverPubkey` and `claimDelay`
|
|
556
|
-
* come from this wallet's own `
|
|
561
|
+
* come from this wallet's own `getArkadeInfo()`, `emulatorPubkey` from a
|
|
557
562
|
* per-network pin, `refundPkScript` from `secrets` — decoded from the
|
|
558
563
|
* refund address at provisioning time, the same address this call returns
|
|
559
564
|
* as `refundAddress`.
|
|
@@ -565,7 +570,7 @@ declare function requestLightningSend(wallet: IWallet, arkServerUrl: string, tra
|
|
|
565
570
|
* `VHTLCV2ContractHandler.serializeParams(script.options)`, the shape the
|
|
566
571
|
* rebuild accepts.
|
|
567
572
|
*/
|
|
568
|
-
|
|
573
|
+
contractParams: LightningSendContractParams;
|
|
569
574
|
}>;
|
|
570
575
|
/**
|
|
571
576
|
* Map an arkade↔arkade quote onto `createOffer` terms. The trader takes the
|
|
@@ -648,7 +653,7 @@ declare function deriveOnchainSend(input: {
|
|
|
648
653
|
quote: RfqQuote;
|
|
649
654
|
paymentHash: string;
|
|
650
655
|
payoutPubkey: Uint8Array;
|
|
651
|
-
|
|
656
|
+
operatorPubkey: Uint8Array;
|
|
652
657
|
emulatorPubkey: Uint8Array;
|
|
653
658
|
claimDelay: number;
|
|
654
659
|
hrp: string;
|
|
@@ -699,7 +704,7 @@ declare function deriveOnchainSend(input: {
|
|
|
699
704
|
* `claimOnchainFill`) before `htlc.refundLocktime`. Missing that window
|
|
700
705
|
* forfeits the fill and falls back to the Arkade covenant refund.
|
|
701
706
|
*/
|
|
702
|
-
declare function requestOnchainSend(wallet: IWallet,
|
|
707
|
+
declare function requestOnchainSend(wallet: IWallet, transport: RfqTransport, params: {
|
|
703
708
|
amount: number;
|
|
704
709
|
amountSide: "from" | "to";
|
|
705
710
|
/** User's x-only L1 key that will claim the HTLC. */
|
|
@@ -747,6 +752,11 @@ declare function requestOnchainSend(wallet: IWallet, arkServerUrl: string, trans
|
|
|
747
752
|
/** `profile.min_confirmations`; gates when the L1 fill becomes claimable,
|
|
748
753
|
* and part of what a restored swap needs to drive its own claim. */
|
|
749
754
|
minConfirmations: number;
|
|
755
|
+
/** The arkade lockup's refund deadline, as the covenant was built with it.
|
|
756
|
+
* Read this rather than `quote.refund_locktime`: that field is optional on
|
|
757
|
+
* the wire, a solver may carry the value in `profile` instead, and
|
|
758
|
+
* `deriveOnchainSend` is what settles which one this contract used. */
|
|
759
|
+
refundLocktime: number;
|
|
750
760
|
/** The VHTLC `sender` x-only key, bound into the covenant. Public. */
|
|
751
761
|
senderPubkey: Uint8Array;
|
|
752
762
|
/** How the preimage and the `sender` key are recovered later — map it
|
|
@@ -813,12 +823,12 @@ declare const assertReceivable: (input: {
|
|
|
813
823
|
maxPayAmount?: number;
|
|
814
824
|
}) => void;
|
|
815
825
|
/** Compile the RECEIVE-direction VHTLC: the same suite-carrying tree as {@link
|
|
816
|
-
*
|
|
826
|
+
* lightningSendContract} with the roles inverted — the trader is the
|
|
817
827
|
* `receiver` (it generated `P` and claims the lockup with it), the solver is
|
|
818
828
|
* the `sender` (it funds the lockup and holds the refund recourse). One
|
|
819
829
|
* function shared by both receive corridors, mirroring the send legs' sharing
|
|
820
|
-
* of `
|
|
821
|
-
declare function
|
|
830
|
+
* of `lightningSendContract`. */
|
|
831
|
+
declare function lightningReceiveContract(params: {
|
|
822
832
|
/** Binding field #1: the solver's x-only key, from the quote — VHTLC's
|
|
823
833
|
* `sender` role on the receive corridors. */
|
|
824
834
|
solverPubkey: Uint8Array;
|
|
@@ -826,7 +836,7 @@ declare function receiveVtxoScript(params: {
|
|
|
826
836
|
* the quote — after it the solver may reclaim an unclaimed lockup. */
|
|
827
837
|
refundLocktime: number;
|
|
828
838
|
/** The Ark server's x-only key — the trader's OWN connection. */
|
|
829
|
-
|
|
839
|
+
operatorPubkey: Uint8Array;
|
|
830
840
|
/** `sha256(P)`, hex — the trader's OWN preimage hash. */
|
|
831
841
|
paymentHash: string;
|
|
832
842
|
/** From {@link unilateralClaimDelay} over the trader's OWN server info. */
|
|
@@ -846,9 +856,9 @@ declare function receiveVtxoScript(params: {
|
|
|
846
856
|
/** LEGACY REBUILD ONLY — see {@link lightningSendVtxoScript}'s `legacy`. */
|
|
847
857
|
legacy?: "preTimelockedRefund";
|
|
848
858
|
}): InstanceType<typeof VHTLC.ScriptV2>;
|
|
849
|
-
/** Every input {@link
|
|
850
|
-
* {@link
|
|
851
|
-
type
|
|
859
|
+
/** Every input {@link lightningReceiveContract} builds from; see
|
|
860
|
+
* {@link LightningSendContractParams}. */
|
|
861
|
+
type LightningReceiveContractParams = Parameters<typeof lightningReceiveContract>[0];
|
|
852
862
|
/**
|
|
853
863
|
* The pure core of {@link requestLightningReceive}: derive the solver-funded
|
|
854
864
|
* covenant locally from the quote's binding fields plus the trader's own data
|
|
@@ -862,7 +872,7 @@ declare function deriveLightningReceive(input: {
|
|
|
862
872
|
paymentHash: string;
|
|
863
873
|
payoutPubkey: Uint8Array;
|
|
864
874
|
payoutAddress: string;
|
|
865
|
-
|
|
875
|
+
operatorPubkey: Uint8Array;
|
|
866
876
|
emulatorPubkey: Uint8Array;
|
|
867
877
|
claimDelay: number;
|
|
868
878
|
hrp: string;
|
|
@@ -875,7 +885,7 @@ declare function deriveLightningReceive(input: {
|
|
|
875
885
|
refundLocktime: number;
|
|
876
886
|
/** Every input the covenant was built from — see the same field on
|
|
877
887
|
* `requestLightningSend`'s result for why a consumer needs them. */
|
|
878
|
-
|
|
888
|
+
contractParams: LightningReceiveContractParams;
|
|
879
889
|
};
|
|
880
890
|
/**
|
|
881
891
|
* The `lightning:BTC->arkade:BTC` user flow: quote → derive the covenant
|
|
@@ -908,7 +918,7 @@ declare function deriveLightningReceive(input: {
|
|
|
908
918
|
* Pay before `invoiceExpiresAt`: the hold-invoice window is minutes, not the
|
|
909
919
|
* quote's `valid_until`.
|
|
910
920
|
*/
|
|
911
|
-
declare function requestLightningReceive(wallet: IWallet,
|
|
921
|
+
declare function requestLightningReceive(wallet: IWallet, transport: RfqTransport, params: {
|
|
912
922
|
amount: number;
|
|
913
923
|
amountSide: "from" | "to";
|
|
914
924
|
/** Co-signer key override (33-byte compressed hex); see
|
|
@@ -953,7 +963,7 @@ declare function requestLightningReceive(wallet: IWallet, arkServerUrl: string,
|
|
|
953
963
|
secrets: ProvisionedClaimSecret;
|
|
954
964
|
/** Every input the covenant was built from; see the same field on
|
|
955
965
|
* `requestLightningSend`'s result. */
|
|
956
|
-
|
|
966
|
+
contractParams: LightningReceiveContractParams;
|
|
957
967
|
}>;
|
|
958
968
|
/**
|
|
959
969
|
* The pure core of {@link requestOnchainReceive}: derive BOTH contracts
|
|
@@ -969,7 +979,7 @@ declare function deriveOnchainReceive(input: {
|
|
|
969
979
|
payoutAddress: string;
|
|
970
980
|
/** The trader's own x-only L1 key — the HTLC's refund role. */
|
|
971
981
|
refundPubkey: Uint8Array;
|
|
972
|
-
|
|
982
|
+
operatorPubkey: Uint8Array;
|
|
973
983
|
emulatorPubkey: Uint8Array;
|
|
974
984
|
claimDelay: number;
|
|
975
985
|
hrp: string;
|
|
@@ -997,7 +1007,7 @@ declare function deriveOnchainReceive(input: {
|
|
|
997
1007
|
* `refundPubkey`) opens at `htlc.refundLocktime` — `buildHtlcRefund` takes it
|
|
998
1008
|
* back from there.
|
|
999
1009
|
*/
|
|
1000
|
-
declare function requestOnchainReceive(wallet: IWallet,
|
|
1010
|
+
declare function requestOnchainReceive(wallet: IWallet, transport: RfqTransport, params: {
|
|
1001
1011
|
amount: number;
|
|
1002
1012
|
amountSide: "from" | "to";
|
|
1003
1013
|
/** Co-signer key override (33-byte compressed hex); see
|
|
@@ -1030,4 +1040,4 @@ declare function requestOnchainReceive(wallet: IWallet, arkServerUrl: string, tr
|
|
|
1030
1040
|
secrets: ProvisionedClaimSecret;
|
|
1031
1041
|
}>;
|
|
1032
1042
|
|
|
1033
|
-
export {
|
|
1043
|
+
export { lightningReceiveRequest as $, ARKADE_ASSET as A, type RfqRefusalReason as B, type ChainSource as C, type RfqStatus as D, SwapRefusal as E, arkadeAssetLeg as F, arkadeSwapRequest as G, type HtlcUtxo as H, type InvoiceFacts as I, assertFundable as J, assertReceivable as K, LIGHTNING_BTC as L, MAX_MIN_CONFIRMATIONS as M, awaitOnchainFill as N, type OnchainNetwork as O, buildHtlcClaim as P, buildHtlcRefund as Q, type RfqTransport as R, SOLO_REFUND_HEADROOM_SECONDS as S, claimOnchainFill as T, classifyOnchainHtlc as U, deriveLightningReceive as V, deriveOnchainReceive as W, deriveOnchainSend as X, extractPreimage as Y, httpTransport as Z, lightningReceiveContract as _, type OnchainHtlc as a, lightningSendContract as a0, lightningSendRequest as a1, newPreimage as a2, newRfqId as a3, offerTermsFromQuote as a4, onchainHtlcScript as a5, onchainReceiveRequest as a6, onchainSendRequest as a7, paymentHashOf as a8, relayTransport as a9, requestOnchainReceive as aa, rfqPair as ab, unilateralClaimDelay as ac, unilateralRefundDelay as ad, unilateralRefundWithoutReceiverDelay as ae, verifyLockupAddress as af, verifyReceiveInvoice as ag, type OnchainHtlcParams as b, requestLightningSend as c, requestOnchainSend as d, ARKADE_BTC as e, AddressMismatch as f, type ChainUtxo as g, LIGHTNING_RECEIVE_PAIR as h, LIGHTNING_SEND_PAIR as i, LOCKTIME_THRESHOLD as j, type LightningReceiveContractParams as k, type LightningSendContractParams as l, MIN_CLAIM_WINDOW_SECONDS as m, MIN_HEADROOM_SECONDS as n, ONCHAIN_BTC as o, ONCHAIN_CLAIM_MARGIN_SECONDS as p, ONCHAIN_DUST_SATS as q, requestLightningReceive as r, ONCHAIN_ORDER_MARGIN_SECONDS as s, ONCHAIN_RECEIVE_PAIR as t, ONCHAIN_SECONDS_PER_BLOCK as u, ONCHAIN_SEND_PAIR as v, type OnchainHtlcPhase as w, RFQ_TERMINAL_STATES as x, type RelaySocket as y, type RfqQuote 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.1.0-rc.0",
|
|
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": {
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
"@noble/hashes": "2.0.1",
|
|
71
71
|
"@scure/base": "2.0.0",
|
|
72
72
|
"@scure/btc-signer": "2.0.1",
|
|
73
|
-
"
|
|
73
|
+
"light-bolt11-decoder": "3.2.0",
|
|
74
|
+
"@arkade-os/sdk": "0.5.0-rc.0"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"nostr-tools": "^2.12.0"
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
},
|
|
91
92
|
"scripts": {
|
|
92
93
|
"build": "tsup src/index.ts src/nostr.ts src/repositories/sqlite/index.ts src/repositories/realm/index.ts --format esm,cjs --dts --clean",
|
|
93
|
-
"typecheck": "tsc --noEmit",
|
|
94
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
94
95
|
"format": "biome format --write src test",
|
|
95
96
|
"lint": "biome format src test",
|
|
96
97
|
"test": "vitest run --exclude test/e2e",
|