code wiki / (root) / nx_cap_token_candidate_t186.nx

nx_cap_token_candidate_t186.nx

buildroot/runtime/nx_cap_token_candidate_t186.nx

10383 B181 linesdepth 8pulls 10 transitivereach 4 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 · 1 importers

nx_signed_cookie_candidate_t187.nx nx_cap_token_candidate_t186.nx nx_cap_mint_candidate_t186.nx

imports: nx_signed_cookie_candidate_t187.nx

imported by: nx_cap_mint_candidate_t186.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
39const CAPT_SIGN_WORKSPACE:i64=SC_SIGNATURE_BYTES
40const CAPT_ERR_ALLOC:i64=0-12
41const CAPT_ERR_RELEASE:i64=0-13
42const CAPT_SIZE_MAX:i64=9223372036854775807

functions

18func capt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: cm_atoimain
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 1: capt_payload
29func capt_payload(allow: *u8, allen: i64, exp: i64, nonce: i64, buf: *u8) -> i64
43func capt_decimal_bytes(value:i64)->i64
called by 1: capt_issue_capacity
47func capt_issue_capacity(allen:i64,exp:i64,nonce:i64)->i64
54func capt_issue_workspace_bytes(allen:i64,exp:i64,nonce:i64)->i64
62func capt_issue_workspace(key:*u8,klen:i64,allow:*u8,allen:i64,exp:i64,nonce:i64,out:*u8,cap:i64,workspace:*u8,capacity:i64)->i64
73func capt_issue(key:*u8,klen:i64,allow:*u8,allen:i64,exp:i64,nonce:i64,out:*u8,cap:i64)->i64
82func capt_allows(allow: *u8, alen: i64, tool: *u8, tlen: i64) -> i64
106func capt_mac_ok(key:*u8,klen:i64,token:*u8,tlen:i64,plen_out:*i64)->i64
114func capt_verify(key: *u8, klen: i64, token: *u8, tlen: i64, tool: *u8, toollen: i64, now: i64) -> i64
137func capt_attenuate(key: *u8, klen: i64, token: *u8, tlen: i64, narrow: *u8, nlen: i64, exp: i64, nonce: i64, out: *u8, cap: i64) -> i64
171func capt_nonce_of(token: *u8, tlen: i64) -> i64