@agenticprimitives/a2a 0.0.0-alpha.47 → 0.0.0-alpha.49

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 (82) hide show
  1. package/CLAUDE.md +4 -1
  2. package/README.md +1 -1
  3. package/dist/agent.d.ts +38 -9
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +256 -38
  6. package/dist/agent.js.map +1 -1
  7. package/dist/auth.d.ts +12 -2
  8. package/dist/auth.d.ts.map +1 -1
  9. package/dist/auth.js +34 -3
  10. package/dist/auth.js.map +1 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +3 -1
  13. package/dist/client.js.map +1 -1
  14. package/dist/conform/index.d.ts.map +1 -1
  15. package/dist/conform/index.js +15 -0
  16. package/dist/conform/index.js.map +1 -1
  17. package/dist/index.d.ts +7 -6
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +6 -4
  20. package/dist/index.js.map +1 -1
  21. package/dist/payment-gate.d.ts +69 -3
  22. package/dist/payment-gate.d.ts.map +1 -1
  23. package/dist/payment-gate.js +36 -5
  24. package/dist/payment-gate.js.map +1 -1
  25. package/dist/placeholder.d.ts +5 -0
  26. package/dist/placeholder.d.ts.map +1 -0
  27. package/dist/placeholder.js +10 -0
  28. package/dist/placeholder.js.map +1 -0
  29. package/dist/runtime.d.ts.map +1 -1
  30. package/dist/runtime.js +31 -10
  31. package/dist/runtime.js.map +1 -1
  32. package/dist/session-wire.d.ts +37 -13
  33. package/dist/session-wire.d.ts.map +1 -1
  34. package/dist/session-wire.js +74 -8
  35. package/dist/session-wire.js.map +1 -1
  36. package/dist/standard/caller.d.ts +9 -1
  37. package/dist/standard/caller.d.ts.map +1 -1
  38. package/dist/standard/caller.js +14 -4
  39. package/dist/standard/caller.js.map +1 -1
  40. package/dist/standard/client.d.ts +13 -2
  41. package/dist/standard/client.d.ts.map +1 -1
  42. package/dist/standard/client.js +27 -6
  43. package/dist/standard/client.js.map +1 -1
  44. package/dist/standard/delegated.d.ts +6 -0
  45. package/dist/standard/delegated.d.ts.map +1 -1
  46. package/dist/standard/delegated.js +10 -1
  47. package/dist/standard/delegated.js.map +1 -1
  48. package/dist/standard/from-agent.d.ts +2 -0
  49. package/dist/standard/from-agent.d.ts.map +1 -1
  50. package/dist/standard/from-agent.js +16 -0
  51. package/dist/standard/from-agent.js.map +1 -1
  52. package/dist/standard/index.d.ts +2 -0
  53. package/dist/standard/index.d.ts.map +1 -1
  54. package/dist/standard/index.js +4 -0
  55. package/dist/standard/index.js.map +1 -1
  56. package/dist/standard/mount.d.ts +7 -0
  57. package/dist/standard/mount.d.ts.map +1 -1
  58. package/dist/standard/mount.js +3 -3
  59. package/dist/standard/mount.js.map +1 -1
  60. package/dist/standard/outbound-fetch.d.ts +51 -0
  61. package/dist/standard/outbound-fetch.d.ts.map +1 -0
  62. package/dist/standard/outbound-fetch.js +152 -0
  63. package/dist/standard/outbound-fetch.js.map +1 -0
  64. package/dist/standard/push-url-policy.d.ts +34 -0
  65. package/dist/standard/push-url-policy.d.ts.map +1 -0
  66. package/dist/standard/push-url-policy.js +218 -0
  67. package/dist/standard/push-url-policy.js.map +1 -0
  68. package/dist/standard/server.d.ts +20 -0
  69. package/dist/standard/server.d.ts.map +1 -1
  70. package/dist/standard/server.js +87 -9
  71. package/dist/standard/server.js.map +1 -1
  72. package/dist/subject-hop.d.ts +24 -0
  73. package/dist/subject-hop.d.ts.map +1 -1
  74. package/dist/subject-hop.js +58 -12
  75. package/dist/subject-hop.js.map +1 -1
  76. package/dist/types.d.ts +27 -2
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js.map +1 -1
  79. package/dist/wire-verify.d.ts.map +1 -1
  80. package/dist/wire-verify.js +4 -0
  81. package/dist/wire-verify.js.map +1 -1
  82. package/package.json +5 -5
@@ -1,3 +1,4 @@
1
+ import type { Hex } from 'viem';
1
2
  import type { A2aMessage } from './types.js';
2
3
  /** PAY-A2A-1 — a skill declares its price in its descriptor. `price.amount` is atomic units (string for
3
4
  * wire-safety); `asset`/`payee` are addresses. `rail` is the registered rail name (e.g. 'x402'). */
@@ -15,6 +16,8 @@ export type X402PaymentStatus = 'payment-required' | 'payment-submitted' | 'paym
15
16
  * settlement receipts). Granular status lives here, never in the A2A TaskState machine. */
