@astrasyncai/verification-gateway 2.3.10 → 2.4.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.
@@ -0,0 +1,369 @@
1
+ /** Configuration for the AstraSync SDK client. */
2
+ interface AstraSyncConfig {
3
+ /** API key (kya_ prefixed). Used as Bearer token. */
4
+ apiKey?: string;
5
+ /** Email for email+password authentication. */
6
+ email?: string;
7
+ /** Password for email+password authentication. */
8
+ password?: string;
9
+ /** secp256k1 private key for crypto signing. Used WITH apiKey or email+password. */
10
+ privateKey?: string;
11
+ /**
12
+ * Base URL for the AstraSync API.
13
+ * Defaults to ASTRASYNC_API_URL env or `https://astrasync.ai` (production).
14
+ * For staging, pass `https://staging.astrasync.ai`.
15
+ */
16
+ baseUrl?: string;
17
+ }
18
+ /**
19
+ * Multi-protocol declarations the agent participates in.
20
+ * Promoted from `metadata.protocols[]` to a first-class field in agent-registration v1.0.0.
21
+ */
22
+ type AgentProtocol = 'a2a' | 'acp' | 'ap2' | 'ucp' | 'mpp' | 'x402' | 'erc8004' | 'vi' | 'agentpay' | 'tap' | 'other';
23
+ /** PDLSS purpose configuration. */
24
+ interface PDLSSPurpose {
25
+ categories: string[];
26
+ allowedActions?: string[];
27
+ deniedActions?: string[];
28
+ }
29
+ /** PDLSS duration configuration. */
30
+ interface PDLSSDuration {
31
+ startTime?: string | null;
32
+ endTime?: string | null;
33
+ timezone?: string | null;
34
+ maxSessionDuration?: number | null;
35
+ ttl?: number | null;
36
+ allowedDays?: number[] | null;
37
+ allowedHours?: {
38
+ start: number;
39
+ end: number;
40
+ } | null;
41
+ }
42
+ /** PDLSS limits configuration. */
43
+ interface PDLSSLimits {
44
+ autonomousThreshold?: number | null;
45
+ stepUpThreshold?: number | null;
46
+ approvalThreshold?: number | null;
47
+ maxTransactionsPerDay?: number | null;
48
+ maxTransactionsPerHour?: number | null;
49
+ maxTotalValue?: number | null;
50
+ currency?: string;
51
+ }
52
+ /** PDLSS scope configuration. */
53
+ interface PDLSSScope {
54
+ resources?: string[];
55
+ resourceTypes?: string[];
56
+ jurisdictions?: string[];
57
+ excludedResources?: string[];
58
+ counterparties?: string[];
59
+ excludedCounterparties?: string[];
60
+ }
61
+ /** PDLSS self-instantiation configuration. */
62
+ interface PDLSSSelfInstantiation {
63
+ allowed: boolean;
64
+ maxSubAgents?: number | null;
65
+ inheritPermissions?: boolean | null;
66
+ allowedPurposes?: string[] | null;
67
+ requireApproval?: boolean | null;
68
+ maxDepth?: number | null;
69
+ }
70
+ /** Full PDLSS configuration. */
71
+ interface PDLSSConfig {
72
+ purpose: PDLSSPurpose;
73
+ duration?: PDLSSDuration;
74
+ limits?: PDLSSLimits;
75
+ scope?: PDLSSScope;
76
+ selfInstantiation?: PDLSSSelfInstantiation;
77
+ }
78
+ /** Model metadata for registration. */
79
+ interface ModelConfig {
80
+ modelName: string;
81
+ modelProvider: string;
82
+ modelType?: 'llm' | 'embedding' | 'image' | 'audio' | 'multimodal' | 'code' | 'other';
83
+ contextWindow?: number;
84
+ maxTokens?: number;
85
+ }
86
+ /** Framework metadata for registration. */
87
+ interface FrameworkConfig {
88
+ frameworkName: string;
89
+ frameworkVersion: string;
90
+ }
91
+ /** Options for agent registration. */
92
+ interface RegisterOptions {
93
+ name: string;
94
+ description?: string;
95
+ agentType?: string;
96
+ /**
97
+ * URL where your agent's verification-gateway SDK is mounted for runtime
98
+ * challenges. Optional — if omitted, your agent declares no runtime-challenge
99
+ * support and some counterparties may decline access requests. Mirrors the
100
+ * webUI "API endpoint" field.
101
+ */
102
+ apiEndpoint?: string;
103
+ model?: ModelConfig;
104
+ framework?: FrameworkConfig;
105
+ /** Multi-protocol declarations (e.g. ['acp', 'ap2', 'a2a']). First-class as of v1.0.0. */
106
+ protocols?: AgentProtocol[];
107
+ metadata?: Record<string, unknown>;
108
+ pdlss?: PDLSSConfig;
109
+ }
110
+ /**
111
+ * Optional blocking-mode flags for `register()`. When `waitForApproval` is
112
+ * true and the backend returns 202 pending, the SDK polls until the request
113
+ * resolves (approved → returns Agent; denied/expired → throws; timeout →
114
+ * throws). The default is non-blocking: the SDK returns the pending result
115
+ * immediately and the caller handles polling itself.
116
+ */
117
+ interface WaitForApprovalOptions {
118
+ /** Block until the request resolves. Default: false. */
119
+ waitForApproval?: boolean;
120
+ /** How long to wait in blocking mode. Default: 600_000ms (10 min). */
121
+ timeoutMs?: number;
122
+ /** Poll cadence in blocking mode. Default: 5000ms. */
123
+ pollIntervalMs?: number;
124
+ /** Called once per poll while still pending; useful for progress UX. */
125
+ onPending?: (event: {
126
+ requestId: string;
127
+ ageMs: number;
128
+ }) => void;
129
+ }
130
+ /**
131
+ * Discriminated registration result.
132
+ *
133
+ * - `active`: synchronous path (crypto-keypair signature verified, or
134
+ * email+password auth). `agent` is the live record.
135
+ * - `pending_approval`: API-key auth path. The owner has been notified by
136
+ * email and a dashboard alert. Poll `pollUrl` or call
137
+ * `sdk.pollRegistration(requestId)` to track progress, or re-call
138
+ * `register` with `waitForApproval: true` to block.
139
+ */
140
+ type RegisterResult = {
141
+ status: 'active';
142
+ agent: AgentRecord;
143
+ } | {
144
+ status: 'pending_approval';
145
+ requestId: string;
146
+ expiresAt: string;
147
+ pollUrl: string;
148
+ message?: string;
149
+ };
150
+ /**
151
+ * Response shape from `pollRegistration(requestId)` and the internal poll
152
+ * loop. State `pending` means still awaiting owner; the others are terminal.
153
+ */
154
+ interface PollRegistrationResult {
155
+ state: 'pending' | 'approved' | 'denied' | 'expired';
156
+ agent?: AgentRecord;
157
+ reason?: string;
158
+ }
159
+ /**
160
+ * Response from agent registration (raw 201 body). Use {@link RegisterResult}
161
+ * for the consumer-facing shape returned from `sdk.register()`.
162
+ */
163
+ interface RegistrationResponse {
164
+ success: boolean;
165
+ message: string;
166
+ data: {
167
+ agent: AgentRecord;
168
+ };
169
+ }
170
+ /** Raw 202 body — internal type, exposed via {@link RegisterResult}. */
171
+ interface PendingRegistrationResponse {
172
+ success: true;
173
+ status: 'pending_approval';
174
+ requestId: string;
175
+ expiresAt: string;
176
+ pollUrl: string;
177
+ message?: string;
178
+ }
179
+ /** Agent record from the API. */
180
+ interface AgentRecord {
181
+ kyaAgentId: string;
182
+ name: string;
183
+ description?: string;
184
+ agentType: string;
185
+ agentStatus: string;
186
+ trustScore: number;
187
+ astrasyncIdLevel1?: string | null;
188
+ tempId?: string | null;
189
+ metadata?: Record<string, unknown>;
190
+ createdAt: string;
191
+ updatedAt: string;
192
+ }
193
+ /** Public agent verification response. */
194
+ interface VerifyResponse {
195
+ success: boolean;
196
+ data: {
197
+ agentUuid: string;
198
+ agentName: string;
199
+ agentDescription: string;
200
+ agentTrustScore: number;
201
+ agentStatus: string;
202
+ ownerName?: string;
203
+ };
204
+ }
205
+ /** Health check response. */
206
+ interface HealthResponse {
207
+ status: string;
208
+ service: string;
209
+ version: string;
210
+ }
211
+ /** Error response from the API. */
212
+ interface ApiErrorResponse {
213
+ success: false;
214
+ error: string;
215
+ code?: string;
216
+ kydUrl?: string;
217
+ ownerNotified?: boolean;
218
+ }
219
+
220
+ /**
221
+ * AstraSync SDK client for registering and managing AI agents.
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const client = new AstraSync({ apiKey: 'kya_your_api_key' });
226
+ * const result = await client.register({
227
+ * name: 'My Agent',
228
+ * model: { modelName: 'gpt-4o', modelProvider: 'openai', modelType: 'llm' },
229
+ * });
230
+ * ```
231
+ *
232
+ * For staging, pass `baseUrl: 'https://staging.astrasync.ai'`.
233
+ */
234
+ declare class AstraSync {
235
+ private readonly baseUrl;
236
+ private readonly apiKey?;
237
+ private readonly email?;
238
+ private readonly password?;
239
+ private readonly privateKey?;
240
+ private cachedJwt?;
241
+ private jwtExpiresAt?;
242
+ constructor(config?: AstraSyncConfig);
243
+ /**
244
+ * Register a new AI agent on the AstraSync KYA Platform.
245
+ *
246
+ * The backend response depends on auth context:
247
+ * - **Crypto-keypair signed** (`privateKey` configured): synchronous 201,
248
+ * returns `{ status: 'active', agent }`.
249
+ * - **API-key only** (no signature): 202 pending, returns
250
+ * `{ status: 'pending_approval', requestId, pollUrl, expiresAt }`. The
251
+ * owner is notified by email and a dashboard alert is emitted; the agent
252
+ * becomes active only after the owner approves.
253
+ *
254
+ * Blocking mode: pass `{ waitForApproval: true }` to have the SDK poll the
255
+ * request until it resolves, then return the live agent record. The promise
256
+ * rejects with `RegistrationDeniedError`, `RegistrationExpiredError`, or
257
+ * `RegistrationTimeoutError` on the corresponding terminal states.
258
+ *
259
+ * @example Non-blocking (default — best for serverless / scheduled agents):
260
+ * ```typescript
261
+ * const result = await sdk.register({ name, pdlss });
262
+ * if (result.status === 'pending_approval') {
263
+ * storeRequestId(result.requestId);
264
+ * return; // function exits; resume later via pollRegistration()
265
+ * }
266
+ * ```
267
+ *
268
+ * @example Blocking (best for long-running services + CLI):
269
+ * ```typescript
270
+ * const agent = await sdk.register({
271
+ * name, pdlss, waitForApproval: true, timeoutMs: 600_000,
272
+ * onPending: ({ ageMs }) => console.log(`waiting ${ageMs}ms`),
273
+ * });
274
+ * ```
275
+ */
276
+ register(options: RegisterOptions & WaitForApprovalOptions): Promise<RegisterResult | AgentRecord>;
277
+ /**
278
+ * Poll the current state of a pending-approval registration request.
279
+ *
280
+ * Useful for caller-driven polling when `waitForApproval: false` (the
281
+ * default). The endpoint is unauthenticated — pass the `requestId` that
282
+ * was returned from the 202 response.
283
+ *
284
+ * @returns `state: 'pending'` while awaiting; `'approved'` carries the
285
+ * minted agent in `agent`; `'denied'` may carry the owner's
286
+ * `reason`; `'expired'` is terminal after 14 days.
287
+ */
288
+ pollRegistration(requestId: string): Promise<PollRegistrationResult>;
289
+ /**
290
+ * Block until a pending registration request resolves to a terminal state.
291
+ * Resolves to the live `AgentRecord` on approval; rejects with the matching
292
+ * Registration*Error on deny/expire/timeout. Usually called via
293
+ * `register({ waitForApproval: true })`, but exposed for callers that want
294
+ * to fire-and-forget the initial register call and resume waiting later
295
+ * (e.g. after restoring a stored `requestId` on cold start).
296
+ */
297
+ waitForApproval(requestId: string, options?: WaitForApprovalOptions): Promise<AgentRecord>;
298
+ /**
299
+ * Look up an agent's public profile by ASTRA ID or UUID.
300
+ */
301
+ verify(agentId: string): Promise<VerifyResponse>;
302
+ /**
303
+ * Check API health.
304
+ */
305
+ health(): Promise<HealthResponse>;
306
+ private request;
307
+ /**
308
+ * Variant of {@link request} that also returns the HTTP status code, so
309
+ * callers can branch on 201 vs 202 (or other success codes) without losing
310
+ * type information about the response body.
311
+ */
312
+ private requestWithStatus;
313
+ private getAuthToken;
314
+ /**
315
+ * Sign a request using secp256k1 (ethers.js).
316
+ * Canonical message format: METHOD:ENDPOINT:SORTED_JSON_BODY
317
+ * Must match apps/backend/src/services/signature-verify.service.ts exactly.
318
+ */
319
+ private signRequest;
320
+ /** Recursively sort object keys for canonical JSON representation. */
321
+ private sortObjectKeys;
322
+ }
323
+
324
+ /** Base error class for AstraSync SDK errors. */
325
+ declare class AstraSyncError extends Error {
326
+ readonly code?: string;
327
+ readonly statusCode: number;
328
+ constructor(message: string, statusCode: number, code?: string);
329
+ }
330
+ /** Thrown when KYD verification is required before agent registration. */
331
+ declare class KYDRequiredError extends AstraSyncError {
332
+ readonly kydUrl: string;
333
+ readonly ownerNotified: boolean;
334
+ constructor(response: ApiErrorResponse);
335
+ }
336
+ /** Thrown when authentication fails. */
337
+ declare class AuthenticationError extends AstraSyncError {
338
+ constructor(message: string);
339
+ }
340
+ /**
341
+ * Thrown by `register({ waitForApproval: true })` when the owner denies the
342
+ * pending registration request. The `reason` field, when present, mirrors the
343
+ * deny note the owner left in the dashboard.
344
+ */
345
+ declare class RegistrationDeniedError extends AstraSyncError {
346
+ readonly requestId: string;
347
+ readonly reason?: string;
348
+ constructor(requestId: string, reason?: string);
349
+ }
350
+ /**
351
+ * Thrown by `register({ waitForApproval: true })` when the pending request
352
+ * passes its 14-day TTL with no owner decision. The agent must re-submit.
353
+ */
354
+ declare class RegistrationExpiredError extends AstraSyncError {
355
+ readonly requestId: string;
356
+ constructor(requestId: string);
357
+ }
358
+ /**
359
+ * Thrown by `register({ waitForApproval: true })` when the caller's local
360
+ * `timeoutMs` elapses before the owner makes a decision. The request is still
361
+ * live server-side — poll `pollRegistration(requestId)` to resume waiting, or
362
+ * call `waitForApproval` again with a longer timeout.
363
+ */
364
+ declare class RegistrationTimeoutError extends AstraSyncError {
365
+ readonly requestId: string;
366
+ constructor(requestId: string);
367
+ }
368
+
369
+ export { type AgentProtocol, type AgentRecord, AstraSync, type AstraSyncConfig, AstraSyncError, AuthenticationError, type FrameworkConfig, type HealthResponse, KYDRequiredError, type ModelConfig, type PDLSSConfig, type PDLSSDuration, type PDLSSLimits, type PDLSSPurpose, type PDLSSScope, type PDLSSSelfInstantiation, type PendingRegistrationResponse, type PollRegistrationResult, type RegisterOptions, type RegisterResult, RegistrationDeniedError, RegistrationExpiredError, type RegistrationResponse, RegistrationTimeoutError, type VerifyResponse, type WaitForApprovalOptions };