@provenonce/sdk 0.5.0 → 0.8.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 CHANGED
@@ -8,6 +8,31 @@ Agent heartbeat client for sovereign time authentication on Solana.
8
8
  npm install @provenonce/sdk
9
9
  ```
10
10
 
11
+ ## Registration
12
+
13
+ Before using the SDK, register your agent to get an API key:
14
+
15
+ ```typescript
16
+ import { register } from '@provenonce/sdk';
17
+
18
+ // Root registration (one-time)
19
+ const creds = await register('my-agent-v1', {
20
+ registryUrl: 'https://provenonce.io',
21
+ registrationSecret: process.env.REGISTRATION_SECRET, // required in production
22
+ });
23
+
24
+ console.log(creds.hash); // unique agent identity
25
+ console.log(creds.api_key); // use this for BeatAgent
26
+ console.log(creds.secret); // save — shown only once
27
+
28
+ // Child registration (requires parent credentials)
29
+ const child = await register('worker-1', {
30
+ registryUrl: 'https://provenonce.io',
31
+ parentHash: creds.hash,
32
+ parentApiKey: creds.api_key,
33
+ });
34
+ ```
35
+
11
36
  ## Quick Start
12
37
 
13
38
  ```typescript
@@ -15,7 +40,7 @@ import { BeatAgent } from '@provenonce/sdk';
15
40
 
16
41
  const agent = new BeatAgent({
17
42
  apiKey: 'pvn_...',
18
- registryUrl: 'https://provenonce.vercel.app',
43
+ registryUrl: 'https://provenonce.io',
19
44
  verbose: true,
20
45
  });
21
46
 
