code wiki / _hdl_build / nx_succession_recover.nx
nx_succession_recover.nx source
↩ module page · 42 lines · 2913 B
1// nx_succession_recover.nx -- ATTESTATION-GATED succession recovery: the worst-case path for when the user
2// AND their family are gone (Alzheimer's / sudden death), especially for lawyer clients whose files must
3// outlive both client and attorney. Recovery returns the master secret ONLY when BOTH hold:
4// (1) a QUORUM of succession shares reconstructs it (Shamir, nx_social_recovery) -- e.g. executor + a
5// designated attestor + successor-attorney, held by parties named in the legal instruments; AND
6// (2) a valid ATTESTATION -- an ed25519-signed document (death certificate / incapacity declaration / court
7// order) from the DESIGNATED authority, bound to THIS user+event so a stale/foreign attestation can't be
8// replayed. No valid attestation => no recovery, even if the shares are present.
9// The crypto ENFORCES the legal succession (the authority signs only on real proof); every recovery is meant
10// to be written to the tamper-evident audit log (nx_access_audit). This is policy + cryptography together:
11// the quorum is the cryptographic floor, the attestation is the authorization + audit anchor.
12// license_tier: ORIGINAL (composes nx_social_recovery Shamir + KAT-verified ed25519)
13import "nx_social_recovery.nx"
14import "nx_ed25519_signature.nx"
15import "nx_syscalls.nx"
16
17const NX_SUCC_OK: i64 = 0
18const NX_SUCC_WRONG_EVENT: i64 = 1 // attestation document != the expected user+event (replay / wrong person)
19const NX_SUCC_BAD_ATTEST: i64 = 2 // signature not from the designated authority (forged / tampered)
20
21func succ_eq(a: *u8, b: *u8, n: i64) -> i64 {
22 var i: i64 = 0
23 while i < n { if (a[i] as i64) != (b[i] as i64) { return 0 } i = i + 1 }
24 return 1
25}
26
27// Recover the master secret iff the attestation is the EXPECTED event, signed by the DESIGNATED authority,
28// and the quorum reconstructs. Returns NX_SUCC_OK (0) or a negative NX_SUCC_* code (refused, secret untouched).
29func nx_succession_recover(
30 attestor_pub: *u8, // designated attesting authority's ed25519 public key (32)
31 attest_msg: *u8, attest_len: i64, // the presented attestation document
32 attest_sig: *u8, // ed25519 signature over the document (64)
33 expected_event: *u8, event_len: i64, // what the document MUST say (binds to THIS user+event)
34 k: i64, xs: *i64, shares_in: *i64, // the succession quorum's K shares + their x-coords
35 secret_out: *u8 // 32-byte master recovered here on success
36) -> i64 {
37 if attest_len != event_len { return 0 - NX_SUCC_WRONG_EVENT }
38 if succ_eq(attest_msg, expected_event, event_len) != 1 { return 0 - NX_SUCC_WRONG_EVENT }
39 if ed25519_verify_full(attestor_pub, attest_msg, attest_len, attest_sig) != NX_ED25519_SIG_OK { return 0 - NX_SUCC_BAD_ATTEST }
40 nx_sr_reconstruct(k, xs, shares_in, secret_out)
41 return NX_SUCC_OK
42}