@arkade-os/swap 0.0.9 → 0.0.11
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 +17 -0
- package/dist/{chunk-2FEMUOIH.js → chunk-RIC5ZTZK.js} +71 -33
- package/dist/index.cjs +235 -52
- package/dist/index.d.cts +61 -15
- package/dist/index.d.ts +61 -15
- package/dist/index.js +166 -20
- 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 +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/{repository-DEHLtD9l.d.cts → repository-B02vsgcV.d.cts} +106 -12
- package/dist/{repository-DIAr5XYk.d.ts → repository-CfE18Fif.d.ts} +106 -12
- package/dist/{rfq-hbzhTWHT.d.ts → rfq-DkckzRKK.d.cts} +54 -24
- package/dist/{rfq-hbzhTWHT.d.cts → rfq-DkckzRKK.d.ts} +54 -24
- package/package.json +4 -4
|
@@ -255,11 +255,15 @@ declare class SwapRefusal extends Error {
|
|
|
255
255
|
readonly rfqId: string | undefined;
|
|
256
256
|
constructor(reason: string, rfqId?: string);
|
|
257
257
|
}
|
|
258
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* The solver's address does not match the local derivation. NEVER fund past
|
|
260
|
+
* this. `derived` is every candidate address tried — more than one when the
|
|
261
|
+
* derivation itself is ambiguous, see {@link verifyLockupAddress}.
|
|
262
|
+
*/
|
|
259
263
|
declare class AddressMismatch extends Error {
|
|
260
|
-
readonly derived: string;
|
|
264
|
+
readonly derived: string | string[];
|
|
261
265
|
readonly quoted: string | undefined;
|
|
262
|
-
constructor(derived: string, quoted?: string);
|
|
266
|
+
constructor(derived: string | string[], quoted?: string);
|
|
263
267
|
}
|
|
264
268
|
/** A fresh client-chosen negotiation id: 32 random bytes, lowercase hex. */
|
|
265
269
|
declare const newRfqId: () => string;
|
|
@@ -323,9 +327,24 @@ declare const arkadeSwapRequest: (input: {
|
|
|
323
327
|
* 90 because the refund CLTV matures against median-time-past (BIP-113),
|
|
324
328
|
* which lags wall clock by ~1h — a smaller wall-clock margin is no margin. */
|
|
325
329
|
declare const MIN_HEADROOM_SECONDS: number;
|
|
326
|
-
/**
|
|
327
|
-
*
|
|
328
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Compare-only check of the solver's address against YOUR OWN derivation(s)
|
|
332
|
+
* — never extends trust, only narrows it.
|
|
333
|
+
*
|
|
334
|
+
* `derivedAddress` may be a single address or an array of candidates. Pass an
|
|
335
|
+
* array when your own derivation is ambiguous — as it is for the covenant
|
|
336
|
+
* lockups while solvers roll out the timelocked non-interactive refund leaf:
|
|
337
|
+
* nothing on the wire says whether a given quote's covenant carries it (the
|
|
338
|
+
* shape is fixed by the solver's own build, not negotiated per quote), so the
|
|
339
|
+
* only safe move is to derive BOTH shapes and accept whichever one the quote's
|
|
340
|
+
* own `lockup_address` matches. This loses no security: every candidate shape
|
|
341
|
+
* pins the refund to the trader's own refund destination, so a solver gains
|
|
342
|
+
* nothing by choosing which one to quote.
|
|
343
|
+
*
|
|
344
|
+
* Throws {@link AddressMismatch} only when NONE of the candidates match.
|
|
345
|
+
* Returns the address that matched, so calls chain exactly as before.
|
|
346
|
+
*/
|
|
347
|
+
declare const verifyLockupAddress: (quote: RfqQuote, derivedAddress: string | string[]) => string;
|
|
329
348
|
/** The user's gates, checked immediately before funding — never at quote
|
|
330
349
|
* time. Throws with a stable `reason` property. `invoiceExpiresAt` applies to
|
|
331
350
|
* BOLT11 profiles only; `onchain` adds the L1-HTLC gates (§ guardrails of the
|
|
@@ -413,15 +432,17 @@ declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => numb
|
|
|
413
432
|
* hex); the script's HASH160 commitment is derived from it here, which is why
|
|
414
433
|
* the trader never needs to see `P`.
|
|
415
434
|
*
|
|
416
|
-
* Every quote gets the full
|
|
435
|
+
* Every quote gets the full emulator-covenant suite on top of VHTLC's own six
|
|
417
436
|
* (`claim`/`refund`/`refundWithoutReceiver`/`unilateralClaim`/
|
|
418
|
-
* `unilateralRefund`/`unilateralRefundWithoutReceiver`)
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
* own `
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
437
|
+
* `unilateralRefund`/`unilateralRefundWithoutReceiver`): `nonInteractiveClaim`
|
|
438
|
+
* (server + emulator, pays the solver's own `receiverPkScript`, no solver
|
|
439
|
+
* signature needed), `nonInteractiveRefund` (server + solver + emulator, pays
|
|
440
|
+
* the trader's own `refundPkScript`, no timelock and no trader signature
|
|
441
|
+
* needed — see {@link VHTLC.Options.nonInteractiveParameters}'s doc comment for why
|
|
442
|
+
* that matters), and its timelocked twin `nonInteractiveRefundWithoutReceiver`
|
|
443
|
+
* (server + emulator alone, after `refundLocktime` — the only refund tier
|
|
444
|
+
* needing no participant at all). Nine leaves in all, unless `legacy` says
|
|
445
|
+
* otherwise.
|
|
425
446
|
*/
|
|
426
447
|
declare function lightningSendVtxoScript(params: {
|
|
427
448
|
/** Binding field #1: the solver's x-only key, from the quote. */
|
|
@@ -439,7 +460,7 @@ declare function lightningSendVtxoScript(params: {
|
|
|
439
460
|
/** Emulator x-only key (32 bytes). */
|
|
440
461
|
emulatorPubkey: Uint8Array;
|
|
441
462
|
/** Where a refund must pay: the trader's P2TR pkScript (34 bytes). Also
|
|
442
|
-
*
|
|
463
|
+
* the refund covenants' destination. */
|
|
443
464
|
refundPkScript: Uint8Array;
|
|
444
465
|
/** The trader's own key — VHTLC's `sender` role. Required on every
|
|
445
466
|
* interactive refund-side leaf; the trader generates and persists it
|
|
@@ -450,6 +471,11 @@ declare function lightningSendVtxoScript(params: {
|
|
|
450
471
|
* covenant key can be derived; the trader does not otherwise use or trust
|
|
451
472
|
* this value. P2TR pkScript, 34 bytes. */
|
|
452
473
|
receiverPkScript: Uint8Array;
|
|
474
|
+
/** LEGACY REBUILD ONLY — see {@link VHTLC.Options.nonInteractiveParameters}'s
|
|
475
|
+
* `legacy` field. Set only to re-derive a lockup funded before the
|
|
476
|
+
* timelocked refund leaf shipped; {@link matchQuotedLockup} passes it when
|
|
477
|
+
* the quote's own address says the solver quoted that shape. */
|
|
478
|
+
legacy?: "preTimelockedRefund";
|
|
453
479
|
}): InstanceType<typeof VHTLC.ScriptV2>;
|
|
454
480
|
/** Every input {@link lightningSendVtxoScript} builds from. Derived from the
|
|
455
481
|
* builder rather than restated, so the two cannot drift. */
|
|
@@ -487,12 +513,11 @@ interface InvoiceFacts {
|
|
|
487
513
|
* throws while nothing is funded. `RfqSwapManager` re-registers as a backstop
|
|
488
514
|
* for older records; a repeat write is a no-op.
|
|
489
515
|
*
|
|
490
|
-
* The `sender` key
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
* recovers the funds even without it — but it needs the SOLVER's active
|
|
516
|
+
* The `sender` key is the wallet's identity key, reused by {@link
|
|
517
|
+
* provisionRefundKey} — returned as `senderPubkey` plus `secrets`. `secrets`
|
|
518
|
+
* holds only a public descriptor; the signer re-derives from the wallet, so
|
|
519
|
+
* nothing secret is at rest. Persist `secrets` with the record anyway: it is
|
|
520
|
+
* how the refund signer is found again. `nonInteractiveRefund` recovers the funds even without it — but it needs the SOLVER's active
|
|
496
521
|
* cooperation, not just infrastructure uptime.
|
|
497
522
|
*/
|
|
498
523
|
declare function requestLightningSend(wallet: IWallet, arkServerUrl: string, transport: RfqTransport, params: {
|
|
@@ -515,7 +540,8 @@ declare function requestLightningSend(wallet: IWallet, arkServerUrl: string, tra
|
|
|
515
540
|
* `lockup` (with `address`): without it the manager can only poll, and
|
|
516
541
|
* cannot retire the row this call just wrote. */
|
|
517
542
|
script: InstanceType<typeof VHTLC.ScriptV2>;
|
|
518
|
-
/** Where a failed swap refunds.
|
|
543
|
+
/** Where a failed swap refunds — the same address `secrets.pkScript` was
|
|
544
|
+
* decoded from, so the quote and the covenant always name one script. */
|
|
519
545
|
refundAddress: string;
|
|
520
546
|
/** The VHTLC `sender` x-only key, bound into the covenant. Public. */
|
|
521
547
|
senderPubkey: Uint8Array;
|
|
@@ -528,7 +554,9 @@ declare function requestLightningSend(wallet: IWallet, arkServerUrl: string, tra
|
|
|
528
554
|
* Returned so a consumer can persist the swap without re-deriving any of
|
|
529
555
|
* it. Half of these are not on the quote: `serverPubkey` and `claimDelay`
|
|
530
556
|
* come from this wallet's own `getInfo()`, `emulatorPubkey` from a
|
|
531
|
-
* per-network pin, `refundPkScript` from
|
|
557
|
+
* per-network pin, `refundPkScript` from `secrets` — decoded from the
|
|
558
|
+
* refund address at provisioning time, the same address this call returns
|
|
559
|
+
* as `refundAddress`.
|
|
532
560
|
*
|
|
533
561
|
* All public. Persisting them is optional: this call also registers the
|
|
534
562
|
* lockup as a contract, and that row is where `rebuildRfqSwap` takes its
|
|
@@ -784,7 +812,7 @@ declare const assertReceivable: (input: {
|
|
|
784
812
|
/** Absolute sats ceiling on `from_amount`. */
|
|
785
813
|
maxPayAmount?: number;
|
|
786
814
|
}) => void;
|
|
787
|
-
/** Compile the RECEIVE-direction VHTLC: the same
|
|
815
|
+
/** Compile the RECEIVE-direction VHTLC: the same suite-carrying tree as {@link
|
|
788
816
|
* lightningSendVtxoScript} with the roles inverted — the trader is the
|
|
789
817
|
* `receiver` (it generated `P` and claims the lockup with it), the solver is
|
|
790
818
|
* the `sender` (it funds the lockup and holds the refund recourse). One
|
|
@@ -815,6 +843,8 @@ declare function receiveVtxoScript(params: {
|
|
|
815
843
|
/** The trader's own Arkade payout pkScript (decoded from its payout
|
|
816
844
|
* address) — `nonInteractiveClaim`'s pinned destination. */
|
|
817
845
|
payoutPkScript: Uint8Array;
|
|
846
|
+
/** LEGACY REBUILD ONLY — see {@link lightningSendVtxoScript}'s `legacy`. */
|
|
847
|
+
legacy?: "preTimelockedRefund";
|
|
818
848
|
}): InstanceType<typeof VHTLC.ScriptV2>;
|
|
819
849
|
/** Every input {@link receiveVtxoScript} builds from; see
|
|
820
850
|
* {@link LightningSendTreeParams}. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkade-os/swap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
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,7 @@
|
|
|
70
70
|
"@noble/hashes": "2.0.1",
|
|
71
71
|
"@scure/base": "2.0.0",
|
|
72
72
|
"@scure/btc-signer": "2.0.1",
|
|
73
|
-
"@arkade-os/sdk": "0.4.
|
|
73
|
+
"@arkade-os/sdk": "0.4.68"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"nostr-tools": "^2.12.0"
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "tsup src/index.ts src/nostr.ts src/repositories/sqlite/index.ts src/repositories/realm/index.ts --format esm,cjs --dts --clean",
|
|
93
93
|
"typecheck": "tsc --noEmit",
|
|
94
|
-
"format": "
|
|
95
|
-
"lint": "
|
|
94
|
+
"format": "biome format --write src test",
|
|
95
|
+
"lint": "biome format src test",
|
|
96
96
|
"test": "vitest run --exclude test/e2e",
|
|
97
97
|
"test:unit": "vitest run --exclude test/e2e",
|
|
98
98
|
"test:integration": "vitest run test/e2e/** --exclude test/e2e/rfq*.test.ts",
|