code wiki / _hdl_build / nx_legal_compliance_gate.nx

nx_legal_compliance_gate.nx source

↩ module page · 162 lines · 8159 B

1// nx_legal_compliance_gate.nx -- GATE for LEGAL D0 (nx_legal_compliance). 2// 3// Drives the REAL classifier + regime selector + validity machine and asserts: 4// 5// CLASSIFIER (the precision a generic e-sign product lacks): 6// "Last Will and Testament" -> WILL (excluded); "Living Will" -> 7// ADVANCE_DIRECTIVE (NOT a will, e-signable); "Revocable Living Trust" -> 8// TRUST_LIVING (e-signable); "Testamentary Trust" -> TESTAMENTARY_TRUST 9// (excluded); "Codicil ..." -> CODICIL; contract/POA/deed classify. 10// 11// UETA GENERAL : a contract with intent+consent+attribution+retainable -> 12// VALID/UETA_GENERAL; drop consent or retainable -> NEEDS_MORE with the 13// exact missing-element reason (drives the concierge "what's left" UX). 14// 15// E-WILLS REGIME : a will in a jurisdiction that permits e-wills, executed 16// with testator intent + attribution + >=2 witnesses + notarization + 17// retainable -> VALID/ELECTRONIC_WILLS; one witness -> NEEDS_MORE(2_WITNESS). 18// 19// *** NEVER-VOID INVARIANT (the safety crux -- legal Rule 26) *** 20// EXHAUSTIVE sweep: for EVERY excluded testamentary type (will/codicil/ 21// testamentary trust), across ALL 2^4 combinations of the general UETA 22// elements and BOTH jurisdiction settings, with no witnesses/notary, the 23// verdict is NEVER VALID. A naive DocuSign-clone would return VALID and 24// produce a legally VOID instrument; this engine cannot, by construction. 25// Plus: an excluded doc in a no-e-wills jurisdiction -> INVALID_VOID/ 26// REQUIRES_WET (never electronically executable). 27// 28// Evidence -> knowledge/status/legal_compliance.log 29// license_tier: ORIGINAL 30import "nx_legal_compliance.nx" 31import "nx_syscalls.nx" 32 33const LC_LOG: *u8 = "knowledge/status/legal_compliance.log" 34 35func ew(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 36func ewn(fd: i64, v: i64) -> i64 { 37 let bb: *u8 = sys_mmap(28); var m: i64 = v 38 if m < 0 { m = 0 - m; sys_write(fd, "-" as *u8, 1) } 39 let t: *u8 = sys_mmap(28); var k: i64 = 0 40 if m == 0 { t[0] = 48; k = 1 } 41 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 42 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 43 sys_write(fd, bb, k); return 0 44} 45 46// EXHAUSTIVE never-void sweep for one excluded doc type: across both 47// jurisdiction settings and all 16 combos of general UETA elements (with 48// witnesses=0, notarized=0), the verdict must NEVER be VALID. Returns 1 if the 49// invariant holds, 0 if ANY combo slipped through as VALID. 50func sweep_excluded(doc_type: i64, reason: *i64, regime: *i64) -> i64 { 51 var holds: i64 = 1 52 var ewa: i64 = 0 53 while ewa <= 1 { 54 var combo: i64 = 0 55 while combo < 16 { 56 let intent: i64 = combo & 1 57 let consent: i64 = (combo >> 1) & 1 58 let attribution: i64 = (combo >> 2) & 1 59 let retainable: i64 = (combo >> 3) & 1 60 let v: i64 = nx_legal_verdict(doc_type, ewa, intent, consent, attribution, retainable, 0, 0, reason, regime) 61 if v == LV_VALID { holds = 0 } 62 combo = combo + 1 63 } 64 ewa = ewa + 1 65 } 66 return holds 67} 68 69func main() -> i64 { 70 var ok: i64 = 1 71 let reason: *i64 = sys_mmap(8) as *i64 72 let regime: *i64 = sys_mmap(8) as *i64 73 74 // ---- CLASSIFIER (living vs testamentary precision) ---- 75 var classify_ok: i64 = 1 76 if nx_legal_doc_classify("Last Will and Testament" as *u8) != DT_WILL { classify_ok = 0 } 77 if nx_legal_doc_classify("Living Will" as *u8) != DT_ADVANCE_DIRECTIVE { classify_ok = 0 } 78 if nx_legal_doc_classify("Advance Healthcare Directive" as *u8) != DT_ADVANCE_DIRECTIVE { classify_ok = 0 } 79 if nx_legal_doc_classify("Revocable Living Trust" as *u8) != DT_TRUST_LIVING { classify_ok = 0 } 80 if nx_legal_doc_classify("Testamentary Trust Agreement" as *u8) != DT_TESTAMENTARY_TRUST { classify_ok = 0 } 81 if nx_legal_doc_classify("Codicil to Last Will" as *u8) != DT_CODICIL { classify_ok = 0 } 82 if nx_legal_doc_classify("Durable Power of Attorney" as *u8) != DT_POA { classify_ok = 0 } 83 if nx_legal_doc_classify("Quitclaim Deed" as *u8) != DT_DEED { classify_ok = 0 } 84 if nx_legal_doc_classify("Client Engagement Agreement" as *u8) != DT_CONTRACT { classify_ok = 0 } 85 if classify_ok != 1 { ok = 0 } 86 87 // ---- UETA GENERAL ---- 88 var ueta_ok: i64 = 1 89 let v1: i64 = nx_legal_verdict(DT_CONTRACT, 1, 1, 1, 1, 1, 0, 0, reason, regime) 90 if v1 != LV_VALID { ueta_ok = 0 } 91 if *regime != RG_UETA_GENERAL { ueta_ok = 0 } 92 if *reason != LR_OK_UETA { ueta_ok = 0 } 93 let v2: i64 = nx_legal_verdict(DT_CONTRACT, 1, 1, 0, 1, 1, 0, 0, reason, regime) 94 if v2 != LV_NEEDS_MORE { ueta_ok = 0 } 95 if *reason != LR_NO_CONSENT { ueta_ok = 0 } 96 let v3: i64 = nx_legal_verdict(DT_CONTRACT, 1, 1, 1, 1, 0, 0, 0, reason, regime) 97 if v3 != LV_NEEDS_MORE { ueta_ok = 0 } 98 if *reason != LR_NOT_RETAINABLE { ueta_ok = 0 } 99 if ueta_ok != 1 { ok = 0 } 100 101 // ---- E-WILLS REGIME ---- 102 var ewills_ok: i64 = 1 103 let w1: i64 = nx_legal_verdict(DT_WILL, 1, 1, 0, 1, 1, 2, 1, reason, regime) 104 if w1 != LV_VALID { ewills_ok = 0 } 105 if *regime != RG_ELECTRONIC_WILLS { ewills_ok = 0 } 106 if *reason != LR_OK_EWILLS { ewills_ok = 0 } 107 let w2: i64 = nx_legal_verdict(DT_WILL, 1, 1, 0, 1, 1, 1, 1, reason, regime) 108 if w2 != LV_NEEDS_MORE { ewills_ok = 0 } 109 if *reason != LR_NEED_2_WITNESS { ewills_ok = 0 } 110 if ewills_ok != 1 { ok = 0 } 111 112 // ---- NEVER-VOID INVARIANT: targeted cases ---- 113 var invariant_ok: i64 = 1 114 // A will with ALL general UETA elements but no witnesses/notary: a naive 115 // clone returns VALID. We must NOT, and must NOT route via UETA_GENERAL. 116 let nv1: i64 = nx_legal_verdict(DT_WILL, 1, 1, 1, 1, 1, 0, 0, reason, regime) 117 if nv1 == LV_VALID { invariant_ok = 0 } 118 if *regime == RG_UETA_GENERAL { invariant_ok = 0 } 119 // A will e-signed where no e-wills statute exists -> VOID / wet required. 120 let nv2: i64 = nx_legal_verdict(DT_WILL, 0, 1, 1, 1, 1, 2, 1, reason, regime) 121 if nv2 != LV_INVALID_VOID { invariant_ok = 0 } 122 if *regime != RG_REQUIRES_WET { invariant_ok = 0 } 123 if *reason != LR_EXCLUDED_WET { invariant_ok = 0 } 124 // testamentary trust gets the same protection 125 let nv3: i64 = nx_legal_verdict(DT_TESTAMENTARY_TRUST, 0, 1, 1, 1, 1, 2, 1, reason, regime) 126 if nv3 != LV_INVALID_VOID { invariant_ok = 0 } 127 if invariant_ok != 1 { ok = 0 } 128 129 // ---- NEVER-VOID INVARIANT: EXHAUSTIVE adversarial sweep ---- 130 var sweep_ok: i64 = 1 131 if sweep_excluded(DT_WILL, reason, regime) != 1 { sweep_ok = 0 } 132 if sweep_excluded(DT_CODICIL, reason, regime) != 1 { sweep_ok = 0 } 133 if sweep_excluded(DT_TESTAMENTARY_TRUST, reason, regime) != 1 { sweep_ok = 0 } 134 if sweep_ok != 1 { ok = 0 } 135 136 // ---- required-elements introspection (concierge UX driver) ---- 137 var req_ok: i64 = 1 138 if nx_legal_required_elements(RG_UETA_GENERAL) != (REQ_INTENT + REQ_CONSENT + REQ_ATTRIBUTION + REQ_RETAINABLE) { req_ok = 0 } 139 if nx_legal_required_elements(RG_ELECTRONIC_WILLS) != (REQ_INTENT + REQ_ATTRIBUTION + REQ_WITNESS2 + REQ_NOTARY + REQ_RETAINABLE) { req_ok = 0 } 140 if req_ok != 1 { ok = 0 } 141 142 // ---- evidence ---- 143 var fd: i64 = 1 144 while fd >= 1 { 145 ew(fd, "LEGALCOMPLIANCEGATE authored=organ grounded=UETA+ESIGN+UEWA classify_ok=" as *u8); ewn(fd, classify_ok) 146 ew(fd, " ueta_general_ok=" as *u8); ewn(fd, ueta_ok) 147 ew(fd, " ewills_regime_ok=" as *u8); ewn(fd, ewills_ok) 148 ew(fd, " never_void_targeted=" as *u8); ewn(fd, invariant_ok) 149 ew(fd, " never_void_exhaustive_sweep=" as *u8); ewn(fd, sweep_ok) 150 ew(fd, " (96 combos x 3 excluded types) required_elements_ok=" as *u8); ewn(fd, req_ok) 151 if ok == 1 { ew(fd, " verdict=GREEN\n" as *u8) } else { ew(fd, " verdict=RED\n" as *u8) } 152 if fd == 1 { 153 let lf: i64 = sys_openat_append(LC_LOG, 420) 154 if lf >= 1 { fd = lf } else { fd = 0 } 155 } else { 156 sys_close(fd); fd = 0 157 } 158 } 159 160 if ok == 1 { return 0 } 161 return 1 162}