@arkade-os/swap 0.1.0-rc.9 → 0.1.1

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.
Files changed (57) hide show
  1. package/README.md +261 -252
  2. package/dist/advanced.cjs +6613 -3224
  3. package/dist/advanced.d.cts +328 -283
  4. package/dist/advanced.d.ts +328 -283
  5. package/dist/advanced.js +347 -34
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-FMRAV77W.js +3065 -0
  8. package/dist/chunk-T4FHBWZI.js +3459 -0
  9. package/dist/{chunk-NS3K6BZG.js → chunk-YHESEL4I.js} +1792 -636
  10. package/dist/index.cjs +6901 -3901
  11. package/dist/index.d.cts +71 -243
  12. package/dist/index.d.ts +71 -243
  13. package/dist/index.js +131 -167
  14. package/dist/lockupContract-CIXkJPxV.d.ts +148 -0
  15. package/dist/lockupContract-CkhWMKCo.d.cts +148 -0
  16. package/dist/node/index.cjs +61 -10
  17. package/dist/node/index.d.cts +307 -635
  18. package/dist/node/index.d.ts +307 -635
  19. package/dist/node/index.js +65 -10
  20. package/dist/nostr.cjs +427 -49
  21. package/dist/nostr.d.cts +59 -70
  22. package/dist/nostr.d.ts +59 -70
  23. package/dist/nostr.js +268 -36
  24. package/dist/offer-BPD2ortO.d.ts +269 -0
  25. package/dist/offer-Diff5Flc.d.cts +269 -0
  26. package/dist/offerFillPlan-B-5ae_gQ.d.cts +1671 -0
  27. package/dist/offerFillPlan-CJzneX6F.d.ts +1671 -0
  28. package/dist/protocol.cjs +5717 -4275
  29. package/dist/protocol.d.cts +258 -328
  30. package/dist/protocol.d.ts +258 -328
  31. package/dist/protocol.js +200 -224
  32. package/dist/repositories/realm/index.cjs +55 -11
  33. package/dist/repositories/realm/index.d.cts +18 -30
  34. package/dist/repositories/realm/index.d.ts +18 -30
  35. package/dist/repositories/realm/index.js +49 -12
  36. package/dist/repositories/sqlite/index.cjs +61 -10
  37. package/dist/repositories/sqlite/index.d.cts +7 -6
  38. package/dist/repositories/sqlite/index.d.ts +7 -6
  39. package/dist/repositories/sqlite/index.js +57 -11
  40. package/dist/repository-BBVRh9ez.d.ts +2357 -0
  41. package/dist/repository-C4pvymhs.d.cts +2357 -0
  42. package/dist/{rfq-BO6o7NwS.d.ts → rfq-C0tHOvn6.d.cts} +323 -444
  43. package/dist/{rfq-BO6o7NwS.d.cts → rfq-C0tHOvn6.d.ts} +323 -444
  44. package/dist/watch-7BiRa4oB.d.ts +74 -0
  45. package/dist/watch-Bxq-lx_6.d.cts +74 -0
  46. package/package.json +10 -10
  47. package/dist/chunk-JFKGMPMH.js +0 -3456
  48. package/dist/chunk-LLG7RD2T.js +0 -1499
  49. package/dist/chunk-U7VWWTL6.js +0 -66
  50. package/dist/errors-CNISbN0M.d.ts +0 -2218
  51. package/dist/errors-DwNhIP0N.d.cts +0 -2218
  52. package/dist/lockupContract-C8-Mcg69.d.ts +0 -664
  53. package/dist/lockupContract-mIt4syse.d.cts +0 -664
  54. package/dist/repository-CGPLbjBe.d.ts +0 -3489
  55. package/dist/repository-DSGGq0ct.d.cts +0 -3489
  56. package/dist/watch-DWyVqyEN.d.cts +0 -96
  57. package/dist/watch-DmvHNX6T.d.ts +0 -96
