@atep/core 0.0.1 → 0.1.0-alpha.3

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.js ADDED
@@ -0,0 +1,374 @@
1
+ // @atep/core: TypeScript API over the Rust atep-core compiled to WebAssembly.
2
+ //
3
+ // Call `await init()` once before anything else (or `initSync(bytes)`).
4
+ import rawInit, { initSync as rawInitSync, Identity as RawIdentity, agentIdOfBundle, parseAgentId as rawParseAgentId, sha256 as rawSha256, encrypt as rawEncrypt, encryptWithRandomness, view as rawView, submittedForm, withAttestations as rawWithAttestations, withInclusionProof as rawWithInclusionProof, merkleRoot as rawMerkleRoot, auditPath as rawAuditPath, verify as rawVerify, verifyAs as rawVerifyAs, verifyCheckpoint as rawVerifyCheckpoint, verifyInclusion as rawVerifyInclusion, checkConsistency as rawCheckConsistency, checkSplitView as rawCheckSplitView, verifySrl as rawVerifySrl, chainIdKind as rawChainIdKind, parseAnchorRecord as rawParseAnchorRecord, encodeAnchorRecord as rawEncodeAnchorRecord, checkpointHash as rawCheckpointHash, checkPublishedAnchor as rawCheckPublishedAnchor, parseRequireAnchor as rawParseRequireAnchor, checkAdmission as rawCheckAdmission, checkDomainBinding as rawCheckDomainBinding, } from "./wasm/atep_wasm.js";
5
+ // ---------------------------------------------------------------------------
6
+ // Initialisation
7
+ let ready = false;
8
+ /**
9
+ * Load the wasm module. Without an argument the binary is found next to this
10
+ * file: read from disk for `file:` URLs (Node, Bun, Deno), fetched otherwise
11
+ * (browsers, bundlers that rewrite `import.meta.url`). Pass bytes, a URL or a
12
+ * `Response` to override. Safe to call more than once.
13
+ */
14
+ export async function init(source) {
15
+ if (ready)
16
+ return;
17
+ let input = source;
18
+ if (input === undefined) {
19
+ const url = new URL("./wasm/atep_wasm_bg.wasm", import.meta.url);
20
+ if (url.protocol === "file:") {
21
+ const { readFile } = await import("node:fs/promises");
22
+ input = await readFile(url);
23
+ }
24
+ else {
25
+ input = url;
26
+ }
27
+ }
28
+ if (input instanceof Uint8Array) {
29
+ rawInitSync({ module: input });
30
+ }
31
+ else {
32
+ await rawInit({ module_or_path: input });
33
+ }
34
+ ready = true;
35
+ }
36
+ /** Synchronous initialisation from wasm bytes or a compiled module. */
37
+ export function initSync(source) {
38
+ if (ready)
39
+ return;
40
+ rawInitSync({ module: source });
41
+ ready = true;
42
+ }
43
+ function need() {
44
+ if (!ready)
45
+ throw new Error("@atep/core: call `await init()` first");
46
+ }
47
+ // ---------------------------------------------------------------------------
48
+ // Helpers
49
+ export function hexToBytes(hex) {
50
+ if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex))
51
+ throw new Error("invalid hex");
52
+ const out = new Uint8Array(hex.length / 2);
53
+ for (let i = 0; i < out.length; i++)
54
+ out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
55
+ return out;
56
+ }
57
+ export function bytesToHex(b) {
58
+ let s = "";
59
+ for (const x of b)
60
+ s += x.toString(16).padStart(2, "0");
61
+ return s;
62
+ }
63
+ const hx = (v) => (typeof v === "string" ? v : bytesToHex(v));
64
+ const nowSecs = () => Math.floor(Date.now() / 1000);
65
+ function normalizePolicy(p) {
66
+ const o = { ...p };
67
+ for (const k of ["known_bundles", "seen_nonces", "attestations", "srls"]) {
68
+ const v = p[k];
69
+ if (v !== undefined)
70
+ o[k] = v.map(hx);
71
+ }
72
+ if (p.detached_payload_hex !== undefined)
73
+ o.detached_payload_hex = hx(p.detached_payload_hex);
74
+ return JSON.stringify(o);
75
+ }
76
+ function signJson(o) {
77
+ const j = {
78
+ content_type: o.contentType,
79
+ issued_at: o.issuedAt ?? nowSecs(),
80
+ expires_at: o.expiresAt ?? undefined,
81
+ detached: o.detached,
82
+ include_bundle: o.includeBundle,
83
+ nonce_hex: o.nonce && bytesToHex(o.nonce),
84
+ mode: o.deterministic ? "deterministic" : "hedged",
85
+ command_class: o.commandClass,
86
+ };
87
+ return JSON.stringify(j);
88
+ }
89
+ /**
90
+ * An agent identity. Its secret seeds live in wasm linear memory and are
91
+ * zeroized when the object is freed. Call `free()` (or use `using`) when done.
92
+ */
93
+ export class Identity {
94
+ #raw;
95
+ constructor(raw) {
96
+ this.#raw = raw;
97
+ }
98
+ /** Generate a new identity. `encryption` adds X25519 and ML-KEM-768 keys (needed to receive encrypted envelopes). */
99
+ static generate(encryption = true) {
100
+ need();
101
+ return new Identity(RawIdentity.generate(encryption));
102
+ }
103
+ /** From raw seeds (the same values the test vectors list). */
104
+ static fromSeeds(seeds) {
105
+ need();
106
+ return new Identity(RawIdentity.fromSeeds(seeds.ed25519, seeds.mldsa65, seeds.x25519 ?? null, seeds.mlkem768 ?? null));
107
+ }
108
+ /** From seeds given as hex (the format of the vector `inputs`). */
109
+ static fromSeedsHex(s) {
110
+ return Identity.fromSeeds({
111
+ ed25519: hexToBytes(s.ed25519),
112
+ mldsa65: hexToBytes(s.mldsa65),
113
+ x25519: s.x25519 ? hexToBytes(s.x25519) : undefined,
114
+ mlkem768: s.mlkem768 ? hexToBytes(s.mlkem768) : undefined,
115
+ });
116
+ }
117
+ /** From the CBOR secret key file written by `exportSecret` or the Rust CLI. */
118
+ static fromSecret(secret) {
119
+ need();
120
+ return new Identity(RawIdentity.fromSecret(secret));
121
+ }
122
+ /** The secret key file. The returned array holds secrets: `fill(0)` it when done. */
123
+ exportSecret() {
124
+ return this.#raw.exportSecret();
125
+ }
126
+ /** Agent ID, `atep:...`. */
127
+ get agentId() {
128
+ return this.#raw.agentId();
129
+ }
130
+ get agentIdBytes() {
131
+ return this.#raw.agentIdBytes();
132
+ }
133
+ get did() {
134
+ return this.#raw.did();
135
+ }
136
+ get publicBundle() {
137
+ return this.#raw.publicBundle();
138
+ }
139
+ get hasEncryption() {
140
+ return this.#raw.hasEncryption();
141
+ }
142
+ /** Sign a payload into a tag 98 envelope (Ed25519 plus ML-DSA-65). */
143
+ sign(payload, options = {}) {
144
+ return this.#raw.sign(payload, signJson(options));
145
+ }
146
+ /** Open a tag 96 envelope addressed to this identity. Returns the inner signed envelope, unverified. */
147
+ decrypt(data) {
148
+ return this.#raw.decrypt(data);
149
+ }
150
+ /** Issue an attestation (spec section 7) about `options.subject`. */
151
+ issueAttestation(o) {
152
+ return this.#raw.issueAttestation(JSON.stringify({
153
+ subject: o.subject,
154
+ claim: o.claim,
155
+ issued_at: o.issuedAt,
156
+ expires_at: o.expiresAt,
157
+ data: o.data,
158
+ data_hex: o.dataCbor && bytesToHex(o.dataCbor),
159
+ evidence_hex: o.evidence && bytesToHex(o.evidence),
160
+ evidence_uri: o.evidenceUri,
161
+ id_hex: o.id && bytesToHex(o.id),
162
+ nonce_hex: o.nonce && bytesToHex(o.nonce),
163
+ mode: o.deterministic ? "deterministic" : "hedged",
164
+ include_bundle: o.includeBundle,
165
+ allow_long_default: o.allowLongDefault,
166
+ }));
167
+ }
168
+ /** Create a signed revocation list with this identity as issuer (spec section 8). */
169
+ createSrl(o) {
170
+ return this.#raw.createSrl(JSON.stringify({
171
+ sequence: o.sequence,
172
+ issued_at: o.issuedAt,
173
+ next_update: o.nextUpdate,
174
+ revoked: o.revoked.map((r) => ({
175
+ ...("attestationId" in r ? { id_hex: bytesToHex(r.attestationId) } : { id: r.identity }),
176
+ reason: r.reason,
177
+ revoked_at: r.revokedAt,
178
+ })),
179
+ nonce_hex: o.nonce && bytesToHex(o.nonce),
180
+ mode: o.deterministic ? "deterministic" : "hedged",
181
+ include_bundle: o.includeBundle,
182
+ }));
183
+ }
184
+ /** Sign a log checkpoint with this identity as the log. */
185
+ createCheckpoint(o) {
186
+ return this.#raw.createCheckpoint(JSON.stringify({
187
+ tree_size: o.treeSize,
188
+ root_hash_hex: bytesToHex(o.rootHash),
189
+ timestamp: o.timestamp,
190
+ nonce_hex: o.nonce && bytesToHex(o.nonce),
191
+ mode: o.deterministic ? "deterministic" : "hedged",
192
+ }));
193
+ }
194
+ /** Verify with this identity as the recipient (opens tag 96 envelopes). */
195
+ verify(data, policy = {}, now = nowSecs()) {
196
+ return JSON.parse(rawVerifyAs(this.#raw, data, normalizePolicy(policy), now));
197
+ }
198
+ /** Zeroize and release the secret seeds. */
199
+ free() {
200
+ this.#raw.free();
201
+ }
202
+ [Symbol.dispose]() {
203
+ this.#raw.free();
204
+ }
205
+ }
206
+ // ---------------------------------------------------------------------------
207
+ // Functions
208
+ /** Generate an identity (alias of `Identity.generate`). */
209
+ export function keygen(encryption = true) {
210
+ return Identity.generate(encryption);
211
+ }
212
+ /** Agent ID of a public bundle (or of an Identity). */
213
+ export function agentId(bundleOrIdentity) {
214
+ need();
215
+ return bundleOrIdentity instanceof Identity
216
+ ? bundleOrIdentity.agentId
217
+ : agentIdOfBundle(bundleOrIdentity);
218
+ }
219
+ /** Parse an Agent ID in `atep:` or `did:atep:` form. */
220
+ export function parseAgentId(s) {
221
+ need();
222
+ return JSON.parse(rawParseAgentId(s));
223
+ }
224
+ export function sign(identity, payload, options = {}) {
225
+ return identity.sign(payload, options);
226
+ }
227
+ /** Encrypt a signed envelope to a recipient's public bundle (hybrid X25519 + ML-KEM-768, AES-256-GCM). */
228
+ export function encrypt(signedEnvelope, recipientBundle) {
229
+ need();
230
+ return rawEncrypt(signedEnvelope, recipientBundle);
231
+ }
232
+ /** Encrypt with explicit randomness. Only for reproducing test vectors. */
233
+ export function encryptDeterministic(signedEnvelope, recipientBundle, rnd) {
234
+ need();
235
+ return encryptWithRandomness(signedEnvelope, recipientBundle, rnd.x25519Ephemeral, rnd.mlkemM, rnd.iv);
236
+ }
237
+ export function decrypt(identity, data) {
238
+ return identity.decrypt(data);
239
+ }
240
+ /**
241
+ * Verify an envelope, spec section 10 steps 1 to 10. A rejection is returned
242
+ * as `{ok: false, step, error}`, not thrown. Malformed arguments throw.
243
+ */
244
+ export function verify(data, policy = {}, options = {}) {
245
+ need();
246
+ const now = options.now ?? nowSecs();
247
+ if (options.recipient)
248
+ return options.recipient.verify(data, policy, now);
249
+ return JSON.parse(rawVerify(data, normalizePolicy(policy), now));
250
+ }
251
+ /** JSON debug rendering of any ATEP CBOR object (envelope, bundle, ...). Not canonical. */
252
+ export function view(data) {
253
+ need();
254
+ return JSON.parse(rawView(data));
255
+ }
256
+ export function sha256(data) {
257
+ need();
258
+ return rawSha256(data);
259
+ }
260
+ /** Put inline attestations into the (unsigned) unprotected header of an envelope. */
261
+ export function withAttestations(envelope, attestations) {
262
+ need();
263
+ return rawWithAttestations(envelope, JSON.stringify(attestations.map(bytesToHex)));
264
+ }
265
+ /** Attach a log inclusion proof to an attestation. */
266
+ export function withInclusionProof(attestation, proof) {
267
+ need();
268
+ return rawWithInclusionProof(attestation, proof.leafIndex, JSON.stringify(proof.auditPath.map(bytesToHex)), proof.checkpoint);
269
+ }
270
+ /** The attestation as submitted to a log: its inclusion proof header removed. This is the Merkle leaf. */
271
+ export function submittedFormOf(attestation) {
272
+ need();
273
+ return submittedForm(attestation);
274
+ }
275
+ /** RFC 9162 Merkle root over leaves. */
276
+ export function merkleRoot(leaves) {
277
+ need();
278
+ return hexToBytes(rawMerkleRoot(JSON.stringify(leaves.map(bytesToHex))));
279
+ }
280
+ /** RFC 9162 audit path of leaf `index`. */
281
+ export function auditPath(index, leaves) {
282
+ need();
283
+ return JSON.parse(rawAuditPath(index, JSON.stringify(leaves.map(bytesToHex)))).map(hexToBytes);
284
+ }
285
+ /** Verify a checkpoint envelope: steps 1 to 8, content type, trusted log, schema. */
286
+ export function verifyCheckpoint(cbor, trustedLogs, now = nowSecs()) {
287
+ need();
288
+ return JSON.parse(rawVerifyCheckpoint(cbor, JSON.stringify(trustedLogs), now));
289
+ }
290
+ /** Verify the inclusion proof an attestation carries (offline, against trusted logs). */
291
+ export function verifyInclusion(attestation, trustedLogs, now = nowSecs()) {
292
+ need();
293
+ return JSON.parse(rawVerifyInclusion(attestation, JSON.stringify(trustedLogs), now));
294
+ }
295
+ /** Check a consistency proof document `{old, new, proof}` (CBOR). */
296
+ export function checkConsistency(cbor, trustedLogs, now = nowSecs()) {
297
+ need();
298
+ return JSON.parse(rawCheckConsistency(cbor, JSON.stringify(trustedLogs), now));
299
+ }
300
+ /** Check a split view document `{a, b, proof?}` (CBOR). */
301
+ export function checkSplitView(cbor, trustedLogs, now = nowSecs()) {
302
+ need();
303
+ return JSON.parse(rawCheckSplitView(cbor, JSON.stringify(trustedLogs), now));
304
+ }
305
+ function normalizeSrlContext(c) {
306
+ const o = { ...c };
307
+ for (const k of ["known_bundles", "attestations"]) {
308
+ const v = c[k];
309
+ if (v !== undefined)
310
+ o[k] = v.map(hx);
311
+ }
312
+ return JSON.stringify(o);
313
+ }
314
+ /**
315
+ * Verify a signed revocation list and apply the freshness rule. `cached` is a
316
+ * previously accepted SRL of the same issuer (rollback and conflict rules apply).
317
+ */
318
+ export function verifySrl(srl, options = {}) {
319
+ need();
320
+ return JSON.parse(rawVerifySrl(srl, options.now ?? nowSecs(), JSON.stringify({ on_stale: options.onStale ?? "fail-closed" }), options.cached ?? undefined, options.context ? normalizeSrlContext(options.context) : undefined));
321
+ }
322
+ /** Is `id` a valid `chain-id`: one of the five registered ids, or `x-` plus a lowercase name. Pure function. */
323
+ export function chainIdKind(id) {
324
+ need();
325
+ return JSON.parse(rawChainIdKind(id));
326
+ }
327
+ /** Decode an anchor record payload (strict deterministic CBOR). Invalid input is a result, not an exception. */
328
+ export function parseAnchorRecord(payload) {
329
+ need();
330
+ return JSON.parse(rawParseAnchorRecord(payload));
331
+ }
332
+ /** Deterministic CBOR of an anchor record (no `block-height` key when it is null or absent). */
333
+ export function encodeAnchorRecord(record) {
334
+ need();
335
+ return rawEncodeAnchorRecord(JSON.stringify(record));
336
+ }
337
+ /** Verify a checkpoint envelope (as `verifyCheckpoint`) and add `checkpoint_hash`: SHA-256 of the verified payload. */
338
+ export function checkpointHash(cbor, trustedLogs, now = nowSecs()) {
339
+ need();
340
+ return JSON.parse(rawCheckpointHash(cbor, JSON.stringify(trustedLogs), now));
341
+ }
342
+ /**
343
+ * Take a log-signed anchor envelope as published: steps 1 to 8 (reported as they are), then the content
344
+ * type, the record schema, the signer (`log`) and the checkpoint hash (hex), in that order.
345
+ * Whether the witness really holds the hash is not checked.
346
+ */
347
+ export function checkPublishedAnchor(envelope, log, checkpointHashHex, now = nowSecs()) {
348
+ need();
349
+ return JSON.parse(rawCheckPublishedAnchor(envelope, log, checkpointHashHex, now));
350
+ }
351
+ /** Parse the `require_anchor` rules of a trust policy object. A bad policy is `{ok: false, error: "policy_invalid"}`. */
352
+ export function parseRequireAnchor(policy) {
353
+ need();
354
+ return JSON.parse(rawParseRequireAnchor(JSON.stringify(policy)));
355
+ }
356
+ /**
357
+ * The admission rules of a log (spec section 9) applied to one submission, including the data rules of
358
+ * `registry-endpoint` and `domain-control`. `logged` are documents admitted first, in order (hex or bytes).
359
+ * This package has no log: this is a pure check of the rules.
360
+ */
361
+ export function checkAdmission(submission, options) {
362
+ need();
363
+ return JSON.parse(rawCheckAdmission(submission, JSON.stringify({
364
+ now: options.now ?? nowSecs(),
365
+ log: options.log,
366
+ max_envelope_bytes: options.maxEnvelopeBytes ?? 65536,
367
+ logged: (options.logged ?? []).map(hx),
368
+ })));
369
+ }
370
+ /** Run the domain binding check (section 7) over a fixture of fetcher answers. No network is used. */
371
+ export function checkDomainBinding(fixture) {
372
+ need();
373
+ return JSON.parse(rawCheckDomainBinding(JSON.stringify(fixture)));
374
+ }
@@ -0,0 +1,312 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * An agent identity. The secret seeds stay inside wasm memory.
6
+ */
7
+ export class Identity {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ agentIdBytes(): Uint8Array;
12
+ /**
13
+ * Agent ID in text form (`atep:...`).
14
+ */
15
+ agentId(): string;
16
+ /**
17
+ * Sign a log checkpoint (this identity is the log). `options` JSON:
18
+ * `{tree_size, root_hash_hex, timestamp, nonce_hex?, mode?}`.
19
+ */
20
+ createCheckpoint(options: string): Uint8Array;
21
+ /**
22
+ * Create a signed revocation list (spec section 8). `options` JSON:
23
+ * `{sequence, issued_at, next_update, revoked: [{id_hex (16 bytes, an
24
+ * attestation) | id (an Agent ID), reason, revoked_at}], nonce_hex?,
25
+ * mode?, include_bundle?}`. The issuer is this identity.
26
+ */
27
+ createSrl(options: string): Uint8Array;
28
+ /**
29
+ * Open a tag 96 envelope addressed to this identity; returns the inner
30
+ * tag 98 envelope (not verified, run `verify` on it or use `verify`
31
+ * directly with this identity as recipient).
32
+ */
33
+ decrypt(data: Uint8Array): Uint8Array;
34
+ did(): string;
35
+ /**
36
+ * The CBOR secret key file. This copies secret material into a JS
37
+ * Uint8Array: the caller owns it and should `.fill(0)` it after use.
38
+ */
39
+ exportSecret(): Uint8Array;
40
+ /**
41
+ * From the CBOR secret key file written by `exportSecret` (and by the Rust CLI).
42
+ */
43
+ static fromSecret(secret_file: Uint8Array): Identity;
44
+ /**
45
+ * From raw seeds. `x25519` and `mlkem768` are both given or both empty.
46
+ */
47
+ static fromSeeds(ed25519: Uint8Array, mldsa65: Uint8Array, x25519?: Uint8Array | null, mlkem768?: Uint8Array | null): Identity;
48
+ /**
49
+ * New identity from system randomness (`crypto.getRandomValues`).
50
+ */
51
+ static generate(with_encryption: boolean): Identity;
52
+ hasEncryption(): boolean;
53
+ /**
54
+ * Issue an attestation (spec section 7). `options` is JSON:
55
+ * `{subject, claim, issued_at, expires_at, data?: JSON object (or data_hex: CBOR),
56
+ * evidence_hex?, evidence_uri?, id_hex?, nonce_hex?, mode?, include_bundle?,
57
+ * allow_long_default?}`. In `data`, `{"$hex": "..."}` becomes a byte string.
58
+ */
59
+ issueAttestation(options: string): Uint8Array;
60
+ /**
61
+ * Canonical public key bundle (CBOR).
62
+ */
63
+ publicBundle(): Uint8Array;
64
+ /**
65
+ * Sign a payload into a tag 98 envelope. `options` is JSON:
66
+ * `{content_type?, issued_at, expires_at?, detached?, include_bundle?,
67
+ * nonce_hex?, mode?: "hedged"|"deterministic", command_class?}`.
68
+ */
69
+ sign(payload: Uint8Array, options: string): Uint8Array;
70
+ }
71
+
72
+ /**
73
+ * Agent ID (text form) of a public bundle.
74
+ */
75
+ export function agentIdOfBundle(bundle_bytes: Uint8Array): string;
76
+
77
+ /**
78
+ * Audit path for `index` (JSON array of hex hashes) over the leaves.
79
+ */
80
+ export function auditPath(index: number, leaves: string): string;
81
+
82
+ /**
83
+ * Check a `chain-id` (spec section 9, "The `chain-id` registry"): returns
84
+ * `{ok: true, kind: "registered" | "extension"}` or `{ok: false}`.
85
+ */
86
+ export function chainIdKind(id: string): string;
87
+
88
+ /**
89
+ * Run the admission rules of a log (spec section 9, "Admission", the 14 core
90
+ * claim types, `registry-endpoint` and `domain-control` data rules) on a
91
+ * submission. `options` JSON: `{now, log, max_envelope_bytes, logged?: [hex]}`
92
+ * where `logged` are documents admitted first, in order. Returns
93
+ * `{ok: true, document}` or `{ok: false, refusal, step?, error?}`.
94
+ */
95
+ export function checkAdmission(cbor: Uint8Array, options: string): string;
96
+
97
+ /**
98
+ * Check a consistency proof document `{old, new, proof}` (CBOR).
99
+ */
100
+ export function checkConsistency(cbor: Uint8Array, trusted_logs: string, now: number): string;
101
+
102
+ /**
103
+ * Run the domain binding check (spec section 7, "Checking a domain binding")
104
+ * on a fixture: `{domain, agent_id, options: {require_both, require_dnssec},
105
+ * well_known: {host: answer}, txt: {name: answer}}`, the fetcher's answers
106
+ * by name (a name with no key does not exist). No network is used. Returns
107
+ * `{well_known, dns, outcome, queried: {well_known, txt}}`.
108
+ */
109
+ export function checkDomainBinding(fixture: string): string;
110
+
111
+ /**
112
+ * Take a log-signed anchor envelope as published (spec section 9, "Anchor
113
+ * records"): steps 1 to 8, content type, record schema, signer is `log`,
114
+ * record is for `checkpoint_hash_hex`. Returns `{ok: true, log, record}` or
115
+ * `{ok: false, step, error}`.
116
+ */
117
+ export function checkPublishedAnchor(cbor: Uint8Array, log_id: string, checkpoint_hash_hex: string, now: number): string;
118
+
119
+ /**
120
+ * Check a split view document `{a, b, proof?}` (CBOR).
121
+ */
122
+ export function checkSplitView(cbor: Uint8Array, trusted_logs: string, now: number): string;
123
+
124
+ /**
125
+ * Verify a checkpoint envelope (as `verifyCheckpoint`) and add its checkpoint
126
+ * hash, SHA-256 of the verified payload bytes. Returns
127
+ * `{ok: true, checkpoint, checkpoint_hash, payload_hex}` or a rejection.
128
+ */
129
+ export function checkpointHash(cbor: Uint8Array, trusted_logs: string, now: number): string;
130
+
131
+ /**
132
+ * Encode an anchor record (deterministic CBOR). `record` is JSON
133
+ * `{checkpoint_hash, chain_id, transaction_id, block_height?, anchored_at}`
134
+ * (the shape `parseAnchorRecord` returns). Throws when the chain id is invalid.
135
+ */
136
+ export function encodeAnchorRecord(record: string): Uint8Array;
137
+
138
+ /**
139
+ * Encrypt a signed envelope to a recipient bundle with fresh randomness.
140
+ */
141
+ export function encrypt(signed_envelope: Uint8Array, recipient_bundle: Uint8Array): Uint8Array;
142
+
143
+ /**
144
+ * Encrypt with caller supplied randomness (for reproducing test vectors; do
145
+ * not use in production). Sizes: 32, 32 and 12 bytes.
146
+ */
147
+ export function encryptWithRandomness(signed_envelope: Uint8Array, recipient_bundle: Uint8Array, x25519_ephemeral: Uint8Array, mlkem_m: Uint8Array, iv: Uint8Array): Uint8Array;
148
+
149
+ /**
150
+ * RFC 9162 Merkle tree root over leaves given as a JSON array of hex strings.
151
+ */
152
+ export function merkleRoot(leaves: string): string;
153
+
154
+ /**
155
+ * Parse any accepted Agent ID spelling (`atep:` text or `did:atep:`) and
156
+ * return `{text, did, hex}` as JSON.
157
+ */
158
+ export function parseAgentId(s: string): string;
159
+
160
+ /**
161
+ * Decode an anchor record payload (strict deterministic CBOR, schema of
162
+ * section 9). Returns `{ok: true, record}` or
163
+ * `{ok: false, error: "anchor_record_invalid"}`. An accepted record must
164
+ * re-encode to the same bytes, else this throws (an internal inconsistency).
165
+ */
166
+ export function parseAnchorRecord(payload: Uint8Array): string;
167
+
168
+ /**
169
+ * Parse the `require_anchor` rules of a trust policy (a JSON object, the
170
+ * policy file format). Returns `{ok: true, require_anchor: [...]}` or
171
+ * `{ok: false, error: "policy_invalid"}` (a configuration error, no step).
172
+ */
173
+ export function parseRequireAnchor(policy: string): string;
174
+
175
+ /**
176
+ * SHA-256.
177
+ */
178
+ export function sha256(data: Uint8Array): Uint8Array;
179
+
180
+ /**
181
+ * The form of an attestation that is submitted to a log (the `-70012` header removed).
182
+ */
183
+ export function submittedForm(envelope_bytes: Uint8Array): Uint8Array;
184
+
185
+ /**
186
+ * Verify an envelope (spec section 10, all ten steps). `policy` is JSON in the
187
+ * format of the test vectors: `{max_skew_secs?, known_bundles: [hex],
188
+ * seen_nonces: [hex], revocations: [{id, reason, revoked_at}],
189
+ * detached_payload_hex?, trust?: {...policy file...}, attestations?: [hex],
190
+ * srls?: [hex], recipient_seeds?: {...}}`. A recipient `Identity` object can
191
+ * be passed instead of `recipient_seeds` (preferred: the seeds then never
192
+ * enter JSON). Returns JSON: `{ok: true, signer, ..., payload_hex}` or
193
+ * `{ok: false, step, error, cause?}`.
194
+ */
195
+ export function verify(data: Uint8Array, policy: string, now: number): string;
196
+
197
+ /**
198
+ * `verify` with a recipient `Identity` object that opens tag 96 envelopes.
199
+ */
200
+ export function verifyAs(recipient: Identity, data: Uint8Array, policy: string, now: number): string;
201
+
202
+ /**
203
+ * Verify a checkpoint envelope against trusted logs (JSON array of Agent IDs).
204
+ */
205
+ export function verifyCheckpoint(cbor: Uint8Array, trusted_logs: string, now: number): string;
206
+
207
+ /**
208
+ * Verify the inclusion proof carried by an attestation.
209
+ */
210
+ export function verifyInclusion(attestation_bytes: Uint8Array, trusted_logs: string, now: number): string;
211
+
212
+ /**
213
+ * Verify an SRL envelope and apply the freshness policy. `srl_policy` JSON:
214
+ * `{on_stale: "fail-closed"|"fail-open", on_missing?}`; `cached_srl` is an
215
+ * optional previously accepted SRL envelope (rollback rules apply).
216
+ * `context` is optional JSON `{known_bundles?: [hex], attestations?: [hex],
217
+ * revocations?: [{id, reason, revoked_at}], max_skew_secs?}`: the verifier's
218
+ * own context in which the cached list and the list are loaded (steps 1 to 8,
219
+ * spec section 8). Without it only the inline bundles are known.
220
+ */
221
+ export function verifySrl(cbor: Uint8Array, now: number, srl_policy: string, cached_srl?: Uint8Array | null, context?: string | null): string;
222
+
223
+ /**
224
+ * JSON debug view of any ATEP CBOR object.
225
+ */
226
+ export function view(data: Uint8Array): string;
227
+
228
+ /**
229
+ * Put inline attestations (`-70009`) into the unprotected header of an
230
+ * envelope. `attestations` is a JSON array of hex strings.
231
+ */
232
+ export function withAttestations(envelope_bytes: Uint8Array, attestations: string): Uint8Array;
233
+
234
+ /**
235
+ * Attach an inclusion proof (`-70012`) to an attestation. `audit_path` is a
236
+ * JSON array of 32 byte hex hashes, `checkpoint` the signed checkpoint envelope.
237
+ */
238
+ export function withInclusionProof(attestation_bytes: Uint8Array, leaf_index: number, audit_path: string, checkpoint: Uint8Array): Uint8Array;
239
+
240
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
241
+
242
+ export interface InitOutput {
243
+ readonly memory: WebAssembly.Memory;
244
+ readonly __wbg_identity_free: (a: number, b: number) => void;
245
+ readonly agentIdOfBundle: (a: number, b: number, c: number) => void;
246
+ readonly auditPath: (a: number, b: number, c: number, d: number) => void;
247
+ readonly chainIdKind: (a: number, b: number, c: number) => void;
248
+ readonly checkAdmission: (a: number, b: number, c: number, d: number, e: number) => void;
249
+ readonly checkConsistency: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
250
+ readonly checkDomainBinding: (a: number, b: number, c: number) => void;
251
+ readonly checkPublishedAnchor: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
252
+ readonly checkSplitView: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
253
+ readonly checkpointHash: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
254
+ readonly encodeAnchorRecord: (a: number, b: number, c: number) => void;
255
+ readonly encrypt: (a: number, b: number, c: number, d: number, e: number) => void;
256
+ readonly encryptWithRandomness: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
257
+ readonly identity_agentId: (a: number, b: number) => void;
258
+ readonly identity_agentIdBytes: (a: number, b: number) => void;
259
+ readonly identity_createCheckpoint: (a: number, b: number, c: number, d: number) => void;
260
+ readonly identity_createSrl: (a: number, b: number, c: number, d: number) => void;
261
+ readonly identity_decrypt: (a: number, b: number, c: number, d: number) => void;
262
+ readonly identity_did: (a: number, b: number) => void;
263
+ readonly identity_exportSecret: (a: number, b: number) => void;
264
+ readonly identity_fromSecret: (a: number, b: number, c: number) => void;
265
+ readonly identity_fromSeeds: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
266
+ readonly identity_generate: (a: number, b: number) => void;
267
+ readonly identity_hasEncryption: (a: number) => number;
268
+ readonly identity_issueAttestation: (a: number, b: number, c: number, d: number) => void;
269
+ readonly identity_publicBundle: (a: number, b: number) => void;
270
+ readonly identity_sign: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
271
+ readonly merkleRoot: (a: number, b: number, c: number) => void;
272
+ readonly parseAgentId: (a: number, b: number, c: number) => void;
273
+ readonly parseAnchorRecord: (a: number, b: number, c: number) => void;
274
+ readonly parseRequireAnchor: (a: number, b: number, c: number) => void;
275
+ readonly sha256: (a: number, b: number, c: number) => void;
276
+ readonly submittedForm: (a: number, b: number, c: number) => void;
277
+ readonly verify: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
278
+ readonly verifyAs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
279
+ readonly verifyCheckpoint: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
280
+ readonly verifyInclusion: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
281
+ readonly verifySrl: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
282
+ readonly view: (a: number, b: number, c: number) => void;
283
+ readonly withAttestations: (a: number, b: number, c: number, d: number, e: number) => void;
284
+ readonly withInclusionProof: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
285
+ readonly __wbindgen_export: (a: number) => void;
286
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
287
+ readonly __wbindgen_export2: (a: number, b: number) => number;
288
+ readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
289
+ readonly __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;
290
+ }
291
+
292
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
293
+
294
+ /**
295
+ * Instantiates the given `module`, which can either be bytes or
296
+ * a precompiled `WebAssembly.Module`.
297
+ *
298
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
299
+ *
300
+ * @returns {InitOutput}
301
+ */
302
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
303
+
304
+ /**
305
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
306
+ * for everything else, calls `WebAssembly.instantiate` directly.
307
+ *
308
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
309
+ *
310
+ * @returns {Promise<InitOutput>}
311
+ */
312
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;