@agledger/verify-core 2.0.0 → 2.2.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/failures.js CHANGED
@@ -41,43 +41,57 @@
41
41
  * verdict, never a silent pass.
42
42
  *
43
43
  * Later additions:
44
- * - CHAIN_ENTRY_UNSIGNED engine mirror of `signature_missing`: an entry with
44
+ * - CHAIN_ENTRY_UNSIGNED Server mirror of `signature_missing`: an entry with
45
45
  * no signing key id after a signed entry in its
46
46
  * chain, or written at or after the earliest
47
47
  * activatedAt in the key set. Earlier unsigned
48
48
  * entries stay reduced coverage.
49
- * - CHECKPOINT_UNSIGNED engine mirror of `checkpoint_unsigned`: the same
49
+ * - CHECKPOINT_UNSIGNED Server mirror of `checkpoint_unsigned`: the same
50
50
  * instant, applied to an unsigned checkpoint.
51
51
  * - TENANT_READ_LEAF_UNSIGNED and TENANT_CHECKPOINT_UNSIGNED the same two
52
- * rules on the org_admin_reads log (engine
52
+ * rules on the org_admin_reads log (Server
53
53
  * `leaf_signature_missing`, `checkpoint_unsigned`).
54
- * - CHAIN_SIGNING_KEY_UNANCHORED engine mirror of `signing_key_unanchored`:
54
+ * - CHAIN_SIGNING_KEY_UNANCHORED Server mirror of `signing_key_unanchored`:
55
55
  * the entry's key is not linked by signed key
56
56
  * statements to a pinned trust anchor. With
57
57
  * CHECKPOINT_KEY_UNANCHORED,
58
58
  * TENANT_READ_KEY_UNANCHORED and
59
59
  * TENANT_CHECKPOINT_KEY_UNANCHORED for the
60
- * engine's `checkpoint_key_unanchored` and
60
+ * Server's `checkpoint_key_unanchored` and
61
61
  * `leaf_key_unanchored`.
62
+ * - CHECKPOINT_KEY_NOT_YET_ACTIVE, CHECKPOINT_KEY_EXPIRED, and the
63
+ * TENANT_READ_KEY_* and TENANT_CHECKPOINT_KEY_* pairs Server mirror of
64
+ * `checkpoint_key_not_yet_active`,
65
+ * `checkpoint_key_expired`, `leaf_key_not_yet_active`
66
+ * and `leaf_key_expired`: a vault checkpoint, a
67
+ * read-log leaf or a read-log tree head written
68
+ * outside its signing key's signed window, by
69
+ * the rule CHAIN_KEY_NOT_YET_ACTIVE and
70
+ * CHAIN_KEY_EXPIRED apply to entries.
71
+ * - CHECKPOINT_ACCOUNTED_ONLY, CHECKPOINT_ACCOUNTED_RUN_EXCEEDED Server mirror
72
+ * of `accounted_checkpoint_only` and
73
+ * `checkpoint_accounted_run_exceeded`: what a
74
+ * chain is left with when the checkpoints a
75
+ * distrustedKeys entry accounts for are set aside.
62
76
  * - KEY_STATEMENT_INVALID, KEY_CLOSURE_INVALID, CHAIN_KEY_WINDOW_DRIFT
63
- * engine mirrors of the key registry findings
77
+ * Server mirrors of the key registry findings
64
78
  * `key_statement_invalid`, `key_closure_invalid`
65
79
  * and `key_window_drift`. They are about the
66
80
  * registry, not about any one entry.
67
81
  * - CHECKPOINT_CLAIM_MISMATCH, TENANT_READ_CLAIM_MISMATCH,
68
- * TENANT_CHECKPOINT_CLAIM_MISMATCH engine mirrors of the vault's
82
+ * TENANT_CHECKPOINT_CLAIM_MISMATCH Server mirrors of the vault's
69
83
  * `checkpoint_claim_mismatch` and the read log's
70
84
  * `leaf_claim_mismatch` and
71
85
  * `checkpoint_claim_mismatch`: the claim signed
72
86
  * inside the envelope does not decode, or says
73
87
  * something the row's columns do not.
74
88
  *
75
- * Server-side cert re-checks are not mirrored here. The engine's chain
89
+ * Server-side cert re-checks are not mirrored here. The Server's chain
76
90
  * verification also reports `cert_missing`, `cert_actor_drift`,
77
91
  * `cert_window_drift`, `cert_expired` and `agent_signature_invalid`, by
78
92
  * comparing what an entry sealed in `predicate.on_behalf_of.cert` against the
79
- * live `ephemeral_certs` row. Neither the export nor the dump carries that
80
- * table, so an offline verifier cannot reproduce those comparisons, and it
93
+ * Server's cert record. Neither the export nor the dump carries that
94
+ * record, so an offline verifier cannot reproduce those comparisons, and it
81
95
  * does not need to: it trusts only the signed bytes, which already fix the
82
96
  * sealed cert id, thumbprint and expiry. The one cert-related check that can
83
97
  * run offline is the agent signature, and only when the caller supplies the
@@ -88,13 +102,13 @@
88
102
  * verifier's caller (auditor, compliance team, or agent) should do next.
89
103
  */
90
104
  const SUGGESTIONS = {
91
- UNSUPPORTED_FORMAT: 'This verifier reads exportFormatVersion 2.0 / RFC8949-CDE canonicalization. Re-export the chain from a current AGLedger instance, or upgrade the verifier to match the producing engine.',
105
+ UNSUPPORTED_FORMAT: 'This verifier reads exportFormatVersion 2.0 / RFC8949-CDE canonicalization. Re-export the chain from a current AGLedger instance, or upgrade the verifier to match the producing Server.',
92
106
  CHAIN_EMPTY: 'No entries were present to verify. Confirm the record id / dump directory is correct and that the chain has not been truncated to zero rows.',
93
107
  CHAIN_POSITION_GAP: 'A chain position is missing or out of order. The chain was truncated or reordered. Obtain a complete, unmodified export/dump from the operator and re-run.',
94
108
  CHAIN_GENESIS_INVALID: 'The first entry must carry previousHash = null. A non-null genesis link means the head of the chain was removed. Request the full chain from position 1.',
95
109
  CHAIN_LINK_BROKEN: 'An entry\'s previousHash does not match the prior entry\'s payloadHash. The chain was edited between these two entries. Treat every entry from this position on as untrusted.',
96
110
  CHAIN_HASH_MISMATCH: 'sha256(cose_sign1) does not equal the stored payloadHash. The envelope bytes or the stored hash were altered. The signed bytes are authoritative; the row was tampered with.',
97
- CHAIN_MALFORMED_ENTRY: 'An entry is missing a field the engine writes on every entry (coseSign1, payloadHash, or a parseable createdAt where a key window or the start of signing needs one), or carries it as another type. The export/dump is incomplete or was edited, and an entry the verifier cannot place is never read as early unsigned history. Regenerate the export/dump from the operator and re-run.',
111
+ CHAIN_MALFORMED_ENTRY: 'An entry is missing a field the Server writes on every entry (coseSign1, payloadHash, or a parseable createdAt where a key window or the start of signing needs one), or carries it as another type. The export/dump is incomplete or was edited, and an entry the verifier cannot place is never read as early unsigned history. Regenerate the export/dump from the operator and re-run.',
98
112
  CHAIN_COSE_DECODE_FAILED: 'The COSE_Sign1 envelope did not decode as a tagged 4-element structure. The signed bytes are corrupt. Regenerate the export/dump.',
99
113
  CHAIN_COSE_HEADER_MISMATCH: 'The position/previousHash signed in the COSE protected header disagree with the row columns. The visible columns were renumbered after signing. Trust the signed header, not the columns.',
100
114
  CHAIN_PAYLOAD_BINDING_MISMATCH: 'The signed payload\'s structure no longer matches the canonical projection of the row columns it is bound to: the visible (denormalised) payload was altered after signing. This is a binding-integrity failure, not a judgement on content.',
@@ -108,29 +122,39 @@ const SUGGESTIONS = {
108
122
  CHAIN_UNSUPPORTED_ALGORITHM: 'The entry\'s trusted verification key commits to a signature algorithm that could not be computed, either because this verifier build does not implement it or because the host runtime refused it (an active OpenSSL FIPS provider carries no EdDSA). The chain is NOT verified, and this is NOT tamper evidence: the signature was never checked. Upgrade the verifier, or re-run on a host without the restriction. Never treat this result as a pass.',
109
123
  CHAIN_SIGNING_KEY_DRIFT: 'The entry\'s signingKeyId column names a different key than the signature-covered kid in the COSE protected header. The column is a denormalized convenience and was rewritten after signing (possibly to point verification at another key). Trust the signed kid; treat the row as tampered.',
110
124
  CHAIN_ACTOR_ATTRIBUTION_MISMATCH: 'The entry\'s actorId / actorOwnerId columns name a different actor than the signature-covered actor claim in the COSE protected header (CWT_Claims label 15, private label -65539). The columns are the projection a report displays and they were rewritten after signing, re-attributing the action to another actor. Trust the signed claim; treat the row as tampered and re-obtain the export from the operator.',
111
- CHAIN_AGENT_SIGNATURE_INVALID: 'The agent signature sealed in predicate.on_behalf_of.agent_signature does not verify under the supplied key whose RFC 7638 thumbprint the entry itself names, or is sealed in a shape nothing can verify. The engine checks this signature at intake and the envelope signature says the engine wrote it, so this is not a caller mistake: treat the agent attribution of this entry as unproven and escalate to the operator.',
125
+ CHAIN_AGENT_SIGNATURE_INVALID: 'The agent signature sealed in predicate.on_behalf_of.agent_signature does not verify under the supplied key whose RFC 7638 thumbprint the entry itself names, or is sealed in a shape nothing can verify. The Server checks this signature at intake and the envelope signature says the Server wrote it, so this is not a caller mistake: treat the agent attribution of this entry as unproven and escalate to the operator.',
126
+ CHAIN_FEDERATION_WIRE_INVALID: 'The federation message sealed in payload.wire does not hold: its body no longer hashes to the bodyHash the sender signed, the entry asserts a state, type, recommendation or dispute the sealed body does not carry, or (under the sender\'s federation key you supplied) the signature does not verify or the sealed senderPublicKey is not that key. The receiving Server verified the message at intake and signed this entry, so this is not a caller mistake: treat what the entry says the peer asserted as unproven and escalate to both operators.',
127
+ CHAIN_EVIDENCE_BINDING_MISMATCH: 'An evidence body inlined in the export (entries[].evidence, from ?evidence=true) does not hash to the payload.evidenceHash or payload.payloadHash its entry signs, or sits on an entry that signs no such hash. The body is an unsigned projection whose only authority is that hash, so it was edited after export or attached where it does not belong. Trust the signed hash, not the body: re-obtain the evidence from the operator and re-bind it (SHA-256 over its RFC 8785 form).',
112
128
  CHAIN_ENTRY_UNSIGNED: 'The entry carries no signing key id where the install could not have written an unsigned entry: after a signed entry in the same chain, or at or after the earliest activation time in the signing key set (retired keys included). From that instant every writer holds a registered key, so this is what a writer without one leaves on the chain, or a signed row whose key id was nulled. Treat the entry as forged and escalate to the operator. Unsigned entries from before the first key activation stay reduced signature coverage, not a break.',
113
129
  CHAIN_SIGNING_KEY_UNANCHORED: 'The entry is signed by a key that no signed key statement links to a trust anchor you pinned. Anything with write access to the Server\'s database can register a key and sign entries with it; what it cannot write is a statement signed by a key you trust. Treat the entry as forged. If the key is one you vouch for, pin it (trustAnchors) from a source outside the Server, never from the document that served it.',
114
130
  CHAIN_KEY_WINDOW_DRIFT: 'A key registry column (activatedAt, retiredAt or status in a dump row or key document) differs from the value its signed key statements carry. The signed value is the one entries are graded against; the column was rewritten, or the retirement was written without its closure statement. Treat the registry as tampered and compare it with the Server\'s own scan (key_window_drift). Where the detail names a distrust entry the listing says the Server applies (distrustedFrom, VAULT_DISTRUSTED_KEYS), the listed retirement may be that entry\'s cut, which the verifier was not given or was given at another instant; the listing\'s word is unsigned, so it stays tampering until the Server\'s operator confirms the entry.',
115
- CHECKPOINT_ROW_MISSING: 'A signed checkpoint anchors a position that has no matching chain row. The chain was truncated below a checkpoint (out-of-band DELETE/TRUNCATE). The checkpoint is proof of the missing rows.',
131
+ CHECKPOINT_ROW_MISSING: 'A signed checkpoint anchors a position that has no matching chain row. Chain entries below a checkpoint were removed out of band. The checkpoint is proof of the missing entries. On a record export the position is the one the export states (exportMetadata.expectedEntries): fetch the export again and verify the file exactly as served.',
116
132
  CHECKPOINT_HASH_MISMATCH: 'A checkpoint\'s payloadHash does not match the chain row at its position. The chain diverged from what was checkpointed. Treat the chain as tampered.',
117
133
  CHECKPOINT_SIGNATURE_INVALID: 'A checkpoint\'s COSE_Sign1 signature did not verify. The checkpoint was forged or altered. Re-run with out-of-band verification keys.',
118
134
  CHECKPOINT_UNSIGNED: 'A checkpoint carries no signing key id but was written at or after the earliest activation time in the signing key set (retired keys included), when every writer holds a registered key. The checkpoint was forged or its key id nulled, and nothing it anchors can be trusted. Escalate to the operator.',
119
135
  CHECKPOINT_KEY_UNANCHORED: 'A vault checkpoint is signed by a key that no signed key statement links to a trust anchor you pinned. Nothing it anchors can be trusted; treat it as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
120
136
  CHECKPOINT_CLAIM_MISMATCH: 'The claim signed inside a vault checkpoint envelope does not decode, or says something the checkpoint row\'s columns do not (chain position, chain tip hash, subject digest or signed kid). A column was rewritten beside an intact envelope. Trust the signed claim, treat the checkpoint row as tampered, and obtain the dump from the operator again.',
137
+ CHECKPOINT_KEY_NOT_YET_ACTIVE: 'A vault checkpoint was written before the activation its signing key\'s statements sign. A checkpoint backdated under a later key, or a key used before its succession was recorded: treat what it anchors as unproven and compare with the Server\'s own scan (checkpoint_key_not_yet_active).',
138
+ CHECKPOINT_KEY_EXPIRED: 'A vault checkpoint was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id, and treat what the checkpoint anchors as unproven.',
139
+ CHECKPOINT_ACCOUNTED_ONLY: 'A chain has no entry in the dump, and its only checkpoints are ones a distrustedKeys entry accounts for. Nothing vouches for the chain and nothing explains its absence: a chain is never empty once written. Obtain the chain from a backup or replica and escalate to the operator (Server scan: accounted_checkpoint_only).',
140
+ CHECKPOINT_ACCOUNTED_RUN_EXCEEDED: 'More than 1000 checkpoints a distrustedKeys entry accounts for sit above the newest checkpoint that entry does not cover. A rotation writes a fresh checkpoint at the next tip, so a run this long is rows planted under the leaked key. Treat the chain as unanchored and escalate to the operator (Server scan: checkpoint_accounted_run_exceeded).',
121
141
  TENANT_READ_LEAF_HASH_MISMATCH: 'An org_admin_reads leaf_hash does not match the RFC 9162 leaf hash of its envelope, sha256(0x00 || cose_sign1). The read-log leaf was altered after recording.',
122
142
  TENANT_READ_LEAF_INDEX_GAP: 'org_admin_reads leaf indices are not gap-free for this org. A read-log entry was removed. Obtain the complete log.',
123
143
  TENANT_READ_SIGNATURE_INVALID: 'An org_admin_reads leaf\'s COSE_Sign1 signature did not verify. The read-log leaf was forged or altered.',
124
144
  TENANT_READ_LEAF_UNSIGNED: 'An org_admin_reads leaf carries the unsigned kid where the install could not have written one: after a signed leaf in the same org log, or at or after the earliest activation time in the signing key set. Treat the leaf as forged and escalate to the operator.',
125
145
  TENANT_READ_KEY_UNANCHORED: 'An org_admin_reads leaf is signed by a key that no signed key statement links to a trust anchor you pinned. Treat the leaf as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
126
146
  TENANT_READ_CLAIM_MISMATCH: 'The claim signed inside an org_admin_reads leaf envelope does not decode, or says something the leaf row\'s columns do not (position, previous_hash, record_id or subject digest). A column was rewritten beside an intact envelope. Trust the signed claim and treat the read-log leaf as tampered.',
147
+ TENANT_READ_KEY_NOT_YET_ACTIVE: 'An org_admin_reads leaf was written before the activation its signing key\'s statements sign. Treat the leaf as backdated or forged and compare with the Server\'s own scan (leaf_key_not_yet_active).',
148
+ TENANT_READ_KEY_EXPIRED: 'An org_admin_reads leaf was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id.',
127
149
  TENANT_CHECKPOINT_LEAF_COUNT_MISMATCH: 'A signed tree head commits to more leaves than the dump contains. The read log was truncated below a checkpoint.',
128
150
  TENANT_CHECKPOINT_ROOT_MISMATCH: 'The RFC 9162 Merkle root recomputed over the leaves does not match the signed root_hash. The read log diverged from what was checkpointed.',
129
151
  TENANT_CHECKPOINT_SIGNATURE_INVALID: 'A signed-tree-head COSE_Sign1 signature did not verify. The STH was forged or altered.',
130
152
  TENANT_CHECKPOINT_UNSIGNED: 'An org_admin_reads signed tree head carries no signing key id but was written at or after the earliest activation time in the signing key set. The tree head was forged or its key id nulled; escalate to the operator.',
131
153
  TENANT_CHECKPOINT_KEY_UNANCHORED: 'An org_admin_reads signed tree head is signed by a key that no signed key statement links to a trust anchor you pinned. Treat it as forged (see CHAIN_SIGNING_KEY_UNANCHORED).',
132
154
  TENANT_CHECKPOINT_CLAIM_MISMATCH: 'The claim signed inside an org_admin_reads tree-head envelope does not decode, or says something the tree-head row\'s columns do not (position, chain_tip_hash, leaf count, subject digest or signed kid). A column was rewritten beside an intact envelope. Trust the signed claim and treat the tree-head row as tampered.',
133
- TENANT_CHECKPOINT_FORK: 'Two signed tree heads at the same tree_size carry different roots. This is an engine fork or signing-key compromise. Escalate immediately.',
155
+ TENANT_CHECKPOINT_KEY_NOT_YET_ACTIVE: 'An org_admin_reads signed tree head was written before the activation its signing key\'s statements sign. Treat the tree head as backdated or forged and compare with the Server\'s own scan (checkpoint_key_not_yet_active).',
156
+ TENANT_CHECKPOINT_KEY_EXPIRED: 'An org_admin_reads signed tree head was written after its signing key was retired, or after the instant distrustedKeys gives for that key; the detail says which. Possible use of a compromised key: check the rotation record for that key id.',
157
+ TENANT_CHECKPOINT_FORK: 'Two signed tree heads at the same tree_size carry different roots. This is a Server fork or signing-key compromise. Escalate immediately.',
134
158
  KEY_STATEMENT_INVALID: 'A key statement does not verify, disagrees with the columns it was stored under, touches no anchored key, or was signed by a key after its closure or after the key was already admitted. It admits nothing. One that does not verify, or that a key signed after its closure, is what a writer with database access or a leaked retired key produces: have the operator retire that key with force and add it to VAULT_DISTRUSTED_KEYS, and pass the same entry as distrustedKeys.',
135
159
  KEY_CLOSURE_INVALID: 'A key is retired with no closure that counts for it, or a closure is signed by a key the walk does not anchor, by a key after its own retirement, or dates a retirement before its subject was activated, or is signed by a key the walk reaches but does not anchor and retires an anchored key earlier, or with force, than any closure a published key signed (so a walk over the published key documents reads that key differently). A closure that still counts ends its subject\'s window whoever wrote it; if its signer leaked, have the operator add it to VAULT_DISTRUSTED_KEYS and pass the same entry as distrustedKeys.',
136
160
  };
@@ -0,0 +1,171 @@
1
+ export declare const FEDERATION_WIRE_SCHEME = "agledger.federation.v2";
2
+ /** The sealed message as the receiver stores it under `payload.wire`. */
3
+ export interface FederationWire {
4
+ scheme: string;
5
+ senderHubId: string;
6
+ /** The sender's Ed25519 key as registered at handshake: base64 SPKI DER, or base64 of the raw 32 bytes. */
7
+ senderPublicKey: string;
8
+ recipientHubId: string;
9
+ method: string;
10
+ path: string;
11
+ /** SHA-256 hex over the RFC 8785 canonical JSON of `body`. */
12
+ bodyHash: string;
13
+ timestamp: string;
14
+ nonce: string;
15
+ /** Hex Ed25519 signature over the sign-input. */
16
+ signature: string;
17
+ /** The request body as received, the bytes `bodyHash` covers. */
18
+ body: Record<string, unknown>;
19
+ }
20
+ /** The domain a federation key statement's signatures sign under. */
21
+ export declare const FEDERATION_KEY_STATEMENT_DOMAIN = "agledger.federation.key-statement.v1";
22
+ /** One statement of a {@link FederationKeyHistoryDocument}, as served. */
23
+ export interface FederationKeyHistoryStatement {
24
+ id: string;
25
+ kind: string;
26
+ /** The RFC 8785 (JCS) bytes both signatures cover, after the domain and a colon. */
27
+ payload: string;
28
+ subjectSignature: string;
29
+ predecessorSignature: string | null;
30
+ createdAt?: string;
31
+ }
32
+ /**
33
+ * A publisher's `GET /.well-known/agledger-federation-keys.json`, as served.
34
+ * Only `hubId`, `statementDomain` and the signed `statements` are read: the
35
+ * `keys` summary is the publisher's own unsigned reading of them, so the
36
+ * windows are taken from the statements instead.
37
+ */
38
+ export interface FederationKeyHistoryDocument {
39
+ hubId: string | null;
40
+ statementDomain: string;
41
+ statements: ReadonlyArray<FederationKeyHistoryStatement>;
42
+ anchoredFrom?: string | null;
43
+ keys?: unknown;
44
+ }
45
+ /**
46
+ * One federation key a sender hub is trusted under, base64 SPKI DER, with the
47
+ * window its signed statements give it. Both bounds are null for a key given
48
+ * without a history: it is trusted at any time, as before histories existed.
49
+ */
50
+ export interface FederationTrustedKey {
51
+ publicKey: string;
52
+ /** When the key took over; null when no signed statement bounds it from below. */
53
+ activatedAt: string | null;
54
+ /** When the next key took over; null while no succession signed by this key and its successor ends it. */
55
+ retiredAt: string | null;
56
+ }
57
+ /**
58
+ * Sender hub id to the federation keys its messages are trusted under, as
59
+ * `buildFederationKeyRegistry` builds it: each pinned key, and with a history
60
+ * every key linked to a pin by successions both keys signed.
61
+ */
62
+ export type FederationKeyRegistry = ReadonlyMap<string, ReadonlyArray<FederationTrustedKey>>;
63
+ /**
64
+ * One sender's federation key, the list shape `buildFederationKeyRegistry`
65
+ * takes. `publicKey` is a key you hold for the hub by other means (the
66
+ * `signingPublicKey` your peer row holds, or one its operator confirmed);
67
+ * with `history`, the publisher's key-history document, every earlier or later
68
+ * key a chain of successions links to it is trusted too, inside its window. A
69
+ * hub may be named more than once, to pin keys no succession links: a key
70
+ * listed `linked: false`, or a key the history does not list at all (one in
71
+ * use before a change made with neither predecessor setting), which is then
72
+ * trusted on its own at any time. At least one pin for a hub with a history
73
+ * must be a key that history lists.
74
+ */
75
+ export interface FederationKeyEntry {
76
+ hubId: string;
77
+ publicKey: string;
78
+ history?: FederationKeyHistoryDocument;
79
+ }
80
+ /**
81
+ * A federation key as base64 SPKI DER, from either form the Server's peer
82
+ * table holds: SPKI DER, or the raw 32-byte key. Returns null for anything
83
+ * that is neither (so a caller refuses it by name rather than verifying
84
+ * nothing under it).
85
+ */
86
+ export declare function normalizeFederationKey(publicKeyBase64: string): string | null;
87
+ /**
88
+ * Build the registry from `{ [hubId]: publicKey }` or
89
+ * `[{ hubId, publicKey, history? }]`. Throws `TypeError` naming the entry on
90
+ * any key that is not an Ed25519 key in one of the two forms, and on a history
91
+ * that is another hub's, carries a statement that does not verify, or lists
92
+ * none of the keys pinned for its hub, so a bad input is refused before any verification
93
+ * runs rather than reported as a signature failure.
94
+ */
95
+ export declare function buildFederationKeyRegistry(input: Readonly<Record<string, string>> | ReadonlyArray<FederationKeyEntry>): FederationKeyRegistry;
96
+ /**
97
+ * RFC 8785 (JCS) canonical JSON, as the Server's `canonicalize` writes it:
98
+ * object keys sorted by code unit, no whitespace, `undefined` members dropped
99
+ * (an array element that is `undefined` serializes as `null`), `-0` as `0`,
100
+ * non-finite numbers as `null`. Numbers take JavaScript's own shortest form,
101
+ * which is what RFC 8785 specifies.
102
+ */
103
+ export declare function canonicalizeJson(value: unknown): string;
104
+ /** The sign-input the Server builds, a colon-joined line under the scheme. */
105
+ export declare function federationSignInput(wire: FederationWire): string;
106
+ /**
107
+ * The `wire` a row payload carries, or null when it carries none. A `wire`
108
+ * that is present but is not an object is returned as `malformed`, so the
109
+ * caller fails it rather than reading an edited row as one with no message.
110
+ */
111
+ export declare function extractFederationWire(payload: Record<string, unknown>): FederationWire | 'malformed' | null;
112
+ export type FederationWireOutcome =
113
+ /**
114
+ * The hash, the entry's fields and, under a supplied key, the signature all
115
+ * hold. `afterRetirement` (only with `allowAfterRetirement`): the key the
116
+ * message is sealed under was retired, by a succession it signed, before the
117
+ * sender signed the message. The receiver accepts the old key until it
118
+ * revokes the peer, so a publisher process not yet restarted onto the new
119
+ * key sends exactly this for a short gap.
120
+ */
121
+ {
122
+ outcome: 'ok';
123
+ signatureChecked: boolean;
124
+ afterRetirement: boolean;
125
+ }
126
+ /** No key was supplied for `senderHubId`; the hash and the entry's fields hold, the signature was not checked. */
127
+ | {
128
+ outcome: 'unchecked';
129
+ } | {
130
+ outcome: 'invalid';
131
+ detail: string;
132
+ }
133
+ /** A key was supplied but this host cannot compute Ed25519. */
134
+ | {
135
+ outcome: 'unsupported';
136
+ detail: string;
137
+ };
138
+ /**
139
+ * The allowance at both edges of a federation key's window, as the Server's
140
+ * receiver recipe gives it. `wire.timestamp` is the clock of the process that
141
+ * signed the message and the window's edges are the sender's database clock,
142
+ * so a message signed within this of a key change is on the right key.
143
+ */
144
+ export declare const FEDERATION_KEY_WINDOW_SKEW_MS = 300000;
145
+ export interface CheckFederationWireOptions {
146
+ /**
147
+ * Accept a message signed by a key its history had already retired (beyond
148
+ * the clock-skew allowance), and count it in `afterRetirement`. A publisher
149
+ * process not yet restarted onto the new key sends exactly this for a short
150
+ * gap, and the receiver accepts the old key until it revokes the peer. Off
151
+ * by default: a retired key signing at any later time is also what a leaked
152
+ * key does.
153
+ */
154
+ allowAfterRetirement?: boolean;
155
+ }
156
+ /**
157
+ * Check one sealed message against the entry that carries it, and under the
158
+ * sender's key when `keys` has one for `wire.senderHubId`.
159
+ *
160
+ * Runs on an entry that already passed every other check, so `payload` is
161
+ * what the receiver signed. `recordId` is the entry's record; the body names
162
+ * the same record on every message type that carries one, or, on an entry that
163
+ * signs `origin`, the record id `origin` names. When the sender's
164
+ * keys came with a history, the message is placed in a key's window by
165
+ * `wire.timestamp`: the sender signed it, the receiver sealed it under its own
166
+ * signature after holding it to its clock-skew allowance, and it is read from
167
+ * the sender's clock, the clock the history's windows are written by, with
168
+ * {@link FEDERATION_KEY_WINDOW_SKEW_MS} allowed at each edge. The
169
+ * entry's `createdAt` is a column no signature covers, so it places nothing.
170
+ */
171
+ export declare function checkFederationWire(entryType: string, recordId: string | null, payload: Record<string, unknown>, wire: FederationWire, keys: FederationKeyRegistry | undefined, options?: CheckFederationWireOptions): FederationWireOutcome;