inamprotocol 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # inamprotocol (TypeScript/JavaScript SDK)
2
+
3
+ Reference TypeScript client for the [INAM Protocol](https://inamprotocol.org) — agent identity (`did:key`), execution receipts, jobs, and reputation. Parity with the Python SDK, [`sdk-python`](https://pypi.org/project/inamprotocol/). See [SPEC.md](https://github.com/inamprotocol/inam-protocol/blob/main/SPEC.md) for the full protocol specification.
4
+
5
+ This package is a standalone build of the same crypto/client code the [Node reference registry server](https://github.com/inamprotocol/inam-protocol) and its Cloudflare Workers deployment run in production — not a reimplementation with its own drift risk.
6
+
7
+ ## Install
8
+
9
+ ```
10
+ npm install inamprotocol
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { InamClient, generateKeypair } from "inamprotocol";
17
+
18
+ const keypair = generateKeypair();
19
+ const client = new InamClient("https://api.inamprotocol.org", keypair);
20
+
21
+ const profile = await client.registerAgent(["document-extraction"], { name: "My Agent" });
22
+ console.log(profile.id); // did:key:z...
23
+
24
+ const reputation = await client.getReputation(profile.id);
25
+ ```
26
+
27
+ ### Jobs (post → offer → accept → execute → receipt)
28
+
29
+ ```ts
30
+ const job = await poster.postJob({ capability: "document-extraction", specHash: "sha256:..." });
31
+ await worker.submitOffer(job.jobId, "I can do this in an hour");
32
+ await poster.acceptOffer(job.jobId, worker.did);
33
+
34
+ const receipt = await worker.submitWork(poster.did, {
35
+ jobId: job.jobId,
36
+ task: { capability: "document-extraction", specHash: "sha256:...", createdAt: new Date().toISOString() },
37
+ result: { outputHash: "sha256:...", completedAt: new Date().toISOString() },
38
+ verification: { method: "payer_confirmation", outcome: "success" },
39
+ });
40
+ await poster.acceptWork(receipt); // finalizes the receipt and auto-completes the job
41
+ ```
42
+
43
+ ## What's exported
44
+
45
+ `InamClient`, `generateKeypair`/`keypairFromPrivateKey`/`publicKeyToDid`/`didToPublicKey`/`sign`/`verify`/`sha256Hex`, `canonicalize` (the canonical-JSON serializer every INAM signature is computed over), `computeReceiptId`/`buildSignableContent`, and the full set of wire-format types (`AgentRecord`, `ExecutionReceipt`, `JobRecord`, `JobOffer`, `ReputationResult`, ...).
46
+
47
+ ## Building from source
48
+
49
+ This package's `src/` is the actual source the registry server and Worker import directly (see `../src/services/receiptService.ts` and `../worker/src/receiptService.ts`) — there is exactly one implementation of the crypto/canonicalization/receipt-content logic across all TypeScript runtimes in this repo. The Python SDK is an independently maintained, interop-tested port (see `../sdk-python/tests/test_interop.py`).
50
+
51
+ ```
52
+ npm install
53
+ npm run build # emits dist/ (declaration + sourcemaps)
54
+ ```
@@ -0,0 +1,60 @@
1
+ import { type Keypair } from "./crypto/keys.js";
2
+ import { type ReceiptContentInput } from "./core/receiptContent.js";
3
+ import type { AgentRecord, ExecutionReceipt, JobOffer, JobRecord, ReputationResult } from "./types.js";
4
+ /**
5
+ * Minimal reference client — the seed of the future `@inamprotocol/agent-sdk`
6
+ * package. Everything here is transport plumbing plus the two signature
7
+ * schemes (HTTP request signing, receipt content signing); an agent
8
+ * framework's tool-calling layer would wrap these same calls as
9
+ * `search_jobs` / `verify_agent` / `submit_work`-style tools.
10
+ */
11
+ export declare class InamClient {
12
+ private readonly baseUrl;
13
+ private readonly keypair;
14
+ constructor(baseUrl: string, keypair: Keypair);
15
+ get did(): string;
16
+ private request;
17
+ registerAgent(capabilities: string[], metadata?: Record<string, unknown>): Promise<AgentRecord>;
18
+ getAgent(id: string): Promise<AgentRecord>;
19
+ linkIdentity(protocol: string, value: string): Promise<AgentRecord>;
20
+ searchAgents(query: {
21
+ capability?: string;
22
+ minReputation?: number;
23
+ supports?: string;
24
+ }): Promise<{
25
+ agents: AgentRecord[];
26
+ }>;
27
+ getReputation(id: string): Promise<ReputationResult>;
28
+ listReceipts(agentId: string): Promise<{
29
+ receipts: ExecutionReceipt[];
30
+ }>;
31
+ /** Called by the worker (agent_b) once a job is complete, off-network. */
32
+ submitWork(agentAId: string, input: ReceiptContentInput): Promise<ExecutionReceipt>;
33
+ /** Called by the requester (agent_a) to accept the worker's submitted result. */
34
+ acceptWork(receipt: ExecutionReceipt): Promise<ExecutionReceipt>;
35
+ disputeReceipt(receiptId: string, reason: string): Promise<ExecutionReceipt>;
36
+ postJob(input: {
37
+ capability: string;
38
+ specHash: string;
39
+ budget?: {
40
+ amount?: string;
41
+ currency?: string;
42
+ };
43
+ expiresAt?: string;
44
+ }): Promise<JobRecord>;
45
+ getJob(id: string): Promise<JobRecord>;
46
+ searchJobs(query: {
47
+ capability?: string;
48
+ status?: string;
49
+ }): Promise<{
50
+ jobs: JobRecord[];
51
+ }>;
52
+ submitOffer(jobId: string, message?: string): Promise<JobRecord>;
53
+ listOffers(jobId: string): Promise<{
54
+ offers: JobOffer[];
55
+ }>;
56
+ /** Called by the job's poster to accept one offer. */
57
+ acceptOffer(jobId: string, agentId: string): Promise<JobRecord>;
58
+ /** Called by the job's poster to cancel a not-yet-completed job. */
59
+ cancelJob(jobId: string): Promise<JobRecord>;
60
+ }
package/dist/client.js ADDED
@@ -0,0 +1,133 @@
1
+ import { canonicalize } from "./crypto/canonical.js";
2
+ import { sha256Hex, sign, toBase64 } from "./crypto/keys.js";
3
+ import { buildSignableContent } from "./core/receiptContent.js";
4
+ /**
5
+ * Minimal reference client — the seed of the future `@inamprotocol/agent-sdk`
6
+ * package. Everything here is transport plumbing plus the two signature
7
+ * schemes (HTTP request signing, receipt content signing); an agent
8
+ * framework's tool-calling layer would wrap these same calls as
9
+ * `search_jobs` / `verify_agent` / `submit_work`-style tools.
10
+ */
11
+ export class InamClient {
12
+ baseUrl;
13
+ keypair;
14
+ constructor(baseUrl, keypair) {
15
+ this.baseUrl = baseUrl;
16
+ this.keypair = keypair;
17
+ }
18
+ get did() {
19
+ return this.keypair.did;
20
+ }
21
+ async request(method, path, body, opts) {
22
+ const rawBody = body !== undefined ? JSON.stringify(body) : "";
23
+ const timestamp = Date.now().toString();
24
+ const bodyHash = sha256Hex(rawBody);
25
+ const signingString = `${method.toUpperCase()}\n${path}\n${timestamp}\n${bodyHash}`;
26
+ const signature = toBase64(sign(new TextEncoder().encode(signingString), this.keypair.privateKey));
27
+ const headers = {
28
+ "content-type": "application/json",
29
+ "inam-agent": this.keypair.did,
30
+ "inam-timestamp": timestamp,
31
+ "inam-signature": signature,
32
+ };
33
+ if (opts?.idempotencyKey)
34
+ headers["idempotency-key"] = opts.idempotencyKey;
35
+ const res = await fetch(`${this.baseUrl}${path}`, {
36
+ method,
37
+ headers,
38
+ body: body !== undefined ? rawBody : undefined,
39
+ });
40
+ const json = await res.json();
41
+ if (!res.ok) {
42
+ throw new Error(`${method} ${path} -> ${res.status}: ${JSON.stringify(json)}`);
43
+ }
44
+ return json;
45
+ }
46
+ registerAgent(capabilities, metadata) {
47
+ return this.request("POST", "/v1/agents", { capabilities, metadata }, { idempotencyKey: `register:${this.keypair.did}` });
48
+ }
49
+ getAgent(id) {
50
+ return this.request("GET", `/v1/agents/${encodeURIComponent(id)}`);
51
+ }
52
+ linkIdentity(protocol, value) {
53
+ return this.request("POST", `/v1/agents/${encodeURIComponent(this.did)}/link`, { protocol, value }, {
54
+ idempotencyKey: `link:${protocol}:${value}`,
55
+ });
56
+ }
57
+ searchAgents(query) {
58
+ const params = new URLSearchParams();
59
+ if (query.capability)
60
+ params.set("capability", query.capability);
61
+ if (query.minReputation !== undefined)
62
+ params.set("min_reputation", String(query.minReputation));
63
+ if (query.supports)
64
+ params.set("supports", query.supports);
65
+ return this.request("GET", `/v1/agents/search?${params.toString()}`);
66
+ }
67
+ getReputation(id) {
68
+ return this.request("GET", `/v1/agents/${encodeURIComponent(id)}/reputation`);
69
+ }
70
+ listReceipts(agentId) {
71
+ return this.request("GET", `/v1/agents/${encodeURIComponent(agentId)}/receipts`);
72
+ }
73
+ /** Called by the worker (agent_b) once a job is complete, off-network. */
74
+ async submitWork(agentAId, input) {
75
+ // receiptId is content-addressed (hash of everything below), so the
76
+ // client computes the exact same id the server will, and signs a payload
77
+ // that already includes it — no round-trip needed before signing.
78
+ const content = buildSignableContent(agentAId, this.did, input);
79
+ const signingBytes = new TextEncoder().encode(canonicalize({ ...content, dispute: undefined }));
80
+ const signature = toBase64(sign(signingBytes, this.keypair.privateKey));
81
+ return this.request("POST", "/v1/receipts", { ...input, agentAId, signature }, { idempotencyKey: `receipt:${input.jobId}` });
82
+ }
83
+ /** Called by the requester (agent_a) to accept the worker's submitted result. */
84
+ async acceptWork(receipt) {
85
+ const content = { ...receipt, signatures: undefined, status: undefined, dispute: undefined };
86
+ const signingBytes = new TextEncoder().encode(canonicalize(content));
87
+ const signature = toBase64(sign(signingBytes, this.keypair.privateKey));
88
+ return this.request("POST", `/v1/receipts/${encodeURIComponent(receipt.receiptId)}/countersign`, { signature }, {
89
+ idempotencyKey: `countersign:${receipt.receiptId}`,
90
+ });
91
+ }
92
+ disputeReceipt(receiptId, reason) {
93
+ return this.request("POST", `/v1/receipts/${encodeURIComponent(receiptId)}/dispute`, { reason }, {
94
+ idempotencyKey: `dispute:${receiptId}`,
95
+ });
96
+ }
97
+ // ---- Jobs (SPEC.md §3) — optional pre-work discovery/offer/accept ----
98
+ postJob(input) {
99
+ return this.request("POST", "/v1/jobs", input, { idempotencyKey: `job:${input.capability}:${input.specHash}:${Date.now()}` });
100
+ }
101
+ getJob(id) {
102
+ return this.request("GET", `/v1/jobs/${encodeURIComponent(id)}`);
103
+ }
104
+ searchJobs(query) {
105
+ const params = new URLSearchParams();
106
+ if (query.capability)
107
+ params.set("capability", query.capability);
108
+ if (query.status)
109
+ params.set("status", query.status);
110
+ return this.request("GET", `/v1/jobs/search?${params.toString()}`);
111
+ }
112
+ submitOffer(jobId, message) {
113
+ return this.request("POST", `/v1/jobs/${encodeURIComponent(jobId)}/offers`, { message }, {
114
+ idempotencyKey: `offer:${jobId}:${this.did}`,
115
+ });
116
+ }
117
+ listOffers(jobId) {
118
+ return this.request("GET", `/v1/jobs/${encodeURIComponent(jobId)}/offers`);
119
+ }
120
+ /** Called by the job's poster to accept one offer. */
121
+ acceptOffer(jobId, agentId) {
122
+ return this.request("POST", `/v1/jobs/${encodeURIComponent(jobId)}/accept`, { agentId }, {
123
+ idempotencyKey: `accept:${jobId}:${agentId}`,
124
+ });
125
+ }
126
+ /** Called by the job's poster to cancel a not-yet-completed job. */
127
+ cancelJob(jobId) {
128
+ return this.request("POST", `/v1/jobs/${encodeURIComponent(jobId)}/cancel`, undefined, {
129
+ idempotencyKey: `cancel:${jobId}`,
130
+ });
131
+ }
132
+ }
133
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAgB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAA4B,MAAM,0BAA0B,CAAC;AAG1F;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IAEF;IACA;IAFnB,YACmB,OAAe,EACf,OAAgB;QADhB,YAAO,GAAP,OAAO,CAAQ;QACf,YAAO,GAAP,OAAO,CAAS;IAChC,CAAC;IAEJ,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;IAC1B,CAAC;IAEO,KAAK,CAAC,OAAO,CAAI,MAAc,EAAE,IAAY,EAAE,IAAc,EAAE,IAAkC;QACvG,MAAM,OAAO,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAA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AAK,IAAI,IAAI,CAAC,GAAG,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED,sDAAsD;IACtD,WAAW,CAAC,KAAa,EAAE,OAAe;QACxC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,EAAE;YACvF,cAAc,EAAE,UAAU,KAAK,IAAI,OAAO,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,oEAAoE;IACpE,SAAS,CAAC,KAAa;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE;YACrF,cAAc,EAAE,UAAU,KAAK,EAAE;SAClC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,41 @@
1
+ import type { SignableReceiptContent } from "../types.js";
2
+ /**
3
+ * Pure, dependency-free receipt content logic shared by both the registry
4
+ * server and any SDK/client. Deliberately has no import from
5
+ * services/storage/middleware — an SDK package must be able to depend on
6
+ * this without pulling in server-only code.
7
+ */
8
+ export interface ReceiptContentInput {
9
+ jobId: string;
10
+ task: {
11
+ capability: string;
12
+ specHash: string;
13
+ createdAt: string;
14
+ };
15
+ result: {
16
+ outputHash: string;
17
+ outputUri?: string;
18
+ completedAt: string;
19
+ };
20
+ settlement?: {
21
+ paymentRef?: string;
22
+ amount?: string;
23
+ currency?: string;
24
+ };
25
+ verification: {
26
+ method: "payer_confirmation" | "independent_validator" | "test_suite_pass";
27
+ verifier?: string;
28
+ outcome: "success" | "partial" | "failed";
29
+ };
30
+ }
31
+ /**
32
+ * Receipt IDs are content-addressed: the hash of everything except the id
33
+ * itself and the signatures/status/dispute fields that get added later. This
34
+ * lets the worker (agent_b) compute the exact id client-side, before the
35
+ * server has seen the receipt, so it can sign a payload that includes its own
36
+ * id without any round-trip — and resubmitting identical content always maps
37
+ * to the same id instead of minting a duplicate.
38
+ */
39
+ export declare function computeReceiptId(agentAId: string, agentBId: string, input: ReceiptContentInput): string;
40
+ /** The exact object shape that must be signed — callers compute this client-side before signing. */
41
+ export declare function buildSignableContent(agentAId: string, agentBId: string, input: ReceiptContentInput): SignableReceiptContent;
@@ -0,0 +1,39 @@
1
+ import { canonicalize } from "../crypto/canonical.js";
2
+ import { sha256Hex } from "../crypto/keys.js";
3
+ /**
4
+ * Receipt IDs are content-addressed: the hash of everything except the id
5
+ * itself and the signatures/status/dispute fields that get added later. This
6
+ * lets the worker (agent_b) compute the exact id client-side, before the
7
+ * server has seen the receipt, so it can sign a payload that includes its own
8
+ * id without any round-trip — and resubmitting identical content always maps
9
+ * to the same id instead of minting a duplicate.
10
+ */
11
+ export function computeReceiptId(agentAId, agentBId, input) {
12
+ const base = {
13
+ jobId: input.jobId,
14
+ agentA: { id: agentAId, role: "requester" },
15
+ agentB: { id: agentBId, role: "worker" },
16
+ task: input.task,
17
+ result: input.result,
18
+ settlement: input.settlement,
19
+ verification: input.verification,
20
+ };
21
+ return `sha256:${sha256Hex(canonicalize(base))}`;
22
+ }
23
+ /** The exact object shape that must be signed — callers compute this client-side before signing. */
24
+ export function buildSignableContent(agentAId, agentBId, input) {
25
+ const receiptId = computeReceiptId(agentAId, agentBId, input);
26
+ return {
27
+ receiptVersion: "1.0",
28
+ receiptId,
29
+ jobId: input.jobId,
30
+ agentA: { id: agentAId, role: "requester" },
31
+ agentB: { id: agentBId, role: "worker" },
32
+ task: input.task,
33
+ result: input.result,
34
+ settlement: input.settlement,
35
+ verification: input.verification,
36
+ dispute: { status: "none", windowClosesAt: "" }, // placeholder, excluded from signature scope in practice
37
+ };
38
+ }
39
+ //# sourceMappingURL=receiptContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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YAAY;QAChC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,yDAAyD;KAC3G,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Minimal canonical JSON serializer: recursively sorts object keys and emits
3
+ * whitespace-free JSON. This is a practical subset of RFC 8785 (JCS) — it does
4
+ * not handle every JCS number-formatting edge case, but it is deterministic
5
+ * for the plain string/number/boolean/array/object shapes used by Inam Protocol's own
6
+ * schemas, which is all that's required for our signer and verifier to agree.
7
+ */
8
+ export declare function canonicalize(value: unknown): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Minimal canonical JSON serializer: recursively sorts object keys and emits
3
+ * whitespace-free JSON. This is a practical subset of RFC 8785 (JCS) — it does
4
+ * not handle every JCS number-formatting edge case, but it is deterministic
5
+ * for the plain string/number/boolean/array/object shapes used by Inam Protocol's own
6
+ * schemas, which is all that's required for our signer and verifier to agree.
7
+ */
8
+ export function canonicalize(value) {
9
+ return stringify(value);
10
+ }
11
+ function stringify(value) {
12
+ if (value === null || typeof value !== "object") {
13
+ return JSON.stringify(value);
14
+ }
15
+ if (Array.isArray(value)) {
16
+ return "[" + value.map(stringify).join(",") + "]";
17
+ }
18
+ const obj = value;
19
+ const keys = Object.keys(obj).sort();
20
+ const entries = keys
21
+ .filter((k) => obj[k] !== undefined)
22
+ .map((k) => JSON.stringify(k) + ":" + stringify(obj[k]));
23
+ return "{" + entries.join(",") + "}";
24
+ }
25
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/crypto/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACpD,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SACnC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACvC,CAAC"}
@@ -0,0 +1,14 @@
1
+ export interface Keypair {
2
+ did: string;
3
+ publicKey: Uint8Array;
4
+ privateKey: Uint8Array;
5
+ }
6
+ export declare function publicKeyToDid(publicKey: Uint8Array): string;
7
+ export declare function didToPublicKey(did: string): Uint8Array;
8
+ export declare function generateKeypair(): Keypair;
9
+ export declare function keypairFromPrivateKey(privateKey: Uint8Array): Keypair;
10
+ export declare function sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
11
+ export declare function verify(signature: Uint8Array, message: Uint8Array, did: string): boolean;
12
+ export declare function sha256Hex(data: Uint8Array | string): string;
13
+ export declare function toBase64(bytes: Uint8Array): string;
14
+ export declare function fromBase64(b64: string): Uint8Array;
@@ -0,0 +1,54 @@
1
+ import * as ed25519 from "@noble/ed25519";
2
+ import { sha512 } from "@noble/hashes/sha512";
3
+ import { sha256 } from "@noble/hashes/sha256";
4
+ import bs58 from "bs58";
5
+ // @noble/ed25519 v2 needs a sha512 implementation wired in for the sync API.
6
+ ed25519.etc.sha512Sync = (...msgs) => sha512(ed25519.etc.concatBytes(...msgs));
7
+ // multicodec value for ed25519-pub (0xed) as a varint: [0xed, 0x01].
8
+ const ED25519_MULTICODEC_PREFIX = Uint8Array.from([0xed, 0x01]);
9
+ export function publicKeyToDid(publicKey) {
10
+ const prefixed = new Uint8Array(ED25519_MULTICODEC_PREFIX.length + publicKey.length);
11
+ prefixed.set(ED25519_MULTICODEC_PREFIX, 0);
12
+ prefixed.set(publicKey, ED25519_MULTICODEC_PREFIX.length);
13
+ return "did:key:z" + bs58.encode(prefixed);
14
+ }
15
+ export function didToPublicKey(did) {
16
+ if (!did.startsWith("did:key:z")) {
17
+ throw new Error(`Unsupported DID method: ${did}`);
18
+ }
19
+ const decoded = bs58.decode(did.slice("did:key:z".length));
20
+ if (decoded[0] !== 0xed || decoded[1] !== 0x01) {
21
+ throw new Error(`Unsupported key type in DID: ${did}`);
22
+ }
23
+ return decoded.slice(2);
24
+ }
25
+ export function generateKeypair() {
26
+ return keypairFromPrivateKey(ed25519.utils.randomPrivateKey());
27
+ }
28
+ export function keypairFromPrivateKey(privateKey) {
29
+ const publicKey = ed25519.getPublicKey(privateKey);
30
+ return { did: publicKeyToDid(publicKey), publicKey, privateKey };
31
+ }
32
+ export function sign(message, privateKey) {
33
+ return ed25519.sign(message, privateKey);
34
+ }
35
+ export function verify(signature, message, did) {
36
+ try {
37
+ const publicKey = didToPublicKey(did);
38
+ return ed25519.verify(signature, message, publicKey);
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
44
+ export function sha256Hex(data) {
45
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
46
+ return Buffer.from(sha256(bytes)).toString("hex");
47
+ }
48
+ export function toBase64(bytes) {
49
+ return Buffer.from(bytes).toString("base64");
50
+ }
51
+ export function fromBase64(b64) {
52
+ return new Uint8Array(Buffer.from(b64, "base64"));
53
+ }
54
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/crypto/keys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,6EAA6E;AAC7E,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,IAAkB,EAAE,EAAE,CACjD,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAE3C,qEAAqE;AACrE,MAAM,yBAAyB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAQhE,MAAM,UAAU,cAAc,CAAC,SAAqB;IAClD,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,yBAAyB,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACrF,QAAQ,CAAC,GAAG,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;IAC3C,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,OAAO,GAAG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CAAC,IAAI,CAAC;IAC/E,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAiB;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { InamClient } from "./client.js";
2
+ export { generateKeypair, keypairFromPrivateKey, publicKeyToDid, didToPublicKey, sign, verify, sha256Hex, toBase64, fromBase64, type Keypair, } from "./crypto/keys.js";
3
+ export { canonicalize } from "./crypto/canonical.js";
4
+ export { computeReceiptId, buildSignableContent, type ReceiptContentInput } from "./core/receiptContent.js";
5
+ export type { LinkedIdentities, AgentRecord, VerificationMethod, ReceiptOutcome, ReceiptStatus, DisputeStatus, ExecutionReceipt, SignableReceiptContent, ReputationComponents, ReputationResult, JobStatus, JobOffer, JobRecord, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { InamClient } from "./client.js";
2
+ export { generateKeypair, keypairFromPrivateKey, publicKeyToDid, didToPublicKey, sign, verify, sha256Hex, toBase64, fromBase64, } from "./crypto/keys.js";
3
+ export { canonicalize } from "./crypto/canonical.js";
4
+ export { computeReceiptId, buildSignableContent } from "./core/receiptContent.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,SAAS,EACT,QAAQ,EACR,UAAU,GAEX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAA4B,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Wire-format types for the INAM Protocol REST API. This is the JS/TS SDK's
3
+ * own copy — parity with `sdk-python/inamprotocol/types` and the registry
4
+ * server's `src/types.ts` — kept in sync by hand rather than shared, since
5
+ * these are plain data shapes with no logic to drift.
6
+ */
7
+ export interface LinkedIdentities {
8
+ agentpass_id?: string;
9
+ aitp_id?: string;
10
+ passport_id?: string;
11
+ a2a_endpoint?: string;
12
+ }
13
+ export interface AgentRecord {
14
+ id: string;
15
+ capabilities: string[];
16
+ metadata: Record<string, unknown>;
17
+ linked: LinkedIdentities;
18
+ stakeUsd: number;
19
+ createdAt: string;
20
+ }
21
+ export type VerificationMethod = "payer_confirmation" | "independent_validator" | "test_suite_pass";
22
+ export type ReceiptOutcome = "success" | "partial" | "failed";
23
+ export type ReceiptStatus = "draft" | "finalized" | "disputed";
24
+ export type DisputeStatus = "none" | "open" | "resolved";
25
+ export interface ExecutionReceipt {
26
+ receiptVersion: "1.0";
27
+ receiptId: string;
28
+ jobId: string;
29
+ agentA: {
30
+ id: string;
31
+ role: "requester";
32
+ };
33
+ agentB: {
34
+ id: string;
35
+ role: "worker";
36
+ };
37
+ task: {
38
+ capability: string;
39
+ specHash: string;
40
+ createdAt: string;
41
+ };
42
+ result: {
43
+ outputHash: string;
44
+ outputUri?: string;
45
+ completedAt: string;
46
+ };
47
+ settlement?: {
48
+ paymentRef?: string;
49
+ amount?: string;
50
+ currency?: string;
51
+ };
52
+ verification: {
53
+ method: VerificationMethod;
54
+ verifier?: string;
55
+ outcome: ReceiptOutcome;
56
+ };
57
+ dispute: {
58
+ status: DisputeStatus;
59
+ reason?: string;
60
+ windowClosesAt: string;
61
+ };
62
+ signatures: {
63
+ agentB?: string;
64
+ agentA?: string;
65
+ };
66
+ status: ReceiptStatus;
67
+ }
68
+ /** The subset of a receipt that gets signed — signatures can't sign themselves. */
69
+ export type SignableReceiptContent = Omit<ExecutionReceipt, "signatures" | "status" | "dispute"> & {
70
+ dispute: {
71
+ status: "none";
72
+ windowClosesAt: string;
73
+ };
74
+ };
75
+ export interface ReputationComponents {
76
+ eigenWeight: number;
77
+ verifiedReceipts: number;
78
+ rawReceipts: number;
79
+ successRate: number;
80
+ volumeUsd: number;
81
+ stakeUsd: number;
82
+ decayHalfLifeDays: number;
83
+ }
84
+ export interface ReputationResult {
85
+ trustScore: number;
86
+ components: ReputationComponents;
87
+ flags: string[];
88
+ }
89
+ export type JobStatus = "open" | "accepted" | "completed" | "cancelled";
90
+ export interface JobOffer {
91
+ agentId: string;
92
+ message?: string;
93
+ createdAt: string;
94
+ }
95
+ export interface JobRecord {
96
+ jobId: string;
97
+ postedBy: string;
98
+ capability: string;
99
+ specHash: string;
100
+ budget?: {
101
+ amount?: string;
102
+ currency?: string;
103
+ };
104
+ status: JobStatus;
105
+ offers: JobOffer[];
106
+ acceptedAgentId?: string;
107
+ receiptId?: string;
108
+ createdAt: string;
109
+ expiresAt?: string;
110
+ }
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Wire-format types for the INAM Protocol REST API. This is the JS/TS SDK's
3
+ * own copy — parity with `sdk-python/inamprotocol/types` and the registry
4
+ * server's `src/types.ts` — kept in sync by hand rather than shared, since
5
+ * these are plain data shapes with no logic to drift.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "inamprotocol",
3
+ "version": "0.1.0",
4
+ "description": "Reference TypeScript/JavaScript SDK for the INAM Protocol — agent identity, execution receipts, jobs, and reputation",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "keywords": [
22
+ "inam",
23
+ "agent",
24
+ "ai-agent",
25
+ "identity",
26
+ "reputation",
27
+ "did",
28
+ "protocol",
29
+ "execution-receipt"
30
+ ],
31
+ "homepage": "https://inamprotocol.org",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/inamprotocol/inam-protocol.git",
35
+ "directory": "sdk-js"
36
+ },
37
+ "bugs": "https://github.com/inamprotocol/inam-protocol/issues",
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.json",
40
+ "prepublishOnly": "npm run build"
41
+ },
42
+ "dependencies": {
43
+ "@noble/ed25519": "^2.1.0",
44
+ "@noble/hashes": "^1.5.0",
45
+ "bs58": "^6.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "typescript": "^5.5.4"
49
+ }
50
+ }