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/README.md
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
# @atp/sdk - Agent Trust Protocol SDK
|
|
2
|
+
|
|
3
|
+
> Official TypeScript SDK for Agent Trust Protocol™ - Build quantum-safe AI agents in 3 lines of code!
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/@atp%2Fsdk)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## 🚀 Quick Start (3 Lines!)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @atp/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Agent } from '@atp/sdk';
|
|
17
|
+
|
|
18
|
+
const agent = await Agent.create('MyBot'); // Line 1: Create quantum-safe agent
|
|
19
|
+
await agent.send('did:atp:other-agent', 'Hello, quantum world!'); // Line 2: Send secure message
|
|
20
|
+
console.log(`Trust: ${await agent.getTrustScore('did:atp:other')}`); // Line 3: Check trust score
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
That's it! You now have a quantum-safe AI agent with decentralized identity, secure messaging, and trust scoring.
|
|
24
|
+
|
|
25
|
+
## 🛠️ Prerequisites
|
|
26
|
+
|
|
27
|
+
Currently, ATP services need to be running locally. Hosted services coming soon!
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Clone and start ATP services
|
|
31
|
+
git clone https://github.com/bigblackcoder/agent-trust-protocol.git
|
|
32
|
+
cd agent-trust-protocol
|
|
33
|
+
./start-services.sh
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 📖 Full SDK Documentation
|
|
37
|
+
|
|
38
|
+
For advanced usage, see the complete API documentation below...
|
|
39
|
+
|
|
40
|
+
## 📖 Documentation
|
|
41
|
+
|
|
42
|
+
- **[Complete Documentation](./docs/README.md)** - Comprehensive guides and API reference
|
|
43
|
+
- **[API Reference](./docs/api/README.md)** - Detailed API documentation
|
|
44
|
+
- **[Examples](./examples/README.md)** - Practical examples and use cases
|
|
45
|
+
- **[Configuration Guide](./docs/guides/configuration.md)** - Advanced configuration options
|
|
46
|
+
- **[Authentication Guide](./docs/guides/authentication.md)** - Security and authentication patterns
|
|
47
|
+
- **[Best Practices](./docs/guides/best-practices.md)** - Production-ready guidelines
|
|
48
|
+
- **[Troubleshooting](./docs/guides/troubleshooting.md)** - Common issues and solutions
|
|
49
|
+
|
|
50
|
+
## ✨ Features
|
|
51
|
+
|
|
52
|
+
### 🔐 **Identity Management**
|
|
53
|
+
- Generate and manage Decentralized Identifiers (DIDs)
|
|
54
|
+
- Register and resolve identities on the ATP network
|
|
55
|
+
- Multi-factor authentication (TOTP, SMS, Email)
|
|
56
|
+
- Trust level management and verification
|
|
57
|
+
- Cryptographic key rotation and recovery
|
|
58
|
+
|
|
59
|
+
### 📜 **Verifiable Credentials**
|
|
60
|
+
- Create and manage credential schemas
|
|
61
|
+
- Issue tamper-proof verifiable credentials
|
|
62
|
+
- Generate and verify presentations
|
|
63
|
+
- Credential lifecycle management (suspend, revoke, reactivate)
|
|
64
|
+
- Zero-knowledge proof support
|
|
65
|
+
|
|
66
|
+
### 🛡️ **Permissions & Access Control**
|
|
67
|
+
- Policy-based access control (PBAC)
|
|
68
|
+
- Fine-grained permission management
|
|
69
|
+
- Capability token delegation
|
|
70
|
+
- Real-time access decision evaluation
|
|
71
|
+
- Comprehensive audit trails
|
|
72
|
+
|
|
73
|
+
### 📋 **Audit & Compliance**
|
|
74
|
+
- Immutable audit logging
|
|
75
|
+
- Blockchain anchoring for integrity
|
|
76
|
+
- Advanced query and search capabilities
|
|
77
|
+
- Compliance reporting and data export
|
|
78
|
+
- Real-time monitoring and alerts
|
|
79
|
+
|
|
80
|
+
### ⚡ **Real-time Features**
|
|
81
|
+
- WebSocket event streaming
|
|
82
|
+
- Live security monitoring
|
|
83
|
+
- Service health monitoring
|
|
84
|
+
- Connection management with auto-reconnection
|
|
85
|
+
- Event filtering and processing
|
|
86
|
+
|
|
87
|
+
## 🏗️ Architecture
|
|
88
|
+
|
|
89
|
+
The ATP™ SDK provides a unified interface to multiple microservices:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
┌─────────────────┐ ┌──────────────────────────────────────┐
|
|
93
|
+
│ Your App │ │ ATP™ SDK │
|
|
94
|
+
│ │ │ │
|
|
95
|
+
│ ┌───────────┐ │ │ ┌─────────────────────────────────┐ │
|
|
96
|
+
│ │ Business │ │◄──►│ │ ATPClient │ │
|
|
97
|
+
│ │ Logic │ │ │ │ │ │
|
|
98
|
+
│ └───────────┘ │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │ │
|
|
99
|
+
└─────────────────┘ │ │ │ ID │ │Creds│ │Perms│ │Audit│ │ │
|
|
100
|
+
│ │ └─────┘ └─────┘ └─────┘ └─────┘ │ │
|
|
101
|
+
│ └─────────────────────────────────┘ │
|
|
102
|
+
└──────────────────────────────────────┘
|
|
103
|
+
│
|
|
104
|
+
┌───────────────────┼───────────────────┐
|
|
105
|
+
│ │ │
|
|
106
|
+
┌───────▼────────┐ ┌────────▼────────┐ ┌───────▼────────┐
|
|
107
|
+
│ Identity Service│ │Credentials Service│ │ Audit Service │
|
|
108
|
+
│ (Port 3001) │ │ (Port 3002) │ │ (Port 3004) │
|
|
109
|
+
└─────────────────┘ └─────────────────┘ └────────────────┘
|
|
110
|
+
│ │ │
|
|
111
|
+
┌───────▼────────┐ ┌────────▼────────┐ ┌───────▼────────┐
|
|
112
|
+
│Permissions Svc │ │ Gateway Service│ │ Your Data │
|
|
113
|
+
│ (Port 3003) │ │ (Port 3000) │ │ Store │
|
|
114
|
+
└─────────────────┘ └─────────────────┘ └────────────────┘
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 🔧 Installation & Setup
|
|
118
|
+
|
|
119
|
+
### Prerequisites
|
|
120
|
+
|
|
121
|
+
- Node.js 18+ with ES modules support
|
|
122
|
+
- TypeScript 4.5+ (for TypeScript projects)
|
|
123
|
+
- Access to ATP™ services (local or hosted)
|
|
124
|
+
|
|
125
|
+
### Installation
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Using npm
|
|
129
|
+
npm install @atp/sdk
|
|
130
|
+
|
|
131
|
+
# Using yarn
|
|
132
|
+
yarn add @atp/sdk
|
|
133
|
+
|
|
134
|
+
# Using pnpm
|
|
135
|
+
pnpm add @atp/sdk
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Basic Configuration
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
import { ATPClient, createQuickConfig } from '@atp/sdk';
|
|
142
|
+
|
|
143
|
+
// Development (local services)
|
|
144
|
+
const config = createQuickConfig('http://localhost');
|
|
145
|
+
|
|
146
|
+
// Production (hosted services)
|
|
147
|
+
const config = {
|
|
148
|
+
baseUrl: 'https://api.atp.example.com',
|
|
149
|
+
timeout: 30000,
|
|
150
|
+
retries: 3,
|
|
151
|
+
auth: {
|
|
152
|
+
did: process.env.ATP_DID,
|
|
153
|
+
privateKey: process.env.ATP_PRIVATE_KEY
|
|
154
|
+
},
|
|
155
|
+
services: {
|
|
156
|
+
identity: 'https://identity.atp.example.com',
|
|
157
|
+
credentials: 'https://credentials.atp.example.com',
|
|
158
|
+
permissions: 'https://permissions.atp.example.com',
|
|
159
|
+
audit: 'https://audit.atp.example.com',
|
|
160
|
+
gateway: 'https://gateway.atp.example.com'
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const client = new ATPClient(config);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 📚 Usage Examples
|
|
168
|
+
|
|
169
|
+
### Identity Management
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
import { DIDUtils, CryptoUtils } from '@atp/sdk';
|
|
173
|
+
|
|
174
|
+
// Generate new identity
|
|
175
|
+
const { did, document, keyPair } = await DIDUtils.generateDID({
|
|
176
|
+
network: 'testnet',
|
|
177
|
+
method: 'atp'
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Authenticate client
|
|
181
|
+
client.setAuthentication({
|
|
182
|
+
did: did,
|
|
183
|
+
privateKey: keyPair.privateKey
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Register identity
|
|
187
|
+
const registration = await client.identity.register({
|
|
188
|
+
did: did,
|
|
189
|
+
document: document,
|
|
190
|
+
metadata: {
|
|
191
|
+
name: 'Alice Smith',
|
|
192
|
+
organization: 'ACME Corp'
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Set up multi-factor authentication
|
|
197
|
+
const mfaSetup = await client.identity.setupMFA({
|
|
198
|
+
method: 'totp',
|
|
199
|
+
label: 'My ATP Account'
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
console.log('MFA QR Code:', mfaSetup.data.qrCodeUrl);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Verifiable Credentials
|
|
206
|
+
|
|
207
|
+
```javascript
|
|
208
|
+
// Create credential schema
|
|
209
|
+
const schema = await client.credentials.createSchema({
|
|
210
|
+
name: 'University Degree',
|
|
211
|
+
description: 'Academic degree certificate',
|
|
212
|
+
version: '1.0.0',
|
|
213
|
+
schema: {
|
|
214
|
+
type: 'object',
|
|
215
|
+
properties: {
|
|
216
|
+
degree: { type: 'string' },
|
|
217
|
+
university: { type: 'string' },
|
|
218
|
+
graduationDate: { type: 'string', format: 'date' },
|
|
219
|
+
gpa: { type: 'number', minimum: 0, maximum: 4.0 }
|
|
220
|
+
},
|
|
221
|
+
required: ['degree', 'university', 'graduationDate']
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Issue credential
|
|
226
|
+
const credential = await client.credentials.issue({
|
|
227
|
+
schemaId: schema.data.id,
|
|
228
|
+
holder: 'did:atp:testnet:student123',
|
|
229
|
+
claims: {
|
|
230
|
+
degree: 'Bachelor of Science',
|
|
231
|
+
university: 'ATP University',
|
|
232
|
+
graduationDate: '2024-05-15',
|
|
233
|
+
gpa: 3.75
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Create presentation
|
|
238
|
+
const presentation = await client.credentials.createPresentation({
|
|
239
|
+
credentialIds: [credential.data.id],
|
|
240
|
+
audience: 'did:atp:testnet:employer456',
|
|
241
|
+
challenge: 'job-application-2024',
|
|
242
|
+
purpose: 'Employment verification'
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Verify presentation
|
|
246
|
+
const verification = await client.credentials.verifyPresentation({
|
|
247
|
+
presentationId: presentation.data.id,
|
|
248
|
+
expectedChallenge: 'job-application-2024',
|
|
249
|
+
expectedAudience: 'did:atp:testnet:employer456'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
console.log('Presentation valid:', verification.data.valid);
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Access Control
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
// Create access policy
|
|
259
|
+
const policy = await client.permissions.createPolicy({
|
|
260
|
+
name: 'Document Access Policy',
|
|
261
|
+
description: 'Controls access to sensitive documents',
|
|
262
|
+
version: '1.0.0',
|
|
263
|
+
rules: [{
|
|
264
|
+
action: 'read',
|
|
265
|
+
resource: 'document:*',
|
|
266
|
+
effect: 'allow',
|
|
267
|
+
conditions: [{
|
|
268
|
+
attribute: 'user.department',
|
|
269
|
+
operator: 'equals',
|
|
270
|
+
value: 'engineering'
|
|
271
|
+
}]
|
|
272
|
+
}]
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Grant permission
|
|
276
|
+
const grant = await client.permissions.grant({
|
|
277
|
+
grantee: 'did:atp:testnet:user123',
|
|
278
|
+
resource: 'document:quarterly-report',
|
|
279
|
+
actions: ['read'],
|
|
280
|
+
policyId: policy.data.id,
|
|
281
|
+
conditions: {
|
|
282
|
+
'user.department': 'engineering',
|
|
283
|
+
'user.clearanceLevel': 'confidential'
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Evaluate access
|
|
288
|
+
const decision = await client.permissions.evaluate({
|
|
289
|
+
subject: 'did:atp:testnet:user123',
|
|
290
|
+
action: 'read',
|
|
291
|
+
resource: 'document:quarterly-report',
|
|
292
|
+
context: {
|
|
293
|
+
'user.department': 'engineering',
|
|
294
|
+
'user.clearanceLevel': 'confidential',
|
|
295
|
+
'request.time': new Date().toISOString()
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
console.log('Access granted:', decision.data.decision === 'allow');
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Audit Logging
|
|
303
|
+
|
|
304
|
+
```javascript
|
|
305
|
+
// Log audit event
|
|
306
|
+
const auditEvent = await client.audit.logEvent({
|
|
307
|
+
source: 'document-service',
|
|
308
|
+
action: 'document_accessed',
|
|
309
|
+
resource: 'document:quarterly-report',
|
|
310
|
+
actor: 'did:atp:testnet:user123',
|
|
311
|
+
details: {
|
|
312
|
+
ipAddress: '192.168.1.100',
|
|
313
|
+
userAgent: 'Mozilla/5.0...',
|
|
314
|
+
accessMethod: 'web_interface'
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Query audit trail
|
|
319
|
+
const auditTrail = await client.audit.queryEvents({
|
|
320
|
+
resource: 'document:quarterly-report',
|
|
321
|
+
startTime: '2024-06-01T00:00:00Z',
|
|
322
|
+
endTime: '2024-06-30T23:59:59Z'
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// Generate compliance report
|
|
326
|
+
const report = await client.audit.generateComplianceReport({
|
|
327
|
+
startDate: '2024-06-01',
|
|
328
|
+
endDate: '2024-06-30',
|
|
329
|
+
reportType: 'access_control',
|
|
330
|
+
format: 'pdf'
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
console.log('Report URL:', report.data.downloadUrl);
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Real-time Monitoring
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
// Connect to event stream
|
|
340
|
+
await client.gateway.connectEventStream({
|
|
341
|
+
filters: {
|
|
342
|
+
eventTypes: ['identity.login', 'permission.granted'],
|
|
343
|
+
severities: ['medium', 'high', 'critical']
|
|
344
|
+
},
|
|
345
|
+
autoReconnect: true
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Handle events
|
|
349
|
+
client.gateway.on('identity.login', (event) => {
|
|
350
|
+
console.log('User logged in:', event.data.actor);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
client.gateway.on('permission.granted', (event) => {
|
|
354
|
+
console.log('Permission granted:', {
|
|
355
|
+
grantee: event.data.grantee,
|
|
356
|
+
resource: event.data.resource
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
client.gateway.on('error', (error) => {
|
|
361
|
+
console.error('Stream error:', error.message);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// Monitor service health
|
|
365
|
+
const health = await client.gateway.getStatus();
|
|
366
|
+
console.log('Gateway status:', health.data.status);
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## 🛠️ Development
|
|
370
|
+
|
|
371
|
+
### Environment Setup
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
# Clone the repository
|
|
375
|
+
git clone https://github.com/atp/sdk.git
|
|
376
|
+
cd sdk
|
|
377
|
+
|
|
378
|
+
# Install dependencies
|
|
379
|
+
npm install
|
|
380
|
+
|
|
381
|
+
# Run tests
|
|
382
|
+
npm test
|
|
383
|
+
|
|
384
|
+
# Build the SDK
|
|
385
|
+
npm run build
|
|
386
|
+
|
|
387
|
+
# Run examples
|
|
388
|
+
npm run examples
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Running Examples
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Run all examples
|
|
395
|
+
node examples/index.js --all
|
|
396
|
+
|
|
397
|
+
# Run specific example
|
|
398
|
+
node examples/index.js 1 # Basic setup
|
|
399
|
+
node examples/index.js 2 # Identity management
|
|
400
|
+
node examples/index.js 3 # Verifiable credentials
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### TypeScript Support
|
|
404
|
+
|
|
405
|
+
The SDK is written in TypeScript and provides comprehensive type definitions:
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { ATPClient, ATPConfig, VerifiableCredential } from '@atp/sdk';
|
|
409
|
+
|
|
410
|
+
const config: ATPConfig = {
|
|
411
|
+
baseUrl: 'http://localhost',
|
|
412
|
+
auth: {
|
|
413
|
+
did: 'did:atp:testnet:example',
|
|
414
|
+
privateKey: 'hex-private-key'
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const client = new ATPClient(config);
|
|
419
|
+
|
|
420
|
+
// Types are automatically inferred
|
|
421
|
+
const credential: VerifiableCredential = await client.credentials.issue({
|
|
422
|
+
schemaId: 'schema-id',
|
|
423
|
+
holder: 'holder-did',
|
|
424
|
+
claims: { name: 'John Doe' }
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
## 🧪 Testing
|
|
429
|
+
|
|
430
|
+
The SDK includes comprehensive tests and testing utilities:
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
# Run unit tests
|
|
434
|
+
npm run test:unit
|
|
435
|
+
|
|
436
|
+
# Run integration tests
|
|
437
|
+
npm run test:integration
|
|
438
|
+
|
|
439
|
+
# Run tests with coverage
|
|
440
|
+
npm run test:coverage
|
|
441
|
+
|
|
442
|
+
# Run specific test suite
|
|
443
|
+
npm run test -- --grep "Identity"
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### Testing Your Application
|
|
447
|
+
|
|
448
|
+
```javascript
|
|
449
|
+
import { ATPClient } from '@atp/sdk';
|
|
450
|
+
import { jest } from '@jest/globals';
|
|
451
|
+
|
|
452
|
+
// Mock the SDK for testing
|
|
453
|
+
jest.mock('@atp/sdk');
|
|
454
|
+
|
|
455
|
+
describe('My Application', () => {
|
|
456
|
+
let mockClient;
|
|
457
|
+
|
|
458
|
+
beforeEach(() => {
|
|
459
|
+
mockClient = {
|
|
460
|
+
identity: {
|
|
461
|
+
resolve: jest.fn(),
|
|
462
|
+
register: jest.fn()
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
ATPClient.mockImplementation(() => mockClient);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test('should handle identity resolution', async () => {
|
|
470
|
+
mockClient.identity.resolve.mockResolvedValue({
|
|
471
|
+
data: { did: 'did:atp:test:123', status: 'active' }
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// Test your application logic
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## 🚀 Production Deployment
|
|
480
|
+
|
|
481
|
+
### Security Checklist
|
|
482
|
+
|
|
483
|
+
- [ ] Use HTTPS/TLS for all communications
|
|
484
|
+
- [ ] Store private keys securely (HSM, KMS, etc.)
|
|
485
|
+
- [ ] Implement proper key rotation
|
|
486
|
+
- [ ] Enable audit logging
|
|
487
|
+
- [ ] Set up monitoring and alerts
|
|
488
|
+
- [ ] Configure rate limiting
|
|
489
|
+
- [ ] Use environment-specific configurations
|
|
490
|
+
- [ ] Implement circuit breakers and retries
|
|
491
|
+
- [ ] Test disaster recovery procedures
|
|
492
|
+
|
|
493
|
+
### Performance Optimization
|
|
494
|
+
|
|
495
|
+
```javascript
|
|
496
|
+
// Connection pooling
|
|
497
|
+
const config = {
|
|
498
|
+
connectionPool: {
|
|
499
|
+
maxSockets: 50,
|
|
500
|
+
maxFreeSockets: 10,
|
|
501
|
+
timeout: 60000
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// Caching
|
|
506
|
+
const cache = new LRUCache({ max: 1000, ttl: 300000 });
|
|
507
|
+
|
|
508
|
+
async function cachedResolve(did) {
|
|
509
|
+
const cached = cache.get(did);
|
|
510
|
+
if (cached) return cached;
|
|
511
|
+
|
|
512
|
+
const result = await client.identity.resolve(did);
|
|
513
|
+
cache.set(did, result);
|
|
514
|
+
return result;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Batch operations
|
|
518
|
+
const results = await Promise.allSettled(
|
|
519
|
+
dids.map(did => client.identity.resolve(did))
|
|
520
|
+
);
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
## 📊 Monitoring
|
|
524
|
+
|
|
525
|
+
### Health Checks
|
|
526
|
+
|
|
527
|
+
```javascript
|
|
528
|
+
// Implement health check endpoint
|
|
529
|
+
app.get('/health', async (req, res) => {
|
|
530
|
+
try {
|
|
531
|
+
const health = await client.testConnectivity();
|
|
532
|
+
|
|
533
|
+
res.status(health.overall ? 200 : 503).json({
|
|
534
|
+
status: health.overall ? 'healthy' : 'degraded',
|
|
535
|
+
services: health,
|
|
536
|
+
timestamp: new Date().toISOString()
|
|
537
|
+
});
|
|
538
|
+
} catch (error) {
|
|
539
|
+
res.status(503).json({
|
|
540
|
+
status: 'unhealthy',
|
|
541
|
+
error: error.message,
|
|
542
|
+
timestamp: new Date().toISOString()
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### Metrics
|
|
549
|
+
|
|
550
|
+
```javascript
|
|
551
|
+
// Collect SDK metrics
|
|
552
|
+
const metrics = {
|
|
553
|
+
operations: {
|
|
554
|
+
total: 0,
|
|
555
|
+
successful: 0,
|
|
556
|
+
failed: 0
|
|
557
|
+
},
|
|
558
|
+
performance: {
|
|
559
|
+
averageLatency: 0,
|
|
560
|
+
p95Latency: 0
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// Instrument operations
|
|
565
|
+
async function instrumentedOperation(operation) {
|
|
566
|
+
const start = Date.now();
|
|
567
|
+
metrics.operations.total++;
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
const result = await operation();
|
|
571
|
+
metrics.operations.successful++;
|
|
572
|
+
return result;
|
|
573
|
+
} catch (error) {
|
|
574
|
+
metrics.operations.failed++;
|
|
575
|
+
throw error;
|
|
576
|
+
} finally {
|
|
577
|
+
const latency = Date.now() - start;
|
|
578
|
+
updateLatencyMetrics(latency);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
## 🤝 Contributing
|
|
584
|
+
|
|
585
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
586
|
+
|
|
587
|
+
### Development Workflow
|
|
588
|
+
|
|
589
|
+
1. Fork the repository
|
|
590
|
+
2. Create a feature branch
|
|
591
|
+
3. Make your changes
|
|
592
|
+
4. Add tests for new functionality
|
|
593
|
+
5. Ensure all tests pass
|
|
594
|
+
6. Submit a pull request
|
|
595
|
+
|
|
596
|
+
### Code Standards
|
|
597
|
+
|
|
598
|
+
- Follow TypeScript best practices
|
|
599
|
+
- Maintain 100% test coverage for new code
|
|
600
|
+
- Use conventional commit messages
|
|
601
|
+
- Update documentation for API changes
|
|
602
|
+
|
|
603
|
+
## 📄 License
|
|
604
|
+
|
|
605
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
606
|
+
|
|
607
|
+
## 🆘 Support
|
|
608
|
+
|
|
609
|
+
- **Documentation**: [https://docs.atp.protocol](https://docs.atp.protocol)
|
|
610
|
+
- **GitHub Issues**: [Report bugs and request features](https://github.com/atp/sdk/issues)
|
|
611
|
+
- **Discord**: [Join our community](https://discord.gg/atp)
|
|
612
|
+
- **Email**: support@atp.protocol
|
|
613
|
+
- **Enterprise Support**: enterprise@atp.protocol
|
|
614
|
+
|
|
615
|
+
## 🔗 Related Projects
|
|
616
|
+
|
|
617
|
+
- **[ATP™ Core Services](https://github.com/atp/core)** - Core ATP protocol implementation
|
|
618
|
+
- **[ATP™ CLI](https://github.com/atp/cli)** - Command-line interface
|
|
619
|
+
- **[ATP™ Examples](https://github.com/atp/examples)** - Real-world examples and demos
|
|
620
|
+
- **[ATP™ Specification](https://github.com/atp/spec)** - Protocol specification
|
|
621
|
+
|
|
622
|
+
## 📈 Roadmap
|
|
623
|
+
|
|
624
|
+
- [ ] **v1.1.0** - WebAssembly support for browser environments
|
|
625
|
+
- [ ] **v1.2.0** - GraphQL API support
|
|
626
|
+
- [ ] **v1.3.0** - Advanced zero-knowledge proof features
|
|
627
|
+
- [ ] **v2.0.0** - ATP Protocol v2 compatibility
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
**Agent Trust Protocol™** - Building the foundation for trustworthy AI and secure digital interactions.
|
|
632
|
+
|
|
633
|
+
© 2024 ATP Foundation. All rights reserved.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest test setup for ATP™ SDK
|
|
3
|
+
*/
|
|
4
|
+
import { jest } from '@jest/globals';
|
|
5
|
+
// Mock WebSocket for Node.js environment
|
|
6
|
+
global.WebSocket = jest.fn(() => ({
|
|
7
|
+
readyState: 1,
|
|
8
|
+
send: jest.fn(),
|
|
9
|
+
close: jest.fn(),
|
|
10
|
+
on: jest.fn(),
|
|
11
|
+
addEventListener: jest.fn(),
|
|
12
|
+
removeEventListener: jest.fn()
|
|
13
|
+
}));
|
|
14
|
+
// Mock fetch for Node.js environment
|
|
15
|
+
global.fetch = jest.fn();
|
|
16
|
+
// Mock WebCrypto API for Node.js environment
|
|
17
|
+
import { webcrypto } from 'crypto';
|
|
18
|
+
global.crypto = {
|
|
19
|
+
...webcrypto,
|
|
20
|
+
getRandomValues: (buffer) => {
|
|
21
|
+
const bytes = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
22
|
+
return webcrypto.getRandomValues(bytes);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
// Mock performance API
|
|
26
|
+
global.performance = {
|
|
27
|
+
now: jest.fn(() => Date.now()),
|
|
28
|
+
mark: jest.fn(),
|
|
29
|
+
measure: jest.fn(),
|
|
30
|
+
getEntriesByName: jest.fn(() => []),
|
|
31
|
+
getEntriesByType: jest.fn(() => []),
|
|
32
|
+
clearMarks: jest.fn(),
|
|
33
|
+
clearMeasures: jest.fn()
|
|
34
|
+
};
|
|
35
|
+
// Mock AbortSignal
|
|
36
|
+
global.AbortSignal = {
|
|
37
|
+
timeout: jest.fn((delay) => {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
setTimeout(() => controller.abort(), delay);
|
|
40
|
+
return controller.signal;
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
// Reset all mocks before each test
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
jest.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
// Global test timeout
|
|
48
|
+
jest.setTimeout(30000);
|
|
49
|
+
// Add at least one test to avoid empty test suite error
|
|
50
|
+
describe('Setup', () => {
|
|
51
|
+
it('should initialize test environment', () => {
|
|
52
|
+
expect(true).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=setup.js.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