LogChain
MMO\core\helpers · 1 symbol · generated 30 Nov 2026
LogChain
LogChain.php:22A journal whose lines cannot be changed, removed or put back without it showing (ISO/IEC 27001 A.8.15, A.5.28, A.5.33): each line carries, in its FIELD, its number (seq), the hash of the line before (previous) and its own (hash), the SHA-256 of those and of its content. Changing a line changes its hash; removing one leaves a gap in the numbers; rewriting one's hash breaks the next line's previous.
- Namespace
MMO\core\helpers- See
Verifyreads them back (php admin.php log-verify). A purge removes the oldest lines only, and keeps the last one it removes as a seal ({seq, hash}): the first line left chains to it.
Index
| FIELD | the key of a line holding its link: {seq: int, previous: ?string, hash: string} | |
| MAX_BREAKS | the most breaks Verify lists: past one, the chain is broken already | |
| Canonical($document) static | The text a line is hashed as: its content, without its link, as json, the keys of each map sorted -- what it reads back from its database (a BSON type as its extended json, mmo.mongodb's ObjectId a… | |
| Hash($document, $seq, $previous) static | ||
| IdOf($document) static | ||
| Link($document, $previous) static | The link of $document, after the line (or the seal) $previous | |
| Normalize($value) static | ||
| ParseHead($head) static | ||
| Verify($documents, $anchor, $expect) static | Read a chain back and tell where it breaks. |
Constants2
FIELD
the key of a line holding its link: {seq: int, previous: ?string, hash: string}
MAX_BREAKS
the most breaks Verify lists: past one, the chain is broken already
Methods7
Canonical($document)
staticLogChain.php:35The text a line is hashed as: its content, without its link, as json, the keys of each map sorted -- what it reads back from its database (a BSON type as its extended json, mmo.mongodb's ObjectId as {"$oid": ...}) is what it was written with.
Hash($document, $seq, $previous)
staticLogChain.php:60| $document | array | the line (its FIELD left out) |
| $seq | int | its number in the chain: 1 for the first line |
| $previous | null | string | the hash of the line before, null for the first |
| returns | string | the hash of the line: SHA-256, in hexadecimal |
IdOf($document)
staticLogChain.php:138Link($document, $previous)
staticLogChain.php:71The link of $document, after the line (or the seal) $previous
| $document | array | |
| $previous | null | array | |
| returns | array | int, previous: ?string, hash: string} what $document stores in FIELD |
Normalize($value)
staticLogChain.php:41ParseHead($head)
staticLogChain.php:148| $head | string | <seq>:<hash>, as log-verify prints it |
| returns | null | array | int, hash: string} null when $head is not one |
Verify($documents, $anchor, $expect)
staticLogChain.php:90| $documents | iterable | the chained lines (arrays: a cursor's documents), by seq ascending |
| $anchor = null | null | array | |
| $expect = null | null | array | |
| returns | array | bool, count: int, first: ?int, head: ?array{seq: int, hash: string}, breaks: list<array<string, int|string>>} |