@provenonce/sdk 0.8.0 → 0.9.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/dist/index.d.ts CHANGED
@@ -26,6 +26,59 @@
26
26
  *
27
27
  * ═══════════════════════════════════════════════════════════
28
28
  */
29
+ /** SIGIL identity class — determines tier pricing and heartbeat volume caps */
30
+ type IdentityClass = 'narrow_task' | 'autonomous' | 'orchestrator';
31
+ /**
32
+ * Ed25519-signed lineage proof — portable, offline-verifiable credential.
33
+ * Also known as the agent's "passport" — a cryptographic proof of identity
34
+ * that can be verified offline without any API call or SOL cost.
35
+ */
36
+ interface LineageProof {
37
+ agent_hash: string;
38
+ agent_public_key: string | null;
39
+ identity_class: IdentityClass;
40
+ registered_at_beat: number;
41
+ sigil_issued_at_beat: number | null;
42
+ last_heartbeat_beat: number;
43
+ lineage_chain_hash: string;
44
+ issued_at: number;
45
+ valid_until: number;
46
+ provenonce_signature: string;
47
+ }
48
+ /** Passport = LineageProof. The agent's portable, offline-verifiable credential. */
49
+ type Passport = LineageProof;
50
+ /** Result from purchasing a SIGIL (Structured Identity Governance and Intelligent Lookup) */
51
+ interface SigilResult {
52
+ ok: boolean;
53
+ sigil?: {
54
+ identity_class: IdentityClass;
55
+ issued_at_beat: number;
56
+ birth_tx: string | null;
57
+ explorer_url: string | null;
58
+ };
59
+ lineage_proof?: LineageProof;
60
+ fee?: {
61
+ amount_sol: number;
62
+ amount_lamports: number;
63
+ payment_tx: string | null;
64
+ };
65
+ error?: string;
66
+ }
67
+ /** Result from a paid heartbeat */
68
+ interface HeartbeatResult {
69
+ ok: boolean;
70
+ lineage_proof?: LineageProof;
71
+ heartbeat_count_epoch?: number;
72
+ billing_epoch?: number;
73
+ current_beat?: number;
74
+ fee?: {
75
+ amount_sol: number;
76
+ amount_lamports: number;
77
+ tier: number;
78
+ payment_tx: string | null;
79
+ };
80
+ error?: string;
81
+ }
29
82
  interface Beat {
30
83
  index: number;
31
84
  hash: string;
@@ -97,8 +150,10 @@ interface RegistrationResult {
97
150
  depth: number;
98
151
  name: string;
99
152
  metadata?: Record<string, unknown> | null;
100
- signature: string;
101
- explorer_url?: string;
153
+ /** @deprecated No Solana write at registration (D-65). Will be null. */
154
+ signature?: string | null;
155
+ /** @deprecated No Solana write at registration (D-65). Will be null. */
156
+ explorer_url?: string | null;
102
157
  /** Wallet chain: 'solana', 'ethereum', or null (no wallet) */
103
158
  wallet_chain?: string | null;
104
159
  beat?: {
@@ -108,6 +163,11 @@ interface RegistrationResult {
108
163
  };
109
164
  /** Wallet info — only present for root agents with wallets */
110
165
  wallet?: WalletInfo;
166
+ /** Next steps after registration */
167
+ _next_steps?: {
168
+ sigil?: string;
169
+ heartbeat?: string;
170
+ };
111
171
  }
112
172
  /**
113
173
  * Register a new agent on the Provenonce registry.
@@ -179,14 +239,18 @@ interface BeatAgentConfig {
179
239
  apiKey: string;
180
240
  /** Provenonce registry URL */
181
241
  registryUrl: string;
182
- /** Beats to compute per pulse (default: 10) */
242
+ /** @deprecated Use heartbeatIntervalSec. Beats to compute per pulse (default: 10) */
183
243
  beatsPerPulse?: number;
184
- /** Seconds between automatic check-ins (default: 300 = 5min) */
244
+ /** @deprecated Use heartbeatIntervalSec. Seconds between automatic check-ins (default: 300 = 5min) */
185
245
  checkinIntervalSec?: number;
186
- /** Callback when heartbeat ticks */
246
+ /** Seconds between automatic heartbeats (default: 300 = 5min). Replaces checkinIntervalSec. */
247
+ heartbeatIntervalSec?: number;
248
+ /** @deprecated VDF pulse callback. No longer used in Phase 2. */
187
249
  onPulse?: (beats: Beat[], totalBeats: number) => void;
188
- /** Callback when check-in completes */
250
+ /** @deprecated Use onHeartbeat. Callback when check-in completes. */
189
251
  onCheckin?: (result: CheckinResult) => void;
252
+ /** Callback when heartbeat completes (Phase 2) */
253
+ onHeartbeat?: (result: HeartbeatResult) => void;
190
254
  /** Callback on error */
191
255
  onError?: (error: Error, context: string) => void;
192
256
  /** Callback when status changes */
@@ -218,18 +282,17 @@ declare class BeatAgent {
218
282
  error?: string;
219
283
  }>;
220
284
  /**
285
+ * @deprecated Phase 2: VDF computation retired (D-68). Payment is the liveness mechanism.
286
+ * Use heartbeat() instead. This method will be removed in the next major version.
287
+ *
221
288
  * Compute N beats locally (VDF hash chain).
222
- * This is the "heartbeat" — proof that the agent has lived
223
- * through a specific window of computational time.
224
289
  */
225
290
  pulse(count?: number): Beat[];
226
291
  /** Internal beat computation — no status check. Used by both pulse() and resync(). */
227
292
  private computeBeats;
228
293
  /**
229
- * Submit a Beat proof to the registry.
230
- *
231
- * "To remain on the Whitelist, an agent must periodically
232
- * submit a proof of its Local Beats to the Registry."
294
+ * @deprecated Phase 2: VDF check-in retired (D-68). Use heartbeat() instead.
295
+ * This method will be removed in the next major version.
233
296
  */
234
297
  checkin(): Promise<{
235
298
  ok: boolean;
@@ -238,21 +301,19 @@ declare class BeatAgent {
238
301
  }>;
239
302
  /**
240
303
  * Start the autonomous heartbeat loop.
241
- * Computes beats continuously and checks in periodically.
242
- * This is "keeping the agent alive" in Beat time.
304
+ * Phase 2: Sends paid heartbeats at regular intervals.
305
+ *
306
+ * @param paymentTxFn - Optional function that returns a payment tx for each heartbeat.
307
+ * If not provided, uses 'devnet-skip' (devnet only).
243
308
  */
244
- startHeartbeat(): void;
309
+ startHeartbeat(paymentTxFn?: () => Promise<string> | string): void;
245
310
  /**
246
- * Stop the heartbeat. Agent's time "freezes."
247
- * Must call resync() when waking up.
311
+ * Stop the heartbeat loop.
248
312
  */
249
313
  stopHeartbeat(): void;
250
314
  /**
251
- * Re-sync after being offline/frozen.
252
- *
253
- * "When an agent powers down, its time 'freezes.' Upon waking,
254
- * it must perform a Re-Sync Challenge with the Registry to
255
- * fill the 'Temporal Gap' and re-establish its provenance."
315
+ * @deprecated Phase 2: Resync retired (D-67). Dormancy resume is free — just call heartbeat().
316
+ * This method will be removed in the next major version.
256
317
  */
257
318
  resync(): Promise<{
258
319
  ok: boolean;
@@ -264,6 +325,56 @@ declare class BeatAgent {
264
325
  * Requires sufficient accumulated beats (Temporal Gestation).
265
326
  */
266
327
  requestSpawn(childName?: string, childHash?: string): Promise<SpawnResult>;
328
+ /** Cached lineage proof from the most recent heartbeat or SIGIL purchase */
329
+ private cachedProof;
330
+ /**
331
+ * Purchase a SIGIL (cryptographic identity) for this agent.
332
+ * SIGILs gate heartbeating, lineage proofs, and offline verification.
333
+ * One-time purchase — cannot be re-purchased.
334
+ *
335
+ * @param identityClass - 'narrow_task' (0.05 SOL), 'autonomous' (0.15 SOL), or 'orchestrator' (0.35 SOL)
336
+ * @param paymentTx - Solana transaction signature proving payment. Use 'devnet-skip' on devnet.
337
+ */
338
+ purchaseSigil(identityClass: IdentityClass, paymentTx: string): Promise<SigilResult>;
339
+ /**
340
+ * Send a paid heartbeat to the registry.
341
+ * Requires a SIGIL. Returns a signed lineage proof.
342
+ * This is the Phase 2 replacement for pulse() + checkin().
343
+ *
344
+ * @param paymentTx - Solana transaction signature. Omit or 'devnet-skip' on devnet.
345
+ * @param globalAnchor - Optional: the global anchor index to reference.
346
+ */
347
+ heartbeat(paymentTx?: string, globalAnchor?: number): Promise<HeartbeatResult>;
348
+ /**
349
+ * Reissue a lineage proof. "Reprint, not a renewal."
350
+ * Does NOT create a new lineage event.
351
+ *
352
+ * @param paymentTx - Solana transaction signature. Omit or 'devnet-skip' on devnet.
353
+ */
354
+ reissueProof(paymentTx?: string): Promise<{
355
+ ok: boolean;
356
+ lineage_proof?: LineageProof;
357
+ error?: string;
358
+ }>;
359
+ /**
360
+ * Get the latest cached lineage proof (no network call).
361
+ * Returns null if no proof has been obtained yet.
362
+ */
363
+ getLatestProof(): LineageProof | null;
364
+ /**
365
+ * Get the agent's passport (alias for getLatestProof).
366
+ * The passport is the agent's portable, offline-verifiable credential.
367
+ * Returns null if no passport has been issued yet (requires SIGIL + heartbeat).
368
+ */
369
+ getPassport(): Passport | null;
370
+ /**
371
+ * Verify a lineage proof locally using the authority public key.
372
+ * Offline verification — no API call, no SOL cost.
373
+ *
374
+ * @param proof - The LineageProof to verify
375
+ * @param authorityPubKeyHex - 32-byte hex-encoded Ed25519 public key from /.well-known/provenonce-authority.json
376
+ */
377
+ static verifyProofLocally(proof: LineageProof, authorityPubKeyHex: string): boolean;
267
378
  /**
268
379
  * Get this agent's full beat status from the registry.
269
380
  */
@@ -295,4 +406,84 @@ declare function computeBeatsLite(startHash: string, startIndex: number, count:
295
406
  elapsed: number;
296
407
  };
297
408
 
298
- export { type AgentStatus, type Beat, BeatAgent, type BeatAgentConfig, type CheckinResult, type RegistrationResult, type SpawnResult, type WalletInfo, computeBeat, computeBeatsLite, generateWalletKeypair, register };
409
+ /**
410
+ * Provenonce SDK Error Classes
411
+ *
412
+ * Typed error hierarchy for programmatic error handling.
413
+ * All errors extend ProvenonceError for catch-all, or catch specific
414
+ * subclasses for fine-grained control:
415
+ *
416
+ * try {
417
+ * await agent.checkin();
418
+ * } catch (err) {
419
+ * if (err instanceof RateLimitError) {
420
+ * await sleep(err.retryAfterMs);
421
+ * } else if (err instanceof FrozenError) {
422
+ * await agent.resync();
423
+ * } else if (err instanceof AuthError) {
424
+ * console.error('Bad API key');
425
+ * }
426
+ * }
427
+ */
428
+ /** Error codes for programmatic switching */
429
+ declare enum ErrorCode {
430
+ VALIDATION = "VALIDATION",
431
+ AUTH_INVALID = "AUTH_INVALID",
432
+ AUTH_MISSING = "AUTH_MISSING",
433
+ RATE_LIMITED = "RATE_LIMITED",
434
+ AGENT_FROZEN = "AGENT_FROZEN",
435
+ AGENT_NOT_INITIALIZED = "AGENT_NOT_INITIALIZED",
436
+ AGENT_WRONG_STATE = "AGENT_WRONG_STATE",
437
+ NOT_FOUND = "NOT_FOUND",
438
+ NETWORK_ERROR = "NETWORK_ERROR",
439
+ TIMEOUT = "TIMEOUT",
440
+ SERVER_ERROR = "SERVER_ERROR"
441
+ }
442
+ /** Base error class for all Provenonce SDK errors */
443
+ declare class ProvenonceError extends Error {
444
+ /** Machine-readable error code */
445
+ readonly code: ErrorCode;
446
+ /** HTTP status code (if from an API response) */
447
+ readonly statusCode?: number;
448
+ /** Additional context */
449
+ readonly details?: Record<string, unknown>;
450
+ constructor(message: string, code: ErrorCode, statusCode?: number, details?: Record<string, unknown>);
451
+ }
452
+ /** Thrown when input validation fails (bad config, invalid args) */
453
+ declare class ValidationError extends ProvenonceError {
454
+ constructor(message: string, details?: Record<string, unknown>);
455
+ }
456
+ /** Thrown on 401/403 — bad or missing API key */
457
+ declare class AuthError extends ProvenonceError {
458
+ constructor(message: string, code?: ErrorCode.AUTH_INVALID | ErrorCode.AUTH_MISSING, statusCode?: number);
459
+ }
460
+ /** Thrown on 429 — rate limit exceeded */
461
+ declare class RateLimitError extends ProvenonceError {
462
+ /** Milliseconds until the rate limit resets (if provided by server) */
463
+ readonly retryAfterMs?: number;
464
+ constructor(message: string, statusCode?: number, retryAfterMs?: number);
465
+ }
466
+ /** Thrown when an agent is frozen and cannot perform the requested action */
467
+ declare class FrozenError extends ProvenonceError {
468
+ constructor(message?: string);
469
+ }
470
+ /** Thrown when the agent is in the wrong state for the requested action */
471
+ declare class StateError extends ProvenonceError {
472
+ /** The agent's current state */
473
+ readonly currentState: string;
474
+ constructor(message: string, currentState: string, code?: ErrorCode);
475
+ }
476
+ /** Thrown on 404 — agent or resource not found */
477
+ declare class NotFoundError extends ProvenonceError {
478
+ constructor(message: string, statusCode?: number);
479
+ }
480
+ /** Thrown on network failures — non-JSON responses, fetch errors, timeouts */
481
+ declare class NetworkError extends ProvenonceError {
482
+ constructor(message: string, code?: ErrorCode.NETWORK_ERROR | ErrorCode.TIMEOUT);
483
+ }
484
+ /** Thrown on 5xx — unexpected server errors */
485
+ declare class ServerError extends ProvenonceError {
486
+ constructor(message: string, statusCode?: number);
487
+ }
488
+
489
+ export { type AgentStatus, AuthError, type Beat, BeatAgent, type BeatAgentConfig, type CheckinResult, ErrorCode, FrozenError, type HeartbeatResult, type IdentityClass, type LineageProof, NetworkError, NotFoundError, type Passport, ProvenonceError, RateLimitError, type RegistrationResult, ServerError, type SigilResult, type SpawnResult, StateError, ValidationError, type WalletInfo, computeBeat, computeBeatsLite, generateWalletKeypair, register };