@gentid/sdk 1.1.0 → 1.1.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 +258 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# @gentid/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for [GentID](https://gentid.com) — cryptographic identity, permissions, and agent gateway infrastructure for AI agents.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@gentid/sdk)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @gentid/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Node.js 18 or later.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { GentIDClient } from '@gentid/sdk';
|
|
22
|
+
|
|
23
|
+
const gentid = new GentIDClient({
|
|
24
|
+
apiKey: process.env.GENTID_API_KEY!, // gid_live_...
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 1. Create an agent identity
|
|
28
|
+
const agent = await gentid.createAgent({ name: 'payments-bot', owner: 'acme-corp' });
|
|
29
|
+
// ⚠ Store agent.privateKey — it is returned only once, never again.
|
|
30
|
+
|
|
31
|
+
// 2. Sign any action
|
|
32
|
+
const { signature } = await gentid.signMessage(agent.id, 'approve-payment-$500');
|
|
33
|
+
|
|
34
|
+
// 3. Verify from anywhere — no API key needed
|
|
35
|
+
const { valid } = await gentid.verifySignature(agent.id, 'approve-payment-$500', signature);
|
|
36
|
+
|
|
37
|
+
// 4. Issue a permission token for a third party to verify
|
|
38
|
+
const { token } = await gentid.getToken(agent.id);
|
|
39
|
+
|
|
40
|
+
// 5. Any server can verify the token offline — no API key needed
|
|
41
|
+
const verified = await gentid.verifyToken(token);
|
|
42
|
+
// { valid: true, agentId, agentName, owner, permissions, ... }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Agents
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Create
|
|
51
|
+
const agent = await gentid.createAgent({ name: 'my-agent', owner: 'acme-corp' });
|
|
52
|
+
|
|
53
|
+
// Read
|
|
54
|
+
const agent = await gentid.getAgent('gentic:agent:a3f9d2c1e8b4');
|
|
55
|
+
const { agents, total } = await gentid.listAgents('acme-corp', { limit: 50, offset: 0 });
|
|
56
|
+
|
|
57
|
+
// Lifecycle
|
|
58
|
+
await gentid.suspendAgent(agent.id);
|
|
59
|
+
await gentid.reactivateAgent(agent.id);
|
|
60
|
+
await gentid.revokeAgent(agent.id); // permanent
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Signatures
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Sign a message locally, then log to GentID for audit
|
|
67
|
+
const { signature } = await gentid.signMessage(agent.id, 'approve-order-123');
|
|
68
|
+
|
|
69
|
+
// Verify — public endpoint, no API key required
|
|
70
|
+
const { valid } = await gentid.verifySignature(agent.id, 'approve-order-123', signature);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Verification
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Public lookup — no API key required
|
|
77
|
+
// Returns identity, public key, status, and trust score (0–100)
|
|
78
|
+
const identity = await gentid.lookupAgent('gentic:agent:a3f9d2c1e8b4');
|
|
79
|
+
// { id, name, status, publicKey, algorithm, owner, issuedAt, trustScore }
|
|
80
|
+
|
|
81
|
+
// Request formal verification (email | domain | manual)
|
|
82
|
+
await gentid.requestVerification(agent.id, 'domain');
|
|
83
|
+
const records = await gentid.getVerificationStatus(agent.id);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Permissions
|
|
87
|
+
|
|
88
|
+
Set what each agent is allowed to do. Permissions are free-form JSON — define any schema that fits your use case.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Set permissions for an agent
|
|
92
|
+
await gentid.setPermissions(agent.id, {
|
|
93
|
+
travel_booking: true,
|
|
94
|
+
max_transaction_usd: 1500,
|
|
95
|
+
allowed_merchants: ['delta.com', 'united.com'],
|
|
96
|
+
expires_at: '2026-12-31T00:00:00Z',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Read back
|
|
100
|
+
const { permissions } = await gentid.getPermissions(agent.id);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Permission tokens
|
|
104
|
+
|
|
105
|
+
Issue a signed JWT that encodes the agent's identity and permissions. Any third party can verify it — online or offline.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Agent side — get a short-lived signed token (1 hour TTL)
|
|
109
|
+
const { token, expiresAt } = await gentid.getToken(agent.id);
|
|
110
|
+
|
|
111
|
+
// Attach to outgoing requests
|
|
112
|
+
fetch('https://partner-site.com/api/book', {
|
|
113
|
+
headers: { 'Authorization': `GentID ${token}` },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Third-party server — verify with no API key
|
|
117
|
+
const result = await gentid.verifyToken(token);
|
|
118
|
+
// {
|
|
119
|
+
// valid: true,
|
|
120
|
+
// agentId: 'gentic:agent:...',
|
|
121
|
+
// agentName: 'payments-bot',
|
|
122
|
+
// owner: 'acme-corp',
|
|
123
|
+
// status: 'active',
|
|
124
|
+
// permissions: { travel_booking: true, max_transaction_usd: 1500 },
|
|
125
|
+
// issuedAt: '...',
|
|
126
|
+
// expiresAt: '...',
|
|
127
|
+
// }
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Approval requests
|
|
131
|
+
|
|
132
|
+
Request a human owner to approve an action in real time. The owner has 15 minutes to respond via the GentID dashboard.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const request = await gentid.requestApproval(
|
|
136
|
+
agent.id,
|
|
137
|
+
'purchase-macbook-pro',
|
|
138
|
+
{ merchant: 'apple.com', amount: 1799, currency: 'USD' },
|
|
139
|
+
);
|
|
140
|
+
// { id, status: 'pending', expiresAt, ... }
|
|
141
|
+
// Owner receives a real-time push notification and approves/rejects in the dashboard.
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Trust
|
|
145
|
+
|
|
146
|
+
Grant one agent the ability to act on behalf of another, within a scoped set of permissions.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Grant trust
|
|
150
|
+
const grant = await gentid.grantTrust(agentA.id, {
|
|
151
|
+
granteeAgentId: agentB.id,
|
|
152
|
+
scope: ['read', 'sign'],
|
|
153
|
+
expiresAt: '2026-12-31T00:00:00Z',
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// List and revoke
|
|
157
|
+
const grants = await gentid.listTrustedAgents(agentA.id);
|
|
158
|
+
await gentid.revokeTrust(agentA.id, grant.id);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Badge
|
|
162
|
+
|
|
163
|
+
Embed a verified identity badge on any page.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// No API key required
|
|
167
|
+
const badge = await gentid.getBadge(agent.id);
|
|
168
|
+
// badge.embedSnippet — paste into any HTML page
|
|
169
|
+
// badge.trustScore — 0–100 public trust score
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Agent Gateway — `@gentid/auth`
|
|
175
|
+
|
|
176
|
+
To accept GentID-authenticated agents on your server, install the companion middleware package:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npm install @gentid/auth
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Express
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { gentidAuth } from '@gentid/auth/express';
|
|
186
|
+
|
|
187
|
+
app.use('/api', gentidAuth());
|
|
188
|
+
|
|
189
|
+
app.post('/api/book', (req, res) => {
|
|
190
|
+
const { agentName, permissions } = req.agent!;
|
|
191
|
+
res.json({ ok: true, bookedBy: agentName });
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Next.js (App Router)
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
// app/api/book/route.ts
|
|
199
|
+
import { withGentidAuth } from '@gentid/auth/next';
|
|
200
|
+
|
|
201
|
+
export const POST = withGentidAuth(async (req, agent) => {
|
|
202
|
+
return Response.json({ ok: true, bookedBy: agent.agentName });
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Cloudflare Worker
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { withGentidAuth } from '@gentid/auth/cloudflare';
|
|
210
|
+
|
|
211
|
+
export default {
|
|
212
|
+
fetch: withGentidAuth(async (request, agent, env, ctx) => {
|
|
213
|
+
return Response.json({ agent: agent.agentName });
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Error handling
|
|
221
|
+
|
|
222
|
+
All methods throw `GentIDError` on non-2xx responses:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
import { GentIDClient, GentIDError } from '@gentid/sdk';
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const agent = await gentid.getAgent('gentic:agent:does-not-exist');
|
|
229
|
+
} catch (err) {
|
|
230
|
+
if (err instanceof GentIDError) {
|
|
231
|
+
console.log(err.statusCode); // 404
|
|
232
|
+
console.log(err.code); // 'AGENT_NOT_FOUND'
|
|
233
|
+
console.log(err.message); // 'Agent not found'
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Configuration
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const gentid = new GentIDClient({
|
|
244
|
+
apiKey: 'gid_live_xxxxxxxxxxxx', // required
|
|
245
|
+
baseUrl: 'https://api.gentid.com', // optional override
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
API keys are generated in the [GentID dashboard](https://gentid.com/dashboard/api-keys). Keys are prefixed with `gid_live_` for production.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Links
|
|
254
|
+
|
|
255
|
+
- [Documentation](https://gentid.com/docs)
|
|
256
|
+
- [Dashboard](https://gentid.com/dashboard)
|
|
257
|
+
- [GitHub](https://github.com/010101G/gentid-sdk)
|
|
258
|
+
- [npm — @gentid/auth](https://www.npmjs.com/package/@gentid/auth)
|
package/package.json
CHANGED