inamprotocol 0.3.1 → 0.4.0

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/client.d.ts CHANGED
@@ -17,6 +17,17 @@ export declare class InamClient {
17
17
  private request;
18
18
  registerAgent(capabilities: string[], metadata?: Record<string, unknown>): Promise<AgentRecord>;
19
19
  getAgent(id: string): Promise<AgentRecord>;
20
+ /** Retires this client's own INAM ID (SPEC.md §2.2). One-way — a revoked
21
+ * ID performs no further signed operations and drops out of search. This
22
+ * is the key-compromise / key-rotation-off tool: an INAM ID *is* its
23
+ * Ed25519 key, so a leaked key can't be re-pointed, only burned. Call
24
+ * this while you still control the key. */
25
+ revoke(reason: string): Promise<AgentRecord>;
26
+ /** Grants or revokes `targetAgentId`'s verifier status (SPEC.md §12.3).
27
+ * Only succeeds when this client's own keypair is the registry's
28
+ * configured operator identity — anyone else gets NOT_OPERATOR. There is
29
+ * no self-service path to becoming a verifier. */
30
+ setVerifierStatus(targetAgentId: string, authorized: boolean): Promise<AgentRecord>;
20
31
  /** Links `a2a_endpoint` — the one protocol that isn't a key-derived
21
32
  * identity, so there's nothing to prove control of beyond this request's
22
33
  * own INAM signature. For `agentpass_id` / `aitp_id` / `passport_id`, use
@@ -47,6 +58,10 @@ export declare class InamClient {
47
58
  /** Called by the requester (agent_a) to accept the worker's submitted result. */
48
59
  acceptWork(receipt: ExecutionReceipt): Promise<ExecutionReceipt>;
49
60
  disputeReceipt(receiptId: string, reason: string): Promise<ExecutionReceipt>;
61
+ /** Withdraw a dispute this client opened (SPEC.md §4.3) — moves the receipt
62
+ * `disputed` -> `finalized` so it counts toward reputation again. Only the
63
+ * party that opened the dispute may call this, and only once. */
64
+ resolveDispute(receiptId: string, note?: string): Promise<ExecutionReceipt>;
50
65
  postJob(input: {
51
66
  capability: string;
52
67
  specHash: string;
package/dist/client.js CHANGED
@@ -50,6 +50,25 @@ export class InamClient {
50
50
  getAgent(id) {
51
51
  return this.request("GET", `/v1/agents/${encodeURIComponent(id)}`);
52
52
  }
53
+ /** Retires this client's own INAM ID (SPEC.md §2.2). One-way — a revoked
54
+ * ID performs no further signed operations and drops out of search. This
55
+ * is the key-compromise / key-rotation-off tool: an INAM ID *is* its
56
+ * Ed25519 key, so a leaked key can't be re-pointed, only burned. Call
57
+ * this while you still control the key. */
58
+ revoke(reason) {
59
+ return this.request("POST", `/v1/agents/${encodeURIComponent(this.keypair.did)}/revoke`, { reason }, {
60
+ idempotencyKey: `revoke:${this.keypair.did}`,
61
+ });
62
+ }
63
+ /** Grants or revokes `targetAgentId`'s verifier status (SPEC.md §12.3).
64
+ * Only succeeds when this client's own keypair is the registry's
65
+ * configured operator identity — anyone else gets NOT_OPERATOR. There is
66
+ * no self-service path to becoming a verifier. */
67
+ setVerifierStatus(targetAgentId, authorized) {
68
+ return this.request("POST", `/v1/agents/${encodeURIComponent(targetAgentId)}/verifier-status`, { authorized }, {
69
+ idempotencyKey: `verifier-status:${targetAgentId}:${authorized}:${Date.now()}`,
70
+ });
71
+ }
53
72
  /** Links `a2a_endpoint` — the one protocol that isn't a key-derived
54
73
  * identity, so there's nothing to prove control of beyond this request's
55
74
  * own INAM signature. For `agentpass_id` / `aitp_id` / `passport_id`, use
@@ -118,6 +137,14 @@ export class InamClient {
118
137
  idempotencyKey: `dispute:${receiptId}`,
119
138
  });
120
139
  }
140
+ /** Withdraw a dispute this client opened (SPEC.md §4.3) — moves the receipt
141
+ * `disputed` -> `finalized` so it counts toward reputation again. Only the
142
+ * party that opened the dispute may call this, and only once. */
143
+ resolveDispute(receiptId, note) {
144
+ return this.request("POST", `/v1/receipts/${encodeURIComponent(receiptId)}/dispute/resolve`, note ? { note } : {}, {
145
+ idempotencyKey: `dispute-resolve:${receiptId}`,
146
+ });
147
+ }
121
148
  // ---- Jobs (SPEC.md §3) — optional pre-work discovery/offer/accept ----
122
149
  postJob(input) {
123
150
  return this.request("POST", "/v1/jobs", input, { idempotencyKey: `job:${input.capability}:${input.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E,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,SAAS,EAAE,EAC3L,EAAE,cAAc,EAAE,gBAAgB,OAAO,CAAC,cAAc,EAAE,EAAE,CAC7D,CAAC;IACJ,CAAC;IAED,eAAe,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,qBAAqB,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,wBAAwB,CAAC,SAAiB;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,kBAAkB,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAC5F,CAAC;CACF"}
@@ -0,0 +1,268 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Request-body validation schemas — the one other piece of logic every
4
+ * runtime in this repo must agree on precisely, same principle as
5
+ * canonical.ts and receiptContent.ts. Before this file existed, the Node
6
+ * reference server (src/routes/*.ts) validated every mutating request with
7
+ * these exact Zod schemas, while the Cloudflare Worker (worker/src/index.ts)
8
+ * only checked that each required field was *present*, never that its value
9
+ * was actually valid — e.g. a signed POST /v1/verifications with
10
+ * `{ "result": "banana", "score": 999 }` would be rejected by the Node
11
+ * server but accepted by the Worker, silently writing an invalid `result`
12
+ * value into D1 forever. Both runtimes now import from here instead of
13
+ * defining their own copies, so "same request -> same validation -> same
14
+ * error code" is a property of sharing one schema, not of two
15
+ * independently-maintained ones happening to agree today.
16
+ */
17
+ export declare const setVerifierStatusSchema: z.ZodObject<{
18
+ authorized: z.ZodBoolean;
19
+ }, "strip", z.ZodTypeAny, {
20
+ authorized: boolean;
21
+ }, {
22
+ authorized: boolean;
23
+ }>;
24
+ export declare const revokeAgentSchema: z.ZodObject<{
25
+ reason: z.ZodString;
26
+ }, "strip", z.ZodTypeAny, {
27
+ reason: string;
28
+ }, {
29
+ reason: string;
30
+ }>;
31
+ export declare const registerAgentSchema: z.ZodObject<{
32
+ capabilities: z.ZodArray<z.ZodString, "many">;
33
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ capabilities: string[];
36
+ metadata?: Record<string, unknown> | undefined;
37
+ }, {
38
+ capabilities: string[];
39
+ metadata?: Record<string, unknown> | undefined;
40
+ }>;
41
+ export declare const linkChallengeSchema: z.ZodObject<{
42
+ protocol: z.ZodEnum<["agentpass_id", "aitp_id", "passport_id", "erc8004_id"]>;
43
+ externalPublicKey: z.ZodString;
44
+ keyType: z.ZodEnum<["ed25519", "p256", "secp256k1"]>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ protocol: "agentpass_id" | "aitp_id" | "passport_id" | "erc8004_id";
47
+ externalPublicKey: string;
48
+ keyType: "ed25519" | "p256" | "secp256k1";
49
+ }, {
50
+ protocol: "agentpass_id" | "aitp_id" | "passport_id" | "erc8004_id";
51
+ externalPublicKey: string;
52
+ keyType: "ed25519" | "p256" | "secp256k1";
53
+ }>;
54
+ export declare const linkSchema: z.ZodObject<{
55
+ protocol: z.ZodEnum<["agentpass_id", "aitp_id", "passport_id", "erc8004_id", "a2a_endpoint"]>;
56
+ value: z.ZodString;
57
+ challengeId: z.ZodOptional<z.ZodString>;
58
+ proofSignature: z.ZodOptional<z.ZodString>;
59
+ }, "strip", z.ZodTypeAny, {
60
+ value: string;
61
+ protocol: "agentpass_id" | "aitp_id" | "passport_id" | "erc8004_id" | "a2a_endpoint";
62
+ challengeId?: string | undefined;
63
+ proofSignature?: string | undefined;
64
+ }, {
65
+ value: string;
66
+ protocol: "agentpass_id" | "aitp_id" | "passport_id" | "erc8004_id" | "a2a_endpoint";
67
+ challengeId?: string | undefined;
68
+ proofSignature?: string | undefined;
69
+ }>;
70
+ export declare const postJobSchema: z.ZodObject<{
71
+ capability: z.ZodString;
72
+ specHash: z.ZodString;
73
+ budget: z.ZodOptional<z.ZodObject<{
74
+ amount: z.ZodOptional<z.ZodString>;
75
+ currency: z.ZodOptional<z.ZodString>;
76
+ }, "strip", z.ZodTypeAny, {
77
+ amount?: string | undefined;
78
+ currency?: string | undefined;
79
+ }, {
80
+ amount?: string | undefined;
81
+ currency?: string | undefined;
82
+ }>>;
83
+ expiresAt: z.ZodOptional<z.ZodString>;
84
+ }, "strip", z.ZodTypeAny, {
85
+ capability: string;
86
+ specHash: string;
87
+ budget?: {
88
+ amount?: string | undefined;
89
+ currency?: string | undefined;
90
+ } | undefined;
91
+ expiresAt?: string | undefined;
92
+ }, {
93
+ capability: string;
94
+ specHash: string;
95
+ budget?: {
96
+ amount?: string | undefined;
97
+ currency?: string | undefined;
98
+ } | undefined;
99
+ expiresAt?: string | undefined;
100
+ }>;
101
+ export declare const offerSchema: z.ZodObject<{
102
+ message: z.ZodOptional<z.ZodString>;
103
+ }, "strip", z.ZodTypeAny, {
104
+ message?: string | undefined;
105
+ }, {
106
+ message?: string | undefined;
107
+ }>;
108
+ export declare const acceptOfferSchema: z.ZodObject<{
109
+ agentId: z.ZodString;
110
+ }, "strip", z.ZodTypeAny, {
111
+ agentId: string;
112
+ }, {
113
+ agentId: string;
114
+ }>;
115
+ export declare const draftReceiptSchema: z.ZodObject<{
116
+ jobId: z.ZodString;
117
+ agentAId: z.ZodString;
118
+ task: z.ZodObject<{
119
+ capability: z.ZodString;
120
+ specHash: z.ZodString;
121
+ createdAt: z.ZodString;
122
+ }, "strip", z.ZodTypeAny, {
123
+ capability: string;
124
+ specHash: string;
125
+ createdAt: string;
126
+ }, {
127
+ capability: string;
128
+ specHash: string;
129
+ createdAt: string;
130
+ }>;
131
+ result: z.ZodObject<{
132
+ outputHash: z.ZodString;
133
+ outputUri: z.ZodOptional<z.ZodString>;
134
+ completedAt: z.ZodString;
135
+ }, "strip", z.ZodTypeAny, {
136
+ outputHash: string;
137
+ completedAt: string;
138
+ outputUri?: string | undefined;
139
+ }, {
140
+ outputHash: string;
141
+ completedAt: string;
142
+ outputUri?: string | undefined;
143
+ }>;
144
+ settlement: z.ZodOptional<z.ZodObject<{
145
+ amount: z.ZodOptional<z.ZodString>;
146
+ currency: z.ZodOptional<z.ZodString>;
147
+ paymentRef: z.ZodOptional<z.ZodString>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ amount?: string | undefined;
150
+ currency?: string | undefined;
151
+ paymentRef?: string | undefined;
152
+ }, {
153
+ amount?: string | undefined;
154
+ currency?: string | undefined;
155
+ paymentRef?: string | undefined;
156
+ }>>;
157
+ verification: z.ZodObject<{
158
+ method: z.ZodEnum<["payer_confirmation", "independent_validator", "test_suite_pass"]>;
159
+ verifier: z.ZodOptional<z.ZodString>;
160
+ outcome: z.ZodEnum<["success", "partial", "failed"]>;
161
+ }, "strip", z.ZodTypeAny, {
162
+ method: "payer_confirmation" | "independent_validator" | "test_suite_pass";
163
+ outcome: "success" | "partial" | "failed";
164
+ verifier?: string | undefined;
165
+ }, {
166
+ method: "payer_confirmation" | "independent_validator" | "test_suite_pass";
167
+ outcome: "success" | "partial" | "failed";
168
+ verifier?: string | undefined;
169
+ }>;
170
+ signature: z.ZodString;
171
+ }, "strip", z.ZodTypeAny, {
172
+ jobId: string;
173
+ task: {
174
+ capability: string;
175
+ specHash: string;
176
+ createdAt: string;
177
+ };
178
+ result: {
179
+ outputHash: string;
180
+ completedAt: string;
181
+ outputUri?: string | undefined;
182
+ };
183
+ verification: {
184
+ method: "payer_confirmation" | "independent_validator" | "test_suite_pass";
185
+ outcome: "success" | "partial" | "failed";
186
+ verifier?: string | undefined;
187
+ };
188
+ agentAId: string;
189
+ signature: string;
190
+ settlement?: {
191
+ amount?: string | undefined;
192
+ currency?: string | undefined;
193
+ paymentRef?: string | undefined;
194
+ } | undefined;
195
+ }, {
196
+ jobId: string;
197
+ task: {
198
+ capability: string;
199
+ specHash: string;
200
+ createdAt: string;
201
+ };
202
+ result: {
203
+ outputHash: string;
204
+ completedAt: string;
205
+ outputUri?: string | undefined;
206
+ };
207
+ verification: {
208
+ method: "payer_confirmation" | "independent_validator" | "test_suite_pass";
209
+ outcome: "success" | "partial" | "failed";
210
+ verifier?: string | undefined;
211
+ };
212
+ agentAId: string;
213
+ signature: string;
214
+ settlement?: {
215
+ amount?: string | undefined;
216
+ currency?: string | undefined;
217
+ paymentRef?: string | undefined;
218
+ } | undefined;
219
+ }>;
220
+ export declare const countersignSchema: z.ZodObject<{
221
+ signature: z.ZodString;
222
+ }, "strip", z.ZodTypeAny, {
223
+ signature: string;
224
+ }, {
225
+ signature: string;
226
+ }>;
227
+ export declare const disputeSchema: z.ZodObject<{
228
+ reason: z.ZodString;
229
+ }, "strip", z.ZodTypeAny, {
230
+ reason: string;
231
+ }, {
232
+ reason: string;
233
+ }>;
234
+ export declare const resolveDisputeSchema: z.ZodObject<{
235
+ note: z.ZodOptional<z.ZodString>;
236
+ }, "strip", z.ZodTypeAny, {
237
+ note?: string | undefined;
238
+ }, {
239
+ note?: string | undefined;
240
+ }>;
241
+ export declare const submitVerificationSchema: z.ZodObject<{
242
+ receiptId: z.ZodString;
243
+ verifier: z.ZodString;
244
+ method: z.ZodEnum<["deterministic", "agent_attestation"]>;
245
+ outputHash: z.ZodString;
246
+ result: z.ZodEnum<["verified", "rejected"]>;
247
+ score: z.ZodOptional<z.ZodNumber>;
248
+ evidenceUri: z.ZodOptional<z.ZodString>;
249
+ signature: z.ZodString;
250
+ }, "strip", z.ZodTypeAny, {
251
+ receiptId: string;
252
+ result: "verified" | "rejected";
253
+ method: "deterministic" | "agent_attestation";
254
+ verifier: string;
255
+ outputHash: string;
256
+ signature: string;
257
+ score?: number | undefined;
258
+ evidenceUri?: string | undefined;
259
+ }, {
260
+ receiptId: string;
261
+ result: "verified" | "rejected";
262
+ method: "deterministic" | "agent_attestation";
263
+ verifier: string;
264
+ outputHash: string;
265
+ signature: string;
266
+ score?: number | undefined;
267
+ evidenceUri?: string | undefined;
268
+ }>;
@@ -0,0 +1,103 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Request-body validation schemas — the one other piece of logic every
4
+ * runtime in this repo must agree on precisely, same principle as
5
+ * canonical.ts and receiptContent.ts. Before this file existed, the Node
6
+ * reference server (src/routes/*.ts) validated every mutating request with
7
+ * these exact Zod schemas, while the Cloudflare Worker (worker/src/index.ts)
8
+ * only checked that each required field was *present*, never that its value
9
+ * was actually valid — e.g. a signed POST /v1/verifications with
10
+ * `{ "result": "banana", "score": 999 }` would be rejected by the Node
11
+ * server but accepted by the Worker, silently writing an invalid `result`
12
+ * value into D1 forever. Both runtimes now import from here instead of
13
+ * defining their own copies, so "same request -> same validation -> same
14
+ * error code" is a property of sharing one schema, not of two
15
+ * independently-maintained ones happening to agree today.
16
+ */
17
+ export const setVerifierStatusSchema = z.object({
18
+ authorized: z.boolean(),
19
+ });
20
+ export const revokeAgentSchema = z.object({
21
+ reason: z.string().min(1).max(500),
22
+ });
23
+ export const registerAgentSchema = z.object({
24
+ capabilities: z.array(z.string().min(1)).min(1),
25
+ metadata: z.record(z.unknown()).optional(),
26
+ });
27
+ export const linkChallengeSchema = z.object({
28
+ protocol: z.enum(["agentpass_id", "aitp_id", "passport_id", "erc8004_id"]),
29
+ externalPublicKey: z.string().min(1),
30
+ keyType: z.enum(["ed25519", "p256", "secp256k1"]),
31
+ });
32
+ export const linkSchema = z.object({
33
+ protocol: z.enum(["agentpass_id", "aitp_id", "passport_id", "erc8004_id", "a2a_endpoint"]),
34
+ value: z.string().min(1),
35
+ challengeId: z.string().min(1).optional(),
36
+ proofSignature: z.string().min(1).optional(),
37
+ });
38
+ // An audit (SPEC.md v0.11) found `settlement.amount`/`currency` and a job's
39
+ // `budget` were `z.string()` with no shape check: `{ amount: "banana" }` or a
40
+ // negative amount passed validation, then `Number("banana")` -> NaN poisoned
41
+ // the reputation volume sums. `amount` is a non-negative decimal string;
42
+ // `currency` is a short code-shaped token (ISO-4217 like "USD" or a
43
+ // stablecoin ticker like "USDC"), not free-form prose.
44
+ const moneyAmount = z.string().regex(/^\d+(\.\d+)?$/, "must be a non-negative decimal string");
45
+ const currencyCode = z.string().regex(/^[A-Za-z0-9]{1,16}$/, "must be a short currency code");
46
+ const moneyFields = { amount: moneyAmount.optional(), currency: currencyCode.optional() };
47
+ export const postJobSchema = z.object({
48
+ capability: z.string().min(1),
49
+ specHash: z.string().min(1),
50
+ budget: z.object({ ...moneyFields }).optional(),
51
+ expiresAt: z.string().optional(),
52
+ });
53
+ export const offerSchema = z.object({ message: z.string().optional() });
54
+ export const acceptOfferSchema = z.object({ agentId: z.string().min(1) });
55
+ // `{ offset: true }` accepts both JS's `Date.prototype.toISOString()` output
56
+ // ("...526Z") and Python's `datetime.isoformat()` output for a UTC-aware
57
+ // datetime ("...459111+00:00") -- confirmed by hand, since these differ in
58
+ // both suffix style and fractional-second precision and an audit's
59
+ // future-dating finding (SPEC.md v0.7 / CHANGELOG) made date validation here
60
+ // necessary. Bounds/ordering (not-in-the-future, completedAt >= createdAt)
61
+ // are enforced in receiptService.ts, not here -- this only validates shape,
62
+ // consistent with the schema/business-rule split elsewhere in this file.
63
+ const isoDateTime = z.string().datetime({ offset: true });
64
+ export const draftReceiptSchema = z.object({
65
+ jobId: z.string().min(1),
66
+ agentAId: z.string().min(1),
67
+ task: z.object({
68
+ capability: z.string().min(1),
69
+ specHash: z.string().min(1),
70
+ createdAt: isoDateTime,
71
+ }),
72
+ result: z.object({
73
+ outputHash: z.string().min(1),
74
+ outputUri: z.string().optional(),
75
+ completedAt: isoDateTime,
76
+ }),
77
+ settlement: z
78
+ .object({
79
+ paymentRef: z.string().optional(),
80
+ ...moneyFields,
81
+ })
82
+ .optional(),
83
+ verification: z.object({
84
+ method: z.enum(["payer_confirmation", "independent_validator", "test_suite_pass"]),
85
+ verifier: z.string().optional(),
86
+ outcome: z.enum(["success", "partial", "failed"]),
87
+ }),
88
+ signature: z.string().min(1),
89
+ });
90
+ export const countersignSchema = z.object({ signature: z.string().min(1) });
91
+ export const disputeSchema = z.object({ reason: z.string().min(1) });
92
+ export const resolveDisputeSchema = z.object({ note: z.string().max(500).optional() });
93
+ export const submitVerificationSchema = z.object({
94
+ receiptId: z.string().min(1),
95
+ verifier: z.string().min(1),
96
+ method: z.enum(["deterministic", "agent_attestation"]),
97
+ outputHash: z.string().min(1),
98
+ result: z.enum(["verified", "rejected"]),
99
+ score: z.number().min(0).max(1).optional(),
100
+ evidenceUri: z.string().optional(),
101
+ signature: z.string().min(1),
102
+ });
103
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/core/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;IAC1E,iBAA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AC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IACtD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC1C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Settlement-amount aggregation for the reputation model (SPEC.md §5.3).
3
+ *
4
+ * An audit found `components.volumeUsd` summed every finalized receipt's
5
+ * `settlement.amount` regardless of `settlement.currency` — a 1000 TRY receipt
6
+ * added 1000 to a field labelled USD, right next to a 10 USDC one. INAM does
7
+ * no FX and takes no position on stablecoin pegs (§10 — payments/settlement
8
+ * enforcement is out of scope), so the honest fix is to bucket volume by the
9
+ * currency it was actually denominated in and never cross-sum.
10
+ *
11
+ * Shared by both runtimes (src/, worker/) so the two agree by construction,
12
+ * same principle as canonical.ts / receiptContent.ts / schemas.ts.
13
+ */
14
+ /**
15
+ * Normalize a free-form `settlement.currency` to a bucket key. Missing or
16
+ * blank is treated as `"USD"` — `volumeUsd` has always implicitly assumed an
17
+ * untagged amount was USD, and receipts predating any currency discipline
18
+ * still need to land somewhere sensible.
19
+ */
20
+ export declare function normalizeCurrency(currency?: string): string;
21
+ /**
22
+ * Parse a `settlement.amount` string to a non-negative finite number, or 0.
23
+ * A registry MUST NOT let a malformed or negative amount poison the running
24
+ * volume sums (same principle as the non-finite-weight guard in §5.2) — the
25
+ * reference schema rejects such values at ingestion, but data from a
26
+ * non-conformant registry still flows through here.
27
+ */
28
+ export declare function parseSettlementAmount(amount?: string): number;
29
+ /** Add one receipt's settlement into a currency→total map, in place. */
30
+ export declare function accrueVolume(byCurrency: Record<string, number>, settlement?: {
31
+ amount?: string;
32
+ currency?: string;
33
+ }): void;
34
+ /** Round every bucket to 2 decimal places — these are money totals, not raw
35
+ * floats, and `0.1 + 0.2` should not surface in an API response. */
36
+ export declare function roundVolumes(byCurrency: Record<string, number>): Record<string, number>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Settlement-amount aggregation for the reputation model (SPEC.md §5.3).
3
+ *
4
+ * An audit found `components.volumeUsd` summed every finalized receipt's
5
+ * `settlement.amount` regardless of `settlement.currency` — a 1000 TRY receipt
6
+ * added 1000 to a field labelled USD, right next to a 10 USDC one. INAM does
7
+ * no FX and takes no position on stablecoin pegs (§10 — payments/settlement
8
+ * enforcement is out of scope), so the honest fix is to bucket volume by the
9
+ * currency it was actually denominated in and never cross-sum.
10
+ *
11
+ * Shared by both runtimes (src/, worker/) so the two agree by construction,
12
+ * same principle as canonical.ts / receiptContent.ts / schemas.ts.
13
+ */
14
+ /**
15
+ * Normalize a free-form `settlement.currency` to a bucket key. Missing or
16
+ * blank is treated as `"USD"` — `volumeUsd` has always implicitly assumed an
17
+ * untagged amount was USD, and receipts predating any currency discipline
18
+ * still need to land somewhere sensible.
19
+ */
20
+ export function normalizeCurrency(currency) {
21
+ const c = (currency ?? "").trim().toUpperCase();
22
+ return c === "" ? "USD" : c;
23
+ }
24
+ /**
25
+ * Parse a `settlement.amount` string to a non-negative finite number, or 0.
26
+ * A registry MUST NOT let a malformed or negative amount poison the running
27
+ * volume sums (same principle as the non-finite-weight guard in §5.2) — the
28
+ * reference schema rejects such values at ingestion, but data from a
29
+ * non-conformant registry still flows through here.
30
+ */
31
+ export function parseSettlementAmount(amount) {
32
+ const n = Number(amount ?? 0);
33
+ return Number.isFinite(n) && n >= 0 ? n : 0;
34
+ }
35
+ /** Add one receipt's settlement into a currency→total map, in place. */
36
+ export function accrueVolume(byCurrency, settlement) {
37
+ const amount = parseSettlementAmount(settlement?.amount);
38
+ if (amount === 0)
39
+ return;
40
+ const key = normalizeCurrency(settlement?.currency);
41
+ byCurrency[key] = (byCurrency[key] ?? 0) + amount;
42
+ }
43
+ /** Round every bucket to 2 decimal places — these are money totals, not raw
44
+ * floats, and `0.1 + 0.2` should not surface in an API response. */
45
+ export function roundVolumes(byCurrency) {
46
+ const out = {};
47
+ for (const [k, v] of Object.entries(byCurrency))
48
+ out[k] = Math.round(v * 100) / 100;
49
+ return out;
50
+ }
51
+ //# sourceMappingURL=settlementVolume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlementVolume.js","sourceRoot":"","sources":["../../src/core/settlementVolume.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiB;IACjD,MAAM,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAChD,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAe;IACnD,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAC1B,UAAkC,EAClC,UAAmD;IAEnD,MAAM,MAAM,GAAG,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACzD,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO;IACzB,MAAM,GAAG,GAAG,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACpD,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC;AACpD,CAAC;AAED;qEACqE;AACrE,MAAM,UAAU,YAAY,CAAC,UAAkC;IAC7D,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACpF,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * ECDSA secp256k1, offered alongside Ed25519/P-256 (SPEC.md §2.1) so an
3
+ * ERC-8004 (EVM) identity can prove control of its key without any bridge
4
+ * curve — secp256k1 is the curve every Ethereum wallet already uses.
5
+ *
6
+ * Digest = keccak256("\x19Ethereum Signed Message:\n32" + challenge), i.e.
7
+ * Ethereum's standard `personal_sign` prefix over the 32 raw challenge bytes.
8
+ * This means a real EVM wallet (MetaMask, viem, ethers `signMessage`) can
9
+ * produce a valid proof signature with zero custom code on the caller's
10
+ * side — the whole point of adding this curve.
11
+ *
12
+ * `secp256k1.sign`/`.verify` return/accept the 64-byte compact r||s encoding
13
+ * and enforce low-S by default (same as p256.ts) — no manual canonicalization
14
+ * needed here. Unlike p256.sign/verify, though, noble's secp256k1 defaults to
15
+ * `prehash: true` (it SHA-256-hashes whatever `message` you pass before
16
+ * signing/verifying) — since this module already hashes the challenge itself
17
+ * (keccak256, not SHA-256, per Ethereum's `personal_sign` convention above),
18
+ * every call below passes `{ prehash: false }` to say "this is already a
19
+ * digest, don't hash it again." Omitting it doesn't break same-language
20
+ * round-trips (sign and verify would both silently double-hash, cancelling
21
+ * out) but breaks cross-language verification against sdk-python's digest —
22
+ * caught live via the v0.18 cross-language proof before this shipped.
23
+ */
24
+ export interface Secp256k1Keypair {
25
+ publicKey: Uint8Array;
26
+ privateKey: Uint8Array;
27
+ }
28
+ export declare function generateSecp256k1Keypair(): Secp256k1Keypair;
29
+ /** Ethereum's `personal_sign` prefix, applied before hashing — see module doc. */
30
+ export declare function ethPersonalSignDigest(message: Uint8Array): Uint8Array;
31
+ export declare function secp256k1Sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
32
+ export declare function secp256k1Verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
33
+ /** Derives the lowercase 0x-prefixed Ethereum address for an uncompressed
34
+ * secp256k1 public key: `"0x" + hex(keccak256(pubkey[1:]))[-40:]` — the same
35
+ * self-certifying principle INAM's own did:key (§2) uses. Required so an
36
+ * `erc8004_id` link (SPEC.md §2.1) can't claim an address unrelated to the
37
+ * key it just proved possession of. */
38
+ export declare function ethAddressFromUncompressedPublicKey(publicKey: Uint8Array): string;
@@ -0,0 +1,41 @@
1
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
2
+ import { keccak_256 } from "@noble/hashes/sha3.js";
3
+ import { toHex } from "./keys.js";
4
+ export function generateSecp256k1Keypair() {
5
+ const privateKey = secp256k1.utils.randomSecretKey();
6
+ const publicKey = secp256k1.getPublicKey(privateKey, false);
7
+ return { privateKey, publicKey };
8
+ }
9
+ /** Ethereum's `personal_sign` prefix, applied before hashing — see module doc. */
10
+ export function ethPersonalSignDigest(message) {
11
+ const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${message.length}`);
12
+ const prefixed = new Uint8Array(prefix.length + message.length);
13
+ prefixed.set(prefix, 0);
14
+ prefixed.set(message, prefix.length);
15
+ return keccak_256(prefixed);
16
+ }
17
+ export function secp256k1Sign(message, privateKey) {
18
+ return secp256k1.sign(ethPersonalSignDigest(message), privateKey, { prehash: false });
19
+ }
20
+ export function secp256k1Verify(signature, message, publicKey) {
21
+ try {
22
+ return secp256k1.verify(signature, ethPersonalSignDigest(message), publicKey, { prehash: false });
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ /** Derives the lowercase 0x-prefixed Ethereum address for an uncompressed
29
+ * secp256k1 public key: `"0x" + hex(keccak256(pubkey[1:]))[-40:]` — the same
30
+ * self-certifying principle INAM's own did:key (§2) uses. Required so an
31
+ * `erc8004_id` link (SPEC.md §2.1) can't claim an address unrelated to the
32
+ * key it just proved possession of. */
33
+ export function ethAddressFromUncompressedPublicKey(publicKey) {
34
+ if (publicKey.length !== 65 || publicKey[0] !== 0x04) {
35
+ throw new Error("expected an uncompressed secp256k1 public key (65 bytes, 0x04 prefix)");
36
+ }
37
+ const hash = keccak_256(publicKey.slice(1));
38
+ const addressBytes = hash.slice(-20);
39
+ return "0x" + toHex(addressBytes);
40
+ }
41
+ //# sourceMappingURL=secp256k1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../src/crypto/secp256k1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AA+BlC,MAAM,UAAU,wBAAwB;IACtC,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IACrD,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC5D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AACnC,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,qBAAqB,CAAC,OAAmB;IACvD,MAAM,M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C,OAAO,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;AACpC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { InamClient } from "./client.js";
2
2
  export { generateKeypair, keypairFromPrivateKey, publicKeyToDid, didToPublicKey, sign, verify, verifyRawEd25519, sha256Hex, toBase64, fromBase64, toHex, fromHex, type Keypair, } from "./crypto/keys.js";
3
3
  export { generateP256Keypair, p256Sign, p256Verify, type P256Keypair } from "./crypto/p256.js";
4
+ export { generateSecp256k1Keypair, secp256k1Sign, secp256k1Verify, ethAddressFromUncompressedPublicKey, ethPersonalSignDigest, type Secp256k1Keypair, } from "./crypto/secp256k1.js";
4
5
  export { canonicalize } from "./crypto/canonical.js";
5
6
  export { computeReceiptId, buildSignableContent, type ReceiptContentInput } from "./core/receiptContent.js";
6
7
  export { computeVerificationId, buildSignableVerificationContent, type VerificationContentInput } from "./core/verificationContent.js";
7
- export type { LinkedIdentities, ExternalKeyType, LinkChallenge, AgentRecord, VerificationMethod, ReceiptOutcome, ReceiptStatus, DisputeStatus, ExecutionReceipt, SignableReceiptContent, ReputationComponents, ReputationResult, JobStatus, JobOffer, JobRecord, IndependentVerificationMethod, VerificationResult, VerificationRecord, } from "./types.js";
8
+ export { registerAgentSchema, linkChallengeSchema, linkSchema, postJobSchema, offerSchema, acceptOfferSchema, draftReceiptSchema, countersignSchema, disputeSchema, submitVerificationSchema, setVerifierStatusSchema, } from "./core/schemas.js";
9
+ export type { LinkedIdentities, ExternalKeyType, LinkChallenge, AgentRecord, VerificationMethod, ReceiptOutcome, ReceiptStatus, DisputeStatus, ExecutionReceipt, SignableReceiptContent, ReputationComponents, ReputationRoleBreakdown, ReputationResult, JobStatus, JobOffer, JobRecord, IndependentVerificationMethod, VerificationResult, VerificationRecord, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,7 +1,14 @@
1
1
  export { InamClient } from "./client.js";
2
2
  export { generateKeypair, keypairFromPrivateKey, publicKeyToDid, didToPublicKey, sign, verify, verifyRawEd25519, sha256Hex, toBase64, fromBase64, toHex, fromHex, } from "./crypto/keys.js";
3
3
  export { generateP256Keypair, p256Sign, p256Verify } from "./crypto/p256.js";
4
+ export { generateSecp256k1Keypair, secp256k1Sign, secp256k1Verify, ethAddressFromUncompressedPublicKey, ethPersonalSignDigest, } from "./crypto/secp256k1.js";
4
5
  export { canonicalize } from "./crypto/canonical.js";
5
6
  export { computeReceiptId, buildSignableContent } from "./core/receiptContent.js";
6
7
  export { computeVerificationId, buildSignableVerificationContent } from "./core/verificationContent.js";
8
+ // Request-body validation schemas — shared by the Node reference server and
9
+ // the Cloudflare Worker so both accept/reject the exact same requests (see
10
+ // core/schemas.ts's own header comment for why this exists). Exported
11
+ // publicly too: a caller building requests by hand (rather than through
12
+ // InamClient) can validate a payload client-side before sending it.
13
+ export { registerAgentSchema, linkChallengeSchema, linkSchema, postJobSchema, offerSchema, acceptOfferSchema, draftReceiptSchema, countersignSchema, disputeSchema, submitVerificationSchema, setVerifierStatusSchema, } from "./core/schemas.js";
7
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,KAAK,EACL,OAAO,GAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAE/F,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAA4B,MAAM,0BAA0B,CAAC;AAE5G,OAAO,EAAE,qBAAqB,EAAE,gCAAgC,EAAiC,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,IAAI,EACJ,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,KAAK,EACL,OAAO,GAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAE/F,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,mCAAmC,EACnC,qBAAqB,GAEtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAA4B,MAAM,0BAA0B,CAAC;AAE5G,OAAO,EAAE,qBAAqB,EAAE,gCAAgC,EAAiC,MAAM,+BAA+B,CAAC;AAEvI,4EAA4E;AAC5E,2EAA2E;AAC3E,sEAAsE;AACtE,wEAAwE;AACxE,oEAAoE;AACpE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC"}
package/dist/types.d.ts CHANGED
@@ -8,13 +8,38 @@ export interface LinkedIdentities {
8
8
  agentpass_id?: string;
9
9
  aitp_id?: string;
10
10
  passport_id?: string;
11
+ erc8004_id?: string;
11
12
  a2a_endpoint?: string;
12
13
  }
13
14
  /** Key type used to prove control of an external identity's public key
14
15
  * before linking it (SPEC.md's external-identity linking section). P-256
15
16
  * matches ATTP (the protocol AgentPass is built on); Ed25519 is offered as
16
- * the same primitive INAM's own did:key already uses. */
17
- export type ExternalKeyType = "ed25519" | "p256";
17
+ * the same primitive INAM's own did:key already uses; secp256k1 is the curve
18
+ * ERC-8004 (EVM) identities use. */
19
+ export type ExternalKeyType = "ed25519" | "p256" | "secp256k1";
20
+ /** How one `linked` entry was verified when it was recorded (SPEC.md §2.1).
21
+ * - `key_possession`: the caller proved control of `externalPublicKey` via a
22
+ * signed challenge at `verifiedAt`. This does NOT confirm that key is the
23
+ * one the external system currently recognizes as authoritative for the
24
+ * identity — live cross-registry resolution is out of scope (SPEC.md §10).
25
+ * - `unverified_claim`: an INAM-signed assertion only, no external proof
26
+ * (`a2a_endpoint`, a service URL rather than a key-derived identity). */
27
+ export interface LinkProof {
28
+ method: "key_possession" | "unverified_claim";
29
+ verifiedAt: string;
30
+ keyType?: ExternalKeyType;
31
+ externalPublicKey?: string;
32
+ }
33
+ /** Per-protocol assurance metadata for `linked`, same keys as
34
+ * `LinkedIdentities` (SPEC.md §2.1). A missing key means that identity isn't
35
+ * linked. */
36
+ export interface LinkedIdentityProofs {
37
+ agentpass_id?: LinkProof;
38
+ aitp_id?: LinkProof;
39
+ passport_id?: LinkProof;
40
+ erc8004_id?: LinkProof;
41
+ a2a_endpoint?: LinkProof;
42
+ }
18
43
  /** Response shape from POST /agents/:id/link/challenge. */
19
44
  export interface LinkChallenge {
20
45
  challengeId: string;
@@ -26,8 +51,22 @@ export interface AgentRecord {
26
51
  capabilities: string[];
27
52
  metadata: Record<string, unknown>;
28
53
  linked: LinkedIdentities;
54
+ /** Per-protocol assurance metadata for `linked` (SPEC.md §2.1) — lets a
55
+ * consumer tell a challenge-verified link from an unverified claim. */
56
+ linkedProof: LinkedIdentityProofs;
29
57
  stakeUsd: number;
30
58
  createdAt: string;
59
+ /** Whether the registry operator has authorized this agent as a verifier
60
+ * (SPEC.md §12.3) — false by default at registration. An agent cannot make
61
+ * itself a verifier by self-registering; only the registry's configured
62
+ * operator identity can grant this via POST /agents/:id/verifier-status. */
63
+ isAuthorizedVerifier: boolean;
64
+ /** ISO timestamp the agent retired this INAM ID via POST /agents/:id/revoke
65
+ * (SPEC.md §2.2) — a one-way, self-signed tombstone for a compromised or
66
+ * rotated-off key. Absent for an active agent. A revoked ID can perform no
67
+ * further signed operations and is excluded from search. */
68
+ revokedAt?: string;
69
+ revocationReason?: string;
31
70
  }
32
71
  export type VerificationMethod = "payer_confirmation" | "independent_validator" | "test_suite_pass";
33
72
  export type ReceiptOutcome = "success" | "partial" | "failed";
@@ -69,6 +108,9 @@ export interface ExecutionReceipt {
69
108
  status: DisputeStatus;
70
109
  reason?: string;
71
110
  windowClosesAt: string;
111
+ openedBy?: string;
112
+ resolvedAt?: string;
113
+ resolution?: string;
72
114
  };
73
115
  signatures: {
74
116
  agentB?: string;
@@ -83,18 +125,47 @@ export type SignableReceiptContent = Omit<ExecutionReceipt, "signatures" | "stat
83
125
  windowClosesAt: string;
84
126
  };
85
127
  };
128
+ /** Weighted receipt count/success-rate/volume for one side of an agent's
129
+ * history — see ReputationComponents.asProvider/asRequester. Same weighting
130
+ * (pairWeight * counterpartyTrust * decay * attestationBoost) as the
131
+ * aggregate trustScore, just filtered to receipts where this agent held
132
+ * that role. Not a separate 0-100 score (that's real scoring-model design
133
+ * work, not done here) — the raw signal an aggregate trustScore currently
134
+ * merges away. */
135
+ export interface ReputationRoleBreakdown {
136
+ receipts: number;
137
+ successRate: number;
138
+ /** Volume denominated in USD (or untagged) only — see
139
+ * ReputationComponents.volumeUsd/volumeByCurrency. */
140
+ volumeUsd: number;
141
+ /** Settlement volume bucketed by `settlement.currency`, never cross-summed. */
142
+ volumeByCurrency: Record<string, number>;
143
+ }
86
144
  export interface ReputationComponents {
87
145
  eigenWeight: number;
88
146
  verifiedReceipts: number;
89
147
  rawReceipts: number;
90
148
  successRate: number;
149
+ /** Total settlement volume across finalized receipts denominated in USD
150
+ * (currency `"USD"` or untagged) only. An audit found this field summed
151
+ * every currency's raw `settlement.amount` into one USD-labelled number;
152
+ * INAM does no FX, so non-USD volume now lives only in `volumeByCurrency`. */
91
153
  volumeUsd: number;
154
+ /** Settlement volume bucketed by normalized `settlement.currency`
155
+ * (uppercased; untagged -> `"USD"`), never converted or cross-summed. */
156
+ volumeByCurrency: Record<string, number>;
92
157
  stakeUsd: number;
93
158
  decayHalfLifeDays: number;
94
159
  /** Count of finalized receipts backed by at least one `verified` Verification
95
160
  * (SPEC.md §12.5) — distinct from `verifiedReceipts` above, which really
96
161
  * means "two-party finalized," not independently attested. */
97
162
  attestedReceipts: number;
163
+ /** This agent's history specifically as agentB (the one who did the work)
164
+ * on its finalized receipts (SPEC.md §5.3). */
165
+ asProvider: ReputationRoleBreakdown;
166
+ /** This agent's history specifically as agentA (the one who requested and
167
+ * countersigned the work) on its finalized receipts (SPEC.md §5.3). */
168
+ asRequester: ReputationRoleBreakdown;
98
169
  }
99
170
  export interface ReputationResult {
100
171
  trustScore: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inamprotocol",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Reference TypeScript/JavaScript SDK for the INAM Protocol — agent identity, execution receipts, jobs, and reputation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,7 +43,8 @@
43
43
  "@noble/curves": "^2.3.0",
44
44
  "@noble/ed25519": "^2.1.0",
45
45
  "@noble/hashes": "^1.5.0",
46
- "bs58": "^6.0.0"
46
+ "bs58": "^6.0.0",
47
+ "zod": "^3.23.8"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/node": "^22.5.0",