@naulon/wayfarer 0.1.2 → 0.3.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.
Files changed (52) hide show
  1. package/dist/agent.d.ts +48 -2
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +127 -10
  4. package/dist/agent.js.map +1 -1
  5. package/dist/appraise.d.ts +55 -0
  6. package/dist/appraise.d.ts.map +1 -1
  7. package/dist/appraise.js +106 -18
  8. package/dist/appraise.js.map +1 -1
  9. package/dist/buyer.d.ts +47 -4
  10. package/dist/buyer.d.ts.map +1 -1
  11. package/dist/buyer.js +118 -4
  12. package/dist/buyer.js.map +1 -1
  13. package/dist/decide.d.ts.map +1 -1
  14. package/dist/decide.js +9 -1
  15. package/dist/decide.js.map +1 -1
  16. package/dist/discovery.d.ts +12 -1
  17. package/dist/discovery.d.ts.map +1 -1
  18. package/dist/discovery.js +25 -8
  19. package/dist/discovery.js.map +1 -1
  20. package/dist/gateway.d.ts +40 -1
  21. package/dist/gateway.d.ts.map +1 -1
  22. package/dist/gateway.js +48 -11
  23. package/dist/gateway.js.map +1 -1
  24. package/dist/lib.d.ts +8 -6
  25. package/dist/lib.d.ts.map +1 -1
  26. package/dist/lib.js +8 -6
  27. package/dist/lib.js.map +1 -1
  28. package/dist/memo.d.ts +39 -15
  29. package/dist/memo.d.ts.map +1 -1
  30. package/dist/memo.js +47 -10
  31. package/dist/memo.js.map +1 -1
  32. package/dist/origin-policy.d.ts +1 -1
  33. package/dist/origin-policy.js +1 -1
  34. package/dist/paidFetch.d.ts.map +1 -1
  35. package/dist/paidFetch.js +14 -4
  36. package/dist/paidFetch.js.map +1 -1
  37. package/dist/pay.d.ts.map +1 -1
  38. package/dist/pay.js +5 -1
  39. package/dist/pay.js.map +1 -1
  40. package/dist/pop.d.ts +11 -1
  41. package/dist/pop.d.ts.map +1 -1
  42. package/dist/pop.js +18 -2
  43. package/dist/pop.js.map +1 -1
  44. package/dist/rail.d.ts.map +1 -1
  45. package/dist/rail.js +6 -5
  46. package/dist/rail.js.map +1 -1
  47. package/dist/types.d.ts +14 -0
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/wallet.d.ts +2 -6
  50. package/dist/wallet.d.ts.map +1 -1
  51. package/dist/wallet.js.map +1 -1
  52. package/package.json +3 -3
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, getConfig } from "@naulon/shared";
23
+ import { activeNetwork, arcPreviewHeaders, getConfig } from "@naulon/shared";
24
24
  import { classifyPaymentError, classifySignerRefusal, probe, } from "./buyer.js";
25
25
  import { runPaidFetch } from "./paidFetch.js";
26
26
  function envAccountKey() {
@@ -85,8 +85,7 @@ export function gatewayBuyer(signer) {
85
85
  // reported the "0x" placeholder until the first pay — agent.ts logs `wallet ${address}`
86
86
  // BEFORE init(), so an operator saw `wallet 0x` instead of the real derived address.
87
87
  await getSigner();
88
- const { GatewayClient } = await import("@circle-fin/x402-batching/client");
89
- const client = new GatewayClient({ chain: activeNetwork().chainName, privateKey: envAccountKey() });
88
+ const client = await newGatewayClient(activeNetwork().chainName, envAccountKey());
90
89
  console.log(` depositing ${cfg.DEPOSIT_AMOUNT_USDC} USDC into the Gateway Wallet...`);
91
90
  const result = await client.deposit(cfg.DEPOSIT_AMOUNT_USDC);
92
91
  console.log(` deposit tx ${result.depositTxHash}`);
@@ -116,6 +115,30 @@ export function gatewayBuyer(signer) {
116
115
  },
117
116
  };
118
117
  }
118
+ /**
119
+ * The `GatewayClient` constructor config for a chain + key. Pure + exported for direct
120
+ * unit testing, the same discipline as tollgate's `facilitatorHeaders` — the six SDK call
121
+ * sites below all build their client through `newGatewayClient`, so this IS the config
122
+ * that runs, not a parallel copy.
123
+ *
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.
130
+ */
131
+ export function gatewayClientConfig(chain, privateKey) {
132
+ return { chain, privateKey, headers: arcPreviewHeaders(chain) };
133
+ }
134
+ /** One owner for every `GatewayClient` construction in this module: the lazy SDK import
135
+ * (so the mock/memo paths never pull the SDK in) plus `gatewayClientConfig`. Six wrappers
136
+ * used to repeat both, which is how the deleted 3.3.0 default would have gone missing in
137
+ * six places at once. */
138
+ async function newGatewayClient(chain, privateKey) {
139
+ const { GatewayClient } = await import("@circle-fin/x402-batching/client");
140
+ return new GatewayClient(gatewayClientConfig(chain, privateKey));
141
+ }
119
142
  /**
120
143
  * Out-of-band, custody-free deposit into the Circle Gateway Wallet — the non-custodial contract that
121
144
  * holds the buyer's unified balance (Circle infra, buyer-controlled; naulon custodies nothing). The
@@ -125,17 +148,33 @@ export function gatewayBuyer(signer) {
125
148
  * script/operator calls. SDK loaded lazily so the mock/memo paths never pull it in.
126
149
  */