16
17
  export interface X402PaymentMetadata {
17
18
  'x402.payment.status': X402PaymentStatus;
19
+ /** Spec 445 decision 8 — exactly what the parked task waits for (amount, asset, payee, a per-park reference). */
20
+ 'x402.payment.awaited'?: AwaitedPaymentV1;
18
21
  'x402.payment.required'?: unknown;
19
22
  'x402.payment.payload'?: unknown;
20
23
  'x402.payment.receipts'?: unknown[];
@@ -32,6 +35,57 @@ export interface PaymentGateDecision {
32
35
  /** When satisfied via a live entitlement: the consumption ref (the app consumed one use — no tx). */
33
36
  entitlementConsumption?: unknown;
34
37
  }
38
+ /** Spec 445 §9 decision 8 — WHAT A PAYMENT-PARKED TASK WAITS FOR, recorded on the task when it parks: the price the
39
+ * skill declared (amount in atomic units, asset, payee, rail) and a random per-park `reference` the payer quotes. A
40
+ * settlement resumes THIS task only if it names exactly these, and only once. */
41
+ export interface AwaitedPaymentV1 {
42
+ rail: string;
43
+ amount: string;
44
+ asset: string;
45
+ payee: string;
46
+ /** 32 random bytes minted at the park. A settlement for an earlier park, or another task's, does not name it. */
47
+ reference: Hex;
48
+ }
49
+ /** What a payer presents to resume a parked task: the terms it paid against, and the rail's proof (opaque to a2a —
50
+ * the gate's `verifySettlement` reads it). */
51
+ export interface PaymentSettlementV1 {
52
+ reference: Hex;
53
+ amount: string;
54
+ asset: string;
55
+ payee: string;
56
+ proof: unknown;
57
+ }
58
+ /** The gate's verdict on a settlement proof. `settled` is believed only with a `settlementId` (the rail's own unique
59
+ * id for the payment — a tx hash, a facilitator receipt id; consumed once) and `paid` (what the PROOF shows was paid,
60
+ * compared again with what the task awaits). */
61
+ export interface SettlementVerdict {
62
+ settled: boolean;
63
+ settlementId?: string;
64
+ paid?: {
65
+ amount: string;
66
+ asset: string;
67
+ payee: string;
68
+ reference: Hex;
69
+ };
70
+ receiptRef?: unknown;
71
+ }
72
+ /** Exact terms: the same amount (as an integer of atomic units), the same asset and payee (case-insensitive), the same
73
+ * reference. Anything unreadable is "not the same". */
74
+ export declare function samePaymentTerms(a: {
75
+ amount: string;
76
+ asset: string;
77
+ payee: string;
78
+ reference?: string;
79
+ }, b: {
80
+ amount: string;
81
+ asset: string;
82
+ payee: string;
83
+ reference?: string;
84
+ }, opts?: {
85
+ reference: boolean;
86
+ }): boolean;
87
+ /** The awaited payment for a skill's declared price, with a fresh per-park reference. */
88
+ export declare function awaitedPaymentFor(payment: SkillPayment): AwaitedPaymentV1;
35
89
  /** The injected gate. The app wires the payments x402 rail + entitlement store. a2a only asks:
36
90
  * "is this priced request paid?" and acts on the verdict. X402-D8: the gate decides ONE lane —
37
91
  * a standing grant, a LIVE entitlement (`entitlementRef`, consume one use, no settlement), or a
@@ -46,6 +100,15 @@ export interface PaymentGate {
46
100
  * The app resolves + consumes it via `@agenticprimitives/payments` entitlement/voucher. */
47
101
  entitlementRef?: unknown;
48
102
  }): Promise<PaymentGateDecision>;
103
+ /** Spec 445 decision 8 — the RESUME path: does `proof` show a settled payment of exactly `awaited`? Consulted by
104
+ * `A2aAgent.settlePayment` only after the presented terms already match what the task awaits. Absent ⇒ no parked
105
+ * task can be resumed here (the settlement is refused; the task stays parked). Throwing ⇒ not settled. */
106
+ verifySettlement?(args: {
107
+ taskId: Hex;
108
+ skill: string;
109
+ awaited: AwaitedPaymentV1;
110
+ proof: unknown;
111
+ }): Promise<SettlementVerdict>;
49
112
  }
50
113
  /** PAY-A2A-4 — the agent-card extension a priced agent advertises in `capabilities.extensions[]`.
51
114
  * Clients activate via the `X-A2A-Extensions` header. */
@@ -61,12 +124,14 @@ export declare function buildPaymentRequiredMetadata(required: unknown): X402Pay
61
124
  export declare function buildPaymentSettledMetadata(receipts: unknown[]): X402PaymentMetadata;
62
125
  /**
63
126
  * PAY-A2A-3 — the payment middleware. Run BEFORE `handler.handle`. Returns:
64
- * - `{ proceed: true, receiptRef? }` when the skill is free, or paid (the gate settled it), or no gate
65
- * is wired — the handler then runs.
127
+ * - `{ proceed: true, receiptRef? }` when the skill is free, or paid (the gate settled it) — the handler
128
+ * then runs.
66
129
  * - `{ proceed: false, parkMetadata }` when payment is required — the caller parks the task
67
130
  * `input-required` and attaches `parkMetadata` (`x402.payment.*`), WITHOUT running the handler.
68
131
  *
69
- * Fail-closed: a priced skill with a gate that returns not-satisfied NEVER reaches the handler.
132
+ * Fail-closed: a priced skill NEVER reaches the handler unless a gate said it is paid. A priced skill with
133
+ * NO gate wired is refused too (RUNB-6, spec 445 W0): "no rail" used to mean "free", and a priced handler
134
+ * returned by `resolveHandler` — which the construction guard cannot see — ran unpaid.
70
135
  */
