@naulon/wayfarer 0.4.1 → 0.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,eAAe,EAAE,MAAM,MAAM,CAAC;AAGpE,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAIL,KAAK,KAAK,EAGV,KAAK,MAAM,EACZ,MAAM,YAAY,CAAC;AAGpB;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;IACvB,aAAa,CAAC,IAAI,EAAE;QAClB,MAAM,EAAE,eAAe,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC,CAAC;QAC7D,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;CAC5B;AAED;;uFAEuF;AACvF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,KAAK,MAAM,EAA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S,GAAG,QAAQ,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,cAAc,GAAG,sBAAsB,CAmBxF"}
package/dist/gateway.js CHANGED
@@ -20,7 +20,7 @@
20
20
  * deposits via the SDK `GatewayClient` for backwards compatibility.
21
21
  */
22
22
  import {} from "viem";
23
- import { activeNetwork, arcPreviewHeaders, getConfig } from "@naulon/shared";
23
+ import { activeNetwork, getConfig } from "@naulon/shared";
24
24
  import { classifyPaymentError, classifySignerRefusal, probe, } from "./buyer.js";
25
25
  import { runPaidFetch } from "./paidFetch.js";
26
26
  function envAccountKey() {
@@ -58,6 +58,82 @@ export async function gatewayLegPayload(signer, quoted, x402Version) {
58
58
  const signed = await scheme.createPaymentPayload(x402Version, requirements);
59
59
  return { ...signed, resource: quoted.resource, accepted: requirements };
60
60
  }
61
+ /**
62
+ * A signature-shaped placeholder, swapped out before anything sees it.
63
+ *
64
+ * 65 bytes of `0x11…` with a v of 27 — structurally a signature, recoverable to nobody. It exists
65
+ * only inside {@link buildLegPayloadsForBatch}, between the SDK building a leg's authorization and
66
+ * the real signer signing all of them together. Deliberately not zeroes: a run of zeroes is what a
67
+ * missing value looks like, and if a bug ever let one of these escape, `0x1111…` in a payment
68
+ * payload is unmistakably a placeholder while `0x0000…` reads as an empty field.
69
+ */
70
+ const PLACEHOLDER_SIGNATURE = `0x${"11".repeat(64)}1b`;
71
+ /**
72
+ * Build every leg's payload WITHOUT signing, and hand back the typed data each one needs.
73
+ *
74
+ * ## Why this shape
75
+ *
76
+ * `BatchEvmScheme.createPaymentPayload` builds the authorization (nonce, the validity clamp, the
77
+ * GatewayWallet domain) and signs it in one step — there is no "give me the typed data" entry
78
+ * point. Reconstructing the authorization ourselves to get at it would fork the shape away from the
79
+ * rail, which is the exact drift `gatewayLegPayload` wraps the SDK to prevent.
80
+ *
81
+ * So the SDK keeps building, and a COLLECTING signer stands in for the real one: it records the
82
+ * typed data it is asked to sign and returns {@link PLACEHOLDER_SIGNATURE}. The caller then signs
83
+ * all of the collected typed data in one call and substitutes the results back, index-aligned. The
84
+ * SDK still owns every byte of the authorization; only the moment of signing moves.
85
+ *
86
+ * Returns the payloads with placeholder signatures and the typed data in the SAME order, so the
87
+ * substitution is positional and cannot mis-pair a signature with another leg's authorization.
88
+ */
89
+ async function buildLegPayloadsForBatch(signerAddress, legQuotes, x402Version) {
90
+ const typedData = [];
91
+ const collector = {
92
+ address: signerAddress,
93
+ async signTypedData(args) {
94
+ typedData.push(args);
95
+ return PLACEHOLDER_SIGNATURE;
96
+ },
97
+ };
98
+ const payloads = [];
99
+ for (const legQuote of legQuotes) {
100
+ // Through `gatewayLegPayload`, not around it: its two pre-sign guards (single-leg shape, and
101
+ // "this really is a GatewayWalletBatched option") must run on every leg here exactly as they do
102
+ // on the single-leg path. Each leg is already narrowed to its own one-leg quote by the caller.
103
+ payloads.push(await gatewayLegPayload(collector, legQuote, x402Version));
104
+ // ONE authorization per leg, checked AS EACH LEG IS BUILT rather than only in total. A total-only
105
+ // check passes an SDK that signed twice for one leg and not at all for another — the counts
106
+ // match and every payload is paired with the wrong signature, which no later check can see.
107
+ if (typedData.length !== payloads.length) {
108
+ throw new Error(`gateway batch: leg ${payloads.length - 1} produced ${typedData.length - (payloads.length - 1)} authorization(s), expected exactly 1`);
109
+ }
110
+ }
111
+ if (typedData.length !== legQuotes.length) {
112
+ // One authorization per leg, or we do not know which signature belongs to which leg. An SDK
113
+ // that signed twice for one leg, or not at all, must fail loudly here rather than produce a
114
+ // payment whose legs are mis-paired.
115
+ throw new Error(`gateway batch: expected ${legQuotes.length} authorization(s) to sign, the SDK produced ${typedData.length}`);
116
+ }
117
+ return { payloads, typedData };
118
+ }
119
+ /**
120
+ * Sign every leg of a multi-leg Gateway toll through ONE call to a batch-capable signer.
121
+ *
122
+ * Exported for `rail.ts`, which is the only caller — kept here beside `gatewayLegPayload` so the
123
+ * single-leg and multi-leg paths share the SDK wrapper, the guards and the placeholder machinery
124
+ * rather than growing a second copy in another file.
125
+ */
126
+ export async function gatewayLegPayloadsBatched(signer, legQuotes, x402Version) {
127
+ const { payloads, typedData } = await buildLegPayloadsForBatch(signer.address, legQuotes, x402Version);
128
+ const signatures = await signer.signTypedDataBatch(typedData);
129
+ if (signatures.length !== typedData.length) {
130
+ throw new Error(`gateway batch: signer returned ${signatures.length} signature(s) for ${typedData.length} leg(s)`);
131
+ }
132
+ return payloads.map((p, i) => {
133
+ const inner = p.payload;
134
+ return { ...p, payload: { ...inner, signature: signatures[i] } };
135
+ });
136
+ }
61
137
  export function gatewayBuyer(signer) {
62
138
  const cfg = getConfig();
63
139
  // Resolve the signer once. An injected signer NEVER reads BUYER_PRIVATE_KEY (the whole point
@@ -121,15 +197,13 @@ export function gatewayBuyer(signer) {
121
197
  * sites below all build their client through `newGatewayClient`, so this IS the config
122
198
  * that runs, not a parallel copy.
123
199
  *
124
- * `headers` is the load-bearing part. SDK 3.2.0 turned the Arc private-mainnet header on
125
- * by itself (`config.arcPrivateMainnet ?? config.chain === "arc"`); 3.3.0 deleted that
126
- * default along with the whole `arcPrivateMainnet` option, so a client built with only
127
- * `{chain, privateKey}` now sends nothing. Passing it explicitly keeps Arc-mainnet
128
- * funding calls behaving exactly as they did on 3.2.0, and — unlike the old default —
129
- * says so out loud at a spot a reader can find.
200
+ * It used to add `X-ARC-PRIVATE-MAINNET-ENABLED` on Arc, restoring by hand the default SDK 3.2.0
201
+ * applied and 3.3.0 deleted. Arc mainnet went public on 2026-09-16, which retired the opt-in
202
+ * itself: measured that day, the Gateway API answers an Arc (domain 26) balances call identically
203
+ * with the header and without it. So the config is the two fields the SDK needs and nothing else.
130
204
  */
131
205
  export function gatewayClientConfig(chain, privateKey) {
132
- return { chain, privateKey, headers: arcPreviewHeaders(chain) };
206
+ return { chain, privateKey };
133
207
  }
134
208
  /** One owner for every `GatewayClient` construction in this module: the lazy SDK import
135
209
  * (so the mock/memo paths never pull the SDK in) plus `gatewayClientConfig`. Six wrappers
@@ -1 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,MAAM,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA4E;IAE5E,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IAC9C,OAAO,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC;AAKD;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAsB;IAC9D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW;YACd,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,UAAU,CAAC;QAChB,KAAK,SAAS,CAAC;QACf,KAAK,WAAW;YACd,OAAO,SAAS,CAAC;QACnB,OAAO,CAAC,CAAC,CAAC;YACR,+EAA+E;YAC/E,2EAA2E;YAC3E,4EAA4E;YAC5E,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,KAAK,WAAW,CAAC;YACjB,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/lib.d.ts CHANGED
@@ -13,19 +13,19 @@
13
13
  */
14
14
  export { run } from "./agent.ts";
15
15
  export type { Logger, RunOptions } from "./agent.ts";
16
- export { tollgateBase, articleUrl, fetchJwks, verifyAgainst, licenseIdentityFor } from "./agent.ts";
16
+ export { tollgateBase, articleUrl, fetchJwks, heldRequestFor, verifyAgainst, licenseIdentityFor, proofLinksFor } from "./agent.ts";
17
17
  export { discover } from "./discover.ts";
18
18
  export { resolvedDiscoverySourceUrl } from "./discovery.ts";
19
19
  export { appraise, buildAppraisePrompt, evidenceLine, parseRelevance } from "./appraise.ts";
20
20
  export type { AppraisalSubject, AppraisePromptOptions } from "./appraise.ts";
21
- export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError, } from "./buyer.ts";
21
+ export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError, classifySignerRefusal, } from "./buyer.ts";
22
22
  export type { Buyer, Quoted, LegRequirements, Fetched, FetchErrorCode, PayGuard, ProbeOutcome } from "./buyer.ts";
23
23
  export { mockBuyer } from "./pay.ts";
24
24
  export { gatewayBuyer, gatewayDeposit, gatewayWithdraw, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.ts";
25
- export type { GatewaySigner, GatewayDepositOpts, GatewaySettlementState } from "./gateway.ts";
25
+ export type { GatewaySigner, GatewayTypedDataArgs, GatewayDepositOpts, GatewaySettlementState } from "./gateway.ts";
26
26
  export { memoBuyer, signMemoPayment, assembleMemoPayment } from "./memo.ts";
27
27
  export type { MemoSigner, MemoTypedData } from "./memo.ts";
28
- export { railBuyer } from "./rail.ts";
28
+ export { railBuyer, assembleRailPayment } from "./rail.ts";
29
29
  export type { RailSigners } from "./rail.ts";
30
30
  export { decide, DEFAULT_POLICY, payHostOf, spendGate } from "./decide.ts";
31
31
  export type { DecisionPolicy, DecideContext, LicenceVerdict, SpendVerdict } from "./decide.ts";
@@ -36,7 +36,7 @@ export { authorizeOrigin } from "./origin-policy.ts";
36
36
  export type { OriginRequest, OriginVerdict, PayableTarget } from "./origin-policy.ts";
37
37
  export { allocateByContribution } from "./allocation.ts";
38
38
  export type { SourceAllocation } from "./allocation.ts";
39
- export { decodeHeld, fileHeldStore, isLive, loadHeld, memoryHeldStore, saveHeld } from "./licenseStore.ts";
39
+ export { decodeHeld, fileHeldStore, findHeld, heldKey, isLive, loadHeld, memoryHeldStore, saveHeld } from "./licenseStore.ts";
40
40
  export type { HeldLicense, HeldStore } from "./licenseStore.ts";
41
41
  export { buildPopProof } from "./pop.ts";
42
42
  export { getWallet } from "./wallet.ts";
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAMrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGpG,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5F,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG7E,OAAO,EACL,KAAK,EACL,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,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AY,CAAC"}
package/dist/lib.js CHANGED
@@ -17,18 +17,24 @@ export { run } from "./agent.js";
17
17
  // article URL from a slug against the configured gate, to derive the gate's
18
18
  // canonical license identity from a paid-into URL, and to verify a captured
19
19
  // license against the gate's JWKS — single-sourced here so the two can't drift.
20
- export { tollgateBase, articleUrl, fetchJwks, verifyAgainst, licenseIdentityFor } from "./agent.js";
20
+ export { tollgateBase, articleUrl, fetchJwks, heldRequestFor, verifyAgainst, licenseIdentityFor, proofLinksFor } from "./agent.js";
21
21
  // ── discover ────────────────────────────────────────────────────────────────
22
22
  export { discover } from "./discover.js";
23
23
  export { resolvedDiscoverySourceUrl } from "./discovery.js";
24
24
  // ── appraise ────────────────────────────────────────────────────────────────
25
25
  export { appraise, buildAppraisePrompt, evidenceLine, parseRelevance } from "./appraise.js";
26
26
  // ── quote + pay (the Buyer seam) ────────────────────────────────────────────
27
- export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError, } from "./buyer.js";
27
+ export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError,
28
+ // Public because it is a CONTRACT, not a helper: it decides whether a signer's refusal is terminal
29
+ // or gets re-signed, and the codes it switches on are minted by whoever implements the signer — not
30
+ // by this package. A host that adds or renames a refusal code and does not add it here has its
31
+ // deterministic refusal silently reclassified as a retryable blip and paid for twice. Exported so a
32
+ // host can assert the two halves agree, instead of finding out in production.
33
+ classifySignerRefusal, } from "./buyer.js";
28
34
  export { mockBuyer } from "./pay.js";
