notaryos 2.0.0 → 2.1.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.
package/README.md CHANGED
@@ -31,111 +31,65 @@ const isValid = await verifyReceipt(receiptJson);
31
31
  // true
32
32
  ```
33
33
 
34
- ## API Reference
35
-
36
- ### `NotaryClient`
37
-
38
- | Method | Auth | Description |
39
- |--------|------|-------------|
40
- | `issue(actionType, payload, options?)` | API Key | Issue a signed receipt |
41
- | `verify(receipt)` | Public | Verify a receipt |
42
- | `verifyById(receiptId)` | API Key | Verify by receipt ID |
43
- | `status()` | Public | Service health check |
44
- | `publicKey()` | Public | Get Ed25519 public key |
45
- | `me()` | API Key | Authenticated agent info |
46
- | `lookup(receiptHash)` | Public | Look up receipt by hash |
47
- | `history(options?)` | Clerk JWT | Paginated receipt history |
48
- | `provenance(receiptHash)` | Public | Provenance DAG report |
49
- | `wrap(obj, config?)` | API Key | Auto-receipt wrapping |
50
-
51
- ### `notary.counterfactual.*`
52
-
53
- | Method | Auth | Description |
54
- |--------|------|-------------|
55
- | `issue(options)` | API Key | Issue v1 counterfactual |
56
- | `get(receiptHash)` | Public | Verify counterfactual |
57
- | `listByAgent(agentId)` | Public | List agent's counterfactuals |
58
- | `commit(options)` | API Key | v2 commit phase |
59
- | `reveal(hash, plaintext)` | API Key | v2 reveal phase |
60
- | `commitStatus(hash)` | Public | Check commit-reveal status |
61
- | `corroborate(hash, signals)` | API Key | Counter-sign |
62
- | `certificate(hash, format?)` | Public | Compliance certificate |
63
- | `verifyChain(agentId)` | Public | Chain continuity |
64
-
65
- ### Standalone Functions
66
-
67
- | Function | Description |
68
- |----------|-------------|
69
- | `verifyReceipt(receipt, baseUrl?)` | Public verification (returns boolean) |
70
- | `computeHash(payload)` | SHA-256 matching server-side hashing |
71
-
72
- ### Error Codes
34
+ ### Full Example
73
35
 
74
36
  ```typescript
75
- import { NotaryErrorCode } from 'notaryos';
76
-
77
- NotaryErrorCode.ERR_RECEIPT_NOT_FOUND // 404
78
- NotaryErrorCode.ERR_INVALID_API_KEY // 401
79
- NotaryErrorCode.ERR_RATE_LIMIT_EXCEEDED // 429
80
- NotaryErrorCode.ERR_CHAIN_BROKEN // 400
81
- // ... 16 total error codes
82
- ```
83
-
84
- ## Auto-Receipting
37
+ import { NotaryClient } from 'notaryos';
85
38
 
86
- ```typescript
87
- const agent = notary.wrap(myAgent, { mode: 'all', fireAndForget: true });
88
- await agent.processData(input); // auto-receipted!
89
- ```
39
+ const notary = new NotaryClient({ apiKey: 'notary_live_xxx' });
90
40
 
91
- Options: `mode` (`'all'` | `'errors_only'` | `'sample'`), `sampleRate`, `fireAndForget`, `dryRun`.
41
+ // Issue a receipt for an agent action
42
+ const receipt = await notary.issue('financial.transfer', {
43
+ from: 'billing-agent',
44
+ to: 'ledger-agent',
45
+ amount: 150.00,
46
+ currency: 'USD',
47
+ });
92
48
 
93
- ## Counterfactual Receipts
49
+ // Verify it
50
+ const result = await notary.verify(receipt);
51
+ console.log(result.valid); // true
52
+ console.log(result.signature_ok); // true
94
53
 
95
- ```typescript
96
- // v1: Direct issuance
97
- const stamp = await notary.counterfactual.issue({
98
- actionNotTaken: 'delete_user_data',
99
- capabilityProof: { scope: 'data:delete', granted: true },
100
- opportunityContext: { user_id: 'u_123' },
101
- decisionReason: 'GDPR retention period not yet expired',
102
- });
54
+ // Check service health
55
+ const status = await notary.status();
56
+ console.log(status.status); // "active"
103
57
 