package/dist/nostr.d.cts CHANGED
@@ -1,84 +1,71 @@
1
- import { e as RfqTransport } from './rfq-BO6o7NwS.cjs';
1
+ import { TransportCardFetcher } from '@arkade-os/solver-discovery';
2
+ import { e as RfqTransport } from './rfq-C0tHOvn6.cjs';
2
3
  import { SimplePool } from 'nostr-tools';
3
4
  import '@arkade-os/sdk';
4
5
 
5
6
  /**
6
- * The Nostr RFQ transport — the PRODUCTION one (the kind, the NIP-44 framing
7
- * and the payloads it carries are public at
8
- * https://docs.arkadeos.com/intents/reference/rfq).
7
+ * One shared Nostr pool for every swap-package reader and writer.
9
8
  *
10
- * `rfq.ts` ships two other transports: `httpTransport`, and `relayTransport`
11
- * which speaks the dev broker's `{op:"sub"|"event"}` framing. Neither is what a
12
- * deployed solver listens on. This is, and it satisfies the same
13
- * {@link RfqTransport} interface, so everything above the transport — the user
14
- * flow, quote verification, the store — is identical whichever one it is handed.
9
+ * nostr-tools' SimplePool already multiplexes subscriptions over one WebSocket
10
+ * per relay, but only within a single pool instance. A pool per transport or
11
+ * per card fetch means one socket per relay per concurrent use, each with its
12
+ * own lifecycle, plus "already in CLOSING" races when two owners tear down the
13
+ * same relay. Sharing one pool collapses that to one socket per relay per app,
14
+ * with subscriptions multiplexed at the protocol level.
15
15
  *
16
- * ## Why this is a separate entry point
17
- *
18
- * Imported as `@arkade-os/swap/nostr`, never from the package root, and
19
- * `nostr-tools` is an OPTIONAL peer dependency. A consumer doing HTTP-only
20
- * swaps should not pay for a Nostr library it never calls, and re-exporting
21
- * this from `index.ts` would put `nostr-tools` in every consumer's module graph
22
- * whether or not they resolve it. The subpath is what keeps that promise: the
23
- * module is only loaded if it is imported.
24
- *
25
- * The consequence, stated plainly: importing this subpath without `nostr-tools`
26
- * installed fails at resolution with a module-not-found. That is the intended
27
- * failure — loud, at the import, naming the missing package — rather than a
28
- * transport that silently degrades.
29
- *
30
- * A dynamic `await import()` inside the factory would also defer the cost, but
31
- * it would make construction async. This transport opens its subscription
32
- * eagerly, on purpose (see below), so an async factory would push a `await`
33
- * into every caller for no benefit the subpath does not already give.
16
+ * The pool is process-wide and never closed by borrowers: transports and card
17
+ * fetches close only their own subscription, and a relay's socket closes once
18
+ * nothing has used it for IDLE_CLOSE_MS. closeSharedNostrPool() tears it all
19
+ * down at once, for tests and short-lived scripts.
34
20
  */
35
21
 
22
+ type NostrPool = SimplePool;
36
23
  /**
37
- * Directed RFQ traffic. Provisional in the spec; kept in one place.
38
- *
39
- * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the
40
- * solver's `NOSTR_KIND_DIRECTED`. The two sides subscribe by `kinds`, so a
41
- * mismatch is not an error either can report — they simply never see each
42
- * other, and every request times out blaming the solver.
43
- *
44
- * Ephemeral because a negotiation is worthless once it is over: a request
45
- * nobody answered inside the timeout, and a quote past its `valid_until`, help
46
- * no one, while a retained copy is a permanent record of who negotiated what
47
- * with whom. The cost is no store-and-forward — a request sent while the solver
48
- * is disconnected is dropped rather than queued — which the timeout and the
49
- * caller's retry cover.
24
+ * A pool safe to share: per-subscription idle accounting, and a keep-alive ping
25
+ * that drops a half-open socket instead of letting every quote on it time out.
50
26
  */
