@atlasauth/pca-verified-core 0.0.0-stage → 0.4.1

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -2
  3. package/dist/bridge.d.ts +43 -0
  4. package/dist/bridge.js +74 -0
  5. package/dist/bridge.js.map +1 -0
  6. package/dist/chain.d.ts +65 -0
  7. package/dist/chain.js +58 -0
  8. package/dist/chain.js.map +1 -0
  9. package/dist/ext-attest.d.ts +109 -0
  10. package/dist/ext-attest.js +310 -0
  11. package/dist/ext-attest.js.map +1 -0
  12. package/dist/ext-merkle.d.ts +49 -0
  13. package/dist/ext-merkle.js +262 -0
  14. package/dist/ext-merkle.js.map +1 -0
  15. package/dist/ext-policyvm.d.ts +73 -0
  16. package/dist/ext-policyvm.js +285 -0
  17. package/dist/ext-policyvm.js.map +1 -0
  18. package/dist/ext-regex.d.ts +24 -0
  19. package/dist/ext-regex.js +66 -0
  20. package/dist/ext-regex.js.map +1 -0
  21. package/dist/ext-taint.d.ts +66 -0
  22. package/dist/ext-taint.js +212 -0
  23. package/dist/ext-taint.js.map +1 -0
  24. package/dist/ext-wire.d.ts +12 -0
  25. package/dist/ext-wire.js +150 -0
  26. package/dist/ext-wire.js.map +1 -0
  27. package/dist/index.d.ts +19 -0
  28. package/dist/index.js +35 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/replay.d.ts +52 -0
  31. package/dist/replay.js +82 -0
  32. package/dist/replay.js.map +1 -0
  33. package/dist/threshold.d.ts +50 -0
  34. package/dist/threshold.js +42 -0
  35. package/dist/threshold.js.map +1 -0
  36. package/dist/verdict.d.ts +119 -0
  37. package/dist/verdict.js +197 -0
  38. package/dist/verdict.js.map +1 -0
  39. package/generated/pca_attest.js +4109 -0
  40. package/generated/pca_core.d.ts +10 -0
  41. package/generated/pca_core.js +4541 -0
  42. package/generated/pca_merkle.js +1807 -0
  43. package/generated/pca_policyvm.js +3485 -0
  44. package/generated/pca_regex.js +3338 -0
  45. package/generated/pca_taint.js +1899 -0
  46. package/generated/pca_wire.js +2762 -0
  47. package/package.json +60 -3
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,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # @atlasauth/pca-verified-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The **decision logic** of the Proof-Carrying Authority (PCA) verifier, written in [Dafny](https://dafny.org), machine-proved
4
+ for all inputs (no bounds on chain length, share count or operation sequence), and compiled to JavaScript.
5
+
6
+ It does not do cryptography. You (the glue) evaluate signatures, hashes and parsing with your primitives and hand the
7
+ **results** (booleans, small enums, integers, opaque messages, lazy pure closures) to this package, which decides:
8
+
9
+ | area | function | proved (see `docs/pca/security/verified-core.md`) |
10
+ |---|---|---|
11
+ | capability chain | `decideChain` | order + first failure, depth bound (16), append-only caveats (attenuation), soundness + completeness |
12
+ | threshold | `decideThreshold` | one key per role / one role per key, count of **distinct** roles, `ok` iff count >= t, t in {1,2,3} |
13
+ | replay guard | `replayPre`, `replayNonceStage`, `replayDecide`, `VerifiedReplayStoreModel` | deny order, accept implies every precondition and store answer, nonce replay freedom, strictly increasing counters |
14
+ | check fold | `CoreState`, `VerdictState`, `enforceRequired`, `withDeniedFallback` | allow iff no check failed, first reason wins, reasons append-only, required checks all `pass` |
15
+ | per-check rules | `audienceStatus`, `validityDecision`, `grantRefBoundStatus`, `counterStatus`, `suitePolicy`, `pqBinding`, `leafDecision`, `thresholdRule`, `reversibilityDecision`, ... | audience fail-closed, expiry/skew window, suite policy, F-2 PQ binding, F-1 hook-enforced t |
16
+
17
+ ```ts
18
+ import { decideChain, decideThreshold, CoreState, validityDecision } from '@atlasauth/pca-verified-core';
19
+
20
+ validityDecision(true, iat, exp, now); // 'pass' | 'expired' | 'future' | ...
21
+ ```
22
+
23
+ No Dafny runtime type appears in the API. The generated JavaScript is committed in `generated/pca_core.js`; regenerate and
24
+ re-verify with `formal/dafny/build.sh`, and check that the committed file is byte-identical to a fresh compile with
25
+ `formal/dafny/build.sh --check` (script `check:generated`). Requires Dafny 4.11.0 (z3 4.12.1), run on a cloud box if not local.
26
+
27
+ The only runtime dependency is `bignumber.js` (Dafny's integer representation).
@@ -0,0 +1,43 @@
1
+ import BigNumber from 'bignumber.js';
2
+ export declare const D: {
3
+ _dafny: any;
4
+ Common: any;
5
+ Chain: any;
6
+ Caveats: any;
7
+ Threshold: any;
8
+ Replay: any;
9
+ Verdict: any;
10
+ };
11
+ export declare const Common: any;
12
+ export declare const Chain: any;
13
+ export declare const Threshold: any;
14
+ export declare const Replay: any;
15
+ export declare const Verdict: any;
16
+ export declare const Caveats: any;
17
+ /** A Dafny `int` from a JS number. Only safe integers are representable; anything else is a caller bug. */
18
+ export declare function bn(n: number): BigNumber;
19
+ export declare const num: (b: BigNumber) => number;
20
+ export declare const some: <T>(v: T) => any;
21
+ export declare const none: () => any;
22
+ export declare const opt: <T>(v: T | undefined) => any;
23
+ export declare const fromOpt: <T>(o: any) => T | undefined;
24
+ /** Dafny seq from a JS array (no spread: safe for very long arrays). */
25
+ export declare function seq<T>(a: readonly T[]): any;
26
+ export declare const fromSeq: <T>(s: any) => T[];
27
+ /** Result of a lazily evaluated primitive: ok, or an opaque diagnostic carried through untouched. */
28
+ export type Res<M> = {
29
+ ok: true;
30
+ } | {
31
+ ok: false;
32
+ m: M;
33
+ };
34
+ export declare const resOk: () => any;
35
+ export declare const wrapRes: <M>(f: () => Res<M>) => () => any;
36
+ export type Status = 'pass' | 'fail' | 'not-enforced';
37
+ export declare function toStatus(s: any): Status;
38
+ export declare function fromStatus(s: Status): any;
39
+ /** Dafny string (sequence of code points) from a JS string - only the replay-store model needs it. */
40
+ /** An empty Dafny `Map` (the fresh state for a verified store). */
41
+ export declare const emptyDafnyMap: () => any;
42
+ export declare const dstr: (s: string) => any;
43
+ export declare const jstr: (d: any) => string;
package/dist/bridge.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.jstr = exports.dstr = exports.emptyDafnyMap = exports.wrapRes = exports.resOk = exports.fromSeq = exports.fromOpt = exports.opt = exports.none = exports.some = exports.num = exports.Caveats = exports.Verdict = exports.Replay = exports.Threshold = exports.Chain = exports.Common = exports.D = void 0;
7
+ exports.bn = bn;
8
+ exports.seq = seq;
9
+ exports.toStatus = toStatus;
10
+ exports.fromStatus = fromStatus;
11
+ /* eslint-disable @typescript-eslint/no-explicit-any */
12
+ // bridge.ts - the ONLY file that touches the Dafny-generated runtime types. Everything exported from the package
13
+ // is plain JSON-like data / closures; Dafny datatypes (BigNumber ints, Seq, Option, Res, tuples) never leak.
14
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
16
+ const core = require('../generated/pca_core.js');
17
+ exports.D = core;
18
+ exports.Common = core.Common;
19
+ exports.Chain = core.Chain;
20
+ exports.Threshold = core.Threshold;
21
+ exports.Replay = core.Replay;
22
+ exports.Verdict = core.Verdict;
23
+ exports.Caveats = core.Caveats;
24
+ /** A Dafny `int` from a JS number. Only safe integers are representable; anything else is a caller bug. */
25
+ function bn(n) {
26
+ if (!Number.isSafeInteger(n))
27
+ throw new RangeError(`pca-verified-core: expected a safe integer, got ${String(n)}`);
28
+ return new bignumber_js_1.default(n);
29
+ }
30
+ const num = (b) => b.toNumber();
31
+ exports.num = num;
32
+ const some = (v) => exports.Common.Option.create_Some(v);
33
+ exports.some = some;
34
+ const none = () => exports.Common.Option.create_None();
35
+ exports.none = none;
36
+ const opt = (v) => (v === undefined ? (0, exports.none)() : (0, exports.some)(v));
37
+ exports.opt = opt;
38
+ const fromOpt = (o) => (o.is_Some ? o.dtor_v : undefined);
39
+ exports.fromOpt = fromOpt;
40
+ /** Dafny seq from a JS array (no spread: safe for very long arrays). */
41
+ function seq(a) {
42
+ const s = core._dafny.Seq.of();
43
+ for (let i = 0; i < a.length; i++)
44
+ s.push(a[i]);
45
+ return s;
46
+ }
47
+ const fromSeq = (s) => Array.from(s);
48
+ exports.fromSeq = fromSeq;
49
+ const resOk = () => exports.Common.Res.create_Ok();
50
+ exports.resOk = resOk;
51
+ const wrapRes = (f) => () => {
52
+ const r = f();
53
+ return r.ok ? exports.Common.Res.create_Ok() : exports.Common.Res.create_Err(r.m);
54
+ };
55
+ exports.wrapRes = wrapRes;
56
+ function toStatus(s) {
57
+ if (s.is_Pass)
58
+ return 'pass';
59
+ if (s.is_Fail)
60
+ return 'fail';
61
+ return 'not-enforced';
62
+ }
63
+ function fromStatus(s) {
64
+ return s === 'pass' ? exports.Common.Status.create_Pass() : s === 'fail' ? exports.Common.Status.create_Fail() : exports.Common.Status.create_NotEnforced();
65
+ }
66
+ /** Dafny string (sequence of code points) from a JS string - only the replay-store model needs it. */
67
+ /** An empty Dafny `Map` (the fresh state for a verified store). */
68
+ const emptyDafnyMap = () => core._dafny.Map.Empty;
69
+ exports.emptyDafnyMap = emptyDafnyMap;
70
+ const dstr = (s) => core._dafny.Seq.UnicodeFromString(s);
71
+ exports.dstr = dstr;
72
+ const jstr = (d) => d.toVerbatimString(false);
73
+ exports.jstr = jstr;
74
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":";;;;;;AAwBA,gBAGC;AASD,kBAIC;AAYD,4BAIC;AACD,gCAEC;AA3DD,uDAAuD;AACvD,iHAAiH;AACjH,6GAA6G;AAC7G,gEAAqC;AACrC,iEAAiE;AACjE,MAAM,IAAI,GAAG,OAAO,CAAC,0BAA0B,CAQ9C,CAAC;AAEW,QAAA,CAAC,GAAG,IAAI,CAAC;AACT,QAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AACrB,QAAA,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;AACnB,QAAA,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;AAC3B,QAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AACrB,QAAA,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;AACvB,QAAA,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;AAEpC,2GAA2G;AAC3G,SAAgB,EAAE,CAAC,CAAS;IAC1B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,mDAAmD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACnH,OAAO,IAAI,sBAAS,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AACM,MAAM,GAAG,GAAG,CAAC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AA+F"}
@@ -0,0 +1,65 @@
1
+ import { bn, fromOpt, type Res, some, none, D } from './bridge';
2
+ /** Maximum delegation chain length (hops) accepted by the verified walk. Proved: longer chains are always TooLong. */
3
+ export declare const MAX_CHAIN_DEPTH: number;
4
+ /**
5
+ * Pre-evaluated facts about one hop. Every closure is a PURE function of the artifact: the glue computes it with the
6
+ * trusted primitives (hashing, suite policy, signature verification) and the verified core decides order,
7
+ * first-failure, depth and attenuation. Closures are only called when the core needs them (lazily, in order).
8
+ */
9
+ export interface ChainHop<M, C> {
10
+ wellTyped: boolean;
11
+ hasParent: boolean;
12
+ /** hop 0 only: the root issuer is the expected principal (or none is expected). */
13
+ rootIssuerOk: boolean;
14
+ /** this hop's caveat list (opaque elements; compared with `ceq`). */
15
+ caveats: readonly C[];
16
+ /** hops >= 1: `hop.parent === capHash(parent)`. */
17
+ parentLinkOk: () => boolean;
18
+ /** hops >= 1: `hop.issuer === parent.holder`. */
19
+ issuerIsParentHolder: () => boolean;
20
+ /** suite policy (allowedSuites) result. */
21
+ suite: () => Res<M>;
22
+ /** F-2 holder_pq binding result (hops >= 1). */
23
+ pq: () => Res<M>;
24
+ /** body digest + signature result. */
25
+ sig: () => Res<M>;
26
+ }
27
+ export type ChainError<M> = {
28
+ kind: 'empty';
29
+ } | {
30
+ kind: 'too-long';
31
+ } | {
32
+ kind: 'malformed';
33
+ hop: number;
34
+ } | {
35
+ kind: 'root-has-parent';
36
+ } | {
37
+ kind: 'root-issuer';
38
+ } | {
39
+ kind: 'suite' | 'pq' | 'sig';
40
+ hop: number;
41
+ m: M;
42
+ } | {
43
+ kind: 'parent-link' | 'issuer-not-holder' | 'drops';
44
+ hop: number;
45
+ } | {
46
+ kind: 'altered';
47
+ hop: number;
48
+ caveat: number;
49
+ } | {
50
+ kind: 'alloc';
51
+ m: M;
52
+ };
53
+ export type ChainDecision<M> = {
54
+ ok: true;
55
+ } | {
56
+ ok: false;
57
+ error: ChainError<M>;
58
+ };
59
+ /**
60
+ * Verified chain walk (formal/dafny/Chain.dfy: VerifyChain). `hopAt(i)` builds the facts of hop i on demand; only the
61
+ * first MAX_CHAIN_DEPTH+1 hops are ever materialised, so an absurdly long chain costs O(1) before it is rejected.
62
+ * `ceq(a, b)` is caveat equality (b must be the parent's element), `alloc()` the budget_alloc monotonicity result.
63
+ */
64
+ export declare function decideChain<M, C>(length: number, hopAt: (i: number) => ChainHop<M, C>, ceq: (child: C, parent: C) => boolean, alloc: () => Res<M>): ChainDecision<M>;
65
+ export { bn, fromOpt, some, none, D };
package/dist/chain.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.D = exports.none = exports.some = exports.fromOpt = exports.bn = exports.MAX_CHAIN_DEPTH = void 0;
4
+ exports.decideChain = decideChain;
5
+ const bridge_1 = require("./bridge");
6
+ Object.defineProperty(exports, "bn", { enumerable: true, get: function () { return bridge_1.bn; } });
7
+ Object.defineProperty(exports, "fromOpt", { enumerable: true, get: function () { return bridge_1.fromOpt; } });
8
+ Object.defineProperty(exports, "some", { enumerable: true, get: function () { return bridge_1.some; } });
9
+ Object.defineProperty(exports, "none", { enumerable: true, get: function () { return bridge_1.none; } });
10
+ Object.defineProperty(exports, "D", { enumerable: true, get: function () { return bridge_1.D; } });
11
+ /** Maximum delegation chain length (hops) accepted by the verified walk. Proved: longer chains are always TooLong. */
12
+ exports.MAX_CHAIN_DEPTH = (0, bridge_1.num)(bridge_1.Chain.__default.MaxDepth);
13
+ /**
14
+ * Verified chain walk (formal/dafny/Chain.dfy: VerifyChain). `hopAt(i)` builds the facts of hop i on demand; only the
15
+ * first MAX_CHAIN_DEPTH+1 hops are ever materialised, so an absurdly long chain costs O(1) before it is rejected.
16
+ * `ceq(a, b)` is caveat equality (b must be the parent's element), `alloc()` the budget_alloc monotonicity result.
17
+ */
18
+ function decideChain(length, hopAt, ceq, alloc) {
19
+ const n = Math.min(length, exports.MAX_CHAIN_DEPTH + 1);
20
+ const hops = [];
21
+ for (let i = 0; i < n; i++) {
22
+ const h = hopAt(i);
23
+ hops.push(bridge_1.Chain.Hop.create_Hop(h.wellTyped, h.hasParent, h.rootIssuerOk, (0, bridge_1.seq)(h.caveats), h.parentLinkOk, h.issuerIsParentHolder, (0, bridge_1.wrapRes)(h.suite), (0, bridge_1.wrapRes)(h.pq), (0, bridge_1.wrapRes)(h.sig)));
24
+ }
25
+ const r = bridge_1.Chain.__default.VerifyChain((0, bridge_1.seq)(hops), ceq, (0, bridge_1.wrapRes)(alloc));
26
+ if (r.is_ChainOk)
27
+ return { ok: true };
28
+ const e = r.dtor_e;
29
+ const error = (() => {
30
+ if (e.is_Empty)
31
+ return { kind: 'empty' };
32
+ if (e.is_TooLong)
33
+ return { kind: 'too-long' };
34
+ if (e.is_Malformed)
35
+ return { kind: 'malformed', hop: (0, bridge_1.num)(e.dtor_hop) };
36
+ if (e.is_RootHasParent)
37
+ return { kind: 'root-has-parent' };
38
+ if (e.is_RootIssuer)
39
+ return { kind: 'root-issuer' };
40
+ if (e.is_SuiteErr)
41
+ return { kind: 'suite', hop: (0, bridge_1.num)(e.dtor_hop), m: e.dtor_m };
42
+ if (e.is_PqErr)
43
+ return { kind: 'pq', hop: (0, bridge_1.num)(e.dtor_hop), m: e.dtor_m };
44
+ if (e.is_SigErr)
45
+ return { kind: 'sig', hop: (0, bridge_1.num)(e.dtor_hop), m: e.dtor_m };
46
+ if (e.is_ParentLink)
47
+ return { kind: 'parent-link', hop: (0, bridge_1.num)(e.dtor_hop) };
48
+ if (e.is_IssuerNotHolder)
49
+ return { kind: 'issuer-not-holder', hop: (0, bridge_1.num)(e.dtor_hop) };
50
+ if (e.is_Drops)
51
+ return { kind: 'drops', hop: (0, bridge_1.num)(e.dtor_hop) };
52
+ if (e.is_Altered)
53
+ return { kind: 'altered', hop: (0, bridge_1.num)(e.dtor_hop), caveat: (0, bridge_1.num)(e.dtor_j) };
54
+ return { kind: 'alloc', m: e.dtor_m };
55
+ })();
56
+ return { ok: false, error };
57
+ }
58
+ //# sourceMappingURL=chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":";;;AA+CA,kCA2CC;AA1FD,qCAA0F;AA6FjF,mFA7FO,WAAE,OA6FP;AAAE,wFA7FO,gBAAO,OA6FP;AAAE,qFA7FoC,aAAI,OA6FpC;AAAE,qFA7FoC,aAAI,OA6FpC;AAAE,kFA7FoC,UAAC,OA6FpC;AA3FnC,sHAAsH;AACzG,QAAA,eAAe,GAAW,IAAA,YAAG,EAAC,cAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAuCrE;;;;GAIG;AACH,SAAgB,WAAW,CACzB,MAAc,EACd,KAAoC,EACpC,GAAqC,EACrC,KAAmB;IAEnB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,uBAAe,GAAG,CAAC,CAAC,CAAC;IAChD,MAAM,IAAI,GAAc,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,CACP,cAAK,CAAC,GAAG,CAAC,UAAU,CAClB,CAAC,CAAC,SAAS,EACX,CAAC,CAAC,SAAS,EACX,CAAC,CAAC,YAAY,EACd,IAAA,YAAG,EAAC,CAAC,CAAC,OAAO,CAAC,EACd,CAAC,CAAC,YAAY,EACd,CAAC,CAAC,oBAAoB,EACtB,IAAA,gBAAO,EAAC,CAAC,CAAC,KAAK,CAAC,EAChB,IAAA,gBAAO,EAAC,CAAC,CAAC,EAAE,CAAC,EACb,IAAA,gBAAO,EAAC,CAAC,CAAC,GAAG,CAAC,CACf,CACF,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,GAAG,cAAK,CAAC,SAAS,CAAC,WAAW,CAAC,IA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AAW,EAAE,CAAC;QAChF,IAAI,CAAC,CAAC,aAAa;YAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,IAAA,YAAG,EAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,CAAC,kBAAkB;YAAE,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,GAAG,EAAE,IAAA,YAAG,EAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrF,IAAI,CAAC,CAAC,QAAQ;YAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAA,YAAG,EAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/D,IAAI,CAAC,CAAC,UAAU;YAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,IAAA,YAAG,EAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAA,YAAG,EAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,MAAW,EAAE,CAAC;IAC7C,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,109 @@
1
+ import BigNumber from 'bignumber.js';
2
+ export interface MeasuredIdentity {
3
+ model_id: string;
4
+ weights_digest: string;
5
+ weights_measured?: boolean;
6
+ runtime_measurement: string;
7
+ operator: string;
8
+ system_prompt_digest?: string;
9
+ tool_manifest_digest?: string;
10
+ }
11
+ export interface HardwareAttestationResult {
12
+ ok: boolean;
13
+ reason?: string;
14
+ measured?: MeasuredIdentity;
15
+ bound?: boolean;
16
+ hostAsserted?: Record<string, string>;
17
+ }
18
+ export interface HardwareAttestationVerifier {
19
+ verify(input: any): Promise<HardwareAttestationResult>;
20
+ }
21
+ export interface MultiRootAttestationPolicy {
22
+ roots: Array<{
23
+ id: string;
24
+ verifier: HardwareAttestationVerifier;
25
+ required?: boolean;
26
+ suite?: string;
27
+ }>;
28
+ threshold: number;
29
+ }
30
+ export interface AgentBinding {
31
+ model_allowlist?: unknown[];
32
+ min_measurement?: string | {
33
+ svn: number;
34
+ };
35
+ operator?: string;
36
+ weights_allowlist?: unknown[];
37
+ system_prompt_allowlist?: unknown[];
38
+ tool_manifest_allowlist?: unknown[];
39
+ require_hardware?: boolean;
40
+ require_measured_weights?: boolean;
41
+ }
42
+ /** Intern values to positive integers with SameValueZero equality (exactly `Array.prototype.includes` / `Map` semantics). */
43
+ declare class Interner {
44
+ private readonly m;
45
+ readonly vals: unknown[];
46
+ id(v: unknown): number;
47
+ /** 0 for anything that is not a non-empty string (the multi-root reconciliation convention). */
48
+ sid(v: unknown): number;
49
+ }
50
+ export interface AttestationRootLike {
51
+ id: string;
52
+ verifier: HardwareAttestationVerifier;
53
+ required?: boolean;
54
+ suite?: string;
55
+ }
56
+ /** Build the verified multi-root verifier. Same construction errors, same results, same reason strings as createMultiRootVerifier. */
57
+ export declare function createMultiRootVerifierVerified(policy: MultiRootAttestationPolicy): HardwareAttestationVerifier;
58
+ /** matchAgentBinding with the decision made by the proved MatchBinding. Same reasons as production. */
59
+ export declare function matchAgentBindingVerified(id: MeasuredIdentity, binding: AgentBinding | undefined): string | null;
60
+ /** requiresAttestation via the proved flag combination. */
61
+ export declare function requiresAttestationVerified(binding: AgentBinding | undefined): boolean;
62
+ /**
63
+ * The proved model of memoryNonceStore (Attest.dfy: MsConsume, SingleUse, LiveNeverEvicted, FullOfLiveRefuses): a consumed nonce is
64
+ * rejected for `retentionMs`; a full store refuses (never evicts a live entry); only aged-out entries are dropped. Same construction
65
+ * checks and messages as production. The proved arithmetic is over integers: `retentionMs` and every `now()` value must be safe
66
+ * integers (Date.now() is); a non-finite clock value is rejected exactly like production, a fractional one throws RangeError.
67
+ */
68
+ export declare class VerifiedMemoryNonceStore {
69
+ private s;
70
+ private readonly it;
71
+ private readonly clock;
72
+ constructor(max?: number, opts?: {
73
+ retentionMs?: number;
74
+ now?: () => number;
75
+ });
76
+ consume(nonce: string): boolean;
77
+ }
78
+ export type AllowlistGateKind = 'shape' | 'options' | 'unknown-issuer' | 'alg-mismatch' | 'issuer-expired' | 'bad-signature' | 'not-yet-valid' | 'expired' | 'lifetime-too-long' | 'below-min-version' | 'rollback' | 'conflict';
79
+ export interface AllowlistGateFacts {
80
+ shapeOk: boolean;
81
+ issuerKnown: boolean;
82
+ algMatches: boolean;
83
+ issuerLive: boolean;
84
+ sigOk: boolean;
85
+ nowMs: number;
86
+ skew: number;
87
+ notBefore: number;
88
+ expiresAt: number;
89
+ maxLifetimeMs?: number;
90
+ minVersion?: number;
91
+ version: number;
92
+ lastSeenVersion?: number;
93
+ lastSeenDigest?: string;
94
+ digest: string;
95
+ }
96
+ /** The ordered decision of verifyAllowlistManifest after the primitive facts are known. `undefined` == accepted. A non-finite skew / lifetime or a non-integer version option is the proved `options` reject (production: `malformed`); otherwise numerics must be safe integers (skew is floored, negative skew clamps to 0). */
97
+ export declare function allowlistGate(f: AllowlistGateFacts): AllowlistGateKind | undefined;
98
+ /** Internal bridge for the production drop-ins in test/support/attest-dropins.ts (not part of the public API). */
99
+ export declare const attestBridge: {
100
+ A: any;
101
+ D: any;
102
+ DF: any;
103
+ bn: (n: number) => BigNumber;
104
+ seqOf: (a: readonly any[]) => any;
105
+ kindName: (k: any) => string;
106
+ none: () => any;
107
+ Interner: typeof Interner;
108
+ };
109
+ export {};