29
35
  export { gatewayBuyer, gatewayDeposit, gatewayWithdraw, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.js";
30
36
  export { memoBuyer, signMemoPayment, assembleMemoPayment } from "./memo.js";
31
- export { railBuyer } from "./rail.js";
37
+ export { railBuyer, assembleRailPayment } from "./rail.js";
32
38
  // ── decide (policy) ─────────────────────────────────────────────────────────
33
39
  export { decide, DEFAULT_POLICY, payHostOf, spendGate } from "./decide.js";
34
40
  // ── origin policy (whose origin may money touch) ─────────────────────────────
@@ -44,7 +50,7 @@ export { authorizeOrigin } from "./origin-policy.js";
44
50
  // ── cross-source allocation (buyer-side citation-reward policy) ──────────────
45
51
  export { allocateByContribution } from "./allocation.js";
46
52
  // ── citation licenses (pay once, re-read free) ──────────────────────────────
47
- export { decodeHeld, fileHeldStore, isLive, loadHeld, memoryHeldStore, saveHeld } from "./licenseStore.js";
53
+ export { decodeHeld, fileHeldStore, findHeld, heldKey, isLive, loadHeld, memoryHeldStore, saveHeld } from "./licenseStore.js";
48
54
  export { buildPopProof } from "./pop.js";
49
55
  // ── wallet ──────────────────────────────────────────────────────────────────
50
56
  export { getWallet } from "./wallet.js";
package/dist/lib.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpG,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG5F,+EAA+E;AAC/E,OAAO,EACL,KAAK,EACL,UAAU,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACrB,MAAM,YAAY,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AG/F,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,gFAAgF;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,+EAA+E;AAC/E,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE9H,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,+EAA+E;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -16,6 +16,10 @@ export interface HeldLicense {
16
16
  scope?: {
17
17
  patterns: string[];
18
18
  };
19
+ /** The RSL usage terms this payment executed (`ai-input` for a per-read toll) — WHAT THE
20
+ * HOLDER MAY DO with the bytes. Absent on licences minted before tolls stated their terms;
21
+ * a consumer reads absent as the same default grounding right, never as "no rights". */
22
+ terms?: string[];
19
23
  /** The canonical URL this source was actually PAID at — captured at pay time so a
20
24
  * later `read_held` re-fetches the exact link (`/articles/<slug>`, a custom domain,
21
25
  * whatever the publisher serves) instead of reconstructing a `/essays/<slug>`
@@ -24,6 +28,24 @@ export interface HeldLicense {
24
28
  * decoded token — it's the buyer's own bookkeeping, so `decodeHeld` never sets it. */
25
29
  url?: string;
26
30
  }
31
+ /**
32
+ * The key a held licence is filed under: its `jti`, never its slug.
33
+ *
34
+ * Slug was the original key and it EVICTS ACROSS PUBLISHERS. `about`, `faq`, `index` and `privacy`
35
+ * are not rare; two independently-run sites share one, and the second purchase silently overwrote
36
+ * the first licence's entry — one row for two payments, with the survivor bound (by `aud`) to only
37
+ * one of them. The buyer then re-paid for the evicted one, which is the double-charge this store
38
+ * exists to prevent. Measured in prod on 2026-09-10.
39
+ *
40
+ * `jti` is the gate's own unique identifier for the licence, so one entry is one purchase. Nothing
41
+ * reads the map by key — `findHeld` scans values and decides coverage with `licenseCoversPath` —
42
+ * so the key's only job is to keep two purchases from colliding, and a slug cannot do it.
43
+ *
44
+ * A re-buy of the SAME slug therefore adds an entry rather than replacing one. That is correct:
45
+ * they are two purchases. Expired entries are pruned by the backing store (the hosted one) or
46
+ * simply ignored by `isLive` (the file one).
47
+ */
48
+ export declare const heldKey: (held: Pick<HeldLicense, "jti">) => string;
27
49
  /**
28
50
  * Decode a token's `jti`, `exp`, and `naulon.slug/title` WITHOUT verifying — this
29
51
  * is the agent reading its own captured receipt for bookkeeping, not trusting a
@@ -33,6 +55,28 @@ export interface HeldLicense {
33
55
  export declare function decodeHeld(jws: string): Omit<HeldLicense, "jws"> | null;
34
56
  /** Is this held license still valid at `nowSec` (epoch seconds)? */
35
57
  export declare function isLive(held: HeldLicense, nowSec: number): boolean;
58
+ /**
59
+ * Find the live held licence that covers a request, or null.
60
+ *
61
+ * The store is a `Map` keyed by SLUG, which answers exactly one question: "did I pay for this
62
+ * one essay?". A scoped licence — bought over `/articles/*` before anything was read — is filed
63
+ * under a synthetic key nobody will ever look up, so without this it is unreachable the moment
64
+ * it is bought. That was the whole of the buyer-side gap.
65
+ *
66
+ * Coverage is decided by `licenseCoversPath`, the SAME function the gate uses to admit a
67
+ * presented licence. Re-deriving the rule here would let the buyer believe it holds a right the
68
+ * gate will refuse — a free-read the agent plans for and then pays for twice.
69
+ *
70
+ * When several cover the request, the most specific wins: an unscoped licence bought for exactly
71
+ * this slug outranks any scope, and a narrower scope outranks a wider one. That ordering matters
72
+ * because the licences are not interchangeable — presenting the widest one first would burn a
73
+ * broad entitlement on a read a narrow one already covered.
74
+ */
75
+ export declare function findHeld(held: Iterable<HeldLicense>, req: {
76
+ slug: string;
77
+ path?: string;
78
+ aud?: string;
79
+ }, nowSec: number): HeldLicense | null;
36
80
  export declare function loadHeld(): Promise<Map<string, HeldLicense>>;
37
81
  export declare function saveHeld(held: Map<string, HeldLicense>): Promise<void>;
38
82
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"licenseStore.d.ts","sourceRoot":"","sources":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EAAE,MAAM,GACb,WAAW,GAAG,IAAI,CAqCpB;AAED,wBAAsB,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAYlE;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5E;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAED,gFAAgF;AAChF,eAAO,MAAM,aAAa,EAAE,SAA8C,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,SAAS,CAS1F"}
@@ -6,8 +6,26 @@
6
6
  */
7
7
  import { mkdir, readFile, writeFile } from "node:fs/promises";
8
8
  import { dirname } from "node:path";
9
- import { getConfig } from "@naulon/shared";
9
+ import { getConfig, licenseCoversPath } from "@naulon/shared";
10
10
  const file = () => getConfig().WAYFARER_LICENSE_PATH;
11
+ /**
12
+ * The key a held licence is filed under: its `jti`, never its slug.
13
+ *
14
+ * Slug was the original key and it EVICTS ACROSS PUBLISHERS. `about`, `faq`, `index` and `privacy`
15
+ * are not rare; two independently-run sites share one, and the second purchase silently overwrote
16
+ * the first licence's entry — one row for two payments, with the survivor bound (by `aud`) to only
17
+ * one of them. The buyer then re-paid for the evicted one, which is the double-charge this store
18
+ * exists to prevent. Measured in prod on 2026-09-10.
19
+ *
20
+ * `jti` is the gate's own unique identifier for the licence, so one entry is one purchase. Nothing
21
+ * reads the map by key — `findHeld` scans values and decides coverage with `licenseCoversPath` —
22
+ * so the key's only job is to keep two purchases from colliding, and a slug cannot do it.
23
+ *
24
+ * A re-buy of the SAME slug therefore adds an entry rather than replacing one. That is correct:
25
+ * they are two purchases. Expired entries are pruned by the backing store (the hosted one) or
26
+ * simply ignored by `isLive` (the file one).
27
+ */
28
+ export const heldKey = (held) => held.jti;
11
29
  /**
12
30
  * Decode a token's `jti`, `exp`, and `naulon.slug/title` WITHOUT verifying — this
13
31
  * is the agent reading its own captured receipt for bookkeeping, not trusting a
@@ -31,9 +49,14 @@ export function decodeHeld(jws) {
31
49
  if (grant !== undefined && grant !== "read")
32
50
  return null;
33
51
  const patterns = claims.naulon.scope?.patterns;
52
+ // The TERMS the payment executed. Carried because the holder is the party that needs to act
53
+ // on them: an agent with bytes and no statement of rights guesses, and guesses the most
54
+ // restrictive thing it can — which is how a buyer was refused an article they had paid for.
55
+ const terms = claims.naulon.terms;
34
56
  return {
35
57
  slug: claims.naulon.slug,
36
58
  title: claims.naulon.title ?? claims.naulon.slug,
59
+ ...(Array.isArray(terms) ? { terms: terms.filter((x) => typeof x === "string") } : {}),
37
60
  ...(Array.isArray(patterns) ? { scope: { patterns: patterns.filter((x) => typeof x === "string") } } : {}),
38
61
  jti: claims.jti,
39
62
  exp: claims.exp,
@@ -49,11 +72,72 @@ export function decodeHeld(jws) {
49
72
  export function isLive(held, nowSec) {
50
73
  return held.exp > nowSec;
51
74
  }
75
+ /**
76
+ * Find the live held licence that covers a request, or null.
77
+ *
78
+ * The store is a `Map` keyed by SLUG, which answers exactly one question: "did I pay for this
79
+ * one essay?". A scoped licence — bought over `/articles/*` before anything was read — is filed
80
+ * under a synthetic key nobody will ever look up, so without this it is unreachable the moment
81
+ * it is bought. That was the whole of the buyer-side gap.
82
+ *
83
+ * Coverage is decided by `licenseCoversPath`, the SAME function the gate uses to admit a
84
+ * presented licence. Re-deriving the rule here would let the buyer believe it holds a right the
85
+ * gate will refuse — a free-read the agent plans for and then pays for twice.
86
+ *
87
+ * When several cover the request, the most specific wins: an unscoped licence bought for exactly
88
+ * this slug outranks any scope, and a narrower scope outranks a wider one. That ordering matters
89
+ * because the licences are not interchangeable — presenting the widest one first would burn a
90
+ * broad entitlement on a read a narrow one already covered.
91
+ */
92
+ export function findHeld(held, req, nowSec) {
93
+ let best = null;
94
+ let bestRank = -1;
95
+ for (const h of held) {
96
+ if (!isLive(h, nowSec))
97
+ continue;
98
+ // Bound to the gate that minted it — scoped or not.
99
+ //
100
+ // The selling gate re-verifies `aud` itself (`licenseEntitlesRead`), so an unbound match was
101
+ // never a way to spend one publisher's licence at another. The damage is on the BUYER's side
102
+ // and is worse than a refusal: two independently-run sites share a generic slug (`faq`,
103
+ // `about`), the slug-only match marks it licensed, and the re-read then fetches the licence's
104
+ // OWN paid url — so the agent cites site A's bytes under site B's title, free, with nothing
105
+ // raised anywhere. For a product whose whole claim is a verifiable citation, that is the
106
+ // expensive failure.
107
+ //
108
+ // The cost of binding is a publisher who overrode `LICENSE_ISSUER` away from `naulon:${host}`:
109
+ // their held licences miss and the agent pays a second time. That is bounded and visible,
110
+ // where the substitution is unbounded and silent — and such a deployment is already degraded,
111
+ // since `agent.ts` verifies captured licences against the same derived identity and marks
112
+ // them UNVERIFIED. `license-token.ts` has bound its own cache by origin all along; this was
113
+ // the outlier.
114
+ //
115
+ // A caller that cannot name the gate gets nothing, rather than a slug-only guess.
116
+ if (req.aud === undefined || h.aud !== req.aud)
117
+ continue;
118
+ if (!licenseCoversPath(h, req))
119
+ continue;
120
+ // An exact-slug licence is rank Infinity-ish: it names one resource and cannot be beaten.
121
+ // A scope's rank is its longest matching pattern's literal length, mirroring RFC 9309's
122
+ // "longest rule wins" — the same tie-break the gate's price rules and RSL both use.
123
+ const rank = h.scope
124
+ ? Math.max(...h.scope.patterns.map((p) => p.replace(/\*/g, "").length))
125
+ : Number.MAX_SAFE_INTEGER;
126
+ if (rank > bestRank) {
127
+ best = h;
128
+ bestRank = rank;
129
+ }
130
+ }
131
+ return best;
132
+ }
52
133
  export async function loadHeld() {
53
134
  try {
54
135
  const raw = await readFile(file(), "utf8");
55
136
  const arr = JSON.parse(raw);
56
- return new Map(arr.map((h) => [h.slug, h]));
137
+ // Keyed by `jti` on load, whatever the file was written with: the on-disk shape is a flat ARRAY
138
+ // of licences, so a store written under the old slug key re-keys itself here with no migration.
139
+ // The only loss is the eviction that already happened before the file was written.
140
+ return new Map(arr.map((h) => [heldKey(h), h]));
57
141
  }
58
142
  catch (err) {
59
143
  if (err.code === "ENOENT")
@@ -1 +1 @@
1
- {"version":3,"file":"licenseStore.js","sourceRoot":"","sources":["../src/licenseStore.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA2B3C,MAAM,IAAI,GAAG,GAAW,EAAE,CAAC,SAAS,EAAE,CAAC,qBAAqB,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAMvE,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI;YAAE,OAAO,IAAI,CAAC;QACnF,wFAAwF;QACxF,uFAAuF;QACvF,uFAAuF;QACvF,qFAAqF;QACrF,6CAA6C;QA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CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/rail.d.ts CHANGED
@@ -7,12 +7,23 @@
7
7
  * both. Absent per-tenant divergence the 402 carries the fleet rail, so railBuyer picks the same
8
8
  * builder activeNetwork() would have — byte-identical to memoBuyer/gatewayBuyer for a single-rail fleet.
9
9
  */
10
- import { type Buyer } from "./buyer.ts";
10
+ import { type Buyer, type Quoted } from "./buyer.ts";
11
11
  import { type MemoSigner } from "./memo.ts";
12
12
  import { type GatewaySigner } from "./gateway.ts";
13
13
  export interface RailSigners {
14
14
  memo?: MemoSigner;
15
15
  gateway?: GatewaySigner;
16
16
  }
17
+ /**
18
+ * Sign a 402 the caller already holds, on the rail the GATE will settle it on — the payment
19
+ * builder `railBuyer` runs inside its fetch loop, exposed on its own for a host that never needs
20
+ * the loop: one that built the 402 itself and is now paying it from the buyer's session signers
21
+ * (the cloud selling a licence it just offered). Picking the rail here, once, is what keeps a
22
+ * sale and a toll on the same envelope for the same tenant chain.
23
+ *
24
+ * Throws on a rail with no signer, and lets `gatewayLegPayload` / the signer throw their own
25
+ * coded refusals (N-leg on the Circle SDK, a grant refusal) — the caller owns the mapping.
26
+ */
27
+ export declare function assembleRailPayment(quoted: Quoted, nowMs: number, signers: RailSigners): Promise<string>;
17
28
  export declare function railBuyer(signers: RailSigners): Buyer;
18
29
  //# sourceMappingURL=rail.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../src/rail.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAIL,KAAK,KAAK,EAIX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAgD,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAGhG,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAcD,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,KAAK,CA8CrD"}
1
+ {"version":3,"file":"rail.d.ts","sourceRoot":"","sources":["../src/rail.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAIL,KAAK,KAAK,EAGV,KAAK,MAAM,EACZ,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAA2E,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAG3H,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAmBD;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB9G;AAqED,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,KAAK,CA0BrD"}