code wiki / _hdl_build / nx_succession_recover_gate.nx
nx_succession_recover_gate.nx source
↩ module page · 94 lines · 4724 B
1// nx_succession_recover_gate.nx -- REFEREE for attestation-gated succession (the death/incapacity path).
2// Splits a master secret into a succession quorum, mints a designated-authority ed25519 key, signs a death
3// attestation, and proves recovery happens ONLY with a genuine, correctly-targeted attestation:
4// T1 valid death attestation + quorum -> master RECOVERED (== expected)
5// T2 attestation signed by the WRONG authority -> REFUSED (BAD_ATTEST) (can't forge the signer)
6// T3 attestation for a DIFFERENT person/event -> REFUSED (WRONG_EVENT) (no replay onto another user)
7// T4 tampered attestation signature -> REFUSED (BAD_ATTEST)
8// GREEN iff T1..T4. Sovereign: nx_succession_recover + nx_social_recovery + ed25519 + nx_syscalls. license_tier: ORIGINAL
9import "nx_succession_recover.nx"
10import "nx_syscalls.nx"
11
12func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
13func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
14func g_row(name: *u8, ok: i64) -> i64 {
15 if ok == 1 { g_w(" PASS " as *u8) }
16 if ok != 1 { g_w(" FAIL " as *u8) }
17 g_w(name)
18 g_w("\n" as *u8)
19 return ok
20}
21func g_eq32(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while i < SR_KEY_BYTES { if (a[i] as i64) != (b[i] as i64) { return 0 } i = i + 1 } return 1 }
22
23func main() -> i64 {
24 g_w("succession gate: attestation-gated recovery (proven death/incapacity required)\n" as *u8)
25
26 // ---- master secret + succession quorum (N=3 contacts, use any 2 as the quorum) ----
27 let master: *u8 = sys_mmap(SR_KEY_BYTES)
28 var i: i64 = 0
29 while i < SR_KEY_BYTES { master[i] = ((i * 5 + 1) & 0xff) as u8; i = i + 1 }
30 let shares: *i64 = sys_mmap(3 * SR_CHUNKS * 8) as *i64
31 if nx_sr_split(master, 3, 2, shares) != 0 { g_w("SPLIT FAIL\n" as *u8); sys_exit(1) }
32 let xs: *i64 = sys_mmap(2 * 8) as *i64
33 xs[0] = 1
34 xs[1] = 2
35 let sin: *i64 = sys_mmap(2 * SR_CHUNKS * 8) as *i64
36 var c: i64 = 0
37 while c < SR_CHUNKS { sin[c] = shares[c]; sin[SR_CHUNKS + c] = shares[SR_CHUNKS + c]; c = c + 1 }
38
39 // ---- designated attesting authority keypair (court / notary / firm) ----
40 let apriv: *u8 = sys_mmap(32)
41 i = 0
42 while i < 32 { apriv[i] = ((i * 3 + 7) & 0xff) as u8; i = i + 1 }
43 let apub: *u8 = sys_mmap(32)
44 ed25519_pub_from_priv(apriv, apub)
45
46 // ---- the death attestation document, signed by the authority ----
47 let event: *u8 = "DEATH:elder-client-001:2026-06-16:cert#A7731" as *u8
48 let elen: i64 = g_len(event)
49 let sig: *u8 = sys_mmap(64)
50 ed25519_sign_full(apriv, event, elen, sig)
51
52 let rec: *u8 = sys_mmap(SR_KEY_BYTES)
53 var pass: i64 = 0
54
55 // ---- T1: valid attestation + quorum -> recovered == master ----
56 var t1: i64 = 0
57 if nx_succession_recover(apub, event, elen, sig, event, elen, 2, xs, sin, rec) == NX_SUCC_OK {
58 if g_eq32(rec, master) == 1 { t1 = 1 }
59 }
60 pass = pass + g_row("T1 valid death attestation + quorum -> master RECOVERED\x00" as *u8, t1)
61
62 // ---- T2: attestation signed by the WRONG authority -> REFUSED ----
63 let wpriv: *u8 = sys_mmap(32)
64 i = 0
65 while i < 32 { wpriv[i] = ((i * 9 + 2) & 0xff) as u8; i = i + 1 }
66 let wsig: *u8 = sys_mmap(64)
67 ed25519_sign_full(wpriv, event, elen, wsig)
68 var t2: i64 = 0
69 if nx_succession_recover(apub, event, elen, wsig, event, elen, 2, xs, sin, rec) == (0 - NX_SUCC_BAD_ATTEST) { t2 = 1 }
70 pass = pass + g_row("T2 forged attestation (wrong authority) -> REFUSED\x00" as *u8, t2)
71
72 // ---- T3: attestation for a DIFFERENT person/event -> REFUSED ----
73 let other: *u8 = "DEATH:someone-else-999:2026-06-16:cert#B0002" as *u8
74 let olen: i64 = g_len(other)
75 let osig: *u8 = sys_mmap(64)
76 ed25519_sign_full(apriv, other, olen, osig)
77 var t3: i64 = 0
78 if nx_succession_recover(apub, other, olen, osig, event, elen, 2, xs, sin, rec) == (0 - NX_SUCC_WRONG_EVENT) { t3 = 1 }
79 pass = pass + g_row("T3 attestation for a DIFFERENT person -> REFUSED\x00" as *u8, t3)
80
81 // ---- T4: tampered attestation signature -> REFUSED ----
82 let tsig: *u8 = sys_mmap(64)
83 c = 0
84 while c < 64 { tsig[c] = sig[c]; c = c + 1 }
85 tsig[10] = ((tsig[10] as i64) ^ 1) as u8
86 var t4: i64 = 0
87 if nx_succession_recover(apub, event, elen, tsig, event, elen, 2, xs, sin, rec) == (0 - NX_SUCC_BAD_ATTEST) { t4 = 1 }
88 pass = pass + g_row("T4 tampered attestation signature -> REFUSED\x00" as *u8, t4)
89
90 if pass == 4 { g_w("SUCCESSION GATE GREEN 4/4 (recovery needs a genuine, person-bound death/incapacity attestation)\n" as *u8); sys_exit(0) }
91 g_w("SUCCESSION GATE RED\n" as *u8)
92 sys_exit(1)
93 return 1
94}