atp-sdk 1.0.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/CHANGELOG.md +111 -0
- package/LICENSE +201 -0
- package/README.md +633 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +55 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client/atp.d.ts.map +1 -0
- package/dist/client/atp.js +90 -0
- package/dist/client/atp.js.map +1 -0
- package/dist/client/audit.d.ts.map +1 -0
- package/dist/client/audit.js +125 -0
- package/dist/client/audit.js.map +1 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +190 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/credentials.d.ts.map +1 -0
- package/dist/client/credentials.js +112 -0
- package/dist/client/credentials.js.map +1 -0
- package/dist/client/gateway.d.ts.map +1 -0
- package/dist/client/gateway.js +214 -0
- package/dist/client/gateway.js.map +1 -0
- package/dist/client/identity.d.ts.map +1 -0
- package/dist/client/identity.js +94 -0
- package/dist/client/identity.js.map +1 -0
- package/dist/client/permissions.d.ts.map +1 -0
- package/dist/client/permissions.js +132 -0
- package/dist/client/permissions.js.map +1 -0
- package/dist/index.cjs +89 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/simple-agent.d.ts.map +1 -0
- package/dist/simple-agent.js +261 -0
- package/dist/simple-agent.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +48 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +100 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/did.d.ts.map +1 -0
- package/dist/utils/did.js +225 -0
- package/dist/utils/did.js.map +1 -0
- package/dist/utils/jwt.d.ts.map +1 -0
- package/dist/utils/jwt.js +235 -0
- package/dist/utils/jwt.js.map +1 -0
- package/docs/README.md +362 -0
- package/docs/api/README.md +1077 -0
- package/docs/guides/authentication.md +667 -0
- package/docs/guides/best-practices.md +1004 -0
- package/docs/guides/configuration.md +588 -0
- package/docs/guides/error-handling.md +1073 -0
- package/docs/guides/troubleshooting.md +850 -0
- package/examples/01-basic-setup.js +53 -0
- package/examples/02-identity-management.js +130 -0
- package/examples/03-verifiable-credentials.js +234 -0
- package/examples/04-permissions-and-access-control.js +326 -0
- package/examples/05-audit-logging.js +310 -0
- package/examples/06-real-time-monitoring.js +302 -0
- package/examples/07-advanced-use-cases.js +584 -0
- package/examples/README.md +211 -0
- package/examples/index.js +135 -0
- package/examples/simple-3-line.ts +51 -0
- package/package.json +108 -0
package/docs/README.md
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# ATP™ SDK Documentation
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the Agent Trust Protocol™
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Quick Start](#quick-start)
|
|
8
|
+
2. [Installation](#installation)
|
|
9
|
+
3. [API Reference](./api/README.md)
|
|
10
|
+
4. [Examples](../examples/README.md)
|
|
11
|
+
5. [Configuration](./guides/configuration.md)
|
|
12
|
+
6. [Authentication](./guides/authentication.md)
|
|
13
|
+
7. [Error Handling](./guides/error-handling.md)
|
|
14
|
+
8. [Best Practices](./guides/best-practices.md)
|
|
15
|
+
9. [Troubleshooting](./guides/troubleshooting.md)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @atp/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import { ATPClient, createQuickConfig } from '@atp/sdk';
|
|
25
|
+
|
|
26
|
+
// Initialize client
|
|
27
|
+
const config = createQuickConfig('http://localhost');
|
|
28
|
+
const client = new ATPClient(config);
|
|
29
|
+
|
|
30
|
+
// Test connectivity
|
|
31
|
+
const status = await client.testConnectivity();
|
|
32
|
+
console.log('Services available:', status);
|
|
33
|
+
|
|
34
|
+
// Use individual services
|
|
35
|
+
const identity = await client.identity.resolve('did:atp:testnet:example');
|
|
36
|
+
const credentials = await client.credentials.query({ issuer: 'did:atp:testnet:issuer' });
|
|
37
|
+
|
|
38
|
+
// Cleanup when done
|
|
39
|
+
client.cleanup();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
### NPM
|
|
45
|
+
```bash
|
|
46
|
+
npm install @atp/sdk
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Yarn
|
|
50
|
+
```bash
|
|
51
|
+
yarn add @atp/sdk
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### PNPM
|
|
55
|
+
```bash
|
|
56
|
+
pnpm add @atp/sdk
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Basic Usage
|
|
60
|
+
|
|
61
|
+
### Initialize Client
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import { ATPClient, createQuickConfig } from '@atp/sdk';
|
|
65
|
+
|
|
66
|
+
// Quick configuration for local development
|
|
67
|
+
const config = createQuickConfig('http://localhost');
|
|
68
|
+
|
|
69
|
+
// Or custom configuration
|
|
70
|
+
const config = {
|
|
71
|
+
baseUrl: 'https://your-atp-instance.com',
|
|
72
|
+
timeout: 30000,
|
|
73
|
+
retries: 3,
|
|
74
|
+
auth: {
|
|
75
|
+
did: 'your-did',
|
|
76
|
+
privateKey: 'your-private-key'
|
|
77
|
+
},
|
|
78
|
+
services: {
|
|
79
|
+
identity: 'https://identity.your-domain.com',
|
|
80
|
+
credentials: 'https://credentials.your-domain.com',
|
|
81
|
+
permissions: 'https://permissions.your-domain.com',
|
|
82
|
+
audit: 'https://audit.your-domain.com',
|
|
83
|
+
gateway: 'https://gateway.your-domain.com'
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const client = new ATPClient(config);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Authentication
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// Using DID and private key
|
|
94
|
+
client.setAuthentication({
|
|
95
|
+
did: 'did:atp:testnet:your-identifier',
|
|
96
|
+
privateKey: 'your-private-key-hex'
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Using JWT token
|
|
100
|
+
client.setAuthentication({
|
|
101
|
+
token: 'your-jwt-token'
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Service Clients
|
|
106
|
+
|
|
107
|
+
The ATP SDK provides dedicated clients for each service:
|
|
108
|
+
|
|
109
|
+
- **Identity Service**: `client.identity` - DID management, trust levels, MFA
|
|
110
|
+
- **Credentials Service**: `client.credentials` - Verifiable credentials and presentations
|
|
111
|
+
- **Permissions Service**: `client.permissions` - Access control and policy management
|
|
112
|
+
- **Audit Service**: `client.audit` - Audit logging and compliance reporting
|
|
113
|
+
- **Gateway Service**: `client.gateway` - Real-time events and service coordination
|
|
114
|
+
|
|
115
|
+
## Core Concepts
|
|
116
|
+
|
|
117
|
+
### Decentralized Identifiers (DIDs)
|
|
118
|
+
|
|
119
|
+
DIDs are globally unique identifiers that enable verifiable, self-sovereign digital identity.
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
import { DIDUtils } from '@atp/sdk';
|
|
123
|
+
|
|
124
|
+
// Generate a new DID
|
|
125
|
+
const { did, document, keyPair } = await DIDUtils.generateDID({
|
|
126
|
+
network: 'testnet',
|
|
127
|
+
method: 'atp'
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Parse DID components
|
|
131
|
+
const parsed = DIDUtils.parseDID(did);
|
|
132
|
+
console.log(parsed); // { method: 'atp', network: 'testnet', identifier: '...' }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Verifiable Credentials
|
|
136
|
+
|
|
137
|
+
Cryptographically secure, privacy-respecting credentials that can be verified independently.
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
// Create credential schema
|
|
141
|
+
const schema = await client.credentials.createSchema({
|
|
142
|
+
name: 'University Degree',
|
|
143
|
+
schema: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
degree: { type: 'string' },
|
|
147
|
+
university: { type: 'string' },
|
|
148
|
+
graduationDate: { type: 'string', format: 'date' }
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Issue credential
|
|
154
|
+
const credential = await client.credentials.issue({
|
|
155
|
+
schemaId: schema.data.id,
|
|
156
|
+
holder: 'did:atp:testnet:holder',
|
|
157
|
+
claims: {
|
|
158
|
+
degree: 'Bachelor of Science',
|
|
159
|
+
university: 'ATP University',
|
|
160
|
+
graduationDate: '2024-05-15'
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Permissions and Access Control
|
|
166
|
+
|
|
167
|
+
Fine-grained access control with policy-based evaluation.
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
// Create access policy
|
|
171
|
+
const policy = await client.permissions.createPolicy({
|
|
172
|
+
name: 'Document Access Policy',
|
|
173
|
+
rules: [{
|
|
174
|
+
action: 'read',
|
|
175
|
+
resource: 'document:*',
|
|
176
|
+
effect: 'allow',
|
|
177
|
+
conditions: [{
|
|
178
|
+
attribute: 'user.department',
|
|
179
|
+
operator: 'equals',
|
|
180
|
+
value: 'engineering'
|
|
181
|
+
}]
|
|
182
|
+
}]
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Grant permission
|
|
186
|
+
const grant = await client.permissions.grant({
|
|
187
|
+
grantee: 'did:atp:testnet:user',
|
|
188
|
+
resource: 'document:quarterly-report',
|
|
189
|
+
actions: ['read'],
|
|
190
|
+
policyId: policy.data.id
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Evaluate access
|
|
194
|
+
const decision = await client.permissions.evaluate({
|
|
195
|
+
subject: 'did:atp:testnet:user',
|
|
196
|
+
action: 'read',
|
|
197
|
+
resource: 'document:quarterly-report',
|
|
198
|
+
context: { 'user.department': 'engineering' }
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Audit Logging
|
|
203
|
+
|
|
204
|
+
Immutable audit trails with blockchain anchoring for compliance.
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
// Log audit event
|
|
208
|
+
const event = await client.audit.logEvent({
|
|
209
|
+
source: 'my-application',
|
|
210
|
+
action: 'document_accessed',
|
|
211
|
+
resource: 'document:quarterly-report',
|
|
212
|
+
actor: 'did:atp:testnet:user',
|
|
213
|
+
details: {
|
|
214
|
+
ipAddress: '192.168.1.100',
|
|
215
|
+
userAgent: 'Browser/1.0'
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Query audit trail
|
|
220
|
+
const events = await client.audit.queryEvents({
|
|
221
|
+
actor: 'did:atp:testnet:user',
|
|
222
|
+
startTime: '2024-06-01T00:00:00Z',
|
|
223
|
+
endTime: '2024-06-30T23:59:59Z'
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Real-time Events
|
|
228
|
+
|
|
229
|
+
Subscribe to real-time events across the ATP network.
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
// Connect to event stream
|
|
233
|
+
await client.gateway.connectEventStream({
|
|
234
|
+
filters: {
|
|
235
|
+
eventTypes: ['identity.login', 'permission.granted'],
|
|
236
|
+
severities: ['medium', 'high', 'critical']
|
|
237
|
+
},
|
|
238
|
+
autoReconnect: true
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Handle events
|
|
242
|
+
client.gateway.on('identity.login', (event) => {
|
|
243
|
+
console.log('User logged in:', event.data.actor);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
client.gateway.on('permission.granted', (event) => {
|
|
247
|
+
console.log('Permission granted:', event.data);
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Utilities
|
|
252
|
+
|
|
253
|
+
The SDK includes utility classes for common operations:
|
|
254
|
+
|
|
255
|
+
### Cryptographic Operations
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
import { CryptoUtils } from '@atp/sdk';
|
|
259
|
+
|
|
260
|
+
// Generate key pair
|
|
261
|
+
const keyPair = await CryptoUtils.generateKeyPair();
|
|
262
|
+
|
|
263
|
+
// Sign data
|
|
264
|
+
const signature = await CryptoUtils.signData('message', privateKey);
|
|
265
|
+
|
|
266
|
+
// Verify signature
|
|
267
|
+
const isValid = await CryptoUtils.verifySignature('message', signature, publicKey);
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### JWT Operations
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
import { JWTUtils } from '@atp/sdk';
|
|
274
|
+
|
|
275
|
+
// Create DID-JWT
|
|
276
|
+
const token = await JWTUtils.createDIDJWT(
|
|
277
|
+
{ custom: 'claims' },
|
|
278
|
+
privateKey,
|
|
279
|
+
did,
|
|
280
|
+
{ expiresIn: '1h' }
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Verify JWT
|
|
284
|
+
const result = await JWTUtils.verifyDIDJWT(token, publicKey);
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Error Handling
|
|
288
|
+
|
|
289
|
+
The SDK provides structured error handling with specific error types:
|
|
290
|
+
|
|
291
|
+
```javascript
|
|
292
|
+
import {
|
|
293
|
+
ATPError,
|
|
294
|
+
ATPNetworkError,
|
|
295
|
+
ATPAuthenticationError,
|
|
296
|
+
ATPAuthorizationError,
|
|
297
|
+
ATPValidationError
|
|
298
|
+
} from '@atp/sdk';
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
await client.identity.resolve('invalid-did');
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (error instanceof ATPValidationError) {
|
|
304
|
+
console.log('Invalid DID format:', error.message);
|
|
305
|
+
} else if (error instanceof ATPNetworkError) {
|
|
306
|
+
console.log('Network issue:', error.message);
|
|
307
|
+
} else if (error instanceof ATPAuthenticationError) {
|
|
308
|
+
console.log('Authentication failed:', error.message);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## TypeScript Support
|
|
314
|
+
|
|
315
|
+
The SDK is written in TypeScript and provides comprehensive type definitions:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import { ATPClient, ATPConfig, DIDDocument, VerifiableCredential } from '@atp/sdk';
|
|
319
|
+
|
|
320
|
+
const config: ATPConfig = {
|
|
321
|
+
baseUrl: 'http://localhost',
|
|
322
|
+
auth: {
|
|
323
|
+
did: 'did:atp:testnet:example',
|
|
324
|
+
privateKey: 'hex-private-key'
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const client = new ATPClient(config);
|
|
329
|
+
|
|
330
|
+
// Types are automatically inferred
|
|
331
|
+
const credential: VerifiableCredential = await client.credentials.issue({
|
|
332
|
+
schemaId: 'schema-id',
|
|
333
|
+
holder: 'holder-did',
|
|
334
|
+
claims: { name: 'John Doe' }
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Environment Configuration
|
|
339
|
+
|
|
340
|
+
Configure the SDK using environment variables:
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
ATP_BASE_URL=https://atp.example.com
|
|
344
|
+
ATP_TIMEOUT=30000
|
|
345
|
+
ATP_RETRIES=3
|
|
346
|
+
ATP_DEBUG=true
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## Next Steps
|
|
350
|
+
|
|
351
|
+
- [API Reference](./api/README.md) - Detailed API documentation
|
|
352
|
+
- [Examples](../examples/README.md) - Comprehensive examples
|
|
353
|
+
- [Configuration Guide](./guides/configuration.md) - Advanced configuration
|
|
354
|
+
- [Best Practices](./guides/best-practices.md) - Production guidelines
|
|
355
|
+
- [Troubleshooting](./guides/troubleshooting.md) - Common issues and solutions
|
|
356
|
+
|
|
357
|
+
## Support
|
|
358
|
+
|
|
359
|
+
- 📚 Documentation: [https://docs.atp.protocol](https://docs.atp.protocol)
|
|
360
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/atp/sdk/issues)
|
|
361
|
+
- 💬 Discussions: [GitHub Discussions](https://github.com/atp/sdk/discussions)
|
|
362
|
+
- 📧 Email: support@atp.protocol
|