104
- // v2: Commit-reveal
105
- const commit = await notary.counterfactual.commit({ ...options });
106
- const reveal = await notary.counterfactual.reveal(hash, plaintext);
58
+ // Get public key for offline verification
59
+ const keyInfo = await notary.publicKey();
60
+ console.log(keyInfo.public_key_pem);
107
61
  ```
108
62
 
109
- ## Offline Verification
110
-
111
- ```typescript
112
- import { OfflineVerifier } from 'notaryos/offline';
63
+ ## API Reference
113
64
 
114
- const verifier = await OfflineVerifier.fromJWKS();
115
- const result = await verifier.verify(receipt);
116
- console.log(result.valid); // true — no API call needed
117
- ```
65
+ ### `NotaryClient`
118
66
 
119
- ## Framework Integrations
67
+ | Method | Auth | Description |
68
+ |--------|------|-------------|
69
+ | `issue(actionType, payload, options?)` | API Key | Issue a signed receipt |
70
+ | `verify(receipt)` | API Key | Verify a receipt |
71
+ | `verifyById(receiptId)` | API Key | Verify by receipt ID |
72
+ | `status()` | API Key | Service health check |
73
+ | `publicKey()` | API Key | Get Ed25519 public key |
74
+ | `me()` | API Key | Authenticated agent info |
120
75
 
121
- ### Vercel AI SDK
76
+ ### `verifyReceipt(receipt, baseUrl?)`
122
77
 
123
- ```typescript
124
- import { notaryMiddleware } from 'notaryos/integrations/vercel-ai';
125
- ```
78
+ Public verification without API key. Returns `boolean`.
126
79
 
127
- ### LangChain.js
80
+ ### `computeHash(payload)`
128
81
 
129
- ```typescript
130
- import { NotaryCallbackHandler } from 'notaryos/integrations/langchain';
131
- const handler = new NotaryCallbackHandler(notary);
132
- ```
82
+ SHA-256 hash matching server-side computation. Returns hex string.
133
83
 
134
- ### OpenAI Agents
84
+ ## Configuration
135
85
 
136
86
  ```typescript
137
- import { notaryToolWrapper } from 'notaryos/integrations/openai-agents';
138
- const wrappedTool = notaryToolWrapper(notary, myToolFn, 'my_tool');
87
+ const notary = new NotaryClient({
88
+ apiKey: 'notary_live_xxx', // Required
89
+ baseUrl: 'https://...', // Default: https://api.agenttownsquare.com
90
+ timeout: 30_000, // Default: 30s
91
+ maxRetries: 2, // Default: 2
92
+ });
139
93
  ```
140
94
 
141
95
  ## Error Handling
@@ -156,17 +110,18 @@ try {
156
110
  }
157
111
  ```
158
112
 
159
- ## Configuration
113
+ ## Get an API Key
160
114
 
161
- ```typescript
162
- const notary = new NotaryClient({
163
- apiKey: 'notary_live_xxx', // Required
164
- baseUrl: 'https://...', // Default: https://api.agenttownsquare.com
165
- timeout: 30_000, // Default: 30s
166
- maxRetries: 2, // Default: 2
167
- });
168
- ```
115
+ 1. Sign up at [agenttownsquare.com/notary](https://agenttownsquare.com/notary)
116
+ 2. Generate an API key from the dashboard
117
+ 3. Keys start with `notary_live_` (production) or `notary_test_` (sandbox)
118
+
119
+ ## Links
120
+
121
+ - [NotaryOS Documentation](https://agenttownsquare.com/notary)
122
+ - [API Reference](https://api.agenttownsquare.com/v1/notary/status)
123
+ - [Public Verification](https://api.agenttownsquare.com/v1/notary/r/{hash})
169
124
 
170
125
  ## License
171
126
 
172
- BUSL-1.1
127
+ MIT
package/dist/index.d.mts 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.1";
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 };