nx_cap_token.nx
buildroot/runtime/nx_cap_token.nx
about
nx_cap_token.nx -- sovereign CAPABILITY TOKEN: the "beyond MCP" security primitive for tool invocation.
A capability is AUTHORITY-IN-THE-TOKEN bound to a designated tool-set -- unforgeable + attenuable. Unlike an
OAuth/JWT bearer (identity + AMBIENT scope, which MCP's own docs admit leads to confused-deputy), verifying a
capability consults NO ambient identity: the token itself names the tools AND confers the authority to call them.
Composes the shipped signed-token MAC (signed_cookie_sign/verify = "<value>.<b64url(HMAC-SHA256(key,value))>" +
constant-time verify); adds ONLY the capability semantics (allow-set membership, expiry, SUBSET-ONLY attenuation).
payload = "<allow>~<exp>~<nonce>" allow = comma-separated tool names or "*"; exp = decimal epoch; nonce = decimal
token = signed_cookie_sign(payload) = "<payload>.<sig>"
license_tier: ORIGINAL
dependencies 1 imports · 17 importers
diagram shows first 10 each side; +0 more imports, +7 more importers in the complete lists below.
imports: nx_signed_cookie.nx
imported by: nx_cap_keygen_gate.nxnx_cap_mint.nxnx_cap_token_gate.nxnx_dev_api.nxnx_devcap_provision.nxnx_login_gate.nxnx_login_gate_gate.nxnx_property_test.nxnx_regress_bank.nxnx_tools_api.nxnx_tools_api_candidate_t182.nxnx_tools_api_canonical_candidate_t182.nxnx_tools_api_idem_candidate_t190.nxnx_tools_api_recovery_candidate_t316.nxnx_tools_api_recovery_candidate_v2_t316.nxnx_tools_api_recovery_candidate_v3_t316.nxnx_toolsapi_bodycap_gate.nx
structs
| none |
consts
| 12 | const CAPT_OK: i64 = 1 |
| 13 | const CAPT_DENY_MAC: i64 = 0 - 2 // forged / tampered / malformed (HMAC mismatch) -- fail-closed |
| 14 | const CAPT_DENY_EXP: i64 = 0 - 3 // expired |
| 15 | const CAPT_DENY_TOOL: i64 = 0 - 4 // valid capability, but it does NOT grant THIS tool (least-authority) |
| 16 | const CAPT_DENY_REVOKED: i64 = 0 - 5 // valid + unexpired MAC, but the cap's nonce is on the revocation denylist |
| 39 | const CAPT_SIGN_WORKSPACE:i64=SC_SIGNATURE_BYTES |
| 40 | const CAPT_ERR_ALLOC:i64=0-12 |
| 41 | const CAPT_ERR_RELEASE:i64=0-13 |
| 42 | const CAPT_SIZE_MAX:i64=9223372036854775807 |
functions
| 18 | func capt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 19 | func capt_catb(d: *u8, o: i64, s: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { d[o + i] = s[i]; i = i + 1 } return o + n } called by 1: capt_payload |
| 20 | func capt_catn(d:*u8,o:i64,v:i64)->i64 |
| 29 | func capt_payload(allow: *u8, allen: i64, exp: i64, nonce: i64, buf: *u8) -> i64 |
| 43 | func capt_decimal_bytes(value:i64)->i64 called by 1: capt_issue_capacity |
| 47 | func capt_issue_capacity(allen:i64,exp:i64,nonce:i64)->i64 called by 4: maincapt_issue_workspace_bytescapt_issue_workspacecapt_issue calls 1: capt_decimal_bytes |
| 54 | func capt_issue_workspace_bytes(allen:i64,exp:i64,nonce:i64)->i64 |
| 62 | func capt_issue_workspace(key:*u8,klen:i64,allow:*u8,allen:i64,exp:i64,nonce:i64,out:*u8,cap:i64,workspace:*u8,capacity:i64)->i64 |
| 73 | func capt_issue(key:*u8,klen:i64,allow:*u8,allen:i64,exp:i64,nonce:i64,out:*u8,cap:i64)->i64 called by 30: maincm_mintcapt_attenuatemainmainmain+24 calls 3: capt_issue_capacitycapt_issue_workspace_bytescapt_issue_workspace |
| 82 | func capt_allows(allow: *u8, alen: i64, tool: *u8, tlen: i64) -> i64 |
| 106 | func capt_mac_ok(key:*u8,klen:i64,token:*u8,tlen:i64,plen_out:*i64)->i64 |
| 114 | func capt_verify(key: *u8, klen: i64, token: *u8, tlen: i64, tool: *u8, toollen: i64, now: i64) -> i64 |
| 137 | func capt_attenuate(key: *u8, klen: i64, token: *u8, tlen: i64, narrow: *u8, nlen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64 called by 9: mainmainta_cap_issueta_cap_issueta_cap_issueta_cap_issue+3 calls 3: capt_mac_okcapt_allowscapt_issue |
| 171 | func capt_nonce_of(token: *u8, tlen: i64) -> i64 |