@agenticprimitives/agent-resolution 0.0.0-alpha.1

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 (92) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +319 -0
  3. package/dist/admission.d.ts +14 -0
  4. package/dist/admission.d.ts.map +1 -0
  5. package/dist/admission.js +137 -0
  6. package/dist/admission.js.map +1 -0
  7. package/dist/authority-ref.d.ts +38 -0
  8. package/dist/authority-ref.d.ts.map +1 -0
  9. package/dist/authority-ref.js +69 -0
  10. package/dist/authority-ref.js.map +1 -0
  11. package/dist/canonicalization.d.ts +16 -0
  12. package/dist/canonicalization.d.ts.map +1 -0
  13. package/dist/canonicalization.js +39 -0
  14. package/dist/canonicalization.js.map +1 -0
  15. package/dist/codec.d.ts +15 -0
  16. package/dist/codec.d.ts.map +1 -0
  17. package/dist/codec.js +34 -0
  18. package/dist/codec.js.map +1 -0
  19. package/dist/compose.d.ts +79 -0
  20. package/dist/compose.d.ts.map +1 -0
  21. package/dist/compose.js +235 -0
  22. package/dist/compose.js.map +1 -0
  23. package/dist/endpoint-control.d.ts +87 -0
  24. package/dist/endpoint-control.d.ts.map +1 -0
  25. package/dist/endpoint-control.js +174 -0
  26. package/dist/endpoint-control.js.map +1 -0
  27. package/dist/errors.d.ts +33 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +71 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/freshness.d.ts +43 -0
  32. package/dist/freshness.d.ts.map +1 -0
  33. package/dist/freshness.js +100 -0
  34. package/dist/freshness.js.map +1 -0
  35. package/dist/grant-index.d.ts +21 -0
  36. package/dist/grant-index.d.ts.map +1 -0
  37. package/dist/grant-index.js +0 -0
  38. package/dist/grant-index.js.map +1 -0
  39. package/dist/grants.d.ts +100 -0
  40. package/dist/grants.d.ts.map +1 -0
  41. package/dist/grants.js +99 -0
  42. package/dist/grants.js.map +1 -0
  43. package/dist/index.d.ts +44 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +63 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/invitation.d.ts +43 -0
  48. package/dist/invitation.d.ts.map +1 -0
  49. package/dist/invitation.js +76 -0
  50. package/dist/invitation.js.map +1 -0
  51. package/dist/peer-attestation.d.ts +61 -0
  52. package/dist/peer-attestation.d.ts.map +1 -0
  53. package/dist/peer-attestation.js +128 -0
  54. package/dist/peer-attestation.js.map +1 -0
  55. package/dist/peer-gate.d.ts +73 -0
  56. package/dist/peer-gate.d.ts.map +1 -0
  57. package/dist/peer-gate.js +108 -0
  58. package/dist/peer-gate.js.map +1 -0
  59. package/dist/policy.d.ts +53 -0
  60. package/dist/policy.d.ts.map +1 -0
  61. package/dist/policy.js +73 -0
  62. package/dist/policy.js.map +1 -0
  63. package/dist/ports.d.ts +59 -0
  64. package/dist/ports.d.ts.map +1 -0
  65. package/dist/ports.js +10 -0
  66. package/dist/ports.js.map +1 -0
  67. package/dist/projection.d.ts +74 -0
  68. package/dist/projection.d.ts.map +1 -0
  69. package/dist/projection.js +134 -0
  70. package/dist/projection.js.map +1 -0
  71. package/dist/proof.d.ts +76 -0
  72. package/dist/proof.d.ts.map +1 -0
  73. package/dist/proof.js +207 -0
  74. package/dist/proof.js.map +1 -0
  75. package/dist/publication.d.ts +123 -0
  76. package/dist/publication.d.ts.map +1 -0
  77. package/dist/publication.js +32 -0
  78. package/dist/publication.js.map +1 -0
  79. package/dist/records.d.ts +168 -0
  80. package/dist/records.d.ts.map +1 -0
  81. package/dist/records.js +83 -0
  82. package/dist/records.js.map +1 -0
  83. package/dist/references.d.ts +61 -0
  84. package/dist/references.d.ts.map +1 -0
  85. package/dist/references.js +7 -0
  86. package/dist/references.js.map +1 -0
  87. package/dist/results.d.ts +89 -0
  88. package/dist/results.d.ts.map +1 -0
  89. package/dist/results.js +37 -0
  90. package/dist/results.js.map +1 -0
  91. package/package.json +57 -0
  92. package/spec.md +78 -0
