@agenticprimitives/agent-profile 1.0.0-alpha.22 → 1.0.0-alpha.23

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 (85) hide show
  1. package/README.md +54 -6
  2. package/dist/a2a/binding.d.ts +99 -0
  3. package/dist/a2a/binding.d.ts.map +1 -0
  4. package/dist/a2a/binding.js +142 -0
  5. package/dist/a2a/binding.js.map +1 -0
  6. package/dist/a2a/canonical.d.ts +31 -0
  7. package/dist/a2a/canonical.d.ts.map +1 -0
  8. package/dist/a2a/canonical.js +43 -0
  9. package/dist/a2a/canonical.js.map +1 -0
  10. package/dist/a2a/field-binding.d.ts +125 -0
  11. package/dist/a2a/field-binding.d.ts.map +1 -0
  12. package/dist/a2a/field-binding.js +242 -0
  13. package/dist/a2a/field-binding.js.map +1 -0
  14. package/dist/a2a/import.d.ts +39 -0
  15. package/dist/a2a/import.d.ts.map +1 -0
  16. package/dist/a2a/import.js +134 -0
  17. package/dist/a2a/import.js.map +1 -0
  18. package/dist/a2a/index.d.ts +13 -0
  19. package/dist/a2a/index.d.ts.map +1 -0
  20. package/dist/a2a/index.js +24 -0
  21. package/dist/a2a/index.js.map +1 -0
  22. package/dist/a2a/jws.d.ts +76 -0
  23. package/dist/a2a/jws.d.ts.map +1 -0
  24. package/dist/a2a/jws.js +186 -0
  25. package/dist/a2a/jws.js.map +1 -0
  26. package/dist/a2a/playbook-binding.d.ts +29 -0
  27. package/dist/a2a/playbook-binding.d.ts.map +1 -0
  28. package/dist/a2a/playbook-binding.js +65 -0
  29. package/dist/a2a/playbook-binding.js.map +1 -0
  30. package/dist/a2a/pointer.d.ts +13 -0
  31. package/dist/a2a/pointer.d.ts.map +1 -0
  32. package/dist/a2a/pointer.js +78 -0
  33. package/dist/a2a/pointer.js.map +1 -0
  34. package/dist/a2a/release.d.ts +77 -0
  35. package/dist/a2a/release.d.ts.map +1 -0
  36. package/dist/a2a/release.js +197 -0
  37. package/dist/a2a/release.js.map +1 -0
  38. package/dist/a2a/types.d.ts +312 -0
  39. package/dist/a2a/types.d.ts.map +1 -0
  40. package/dist/a2a/types.js +32 -0
  41. package/dist/a2a/types.js.map +1 -0
  42. package/dist/a2a/validation.d.ts +81 -0
  43. package/dist/a2a/validation.d.ts.map +1 -0
  44. package/dist/a2a/validation.js +477 -0
  45. package/dist/a2a/validation.js.map +1 -0
  46. package/dist/calls.d.ts +12 -0
  47. package/dist/calls.d.ts.map +1 -1
  48. package/dist/calls.js +16 -0
  49. package/dist/calls.js.map +1 -1
  50. package/dist/card.d.ts +12 -6
  51. package/dist/card.d.ts.map +1 -1
  52. package/dist/card.js +12 -6
  53. package/dist/card.js.map +1 -1
  54. package/dist/client.d.ts +4 -4
  55. package/dist/client.d.ts.map +1 -1
  56. package/dist/client.js +20 -2
  57. package/dist/client.js.map +1 -1
  58. package/dist/constants.d.ts +23 -1
  59. package/dist/constants.d.ts.map +1 -1
  60. package/dist/constants.js +30 -1
  61. package/dist/constants.js.map +1 -1
  62. package/dist/derived-type.d.ts +14 -0
  63. package/dist/derived-type.d.ts.map +1 -0
  64. package/dist/derived-type.js +56 -0
  65. package/dist/derived-type.js.map +1 -0
  66. package/dist/distribution.d.ts +32 -0
  67. package/dist/distribution.d.ts.map +1 -0
  68. package/dist/distribution.js +167 -0
  69. package/dist/distribution.js.map +1 -0
  70. package/dist/errors.d.ts +6 -0
  71. package/dist/errors.d.ts.map +1 -1
  72. package/dist/errors.js +11 -0
  73. package/dist/errors.js.map +1 -1
  74. package/dist/index.d.ts +7 -5
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +12 -5
  77. package/dist/index.js.map +1 -1
  78. package/dist/profile.d.ts +4 -4
  79. package/dist/profile.d.ts.map +1 -1
  80. package/dist/profile.js +12 -1
  81. package/dist/profile.js.map +1 -1
  82. package/dist/types.d.ts +104 -7
  83. package/dist/types.d.ts.map +1 -1
  84. package/package.json +13 -6
  85. package/spec.md +5 -1
package/README.md CHANGED
@@ -4,14 +4,26 @@
4
4
 
5
5
  Part of [agenticprimitives](../../README.md) — the trust substrate for the agent economy: one canonical Smart Agent identity with custody, delegation, naming, credentials, and audit evidence designed as one system.
6
6
 
7
- Where [`agent-naming`](../agent-naming) maps names → addresses, this package maps addresses → typed profiles and optional endpoint-control proofs: the `AgentCard` schema, deterministic content hashing for on-chain anchoring, and CAIP-10 `nativeId` helpers for cross-registry back-links.
7
+ Where [`agent-naming`](../agent-naming) maps names → addresses, this package maps addresses → typed profiles and optional endpoint-control proofs: the `CanonicalAgentProfileV1` schema, deterministic content hashing for on-chain anchoring, and CAIP-10 `nativeId` helpers for cross-registry back-links. Since spec 347 it also owns the **A2A 1.0 Agent Card model** (`./a2a`) — a different object, see below.
8
8
 
