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.
Files changed (65) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/LICENSE +201 -0
  3. package/README.md +633 -0
  4. package/dist/__tests__/setup.d.ts.map +1 -0
  5. package/dist/__tests__/setup.js +55 -0
  6. package/dist/__tests__/setup.js.map +1 -0
  7. package/dist/client/atp.d.ts.map +1 -0
  8. package/dist/client/atp.js +90 -0
  9. package/dist/client/atp.js.map +1 -0
  10. package/dist/client/audit.d.ts.map +1 -0
  11. package/dist/client/audit.js +125 -0
  12. package/dist/client/audit.js.map +1 -0
  13. package/dist/client/base.d.ts.map +1 -0
  14. package/dist/client/base.js +190 -0
  15. package/dist/client/base.js.map +1 -0
  16. package/dist/client/credentials.d.ts.map +1 -0
  17. package/dist/client/credentials.js +112 -0
  18. package/dist/client/credentials.js.map +1 -0
  19. package/dist/client/gateway.d.ts.map +1 -0
  20. package/dist/client/gateway.js +214 -0
  21. package/dist/client/gateway.js.map +1 -0
  22. package/dist/client/identity.d.ts.map +1 -0
  23. package/dist/client/identity.js +94 -0
  24. package/dist/client/identity.js.map +1 -0
  25. package/dist/client/permissions.d.ts.map +1 -0
  26. package/dist/client/permissions.js +132 -0
  27. package/dist/client/permissions.js.map +1 -0
  28. package/dist/index.cjs +89 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +72 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/simple-agent.d.ts.map +1 -0
  33. package/dist/simple-agent.js +261 -0
  34. package/dist/simple-agent.js.map +1 -0
  35. package/dist/tsconfig.tsbuildinfo +1 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +48 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils/crypto.d.ts.map +1 -0
  40. package/dist/utils/crypto.js +100 -0
  41. package/dist/utils/crypto.js.map +1 -0
  42. package/dist/utils/did.d.ts.map +1 -0
  43. package/dist/utils/did.js +225 -0
  44. package/dist/utils/did.js.map +1 -0
  45. package/dist/utils/jwt.d.ts.map +1 -0
  46. package/dist/utils/jwt.js +235 -0
  47. package/dist/utils/jwt.js.map +1 -0
  48. package/docs/README.md +362 -0
  49. package/docs/api/README.md +1077 -0
  50. package/docs/guides/authentication.md +667 -0
  51. package/docs/guides/best-practices.md +1004 -0
  52. package/docs/guides/configuration.md +588 -0
  53. package/docs/guides/error-handling.md +1073 -0
  54. package/docs/guides/troubleshooting.md +850 -0
  55. package/examples/01-basic-setup.js +53 -0
  56. package/examples/02-identity-management.js +130 -0
  57. package/examples/03-verifiable-credentials.js +234 -0
  58. package/examples/04-permissions-and-access-control.js +326 -0
  59. package/examples/05-audit-logging.js +310 -0
  60. package/examples/06-real-time-monitoring.js +302 -0
  61. package/examples/07-advanced-use-cases.js +584 -0
  62. package/examples/README.md +211 -0
  63. package/examples/index.js +135 -0
  64. package/examples/simple-3-line.ts +51 -0
  65. package/package.json +108 -0