127
150
  export async function gatewayDeposit(opts) {
128
- const { GatewayClient } = await import("@circle-fin/x402-batching/client");
129
- const client = new GatewayClient({ chain: opts.chain, privateKey: opts.privateKey });
151
+ const client = await newGatewayClient(opts.chain, opts.privateKey);
130
152
  return client.deposit(opts.amountUsdc);
131
153
  }
154
+ /**
155
+ * Withdraw from the Gateway unified balance back to a normal address. Same-chain by
156
+ * construction — `withdraw()` to the source chain is instant (no 7-day delay); the
157
+ * trustless initiate/complete pair is emergency-only, for a Circle API outage. `chain`
158
+ * is passed explicitly even though `withdraw()` already defaults to the source chain
159
+ * when `options.chain` is omitted — the same-chain intent is the whole point of this
160
+ * wrapper, so it stays legible and testable rather than inherited from a default.
161
+ * `maxFee` is left at the SDK default (2.01 USDC) — inventing a fee ceiling at this
162
+ * layer is a product decision this wrapper hasn't been given.
163
+ * NOTE: `transfer()` is a one-line deprecated alias for this same call
164
+ * (`transfer(amount, chain, recipient) => withdraw(amount, { chain, recipient })`) —
165
+ * don't "helpfully" switch back to it.
166
+ * SDK lazy, so the mock/memo paths never pull it in — same discipline as `gatewayDeposit`.
167
+ */
168
+ export async function gatewayWithdraw(opts) {
169
+ const client = await newGatewayClient(opts.chain, opts.privateKey);
170
+ return client.withdraw(opts.amountUsdc, { chain: opts.chain, recipient: opts.to });
171
+ }
132
172
  /** Read the wallet + Gateway balances for a key — the preflight a deposit script shows before it moves
133
173
  * funds, and the check the buyer uses to see if its unified balance covers a toll. Pass `address` to
134
174
  * read ANOTHER account's balances (e.g. confirm the AUTHOR received a settle) — the client key only
135
175
  * authenticates the read, it needn't own the address. SDK loaded lazily. */
136
176
  export async function gatewayBalances(opts) {
137
- const { GatewayClient } = await import("@circle-fin/x402-batching/client");
138
- return new GatewayClient({ chain: opts.chain, privateKey: opts.privateKey }).getBalances(opts.address);
177
+ return (await newGatewayClient(opts.chain, opts.privateKey)).getBalances(opts.address);
139
178
  }
140
179
  /**
141
180
  * Look up a single Gateway transfer (a settlement) by its Circle id — the `settlementRef` a gateway
@@ -144,8 +183,7 @@ export async function gatewayBalances(opts) {
144
183
  * correct "did the settle land?" check — pair `status` with `classifyGatewaySettlement`. SDK lazy.
145
184
  */
146
185
  export async function gatewayTransferStatus(opts) {
147
- const { GatewayClient } = await import("@circle-fin/x402-batching/client");
148
- return new GatewayClient({ chain: opts.chain, privateKey: opts.privateKey }).getTransferById(opts.id);
186
+ return (await newGatewayClient(opts.chain, opts.privateKey)).getTransferById(opts.id);
149
187
  }
150
188
  /**
151
189
  * Search Gateway transfers with optional filters (`to`/`from`/`status`/`network`/date range). Use to
@@ -154,8 +192,7 @@ export async function gatewayTransferStatus(opts) {
154
192
  */
155
193
  export async function gatewayTransfers(opts) {
156
194
  const { chain, privateKey, ...params } = opts;
157
- const { GatewayClient } = await import("@circle-fin/x402-batching/client");
158
- return new GatewayClient({ chain, privateKey }).searchTransfers(params);
195
+ return (await newGatewayClient(chain, privateKey)).searchTransfers(params);
159
196
  }
