@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.
- package/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/admission.d.ts +14 -0
- package/dist/admission.d.ts.map +1 -0
- package/dist/admission.js +137 -0
- package/dist/admission.js.map +1 -0
- package/dist/authority-ref.d.ts +38 -0
- package/dist/authority-ref.d.ts.map +1 -0
- package/dist/authority-ref.js +69 -0
- package/dist/authority-ref.js.map +1 -0
- package/dist/canonicalization.d.ts +16 -0
- package/dist/canonicalization.d.ts.map +1 -0
- package/dist/canonicalization.js +39 -0
- package/dist/canonicalization.js.map +1 -0
- package/dist/codec.d.ts +15 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +34 -0
- package/dist/codec.js.map +1 -0
- package/dist/compose.d.ts +79 -0
- package/dist/compose.d.ts.map +1 -0
- package/dist/compose.js +235 -0
- package/dist/compose.js.map +1 -0
- package/dist/endpoint-control.d.ts +87 -0
- package/dist/endpoint-control.d.ts.map +1 -0
- package/dist/endpoint-control.js +174 -0
- package/dist/endpoint-control.js.map +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/freshness.d.ts +43 -0
- package/dist/freshness.d.ts.map +1 -0
- package/dist/freshness.js +100 -0
- package/dist/freshness.js.map +1 -0
- package/dist/grant-index.d.ts +21 -0
- package/dist/grant-index.d.ts.map +1 -0
- package/dist/grant-index.js +0 -0
- package/dist/grant-index.js.map +1 -0
- package/dist/grants.d.ts +100 -0
- package/dist/grants.d.ts.map +1 -0
- package/dist/grants.js +99 -0
- package/dist/grants.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/invitation.d.ts +43 -0
- package/dist/invitation.d.ts.map +1 -0
- package/dist/invitation.js +76 -0
- package/dist/invitation.js.map +1 -0
- package/dist/peer-attestation.d.ts +61 -0
- package/dist/peer-attestation.d.ts.map +1 -0
- package/dist/peer-attestation.js +128 -0
- package/dist/peer-attestation.js.map +1 -0
- package/dist/peer-gate.d.ts +73 -0
- package/dist/peer-gate.d.ts.map +1 -0
- package/dist/peer-gate.js +108 -0
- package/dist/peer-gate.js.map +1 -0
- package/dist/policy.d.ts +53 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +73 -0
- package/dist/policy.js.map +1 -0
- package/dist/ports.d.ts +59 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +10 -0
- package/dist/ports.js.map +1 -0
- package/dist/projection.d.ts +74 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +134 -0
- package/dist/projection.js.map +1 -0
- package/dist/proof.d.ts +76 -0
- package/dist/proof.d.ts.map +1 -0
- package/dist/proof.js +207 -0
- package/dist/proof.js.map +1 -0
- package/dist/publication.d.ts +123 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +32 -0
- package/dist/publication.js.map +1 -0
- package/dist/records.d.ts +168 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +83 -0
- package/dist/records.js.map +1 -0
- package/dist/references.d.ts +61 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/references.js +7 -0
- package/dist/references.js.map +1 -0
- package/dist/results.d.ts +89 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +37 -0
- package/dist/results.js.map +1 -0
- package/package.json +57 -0
- package/spec.md +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# @agenticprimitives/agent-resolution
|
|
2
|
+
|
|
3
|
+
**Every agent has a canonical identity. Naming is optional. Public listing is optional. Inbound
|
|
4
|
+
addressability is optional. Authorized private resolution is a first-class capability.**
|
|
5
|
+
|
|
6
|
+
Provider-neutral primitives for answering *"may this party discover how to reach this agent, and
|
|
7
|
+
where is it right now?"* — with a hard wall between that question and *"may this party use it?"*
|
|
8
|
+
|
|
9
|
+
Spec: `[specs/338](https://github.com/agentictrustlabs/agenticprimitives/blob/master/specs/338-private-agent-resolution-and-service-publication.md)` ·
|
|
10
|
+
Doctrine: [ADR-0056](https://github.com/agentictrustlabs/agenticprimitives/blob/master/docs/architecture/decisions/0056-resolution-is-not-authority-private-agent-resolution.md)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## The rule
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
A resolution grant answers: "May this party DISCOVER how to reach this agent?"
|
|
18
|
+
It NEVER answers: "May this party USE this agent?"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Successful resolution gives you an endpoint and a verified peer identity. Invocation still requires
|
|
22
|
+
the whole chain, re-run at the origin:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
delegation ∩ entitlement ∩ tool/action policy ∩ exact invocation proof ∩ revocation ∩ audit
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Resolution is one of **four orthogonal concerns** with **custody** ("who signed"), **admission**
|
|
29
|
+
("may these bytes enter"), and **authority** ("what may this principal do"). A *yes* to one is never
|
|
30
|
+
a *yes* to another.
|
|
31
|
+
|
|
32
|
+
## Four independent dimensions
|
|
33
|
+
|
|
34
|
+
"Nameless" = no public label only. Listing, resolution, and inbound are modelled separately.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
| Posture | naming | listing | resolution | inbound |
|
|
38
|
+
| ------------------------------ | --------------- | -------- | --------------- | --------------------- |
|
|
39
|
+
| Public commercial agent | `public` | `public` | `public` | `delegation-required` |
|
|
40
|
+
| Public name, protected details | `public` | `public` | `authenticated` | `delegation-required` |
|
|
41
|
+
| Private partner agent | `private-label` | `none` | `invitation` | `known-peer` |
|
|
42
|
+
| Pairwise treasury agent | `private-label` | `none` | `pairwise` | `delegation-required` |
|
|
43
|
+
| Unnamed internal worker | `none` | `none` | `invitation` | `known-peer` |
|
|
44
|
+
| Temporary direct agent | `none` | `none` | `direct` | `delegation-required` |
|
|
45
|
+
| Background outbound worker | `none` | `none` | `none` | `outbound-only` |
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { discoveryPolicyFromPreset, validateDiscoveryPolicy } from '@agenticprimitives/agent-resolution';
|
|
50
|
+
|
|
51
|
+
const policy = discoveryPolicyFromPreset('private-partner');
|
|
52
|
+
validateDiscoveryPolicy(policy); // [] — combinations that cannot be enforced are rejected
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Every path resolves to the same canonical identity: `eip155:<chainId>:<SmartAgentAddress>`.
|
|
56
|
+
|
|
57
|
+
## Worked flow — Agent A reaches a nameless treasury (Agent B)
|
|
58
|
+
|
|
59
|
+
Scenario: **Agent A** (caller SA for a person/org) must call **Agent B** (treasury service SA) over
|
|
60
|
+
A2A. B has **no public ANS name** (`naming: none`, `listing: none`). Reachability is invitation /
|
|
61
|
+
private-grant resolution — not a public label.
|
|
62
|
+
|
|
63
|
+
**Where the A2A URL comes from:** it is **not** invented by the private resolver and **not** looked
|
|
64
|
+
up by name. It is a field on a signed `AgentServicePublicationV1`:
|
|
65
|
+
|
|
66
|
+
`publication.surfaces[]` → entry with `protocol: 'a2a'` → **`uri`** (e.g. `https://xyz.example/a2a/v1`).
|
|
67
|
+
|
|
68
|
+
The resolver only **admits** Alice’s grant and **selects** a pre-signed publication from B’s owner
|
|
69
|
+
vault (`selectPresignedPublication` — select, never edit). Alice extracts the URI **after**
|
|
70
|
+
`verifyPublication` on her side.
|
|
71
|
+
|
|
72
|
+
### Diagrams
|
|
73
|
+
|
|
74
|
+
**1. Conceptual flow** — nameless Agent A → treasury Agent B (terms used everywhere below):
|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+
*Agent A → nameless treasury B. Vault holds signed publication (A2A `uri` in `surfaces[]`),
|
|
79
|
+
subject-bound grant, publication authority. Steps: issue grant → invitation
|
|
80
|
+
(`initialPublication` + rendezvous) → first dial or resolver refresh
|
|
81
|
+
(`selectPresignedPublication`) → A2A + delegation. Resolver never forges the endpoint.*
|
|
82
|
+
|
|
83
|
+
**2. Local architecture** — same terms → monorepo Workers:
|
|
84
|
+
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
*`demo-web-pro` / `demo-sso-next` = Agent A; `demo-resolver` `:8795` = private resolver;
|
|
88
|
+
`demo-publications` `:8796` = pub store; `demo-a2a` `:8787` = B’s A2A host (URI in publication).
|
|
89
|
+
Optional `demo-edge`. Steps match diagram 1. Live treasury may still use a known URL + delegation;
|
|
90
|
+
private resolve is the parallel Ring-1 path.*
|
|
91
|
+
|
|
92
|
+
| Step | What moves | A2A endpoint? |
|
|
93
|
+
| --- | --- | --- |
|
|
94
|
+
| 1 | B issues `PrivateResolutionGrantV1` (subject-bound to A) | no — grant = may *discover* |
|
|
95
|
+
| 2 | Invitation to A = **initialPublication** + grant + rendezvous | **yes** — URI already inside `initialPublication.surfaces[]` |
|
|
96
|
+
| 3a | First connect: A verifies that publication locally | URI from verified publication (no resolver hop) |
|
|
97
|
+
| 3b | Refresh: A → resolver → `selectPresignedPublication` → A verifies | **yes** — URI from the **selected publication’s** `surfaces[]`, not from resolver logic |
|
|
98
|
+
| 4 | A2A task + delegation ∩ entitlement ∩ policy | use, not resolve |
|
|
99
|
+
|
|
100
|
+
**Nameless** = no public label. **Publication authority** = endpoint/session-key rotation is an ops
|
|
101
|
+
publish, not a custody ceremony. **Delegation** = what lets A invoke treasury skills after the URL
|
|
102
|
+
is known.
|
|
103
|
+
|
|
104
|
+
```mermaid
|
|
105
|
+
sequenceDiagram
|
|
106
|
+
autonumber
|
|
107
|
+
participant B as Agent B treasury SA
|
|
108
|
+
participant Vault as B owner vault
|
|
109
|
+
participant R as Private resolver
|
|
110
|
+
participant A as Agent A
|
|
111
|
+
participant A2A as B A2A host<br/>xyz…/a2a/v1
|
|
112
|
+
|
|
113
|
+
B->>Vault: Store signed AgentServicePublicationV1<br/>surfaces: [{protocol:a2a, uri}]
|
|
114
|
+
B->>Vault: Issue PrivateResolutionGrantV1 subject=A
|
|
115
|
+
B-->>A: Invitation = initialPublication + grant + rendezvous
|
|
116
|
+
|
|
117
|
+
Note over A: Resolve — endpoint is in the publication
|
|
118
|
+
A->>A: verifyPublication(initialPublication)
|
|
119
|
+
A->>A: a2aUrl = surfaces.find(p=>p.protocol==='a2a').uri
|
|
120
|
+
|
|
121
|
+
opt Endpoint moved — same grant
|
|
122
|
+
A->>R: Present grant + PoP
|
|
123
|
+
R->>Vault: Admit + selectPresignedPublication
|
|
124
|
+
R-->>A: Pre-signed publication (includes new uri)
|
|
125
|
+
A->>A: verifyPublication → read surfaces[].uri again
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
A->>A2A: Open channel to a2aUrl
|
|
129
|
+
A->>A2A: Task + delegation (other packages)
|
|
130
|
+
alt Authority OK
|
|
131
|
+
A2A-->>A: Result
|
|
132
|
+
else Resolution grant only
|
|
133
|
+
A2A-->>A: Denied — resolution ≠ use
|
|
134
|
+
end
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Local apps — term → Worker map
|
|
138
|
+
|
|
139
|
+
| Conceptual term | Local app |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| Agent A app | `demo-web-pro`; invite inspect `demo-sso-next` `/visibility` |
|
|
142
|
+
| Agent B A2A host | `demo-a2a` `:8787` — `/api/a2a`, `A2aTaskDO` |
|
|
143
|
+
| Private resolver | `demo-resolver` `:8795` — `/v1/private/{challenge,resolve}` |
|
|
144
|
+
| B vault (demo stand-in) | `demo-publications` `:8796` — `/v1/publications` |
|
|
145
|
+
| A2A `uri` | Inside publication `surfaces[]` → e.g. `http://127.0.0.1:8787/api/a2a` |
|
|
146
|
+
| Optional edge | `demo-edge` — `/api/a2a/<handle>` |
|
|
147
|
+
| Use (not resolve) | Delegation gates in `demo-a2a` |
|
|
148
|
+
|
|
149
|
+
## Worked sequence — DNTLS as a Ring-1 resolution provider
|
|
150
|
+
|
|
151
|
+
DNTLS is **not** a dependency. A Ring-1 `AgentResolutionProvider` (`method: 'dntls'`) maps a Service
|
|
152
|
+
Record → `AgentServicePublicationV1`; `createComposedResolver` verifies SA binding (spec 338 §18).
|
|
153
|
+
Namespace membership may be a **policy predicate**, never the grant. **Bidirectional binding
|
|
154
|
+
required.** DNTLS alone never grants identity, delegation, MCP/A2A permission, entitlement, or custody.
|
|
155
|
+
|
|
156
|
+
```mermaid
|
|
157
|
+
sequenceDiagram
|
|
158
|
+
autonumber
|
|
159
|
+
participant D as DNTLS resolver<br/>(external)
|
|
160
|
+
participant Adapt as dntls provider<br/>(Ring-1)
|
|
161
|
+
participant AP as createComposedResolver
|
|
162
|
+
actor A as Agent A
|
|
163
|
+
participant A2A as B A2A host
|
|
164
|
+
|
|
165
|
+
A->>AP: resolve({ kind:'external', method:'dntls', identifier })
|
|
166
|
+
AP->>Adapt: resolve(reference, context)
|
|
167
|
+
Adapt->>D: Resolve name / commitment
|
|
168
|
+
D-->>Adapt: Service Record + proof
|
|
169
|
+
Adapt->>Adapt: Map → AgentServicePublicationV1
|
|
170
|
+
Adapt-->>AP: UnverifiedResolutionBundleV1
|
|
171
|
+
AP->>AP: verifyPublication + SA↔DNTLS binding<br/>+ authorityCheck + continuity
|
|
172
|
+
alt Fail
|
|
173
|
+
AP-->>A: resolution failure
|
|
174
|
+
else OK
|
|
175
|
+
AP-->>A: VerifiedAgentResolutionV1<br/>(reachability only)
|
|
176
|
+
end
|
|
177
|
+
A->>A2A: Open surface URI + AP delegation
|
|
178
|
+
A2A->>A2A: delegation ∩ entitlement ∩ policy
|
|
179
|
+
alt Authority OK
|
|
180
|
+
A2A-->>A: Result + receipt
|
|
181
|
+
else Resolution-only
|
|
182
|
+
A2A-->>A: Denied — resolution ≠ use
|
|
183
|
+
end
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Illustrative adapter (ports are real; DNTLS client/wire is external and not shipped):
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import {
|
|
190
|
+
createComposedResolver,
|
|
191
|
+
type AgentResolutionProvider,
|
|
192
|
+
type AgentServicePublicationV1,
|
|
193
|
+
} from '@agenticprimitives/agent-resolution';
|
|
194
|
+
|
|
195
|
+
// Ring-1: map DNTLS Service Record → AgentServicePublicationV1
|
|
196
|
+
// (agentId, channelId, sequence, surfaces[].uri/protocol, transportKeyBinding,
|
|
197
|
+
// publishedBy, publicationAuthorityRef, digest, proofs[] — then ERC-1271 sign)
|
|
198
|
+
declare function mapDntlsRecord(record: unknown): AgentServicePublicationV1;
|
|
199
|
+
declare const externalDntlsClient: { resolve(id: string): Promise<{ record: unknown; proof: unknown }> };
|
|
200
|
+
|
|
201
|
+
const dntlsProvider: AgentResolutionProvider = {
|
|
202
|
+
method: 'dntls',
|
|
203
|
+
supports: (ref) => ref.kind === 'external' && ref.method === 'dntls',
|
|
204
|
+
async resolve(ref, _ctx) {
|
|
205
|
+
if (ref.kind !== 'external') throw new Error('unsupported');
|
|
206
|
+
const { record, proof } = await externalDntlsClient.resolve(ref.identifier);
|
|
207
|
+
return {
|
|
208
|
+
method: 'dntls',
|
|
209
|
+
referenceKind: 'external',
|
|
210
|
+
publication: mapDntlsRecord(record),
|
|
211
|
+
providerEvidence: [proof],
|
|
212
|
+
servedAt: new Date().toISOString(),
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const resolve = createComposedResolver({
|
|
218
|
+
providers: [dntlsProvider],
|
|
219
|
+
verifier: publicClient,
|
|
220
|
+
// authorityCheck should also require AP facet → DNTLS commitment (bidirectional)
|
|
221
|
+
authorityCheck,
|
|
222
|
+
minAssurance: 'signed-publication',
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const result = await resolve(
|
|
226
|
+
{ kind: 'external', method: 'dntls', identifier: 'treasury.ops.acme.dntls' },
|
|
227
|
+
{ requester: 'eip155:84532:0xaaa…', now: new Date().toISOString() },
|
|
228
|
+
'eip155:84532:0xbbb…',
|
|
229
|
+
);
|
|
230
|
+
// result.ok ⇒ VerifiedAgentResolutionV1 — still no spend / tool permission
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Full audit: [`dntls-comparison.md`](../../docs/architecture/dntls-comparison.md).
|
|
234
|
+
|
|
235
|
+
## A hash proves *unmodified*. It does not prove *current*.
|
|
236
|
+
|
|
237
|
+
A signed card proves nobody tampered with a snapshot — not that it is still in force. So every
|
|
238
|
+
publication carries a monotonic `sequence`, `previousDigest`, `status`, and `expiresAt`.
|
|
239
|
+
Verification is fail-closed (rollback, equivocation, expiry, unauthorized publisher, missing
|
|
240
|
+
endpoint-control proof, out-of-window transport keys):
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
import { verifyPublication } from '@agenticprimitives/agent-resolution';
|
|
244
|
+
|
|
245
|
+
const result = await verifyPublication(publication, {
|
|
246
|
+
expectedAgentId: 'eip155:84532:0xacme…',
|
|
247
|
+
now: new Date().toISOString(),
|
|
248
|
+
verifier: publicClient, // any { verifyHash } — a viem PublicClient fits
|
|
249
|
+
authorityCheck, // "was this publisher allowed to publish for this agent?"
|
|
250
|
+
known: continuity, // what we already accepted on this channel
|
|
251
|
+
requireEndpointProof: true,
|
|
252
|
+
maxExposure: 'private',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (!result.ok) {
|
|
256
|
+
// Precise codes for YOUR logs; result.failures[].wireCode for anything you return to a caller.
|
|
257
|
+
if (result.freshness.conflict) escalate('publisher equivocation — possible key compromise');
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Equivocation — two validly signed publications at the same sequence — is *reported*, not merely
|
|
262
|
+
rejected. It is evidence of publisher-key compromise, not a transient error.
|
|
263
|
+
|
|
264
|
+
### Rotation is cheap; identity never moves
|
|
265
|
+
|
|
266
|
+
Endpoint change, transport-key rotation, regional failover, protocol bump, and provider migration
|
|
267
|
+
all republish at `sequence + 1`. **No grant is reissued and the canonical agent id does not change.**
|
|
268
|
+
|
|
269
|
+
## Private resolution grants, not private names
|
|
270
|
+
|
|
271
|
+
Salted private *names* are rejected (low-entropy secret, name becomes load-bearing). Grants are
|
|
272
|
+
opaque high-entropy capabilities (`apd1_…`), recipient-bound:
|
|
273
|
+
|
|
274
|
+
| Mode | Use |
|
|
275
|
+
| --- | --- |
|
|
276
|
+
| `subject-bound` *(default)* | Presenter proves subject SA possession — a copy is useless to others |
|
|
277
|
+
| `pairwise` | Distinct grant/projection/history per relationship |
|
|
278
|
+
| `bearer-bootstrap` | Short-lived only until the recipient has an SA |
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
const admission = await admitGrantPresentation(presentation, deps, {
|
|
282
|
+
resolverAudience: 'https://resolve.acme.example/v1/private',
|
|
283
|
+
});
|
|
284
|
+
admission.projectionProfile; // 'partner' — what may be DISCLOSED, never invoked
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Wire denials all use `resolution_denied` (no enumeration oracle); precise codes stay local.
|
|
288
|
+
|
|
289
|
+
## Bootstrap, resolver, storage
|
|
290
|
+
|
|
291
|
+
Invitation = initial publication + grant + rendezvous + expected bindings (no re-invite on endpoint
|
|
292
|
+
rotation). Org rendezvous reveals only that a private resolution service exists — replaceable, not
|
|
293
|
+
the publication authority, cannot forge target-signed pubs or grant use. `findOverDisclosure`
|
|
294
|
+
catches over-disclosure.
|
|
295
|
+
|
|
296
|
+
**Owner vault** (authoritative): pubs, grants, revocation, aliases. **Resolver vault** (ops only):
|
|
297
|
+
keyed grant index, nonces, budgets — never the sole copy of anything that matters.
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
const digest = await deriveGrantDigest(grantId, resolverIndexSecret); // HMAC; 32-byte secret
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Scope
|
|
304
|
+
|
|
305
|
+
**Owns:** discovery policy · publication verify · freshness · grants · invitations · projection ·
|
|
306
|
+
errors · provider ports. **Not:** transport, storage, clocks, authZ, naming, directory, search,
|
|
307
|
+
profile, surface-catalog. Ring-0 (`types` only); ANS / rendezvous / DNTLS / DID are Ring-1.
|
|
308
|
+
|
|
309
|
+
## Install
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
pnpm add @agenticprimitives/agent-resolution
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
## License
|
|
318
|
+
|
|
319
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ResolutionGrantPresentationV1 } from './grants.js';
|
|
2
|
+
import type { GrantAdmissionResult, ResolverDependencies } from './ports.js';
|
|
3
|
+
export interface AdmitGrantOptions {
|
|
4
|
+
/** The resolver's own audience id. A grant bound elsewhere MUST NOT be accepted here. */
|
|
5
|
+
resolverAudience: string;
|
|
6
|
+
/** Maximum clock skew tolerated on the presentation timestamp. */
|
|
7
|
+
maxPresentationAgeMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Admit (or deny) a presented resolution grant. Never throws on a denial — returns precise, LOCAL
|
|
11
|
+
* failures so the resolver can log them privately while returning a uniform wire code.
|
|
12
|
+
*/
|
|
13
|
+
export declare function admitGrantPresentation(presentation: ResolutionGrantPresentationV1, deps: ResolverDependencies, opts: AdmitGrantOptions): Promise<GrantAdmissionResult>;
|
|
14
|
+
//# sourceMappingURL=admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../src/admission.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,6BAA6B,EACnC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,gBAAgB,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,6BAA6B,EAC3C,IAAI,EAAE,oBAAoB,EAC1B,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,oBAAoB,CAAC,CAoI/B"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Grant admission — "may this presenter discover this agent?" (spec 338 §7).
|
|
2
|
+
//
|
|
3
|
+
// This is the ONE question a resolution grant answers. Admission yields a projection profile, never
|
|
4
|
+
// a token, scope, or capability to invoke (ADR-0056 §1). A consumer that treats `GrantAdmissionResult`
|
|
5
|
+
// as authorization has made the precise error this ADR exists to prevent.
|
|
6
|
+
//
|
|
7
|
+
// Check ORDER is deliberate: cheap static checks before any storage read, and storage reads before
|
|
8
|
+
// the expensive signature verification, so an attacker cannot use an oversized or malformed
|
|
9
|
+
// presentation to make the resolver do costly work (spec 338 §16, abuse tests).
|
|
10
|
+
//
|
|
11
|
+
// Every failure returns the SAME wire code (`resolution_denied`, see `errors.ts`). Distinguishing
|
|
12
|
+
// "unknown grant" from "expired grant" on the wire is an enumeration oracle.
|
|
13
|
+
import { failure } from './errors.js';
|
|
14
|
+
import { RESOLVE_ACTION, validateGrantShape, } from './grants.js';
|
|
15
|
+
const DEFAULT_MAX_PRESENTATION_AGE_MS = 2 * 60 * 1000;
|
|
16
|
+
/**
|
|
17
|
+
* Admit (or deny) a presented resolution grant. Never throws on a denial — returns precise, LOCAL
|
|
18
|
+
* failures so the resolver can log them privately while returning a uniform wire code.
|
|
19
|
+
*/
|
|
20
|
+
export async function admitGrantPresentation(presentation, deps, opts) {
|
|
21
|
+
const failures = [];
|
|
22
|
+
const deny = () => ({ admitted: false, failures });
|
|
23
|
+
const now = deps.now();
|
|
24
|
+
const nowMs = Date.parse(now);
|
|
25
|
+
// 1. Audience — before any lookup. A grant minted for another resolver must never be honoured
|
|
26
|
+
// here, or this resolver becomes a confused deputy for that one.
|
|
27
|
+
if (presentation.audience !== opts.resolverAudience) {
|
|
28
|
+
failures.push(failure('grant_audience_mismatch', 'presentation audience does not match this resolver', {
|
|
29
|
+
expected: opts.resolverAudience,
|
|
30
|
+
got: presentation.audience,
|
|
31
|
+
}));
|
|
32
|
+
return deny();
|
|
33
|
+
}
|
|
34
|
+
// 2. Presentation timestamp — cheap staleness rejection before storage.
|
|
35
|
+
const tsMs = Date.parse(presentation.timestamp);
|
|
36
|
+
const maxAge = opts.maxPresentationAgeMs ?? DEFAULT_MAX_PRESENTATION_AGE_MS;
|
|
37
|
+
if (Number.isNaN(tsMs) || Number.isNaN(nowMs)) {
|
|
38
|
+
failures.push(failure('malformed', 'presentation timestamp is not a parseable ISO-8601 value'));
|
|
39
|
+
return deny();
|
|
40
|
+
}
|
|
41
|
+
if (Math.abs(nowMs - tsMs) > maxAge) {
|
|
42
|
+
failures.push(failure('grant_expired', 'presentation timestamp is outside the accepted window'));
|
|
43
|
+
return deny();
|
|
44
|
+
}
|
|
45
|
+
// 3. Nonce — single use. Consumed BEFORE the signature check so a replayed presentation cannot be
|
|
46
|
+
// used to make the resolver repeatedly perform signature verification.
|
|
47
|
+
const nonceFresh = await deps.store.consumeChallengeNonce(presentation.challengeNonce, presentation.audience);
|
|
48
|
+
if (!nonceFresh) {
|
|
49
|
+
failures.push(failure('grant_challenge_replayed', 'challenge nonce was already spent'));
|
|
50
|
+
return deny();
|
|
51
|
+
}
|
|
52
|
+
// 4. Lookup.
|
|
53
|
+
const grant = await deps.store.findByGrantId(presentation.grantId);
|
|
54
|
+
if (!grant) {
|
|
55
|
+
failures.push(failure('grant_unknown', 'no such grant'));
|
|
56
|
+
return deny();
|
|
57
|
+
}
|
|
58
|
+
// 5. Static shape — a stored grant that violates its own invariants is not honoured.
|
|
59
|
+
// Uses `grant_shape_invalid`, NOT `malformed`: this outcome is only reachable after a
|
|
60
|
+
// successful lookup, so a distinguishable wire code here would tell an attacker that the
|
|
61
|
+
// grant id exists. It denies uniformly like every other post-lookup failure.
|
|
62
|
+
const shape = validateGrantShape(grant);
|
|
63
|
+
if (shape.length > 0) {
|
|
64
|
+
failures.push(...shape.map((v) => failure('grant_shape_invalid', `stored grant violates its shape: ${v.message}`, { field: v.field })));
|
|
65
|
+
return deny();
|
|
66
|
+
}
|
|
67
|
+
// 6. Action.
|
|
68
|
+
if (!grant.actions.includes(RESOLVE_ACTION)) {
|
|
69
|
+
failures.push(failure('grant_action_not_permitted', `grant does not carry "${RESOLVE_ACTION}"`));
|
|
70
|
+
return deny();
|
|
71
|
+
}
|
|
72
|
+
// 7. Validity window.
|
|
73
|
+
const notBefore = Date.parse(grant.constraints.notBefore);
|
|
74
|
+
const expiresAt = Date.parse(grant.constraints.expiresAt);
|
|
75
|
+
if (nowMs < notBefore) {
|
|
76
|
+
failures.push(failure('grant_not_yet_valid', 'grant is not yet valid'));
|
|
77
|
+
return deny();
|
|
78
|
+
}
|
|
79
|
+
if (nowMs >= expiresAt) {
|
|
80
|
+
failures.push(failure('grant_expired', 'grant has expired'));
|
|
81
|
+
return deny();
|
|
82
|
+
}
|
|
83
|
+
// 8. Grant's own audience binding — the stored grant must also name this resolver.
|
|
84
|
+
if (grant.constraints.audience !== opts.resolverAudience) {
|
|
85
|
+
failures.push(failure('grant_audience_mismatch', 'grant is bound to a different resolver audience'));
|
|
86
|
+
return deny();
|
|
87
|
+
}
|
|
88
|
+
// 9. Revocation — authoritative in the issuer's vault.
|
|
89
|
+
if (await deps.store.isRevoked(grant.grantId)) {
|
|
90
|
+
failures.push(failure('grant_revoked', 'grant has been revoked'));
|
|
91
|
+
return deny();
|
|
92
|
+
}
|
|
93
|
+
// 10. Proof of possession — the expensive check, last. This is what makes a copied grant useless.
|
|
94
|
+
if (grant.constraints.requireProofOfPossession) {
|
|
95
|
+
if (!grant.subject) {
|
|
96
|
+
failures.push(failure('grant_subject_mismatch', 'grant requires proof of possession but names no subject'));
|
|
97
|
+
return deny();
|
|
98
|
+
}
|
|
99
|
+
if (!presentation.subjectProof) {
|
|
100
|
+
failures.push(failure('grant_proof_of_possession_failed', 'grant requires proof of possession; none presented'));
|
|
101
|
+
return deny();
|
|
102
|
+
}
|
|
103
|
+
if (presentation.subjectProof.subject !== grant.subject) {
|
|
104
|
+
failures.push(failure('grant_subject_mismatch', 'presented subject is not the grant subject'));
|
|
105
|
+
return deny();
|
|
106
|
+
}
|
|
107
|
+
let proofOk = false;
|
|
108
|
+
try {
|
|
109
|
+
proofOk = await deps.verifySubjectProof({
|
|
110
|
+
subject: grant.subject,
|
|
111
|
+
presentation,
|
|
112
|
+
targetAgent: grant.targetAgent,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// A verifier that errors did not verify. No fallback to a weaker check (ADR-0013).
|
|
117
|
+
proofOk = false;
|
|
118
|
+
}
|
|
119
|
+
if (!proofOk) {
|
|
120
|
+
failures.push(failure('grant_proof_of_possession_failed', 'subject proof did not verify'));
|
|
121
|
+
return deny();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 11. Budget — consumed LAST so a denied presentation never burns the recipient's quota.
|
|
125
|
+
const budget = await deps.store.consumeResolution(grant.grantId);
|
|
126
|
+
if (!budget.allowed) {
|
|
127
|
+
failures.push(failure('grant_resolution_budget_exhausted', 'grant resolution budget is exhausted'));
|
|
128
|
+
return deny();
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
admitted: true,
|
|
132
|
+
grant,
|
|
133
|
+
projectionProfile: grant.projection.profile,
|
|
134
|
+
failures: [],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.js","sourceRoot":"","sources":["../src/admission.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,oGAAoG;AACpG,uGAAuG;AACvG,0EAA0E;AAC1E,EAAE;AACF,mGAAmG;AACnG,4FAA4F;AAC5F,gFAAgF;AAChF,EAAE;AACF,kGAAkG;AAClG,6EAA6E;AAE7E,OAAO,EAAE,OAAO,EAA0B,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,kBAAkB,GAGnB,MAAM,aAAa,CAAC;AAUrB,MAAM,+BAA+B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,YAA2C,EAC3C,IAA0B,EAC1B,IAAuB;IAEvB,MAAM,QAAQ,GAAwB,EAAE,CAAC;IACzC,M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a future authority form is a new prefix, never a reinterpretation. */
|
|
2
|
+
export declare const DELEGATION_AUTHORITY_SCHEME = "apdel1:";
|
|
3
|
+
export type AuthorityRefKind =
|
|
4
|
+
/** The agent acted for itself; no delegation is involved or expected. */
|
|
5
|
+
{
|
|
6
|
+
kind: 'self';
|
|
7
|
+
}
|
|
8
|
+
/** A delegation authorized the act. `delegationHash` MUST equal `hashDelegation(d)`. */
|
|
9
|
+
| {
|
|
10
|
+
kind: 'delegation';
|
|
11
|
+
delegationHash: `0x${string}`;
|
|
12
|
+
}
|
|
13
|
+
/** Not a form we understand. ALWAYS deny — never treat an unknown ref as self-issuance. */
|
|
14
|
+
| {
|
|
15
|
+
kind: 'unrecognized';
|
|
16
|
+
reason: string;
|
|
17
|
+
};
|
|
18
|
+
/** Build the ref an issuer signs when acting under a delegation. */
|
|
19
|
+
export declare function delegationAuthorityRef(delegationHash: `0x${string}`): string;
|
|
20
|
+
/** The ref an agent signs when acting for itself. */
|
|
21
|
+
export declare const SELF_AUTHORITY_REF = "";
|
|
22
|
+
/**
|
|
23
|
+
* Parse an `authorityRef`. Total — never throws, never guesses.
|
|
24
|
+
*
|
|
25
|
+
* An unparseable ref returns `unrecognized`, which callers MUST deny. That direction matters: the
|
|
26
|
+
* failure mode we are avoiding is a malformed ref falling through to the self-issuance branch, which
|
|
27
|
+
* would let anyone publish for anyone by sending garbage.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseAuthorityRef(ref: string | undefined | null): AuthorityRefKind;
|
|
30
|
+
/**
|
|
31
|
+
* Does this ref commit to this delegation?
|
|
32
|
+
*
|
|
33
|
+
* Case-insensitive on the hex (a caller may hold a checksummed hash) but otherwise exact — a ref that
|
|
34
|
+
* commits to a different delegation is a substituted authority, which is the whole attack this
|
|
35
|
+
* commitment exists to stop.
|
|
36
|
+
*/
|
|
37
|
+
export declare function authorityRefMatches(ref: string, delegationHash: `0x${string}`): boolean;
|
|
38
|
+
//# sourceMappingURL=authority-ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-ref.d.ts","sourceRoot":"","sources":["../src/authority-ref.ts"],"names":[],"mappings":"AA8BA,qGAAqG;AACrG,eAAO,MAAM,2BAA2B,YAAY,CAAC;AAErD,MAAM,MAAM,gBAAgB;AAC1B,yEAAyE;AACvE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;AAClB,wFAAwF;GACtF;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,cAAc,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE;AACvD,2FAA2F;GACzF;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAI7C,oEAAoE;AACpE,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM,CAE5E;AAED,qDAAqD;AACrD,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,gBAAgB,CAalF;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,MAAM,EAAE,GAAG,OAAO,CAGvF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// What an `authorityRef` IS (spec 338 §3, §4; ADR-0056).
|
|
2
|
+
//
|
|
3
|
+
// HISTORY, BECAUSE IT EXPLAINS THE SHAPE: this package used to define its own
|
|
4
|
+
// `PublicationAuthorityRecordV1` — a bespoke record with `publisher`, `notBefore`, `expiresAt`,
|
|
5
|
+
// `revokedAt` and a `proof`, plus a reference checker that read them. That record was a delegation
|
|
6
|
+
// wearing a different name: "party B may perform action X on behalf of party A, within a window,
|
|
7
|
+
// revocably". The repo already has exactly one mechanism for that, with on-chain revocation, EIP-712
|
|
8
|
+
// hashing, caveat enforcers and an audited fail-closed evaluator. Maintaining a second one meant a
|
|
9
|
+
// second thing to get wrong, and it had no on-chain revocation at all.
|
|
10
|
+
//
|
|
11
|
+
// So `authorityRef` is now a COMMITMENT to a delegation, not a pointer into a vault:
|
|
12
|
+
//
|
|
13
|
+
// '' self-issuance — the agent's own key signed for itself
|
|
14
|
+
// 'apdel1:<0x…32 bytes>' hashDelegation() of the delegation that authorized this act
|
|
15
|
+
//
|
|
16
|
+
// TWO CONSEQUENCES WORTH STATING:
|
|
17
|
+
//
|
|
18
|
+
// 1. NO LOOKUP. The old ref was a vault key, so establishing authority meant an I/O round trip that
|
|
19
|
+
// could fail open if written carelessly. A hash commits to the delegation the presenter must
|
|
20
|
+
// supply, so the verifier compares bytes it already holds.
|
|
21
|
+
//
|
|
22
|
+
// 2. THE SIGNED BODY PINS THE AUTHORITY. `authorityRef` is inside `grantBody()` and the publication
|
|
23
|
+
// body, so the issuer's signature commits to WHICH delegation authorized it. Swapping in a
|
|
24
|
+
// different (even valid) delegation invalidates the signature — an operator cannot re-file the
|
|
25
|
+
// same act under a broader authority than the one signed for.
|
|
26
|
+
//
|
|
27
|
+
// This module is deliberately PURE STRING WORK. Verifying the delegation needs chain reads and lives
|
|
28
|
+
// in `@agenticprimitives/delegation.authorizeMethodDelegation`; keeping the format here lets the
|
|
29
|
+
// browser-side verifier stay a leaf that depends only on `@agenticprimitives/types`.
|
|
30
|
+
/** Scheme prefix. Versioned so a future authority form is a new prefix, never a reinterpretation. */
|
|
31
|
+
export const DELEGATION_AUTHORITY_SCHEME = 'apdel1:';
|
|
32
|
+
const HASH32 = /^0x[0-9a-f]{64}$/;
|
|
33
|
+
/** Build the ref an issuer signs when acting under a delegation. */
|
|
34
|
+
export function delegationAuthorityRef(delegationHash) {
|
|
35
|
+
return `${DELEGATION_AUTHORITY_SCHEME}${delegationHash.toLowerCase()}`;
|
|
36
|
+
}
|
|
37
|
+
/** The ref an agent signs when acting for itself. */
|
|
38
|
+
export const SELF_AUTHORITY_REF = '';
|
|
39
|
+
/**
|
|
40
|
+
* Parse an `authorityRef`. Total — never throws, never guesses.
|
|
41
|
+
*
|
|
42
|
+
* An unparseable ref returns `unrecognized`, which callers MUST deny. That direction matters: the
|
|
43
|
+
* failure mode we are avoiding is a malformed ref falling through to the self-issuance branch, which
|
|
44
|
+
* would let anyone publish for anyone by sending garbage.
|
|
45
|
+
*/
|
|
46
|
+
export function parseAuthorityRef(ref) {
|
|
47
|
+
if (ref === undefined || ref === null || ref === '')
|
|
48
|
+
return { kind: 'self' };
|
|
49
|
+
if (!ref.startsWith(DELEGATION_AUTHORITY_SCHEME)) {
|
|
50
|
+
return { kind: 'unrecognized', reason: 'unknown authority scheme' };
|
|
51
|
+
}
|
|
52
|
+
const hash = ref.slice(DELEGATION_AUTHORITY_SCHEME.length).toLowerCase();
|
|
53
|
+
if (!HASH32.test(hash)) {
|
|
54
|
+
return { kind: 'unrecognized', reason: 'delegation hash must be 32 bytes of lowercase hex' };
|
|
55
|
+
}
|
|
56
|
+
return { kind: 'delegation', delegationHash: hash };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Does this ref commit to this delegation?
|
|
60
|
+
*
|
|
61
|
+
* Case-insensitive on the hex (a caller may hold a checksummed hash) but otherwise exact — a ref that
|
|
62
|
+
* commits to a different delegation is a substituted authority, which is the whole attack this
|
|
63
|
+
* commitment exists to stop.
|
|
64
|
+
*/
|
|
65
|
+
export function authorityRefMatches(ref, delegationHash) {
|
|
66
|
+
const parsed = parseAuthorityRef(ref);
|
|
67
|
+
return parsed.kind === 'delegation' && parsed.delegationHash === delegationHash.toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=authority-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-ref.js","sourceRoot":"","sources":["../src/authority-ref.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,8EAA8E;AAC9E,gGAAgG;AAChG,mGAAmG;AACnG,iGAAiG;AACjG,qGAAqG;AACrG,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c,EAAE,IAAqB,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,cAA6B;IAC5E,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,MAAM,CAAC,cAAc,KAAK,cAAc,CAAC,WAAW,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A `sha256:<64 hex>` digest string — the convention shared with `registry-kit` binding proofs. */
|
|
2
|
+
export type Sha256 = `sha256:${string}`;
|
|
3
|
+
/** sha256 over the canonical JSON form of `body`. */
|
|
4
|
+
export declare function digestOf(body: unknown): Promise<Sha256>;
|
|
5
|
+
/** The 32-byte `0x`-hex digest a Smart Agent signs / an ERC-1271 read validates over. It IS the
|
|
6
|
+
* `sha256:` digest's bytes, so the signature binds every field of the canonical body. */
|
|
7
|
+
export declare function signingDigest(d: Sha256): `0x${string}`;
|
|
8
|
+
/**
|
|
9
|
+
* Constant-time-ish string comparison for digests and opaque ids.
|
|
10
|
+
*
|
|
11
|
+
* Digest comparison is not a secret comparison, but grant-id lookups are — and a resolver that
|
|
12
|
+
* short-circuits on the first differing byte is a timing oracle for which grant ids exist
|
|
13
|
+
* (spec 338 §10, "public enumeration oracle"). Length is not secret; content is.
|
|
14
|
+
*/
|
|
15
|
+
export declare function timingSafeEqual(a: string, b: string): boolean;
|
|
16
|
+
//# sourceMappingURL=canonicalization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalization.d.ts","sourceRoot":"","sources":["../src/canonicalization.ts"],"names":[],"mappings":"AASA,oGAAoG;AACpG,MAAM,MAAM,MAAM,GAAG,UAAU,MAAM,EAAE,CAAC;AAcxC,qDAAqD;AACrD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7D;AAED;0FAC0F;AAC1F,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAEtD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAK7D"}
|