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 · 10 importers
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.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 |
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 |
| 30 | func capt_payload(allow: *u8, allen: i64, exp: i64, nonce: i64, buf: *u8) -> i64 |
| 40 | func capt_issue(key: *u8, klen: i64, allow: *u8, allen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64 |
| 47 | func capt_allows(allow: *u8, alen: i64, tool: *u8, tlen: i64) -> i64 |
| 72 | func capt_mac_ok(key: *u8, klen: i64, token: *u8, tlen: i64, plen_out: *i64) -> i64 |
| 85 | func capt_verify(key: *u8, klen: i64, token: *u8, tlen: i64, tool: *u8, toollen: i64, now: i64) -> i64 |
| 104 | func capt_attenuate(key: *u8, klen: i64, token: *u8, tlen: i64, narrow: *u8, nlen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64 |
| 134 | func capt_nonce_of(token: *u8, tlen: i64) -> i64 |