@aura-labs-ai/mcp-server-admission 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,10 +18,22 @@ only signatures do. Discovery stays on the hosted AURA MCP; authority lives here
18
18
  }
19
19
  ```
20
20
 
21
+ `npx -y` fetches the latest published version. Version 0.2.0 and later sign the
22
+ principal binding (tool 5 below). `x-aura-signature-test-vectors` in
23
+ `openapi.json` holds the `agent_binding` vector and the accepted registration
24
+ body, `register_scout_with_binding`.
25
+
21
26
  Environment:
22
27
 
23
- - `AURA_BENCH_URL` — the certification bench (default `https://sandbox.aura-labs.ai`)
24
- - `AURA_KEY_PATH` — key file location override (default: macOS Keychain, else `~/.aura/keys.json` at 0600)
28
+ - `AURA_BENCH_URL`: the certification bench (default `https://sandbox.aura-labs.ai`).
29
+ A binding names the host of this URL as its `aud`. Core accepts the binding
30
+ only when that host equals its own `canonical_host`, which `GET /v1/` returns.
31
+ - `AURA_KEY_PATH`: key file location override (default: macOS Keychain, else `~/.aura/keys.json` at 0600)
32
+
33
+ `provision_sandbox` is two-step (DEC-228): it first calls the AURA Dev Centre at
34
+ `https://agentcentre.aura-labs.ai` for a signed grant, then carries that grant to
35
+ the certification bench's own `provision_url` to materialise the environment.
36
+ Every other tool targets the bench above.
25
37
 
26
38
  ## The tools, in recorded-run order
27
39
 
@@ -30,19 +42,44 @@ into it only when the sandbox key is presented — so the order below matters.
30
42
  Registering before provisioning still succeeds, but the transcript never
31
43
  captures it.
32
44
 
33
- 1. `get_admission_guide` — read the admission chain from the bench.
34
- 2. `mint_sandbox_key` — two-phase. The first call generates and holds a
45
+ 1. `get_admission_guide`: read the admission chain from the bench.
46
+ 2. `mint_sandbox_key`: two-phase. The first call generates and holds a
35
47
  dedicated domain signing key and returns the exact domain-control proof to
36
48
  publish (DNS TXT `_aura-agent-key.<domain>` = `aura-key=<public_key>`, or the
37
49
  HTTPS document `https://<domain>/.well-known/aura-agent-key` containing
38
50
  `{"public_key":"<base64>"}`). Publish it, call again: the tool attempts the
39
51
  mint and, until the proof is visible, returns the bench's `looked_for` /
40
52
  `found` verbatim. On success the bearer key is held locally.
41
- 3. `provision_sandbox` — the seeded market, the manifest, and the opened
42
- `run_id`. Idempotent.
43
- 4. `register_principal` — signed locally with the held principal key.
44
- 5. `register_agent` — signed locally with the held agent key.
45
- 6. `reset_sandbox` — opens a fresh run (not idempotent; spends run quota).
53
+ 3. `provision_sandbox`: two-step, agent-carried (DEC-228). The tool first calls
54
+ the Dev Centre (`POST /provision`, bearer sandbox key), which charges quota,
55
+ mints the namespace, and returns a signed grant plus the exact bench
56
+ `provision_url` — it does not provision. The tool then carries that grant to
57
+ the Bench Core itself (`POST` the `provision_url`, presenting the grant as
58
+ `X-AURA-Bench-Grant`), and the bench returns the seeded market, the manifest,
59
+ the opened `run_id`, and the once-shown run context. The context never crosses
60
+ the Dev Centre. Idempotent: a repeat call replays the same environment. There
61
+ is no reset — provisioning again stands up a fresh environment, and idle
62
+ environments are reclaimed by the reaper.
63
+ 4. `register_principal`: signed locally with the held principal key
64
+ (`X-Signature`). The tool holds the `principal_id` Core returns.
65
+ 5. `register_agent`: Core registers an agent only on its principal's signed
66
+ binding (DEC-249). The tool builds the nine claims of the `agent_binding`
67
+ signature profile: the principal, the fingerprint of the agent key, the agent
68
+ type, the capacity, the bench host as `aud`, the fingerprint of the principal
69
+ key as `kid`, a window of 300 seconds (`iat`, `exp`) and a single-use `jti`.
70
+ The held principal key signs them. The request body carries the claims and
71
+ that signature as `principal_binding`, and the held agent key signs the body
72
+ (`X-Agent-Signature`), so the agent key signs the binding it presents. A
73
+ `principal_id` argument that is not the held principal is refused locally as
74
+ `principal_not_held`, and no request is sent. A refusal from Core is returned
75
+ with its `error`, its `message` and, for `invalid_principal_binding`, its
76
+ `reason` (`claims`, `audience`, `window`, `expired`, `signature` or
77
+ `replayed`). A second call with the same keys is answered from Core's record
78
+ and writes nothing. The result states the binding Core recorded, as
79
+ `binding`: `attested`, or `unattested` when Core's answer carries no attested
80
+ binding. A Core that does not yet require the binding accepts the body and
81
+ records none, and the result then carries a `binding_warning` that says to
82
+ call `register_agent` again.
46
83
 
47
84
  ## Key custody
48
85
 
