@provenonce/sdk 0.6.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/README.md +82 -25
- package/dist/index.d.mts +293 -27
- package/dist/index.d.ts +293 -27
- package/dist/index.js +641 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +631 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @provenonce/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cryptographic identity and accountability SDK for AI agents. Chain-agnostic (Solana + Ethereum).
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -15,9 +15,9 @@ Before using the SDK, register your agent to get an API key:
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { register } from '@provenonce/sdk';
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// No-wallet registration (default — identity only)
|
|
19
19
|
const creds = await register('my-agent-v1', {
|
|
20
|
-
registryUrl: 'https://provenonce.
|
|
20
|
+
registryUrl: 'https://provenonce.io',
|
|
21
21
|
registrationSecret: process.env.REGISTRATION_SECRET, // required in production
|
|
22
22
|
});
|
|
23
23
|
|
|
@@ -25,9 +25,17 @@ console.log(creds.hash); // unique agent identity
|
|
|
25
25
|
console.log(creds.api_key); // use this for BeatAgent
|
|
26
26
|
console.log(creds.secret); // save — shown only once
|
|
27
27
|
|
|
28
|
+
// Solana self-custody wallet (opt-in)
|
|
29
|
+
const withWallet = await register('my-org', {
|
|
30
|
+
registryUrl: 'https://provenonce.io',
|
|
31
|
+
walletModel: 'self-custody',
|
|
32
|
+
});
|
|
33
|
+
// withWallet.wallet.address = Solana address
|
|
34
|
+
// withWallet.wallet.secret_key = SAVE — cannot be recovered
|
|
35
|
+
|
|
28
36
|
// Child registration (requires parent credentials)
|
|
29
37
|
const child = await register('worker-1', {
|
|
30
|
-
registryUrl: 'https://provenonce.
|
|
38
|
+
registryUrl: 'https://provenonce.io',
|
|
31
39
|
parentHash: creds.hash,
|
|
32
40
|
parentApiKey: creds.api_key,
|
|
33
41
|
});
|
|
@@ -40,14 +48,28 @@ import { BeatAgent } from '@provenonce/sdk';
|
|
|
40
48
|
|
|
41
49
|
const agent = new BeatAgent({
|
|
42
50
|
apiKey: 'pvn_...',
|
|
43
|
-
registryUrl: 'https://provenonce.
|
|
51
|
+
registryUrl: 'https://provenonce.io',
|
|
44
52
|
verbose: true,
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
await agent.init(); // Birth in Beat time
|
|
48
|
-
agent.startHeartbeat(); // Compute + check in continuously
|
|
49
56
|
|
|
50
|
-
//
|
|
57
|
+
// Purchase a SIGIL (cryptographic identity)
|
|
58
|
+
const sigil = await agent.purchaseSigil({
|
|
59
|
+
identityClass: 'autonomous',
|
|
60
|
+
paymentTx: 'solana-tx-signature...',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Start heartbeating (paid liveness proofs)
|
|
64
|
+
agent.startHeartbeat();
|
|
65
|
+
|
|
66
|
+
// Get your Passport (latest lineage proof)
|
|
67
|
+
const passport = await agent.getPassport();
|
|
68
|
+
console.log(passport?.identity_class); // 'autonomous'
|
|
69
|
+
console.log(passport?.provenonce_signature); // Ed25519 signed
|
|
70
|
+
|
|
71
|
+
// Verify any proof offline — no API call needed
|
|
72
|
+
const valid = BeatAgent.verifyProofLocally(passport, authorityPubKeyHex);
|
|
51
73
|
|
|
52
74
|
agent.stopHeartbeat();
|
|
53
75
|
```
|
|
@@ -59,14 +81,16 @@ agent.stopHeartbeat();
|
|
|
59
81
|
| Method | Description |
|
|
60
82
|
|--------|-------------|
|
|
61
83
|
| `init()` | Initialize the agent's Beat chain (birth in Logical Time) |
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `startHeartbeat()` | Start autonomous
|
|
65
|
-
| `stopHeartbeat()` | Stop heartbeat
|
|
66
|
-
| `
|
|
84
|
+
| `purchaseSigil(opts)` | Purchase a SIGIL identity (required for heartbeating) |
|
|
85
|
+
| `heartbeat(opts?)` | Submit a paid heartbeat and receive a signed lineage proof |
|
|
86
|
+
| `startHeartbeat()` | Start autonomous heartbeat loop |
|
|
87
|
+
| `stopHeartbeat()` | Stop heartbeat |
|
|
88
|
+
| `getPassport()` | Get latest lineage proof (Passport) |
|
|
89
|
+
| `reissueProof(paymentTx?)` | Reissue proof without extending lineage |
|
|
67
90
|
| `requestSpawn(name?)` | Spawn a child agent (requires accumulated beats) |
|
|
68
91
|
| `getStatus()` | Get full beat status from registry |
|
|
69
92
|
| `getLocalState()` | Get local state (no network call) |
|
|
93
|
+
| `static verifyProofLocally(proof, pubKey)` | Verify a lineage proof offline |
|
|
70
94
|
|
|
71
95
|
### `BeatAgentConfig`
|
|
72
96
|
|
|
@@ -74,24 +98,57 @@ agent.stopHeartbeat();
|
|
|
74
98
|
|--------|---------|-------------|
|
|
75
99
|
| `apiKey` | *required* | API key from registration (`pvn_...`) |
|
|
76
100
|
| `registryUrl` | *required* | Provenonce registry URL |
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `onPulse` | — | Callback when heartbeat ticks |
|
|
80
|
-
| `onCheckin` | — | Callback when check-in completes |
|
|
101
|
+
| `heartbeatIntervalSec` | `300` | Seconds between automatic heartbeats |
|
|
102
|
+
| `onHeartbeat` | — | Callback when heartbeat completes |
|
|
81
103
|
| `onError` | — | Callback on error |
|
|
82
104
|
| `onStatusChange` | — | Callback when status changes |
|
|
83
105
|
| `verbose` | `false` | Enable console logging |
|
|
84
106
|
|
|
85
|
-
###
|
|
107
|
+
### `register(name, options)`
|
|
108
|
+
|
|
109
|
+
| Option | Description |
|
|
110
|
+
|--------|-------------|
|
|
111
|
+
| `registryUrl` | Registry URL (required) |
|
|
112
|
+
| `registrationSecret` | Registration gate (mainnet) |
|
|
113
|
+
| `walletModel` | `'self-custody'` or `'operator'` (opt-in wallet) |
|
|
114
|
+
| `walletChain` | `'solana'` or `'ethereum'` |
|
|
115
|
+
| `walletAddress` | Ethereum BYO address |
|
|
116
|
+
| `walletSignFn` | Signing function for BYO wallets |
|
|
117
|
+
| `parentHash` | Parent hash (child registration) |
|
|
118
|
+
| `parentApiKey` | Parent's API key (child registration) |
|
|
119
|
+
|
|
120
|
+
Returns `RegistrationResult` with `hash`, `api_key`, `secret`, `wallet?`.
|
|
121
|
+
|
|
122
|
+
**Note:** Agent names should only contain `[a-zA-Z0-9_\-. ]`. Other characters are stripped by the server before signature verification.
|
|
123
|
+
|
|
124
|
+
### Phase 2 Types
|
|
86
125
|
|
|
87
126
|
```typescript
|
|
88
|
-
import {
|
|
127
|
+
import type { Passport, LineageProof, IdentityClass, SigilResult, HeartbeatResult } from '@provenonce/sdk';
|
|
89
128
|
|
|
90
|
-
//
|
|
91
|
-
|
|
129
|
+
// Passport = LineageProof (type alias)
|
|
130
|
+
// Contains: agent_hash, agent_public_key, identity_class, lineage_chain_hash,
|
|
131
|
+
// provenonce_signature, issued_at, valid_until, etc.
|
|
92
132
|
|
|
93
|
-
//
|
|
94
|
-
|
|
133
|
+
// IdentityClass = 'narrow_task' | 'autonomous' | 'orchestrator'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Error Handling
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { ProvenonceError, AuthError, RateLimitError, FrozenError, ErrorCode } from '@provenonce/sdk';
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
await agent.heartbeat();
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err instanceof RateLimitError) {
|
|
145
|
+
console.log(`Retry after ${err.retryAfterMs}ms`);
|
|
146
|
+
} else if (err instanceof FrozenError) {
|
|
147
|
+
console.log('Agent is frozen — heartbeat refused');
|
|
148
|
+
} else if (err instanceof AuthError) {
|
|
149
|
+
console.log('Invalid API key');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
95
152
|
```
|
|
96
153
|
|
|
97
154
|
## Framework Integration Examples
|
|
@@ -109,7 +166,7 @@ Python examples use the REST API directly — no Python SDK needed. See [`exampl
|
|
|
109
166
|
|
|
110
167
|
## Links
|
|
111
168
|
|
|
112
|
-
- [Live prototype](https://provenonce.
|
|
169
|
+
- [Live prototype](https://provenonce.io)
|
|
113
170
|
- [npm package](https://www.npmjs.com/package/@provenonce/sdk)
|
|
114
|
-
- [API docs](https://provenonce.
|
|
115
|
-
- [
|
|
171
|
+
- [API docs](https://provenonce.dev)
|
|
172
|
+
- [Whitepaper](https://provenonce.dev/whitepaper)
|
package/dist/index.d.mts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* const agent = new BeatAgent({
|
|
14
14
|
* apiKey: 'pvn_...',
|
|
15
|
-
* registryUrl: 'https://provenonce.
|
|
15
|
+
* registryUrl: 'https://provenonce.io',
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
18
|
* await agent.init(); // Birth in Beat time
|
|
@@ -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;
|
|
@@ -65,6 +118,28 @@ interface AgentStatus {
|
|
|
65
118
|
};
|
|
66
119
|
difficulty?: number;
|
|
67
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Generate an Ed25519 keypair for agent wallet identity.
|
|
123
|
+
* Returns hex-encoded raw keys (32 bytes each).
|
|
124
|
+
* Uses Node.js built-in crypto — zero external dependencies.
|
|
125
|
+
*/
|
|
126
|
+
declare function generateWalletKeypair(): {
|
|
127
|
+
publicKey: string;
|
|
128
|
+
secretKey: string;
|
|
129
|
+
};
|
|
130
|
+
/** Wallet info returned from root registration */
|
|
131
|
+
interface WalletInfo {
|
|
132
|
+
/** Hex-encoded 32-byte Ed25519 public key (Solana self-custody only, empty otherwise) */
|
|
133
|
+
public_key: string;
|
|
134
|
+
/** Hex-encoded 32-byte Ed25519 secret seed — SAVE THIS for future fee signing (Solana self-custody only) */
|
|
135
|
+
secret_key: string;
|
|
136
|
+
/** Solana-compatible base58 address (Solana wallets only) */
|
|
137
|
+
solana_address?: string;
|
|
138
|
+
/** The wallet address (base58 for Solana, 0x for Ethereum) */
|
|
139
|
+
address: string;
|
|
140
|
+
/** Wallet chain: 'solana' or 'ethereum' */
|
|
141
|
+
chain: string;
|
|
142
|
+
}
|
|
68
143
|
/** Result from registering an agent */
|
|
69
144
|
interface RegistrationResult {
|
|
70
145
|
hash: string;
|
|
@@ -74,21 +149,63 @@ interface RegistrationResult {
|
|
|
74
149
|
parent: string | null;
|
|
75
150
|
depth: number;
|
|
76
151
|
name: string;
|
|
77
|
-
|
|
78
|
-
|
|
152
|
+
metadata?: Record<string, unknown> | null;
|
|
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;
|
|
157
|
+
/** Wallet chain: 'solana', 'ethereum', or null (no wallet) */
|
|
158
|
+
wallet_chain?: string | null;
|
|
79
159
|
beat?: {
|
|
80
160
|
genesis_hash: string;
|
|
81
161
|
difficulty: number;
|
|
82
162
|
status: string;
|
|
83
163
|
};
|
|
164
|
+
/** Wallet info — only present for root agents with wallets */
|
|
165
|
+
wallet?: WalletInfo;
|
|
166
|
+
/** Next steps after registration */
|
|
167
|
+
_next_steps?: {
|
|
168
|
+
sigil?: string;
|
|
169
|
+
heartbeat?: string;
|
|
170
|
+
};
|
|
84
171
|
}
|
|
85
172
|
/**
|
|
86
173
|
* Register a new agent on the Provenonce registry.
|
|
87
174
|
*
|
|
88
|
-
*
|
|
89
|
-
* const creds = await register('my-
|
|
175
|
+
* No wallet (default, single-phase):
|
|
176
|
+
* const creds = await register('my-agent', { registryUrl: '...' });
|
|
90
177
|
*
|
|
91
|
-
*
|
|
178
|
+
* Solana self-custody wallet (Model A, two-phase):
|
|
179
|
+
* const creds = await register('my-org', {
|
|
180
|
+
* registryUrl: '...',
|
|
181
|
+
* walletModel: 'self-custody',
|
|
182
|
+
* });
|
|
183
|
+
* // creds.wallet.secret_key = hex secret (SAVE THIS)
|
|
184
|
+
* // creds.wallet.address = base58 Solana address
|
|
185
|
+
*
|
|
186
|
+
* Solana with existing key:
|
|
187
|
+
* const creds = await register('my-org', {
|
|
188
|
+
* registryUrl: '...',
|
|
189
|
+
* walletSecretKey: '<hex-encoded-32-byte-seed>',
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* Ethereum bring-your-own (two-phase):
|
|
193
|
+
* const creds = await register('my-org', {
|
|
194
|
+
* registryUrl: '...',
|
|
195
|
+
* walletChain: 'ethereum',
|
|
196
|
+
* walletAddress: '0x...',
|
|
197
|
+
* walletSignFn: (msg) => wallet.signMessage(msg),
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* Solana operator (Model B, two-phase):
|
|
201
|
+
* const creds = await register('my-org', {
|
|
202
|
+
* registryUrl: '...',
|
|
203
|
+
* walletModel: 'operator',
|
|
204
|
+
* operatorWalletAddress: '<base58>',
|
|
205
|
+
* operatorSignFn: (msg) => signWithWallet(msg),
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* Child agent (no wallet):
|
|
92
209
|
* const creds = await register('worker-1', {
|
|
93
210
|
* registryUrl: '...',
|
|
94
211
|
* parentHash: parentCreds.hash,
|
|
@@ -100,20 +217,40 @@ declare function register(name: string, options?: {
|
|
|
100
217
|
parentHash?: string;
|
|
101
218
|
parentApiKey?: string;
|
|
102
219
|
registrationSecret?: string;
|
|
220
|
+
/** Hex-encoded 32-byte Ed25519 secret seed (bring-your-own Solana key) */
|
|
221
|
+
walletSecretKey?: string;
|
|
222
|
+
/** Wallet model: 'self-custody' (Model A) or 'operator' (Model B). Must be set explicitly to opt in. */
|
|
223
|
+
walletModel?: 'self-custody' | 'operator';
|
|
224
|
+
/** Wallet chain: 'solana' (default when wallet is used) or 'ethereum' (D-63) */
|
|
225
|
+
walletChain?: 'solana' | 'ethereum';
|
|
226
|
+
/** Wallet address for Ethereum bring-your-own (0x + 40 hex chars) */
|
|
227
|
+
walletAddress?: string;
|
|
228
|
+
/** Async function to sign a message with an Ethereum wallet (EIP-191 personal_sign). Returns 0x-prefixed 65-byte hex sig. */
|
|
229
|
+
walletSignFn?: (message: string) => Promise<string>;
|
|
230
|
+
/** Operator's Solana wallet address (base58). Required when walletModel='operator'. */
|
|
231
|
+
operatorWalletAddress?: string;
|
|
232
|
+
/** Function to sign a message with the operator's Solana wallet. Required when walletModel='operator'. */
|
|
233
|
+
operatorSignFn?: (message: string) => Promise<string>;
|
|
234
|
+
/** Optional agent metadata (arbitrary JSON object, max 4KB). Returned in /verify and /status. */
|
|
235
|
+
metadata?: Record<string, unknown>;
|
|
103
236
|
}): Promise<RegistrationResult>;
|
|
104
237
|
interface BeatAgentConfig {
|
|
105
238
|
/** API key from registration (pvn_...) */
|
|
106
239
|
apiKey: string;
|
|
107
240
|
/** Provenonce registry URL */
|
|
108
241
|
registryUrl: string;
|
|
109
|
-
/** Beats to compute per pulse (default: 10) */
|
|
242
|
+
/** @deprecated Use heartbeatIntervalSec. Beats to compute per pulse (default: 10) */
|
|
110
243
|
beatsPerPulse?: number;
|
|
111
|
-
/** Seconds between automatic check-ins (default: 300 = 5min) */
|
|
244
|
+
/** @deprecated Use heartbeatIntervalSec. Seconds between automatic check-ins (default: 300 = 5min) */
|
|
112
245
|
checkinIntervalSec?: number;
|
|
113
|
-
/**
|
|
246
|
+
/** Seconds between automatic heartbeats (default: 300 = 5min). Replaces checkinIntervalSec. */
|
|
247
|
+
heartbeatIntervalSec?: number;
|
|
248
|
+
/** @deprecated VDF pulse callback. No longer used in Phase 2. */
|
|
114
249
|
onPulse?: (beats: Beat[], totalBeats: number) => void;
|
|
115
|
-
/** Callback when check-in completes */
|
|
250
|
+
/** @deprecated Use onHeartbeat. Callback when check-in completes. */
|
|
116
251
|
onCheckin?: (result: CheckinResult) => void;
|
|
252
|
+
/** Callback when heartbeat completes (Phase 2) */
|
|
253
|
+
onHeartbeat?: (result: HeartbeatResult) => void;
|
|
117
254
|
/** Callback on error */
|
|
118
255
|
onError?: (error: Error, context: string) => void;
|
|
119
256
|
/** Callback when status changes */
|
|
@@ -145,16 +282,17 @@ declare class BeatAgent {
|
|
|
145
282
|
error?: string;
|
|
146
283
|
}>;
|
|
147
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
|
+
*
|
|
148
288
|
* Compute N beats locally (VDF hash chain).
|
|
149
|
-
* This is the "heartbeat" — proof that the agent has lived
|
|
150
|
-
* through a specific window of computational time.
|
|
151
289
|
*/
|
|
152
290
|
pulse(count?: number): Beat[];
|
|
291
|
+
/** Internal beat computation — no status check. Used by both pulse() and resync(). */
|
|
292
|
+
private computeBeats;
|
|
153
293
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* "To remain on the Whitelist, an agent must periodically
|
|
157
|
-
* 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.
|
|
158
296
|
*/
|
|
159
297
|
checkin(): Promise<{
|
|
160
298
|
ok: boolean;
|
|
@@ -163,21 +301,19 @@ declare class BeatAgent {
|
|
|
163
301
|
}>;
|
|
164
302
|
/**
|
|
165
303
|
* Start the autonomous heartbeat loop.
|
|
166
|
-
*
|
|
167
|
-
*
|
|
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).
|
|
168
308
|
*/
|
|
169
|
-
startHeartbeat(): void;
|
|
309
|
+
startHeartbeat(paymentTxFn?: () => Promise<string> | string): void;
|
|
170
310
|
/**
|
|
171
|
-
* Stop the heartbeat
|
|
172
|
-
* Must call resync() when waking up.
|
|
311
|
+
* Stop the heartbeat loop.
|
|
173
312
|
*/
|
|
174
313
|
stopHeartbeat(): void;
|
|
175
314
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* "When an agent powers down, its time 'freezes.' Upon waking,
|
|
179
|
-
* it must perform a Re-Sync Challenge with the Registry to
|
|
180
|
-
* 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.
|
|
181
317
|
*/
|
|
182
318
|
resync(): Promise<{
|
|
183
319
|
ok: boolean;
|
|
@@ -189,6 +325,56 @@ declare class BeatAgent {
|
|
|
189
325
|
* Requires sufficient accumulated beats (Temporal Gestation).
|
|
190
326
|
*/
|
|
191
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;
|
|
192
378
|
/**
|
|
193
379
|
* Get this agent's full beat status from the registry.
|
|
194
380
|
*/
|
|
@@ -220,4 +406,84 @@ declare function computeBeatsLite(startHash: string, startIndex: number, count:
|
|
|
220
406
|
elapsed: number;
|
|
221
407
|
};
|
|
222
408
|
|
|
223
|
-
|
|
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 };
|