@arkade-os/swap 0.1.0-rc.2 → 0.1.0-rc.21

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 (54) hide show
  1. package/README.md +52 -2
  2. package/dist/advanced.cjs +8376 -0
  3. package/dist/advanced.d.cts +550 -0
  4. package/dist/advanced.d.ts +550 -0
  5. package/dist/advanced.js +451 -0
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-HUQQVBC4.js +4262 -0
  8. package/dist/{chunk-EOYGUCDM.js → chunk-ITFCQWPG.js} +755 -1382
  9. package/dist/chunk-PVB7EBAM.js +2517 -0
  10. package/dist/errors-C3h8ANmE.d.ts +1560 -0
  11. package/dist/errors-hm7aqnRM.d.cts +1560 -0
  12. package/dist/index.cjs +4861 -3988
  13. package/dist/index.d.cts +69 -2812
  14. package/dist/index.d.ts +69 -2812
  15. package/dist/index.js +179 -3719
  16. package/dist/lockupContract-5r5RlgOJ.d.cts +137 -0
  17. package/dist/lockupContract-5r5RlgOJ.d.ts +137 -0
  18. package/dist/node/index.cjs +61 -10
  19. package/dist/node/index.d.cts +249 -591
  20. package/dist/node/index.d.ts +249 -591
  21. package/dist/node/index.js +65 -10
  22. package/dist/nostr.cjs +191 -11
  23. package/dist/nostr.d.cts +23 -68
  24. package/dist/nostr.d.ts +23 -68
  25. package/dist/nostr.js +3 -4
  26. package/dist/offer-Bd9Yvd8Z.d.ts +261 -0
  27. package/dist/offer-F88rtL_I.d.cts +261 -0
  28. package/dist/protocol.cjs +4086 -3706
  29. package/dist/protocol.d.cts +163 -768
  30. package/dist/protocol.d.ts +163 -768
  31. package/dist/protocol.js +190 -173
  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-BuYWGAKz.d.cts +2261 -0
  41. package/dist/repository-DYnRLPt-.d.ts +2261 -0
  42. package/dist/rfq-60PGpQ_x.d.cts +950 -0
  43. package/dist/rfq-60PGpQ_x.d.ts +950 -0
  44. package/dist/watch-BTyiBLSd.d.ts +74 -0
  45. package/dist/watch-M_KY-5ho.d.cts +74 -0
  46. package/package.json +20 -10
  47. package/dist/chunk-LYCMM3VB.js +0 -1357
  48. package/dist/chunk-U7VWWTL6.js +0 -66
  49. package/dist/repository-_zU9_pM3.d.cts +0 -3426
  50. package/dist/repository-kO95noyv.d.ts +0 -3426
  51. package/dist/rfq-DdBV4JO5.d.cts +0 -1097
  52. package/dist/rfq-DdBV4JO5.d.ts +0 -1097
  53. package/dist/watch-CQqvwgwY.d.cts +0 -96
  54. package/dist/watch-wMbmfN4p.d.ts +0 -96
@@ -33,9 +33,20 @@ import {
33
33
  runInTransaction,
34
34
  sanitizeTablePrefix
35
35
  } from "@arkade-os/sdk/repositories/sqlite";
36
+ import { assertPageRequest as assertPageRequest2, pageResult as pageResult2 } from "@arkade-os/sdk";
36
37
 
37
38
  // src/repository.ts
39
+ import {
40
+ assertPageRequest,
41
+ collectPages,
42
+ pageResult
43
+ } from "@arkade-os/sdk";
38
44
  var marketsCacheKey = (network, registry) => `arkade-intents-markets-${network}-${registry}`;
45
+ function assertRfqSwapPageFilter(filter) {
46
+ if (filter.since !== void 0 && (!Number.isSafeInteger(filter.since) || filter.since < 0)) {
47
+ throw new RangeError("RFQ history since must be non-negative Unix seconds");
48
+ }
49
+ }
39
50
 
40
51
  // src/repositories/sqlite/repository.ts
41
52
  var DEFAULT_PREFIX = "arkade_";
@@ -94,6 +105,13 @@ var SQLiteAssetSwapRepository = class {
94
105
  updated_at INTEGER NOT NULL,
95
106
  data TEXT NOT NULL
96
107
  )`);
108
+ await this.db.run(
109
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_updated ON ${this.rfqSwaps} (updated_at, rfq_id)`
110
+ );
111
+ await this.db.run(
112
+ `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_history ON ${this.rfqSwaps} (state, updated_at, rfq_id)`
113
+ );
114
+ await this.db.run(`DROP INDEX IF EXISTS idx_${this.prefix}rfq_swaps_page`);
97
115
  await this.db.run(
98
116
  `CREATE INDEX IF NOT EXISTS idx_${this.prefix}rfq_swaps_state ON ${this.rfqSwaps} (state)`
99
117
  );
@@ -131,10 +149,8 @@ var SQLiteAssetSwapRepository = class {
131
149
  );
132
150
  });
133
151
  }
134
- async getAllSwaps() {
135
- await this.ensureInit();
136
- const rows = await this.db.all(`SELECT data FROM ${this.swaps}`);
137
- return rows.map((r) => JSON.parse(r.data));
152
+ async getAssetSwapsPage(page) {
153
+ return this.pageTable(this.swaps, "id", page);
138
154
  }
139
155
  async saveRfqSwap(record) {
140
156
  await this.ensureInit();
@@ -154,10 +170,38 @@ var SQLiteAssetSwapRepository = class {
154
170
  );
155
171
  return row ? JSON.parse(row.data) : void 0;
156
172
  }
157
- async getAllRfqSwaps() {
173
+ async getRfqSwapsPage(filter, page) {
174
+ assertPageRequest2(page);
175
+ assertRfqSwapPageFilter(filter);
158
176
  await this.ensureInit();
159
- const rows = await this.db.all(`SELECT data FROM ${this.rfqSwaps}`);
160
- return rows.map((r) => JSON.parse(r.data));
177
+ const conditions = [];
178
+ const params = [];
179
+ if (filter.state !== void 0) {
180
+ conditions.push("state = ?");
181
+ params.push(filter.state);
182
+ }
183
+ if (filter.since !== void 0) {
184
+ conditions.push("updated_at >= ?");
185
+ params.push(filter.since);
186
+ }
187
+ if (page.after !== void 0) {
188
+ conditions.push("(updated_at, rfq_id) > (?, ?)");
189
+ params.push(page.after.updatedAt, page.after.rfqId);
190
+ }
191
+ const where = conditions.length ? ` WHERE ${conditions.join(" AND ")}` : "";
192
+ const rows = await this.db.all(
193
+ `SELECT data, updated_at, rfq_id FROM ${this.rfqSwaps}${where}
194
+ ORDER BY updated_at, rfq_id LIMIT ?`,
195
+ [...params, page.limit + 1]
196
+ );
197
+ const result = pageResult2(rows, page.limit, (row) => ({
198
+ updatedAt: row.updated_at,
199
+ rfqId: row.rfq_id
200
+ }));
201
+ return {
202
+ items: result.items.map((row) => JSON.parse(row.data)),
203
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
204
+ };
161
205
  }
162
206
  async removeRfqSwap(rfqId) {
163
207
  await this.ensureInit();
@@ -183,10 +227,21 @@ var SQLiteAssetSwapRepository = class {
183
227
  );
184
228
  return row ? JSON.parse(row.data) : void 0;
185
229
  }
186
- async getAllSwapRecords() {
230
+ async getSwapRecordsPage(page) {
231
+ return this.pageTable(this.swapRecords, "id", page);
232
+ }
233
+ async pageTable(table, key, page) {
234
+ assertPageRequest2(page);
187
235
  await this.ensureInit();
188
- const rows = await this.db.all(`SELECT data FROM ${this.swapRecords}`);
189
- return rows.map((r) => JSON.parse(r.data));
236
+ const rows = await this.db.all(
237
+ page.after === void 0 ? `SELECT ${key} AS key, data FROM ${table} ORDER BY ${key} LIMIT ?` : `SELECT ${key} AS key, data FROM ${table} WHERE ${key} > ? ORDER BY ${key} LIMIT ?`,
238
+ page.after === void 0 ? [page.limit + 1] : [page.after, page.limit + 1]
239
+ );
240
+ const result = pageResult2(rows, page.limit, (row) => row.key);
241
+ return {
242
+ items: result.items.map((row) => JSON.parse(row.data)),
243
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
244
+ };
190
245
  }
191
246
  async removeSwapRecord(id) {
192
247
  await this.ensureInit();
package/dist/nostr.cjs CHANGED
@@ -39,9 +39,10 @@ __export(nostr_exports, {
39
39
  module.exports = __toCommonJS(nostr_exports);
40
40
 
41
41
  // src/rfq.ts
42
- var import_base4 = require("@scure/base");
42
+ var import_base6 = require("@scure/base");
43
+ var import_solver_discovery = require("@arkade-os/solver-discovery");
43
44
  var import_legacy2 = require("@noble/hashes/legacy.js");
44
- var import_sdk2 = require("@arkade-os/sdk");
45
+ var import_sdk5 = require("@arkade-os/sdk");
45
46
 
46
47
  // src/onchainHtlc.ts
47
48
  var import_base = require("@scure/base");
@@ -58,10 +59,11 @@ var L1_NETWORKS = {
58
59
  };
59
60
 
60
61
  // src/rfq.ts
61
- var import_sdk3 = require("@arkade-os/sdk");
62
+ var import_sdk6 = require("@arkade-os/sdk");
62
63
 
63
64
  // src/claimPacket.ts
64
65
  var import_base2 = require("@scure/base");
66
+ var import_utils = require("@scure/btc-signer/utils.js");
65
67
  var import_aes = require("@noble/ciphers/aes.js");
66
68
  var import_secp256k1 = require("@noble/curves/secp256k1.js");
67
69
  var import_hkdf = require("@noble/hashes/hkdf.js");
@@ -72,6 +74,114 @@ var HKDF_INFO = new TextEncoder().encode("covclaimd/preimage/v1");
72
74
  var import_base3 = require("@scure/base");
73
75
  var import_sdk = require("@arkade-os/sdk");
74
76
 
77
+ // src/offer.ts
78
+ var import_base5 = require("@scure/base");
79
+ var import_utils2 = require("@scure/btc-signer/utils.js");
80
+ var import_sdk4 = require("@arkade-os/sdk");
81
+
82
+ // src/swap-want-asset.program.json
83
+ var swap_want_asset_program_default = {
84
+ version: 0,
85
+ name: "banco-btc-to-asset",
86
+ params: [
87
+ { name: "makerWP", type: "pubkey" },
88
+ { name: "wantAmount", type: "int" },
89
+ { name: "wantAssetTxid", type: "hash" },
90
+ { name: "wantAssetGroupIndex", type: "int" },
91
+ { name: "server", type: "pubkey" },
92
+ { name: "user", type: "pubkey" }
93
+ ],
94
+ functions: {
95
+ fulfill: {
96
+ tapscript: { signers: ["$server"] },
97
+ arkadeScript: {
98
+ asm: [
99
+ 0,
100
+ "$wantAssetTxid",
101
+ "$wantAssetGroupIndex",
102
+ "INSPECTOUTASSETLOOKUP",
103
+ "VERIFY",
104
+ "$wantAmount",
105
+ "GREATERTHANOREQUAL",
106
+ "VERIFY",
107
+ 0,
108
+ "INSPECTOUTPUTSCRIPTPUBKEY",
109
+ 1,
110
+ "EQUALVERIFY",
111
+ "$makerWP",
112
+ "EQUAL"
113
+ ]
114
+ }
115
+ },
116
+ cancel: {
117
+ tapscript: { signers: ["$user", "$server"] }
118
+ }
119
+ }
120
+ };
121
+
122
+ // src/swap-want-btc.program.json
123
+ var swap_want_btc_program_default = {
124
+ version: 0,
125
+ name: "banco-asset-to-btc",
126
+ params: [
127
+ { name: "makerWP", type: "pubkey" },
128
+ { name: "wantAmount", type: "int" },
129
+ { name: "server", type: "pubkey" },
130
+ { name: "user", type: "pubkey" }
131
+ ],
132
+ functions: {
133
+ fulfill: {
134
+ tapscript: { signers: ["$server"] },
135
+ arkadeScript: {
136
+ asm: [
137
+ 0,
138
+ "INSPECTOUTPUTVALUE",
139
+ "$wantAmount",
140
+ "GREATERTHANOREQUAL",
141
+ "VERIFY",
142
+ 0,
143
+ "INSPECTOUTPUTSCRIPTPUBKEY",
144
+ 1,
145
+ "EQUALVERIFY",
146
+ "$makerWP",
147
+ "EQUAL"
148
+ ]
149
+ }
150
+ },
151
+ cancel: {
152
+ tapscript: { signers: ["$user", "$server"] }
153
+ }
154
+ }
155
+ };
156
+
157
+ // src/store.ts
158
+ var import_base4 = require("@scure/base");
159
+ var import_sha23 = require("@noble/hashes/sha2.js");
160
+ var import_sdk3 = require("@arkade-os/sdk");
161
+
162
+ // src/repository.ts
163
+ var import_sdk2 = require("@arkade-os/sdk");
164
+
165
+ // src/offer.ts
166
+ var swapPrograms = {
167
+ wantAsset: import_sdk4.arkade.parseArtifact(swap_want_asset_program_default),
168
+ wantBtc: import_sdk4.arkade.parseArtifact(swap_want_btc_program_default)
169
+ };
170
+ var FIELDS = {
171
+ swapPkScript: { tag: 1, width: 34 },
172
+ wantAmount: { tag: 2, width: 8 },
173
+ wantAsset: { tag: 3, width: void 0 },
174
+ makerPkScript: { tag: 5, width: 34 },
175
+ makerPublicKey: { tag: 7, width: 32 },
176
+ emulatorPubkey: { tag: 8, width: 32 },
177
+ ratioNum: { tag: 9, width: 8 },
178
+ ratioDen: { tag: 10, width: 8 },
179
+ offerAsset: { tag: 11, width: void 0 },
180
+ exitTimelock: { tag: 12, width: 9 }
181
+ };
182
+ var NAMES = Object.fromEntries(Object.entries(FIELDS).map(([k, f]) => [f.tag, k]));
183
+ var ASSET_CARRIER_SATS = BigInt(import_sdk4.ASSET_CARRIER_SATS);
184
+
75
185
  // src/rfq.ts
76
186
  var ARKADE_BTC = "arkade:BTC";
77
187
  var LIGHTNING_BTC = "lightning:BTC";
@@ -81,23 +191,95 @@ var LIGHTNING_SEND_PAIR = rfqPair(ARKADE_BTC, LIGHTNING_BTC);
81
191
  var LIGHTNING_RECEIVE_PAIR = rfqPair(LIGHTNING_BTC, ARKADE_BTC);
82
192
  var ONCHAIN_SEND_PAIR = rfqPair(ARKADE_BTC, ONCHAIN_BTC);
83
193
  var ONCHAIN_RECEIVE_PAIR = rfqPair(ONCHAIN_BTC, ARKADE_BTC);
194
+ var RFQ_REFUSAL_ERROR_CODES = [
195
+ "amount_side_unsupported",
196
+ "exact_out_unsupported",
197
+ "invalid_amount",
198
+ "invalid_payout_address",
199
+ "invalid_refund_address",
200
+ "invoice_amount_mismatch",
201
+ "invoice_cltv_too_large",
202
+ "invoice_malformed",
203
+ "invoice_missing_amount",
204
+ "invoice_missing_network",
205
+ "invoice_missing_payment_hash",
206
+ "invoice_missing_timestamp",
207
+ "invoice_mixed_case",
208
+ "invoice_sub_satoshi_amount",
209
+ "invoice_too_long",
210
+ "invoice_wrong_network"
211
+ ];
212
+ var isRfqRefusalErrorCode = (value) => typeof value === "string" && RFQ_REFUSAL_ERROR_CODES.includes(value);
213
+ var REFUSAL_FIELDS = /* @__PURE__ */ new Set([
214
+ "amount",
215
+ "amount_side",
216
+ "profile.invoice",
217
+ "profile.payout_address",
218
+ "profile.refund_address"
219
+ ]);
220
+ var REFUSAL_UNITS = /* @__PURE__ */ new Set(["blocks", "characters", "sats"]);
221
+ var safeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
222
+ var safeRefusalDetail = (detail) => {
223
+ if (!isRfqRefusalErrorCode(detail.errorCode)) return {};
224
+ return {
225
+ errorCode: detail.errorCode,
226
+ field: typeof detail.field === "string" && REFUSAL_FIELDS.has(detail.field) ? detail.field : void 0,
227
+ actual: safeInteger(detail.actual),
228
+ expected: safeInteger(detail.expected),
229
+ limit: safeInteger(detail.limit),
230
+ unit: typeof detail.unit === "string" && REFUSAL_UNITS.has(detail.unit) ? detail.unit : void 0
231
+ };
232
+ };
233
+ var refusalMessage = (reason, detail) => {
234
+ if (!detail.errorCode) return `solver refused: ${reason}`;
235
+ const where = detail.field ? ` at ${detail.field}` : "";
236
+ const unit = detail.unit ? ` ${detail.unit}` : "";
237
+ if (detail.actual !== void 0 && detail.limit !== void 0) {
238
+ return `solver refused: ${reason} (${detail.errorCode}${where}: ${detail.actual}${unit}, limit ${detail.limit})`;
239
+ }
240
+ if (detail.actual !== void 0 && detail.expected !== void 0) {
241
+ return `solver refused: ${reason} (${detail.errorCode}${where}: ${detail.actual}${unit}, expected ${detail.expected})`;
242
+ }
243
+ return `solver refused: ${reason} (${detail.errorCode}${where})`;
244
+ };
84
245
  var SwapRefusal = class extends Error {
85
246
  /** Literal-typed so the v2 error taxonomy's union discriminates on `name`
86
- * — a `string` here collapses the discriminant for every member. Same value
87
- * the constructor has always set, moved to a field initializer. */
247
+ * — a `string` here collapses the discriminant for every member. */
88
248
  name = "SwapRefusal";
89
249
  reason;
90
250
  rfqId;
91
- constructor(reason, rfqId) {
92
- super(`solver refused: ${reason}`);
251
+ errorCode;
252
+ field;
253
+ actual;
254
+ expected;
255
+ limit;
256
+ unit;
257
+ constructor(reason, rfqId, detail = {}) {
258
+ const safeDetail = safeRefusalDetail(detail);
259
+ super(refusalMessage(reason, safeDetail));
93
260
  this.reason = reason;
94
261
  this.rfqId = rfqId;
262
+ this.errorCode = safeDetail.errorCode;
263
+ this.field = safeDetail.field;
264
+ this.actual = safeDetail.actual;
265
+ this.expected = safeDetail.expected;
266
+ this.limit = safeDetail.limit;
267
+ this.unit = safeDetail.unit;
95
268
  }
96
269
  };
97
270
  var MIN_HEADROOM_SECONDS = 90 * 60;
98
271
  var expectQuote = (payload, rfqId, requestedPair) => {
99
272
  const p = payload;
100
- if (p?.type === "rfq_refusal") throw new SwapRefusal(p.reason ?? "unknown", p.rfq_id ?? rfqId);
273
+ if (p?.type === "rfq_refusal") {
274
+ throw new SwapRefusal(p.reason ?? "unknown", p.rfq_id ?? rfqId, {
275
+ errorCode: p.error_code,
276
+ field: p.field,
277
+ actual: p.actual,
278
+ expected: p.expected,
279
+ limit: p.limit,
280
+ unit: p.unit
281
+ });
282
+ }
101
283
  if (p?.type !== "rfq_quote" || p.rfq_id !== rfqId) {
102
284
  throw new Error(`unexpected reply: ${p?.type ?? "no payload"}`);
103
285
  }
@@ -163,9 +345,7 @@ var nostrRfqTransport = (options) => {
163
345
  if (!rfqId) return;
164
346
  waiters.get(rfqId)?.resolve(payload);
165
347
  },
166
- // subscribeMany calls this once every relay has closed. Nothing will
167
- // arrive after it, so failing now beats waiting out the timeout — and
168
- // it names the real cause instead of implicating the solver.
348
+ // Called once every relay has closed: fail now with the real cause, not at timeout.
169
349
  onclose(reasons) {
170
350
  if (closed) return;
171
351
  const error = new RelayUnavailable(closeReasons(reasons));
package/dist/nostr.d.cts CHANGED
@@ -1,84 +1,44 @@
1
- import { a as RfqTransport } from './rfq-DdBV4JO5.cjs';
1
+ import { e as RfqTransport } from './rfq-60PGpQ_x.cjs';
2
2
  import { SimplePool } from 'nostr-tools';
3
3
  import '@arkade-os/sdk';
4
4
 
5
5
  /**
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).
6
+ * The Nostr RFQ transport — the PRODUCTION one; `httpTransport` and the dev-broker
7
+ * `relayTransport` in `rfq.ts` are not what deployed solvers listen on. The kind, NIP-44 framing
8
+ * and payloads are public at https://docs.arkadeos.com/intents/reference/rfq.
9
9
  *
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.
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.
10
+ * A separate entry point (`@arkade-os/swap/nostr`) so `nostr-tools`, an OPTIONAL peer dependency,
11
+ * stays out of HTTP-only consumers' module graphs. Importing it without `nostr-tools` installed
12
+ * fails loudly at resolution, by design. A dynamic `import()` in the factory was rejected: it
13
+ * would make construction async, and the subscription is opened eagerly.
34
14
  */
35
15
 
36
16
  /**
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.
17
+ * Directed RFQ traffic. Provisional in the spec.
43
18
  *
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.
19
+ * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the solver's
20
+ * `NOSTR_KIND_DIRECTED`: both sides subscribe by `kinds`, so a mismatch surfaces only as every
21
+ * request timing out. Ephemeral because a finished negotiation is worthless and a retained copy
22
+ * records who negotiated with whom; the cost (no store-and-forward) is covered by timeout + retry.
50
23
  */
51
24
  declare const RFQ_DIRECTED_KIND = 24859;
52
25
  /**
53
26
  * Indicative solver advertisement — never binding; only a quote binds.
54
- *
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.
27
+ * Addressable (30000–39999), not ephemeral: an ad is standing state relays should retain. The
28
+ * opposite retention to {@link RFQ_DIRECTED_KIND} is intentional, not a typo.
59
29
  */
60
30
  declare const RFQ_AD_KIND = 38859;
61
31
  /**
62
- * Every relay dropped the subscription, so no reply can arrive on it.
63
- *
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.
32
+ * Every relay dropped the subscription, so no reply can arrive on it. Distinct from a timeout:
33
+ * that says the solver did not respond, this says we could never have heard it.
69
34
  */
70
35
  declare class RelayUnavailable extends Error {
71
36
  readonly reasons: string[];
72
37
  constructor(reasons: string[]);
73
38
  }
74
39
  /**
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.
40
+ * `close()` was called while a negotiation was still waiting on a reply. A deliberate local
41
+ * decision, so a caller can match on it and stay quiet rather than report a solver failure.
82
42
  */
83
43
  declare class TransportClosed extends Error {
84
44
  constructor();
@@ -89,10 +49,8 @@ interface NostrRfqOptions {
89
49
  /** The card's `discovery_pubkey`, x-only hex — who we address. */
90
50
  solverPubkey: string;
91
51
  /**
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.
52
+ * Transport key. Defaults to a FRESH key per transport so the negotiation is not linkable to
53
+ * a long-term identity; the quote binds to the covenant, not to who asked.
96
54
  */
97
55
  secretKey?: Uint8Array;
98
56
  /** Injectable for tests; a caller may also share one pool across swaps. */
@@ -100,11 +58,8 @@ interface NostrRfqOptions {
100
58
  timeoutMs?: number;
101
59
  }
102
60
  /**
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.
61
+ * Build an `RfqTransport` speaking kind-24859 directed traffic. Replies arrive on one
62
+ * long-lived subscription filtered to this transport key.
108
63
  */
109
64
  declare const nostrRfqTransport: (options: NostrRfqOptions) => RfqTransport;
110
65
 
package/dist/nostr.d.ts CHANGED
@@ -1,84 +1,44 @@
1
- import { a as RfqTransport } from './rfq-DdBV4JO5.js';
1
+ import { e as RfqTransport } from './rfq-60PGpQ_x.js';
2
2
  import { SimplePool } from 'nostr-tools';
3
3
  import '@arkade-os/sdk';
4
4
 
5
5
  /**
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).
6
+ * The Nostr RFQ transport — the PRODUCTION one; `httpTransport` and the dev-broker
7
+ * `relayTransport` in `rfq.ts` are not what deployed solvers listen on. The kind, NIP-44 framing
8
+ * and payloads are public at https://docs.arkadeos.com/intents/reference/rfq.
9
9
  *
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.
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.
10
+ * A separate entry point (`@arkade-os/swap/nostr`) so `nostr-tools`, an OPTIONAL peer dependency,
11
+ * stays out of HTTP-only consumers' module graphs. Importing it without `nostr-tools` installed
12
+ * fails loudly at resolution, by design. A dynamic `import()` in the factory was rejected: it
13
+ * would make construction async, and the subscription is opened eagerly.
34
14
  */
35
15
 
36
16
  /**
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.
17
+ * Directed RFQ traffic. Provisional in the spec.
43
18
  *
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.
19
+ * MUST stay inside NIP-01's ephemeral range (20000–29999) and MUST match the solver's
20
+ * `NOSTR_KIND_DIRECTED`: both sides subscribe by `kinds`, so a mismatch surfaces only as every
21
+ * request timing out. Ephemeral because a finished negotiation is worthless and a retained copy
22
+ * records who negotiated with whom; the cost (no store-and-forward) is covered by timeout + retry.
50
23
  */
51
24
  declare const RFQ_DIRECTED_KIND = 24859;
52
25
  /**
53
26
  * Indicative solver advertisement — never binding; only a quote binds.
54
- *
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.
27
+ * Addressable (30000–39999), not ephemeral: an ad is standing state relays should retain. The
28
+ * opposite retention to {@link RFQ_DIRECTED_KIND} is intentional, not a typo.
59
29
  */
60
30
  declare const RFQ_AD_KIND = 38859;
61
31
  /**
62
- * Every relay dropped the subscription, so no reply can arrive on it.
63
- *
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.
32
+ * Every relay dropped the subscription, so no reply can arrive on it. Distinct from a timeout:
33
+ * that says the solver did not respond, this says we could never have heard it.
69
34
  */
70
35
  declare class RelayUnavailable extends Error {
71
36
  readonly reasons: string[];
72
37
  constructor(reasons: string[]);
73
38
  }
74
39
  /**
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.
40
+ * `close()` was called while a negotiation was still waiting on a reply. A deliberate local
41
+ * decision, so a caller can match on it and stay quiet rather than report a solver failure.
82
42
  */
83
43
  declare class TransportClosed extends Error {
84
44
  constructor();
@@ -89,10 +49,8 @@ interface NostrRfqOptions {
89
49
  /** The card's `discovery_pubkey`, x-only hex — who we address. */
90
50
  solverPubkey: string;
91
51
  /**
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.
52
+ * Transport key. Defaults to a FRESH key per transport so the negotiation is not linkable to
53
+ * a long-term identity; the quote binds to the covenant, not to who asked.
96
54
  */
97
55
  secretKey?: Uint8Array;
98
56
  /** Injectable for tests; a caller may also share one pool across swaps. */
@@ -100,11 +58,8 @@ interface NostrRfqOptions {
100
58
  timeoutMs?: number;
101
59
  }
102
60
  /**
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.
61
+ * Build an `RfqTransport` speaking kind-24859 directed traffic. Replies arrive on one
62
+ * long-lived subscription filtered to this transport key.
108
63
  */
109
64
  declare const nostrRfqTransport: (options: NostrRfqOptions) => RfqTransport;
110
65
 
package/dist/nostr.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  expectQuote,
3
3
  pairOf
4
- } from "./chunk-LYCMM3VB.js";
4
+ } from "./chunk-PVB7EBAM.js";
5
+ import "./chunk-A3SHHRX4.js";
5
6
 
6
7
  // src/nostr.ts
7
8
  import {
@@ -59,9 +60,7 @@ var nostrRfqTransport = (options) => {
59
60
  if (!rfqId) return;
60
61
  waiters.get(rfqId)?.resolve(payload);
61
62
  },
62
- // subscribeMany calls this once every relay has closed. Nothing will
63
- // arrive after it, so failing now beats waiting out the timeout — and
64
- // it names the real cause instead of implicating the solver.
63
+ // Called once every relay has closed: fail now with the real cause, not at timeout.
65
64
  onclose(reasons) {
66
65
  if (closed) return;
67
66
  const error = new RelayUnavailable(closeReasons(reasons));