@@ -0,0 +1,1077 @@
1
+ # ATP™ SDK API Reference
2
+
3
+ Complete API reference for the Agent Trust Protocol™ SDK.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Core Classes](#core-classes)
8
+ - [ATPClient](#atpclient)
9
+ - [BaseClient](#baseclient)
10
+ 2. [Service Clients](#service-clients)
11
+ - [IdentityClient](#identityclient)
12
+ - [CredentialsClient](#credentialsclient)
13
+ - [PermissionsClient](#permissionsclient)
14
+ - [AuditClient](#auditclient)
15
+ - [GatewayClient](#gatewayclient)
16
+ 3. [Utility Classes](#utility-classes)
17
+ - [CryptoUtils](#cryptoutils)
18
+ - [DIDUtils](#didutils)
19
+ - [JWTUtils](#jwtutils)
20
+ 4. [Types and Interfaces](#types-and-interfaces)
21
+ 5. [Error Classes](#error-classes)
22
+
23
+ ## Core Classes
24
+
25
+ ### ATPClient
26
+
27
+ Main SDK client providing unified access to all ATP services.
28
+
29
+ #### Constructor
30
+
31
+ ```typescript
32
+ constructor(config: ATPConfig)
33
+ ```
34
+
35
+ Creates a new ATP client with the specified configuration.
36
+
37
+ **Parameters:**
38
+ - `config: ATPConfig` - Client configuration object
39
+
40
+ **Example:**
41
+ ```javascript
42
+ const client = new ATPClient({
43
+ baseUrl: 'http://localhost',
44
+ auth: {
45
+ did: 'did:atp:testnet:example',
46
+ privateKey: 'hex-private-key'
47
+ }
48
+ });
49
+ ```
50
+
51
+ #### Properties
52
+
53
+ - `identity: IdentityClient` - Identity service client
54
+ - `credentials: CredentialsClient` - Credentials service client
55
+ - `permissions: PermissionsClient` - Permissions service client
56
+ - `audit: AuditClient` - Audit service client
57
+ - `gateway: GatewayClient` - Gateway service client
58
+
59
+ #### Methods
60
+
61
+ ##### `setAuthentication(auth)`
62
+
63
+ Updates authentication for all service clients.
64
+
65
+ **Parameters:**
66
+ - `auth: object` - Authentication configuration
67
+ - `did?: string` - DID for authentication
68
+ - `privateKey?: string` - Private key in hex format
69
+ - `token?: string` - JWT token
70
+
71
+ **Example:**
72
+ ```javascript
73
+ client.setAuthentication({
74
+ did: 'did:atp:testnet:example',
75
+ privateKey: 'private-key-hex'
76
+ });
77
+ ```
78
+
79
+ ##### `getConfig()`
80
+
81
+ Returns the current client configuration.
82
+
83
+ **Returns:** `ATPConfig` - Current configuration
84
+
85
+ ##### `updateConfig(updates)`
86
+
87
+ Updates the client configuration.
88
+
89
+ **Parameters:**
90
+ - `updates: Partial<ATPConfig>` - Configuration updates
91
+
92
+ ##### `isAuthenticated()`
93
+
94
+ Checks if the client is properly authenticated.
95
+
96
+ **Returns:** `boolean` - True if authenticated
97
+
98
+ ##### `testConnectivity()`
99
+
100
+ Tests connectivity to all ATP services.
101
+
102
+ **Returns:** `Promise<ConnectivityStatus>` - Status of each service
103
+
104
+ **Example:**
105
+ ```javascript
106
+ const status = await client.testConnectivity();
107
+ console.log('Identity service:', status.identity ? 'Available' : 'Unavailable');
108
+ ```
109
+
110
+ ##### `cleanup()`
111
+
112
+ Cleans up resources and closes connections.
113
+
114
+ ---
115
+
116
+ ### BaseClient
117
+
118
+ Abstract base class for all service clients.
119
+
120
+ #### Methods
121
+
122
+ ##### `updateAuth(auth)`
123
+
124
+ Updates authentication configuration.
125
+
126
+ **Parameters:**
127
+ - `auth: object` - Authentication updates
128
+
129
+ ##### `isAuthenticated()`
130
+
131
+ Checks authentication status.
132
+
133
+ **Returns:** `boolean` - Authentication status
134
+
135
+ ##### `getConfig()`
136
+
137
+ Gets current configuration.
138
+
139
+ **Returns:** `Readonly<ATPConfig>` - Configuration
140
+
141
+ ---
142
+
143
+ ## Service Clients
144
+
145
+ ### IdentityClient
146
+
147
+ Manages decentralized identities, trust levels, and multi-factor authentication.
148
+
149
+ #### Methods
150
+
151
+ ##### `register(request)`
152
+
153
+ Registers a new identity with the ATP network.
154
+
155
+ **Parameters:**
156
+ - `request: IdentityRegistrationRequest`
157
+ - `did: string` - DID to register
158
+ - `document: DIDDocument` - DID document
159
+ - `metadata?: object` - Additional metadata
160
+
161
+ **Returns:** `Promise<ATPResponse<Identity>>` - Registration result
162
+
163
+ **Example:**
164
+ ```javascript
165
+ const result = await client.identity.register({
166
+ did: 'did:atp:testnet:example',
167
+ document: didDocument,
168
+ metadata: {
169
+ name: 'John Doe',
170
+ organization: 'Example Corp'
171
+ }
172
+ });
173
+ ```
174
+
175
+ ##### `resolve(did)`
176
+
177
+ Resolves a DID to its current document and metadata.
178
+
179
+ **Parameters:**
180
+ - `did: string` - DID to resolve
181
+
182
+ **Returns:** `Promise<ATPResponse<IdentityResolution>>` - Resolution result
183
+
184
+ ##### `update(did, updates)`
185
+
186
+ Updates an identity's metadata or document.
187
+
188
+ **Parameters:**
189
+ - `did: string` - DID to update
190
+ - `updates: IdentityUpdate` - Updates to apply
191
+
192
+ **Returns:** `Promise<ATPResponse<Identity>>` - Updated identity
193
+
194
+ ##### `setupMFA(request)`
195
+
196
+ Sets up multi-factor authentication for an identity.
197
+
198
+ **Parameters:**
199
+ - `request: MFASetupRequest`
200
+ - `method: 'totp' | 'sms' | 'email'` - MFA method
201
+ - `label?: string` - Label for the MFA device
202
+
203
+ **Returns:** `Promise<ATPResponse<MFASetup>>` - MFA setup result
204
+
205
+ ##### `verifyMFA(request)`
206
+
207
+ Verifies an MFA code.
208
+
209
+ **Parameters:**
210
+ - `request: MFAVerificationRequest`
211
+ - `method: string` - MFA method
212
+ - `code: string` - Verification code
213
+
214
+ **Returns:** `Promise<ATPResponse<MFAVerification>>` - Verification result
215
+
216
+ ##### `updateTrustLevel(did, update)`
217
+
218
+ Updates the trust level for an identity.
219
+
220
+ **Parameters:**
221
+ - `did: string` - Target DID
222
+ - `update: TrustLevelUpdate`
223
+ - `level: TrustLevel` - New trust level
224
+ - `evidence: string[]` - Supporting evidence
225
+ - `verifiedBy: string` - Verifier DID
226
+
227
+ **Returns:** `Promise<ATPResponse<TrustUpdate>>` - Trust update result
228
+
229
+ ##### `getTrustScore(did, params?)`
230
+
231
+ Gets the trust score for an identity.
232
+
233
+ **Parameters:**
234
+ - `did: string` - Target DID
235
+ - `params?: TrustScoreParams` - Query parameters
236
+
237
+ **Returns:** `Promise<ATPResponse<TrustScore>>` - Trust score details
238
+
239
+ ##### `search(query)`
240
+
241
+ Searches for identities based on criteria.
242
+
243
+ **Parameters:**
244
+ - `query: IdentitySearchQuery` - Search parameters
245
+
246
+ **Returns:** `Promise<ATPResponse<IdentitySearchResult>>` - Search results
247
+
248
+ ##### `getHealth()`
249
+
250
+ Gets identity service health status.
251
+
252
+ **Returns:** `Promise<ATPResponse<HealthStatus>>` - Health status
253
+
254
+ ---
255
+
256
+ ### CredentialsClient
257
+
258
+ Manages verifiable credentials, schemas, and presentations.
259
+
260
+ #### Methods
261
+
262
+ ##### `createSchema(request)`
263
+
264
+ Creates a new credential schema.
265
+
266
+ **Parameters:**
267
+ - `request: SchemaCreationRequest`
268
+ - `name: string` - Schema name
269
+ - `description?: string` - Schema description
270
+ - `version: string` - Schema version
271
+ - `schema: object` - JSON schema definition
272
+
273
+ **Returns:** `Promise<ATPResponse<CredentialSchema>>` - Created schema
274
+
275
+ ##### `getSchema(schemaId)`
276
+
277
+ Retrieves a credential schema by ID.
278
+
279
+ **Parameters:**
280
+ - `schemaId: string` - Schema identifier
281
+
282
+ **Returns:** `Promise<ATPResponse<CredentialSchema>>` - Schema details
283
+
284
+ ##### `issue(request)`
285
+
286
+ Issues a new verifiable credential.
287
+
288
+ **Parameters:**
289
+ - `request: CredentialIssuanceRequest`
290
+ - `schemaId: string` - Schema ID
291
+ - `holder: string` - Holder DID
292
+ - `claims: object` - Credential claims
293
+ - `metadata?: object` - Additional metadata
294
+
295
+ **Returns:** `Promise<ATPResponse<VerifiableCredential>>` - Issued credential
296
+
297
+ ##### `verify(request)`
298
+
299
+ Verifies a credential's authenticity and validity.
300
+
301
+ **Parameters:**
302
+ - `request: CredentialVerificationRequest`
303
+ - `credentialId: string` - Credential ID
304
+ - `checkRevocation?: boolean` - Check revocation status
305
+ - `checkExpiry?: boolean` - Check expiration
306
+
307
+ **Returns:** `Promise<ATPResponse<CredentialVerification>>` - Verification result
308
+
309
+ ##### `createPresentation(request)`
310
+
311
+ Creates a verifiable presentation.
312
+
313
+ **Parameters:**
314
+ - `request: PresentationRequest`
315
+ - `credentialIds: string[]` - Credentials to include
316
+ - `audience: string` - Intended audience
317
+ - `challenge?: string` - Cryptographic challenge
318
+ - `purpose?: string` - Presentation purpose
319
+
320
+ **Returns:** `Promise<ATPResponse<VerifiablePresentation>>` - Created presentation
321
+
322
+ ##### `verifyPresentation(request)`
323
+
324
+ Verifies a verifiable presentation.
325
+
326
+ **Parameters:**
327
+ - `request: PresentationVerificationRequest`
328
+ - `presentationId: string` - Presentation ID
329
+ - `expectedChallenge?: string` - Expected challenge
330
+ - `expectedAudience?: string` - Expected audience
331
+
332
+ **Returns:** `Promise<ATPResponse<PresentationVerification>>` - Verification result
333
+
334
+ ##### `revoke(request)`
335
+
336
+ Revokes a verifiable credential.
337
+
338
+ **Parameters:**
339
+ - `request: RevocationRequest`
340
+ - `credentialId: string` - Credential to revoke
341
+ - `reason: string` - Revocation reason
342
+
343
+ **Returns:** `Promise<ATPResponse<RevocationResult>>` - Revocation result
344
+
345
+ ##### `getStatus(credentialId)`
346
+
347
+ Gets the current status of a credential.
348
+
349
+ **Parameters:**
350
+ - `credentialId: string` - Credential ID
351
+
352
+ **Returns:** `Promise<ATPResponse<CredentialStatus>>` - Current status
353
+
354
+ ##### `query(params)`
355
+
356
+ Queries credentials based on criteria.
357
+
358
+ **Parameters:**
359
+ - `params: CredentialQuery` - Query parameters
360
+
361
+ **Returns:** `Promise<ATPResponse<CredentialQueryResult>>` - Query results
362
+
363
+ ##### `getAnalytics(params)`
364
+
365
+ Gets credential issuance and verification analytics.
366
+
367
+ **Parameters:**
368
+ - `params: AnalyticsQuery` - Analytics parameters
369
+
370
+ **Returns:** `Promise<ATPResponse<CredentialAnalytics>>` - Analytics data
371
+
372
+ ---
373
+
374
+ ### PermissionsClient
375
+
376
+ Manages access control policies, permissions, and capability tokens.
377
+
378
+ #### Methods
379
+
380
+ ##### `createPolicy(request)`
381
+
382
+ Creates a new access control policy.
383
+
384
+ **Parameters:**
385
+ - `request: PolicyCreationRequest`
386
+ - `name: string` - Policy name
387
+ - `description?: string` - Policy description
388
+ - `version: string` - Policy version
389
+ - `rules: PolicyRule[]` - Policy rules
390
+
391
+ **Returns:** `Promise<ATPResponse<PermissionPolicy>>` - Created policy
392
+
393
+ ##### `grant(request)`
394
+
395
+ Grants permissions to a subject.
396
+
397
+ **Parameters:**
398
+ - `request: PermissionGrantRequest`
399
+ - `grantee: string` - Subject DID
400
+ - `resource: string` - Resource identifier
401
+ - `actions: string[]` - Allowed actions
402
+ - `policyId?: string` - Associated policy ID
403
+ - `conditions?: object` - Grant conditions
404
+
405
+ **Returns:** `Promise<ATPResponse<PermissionGrant>>` - Grant result
406
+
407
+ ##### `revoke(request)`
408
+
409
+ Revokes a permission grant.
410
+
411
+ **Parameters:**
412
+ - `request: RevocationRequest`
413
+ - `grantId: string` - Grant to revoke
414
+ - `reason: string` - Revocation reason
415
+
416
+ **Returns:** `Promise<ATPResponse<RevocationResult>>` - Revocation result
417
+
418
+ ##### `evaluate(request)`
419
+
420
+ Evaluates an access control decision.
421
+
422
+ **Parameters:**
423
+ - `request: AccessControlRequest`
424
+ - `subject: string` - Subject DID
425
+ - `action: string` - Requested action
426
+ - `resource: string` - Target resource
427
+ - `context?: object` - Request context
428
+
429
+ **Returns:** `Promise<ATPResponse<AccessDecision>>` - Access decision
430
+
431
+ ##### `createCapabilityToken(request)`
432
+
433
+ Creates a capability token for delegation.
434
+
435
+ **Parameters:**
436
+ - `request: CapabilityTokenRequest`
437
+ - `grantee: string` - Token recipient
438
+ - `capabilities: string[]` - Granted capabilities
439
+ - `resource: string` - Target resource
440
+ - `restrictions?: object` - Token restrictions
441
+
442
+ **Returns:** `Promise<ATPResponse<CapabilityToken>>` - Created token
443
+
444
+ ##### `verifyCapabilityToken(request)`
445
+
446
+ Verifies a capability token.
447
+
448
+ **Parameters:**
449
+ - `request: TokenVerificationRequest`
450
+ - `token: string` - Token to verify
451
+ - `requiredCapability?: string` - Required capability
452
+ - `resource?: string` - Target resource
453
+
454
+ **Returns:** `Promise<ATPResponse<TokenVerification>>` - Verification result
455
+
456
+ ##### `listGrants(params)`
457
+
458
+ Lists permission grants.
459
+
460
+ **Parameters:**
461
+ - `params: GrantQuery` - Query parameters
462
+
463
+ **Returns:** `Promise<ATPResponse<GrantQueryResult>>` - Grant list
464
+
465
+ ##### `getAnalytics(params)`
466
+
467
+ Gets permission analytics.
468
+
469
+ **Parameters:**
470
+ - `params: AnalyticsQuery` - Analytics parameters
471
+
472
+ **Returns:** `Promise<ATPResponse<PermissionAnalytics>>` - Analytics data
473
+
474
+ ---
475
+
476
+ ### AuditClient
477
+
478
+ Manages audit logging, compliance reporting, and integrity verification.
479
+
480
+ #### Methods
481
+
482
+ ##### `logEvent(request)`
483
+
484
+ Logs an audit event.
485
+
486
+ **Parameters:**
487
+ - `request: AuditLogRequest`
488
+ - `source: string` - Event source
489
+ - `action: string` - Action performed
490
+ - `resource: string` - Target resource
491
+ - `actor?: string` - Actor DID
492
+ - `details?: object` - Event details
493
+
494
+ **Returns:** `Promise<ATPResponse<AuditEvent>>` - Logged event
495
+
496
+ ##### `getEvent(eventId)`
497
+
498
+ Retrieves an audit event by ID.
499
+
500
+ **Parameters:**
501
+ - `eventId: string` - Event identifier
502
+
503
+ **Returns:** `Promise<ATPResponse<AuditEvent>>` - Event details
504
+
505
+ ##### `queryEvents(query)`
506
+
507
+ Queries audit events with filters.
508
+
509
+ **Parameters:**
510
+ - `query: AuditQuery` - Query parameters
511
+
512
+ **Returns:** `Promise<ATPResponse<AuditQueryResult>>` - Query results
513
+
514
+ ##### `verifyIntegrity()`
515
+
516
+ Verifies audit chain integrity.
517
+
518
+ **Returns:** `Promise<ATPResponse<IntegrityVerification>>` - Integrity status
519
+
520
+ ##### `getStats(params?)`
521
+
522
+ Gets audit statistics.
523
+
524
+ **Parameters:**
525
+ - `params?: StatsQuery` - Statistics parameters
526
+
527
+ **Returns:** `Promise<ATPResponse<AuditStats>>` - Statistics data
528
+
529
+ ##### `generateComplianceReport(params)`
530
+
531
+ Generates a compliance report.
532
+
533
+ **Parameters:**
534
+ - `params: ComplianceReportRequest`
535
+ - `startDate: string` - Report start date
536
+ - `endDate: string` - Report end date
537
+ - `reportType: string` - Type of report
538
+ - `format?: string` - Output format
539
+
540
+ **Returns:** `Promise<ATPResponse<ComplianceReport>>` - Generated report
541
+
542
+ ##### `exportAuditData(params)`
543
+
544
+ Exports audit data.
545
+
546
+ **Parameters:**
547
+ - `params: ExportRequest`
548
+ - `startDate: string` - Export start date
549
+ - `endDate: string` - Export end date
550
+ - `format: string` - Export format
551
+
552
+ **Returns:** `Promise<ATPResponse<ExportResult>>` - Export details
553
+
554
+ ##### `getBlockchainAnchor(eventId)`
555
+
556
+ Gets blockchain anchor for an event.
557
+
558
+ **Parameters:**
559
+ - `eventId: string` - Event ID
560
+
561
+ **Returns:** `Promise<ATPResponse<BlockchainAnchor>>` - Anchor details
562
+
563
+ ---
564
+
565
+ ### GatewayClient
566
+
567
+ Manages API gateway, real-time events, and service coordination.
568
+
569
+ #### Methods
570
+
571
+ ##### `getStatus()`
572
+
573
+ Gets gateway status and health.
574
+
575
+ **Returns:** `Promise<ATPResponse<GatewayStatus>>` - Gateway status
576
+
577
+ ##### `getHealth()`
578
+
579
+ Gets detailed health check.
580
+
581
+ **Returns:** `Promise<ATPResponse<HealthCheck>>` - Health details
582
+
583
+ ##### `connectEventStream(options?)`
584
+
585
+ Connects to real-time event stream.
586
+
587
+ **Parameters:**
588
+ - `options?: EventStreamOptions`
589
+ - `filters?: object` - Event filters
590
+ - `autoReconnect?: boolean` - Auto-reconnection
591
+
592
+ **Returns:** `Promise<void>` - Connection promise
593
+
594
+ ##### `disconnectEventStream()`
595
+
596
+ Disconnects from event stream.
597
+
598
+ ##### `on(event, handler)`
599
+
600
+ Subscribes to events.
601
+
602
+ **Parameters:**
603
+ - `event: string` - Event name
604
+ - `handler: Function` - Event handler
605
+
606
+ ##### `off(event, handler?)`
607
+
608
+ Unsubscribes from events.
609
+
610
+ **Parameters:**
611
+ - `event: string` - Event name
612
+ - `handler?: Function` - Specific handler (optional)
613
+
614
+ ##### `sendCommand(command)`
615
+
616
+ Sends command through WebSocket.
617
+
618
+ **Parameters:**
619
+ - `command: object` - Command to send
620
+
621
+ **Returns:** `Promise<void>` - Send promise
622
+
623
+ ##### `getSecurityEvents(params?)`
624
+
625
+ Gets security events.
626
+
627
+ **Parameters:**
628
+ - `params?: SecurityEventQuery` - Query parameters
629
+
630
+ **Returns:** `Promise<ATPResponse<SecurityEventResult>>` - Security events
631
+
632
+ ##### `getConnectionStats()`
633
+
634
+ Gets connection statistics.
635
+
636
+ **Returns:** `Promise<ATPResponse<ConnectionStats>>` - Connection stats
637
+
638
+ ---
639
+
640
+ ## Utility Classes
641
+
642
+ ### CryptoUtils
643
+
644
+ Cryptographic utilities for Ed25519 operations.
645
+
646
+ #### Static Methods
647
+
648
+ ##### `generateKeyPair()`
649
+
650
+ Generates a new Ed25519 key pair.
651
+
652
+ **Returns:** `Promise<KeyPair>` - Generated key pair
653
+
654
+ ##### `signData(data, privateKey)`
655
+
656
+ Signs data with a private key.
657
+
658
+ **Parameters:**
659
+ - `data: string | Buffer` - Data to sign
660
+ - `privateKey: string` - Private key in hex
661
+
662
+ **Returns:** `Promise<string>` - Signature in hex
663
+
664
+ ##### `verifySignature(data, signature, publicKey)`
665
+
666
+ Verifies a signature.
667
+
668
+ **Parameters:**
669
+ - `data: string | Buffer` - Original data
670
+ - `signature: string` - Signature in hex
671
+ - `publicKey: string` - Public key in hex
672
+
673
+ **Returns:** `Promise<boolean>` - Verification result
674
+
675
+ ##### `hash(data)`
676
+
677
+ Hashes data using SHA-256.
678
+
679
+ **Parameters:**
680
+ - `data: string | Buffer` - Data to hash
681
+
682
+ **Returns:** `string` - Hash in hex
683
+
684
+ ##### `randomBytes(length)`
685
+
686
+ Generates cryptographically secure random bytes.
687
+
688
+ **Parameters:**
689
+ - `length: number` - Number of bytes
690
+
691
+ **Returns:** `Buffer` - Random bytes
692
+
693
+ ##### `randomString(length?)`
694
+
695
+ Generates a random hex string.
696
+
697
+ **Parameters:**
698
+ - `length?: number` - String length (default: 32)
699
+
700
+ **Returns:** `string` - Random hex string
701
+
702
+ ---
703
+
704
+ ### DIDUtils
705
+
706
+ Utilities for DID generation, parsing, and manipulation.
707
+
708
+ #### Static Methods
709
+
710
+ ##### `generateDID(options?)`
711
+
712
+ Generates a new DID with document and key pair.
713
+
714
+ **Parameters:**
715
+ - `options?: object`
716
+ - `network?: string` - Network identifier
717
+ - `method?: string` - DID method
718
+
719
+ **Returns:** `Promise<DIDGeneration>` - Generated DID data
720
+
721
+ ##### `parseDID(did)`
722
+
723
+ Parses a DID string into components.
724
+
725
+ **Parameters:**
726
+ - `did: string` - DID to parse
727
+
728
+ **Returns:** `DIDComponents | null` - Parsed components
729
+
730
+ ##### `isValidDID(did)`
731
+
732
+ Validates DID format.
733
+
734
+ **Parameters:**
735
+ - `did: string` - DID to validate
736
+
737
+ **Returns:** `boolean` - Validation result
738
+
739
+ ##### `extractPublicKey(document, keyId?)`
740
+
741
+ Extracts public key from DID document.
742
+
743
+ **Parameters:**
744
+ - `document: DIDDocument` - DID document
745
+ - `keyId?: string` - Specific key ID
746
+
747
+ **Returns:** `string | null` - Public key in hex
748
+
749
+ ##### `signDIDDocument(document, privateKey, keyId?)`
750
+
751
+ Signs a DID document.
752
+
753
+ **Parameters:**
754
+ - `document: DIDDocument` - Document to sign
755
+ - `privateKey: string` - Private key in hex
756
+ - `keyId?: string` - Key ID for signing
757
+
758
+ **Returns:** `Promise<DIDDocument>` - Signed document
759
+
760
+ ##### `verifyDIDDocument(document)`
761
+
762
+ Verifies DID document signature.
763
+
764
+ **Parameters:**
765
+ - `document: DIDDocument` - Document to verify
766
+
767
+ **Returns:** `Promise<boolean>` - Verification result
768
+
769
+ ---
770
+
771
+ ### JWTUtils
772
+
773
+ Utilities for JWT creation and verification with DID support.
774
+
775
+ #### Static Methods
776
+
777
+ ##### `createDIDJWT(payload, privateKey, did, options?)`
778
+
779
+ Creates a DID-JWT token.
780
+
781
+ **Parameters:**
782
+ - `payload: object` - JWT payload
783
+ - `privateKey: string` - Private key in hex
784
+ - `did: string` - Issuer DID
785
+ - `options?: object` - JWT options
786
+
787
+ **Returns:** `Promise<string>` - JWT token
788
+
789
+ ##### `verifyDIDJWT(token, publicKey, options?)`
790
+
791
+ Verifies a DID-JWT token.
792
+
793
+ **Parameters:**
794
+ - `token: string` - JWT to verify
795
+ - `publicKey: string` - Public key in hex
796
+ - `options?: object` - Verification options
797
+
798
+ **Returns:** `Promise<JWTVerification>` - Verification result
799
+
800
+ ##### `decodeJWT(token)`
801
+
802
+ Decodes JWT without verification.
803
+
804
+ **Parameters:**
805
+ - `token: string` - JWT to decode
806
+
807
+ **Returns:** `JWTDecoded | null` - Decoded JWT
808
+
809
+ ##### `isExpired(token)`
810
+
811
+ Checks if JWT is expired.
812
+
813
+ **Parameters:**
814
+ - `token: string` - JWT to check
815
+
816
+ **Returns:** `boolean` - Expiration status
817
+
818
+ ##### `createAuthToken(did, privateKey, options?)`
819
+
820
+ Creates authentication token for ATP services.
821
+
822
+ **Parameters:**
823
+ - `did: string` - User DID
824
+ - `privateKey: string` - Private key
825
+ - `options?: object` - Token options
826
+
827
+ **Returns:** `Promise<string>` - Auth token
828
+
829
+ ##### `createCapabilityToken(issuer, subject, capabilities, privateKey, options?)`
830
+
831
+ Creates capability token.
832
+
833
+ **Parameters:**
834
+ - `issuer: string` - Issuer DID
835
+ - `subject: string` - Subject DID
836
+ - `capabilities: string[]` - Granted capabilities
837
+ - `privateKey: string` - Private key
838
+ - `options?: object` - Token options
839
+
840
+ **Returns:** `Promise<string>` - Capability token
841
+
842
+ ---
843
+
844
+ ## Types and Interfaces
845
+
846
+ ### Core Types
847
+
848
+ #### `ATPConfig`
849
+
850
+ ```typescript
851
+ interface ATPConfig {
852
+ baseUrl: string;
853
+ services?: {
854
+ identity?: string;
855
+ credentials?: string;
856
+ permissions?: string;
857
+ audit?: string;
858
+ gateway?: string;
859
+ };
860
+ auth?: {
861
+ did?: string;
862
+ privateKey?: string;
863
+ token?: string;
864
+ };
865
+ timeout?: number;
866
+ retries?: number;
867
+ retryDelay?: number;
868
+ debug?: boolean;
869
+ headers?: Record<string, string>;
870
+ }
871
+ ```
872
+
873
+ #### `ATPResponse<T>`
874
+
875
+ ```typescript
876
+ interface ATPResponse<T> {
877
+ success: boolean;
878
+ data: T;
879
+ message?: string;
880
+ timestamp: string;
881
+ requestId: string;
882
+ }
883
+ ```
884
+
885
+ ### Identity Types
886
+
887
+ #### `DIDDocument`
888
+
889
+ ```typescript
890
+ interface DIDDocument {
891
+ id: string;
892
+ '@context': string[];
893
+ verificationMethod: VerificationMethod[];
894
+ authentication?: string[];
895
+ assertionMethod?: string[];
896
+ keyAgreement?: string[];
897
+ service?: Service[];
898
+ proof?: Proof;
899
+ }
900
+ ```
901
+
902
+ #### `VerificationMethod`
903
+
904
+ ```typescript
905
+ interface VerificationMethod {
906
+ id: string;
907
+ type: string;
908
+ controller: string;
909
+ publicKeyMultibase?: string;
910
+ publicKeyJwk?: object;
911
+ }
912
+ ```
913
+
914
+ ### Credential Types
915
+
916
+ #### `VerifiableCredential`
917
+
918
+ ```typescript
919
+ interface VerifiableCredential {
920
+ '@context': string[];
921
+ type: string[];
922
+ id: string;
923
+ issuer: string;
924
+ issuanceDate: string;
925
+ expirationDate?: string;
926
+ credentialSubject: object;
927
+ proof: Proof;
928
+ credentialStatus?: CredentialStatus;
929
+ }
930
+ ```
931
+
932
+ #### `VerifiablePresentation`
933
+
934
+ ```typescript
935
+ interface VerifiablePresentation {
936
+ '@context': string[];
937
+ type: string[];
938
+ id: string;
939
+ holder: string;
940
+ verifiableCredential: VerifiableCredential[];
941
+ proof: Proof;
942
+ }
943
+ ```
944
+
945
+ ### Permission Types
946
+
947
+ #### `PermissionPolicy`
948
+
949
+ ```typescript
950
+ interface PermissionPolicy {
951
+ id: string;
952
+ name: string;
953
+ description?: string;
954
+ version: string;
955
+ rules: PolicyRule[];
956
+ createdAt: string;
957
+ updatedAt: string;
958
+ }
959
+ ```
960
+
961
+ #### `PolicyRule`
962
+
963
+ ```typescript
964
+ interface PolicyRule {
965
+ action: string;
966
+ resource: string;
967
+ effect: 'allow' | 'deny';
968
+ conditions?: PolicyCondition[];
969
+ }
970
+ ```
971
+
972
+ ### Audit Types
973
+
974
+ #### `AuditEvent`
975
+
976
+ ```typescript
977
+ interface AuditEvent {
978
+ id: string;
979
+ source: string;
980
+ action: string;
981
+ resource: string;
982
+ actor?: string;
983
+ timestamp: string;
984
+ details?: object;
985
+ signature?: string;
986
+ ipfsHash?: string;
987
+ blockchainAnchor?: string;
988
+ }
989
+ ```
990
+
991
+ ---
992
+
993
+ ## Error Classes
994
+
995
+ ### `ATPError`
996
+
997
+ Base error class for all ATP SDK errors.
998
+
999
+ ```typescript
1000
+ class ATPError extends Error {
1001
+ code: string;
1002
+ details?: object;
1003
+
1004
+ constructor(message: string, code?: string, details?: object)
1005
+ }
1006
+ ```
1007
+
1008
+ ### `ATPNetworkError`
1009
+
1010
+ Network-related errors.
1011
+
1012
+ ```typescript
1013
+ class ATPNetworkError extends ATPError {
1014
+ statusCode?: number;
1015
+ response?: object;
1016
+ }
1017
+ ```
1018
+
1019
+ ### `ATPAuthenticationError`
1020
+
1021
+ Authentication failures.
1022
+
1023
+ ```typescript
1024
+ class ATPAuthenticationError extends ATPError {
1025
+ authMethod?: string;
1026
+ }
1027
+ ```
1028
+
1029
+ ### `ATPAuthorizationError`
1030
+
1031
+ Authorization failures.
1032
+
1033
+ ```typescript
1034
+ class ATPAuthorizationError extends ATPError {
1035
+ requiredPermissions?: string[];
1036
+ }
1037
+ ```
1038
+
1039
+ ### `ATPValidationError`
1040
+
1041
+ Input validation errors.
1042
+
1043
+ ```typescript
1044
+ class ATPValidationError extends ATPError {
1045
+ field?: string;
1046
+ value?: any;
1047
+ }
1048
+ ```
1049
+
1050
+ ### `ATPServiceError`
1051
+
1052
+ Service-specific errors.
1053
+
1054
+ ```typescript
1055
+ class ATPServiceError extends ATPError {
1056
+ service: string;
1057
+ operation?: string;
1058
+ }
1059
+ ```
1060
+
1061
+ ---
1062
+
1063
+ ## Helper Functions
1064
+
1065
+ ### `createQuickConfig(baseUrl, options?)`
1066
+
1067
+ Creates a quick configuration for local development.
1068
+
1069
+ **Parameters:**
1070
+ - `baseUrl: string` - Base URL for ATP services
1071
+ - `options?: object` - Additional options
1072
+
1073
+ **Returns:** `ATPConfig` - Generated configuration
1074
+
1075
+ ---
1076
+
1077
+ This API reference provides comprehensive documentation for all classes, methods, and types in the ATP™ SDK. For more detailed examples and usage patterns, see the [Examples](../examples/README.md) section.