@agent-custody/state 0.16.10 → 0.16.11
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/dist/verify-web.d.ts +2 -2
- package/dist/verify-web.js +50 -3
- package/package.json +2 -2
package/dist/verify-web.d.ts
CHANGED
|
@@ -47,8 +47,8 @@ export declare function dsseVerify(env: Envelope, trusted: PublicKey[]): Promise
|
|
|
47
47
|
error: string;
|
|
48
48
|
}>;
|
|
49
49
|
export declare function delegationHasParent(env: Envelope): boolean;
|
|
50
|
-
/** Mirrors verifyDelegation in the package: walks a chain to a grant signed by a trusted principal key. */
|
|
51
|
-
export declare function verifyDelegationChain(env: Envelope, trusted: PublicKey[]
|
|
50
|
+
/** Mirrors verifyDelegation in the package: walks a chain to a grant signed by a trusted principal key, and checks each did:key agent. */
|
|
51
|
+
export declare function verifyDelegationChain(env: Envelope, trusted: PublicKey[]): Promise<{
|
|
52
52
|
ok: true;
|
|
53
53
|
delegation: any;
|
|
54
54
|
keyid: string;
|
package/dist/verify-web.js
CHANGED
|
@@ -168,8 +168,55 @@ function decodeDelegationPayload(env) {
|
|
|
168
168
|
export function delegationHasParent(env) {
|
|
169
169
|
return decodeDelegationPayload(env)?.parent !== undefined;
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
172
|
+
/** Mirrors didKeyAgentFault in the package: why a did:key agent does not check out, or null. */
|
|
173
|
+
async function didKeyAgentFault(did, agentKey) {
|
|
174
|
+
const text = did.slice(9);
|
|
175
|
+
const bytes = [];
|
|
176
|
+
// a leading "1" is a zero byte, and an Ed25519 did:key starts with 0xed
|
|
177
|
+
let good = did.length <= 100 && did.startsWith("did:key:z") && text[0] !== "1";
|
|
178
|
+
for (const ch of good ? text : "") {
|
|
179
|
+
let carry = BASE58.indexOf(ch);
|
|
180
|
+
if (carry < 0) {
|
|
181
|
+
good = false;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
185
|
+
carry += bytes[i] * 58;
|
|
186
|
+
bytes[i] = carry & 0xff;
|
|
187
|
+
carry >>= 8;
|
|
188
|
+
}
|
|
189
|
+
for (; carry; carry >>= 8)
|
|
190
|
+
bytes.unshift(carry & 0xff);
|
|
191
|
+
}
|
|
192
|
+
if (!good || bytes.length !== 34 || bytes[0] !== 0xed || bytes[1] !== 0x01)
|
|
193
|
+
return "the grant's did:key agent does not decode to an Ed25519 key";
|
|
194
|
+
if (agentKey === undefined)
|
|
195
|
+
return null;
|
|
196
|
+
let raw;
|
|
197
|
+
try {
|
|
198
|
+
raw = new Uint8Array(await subtle().exportKey("raw", (await publicKeyFromPem(agentKey)).key));
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return "the grant's agentKey is not a public key";
|
|
202
|
+
}
|
|
203
|
+
return raw.every((b, i) => b === bytes[i + 2]) ? null : "the grant's agentKey is not the key its did:key agent names";
|
|
204
|
+
}
|
|
205
|
+
/** Mirrors verifyDelegation in the package: walks a chain to a grant signed by a trusted principal key, and checks each did:key agent. */
|
|
206
|
+
export async function verifyDelegationChain(env, trusted) {
|
|
207
|
+
const checked = await walkDelegationChain(env, trusted, 1);
|
|
208
|
+
if (!checked.ok)
|
|
209
|
+
return checked;
|
|
210
|
+
for (const [i, link] of checked.chain.entries()) {
|
|
211
|
+
if (!link.agent.startsWith("did:key:"))
|
|
212
|
+
continue;
|
|
213
|
+
const fault = await didKeyAgentFault(link.agent, link.agentKey);
|
|
214
|
+
if (fault)
|
|
215
|
+
return { ok: false, error: (i === checked.chain.length - 1 ? "" : `link ${i} (${link.agent}): `) + fault };
|
|
216
|
+
}
|
|
217
|
+
return checked;
|
|
218
|
+
}
|
|
219
|
+
async function walkDelegationChain(env, trusted, depth) {
|
|
173
220
|
if (env.payloadType !== DELEGATION_TYPE)
|
|
174
221
|
return { ok: false, error: `unexpected payloadType ${env.payloadType}` };
|
|
175
222
|
if (depth > 4)
|
|
@@ -185,7 +232,7 @@ export async function verifyDelegationChain(env, trusted, depth = 1) {
|
|
|
185
232
|
return { ok: false, error: "malformed delegation" };
|
|
186
233
|
return { ok: true, delegation: r.payload, keyid: r.keyid, chain: [r.payload] };
|
|
187
234
|
}
|
|
188
|
-
const up = await
|
|
235
|
+
const up = await walkDelegationChain(unverified.parent, trusted, depth + 1);
|
|
189
236
|
if (!up.ok)
|
|
190
237
|
return { ok: false, error: `link ${depth}: ${up.error}` };
|
|
191
238
|
const parent = up.delegation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/state",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.11",
|
|
4
4
|
"description": "Governed memory for AI agents: a fact ledger with provenance, valid time, rollback, lineage, certified forget, and a store that is a JSONL file, SQLite, or Postgres, built on @agent-custody/receipts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"node": ">=22"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@agent-custody/receipts": "0.16.
|
|
37
|
+
"@agent-custody/receipts": "0.16.11",
|
|
38
38
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
39
39
|
"zod": "4.5.4"
|
|
40
40
|
},
|