9
9
  > **Layer:** Discover — a profile **facet** (not login — that is `connect-auth`; not canonical identity — that is `agent-account`).
10
- > **Canonical key:** the Smart Agent address the AgentCard describes.
10
+ > **Canonical key:** the Smart Agent address the profile describes.
11
+
12
+ ## Profile ≠ A2A card
13
+
14
+ | | `CanonicalAgentProfileV1` (root) | `A2AAgentCardV1` (`./a2a`) |
15
+ | --- | --- | --- |
16
+ | Answers | what is this agent, who operates it, what does it claim | what does THIS A2A server do and how do I talk to it |
17
+ | Shape | AP-native, discriminated on `type` | A2A 1.0 Agent Card (`supportedInterfaces`, `capabilities`, `skills`, `securitySchemes`, `signatures`) |
18
+ | Canonical bytes | sorted-key canonical JSON → keccak (`profileContentHash`, on-chain `metadata-hash`) | RFC 8785 JCS minus `signatures` → sha256 (`cardContentDigest`) |
19
+ | Proof | `SignedCanonicalProfileBundleV1` (ERC-1271 by the SA) | ES256 JWS (any A2A client verifies) **plus** `SmartAgentCardBindingV1` (EIP-712, ERC-1271 — AP verifiers) |
20
+
21
+ `AgentCard`, `SignedAgentCardBundleV1`, `hashAgentCard`, `buildSignedAgentCardBundle`, `verifySignedAgentCardBundle` still compile as **deprecated aliases** for one release ([spec 347 §0.3](../../specs/347-a2a-agent-card-and-projection-studio.md), [ADR-0062](../../docs/architecture/decisions/0062-agent-card-projection-publication-binding.md)).
11
22
 
12
23
  ## Use this when
13
24
 
14
- - You author or validate an `AgentCard` (person, org, service, treasury, MCP server, multisig).
25
+ - You author or validate a `CanonicalAgentProfileV1` (person, org, service, treasury, MCP server, multisig).
26
+ - You inherit, curate, validate, sign, release or import an **A2A Agent Card** (`./a2a`) with field-level provenance and a Smart Agent binding.
15
27
  - You need a deterministic `profileContentHash` for the on-chain `metadata-hash` anchor — so a tampered profile is detectable by anyone holding the hash.
16
28
  - You need CAIP-10 `nativeId` encode/decode (strict encode, permissive decode) as a portable back-link to the canonical SA ([ADR-0008](../../docs/architecture/decisions/0008-caip10-nativeid-record-predicate.md)).
17
29
  - You need endpoint-verification methods (DNS TXT, signed URL, HTTP challenge, verifiable presentation) — Phase 2+.
@@ -40,12 +52,12 @@ import {
40
52
  canonicalProfileJson,
41
53
  profileContentHash,
42
54
  buildCaip10Address,
43
- type AgentCard,
55
+ type CanonicalAgentProfileV1,
44
56
  } from '@agenticprimitives/agent-profile';
45
57
 
46
58
  const canonicalAddr = '0x0000000000000000000000000000000000000003' as const;
47
59
 
