raz-encrypt 1.1.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +442 -212
  3. package/dist/canonicalJson.d.ts +15 -0
  4. package/dist/canonicalJson.js +73 -13
  5. package/dist/canonicalJson.js.map +1 -1
  6. package/dist/core.d.ts +4 -2
  7. package/dist/core.js +3 -1
  8. package/dist/core.js.map +1 -1
  9. package/dist/crypto/classical.d.ts +2 -0
  10. package/dist/crypto/classical.js +4 -0
  11. package/dist/crypto/classical.js.map +1 -1
  12. package/dist/crypto/confirmedSession.d.ts +47 -0
  13. package/dist/crypto/confirmedSession.js +84 -0
  14. package/dist/crypto/confirmedSession.js.map +1 -0
  15. package/dist/crypto/frameCipher.js +8 -2
  16. package/dist/crypto/frameCipher.js.map +1 -1
  17. package/dist/crypto/frameSession.d.ts +40 -0
  18. package/dist/crypto/frameSession.js +96 -0
  19. package/dist/crypto/frameSession.js.map +1 -0
  20. package/dist/crypto/hybrid.d.ts +95 -8
  21. package/dist/crypto/hybrid.js +374 -49
  22. package/dist/crypto/hybrid.js.map +1 -1
  23. package/dist/crypto/nodeHybrid.d.ts +6 -4
  24. package/dist/crypto/nodeHybrid.js +3 -2
  25. package/dist/crypto/nodeHybrid.js.map +1 -1
  26. package/dist/crypto/pqc.d.ts +7 -2
  27. package/dist/crypto/pqc.js +13 -4
  28. package/dist/crypto/pqc.js.map +1 -1
  29. package/dist/crypto/ratchet.js +5 -0
  30. package/dist/crypto/ratchet.js.map +1 -1
  31. package/dist/fileCrypto.d.ts +44 -2
  32. package/dist/fileCrypto.js +197 -28
  33. package/dist/fileCrypto.js.map +1 -1
  34. package/dist/identity.d.ts +69 -4
  35. package/dist/identity.js +111 -12
  36. package/dist/identity.js.map +1 -1
  37. package/dist/index.d.ts +8 -7
  38. package/dist/index.js +4 -4
  39. package/dist/index.js.map +1 -1
  40. package/dist/passphrase.d.ts +27 -0
  41. package/dist/passphrase.js +69 -0
  42. package/dist/passphrase.js.map +1 -0
  43. package/dist/store.d.ts +42 -5
  44. package/dist/store.js +254 -22
  45. package/dist/store.js.map +1 -1
  46. package/dist/trust.d.ts +143 -2
  47. package/dist/trust.js +376 -27
  48. package/dist/trust.js.map +1 -1
  49. package/package.json +62 -48
package/dist/store.js CHANGED
@@ -1,14 +1,92 @@
1
+ import { gcm } from "@noble/ciphers/aes.js";
2
+ import { equalBytes } from "@noble/ciphers/utils.js";
3
+ import { hkdf } from "@noble/hashes/hkdf.js";
4
+ import { hmac } from "@noble/hashes/hmac.js";
1
5
  import { sha384 } from "@noble/hashes/sha2.js";
2
- import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
6
+ import { bytesToHex, concatBytes, hexToBytes, randomBytes, utf8ToBytes } from "@noble/hashes/utils.js";
3
7
  import { appendFile, mkdir, readFile } from "node:fs/promises";
4
- import { join } from "node:path";
8
+ import { join, resolve } from "node:path";
5
9
  import { canonicalize } from "./canonicalJson.js";
10
+ import { writeFileAtomic } from "./fileCrypto.js";
11
+ function isV2Entry(entry) {
12
+ return entry.version === 2;
13
+ }
14
+ function stripChainFields(entry) {
15
+ const { prevMac: _prevMac, mac: _mac, ...rest } = entry;
16
+ return rest;
17
+ }
6
18
  const GENESIS_HASH = "GENESIS";