160
197
  /**
161
198
  * Classify a Circle Gateway transfer `status` into settled / pending / failed. This is the CODE form
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAgD,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAW1D,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,GAKN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA4B9C,SAAS,aAAa;IACpB,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,2BAA2B,aAAa,EAAE,CAAC,SAAS,2CAA2C;YAC7F,oFAAoF,CACvF,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,iBAAiB,EAAE,CAAkB,CAAC;AAC1H,CAAC;AAED;;;wFAGwF;AACxF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAqB,EACrB,MAAc,EACd,WAAmB;IAEnB,6FAA6F;IAC7F,2FAA2F;IAC3F,8FAA8F;IAC9F,oFAAoF;IACpF,EAAE;IACF,iGAAiG;IACjG,2EAA2E;IAC3E,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,0CAA0C,MAAM,C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AC;IACH,CAAC;AACH,CAAC"}
package/dist/lib.d.ts CHANGED
@@ -13,19 +13,21 @@
13
13
  */
14
14
  export { run } from "./agent.ts";
15
15
  export type { Logger, RunOptions } from "./agent.ts";
16
- export { tollgateBase, articleUrl, fetchJwks, verifyAgainst } from "./agent.ts";
16
+ export { tollgateBase, articleUrl, fetchJwks, verifyAgainst, licenseIdentityFor } from "./agent.ts";
17
17
  export { discover } from "./discover.ts";
18
- export { appraise } from "./appraise.ts";
18
+ export { resolvedDiscoverySourceUrl } from "./discovery.ts";
19
+ export { appraise, buildAppraisePrompt, evidenceLine, parseRelevance } from "./appraise.ts";
20
+ export type { AppraisalSubject, AppraisePromptOptions } from "./appraise.ts";
19
21
  export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError, } from "./buyer.ts";
20
22
  export type { Buyer, Quoted, LegRequirements, Fetched, FetchErrorCode, PayGuard, ProbeOutcome } from "./buyer.ts";
21
23
  export { mockBuyer } from "./pay.ts";
