code wiki / (root) / nx_cap_token.nx

nx_cap_token.nx

buildroot/runtime/nx_cap_token.nx

8076 B144 linesdepth 7pulls 9 transitivereach 24 importersview sourcekind librarytopic cap
docsdependenciesstructsconstsfunctions

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

nx_signed_cookie.nx nx_cap_token.nx nx_cap_keygen_gate.nx nx_cap_mint.nx nx_cap_token_gate.nx nx_dev_api.nx nx_devcap_provision.nx nx_login_gate.nx nx_login_gate_gate.nx nx_property_test.nx nx_regress_bank.nx nx_tools_api.nx

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

12const CAPT_OK: i64 = 1
13const CAPT_DENY_MAC: i64 = 0 - 2 // forged / tampered / malformed (HMAC mismatch) -- fail-closed
14const CAPT_DENY_EXP: i64 = 0 - 3 // expired
15const CAPT_DENY_TOOL: i64 = 0 - 4 // valid capability, but it does NOT grant THIS tool (least-authority)
16const CAPT_DENY_REVOKED: i64 = 0 - 5 // valid + unexpired MAC, but the cap's nonce is on the revocation denylist

functions

18func capt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
19func 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
20func capt_catn(d: *u8, o: i64, v: i64) -> i64
called by 2: capt_payloadpn
30func capt_payload(allow: *u8, allen: i64, exp: i64, nonce: i64, buf: *u8) -> i64
called by 1: capt_issue calls 2: capt_catbcapt_catn
40func capt_issue(key: *u8, klen: i64, allow: *u8, allen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64
47func capt_allows(allow: *u8, alen: i64, tool: *u8, tlen: i64) -> i64
72func capt_mac_ok(key: *u8, klen: i64, token: *u8, tlen: i64, plen_out: *i64) -> i64
85func capt_verify(key: *u8, klen: i64, token: *u8, tlen: i64, tool: *u8, toollen: i64, now: i64) -> i64
104func capt_attenuate(key: *u8, klen: i64, token: *u8, tlen: i64, narrow: *u8, nlen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64
134func capt_nonce_of(token: *u8, tlen: i64) -> i64