19
+ const AUDIT_LOG_HMAC_INFO = utf8ToBytes("raz-encrypt-audit-log-v1|hmac-key");
20
+ // A separate key for the head record, so a head MAC can never be mistaken for an entry MAC (ADR 0019).
21
+ const AUDIT_LOG_HEAD_INFO = utf8ToBytes("raz-encrypt-audit-log-v1|head-hmac-key");
22
+ // A separate key from both MAC keys above, same reasoning (ADR 0027) — never derived from a passphrase, since appendLogEntry/readLog only ever receive an Identity.
23
+ const AUDIT_LOG_ENC_INFO = utf8ToBytes("raz-encrypt-audit-log-v1|enc-key");
7
24
  function logFilePath(storageDir) {
8
25
  return join(storageDir, "log.jsonl");
9
26
  }
10
- function computeHash(entry) {
11
- return bytesToHex(sha384(utf8ToBytes(canonicalize(entry))));
27
+ function headFilePath(storageDir) {
28
+ return join(storageDir, "log.head.json");
29
+ }
30
+ /**
31
+ * HKDF-derived from BOTH the classical and PQC signing secrets (concatenated,
32
+ * same composition pattern as hybrid.ts's deriveHybridKey) — matching this
33
+ * library's hybrid posture everywhere else: compromising either secret key
34
+ * alone must not be enough to forge the chain. Recomputed fresh on every
35
+ * call, never persisted (ADR 0009).
36
+ */
37
+ function deriveAuditLogKey(identity) {
38
+ return hkdf(sha384, concatBytes(identity.classical.secretKey, identity.pqcSign.secretKey), undefined, AUDIT_LOG_HMAC_INFO, 32);
39
+ }
40
+ /**
41
+ * Keyed with deriveAuditLogKey — plain SHA-384 (ADR 0009's rejected
42
+ * approach) lets anyone with filesystem write access to log.jsonl forge the
43
+ * whole chain with no knowledge of the Identity's secret material at all.
44
+ * HMAC means forging it requires that secret. Generic over the entry's own
45
+ * shape (v1 plaintext fields, or v2's `{version,nonce,ciphertext}` — issue
46
+ * #43) since `canonicalize` doesn't care which fields are present; the chain
47
+ * mechanism itself never changes, only the bytes it authenticates.
48
+ */
49
+ function computeMac(identity, entry) {
50
+ return bytesToHex(hmac(sha384, deriveAuditLogKey(identity), utf8ToBytes(canonicalize(entry))));
51
+ }
52
+ /** Same derivation shape as deriveAuditLogKey, under its own info label (ADR 0027). */
53
+ function deriveAuditLogEncKey(identity) {
54
+ return hkdf(sha384, concatBytes(identity.classical.secretKey, identity.pqcSign.secretKey), undefined, AUDIT_LOG_ENC_INFO, 32);
55
+ }
56
+ /** Associated data for an entry's content AEAD: binds the ciphertext to its format version and its own nonce, same pattern as fileCrypto.ts's headerAad. */
57
+ function entryAad(nonce) {
58
+ return utf8ToBytes(canonicalize({ version: 2, nonce }));
59
+ }
60
+ function encryptEntryContent(identity, content) {
61
+ const nonceBytes = randomBytes(12);
62
+ const nonce = bytesToHex(nonceBytes);
63
+ const ciphertext = gcm(deriveAuditLogEncKey(identity), nonceBytes, entryAad(nonce)).encrypt(utf8ToBytes(canonicalize(content)));
64
+ return { nonce, ciphertext: bytesToHex(ciphertext) };
65
+ }
66
+ /** Throws (never returns something un-decrypted) if the entry doesn't authenticate under this identity's key. */
67
+ function decryptEntryContent(identity, entry) {
68
+ try {
69
+ const plaintext = gcm(deriveAuditLogEncKey(identity), hexToBytes(entry.nonce), entryAad(entry.nonce)).decrypt(hexToBytes(entry.ciphertext));
70
+ return JSON.parse(new TextDecoder().decode(plaintext));
71
+ }
72
+ catch (err) {
73
+ throw new Error(`Audit log entry failed to decrypt: ${err instanceof Error ? err.message : String(err)}`);
74
+ }
75
+ }
76
+ /**
77
+ * Constant-time MAC comparison (ADR 0009/0019's chain and head MACs are both
78
+ * HMAC-SHA384, so 96 lowercase hex chars). `candidate` is untrusted on-disk
79
+ * data of unknown shape: a non-string, wrong-length, or non-hex value is
80
+ * reported as a mismatch, never thrown, matching verifyKeyConfirmation's
81
+ * contract in crypto/hybrid.ts.
82
+ *
83
+ * Exported (ADR 0026) so the timing-safety test can exercise this exact
84
+ * compare in isolation, without the file I/O its only internal callers do.
85
+ */
86
+ export function macEquals(candidate, expected) {
87
+ if (typeof candidate !== "string" || !/^[0-9a-f]{96}$/.test(candidate))
88
+ return false;
89
+ return equalBytes(hexToBytes(candidate), hexToBytes(expected));
12
90
  }
13
91
  async function readStoredEntries(storageDir) {
14
92
  try {
@@ -16,7 +94,15 @@ async function readStoredEntries(storageDir) {
16
94
  return raw
17
95
  .split("\n")
18
96
  .filter((line) => line.trim().length > 0)
19
- .map((line) => JSON.parse(line));
97
+ .map((line) => {
98
+ const parsed = JSON.parse(line);
99
+ // A corrupted line can be valid JSON that isn't an object (e.g.
100
+ // `null`) — destructuring that downstream throws TypeError instead
101
+ // of being reported as a broken chain link. Coerce to an empty
102
+ // object so it flows safely through as a non-matching entry (found
103
+ // by fuzzing, issue #42).
104
+ return (typeof parsed === "object" && parsed !== null ? parsed : {});
105
+ });
20
106
  }
21
107
  catch (err) {
22
108
  if (err.code === "ENOENT")
@@ -24,39 +110,185 @@ async function readStoredEntries(storageDir) {
24
110
  throw err;
25
111
  }
26
112
  }
113
+ function computeHeadMac(identity, head) {
114
+ const key = hkdf(sha384, concatBytes(identity.classical.secretKey, identity.pqcSign.secretKey), undefined, AUDIT_LOG_HEAD_INFO, 32);
115
+ return bytesToHex(hmac(sha384, key, utf8ToBytes(canonicalize(head))));
116
+ }
117
+ async function readHead(identity) {
118
+ let raw;
119
+ try {
120
+ raw = await readFile(headFilePath(identity.storageDir), "utf8");
121
+ }
122
+ catch (err) {
123
+ if (err.code === "ENOENT")
124
+ return { state: "missing" };
125
+ throw err;
126
+ }
127
+ try {
128
+ const parsed = JSON.parse(raw);
129
+ const { headMac, ...rest } = parsed;
130
+ if (rest.version !== 1 ||
131
+ typeof rest.count !== "number" ||
132
+ !Number.isSafeInteger(rest.count) ||
133
+ rest.count < 0 ||
134
+ typeof rest.mac !== "string" ||
135
+ typeof headMac !== "string" ||
136
+ (rest.encrypted !== undefined && rest.encrypted !== true)) {
137
+ return { state: "invalid" };
138
+ }
139
+ // Only ever include `encrypted` when true, exactly as writeHead does —
140
+ // otherwise a legacy head record's canonicalized bytes (and therefore
141
+ // its headMac) would silently change underneath it.
142
+ const head = rest.encrypted === true ? { version: 1, count: rest.count, mac: rest.mac, encrypted: true } : { version: 1, count: rest.count, mac: rest.mac };
143
+ return macEquals(headMac, computeHeadMac(identity, head)) ? { state: "ok", head } : { state: "invalid" };
144
+ }
145
+ catch {
146
+ return { state: "invalid" };
147
+ }
148
+ }
149
+ /** Compares an already-read head against the entries on disk. Returns undefined when they agree (a head up to a few entries behind is fine: that is a crash between append and head update). */
150
+ function checkHeadAgainst(read, entries) {
151
+ if (read.state === "missing")
152
+ return entries.length === 0 ? undefined : { reason: "head-missing", brokenAtIndex: entries.length };
153
+ if (read.state === "invalid")
154
+ return { reason: "head-invalid", brokenAtIndex: entries.length };
155
+ const { count, mac } = read.head;
156
+ if (count > entries.length)
157
+ return { reason: "truncated", brokenAtIndex: entries.length };
158
+ const expected = count === 0 ? GENESIS_HASH : entries[count - 1].mac;
159
+ if (mac !== expected)
160
+ return { reason: "head-invalid", brokenAtIndex: entries.length };
161
+ return undefined;
162
+ }
163
+ async function checkHead(identity, entries) {
164
+ return checkHeadAgainst(await readHead(identity), entries);
165
+ }
166
+ async function writeHead(identity, count, mac, encrypted) {
167
+ const head = encrypted ? { version: 1, count, mac, encrypted: true } : { version: 1, count, mac };
168
+ await writeFileAtomic(headFilePath(identity.storageDir), JSON.stringify({ ...head, headMac: computeHeadMac(identity, head) }));
169
+ }
170
+ const appendState = new Map();
171
+ function stateFor(storageDir) {
172
+ const key = resolve(storageDir);
173
+ let state = appendState.get(key);
174
+ if (!state) {
175
+ state = { queue: Promise.resolve(), tail: null, headTrusted: true, encrypted: false };
176
+ appendState.set(key, state);
177
+ }
178
+ return state;
179
+ }
180
+ async function doAppend(identity, entry, state) {
181
+ const full = { ...entry, at: new Date().toISOString() };
182
+ if (!state.tail) {
183
+ const existing = await readStoredEntries(identity.storageDir);
184
+ const head = await readHead(identity);
185
+ state.tail = { mac: existing.length > 0 ? existing[existing.length - 1].mac : GENESIS_HASH, entryCount: existing.length };
186
+ state.headTrusted = checkHeadAgainst(head, existing) === undefined;
187
+ state.encrypted = head.state === "ok" && head.head.encrypted === true;
188
+ }
189
+ const content = state.encrypted ? { version: 2, ...encryptEntryContent(identity, full) } : { ...full };
190
+ const withPrev = { ...content, prevMac: state.tail.mac };
191
+ const mac = computeMac(identity, withPrev);
192
+ const stored = { ...withPrev, mac };
193
+ await mkdir(identity.storageDir, { recursive: true, mode: 0o700 });
194
+ await appendFile(logFilePath(identity.storageDir), JSON.stringify(stored) + "\n", { mode: 0o600 });
195
+ state.tail = { mac, entryCount: state.tail.entryCount + 1 };
196
+ // Never overwrite a head that already disagreed with the log: that would
197
+ // launder a truncation into a "clean" state.
198
+ if (state.headTrusted)
199
+ await writeHead(identity, state.tail.entryCount, mac, state.encrypted);
200
+ }
27
201
  /**
28
202
  * Appends one entry to the local, append-only audit log (public metadata
29
- * only — no secrets). Each entry is chained to the previous one's hash
30
- * (see verifyLogIntegrity) so tampering or deleting past entries is
31
- * detectable, not just theoretically append-only.
203
+ * only — no secrets). Each entry is chained to the previous one's MAC
204
+ * (see verifyLogIntegrity), keyed from identity's own secret material
205
+ * (ADR 0009) so tampering or deleting past entries is detectable by anyone
206
+ * EXCEPT someone who also holds that secret — not just theoretically
207
+ * append-only, and not forgeable by file-write access alone.
32
208
  */
33
209
  export async function appendLogEntry(identity, entry) {
34
- const full = { ...entry, at: new Date().toISOString() };
35
- const existing = await readStoredEntries(identity.storageDir);
36
- const prevHash = existing.length > 0 ? existing[existing.length - 1].hash : GENESIS_HASH;
37
- const withPrev = { ...full, prevHash };
38
- const stored = { ...withPrev, hash: computeHash(withPrev) };
39
- await mkdir(identity.storageDir, { recursive: true });
40
- await appendFile(logFilePath(identity.storageDir), JSON.stringify(stored) + "\n", { mode: 0o600 });
210
+ const state = stateFor(identity.storageDir);
211
+ // Chain onto the previous operation regardless of how it settled (a past
212
+ // failure must not permanently block future appends to this storageDir),
213
+ // but this call's own outcome — via `task`, awaited below — propagates to
214
+ // ITS caller untouched.
215
+ const task = state.queue.catch(() => { }).then(() => doAppend(identity, entry, state));
216
+ state.queue = task.catch(() => { });
217
+ await task;
41
218
  }
219
+ /** Transparently decrypts any v2 (encrypted, issue #43) entries alongside plaintext v1 ones. */
42
220
  export async function readLog(identity) {
43
- return (await readStoredEntries(identity.storageDir)).map(({ prevHash: _prevHash, hash: _hash, ...entry }) => entry);
221
+ return (await readStoredEntries(identity.storageDir)).map((entry) => (isV2Entry(entry) ? decryptEntryContent(identity, entry) : stripChainFields(entry)));
44
222
  }
45
223
  /**
46
- * Walks the hash chain and reports whether it's intact. If an entry was
224
+ * Walks the MAC chain and reports whether it's intact. If an entry was
47
225
  * edited or deleted, `brokenAtIndex` is the (0-based) index of the first
48
- * entry whose chain link no longer matches.
226
+ * entry whose chain link no longer matches. Recomputing a matching MAC
227
+ * requires identity's own secret material (see computeMac/deriveAuditLogKey)
228
+ * — this is what makes forging the chain require more than filesystem
229
+ * write access (ADR 0009). It also checks the authenticated head record
230
+ * (ADR 0019), so deleting the most recent entries is reported too, with
231
+ * `reason: "truncated"`.
232
+ *
233
+ * Not detectable: replacing BOTH log.jsonl and log.head.json with an older,
234
+ * consistent pair, or deleting both files outright. Keep an off-box copy of
235
+ * the head if that matters to you.
49
236
  */
50
237
  export async function verifyLogIntegrity(identity) {
51
238
  const entries = await readStoredEntries(identity.storageDir);
52
- let expectedPrevHash = GENESIS_HASH;
239
+ let expectedPrevMac = GENESIS_HASH;
53
240
  for (let i = 0; i < entries.length; i++) {
54
- const { prevHash, hash, ...rest } = entries[i];
55
- if (prevHash !== expectedPrevHash || hash !== computeHash({ ...rest, prevHash })) {
241
+ const { prevMac, mac, ...rest } = entries[i];
242
+ if (prevMac !== expectedPrevMac || !macEquals(mac, computeMac(identity, { ...rest, prevMac }))) {
56
243
  return { intact: false, brokenAtIndex: i };
57
244
  }
58
- expectedPrevHash = hash;
245
+ expectedPrevMac = mac;
59
246
  }
247
+ const problem = await checkHead(identity, entries);
248
+ if (problem)
249
+ return { intact: false, ...problem };
60
250
  return { intact: true };
61
251
  }
252
+ /**
253
+ * One-time, explicit opt-in (issue #43/ADR 0027) to encrypt the audit log's
254
+ * entry content, so filesystem access alone no longer reveals what actions
255
+ * this identity has performed. Re-encrypts every existing entry in one pass
256
+ * (there is no mixed-format file afterwards) and marks the head record so
257
+ * every later `appendLogEntry` call encrypts just the one entry it writes —
258
+ * never the whole log again. A no-op if the log is already encrypted.
259
+ * Throws if the log fails its integrity check first: there is nothing safe
260
+ * to migrate if the chain can't be trusted.
261
+ */
262
+ export async function migrateAuditLogToEncrypted(identity) {
263
+ const state = stateFor(identity.storageDir);
264
+ const task = state.queue.catch(() => { }).then(() => doMigrateToEncrypted(identity, state));
265
+ state.queue = task.catch(() => { });
266
+ await task;
267
+ }
268
+ async function doMigrateToEncrypted(identity, state) {
269
+ const head = await readHead(identity);
270
+ if (head.state === "ok" && head.head.encrypted === true)
271
+ return; // already encrypted — true no-op
272
+ const integrity = await verifyLogIntegrity(identity);
273
+ if (!integrity.intact) {
274
+ throw new Error("Cannot migrate: the audit log failed its integrity check. Investigate before encrypting it.");
275
+ }
276
+ const entries = await readStoredEntries(identity.storageDir);
277
+ let prevMac = GENESIS_HASH;
278
+ const rewritten = [];
279
+ for (const entry of entries) {
280
+ const content = isV2Entry(entry) ? decryptEntryContent(identity, entry) : stripChainFields(entry);
281
+ const { nonce, ciphertext } = encryptEntryContent(identity, content);
282
+ const withPrev = { version: 2, nonce, ciphertext, prevMac };
283
+ const mac = computeMac(identity, withPrev);
284
+ rewritten.push({ ...withPrev, mac });
285
+ prevMac = mac;
286
+ }
287
+ await mkdir(identity.storageDir, { recursive: true, mode: 0o700 });
288
+ await writeFileAtomic(logFilePath(identity.storageDir), rewritten.map((entry) => JSON.stringify(entry)).join("\n") + (rewritten.length > 0 ? "\n" : ""));
289
+ await writeHead(identity, rewritten.length, prevMac, true);
290
+ state.tail = { mac: prevMac, entryCount: rewritten.length };
291
+ state.headTrusted = true;
292
+ state.encrypted = true;
293
+ }
62
294
  //# sourceMappingURL=store.js.map
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiBlD,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,SAAS,WAAW,C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IAED,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACnE,MAAM,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzJ,MAAM,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAE3D,KAAK,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;IAC5D,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;AACzB,CAAC"}
package/dist/trust.d.ts CHANGED
@@ -1,16 +1,62 @@
1
- import type { Identity, PublicCard } from "./identity.js";
1
+ import { type Certificate, type VerifyResult } from "./crypto/hybrid.js";
2
+ import { type Identity, type PublicCard } from "./identity.js";
2
3
  export interface TrustRecord {
3
4
  card: PublicCard;
4
5
  trustedAt: string;
5
6
  /** Set when this party was later revoked (see untrustParty). Absent = still trusted. */
6
7
  revokedAt?: string;
8
+ /**
9
+ * Set alongside revokedAt when this record was tombstoned by a verified
10
+ * rotation (applyRotation), not an ordinary revocation: the fingerprint of
11
+ * the card this party rotated TO. Informational only — verify() still
12
+ * reports "revoked-signer" for this record either way (ADR 0023/issue
13
+ * #37); nothing reads this field to change verification behavior.
14
+ */
15
+ rotatedTo?: string;
7
16
  }
17
+ type Entries = Record<string, TrustRecord>;
18
+ /**
19
+ * Thrown when trust.json cannot be trusted: its MAC does not verify (edited,
20
+ * truncated, copied from another identity), it is not valid JSON, or it is an
21
+ * unauthenticated legacy file that was never explicitly adopted with
22
+ * `migrateLegacyTrustStore`. Everything that consults the trust list fails
23
+ * closed on this rather than reading a file anyone with filesystem access
24
+ * could have written.
25
+ */
26
+ export declare class TrustStoreIntegrityError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /**
30
+ * Exported (ADR 0026) so the timing-safety test can exercise this exact
31
+ * compare in isolation, without the file I/O its only internal callers do.
32
+ */
33
+ export declare function macMatches(identity: Identity, entries: Entries, mac: unknown): boolean;
34
+ /**
35
+ * One-time, explicit opt-in (issue #43/ADR 0027) to encrypt `trust.json`'s
36
+ * entries, so filesystem access alone no longer reveals who this identity
37
+ * trusts. A no-op if the store is already v4. A legacy (unauthenticated) file
38
+ * is not implicitly adopted here — call `migrateLegacyTrustStore` first, same
39
+ * as reading it would require.
40
+ */
41
+ export declare function migrateTrustStoreToEncrypted(identity: Identity): Promise<void>;
42
+ /**
43
+ * One-time, explicit adoption of a trust.json written before trust-store
44
+ * MACs existed (a v1 alias map or a v2 fingerprint-keyed file). Those files
45
+ * carry no proof of who wrote them, so they are never read implicitly (an
46
+ * attacker could otherwise plant one and bypass the MAC). Calling this says
47
+ * "I have reviewed the current file and it is mine": its records are kept
48
+ * and the file is rewritten authenticated. Returns the number of records
49
+ * adopted; returns 0 and changes nothing if the file is missing or already
50
+ * authenticated (a modified authenticated file still throws).
51
+ */
52
+ export declare function migrateLegacyTrustStore(identity: Identity): Promise<number>;
8
53
  /**
9
54
  * Records another party's public card as trusted, keyed by the card's
10
55
  * fingerprint (not alias — two different real parties could otherwise pick
11
56
  * the same alias and silently overwrite each other). Public keys are not
12
57
  * secret, so this file is plain JSON (unlike identity.enc.json), though it's
13
- * still permission-restricted to the owning user.
58
+ * permission-restricted to the owning user and, since ADR 0015, carries an
59
+ * HMAC (keyed from the Identity's secret keys) so edits are detected.
14
60
  *
15
61
  * Trusting a card again after it was revoked reinstates it (clears revokedAt).
16
62
  */
@@ -23,6 +69,14 @@ export declare function trustParty(identity: Identity, card: PublicCard): Promis
23
69
  * "untrusted-signer" (never trusted at all).
24
70
  */
25
71
  export declare function untrustParty(identity: Identity, alias: string): Promise<void>;
72
+ /**
73
+ * Revokes exactly one card, identified by its `fingerprint(card)` string
74
+ * (spaces and case are ignored). Unlike `untrustParty`, parties that merely
75
+ * share an alias are untouched — alias is a non-unique display label.
76
+ * Returns true if a currently-trusted record was revoked, false if no such
77
+ * trusted record exists (a typo'd fingerprint is reported, not ignored).
78
+ */
79
+ export declare function untrustFingerprint(identity: Identity, fingerprintValue: string): Promise<boolean>;
26
80
  /** Every currently-trusted (non-revoked) card. */
27
81
  export declare function listTrustedParties(identity: Identity): Promise<PublicCard[]>;
28
82
  /** Every trust record ever made, revoked or not — for audit/history purposes. */
@@ -39,3 +93,90 @@ export declare function getTrustedParty(identity: Identity, alias: string): Prom
39
93
  export declare function getTrustedPartiesByAlias(identity: Identity, alias: string): Promise<PublicCard[]>;
40
94
  /** All trust records (revoked or not) recorded under this alias. */
41
95
  export declare function getTrustRecordsByAlias(identity: Identity, alias: string): Promise<TrustRecord[]>;
96
+ /**
97
+ * Verifies a self-signed card (from `exportSignedCard`) — checks the
98
+ * signature is self-consistent (the certificate's signer IS the card it's
99
+ * attached to) and, if the card carries an `expiresAt`, that it hasn't
100
+ * passed. Only on success does this call the ordinary `trustParty` to
101
+ * actually record it — self-signing proves the card is authentic and
102
+ * current, not that you've decided to trust it (Fingerprint confirmation
103
+ * is still the human-level trust decision, same as a bare card).
104
+ */
105
+ export declare function trustSignedCard(identity: Identity, card: PublicCard, certificate: Certificate): Promise<VerifyResult>;
106
+ export interface RotationDocument {
107
+ oldCard: PublicCard;
108
+ newCard: PublicCard;
109
+ rotatedAt: string;
110
+ }
111
+ export interface RotationStatement {
112
+ document: RotationDocument;
113
+ oldCertificate: Certificate;
114
+ newCertificate: Certificate;
115
+ }
116
+ /**
117
+ * Starts a key rotation: the OLD identity signs a statement naming `newCard`
118
+ * as its successor. Hand the result to `completeRotation`, called with the
119
+ * NEW identity, to get a complete, dual-signed RotationStatement — a single
120
+ * signature from the old key alone is never enough to redirect a peer's
121
+ * trust (see `applyRotation`), so this function's output is not yet usable
122
+ * on its own.
123
+ */
124
+ export declare function beginRotation(oldIdentity: Identity, newCard: PublicCard, options?: {
125
+ rotatedAt?: string;
126
+ }): Promise<{
127
+ document: RotationDocument;
128
+ oldCertificate: Certificate;
129
+ }>;
130
+ /**
131
+ * Finishes a key rotation: the NEW identity signs the SAME document
132
+ * `beginRotation` produced, proving the new key exists and agrees to be
133
+ * named as successor — not just asserted unilaterally by whoever holds the
134
+ * old key (which could be an attacker who compromised it alone).
135
+ */
136
+ export declare function completeRotation(newIdentity: Identity, draft: {
137
+ document: RotationDocument;
138
+ oldCertificate: Certificate;
139
+ }): Promise<RotationStatement>;
140
+ /**
141
+ * Verifies a RotationStatement (both signatures self-consistent, both
142
+ * certificates over the identical document) and, only if `oldCard` already
143
+ * has an existing Trust Record, moves trust to `newCard` and tombstones
144
+ * `oldCard`'s record (revokedAt set, plus rotatedTo pointing at newCard's
145
+ * fingerprint). A statement for a card you never trusted is a no-op — this
146
+ * is not a way to seed your trust store with a card you never decided to
147
+ * trust in the first place.
148
+ */
149
+ export declare function applyRotation(identity: Identity, statement: RotationStatement): Promise<VerifyResult>;
150
+ export interface RevocationDocument {
151
+ revokedCard: PublicCard;
152
+ revokedAt: string;
153
+ reason?: string;
154
+ }
155
+ /** A Certificate only stores its document's HASH, not the document itself (same as everywhere else in this codebase) — so a revocation notice bundles the document alongside its certificate, the same shape RotationStatement already uses for the same reason. */
156
+ export interface RevocationNotice {
157
+ document: RevocationDocument;
158
+ certificate: Certificate;
159
+ }
160
+ /**
161
+ * Produces a self-signed, portable revocation notice for `identity`'s own
162
+ * card — verifiable by any peer independently of their (or your) local
163
+ * trust-store state. The same function works whether called reactively
164
+ * (retiring a key now) or right after createIdentity, to be stored
165
+ * separately and used later if this identity becomes inaccessible — that's
166
+ * what actually makes "recovery" possible for a lost passphrase or a lost
167
+ * identity file (ADR 0023): there is no special "pre-generated" mode, it's
168
+ * the same notice either way.
169
+ */
170
+ export declare function createRevocationNotice(identity: Identity, options?: {
171
+ reason?: string;
172
+ }): Promise<RevocationNotice>;
173
+ /**
174
+ * Verifies a revocation notice (self-consistent, well-formed, `revokedAt`
175
+ * a valid ISO instant) and, only if the named card already has an existing
176
+ * Trust Record, tombstones it (revokedAt set) — exactly like
177
+ * `untrustFingerprint`. A notice for a card you never trusted is a no-op,
178
+ * for the same reason `applyRotation` is: this is not a pre-emptive
179
+ * denylist feature.
180
+ */
181
+ export declare function applyRevocationNotice(identity: Identity, notice: RevocationNotice): Promise<VerifyResult>;
182
+ export {};