@@ -52,9 +89,32 @@ state (`sandbox_key`, `principal_id`, `agent_id`, `namespace_id`, `run_id`)
52
89
  persist across restarts via the platform storage adapter. Nothing sensitive is
53
90
  ever written to stdout (the MCP channel) or included in tool results.
54
91
 
92
+ The principal key signs two artefacts: the principal registration and the agent
93
+ binding. The wallet signs a binding through one method, `signAgentBinding`, which
94
+ builds the signed bytes from the claims. It refuses a claim set that is not
95
+ exactly the nine, a `kid` that is not the fingerprint of its principal key and an
96
+ `agent_key_id` that is not the fingerprint of its agent key. `sign` refuses bytes
97
+ that begin with the binding prefix, for every slot. The principal key therefore
98
+ signs a binding only for the agent key the same wallet holds. Both keys sit in
99
+ one store, so on the bench the party that signs a binding is the party that
100
+ presents it.
101
+
55
102
  ## Publishing (maintainers)
56
103
 
57
- The package publishes over npm OIDC trusted publishing from the repository
58
- workflow. A brand-new package name requires a one-time bootstrap publish via
59
- traditional auth, then registering its Trusted Publisher on npmjs.com, before
60
- the workflow can publish it.
104
+ Version 0.1.0 was the bootstrap publish from the owner's account: a new package
105
+ name needs one publish before a Trusted Publisher can be registered for it on
106
+ npmjs.com, and the owner registered its Trusted Publisher on 2026-07-11. Every
107
+ later version publishes from the repository workflow `npm-publish.yml` over npm
108
+ OIDC trusted publishing.
109
+
110
+ A merge to `main` that raises `version` in `package.json` publishes that version.
111
+ CI's SDK version gate refuses a pull request that changes a file npm publishes
112
+ from this directory without raising it (DEC-272). Raise it with
113
+ `npm version patch --no-git-tag-version` here, which updates `package.json` and
114
+ the lockfile, and write the same version as the server version in `src/index.js`:
115
+ the DEC-272 gate holds them equal.
116
+
117
+ 0.1.0 provisions at a route Core no longer serves and sends no
118
+ `principal_binding`; 0.2.0 is the first version that completes admission.
119
+ `files` in `package.json` names every module the entry point imports,
120
+ `src/agent-binding.js` among them, and the DEC-249 gate holds that list.
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@aura-labs-ai/mcp-server-admission",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "AURA admission MCP server: the local action layer that onboards an agent onto the AURA certification bench. Holds the agent's Ed25519 keys and signs every admission request locally — keys never leave the machine.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
- "mcp-server-admission": "./src/index.js"
8
+ "mcp-server-admission": "src/index.js"
9
9
  },
10
10
  "files": [
11
11
  "src/index.js",
12
12
  "src/tools.js",
13
13
  "src/wallet.js",
14
+ "src/agent-binding.js",
14
15
  "README.md"
15
16
  ],
16
17
  "scripts": {
@@ -37,6 +38,11 @@
37
38
  "sandbox"
38
39
  ],
39
40
  "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/aura-labs-ai/aura-labs.ai.git",
44
+ "directory": "sdks/mcp-server-admission"
45
+ },
40
46
  "publishConfig": {
41
47
  "access": "public"
42
48
  }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Agent binding payload: the bytes a principal signs to authorise an agent key (DEC-249).
3
+ *
4
+ * Core binds an agent to a principal only on the principal's own signature over the
5
+ * agent key (signature profile agent_binding). The signed bytes are a domain prefix,
6
+ * then recursive canonical JSON of nine closed claims.
7
+ *
8
+ * This module is a replica. AGENT_BINDING_DOMAIN_PREFIX, canonicalJSON and
9
+ * buildAgentBindingPayload are copied textually from Core's lib/agent-binding.js, and the
10
+ * DEC-249 gate holds the three byte-identical to it. The package ships standalone, so it
11
+ * cannot import Core. keyFingerprint is this module's own: the SHA-256 that Core computes
12
+ * over a key.
13
+ *
14
+ * Dependency-free (node:crypto only), so the unit suite and Core's integration suite
15
+ * load it with no installed package.
16
+ */
17
+
18
+ import crypto from 'node:crypto';
19
+
20
+ // Domain separation: a binding signature verifies as no other artefact a principal key
21
+ // signs, and no other signature verifies as a binding.
22
+ export const AGENT_BINDING_DOMAIN_PREFIX = 'AURA-AGENT-BINDING\n';
23
+
24
+ // The closed claim set. Every claim is required and no other is admitted. Order here is
25
+ // documentation only: canonicalJSON sorts keys, so the signed bytes are order-independent.
26
+ export const BINDING_CLAIMS = Object.freeze([
27
+ 'principal_id', 'agent_key_id', 'agent_type', 'capacity', 'aud', 'kid', 'iat', 'exp', 'jti',
28
+ ]);
29
+
30
+ /**
31
+ * Recursive canonical JSON (DEC-144, GAP-06 safe): object keys sorted at EVERY
32
+ * depth, array order preserved, scalars via JSON.stringify. Byte-identical to
33
+ * Core's offer-signature.js canonicalJSON.
34
+ */
35
+ export function canonicalJSON(value) {
36
+ if (value === null || typeof value !== 'object') return JSON.stringify(value);
37
+ if (Array.isArray(value)) return '[' + value.map(canonicalJSON).join(',') + ']';
38
+ return '{' + Object.keys(value).sort()
39
+ .map((k) => JSON.stringify(k) + ':' + canonicalJSON(value[k]))
40
+ .join(',') + '}';
41
+ }
42
+
43
+ // The canonical bytes a principal signs and Core verifies for a binding.
44
+ export function buildAgentBindingPayload(claims) {
45
+ return AGENT_BINDING_DOMAIN_PREFIX + canonicalJSON(claims);
46
+ }
47
+
48
+ /**
49
+ * The fingerprint of an Ed25519 public key: SHA-256, in hex, of its raw 32 bytes. It is
50
+ * the value of the claims agent_key_id and kid.
51
+ * @param {string} publicKeyBase64 - the raw public key, base64
52
+ * @returns {string} 64 lower-case hex characters
53
+ */
54
+ export function keyFingerprint(publicKeyBase64) {
55
+ return crypto.createHash('sha256').update(Buffer.from(publicKeyBase64, 'base64')).digest('hex');
56
+ }
package/src/index.js CHANGED
@@ -9,12 +9,12 @@
9
9
  * hosted AURA MCP stays read/discover-only; authority lives here.
