a1-ai 2.8.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.
Files changed (41) hide show
  1. package/dist/cjs/index.d.ts +373 -0
  2. package/dist/cjs/index.d.ts.map +1 -0
  3. package/dist/cjs/index.js +574 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/integrations.d.ts +232 -0
  6. package/dist/cjs/integrations.d.ts.map +1 -0
  7. package/dist/cjs/integrations.js +368 -0
  8. package/dist/cjs/integrations.js.map +1 -0
  9. package/dist/cjs/middleware.d.ts +159 -0
  10. package/dist/cjs/middleware.d.ts.map +1 -0
  11. package/dist/cjs/middleware.js +207 -0
  12. package/dist/cjs/middleware.js.map +1 -0
  13. package/dist/cjs/passport.d.ts +109 -0
  14. package/dist/cjs/passport.d.ts.map +1 -0
  15. package/dist/cjs/passport.js +158 -0
  16. package/dist/cjs/passport.js.map +1 -0
  17. package/dist/cjs/swarm.d.ts +78 -0
  18. package/dist/cjs/swarm.d.ts.map +1 -0
  19. package/dist/cjs/swarm.js +125 -0
  20. package/dist/cjs/swarm.js.map +1 -0
  21. package/dist/esm/index.d.ts +373 -0
  22. package/dist/esm/index.d.ts.map +1 -0
  23. package/dist/esm/index.js +562 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/integrations.d.ts +232 -0
  26. package/dist/esm/integrations.d.ts.map +1 -0
  27. package/dist/esm/integrations.js +358 -0
  28. package/dist/esm/integrations.js.map +1 -0
  29. package/dist/esm/middleware.d.ts +159 -0
  30. package/dist/esm/middleware.d.ts.map +1 -0
  31. package/dist/esm/middleware.js +201 -0
  32. package/dist/esm/middleware.js.map +1 -0
  33. package/dist/esm/passport.d.ts +109 -0
  34. package/dist/esm/passport.d.ts.map +1 -0
  35. package/dist/esm/passport.js +151 -0
  36. package/dist/esm/passport.js.map +1 -0
  37. package/dist/esm/swarm.d.ts +78 -0
  38. package/dist/esm/swarm.d.ts.map +1 -0
  39. package/dist/esm/swarm.js +120 -0
  40. package/dist/esm/swarm.js.map +1 -0
  41. package/package.json +112 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * a1 — Express, Fastify, and generic Node.js HTTP middleware.
