Purpose. Compact, language-agnostic pseudocode so any team can implement the core. Everything is plain ASCII; the canonical line is SSMCLOCK1|iso_utc|rasi_idx|theta_deg|sha256(file)|chain[|kv:...].
Utilities (pure functions)
wrap360(x) = x - 360*floor(x/360)theta_deg = wrap360( (unix_seconds / 86400) * 360 )rasi_idx = floor(theta_deg / 30)chain_k = H_chain( ascii(chain_{k-1} + "|" + stamp_core) )withchain_0 = "0"*64rollup_D = sha256( ascii(Stamp_1 "|" ... "|" Stamp_n) )(anchor fixed to sha256)
Helper signatures (ASCII):
ascii(s) -> bytes_ascii(reject anyord(c) > 127)hex64_lower_ok(h) -> bool(len==64and[0-9a-f])parse_iso_utc_Z(s) -> int_seconds(requireYYYY-MM-DDTHH:MM:SSZ, forbid:60)bankers_round_string(x, frac_digits) -> string(round-half-to-even)select_hash(name) -> func(one ofsha256_hex,sha3_256_hex,blake2b_256_hex)parse_kv_tail("kv:k1=v1;...") -> map(unknown keys allowed)kv_with_defaults(m) -> map(defaults:algo=sha256; chain_algo=sha256; theta_prec=5; float=ieee75464; time_mode=derived_utc)
Emit one stamp line (single file)
Function (essential steps):make_stamp_line(file_bytes, iso_utc, prev_chain, kv_map) -> stamp_line
- Policy defaults:
cfg = kv_with_defaults(kv_map or {}) - UTC → epoch:
unix = parse_iso_utc_Z(iso_utc) - Clock:
theta = wrap360( (unix / 86400.0) * 360.0 ),rasi = floor(theta / 30.0)
Print:theta_str = bankers_round_string(theta, int(cfg["theta_prec"])) - File digest:
H = select_hash(cfg["algo"]),h_file = H(file_bytes) - Core:
stamp_core = "SSMCLOCK1|" + iso_utc + "|" + str(rasi) + "|" + theta_str + "|" + h_file - Chain:
prev = prev_chain or "0"*64;Hc = select_hash(cfg["chain_algo"]);chain = Hc( ascii(prev + "|" + stamp_core) ) - Final line:
- no kv:
stamp_core + "|" + chain - with kv:
stamp_core + "|" + chain + "|kv:" + "k1=v1;...;"(no spaces,|and;not allowed inside values)
- no kv:
Verify single (sidecar + file)
Function: verify_file_against_stamp(file_bytes, stamp_line) -> {HASH_OK, CLOCK_OK, CHAIN_OK, VERDICT}
- Split by
|; requireparts[0] == "SSMCLOCK1"and arity6or7. - Parse:
iso_utc, rasi_s, theta_s, h_rec, chain_rec(and optionalkv). - Enforce shapes: UTC
...Z(no:60),rasi ∈ {0..11},h_recandchain_recare lowercase 64-hex. - Hash:
H = select_hash(cfg["algo"]);h' = H(file_bytes);HASH_OK = (h' == h_rec). - Clock:
unix = parse_iso_utc_Z(iso_utc);theta' = wrap360((unix/86400)*360);rasi' = floor(theta'/30);CLOCK_OKrequiresrasi' == rasi.
Recommended string check:theta_prec = int(cfg["theta_prec"]);theta_str' = bankers_round_string(theta', theta_prec);
iftheta_str' != theta_s, optionally accept numeric toleranceabs(theta' - float(theta_s)) <= 0.5*10^(-theta_prec). CHAIN_OK = "na"here (done in ledger walk).VERDICT = "PASS"ifHASH_OKandCLOCK_OK(and any provided chain/anchor checks elsewhere).
Ledger rewalk (append-only continuity)
Function: rewalk_ledger(ledger_rows) -> {LEDGER_OK, tip, row|reason}
For rows with fields {iso_utc, rasi_idx, theta_deg, digest, chain, kv_tail?}:
prev = "0"*64- For each row
k:core_k = "SSMCLOCK1|" + iso + "|" + rasi + "|" + theta + "|" + digestHc = select_hash(row.kv.chain_algo or "sha256")calc = Hc( ascii(prev + "|" + core_k) )- Require
calc == row.chain; else return first failingk. prev = calc
- Return
{LEDGER_OK=true, tip=prev}
Roll-up and anchor verify (UTC day)
Canonical order key: (iso_utc, stamp_core, chain) (all ascending, string compare).
Digest: rollup_D = sha256( ascii(Stamp_1 "|" ... "|" Stamp_n) ).
Functions:
canonical_sort(stamp_lines) -> lines_sorted(derivestamp_corefrom each line; sort by(iso_utc, stamp_core, chain))rollup_digest(stamp_lines) -> {count, rollup_D}(empty set ⇒sha256( ascii("") ))verify_anchor_for_day(stamps_from_ledger, stamps_from_sidecars, note) -> {ANCHOR_LEDGER_OK, ANCHOR_SIDECARS_OK, VERDICT}where note hasdate,count,rollup_sha256,source.
Verify-all harness (files, ledger, anchors)
Function: verify_all(files, sidecars_map, ledger_rows, anchor_note) -> summary
- For each
(path, line)in sidecars: verify single; count PASS/FAIL; track orphans. L = rewalk_ledger(ledger_rows)- Build day sets from ledger/sidecars;
A = verify_anchor_for_day(...) - Summarize:
files_verified,PASS,FAIL,ORPHANS,LEDGER_OK,ANCHOR_VERDICT.
Determinism & equality hints (checklist)
iso_utcmust be UTC...Zonly; reject offsets and:60.- Print
theta_degwith exactlytheta_precdigits (default5), round-half-to-even. - All digests are lowercase 64-hex; enforce
hex64_lower_ok. - All hashing inputs are
ascii(...)of the literal strings. - Roll-up join is exactly
"Stamp_1|...|Stamp_n"(literal|, no leading/trailing). - Per-stamp algorithms come from the optional
kv:tail; anchors always usesha256over the ASCII-joined stamp lines.
Navigation
Back: SSM-Clock Stamp – Glossary & Notation (10)
Next: SSM-Clock Stamp – Q&A (12A)