nx_doc_envelope.nx
buildroot/runtime/nx_doc_envelope.nx
about
nx_doc_envelope.nx -- LEGAL RUNG D2: the e-signature ENVELOPE workflow.
module: nishi-core.legal.doc_envelope
capability: LEGAL_ESIGN_ENVELOPE
The "DocuSign but better" WORKFLOW core. It orchestrates one document through
create -> send -> sign (per recipient, in routing order) -> complete, binding
the three already-GREEN legal organs into one client-facing flow:
D0 nx_legal_compliance -- classify the document + pick its legal regime at
CREATE; REFUSE to route a void instrument into the
e-sign flow at SEND (never-route-a-void-instrument).
D5 nx_doc_seal -- each signer's signature is a REAL RFC-8032 Ed25519
seal; SIGN verifies it; an envelope can only
COMPLETE when every required signer has a VERIFIED,
non-refused, VALID-verdict seal
(all-signers-or-not-complete).
D1 nx_doc_vault -- (gate-composed) the completed, sealed version is
attached to the per-tenant additive vault.
THE s-class-exceed property, carried LIVE through the workflow (a generic
e-sign product lacks every one of these):
* a will / codicil / testamentary trust in a NON-e-wills jurisdiction can
NEVER be sent for e-signature -- it would produce a legally VOID instrument
(UETA 3(b) / ESIGN 7003(a)). The refusal is at the workflow boundary
(SEND), not merely at the crypto. This is the legal analog of Rule 26.
* routing order is enforced -- recipient N+1 cannot sign before recipient N.
* a forged or tampered signature can never complete an envelope.
* decline / void retain full history (Rule 13 additive-only).
* we do NOT over-refuse: a properly-executed e-will (in an e-wills state)
routes through the stricter regime and completes.
Representation: caller-allocated flat i64 record arrays (substrate scale-
agnostic, no internal allocation), mirroring nx_doc_vault. Pure logic core ->
the gate is self-contained (no socket, no fork).
Composes: nx_legal_compliance (D0 classify+regime+verdict), nx_doc_seal
(D5 NxSeal + verify). Distinct from nx_doc_seal because: that produces ONE
signature; this is the multi-recipient lifecycle + status + audit around it.
license_tier: ORIGINAL
lineage_id: nishi_doc_envelope_d2
dependencies 3 imports · 9 importers
imports: nx_syscalls.nxnx_legal_compliance.nxnx_doc_seal.nx
imported by: nx_doc_annotate_gate.nxnx_doc_envelope_gate.nxnx_legal_portal.nxnx_legal_portal_boot.nxnx_legal_portal_boot_gate.nxnx_legal_portal_daemon.nxnx_legal_portal_gate.nxnx_legal_portal_live_gate.nxnx_legal_portal_post_gate.nx
structs
| none |
consts
| 46 | const ENV_DRAFT: i64 = 0 |
| 47 | const ENV_SENT: i64 = 1 |
| 48 | const ENV_COMPLETED: i64 = 2 |
| 49 | const ENV_DECLINED: i64 = 3 |
| 50 | const ENV_VOIDED: i64 = 4 |
| 53 | const ROLE_SIGNER: i64 = 0 |
| 54 | const ROLE_CC: i64 = 1 // informational copy; never signs |
| 55 | const ROLE_APPROVER: i64 = 2 // reserved: approves without a cryptographic seal |
| 58 | const RC_PENDING: i64 = 0 |
| 59 | const RC_VIEWED: i64 = 1 |
| 60 | const RC_SIGNED: i64 = 2 |
| 61 | const RC_DECLINED: i64 = 3 |
| 64 | const ENV_SEND_OK: i64 = 0 |
| 65 | const ENV_SEND_REFUSED_VOID: i64 = 1 // regime REQUIRES_WET -> never route into e-sign |
| 66 | const ENV_SEND_BAD_STATE: i64 = 2 // not found / not in DRAFT |
| 69 | const ENV_SIGN_OK: i64 = 0 |
| 70 | const ENV_SIGN_OUT_OF_ORDER: i64 = 1 // an earlier-order signer has not signed yet |
| 71 | const ENV_SIGN_BAD_SEAL: i64 = 2 // seal refused / not VALID / does not verify |
| 72 | const ENV_SIGN_BAD_STATE: i64 = 3 // envelope not found / not SENT |
| 73 | const ENV_SIGN_NO_RCPT: i64 = 4 // recipient not on envelope, or not a signer |
| 76 | const ENV_COMPLETE_OK: i64 = 0 |
| 77 | const ENV_COMPLETE_NOT_READY: i64 = 1 |
| 80 | const EV_CREATED: i64 = 0 |
| 81 | const EV_SENT: i64 = 1 |
| 82 | const EV_VIEWED: i64 = 2 |
| 83 | const EV_SIGNED: i64 = 3 |
| 84 | const EV_COMPLETED: i64 = 4 |
| 85 | const EV_DECLINED: i64 = 5 |
| 86 | const EV_VOIDED: i64 = 6 |
| 89 | const EF_ENV: i64 = 0 // envelope id |
| 90 | const EF_DOC: i64 = 1 // vault doc id this envelope wraps |
| 91 | const EF_DTYPE: i64 = 2 // D0 document type (classified at create) |
| 92 | const EF_REGIME: i64 = 3 // D0 legal regime (decided at create) |
| 93 | const EF_STATUS: i64 = 4 |
| 94 | const EF_NSIGN: i64 = 5 // required signer count (frozen at send) |
| 95 | const EF_NDONE: i64 = 6 // signers that have signed |
| 96 | const EF_TS: i64 = 7 |
| 97 | const EF_EWILLS: i64 = 8 // jurisdiction: e-wills statute present (0/1) |
| 98 | const EF_STRIDE: i64 = 9 |
| 101 | const RF_ENV: i64 = 0 |
| 102 | const RF_RCPT: i64 = 1 |
| 103 | const RF_ROLE: i64 = 2 |
| 104 | const RF_ORDER: i64 = 3 // routing order (1,2,3,...) |
| 105 | const RF_STATUS: i64 = 4 |
| 106 | const RF_SEALOK: i64 = 5 // 1 = a verified Ed25519 seal was recorded for this signer |
| 107 | const RF_TS: i64 = 6 |
| 108 | const RF_STRIDE: i64 = 7 |
| 111 | const AF_ENV: i64 = 0 |
| 112 | const AF_KIND: i64 = 1 |
| 113 | const AF_ACTOR: i64 = 2 |
| 114 | const AF_TS: i64 = 3 |
| 115 | const AF_STRIDE: i64 = 4 |
| 117 | const ENV_ORDER_NONE: i64 = 2147483647 |
functions
| 120 | func ne_find_env(flat_env: *i64, ne: i64, env_id: i64) -> i64 |
| 130 | func ne_find_rcpt(flat_rc: *i64, nr: i64, env_id: i64, rcpt_id: i64) -> i64 |
| 144 | func nx_env_create(flat_env: *i64, ne: i64, cap: i64, env_id: i64, doc_id: i64, |
| 163 | func nx_env_add_recipient(flat_rc: *i64, nr: i64, cap: i64, env_id: i64, |
| 177 | func nx_env_status(flat_env: *i64, ne: i64, env_id: i64) -> i64 |
| 182 | func nx_env_regime(flat_env: *i64, ne: i64, env_id: i64) -> i64 |
| 187 | func nx_env_doctype(flat_env: *i64, ne: i64, env_id: i64) -> i64 |
| 194 | func nx_env_required_signers(flat_rc: *i64, nr: i64, env_id: i64) -> i64 |
| 206 | func nx_env_signed_count(flat_rc: *i64, nr: i64, env_id: i64) -> i64 |
| 223 | func ne_next_signer_order(flat_rc: *i64, nr: i64, env_id: i64) -> i64 called by 1: nx_env_sign |
| 246 | func nx_env_send(flat_env: *i64, ne: i64, flat_rc: *i64, nr: i64, env_id: i64) -> i64 |
| 258 | func nx_env_mark_viewed(flat_rc: *i64, nr: i64, env_id: i64, rcpt_id: i64, ts: i64) -> i64 calls 1: ne_find_rcpt |
| 271 | func nx_env_sign(flat_env: *i64, ne: i64, flat_rc: *i64, nr: i64, called by 5: mainmainmainmainmain calls 4: ne_find_envne_find_rcptne_next_signer_ordernx_seal_verify |
| 295 | func nx_env_try_complete(flat_env: *i64, ne: i64, flat_rc: *i64, nr: i64, env_id: i64) -> i64 |
| 310 | func nx_env_decline(flat_env: *i64, ne: i64, flat_rc: *i64, nr: i64, env_id: i64, rcpt_id: i64) -> i64 |
| 321 | func nx_env_void(flat_env: *i64, ne: i64, env_id: i64) -> i64 calls 1: ne_find_env |
| 329 | func nx_env_audit_add(flat_au: *i64, na: i64, cap: i64, env_id: i64, kind: i64, actor: i64, ts: i64) -> i64 called by 1: main |
| 338 | func nx_env_audit_count(flat_au: *i64, na: i64, env_id: i64) -> i64 called by 1: main |
| 348 | func nx_env_status_name(s: i64) -> *u8 called by 1: lp_handle |