48
- const profile: AgentCard = {
60
+ const profile: CanonicalAgentProfileV1 = {
49
61
  type: 'person',
50
62
  displayName: 'Alice',
51
63
  };
@@ -59,6 +71,37 @@ const nativeId = buildCaip10Address({
59
71
  // Anchor hash + nativeId on chain via agent-naming records or profile resolver.
60
72
  ```
61
73
 
74
+ ### A2A card in 60 seconds
75
+
76
+ ```ts
77
+ import {
78
+ inheritCardBase, draftFromBase, applyOverride, createRelease, transition, attachSignature,
79
+ generateA2ACardSigningKey, signA2ACard, verifyA2ACardSignatures, importA2ACard,
80
+ } from '@agenticprimitives/agent-profile/a2a';
81
+
82
+ const now = new Date().toISOString();
83
+ const base = inheritCardBase({
84
+ profile, names: { primary: 'alice.svc.agent' },
85
+ surfaceCards: toCardProjectionSet(catalog), // surface-catalog — the only source of inherited skills
86
+ runtimeCapabilities: { streaming: false, pushNotifications: false },
87
+ deployment: { host: 'https://alice.agent.example', a2aUrl: 'https://alice.agent.example/api/a2a' },
88
+ agentVersion: '2.0.0', now,
89
+ });
90
+ let draft = draftFromBase(base, { cardResourceId: 'card_01', now });
91
+ draft = applyOverride(draft, '/description', 'Curated copy.', { now }); // recorded, reviewable
92
+ let release = createRelease(draft, { releaseNumber: 1, agentVersion: '2.0.0', now,
93
+ validation: { environment: 'production', catalogSkills: base.card.skills, runtimeCapabilities: {} } });
94
+ release = transition(release, 'approvalPending', { now });
95
+ release = transition(release, 'approved', { now, approval }); // ApprovalRefV1 names the exact digest
96
+ const key = await generateA2ACardSigningKey(); // ES256, kid = RFC 7638 thumbprint
97
+ const signed = await signA2ACard(release.unsignedCard, { privateKey: key.privateKey, kid: key.kid });
98
+ release = attachSignature(release, { signedCard: signed.card, signature: signed.signature });
99
+ // A non-AP client:
100
+ await verifyA2ACardSignatures(signed.card, { keys: (kid) => (kid === key.kid ? key.publicJwk : undefined) });
101
+ // Importing someone else's card: bytes kept, signatures verified BEFORE normalizing, unknown fields flagged.
102
+ const { imported, diagnostics } = await importA2ACard(bytes, { verifyKeys });
103
+ ```
104
+
62
105
  ## How it's different
63
106
 
64
107
  The reference points are registry and agent-card ecosystems, but this package defines the AP-native primitive:
@@ -70,7 +113,9 @@ The reference points are registry and agent-card ecosystems, but this package de
70
113
 
71
114
  ## Main concepts
72
115
 
73
- - **AgentCard**: AP-native typed JSON discriminated by `type`, with type-specific sub-objects (`AiAgentProfile`, `McpServerProfile`, `MultisigProfile`, `ServiceProfile`).
116
+ - **CanonicalAgentProfileV1**: AP-native typed JSON discriminated by `type`, with type-specific sub-objects (`AiAgentProfile`, `McpServerProfile`, `MultisigProfile`, `ServiceProfile`).
117
+ - **A2A Agent Card** (`./a2a`): `A2AAgentCardV1` + draft / release / `FieldBindingV1` provenance (`inherit | override | computed | manual`), pure `validateA2ACard` (stable `DIAGNOSTIC_CODES`, incl. `CATALOG_DIVERGENCE` and `CAPABILITY_UNVERIFIED`), lifecycle `draft → validated → approvalPending → approved → signed → published → superseded | deprecated | revoked`.
118
+ - **Distribution** (`AgentDistributionV1`, spec 347 §8.5): how to OBTAIN AND RUN the agent's software — `acp?` (ACP conformance, the eligibility flag for a hosted ACP `registry.json`), `version?` (implementation semver), `npx` / `uvx` `{ package, args?, env? }`, `binary[<ACP_PLATFORMS>] { archive (https, no .dmg/.pkg/.deb/.rpm), cmd, sha256?, args?, env? }` — field names verbatim from the ACP registry `agent.schema.json`. Stored as the SA-keyed `DISTRIBUTION` (`atl:distribution`) string property in JCS form: `validateDistribution` (pure, `string[]` issues) · `encodeDistribution` (throws on invalid) · `decodeDistribution` (fail-closed → `null`) · `buildSetDistributionCall`. Public on-chain data by construction — never put a secret in `env`.
74
119
  - **Profile facet**: `metadata-uri` + `metadata-hash` pointing at the canonical SA.
75
120
  - **CAIP-10 `nativeId`**: the cross-registry back-link; must match the SA on EVM chains.
76
121
  - **Verification**: proves an MCP/A2A URL is controlled by the SA (distinct from naming).
@@ -81,10 +126,13 @@ See [`docs/concepts.md`](docs/concepts.md).
81
126
 
82
127
  - `@agenticprimitives/agent-profile/caip10` — CAIP-10 helpers only (no client baggage).
83
128
  - `@agenticprimitives/agent-profile/profile` — canonical JSON + content hash.
129
+ - `@agenticprimitives/agent-profile/card` — signed canonical-profile bundle.
130
+ - `@agenticprimitives/agent-profile/a2a` — A2A 1.0 Agent Card model: JCS canonical bytes, ES256 JWS, EIP-712 Smart Agent binding, field provenance, validation, import, release lifecycle.
84
131
 
85
132
  ## Security invariants
86
133
 
87
134
  - Profile content-hash is deterministic (canonical JSON).
135
+ - Card canonical bytes are RFC 8785 JCS (never the sorted-key `canonicalizeJson`); signature and binding verification are fail-closed; import verifies before it normalizes; validation refuses secret material, private URLs and vault references in a card.
88
136
  - No raw passkey material in profiles — only `credentialIdDigest`.
89
137
  - Verification methods are explicit, not auto-selected.
90
138
  - No UAID generation ([ADR-0008](../../docs/architecture/decisions/0008-caip10-nativeid-record-predicate.md)).
@@ -0,0 +1,99 @@
1
+ /**
2
+ * `SmartAgentCardBindingV1` — the Smart Agent's EIP-712 statement that a specific released card (by
3
+ * resource, release, URI and BOTH digests) is its card, signed by the SA and validated through ERC-1271
4
+ * (spec 347 §4.2; ADR-0062 §2).
5
+ *
6
+ * Separate from the JWS on purpose: a non-AP A2A client verifies the JWS and never needs this; an AP
7
+ * verifier checks JWS → key thumbprint authorized → binding. The binding carries NO authority to act — it
8
+ * is descriptive evidence that the SA stands behind these exact bytes.
9
+ *
10
+ * Domain: `{ name:'AgenticPrimitivesAgentCard', version:'1', chainId, verifyingContract: <SA> }`.
11
+ * The ERC-1271 read is INJECTED (`Erc1271Verifier`, same port as `card.ts`) so this stays network-free.
12
+ */
13
+ import { type Address, type Hex } from 'viem';
14
+ import type { Erc1271Verifier } from '../card.js';
15
+ import type { Sha256 } from '../types.js';
16
+ import type { SignedSmartAgentCardBindingV1, SmartAgentCardBindingV1 } from './types.js';
17
+ export declare const SMART_AGENT_CARD_BINDING_DOMAIN_NAME = "AgenticPrimitivesAgentCard";
18
+ export declare const SMART_AGENT_CARD_BINDING_DOMAIN_VERSION = "1";
19
+ export declare const SMART_AGENT_CARD_BINDING_TYPES: {
20
+ readonly SmartAgentCardBinding: readonly [{
21
+ readonly name: "canonicalAgentId";
22
+ readonly type: "string";
23
+ }, {
24
+ readonly name: "cardResourceId";
25
+ readonly type: "string";
26
+ }, {
27
+ readonly name: "cardReleaseId";
28
+ readonly type: "string";
29
+ }, {
30
+ readonly name: "cardUri";
31
+ readonly type: "string";
32
+ }, {
33
+ readonly name: "unsignedCardDigest";
34
+ readonly type: "bytes32";
35
+ }, {
36
+ readonly name: "signedCardDigest";
37
+ readonly type: "bytes32";
38
+ }, {
39
+ readonly name: "signerKeyThumbprint";
40
+ readonly type: "bytes32";
41
+ }, {
42
+ readonly name: "validFrom";
43
+ readonly type: "uint64";
44
+ }, {
45
+ readonly name: "validUntil";
46
+ readonly type: "uint64";
47
+ }];
48
+ };
49
+ /** The EIP-712 type string (for on-chain `TYPEHASH` parity checks). */
50
+ export declare const SMART_AGENT_CARD_BINDING_TYPE_STRING = "SmartAgentCardBinding(string canonicalAgentId,string cardResourceId,string cardReleaseId,string cardUri,bytes32 unsignedCardDigest,bytes32 signedCardDigest,bytes32 signerKeyThumbprint,uint64 validFrom,uint64 validUntil)";
51
+ export declare function smartAgentCardBindingDomain(chainId: number, smartAgent: Address): {
52
+ readonly name: "AgenticPrimitivesAgentCard";
53
+ readonly version: "1";
54
+ readonly chainId: number;
55
+ readonly verifyingContract: `0x${string}`;
56
+ };
57
+ export declare function sha256ToBytes32(digest: Sha256 | string): Hex;
58
+ export declare function bytes32ToSha256(h: Hex): Sha256;
59
+ /** RFC 7638 thumbprint (base64url of a sha256) ↔ bytes32. */
60
+ export declare function thumbprintToBytes32(thumbprint: string): Hex;
61
+ export declare function bytes32ToThumbprint(h: Hex): string;
62
+ /** The EIP-712 message as signed: digests + thumbprint as bytes32, times as uint64. */
63
+ export declare function smartAgentCardBindingMessage(b: SmartAgentCardBindingV1): {
64
+ canonicalAgentId: string;
65
+ cardResourceId: string;
66
+ cardReleaseId: string;
67
+ cardUri: string;
68
+ unsignedCardDigest: `0x${string}`;
69
+ signedCardDigest: `0x${string}`;
70
+ signerKeyThumbprint: `0x${string}`;
71
+ validFrom: bigint;
72
+ validUntil: bigint;
73
+ };
74
+ /** The 32-byte EIP-712 digest the SA signs and ERC-1271 validates. */
75
+ export declare function smartAgentCardBindingDigest(binding: SmartAgentCardBindingV1, chainId: number, smartAgent: Address): Hex;
76
+ export type VerifySmartAgentCardBindingResult = {
77
+ ok: true;
78
+ smartAgent: Address;
79
+ digest: Hex;
80
+ } | {
81
+ ok: false;
82
+ reason: 'bad_shape' | 'agent_mismatch' | 'digest_mismatch' | 'not_yet_valid' | 'expired' | 'signature_invalid';
83
+ };
84
+ export interface VerifySmartAgentCardBindingOptions {
85
+ erc1271Verifier: Erc1271Verifier;
86
+ /** Unix seconds; defaults to now. */
87
+ now?: number;
88
+ /** When given, the binding's digests MUST equal these (the release actually being verified). */
89
+ expect?: {
90
+ unsignedCardDigest?: Sha256;
91
+ signedCardDigest?: Sha256;
92
+ };
93
+ }
94
+ /**
95
+ * Fail-closed verification: shape → `canonicalAgentId` names this SA on this chain → expected digests →
96
+ * validity window → ERC-1271 over the EIP-712 digest. Any anomaly ⇒ `ok:false`.
97
+ */
98
+ export declare function verifySmartAgentCardBinding(signed: SignedSmartAgentCardBindingV1, opts: VerifySmartAgentCardBindingOptions): Promise<VerifySmartAgentCardBindingResult>;
99
+ //# sourceMappingURL=binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../src/a2a/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEzF,eAAO,MAAM,oCAAoC,+BAA+B,CAAC;AACjF,eAAO,MAAM,uCAAuC,MAAM,CAAC;AAE3D,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYjC,CAAC;AAEX,uEAAuE;AACvE,eAAO,MAAM,oCAAoC,gOAC8K,CAAC;AAEhO,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;;;;;EAO/E;AAMD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAI5D;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAG9C;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAI3D;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAKlD;AAID,uFAAuF;AACvF,wBAAgB,4BAA4B,CAAC,CAAC,EAAE,uBAAuB;;;;;;;;;;EAetE;AAED,sEAAsE;AACtE,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,GAAG,CAOvH;AAID,MAAM,MAAM,iCAAiC,GACzC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,GAC9C;IACE,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EACF,WAAW,GACX,gBAAgB,GAChB,iBAAiB,GACjB,eAAe,GACf,SAAS,GACT,mBAAmB,CAAC;CACzB,CAAC;AAEN,MAAM,WAAW,kCAAkC;IACjD,eAAe,EAAE,eAAe,CAAC;IACjC,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,MAAM,CAAC,EAAE;QAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE;AAID;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,6BAA6B,EACrC,IAAI,EAAE,kCAAkC,GACvC,OAAO,CAAC,iCAAiC,CAAC,CAuC5C"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * `SmartAgentCardBindingV1` — the Smart Agent's EIP-712 statement that a specific released card (by
3
+ * resource, release, URI and BOTH digests) is its card, signed by the SA and validated through ERC-1271
4
+ * (spec 347 §4.2; ADR-0062 §2).
5
+ *
6
+ * Separate from the JWS on purpose: a non-AP A2A client verifies the JWS and never needs this; an AP
7
+ * verifier checks JWS → key thumbprint authorized → binding. The binding carries NO authority to act — it
8
+ * is descriptive evidence that the SA stands behind these exact bytes.
9
+ *
10
+ * Domain: `{ name:'AgenticPrimitivesAgentCard', version:'1', chainId, verifyingContract: <SA> }`.
11
+ * The ERC-1271 read is INJECTED (`Erc1271Verifier`, same port as `card.ts`) so this stays network-free.
12
+ */
13
+ import { hashTypedData } from 'viem';
14
+ import { base64UrlDecode, base64UrlEncode } from './jws.js';
15
+ export const SMART_AGENT_CARD_BINDING_DOMAIN_NAME = 'AgenticPrimitivesAgentCard';
16
+ export const SMART_AGENT_CARD_BINDING_DOMAIN_VERSION = '1';
17
+ export const SMART_AGENT_CARD_BINDING_TYPES = {
18
+ SmartAgentCardBinding: [
19
+ { name: 'canonicalAgentId', type: 'string' },
20
+ { name: 'cardResourceId', type: 'string' },
21
+ { name: 'cardReleaseId', type: 'string' },
22
+ { name: 'cardUri', type: 'string' },
23
+ { name: 'unsignedCardDigest', type: 'bytes32' },
24
+ { name: 'signedCardDigest', type: 'bytes32' },
25
+ { name: 'signerKeyThumbprint', type: 'bytes32' },
26
+ { name: 'validFrom', type: 'uint64' },
27
+ { name: 'validUntil', type: 'uint64' },
28
+ ],
29
+ };
30
+ /** The EIP-712 type string (for on-chain `TYPEHASH` parity checks). */
31
+ export const SMART_AGENT_CARD_BINDING_TYPE_STRING = 'SmartAgentCardBinding(string canonicalAgentId,string cardResourceId,string cardReleaseId,string cardUri,bytes32 unsignedCardDigest,bytes32 signedCardDigest,bytes32 signerKeyThumbprint,uint64 validFrom,uint64 validUntil)';
32
+ export function smartAgentCardBindingDomain(chainId, smartAgent) {
33
+ return {
34
+ name: SMART_AGENT_CARD_BINDING_DOMAIN_NAME,
35
+ version: SMART_AGENT_CARD_BINDING_DOMAIN_VERSION,
36
+ chainId,
37
+ verifyingContract: smartAgent,
38
+ };
39
+ }
40
+ // ─── digest ↔ bytes32 ────────────────────────────────────────────────────────────────────────────────
41
+ const SHA256_RE = /^sha256:([0-9a-f]{64})$/;
42
+ export function sha256ToBytes32(digest) {
43
+ const m = SHA256_RE.exec(digest.toLowerCase());
44
+ if (!m)
45
+ throw new Error(`not a sha256 digest: "${digest}"`);
46
+ return `0x${m[1]}`;
47
+ }
48
+ export function bytes32ToSha256(h) {
49
+ if (!/^0x[0-9a-fA-F]{64}$/.test(h))
50
+ throw new Error(`not a bytes32: "${h}"`);
51
+ return `sha256:${h.slice(2).toLowerCase()}`;
52
+ }
53
+ /** RFC 7638 thumbprint (base64url of a sha256) ↔ bytes32. */
54
+ export function thumbprintToBytes32(thumbprint) {
55
+ const bytes = base64UrlDecode(thumbprint);
56
+ if (bytes.length !== 32)
57
+ throw new Error('signerKeyThumbprint must be a base64url sha256 (32 bytes)');
58
+ return `0x${Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')}`;
59
+ }
60
+ export function bytes32ToThumbprint(h) {
61
+ if (!/^0x[0-9a-fA-F]{64}$/.test(h))
62
+ throw new Error(`not a bytes32: "${h}"`);
63
+ const bytes = new Uint8Array(32);
64
+ for (let i = 0; i < 32; i++)
65
+ bytes[i] = parseInt(h.slice(2 + i * 2, 4 + i * 2), 16);
66
+ return base64UrlEncode(bytes);
67
+ }
68
+ // ─── digest ──────────────────────────────────────────────────────────────────────────────────────────
69
+ /** The EIP-712 message as signed: digests + thumbprint as bytes32, times as uint64. */
70
+ export function smartAgentCardBindingMessage(b) {
71
+ if (!Number.isInteger(b.validFrom) || b.validFrom < 0 || !Number.isInteger(b.validUntil) || b.validUntil < 0) {
72
+ throw new Error('validFrom/validUntil must be non-negative integer unix seconds');
73
+ }
74
+ return {
75
+ canonicalAgentId: b.canonicalAgentId,
76
+ cardResourceId: b.cardResourceId,
77
+ cardReleaseId: b.cardReleaseId,
78
+ cardUri: b.cardUri,
79
+ unsignedCardDigest: sha256ToBytes32(b.unsignedCardDigest),
80
+ signedCardDigest: sha256ToBytes32(b.signedCardDigest),
81
+ signerKeyThumbprint: thumbprintToBytes32(b.signerKeyThumbprint),
82
+ validFrom: BigInt(b.validFrom),
83
+ validUntil: BigInt(b.validUntil),
84
+ };
85
+ }
86
+ /** The 32-byte EIP-712 digest the SA signs and ERC-1271 validates. */
87
+ export function smartAgentCardBindingDigest(binding, chainId, smartAgent) {
88
+ return hashTypedData({
89
+ domain: smartAgentCardBindingDomain(chainId, smartAgent),
90
+ types: SMART_AGENT_CARD_BINDING_TYPES,
91
+ primaryType: 'SmartAgentCardBinding',
92
+ message: smartAgentCardBindingMessage(binding),
93
+ });
94
+ }
95
+ const CAIP10_EVM = /^eip155:(\d+):(0x[0-9a-fA-F]{40})$/;
96
+ /**
97
+ * Fail-closed verification: shape → `canonicalAgentId` names this SA on this chain → expected digests →
98
+ * validity window → ERC-1271 over the EIP-712 digest. Any anomaly ⇒ `ok:false`.
99
+ */
100
+ export async function verifySmartAgentCardBinding(signed, opts) {
101
+ const b = signed?.binding;
102
+ if (!b ||
103
+ typeof signed.chainId !== 'number' ||
104
+ typeof signed.verifyingContract !== 'string' ||
105
+ typeof signed.signature !== 'string' ||
106
+ typeof b.canonicalAgentId !== 'string') {
107
+ return { ok: false, reason: 'bad_shape' };
108
+ }
109
+ const m = CAIP10_EVM.exec(b.canonicalAgentId);
110
+ if (!m || Number(m[1]) !== signed.chainId || m[2].toLowerCase() !== signed.verifyingContract.toLowerCase()) {
111
+ return { ok: false, reason: 'agent_mismatch' };
112
+ }
113
+ if (opts.expect?.unsignedCardDigest && opts.expect.unsignedCardDigest !== b.unsignedCardDigest) {
114
+ return { ok: false, reason: 'digest_mismatch' };
115
+ }
116
+ if (opts.expect?.signedCardDigest && opts.expect.signedCardDigest !== b.signedCardDigest) {
117
+ return { ok: false, reason: 'digest_mismatch' };
118
+ }
119
+ const now = opts.now ?? Math.floor(Date.now() / 1000);
120
+ if (now < b.validFrom)
121
+ return { ok: false, reason: 'not_yet_valid' };
122
+ if (b.validUntil !== 0 && now > b.validUntil)
123
+ return { ok: false, reason: 'expired' };
124
+ let digest;
125
+ try {
126
+ digest = smartAgentCardBindingDigest(b, signed.chainId, signed.verifyingContract);
127
+ }
128
+ catch {
129
+ return { ok: false, reason: 'bad_shape' };
130
+ }
131
+ let valid;
132
+ try {
133
+ valid = await opts.erc1271Verifier.verifyHash({ address: signed.verifyingContract, hash: digest, signature: signed.signature });
134
+ }
135
+ catch {
136
+ return { ok: false, reason: 'signature_invalid' };
137
+ }
138
+ if (!valid)
139
+ return { ok: false, reason: 'signature_invalid' };
140
+ return { ok: true, smartAgent: signed.verifyingContract, digest };
141
+ }
142
+ //# sourceMappingURL=binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/a2a/binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAA0B,MAAM,MAAM,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG5D,MAAM,CAAC,MAAM,oCAAoC,GAAG,4BAA4B,CAAC;AACjF,MAAM,CAAC,MAAM,uCAAuC,GAAG,GAAG,CAAC;AAE3D,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,qBAAqB,EAAE;QACrB,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC5C,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1C,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;QACnC,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,SAAS,EAAE;QAC/C,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE;QAC7C,EAAE,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,SAAS,EAAE;QAChD,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI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AAM,CAAC,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAClI,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IACpD,CAAC;IACD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;AACpE,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Canonical form of an A2A Agent Card (spec 347 §4.2).
3
+ *
4
+ * remove `signatures` → RFC 8785 JCS → UTF-8 bytes → `sha256:<hex>`
5
+ *
6
+ * Uses `types.jcsCanonicalize` (RFC 8785: number formatting, escaping, UTF-16 code-unit key order) and
7
+ * NOT the sorted-key `canonicalizeJson` — those produce different bytes for the same document, and these
8
+ * bytes are what every JWS signs and every Smart Agent binding names. Presence is preserved: an omitted
9
+ * optional and an explicit default are different bytes, on purpose.
10
+ */
11
+ import type { Sha256 } from '../types.js';
12
+ /** Anything card-shaped: the typed card, or a raw imported object (unknown fields included — they are
13
+ * part of what an existing signature covers). */
14
+ export type CardLike = {
15
+ signatures?: unknown;
16
+ };
17
+ /** The card without `signatures` — the exact object every signature is computed over. */
18
+ export declare function unsignedCard<T extends CardLike>(card: T): Omit<T, 'signatures'>;
19
+ /** JCS string of the unsigned card. Throws (`JcsError`) on non-JSON values — never silently drops. */
20
+ export declare function canonicalCardJson(card: CardLike): string;
21
+ /** UTF-8 bytes of {@link canonicalCardJson}. */
22
+ export declare function canonicalCardBytes(card: CardLike): Uint8Array;
23
+ /** `sha256:<hex>` of arbitrary bytes. */
24
+ export declare function sha256Digest(bytes: Uint8Array): Sha256;
25
+ /** `sha256:<hex>` of a JCS-canonicalized value (used for field digests + etags). */
26
+ export declare function jcsDigest(value: unknown): Sha256;
27
+ /** `unsignedContentDigest`: sha256 of the canonical (unsigned) card bytes. */
28
+ export declare function cardContentDigest(card: CardLike): Sha256;
29
+ /** `signedContentDigest`: sha256 over JCS of the WHOLE card, signatures included. */
30
+ export declare function signedCardContentDigest(card: CardLike): Sha256;
31
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/a2a/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;kDACkD;AAClD,MAAM,MAAM,QAAQ,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhD,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAG/E;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAExD;AAID,gDAAgD;AAChD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAE7D;AAED,yCAAyC;AACzC,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEtD;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAExD;AAED,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAE9D"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Canonical form of an A2A Agent Card (spec 347 §4.2).
3
+ *
4
+ * remove `signatures` → RFC 8785 JCS → UTF-8 bytes → `sha256:<hex>`
5
+ *
6
+ * Uses `types.jcsCanonicalize` (RFC 8785: number formatting, escaping, UTF-16 code-unit key order) and
7
+ * NOT the sorted-key `canonicalizeJson` — those produce different bytes for the same document, and these
8
+ * bytes are what every JWS signs and every Smart Agent binding names. Presence is preserved: an omitted
9
+ * optional and an explicit default are different bytes, on purpose.
10
+ */
11
+ import { jcsCanonicalize } from '@agenticprimitives/types';
12
+ import { sha256 as viemSha256 } from 'viem';
13
+ /** The card without `signatures` — the exact object every signature is computed over. */
14
+ export function unsignedCard(card) {
15
+ const { signatures: _drop, ...rest } = card;
16
+ return rest;
17
+ }
18
+ /** JCS string of the unsigned card. Throws (`JcsError`) on non-JSON values — never silently drops. */
19
+ export function canonicalCardJson(card) {
20
+ return jcsCanonicalize(unsignedCard(card));
21
+ }
22
+ const utf8 = new TextEncoder();
23
+ /** UTF-8 bytes of {@link canonicalCardJson}. */
24
+ export function canonicalCardBytes(card) {
25
+ return utf8.encode(canonicalCardJson(card));
26
+ }
27
+ /** `sha256:<hex>` of arbitrary bytes. */
28
+ export function sha256Digest(bytes) {
29
+ return `sha256:${viemSha256(bytes).slice(2)}`;
30
+ }
31
+ /** `sha256:<hex>` of a JCS-canonicalized value (used for field digests + etags). */
32
+ export function jcsDigest(value) {
33
+ return sha256Digest(utf8.encode(jcsCanonicalize(value)));
34
+ }
35
+ /** `unsignedContentDigest`: sha256 of the canonical (unsigned) card bytes. */
36
+ export function cardContentDigest(card) {
37
+ return sha256Digest(canonicalCardBytes(card));
38
+ }
39
+ /** `signedContentDigest`: sha256 over JCS of the WHOLE card, signatures included. */
40
+ export function signedCardContentDigest(card) {
41
+ return jcsDigest(card);
42
+ }
43
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/a2a/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAO5C,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAqB,IAAO;IACtD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,iBAAiB,CAAC,IAAc;IAC9C,OAAO,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAE/B,gDAAgD;AAChD,MAAM,UAAU,kBAAkB,CAAC,IAAc;IAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,yCAAyC;AACzC,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,OAAO,UAAU,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAY,CAAC;AAC1D,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,IAAc;IAC9C,OAAO,YAAY,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,uBAAuB,CAAC,IAAc;IACpD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Field provenance (spec 347 §4.3; ADR-0062 §4): inherit the card base, curate with recorded overrides,
3
+ * detect when an inherited source moved under a draft. PURE — the clock is an input.
4
+ *
5
+ * Sources are STRUCTURAL (no package import): `surfaceCards` is shaped like `surface-catalog`'s
6
+ * `toCardProjectionSet(...)` output, `publicSkillCandidates` like `capability-claims`'
7
+ * `A2aAgentSkillDescriptor`. surface-catalog remains the only generator of inherited interface/skill
8
+ * fields; capability claims add PUBLIC skills with their own provenance.
9
+ */
10
+ import type { EvidenceRefV1 } from '@agenticprimitives/types';
11
+ import type { CanonicalAgentProfileV1 } from '../types.js';
12
+ import type { A2AAgentCapabilitiesV1, A2AAgentCardDraftV1, A2AAgentCardV1, A2AAgentInterfaceV1, FieldBindingSourceKind, FieldBindingV1, Sha256 } from './types.js';
13
+ /** Shape of `surface-catalog` `A2aCardSkillLike` (structural, no package dependency). */
14
+ export interface SurfaceCardSkillLike {
15
+ id: string;
16
+ name: string;
17
+ description?: string;
18
+ }
19
+ /** Structural shape of `AdvertisedCapabilityV1` — used for both profile capabilities and public claims. */
20
+ export interface AdvertisedCapabilityLike {
21
+ id: string;
22
+ name: string;
23
+ description: string;
24
+ tags: string[];
25
+ examples?: string[];
26
+ inputModes?: string[];
27
+ outputModes?: string[];
28
+ }
29
+ /** @deprecated Name says "skill"; this is an advertised capability. Alias kept for existing importers. */
30
+ export interface PublicSkillCandidateLike {
31
+ id: string;
32
+ name: string;
33
+ description: string;
34
+ tags: string[];
35
+ examples?: string[];
36
+ inputModes?: string[];
37
+ outputModes?: string[];
38
+ }
39
+ export interface InheritCardBaseInput {
40
+ profile: CanonicalAgentProfileV1;
41
+ /** From `agent-naming`: the primary public name (used as the card name when present). */
42
+ names?: {
43
+ primary?: string;
44
+ all?: string[];
45
+ };
46
+ /** `toCardProjectionSet(catalog).public` — the runtime-served public skills. */
47
+ surfaceCards: {
48
+ public: SurfaceCardSkillLike[];
49
+ };
50
+ /** Interfaces the surface catalog / deployment serves; absent ⇒ computed from `deployment.a2aUrl`. */
51
+ surfaceInterfaces?: A2AAgentInterfaceV1[];
52
+ /** What the runtime actually implements. Absent ⇒ every flag false (honest, ADR-0059). */
53
+ runtimeCapabilities?: A2AAgentCapabilitiesV1;
54
+ /** Eligible PUBLIC capability claims, already policy-filtered (spec 347 §5). */
55
+ publicSkillCandidates?: PublicSkillCandidateLike[];
56
+ deployment: {
57
+ /** Public origin, e.g. `https://agent.example`. */
58
+ host?: string;
59
+ /** The A2A message endpoint URL. */
60
+ a2aUrl: string;
61
+ protocolBinding?: A2AAgentInterfaceV1['protocolBinding'];
62
+ documentationUrl?: string;
63
+ /** Provider organization/url (operator relationship); falls back to the profile. */
64
+ provider?: {
65
+ organization: string;
66
+ url: string;
67
+ };
68
+ };
69
+ /** The AGENT implementation version. Default `'0.1.0'`. */
70
+ agentVersion?: string;
71
+ protocolVersion?: string;
72
+ mediaModes?: {
73
+ input?: string[];
74
+ output?: string[];
75
+ };
76
+ /** ISO timestamp for every binding's `updatedAt` (pure — the caller supplies the clock). */
77
+ now: string;
78
+ }
79
+ export interface InheritedCardBase {
80
+ card: A2AAgentCardV1;
81
+ fieldBindings: Record<string, FieldBindingV1>;
82
+ /** `sha256:` of the inherited card — the draft's `sourceSnapshotDigest`. */
83
+ snapshotDigest: Sha256;
84
+ }
85
+ /** Generate the card base from canonical sources. Every field carries an `inherit` or `computed` binding. */
86
+ export declare function inheritCardBase(input: InheritCardBaseInput): InheritedCardBase;
87
+ /** Start a draft from an inherited base. */
88
+ export declare function draftFromBase(base: InheritedCardBase, opts: {
89
+ cardResourceId: string;
90
+ now: string;
91
+ revision?: number;
92
+ basedOnReleaseId?: string;
93
+ }): A2AAgentCardDraftV1;
94
+ /** Opaque optimistic-concurrency token: digest of card + bindings + revision. */
95
+ export declare function draftEtag(d: Pick<A2AAgentCardDraftV1, 'card' | 'fieldBindings' | 'revision' | 'extendedCardPolicies'>): string;
96
+ export interface ApplyOverrideOptions {
97
+ source?: {
98
+ kind: FieldBindingSourceKind;
99
+ ref?: string;
100
+ };
101
+ evidence?: EvidenceRefV1[];
102
+ now: string;
103
+ }
104
+ /**
105
+ * Curate one field. Returns a NEW draft (revision+1) with an `override` binding at `pointer` that remembers
106
+ * the digest of the value it replaced. Nothing is mutated. `value === undefined` removes the field.
107
+ */
108
+ export declare function applyOverride(draft: A2AAgentCardDraftV1, pointer: string, value: unknown, opts: ApplyOverrideOptions): A2AAgentCardDraftV1;
109
+ export interface StaleReport {
110
+ /** Inherited/computed pointers whose fresh base value differs from the draft. */
111
+ stale: string[];
112
+ /** Overridden pointers whose fresh base value differs from the value the override replaced. */
113
+ conflict: string[];
114
+ /** The draft with binding states updated (`stale` / `conflict`); overrides' VALUES untouched. */
115
+ draft: A2AAgentCardDraftV1;
116
+ }
117
+ /**
118
+ * Compare a draft against a freshly inherited base. Published releases are never touched; the draft's
119
+ * bindings become `stale` (inherited value moved) or `conflict` (base moved under an override). The
120
+ * editor then shows old / new / effective and the user accepts, retains, or revises.
121
+ */
122
+ export declare function detectStale(draft: A2AAgentCardDraftV1, freshBase: Pick<InheritedCardBase, 'card' | 'snapshotDigest'>): StaleReport;
123
+ /** Accept the fresh inherited value for one stale pointer (binding back to `inherit`, state `fresh`). */
124
+ export declare function acceptInherited(draft: A2AAgentCardDraftV1, pointer: string, freshBase: Pick<InheritedCardBase, 'card' | 'fieldBindings'>, now: string): A2AAgentCardDraftV1;
125
+ //# sourceMappingURL=field-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-binding.d.ts","sourceRoot":"","sources":["../../src/a2a/field-binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EAEnB,sBAAsB,EACtB,cAAc,EACd,MAAM,EACP,MAAM,YAAY,CAAC;AAEpB,yFAAyF;AACzF,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,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