10
10
  *
11
11
  * Tools (recorded-run order):
12
- * get_admission_guide — read the admission chain from the bench
13
- * mint_sandbox_key — two-phase domain-proof mint of the sandbox key
14
- * provision_sandbox — provision the namespace; opens the recorded run
15
- * register_principal — register the principal (signed locally)
16
- * register_agent — register this agent (signed locally)
17
- * reset_sandbox — open a fresh run
12
+ * get_admission_guide: read the admission chain from the bench
13
+ * mint_sandbox_key: two-phase domain-proof mint of the sandbox key
14
+ * provision_sandbox: provision the namespace; opens the recorded run
15
+ * register_principal: register the principal (signed locally)
16
+ * register_agent: register this agent on the principal's signed binding of
17
+ * its key (DEC-249; both signatures made locally)
18
18
  *
19
19
  * Key custody: three Ed25519 slots (principal / agent / domain) plus the chain
20
20
  * state, persisted via @aura-labs-ai/sdk-common createStorage() — the macOS
@@ -49,7 +49,7 @@ async function main() {
49
49
  const deps = { wallet, fetch: globalThis.fetch, baseUrl: BENCH_URL };
50
50
 
51
51
  const server = new Server(
52
- { name: 'aura-admission', version: '0.1.0' },
52
+ { name: 'aura-admission', version: '0.2.0' },
53
53
  { capabilities: { tools: {} } },
54
54
  );
55
55
 
package/src/tools.js CHANGED
@@ -1,19 +1,27 @@
1
1
  /**
2
- * The six admission action tools (ADR-017, DEC-176).
2
+ * The five admission action tools (ADR-017, DEC-176).
3
3
  *
4
4
  * Pure, dependency-injected handlers: every tool is (args, deps) -> result where
5
5
  * deps = { wallet, fetch, baseUrl }. No module-level I/O and no imports beyond
6
- * node builtins, so the handlers unit-test with an in-memory wallet + scripted
7
- * fetch, and the bench integration suite drives them against the real routes
8
- * through an injected fetch shim.
6
+ * node builtins and this package's own agent-binding module, so the handlers
7
+ * unit-test with an in-memory wallet + scripted fetch, and the bench integration
8
+ * suite drives them against the real routes through an injected fetch shim.
9
9
  *
10
10
  * Auth surfaces (each tool signs locally; keys never leave the wallet):
11
11
  * register_principal X-Signature principal key, over JSON.stringify(body)
12
12
  * register_agent X-Agent-Signature agent key, over JSON.stringify(body)
13
+ * principal_binding principal key, over the agent_binding payload (in the body)
13
14
  * mint_sandbox_key X-Signature domain key, over JSON.stringify(body)
14
- * provision_sandbox / reset_sandbox bearer X-AURA-Sandbox-Key, no signature
15
+ * provision_sandbox bearer X-AURA-Sandbox-Key (Dev Centre), no signature
15
16
  * get_admission_guide unauthenticated read
16
17
  *
18
+ * THE PRINCIPAL BINDING (DEC-249): Core registers an agent only on its principal's
19
+ * signature over the agent key. register_agent builds the nine claims of the
20
+ * agent_binding profile and has the wallet sign them with the principal slot, through
21
+ * signAgentBinding. The body carries the result as principal_binding, so the agent key
22
+ * signs the binding it presents. The tool refuses a principal the wallet does not hold
23
+ * before any request.
24
+ *
17
25
  * ORDERING: the recorded-run happy path is guide -> mint -> provision ->
18
26
  * register_principal -> register_agent. Provision opens the conformance run and
19
27
  * the recorder attributes registrations to it only when the sandbox key is
@@ -22,18 +30,23 @@
22
30
  * misled by the admission phases' ordinal order.
23
31
  */
24
32
 
25
- const ORDER_NOTE = 'Recorded-run order: get_admission_guide -> mint_sandbox_key -> provision_sandbox -> register_principal -> register_agent (-> reset_sandbox for a fresh run). Provision opens the recorded run; register before provisioning and the transcript never captures the identity.';
33
+ import crypto from 'node:crypto';
34
+ import { keyFingerprint } from './agent-binding.js';
35
+
36
+ const ORDER_NOTE = 'Recorded-run order: get_admission_guide -> mint_sandbox_key -> provision_sandbox -> register_principal -> register_agent. Provision opens the recorded run; register before provisioning and the transcript never captures the identity.';
26
37
 
27
- /** Tool name -> the openapi.json operationId it drives. get_admission_guide reads
28
- * the bench guide resource, which is deliberately absent from the contract paths
29
- * (a runtime projection of x-aura-agent-admission), so it maps to null. */
38
+ /** Tool name -> the operationId it drives. Core-protocol tools drive an
39
+ * openapi.json operationId; provision_sandbox drives the Dev Centre's
40
+ * provisionEnvironment (agentcentre.json), since provisioning is a Dev-Centre
41
+ * action, not a Core protocol operation (ADR-021 inc4d-vii-b-3). get_admission_guide
42
+ * reads the bench guide resource, absent from the contract paths (a runtime
43
+ * projection of x-aura-agent-admission), so it maps to null. There is no reset. */
30
44
  export const TOOL_OPERATIONS = {
31
45
  get_admission_guide: null,
32
46
  mint_sandbox_key: 'mintSandboxKey',
33
- provision_sandbox: 'provisionSandbox',
47
+ provision_sandbox: 'provisionEnvironment',
34
48
  register_principal: 'registerPrincipal',
35
49
  register_agent: 'registerAgent',
36
- reset_sandbox: 'resetSandbox',
37
50
  };
38
51
 
39
52
  export const TOOL_DEFINITIONS = [
@@ -57,12 +70,12 @@ export const TOOL_DEFINITIONS = [
57
70
  },
58
71
  {
59
72
  name: 'provision_sandbox',
60
- description: `Provision the sandbox namespace (POST /v1/sandbox/namespaces, bearer sandbox key): a seeded market, the manifest, and the OPENED CONFORMANCE RUN (run_id) the transcript records into. Idempotent: a repeat call replays the same namespace and run. Run this BEFORE registering identities so they are recorded. ${ORDER_NOTE}`,
73
+ description: `Provision your rehearsal environment (POST /provision on the Dev Centre at agentcentre.aura-labs.ai, bearer sandbox key): a seeded market, the manifest, and the OPENED CONFORMANCE RUN (run_id) the transcript records into. Provisioning is a Dev-Centre operational action, not a Core protocol operation. Idempotent: a repeat call replays the same namespace and run. Run this BEFORE registering identities so they are recorded. ${ORDER_NOTE}`,
61
74
  inputSchema: { type: 'object', properties: {}, additionalProperties: false },
62
75
  },
63
76
  {
64
77
  name: 'register_principal',
65
- description: `Register the principal you act for (POST /v1/principals), signed locally with the held principal key (X-Signature). Attaches the held sandbox key so the registration is namespace-stamped and recorded into the open run — provision first, or nothing is recorded. Returns and holds principal_id. ${ORDER_NOTE}`,
78
+ description: `Register the principal you act for (POST /v1/principals), signed locally with the held principal key (X-Signature). Carries no build credential; attaches the held run context so the registration is recorded into the open run — provision first, or nothing is recorded. Returns and holds principal_id. ${ORDER_NOTE}`,
66
79
  inputSchema: {
67
80
  type: 'object',
68
81
  properties: {
@@ -81,31 +94,54 @@ export const TOOL_DEFINITIONS = [
81
94
  },
82
95
  {
83
96
  name: 'register_agent',
84
- description: `Register this agent under the held principal (POST /v1/agents/register), signed locally with the held agent key (X-Agent-Signature). Attaches the held sandbox key so the registration is recorded into the open run. Returns and holds agent_id. ${ORDER_NOTE}`,
97
+ description: `Register this agent under the held principal (POST /v1/agents/register). Core registers an agent only on its principal's signed binding: the held principal key signs the binding of the agent key (principal_binding, signature profile agent_binding), and the held agent key signs the body that carries it (X-Agent-Signature). Both signatures are made locally. Carries no build credential; attaches the held run context so the registration is recorded into the open run. Returns and holds agent_id, and returns the binding Core recorded as binding: attested, or unattested with a binding_warning when Core's answer carries no attested binding. ${ORDER_NOTE}`,
85
98
  inputSchema: {
86
99
  type: 'object',
87
100
  properties: {
88
101
  type: { type: 'string', enum: ['scout', 'beacon'], description: 'The agent role to register.' },
89
- principal_id: { type: 'string', description: 'Optional override; defaults to the principal_id held from register_principal.' },
102
+ principal_id: { type: 'string', description: 'Optional. When given it must equal the principal_id held from register_principal: the wallet signs a binding only for the principal whose key it holds, and any other value is refused locally as principal_not_held.' },
90
103
  },
91
104
  required: ['type'],
92
105
  additionalProperties: false,
93
106
  },
94
107
  },
95
- {
96
- name: 'reset_sandbox',
97
- description: `Reset the namespace and open a FRESH conformance run (POST /v1/sandbox/namespaces/current/reset, bearer sandbox key). NOT idempotent: each success is a new run boundary and spends run quota; an in-flight flow refuses with sandbox_run_active (let it quiesce), and the tier run quota can refuse with 429. Returns and holds the new run_id. ${ORDER_NOTE}`,
98
- inputSchema: {
99
- type: 'object',
100
- properties: { reason: { type: 'string', description: 'Optional note recorded with the reset.' } },
101
- additionalProperties: false,
102
- },
103
- },
104
108
  ];
105
109
 
106
110
  // --- wire helpers ---------------------------------------------------------
107
111
 
108
112
  const DEFAULT_BASE_URL = 'https://sandbox.aura-labs.ai';
113
+ // Provisioning is a Dev-Centre action on a different host and an unversioned path
114
+ // (ADR-021 inc4d-vii-b-3). callDevCentre posts there; no /v1 prefix.
115
+ const DEFAULT_DEVCENTRE_BASE_URL = 'https://agentcentre.aura-labs.ai';
116
+
117
+ async function callDevCentre(deps, method, path, { body, headers } = {}) {
118
+ const baseUrl = (deps.devCentreBaseUrl || DEFAULT_DEVCENTRE_BASE_URL).replace(/\/$/, '');
119
+ const bodyString = body === undefined ? undefined : JSON.stringify(body);
120
+ const res = await deps.fetch(`${baseUrl}${path}`, {
121
+ method,
122
+ headers: {
123
+ ...(bodyString !== undefined && { 'content-type': 'application/json' }),
124
+ ...headers,
125
+ },
126
+ ...(bodyString !== undefined && { body: bodyString }),
127
+ });
128
+ let json = null;
129
+ try { json = await res.json(); } catch { /* non-JSON body */ }
130
+ return { status: res.status, json };
131
+ }
132
+
133
+ // The agent carries the grant to the Bench Core directly (ADR-021 inc4d-vii-b-2, DEC-228,
134
+ // agent-carried): POST the exact provision_url the Dev Centre returned, presenting the signed grant as
135
+ // X-AURA-Bench-Grant. An absolute URL (the Dev Centre supplies it), so it bypasses callDevCentre's base.
136
+ async function callBenchGrant(deps, url, benchGrantHeader) {
137
+ const res = await deps.fetch(url, {
138
+ method: 'POST',
139
+ headers: { 'content-type': 'application/json', 'x-aura-bench-grant': benchGrantHeader },
140
+ });
141
+ let json = null;
142
+ try { json = await res.json(); } catch { /* non-JSON body */ }
143
+ return { status: res.status, json };
144
+ }
109
145
 
110
146
  async function call(deps, method, path, { body, headers } = {}) {
111
147
  const baseUrl = (deps.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, '');
@@ -135,28 +171,63 @@ async function signBody(deps, slot, body) {
135
171
  async function callSigned(deps, path, body, signatureHeader, slot) {
136
172
  const baseUrl = (deps.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, '');
137
173
  const { bodyString, signature } = await signBody(deps, slot, body);
138
- const sandboxKey = await deps.wallet.getState('sandbox_key');
174
+ // The actor-registration unweld (DEC-192): registration carries no build credential.
175
+ // Attach the run context (the opaque X-AURA-Sandbox-Context held from provision) so the
176
+ // registration attributes to the open run; the sandbox key is never presented here.
177
+ const sandboxContext = await deps.wallet.getState('sandbox_context');
139
178
  const res = await deps.fetch(`${baseUrl}/v1${path}`, {
140
179
  method: 'POST',
141
180
  headers: {
142
181
  'content-type': 'application/json',
143
182
  [signatureHeader]: signature,
144
- ...(sandboxKey && { 'x-aura-sandbox-key': sandboxKey }),
183
+ ...(sandboxContext && { 'x-aura-sandbox-context': sandboxContext }),
145
184
  },
146
185
  body: bodyString,
147
186
  });
148
187
  let json = null;
149
188
  try { json = await res.json(); } catch { /* non-JSON body */ }
150
- return { status: res.status, json, sandboxKeyAttached: Boolean(sandboxKey) };
189
+ return { status: res.status, json, sandboxContextAttached: Boolean(sandboxContext) };
151
190
  }
152
191
 
192
+ // A refusal is relayed as Core's error, its message and, when Core gives one, its reason
193
+ // (the closed list of invalid_principal_binding). No other member of the answer is copied.
153
194
  const apiError = (r) => ({
154
195
  status: 'error',
155
196
  http: r.status,
156
197
  error: r.json?.error ?? 'unknown_error',
157
198
  message: r.json?.message ?? 'The bench returned a non-success response.',
199
+ ...(typeof r.json?.reason === 'string' && { reason: r.json.reason }),
158
200
  });
159
201
 
202
+ // --- the principal binding (DEC-249) ----------------------------------------
203
+
204
+ // The presentation window of a binding, in seconds. The tool signs a binding and presents
205
+ // it in the same call, so the window covers the request and a client clock up to five
206
+ // minutes behind Core. Core admits an iat up to 300 seconds ahead of its own clock, and the
207
+ // profile allows at most 86400.
208
+ const BINDING_LIFETIME_SECONDS = 300;
209
+
210
+ /**
211
+ * The nine claims of an agent binding, for the two keys the wallet holds. aud is the host
212
+ * of the configured bench URL: a binding names the Core it is presented to, and Core
213
+ * compares it with its own canonical host. jti is drawn per call, since Core records a
214
+ * binding identifier once.
215
+ */
216
+ async function bindingClaims(deps, { principalId, type, capacity }) {
217
+ const iat = Math.floor(Date.now() / 1000);
218
+ return {
219
+ principal_id: principalId.toLowerCase(),
220
+ agent_key_id: keyFingerprint(await deps.wallet.publicKey('agent')),
221
+ agent_type: type,
222
+ capacity,
223
+ aud: new URL(deps.baseUrl || DEFAULT_BASE_URL).host,
224
+ kid: keyFingerprint(await deps.wallet.publicKey('principal')),
225
+ iat,
226
+ exp: iat + BINDING_LIFETIME_SECONDS,
227
+ jti: crypto.randomBytes(16).toString('hex'),
228
+ };
229
+ }
230
+
160
231
  // --- the domain-control proof the mint requires (mirrors Core's derivation) ---
161
232
 
162
233
  export function domainProof(domain, method, publicKeyBase64) {
@@ -182,7 +253,7 @@ export async function handleGetAdmissionGuide(args, deps) {
182
253
  if (r.status !== 200) return apiError(r);
183
254
  return {
184
255
  status: 'ok',
185
- recommended_tool_order: ['get_admission_guide', 'mint_sandbox_key', 'provision_sandbox', 'register_principal', 'register_agent', 'reset_sandbox'],
256
+ recommended_tool_order: ['get_admission_guide', 'mint_sandbox_key', 'provision_sandbox', 'register_principal', 'register_agent'],
186
257
  ordering_note: ORDER_NOTE,
187
258
  guide: r.json,
188
259
  };
@@ -238,21 +309,37 @@ export async function handleMintSandboxKey(args, deps) {
238
309
  export async function handleProvisionSandbox(args, deps) {
239
310
  const sandboxKey = await deps.wallet.getState('sandbox_key');
240
311
  if (!sandboxKey) return { status: 'error', error: 'no_sandbox_key', message: 'Mint a sandbox key first: mint_sandbox_key.' };
241
- const r = await call(deps, 'POST', '/sandbox/namespaces', { headers: { 'x-aura-sandbox-key': sandboxKey } });
242
- if (r.status === 201 || r.status === 200) {
243
- await deps.wallet.setState('namespace_id', r.json.namespace_id);
244
- if (r.json.run_id) await deps.wallet.setState('run_id', r.json.run_id);
245
- return {
246
- status: r.status === 201 ? 'provisioned' : 'already_provisioned',
247
- namespace_id: r.json.namespace_id,
248
- run_id: r.json.run_id ?? null,
249
- scenario_version: r.json.scenario_version,
250
- quotas: r.json.quotas,
251
- counterparties: r.json.counterparties,
252
- note: 'The conformance run is open; registrations from here on are recorded into it.',
253
- };
312
+
313
+ // Step 1 (agent-carried, DEC-228): get a signed grant from the Dev Centre (agentcentre). It charges
314
+ // quota and mints the namespace, then returns a grant + the exact bench URL to call. It does NOT
315
+ // provision — the agent does, so the once-shown context never crosses the Dev Centre.
316
+ const g = await callDevCentre(deps, 'POST', '/provision', { headers: { 'x-aura-sandbox-key': sandboxKey } });
317
+ if (g.status !== 201 && g.status !== 200) return apiError(g);
318
+ const { namespace_id, tier, grant, signature, provision_url } = g.json || {};
319
+ if (!grant || !signature || !provision_url) {
320
+ return { status: 'error', error: 'malformed_grant', message: 'The Dev Centre did not return a usable provision grant.' };
254
321
  }
255
- return apiError(r);
322
+ await deps.wallet.setState('namespace_id', namespace_id);
323
+
324
+ // Step 2: carry the grant to the Bench Core directly and materialise the tenant. The manifest, the
325
+ // opened run_id, and the once-shown sandbox_context come straight from the bench.
326
+ const benchGrant = Buffer.from(JSON.stringify({ grant, signature })).toString('base64');
327
+ const b = await callBenchGrant(deps, provision_url, benchGrant);
328
+ if (b.status !== 201 && b.status !== 200) return apiError(b);
329
+ if (b.json.run_id) await deps.wallet.setState('run_id', b.json.run_id);
330
+ // Hold the shown-once run context (DEC-190): registration presents it to attribute the recorded run
331
+ // without carrying the build credential (the unweld, DEC-192).
332
+ if (b.json.sandbox_context) await deps.wallet.setState('sandbox_context', b.json.sandbox_context);
333
+ return {
334
+ status: b.status === 201 ? 'provisioned' : 'already_provisioned',
335
+ namespace_id,
336
+ tier: tier ?? b.json.quotas?.tier ?? null,
337
+ run_id: b.json.run_id ?? null,
338
+ scenario_version: b.json.scenario_version,
339
+ quotas: b.json.quotas,
340
+ counterparties: b.json.counterparties,
341
+ note: 'The conformance run is open; registrations from here on are recorded into it.',
342
+ };
256
343
  }
257
344
 
258
345
  export async function handleRegisterPrincipal(args, deps) {
@@ -270,14 +357,24 @@ export async function handleRegisterPrincipal(args, deps) {
270
357
  status: 'registered',
271
358
  principal_id: r.json.principal_id,
272
359
  verification_level: r.json.verification_level,
273
- ...(!r.sandboxKeyAttached && { warning: 'No sandbox key was held, so this registration is not namespace-stamped and was NOT recorded into any run. Mint and provision first for a recorded onboarding.' }),
360
+ ...(!r.sandboxContextAttached && { warning: 'No run context was held, so this registration was NOT recorded into any run. Provision first (it issues the context) for a recorded onboarding.' }),
274
361
  };
275
362
  }
276
363
  return apiError(r);
277
364
  }
278
365
 
279
366
  export async function handleRegisterAgent(args, deps) {
280
- const principalId = args.principal_id ?? (await deps.wallet.getState('principal_id'));
367
+ const principalId = await deps.wallet.getState('principal_id');
368
+ // SECURITY: separation of duty (ADR-018, DEC-249). The wallet signs a binding only for
369
+ // the principal whose key it holds. A principal_id that is not the held one is refused
370
+ // here, before any request: the comparison is exact, so another letter case is another id.
371
+ if (args.principal_id !== undefined && args.principal_id !== principalId) {
372
+ return {
373
+ status: 'error',
374
+ error: 'principal_not_held',
375
+ message: 'This wallet holds no key for that principal, so it cannot sign the binding Core requires. Omit principal_id to register under the principal held from register_principal.',
376
+ };
377
+ }
281
378
  if (!principalId) return { status: 'error', error: 'no_principal', message: 'Register the principal first: register_principal.' };
282
379
  const body = {
283
380
  public_key: await deps.wallet.publicKey('agent'),
@@ -286,38 +383,27 @@ export async function handleRegisterAgent(args, deps) {
286
383
  capacity: 'agent_for_principal',
287
384
  manifest: {},
288
385
  };
386
+ // The principal slot signs the binding of the agent key, through the one wallet method
387
+ // that builds the signed bytes itself. The body then carries it, so the agent slot's
388
+ // proof of possession below covers the binding it presents.
389
+ const claims = await bindingClaims(deps, { principalId, type: body.type, capacity: body.capacity });
390
+ body.principal_binding = { claims, signature: await deps.wallet.signAgentBinding(claims) };
289
391
  const r = await callSigned(deps, '/agents/register', body, 'x-agent-signature', 'agent');
290
392
  if (r.status === 201 || r.status === 200) {
291
393
  await deps.wallet.setState('agent_id', r.json.agent_id);
394
+ // Core states the binding it recorded. A Core that does not yet require one accepts
395
+ // this body, ignores the member and answers with none, so the tool reports the status
396
+ // Core gave and never infers it from the request it sent.
397
+ const attested = r.json.binding?.status === 'attested';
292
398
  return {
293
399
  status: 'registered',
294
400
  agent_id: r.json.agent_id,
295
401
  principal_id: r.json.principal_id,
296
- ...(!r.sandboxKeyAttached && { warning: 'No sandbox key was held, so this registration is not namespace-stamped and was NOT recorded into any run. Mint and provision first for a recorded onboarding.' }),
297
- };
298
- }
299
- return apiError(r);
300
- }
301
-
302
- export async function handleResetSandbox(args, deps) {
303
- const sandboxKey = await deps.wallet.getState('sandbox_key');
304
- if (!sandboxKey) return { status: 'error', error: 'no_sandbox_key', message: 'Mint a sandbox key first: mint_sandbox_key.' };
305
- const r = await call(deps, 'POST', '/sandbox/namespaces/current/reset', {
306
- headers: { 'x-aura-sandbox-key': sandboxKey },
307
- ...(args.reason && { body: { reason: args.reason } }),
308
- });
309
- if (r.status === 200) {
310
- await deps.wallet.setState('run_id', r.json.run_id);
311
- return {
312
- status: 'reset',
313
- run_id: r.json.run_id,
314
- namespace_id: r.json.namespace_id,
315
- scenario_version: r.json.scenario_version,
316
- note: 'A fresh run is open; prior runs and their transcripts survive.',
402
+ binding: attested ? 'attested' : 'unattested',
403
+ ...(!attested && { binding_warning: 'Core answered this registration with no attested binding, so it holds no binding for this agent. A Core that requires the binding refuses the agent outside its own record. Call register_agent again: it signs a new binding for the same key, and a Core that requires one records it.' }),
404
+ ...(!r.sandboxContextAttached && { warning: 'No run context was held, so this registration was NOT recorded into any run. Provision first (it issues the context) for a recorded onboarding.' }),
317
405
  };
318
406
  }
319
- if (r.status === 409) return { status: 'run_active', error: r.json?.error, message: r.json?.message };
320
- if (r.status === 429) return { status: 'quota_exhausted', error: r.json?.error, message: r.json?.message, quota: r.json?.quota, tier: r.json?.tier };
321
407
  return apiError(r);
322
408
  }
323
409
 
@@ -327,5 +413,4 @@ export const TOOL_HANDLERS = {
327
413
  provision_sandbox: handleProvisionSandbox,
328
414
  register_principal: handleRegisterPrincipal,
329
415
  register_agent: handleRegisterAgent,
330
- reset_sandbox: handleResetSandbox,
331
416
  };
package/src/wallet.js CHANGED
@@ -5,9 +5,14 @@
5
5
  * enforces fingerprint uniqueness across principals, agents, key history, and
6
6
  * sandbox keys, so the domain key can never be the principal or agent key):
7
7
  *
8
- * principal — signs the principal registration (X-Signature)
9
- * agent — signs the agent registration (X-Agent-Signature)
10
- * domain — signs the sandbox-key mint (X-Signature)
8
+ * principal: signs the principal registration (X-Signature) and the agent binding
9
+ * agent: signs the agent registration (X-Agent-Signature)
10
+ * domain: signs the sandbox-key mint (X-Signature)
11
+ *
12
+ * The agent binding (DEC-249) is the principal's signature over the agent key. The
13
+ * wallet signs it through signAgentBinding alone, which builds the signed bytes from
14
+ * the claims and signs only for the two keys this wallet holds. sign refuses those
15
+ * bytes for every slot, so no caller hands the principal key a binding to sign.
11
16
  *
12
17
  * plus a state record for what the chain returns (the bearer sandbox key,
13
18
  * principal_id, agent_id, namespace_id, run_id), so identity survives across
@@ -21,6 +26,7 @@
21
26
  */
22
27
 
23
28
  import crypto from 'node:crypto';
29
+ import { AGENT_BINDING_DOMAIN_PREFIX, BINDING_CLAIMS, buildAgentBindingPayload, keyFingerprint } from './agent-binding.js';
24
30
 
25
31
  // Ed25519 DER prefixes for raw key <-> KeyObject conversion (same constants the
26
32
  // scout SDK KeyManager uses).
@@ -28,8 +34,9 @@ const SPKI_PREFIX = Buffer.from('302a300506032b6570032100', 'hex');
28
34
  const PKCS8_PREFIX = Buffer.from('302e020100300506032b657004220420', 'hex');
29
35
 
30
36
  const SLOTS = ['principal', 'agent', 'domain'];
31
- const STATE_FIELDS = ['sandbox_key', 'principal_id', 'agent_id', 'namespace_id', 'run_id'];
37
+ const STATE_FIELDS = ['sandbox_key', 'sandbox_context', 'principal_id', 'agent_id', 'namespace_id', 'run_id'];
32
38
  const PREFIX = 'aura:admission:';
39
+ const BINDING_PREFIX_BYTES = Buffer.from(AGENT_BINDING_DOMAIN_PREFIX);
33
40
 
34
41
  export class AdmissionWallet {
35
42
  #storage;
@@ -68,13 +75,51 @@ export class AdmissionWallet {
68
75
  /**
69
76
  * Sign a string with a slot's private key. The signature is the only thing
70
77
  * that ever leaves the wallet.
78
+ *
79
+ * SECURITY: separation of duty (ADR-018, DEC-249). Data that begins with the agent
80
+ * binding prefix is refused for every slot: a binding is signed through
81
+ * signAgentBinding, which builds the bytes itself.
82
+ *
71
83
  * @param {'principal'|'agent'|'domain'} slot
72
84
  * @param {string} data
73
85
  * @returns {Promise<string>} base64 Ed25519 signature
74
86
  */
75
87
  async sign(slot, data) {
88
+ const bytes = Buffer.from(data);
89
+ if (bytes.subarray(0, BINDING_PREFIX_BYTES.length).equals(BINDING_PREFIX_BYTES)) {
90
+ throw new Error('sign refuses an agent binding payload: a binding is signed through signAgentBinding');
91
+ }
76
92
  const k = await this.#load(slot);
77
- return crypto.sign(null, Buffer.from(data), k.privateKeyObject).toString('base64');
93
+ return crypto.sign(null, bytes, k.privateKeyObject).toString('base64');
94
+ }
95
+
96
+ /**
97
+ * Sign an agent binding with the principal slot (signature profile agent_binding).
98
+ * The wallet builds the signed bytes from the claims: the domain prefix, then their
99
+ * canonical JSON. The caller hands over claims and no bytes.
100
+ *
101
+ * SECURITY: separation of duty (ADR-018, DEC-249). The principal key signs a binding
102
+ * only for the agent key this wallet holds, and only as itself. A claim set that is not
103
+ * exactly the nine, a kid that is not the principal slot's key and an agent_key_id that
104
+ * is not the agent slot's key are each refused, and nothing is signed.
105
+ *
106
+ * @param {object} claims - the nine claims of the profile
107
+ * @returns {Promise<string>} base64 Ed25519 signature over the binding payload
108
+ */
109
+ async signAgentBinding(claims) {
110
+ const named = claims !== null && typeof claims === 'object' && !Array.isArray(claims) ? Object.keys(claims) : [];
111
+ if (named.length !== BINDING_CLAIMS.length || !BINDING_CLAIMS.every((claim) => named.includes(claim))) {
112
+ throw new Error('an agent binding carries exactly the nine claims of the agent_binding profile');
113
+ }
114
+ const principal = await this.#load('principal');
115
+ if (claims.kid !== keyFingerprint(principal.publicKeyBase64)) {
116
+ throw new Error('kid does not name the principal key this wallet holds');
117
+ }
118
+ const agent = await this.#load('agent');
119
+ if (claims.agent_key_id !== keyFingerprint(agent.publicKeyBase64)) {
120
+ throw new Error('agent_key_id does not name the agent key this wallet holds');
121
+ }
122
+ return crypto.sign(null, Buffer.from(buildAgentBindingPayload(claims)), principal.privateKeyObject).toString('base64');
78
123
  }
79
124
 
80
125
  /** @param {string} field @returns {Promise<string|null>} */