@@ -84,7 +109,7 @@ Python examples use the REST API directly — no Python SDK needed. See [`exampl
84
109
 
85
110
  ## Links
86
111
 
87
- - [Live prototype](https://provenonce.vercel.app)
112
+ - [Live prototype](https://provenonce.io)
88
113
  - [npm package](https://www.npmjs.com/package/@provenonce/sdk)
89
- - [API docs](https://provenonce.vercel.app/docs)
114
+ - [API docs](https://provenonce.io/docs)
90
115
  - [GitHub](https://github.com/jarekpiot/provenonce)
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.vercel.app',
15
+ * registryUrl: 'https://provenonce.io',
16
16
  * });
17
17
  *
18
18
  * await agent.init(); // Birth in Beat time
@@ -32,8 +32,148 @@ interface Beat {
32
32
  prev: string;
33
33
  timestamp: number;
34
34
  nonce?: string;
35
+ anchor_hash?: string;
35
36
  }
36
- declare function computeBeat(prevHash: string, beatIndex: number, difficulty: number, nonce?: string): Beat;
37
+ declare function computeBeat(prevHash: string, beatIndex: number, difficulty: number, nonce?: string, anchorHash?: string): Beat;
38
+ /** Result from a check-in submission */
39
+ interface CheckinResult {
40
+ ok: boolean;
41
+ total_beats: number;
42
+ beats_accepted: number;
43
+ global_beat: number;
44
+ status?: string;
45
+ beats_behind?: number;
46
+ }
47
+ /** Result from a spawn request */
48
+ interface SpawnResult {
49
+ ok: boolean;
50
+ eligible: boolean;
51
+ child_hash?: string;
52
+ progress_pct?: number;
53
+ deficit?: number;
54
+ }
55
+ /** Agent status from the registry */
56
+ interface AgentStatus {
57
+ already_initialized: boolean;
58
+ total_beats: number;
59
+ genesis_hash: string;
60
+ status: string;
61
+ genesis?: {
62
+ hash: string;
63
+ prev: string;
64
+ timestamp: number;
65
+ };
66
+ difficulty?: number;
67
+ }
68
+ /**
69
+ * Generate an Ed25519 keypair for agent wallet identity.
70
+ * Returns hex-encoded raw keys (32 bytes each).
71
+ * Uses Node.js built-in crypto — zero external dependencies.
72
+ */
73
+ declare function generateWalletKeypair(): {
74
+ publicKey: string;
75
+ secretKey: string;
76
+ };
77
+ /** Wallet info returned from root registration */
78
+ interface WalletInfo {
79
+ /** Hex-encoded 32-byte Ed25519 public key (Solana self-custody only, empty otherwise) */
80
+ public_key: string;
81
+ /** Hex-encoded 32-byte Ed25519 secret seed — SAVE THIS for future fee signing (Solana self-custody only) */
82
+ secret_key: string;
83
+ /** Solana-compatible base58 address (Solana wallets only) */
84
+ solana_address?: string;
85
+ /** The wallet address (base58 for Solana, 0x for Ethereum) */
86
+ address: string;
87
+ /** Wallet chain: 'solana' or 'ethereum' */
88
+ chain: string;
89
+ }
90
+ /** Result from registering an agent */
91
+ interface RegistrationResult {
92
+ hash: string;
93
+ api_key: string;
94
+ secret: string;
95
+ type: 'root' | 'agent';
96
+ parent: string | null;
97
+ depth: number;
98
+ name: string;
99
+ metadata?: Record<string, unknown> | null;
100
+ signature: string;
101
+ explorer_url?: string;
102
+ /** Wallet chain: 'solana', 'ethereum', or null (no wallet) */
103
+ wallet_chain?: string | null;
104
+ beat?: {
105
+ genesis_hash: string;
106
+ difficulty: number;
107
+ status: string;
108
+ };
109
+ /** Wallet info — only present for root agents with wallets */
110
+ wallet?: WalletInfo;
111
+ }
112
+ /**
113
+ * Register a new agent on the Provenonce registry.
114
+ *
115
+ * No wallet (default, single-phase):
116
+ * const creds = await register('my-agent', { registryUrl: '...' });
117
+ *
118
+ * Solana self-custody wallet (Model A, two-phase):
119
+ * const creds = await register('my-org', {
120
+ * registryUrl: '...',
121
+ * walletModel: 'self-custody',
122
+ * });
123
+ * // creds.wallet.secret_key = hex secret (SAVE THIS)
124
+ * // creds.wallet.address = base58 Solana address
125
+ *
126
+ * Solana with existing key:
127
+ * const creds = await register('my-org', {
128
+ * registryUrl: '...',
129
+ * walletSecretKey: '<hex-encoded-32-byte-seed>',
130
+ * });
131
+ *
132
+ * Ethereum bring-your-own (two-phase):
133
+ * const creds = await register('my-org', {
134
+ * registryUrl: '...',
135
+ * walletChain: 'ethereum',
136
+ * walletAddress: '0x...',
137
+ * walletSignFn: (msg) => wallet.signMessage(msg),
138
+ * });
139
+ *
140
+ * Solana operator (Model B, two-phase):
141
+ * const creds = await register('my-org', {
142
+ * registryUrl: '...',
143
+ * walletModel: 'operator',
144
+ * operatorWalletAddress: '<base58>',
145
+ * operatorSignFn: (msg) => signWithWallet(msg),
146
+ * });
147
+ *
148
+ * Child agent (no wallet):
149
+ * const creds = await register('worker-1', {
150
+ * registryUrl: '...',
151
+ * parentHash: parentCreds.hash,
152
+ * parentApiKey: parentCreds.api_key,
153
+ * });
154
+ */
155
+ declare function register(name: string, options?: {
156
+ registryUrl?: string;
157
+ parentHash?: string;
158
+ parentApiKey?: string;
159
+ registrationSecret?: string;
160
+ /** Hex-encoded 32-byte Ed25519 secret seed (bring-your-own Solana key) */
161
+ walletSecretKey?: string;
162
+ /** Wallet model: 'self-custody' (Model A) or 'operator' (Model B). Must be set explicitly to opt in. */
163
+ walletModel?: 'self-custody' | 'operator';
164
+ /** Wallet chain: 'solana' (default when wallet is used) or 'ethereum' (D-63) */
165
+ walletChain?: 'solana' | 'ethereum';
166
+ /** Wallet address for Ethereum bring-your-own (0x + 40 hex chars) */
167
+ walletAddress?: string;
168
+ /** Async function to sign a message with an Ethereum wallet (EIP-191 personal_sign). Returns 0x-prefixed 65-byte hex sig. */
169
+ walletSignFn?: (message: string) => Promise<string>;
170
+ /** Operator's Solana wallet address (base58). Required when walletModel='operator'. */
171
+ operatorWalletAddress?: string;
172
+ /** Function to sign a message with the operator's Solana wallet. Required when walletModel='operator'. */
173
+ operatorSignFn?: (message: string) => Promise<string>;
174
+ /** Optional agent metadata (arbitrary JSON object, max 4KB). Returned in /verify and /status. */
175
+ metadata?: Record<string, unknown>;
176
+ }): Promise<RegistrationResult>;
37
177
  interface BeatAgentConfig {
38
178
  /** API key from registration (pvn_...) */
39
179
  apiKey: string;
@@ -46,11 +186,11 @@ interface BeatAgentConfig {
46
186
  /** Callback when heartbeat ticks */
47
187
  onPulse?: (beats: Beat[], totalBeats: number) => void;
48
188
  /** Callback when check-in completes */
49
- onCheckin?: (result: any) => void;
189
+ onCheckin?: (result: CheckinResult) => void;
50
190
  /** Callback on error */
51
191
  onError?: (error: Error, context: string) => void;
52
192
  /** Callback when status changes */
53
- onStatusChange?: (status: string, details: any) => void;
193
+ onStatusChange?: (status: string, details: Record<string, unknown>) => void;
54
194
  /** Enable verbose logging */
55
195
  verbose?: boolean;
56
196
  }
@@ -65,6 +205,7 @@ declare class BeatAgent {
65
205
  private status;
66
206
  private heartbeatInterval;
67
207
  private globalBeat;
208
+ private globalAnchorHash;
68
209
  constructor(config: BeatAgentConfig);
69
210
  /**
70
211
  * Initialize the agent's Beat chain.
@@ -82,6 +223,8 @@ declare class BeatAgent {
82
223
  * through a specific window of computational time.
83
224
  */
84
225
  pulse(count?: number): Beat[];
226
+ /** Internal beat computation — no status check. Used by both pulse() and resync(). */
227
+ private computeBeats;
85
228
  /**
86
229
  * Submit a Beat proof to the registry.
87
230
  *
@@ -120,11 +263,11 @@ declare class BeatAgent {
120
263
  * Request to spawn a child agent.
121
264
  * Requires sufficient accumulated beats (Temporal Gestation).
122
265
  */
123
- requestSpawn(childName?: string, childHash?: string): Promise<any>;
266
+ requestSpawn(childName?: string, childHash?: string): Promise<SpawnResult>;
124
267
  /**
125
268
  * Get this agent's full beat status from the registry.
126
269
  */
127
- getStatus(): Promise<any>;
270
+ getStatus(): Promise<AgentStatus>;
128
271
  /**
129
272
  * Get local state (no network call).
130
273
  */
@@ -147,9 +290,9 @@ declare class BeatAgent {
147
290
  * Compute N sequential VDF beats.
148
291
  * Returns only the last beat (for lightweight usage).
149
292
  */
150
- declare function computeBeatsLite(startHash: string, startIndex: number, count: number, difficulty?: number): {
293
+ declare function computeBeatsLite(startHash: string, startIndex: number, count: number, difficulty?: number, anchorHash?: string): {
151
294
  lastBeat: Beat;
152
295
  elapsed: number;
153
296
  };
154
297
 
155
- export { type Beat, BeatAgent, type BeatAgentConfig, computeBeat, computeBeatsLite };
298
+ export { type AgentStatus, type Beat, BeatAgent, type BeatAgentConfig, type CheckinResult, type RegistrationResult, type SpawnResult, type WalletInfo, computeBeat, computeBeatsLite, generateWalletKeypair, register };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * const agent = new BeatAgent({
14
14
  * apiKey: 'pvn_...',
15
- * registryUrl: 'https://provenonce.vercel.app',
15
+ * registryUrl: 'https://provenonce.io',
16
16
  * });
17
17
  *
18
18
  * await agent.init(); // Birth in Beat time
@@ -32,8 +32,148 @@ interface Beat {
32
32
  prev: string;
33
33
  timestamp: number;
34
34
  nonce?: string;
35
+ anchor_hash?: string;
35
36
  }
36
- declare function computeBeat(prevHash: string, beatIndex: number, difficulty: number, nonce?: string): Beat;
37
+ declare function computeBeat(prevHash: string, beatIndex: number, difficulty: number, nonce?: string, anchorHash?: string): Beat;
38
+ /** Result from a check-in submission */
39
+ interface CheckinResult {
40
+ ok: boolean;
41
+ total_beats: number;
42
+ beats_accepted: number;
43
+ global_beat: number;
44
+ status?: string;
45
+ beats_behind?: number;
46
+ }
47
+ /** Result from a spawn request */
48
+ interface SpawnResult {
49
+ ok: boolean;
50
+ eligible: boolean;
51
+ child_hash?: string;
52
+ progress_pct?: number;
53
+ deficit?: number;
54
+ }
55
+ /** Agent status from the registry */
56
+ interface AgentStatus {
57
+ already_initialized: boolean;
58
+ total_beats: number;
59
+ genesis_hash: string;
60
+ status: string;
61
+ genesis?: {
62
+ hash: string;
63
+ prev: string;
64
+ timestamp: number;
65
+ };
66
+ difficulty?: number;
67
+ }
68
+ /**
69
+ * Generate an Ed25519 keypair for agent wallet identity.
70
+ * Returns hex-encoded raw keys (32 bytes each).
71
+ * Uses Node.js built-in crypto — zero external dependencies.
72
+ */
73
+ declare function generateWalletKeypair(): {
74
+ publicKey: string;
75
+ secretKey: string;
76
+ };
77
+ /** Wallet info returned from root registration */
78
+ interface WalletInfo {
79
+ /** Hex-encoded 32-byte Ed25519 public key (Solana self-custody only, empty otherwise) */
80
+ public_key: string;
81
+ /** Hex-encoded 32-byte Ed25519 secret seed — SAVE THIS for future fee signing (Solana self-custody only) */
82
+ secret_key: string;
83
+ /** Solana-compatible base58 address (Solana wallets only) */
84
+ solana_address?: string;
85
+ /** The wallet address (base58 for Solana, 0x for Ethereum) */
86
+ address: string;
87
+ /** Wallet chain: 'solana' or 'ethereum' */
88
+ chain: string;
89
+ }
90
+ /** Result from registering an agent */
91
+ interface RegistrationResult {
92
+ hash: string;
93
+ api_key: string;
94
+ secret: string;
95
+ type: 'root' | 'agent';
96
+ parent: string | null;
97
+ depth: number;
98
+ name: string;
99
+ metadata?: Record<string, unknown> | null;
100
+ signature: string;
101
+ explorer_url?: string;
102
+ /** Wallet chain: 'solana', 'ethereum', or null (no wallet) */
103
+ wallet_chain?: string | null;
104
+ beat?: {
105
+ genesis_hash: string;
106
+ difficulty: number;
107
+ status: string;
108
+ };
109
+ /** Wallet info — only present for root agents with wallets */
110
+ wallet?: WalletInfo;
111
+ }
112
+ /**
113
+ * Register a new agent on the Provenonce registry.
114
+ *
115
+ * No wallet (default, single-phase):
116
+ * const creds = await register('my-agent', { registryUrl: '...' });
117
+ *
118
+ * Solana self-custody wallet (Model A, two-phase):
119
+ * const creds = await register('my-org', {
120
+ * registryUrl: '...',
121
+ * walletModel: 'self-custody',
122
+ * });
123
+ * // creds.wallet.secret_key = hex secret (SAVE THIS)
124
+ * // creds.wallet.address = base58 Solana address
125
+ *
126
+ * Solana with existing key:
127
+ * const creds = await register('my-org', {
128
+ * registryUrl: '...',
129
+ * walletSecretKey: '<hex-encoded-32-byte-seed>',
130
+ * });
131
+ *
132
+ * Ethereum bring-your-own (two-phase):
133
+ * const creds = await register('my-org', {
134
+ * registryUrl: '...',
135
+ * walletChain: 'ethereum',
136
+ * walletAddress: '0x...',
137
+ * walletSignFn: (msg) => wallet.signMessage(msg),
138
+ * });
139
+ *
140
+ * Solana operator (Model B, two-phase):
141
+ * const creds = await register('my-org', {
142
+ * registryUrl: '...',
143
+ * walletModel: 'operator',
144
+ * operatorWalletAddress: '<base58>',
145
+ * operatorSignFn: (msg) => signWithWallet(msg),
146
+ * });
147
+ *
148
+ * Child agent (no wallet):
149
+ * const creds = await register('worker-1', {
150
+ * registryUrl: '...',
151
+ * parentHash: parentCreds.hash,
152
+ * parentApiKey: parentCreds.api_key,
153
+ * });
154
+ */
155
+ declare function register(name: string, options?: {
156
+ registryUrl?: string;
157
+ parentHash?: string;
158
+ parentApiKey?: string;
159
+ registrationSecret?: string;
160
+ /** Hex-encoded 32-byte Ed25519 secret seed (bring-your-own Solana key) */
161
+ walletSecretKey?: string;
162
+ /** Wallet model: 'self-custody' (Model A) or 'operator' (Model B). Must be set explicitly to opt in. */
163
+ walletModel?: 'self-custody' | 'operator';
164
+ /** Wallet chain: 'solana' (default when wallet is used) or 'ethereum' (D-63) */
165
+ walletChain?: 'solana' | 'ethereum';
166
+ /** Wallet address for Ethereum bring-your-own (0x + 40 hex chars) */
167
+ walletAddress?: string;
168
+ /** Async function to sign a message with an Ethereum wallet (EIP-191 personal_sign). Returns 0x-prefixed 65-byte hex sig. */
169
+ walletSignFn?: (message: string) => Promise<string>;
170
+ /** Operator's Solana wallet address (base58). Required when walletModel='operator'. */
171
+ operatorWalletAddress?: string;
172
+ /** Function to sign a message with the operator's Solana wallet. Required when walletModel='operator'. */
173
+ operatorSignFn?: (message: string) => Promise<string>;
174
+ /** Optional agent metadata (arbitrary JSON object, max 4KB). Returned in /verify and /status. */
175
+ metadata?: Record<string, unknown>;
176
+ }): Promise<RegistrationResult>;
37
177
  interface BeatAgentConfig {
38
178
  /** API key from registration (pvn_...) */
39
179
  apiKey: string;
@@ -46,11 +186,11 @@ interface BeatAgentConfig {
46
186
  /** Callback when heartbeat ticks */
47
187
  onPulse?: (beats: Beat[], totalBeats: number) => void;
48
188
  /** Callback when check-in completes */
49
- onCheckin?: (result: any) => void;
189
+ onCheckin?: (result: CheckinResult) => void;
50
190
  /** Callback on error */
51
191
  onError?: (error: Error, context: string) => void;
52
192
  /** Callback when status changes */
53
- onStatusChange?: (status: string, details: any) => void;
193
+ onStatusChange?: (status: string, details: Record<string, unknown>) => void;
54
194
  /** Enable verbose logging */
55
195
  verbose?: boolean;
56
196
  }
@@ -65,6 +205,7 @@ declare class BeatAgent {
65
205
  private status;
66
206
  private heartbeatInterval;
67
207
  private globalBeat;
208
+ private globalAnchorHash;
68
209
  constructor(config: BeatAgentConfig);
69
210
  /**
70
211
  * Initialize the agent's Beat chain.
@@ -82,6 +223,8 @@ declare class BeatAgent {
82
223
  * through a specific window of computational time.
83
224
  */
84
225
  pulse(count?: number): Beat[];
226
+ /** Internal beat computation — no status check. Used by both pulse() and resync(). */
227
+ private computeBeats;
85
228
  /**
86
229
  * Submit a Beat proof to the registry.
87
230
  *
@@ -120,11 +263,11 @@ declare class BeatAgent {
120
263
  * Request to spawn a child agent.
121
264
  * Requires sufficient accumulated beats (Temporal Gestation).
122
265
  */
123
- requestSpawn(childName?: string, childHash?: string): Promise<any>;
266
+ requestSpawn(childName?: string, childHash?: string): Promise<SpawnResult>;
124
267
  /**
125
268
  * Get this agent's full beat status from the registry.
126
269
  */
127
- getStatus(): Promise<any>;
270
+ getStatus(): Promise<AgentStatus>;
128
271
  /**
129
272
  * Get local state (no network call).
130
273
  */
@@ -147,9 +290,9 @@ declare class BeatAgent {
147
290
  * Compute N sequential VDF beats.
148
291
  * Returns only the last beat (for lightweight usage).
149
292
  */
150
- declare function computeBeatsLite(startHash: string, startIndex: number, count: number, difficulty?: number): {
293
+ declare function computeBeatsLite(startHash: string, startIndex: number, count: number, difficulty?: number, anchorHash?: string): {
151
294
  lastBeat: Beat;
152
295
  elapsed: number;
153
296
  };
154
297
 
155
- export { type Beat, BeatAgent, type BeatAgentConfig, computeBeat, computeBeatsLite };
298
+ export { type AgentStatus, type Beat, BeatAgent, type BeatAgentConfig, type CheckinResult, type RegistrationResult, type SpawnResult, type WalletInfo, computeBeat, computeBeatsLite, generateWalletKeypair, register };