71
136
  export declare function gateSkillPayment(args: {
72
137
  payment?: SkillPayment;
@@ -84,5 +149,6 @@ export declare function gateSkillPayment(args: {
84
149
  } | {
85
150
  proceed: false;
86
151
  parkMetadata: X402PaymentMetadata;
152
+ awaited: AwaitedPaymentV1;
87
153
  }>;
88
154
  //# sourceMappingURL=payment-gate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment-gate.d.ts","sourceRoot":"","sources":["../src/payment-gate.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;qGACqG;AACrG,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,iBAAiB,GACzB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,CAAC;AAErB;;4FAE4F;AAC5F,MAAM,WAAW,mBAAmB;IAClC,qBAAqB,E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AC3C,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gGAAgG;IAChG,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GAAG,OAAO,CACP;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,WAAW,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5F;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,YAAY,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CACnF,CAgBA"}
@@ -4,6 +4,33 @@
4
4
  // payment parks in the EXISTING `input-required` task state with `x402.payment.*` metadata — NO new
5
5
  // TaskState (PAY-A2A-2). Payment is MIDDLEWARE: skill handlers never see raw x402 wire objects, only
6
6
  // "payment satisfied" + a receipt ref (PAY-A2A-6).
7
+ /** Exact terms: the same amount (as an integer of atomic units), the same asset and payee (case-insensitive), the same
8
+ * reference. Anything unreadable is "not the same". */
9
+ export function samePaymentTerms(a, b, opts = { reference: true }) {
10
+ try {
11
+ if (typeof a.amount !== 'string' || typeof b.amount !== 'string' || !/^\d+$/.test(a.amount) || !/^\d+$/.test(b.amount))
12
+ return false;
13
+ if (BigInt(a.amount) !== BigInt(b.amount))
14
+ return false;
15
+ if (typeof a.asset !== 'string' || typeof b.asset !== 'string' || a.asset.toLowerCase() !== b.asset.toLowerCase())
16
+ return false;
17
+ if (typeof a.payee !== 'string' || typeof b.payee !== 'string' || a.payee.toLowerCase() !== b.payee.toLowerCase())
18
+ return false;
19
+ if (opts.reference && (typeof a.reference !== 'string' || typeof b.reference !== 'string' || a.reference.toLowerCase() !== b.reference.toLowerCase()))
20
+ return false;
21
+ return true;
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ /** The awaited payment for a skill's declared price, with a fresh per-park reference. */
28
+ export function awaitedPaymentFor(payment) {
29
+ const b = new Uint8Array(32);
30
+ globalThis.crypto.getRandomValues(b);
31
+ const reference = `0x${Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('')}`;
32
+ return { rail: payment.rail, amount: payment.price.amount, asset: payment.price.asset, payee: payment.payee, reference };
33
+ }
7
34
  /** PAY-A2A-4 — the agent-card extension a priced agent advertises in `capabilities.extensions[]`.
8
35
  * Clients activate via the `X-A2A-Extensions` header. */
9
36
  export const X402_EXTENSION_URI = 'https://github.com/google-a2a/a2a-x402/v0.1';
@@ -20,18 +47,22 @@ export function buildPaymentSettledMetadata(receipts) {
20
47
  }
21
48
  /**
22
49
  * PAY-A2A-3 — the payment middleware. Run BEFORE `handler.handle`. Returns:
23
- * - `{ proceed: true, receiptRef? }` when the skill is free, or paid (the gate settled it), or no gate
24
- * is wired — the handler then runs.
50
+ * - `{ proceed: true, receiptRef? }` when the skill is free, or paid (the gate settled it) — the handler
51
+ * then runs.
25
52
  * - `{ proceed: false, parkMetadata }` when payment is required — the caller parks the task
26
53
  * `input-required` and attaches `parkMetadata` (`x402.payment.*`), WITHOUT running the handler.
27
54
  *
28
- * Fail-closed: a priced skill with a gate that returns not-satisfied NEVER reaches the handler.
55
+ * Fail-closed: a priced skill NEVER reaches the handler unless a gate said it is paid. A priced skill with
56
+ * NO gate wired is refused too (RUNB-6, spec 445 W0): "no rail" used to mean "free", and a priced handler
57
+ * returned by `resolveHandler` — which the construction guard cannot see — ran unpaid.
29
58
  */
30
59
  export async function gateSkillPayment(args) {
31
60
  if (!args.payment)
32
61
  return { proceed: true }; // free skill
62
+ // Spec 445 decision 8 — a park records EXACTLY what it waits for, under a fresh reference.
63
+ const awaited = awaitedPaymentFor(args.payment);
33
64
  if (!args.gate)
34
- return { proceed: true }; // no rail wired (dev / unpriced deployment) — app opts in
65
+ return { proceed: false, awaited, parkMetadata: { ...buildPaymentRequiredMetadata({ error: 'payment-gate-unavailable', rail: args.payment.rail }), 'x402.payment.awaited': awaited } };
35
66
  const decision = await args.gate.check({
36
67
  skill: args.skill,
37
68
  payment: args.payment,
@@ -42,6 +73,6 @@ export async function gateSkillPayment(args) {
42
73
  if (decision.satisfied) {
43
74
  return { proceed: true, via: decision.via, receiptRef: decision.receiptRef, entitlementConsumption: decision.entitlementConsumption };
44
75
  }
45
- return { proceed: false, parkMetadata: buildPaymentRequiredMetadata(decision.required) };
76
+ return { proceed: false, awaited, parkMetadata: { ...buildPaymentRequiredMetadata(decision.required), 'x402.payment.awaited': awaited } };
46
77
  }
47
78
  //# sourceMappingURL=payment-gate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment-gate.js","sourceRoot":"","sources":["../src/payment-gate.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,0GAA0G;AAC1G,mGAAmG;AACnG,oGAAoG;AACpG,qGAAqG;AACrG,mDAAmD;AA4DnD;0DAC0D;AAC1D,MAAM,CAAC,MAAM,kBAAkB,GAAG,6CAA6C,CAAC;AAChF,MAAM,UAAU,sBAAsB;IACpC,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,oCAAoC,EAAE,CAAC;AACzG,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,4BAA4B,CAAC,QAAiB;IAC5D,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,CAAC;AAC1F,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,2BAA2B,CAAC,QAAmB;IAC7D,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,CAAC;AAC3F,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAQtC;IAIC,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE,OAAO,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C,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,sBAAsB,EAAE,OAAO,EAAE,EAAE,CAAC;IACvM,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QACrC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,cAAc,EAAE,IAAI,CAAC,cAAc;KACpC,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QACvB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,sBAAsB,EAAE,QAAQ,CAAC,sBAAsB,EAAE,CAAC;IACxI,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,GAAG,4BAA4B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,sBAAsB,EAAE,OAAO,EAAE,EAAE,CAAC;AAC5I,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Address } from 'viem';
2
+ /** True for the zero address, `0x…01` and every address up to `0x…0a`; also for anything that is not an address
3
+ * at all (fail closed: a value that cannot be read as a delegate is not one). */
4
+ export declare function isPlaceholderAddress(a: Address | string | null | undefined): boolean;
5
+ //# sourceMappingURL=placeholder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholder.d.ts","sourceRoot":"","sources":["../src/placeholder.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAKpC;kFACkF;AAClF,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAGpF"}
@@ -0,0 +1,10 @@
1
+ /** Highest numeric value treated as a placeholder: `0x…01` and the precompiles up to `0x…0a`. */
2
+ const PLACEHOLDER_MAX = 0x0an;
3
+ /** True for the zero address, `0x…01` and every address up to `0x…0a`; also for anything that is not an address
4
+ * at all (fail closed: a value that cannot be read as a delegate is not one). */
5
+ export function isPlaceholderAddress(a) {
6
+ if (typeof a !== 'string' || !/^0x[0-9a-fA-F]{40}$/.test(a))
7
+ return true;
8
+ return BigInt(a) <= PLACEHOLDER_MAX;
9
+ }
10
+ //# sourceMappingURL=placeholder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placeholder.js","sourceRoot":"","sources":["../src/placeholder.ts"],"names":[],"mappings":"AAQA,iGAAiG;AACjG,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;kFACkF;AAClF,MAAM,UAAU,oBAAoB,CAAC,CAAsC;IACzE,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACzE,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC;AACtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACzG,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAkC,KAAK,YAAY,EAAE,KAAK,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAC5H,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,mBA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AS,EAAE,CAAA;CAAE,CAAC,CAoItD;AAQD,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/dist/runtime.js CHANGED
@@ -6,7 +6,7 @@
6
6
  import { canTaskTransition, isHandoffAllowed } from '@agenticprimitives/fulfillment';
7
7
  import { isTerminal } from './types.js';
8
8
  import { AuthRequired, HandoffRequested } from './skill-handler.js';
9
- import { gateSkillPayment } from './payment-gate.js';
9
+ import { gateSkillPayment, samePaymentTerms } from './payment-gate.js';
10
10
  /** Build a fresh `submitted` task record from a verified inbound message + grant. */
11
11
  export function newTaskRecord(args) {
12
12
  return {
@@ -52,11 +52,13 @@ export function applyTransition(record, to, opts = { now: 0 }) {
52
52
  }
53
53
  export async function dispatchTask(record, registry, makeContext, now, opts) {
54
54
  const events = [];
55
- if (record.task.state !== 'submitted') {
55
+ // Spec 445 decision 8 — a payment-parked task RESUMES here: `settlePayment` moved it input-required → working with a
56
+ // verified settlement for exactly what it awaited. Any other `working` record is not ours to run.
57
+ const resumingPaid = record.task.state === 'working' && isSettledForPark(record);
58
+ if (record.task.state !== 'submitted' && !resumingPaid) {
56
59
  return { record, events };
57
60
  }
58
61
  const handler = registry.get(record.skill);
59
- console.log('[a2a dispatchTask]', record.skill, handler ? 'handler found' : 'NO HANDLER');
60
62
  if (!handler) {
61
63
  const rejected = applyTransition(record, 'rejected', { now, error: `unknown skill: ${record.skill}` });
62
64
  if (rejected.ok) {
@@ -65,18 +67,28 @@ export async function dispatchTask(record, registry, makeContext, now, opts) {
65
67
  }
66
68
  return { record, events };
67
69
  }
68
- const working = applyTransition(record, 'working', { now });
69
- if (!working.ok)
70
- return { record, events };
71
- let cur = working.record;
72
- events.push(working.event);
70
+ let cur;
71
+ if (resumingPaid) {
72
+ cur = record;
73
+ }
74
+ else {
75
+ const working = applyTransition(record, 'working', { now });
76
+ if (!working.ok)
77
+ return { record, events };
78
+ cur = working.record;
79
+ events.push(working.event);
80
+ }
73
81
  const base = makeContext(cur);
74
82
  // A2A-5 (seam audit): a PRICED skill is gated BEFORE its handler runs. Previously the gate was declared
75
83
  // + exported but NEVER invoked, so priced skills executed for free. gateSkillPayment now runs here; on
76
84
  // not-satisfied the task parks `input-required` (a legal working→input-required transition) and the
77
85
  // handler is NOT run (fail-closed). A free skill (no `payment`) proceeds unchanged. The construction
78
86
  // guard in createA2aAgent additionally forbids registering a priced handler with no gate wired.
79
- if (handler.payment) {
87
+ // Spec 445 decision 8 — PAID ALREADY: the task carries a verified settlement for its own park whose terms are the
88
+ // skill's price now. It runs ungated (the settlement was consumed once, in `settlePayment`). A price that changed
89
+ // since the park is gated afresh — the settlement paid for the old terms, not these.
90
+ const paidForThisPrice = !!handler.payment && isSettledForPark(cur) && samePaymentTerms({ amount: handler.payment.price.amount, asset: handler.payment.price.asset, payee: handler.payment.payee }, cur.awaitingPayment, { reference: false }) && handler.payment.rail === cur.awaitingPayment.rail;
91
+ if (handler.payment && !paidForThisPrice) {
80
92
  const gated = await gateSkillPayment({
81
93
  payment: handler.payment,
82
94
  gate: opts?.paymentGate,
@@ -89,7 +101,11 @@ export async function dispatchTask(record, registry, makeContext, now, opts) {
89
101
  const parked = applyTransition(cur, 'input-required', { now });
90
102
  if (parked.ok) {
91
103
  events.push(parked.event);
92
- return { record: parked.record, events };
104
+ // RUNB-6 — what to pay is KEPT on the record (it was computed and dropped, so a parked client could
105
+ // not learn the price).
106
+ // Spec 445 decision 8 — and EXACTLY what it waits for, under a fresh reference; an older settlement is void.
107
+ const { paymentSettlement: _void, ...rest } = parked.record;
108
+ return { record: { ...rest, payment: gated.parkMetadata, awaitingPayment: gated.awaited }, events };
93
109
  }
94
110
  return { record: cur, events };
95
111
  }
@@ -175,5 +191,10 @@ export async function dispatchTask(record, registry, makeContext, now, opts) {
175
191
  events.push(t.event);
176
192
  return { record: cur, events };
177
193
  }
194
+ /** The task carries a settlement for its own (latest) park. */
195
+ function isSettledForPark(r) {
196
+ return !!r.paymentSettlement && !!r.awaitingPayment
197
+ && r.paymentSettlement.reference.toLowerCase() === r.awaitingPayment.reference.toLowerCase();
198
+ }
178
199
  export { isTerminal };
179
200
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,wGAAwG;AACxG,wGAAwG;AACxG,0GAA0G;AAC1G,4GAA4G;AAC5G,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAsB,MAAM,gCAAgC,CAAC;AAIzG,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAA0D,MAAM,oBAAoB,CAAC;AAC5H,OAAO,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAC;AAEvE,qFAAqF;AACrF,MAAM,UAAU,aAAa,CAAC,IAc7B;IACC,OAAO;QACL,IAAI,EAAE;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,WAAW;YAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,YAAY,EAAE,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,EAAE;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,CAAC;YAChC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC5C;QACD,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;QACvB,SAAS,EAAE,EAAE;QACb,GAAG,EAAE,CAAC;QACN,SAAS,EAAE,IAAI,CAAC,GAAG;KACpB,CAAC;AACJ,CAAC;AAMD;+FAC+F;AAC/F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,EAAE,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE;QAC9E,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACb,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC;AAED,+DAA+D;AAC/D,SAAS,gBAAgB,CAAC,CAAa;IACrC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe;WAC9C,CAAC,CAAC,iBAAiB,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;AACjG,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -27,10 +27,33 @@ export declare function parseSessionWrappedSignature(signature: string): {
27
27
  } | null;
28
28
  export declare function wireToDelegation(w: DelegationWireV1): Delegation;
29
29
  export declare function delegationToWire(d: Delegation): DelegationWireV1;
30
+ /** The enforcer addresses a session wire's caveats are read by (this deployment's). All three are required:
31
+ * a verifier that cannot read the target caveat cannot tell which host the wire was minted for. */
32
+ export interface SessionWireEnforcers {
33
+ timestamp: string;
34
+ allowedMethods: string;
35
+ allowedTargets: string;
36
+ }
37
+ /** RUNB-17 (spec 445 §9 decision 8) — a caveat beyond the three this verifier reads, which the verifier RECOGNISES
38
+ * because it enforces it: `check` runs on the caveat's terms and returns null when it holds, else why not. A caveat
39
+ * whose enforcer is neither one of the three nor listed here is refused — never "permissive by omission". */
40
+ export interface SessionWireCaveatCheck {
41
+ enforcer: string;
42
+ check: (terms: Hex, ctx: {
43
+ nowSec: number;
44
+ target: string;
45
+ skill?: string;
46
+ }) => string | null;
47
+ }
30
48
  /**
31
- * Shape check for a session wire (at ceremony store time AND at every gate hit): timestamp-bounded, a
32
- * pinned allowedMethods set that never carries the any-skill sentinel and — when `skill` is given — names
33
- * that skill's selector.
49
+ * Shape check for a session wire (at ceremony store time AND at every gate hit): timestamp-bounded, an
50
+ * allowedTargets caveat that names `target` — THIS host's own agent — and a pinned allowedMethods set that
51
+ * never carries the any-skill sentinel and, when `skill` is given, names that skill's selector.
52
+ *
53
+ * `target` is REQUIRED (RUN-9, audit 2026-11-10). The custodian signs a wire for one receiving agent; the
54
+ * verifier is the only party that knows which agent it is, so it says so, and the wire must agree. A wire
55
+ * with no allowedTargets caveat is refused: "minted for nowhere in particular" was being read as "valid
56
+ * everywhere". There is no default and no wildcard — a verifier with no identity to offer refuses every wire.
34
57
  *
35
58
  * `skill` should be passed wherever the request names one: a wire minted for one rail must not authorize
36
59
  * another. It is omitted only on the read/control path (`tasks/get`, `tasks/cancel`,
@@ -38,11 +61,10 @@ export declare function delegationToWire(d: Delegation): DelegationWireV1;
38
61
  * narrow rather than lax — the wire must still be pinned, live, ERC-1271-valid and unrevoked, and the task
39
62
  * runtime independently requires the caller to BE a party to the task.
40
63
  */
41
- export declare function checkSessionWireShape(wire: DelegationWireV1, enforcers: {
42
- timestamp: string;
43
- allowedMethods: string;
44
- }, nowSec: number, opts?: {
64
+ export declare function checkSessionWireShape(wire: DelegationWireV1, enforcers: SessionWireEnforcers, nowSec: number, opts: {
65
+ target: string;
45
66
  skill?: string;
67
+ recognisedCaveats?: readonly SessionWireCaveatCheck[];
46
68
  }): string | null;
47
69
  /**
48
70
  * Verify a session-wrapped signature for `signer` over `digest`, fail-closed on every leg. The on-chain
@@ -53,16 +75,18 @@ export declare function verifySessionWrappedSignature(args: {
53
75
  signer: Address;
54
76
  digest: Hex;
55
77
  signature: string;
56
- enforcers: {
57
- timestamp: string;
58
- allowedMethods: string;
59
- };
78
+ enforcers: SessionWireEnforcers;
79
+ /** THIS host's own agent — the address the wire's allowedTargets caveat must name (RUN-9). Required: a
80
+ * wire minted for another host, or for no host, is refused. Never taken from the request's own claims. */
81
+ target: Address;
60
82
  verifyDelegationSig: (d: Delegation) => Promise<boolean>;
61
83
  isRevoked: (d: Delegation) => Promise<boolean>;
62
84
  /** The skill the inbound message requests. Omit ONLY on the read/control path. */
63
85
  skill?: string;
64
86
  /** Milliseconds (Date.now() shape); injected for determinism. */
65
87
  now?: number;
88
+ /** RUNB-17 — caveats beyond timestamp / allowedMethods / allowedTargets this verifier enforces. Any other is refused. */
89
+ recognisedCaveats?: readonly SessionWireCaveatCheck[];
66
90
  }): Promise<boolean>;
67
91
  /**
68
92
  * Verify a session-wrapped signature over a digest THAT WAS SIGNED AT A KNOWN TIME — a release, an attestation, anything
@@ -70,8 +94,8 @@ export declare function verifySessionWrappedSignature(args: {
70
94
  * W5 / spec 413). Every leg of `verifySessionWrappedSignature` except two:
71
95
  * • the timestamp window is judged AT `at` (when the thing was signed), not now — back-dating widens nothing, because
72
96
  * the leaf must still verify ERC-1271 against the signer and the key must still recover;
73
- * • no skill selector is required: a message gate asks "may this key send THIS skill"; a signed artifact asks only
74
- * "did the signer's agent sign it while its leaf was live".
97
+ * • no skill selector and no target is required: a message gate asks "may this key send THIS skill, HERE"; a signed
98
+ * artifact is not presented at a host — it asks only "did the signer's agent sign it while its leaf was live".
75
99
  * Revocation is read NOW: a leaf the custodian revoked stops vouching for anything it ever signed.
76
100
  * Returns null when every leg holds, else the leg that failed, in words. Fail-closed on a chain-read failure.
77
101
  */
@@ -1 +1 @@
1
- {"version":3,"file":"session-wire.d.ts","sourceRoot":"","sources":["../src/session-wire.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAmD,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAC/F,OAAO,EAAmD,KAAK,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGjH,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,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IG;AACH,wBAAsB,6BAA6B,CAAC,IAAI,EAAE;IACxD,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,oBAAoB,CAAC;IAChC;+GAC2G;IAC3G,MAAM,EAAE,OAAO,CAAC;IAChB,mBAAmB,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzD,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yHAAyH;IACzH,iBAAiB,CAAC,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACvD,GAAG,OAAO,CAAC,OAAO,CAAC,CAuBnB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,EAAE;IACvD,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,EAAE,EAAE,MAAM,CAAC;IACX,mBAAmB,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzD,SAAS,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBzB;AAED,qGAAqG;AACrG,eAAO,MAAM,eAAe,SAAU,OAAO,KAAG,GAAuD,CAAC"}
@@ -13,7 +13,9 @@
13
13
  // ON THE WIRE such a signature is the SESSION-WRAPPED form: `0x51` (a type byte no on-chain validator
14
14
  // accepts — it fails closed anywhere but a gate that understands it) followed by hex(utf8(JSON({ wire,
15
15
  // sig }))). A gate verifies it fail-closed PER MESSAGE: delegator === the claimed signer; timestamp window
16
- // live; a pinned selector set that names the requested skill and never A2A_ANY_SKILL; the raw ECDSA sig
16
+ // live; an allowedTargets caveat that names THIS host's agent (RUN-9 — a wire minted for one host is not a
17
+ // credential at another, and a wire that names no target is a credential nowhere);
18
+ // a pinned selector set that names the requested skill and never A2A_ANY_SKILL; the raw ECDSA sig
17
19
  // recovers to the wire's delegate; the wire's own signature ERC-1271-verifies against the delegator; AND
18
20
  // the wire is unrevoked on chain — so a custodian's revocation kills the authority at every gate, now.
19
21
  //
@@ -25,8 +27,9 @@
25
27
  // contracts a stewardship wire must pin. `org-wire.ts`'s `hasStewardshipShape` is a positive identity
26
28
  // test no generic layer can express, and it does not move.
27
29
  import { hashMessage, keccak256, recoverAddress, toBytes } from 'viem';
28
- import { decodeAllowedMethodsTerms, decodeTimestampTerms } from '@agenticprimitives/delegation';
30
+ import { decodeAllowedMethodsTerms, decodeAllowedTargetsTerms, decodeTimestampTerms } from '@agenticprimitives/delegation';
29
31
  import { A2A_ANY_SKILL, skillSelector } from './grant.js';
32
+ import { isPlaceholderAddress } from './placeholder.js';
30
33
  /** Signature type byte for the session-wrapped form. Unknown to AgentAccount `_validateSig` (fails closed
31
34
  * on chain) and to every other verifier — only a gate that calls `verifySessionWrappedSignature` accepts
32
35
  * it, and only after full verification. */
@@ -75,10 +78,16 @@ export function delegationToWire(d) {
75
78
  salt: d.salt.toString(), signature: d.signature,
76
79
  };
77
80
  }
81
+ const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
78
82
  /**
79
- * Shape check for a session wire (at ceremony store time AND at every gate hit): timestamp-bounded, a
80
- * pinned allowedMethods set that never carries the any-skill sentinel and — when `skill` is given — names
81
- * that skill's selector.
83
+ * Shape check for a session wire (at ceremony store time AND at every gate hit): timestamp-bounded, an
84
+ * allowedTargets caveat that names `target` — THIS host's own agent — and a pinned allowedMethods set that
85
+ * never carries the any-skill sentinel and, when `skill` is given, names that skill's selector.
86
+ *
87
+ * `target` is REQUIRED (RUN-9, audit 2026-11-10). The custodian signs a wire for one receiving agent; the
88
+ * verifier is the only party that knows which agent it is, so it says so, and the wire must agree. A wire
89
+ * with no allowedTargets caveat is refused: "minted for nowhere in particular" was being read as "valid
90
+ * everywhere". There is no default and no wildcard — a verifier with no identity to offer refuses every wire.
82
91
  *
83
92
  * `skill` should be passed wherever the request names one: a wire minted for one rail must not authorize
84
93
  * another. It is omitted only on the read/control path (`tasks/get`, `tasks/cancel`,
@@ -88,6 +97,32 @@ export function delegationToWire(d) {
88
97
  */
89
98
  export function checkSessionWireShape(wire, enforcers, nowSec, opts) {
90
99
  const byEnforcer = (addr) => (wire.caveats ?? []).find((c) => (c.enforcer ?? '').toLowerCase() === addr.toLowerCase());
100
+ // Spec 445 decision 8 — the delegate is a real key, never a placeholder (`0x…01`, the zero address).
101
+ if (isPlaceholderAddress(wire.delegate))
102
+ return 'session wire delegate is a placeholder address';
103
+ // RUNB-17 (spec 445 §9 decision 8) — EVERY caveat is read, or the wire is refused. A restriction the delegator signed
104
+ // in (a value limit, a digest binding, a vault-key scope…) that this verifier does not enforce would otherwise be
105
+ // ignored, and a delegation written for a narrower purpose would pass as a session wire. Each enforcer appears once:
106
+ // a second caveat of one kind would be a restriction the lookup below never reads.
107
+ if (!Array.isArray(wire.caveats))
108
+ return 'session wire carries no caveats';
109
+ const known = new Map([
110
+ [String(enforcers.timestamp ?? '').toLowerCase(), null],
111
+ [String(enforcers.allowedMethods ?? '').toLowerCase(), null],
112
+ [String(enforcers.allowedTargets ?? '').toLowerCase(), null],
113
+ ]);
114
+ for (const r of opts?.recognisedCaveats ?? [])
115
+ if (typeof r?.enforcer === 'string' && ADDRESS.test(r.enforcer))
116
+ known.set(r.enforcer.toLowerCase(), r);
117
+ const seenEnforcers = new Set();
118
+ for (const c of wire.caveats) {
119
+ const e = String(c?.enforcer ?? '').toLowerCase();
120
+ if (!ADDRESS.test(e) || !known.has(e))
121
+ return `session wire carries a caveat this verifier does not recognise (${e || 'no enforcer'}) — refused, never ignored`;
122
+ if (seenEnforcers.has(e))
123
+ return `session wire carries two caveats for one enforcer (${e})`;
124
+ seenEnforcers.add(e);
125
+ }
91
126
  const tsCav = byEnforcer(enforcers.timestamp);
92
127
  if (!tsCav?.terms)
93
128
  return 'session wire must be timestamp-bounded';
@@ -100,6 +135,22 @@ export function checkSessionWireShape(wire, enforcers, nowSec, opts) {
100
135
  catch {
101
136
  return 'session wire timestamp terms undecodable';
102
137
  }
138
+ // THE TARGET (RUN-9) — checked here, at the point of use, against the identity the verifier supplied.
139
+ if (typeof opts?.target !== 'string' || !ADDRESS.test(opts.target))
140
+ return 'the verifier named no target — a session wire is checked against this host\'s own agent';
141
+ if (typeof enforcers.allowedTargets !== 'string' || !ADDRESS.test(enforcers.allowedTargets))
142
+ return 'the verifier has no allowedTargets enforcer — the wire\'s target cannot be read';
143
+ const atCav = byEnforcer(enforcers.allowedTargets);
144
+ if (!atCav?.terms)
145
+ return 'session wire must carry an allowedTargets caveat naming this host';
146
+ try {
147
+ const targets = decodeAllowedTargetsTerms(atCav.terms).map((t) => t.toLowerCase());
148
+ if (!targets.includes(opts.target.toLowerCase()))
149
+ return 'session wire was minted for another target, not this host';
150
+ }
151
+ catch {
152
+ return 'session wire allowedTargets terms undecodable';
153
+ }
103
154
  const amCav = byEnforcer(enforcers.allowedMethods);
104
155
  if (!amCav?.terms)
105
156
  return 'session wire must carry an allowedMethods caveat';
@@ -120,6 +171,21 @@ export function checkSessionWireShape(wire, enforcers, nowSec, opts) {
120
171
  catch {
121
172
  return 'session wire allowedMethods terms undecodable';
122
173
  }
174
+ // RUNB-17 — every recognised further caveat is ENFORCED, not merely allowed.
175
+ for (const c of wire.caveats) {
176
+ const r = known.get(String(c.enforcer).toLowerCase());
177
+ if (!r)
178
+ continue;
179
+ let why;
180
+ try {
181
+ why = r.check(c.terms, { nowSec, target: opts.target, ...(opts.skill ? { skill: opts.skill } : {}) });
182
+ }
183
+ catch (e) {
184
+ why = `caveat ${r.enforcer} could not be checked: ${e instanceof Error ? e.message : String(e)}`;
185
+ }
186
+ if (why !== null)
187
+ return `session wire caveat ${r.enforcer} does not hold: ${why}`;
188
+ }
123
189
  return null;
124
190
  }
125
191
  /**
@@ -134,7 +200,7 @@ export async function verifySessionWrappedSignature(args) {
134
200
  const { wire, sig } = parsed;
135
201
  if (wire.delegator.toLowerCase() !== args.signer.toLowerCase())
136
202
  return false;
137
- const shapeOpts = args.skill ? { skill: args.skill } : undefined;
203
+ const shapeOpts = { target: args.target, ...(args.skill ? { skill: args.skill } : {}), ...(args.recognisedCaveats ? { recognisedCaveats: args.recognisedCaveats } : {}) };
138
204
  if (checkSessionWireShape(wire, args.enforcers, Math.floor((args.now ?? Date.now()) / 1000), shapeOpts) !== null)
139
205
  return false;
140
206
  // The raw sig must recover to the wire's delegate (the KMS session key). Accept both raw-digest and
@@ -171,8 +237,8 @@ export async function verifySessionWrappedSignature(args) {
171
237
  * W5 / spec 413). Every leg of `verifySessionWrappedSignature` except two:
172
238
  * • the timestamp window is judged AT `at` (when the thing was signed), not now — back-dating widens nothing, because
173
239
  * the leaf must still verify ERC-1271 against the signer and the key must still recover;
174
- * • no skill selector is required: a message gate asks "may this key send THIS skill"; a signed artifact asks only
175
- * "did the signer's agent sign it while its leaf was live".
240
+ * • no skill selector and no target is required: a message gate asks "may this key send THIS skill, HERE"; a signed
241
+ * artifact is not presented at a host — it asks only "did the signer's agent sign it while its leaf was live".
176
242
  * Revocation is read NOW: a leaf the custodian revoked stops vouching for anything it ever signed.
177
243
  * Returns null when every leg holds, else the leg that failed, in words. Fail-closed on a chain-read failure.
178
244
  */