51
- declare const RFQ_DIRECTED_KIND = 24859;
27
+ declare const createNostrPool: () => SimplePool;
28
+ /** The process-wide pool. Lazy, so HTTP-only consumers never touch the network. */
29
+ declare const sharedNostrPool: () => SimplePool;
52
30
  /**
53
- * Indicative solver advertisement — never binding; only a quote binds.
31
+ * Tear down the shared pool. Borrowers must have closed their subscriptions
32
+ * (transport.close(), or the card fetcher's own timeout/EOSE path). For tests
33
+ * and short-lived scripts that should not wait out IDLE_CLOSE_MS.
34
+ */
35
+ declare const closeSharedNostrPool: () => void;
36
+
37
+ /**
38
+ * The Nostr RFQ transport — the PRODUCTION one; `httpTransport` and the dev-broker
39
+ * `relayTransport` in `rfq.ts` are not what deployed solvers listen on. The kind, NIP-44 framing
40
+ * and payloads are public at https://docs.arkadeos.com/intents/reference/rfq.
54
41
  *
55
- * Addressable (30000–39999) rather than ephemeral, deliberately: an ad is
56
- * standing state a relay should keep the current version of, not a message in a
57
- * negotiation. The two constants want OPPOSITE retention, and neither is a typo
58
- * of the other.
42
+ * A separate entry point (`@arkade-os/swap/nostr`) so `nostr-tools`, an OPTIONAL peer dependency,
43
+ * stays out of HTTP-only consumers' module graphs. Importing it without `nostr-tools` installed
44
+ * fails loudly at resolution, by design. A dynamic `import()` in the factory was rejected: it
45
+ * would make construction async, and the subscription is opened eagerly.
59
46
  */
60
- declare const RFQ_AD_KIND = 38859;
47
+
61
48
  /**
62
- * Every relay dropped the subscription, so no reply can arrive on it.
49
+ * Directed RFQ traffic. Provisional in the spec.
63
50
  *
64
- * Distinct from a timeout on purpose. Both look like "no answer", but they mean
65
- * opposite things: a timeout says the solver did not respond, while this says
66
- * we were never in a position to hear it. Without the distinction the transport
67
- * waits out the full timeout and then blames the solver for a failure on our
68
- * own side of the wire.
51
+ * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the solver's
52
+ * `NOSTR_KIND_DIRECTED`: both sides subscribe by `kinds`, so a mismatch surfaces only as every
53
+ * request timing out. Ephemeral because a finished negotiation is worthless and a retained copy
54
+ * records who negotiated with whom; the cost (no store-and-forward) is covered by timeout + retry.
55
+ */
56
+ declare const RFQ_DIRECTED_KIND = 24859;
57
+
58
+ /**
59
+ * Every relay dropped the subscription, so no reply can arrive on it. Distinct from a timeout:
60
+ * that says the solver did not respond, this says we could never have heard it.
69
61
  */
70
62
  declare class RelayUnavailable extends Error {
71
63
  readonly reasons: string[];
72
64
  constructor(reasons: string[]);
73
65
  }
74
66
  /**
75
- * `close()` was called while a negotiation was still waiting on a reply.
76
- *
77
- * Distinct from both a timeout and {@link RelayUnavailable}, which describe the
78
- * wire; this describes a decision on our own side of it. A caller that closed
79
- * deliberately — a user leaving the screen, a flow abandoning its request — can
80
- * match on this and stay quiet, rather than reporting a solver failure that
81
- * never happened.
67
+ * `close()` was called while a negotiation was still waiting on a reply. A deliberate local
68
+ * decision, so a caller can match on it and stay quiet rather than report a solver failure.
82
69
  */
