@agenticprimitives/agent-naming 0.1.0-alpha.2
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/AUDIT.md +86 -0
- package/CLAUDE.md +180 -0
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/abis.d.ts +1532 -0
- package/dist/abis.d.ts.map +1 -0
- package/dist/abis.js +417 -0
- package/dist/abis.js.map +1 -0
- package/dist/client.d.ts +102 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +299 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/custody.d.ts +133 -0
- package/dist/custody.d.ts.map +1 -0
- package/dist/custody.js +214 -0
- package/dist/custody.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/namehash.d.ts +31 -0
- package/dist/namehash.d.ts.map +1 -0
- package/dist/namehash.js +46 -0
- package/dist/namehash.js.map +1 -0
- package/dist/normalize.d.ts +28 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +68 -0
- package/dist/normalize.js.map +1 -0
- package/dist/records.d.ts +88 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +193 -0
- package/dist/records.js.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/api.md +110 -0
- package/docs/concepts.md +159 -0
- package/docs/migration.md +93 -0
- package/docs/security.md +127 -0
- package/docs/troubleshooting.md +116 -0
- package/examples/basic.ts +31 -0
- package/examples/custody-rotation.ts +44 -0
- package/examples/records.ts +41 -0
- package/package.json +71 -0
- package/spec.md +14 -0
package/dist/custody.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subpath `@agenticprimitives/agent-naming/custody`.
|
|
3
|
+
*
|
|
4
|
+
* Pure encoded call builders for name-registry + resolver writes.
|
|
5
|
+
* Compose these into a custody ceremony, a direct EOA tx, an
|
|
6
|
+
* ERC-4337 UserOp, or anything else that submits a transaction.
|
|
7
|
+
* The package boundary (spec 215 § 3) prohibits importing
|
|
8
|
+
* `@agenticprimitives/account-custody` from here — these builders MUST stay
|
|
9
|
+
* pure encode-only.
|
|
10
|
+
*
|
|
11
|
+
* Each builder returns a `ContractCall` shape (`{ to, value, data }`)
|
|
12
|
+
* matching the standard "compose-then-submit" pattern used across
|
|
13
|
+
* other agenticprimitives packages.
|
|
14
|
+
*
|
|
15
|
+
* Phase 4 lands the encoders; the client (`AgentNamingClient`) layers
|
|
16
|
+
* walletClient submission on top.
|
|
17
|
+
*/
|
|
18
|
+
import { encodeFunctionData } from 'viem';
|
|
19
|
+
import { agentNameAttributeResolverAbi, agentNameRegistryAbi, permissionlessSubregistryAbi, } from './abis';
|
|
20
|
+
import { PREDICATE_ID, AGENT_KIND_ID } from './records';
|
|
21
|
+
// ─── Registry writes ───────────────────────────────────────────────
|
|
22
|
+
/**
|
|
23
|
+
* Build a call to register `<label>.<parent>` under the parent
|
|
24
|
+
* namespace. Caller MUST be the parent's owner OR subregistry
|
|
25
|
+
* delegate (msg.sender check on chain).
|
|
26
|
+
*/
|
|
27
|
+
export function buildRegisterSubnameCall(args) {
|
|
28
|
+
return {
|
|
29
|
+
to: args.registry,
|
|
30
|
+
value: 0n,
|
|
31
|
+
data: encodeFunctionData({
|
|
32
|
+
abi: agentNameRegistryAbi,
|
|
33
|
+
functionName: 'register',
|
|
34
|
+
args: [
|
|
35
|
+
args.parentNode,
|
|
36
|
+
args.label,
|
|
37
|
+
args.newOwner,
|
|
38
|
+
args.resolver ?? '0x0000000000000000000000000000000000000000',
|
|
39
|
+
args.expiry ?? 0n,
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build a call to rotate the owner Smart Agent for a name.
|
|
46
|
+
* Caller MUST be the current owner.
|
|
47
|
+
*/
|
|
48
|
+
export function buildRotateNameOwnerCall(args) {
|
|
49
|
+
return {
|
|
50
|
+
to: args.registry,
|
|
51
|
+
value: 0n,
|
|
52
|
+
data: encodeFunctionData({
|
|
53
|
+
abi: agentNameRegistryAbi,
|
|
54
|
+
functionName: 'setOwner',
|
|
55
|
+
args: [args.node, args.newOwner],
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a call to swap the resolver contract for a name.
|
|
61
|
+
* Caller MUST be the current owner.
|
|
62
|
+
*/
|
|
63
|
+
export function buildRotateNameResolverCall(args) {
|
|
64
|
+
return {
|
|
65
|
+
to: args.registry,
|
|
66
|
+
value: 0n,
|
|
67
|
+
data: encodeFunctionData({
|
|
68
|
+
abi: agentNameRegistryAbi,
|
|
69
|
+
functionName: 'setResolver',
|
|
70
|
+
args: [args.node, args.newResolver],
|
|
71
|
+
}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a call to delegate child-name issuance authority for a
|
|
76
|
+
* subtree to a subregistry contract. Setting `subregistry = address(0)`
|
|
77
|
+
* reverts to "owner-only" issuance.
|
|
78
|
+
*/
|
|
79
|
+
export function buildSetSubregistryCall(args) {
|
|
80
|
+
return {
|
|
81
|
+
to: args.registry,
|
|
82
|
+
value: 0n,
|
|
83
|
+
data: encodeFunctionData({
|
|
84
|
+
abi: agentNameRegistryAbi,
|
|
85
|
+
functionName: 'setSubregistry',
|
|
86
|
+
args: [args.node, args.subregistry],
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Build a call to set the caller's primary name (reverse record).
|
|
92
|
+
* Caller MUST be the agent for which the primary name is being set
|
|
93
|
+
* (msg.sender == agent on chain). Setting `node = bytes32(0)` clears
|
|
94
|
+
* the primary name.
|
|
95
|
+
*/
|
|
96
|
+
export function buildSetPrimaryNameCall(args) {
|
|
97
|
+
return {
|
|
98
|
+
to: args.registry,
|
|
99
|
+
value: 0n,
|
|
100
|
+
data: encodeFunctionData({
|
|
101
|
+
abi: agentNameRegistryAbi,
|
|
102
|
+
functionName: 'setPrimaryName',
|
|
103
|
+
args: [args.node],
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// ─── Resolver (record) writes ──────────────────────────────────────
|
|
108
|
+
/** Build a typed `setStringAttribute(node, predicate, value)` call. */
|
|
109
|
+
export function buildSetStringAttributeCall(args) {
|
|
110
|
+
return {
|
|
111
|
+
to: args.resolver,
|
|
112
|
+
value: 0n,
|
|
113
|
+
data: encodeFunctionData({
|
|
114
|
+
abi: agentNameAttributeResolverAbi,
|
|
115
|
+
functionName: 'setStringAttribute',
|
|
116
|
+
args: [args.node, args.predicate, args.value],
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Build a typed `setAddressAttribute(node, predicate, value)` call. */
|
|
121
|
+
export function buildSetAddressAttributeCall(args) {
|
|
122
|
+
return {
|
|
123
|
+
to: args.resolver,
|
|
124
|
+
value: 0n,
|
|
125
|
+
data: encodeFunctionData({
|
|
126
|
+
abi: agentNameAttributeResolverAbi,
|
|
127
|
+
functionName: 'setAddressAttribute',
|
|
128
|
+
args: [args.node, args.predicate, args.value],
|
|
129
|
+
}),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** Build a typed `setBytes32Attribute(node, predicate, value)` call. */
|
|
133
|
+
export function buildSetBytes32AttributeCall(args) {
|
|
134
|
+
return {
|
|
135
|
+
to: args.resolver,
|
|
136
|
+
value: 0n,
|
|
137
|
+
data: encodeFunctionData({
|
|
138
|
+
abi: agentNameAttributeResolverAbi,
|
|
139
|
+
functionName: 'setBytes32Attribute',
|
|
140
|
+
args: [args.node, args.predicate, args.value],
|
|
141
|
+
}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// ─── Records bundle → array of typed-attribute calls ───────────────
|
|
145
|
+
/**
|
|
146
|
+
* Translate an `AgentNameRecords` bundle into N typed-attribute
|
|
147
|
+
* calls. Caller submits them via walletClient OR composes them into
|
|
148
|
+
* a single AgentAccount.execute / CustodyPolicy ceremony.
|
|
149
|
+
*
|
|
150
|
+
* Mirrors `encodeRecords` from `agent-naming/records` but produces
|
|
151
|
+
* full `ContractCall` shapes instead of `EncodedRecord` shapes.
|
|
152
|
+
*/
|
|
153
|
+
export function buildRecordCalls(args) {
|
|
154
|
+
const out = [];
|
|
155
|
+
const { resolver, node, records } = args;
|
|
156
|
+
if (records.addr !== undefined) {
|
|
157
|
+
out.push(buildSetAddressAttributeCall({ resolver, node, predicate: PREDICATE_ID.addr, value: records.addr }));
|
|
158
|
+
}
|
|
159
|
+
if (records.agentKind !== undefined) {
|
|
160
|
+
out.push(buildSetBytes32AttributeCall({
|
|
161
|
+
resolver, node,
|
|
162
|
+
predicate: PREDICATE_ID.agentKind,
|
|
163
|
+
value: AGENT_KIND_ID[records.agentKind],
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
if (records.displayName !== undefined) {
|
|
167
|
+
out.push(buildSetStringAttributeCall({ resolver, node, predicate: PREDICATE_ID.displayName, value: records.displayName }));
|
|
168
|
+
}
|
|
169
|
+
if (records.a2aEndpoint !== undefined) {
|
|
170
|
+
out.push(buildSetStringAttributeCall({ resolver, node, predicate: PREDICATE_ID.a2aEndpoint, value: records.a2aEndpoint }));
|
|
171
|
+
}
|
|
172
|
+
if (records.mcpEndpoint !== undefined) {
|
|
173
|
+
out.push(buildSetStringAttributeCall({ resolver, node, predicate: PREDICATE_ID.mcpEndpoint, value: records.mcpEndpoint }));
|
|
174
|
+
}
|
|
175
|
+
if (records.metadataUri !== undefined) {
|
|
176
|
+
out.push(buildSetStringAttributeCall({ resolver, node, predicate: PREDICATE_ID.metadataUri, value: records.metadataUri }));
|
|
177
|
+
}
|
|
178
|
+
if (records.metadataHash !== undefined) {
|
|
179
|
+
out.push(buildSetBytes32AttributeCall({ resolver, node, predicate: PREDICATE_ID.metadataHash, value: records.metadataHash }));
|
|
180
|
+
}
|
|
181
|
+
if (records.passkeyCredentialDigest !== undefined) {
|
|
182
|
+
out.push(buildSetBytes32AttributeCall({ resolver, node, predicate: PREDICATE_ID.passkeyCredentialDigest, value: records.passkeyCredentialDigest }));
|
|
183
|
+
}
|
|
184
|
+
if (records.custodyPolicy !== undefined) {
|
|
185
|
+
out.push(buildSetAddressAttributeCall({ resolver, node, predicate: PREDICATE_ID.custodyPolicy, value: records.custodyPolicy }));
|
|
186
|
+
}
|
|
187
|
+
if (records.nativeId !== undefined) {
|
|
188
|
+
out.push(buildSetStringAttributeCall({ resolver, node, predicate: PREDICATE_ID.nativeId, value: records.nativeId }));
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
// ─── PermissionlessSubregistry ─────────────────────────────────────
|
|
193
|
+
/**
|
|
194
|
+
* Build a call to claim `<label>.<parent>` through a deployed
|
|
195
|
+
* PermissionlessSubregistry instance. The caller pays gas; the
|
|
196
|
+
* registered child name is owned by `newOwner` (typically the
|
|
197
|
+
* caller's own PSA OR an account they control).
|
|
198
|
+
*
|
|
199
|
+
* Anti-spam: one claim per `msg.sender` is enforced on chain; the
|
|
200
|
+
* call reverts with `AlreadyClaimed(existingNode)` if the caller
|
|
201
|
+
* has previously claimed a name through this subregistry instance.
|
|
202
|
+
*/
|
|
203
|
+
export function buildSubregistryRegisterCall(args) {
|
|
204
|
+
return {
|
|
205
|
+
to: args.subregistry,
|
|
206
|
+
value: 0n,
|
|
207
|
+
data: encodeFunctionData({
|
|
208
|
+
abi: permissionlessSubregistryAbi,
|
|
209
|
+
functionName: 'register',
|
|
210
|
+
args: [args.label, args.newOwner],
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=custody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custody.js","sourceRoot":"","sources":["../src/custody.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAC;AAU5E,sEAAsE;AAEtE;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAOxC;IACC,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,QAAQ;QACjB,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,kBAAkB,CAAC;YACvB,GAAG,EAAE,oBAAoB;YACzB,YAAY,EAAE,UAAU;YACxB,IAAI,EAAE;gBACJ,IAAI,CAAC,UAAU;gBACf,IAAI,CAAC,KAAK;gBACV,IAAI,CAAC,QAAQ;gBACb,IAAI,CAAC,QAAQ,IAAK,4CAAwD;gBAC1E,IAAI,CAAC,MAAM,IAAI,EAAE;aAClB;SACF,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAIxC;IACC,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,QAAQ;QACjB,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,kBAAkB,CAAC;YACvB,GAAG,EAAE,oBAAoB;YACzB,YAAY,EAAE,UAAU;YACxB,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;SACjC,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAI3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ly reason: string;
|
|
4
|
+
constructor(agentName: string, reason: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class NameNotFoundError extends Error {
|
|
7
|
+
readonly agentName: string;
|
|
8
|
+
constructor(agentName: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class UnauthorizedNameOwnerError extends Error {
|
|
11
|
+
readonly agentName: string;
|
|
12
|
+
readonly attemptedSigner?: string | undefined;
|
|
13
|
+
constructor(agentName: string, attemptedSigner?: string | undefined);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAiB,SAAQ,KAAK;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAA1C,SAAS,EAAE,MAAM,EAAW,MAAM,EAAE,MAAM;CAIhE;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAIvC;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM;IAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM;gBAApD,SAAS,EAAE,MAAM,EAAW,eAAe,CAAC,EAAE,MAAM,YAAA;CAO1E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class InvalidNameError extends Error {
|
|
2
|
+
agentName;
|
|
3
|
+
reason;
|
|
4
|
+
constructor(agentName, reason) {
|
|
5
|
+
super(`[agent-naming] invalid name "${agentName}": ${reason}`);
|
|
6
|
+
this.agentName = agentName;
|
|
7
|
+
this.reason = reason;
|
|
8
|
+
this.name = 'InvalidNameError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class NameNotFoundError extends Error {
|
|
12
|
+
agentName;
|
|
13
|
+
constructor(agentName) {
|
|
14
|
+
super(`[agent-naming] name not registered: ${agentName}`);
|
|
15
|
+
this.agentName = agentName;
|
|
16
|
+
this.name = 'NameNotFoundError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class UnauthorizedNameOwnerError extends Error {
|
|
20
|
+
agentName;
|
|
21
|
+
attemptedSigner;
|
|
22
|
+
constructor(agentName, attemptedSigner) {
|
|
23
|
+
super(`[agent-naming] caller is not the owner of "${agentName}"` +
|
|
24
|
+
(attemptedSigner ? ` (attempted: ${attemptedSigner})` : ''));
|
|
25
|
+
this.agentName = agentName;
|
|
26
|
+
this.attemptedSigner = attemptedSigner;
|
|
27
|
+
this.name = 'UnauthorizedNameOwnerError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACpB;IAA4B;IAAjD,YAAqB,SAAiB,EAAW,MAAc;QAC7D,KAAK,CAAC,gCAAgC,SAAS,MAAM,MAAM,EAAE,CAAC,CAAC;QAD5C,cAAS,GAAT,SAAS,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAQ;QAE7D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACrB;IAArB,YAAqB,SAAiB;QACpC,KAAK,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;QADvC,cAAS,GAAT,SAAS,CAAQ;QAEpC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC9B;IAA4B;IAAjD,YAAqB,SAAiB,EAAW,eAAwB;QACvE,KAAK,CACH,8CAA8C,SAAS,GAAG;YACxD,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,eAAe,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAC9D,CAAC;QAJiB,cAAS,GAAT,SAAS,CAAQ;QAAW,oBAAe,GAAf,eAAe,CAAS;QAKvE,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AGENT_TLD, type AgentTld } from './constants';
|
|
2
|
+
export { normalizeAgentName, isValidAgentName } from './normalize';
|
|
3
|
+
export { labelhash, namehash, ZERO_NODE } from './namehash';
|
|
4
|
+
export { InvalidNameError, NameNotFoundError, UnauthorizedNameOwnerError, } from './errors';
|
|
5
|
+
export type { AgentKind, AgentNameRecords, RegisterSubnameInput, SetPrimaryNameInput, SetAgentRecordsInput, SetSubregistryInput, AgentNamingClientOpts, } from './types';
|
|
6
|
+
export { AgentNamingClient, type WriteContext } from './client';
|
|
7
|
+
export { buildRegisterSubnameCall, buildRotateNameOwnerCall, buildRotateNameResolverCall, buildSetSubregistryCall, buildSetPrimaryNameCall, buildSetStringAttributeCall, buildSetAddressAttributeCall, buildSetBytes32AttributeCall, buildRecordCalls, buildSubregistryRegisterCall, type ContractCall, } from './custody';
|
|
8
|
+
export { agentNameRegistryAbi, agentNameAttributeResolverAbi, agentNameUniversalResolverAbi, ontologyTermRegistryAbi, shapeRegistryAbi, permissionlessSubregistryAbi, } from './abis';
|
|
9
|
+
export { PREDICATE_ID, AGENT_KIND_ID, CLASS_AGENT_NAME, AGENT_KIND_ENUM, CAIP10_NAMESPACE_ALLOWLIST, encodeRecords, decodeRecords, type PredicateName, type EncodedRecord, type DecodeInput, } from './records';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAIhE,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,EAC5B,gBAAgB,EAChB,4BAA4B,EAC5B,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAKnB,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,EACvB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,QAAQ,CAAC;AAIhB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,aAAa,EACb,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @agenticprimitives/agent-naming — public API.
|
|
2
|
+
//
|
|
3
|
+
// See:
|
|
4
|
+
// - capability.manifest.json — boundary
|
|
5
|
+
// - CLAUDE.md — doctrine
|
|
6
|
+
// - specs/215-agent-naming.md — the contract
|
|
7
|
+
export { AGENT_TLD } from './constants';
|
|
8
|
+
export { normalizeAgentName, isValidAgentName } from './normalize';
|
|
9
|
+
export { labelhash, namehash, ZERO_NODE } from './namehash';
|
|
10
|
+
export { InvalidNameError, NameNotFoundError, UnauthorizedNameOwnerError, } from './errors';
|
|
11
|
+
export { AgentNamingClient } from './client';
|
|
12
|
+
// Phase 4 pure call builders (subpath `@agenticprimitives/agent-naming/custody`
|
|
13
|
+
// re-exported from top-level for convenience).
|
|
14
|
+
export { buildRegisterSubnameCall, buildRotateNameOwnerCall, buildRotateNameResolverCall, buildSetSubregistryCall, buildSetPrimaryNameCall, buildSetStringAttributeCall, buildSetAddressAttributeCall, buildSetBytes32AttributeCall, buildRecordCalls, buildSubregistryRegisterCall, } from './custody';
|
|
15
|
+
// Phase 3 contract ABIs (live at deployed addresses recorded in
|
|
16
|
+
// packages/contracts/deployments-<network>.json). ADR-0009 pivot: the
|
|
17
|
+
// resolver inherits the shared `AttributeStorage` + ontology stack.
|
|
18
|
+
export { agentNameRegistryAbi, agentNameAttributeResolverAbi, agentNameUniversalResolverAbi, ontologyTermRegistryAbi, shapeRegistryAbi, permissionlessSubregistryAbi, } from './abis';
|
|
19
|
+
// Ontology predicate ids (bytes32 mirror of AgentNamePredicates.sol) +
|
|
20
|
+
// CAIP-10 helpers + typed encoder / decoder.
|
|
21
|
+
export { PREDICATE_ID, AGENT_KIND_ID, CLASS_AGENT_NAME, AGENT_KIND_ENUM, CAIP10_NAMESPACE_ALLOWLIST, encodeRecords, decodeRecords, } from './records';
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,OAAO;AACP,0CAA0C;AAC1C,2BAA2B;AAC3B,+CAA+C;AAE/C,OAAO,EAAE,SAAS,EAAiB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAUlB,OAAO,EAAE,iBAAiB,EAAqB,MAAM,UAAU,CAAC;AAEhE,gFAAgF;AAChF,+CAA+C;AAC/C,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,EAC5B,gBAAgB,EAChB,4BAA4B,GAE7B,MAAM,WAAW,CAAC;AAEnB,gEAAgE;AAChE,sEAAsE;AACtE,oEAAoE;AACpE,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,EACvB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,QAAQ,CAAC;AAEhB,uEAAuE;AACvE,6CAA6C;AAC7C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,aAAa,EACb,aAAa,GAId,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Hex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the namehash of an agent name (ENS-compatible).
|
|
4
|
+
*
|
|
5
|
+
* namehash('') = 0x00…00
|
|
6
|
+
* namehash('agent') = keccak256(namehash('') || labelhash('agent'))
|
|
7
|
+
* namehash('alice.acme.agent')
|
|
8
|
+
* = keccak256(namehash('acme.agent') || labelhash('alice'))
|
|
9
|
+
*
|
|
10
|
+
* The hash is computed against the NORMALIZED name (see
|
|
11
|
+
* `normalizeAgentName`). Two strings that normalize identically
|
|
12
|
+
* produce identical namehashes.
|
|
13
|
+
*
|
|
14
|
+
* Throws `InvalidNameError` (via `normalizeAgentName`) on malformed
|
|
15
|
+
* input. Passing `''` returns `0x00…00` — the canonical "empty / root"
|
|
16
|
+
* sentinel matching the ENS convention.
|
|
17
|
+
*/
|
|
18
|
+
export declare function namehash(name: string): Hex;
|
|
19
|
+
/**
|
|
20
|
+
* Compute the labelhash of a single label.
|
|
21
|
+
*
|
|
22
|
+
* `labelhash(label)` = keccak256(utf8Bytes(label))
|
|
23
|
+
*
|
|
24
|
+
* No normalization is applied here — the caller is expected to pass a
|
|
25
|
+
* label produced by splitting a normalized name. Pass a non-normalized
|
|
26
|
+
* label at your own risk.
|
|
27
|
+
*/
|
|
28
|
+
export declare function labelhash(label: string): Hex;
|
|
29
|
+
/** The all-zeros 32-byte sentinel namehash (the root of the tree). */
|
|
30
|
+
export declare const ZERO_NODE: Hex;
|
|
31
|
+
//# sourceMappingURL=namehash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namehash.d.ts","sourceRoot":"","sources":["../src/namehash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAGlE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAW1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAE5C;AAED,sEAAsE;AACtE,eAAO,MAAM,SAAS,EAAE,GAA0E,CAAC"}
|
package/dist/namehash.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { keccak256, encodePacked, toBytes } from 'viem';
|
|
2
|
+
import { normalizeAgentName } from './normalize';
|
|
3
|
+
/**
|
|
4
|
+
* Compute the namehash of an agent name (ENS-compatible).
|
|
5
|
+
*
|
|
6
|
+
* namehash('') = 0x00…00
|
|
7
|
+
* namehash('agent') = keccak256(namehash('') || labelhash('agent'))
|
|
8
|
+
* namehash('alice.acme.agent')
|
|
9
|
+
* = keccak256(namehash('acme.agent') || labelhash('alice'))
|
|
10
|
+
*
|
|
11
|
+
* The hash is computed against the NORMALIZED name (see
|
|
12
|
+
* `normalizeAgentName`). Two strings that normalize identically
|
|
13
|
+
* produce identical namehashes.
|
|
14
|
+
*
|
|
15
|
+
* Throws `InvalidNameError` (via `normalizeAgentName`) on malformed
|
|
16
|
+
* input. Passing `''` returns `0x00…00` — the canonical "empty / root"
|
|
17
|
+
* sentinel matching the ENS convention.
|
|
18
|
+
*/
|
|
19
|
+
export function namehash(name) {
|
|
20
|
+
if (name === '')
|
|
21
|
+
return ZERO_NODE;
|
|
22
|
+
const labels = normalizeAgentName(name).split('.');
|
|
23
|
+
let node = ZERO_NODE;
|
|
24
|
+
// Walk from rightmost (TLD-side) label inward so the root anchors
|
|
25
|
+
// the recursion — same as ENS reference impl.
|
|
26
|
+
for (let i = labels.length - 1; i >= 0; i--) {
|
|
27
|
+
const lh = labelhash(labels[i]);
|
|
28
|
+
node = keccak256(encodePacked(['bytes32', 'bytes32'], [node, lh]));
|
|
29
|
+
}
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compute the labelhash of a single label.
|
|
34
|
+
*
|
|
35
|
+
* `labelhash(label)` = keccak256(utf8Bytes(label))
|
|
36
|
+
*
|
|
37
|
+
* No normalization is applied here — the caller is expected to pass a
|
|
38
|
+
* label produced by splitting a normalized name. Pass a non-normalized
|
|
39
|
+
* label at your own risk.
|
|
40
|
+
*/
|
|
41
|
+
export function labelhash(label) {
|
|
42
|
+
return keccak256(toBytes(label));
|
|
43
|
+
}
|
|
44
|
+
/** The all-zeros 32-byte sentinel namehash (the root of the tree). */
|
|
45
|
+
export const ZERO_NODE = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
46
|
+
//# sourceMappingURL=namehash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namehash.js","sourceRoot":"","sources":["../src/namehash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAY,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAClC,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,IAAI,GAAQ,SAAS,CAAC;IAC1B,kEAAkE;IAClE,8CAA8C;IAC9C,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,CAAC;QACjC,IAAI,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,SAAS,GAAQ,oEAAoE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize an agent name to canonical form.
|
|
3
|
+
*
|
|
4
|
+
* Phase 1 normalization (US-ASCII subset; spec § 4 normalization
|
|
5
|
+
* rules; matches `smart-agent/packages/sdk/src/naming.ts:normalize`
|
|
6
|
+
* with stricter label validation):
|
|
7
|
+
*
|
|
8
|
+
* 1. NFC normalize the input.
|
|
9
|
+
* 2. Trim outer whitespace.
|
|
10
|
+
* 3. Lowercase (`String.prototype.toLowerCase` — note Turkish-i
|
|
11
|
+
* edge case; acceptable in Phase 1 since labels are ASCII-only).
|
|
12
|
+
* 4. Split on `.`. For each label:
|
|
13
|
+
* - Reject empty.
|
|
14
|
+
* - Reject leading or trailing `-`.
|
|
15
|
+
* - Reject characters outside `[a-z 0-9 -]`.
|
|
16
|
+
* - Reject length > 63.
|
|
17
|
+
* 5. Return joined.
|
|
18
|
+
*
|
|
19
|
+
* Throws `InvalidNameError` on any rule violation. Use this BEFORE
|
|
20
|
+
* `namehash` so the namehash is computed against the canonical form.
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeAgentName(name: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Predicate variant — returns true / false instead of throwing.
|
|
25
|
+
* Useful for UI input validation.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isValidAgentName(name: string): boolean;
|
|
28
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAavD;AAyBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOtD"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { InvalidNameError } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize an agent name to canonical form.
|
|
4
|
+
*
|
|
5
|
+
* Phase 1 normalization (US-ASCII subset; spec § 4 normalization
|
|
6
|
+
* rules; matches `smart-agent/packages/sdk/src/naming.ts:normalize`
|
|
7
|
+
* with stricter label validation):
|
|
8
|
+
*
|
|
9
|
+
* 1. NFC normalize the input.
|
|
10
|
+
* 2. Trim outer whitespace.
|
|
11
|
+
* 3. Lowercase (`String.prototype.toLowerCase` — note Turkish-i
|
|
12
|
+
* edge case; acceptable in Phase 1 since labels are ASCII-only).
|
|
13
|
+
* 4. Split on `.`. For each label:
|
|
14
|
+
* - Reject empty.
|
|
15
|
+
* - Reject leading or trailing `-`.
|
|
16
|
+
* - Reject characters outside `[a-z 0-9 -]`.
|
|
17
|
+
* - Reject length > 63.
|
|
18
|
+
* 5. Return joined.
|
|
19
|
+
*
|
|
20
|
+
* Throws `InvalidNameError` on any rule violation. Use this BEFORE
|
|
21
|
+
* `namehash` so the namehash is computed against the canonical form.
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeAgentName(name) {
|
|
24
|
+
if (typeof name !== 'string') {
|
|
25
|
+
throw new InvalidNameError(String(name), 'must be a string');
|
|
26
|
+
}
|
|
27
|
+
const trimmed = name.normalize('NFC').trim().toLowerCase();
|
|
28
|
+
if (trimmed.length === 0) {
|
|
29
|
+
throw new InvalidNameError(name, 'empty');
|
|
30
|
+
}
|
|
31
|
+
const labels = trimmed.split('.');
|
|
32
|
+
for (const label of labels) {
|
|
33
|
+
validateLabel(name, label);
|
|
34
|
+
}
|
|
35
|
+
return labels.join('.');
|
|
36
|
+
}
|
|
37
|
+
const LABEL_RE = /^[a-z0-9-]+$/;
|
|
38
|
+
function validateLabel(fullName, label) {
|
|
39
|
+
if (label.length === 0) {
|
|
40
|
+
throw new InvalidNameError(fullName, 'empty label (consecutive dots or leading/trailing dot)');
|
|
41
|
+
}
|
|
42
|
+
if (label.length > 63) {
|
|
43
|
+
throw new InvalidNameError(fullName, `label "${label}" exceeds 63 chars`);
|
|
44
|
+
}
|
|
45
|
+
if (label.startsWith('-')) {
|
|
46
|
+
throw new InvalidNameError(fullName, `label "${label}" starts with hyphen`);
|
|
47
|
+
}
|
|
48
|
+
if (label.endsWith('-')) {
|
|
49
|
+
throw new InvalidNameError(fullName, `label "${label}" ends with hyphen`);
|
|
50
|
+
}
|
|
51
|
+
if (!LABEL_RE.test(label)) {
|
|
52
|
+
throw new InvalidNameError(fullName, `label "${label}" contains characters outside [a-z 0-9 -]`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Predicate variant — returns true / false instead of throwing.
|
|
57
|
+
* Useful for UI input validation.
|
|
58
|
+
*/
|
|
59
|
+
export function isValidAgentName(name) {
|
|
60
|
+
try {
|
|
61
|
+
normalizeAgentName(name);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC3D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,QAAQ,GAAG,cAAc,CAAC;AAEhC,SAAS,aAAa,CAAC,QAAgB,EAAE,KAAa;IACpD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,wDAAwD,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,UAAU,KAAK,oBAAoB,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,UAAU,KAAK,sBAAsB,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,UAAU,KAAK,oBAAoB,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,gBAAgB,CACxB,QAAQ,EACR,UAAU,KAAK,2CAA2C,CAC3D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC;QACH,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predicate ids + typed record encoders/decoders for the on-chain
|
|
3
|
+
* ontology-backed resolver (ADR-0009 / NS Phase 3 pivot).
|
|
4
|
+
*
|
|
5
|
+
* Subpath: `@agenticprimitives/agent-naming/records`.
|
|
6
|
+
*
|
|
7
|
+
* The `AgentNameAttributeResolver` (packages/contracts/src/naming/) inherits
|
|
8
|
+
* `AttributeStorage` and validates every write against the
|
|
9
|
+
* `OntologyTermRegistry`. Predicate keys are `bytes32` ids
|
|
10
|
+
* (`keccak256("atl:displayName")` etc.), not strings; this module is
|
|
11
|
+
* the canonical TS mirror of those ids — kept in lockstep with
|
|
12
|
+
* `packages/contracts/src/naming/AgentNamePredicates.sol`.
|
|
13
|
+
*
|
|
14
|
+
* Datatype binding:
|
|
15
|
+
* - `addr`, `custodyPolicy` → on-chain `address`
|
|
16
|
+
* - `agentKind`, `metadataHash`,
|
|
17
|
+
* `passkeyCredentialDigest` → on-chain `bytes32`
|
|
18
|
+
* - `displayName`, `a2aEndpoint`,
|
|
19
|
+
* `mcpEndpoint`, `metadataUri`,
|
|
20
|
+
* `nativeId` → on-chain `string`
|
|
21
|
+
*
|
|
22
|
+
* The encoder routes each predicate to its typed setter; the decoder
|
|
23
|
+
* routes each predicate to its typed getter. Unknown predicates are
|
|
24
|
+
* dropped on decode (fail-closed on read); encoders refuse unknown
|
|
25
|
+
* predicates (fail-loud on write).
|
|
26
|
+
*/
|
|
27
|
+
import { type Hex } from 'viem';
|
|
28
|
+
import type { AgentKind, AgentNameRecords } from './types';
|
|
29
|
+
export declare const PREDICATE_ID: {
|
|
30
|
+
readonly addr: `0x${string}`;
|
|
31
|
+
readonly agentKind: `0x${string}`;
|
|
32
|
+
readonly displayName: `0x${string}`;
|
|
33
|
+
readonly a2aEndpoint: `0x${string}`;
|
|
34
|
+
readonly mcpEndpoint: `0x${string}`;
|
|
35
|
+
readonly metadataUri: `0x${string}`;
|
|
36
|
+
readonly metadataHash: `0x${string}`;
|
|
37
|
+
readonly passkeyCredentialDigest: `0x${string}`;
|
|
38
|
+
readonly custodyPolicy: `0x${string}`;
|
|
39
|
+
readonly nativeId: `0x${string}`;
|
|
40
|
+
};
|
|
41
|
+
export type PredicateName = keyof typeof PREDICATE_ID;
|
|
42
|
+
export declare const AGENT_KIND_ID: Record<AgentKind, Hex>;
|
|
43
|
+
/** `keccak256("atl:AgentName")` — the ShapeRegistry class id. */
|
|
44
|
+
export declare const CLASS_AGENT_NAME: Hex;
|
|
45
|
+
/** `keccak256("atl:AgentKindEnum")` — the enum-set id bound to `atl:agentKind`. */
|
|
46
|
+
export declare const AGENT_KIND_ENUM: Hex;
|
|
47
|
+
/**
|
|
48
|
+
* Phase 1 CAIP-10 namespace allowlist for `nativeId`. Strict on
|
|
49
|
+
* encode (validate-at-write), permissive on decode (forward-compat).
|
|
50
|
+
*/
|
|
51
|
+
export declare const CAIP10_NAMESPACE_ALLOWLIST: ReadonlySet<string>;
|
|
52
|
+
/**
|
|
53
|
+
* The shape of one encoded predicate write. The consumer (Phase 4 SDK
|
|
54
|
+
* client + demos) chooses the matching `setXxxAttribute` setter
|
|
55
|
+
* by the `datatype` discriminator.
|
|
56
|
+
*/
|
|
57
|
+
export type EncodedRecord = {
|
|
58
|
+
predicate: Hex;
|
|
59
|
+
datatype: 'string';
|
|
60
|
+
value: string;
|
|
61
|
+
} | {
|
|
62
|
+
predicate: Hex;
|
|
63
|
+
datatype: 'address';
|
|
64
|
+
value: `0x${string}`;
|
|
65
|
+
} | {
|
|
66
|
+
predicate: Hex;
|
|
67
|
+
datatype: 'bytes32';
|
|
68
|
+
value: Hex;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Encode the typed `AgentNameRecords` bundle into per-predicate
|
|
72
|
+
* encoded-call args. Caller dispatches each to the resolver's typed
|
|
73
|
+
* `setXxxAttribute(node, predicate, value)` setter.
|
|
74
|
+
*/
|
|
75
|
+
export declare function encodeRecords(records: AgentNameRecords): EncodedRecord[];
|
|
76
|
+
/**
|
|
77
|
+
* The shape of one decoded result the SDK reads from the resolver.
|
|
78
|
+
* The reader pre-fetches `(predicateId → typed value)` pairs via the
|
|
79
|
+
* three typed getter families on the universal resolver
|
|
80
|
+
* (`resolveString`, `resolveBytes32`, `resolveAddress`).
|
|
81
|
+
*/
|
|
82
|
+
export interface DecodeInput {
|
|
83
|
+
strings: Partial<Record<Hex, string>>;
|
|
84
|
+
addresses: Partial<Record<Hex, `0x${string}`>>;
|
|
85
|
+
bytes32s: Partial<Record<Hex, Hex>>;
|
|
86
|
+
}
|
|
87
|
+
export declare function decodeRecords(input: DecodeInput): AgentNameRecords;
|
|
88
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAoB,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAa3D,eAAO,MAAM,YAAY;;;;;;;;;;;CAWf,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,YAAY,CAAC;AAItD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,CAIhD,CAAC;AAUF,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,EAAE,GAA8B,CAAC;AAC9D,mFAAmF;AACnF,eAAO,MAAM,eAAe,EAAE,GAAkC,CAAC;AAIjE;;;GAGG;AACH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAIzD,CAAC;AAMH;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,SAAS,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,SAAS,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,GAC7D;IAAE,SAAS,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE,CAAC;AAExD;;;;GAIG;AACH,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