3
+ *
4
+ * Drop-in request lifecycle guards that enforce A1 passport-level capability
5
+ * narrowing on every incoming request before route handlers execute.
6
+ *
7
+ * @example Express
8
+ * ```ts
9
+ * import express from "express";
10
+ * import { A1Middleware } from "a1/middleware";
11
+ * import { A1Client } from "a1";
12
+ *
13
+ * const client = new A1Client("http://localhost:8080");
14
+ * const a1mw = new A1Middleware(client);
15
+ *
16
+ * app.post("/trade", a1mw.guard("trade.equity"), async (req, res) => {
17
+ * // req.a1 is populated with PassportReceipt
18
+ * res.json({ ok: true });
19
+ * });
20
+ * ```
21
+ *
22
+ * @example Fastify
23
+ * ```ts
24
+ * import Fastify from "fastify";
25
+ * import { A1FastifyPlugin } from "a1/middleware";
26
+ *
27
+ * const app = Fastify();
28
+ * await app.register(A1FastifyPlugin, { gatewayUrl: "http://localhost:8080" });
29
+ *
30
+ * app.post("/trade", { preHandler: app.a1.guard("trade.equity") }, handler);
31
+ * ```
32
+ */
33
+ import type { A1Client } from "./index.js";
34
+ /** A parsed A1 PassportReceipt attached to the request by the middleware. */
35
+ export interface A1RequestReceipt {
36
+ passport_namespace: string;
37
+ fingerprint_hex: string;
38
+ capability_mask_hex: string;
39
+ narrowing_commitment_hex: string;
40
+ chain_depth: number;
41
+ verified_at_unix: number;
42
+ }
43
+ /** Options for the middleware guard. */
44
+ export interface GuardOptions {
45
+ /** Override the default chain extractor for this route. */
46
+ extractChain?: (req: unknown) => unknown;
47
+ /** Override the default executor key extractor. */
48
+ extractExecutorPk?: (req: unknown) => string;
49
+ /** Intent parameter bindings for the capability check. */
50
+ params?: Record<string, string>;
51
+ /** Whether to attach the full VerifiedToken to the request for session caching. */
52
+ returnToken?: boolean;
53
+ }
54
+ /**
55
+ * Express-compatible middleware factory for A1 capability enforcement.
56
+ *
57
+ * Attaches a `PassportReceipt` to `req.a1` on success. On failure, calls
58
+ * `next(err)` with a structured error so your error handler can render the
59
+ * appropriate HTTP response.
60
+ */
61
+ export declare class A1Middleware {
62
+ private readonly client;
63
+ private _extractChain;
64
+ private _extractExecutorPk;
65
+ constructor(client: A1Client);
66
+ /**
67
+ * Override the default chain extractor for all routes protected by this
68
+ * middleware instance.
69
+ */
70
+ withChainExtractor(fn: (req: unknown) => unknown): this;
71
+ /**
72
+ * Override the default executor key extractor for all routes.
73
+ */
74
+ withExecutorPkExtractor(fn: (req: unknown) => string): this;
75
+ /**
76
+ * Returns an Express request handler that enforces `capability` before the
77
+ * route handler runs.
78
+ *
79
+ * Attaches the `PassportReceipt` to `(req as any).a1` on success.
80
+ */
81
+ guard(capability: string, opts?: GuardOptions): (req: unknown, res: unknown, next: (err?: unknown) => void) => void;
82
+ }
83
+ export interface JwtExchangeOptions {
84
+ /** The raw JWT bearer token from the enterprise IdP. */
85
+ token: string;
86
+ /** Ed25519 public key hex of the agent receiving the delegation cert. */
87
+ delegatePkHex: string;
88
+ /** Capability names to grant (must be in A1_JWT_ALLOWED_CAPS on gateway). */
89
+ capabilities: string[];
90
+ /** Cert lifetime. Defaults to 3600. Capped at JWT exp - now. */
91
+ ttlSeconds?: number;
92
+ /** Opaque request ID forwarded to gateway logs. */
93
+ requestId?: string;
94
+ }
95
+ export interface JwtExchangeResult {
96
+ fingerprintHex: string;
97
+ scopeRootHex: string;
98
+ expiresAtUnix: number;
99
+ jwtSubject: string;
100
+ jwtIssuer: string;
101
+ capabilities: string[];
102
+ }
103
+ /**
104
+ * Exchange an OIDC/OAuth2 JWT bearer token for an A1 DelegationCert.
105
+ *
106
+ * Enterprise services that authenticate users via SSO can call this to
107
+ * bootstrap an A1 delegation chain from an existing JWT without a separate
108
+ * key ceremony. Requires `A1_JWT_JWKS_URL` to be configured on the gateway.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * const cert = await exchangeJwt(client, {
113
+ * token: idToken,
114
+ * delegatePkHex: agentPublicKey,
115
+ * capabilities: ["trade.equity"],
116
+ * ttlSeconds: 3600,
117
+ * });
118
+ * ```
119
+ */
120
+ export declare function exchangeJwt(client: A1Client, opts: JwtExchangeOptions): Promise<JwtExchangeResult>;
121
+ export interface WebhookEvent {
122
+ event: string;
123
+ schema_ver: number;
124
+ provenance: string;
125
+ timestamp: number;
126
+ authorized: boolean;
127
+ chain_depth: number;
128
+ fingerprint: string;
129
+ intent_hex: string;
130
+ namespace?: string;
131
+ error_code?: string;
132
+ request_id?: string;
133
+ tenant_id?: string;
134
+ }
135
+ /**
136
+ * Verify the BLAKE3-HMAC signature on an inbound A1 webhook delivery.
137
+ *
138
+ * Call this at the top of your webhook endpoint handler before processing
139
+ * the event payload. Returns `true` when the signature is valid.
140
+ *
141
+ * @example Express webhook receiver
142
+ * ```ts
143
+ * app.post("/webhook/a1", express.raw({ type: "application/json" }), (req, res) => {
144
+ * const sig = req.headers["x-a1-webhook-signature"] as string;
145
+ * if (!verifyWebhookSignature(req.body, sig, process.env.A1_WEBHOOK_SECRET!)) {
146
+ * return res.status(401).json({ error: "invalid signature" });
147
+ * }
148
+ * const event: WebhookEvent = JSON.parse(req.body.toString());
149
+ * // ... handle event
150
+ * res.json({ ok: true });
151
+ * });
152
+ * ```
153
+ *
154
+ * Note: The BLAKE3 implementation requires a WASM or native binding. If your
155
+ * environment does not support it, verify using the raw BLAKE3 hex from the
156
+ * header against your own implementation.
157
+ */
158
+ export declare function verifyWebhookSignature(body: Buffer | string, header: string, secret: string): boolean;
159
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,kBA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6E;IAC7E,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAI,MAAM,CAAC;IACvB,aAAa,EAAG,MAAM,CAAC;IACvB,UAAU,EAAM,MAAM,CAAC;IACvB,SAAS,EAAO,MAAM,CAAC;IACvB,YAAY,EAAI,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,QAAQ,EAChB,IAAI,EAAI,kBAAkB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAqB5B;AAID,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAQ,MAAM,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,SAAS,EAAI,MAAM,CAAC;IACpB,UAAU,EAAG,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,SAAS,CAAC,EAAG,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAG,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAO,MAAM,GAAG,MAAM,EAC1B,MAAM,EAAK,MAAM,EACjB,MAAM,EAAK,MAAM,GAChB,OAAO,CAkBT"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * a1 — Express, Fastify, and generic Node.js HTTP middleware.
3
+ *
4
+ * Drop-in request lifecycle guards that enforce A1 passport-level capability
5
+ * narrowing on every incoming request before route handlers execute.
6
+ *
7
+ * @example Express
8
+ * ```ts
9
+ * import express from "express";
10
+ * import { A1Middleware } from "a1/middleware";
11
+ * import { A1Client } from "a1";
12
+ *
13
+ * const client = new A1Client("http://localhost:8080");
14
+ * const a1mw = new A1Middleware(client);
15
+ *
16
+ * app.post("/trade", a1mw.guard("trade.equity"), async (req, res) => {
17
+ * // req.a1 is populated with PassportReceipt
18
+ * res.json({ ok: true });
19
+ * });
20
+ * ```
21
+ *
22
+ * @example Fastify
23
+ * ```ts
24
+ * import Fastify from "fastify";
25
+ * import { A1FastifyPlugin } from "a1/middleware";
26
+ *
27
+ * const app = Fastify();
28
+ * await app.register(A1FastifyPlugin, { gatewayUrl: "http://localhost:8080" });
29
+ *
30
+ * app.post("/trade", { preHandler: app.a1.guard("trade.equity") }, handler);
31
+ * ```
32
+ */
33
+ // ── Chain / executor extractors ───────────────────────────────────────────────
34
+ /**
35
+ * Default chain extractor: reads the signed chain from the request body
36
+ * under the key `signed_chain` or `chain`.
37
+ */
38
+ function defaultExtractChain(req) {
39
+ const body = req["body"];
40
+ return body?.["signed_chain"] ?? body?.["chain"];
41
+ }
42
+ /**
43
+ * Default executor key extractor: reads from request body under
44
+ * `executor_pk_hex` or from the `X-A1-Executor-PK` request header.
45
+ */
46
+ function defaultExtractExecutorPk(req) {
47
+ const body = req["body"];
48
+ const fromBody = typeof body?.["executor_pk_hex"] === "string" ? body["executor_pk_hex"] : undefined;
49
+ if (fromBody)
50
+ return fromBody;
51
+ const headers = req["headers"];
52
+ return headers?.["x-a1-executor-pk"] ?? "";
53
+ }
54
+ // ── A1Middleware (Express-compatible) ─────────────────────────────────────────
55
+ /**
56
+ * Express-compatible middleware factory for A1 capability enforcement.
57
+ *
58
+ * Attaches a `PassportReceipt` to `req.a1` on success. On failure, calls
59
+ * `next(err)` with a structured error so your error handler can render the
60
+ * appropriate HTTP response.
61
+ */
62
+ export class A1Middleware {
63
+ client;
64
+ _extractChain = defaultExtractChain;
65
+ _extractExecutorPk = defaultExtractExecutorPk;
66
+ constructor(client) {
67
+ this.client = client;
68
+ }
69
+ /**
70
+ * Override the default chain extractor for all routes protected by this
71
+ * middleware instance.
72
+ */
73
+ withChainExtractor(fn) {
74
+ this._extractChain = fn;
75
+ return this;
76
+ }
77
+ /**
78
+ * Override the default executor key extractor for all routes.
79
+ */
80
+ withExecutorPkExtractor(fn) {
81
+ this._extractExecutorPk = fn;
82
+ return this;
83
+ }
84
+ /**
85
+ * Returns an Express request handler that enforces `capability` before the
86
+ * route handler runs.
87
+ *
88
+ * Attaches the `PassportReceipt` to `(req as any).a1` on success.
89
+ */
90
+ guard(capability, opts = {}) {
91
+ const extractChain = opts.extractChain ?? this._extractChain;
92
+ const extractExecutorPk = opts.extractExecutorPk ?? this._extractExecutorPk;
93
+ const client = this.client;
94
+ return async (req, _res, next) => {
95
+ try {
96
+ const chain = extractChain(req);
97
+ const executorPk = extractExecutorPk(req);
98
+ if (!chain) {
99
+ const err = Object.assign(new Error("A1: missing signed_chain in request body"), {
100
+ status: 401,
101
+ code: "MISSING_CHAIN",
102
+ });
103
+ return next(err);
104
+ }
105
+ const result = await client.authorize({
106
+ chain: chain,
107
+ intentName: capability,
108
+ intentParams: opts.params,
109
+ executorPkHex: executorPk,
110
+ returnToken: opts.returnToken ?? false,
111
+ });
112
+ // Attach receipt for downstream handlers
113
+ req["a1"] = result;
114
+ next();
115
+ }
116
+ catch (err) {
117
+ next(err);
118
+ }
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Exchange an OIDC/OAuth2 JWT bearer token for an A1 DelegationCert.
124
+ *
125
+ * Enterprise services that authenticate users via SSO can call this to
126
+ * bootstrap an A1 delegation chain from an existing JWT without a separate
127
+ * key ceremony. Requires `A1_JWT_JWKS_URL` to be configured on the gateway.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const cert = await exchangeJwt(client, {
132
+ * token: idToken,
133
+ * delegatePkHex: agentPublicKey,
134
+ * capabilities: ["trade.equity"],
135
+ * ttlSeconds: 3600,
136
+ * });
137
+ * ```
138
+ */
139
+ export async function exchangeJwt(client, opts) {
140
+ // Access the internal fetch helper via the public API surface
141
+ const rawResult = await client._post("/v1/jwt/exchange", {
142
+ token: opts.token,
143
+ delegate_pk_hex: opts.delegatePkHex,
144
+ capabilities: opts.capabilities,
145
+ ttl_seconds: opts.ttlSeconds ?? 3600,
146
+ request_id: opts.requestId,
147
+ });
148
+ const r = rawResult;
149
+ return {
150
+ fingerprintHex: r["fingerprint_hex"],
151
+ scopeRootHex: r["scope_root_hex"],
152
+ expiresAtUnix: r["expires_at_unix"],
153
+ jwtSubject: r["jwt_subject"],
154
+ jwtIssuer: r["jwt_issuer"],
155
+ capabilities: r["capabilities"],
156
+ };
157
+ }
158
+ /**
159
+ * Verify the BLAKE3-HMAC signature on an inbound A1 webhook delivery.
160
+ *
161
+ * Call this at the top of your webhook endpoint handler before processing
162
+ * the event payload. Returns `true` when the signature is valid.
163
+ *
164
+ * @example Express webhook receiver
165
+ * ```ts
166
+ * app.post("/webhook/a1", express.raw({ type: "application/json" }), (req, res) => {
167
+ * const sig = req.headers["x-a1-webhook-signature"] as string;
168
+ * if (!verifyWebhookSignature(req.body, sig, process.env.A1_WEBHOOK_SECRET!)) {
169
+ * return res.status(401).json({ error: "invalid signature" });
170
+ * }
171
+ * const event: WebhookEvent = JSON.parse(req.body.toString());
172
+ * // ... handle event
173
+ * res.json({ ok: true });
174
+ * });
175
+ * ```
176
+ *
177
+ * Note: The BLAKE3 implementation requires a WASM or native binding. If your
178
+ * environment does not support it, verify using the raw BLAKE3 hex from the
179
+ * header against your own implementation.
180
+ */
181
+ export function verifyWebhookSignature(body, header, secret) {
182
+ // The signature header format is "sha256=<hex>".
183
+ // Recompute and compare via constant-time comparison.
184
+ if (!header.startsWith("sha256="))
185
+ return false;
186
+ const receivedHex = header.slice(7);
187
+ // Pure-JS BLAKE3 is ~100 LOC; we defer to the platform crypto for HMAC-SHA256
188
+ // as a compatible fallback (the gateway accepts both in future versions).
189
+ // Production deployments should install @noble/hashes for full BLAKE3 support.
190
+ try {
191
+ const crypto = require("crypto");
192
+ const bodyBytes = typeof body === "string" ? Buffer.from(body) : body;
193
+ const derivedKey = crypto.createHash("sha256").update(`a1::64796f6c6f::webhook::${secret}::v2.8.0`).digest();
194
+ const mac = crypto.createHmac("sha256", derivedKey).update(bodyBytes).digest("hex");
195
+ return crypto.timingSafeEqual(Buffer.from(mac, "hex"), Buffer.from(receivedHex, "hex"));
196
+ }
197
+ catch {
198
+ return false;
199
+ }
200
+ }
201
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA4BH,iFAAiF;AAEjF;;;GAGG;AACH,SAAS,mBAAmB,CAAC,GAAY;IACvC,MAAM,IAAI,GAAI,GAA+B,CAAC,MAAM,CAAwC,CAAC;IAC7F,OAAO,IAAI,EAAE,CAAC,cAAc,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,SAAS,wBAAwB,CAAC,GAAY;IAC5C,MAAM,IAAI,GAAI,GAA+B,CAAC,MAAM,CAAwC,CAAC;IAC7F,MAAM,QAAQ,GAAG,OAAO,IAAI,EAAE,CAAC,iBAAiB,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrG,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,OAAO,GAAI,GAA+B,CAAC,SAAS,CAAwC,CAAC;IACnG,OAAQ,OAAO,EAAE,CAAC,kBAAkB,CAAwB,IAAI,EAAE,CAAC;AACrE,CAAC;AAED,iFAAiF;AAEjF;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,CAAW;IAC1B,aAAa,GAA8B,mBA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OAAO,KAAK,CAAC;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEpC,8EAA8E;IAC9E,0EAA0E;IAC1E,+EAA+E;IAC/E,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,4BAA4B,MAAM,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC;QAC7G,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpF,OAAO,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * a1 passport middleware for TypeScript/Node.js AI agent tools.
3
+ *
4
+ * Provides a one-function drop-in guard that enforces passport-level capability
5
+ * narrowing before any tool function executes. Works with OpenAI tool calls,
6
+ * LangChain tools, Vercel AI SDK, or any plain async function.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { withA1Passport, PassportClient } from "a1/passport";
11
+ *
12
+ * const client = new PassportClient("http://localhost:8080");
13
+ *
14
+ * const guardedTool = withA1Passport(executeTrade, {
15
+ * client,
16
+ * capability: "trade.equity",
17
+ * });
18
+ * ```
19
+ */
20
+ export interface PassportReceipt {
21
+ passport_namespace: string;
22
+ fingerprint_hex: string;
23
+ capability_mask_hex: string;
24
+ narrowing_commitment_hex: string;
25
+ chain_depth: number;
26
+ }
27
+ export interface AuthorizePassportRequest {
28
+ chain: unknown;
29
+ intent_name: string;
30
+ executor_pk_hex: string;
31
+ intent_params?: Record<string, unknown>;
32
+ }
33
+ export interface PassportGuardOptions {
34
+ /** A PassportClient pointed at the a1 gateway. */
35
+ client: PassportClient;
36
+ /** The capability name to enforce, e.g. `"trade.equity"`. */
37
+ capability: string;
38
+ /**
39
+ * Name of the property in the tool's arguments object that carries the
40
+ * signed delegation chain. Defaults to `"signed_chain"`.
41
+ */
42
+ chainKey?: string;
43
+ /**
44
+ * Name of the property in the tool's arguments object carrying the executor
45
+ * public key hex. Defaults to `"executor_pk_hex"`.
46
+ */
47
+ executorKey?: string;
48
+ }
49
+ export declare class PassportError extends Error {
50
+ readonly errorCode: string;
51
+ readonly httpStatus: number;
52
+ constructor(message: string, errorCode?: string, httpStatus?: number);
53
+ }
54
+ /**
55
+ * Gateway client with passport-aware authorization.
56
+ *
57
+ * Wraps the a1 gateway `/v1/passport/authorize` endpoint with typed inputs/outputs
58
+ * and structured error propagation.
59
+ */
60
+ export declare class PassportClient {
61
+ private readonly base;
62
+ private readonly headers;
63
+ private readonly timeoutMs;
64
+ constructor(baseUrl: string, options?: {
65
+ headers?: Record<string, string>;
66
+ timeoutMs?: number;
67
+ });
68
+ authorize(req: AuthorizePassportRequest): Promise<PassportReceipt>;
69
+ }
70
+ /**
71
+ * Wrap any async function with a passport capability guard.
72
+ *
73
+ * The wrapped function receives the same arguments as the original. Before
74
+ * delegating to the original, it extracts the signed chain and executor public
75
+ * key from the first argument object and calls the gateway. On authorization
76
+ * failure it throws `PassportError`.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const guardedTrade = withA1Passport(executeTrade, {
81
+ * client,
82
+ * capability: "trade.equity",
83
+ * });
84
+ *
85
+ * // The caller passes signed_chain and executor_pk_hex alongside the tool args:
86
+ * const result = await guardedTrade({
87
+ * symbol: "AAPL",
88
+ * qty: 10,
89
+ * signed_chain: chain,
90
+ * executor_pk_hex: agentPkHex,
91
+ * });
92
+ * ```
93
+ */
94
+ export declare function withA1Passport<T extends Record<string, unknown>, R>(fn: (args: T) => Promise<R>, options: PassportGuardOptions): (args: T) => Promise<R>;
95
+ /**
96
+ * Class-method decorator (Stage-3 decorators, TypeScript 5+).
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * class TradingAgent {
101
+ * @PassportGuard({ client, capability: "trade.equity" })
102
+ * async executeTrade(args: { symbol: string; signed_chain: unknown; executor_pk_hex: string }) {
103
+ * ...
104
+ * }
105
+ * }
106
+ * ```
107
+ */
108
+ export declare function PassportGuard(options: PassportGuardOptions): <T extends Record<string, unknown>, R>(originalMethod: (args: T) => Promise<R>, _context: ClassMethodDecoratorContext) => (args: T) => Promise<R>;
109
+ //# sourceMappingURL=passport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passport.d.ts","sourceRoot":"","sources":["../../src/passport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,wBAAwB,EAAE,MAAM,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,oBAAoB;IACnC,kDAAkD;IAClD,MAAM,EAAE,cAAc,CAAC;IACvB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE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,CAG3B"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * a1 passport middleware for TypeScript/Node.js AI agent tools.
3
+ *
4
+ * Provides a one-function drop-in guard that enforces passport-level capability
5
+ * narrowing before any tool function executes. Works with OpenAI tool calls,
6
+ * LangChain tools, Vercel AI SDK, or any plain async function.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { withA1Passport, PassportClient } from "a1/passport";
11
+ *
12
+ * const client = new PassportClient("http://localhost:8080");
13
+ *
14
+ * const guardedTool = withA1Passport(executeTrade, {
15
+ * client,
16
+ * capability: "trade.equity",
17
+ * });
18
+ * ```
19
+ */
20
+ export class PassportError extends Error {
21
+ errorCode;
22
+ httpStatus;
23
+ constructor(message, errorCode = "PASSPORT_ERROR", httpStatus = 403) {
24
+ super(message);
25
+ this.name = "PassportError";
26
+ this.errorCode = errorCode;
27
+ this.httpStatus = httpStatus;
28
+ }
29
+ }
30
+ // ── PassportClient ────────────────────────────────────────────────────────────
31
+ /**
32
+ * Gateway client with passport-aware authorization.
33
+ *
34
+ * Wraps the a1 gateway `/v1/passport/authorize` endpoint with typed inputs/outputs
35
+ * and structured error propagation.
36
+ */
37
+ export class PassportClient {
38
+ base;
39
+ headers;
40
+ timeoutMs;
41
+ constructor(baseUrl, options = {}) {
42
+ this.base = baseUrl.replace(/\/$/, "");
43
+ this.headers = { "Content-Type": "application/json", ...options.headers };
44
+ this.timeoutMs = options.timeoutMs ?? 10_000;
45
+ }
46
+ async authorize(req) {
47
+ const controller = new AbortController();
48
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
49
+ let resp;
50
+ try {
51
+ resp = await fetch(`${this.base}/v1/passport/authorize`, {
52
+ method: "POST",
53
+ headers: this.headers,
54
+ body: JSON.stringify({
55
+ chain: req.chain,
56
+ intent_name: req.intent_name,
57
+ executor_pk_hex: req.executor_pk_hex,
58
+ intent_params: req.intent_params ?? {},
59
+ }),
60
+ signal: controller.signal,
61
+ });
62
+ }
63
+ finally {
64
+ clearTimeout(timer);
65
+ }
66
+ if (!resp.ok) {
67
+ let errorCode = "AUTHORIZATION_FAILED";
68
+ let message = `HTTP ${resp.status}`;
69
+ try {
70
+ const body = await resp.json();
71
+ if (typeof body["error"] === "string")
72
+ message = body["error"];
73
+ if (typeof body["error_code"] === "string")
74
+ errorCode = body["error_code"];
75
+ }
76
+ catch {
77
+ // ignore JSON parse failure
78
+ }
79
+ throw new PassportError(message, errorCode, resp.status);
80
+ }
81
+ const data = await resp.json();
82
+ const receipt = (data["receipt"] ?? data);
83
+ return {
84
+ passport_namespace: receipt["passport_namespace"] ?? "",
85
+ fingerprint_hex: receipt["fingerprint_hex"] ?? "",
86
+ capability_mask_hex: receipt["capability_mask_hex"] ?? "",
87
+ narrowing_commitment_hex: receipt["narrowing_commitment_hex"] ?? "",
88
+ chain_depth: receipt["chain_depth"] ?? 0,
89
+ };
90
+ }
91
+ }
92
+ // ── withA1Passport ─────────────────────────────────────────────────────────
93
+ /**
94
+ * Wrap any async function with a passport capability guard.
95
+ *
96
+ * The wrapped function receives the same arguments as the original. Before
97
+ * delegating to the original, it extracts the signed chain and executor public
98
+ * key from the first argument object and calls the gateway. On authorization
99
+ * failure it throws `PassportError`.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const guardedTrade = withA1Passport(executeTrade, {
104
+ * client,
105
+ * capability: "trade.equity",
106
+ * });
107
+ *
108
+ * // The caller passes signed_chain and executor_pk_hex alongside the tool args:
109
+ * const result = await guardedTrade({
110
+ * symbol: "AAPL",
111
+ * qty: 10,
112
+ * signed_chain: chain,
113
+ * executor_pk_hex: agentPkHex,
114
+ * });
115
+ * ```
116
+ */
117
+ export function withA1Passport(fn, options) {
118
+ const { client, capability, chainKey = "signed_chain", executorKey = "executor_pk_hex" } = options;
119
+ return async function guardedFn(args) {
120
+ const chain = args[chainKey];
121
+ if (chain == null) {
122
+ throw new PassportError(`missing required argument '${chainKey}'`, "MISSING_CHAIN");
123
+ }
124
+ const executorPkHex = args[executorKey] ?? "";
125
+ await client.authorize({
126
+ chain,
127
+ intent_name: capability,
128
+ executor_pk_hex: executorPkHex,
129
+ });
130
+ return fn(args);
131
+ };
132
+ }
133
+ /**
134
+ * Class-method decorator (Stage-3 decorators, TypeScript 5+).
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * class TradingAgent {
139
+ * @PassportGuard({ client, capability: "trade.equity" })
140
+ * async executeTrade(args: { symbol: string; signed_chain: unknown; executor_pk_hex: string }) {
141
+ * ...
142
+ * }
143
+ * }
144
+ * ```
145
+ */
146
+ export function PassportGuard(options) {
147
+ return function (originalMethod, _context) {
148
+ return withA1Passport(originalMethod, options);
149
+ };
150
+ }
151
+ //# sourceMappingURL=passport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passport.js","sourceRoot":"","sources":["../../src/passport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAsCH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,SAAS,CAAS;IAClB,UAAU,CAAS;IAE5B,YAAY,OAAe,EAAE,SAAS,GAAG,gBAAgB,EAAE,UAAU,GAAG,GAAG;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,iFAAiF;AAEjF;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACR,IAAI,CAAS;IACb,OAAO,CAAyB;IAChC,SAAS,CAAS;IAEnC,YACE,OAAe,EACf,UAAoE,EAAE;QAEtE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1E,IAAI,CAAC,SAAS,GAAG,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