@kya-os/checkpoint-shared 1.5.1 → 1.5.2
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/CHANGELOG.md +120 -0
- package/dist/beacon-nonce/index.d.mts +36 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -0
- package/dist/beacon-nonce/index.d.ts +36 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -0
- package/dist/beacon-nonce/index.js +305 -0
- package/dist/beacon-nonce/index.mjs +294 -0
- package/dist/beacon-nonce/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +29 -0
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +29 -0
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +36 -5
- package/dist/beacon-types/index.mjs +33 -6
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/browser-posture-D4j2a5gi.d.ts +169 -0
- package/dist/browser-posture-D4j2a5gi.d.ts.map +1 -0
- package/dist/browser-posture-DVoHMHjY.d.mts +169 -0
- package/dist/browser-posture-DVoHMHjY.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +4 -2
- package/dist/browser-posture-cookie.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.ts +4 -2
- package/dist/browser-posture-cookie.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof.d.mts +18 -0
- package/dist/browser-posture-proof.d.mts.map +1 -0
- package/dist/browser-posture-proof.d.ts +18 -0
- package/dist/browser-posture-proof.d.ts.map +1 -0
- package/dist/browser-posture-proof.js +66 -0
- package/dist/browser-posture-proof.mjs +63 -0
- package/dist/browser-posture-proof.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +59 -2
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +59 -2
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +1 -1
- package/dist/browser-posture-report.mjs.map +1 -1
- package/dist/browser-posture.d.mts +2 -85
- package/dist/browser-posture.d.ts +2 -85
- package/dist/browser-posture.js +205 -43
- package/dist/browser-posture.mjs +194 -44
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +0 -8
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +0 -8
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/{client-ip-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
- package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
- package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
- package/dist/consent-handoff.d.mts +41 -0
- package/dist/consent-handoff.d.mts.map +1 -0
- package/dist/consent-handoff.d.ts +41 -0
- package/dist/consent-handoff.d.ts.map +1 -0
- package/dist/consent-handoff.js +1 -0
- package/dist/consent-handoff.mjs +2 -0
- package/dist/consent-handoff.mjs.map +1 -0
- package/dist/errors/index.d.mts +138 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +138 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +441 -9
- package/dist/errors/index.mjs +441 -10
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-jr_S4iSS.d.mts → external-Ct8j_hto.d.mts} +2 -2
- package/dist/{external-jr_S4iSS.d.mts.map → external-Ct8j_hto.d.mts.map} +1 -1
- package/dist/{external-jr_S4iSS.d.ts → external-Ct8j_hto.d.ts} +2 -2
- package/dist/{external-jr_S4iSS.d.ts.map → external-Ct8j_hto.d.ts.map} +1 -1
- package/dist/gateway-client-ip.d.mts +1 -1
- package/dist/gateway-client-ip.d.ts +1 -1
- package/dist/gateway-client-ip.js +1 -1
- package/dist/gateway-client-ip.mjs +1 -1
- package/dist/index.d.mts +5131 -967
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +5131 -967
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3678 -546
- package/dist/index.mjs +3446 -534
- package/dist/index.mjs.map +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +1 -1
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
- package/dist/mcpi/approval-grant/index.d.ts +1 -1
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
- package/dist/mcpi/approval-grant/index.js +48 -48
- package/dist/mcpi/approval-grant/index.mjs +48 -48
- package/dist/mcpi/approval-grant/index.mjs.map +1 -1
- package/dist/posture-origins/index.d.mts +41 -0
- package/dist/posture-origins/index.d.mts.map +1 -0
- package/dist/posture-origins/index.d.ts +41 -0
- package/dist/posture-origins/index.d.ts.map +1 -0
- package/dist/posture-origins/index.js +441 -0
- package/dist/posture-origins/index.mjs +430 -0
- package/dist/posture-origins/index.mjs.map +1 -0
- package/dist/posture-origins-CEm83u4D.js +621 -0
- package/dist/posture-origins-Dl7i8j93.mjs +533 -0
- package/dist/posture-origins-Dl7i8j93.mjs.map +1 -0
- package/dist/rules.json +0 -1
- package/dist/signals/index.d.mts +75 -55
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts +75 -55
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +246 -2
- package/dist/signals/index.mjs +236 -3
- package/dist/signals/index.mjs.map +1 -1
- package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
- package/fixtures/browser-integrity/null-score.json +11 -0
- package/fixtures/browser-integrity/numeric-score.json +11 -0
- package/fixtures/browser-posture-claims.json +168 -0
- package/fixtures/browser-posture-headers.json +6 -0
- package/fixtures/kya-http/README.md +1 -0
- package/fixtures/kya-http/consent-handoff.codes.json +34 -0
- package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
- package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
- package/fixtures/workbench/delegation-management.v1.json +507 -0
- package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
- package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
- package/fixtures/workbench/identity-provisioning.v1.json +643 -0
- package/fixtures/workbench/linear-installation.v1.json +484 -0
- package/fixtures/workbench/management-session.v1.json +716 -0
- package/fixtures/workbench/model-credentials.v1.json +630 -0
- package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
- package/fixtures/workbench/task-grant.v1.json +695 -0
- package/fixtures/workbench/task-status-projection.v1.json +591 -0
- package/fixtures/workbench/workload-enrollment.v1.json +580 -0
- package/package.json +21 -2
- package/src/data/compiled/merged-rules.json +2 -9
- package/src/data/default-rules.json +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
- package/dist/browser-posture.d.mts.map +0 -1
- package/dist/browser-posture.d.ts.map +0 -1
- package/dist/patterns-CkRVOdtV.js +0 -243
- package/dist/patterns-DzkGy_qk.mjs +0 -173
- package/dist/patterns-DzkGy_qk.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JWK } from "jose";
|
|
2
2
|
//#region src/mcpi/approval-grant/nonce.d.ts
|
|
3
|
+
export declare const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
3
4
|
interface ApprovalNonceStore {
|
|
4
5
|
issue(requestHash: string, ttlSec?: number): string;
|
|
5
6
|
current(requestHash: string): string | null;
|
|
@@ -14,7 +15,6 @@ export declare class InMemoryApprovalNonceStore implements ApprovalNonceStore {
|
|
|
14
15
|
//#endregion
|
|
15
16
|
//#region src/mcpi/approval-grant/grant.d.ts
|
|
16
17
|
export declare const APPROVAL_GRANT_TYP = "approval-grant+jwt";
|
|
17
|
-
export declare const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
18
18
|
interface Ed25519PublicJWK {
|
|
19
19
|
kty: 'OKP';
|
|
20
20
|
crv: 'Ed25519';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/mcpi/approval-grant/nonce.ts","../../../src/mcpi/approval-grant/grant.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/mcpi/approval-grant/nonce.ts","../../../src/mcpi/approval-grant/grant.ts"],"mappings":";;qBAiBa;UAEI;EAOf,MAAM,qBAAqB;EAE3B,QAAQ;EAWR,WAAW;;qBAQA,sCAAsC;mBAChC;EAKjB,MAAM,qBAAqB;EAc3B,QAAQ;EAMR,WAAW;;;;qBCtCA;UAEI;EACf;EACA;EACA;;UAIe;EACf;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA,MAAM;;UAGS;EACf;EACA;EACA;EACA;EACA;EACA;;KAGU,uBAAuB,gBAAgB,QAAQ;UAE1C;EACf;EACA;EACA;;wBAIoB,kBACpB,MAAM,mBACN,eAAe,MACd,QAAQ;wBAsCW,oBAAoB;EACxC,OAAO;EACP,UAAU;EACV,YAAY;IACV,QAAQ;UAsEK;EACf;EACA;;wBASoB,2BAA2B;EAC/C,QAAQ;EACR;IAAY;IAAqB;IAAkB;IAAkB;;EACrE;IAAU;IAAW;;EACrB,YAAY;EACZ,YAAY;IACV,QAAQ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JWK } from "jose";
|
|
2
2
|
//#region src/mcpi/approval-grant/nonce.d.ts
|
|
3
|
+
export declare const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
3
4
|
interface ApprovalNonceStore {
|
|
4
5
|
issue(requestHash: string, ttlSec?: number): string;
|
|
5
6
|
current(requestHash: string): string | null;
|
|
@@ -14,7 +15,6 @@ export declare class InMemoryApprovalNonceStore implements ApprovalNonceStore {
|
|
|
14
15
|
//#endregion
|
|
15
16
|
//#region src/mcpi/approval-grant/grant.d.ts
|
|
16
17
|
export declare const APPROVAL_GRANT_TYP = "approval-grant+jwt";
|
|
17
|
-
export declare const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
18
18
|
interface Ed25519PublicJWK {
|
|
19
19
|
kty: 'OKP';
|
|
20
20
|
crv: 'Ed25519';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/mcpi/approval-grant/nonce.ts","../../../src/mcpi/approval-grant/grant.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/mcpi/approval-grant/nonce.ts","../../../src/mcpi/approval-grant/grant.ts"],"mappings":";;qBAiBa;UAEI;EAOf,MAAM,qBAAqB;EAE3B,QAAQ;EAWR,WAAW;;qBAQA,sCAAsC;mBAChC;EAKjB,MAAM,qBAAqB;EAc3B,QAAQ;EAMR,WAAW;;;;qBCtCA;UAEI;EACf;EACA;EACA;;UAIe;EACf;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA,MAAM;;UAGS;EACf;EACA;EACA;EACA;EACA;EACA;;KAGU,uBAAuB,gBAAgB,QAAQ;UAE1C;EACf;EACA;EACA;;wBAIoB,kBACpB,MAAM,mBACN,eAAe,MACd,QAAQ;wBAsCW,oBAAoB;EACxC,OAAO;EACP,UAAU;EACV,YAAY;IACV,QAAQ;UAsEK;EACf;EACA;;wBASoB,2BAA2B;EAC/C,QAAQ;EACR;IAAY;IAAqB;IAAkB;IAAkB;;EACrE;IAAU;IAAW;;EACrB,YAAY;EACZ,YAAY;IACV,QAAQ"}
|
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let jose = require("jose");
|
|
3
3
|
|
|
4
|
+
//#region src/mcpi/approval-grant/nonce.ts
|
|
5
|
+
/**
|
|
6
|
+
* Server-issued, single-use nonce store for step-up approval grants.
|
|
7
|
+
*
|
|
8
|
+
* Issues one nonce per suspended action (`requestHash`) and consumes it when the
|
|
9
|
+
* quorum is satisfied. A resubmission of the same grants finds the nonce gone →
|
|
10
|
+
* rejected. This is what makes the grant single-use (closes replay across
|
|
11
|
+
* connections). In production this is shared state (Redis/DO); in-memory here.
|
|
12
|
+
*
|
|
13
|
+
* Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web
|
|
14
|
+
* Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded
|
|
15
|
+
* with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.
|
|
16
|
+
*
|
|
17
|
+
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
18
|
+
*/
|
|
19
|
+
const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
20
|
+
/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */
|
|
21
|
+
function generateNonce() {
|
|
22
|
+
return jose.base64url.encode(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
23
|
+
}
|
|
24
|
+
var InMemoryApprovalNonceStore = class {
|
|
25
|
+
issued = /* @__PURE__ */ new Map();
|
|
26
|
+
issue(requestHash, ttlSec = 300) {
|
|
27
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
28
|
+
const existing = this.issued.get(requestHash);
|
|
29
|
+
if (existing && !existing.consumed && existing.expiresAt >= now) return existing.nonce;
|
|
30
|
+
const nonce = generateNonce();
|
|
31
|
+
this.issued.set(requestHash, {
|
|
32
|
+
nonce,
|
|
33
|
+
consumed: false,
|
|
34
|
+
expiresAt: now + ttlSec
|
|
35
|
+
});
|
|
36
|
+
return nonce;
|
|
37
|
+
}
|
|
38
|
+
current(requestHash) {
|
|
39
|
+
const e = this.issued.get(requestHash);
|
|
40
|
+
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return null;
|
|
41
|
+
return e.nonce;
|
|
42
|
+
}
|
|
43
|
+
tryConsume(requestHash) {
|
|
44
|
+
const e = this.issued.get(requestHash);
|
|
45
|
+
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return false;
|
|
46
|
+
e.consumed = true;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
4
52
|
//#region src/mcpi/approval-grant/grant.ts
|
|
5
53
|
/**
|
|
6
54
|
* Step-up approval grants — portable, edge-safe reference implementation.
|
|
@@ -33,7 +81,6 @@ let jose = require("jose");
|
|
|
33
81
|
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
34
82
|
*/
|
|
35
83
|
const APPROVAL_GRANT_TYP = "approval-grant+jwt";
|
|
36
|
-
const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
37
84
|
/** Produce a signed grant (runs in the approver's client, with their key). */
|
|
38
85
|
async function signApprovalGrant(meta, privateKeyJwk) {
|
|
39
86
|
if (!Number.isInteger(meta.created) || !Number.isInteger(meta.expires)) throw new Error("approval grant: created/expires must be integer unix seconds");
|
|
@@ -181,53 +228,6 @@ async function verifySignedApprovalQuorum(opts) {
|
|
|
181
228
|
};
|
|
182
229
|
}
|
|
183
230
|
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/mcpi/approval-grant/nonce.ts
|
|
186
|
-
/**
|
|
187
|
-
* Server-issued, single-use nonce store for step-up approval grants.
|
|
188
|
-
*
|
|
189
|
-
* Issues one nonce per suspended action (`requestHash`) and consumes it when the
|
|
190
|
-
* quorum is satisfied. A resubmission of the same grants finds the nonce gone →
|
|
191
|
-
* rejected. This is what makes the grant single-use (closes replay across
|
|
192
|
-
* connections). In production this is shared state (Redis/DO); in-memory here.
|
|
193
|
-
*
|
|
194
|
-
* Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web
|
|
195
|
-
* Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded
|
|
196
|
-
* with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.
|
|
197
|
-
*
|
|
198
|
-
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
199
|
-
*/
|
|
200
|
-
/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */
|
|
201
|
-
function generateNonce() {
|
|
202
|
-
return jose.base64url.encode(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
203
|
-
}
|
|
204
|
-
var InMemoryApprovalNonceStore = class {
|
|
205
|
-
issued = /* @__PURE__ */ new Map();
|
|
206
|
-
issue(requestHash, ttlSec = 300) {
|
|
207
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
208
|
-
const existing = this.issued.get(requestHash);
|
|
209
|
-
if (existing && !existing.consumed && existing.expiresAt >= now) return existing.nonce;
|
|
210
|
-
const nonce = generateNonce();
|
|
211
|
-
this.issued.set(requestHash, {
|
|
212
|
-
nonce,
|
|
213
|
-
consumed: false,
|
|
214
|
-
expiresAt: now + ttlSec
|
|
215
|
-
});
|
|
216
|
-
return nonce;
|
|
217
|
-
}
|
|
218
|
-
current(requestHash) {
|
|
219
|
-
const e = this.issued.get(requestHash);
|
|
220
|
-
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return null;
|
|
221
|
-
return e.nonce;
|
|
222
|
-
}
|
|
223
|
-
tryConsume(requestHash) {
|
|
224
|
-
const e = this.issued.get(requestHash);
|
|
225
|
-
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return false;
|
|
226
|
-
e.consumed = true;
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
231
|
//#endregion
|
|
232
232
|
exports.APPROVAL_GRANT_MAX_LIFETIME_SEC = APPROVAL_GRANT_MAX_LIFETIME_SEC;
|
|
233
233
|
exports.APPROVAL_GRANT_TYP = APPROVAL_GRANT_TYP;
|
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
import { SignJWT, base64url, importJWK, jwtVerify } from "jose";
|
|
2
2
|
|
|
3
|
+
//#region src/mcpi/approval-grant/nonce.ts
|
|
4
|
+
/**
|
|
5
|
+
* Server-issued, single-use nonce store for step-up approval grants.
|
|
6
|
+
*
|
|
7
|
+
* Issues one nonce per suspended action (`requestHash`) and consumes it when the
|
|
8
|
+
* quorum is satisfied. A resubmission of the same grants finds the nonce gone →
|
|
9
|
+
* rejected. This is what makes the grant single-use (closes replay across
|
|
10
|
+
* connections). In production this is shared state (Redis/DO); in-memory here.
|
|
11
|
+
*
|
|
12
|
+
* Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web
|
|
13
|
+
* Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded
|
|
14
|
+
* with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.
|
|
15
|
+
*
|
|
16
|
+
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
17
|
+
*/
|
|
18
|
+
const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
19
|
+
/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */
|
|
20
|
+
function generateNonce() {
|
|
21
|
+
return base64url.encode(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
22
|
+
}
|
|
23
|
+
var InMemoryApprovalNonceStore = class {
|
|
24
|
+
issued = /* @__PURE__ */ new Map();
|
|
25
|
+
issue(requestHash, ttlSec = 300) {
|
|
26
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
27
|
+
const existing = this.issued.get(requestHash);
|
|
28
|
+
if (existing && !existing.consumed && existing.expiresAt >= now) return existing.nonce;
|
|
29
|
+
const nonce = generateNonce();
|
|
30
|
+
this.issued.set(requestHash, {
|
|
31
|
+
nonce,
|
|
32
|
+
consumed: false,
|
|
33
|
+
expiresAt: now + ttlSec
|
|
34
|
+
});
|
|
35
|
+
return nonce;
|
|
36
|
+
}
|
|
37
|
+
current(requestHash) {
|
|
38
|
+
const e = this.issued.get(requestHash);
|
|
39
|
+
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return null;
|
|
40
|
+
return e.nonce;
|
|
41
|
+
}
|
|
42
|
+
tryConsume(requestHash) {
|
|
43
|
+
const e = this.issued.get(requestHash);
|
|
44
|
+
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return false;
|
|
45
|
+
e.consumed = true;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
3
51
|
//#region src/mcpi/approval-grant/grant.ts
|
|
4
52
|
/**
|
|
5
53
|
* Step-up approval grants — portable, edge-safe reference implementation.
|
|
@@ -32,7 +80,6 @@ import { SignJWT, base64url, importJWK, jwtVerify } from "jose";
|
|
|
32
80
|
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
33
81
|
*/
|
|
34
82
|
const APPROVAL_GRANT_TYP = "approval-grant+jwt";
|
|
35
|
-
const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;
|
|
36
83
|
/** Produce a signed grant (runs in the approver's client, with their key). */
|
|
37
84
|
async function signApprovalGrant(meta, privateKeyJwk) {
|
|
38
85
|
if (!Number.isInteger(meta.created) || !Number.isInteger(meta.expires)) throw new Error("approval grant: created/expires must be integer unix seconds");
|
|
@@ -180,53 +227,6 @@ async function verifySignedApprovalQuorum(opts) {
|
|
|
180
227
|
};
|
|
181
228
|
}
|
|
182
229
|
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region src/mcpi/approval-grant/nonce.ts
|
|
185
|
-
/**
|
|
186
|
-
* Server-issued, single-use nonce store for step-up approval grants.
|
|
187
|
-
*
|
|
188
|
-
* Issues one nonce per suspended action (`requestHash`) and consumes it when the
|
|
189
|
-
* quorum is satisfied. A resubmission of the same grants finds the nonce gone →
|
|
190
|
-
* rejected. This is what makes the grant single-use (closes replay across
|
|
191
|
-
* connections). In production this is shared state (Redis/DO); in-memory here.
|
|
192
|
-
*
|
|
193
|
-
* Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web
|
|
194
|
-
* Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded
|
|
195
|
-
* with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.
|
|
196
|
-
*
|
|
197
|
-
* @module @kya-os/checkpoint-shared/mcpi/approval-grant
|
|
198
|
-
*/
|
|
199
|
-
/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */
|
|
200
|
-
function generateNonce() {
|
|
201
|
-
return base64url.encode(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
202
|
-
}
|
|
203
|
-
var InMemoryApprovalNonceStore = class {
|
|
204
|
-
issued = /* @__PURE__ */ new Map();
|
|
205
|
-
issue(requestHash, ttlSec = 300) {
|
|
206
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
207
|
-
const existing = this.issued.get(requestHash);
|
|
208
|
-
if (existing && !existing.consumed && existing.expiresAt >= now) return existing.nonce;
|
|
209
|
-
const nonce = generateNonce();
|
|
210
|
-
this.issued.set(requestHash, {
|
|
211
|
-
nonce,
|
|
212
|
-
consumed: false,
|
|
213
|
-
expiresAt: now + ttlSec
|
|
214
|
-
});
|
|
215
|
-
return nonce;
|
|
216
|
-
}
|
|
217
|
-
current(requestHash) {
|
|
218
|
-
const e = this.issued.get(requestHash);
|
|
219
|
-
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return null;
|
|
220
|
-
return e.nonce;
|
|
221
|
-
}
|
|
222
|
-
tryConsume(requestHash) {
|
|
223
|
-
const e = this.issued.get(requestHash);
|
|
224
|
-
if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1e3)) return false;
|
|
225
|
-
e.consumed = true;
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
230
|
//#endregion
|
|
231
231
|
export { APPROVAL_GRANT_MAX_LIFETIME_SEC, APPROVAL_GRANT_TYP, InMemoryApprovalNonceStore, signApprovalGrant, verifyApprovalGrant, verifySignedApprovalQuorum };
|
|
232
232
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/mcpi/approval-grant/grant.ts","../../../src/mcpi/approval-grant/nonce.ts"],"sourcesContent":["/**\n * Step-up approval grants — portable, edge-safe reference implementation.\n *\n * The signed approval-grant scheme the step-up gate verifies. Lives in\n * `@kya-os/checkpoint-shared` (the runtime-neutral home) so every runtime that\n * enforces N-of-M step-up at the edge — the central gateway AND the SDK\n * middleware adapters (Express / Next.js / Cloudflare-worker / .NET-port) —\n * injects the SAME verifier into the step-up core\n * (`@kya-os/checkpoint-wasm-runtime/step-up`) instead of re-implementing it.\n *\n * A grant is a compact EdDSA JWS (one crypto path with the delegation proof)\n * binding five independent dimensions so a captured grant can't be replayed or\n * repurposed past any one of them:\n * - `requestHash` — the exact suspended action (TOCTOU)\n * - `aud` — the resource/gateway it's valid for\n * - `sub` — the AGENT being approved (`agentDid`; an approval for X must\n * not satisfy Y's byte-identical call)\n * - `iat`/`exp` — freshness (lifetime <= 300s; jose enforces exp)\n * - `nonce` — server-issued + single-use; consumed on quorum satisfaction\n * so a resubmission of the same grants is rejected\n *\n * The approver holds their own key and signs client-side; verification resolves\n * the approver DID (via the host-injected {@link ApproverKeyResolver}) and is\n * fail-closed.\n *\n * Edge-safe: `jose` is isomorphic (Web Crypto `SubtleCrypto`); nonce generation\n * uses `globalThis.crypto.getRandomValues` (see `./nonce`). No `node:*` import.\n *\n * @module @kya-os/checkpoint-shared/mcpi/approval-grant\n */\n\nimport { SignJWT, jwtVerify, importJWK, type JWK, type JWTPayload } from 'jose';\n\nimport type { ApprovalNonceStore } from './nonce';\n\nexport const APPROVAL_GRANT_TYP = 'approval-grant+jwt';\nexport const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;\n\nexport interface Ed25519PublicJWK {\n kty: 'OKP';\n crv: 'Ed25519';\n x: string;\n}\n\n/** What an approver attests — canonicalised into the JWS payload. */\nexport interface ApprovalGrantMeta {\n approvalRequestId: string;\n approverDid: string;\n /** The agent being approved (`sub`). Aligns with the engine/Cedar agent identity. */\n agentDid: string;\n requestHash: string;\n audience: string;\n decision: 'approve' | 'deny';\n nonce: string;\n created: number;\n expires: number;\n amr?: string[];\n delegationRef?: string;\n}\n\nexport interface SignedApprovalGrant {\n jws: string;\n meta: ApprovalGrantMeta;\n}\n\nexport interface ApprovalGrantExpectation {\n requestHash: string;\n audience: string;\n nonce: string;\n agentDid: string;\n now?: number;\n maxLifetimeSec?: number;\n}\n\nexport type ApproverKeyResolver = (did: string) => Promise<Ed25519PublicJWK | null>;\n\nexport interface ApprovalGrantVerification {\n valid: boolean;\n reason?: string;\n approverDid?: string;\n}\n\n/** Produce a signed grant (runs in the approver's client, with their key). */\nexport async function signApprovalGrant(\n meta: ApprovalGrantMeta,\n privateKeyJwk: JWK\n): Promise<SignedApprovalGrant> {\n if (!Number.isInteger(meta.created) || !Number.isInteger(meta.expires)) {\n throw new Error('approval grant: created/expires must be integer unix seconds');\n }\n if (meta.expires <= meta.created) {\n throw new Error('approval grant: expires must be after created');\n }\n if (meta.expires - meta.created > APPROVAL_GRANT_MAX_LIFETIME_SEC) {\n throw new Error(`approval grant: lifetime exceeds ${APPROVAL_GRANT_MAX_LIFETIME_SEC}s ceiling`);\n }\n\n const key = await importJWK(privateKeyJwk, 'EdDSA');\n const claims: JWTPayload = {\n requestHash: meta.requestHash,\n decision: meta.decision,\n nonce: meta.nonce,\n };\n if (meta.amr) claims.amr = meta.amr;\n if (meta.delegationRef) claims.delegationRef = meta.delegationRef;\n\n const jws = await new SignJWT(claims)\n .setProtectedHeader({\n alg: 'EdDSA',\n kid: `${meta.approverDid}#key-1`,\n typ: APPROVAL_GRANT_TYP,\n })\n .setIssuer(meta.approverDid)\n .setSubject(meta.agentDid)\n .setAudience(meta.audience)\n .setJti(meta.approvalRequestId)\n .setIssuedAt(new Date(meta.created * 1000))\n .setExpirationTime(new Date(meta.expires * 1000))\n .sign(key);\n\n return { jws, meta };\n}\n\n/** Verify a single grant against the gateway's expectation. Fail-closed. */\nexport async function verifyApprovalGrant(opts: {\n grant: SignedApprovalGrant;\n expected: ApprovalGrantExpectation;\n resolveKey: ApproverKeyResolver;\n}): Promise<ApprovalGrantVerification> {\n const { grant, expected, resolveKey } = opts;\n\n const approverDid = grant?.meta?.approverDid;\n if (typeof approverDid !== 'string' || approverDid.length === 0) {\n return { valid: false, reason: 'missing_approver_did' };\n }\n\n let publicKeyJwk: Ed25519PublicJWK | null = null;\n try {\n publicKeyJwk = await resolveKey(approverDid);\n } catch {\n return { valid: false, reason: 'approver_key_unresolved' };\n }\n if (!publicKeyJwk) {\n return { valid: false, reason: 'approver_key_unresolved' };\n }\n\n try {\n const key = await importJWK(publicKeyJwk, 'EdDSA');\n const { payload, protectedHeader } = await jwtVerify(grant.jws, key, {\n algorithms: ['EdDSA'],\n issuer: approverDid,\n audience: expected.audience,\n ...(expected.now !== undefined ? { currentDate: new Date(expected.now * 1000) } : {}),\n });\n\n if (protectedHeader.typ !== APPROVAL_GRANT_TYP) {\n return { valid: false, reason: 'bad_typ' };\n }\n if (payload.requestHash !== expected.requestHash) {\n return { valid: false, reason: 'request_hash_mismatch' };\n }\n if (payload.nonce !== expected.nonce) {\n return { valid: false, reason: 'nonce_mismatch' };\n }\n if (payload.sub !== expected.agentDid) {\n return { valid: false, reason: 'agent_mismatch' };\n }\n if (payload.decision !== 'approve') {\n return { valid: false, reason: 'not_approved' };\n }\n\n const iat = payload.iat;\n const exp = payload.exp;\n if (typeof iat !== 'number' || typeof exp !== 'number') {\n return { valid: false, reason: 'missing_times' };\n }\n if (exp - iat > (expected.maxLifetimeSec ?? APPROVAL_GRANT_MAX_LIFETIME_SEC)) {\n return { valid: false, reason: 'lifetime_exceeded' };\n }\n if (\n grant.meta.requestHash !== payload.requestHash ||\n grant.meta.nonce !== payload.nonce ||\n grant.meta.agentDid !== payload.sub ||\n grant.meta.audience !== payload.aud ||\n grant.meta.decision !== payload.decision ||\n grant.meta.approverDid !== payload.iss\n ) {\n return { valid: false, reason: 'meta_mismatch' };\n }\n\n return { valid: true, approverDid };\n } catch {\n return { valid: false, reason: 'verify_failed' };\n }\n}\n\n// ── Quorum over signed grants ───────────────────────────────────────────────\n\nexport interface SignedQuorumResult {\n satisfied: boolean;\n reason?: string;\n}\n\n/**\n * Quorum is satisfied iff >= `quorum.n` DISTINCT allow-listed approvers each\n * signed a valid grant bound to the suspended action's outstanding nonce. On\n * satisfaction the nonce is consumed — a replay of the same grants then finds no\n * outstanding nonce and is rejected. Reuses {@link verifyApprovalGrant} per grant.\n */\nexport async function verifySignedApprovalQuorum(opts: {\n grants: SignedApprovalGrant[];\n expected: { requestHash: string; audience: string; agentDid: string; now?: number };\n quorum: { n: number; approvers: string[] };\n resolveKey: ApproverKeyResolver;\n nonceStore: ApprovalNonceStore;\n}): Promise<SignedQuorumResult> {\n const { grants, expected, quorum, resolveKey, nonceStore } = opts;\n\n if (!Number.isInteger(quorum.n) || quorum.n < 1) {\n return { satisfied: false, reason: 'invalid_quorum' };\n }\n if (!Array.isArray(quorum.approvers) || quorum.approvers.length === 0) {\n // Fail-closed: an empty allowlist means \"anyone who signs\" = not authorization.\n return { satisfied: false, reason: 'no_approvers' };\n }\n\n const nonce = nonceStore.current(expected.requestHash);\n if (!nonce) {\n // No outstanding challenge — covers a replay after a prior satisfaction.\n return { satisfied: false, reason: 'no_outstanding_challenge' };\n }\n\n const approvers = new Set<string>();\n for (const grant of grants) {\n const v = await verifyApprovalGrant({\n grant,\n expected: {\n requestHash: expected.requestHash,\n audience: expected.audience,\n agentDid: expected.agentDid,\n nonce,\n ...(expected.now !== undefined ? { now: expected.now } : {}),\n },\n resolveKey,\n });\n if (!v.valid || !v.approverDid) continue;\n if (!quorum.approvers.includes(v.approverDid)) continue;\n approvers.add(v.approverDid);\n }\n\n if (approvers.size >= quorum.n) {\n // ATOMIC single-use: only the first concurrent satisfier claims the nonce and\n // proceeds. A request that verified the same grants against the same nonce but\n // lost the race is re-challenged rather than double-admitted (closes the\n // read-verify-consume TOCTOU on the shared nonce).\n if (!nonceStore.tryConsume(expected.requestHash)) {\n return { satisfied: false, reason: 'nonce_already_consumed' };\n }\n return { satisfied: true };\n }\n return { satisfied: false, reason: `quorum_not_met:${approvers.size}/${quorum.n}` };\n}\n","/**\n * Server-issued, single-use nonce store for step-up approval grants.\n *\n * Issues one nonce per suspended action (`requestHash`) and consumes it when the\n * quorum is satisfied. A resubmission of the same grants finds the nonce gone →\n * rejected. This is what makes the grant single-use (closes replay across\n * connections). In production this is shared state (Redis/DO); in-memory here.\n *\n * Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web\n * Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded\n * with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.\n *\n * @module @kya-os/checkpoint-shared/mcpi/approval-grant\n */\n\nimport { base64url } from 'jose';\n\nimport { APPROVAL_GRANT_MAX_LIFETIME_SEC } from './grant';\n\nexport interface ApprovalNonceStore {\n /**\n * The action's nonce — minted once on the first `step_up`, then REUSED on every\n * resubmit (so grants already signed for it stay valid across partial resumes).\n * A fresh nonce is minted only for a NEW action instance — after the prior was\n * consumed (the action proceeded) or expired. Idempotent per `requestHash`.\n */\n issue(requestHash: string, ttlSec?: number): string;\n /** The outstanding, unconsumed, unexpired nonce for this action — else null. */\n current(requestHash: string): string | null;\n /**\n * ATOMICALLY claim + consume the action's outstanding nonce. Returns `true` for\n * the FIRST caller to claim it, `false` for every subsequent call (already\n * consumed, expired, or never issued). This is the single-use guarantee under\n * CONCURRENCY: two overlapping requests can both verify their grants against the\n * same outstanding nonce, but only the winner of `tryConsume` proceeds — the\n * loser is re-challenged, not double-admitted. The in-memory impl is atomic by\n * virtue of the synchronous event loop; a shared (Redis/DO) impl MUST back this\n * with an atomic compare-and-delete, not a read-then-write.\n */\n tryConsume(requestHash: string): boolean;\n}\n\n/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */\nfunction generateNonce(): string {\n return base64url.encode(globalThis.crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport class InMemoryApprovalNonceStore implements ApprovalNonceStore {\n private readonly issued = new Map<\n string,\n { nonce: string; consumed: boolean; expiresAt: number }\n >();\n\n issue(requestHash: string, ttlSec = APPROVAL_GRANT_MAX_LIFETIME_SEC): string {\n const now = Math.floor(Date.now() / 1000);\n const existing = this.issued.get(requestHash);\n // Idempotent per action: a resubmitted step_up reuses the outstanding nonce\n // rather than rotating it (which would invalidate grants already signed for\n // it). Mint fresh only for a new action instance — after consume or expiry.\n if (existing && !existing.consumed && existing.expiresAt >= now) {\n return existing.nonce;\n }\n const nonce = generateNonce();\n this.issued.set(requestHash, { nonce, consumed: false, expiresAt: now + ttlSec });\n return nonce;\n }\n\n current(requestHash: string): string | null {\n const e = this.issued.get(requestHash);\n if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1000)) return null;\n return e.nonce;\n }\n\n tryConsume(requestHash: string): boolean {\n const e = this.issued.get(requestHash);\n if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1000)) return false;\n e.consumed = true; // synchronous compare-and-set — the event loop serializes concurrent claims\n return true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,qBAAqB;AAClC,MAAa,kCAAkC;;AA+C/C,eAAsB,kBACpB,MACA,eAC8B;CAC9B,IAAI,CAAC,OAAO,UAAU,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU,KAAK,OAAO,GACnE,MAAM,IAAI,MAAM,8DAA8D;CAEhF,IAAI,KAAK,WAAW,KAAK,SACvB,MAAM,IAAI,MAAM,+CAA+C;CAEjE,IAAI,KAAK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EAElB,MAAM,QAAQ,cAAc;EAC5B,KAAK,OAAO,IAAI,aAAa;GAAE;GAAO,UAAU;GAAO,WAAW,MAAM;EAAO,CAAC;EAChF,OAAO;CACT;CAEA,QAAQ,aAAoC;EAC1C,MAAM,IAAI,KAAK,OAAO,IAAI,WAAW;EACrC,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,YAAY,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAAG,OAAO;EAC5E,OAAO,EAAE;CACX;CAEA,WAAW,aAA8B;EACvC,MAAM,IAAI,KAAK,OAAO,IAAI,WAAW;EACrC,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,YAAY,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAAG,OAAO;EAC5E,EAAE,WAAW;EACb,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/mcpi/approval-grant/nonce.ts","../../../src/mcpi/approval-grant/grant.ts"],"sourcesContent":["/**\n * Server-issued, single-use nonce store for step-up approval grants.\n *\n * Issues one nonce per suspended action (`requestHash`) and consumes it when the\n * quorum is satisfied. A resubmission of the same grants finds the nonce gone →\n * rejected. This is what makes the grant single-use (closes replay across\n * connections). In production this is shared state (Redis/DO); in-memory here.\n *\n * Edge-safe: nonce bytes come from `globalThis.crypto.getRandomValues` (Web\n * Crypto — present on Node 18+, Cloudflare Workers, and Vercel Edge), encoded\n * with `jose`'s isomorphic `base64url`. No `node:crypto`, no `Buffer`.\n *\n * @module @kya-os/checkpoint-shared/mcpi/approval-grant\n */\n\nimport { base64url } from 'jose';\n\nexport const APPROVAL_GRANT_MAX_LIFETIME_SEC = 300;\n\nexport interface ApprovalNonceStore {\n /**\n * The action's nonce — minted once on the first `step_up`, then REUSED on every\n * resubmit (so grants already signed for it stay valid across partial resumes).\n * A fresh nonce is minted only for a NEW action instance — after the prior was\n * consumed (the action proceeded) or expired. Idempotent per `requestHash`.\n */\n issue(requestHash: string, ttlSec?: number): string;\n /** The outstanding, unconsumed, unexpired nonce for this action — else null. */\n current(requestHash: string): string | null;\n /**\n * ATOMICALLY claim + consume the action's outstanding nonce. Returns `true` for\n * the FIRST caller to claim it, `false` for every subsequent call (already\n * consumed, expired, or never issued). This is the single-use guarantee under\n * CONCURRENCY: two overlapping requests can both verify their grants against the\n * same outstanding nonce, but only the winner of `tryConsume` proceeds — the\n * loser is re-challenged, not double-admitted. The in-memory impl is atomic by\n * virtue of the synchronous event loop; a shared (Redis/DO) impl MUST back this\n * with an atomic compare-and-delete, not a read-then-write.\n */\n tryConsume(requestHash: string): boolean;\n}\n\n/** 32 cryptographically-random bytes, base64url-encoded. Edge-safe. */\nfunction generateNonce(): string {\n return base64url.encode(globalThis.crypto.getRandomValues(new Uint8Array(32)));\n}\n\nexport class InMemoryApprovalNonceStore implements ApprovalNonceStore {\n private readonly issued = new Map<\n string,\n { nonce: string; consumed: boolean; expiresAt: number }\n >();\n\n issue(requestHash: string, ttlSec = APPROVAL_GRANT_MAX_LIFETIME_SEC): string {\n const now = Math.floor(Date.now() / 1000);\n const existing = this.issued.get(requestHash);\n // Idempotent per action: a resubmitted step_up reuses the outstanding nonce\n // rather than rotating it (which would invalidate grants already signed for\n // it). Mint fresh only for a new action instance — after consume or expiry.\n if (existing && !existing.consumed && existing.expiresAt >= now) {\n return existing.nonce;\n }\n const nonce = generateNonce();\n this.issued.set(requestHash, { nonce, consumed: false, expiresAt: now + ttlSec });\n return nonce;\n }\n\n current(requestHash: string): string | null {\n const e = this.issued.get(requestHash);\n if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1000)) return null;\n return e.nonce;\n }\n\n tryConsume(requestHash: string): boolean {\n const e = this.issued.get(requestHash);\n if (!e || e.consumed || e.expiresAt < Math.floor(Date.now() / 1000)) return false;\n e.consumed = true; // synchronous compare-and-set — the event loop serializes concurrent claims\n return true;\n }\n}\n","/**\n * Step-up approval grants — portable, edge-safe reference implementation.\n *\n * The signed approval-grant scheme the step-up gate verifies. Lives in\n * `@kya-os/checkpoint-shared` (the runtime-neutral home) so every runtime that\n * enforces N-of-M step-up at the edge — the central gateway AND the SDK\n * middleware adapters (Express / Next.js / Cloudflare-worker / .NET-port) —\n * injects the SAME verifier into the step-up core\n * (`@kya-os/checkpoint-wasm-runtime/step-up`) instead of re-implementing it.\n *\n * A grant is a compact EdDSA JWS (one crypto path with the delegation proof)\n * binding five independent dimensions so a captured grant can't be replayed or\n * repurposed past any one of them:\n * - `requestHash` — the exact suspended action (TOCTOU)\n * - `aud` — the resource/gateway it's valid for\n * - `sub` — the AGENT being approved (`agentDid`; an approval for X must\n * not satisfy Y's byte-identical call)\n * - `iat`/`exp` — freshness (lifetime <= 300s; jose enforces exp)\n * - `nonce` — server-issued + single-use; consumed on quorum satisfaction\n * so a resubmission of the same grants is rejected\n *\n * The approver holds their own key and signs client-side; verification resolves\n * the approver DID (via the host-injected {@link ApproverKeyResolver}) and is\n * fail-closed.\n *\n * Edge-safe: `jose` is isomorphic (Web Crypto `SubtleCrypto`); nonce generation\n * uses `globalThis.crypto.getRandomValues` (see `./nonce`). No `node:*` import.\n *\n * @module @kya-os/checkpoint-shared/mcpi/approval-grant\n */\n\nimport { SignJWT, jwtVerify, importJWK, type JWK, type JWTPayload } from 'jose';\n\nimport { APPROVAL_GRANT_MAX_LIFETIME_SEC, type ApprovalNonceStore } from './nonce';\n\nexport const APPROVAL_GRANT_TYP = 'approval-grant+jwt';\n\nexport interface Ed25519PublicJWK {\n kty: 'OKP';\n crv: 'Ed25519';\n x: string;\n}\n\n/** What an approver attests — canonicalised into the JWS payload. */\nexport interface ApprovalGrantMeta {\n approvalRequestId: string;\n approverDid: string;\n /** The agent being approved (`sub`). Aligns with the engine/Cedar agent identity. */\n agentDid: string;\n requestHash: string;\n audience: string;\n decision: 'approve' | 'deny';\n nonce: string;\n created: number;\n expires: number;\n amr?: string[];\n delegationRef?: string;\n}\n\nexport interface SignedApprovalGrant {\n jws: string;\n meta: ApprovalGrantMeta;\n}\n\nexport interface ApprovalGrantExpectation {\n requestHash: string;\n audience: string;\n nonce: string;\n agentDid: string;\n now?: number;\n maxLifetimeSec?: number;\n}\n\nexport type ApproverKeyResolver = (did: string) => Promise<Ed25519PublicJWK | null>;\n\nexport interface ApprovalGrantVerification {\n valid: boolean;\n reason?: string;\n approverDid?: string;\n}\n\n/** Produce a signed grant (runs in the approver's client, with their key). */\nexport async function signApprovalGrant(\n meta: ApprovalGrantMeta,\n privateKeyJwk: JWK\n): Promise<SignedApprovalGrant> {\n if (!Number.isInteger(meta.created) || !Number.isInteger(meta.expires)) {\n throw new Error('approval grant: created/expires must be integer unix seconds');\n }\n if (meta.expires <= meta.created) {\n throw new Error('approval grant: expires must be after created');\n }\n if (meta.expires - meta.created > APPROVAL_GRANT_MAX_LIFETIME_SEC) {\n throw new Error(`approval grant: lifetime exceeds ${APPROVAL_GRANT_MAX_LIFETIME_SEC}s ceiling`);\n }\n\n const key = await importJWK(privateKeyJwk, 'EdDSA');\n const claims: JWTPayload = {\n requestHash: meta.requestHash,\n decision: meta.decision,\n nonce: meta.nonce,\n };\n if (meta.amr) claims.amr = meta.amr;\n if (meta.delegationRef) claims.delegationRef = meta.delegationRef;\n\n const jws = await new SignJWT(claims)\n .setProtectedHeader({\n alg: 'EdDSA',\n kid: `${meta.approverDid}#key-1`,\n typ: APPROVAL_GRANT_TYP,\n })\n .setIssuer(meta.approverDid)\n .setSubject(meta.agentDid)\n .setAudience(meta.audience)\n .setJti(meta.approvalRequestId)\n .setIssuedAt(new Date(meta.created * 1000))\n .setExpirationTime(new Date(meta.expires * 1000))\n .sign(key);\n\n return { jws, meta };\n}\n\n/** Verify a single grant against the gateway's expectation. Fail-closed. */\nexport async function verifyApprovalGrant(opts: {\n grant: SignedApprovalGrant;\n expected: ApprovalGrantExpectation;\n resolveKey: ApproverKeyResolver;\n}): Promise<ApprovalGrantVerification> {\n const { grant, expected, resolveKey } = opts;\n\n const approverDid = grant?.meta?.approverDid;\n if (typeof approverDid !== 'string' || approverDid.length === 0) {\n return { valid: false, reason: 'missing_approver_did' };\n }\n\n let publicKeyJwk: Ed25519PublicJWK | null = null;\n try {\n publicKeyJwk = await resolveKey(approverDid);\n } catch {\n return { valid: false, reason: 'approver_key_unresolved' };\n }\n if (!publicKeyJwk) {\n return { valid: false, reason: 'approver_key_unresolved' };\n }\n\n try {\n const key = await importJWK(publicKeyJwk, 'EdDSA');\n const { payload, protectedHeader } = await jwtVerify(grant.jws, key, {\n algorithms: ['EdDSA'],\n issuer: approverDid,\n audience: expected.audience,\n ...(expected.now !== undefined ? { currentDate: new Date(expected.now * 1000) } : {}),\n });\n\n if (protectedHeader.typ !== APPROVAL_GRANT_TYP) {\n return { valid: false, reason: 'bad_typ' };\n }\n if (payload.requestHash !== expected.requestHash) {\n return { valid: false, reason: 'request_hash_mismatch' };\n }\n if (payload.nonce !== expected.nonce) {\n return { valid: false, reason: 'nonce_mismatch' };\n }\n if (payload.sub !== expected.agentDid) {\n return { valid: false, reason: 'agent_mismatch' };\n }\n if (payload.decision !== 'approve') {\n return { valid: false, reason: 'not_approved' };\n }\n\n const iat = payload.iat;\n const exp = payload.exp;\n if (typeof iat !== 'number' || typeof exp !== 'number') {\n return { valid: false, reason: 'missing_times' };\n }\n if (exp - iat > (expected.maxLifetimeSec ?? APPROVAL_GRANT_MAX_LIFETIME_SEC)) {\n return { valid: false, reason: 'lifetime_exceeded' };\n }\n if (\n grant.meta.requestHash !== payload.requestHash ||\n grant.meta.nonce !== payload.nonce ||\n grant.meta.agentDid !== payload.sub ||\n grant.meta.audience !== payload.aud ||\n grant.meta.decision !== payload.decision ||\n grant.meta.approverDid !== payload.iss\n ) {\n return { valid: false, reason: 'meta_mismatch' };\n }\n\n return { valid: true, approverDid };\n } catch {\n return { valid: false, reason: 'verify_failed' };\n }\n}\n\n// ── Quorum over signed grants ───────────────────────────────────────────────\n\nexport interface SignedQuorumResult {\n satisfied: boolean;\n reason?: string;\n}\n\n/**\n * Quorum is satisfied iff >= `quorum.n` DISTINCT allow-listed approvers each\n * signed a valid grant bound to the suspended action's outstanding nonce. On\n * satisfaction the nonce is consumed — a replay of the same grants then finds no\n * outstanding nonce and is rejected. Reuses {@link verifyApprovalGrant} per grant.\n */\nexport async function verifySignedApprovalQuorum(opts: {\n grants: SignedApprovalGrant[];\n expected: { requestHash: string; audience: string; agentDid: string; now?: number };\n quorum: { n: number; approvers: string[] };\n resolveKey: ApproverKeyResolver;\n nonceStore: ApprovalNonceStore;\n}): Promise<SignedQuorumResult> {\n const { grants, expected, quorum, resolveKey, nonceStore } = opts;\n\n if (!Number.isInteger(quorum.n) || quorum.n < 1) {\n return { satisfied: false, reason: 'invalid_quorum' };\n }\n if (!Array.isArray(quorum.approvers) || quorum.approvers.length === 0) {\n // Fail-closed: an empty allowlist means \"anyone who signs\" = not authorization.\n return { satisfied: false, reason: 'no_approvers' };\n }\n\n const nonce = nonceStore.current(expected.requestHash);\n if (!nonce) {\n // No outstanding challenge — covers a replay after a prior satisfaction.\n return { satisfied: false, reason: 'no_outstanding_challenge' };\n }\n\n const approvers = new Set<string>();\n for (const grant of grants) {\n const v = await verifyApprovalGrant({\n grant,\n expected: {\n requestHash: expected.requestHash,\n audience: expected.audience,\n agentDid: expected.agentDid,\n nonce,\n ...(expected.now !== undefined ? { now: expected.now } : {}),\n },\n resolveKey,\n });\n if (!v.valid || !v.approverDid) continue;\n if (!quorum.approvers.includes(v.approverDid)) continue;\n approvers.add(v.approverDid);\n }\n\n if (approvers.size >= quorum.n) {\n // ATOMIC single-use: only the first concurrent satisfier claims the nonce and\n // proceeds. A request that verified the same grants against the same nonce but\n // lost the race is re-challenged rather than double-admitted (closes the\n // read-verify-consume TOCTOU on the shared nonce).\n if (!nonceStore.tryConsume(expected.requestHash)) {\n return { satisfied: false, reason: 'nonce_already_consumed' };\n }\n return { satisfied: true };\n }\n return { satisfied: false, reason: `quorum_not_met:${approvers.size}/${quorum.n}` };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAa,kCA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AAW;EAAO,QAAQ;CAAe;CAGpD,MAAM,QAAQ,WAAW,QAAQ,SAAS,WAAW;CACrD,IAAI,CAAC,OAEH,OAAO;EAAE,WAAW;EAAO,QAAQ;CAA2B;CAGhE,MAAM,4BAAY,IAAI,IAAY;CAClC,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,IAAI,MAAM,oBAAoB;GAClC;GACA,UAAU;IACR,aAAa,SAAS;IACtB,UAAU,SAAS;IACnB,UAAU,SAAS;IACnB;IACA,GAAI,SAAS,QAAQ,SAAY,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC;GAC5D;GACA;EACF,CAAC;EACD,IAAI,CAAC,EAAE,SAAS,CAAC,EAAE,aAAa;EAChC,IAAI,CAAC,OAAO,UAAU,SAAS,EAAE,WAAW,GAAG;EAC/C,UAAU,IAAI,EAAE,WAAW;CAC7B;CAEA,IAAI,UAAU,QAAQ,OAAO,GAAG;EAK9B,IAAI,CAAC,WAAW,WAAW,SAAS,WAAW,GAC7C,OAAO;GAAE,WAAW;GAAO,QAAQ;EAAyB;EAE9D,OAAO,EAAE,WAAW,KAAK;CAC3B;CACA,OAAO;EAAE,WAAW;EAAO,QAAQ,kBAAkB,UAAU,KAAK,GAAG,OAAO;CAAI;AACpF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/posture-origins/index.d.ts
|
|
2
|
+
export declare const MAX_POSTURE_ORIGINS = 20;
|
|
3
|
+
export declare const MAX_POSTURE_ORIGIN_LENGTH = 300;
|
|
4
|
+
export declare const MULTI_TENANT_SUFFIXES: ReadonlySet<string>;
|
|
5
|
+
export interface ParsedOriginPattern {
|
|
6
|
+
pattern: string;
|
|
7
|
+
wildcard: boolean;
|
|
8
|
+
host: string;
|
|
9
|
+
port: string;
|
|
10
|
+
}
|
|
11
|
+
export type OriginPatternResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
value: ParsedOriginPattern;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function isPublicSuffixLike(host: string): boolean;
|
|
19
|
+
export declare function parseOriginPattern(input: string): OriginPatternResult;
|
|
20
|
+
export type PostureOriginsValidation = {
|
|
21
|
+
ok: true;
|
|
22
|
+
origins: string[];
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
errors: Array<{
|
|
26
|
+
index: number;
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
export declare function validatePostureOrigins(input: unknown): PostureOriginsValidation;
|
|
31
|
+
export declare function primaryPostureOrigin(domain: string | null | undefined): string | undefined;
|
|
32
|
+
export declare function postureKeysUrl(base: string, projectId: string): string;
|
|
33
|
+
export declare function readPostureOriginsSetting(settings: unknown): string[];
|
|
34
|
+
export declare function resolveProjectAllowedOrigins(project: {
|
|
35
|
+
domain: string | null | undefined;
|
|
36
|
+
settings?: unknown;
|
|
37
|
+
}): string[];
|
|
38
|
+
export declare function matchAllowedOrigin(pageOrigin: string | null | undefined, allowed: readonly string[]): string | undefined;
|
|
39
|
+
export declare function pageOriginFromHeaders(origin: string | null | undefined, referer: string | null | undefined): string | null;
|
|
40
|
+
//#endregion
|
|
41
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/posture-origins/index.ts"],"mappings":";qBA2Ca;qBAEA;qBAcA,uBAAuB;iBA2InB;EAEf;EACA;EAEA;EAEA;;YAGU;EACN;EAAU,OAAO;;EACjB;EAAW;;wBASD,mBAAmB;wBAqBnB,mBAAmB,gBAAgB;YAoDvC;EACN;EAAU;;EACV;EAAW,QAAQ;IAAQ;IAAe;;;wBAOhC,uBAAuB,iBAAiB;wBAgCxC,qBAAqB;wBAwBrB,eAAe,cAAc;wBAI7B,0BAA0B;wBAkB1B,6BAA6B;EAC3C;EACA;;wBAkBc,mBACd,uCACA;wBAqCc,sBACd,mCACA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/posture-origins/index.d.ts
|
|
2
|
+
export declare const MAX_POSTURE_ORIGINS = 20;
|
|
3
|
+
export declare const MAX_POSTURE_ORIGIN_LENGTH = 300;
|
|
4
|
+
export declare const MULTI_TENANT_SUFFIXES: ReadonlySet<string>;
|
|
5
|
+
export interface ParsedOriginPattern {
|
|
6
|
+
pattern: string;
|
|
7
|
+
wildcard: boolean;
|
|
8
|
+
host: string;
|
|
9
|
+
port: string;
|
|
10
|
+
}
|
|
11
|
+
export type OriginPatternResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
value: ParsedOriginPattern;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function isPublicSuffixLike(host: string): boolean;
|
|
19
|
+
export declare function parseOriginPattern(input: string): OriginPatternResult;
|
|
20
|
+
export type PostureOriginsValidation = {
|
|
21
|
+
ok: true;
|
|
22
|
+
origins: string[];
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
errors: Array<{
|
|
26
|
+
index: number;
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
export declare function validatePostureOrigins(input: unknown): PostureOriginsValidation;
|
|
31
|
+
export declare function primaryPostureOrigin(domain: string | null | undefined): string | undefined;
|
|
32
|
+
export declare function postureKeysUrl(base: string, projectId: string): string;
|
|
33
|
+
export declare function readPostureOriginsSetting(settings: unknown): string[];
|
|
34
|
+
export declare function resolveProjectAllowedOrigins(project: {
|
|
35
|
+
domain: string | null | undefined;
|
|
36
|
+
settings?: unknown;
|
|
37
|
+
}): string[];
|
|
38
|
+
export declare function matchAllowedOrigin(pageOrigin: string | null | undefined, allowed: readonly string[]): string | undefined;
|
|
39
|
+
export declare function pageOriginFromHeaders(origin: string | null | undefined, referer: string | null | undefined): string | null;
|
|
40
|
+
//#endregion
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/posture-origins/index.ts"],"mappings":";qBA2Ca;qBAEA;qBAcA,uBAAuB;iBA2InB;EAEf;EACA;EAEA;EAEA;;YAGU;EACN;EAAU,OAAO;;EACjB;EAAW;;wBASD,mBAAmB;wBAqBnB,mBAAmB,gBAAgB;YAoDvC;EACN;EAAU;;EACV;EAAW,QAAQ;IAAQ;IAAe;;;wBAOhC,uBAAuB,iBAAiB;wBAgCxC,qBAAqB;wBAwBrB,eAAe,cAAc;wBAI7B,0BAA0B;wBAkB1B,6BAA6B;EAC3C;EACA;;wBAkBc,mBACd,uCACA;wBAqCc,sBACd,mCACA"}
|