@@ -0,0 +1,39 @@
1
+ // Deterministic canonicalization + digest for resolution objects (spec 338 §3).
2
+ //
3
+ // Uses the shared `canonicalizeJson` convention from `@agenticprimitives/types` so a digest computed
4
+ // here matches one computed by `messaging` / `verification-receipts` / `key-authorization` over the
5
+ // same body. Hashing is WebCrypto (`globalThis.crypto.subtle`) — present in Node >= 20 and workerd —
6
+ // which keeps this package a pure, network-free leaf with no crypto dependency.
7
+ import { canonicalizeJson } from '@agenticprimitives/types';
8
+ const enc = new TextEncoder();
9
+ async function sha256Hex(input) {
10
+ const digest = await globalThis.crypto.subtle.digest('SHA-256', enc.encode(input));
11
+ return Array.from(new Uint8Array(digest))
12
+ .map((b) => b.toString(16).padStart(2, '0'))
13
+ .join('');
14
+ }
15
+ /** sha256 over the canonical JSON form of `body`. */
16
+ export async function digestOf(body) {
17
+ return `sha256:${await sha256Hex(canonicalizeJson(body))}`;
18
+ }
19
+ /** The 32-byte `0x`-hex digest a Smart Agent signs / an ERC-1271 read validates over. It IS the
20
+ * `sha256:` digest's bytes, so the signature binds every field of the canonical body. */
21
+ export function signingDigest(d) {
22
+ return `0x${d.slice('sha256:'.length)}`;
23
+ }
24
+ /**
25
+ * Constant-time-ish string comparison for digests and opaque ids.
26
+ *
27
+ * Digest comparison is not a secret comparison, but grant-id lookups are — and a resolver that
28
+ * short-circuits on the first differing byte is a timing oracle for which grant ids exist
29
+ * (spec 338 §10, "public enumeration oracle"). Length is not secret; content is.
30
+ */
31
+ export function timingSafeEqual(a, b) {
32
+ if (a.length !== b.length)
33
+ return false;
34
+ let diff = 0;
35
+ for (let i = 0; i < a.length; i += 1)
36
+ diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
37
+ return diff === 0;
38
+ }
39
+ //# sourceMappingURL=canonicalization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalization.js","sourceRoot":"","sources":["../src/canonicalization.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,qGAAqG;AACrG,oGAAoG;AACpG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;IAChF,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { AgentServicePublicationV1 } from './publication.js';
2
+ import type { AgentResolutionReceiptV1 } from './results.js';
3
+ /** Wire form of a publication: `sequence` as a decimal string. */
4
+ export type JsonAgentServicePublicationV1 = Omit<AgentServicePublicationV1, 'sequence'> & {
5
+ sequence: string;
6
+ };
7
+ /** Wire form of a receipt: `publicationSequence` as a decimal string. */
8
+ export type JsonAgentResolutionReceiptV1 = Omit<AgentResolutionReceiptV1, 'publicationSequence'> & {
9
+ publicationSequence?: string;
10
+ };
11
+ export declare function encodePublication(p: AgentServicePublicationV1): JsonAgentServicePublicationV1;
12
+ export declare function decodePublication(j: JsonAgentServicePublicationV1): AgentServicePublicationV1;
13
+ export declare function encodeReceipt(r: AgentResolutionReceiptV1): JsonAgentResolutionReceiptV1;
14
+ export declare function decodeReceipt(j: JsonAgentResolutionReceiptV1): AgentResolutionReceiptV1;
15
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAE7D,kEAAkE;AAClE,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,yBAAyB,EAAE,UAAU,CAAC,GAAG;IACxF,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,wBAAwB,EAAE,qBAAqB,CAAC,GAAG;IACjG,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,yBAAyB,GAAG,6BAA6B,CAE7F;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,6BAA6B,GAAG,yBAAyB,CAI7F;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,wBAAwB,GAAG,4BAA4B,CAKvF;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,4BAA4B,GAAG,wBAAwB,CAKvF"}
package/dist/codec.js ADDED
@@ -0,0 +1,34 @@
1
+ // JSON codecs for the two shapes that carry `bigint` (spec 338 §3, §11).
2
+ //
3
+ // WHY BIGINT AT ALL: `sequence` is the anti-rollback axis. A `number` silently loses precision past
4
+ // 2^53 and invites float comparison bugs in exactly the check that must never be wrong, so the
5
+ // domain type stays `bigint`.
6
+ //
7
+ // WHY CODECS: `JSON.stringify` THROWS on a bigint. Every caller that persists a publication to a
8
+ // vault, puts a receipt on the wire, or logs either one hits that — so the conversion is shipped
9
+ // here once, matching the decimal-string convention `publicationBody` already uses for digests,
10
+ // rather than being hand-rolled (and hand-mangled) at each call site.
11
+ //
12
+ // Round-trip is exact: encode → decode yields a structurally equal value.
13
+ export function encodePublication(p) {
14
+ return { ...p, sequence: p.sequence.toString(10) };
15
+ }
16
+ export function decodePublication(j) {
17
+ const sequence = BigInt(j.sequence);
18
+ if (sequence < 0n)
19
+ throw new Error('agent-resolution: publication sequence must not be negative');
20
+ return { ...j, sequence };
21
+ }
22
+ export function encodeReceipt(r) {
23
+ return {
24
+ ...r,
25
+ publicationSequence: r.publicationSequence === undefined ? undefined : r.publicationSequence.toString(10),
26
+ };
27
+ }
28
+ export function decodeReceipt(j) {
29
+ return {
30
+ ...j,
31
+ publicationSequence: j.publicationSequence === undefined ? undefined : BigInt(j.publicationSequence),
32
+ };
33
+ }
34
+ //# sourceMappingURL=codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.js","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,oGAAoG;AACpG,+FAA+F;AAC/F,8BAA8B;AAC9B,EAAE;AACF,iGAAiG;AACjG,iGAAiG;AACjG,gGAAgG;AAChG,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAe1E,MAAM,UAAU,iBAAiB,CAAC,CAA4B;IAC5D,OAAO,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,CAAgC;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,QAAQ,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAClG,OAAO,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAA2B;IACvD,OAAO;QACL,GAAG,CAAC;QACJ,mBAAmB,EAAE,CAAC,CAAC,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;KAC1G,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAA+B;IAC3D,OAAO;QACL,GAAG,CAAC;QACJ,mBAAmB,EAAE,CAAC,CAAC,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC;KACrG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { CanonicalAgentId, VerifiedPeerContextV1 } from '@agenticprimitives/types';
2
+ import { type ResolvedPeerPolicy } from './peer-gate.js';
3
+ import { type ResolutionFailure } from './errors.js';
4
+ import { type ChannelContinuityState } from './freshness.js';
5
+ import { type Erc1271Verifier, type PublicationAuthorityCheck, type VerifyPublicationOptions } from './proof.js';
6
+ import type { AgentResolutionReference, ResolutionContextV1 } from './references.js';
7
+ import type { AgentResolutionProvider } from './ports.js';
8
+ import { type ResolutionAssurance, type VerifiedAgentResolutionV1 } from './results.js';
9
+ /** Reads/writes what a client already accepted on a channel. Injected — this package holds no state. */
10
+ export interface ContinuityStore {
11
+ get(channelId: string): Promise<ChannelContinuityState | undefined>;
12
+ put(state: ChannelContinuityState): Promise<void>;
13
+ }
14
+ export interface ComposedResolverOptions {
15
+ providers: readonly AgentResolutionProvider[];
16
+ verifier: Erc1271Verifier;
17
+ /** Omit and assurance can never exceed `asserted` — see `assuranceOf`. */
18
+ authorityCheck?: PublicationAuthorityCheck;
19
+ /** Minimum assurance the caller will accept. A weaker result is a failure, never a silent pass. */
20
+ minAssurance?: ResolutionAssurance;
21
+ continuity?: ContinuityStore;
22
+ endpointControl?: VerifyPublicationOptions['endpointControl'];
23
+ minEndpointAssurance?: VerifyPublicationOptions['minEndpointAssurance'];
24
+ maxExposure?: VerifyPublicationOptions['maxExposure'];
25
+ requireEndpointProof?: boolean;
26
+ /**
27
+ * The post-resolve peer gate (AR-L7). Supply it and resolution ENFORCES
28
+ * "the peer must be the agent we resolved" — omit it and it does not.
29
+ *
30
+ * WHY OPTIONAL RATHER THAN ALWAYS-ON. Attesting requires the responding host to hold the agent's
31
+ * signing key. A host serving an agent it does not custody cannot do it, and on a baseline HTTPS
32
+ * transport no channel binding exists at all — so a mandatory gate would refuse every deployment we
33
+ * currently run. Optional, loudly documented, and the ONLY route to `peer-authenticated`.
34
+ *
35
+ * OMITTING IT IS NOT FREE: assurance then cannot exceed `endpoint-control-verified`, because
36
+ * nothing verified who answered.
37
+ */
38
+ peer?: {
39
+ /**
40
+ * Obtain a peer context for the resolved endpoint — typically by issuing a nonce and calling
41
+ * `verifyPeerAttestation` on the response. Returning `undefined` means "could not establish",
42
+ * which the gate treats as a refusal, never as a pass.
43
+ */
44
+ obtain: (input: {
45
+ expectedAgentId: CanonicalAgentId;
46
+ endpointUri: string;
47
+ }) => Promise<VerifiedPeerContextV1 | undefined>;
48
+ policy?: ResolvedPeerPolicy;
49
+ };
50
+ }
51
+ export type ComposedResolutionResult = {
52
+ ok: true;
53
+ resolution: VerifiedAgentResolutionV1;
54
+ } | {
55
+ ok: false;
56
+ failures: readonly ResolutionFailure[];
57
+ };
58
+ /**
59
+ * The assurance a verification result earned.
60
+ *
61
+ * Deliberately conservative at each step. Note `publisherAuthorized`: a publication whose signature
62
+ * verifies but whose publisher authority was never checked is `asserted`, NOT `signed-publication` —
63
+ * a valid signature by an unauthorized publisher is still a forgery, so a caller that omitted
64
+ * `authorityCheck` must not be told it got the stronger level.
65
+ */
66
+ export declare function assuranceOf(v: {
67
+ signatureValid: boolean;
68
+ publisherAuthorized: boolean;
69
+ endpointVerified: boolean;
70
+ peerAuthenticated?: boolean;
71
+ }): ResolutionAssurance;
72
+ /**
73
+ * Build a resolver over several providers.
74
+ *
75
+ * Throws at construction if two providers claim the same reference kind — an ambiguity that would
76
+ * otherwise be resolved by array order, which is not a trust decision anyone intended to make.
77
+ */
78
+ export declare function createComposedResolver(opts: ComposedResolverOptions): (reference: AgentResolutionReference, context: ResolutionContextV1, expectedAgentId?: CanonicalAgentId) => Promise<ComposedResolutionResult>;
79
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAA4C,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAiC,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC9B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,wBAAwB,EACxB,mBAAmB,EAEpB,MAAM,iBAAiB,C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Q,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,mBAAmB,CAKtB;AA6BD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,uBAAuB,eAYrD,wBAAwB,WAC1B,mBAAmB,oBAEV,gBAAgB,KACjC,OAAO,CAAC,wBAAwB,CAAC,CA4KrC"}
@@ -0,0 +1,235 @@
1
+ // Composed resolution (spec 338 §12, W5) — many methods, ONE verification path.
2
+ //
3
+ // ─── WHY THIS IS NOT A FALLBACK CHAIN ───────────────────────────────────────────────────────────
4
+ // The obvious shape for "compose several providers" is: try each in turn until one answers. That is
5
+ // exactly the pattern ADR-0013 forbids. A reference names ONE method — an ANS name is not a private
6
+ // grant, a grant is not an invitation — so trying the next provider when the first says "no" means
7
+ // answering a question nobody asked, with weaker evidence than the caller believed they had.
8
+ //
9
+ // So dispatch here is EXACTLY ONE provider per reference, chosen by `supports()`. If that provider
10
+ // returns nothing, that is the answer. Two providers claiming the same reference is a CONFIGURATION
11
+ // ERROR and throws at construction — not a race resolved at request time.
12
+ //
13
+ // What composition does buy: every method converges on the same verification (digest, signature,
14
+ // authority, freshness, continuity, endpoint control) and the same assurance ladder, so a caller can
15
+ // state a minimum assurance once and have it enforced regardless of how the agent was found.
16
+ import { checkResolvedPeer, peerAuthenticatedFrom } from './peer-gate.js';
17
+ import { AgentResolutionError, failure } from './errors.js';
18
+ import { advanceContinuity } from './freshness.js';
19
+ import { verifyPublication, } from './proof.js';
20
+ import { meetsAssurance, } from './results.js';
21
+ /**
22
+ * The assurance a verification result earned.
23
+ *
24
+ * Deliberately conservative at each step. Note `publisherAuthorized`: a publication whose signature
25
+ * verifies but whose publisher authority was never checked is `asserted`, NOT `signed-publication` —
26
+ * a valid signature by an unauthorized publisher is still a forgery, so a caller that omitted
27
+ * `authorityCheck` must not be told it got the stronger level.
28
+ */
29
+ export function assuranceOf(v) {
30
+ if (!v.signatureValid)
31
+ return 'unverified';
32
+ if (!v.publisherAuthorized)
33
+ return 'asserted';
34
+ if (v.peerAuthenticated)
35
+ return 'peer-authenticated';
36
+ return v.endpointVerified ? 'endpoint-control-verified' : 'signed-publication';
37
+ }
38
+ /** The canonical agent a reference expects, when the reference itself names one. */
39
+ function expectedAgentOf(ref) {
40
+ switch (ref.kind) {
41
+ case 'canonical-agent':
42
+ return ref.agentId;
43
+ case 'direct-invitation':
44
+ return ref.invitation.expectedBindings.targetAgentId;
45
+ default:
46
+ // ANS names, private grants and external methods learn the target FROM the resolution; the
47
+ // publication's own `agentId` is then checked against whatever the caller expected.
48
+ return null;
49
+ }
50
+ }
51
+ function isPublication(v) {
52
+ if (!v || typeof v !== 'object')
53
+ return false;
54
+ const p = v;
55
+ return (p.specVersion === 'ap.agent-service-publication/1' &&
56
+ typeof p.agentId === 'string' &&
57
+ typeof p.channelId === 'string' &&
58
+ typeof p.digest === 'string' &&
59
+ Array.isArray(p.surfaces) &&
60
+ Array.isArray(p.proofs));
61
+ }
62
+ /**
63
+ * Build a resolver over several providers.
64
+ *
65
+ * Throws at construction if two providers claim the same reference kind — an ambiguity that would
66
+ * otherwise be resolved by array order, which is not a trust decision anyone intended to make.
67
+ */
68
+ export function createComposedResolver(opts) {
69
+ if (opts.providers.length === 0) {
70
+ throw new AgentResolutionError('malformed', 'agent-resolution: at least one provider is required');
71
+ }
72
+ const methods = opts.providers.map((p) => p.method);
73
+ const duplicate = methods.find((m, i) => methods.indexOf(m) !== i);
74
+ if (duplicate) {
75
+ throw new AgentResolutionError('malformed', `agent-resolution: duplicate provider method "${duplicate}"`);
76
+ }
77
+ return async function resolve(reference, context,
78
+ /** What the caller expected to reach. Required when the reference does not name an agent. */
79
+ expectedAgentId) {
80
+ // 1. Dispatch — exactly one provider, no fallback.
81
+ const matching = opts.providers.filter((p) => p.supports(reference));
82
+ if (matching.length === 0) {
83
+ return { ok: false, failures: [failure('reference_unsupported', `no provider supports reference kind "${reference.kind}"`)] };
84
+ }
85
+ if (matching.length > 1) {
86
+ return {
87
+ ok: false,
88
+ failures: [
89
+ failure('malformed', `ambiguous reference: ${matching.length} providers claim it`, {
90
+ methods: matching.map((p) => p.method),
91
+ }),
92
+ ],
93
+ };
94
+ }
95
+ const provider = matching[0];
96
+ // 2. Fetch. A provider that throws produced no answer — it does NOT hand off to another.
97
+ let bundle;
98
+ try {
99
+ bundle = await provider.resolve(reference, context);
100
+ }
101
+ catch {
102
+ return { ok: false, failures: [failure('malformed', `provider "${provider.method}" failed to resolve`)] };
103
+ }
104
+ if (!isPublication(bundle.publication)) {
105
+ return { ok: false, failures: [failure('malformed', 'provider returned no well-formed publication')] };
106
+ }
107
+ const publication = bundle.publication;
108
+ // 3. Which agent did we expect? The reference wins; otherwise the caller must say.
109
+ const expected = expectedAgentOf(reference) ?? expectedAgentId;
110
+ if (!expected) {
111
+ return {
112
+ ok: false,
113
+ failures: [
114
+ failure('malformed', 'expectedAgentId is required for a reference that does not name its target — otherwise the resolver decides who you reached'),
115
+ ],
116
+ };
117
+ }
118
+ // 4. Verify — the SAME path for every method. This is what composition is for.
119
+ const known = await opts.continuity?.get(publication.channelId);
120
+ const verified = await verifyPublication(publication, {
121
+ expectedAgentId: expected,
122
+ now: context.now,
123
+ verifier: opts.verifier,
124
+ authorityCheck: opts.authorityCheck,
125
+ known,
126
+ requireEndpointProof: opts.requireEndpointProof,
127
+ endpointControl: opts.endpointControl,
128
+ minEndpointAssurance: opts.minEndpointAssurance,
129
+ maxExposure: opts.maxExposure,
130
+ });
131
+ if (!verified.ok)
132
+ return { ok: false, failures: verified.failures };
133
+ // 5. Assurance ladder — enforced, not advisory.
134
+ const endpointVerified = opts.requireEndpointProof === true &&
135
+ opts.endpointControl !== undefined &&
136
+ publication.surfaces.length > 0 &&
137
+ publication.surfaces.every((s) => {
138
+ const a = verified.endpointAssurance[s.surfaceId];
139
+ return a === 'cryptographic' || a === 'observed';
140
+ });
141
+ // ── The post-resolve peer gate ───────────────────────────────────────
142
+ // Runs AFTER the publication verified (we need to know which agent to expect) and BEFORE the
143
+ // caller is handed anything it could send a task to. A refusal here fails the whole resolution:
144
+ // knowing where an agent said it lives is not the same as having reached that agent.
145
+ let peerAuthenticated = false;
146
+ if (opts.peer) {
147
+ const endpointUri = verified.publication?.surfaces[0]?.uri ?? '';
148
+ let peerContext;
149
+ try {
150
+ peerContext = await opts.peer.obtain({
151
+ expectedAgentId: verified.publication.agentId,
152
+ endpointUri,
153
+ });
154
+ }
155
+ catch {
156
+ // Could not establish ⇒ not established. Never "assume it was fine" (ADR-0013).
157
+ peerContext = undefined;
158
+ }
159
+ const gate = checkResolvedPeer({
160
+ expectedAgentId: verified.publication.agentId,
161
+ peer: peerContext,
162
+ policy: opts.peer.policy,
163
+ });
164
+ if (!gate.ok) {
165
+ return {
166
+ ok: false,
167
+ failures: gate.failures.map((f) => failure('peer_gate_refused', f.detail, { code: f.code })),
168
+ };
169
+ }
170
+ peerAuthenticated = peerAuthenticatedFrom(gate);
171
+ }
172
+ const assurance = assuranceOf({
173
+ signatureValid: verified.signatureValid,
174
+ publisherAuthorized: verified.publisherAuthorized,
175
+ endpointVerified,
176
+ peerAuthenticated,
177
+ });
178
+ if (opts.minAssurance && !meetsAssurance(assurance, opts.minAssurance)) {
179
+ return {
180
+ ok: false,
181
+ failures: [
182
+ failure('publication_signature_invalid', `resolution assurance "${assurance}" is weaker than the required "${opts.minAssurance}"`, {
183
+ assurance,
184
+ required: opts.minAssurance,
185
+ }),
186
+ ],
187
+ };
188
+ }
189
+ // 6. Only now advance continuity — a rejected publication must never move the anti-rollback mark.
190
+ if (opts.continuity) {
191
+ await opts.continuity.put(advanceContinuity(known, {
192
+ channelId: publication.channelId,
193
+ sequence: publication.sequence,
194
+ digest: publication.digest,
195
+ }));
196
+ }
197
+ const identityEvidence = [
198
+ { kind: 'publication-signature', source: provider.method, digest: publication.digest, observedAt: context.now },
199
+ ];
200
+ if (verified.publisherAuthorized) {
201
+ identityEvidence.push({
202
+ kind: 'publication-authority',
203
+ source: publication.publicationAuthorityRef,
204
+ observedAt: context.now,
205
+ });
206
+ }
207
+ const endpointEvidence = publication.surfaces
208
+ .filter((s) => s.endpointControlProof)
209
+ .map((s) => ({
210
+ kind: 'endpoint-control',
211
+ source: s.endpointControlProof.evidenceRef,
212
+ observedAt: s.endpointControlProof.verifiedAt,
213
+ }));
214
+ return {
215
+ ok: true,
216
+ resolution: {
217
+ canonicalAgentId: publication.agentId,
218
+ method: bundle.method,
219
+ referenceKind: reference.kind,
220
+ publication,
221
+ identityEvidence,
222
+ endpointEvidence,
223
+ assurance,
224
+ freshness: verified.freshness,
225
+ disclosure: {
226
+ projectionProfile: context.requestedProjection ?? 'public',
227
+ disclosedFields: verified.acceptedSurfaces.map((s) => s.surfaceId),
228
+ audienceBound: verified.acceptedSurfaces.some((s) => s.exposure === 'private'),
229
+ },
230
+ verifiedAt: context.now,
231
+ },
232
+ };
233
+ };
234
+ }
235
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sourceRoot":"","sources":["../src/compose.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG,oGAAoG;AACpG,mGAAmG;AACnG,6FAA6F;AAC7F,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG,0EAA0E;AAC1E,EAAE;AACF,iGAAiG;AACjG,qGAAqG;AACrG,6FAA6F;AAG7F,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAA2B,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAA0B,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAA+B,MA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;oBAC1D,eAAe,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;oBAClE,aAAa,EAAE,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC;iBAC/E;gBACD,UAAU,EAAE,OAAO,CAAC,GAAG;aACxB;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { type CanonicalAgentId } from '@agenticprimitives/types';
2
+ import { type ResolutionFailure } from './errors.js';
3
+ import type { EndpointControlProofV1 } from './publication.js';
4
+ import type { Erc1271Verifier } from './proof.js';
5
+ /** How strongly control of the endpoint was established. */
6
+ export type EndpointControlAssurance =
7
+ /** Nothing verified. */
8
+ 'none'
9
+ /** A well-formed, correctly-bound, fresh observation by a trusted observer. NOT re-checked here. */
10
+ | 'observed'
11
+ /** A signature by the agent over a body binding this exact uri + surface. Verified in-process. */
12
+ | 'cryptographic';
13
+ /**
14
+ * The body an agent signs to prove it controls an endpoint.
15
+ *
16
+ * Binding `uri` AND `surfaceId` AND `agentId` together is the point: a signature harvested for one
17
+ * surface cannot be replayed to claim control of another, and a challenge issued for one agent
18
+ * cannot be presented by a different one.
19
+ */
20
+ export interface EndpointChallengeBody {
21
+ uri: string;
22
+ agentId: CanonicalAgentId;
23
+ surfaceId: string;
24
+ /** High-entropy, issued by the verifier. A predictable challenge defeats the whole exercise. */
25
+ challenge: string;
26
+ issuedAt: string;
27
+ }
28
+ /** Evidence for `method: 'signed-challenge'` — fully verifiable here. */
29
+ export interface SignedChallengeEvidenceV1 {
30
+ kind: 'signed-challenge';
31
+ body: EndpointChallengeBody;
32
+ signature: `0x${string}`;
33
+ }
34
+ /** Evidence for the observation-based methods. Verified for binding + freshness, not re-performed. */
35
+ export interface ObservedControlEvidenceV1 {
36
+ kind: 'http-challenge' | 'dns' | 'verifiable-presentation' | 'transport-handshake';
37
+ uri: string;
38
+ agentId: CanonicalAgentId;
39
+ surfaceId: string;
40
+ /** Who performed the observation. A caller decides whether it trusts this observer. */
41
+ observedBy: CanonicalAgentId;
42
+ observedAt: string;
43
+ /** What was seen — e.g. the token found at a well-known path, or the TXT record value. */
44
+ observation: string;
45
+ /** The value the observer expected. Compared here so a mismatch is caught even if the observer wasn't careful. */
46
+ expected: string;
47
+ }
48
+ export type EndpointControlEvidenceV1 = SignedChallengeEvidenceV1 | ObservedControlEvidenceV1;
49
+ /** Resolves an `evidenceRef` to its body. Injected — evidence lives in a vault, and this is a leaf. */
50
+ export type EndpointEvidenceResolver = (evidenceRef: string) => Promise<EndpointControlEvidenceV1 | null>;
51
+ export interface VerifyEndpointControlOptions {
52
+ /** The surface being checked — proof must bind to THIS uri and surface, not merely to the agent. */
53
+ uri: string;
54
+ surfaceId: string;
55
+ agentId: CanonicalAgentId;
56
+ /** ISO-8601, injected. */
57
+ now: string;
58
+ verifier: Erc1271Verifier;
59
+ resolveEvidence: EndpointEvidenceResolver;
60
+ /** Maximum age of an OBSERVED proof. Defaults to 24h — an old observation is a weak claim. */
61
+ maxObservationAgeMs?: number;
62
+ /** Observers whose observations are accepted. Empty/absent ⇒ none are (fail-closed). */
63
+ trustedObservers?: readonly CanonicalAgentId[];
64
+ }
65
+ export interface EndpointControlResult {
66
+ ok: boolean;
67
+ assurance: EndpointControlAssurance;
68
+ failures: readonly ResolutionFailure[];
69
+ }
70
+ /**
71
+ * Normalize a URI for comparison so a cosmetic difference is not treated as a different endpoint —
72
+ * and, more importantly, so `https://acme.example` and `https://acme.example:443/` cannot be used to
73
+ * claim two different things about the same host.
74
+ *
75
+ * Deliberately conservative: scheme + host + port + path only. Query and fragment are dropped
76
+ * because they are not part of endpoint identity; userinfo is REJECTED because
77
+ * `https://evil@acme.example` is a classic confusion vector.
78
+ */
79
+ export declare function normalizeEndpointUri(uri: string): string | null;
80
+ /** The digest an agent signs for `signed-challenge`. */
81
+ export declare function endpointChallengeDigest(body: EndpointChallengeBody): Promise<`0x${string}`>;
82
+ /**
83
+ * Verify that the publisher controls the endpoint. Fail-closed: any missing, mis-bound, stale, or
84
+ * unverifiable evidence yields `ok: false`, and an unrecognized method is a failure rather than a pass.
85
+ */
86
+ export declare function verifyEndpointControl(proof: EndpointControlProofV1, opts: VerifyEndpointControlOptions): Promise<EndpointControlResult>;
87
+ //# sourceMappingURL=endpoint-control.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-control.d.ts","sourceRoot":"","sources":["../src/endpoint-control.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,OAAO,EAAW,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,4DAA4D;AAC5D,MAAM,MAAM,wBAAwB;AAClC,wBAAwB;AACtB,MAAM;AACR,oGAAoG;GAClG,UAAU;AACZ,kGAAkG;GAChG,eAAe,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,gBAAgB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,gGAAgG;IAChG,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,yEAAyE;AACzE,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,kBAAkB,CAAC;IACzB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,SAAS,EAAE,KAAK,MAAM,EAAE,CAAC;CAC1B;AAED,sGAAsG;AACtG,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,yBAAyB,GAAG,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