@atlasauth/pca-next 0.1.0 → 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atlas Authorization
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,36 +1,53 @@
1
1
  # @atlasauth/pca-next
2
2
 
3
- Next.js helper for Proof-Carrying Authority: wrap a Route Handler so the inbound PCActn is verified before your handler runs, with a 401/403 response otherwise.
3
+ Next.js (App Router) helper for Proof-Carrying Authority (PCA). `withPCA` wraps a Route Handler so the inbound PCActn is verified with the resource-server guard from `@atlasauth/pca` before your handler runs; otherwise it returns a 401/403 JSON response with a `WWW-Authenticate` challenge. Verification is default-deny.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- npm i @atlasauth/pca-next
9
- # peer dependency, install alongside:
10
- npm i next
8
+ npm i @atlasauth/pca-next @atlasauth/pca
9
+ npm i next # optional peer dependency (^14 || ^15)
11
10
  ```
12
11
 
13
- `next` (v14 or v15) is an optional peer dependency.
14
-
15
12
  ## Usage
16
13
 
17
14
  ```ts
18
15
  // app/refunds/route.ts
19
16
  import { withPCA } from '@atlasauth/pca-next';
17
+ import { memoryPcaStore } from '@atlasauth/pca';
20
18
 
21
19
  export const POST = withPCA(
22
20
  {
23
- audience: 'ins_acme', // this resource server's / instance id the PCActn must name
24
- resolveGrant, // (ref) => Capability — look up the root grant
25
- budgetStore, // per-holder replay/budget store
21
+ audience: 'ins_acme', // this resource server's id; the PCActn's signed `aud` must match
22
+ resolveGrant: async (ref) => grants.get(ref) ?? null, // look up the Root Intent Grant by grant_ref
23
+ budgetStore: memoryPcaStore(), // replay counter store (use a durable one in production)
24
+ hooks: { revocation: async () => ({ enforced: true, ok: !(await isRevoked()) }) }, // revocation checker
25
+ context: async (req, pcactn) => ({ // facts only the resource server can vouch for
26
+ params: { amount: 20, currency: 'usd' },
27
+ plan: authorizedPlanNodes, // your copy of the principal-authorized plan
28
+ planAuthorized: true,
29
+ budget: { B: 500, tau: 0 },
30
+ risk: { blastRadius: 0.04 }, // risk inputs you can vouch for (missing ones fail closed to worst case)
31
+ }),
26
32
  },
27
33
  async (req, { pca }) => {
28
- const { verdict, pcactn } = pca; // handler only runs on a valid PCActn
34
+ const { verdict, pcactn } = pca; // handler only runs for a valid PCActn
29
35
  return Response.json({ ok: true });
30
36
  },
31
37
  );
