@newtype-ai/nit-sdk 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 newtype-ai contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @newtype-ai/nit-sdk
2
+
3
+ Verify AI agent identity with one function call. No crypto, no OAuth, no secrets needed.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @newtype-ai/nit-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { verifyAgent } from '@newtype-ai/nit-sdk';
15
+
16
+ // The agent sends you a login payload (generated by `nit sign --login your-app.com`)
17
+ const result = await verifyAgent(payload);
18
+
19
+ if (result.verified) {
20
+ // result.agent_id — the agent's permanent UUID
21
+ // result.card — the agent's public profile (name, skills, etc.)
22
+ // result.solanaAddress — the agent's Solana wallet address
23
+ console.log(`Welcome, ${result.card?.name}`);
24
+ } else {
25
+ console.log(`Verification failed: ${result.error}`);
26
+ }
27
+ ```
28
+
29
+ ## How It Works
30
+
31
+ 1. The agent runs `nit sign --login your-app.com` to generate a signed login payload
32
+ 2. The agent sends the payload to your app
33
+ 3. Your app calls `verifyAgent(payload)` — this hits `api.newtype-ai.org/agent-card/verify`
34
+ 4. You get back `{ verified: true, agent_id, card }` or `{ verified: false, error }`
35
+
36
+ That's it. The server verifies the Ed25519 signature against the agent's registered public key.
37
+
38
+ ## API
39
+
40
+ ### `verifyAgent(payload, options?)`
41
+
42
+ | Parameter | Type | Description |
43
+ |-----------|------|-------------|
44
+ | `payload` | `LoginPayload` | `{ agent_id, domain, timestamp, signature }` from the agent |
45
+ | `options.apiUrl` | `string` | Override API URL (default: `https://api.newtype-ai.org`) |
46
+
47
+ Returns `Promise<VerifyResult>` — either `{ verified: true, agent_id, domain, card, solanaAddress }` or `{ verified: false, error }`.
48
+
49
+ ## Full Integration Guide
50
+
51
+ See [app-integration.md](https://github.com/newtype-ai/newtype-ai/blob/main/docs/app-integration.md) for the complete flow, endpoint spec, and examples in multiple languages.
52
+
53
+ ## License
54
+
55
+ MIT
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @newtype-ai/nit-sdk — Verify agent identity with one function call.
3
+ *
4
+ * Apps receive a login payload from an agent (via nit) and call
5
+ * verifyAgent() to confirm the agent's identity. No crypto needed.
6
+ */
7
+ /** The login payload an agent sends to your app. */
8
+ interface LoginPayload {
9
+ agent_id: string;
10
+ domain: string;
11
+ timestamp: number;
12
+ signature: string;
13
+ }
14
+ /** A skill listed in an agent's card. */
15
+ interface AgentCardSkill {
16
+ id: string;
17
+ name?: string;
18
+ description?: string;
19
+ tags?: string[];
20
+ examples?: string[];
21
+ inputModes?: string[];
22
+ outputModes?: string[];
23
+ }
24
+ /** The agent's public identity card (A2A-compliant). */
25
+ interface AgentCard {
26
+ protocolVersion: string;
27
+ name: string;
28
+ description: string;
29
+ version: string;
30
+ url: string;
31
+ defaultInputModes: string[];
32
+ defaultOutputModes: string[];
33
+ provider?: {
34
+ organization: string;
35
+ url?: string;
36
+ };
37
+ skills: AgentCardSkill[];
38
+ publicKey?: string;
39
+ iconUrl?: string;
40
+ documentationUrl?: string;
41
+ }
42
+ /** Successful verification result. */
43
+ interface VerifySuccess {
44
+ verified: true;
45
+ agent_id: string;
46
+ domain: string;
47
+ card: AgentCard | null;
48
+ /** Which branch the card came from — the domain branch if pushed, otherwise 'main'. */
49
+ branch: string;
50
+ /** Solana wallet address derived from the agent's Ed25519 public key. */
51
+ solanaAddress?: string;
52
+ /** HMAC-signed read token for fetching the agent's domain branch card. 30-day expiry. */
53
+ readToken: string;
54
+ }
55
+ /** Failed verification result. */
56
+ interface VerifyFailure {
57
+ verified: false;
58
+ error: string;
59
+ }
60
+ type VerifyResult = VerifySuccess | VerifyFailure;
61
+ interface VerifyOptions {
62
+ /** Override the API base URL. Defaults to https://api.newtype-ai.org */
63
+ apiUrl?: string;
64
+ }
65
+ interface FetchCardOptions {
66
+ /** Override the base URL for agent card hosting. Defaults to https://agent-{agent_id}.newtype-ai.org */
67
+ baseUrl?: string;
68
+ }
69
+ /**
70
+ * Verify an agent's login payload against the newtype-ai.org server.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { verifyAgent } from '@newtype-ai/nit-sdk';
75
+ *
76
+ * const result = await verifyAgent(payload);
77
+ * if (result.verified) {
78
+ * console.log(`Agent ${result.agent_id} verified`);
79
+ * console.log(`Card:`, result.card);
80
+ * }
81
+ * ```
82
+ */
83
+ declare function verifyAgent(payload: LoginPayload, options?: VerifyOptions): Promise<VerifyResult>;
84
+ /**
85
+ * Fetch an agent's domain branch card using a read token.
86
+ *
87
+ * The read token is returned by verifyAgent() on successful verification.
88
+ * It is scoped to a specific agent_id + domain and expires after 30 days.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import { verifyAgent, fetchAgentCard } from '@newtype-ai/nit-sdk';
93
+ *
94
+ * const result = await verifyAgent(payload);
95
+ * if (result.verified) {
96
+ * // Later, fetch the latest card:
97
+ * const card = await fetchAgentCard(result.agent_id, result.domain, result.readToken);
98
+ * }
99
+ * ```
100
+ */
101
+ declare function fetchAgentCard(agentId: string, domain: string, readToken: string, options?: FetchCardOptions): Promise<AgentCard | null>;
102
+
103
+ export { type AgentCard, type AgentCardSkill, type FetchCardOptions, type LoginPayload, type VerifyFailure, type VerifyOptions, type VerifyResult, type VerifySuccess, fetchAgentCard, verifyAgent };
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ // src/index.ts
2
+ var DEFAULT_API_URL = "https://api.newtype-ai.org";
3
+ async function verifyAgent(payload, options) {
4
+ const apiUrl = options?.apiUrl ?? DEFAULT_API_URL;
5
+ const res = await fetch(`${apiUrl}/agent-card/verify`, {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({
9
+ agent_id: payload.agent_id,
10
+ domain: payload.domain,
11
+ timestamp: payload.timestamp,
12
+ signature: payload.signature
13
+ })
14
+ });
15
+ return res.json();
16
+ }
17
+ async function fetchAgentCard(agentId, domain, readToken, options) {
18
+ const baseUrl = options?.baseUrl ?? `https://agent-${agentId}.newtype-ai.org`;
19
+ const url = `${baseUrl}/.well-known/agent-card.json?branch=${encodeURIComponent(domain)}`;
20
+ const res = await fetch(url, {
21
+ headers: { Authorization: `Bearer ${readToken}` }
22
+ });
23
+ if (!res.ok) return null;
24
+ return res.json();
25
+ }
26
+ export {
27
+ fetchAgentCard,
28
+ verifyAgent
29
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@newtype-ai/nit-sdk",
3
+ "version": "0.2.1",
4
+ "description": "Verify agent identity with one function call",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/newtype-ai/nit-sdk"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": ["dist"],
20
+ "scripts": {
21
+ "build": "tsup",
22
+ "prepublishOnly": "npm run build"
23
+ },
24
+ "devDependencies": {
25
+ "tsup": "^8.0.0",
26
+ "typescript": "^5.7.0"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }