notaryos 2.0.0 → 2.1.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
@@ -17,27 +17,7 @@
17
17
  *
18
18
  * @packageDocumentation
19
19
  */
20
- declare const SDK_VERSION = "2.0.0";
21
- /** Standardized error codes mirroring the backend API. */
22
- declare const NotaryErrorCode: {
23
- readonly ERR_RECEIPT_NOT_FOUND: "ERR_RECEIPT_NOT_FOUND";
24
- readonly ERR_INVALID_SIGNATURE: "ERR_INVALID_SIGNATURE";
25
- readonly ERR_INVALID_STRUCTURE: "ERR_INVALID_STRUCTURE";
26
- readonly ERR_INVALID_TIMESTAMP: "ERR_INVALID_TIMESTAMP";
27
- readonly ERR_UNKNOWN_SIGNER: "ERR_UNKNOWN_SIGNER";
28
- readonly ERR_UNSUPPORTED_ALGORITHM: "ERR_UNSUPPORTED_ALGORITHM";
29
- readonly ERR_CHAIN_BROKEN: "ERR_CHAIN_BROKEN";
30
- readonly ERR_CHAIN_MISSING: "ERR_CHAIN_MISSING";
31
- readonly ERR_PAYLOAD_TOO_LARGE: "ERR_PAYLOAD_TOO_LARGE";
32
- readonly ERR_RATE_LIMIT_EXCEEDED: "ERR_RATE_LIMIT_EXCEEDED";
33
- readonly ERR_INVALID_API_KEY: "ERR_INVALID_API_KEY";
34
- readonly ERR_INSUFFICIENT_SCOPE: "ERR_INSUFFICIENT_SCOPE";
35
- readonly ERR_VALIDATION_FAILED: "ERR_VALIDATION_FAILED";
36
- readonly ERR_INTERNAL_ERROR: "ERR_INTERNAL_ERROR";
37
- readonly ERR_DATABASE_ERROR: "ERR_DATABASE_ERROR";
38
- readonly ERR_SIGNING_ERROR: "ERR_SIGNING_ERROR";
39
- };
40
- type NotaryErrorCodeType = (typeof NotaryErrorCode)[keyof typeof NotaryErrorCode];
20
+ declare const SDK_VERSION = "2.1.0";
41
21
  /** Client configuration options. */
42
22
  interface NotaryConfig {
43
23
  /** Your Notary API key (notary_live_xxx or notary_test_xxx). */
@@ -93,13 +73,6 @@ interface PublicKeyInfo {
93
73
  public_key_pem: string;
94
74
  verification_note: string;
95
75
  }
96
- /** Result of a receipt lookup by hash. */
97
- interface LookupResult {
98
- found: boolean;
99
- receipt: Receipt | null;
100
- verification: VerificationResult | null;
101
- meta: Record<string, unknown> | null;
102
- }
103
76
  /** Authenticated agent information. */
104
77
  interface AgentInfo {
105
78
  agent_id: string;
@@ -115,46 +88,16 @@ interface IssueOptions {
115
88
  /** Additional metadata. */
116
89
  metadata?: Record<string, unknown>;
117
90
  }
118
- /** Paginated history result. */
119
- interface HistoryResult {
120
- items: Record<string, unknown>[];
121
- total: number;
122
- totalPages: number;
123
- page: number;
124
- pageSize: number;
125
- }
126
- /** Options for history queries. */
127
- interface HistoryOptions {
128
- page?: number;
129
- pageSize?: number;
130
- status?: string;
131
- search?: string;
132
- startDate?: string;
133
- endDate?: string;
134
- clerkToken?: string;
135
- }
136
- /** Counterfactual issue options. */
137
- interface CounterfactualIssueOptions {
138
- actionNotTaken: string;
139
- capabilityProof: Record<string, unknown>;
140
- opportunityContext: Record<string, unknown>;
141
- decisionReason: string;
142
- declinationReason?: string;
143
- provenanceRefs?: string[];
144
- validityWindowMinutes?: number;
145
- }
146
- /** Counterfactual commit options (v2 commit-reveal). */
147
- interface CounterfactualCommitOptions extends CounterfactualIssueOptions {
148
- minRevealDelaySeconds?: number;
149
- maxRevealWindowSeconds?: number;
150
- }
151
- /** Auto-receipt configuration. */
152
- interface AutoReceiptConfig {
153
- mode?: 'all' | 'errors_only' | 'sample';
154
- sampleRate?: number;
155
- fireAndForget?: boolean;
156
- maxPayloadBytes?: number;
157
- dryRun?: boolean;
91
+ /** Object-form argument for issue()/seal(). */
92
+ interface IssueRequest {
93
+ /** Type of action (e.g., "data_processing", "api_call"). */
94
+ actionType: string;
95
+ /** Action payload to be receipted. */
96
+ payload: Record<string, unknown>;
97
+ /** Hash of previous receipt for chaining. */
98
+ previousReceiptHash?: string;
99
+ /** Additional metadata. */
100
+ metadata?: Record<string, unknown>;
158
101
  }
159
102
  /** Base error for all NotaryOS SDK errors. */
160
103
  declare class NotaryError extends Error {
@@ -176,41 +119,6 @@ declare class RateLimitError extends NotaryError {
176
119
  declare class ValidationError extends NotaryError {
177
120
  constructor(message: string, details?: Record<string, unknown>);
178
121
  }
179
- /**
180
- * Sub-client for counterfactual receipt operations (proof of non-action).
181
- *
182
- * @example
183
- * ```typescript
184
- * const stamp = await notary.counterfactual.issue({
185
- * actionNotTaken: 'delete_user_data',
186
- * capabilityProof: { scope: 'data:delete', granted: true },
187
- * opportunityContext: { user_id: 'u_123' },
188
- * decisionReason: 'GDPR retention period not yet expired',
189
- * });
190
- * ```
191
- */
192
- declare class CounterfactualClient {
193
- private client;
194
- constructor(client: NotaryClient);
195
- /** Issue a v1 counterfactual receipt (proof of non-action). */
196
- issue(options: CounterfactualIssueOptions): Promise<Record<string, unknown>>;
197
- /** Retrieve/verify a counterfactual receipt by hash (public). */
198
- get(receiptHash: string): Promise<Record<string, unknown>>;
199
- /** List counterfactual receipts for a specific agent (public). */
200
- listByAgent(agentId: string, limit?: number, offset?: number): Promise<Record<string, unknown>>;
201
- /** Commit a v2 counterfactual receipt (Phase 1 of commit-reveal). */
202
- commit(options: CounterfactualCommitOptions): Promise<Record<string, unknown>>;
203
- /** Reveal a committed counterfactual receipt (Phase 2). */
204
- reveal(receiptHash: string, decisionReasonPlaintext: string): Promise<Record<string, unknown>>;
205
- /** Check commit-reveal lifecycle status (public). */
206
- commitStatus(receiptHash: string): Promise<Record<string, unknown>>;
207
- /** Counter-sign a counterfactual receipt (corroboration). */
208
- corroborate(receiptHash: string, signals: string[]): Promise<Record<string, unknown>>;
209
- /** Generate a compliance certificate for a counterfactual receipt (public). */
210
- certificate(receiptHash: string, format?: string): Promise<Record<string, unknown>>;
211
- /** Verify counterfactual chain continuity for an agent (public). */
212
- verifyChain(agentId: string): Promise<Record<string, unknown>>;
213
- }
214
122
  /**
215
123
  * NotaryOS API client.
216
124
  *
@@ -225,11 +133,8 @@ declare class CounterfactualClient {
225
133
  * const result = await notary.verify(receipt);
226
134
  * console.log(result.valid); // true
227
135
  *
228
- * // Counterfactual receipts
229
- * const stamp = await notary.counterfactual.issue({ ... });
230
- *
231
- * // Auto-receipt wrapping
232
- * const agent = notary.wrap(myAgent, { mode: 'all' });
136
+ * // Check service health
137
+ * const status = await notary.status();
233
138
  * ```
234
139
  */
235
140
  declare class NotaryClient {
@@ -237,78 +142,88 @@ declare class NotaryClient {
237
142
  private baseUrl;
238
143
  private timeout;
239
144
  private maxRetries;
240
- private _counterfactual?;
241
145
  static readonly DEFAULT_BASE_URL = "https://api.agenttownsquare.com";
242
146
  static readonly DEFAULT_TIMEOUT = 30000;
243
147
  constructor(config: NotaryConfig);
244
- /** Access counterfactual receipt operations (enterprise premium). */
245
- get counterfactual(): CounterfactualClient;
246
148
  private request;
247
- /** Public GET helper (no API key in headers). */
248
- private publicGet;
249
149
  private sleep;
250
150
  /**
251
151
  * Issue a signed receipt for an action.
252
152
  *
253
- * @param actionType - Type of action (e.g., "data_processing", "api_call")
254
- * @param payload - Action payload to be receipted
255
- * @param options - Optional chaining and metadata
256
- * @returns A signed Receipt
257
- */
258
- issue(actionType: string, payload: Record<string, unknown>, options?: IssueOptions): Promise<Receipt>;
259
- /** Verify a receipt's signature and integrity. */
260
- verify(receipt: Receipt | Record<string, unknown>): Promise<VerificationResult>;
261
- /** Verify a receipt by its ID (server-side lookup). */
262
- verifyById(receiptId: string): Promise<VerificationResult>;
263
- /** Get Notary service status. */
264
- status(): Promise<ServiceStatus>;
265
- /** Get the public key for offline verification. */
266
- publicKey(): Promise<PublicKeyInfo>;
267
- /** Get authenticated agent info. */
268
- me(): Promise<AgentInfo>;
269
- /** Look up a receipt by hash (public endpoint). */
270
- lookup(receiptHash: string): Promise<LookupResult>;
271
- /**
272
- * Get paginated receipt history (requires Clerk JWT).
153
+ * Supports two calling conventions:
154
+ * - `issue('action_type', { key: 'value' })` positional args
155
+ * - `issue({ actionType: 'action_type', payload: { key: 'value' } })` — object form
273
156
  *
274
- * @param options - Pagination, filters, and Clerk token
275
- * @returns Paginated history with items, total, totalPages
276
- */
277
- history(options?: HistoryOptions): Promise<HistoryResult>;
278
- /**
279
- * Get the provenance DAG report for a receipt (public).
157
+ * @example
158
+ * ```typescript
159
+ * // Positional (recommended)
160
+ * const receipt = await notary.issue('transfer', { amount: 100 });
280
161
  *
281
- * @param receiptHash - The receipt hash to check
282
- * @returns Provenance report with grounding status, ancestors, paths
162
+ * // Object form
163
+ * const receipt = await notary.issue({ actionType: 'transfer', payload: { amount: 100 } });
164
+ * ```
283
165
  */
284
- provenance(receiptHash: string): Promise<Record<string, unknown>>;
166
+ issue(actionTypeOrRequest: string | IssueRequest, payload?: Record<string, unknown>, options?: IssueOptions): Promise<Receipt>;
167
+ /** Alias: seal() → issue() for the 3-line integration pattern. */
168
+ seal: (actionTypeOrRequest: string | IssueRequest, payload?: Record<string, unknown>, options?: IssueOptions) => Promise<Receipt>;
285
169
  /**
286
- * Wrap an object so method calls are automatically receipted.
170
+ * Verify a receipt's signature and integrity.
287
171
  *
288
- * Uses ES6 Proxy to intercept method calls. Receipts are issued
289
- * in the background via fire-and-forget (won't slow down your agent).
172
+ * @param receipt - Receipt object or raw receipt dict
173
+ * @returns VerificationResult with validity details
290
174
  *
291
- * @param obj - The agent or object to wrap
292
- * @param config - Optional auto-receipt configuration
293
- * @returns A proxied version of the object
175
+ * @example
176
+ * ```typescript
177
+ * const result = await notary.verify(receipt);
178
+ * if (result.valid) {
179
+ * console.log('Receipt is authentic');
180
+ * }
181
+ * ```
182
+ */
183
+ verify(receipt: Receipt | Record<string, unknown>): Promise<VerificationResult>;
184
+ /** Verify a receipt by its ID (server-side lookup). */
185
+ verifyById(receiptId: string): Promise<VerificationResult>;
186
+ /**
187
+ * Get Notary service status.
294
188
  *
295
189
  * @example
296
190
  * ```typescript
297
- * const agent = notary.wrap(myAgent, { mode: 'all', fireAndForget: true });
298
- * await agent.processData(input); // auto-receipted!
191
+ * const status = await notary.status();
192
+ * console.log(status.status); // "active"
299
193
  * ```
300
194
  */
301
- wrap<T extends object>(obj: T, config?: AutoReceiptConfig): T;
195
+ status(): Promise<ServiceStatus>;
196
+ /** Get the public key for offline verification. */
197
+ publicKey(): Promise<PublicKeyInfo>;
198
+ /** Get authenticated agent info. */
199
+ me(): Promise<AgentInfo>;
302
200
  }
303
201
  /**
304
202
  * Quick receipt verification without API key.
203
+ *
305
204
  * Uses the public /verify endpoint — no authentication needed.
205
+ *
206
+ * @param receipt - Receipt JSON object
207
+ * @param baseUrl - API base URL (default: production)
208
+ * @returns true if the receipt is valid
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * import { verifyReceipt } from 'notaryos';
213
+ *
214
+ * const isValid = await verifyReceipt(receiptJson);
215
+ * console.log(isValid); // true
216
+ * ```
306
217
  */
307
218
  declare function verifyReceipt(receipt: Record<string, unknown>, baseUrl?: string): Promise<boolean>;
308
219
  /**
309
220
  * Compute SHA-256 hash of a payload using Web Crypto API.
221
+ *
310
222
  * Matches the server-side hashing for independent verification.
223
+ *
224
+ * @param payload - String or JSON-serializable object
225
+ * @returns Hex-encoded SHA-256 digest
311
226
  */
312
227
  declare function computeHash(payload: Record<string, unknown> | string): Promise<string>;
313
228
 
314
- export { type AgentInfo, AuthenticationError, type AutoReceiptConfig, CounterfactualClient, type CounterfactualCommitOptions, type CounterfactualIssueOptions, type HistoryOptions, type HistoryResult, type IssueOptions, type LookupResult, NotaryClient, type NotaryConfig, NotaryError, NotaryErrorCode, type NotaryErrorCodeType, type PublicKeyInfo, RateLimitError, type Receipt, SDK_VERSION, type ServiceStatus, ValidationError, type VerificationResult, computeHash, verifyReceipt };
229
+ export { type AgentInfo, AuthenticationError, type IssueOptions, type IssueRequest, NotaryClient, type NotaryConfig, NotaryError, type PublicKeyInfo, RateLimitError, type Receipt, SDK_VERSION, type ServiceStatus, ValidationError, type VerificationResult, computeHash, verifyReceipt };