@newtype-ai/nit-sdk 0.2.3 → 0.3.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/README.md +35 -8
- package/dist/index.d.ts +33 -1
- package/dist/index.js +2 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -14,14 +14,19 @@ npm install @newtype-ai/nit-sdk
|
|
|
14
14
|
import { verifyAgent } from '@newtype-ai/nit-sdk';
|
|
15
15
|
|
|
16
16
|
// The agent sends you a login payload (generated by `nit sign --login your-app.com`)
|
|
17
|
-
const result = await verifyAgent(payload
|
|
17
|
+
const result = await verifyAgent(payload, {
|
|
18
|
+
policy: { max_identities_per_machine: 10, min_age_seconds: 3600 }
|
|
19
|
+
});
|
|
18
20
|
|
|
19
|
-
if (result.verified) {
|
|
21
|
+
if (result.verified && result.admitted) {
|
|
20
22
|
// result.agent_id — the agent's permanent UUID
|
|
21
23
|
// result.card — the agent's card for your domain (skills, description, etc.)
|
|
22
24
|
// result.wallet — { solana, evm } chain addresses
|
|
25
|
+
// result.identity — registration time, machine/IP identity counts, login history
|
|
23
26
|
// result.readToken — for fetching updated cards later
|
|
24
27
|
console.log(`Welcome, ${result.card?.name}`);
|
|
28
|
+
} else if (result.verified && !result.admitted) {
|
|
29
|
+
console.log('Identity verified but does not meet trust policy');
|
|
25
30
|
} else {
|
|
26
31
|
console.log(`Verification failed: ${result.error}`);
|
|
27
32
|
}
|
|
@@ -31,10 +36,10 @@ if (result.verified) {
|
|
|
31
36
|
|
|
32
37
|
1. The agent runs `nit sign --login your-app.com` to generate a signed login payload
|
|
33
38
|
2. The agent sends the payload to your app
|
|
34
|
-
3. Your app calls `verifyAgent(payload)` — this hits `api.newtype-ai.org/agent-card/verify`
|
|
35
|
-
4. You get back `{ verified
|
|
39
|
+
3. Your app calls `verifyAgent(payload, { policy })` — this hits `api.newtype-ai.org/agent-card/verify`
|
|
40
|
+
4. You get back `{ verified, admitted, agent_id, card, identity, attestation, ... }` or `{ verified: false, error }`
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
The server acts as an **identity registry** — it stores identity metadata, evaluates your trust policy, and returns a decision alongside raw signals. Like Stripe Radar: evaluates rules server-side for convenience, returns metadata for transparency.
|
|
38
43
|
|
|
39
44
|
## API
|
|
40
45
|
|
|
@@ -44,12 +49,34 @@ That's it. The server verifies the Ed25519 signature against the agent's registe
|
|
|
44
49
|
|-----------|------|-------------|
|
|
45
50
|
| `payload` | `LoginPayload` | `{ agent_id, domain, timestamp, signature }` from the agent |
|
|
46
51
|
| `options.apiUrl` | `string` | Override API URL (default: `https://api.newtype-ai.org`) |
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
| `options.policy` | `VerifyPolicy` | Trust rules the server evaluates (all optional) |
|
|
53
|
+
|
|
54
|
+
**Policy fields:**
|
|
55
|
+
|
|
56
|
+
| Field | Type | Description |
|
|
57
|
+
|-------|------|-------------|
|
|
58
|
+
| `max_identities_per_ip` | `number` | Reject if too many identities from same registration IP |
|
|
59
|
+
| `max_identities_per_machine` | `number` | Reject if too many identities from same machine |
|
|
60
|
+
| `min_age_seconds` | `number` | Reject identities younger than this (default: 5) |
|
|
61
|
+
| `max_login_rate_per_hour` | `number` | Reject if login rate is too high |
|
|
62
|
+
|
|
63
|
+
**Returns** `Promise<VerifyResult>`:
|
|
64
|
+
|
|
65
|
+
| Field | Type | Description |
|
|
66
|
+
|-------|------|-------------|
|
|
67
|
+
| `verified` | `boolean` | Ed25519 signature is valid |
|
|
68
|
+
| `admitted` | `boolean` | Identity meets your policy (`true` if no policy specified) |
|
|
69
|
+
| `agent_id` | `string` | Agent's permanent UUID |
|
|
70
|
+
| `card` | `AgentCard` | Agent's card for your domain |
|
|
71
|
+
| `branch` | `string` | Which branch the card came from (domain or `"main"`) |
|
|
72
|
+
| `wallet` | `{ solana, evm }` | Chain addresses |
|
|
73
|
+
| `readToken` | `string` | For fetching updated cards (30-day expiry) |
|
|
74
|
+
| `identity` | `IdentityMetadata` | Registration time, machine/IP counts, login history |
|
|
75
|
+
| `attestation` | `ServerAttestation` | Server's Ed25519 signature over the result |
|
|
49
76
|
|
|
50
77
|
## Full Integration Guide
|
|
51
78
|
|
|
52
|
-
See [app-integration.md](
|
|
79
|
+
See [docs/app-integration.md](docs/app-integration.md) for the complete flow, endpoint spec, code examples in multiple languages, fetching updated cards, and security notes.
|
|
53
80
|
|
|
54
81
|
## License
|
|
55
82
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ interface LoginPayload {
|
|
|
10
10
|
domain: string;
|
|
11
11
|
timestamp: number;
|
|
12
12
|
signature: string;
|
|
13
|
+
/** Agent's public key. Present in nit >= 0.6.0. */
|
|
14
|
+
public_key?: string;
|
|
13
15
|
}
|
|
14
16
|
/** A skill listed in an agent's card. */
|
|
15
17
|
interface AgentCardSkill {
|
|
@@ -43,9 +45,33 @@ interface AgentCard {
|
|
|
43
45
|
iconUrl?: string;
|
|
44
46
|
documentationUrl?: string;
|
|
45
47
|
}
|
|
48
|
+
/** Identity metadata returned by the server. */
|
|
49
|
+
interface IdentityMetadata {
|
|
50
|
+
registration_timestamp: number | null;
|
|
51
|
+
machine_identity_count: number;
|
|
52
|
+
ip_identity_count: number;
|
|
53
|
+
total_logins: number;
|
|
54
|
+
last_login_timestamp: number | null;
|
|
55
|
+
unique_domains: number;
|
|
56
|
+
}
|
|
57
|
+
/** App-defined trust policy. Server evaluates and returns admitted: true/false. */
|
|
58
|
+
interface VerifyPolicy {
|
|
59
|
+
max_identities_per_ip?: number;
|
|
60
|
+
max_identities_per_machine?: number;
|
|
61
|
+
min_age_seconds?: number;
|
|
62
|
+
max_login_rate_per_hour?: number;
|
|
63
|
+
}
|
|
64
|
+
/** Server attestation proving the server endorsed this verification. */
|
|
65
|
+
interface ServerAttestation {
|
|
66
|
+
server_signature: string;
|
|
67
|
+
server_url: string;
|
|
68
|
+
server_public_key: string;
|
|
69
|
+
}
|
|
46
70
|
/** Successful verification result. */
|
|
47
71
|
interface VerifySuccess {
|
|
48
72
|
verified: true;
|
|
73
|
+
/** Whether the identity meets the app's policy. True if no policy were specified. */
|
|
74
|
+
admitted: boolean;
|
|
49
75
|
agent_id: string;
|
|
50
76
|
domain: string;
|
|
51
77
|
card: AgentCard | null;
|
|
@@ -58,6 +84,10 @@ interface VerifySuccess {
|
|
|
58
84
|
} | null;
|
|
59
85
|
/** HMAC-signed read token for fetching the agent's domain branch card. 30-day expiry. */
|
|
60
86
|
readToken: string;
|
|
87
|
+
/** Identity metadata — registration time, login count, machine/IP grouping, etc. */
|
|
88
|
+
identity?: IdentityMetadata;
|
|
89
|
+
/** Server attestation (if server signing key is configured). */
|
|
90
|
+
attestation?: ServerAttestation;
|
|
61
91
|
}
|
|
62
92
|
/** Failed verification result. */
|
|
63
93
|
interface VerifyFailure {
|
|
@@ -68,6 +98,8 @@ type VerifyResult = VerifySuccess | VerifyFailure;
|
|
|
68
98
|
interface VerifyOptions {
|
|
69
99
|
/** Override the API base URL. Defaults to https://api.newtype-ai.org */
|
|
70
100
|
apiUrl?: string;
|
|
101
|
+
/** App-defined trust policy. Server evaluates and returns admitted: true/false. */
|
|
102
|
+
policy?: VerifyPolicy;
|
|
71
103
|
}
|
|
72
104
|
interface FetchCardOptions {
|
|
73
105
|
/** Override the base URL for agent card hosting. Defaults to https://agent-{agent_id}.newtype-ai.org */
|
|
@@ -107,4 +139,4 @@ declare function verifyAgent(payload: LoginPayload, options?: VerifyOptions): Pr
|
|
|
107
139
|
*/
|
|
108
140
|
declare function fetchAgentCard(agentId: string, domain: string, readToken: string, options?: FetchCardOptions): Promise<AgentCard | null>;
|
|
109
141
|
|
|
110
|
-
export { type AgentCard, type AgentCardSkill, type FetchCardOptions, type LoginPayload, type VerifyFailure, type VerifyOptions, type VerifyResult, type VerifySuccess, fetchAgentCard, verifyAgent };
|
|
142
|
+
export { type AgentCard, type AgentCardSkill, type FetchCardOptions, type IdentityMetadata, type LoginPayload, type ServerAttestation, type VerifyFailure, type VerifyOptions, type VerifyPolicy, type VerifyResult, type VerifySuccess, fetchAgentCard, verifyAgent };
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ async function verifyAgent(payload, options) {
|
|
|
9
9
|
agent_id: payload.agent_id,
|
|
10
10
|
domain: payload.domain,
|
|
11
11
|
timestamp: payload.timestamp,
|
|
12
|
-
signature: payload.signature
|
|
12
|
+
signature: payload.signature,
|
|
13
|
+
...options?.policy ? { policy: options.policy } : {}
|
|
13
14
|
})
|
|
14
15
|
});
|
|
15
16
|
return res.json();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newtype-ai/nit-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Verify agent identity with one function call",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
},
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
|
-
"files": [
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
20
22
|
"scripts": {
|
|
21
23
|
"build": "tsup",
|
|
22
24
|
"prepublishOnly": "npm run build"
|