83
70
  declare class TransportClosed extends Error {
84
71
  constructor();
@@ -89,10 +76,8 @@ interface NostrRfqOptions {
89
76
  /** The card's `discovery_pubkey`, x-only hex — who we address. */
90
77
  solverPubkey: string;
91
78
  /**
92
- * Transport key. Defaults to a FRESH key per transport, deliberately: the
93
- * negotiation should not be linkable to a long-term identity, and nothing in
94
- * the protocol needs a stable client key — the quote binds to the covenant,
95
- * not to who asked for it.
79
+ * Transport key. Defaults to a FRESH key per transport so the negotiation is not linkable to
80
+ * a long-term identity; the quote binds to the covenant, not to who asked.
96
81
  */
97
82
  secretKey?: Uint8Array;
98
83
  /** Injectable for tests; a caller may also share one pool across swaps. */
@@ -100,12 +85,16 @@ interface NostrRfqOptions {
100
85
  timeoutMs?: number;
101
86
  }
102
87
  /**
103
- * Build an `RfqTransport` speaking kind-24859 directed traffic.
104
- *
105
- * Sends are fire-and-forget publishes; replies arrive on a single long-lived
106
- * subscription filtered to this transport key, so a reply that arrives before
107
- * the publish promise settles is not missed.
88
+ * Build an `RfqTransport` speaking kind-24859 directed traffic. Replies arrive on one
89
+ * long-lived subscription filtered to this transport key.
108
90
  */
109
91
  declare const nostrRfqTransport: (options: NostrRfqOptions) => RfqTransport;
92
+ interface NostrCardFetcherOptions {
93
+ /** Injectable for tests; a lent pool is never closed, only the subscription on it. */
94
+ pool?: SimplePool;
95
+ /** How long to wait for every relay's EOSE before answering with what arrived. */
96
+ timeoutMs?: number;
97
+ }
98
+ declare const nostrCardFetcher: (options?: NostrCardFetcherOptions) => TransportCardFetcher;
110
99
 
111
- export { type NostrRfqOptions, RFQ_AD_KIND, RFQ_DIRECTED_KIND, RelayUnavailable, TransportClosed, nostrRfqTransport };
100
+ export { type NostrCardFetcherOptions, type NostrPool, type NostrRfqOptions, RFQ_DIRECTED_KIND, RelayUnavailable, TransportClosed, closeSharedNostrPool, createNostrPool, nostrCardFetcher, nostrRfqTransport, sharedNostrPool };
package/dist/nostr.d.ts CHANGED
@@ -1,84 +1,71 @@
1
- import { e as RfqTransport } from './rfq-BO6o7NwS.js';
1
+ import { TransportCardFetcher } from '@arkade-os/solver-discovery';
2
+ import { e as RfqTransport } from './rfq-C0tHOvn6.js';
2
3
  import { SimplePool } from 'nostr-tools';
3
4
  import '@arkade-os/sdk';
4
5
 
5
6
  /**
6
- * The Nostr RFQ transport — the PRODUCTION one (the kind, the NIP-44 framing
7
- * and the payloads it carries are public at
8
- * https://docs.arkadeos.com/intents/reference/rfq).
7
+ * One shared Nostr pool for every swap-package reader and writer.
9
8
  *
10
- * `rfq.ts` ships two other transports: `httpTransport`, and `relayTransport`
11
- * which speaks the dev broker's `{op:"sub"|"event"}` framing. Neither is what a
12
- * deployed solver listens on. This is, and it satisfies the same
13
- * {@link RfqTransport} interface, so everything above the transport — the user
14
- * flow, quote verification, the store — is identical whichever one it is handed.
9
+ * nostr-tools' SimplePool already multiplexes subscriptions over one WebSocket
10
+ * per relay, but only within a single pool instance. A pool per transport or
11
+ * per card fetch means one socket per relay per concurrent use, each with its
12
+ * own lifecycle, plus "already in CLOSING" races when two owners tear down the
13
+ * same relay. Sharing one pool collapses that to one socket per relay per app,
14
+ * with subscriptions multiplexed at the protocol level.
15
15
  *
16
- * ## Why this is a separate entry point
17
- *
18
- * Imported as `@arkade-os/swap/nostr`, never from the package root, and
19
- * `nostr-tools` is an OPTIONAL peer dependency. A consumer doing HTTP-only
20
- * swaps should not pay for a Nostr library it never calls, and re-exporting
21
- * this from `index.ts` would put `nostr-tools` in every consumer's module graph
22
- * whether or not they resolve it. The subpath is what keeps that promise: the
23
- * module is only loaded if it is imported.
24
- *
25
- * The consequence, stated plainly: importing this subpath without `nostr-tools`
26
- * installed fails at resolution with a module-not-found. That is the intended
27
- * failure — loud, at the import, naming the missing package — rather than a
28
- * transport that silently degrades.
29
- *
30
- * A dynamic `await import()` inside the factory would also defer the cost, but
31
- * it would make construction async. This transport opens its subscription
32
- * eagerly, on purpose (see below), so an async factory would push a `await`
33
- * into every caller for no benefit the subpath does not already give.
16
+ * The pool is process-wide and never closed by borrowers: transports and card
17
+ * fetches close only their own subscription, and a relay's socket closes once
18
+ * nothing has used it for IDLE_CLOSE_MS. closeSharedNostrPool() tears it all
19
+ * down at once, for tests and short-lived scripts.
34
20
  */
35
21
 
22
+ type NostrPool = SimplePool;
36
23
  /**
37
- * Directed RFQ traffic. Provisional in the spec; kept in one place.
38
- *
39
- * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the
40
- * solver's `NOSTR_KIND_DIRECTED`. The two sides subscribe by `kinds`, so a
41
- * mismatch is not an error either can report — they simply never see each
42
- * other, and every request times out blaming the solver.
43
- *
44
- * Ephemeral because a negotiation is worthless once it is over: a request
45
- * nobody answered inside the timeout, and a quote past its `valid_until`, help
46
- * no one, while a retained copy is a permanent record of who negotiated what
47
- * with whom. The cost is no store-and-forward — a request sent while the solver
48
- * is disconnected is dropped rather than queued — which the timeout and the
49
- * caller's retry cover.
24
+ * A pool safe to share: per-subscription idle accounting, and a keep-alive ping
25
+ * that drops a half-open socket instead of letting every quote on it time out.
50
26
  */
51
- declare const RFQ_DIRECTED_KIND = 24859;
27
+ declare const createNostrPool: () => SimplePool;
28
+ /** The process-wide pool. Lazy, so HTTP-only consumers never touch the network. */
29
+ declare const sharedNostrPool: () => SimplePool;
52
30
  /**
53
- * Indicative solver advertisement — never binding; only a quote binds.
31
+ * Tear down the shared pool. Borrowers must have closed their subscriptions
32
+ * (transport.close(), or the card fetcher's own timeout/EOSE path). For tests
33
+ * and short-lived scripts that should not wait out IDLE_CLOSE_MS.
34
+ */
35
+ declare const closeSharedNostrPool: () => void;
36
+
37
+ /**
38
+ * The Nostr RFQ transport — the PRODUCTION one; `httpTransport` and the dev-broker
39
+ * `relayTransport` in `rfq.ts` are not what deployed solvers listen on. The kind, NIP-44 framing
40
+ * and payloads are public at https://docs.arkadeos.com/intents/reference/rfq.
54
41
  *
55
- * Addressable (30000–39999) rather than ephemeral, deliberately: an ad is
56
- * standing state a relay should keep the current version of, not a message in a
57
- * negotiation. The two constants want OPPOSITE retention, and neither is a typo
58
- * of the other.
42
+ * A separate entry point (`@arkade-os/swap/nostr`) so `nostr-tools`, an OPTIONAL peer dependency,
43
+ * stays out of HTTP-only consumers' module graphs. Importing it without `nostr-tools` installed
44
+ * fails loudly at resolution, by design. A dynamic `import()` in the factory was rejected: it
45
+ * would make construction async, and the subscription is opened eagerly.
59
46
  */
60
- declare const RFQ_AD_KIND = 38859;
47
+
61
48
  /**
62
- * Every relay dropped the subscription, so no reply can arrive on it.
49
+ * Directed RFQ traffic. Provisional in the spec.
63
50
  *
64
- * Distinct from a timeout on purpose. Both look like "no answer", but they mean
65
- * opposite things: a timeout says the solver did not respond, while this says
66
- * we were never in a position to hear it. Without the distinction the transport
67
- * waits out the full timeout and then blames the solver for a failure on our
68
- * own side of the wire.
51
+ * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the solver's
52
+ * `NOSTR_KIND_DIRECTED`: both sides subscribe by `kinds`, so a mismatch surfaces only as every
53
+ * request timing out. Ephemeral because a finished negotiation is worthless and a retained copy
54
+ * records who negotiated with whom; the cost (no store-and-forward) is covered by timeout + retry.
55
+ */
56
+ declare const RFQ_DIRECTED_KIND = 24859;
57
+
58
+ /**
59
+ * Every relay dropped the subscription, so no reply can arrive on it. Distinct from a timeout:
60
+ * that says the solver did not respond, this says we could never have heard it.
69
61
  */
70
62
  declare class RelayUnavailable extends Error {
71
63
  readonly reasons: string[];
72
64
  constructor(reasons: string[]);
73
65
  }
74
66
  /**
75
- * `close()` was called while a negotiation was still waiting on a reply.
76
- *
77
- * Distinct from both a timeout and {@link RelayUnavailable}, which describe the
78
- * wire; this describes a decision on our own side of it. A caller that closed
79
- * deliberately — a user leaving the screen, a flow abandoning its request — can
80
- * match on this and stay quiet, rather than reporting a solver failure that
81
- * never happened.
67
+ * `close()` was called while a negotiation was still waiting on a reply. A deliberate local
68
+ * decision, so a caller can match on it and stay quiet rather than report a solver failure.
82
69
  */
83
70
  declare class TransportClosed extends Error {
84
71
  constructor();
@@ -89,10 +76,8 @@ interface NostrRfqOptions {
89
76
  /** The card's `discovery_pubkey`, x-only hex — who we address. */
90
77
  solverPubkey: string;
91
78
  /**
92
- * Transport key. Defaults to a FRESH key per transport, deliberately: the
93
- * negotiation should not be linkable to a long-term identity, and nothing in
94
- * the protocol needs a stable client key — the quote binds to the covenant,
95
- * not to who asked for it.
79
+ * Transport key. Defaults to a FRESH key per transport so the negotiation is not linkable to
80
+ * a long-term identity; the quote binds to the covenant, not to who asked.
96
81
  */
97
82
  secretKey?: Uint8Array;
98
83
  /** Injectable for tests; a caller may also share one pool across swaps. */
@@ -100,12 +85,16 @@ interface NostrRfqOptions {
100
85
  timeoutMs?: number;
101
86
  }
102
87
  /**
103
- * Build an `RfqTransport` speaking kind-24859 directed traffic.
104
- *
105
- * Sends are fire-and-forget publishes; replies arrive on a single long-lived
106
- * subscription filtered to this transport key, so a reply that arrives before
107
- * the publish promise settles is not missed.
88
+ * Build an `RfqTransport` speaking kind-24859 directed traffic. Replies arrive on one
89
+ * long-lived subscription filtered to this transport key.
108
90
  */
109
91
  declare const nostrRfqTransport: (options: NostrRfqOptions) => RfqTransport;
92
+ interface NostrCardFetcherOptions {
93
+ /** Injectable for tests; a lent pool is never closed, only the subscription on it. */
94
+ pool?: SimplePool;
95
+ /** How long to wait for every relay's EOSE before answering with what arrived. */
96
+ timeoutMs?: number;
97
+ }
98
+ declare const nostrCardFetcher: (options?: NostrCardFetcherOptions) => TransportCardFetcher;
110
99
 
111
- export { type NostrRfqOptions, RFQ_AD_KIND, RFQ_DIRECTED_KIND, RelayUnavailable, TransportClosed, nostrRfqTransport };
100
+ export { type NostrCardFetcherOptions, type NostrPool, type NostrRfqOptions, RFQ_DIRECTED_KIND, RelayUnavailable, TransportClosed, closeSharedNostrPool, createNostrPool, nostrCardFetcher, nostrRfqTransport, sharedNostrPool };