32
38
  ```
33
39
 
34
- The client sends the PCActn as `PCA-Action: <base64url>` (see `@atlasauth/pca` `pcaHeaders`) or a JSON body `{ pcactn }` — the default extractor reads both. The wrapper verifies and is default-deny; it is the verifier that decides, not the client's proof.
40
+ The client sends the PCActn as a `PCA-Action: <base64url>` header (see `pcaHeaders` in `@atlasauth/pca`) or as a JSON body `{ pcactn }`; the default extractor reads both. The wrapper reads a clone of the request body, so your handler can still read it. By default a deployment must supply `budgetStore`, a `hooks.revocation` checker, and a `context()` returning the server's own `plan` and `planAuthorized: true`; otherwise requests are denied. `insecureAllowUnenforced: true` relaxes this for local development only.
41
+
42
+ ## API
43
+
44
+ - `withPCA(options, handler)` - returns `(req: Request) => Promise<Response>`. Options extend `RequirePcaOptions` from `@atlasauth/pca`, plus `onDeny(result, req)` to customize the error response.
45
+ - Re-exports `requirePCA`, `defaultExtract`, `memoryPcaStore`.
46
+
47
+ ## Status
48
+
49
+ This package only wires the guard into Next.js route handlers; all verification logic lives in `@atlasauth/pca`. PCA cryptography has not been independently audited.
50
+
51
+ ## License
35
52
 
36
- Part of Proof-Carrying Authority — see `@atlasauth/pca`.
53
+ MIT - see LICENSE
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * );
8
8
  *
9
9
  * It wraps a Route Handler so the inbound PCActn is verified with the framework-agnostic `requirePCA` guard
10
- * from `@atlasauth/backend` (default-deny: a required check that is unenforced DENIES) before your handler
10
+ * from `@atlasauth/pca` (default-deny: a required check that is unenforced DENIES) before your handler
11
11
  * runs. On success it calls your handler with `{ pca: { verdict, pcactn } }`; on failure it returns a 401/403
12
12
  * JSON response with a WWW-Authenticate challenge. The client sends the PCActn as `PCA-Action: <base64url>`
13
13
  * (see `@atlasauth/pca` `pcaHeaders`) or a JSON body `{ pcactn }`; that is exactly what the default extractor
@@ -16,8 +16,8 @@
16
16
  * `next` is an OPTIONAL peer dependency and is never imported — the handler takes the web `Request` and returns
17
17
  * a web `Response`, which is exactly what an App-Router Route Handler is.
18
18
  */
19
- import { requirePCA, defaultExtract, memoryPcaStore } from '@atlasauth/backend';
20
- import type { PcaGuardResult, RequirePcaOptions, PcaStateStore } from '@atlasauth/backend';
19
+ import { requirePCA, defaultExtract, memoryPcaStore } from '@atlasauth/pca';
20
+ import type { PcaGuardResult, RequirePcaOptions, PcaStateStore } from '@atlasauth/pca';
21
21
  import type { PCActn } from '@atlasauth/pca';
22
22
  /** The verdict + PCActn handed to the wrapped handler on success. */
23
23
  export interface PcaAttachment {
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * );
9
9
  *
10
10
  * It wraps a Route Handler so the inbound PCActn is verified with the framework-agnostic `requirePCA` guard
11
- * from `@atlasauth/backend` (default-deny: a required check that is unenforced DENIES) before your handler
11
+ * from `@atlasauth/pca` (default-deny: a required check that is unenforced DENIES) before your handler
12
12
  * runs. On success it calls your handler with `{ pca: { verdict, pcactn } }`; on failure it returns a 401/403
13
13
  * JSON response with a WWW-Authenticate challenge. The client sends the PCActn as `PCA-Action: <base64url>`
14
14
  * (see `@atlasauth/pca` `pcaHeaders`) or a JSON body `{ pcactn }`; that is exactly what the default extractor
@@ -20,14 +20,14 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.memoryPcaStore = exports.defaultExtract = exports.requirePCA = void 0;
22
22
  exports.withPCA = withPCA;
23
- const backend_1 = require("@atlasauth/backend");
24
- Object.defineProperty(exports, "requirePCA", { enumerable: true, get: function () { return backend_1.requirePCA; } });
25
- Object.defineProperty(exports, "defaultExtract", { enumerable: true, get: function () { return backend_1.defaultExtract; } });
26
- Object.defineProperty(exports, "memoryPcaStore", { enumerable: true, get: function () { return backend_1.memoryPcaStore; } });
23
+ const pca_1 = require("@atlasauth/pca");
24
+ Object.defineProperty(exports, "requirePCA", { enumerable: true, get: function () { return pca_1.requirePCA; } });
25
+ Object.defineProperty(exports, "defaultExtract", { enumerable: true, get: function () { return pca_1.defaultExtract; } });
26
+ Object.defineProperty(exports, "memoryPcaStore", { enumerable: true, get: function () { return pca_1.memoryPcaStore; } });
27
27
  /** Wrap an App-Router Route Handler so it only runs for a valid PCActn. */
28
28
  function withPCA(options, handler) {
29
29
  const onDeny = options.onDeny;
30
- const guard = (0, backend_1.requirePCA)(options);
30
+ const guard = (0, pca_1.requirePCA)(options);
31
31
  return async (req) => {
32
32
  const like = {
33
33
  headers: { get: (n) => req.headers.get(n) },
package/dist/index.js.map CHANGED
@@ -1 +1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;QACnF,CAAC;QACD,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACvC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE;YAClH,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAClF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "@atlasauth/pca-next",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Next.js helper for Proof-Carrying Authority: wrap a Route Handler so the inbound PCActn is verified before your handler runs, with a 401/403 response otherwise.",
5
+ "keywords": [
6
+ "next.js",
7
+ "route handler",
8
+ "middleware",
9
+ "agent authorization",
10
+ "proof-carrying authority",
11
+ "pca",
12
+ "ai agents"
13
+ ],
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/Atlas-Authorization/pca#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/Atlas-Authorization/pca/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Atlas-Authorization/pca.git",
22
+ "directory": "packages/pca-next"
23
+ },
5
24
  "main": "./dist/index.js",
6
25
  "types": "./dist/index.d.ts",
7
26
  "exports": {
@@ -12,8 +31,7 @@
12
31
  "./package.json": "./package.json"
13
32
  },
14
33
  "dependencies": {
15
- "@atlasauth/pca": "0.1.0",
16
- "@atlasauth/backend": "0.3.0"
34
+ "@atlasauth/pca": "0.3.0"
17
35
  },
18
36
  "peerDependencies": {
19
37
  "next": "^14 || ^15"
@@ -29,8 +47,12 @@
29
47
  },
30
48
  "files": [
31
49
  "dist",
32
- "README.md"
50
+ "README.md",
51
+ "LICENSE"
33
52
  ],
53
+ "engines": {
54
+ "node": ">=20"
55
+ },
34
56
  "publishConfig": {
35
57
  "access": "public"
36
58
  },