22
- export { gatewayBuyer, gatewayDeposit, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.ts";
24
+ export { gatewayBuyer, gatewayDeposit, gatewayWithdraw, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.ts";
23
25
  export type { GatewaySigner, GatewayDepositOpts, GatewaySettlementState } from "./gateway.ts";
24
- export { memoBuyer, signMemoPayment } from "./memo.ts";
25
- export type { MemoSigner } from "./memo.ts";
26
+ export { memoBuyer, signMemoPayment, assembleMemoPayment } from "./memo.ts";
27
+ export type { MemoSigner, MemoTypedData } from "./memo.ts";
26
28
  export { railBuyer } from "./rail.ts";
27
29
  export type { RailSigners } from "./rail.ts";
28
- export { decide, DEFAULT_POLICY, spendGate } from "./decide.ts";
30
+ export { decide, DEFAULT_POLICY, payHostOf, spendGate } from "./decide.ts";
29
31
  export type { DecisionPolicy, DecideContext, SpendVerdict } from "./decide.ts";
30
32
  export { authorizeOrigin } from "./origin-policy.ts";
31
33
  export type { OriginRequest, OriginVerdict, PayableTarget } from "./origin-policy.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;AAKrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,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,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,MAAM,WAAW,CAAC;AACvD,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,MAAM,W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AM,iBAAiB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC3G,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,YAAY,EACV,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,MAAM,EACN,QAAQ,EACR,MAAM,EACN,SAAS,GACV,MAAM,YAAY,CAAC"}
package/dist/lib.js CHANGED
@@ -14,21 +14,23 @@
14
14
  // ── pipeline entry ──────────────────────────────────────────────────────────
15
15
  export { run } from "./agent.js";
16
16
  // Pipeline primitives a second consumer (the MCP server) reuses to resolve an
17
- // article URL from a slug against the configured gate, and to verify a captured
17
+ // article URL from a slug against the configured gate, to derive the gate's
18
+ // canonical license identity from a paid-into URL, and to verify a captured
18
19
  // license against the gate's JWKS — single-sourced here so the two can't drift.
19
- export { tollgateBase, articleUrl, fetchJwks, verifyAgainst } from "./agent.js";
20
+ export { tollgateBase, articleUrl, fetchJwks, verifyAgainst, licenseIdentityFor } from "./agent.js";
20
21
  // ── discover ────────────────────────────────────────────────────────────────
21
22
  export { discover } from "./discover.js";
23
+ export { resolvedDiscoverySourceUrl } from "./discovery.js";
22
24
  // ── appraise ────────────────────────────────────────────────────────────────
23
- export { appraise } from "./appraise.js";
25
+ export { appraise, buildAppraisePrompt, evidenceLine, parseRelevance } from "./appraise.js";
24
26
  // ── quote + pay (the Buyer seam) ────────────────────────────────────────────
25
27
  export { probe, probePrice, probeFailure, assemblePayment, rereadWithLicense, selectBuyer, quotedTotalAtomic, tollMovedOrNull, classifyPaymentError, } from "./buyer.js";
26
28
  export { mockBuyer } from "./pay.js";
27
- export { gatewayBuyer, gatewayDeposit, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.js";
28
- export { memoBuyer, signMemoPayment } from "./memo.js";
29
+ export { gatewayBuyer, gatewayDeposit, gatewayWithdraw, gatewayBalances, gatewayTransferStatus, gatewayTransfers, classifyGatewaySettlement, } from "./gateway.js";
30
+ export { memoBuyer, signMemoPayment, assembleMemoPayment } from "./memo.js";
29
31
  export { railBuyer } from "./rail.js";
30
32
  // ── decide (policy) ─────────────────────────────────────────────────────────
31
- export { decide, DEFAULT_POLICY, spendGate } from "./decide.js";
33
+ export { decide, DEFAULT_POLICY, payHostOf, spendGate } from "./decide.js";
32
34
  // ── origin policy (whose origin may money touch) ─────────────────────────────
33
35
  // The one answer to that question; `spendGate` above stays the one answer to "how
34
36
  // much". `PayableTarget` is mintable only by `authorizeOrigin`, so a pay path that
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,gFAAgF;AAChF,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,+EAA+E;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,+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,CAAC;AAEpB,OAAO,EAAE,S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E,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,CAAC;AAEpB,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;AAEtB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,+EAA+E;AAC/E,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG3E,gFAAgF;AAChF,kFAAkF;AAClF,mFAAmF;AACnF,wEAAwE;AACxE,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,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE3G,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,+EAA+E;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
package/dist/memo.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type TypedDataDomain } from "viem";
2
- import { TRANSFER_WITH_AUTHORIZATION_TYPES, type MemoAuthorization } from "@naulon/shared";
2
+ import { TRANSFER_WITH_AUTHORIZATION_TYPES, type MemoAuthorization, type SettlementNetwork } from "@naulon/shared";
3
3
  import { type Buyer, type LegRequirements, type Quoted } from "./buyer.ts";
4
4
  /**
5
5
  * The signer seam (BUY-2). By default the memo buyer signs each EIP-3009 leg with the local
@@ -11,19 +11,33 @@ import { type Buyer, type LegRequirements, type Quoted } from "./buyer.ts";
11
11
  */
12
12
  export interface MemoSigner {
13
13
  address: `0x${string}`;
14
- signTypedData(args: {
15
- domain: TypedDataDomain;
16
- types: typeof TRANSFER_WITH_AUTHORIZATION_TYPES;
17
- primaryType: "TransferWithAuthorization";
18
- message: {
19
- from: `0x${string}`;
20
- to: `0x${string}`;
21
- value: bigint;
22
- validAfter: bigint;
23
- validBefore: bigint;
24
- nonce: `0x${string}`;
25
- };
26
- }): Promise<`0x${string}`>;
14
+ signTypedData(args: MemoTypedData): Promise<`0x${string}`>;
15
+ /**
16
+ * OPTIONAL batch sign — sign EVERY leg of a multi-leg toll (operator fee, co-author split) in ONE
17
+ * call, so a batch-capable host can RESERVE them atomically (all-or-nothing, no stranded sibling
18
+ * leg). Returns one signature per input, index-aligned.
19
+ *
20
+ * A signer WITHOUT this method (a local env-key `PrivateKeyAccount`, the OSS self-host path, or a mock)
21
+ * falls back to per-leg signing via {@link assembleMemoPayment} — safe there precisely because those
22
+ * paths take no host-side reserve (mock) or never carry a multi-leg quote through a hosted grant. Only
23
+ * an injected cloud signer that reserves needs the atomicity, and only it implements this.
24
+ */
25
+ signTypedDataBatch?(argsList: MemoTypedData[]): Promise<`0x${string}`[]>;
26
+ }
27
+ /** The EIP-3009 `TransferWithAuthorization` typed data a memo leg signs — one shape for the single and
28
+ * batch signer methods so a leg is signed identically however it is batched. */
29
+ export interface MemoTypedData {
30
+ domain: TypedDataDomain;
31
+ types: typeof TRANSFER_WITH_AUTHORIZATION_TYPES;
32
+ primaryType: "TransferWithAuthorization";
33
+ message: {
34
+ from: `0x${string}`;
35
+ to: `0x${string}`;
36
+ value: bigint;
37
+ validAfter: bigint;
38
+ validBefore: bigint;
39
+ nonce: `0x${string}`;
40
+ };
27
41
  }
28
42
  /** Sign a raw USDC EIP-3009 `TransferWithAuthorization` against the active network's USDC
29
43
  * EIP-712 domain and return the base64 `{authorization, signature}` payload the gate's
@@ -35,9 +49,19 @@ export declare function signMemoPayment(requirements: Quoted["requirements"], no
35
49
  * per-leg primitive `assemblePayment` calls once per advertised leg (mirrors the gate's
36
50
  * `memoLegPayload` → `buildMemoSignatures`). The memo id is NOT signed (the relayer
37
51
  * attaches it at submit), so each leg needs nothing beyond its own authorization. */
38
- export declare function memoLegPayload(requirements: LegRequirements, nowMs: number, signer?: MemoSigner, net?: import("@naulon/shared").SettlementNetwork): Promise<{
52
+ export declare function memoLegPayload(requirements: LegRequirements, nowMs: number, signer?: MemoSigner, net?: SettlementNetwork): Promise<{
39
53
  authorization: MemoAuthorization;
40
54
  signature: `0x${string}`;
41
55
  }>;
56
+ /**
57
+ * Assemble the memo rail's base64 `payment-signature`. For a multi-leg toll signed by a BATCH-capable
58
+ * injected signer, build every leg's authorization, sign them ALL in ONE call (so the host reserves them
59
+ * atomically — a sibling leg that trips a ceiling can never strand an already-debited author leg), and
60
+ * frame the leg array (author first) exactly as {@link assemblePayment} does. Every OTHER case — a
61
+ * single-leg toll, the local env-key signer, or an injected signer WITHOUT a batch method — falls
62
+ * straight through to the per-leg path, byte-identical to before this seam existed. The multi-leg-only
63
+ * batch means a non-fee read and every non-hosted path are provably untouched.
64
+ */
65
+ export declare function assembleMemoPayment(quoted: Quoted, nowMs: number, signer?: MemoSigner, net?: SettlementNetwork): Promise<string>;
42
66
  export declare function memoBuyer(signer?: MemoSigner): Buyer;
43
67
  //# sourceMappingURL=memo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAeA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,EAIL,iCAAiC,EACjC,KAAK,iBAAiB,EACvB,MAAM,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CAAC,CAQzE;AA6CD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,UAAU,EACnB,GAAG,GAAE,iBAAmC,GACvC,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK,CA+BpD"}
package/dist/memo.js CHANGED
@@ -38,17 +38,27 @@ export async function signMemoPayment(requirements, nowMs) {
38
38
  * `memoLegPayload` → `buildMemoSignatures`). The memo id is NOT signed (the relayer
39
39
  * attaches it at submit), so each leg needs nothing beyond its own authorization. */
40
40
  export async function memoLegPayload(requirements, nowMs, signer, net = activeNetwork()) {
41
- const cfg = getConfig();
42
41
  // Default path resolves the local key; an injected signer NEVER reads BUYER_PRIVATE_KEY (the whole
43
42
  // point of the cloud wallet — the key lives in the grant-checked BFF, not this process).
44
43
  const envAccount = signer ? undefined : privateKeyToAccount(buyerKey());
45
44
  const from = (signer?.address ?? envAccount.address);
46
- // Stamp validity at PAY time (nowMs is `Date.now()` from fetch, not quote time) with a
47
- // MARGIN: floor the window to WAYFARER_MIN_VALIDITY_SECONDS so a gate advertising a
48
- // too-short maxTimeoutSeconds can't make the authorization expire before the relay
49
- // submits it (the facilitator's `authorization_validity_too_short` — the Keryx ~1-day
50
- // lesson; see memory `x402-validity-window-floor`). The window only widens, never
51
- // shrinks — a long gate window is honored as-is.
45
+ const { authorization, typedData } = buildMemoLeg(requirements, nowMs, from, net);
46
+ const signature = signer ? await signer.signTypedData(typedData) : await envAccount.signTypedData(typedData);
47
+ return { authorization, signature };
48
+ }
49
+ /**
50
+ * Build ONE leg's EIP-3009 authorization + the typed data to sign, WITHOUT signing — the pure half of
51
+ * {@link memoLegPayload}, shared by the per-leg and batch paths so both stamp the identical validity
52
+ * window and USDC domain. `from` is the already-resolved signer address.
53
+ *
54
+ * Stamps validity at PAY time (`nowMs` is `Date.now()` from fetch, not quote time) with a MARGIN: floor
55
+ * the window to WAYFARER_MIN_VALIDITY_SECONDS so a gate advertising a too-short maxTimeoutSeconds can't
56
+ * make the authorization expire before the relay submits it (the facilitator's
57
+ * `authorization_validity_too_short` — the Keryx ~1-day lesson; see memory `x402-validity-window-floor`).
58
+ * The window only widens, never shrinks — a long gate window is honored as-is.
59
+ */
60
+ function buildMemoLeg(requirements, nowMs, from, net) {
61
+ const cfg = getConfig();
52
62
  const window = Math.max(requirements.maxTimeoutSeconds, cfg.WAYFARER_MIN_VALIDITY_SECONDS);
53
63
  const authorization = {
54
64
  from,
@@ -71,8 +81,35 @@ export async function memoLegPayload(requirements, nowMs, signer, net = activeNe
71
81
  nonce: authorization.nonce,
72
82
  },
73
83
  };
74
- const signature = signer ? await signer.signTypedData(typedData) : await envAccount.signTypedData(typedData);
75
- return { authorization, signature };
84
+ return { authorization, typedData };
85
+ }
86
+ /**
87
+ * Assemble the memo rail's base64 `payment-signature`. For a multi-leg toll signed by a BATCH-capable
88
+ * injected signer, build every leg's authorization, sign them ALL in ONE call (so the host reserves them
89
+ * atomically — a sibling leg that trips a ceiling can never strand an already-debited author leg), and
90
+ * frame the leg array (author first) exactly as {@link assemblePayment} does. Every OTHER case — a
91
+ * single-leg toll, the local env-key signer, or an injected signer WITHOUT a batch method — falls
92
+ * straight through to the per-leg path, byte-identical to before this seam existed. The multi-leg-only
93
+ * batch means a non-fee read and every non-hosted path are provably untouched.
94
+ */
95
+ export async function assembleMemoPayment(quoted, nowMs, signer, net = activeNetwork()) {
96
+ if (quoted.legs && quoted.legs.length > 1 && signer?.signTypedDataBatch) {
97
+ // Build every leg first (fresh nonce + validity), then one atomic batch sign. The from is the
98
+ // injected signer's address — the batch path only exists for a hosted signer, which never reads the
99
+ // env key. Leg order (author first) is preserved into the framed array, matching assemblePayment.
100
+ const built = quoted.legs.map((leg) => buildMemoLeg({ ...quoted.requirements, payTo: leg.payTo, amount: leg.amount }, nowMs, signer.address, net));
101
+ const signatures = await signer.signTypedDataBatch(built.map((b) => b.typedData));
102
+ // A count mismatch means the host signed a different set than we sent — never frame a partial or
103
+ // misaligned payment. Fail loud; the caller's onSignError turns it into a typed, non-signed result.
104
+ if (signatures.length !== built.length) {
105
+ throw new Error(`batch signer returned ${signatures.length} signatures for ${built.length} legs`);
106
+ }
107
+ const payloads = built.map((b, i) => ({ authorization: b.authorization, signature: signatures[i] }));
108
+ return Buffer.from(JSON.stringify(payloads)).toString("base64");
109
+ }
110
+ // Single leg, the env-key signer, or a signer without batch: today's per-leg framing (mock/OSS/gateway
111
+ // paths are unaffected — assemblePayment signs one leg, or Promise.all's the legs, exactly as before).
112
+ return assemblePayment(quoted, (req) => memoLegPayload(req, nowMs, signer, net));
76
113
  }
77
114
  export function memoBuyer(signer) {
78
115
  const address = signer ? signer.address : privateKeyToAccount(buyerKey()).address;
@@ -90,7 +127,7 @@ export function memoBuyer(signer) {
90
127
  // single-author quote stays the bare object, byte-identical to before. The shared loop owns
91
128
  // probe→moved-guard→paid-GET→classify; the memo rail supplies only how it signs and how it
92
129
  // types a sign refusal (grant exhausted/expired/no session → typed; else a transient origin throw).
93
- return runPaidFetch(url, kind, address, guard, (quoted, nowMs) => assemblePayment(quoted, (req) => memoLegPayload(req, nowMs, signer)), (error) => {
130
+ return runPaidFetch(url, kind, address, guard, (quoted, nowMs) => assembleMemoPayment(quoted, nowMs, signer), (error) => {
94
131
  const refusal = classifySignerRefusal(error);
95
132
  return refusal
96
133
  ? { ok: false, error, ...refusal }
package/dist/memo.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"memo.js","sourceRoot":"","sources":["../src/memo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,KAAK,EAAwB,MAAM,MAAM,CAAC;AACnD,OAAO,EACL,aAAa,EACb,SAAS,EACT,UAAU,EACV,iCAAiC,GAElC,MAAM,gBAA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,EAAE,IAAI,EAAE,CAAC;YACvE,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -15,7 +15,7 @@
15
15
  * the configured gate, because a different port is a different service and must not
16
16
  * satisfy the pin. That is the whole of its authority.
17
17
  *
18
- * It does NOT own domain policy. An allowlist names domains ("inneraxiom.com"), and
18
+ * It does NOT own domain policy. An allowlist names domains ("publisher.example"), and
19
19
  * which of them are payable — along with deny lists, per-domain caps, the kill switch
20
20
  * and human approval — belongs to `spendGate`, the one shared evaluator. Stating an
21
21
  * allowlist therefore REPLACES the gate pin rather than stacking with it: the operator
@@ -15,7 +15,7 @@
15
15
  * the configured gate, because a different port is a different service and must not
16
16
  * satisfy the pin. That is the whole of its authority.
17
17
  *
18
- * It does NOT own domain policy. An allowlist names domains ("inneraxiom.com"), and
18
+ * It does NOT own domain policy. An allowlist names domains ("publisher.example"), and
19
19
  * which of them are payable — along with deny lists, per-domain caps, the kill switch
20
20
  * and human approval — belongs to `spendGate`, the one shared evaluator. Stating an
21
21
  * allowlist therefore REPLACES the gate pin rather than stacking with it: the operator
@@ -1 +1 @@
1
- {"version":3,"file":"paidFetch.d.ts","sourceRoot":"","sources":["../src/paidFetch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,oBAAoB,EACpB,qBAAqB,EAKrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,YAAY,CAAC;AAGpB,qGAAqG;AACrG,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9E,2FAA2F;AAC3F,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErD,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,EAAE,KAAK,MAAM,EAAE,EACtB,KAAK,EAAE,QAAQ,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,OAAO,CAAC,CA2ElB;AAID,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"paidFetch.d.ts","sourceRoot":"","sources":["../src/paidFetch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,oBAAoB,EACpB,qBAAqB,EAMrB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,YAAY,CAAC;AAGpB,qGAAqG;AACrG,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9E,2FAA2F;AAC3F,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErD,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,EAAE,KAAK,MAAM,EAAE,EACtB,KAAK,EAAE,QAAQ,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,OAAO,CAAC,CAqFlB;AAID,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAC"}
package/dist/paidFetch.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * from memoBuyer/gatewayBuyer so a third buyer (railBuyer) reuses it without a third copy of
5
5
  * the loop. Behaviour is byte-identical to the two originals (their suites are the regression).
6
6
  */
7
- import { AGENT_UA, classifyPaymentError, classifySignerRefusal, probe, probeFailure, quotedTotalAtomic, tollMovedOrNull, } from "./buyer.js";
7
+ import { AGENT_UA, classifyPaymentError, classifySignerRefusal, probe, probeFailure, payeeRefusedOrNull, quotedTotalAtomic, tollMovedOrNull, } from "./buyer.js";
8
8
  import { agentFetch } from "./sign.js";
9
9
  export async function runPaidFetch(url, kind, address, guard, buildPayment, onSignError) {
10
10
  const outcome = await probe(url, kind, address);
@@ -15,6 +15,11 @@ export async function runPaidFetch(url, kind, address, guard, buildPayment, onSi
15
15
  const moved = tollMovedOrNull(quoted, guard);
16
16
  if (moved)
17
17
  return moved;
18
+ // Payee identity: refuse a payTo no owner authorized for this origin, BEFORE signing (nothing paid).
19
+ // Checked on the SAME leg set assemblePayment signs, so check == sign. Opt-in (no authorizePayee ⇒ null).
20
+ const refused = await payeeRefusedOrNull(quoted, guard);
21
+ if (refused)
22
+ return refused;
18
23
  // Signing and the paid fetch are wrapped SEPARATELY, because their non-spend failures classify
19
24
  // differently: a build/sign throw is rail-specific (a hosted session signer THROWS a coded grant
20
25
  // refusal → needs_topup; a config/payload fault → the rail's fallback, memo→origin_error,
@@ -46,13 +51,18 @@ export async function runPaidFetch(url, kind, address, guard, buildPayment, onSi
46
51
  const error = err instanceof Error ? err.message : String(err);
47
52
  return { ok: false, error, errorCode: "origin_error", retryable: true };
48
53
  }
54
+ // Both branches below hold a COMPLETE response from a gate that did not serve, so nothing settled
55
+ // and `unpaid` records that as knowledge. The throw paths above and the body-read failure below
56
+ // stay silent on it: once the request is on the wire, "it never settled" and "it settled and I
57
+ // lost the answer" are the same observation from here.
49
58
  if (res.status === 402) {
50
59
  const body = (await res.json().catch(() => ({})));
51
60
  const error = body.error ?? "payment rejected";
52
- return { ok: false, error, ...classifyPaymentError(error) };
61
+ return { ok: false, error, unpaid: true, ...classifyPaymentError(error) };
62
+ }
63
+ if (!res.ok) {
64
+ return { ok: false, error: `origin returned ${res.status}`, errorCode: "origin_error", retryable: true, unpaid: true };
53
65
  }
54
- if (!res.ok)
55
- return { ok: false, error: `origin returned ${res.status}`, errorCode: "origin_error", retryable: true };
56
66
  let settlementRef;
57
67
  const respHeader = res.headers.get("payment-response");
58
68
  if (respHeader) {
@@ -1 +1 @@
1
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BAAoB,EAAE,qBAAqB,EAAE,CAAC"}
package/dist/pay.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pay.d.ts","sourceRoot":"","sources":["../src/pay.ts"],"names":[],"mappings":"AAQA,OAAO,EASL,KAAK,KAAK,EAIX,MAAM,YAAY,CAAC;AAEpB,wBAAgB,SAAS,IAAI,KAAK,CAoEjC"}
1
+ {"version":3,"file":"pay.d.ts","sourceRoot":"","sources":["../src/pay.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,KAAK,KAAK,EAIX,MAAM,YAAY,CAAC;AAEpB,wBAAgB,SAAS,IAAI,KAAK,CAuEjC"}
package/dist/pay.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { agentFetch } from "./sign.js";
8
8
  import { getWallet } from "./wallet.js";
9
- import { AGENT_UA, assemblePayment, classifyPaymentError, probe, probeFailure, probePrice, quotedTotalAtomic, tollMovedOrNull, } from "./buyer.js";
9
+ import { AGENT_UA, assemblePayment, classifyPaymentError, payeeRefusedOrNull, probe, probeFailure, probePrice, quotedTotalAtomic, tollMovedOrNull, } from "./buyer.js";
10
10
  export function mockBuyer() {
11
11
  const wallet = getWallet();
12
12
  return {
@@ -26,6 +26,10 @@ export function mockBuyer() {
26
26
  const moved = tollMovedOrNull(quoted, guard);
27
27
  if (moved)
28
28
  return moved;
29
+ // Payee identity: refuse a payTo no owner authorized, before signing (parity with runPaidFetch).
30
+ const refused = await payeeRefusedOrNull(quoted, guard);
31
+ if (refused)
32
+ return refused;
29
33
  // One offline signature per advertised leg (operator fee → 2-leg array); a stock
30
34
  // single-author quote stays the bare object assemblePayment emits for one leg.
31
35
  const paymentSignature = await assemblePayment(quoted, (req, nonce) => ({
package/dist/pay.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pay.js","sourceRoot":"","sources":["../src/pay.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC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BACtG,CAAC;YACJ,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;YAC/D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;QAC7F,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/pop.d.ts CHANGED
@@ -2,7 +2,17 @@ import type { HeldLicense } from "./licenseStore.ts";
2
2
  import type { AgentWallet } from "./wallet.ts";
3
3
  /**
4
4
  * Build a proof-of-possession header for a held license, or null if the wallet
5
- * can't sign (no key) — in which case the caller must fall back to paying.
5
+ * can't sign (no key, or the signer itself failed) — in which case the caller
6
+ * must fall back to paying.
7
+ *
8
+ * `wallet.signMessage` is a real op on the hosted path — `cloudPopSigner`
9
+ * (wayfarer-mcp/cloud-signer.ts) POSTs to `/_naulon/buyer-wallet/sign-pop` and
10
+ * THROWS a `SignerError` on any non-2xx (network blip, expired session, 5xx).
11
+ * A held-license re-read is a best-effort free path, exactly like the re-read
12
+ * fetch itself (A1) — so a signing failure here must degrade to the same "can't
13
+ * sign" null, not propagate an uncaught rejection through every caller (run()'s
14
+ * cache branch, naulon_read_held) and crash the whole operation over one
15
+ * skippable decision (FU-A1b).
6
16
  */
7
17
  export declare function buildPopProof(held: HeldLicense, wallet: AgentWallet, now: number): Promise<string | null>;
8
18
  //# sourceMappingURL=pop.d.ts.map
package/dist/pop.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pop.d.ts","sourceRoot":"","sources":["../src/pop.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOxB"}
1
+ {"version":3,"file":"pop.d.ts","sourceRoot":"","sources":["../src/pop.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYxB"}
package/dist/pop.js CHANGED
@@ -11,7 +11,17 @@ import { randomBytes } from "node:crypto";
11
11
  import { popMessage } from "@naulon/shared";
12
12
  /**
13
13
  * Build a proof-of-possession header for a held license, or null if the wallet
14
- * can't sign (no key) — in which case the caller must fall back to paying.
14
+ * can't sign (no key, or the signer itself failed) — in which case the caller
15
+ * must fall back to paying.
16
+ *
17
+ * `wallet.signMessage` is a real op on the hosted path — `cloudPopSigner`
18
+ * (wayfarer-mcp/cloud-signer.ts) POSTs to `/_naulon/buyer-wallet/sign-pop` and
19
+ * THROWS a `SignerError` on any non-2xx (network blip, expired session, 5xx).
20
+ * A held-license re-read is a best-effort free path, exactly like the re-read
21
+ * fetch itself (A1) — so a signing failure here must degrade to the same "can't
22
+ * sign" null, not propagate an uncaught rejection through every caller (run()'s
23
+ * cache branch, naulon_read_held) and crash the whole operation over one
24
+ * skippable decision (FU-A1b).
15
25
  */
16
26
  export async function buildPopProof(held, wallet, now) {
17
27
  if (!wallet.signMessage)
@@ -19,7 +29,13 @@ export async function buildPopProof(held, wallet, now) {
19
29
  const ts = Math.floor(now / 1000);
20
30
  const nonce = randomBytes(16).toString("hex");
21
31
  const message = popMessage({ aud: held.aud, jti: held.jti, slug: held.slug, ts, nonce });
22
- const sig = await wallet.signMessage(message);
32
+ let sig;
33
+ try {
34
+ sig = await wallet.signMessage(message);
35
+ }
36
+ catch {
37
+ return null;
38
+ }
23
39
  return `${ts}.${nonce}.${sig}`;
24
40
  }
25
41
  //# sourceMappingURL=pop.js.map