@qed-proof/sdk 0.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.
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Typed helpers for the five live actions plus `http.url.status`, matching the wire shape the
3
+ * node's verifiers expect (`oss/spec/profiles/*.md`, `oss/node/src/poaw_node/verifiers/*.py`).
4
+ * Validation here is cheap and local — it never calls the network — but it fails fast with a
5
+ * clear message before the claim is submitted, since params are copied into public receipts.
6
+ */
7
+ interface ClaimAction {
8
+ action: string;
9
+ target: string;
10
+ params: Record<string, unknown>;
11
+ }
12
+ declare function githubCommitPush(input: {
13
+ target: string;
14
+ sha: string;
15
+ branch: string;
16
+ }): ClaimAction;
17
+ declare function githubPrOpen(input: {
18
+ target: string;
19
+ number: number;
20
+ base?: string;
21
+ headSha?: string;
22
+ }): ClaimAction;
23
+ declare function githubChecksPass(input: {
24
+ target: string;
25
+ sha: string;
26
+ }): ClaimAction;
27
+ declare function xPostPublish(input: {
28
+ target: string;
29
+ postId: string;
30
+ textSha256?: string;
31
+ }): ClaimAction;
32
+ declare function slackMessagePost(input: {
33
+ target: string;
34
+ ts: string;
35
+ textSha256?: string;
36
+ }): ClaimAction;
37
+ declare function httpUrlStatus(input: {
38
+ target: string;
39
+ status?: number;
40
+ contentFingerprint?: string;
41
+ }): ClaimAction;
42
+
43
+ type actions_ClaimAction = ClaimAction;
44
+ declare const actions_githubChecksPass: typeof githubChecksPass;
45
+ declare const actions_githubCommitPush: typeof githubCommitPush;
46
+ declare const actions_githubPrOpen: typeof githubPrOpen;
47
+ declare const actions_httpUrlStatus: typeof httpUrlStatus;
48
+ declare const actions_slackMessagePost: typeof slackMessagePost;
49
+ declare const actions_xPostPublish: typeof xPostPublish;
50
+ declare namespace actions {
51
+ export { type actions_ClaimAction as ClaimAction, actions_githubChecksPass as githubChecksPass, actions_githubCommitPush as githubCommitPush, actions_githubPrOpen as githubPrOpen, actions_httpUrlStatus as httpUrlStatus, actions_slackMessagePost as slackMessagePost, actions_xPostPublish as xPostPublish };
52
+ }
53
+
54
+ interface Proof$1 {
55
+ log_id: string;
56
+ leaf_index: number;
57
+ tree_size: number;
58
+ root_hash: string;
59
+ inclusion: string[];
60
+ anchor?: {
61
+ chain: string;
62
+ scheme: string;
63
+ uid: string;
64
+ tx_hash: string;
65
+ tree_size: number;
66
+ };
67
+ }
68
+ interface Keyset {
69
+ keys?: Array<{
70
+ key_id: string;
71
+ public_key: string;
72
+ valid_from: string;
73
+ revoked_at: string | null;
74
+ }>;
75
+ anchor_addresses?: string[];
76
+ anchor_schemas?: string[];
77
+ }
78
+ interface AnchorResult {
79
+ ok: boolean;
80
+ reason: string;
81
+ proven_by: number | null;
82
+ }
83
+
84
+ interface VerifyChecks {
85
+ spec_version: boolean;
86
+ schema: boolean;
87
+ integers_only: boolean;
88
+ key: boolean;
89
+ signature: boolean;
90
+ claim_digest: boolean;
91
+ inclusion: boolean | "absent";
92
+ anchor: boolean | "absent" | "not_checked_offline" | string;
93
+ }
94
+ interface VerifyReport {
95
+ checks: VerifyChecks;
96
+ valid: boolean;
97
+ verdict: string | null;
98
+ achieved_trust_level: number;
99
+ proven_by?: number | null;
100
+ }
101
+ interface VerifyOptions {
102
+ keys: Keyset;
103
+ rpcUrl?: string;
104
+ }
105
+ declare function verifyReceipt(receipt: unknown | string, options: VerifyOptions): Promise<VerifyReport>;
106
+
107
+ /**
108
+ * The HTTP client. Shapes follow `oss/node/src/poaw_node/app.py`, `models.py` (`ClaimIn`) and
109
+ * `store.py` (`claim_status`). Uses only `fetch` — no Node built-ins — so it runs on Node, Deno
110
+ * and in browsers.
111
+ */
112
+
113
+ interface QedProofOptions {
114
+ apiKey?: string;
115
+ baseUrl?: string;
116
+ fetch?: typeof fetch;
117
+ }
118
+ interface SubmitClaimOptions {
119
+ agentId: string;
120
+ clientClaimId?: string;
121
+ claimedAt?: string | Date;
122
+ }
123
+ interface ClaimStatus {
124
+ claim_id: string;
125
+ created?: boolean;
126
+ state: "queued" | "decided";
127
+ attempts: number;
128
+ receipt_id: string | null;
129
+ verdict: string | null;
130
+ }
131
+ interface WaitOptions {
132
+ timeoutMs?: number;
133
+ pollIntervalMs?: number;
134
+ }
135
+ interface Receipt {
136
+ body: Record<string, unknown>;
137
+ signature: Record<string, unknown>;
138
+ proof?: Record<string, unknown>;
139
+ [key: string]: unknown;
140
+ }
141
+ interface ClaimSummary {
142
+ claim_id: string;
143
+ state: string;
144
+ attempts: number;
145
+ receipt_id: string | null;
146
+ verdict: string | null;
147
+ }
148
+ interface ListClaimsOptions {
149
+ limit?: number;
150
+ cursor?: string;
151
+ agentId?: string;
152
+ action?: string;
153
+ verdict?: string;
154
+ state?: string;
155
+ }
156
+ interface ClaimPage {
157
+ claims: ClaimSummary[];
158
+ nextCursor: string | null;
159
+ }
160
+ declare class QedProof {
161
+ private readonly apiKey?;
162
+ private readonly baseUrl;
163
+ private readonly fetchImpl;
164
+ constructor(options?: QedProofOptions);
165
+ private request;
166
+ submitClaim(claim: ClaimAction, options: SubmitClaimOptions): Promise<ClaimStatus>;
167
+ getClaim(claimId: string): Promise<ClaimStatus>;
168
+ waitForVerdict(claimId: string, options?: WaitOptions): Promise<ClaimStatus>;
169
+ /**
170
+ * `GET /v1/claims`, newest first. `options.limit` (1-200, default 50) is validated locally —
171
+ * out of range throws a `RangeError` before any request is made.
172
+ */
173
+ listClaims(options?: ListClaimsOptions): Promise<ClaimPage>;
174
+ /** Yields every claim matching the filters, following `nextCursor` until exhausted. */
175
+ iterClaims(options?: Omit<ListClaimsOptions, "cursor" | "limit"> & {
176
+ pageSize?: number;
177
+ }): AsyncGenerator<ClaimSummary>;
178
+ /** Receipts are designed to be shared and checked by anyone (SPEC §1): no Authorization header. */
179
+ getReceipt(receiptId: string): Promise<Receipt>;
180
+ /** Public by design: `/.well-known/poaw-keys.json` (SPEC §5.2, §8.4). */
181
+ getKeys(): Promise<Keyset>;
182
+ verify(receipt: unknown | string, options?: {
183
+ keys?: Keyset;
184
+ rpcUrl?: string;
185
+ }): Promise<VerifyReport>;
186
+ }
187
+
188
+ declare class QedProofError extends Error {
189
+ status: number;
190
+ detail: string;
191
+ constructor(status: number, detail: string);
192
+ }
193
+ declare class RateLimitError extends QedProofError {
194
+ retryAfter: number | undefined;
195
+ constructor(detail: string, retryAfter: number | undefined);
196
+ }
197
+
198
+ declare const SPEC_VERSION = "poaw/0.1";
199
+ declare const SIG_DOMAIN: Uint8Array<ArrayBuffer>;
200
+ declare function b64u(data: Uint8Array): string;
201
+ declare function b64uDecode(text: string): Uint8Array;
202
+ /** RFC 8785 JCS, as UTF-8 bytes (matches Python's `rfc8785.dumps`, which returns bytes). */
203
+ declare function jcs(obj: unknown): Uint8Array;
204
+ declare function sha256(data: Uint8Array): Uint8Array;
205
+ /**
206
+ * §3: receipts carry integers only. JSON.parse collapses the int/float distinction Python's
207
+ * `json.loads` preserves (e.g. `1.0` parses to the same JS number as `1`), so this checks two
208
+ * ways:
209
+ * - `hasFloatValue`: any value that is a non-integer finite number (catches every float that
210
+ * actually matters, e.g. `0.5` in vector 014-float-in-body.json).
211
+ * - `hasFloatText`: scans the raw JSON text (outside string literals) for a numeric token
212
+ * containing `.`, `e` or `E` — the same signal Python's tokenizer used to decide `float` vs
213
+ * `int`, for callers that still have the original text (files, HTTP bodies).
214
+ * `verifyReceipt` OR's both when raw text is available, so nothing is hidden by `JSON.parse`.
215
+ */
216
+ declare function hasFloatValue(value: unknown): boolean;
217
+ declare function hasFloatText(text: string): boolean;
218
+ declare function keyId(pkRaw: Uint8Array): string;
219
+ declare function verifySignature(pkRaw: Uint8Array, body: unknown, sigValue: string): boolean;
220
+ declare function claimDigest(claim: Record<string, unknown>): string;
221
+ declare function leafHash(receipt: {
222
+ body: unknown;
223
+ signature: unknown;
224
+ }): Uint8Array;
225
+ /**
226
+ * RFC 9162 §2.1.3.2 audit-path verification. Returns the computed root, or null if the path is
227
+ * malformed. Ported line for line from `poaw_core.root_from_inclusion`.
228
+ */
229
+ declare function rootFromInclusion(index: number, size: number, leaf: Uint8Array, path: Uint8Array[]): Uint8Array | null;
230
+
231
+ /**
232
+ * This file was automatically generated by `npm run gen:types` from
233
+ * ../../../src/receipt.schema.json (the vendored PoAW receipt schema). Do not edit by hand.
234
+ */
235
+ type Timestamp = string;
236
+ type KeyId = string;
237
+ type Action = string;
238
+ type B64Url = string;
239
+ type Fingerprint = string;
240
+ type VerdictValue = "verified" | "late" | "mismatch" | "failed" | "unverifiable";
241
+ type ReasonCode = "not_found" | "content_mismatch" | "target_mismatch" | "observed_after_tolerance" | "no_connection" | "permission_denied" | "rate_limited" | "destination_unavailable" | "unsupported_action" | "claim_ambiguous" | "verifier_error";
242
+ /**
243
+ * Structural schema for a Proof of Agent Work receipt. Signature, inclusion and anchor checks are defined in SPEC.md and are not expressible in JSON Schema.
244
+ */
245
+ interface PoAWReceiptPoaw01 {
246
+ body: Body;
247
+ signature: Signature;
248
+ proof?: Proof;
249
+ }
250
+ interface Body {
251
+ spec_version: "poaw/0.1";
252
+ receipt_id: string;
253
+ issued_at: Timestamp;
254
+ issuer: {
255
+ key_id: KeyId;
256
+ name?: string;
257
+ };
258
+ agent: {
259
+ id: string;
260
+ erc8004?: {
261
+ chain: string;
262
+ registry: string;
263
+ agent_id: string;
264
+ };
265
+ };
266
+ operator?: string;
267
+ claim: {
268
+ action: Action;
269
+ target: string;
270
+ params: {};
271
+ claimed_at: Timestamp;
272
+ client_claim_id?: string;
273
+ claim_digest: B64Url;
274
+ };
275
+ observation: {
276
+ verifier: {
277
+ id: Action;
278
+ version: string;
279
+ code_hash?: Fingerprint;
280
+ };
281
+ observed_at: Timestamp;
282
+ deadline_at: Timestamp;
283
+ attempts: number;
284
+ facts: {};
285
+ };
286
+ verdict: {
287
+ value: VerdictValue;
288
+ reason_code?: ReasonCode;
289
+ };
290
+ trust_level: number;
291
+ attestation?: {
292
+ type: string;
293
+ document: B64Url;
294
+ };
295
+ supersedes?: string;
296
+ }
297
+ interface Signature {
298
+ alg: "Ed25519";
299
+ key_id: KeyId;
300
+ value: string;
301
+ }
302
+ interface Proof {
303
+ log_id: B64Url;
304
+ leaf_index: number;
305
+ tree_size: number;
306
+ root_hash: B64Url;
307
+ inclusion: B64Url[];
308
+ anchor?: {
309
+ chain: string;
310
+ scheme: "eas";
311
+ uid: string;
312
+ tx_hash: string;
313
+ tree_size: number;
314
+ };
315
+ }
316
+
317
+ export { type AnchorResult, type ClaimAction, type ClaimPage, type ClaimStatus, type ClaimSummary, type PoAWReceiptPoaw01 as GeneratedReceipt, type Keyset, type ListClaimsOptions, type Proof$1 as Proof, QedProof, QedProofError, type QedProofOptions, RateLimitError, type Receipt, SIG_DOMAIN, SPEC_VERSION, type SubmitClaimOptions, type VerifyChecks, type VerifyOptions, type VerifyReport, type WaitOptions, actions, b64u, b64uDecode, claimDigest, hasFloatText, hasFloatValue, jcs, keyId, leafHash, rootFromInclusion, sha256, verifyReceipt, verifySignature };