@parmanasystems/core 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @parmanasystems/core
2
+
3
+ Portable runtime SDK for the parmanasystems deterministic governance ecosystem.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@parmanasystems/core)](https://www.npmjs.com/package/@parmanasystems/core)
6
+
7
+ ## Overview
8
+
9
+ `@parmanasystems/core` is the recommended single-package install for most applications. It re-exports the full governance lifecycle, execution runtime, and verification layer, and adds the deterministic validator and canonical JSON utilities.
10
+
11
+ Install this instead of separately installing `@parmanasystems/execution`, `@parmanasystems/governance`, and `@parmanasystems/verifier`.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @parmanasystems/core
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```typescript
22
+ import {
23
+ executeFromSignals,
24
+ verifyAttestation,
25
+ LocalSigner,
26
+ LocalVerifier,
27
+ getRuntimeManifest,
28
+ RedisReplayStore,
29
+ } from "@parmanasystems/core";
30
+ import { createClient } from "redis";
31
+
32
+ const redis = createClient();
33
+ await redis.connect();
34
+
35
+ const signer = new LocalSigner(process.env.Parmana_PRIVATE_KEY!);
36
+ const verifier = new LocalVerifier(process.env.Parmana_PUBLIC_KEY!);
37
+ const store = new RedisReplayStore(redis);
38
+ const manifest = getRuntimeManifest();
39
+
40
+ // Execute a governance decision
41
+ const result = await executeFromSignals(
42
+ {
43
+ policyId: "claims-approval",
44
+ policyVersion: "v1",
45
+ signals: { insurance_active: true, risk_score: 42 },
46
+ },
47
+ signer,
48
+ verifier,
49
+ store
50
+ );
51
+
52
+ if (result.status === "success" && result.signature) {
53
+ // Independently verify
54
+ const verification = verifyAttestation(
55
+ { execution_id: result.execution_id, ...result },
56
+ verifier,
57
+ manifest
58
+ );
59
+ console.log(verification.valid); // true
60
+ }
61
+ ```
62
+
63
+ ## Exports
64
+
65
+ ### Governance lifecycle (from `@parmanasystems/governance`)
66
+
67
+ | Export | Description |
68
+ |---|---|
69
+ | `createPolicy` | Scaffold a new policy directory |
70
+ | `upgradePolicy` | Create an upgraded policy version |
71
+ | `validatePolicy` | Validate a policy structure |
72
+ | `generateBundle` | Generate a content-addressed policy bundle |
73
+ | `definePolicy` | Build a PolicyDefinition in memory |
74
+
75
+ ### Deterministic execution (from `@parmanasystems/execution`)
76
+
77
+ | Export | Description |
78
+ |---|---|
79
+ | `executeFromSignals` | Full pipeline: load policy → evaluate → sign |
80
+ | `executeDecision` | Lower-level: token → verify → replay → sign |
81
+ | `executeSimple` | Token-based execution without policy file |
82
+ | `resolveOverride` | Complete a pending_override execution |
83
+ | `evaluatePolicy` | Pure policy rule evaluation |
84
+ | `issueToken` | Issue a single-use execution token |
85
+ | `signExecutionToken` | Sign a token |
86
+ | `verifyExecutionToken` | Verify a token signature |
87
+ | `getRuntimeManifest` | Return the active runtime manifest |
88
+ | `signRuntimeManifest` | Sign a runtime manifest |
89
+ | `verifyRuntimeManifest` | Verify a runtime manifest signature |
90
+ | `LocalSigner` | Ed25519 signer (Node.js crypto) |
91
+ | `LocalVerifier` | Ed25519 verifier (Node.js crypto) |
92
+ | `MemoryReplayStore` | In-process replay protection |
93
+ | `RedisReplayStore` | Distributed Redis replay protection |
94
+ | `INVARIANT_REGISTRY` | All 60+ registered invariants |
95
+ | `InvariantViolation` | Invariant violation error class |
96
+ | `violate` | Throw a structured invariant violation |
97
+
98
+ ### Portable verification (from `@parmanasystems/verifier`)
99
+
100
+ | Export | Description |
101
+ |---|---|
102
+ | `verifyAttestation` | Four-check attestation verification |
103
+ | `verifyBundle` | Bundle signature and hash verification |
104
+ | `verifyRuntime` | Runtime manifest comparison |
105
+ | `verifyRuntimeCompatibility` | Runtime requirements check |
106
+ | `verifyExecutionRequirements` | Execution requirements check |
107
+
108
+ ### Canonical utilities (from `@parmanasystems/bundle`)
109
+
110
+ ```typescript
111
+ import { canonicalize } from "@parmanasystems/core";
112
+ // Deterministic JSON serialization (sorted keys, stable bytes)
113
+ ```
114
+
115
+ ### Types
116
+
117
+ ```typescript
118
+ import type {
119
+ ExecutionContext,
120
+ ExecutionAttestation,
121
+ ExecutionToken,
122
+ DecisionResult,
123
+ RuntimeManifest,
124
+ Signer,
125
+ AsyncSigner,
126
+ Verifier,
127
+ ReplayStore,
128
+ AsyncReplayStore,
129
+ ViolationReport,
130
+ } from "@parmanasystems/core";
131
+ ```
132
+
133
+ ## License
134
+
135
+ Apache-2.0
@@ -0,0 +1,217 @@
1
+ export { RuntimeRequirements, createPolicy, generateBundle, upgradePolicy, validatePolicy } from '@parmanasystems/governance';
2
+ export { DecisionResult, ExecutionAttestation, ExecutionContext, ExecutionToken, INVARIANT_REGISTRY, InvariantBoundary, InvariantEntry, InvariantId, InvariantViolation, LocalSigner, LocalVerifier, MemoryReplayStore, ReplayStore, RuntimeManifest, Signer, Verifier, ViolationReport, executeDecision, executeFromSignals, getRuntimeManifest, hashInput, issueToken, signRuntimeManifest, verifyExecutionToken, verifyRuntimeManifest, violate } from '@parmanasystems/execution';
3
+ export { verifyAttestation, verifyBundle, verifyExecutionRequirements, verifyRuntime, verifyRuntimeCompatibility } from '@parmanasystems/verifier';
4
+
5
+ /**
6
+ * Serializes `value` to a stable, compact JSON string with object keys sorted
7
+ * recursively. Used by the core validation pipeline for determinism checks.
8
+ *
9
+ * Note: unlike `@parmanasystems/bundle`'s `canonicalize`, this variant uses
10
+ * compact output (`JSON.stringify` without indentation) for in-memory comparisons.
11
+ */
12
+ declare function canonicalize(value: unknown): string;
13
+
14
+ /** Configuration for {@link LocalValidator}. */
15
+ interface ValidatorConfig {
16
+ /**
17
+ * Field names that must not appear anywhere inside a deterministic payload.
18
+ * Defaults to {@link forbiddenDeterministicFields} when omitted.
19
+ */
20
+ forbiddenDeterministicFields?: readonly string[];
21
+ }
22
+
23
+ /**
24
+ * Per-stage pass/fail breakdown produced by {@link LocalValidator}.
25
+ * Each stage is run in order; a `false` entry short-circuits subsequent
26
+ * stages that depend on it.
27
+ */
28
+ interface ValidationStages {
29
+ /** Envelope has both `payload` and `signature` fields of the correct types. */
30
+ structure: boolean;
31
+ /** The payload serializes without error through the canonical JSON pipeline. */
32
+ canonical: boolean;
33
+ /**
34
+ * The payload contains no {@link forbiddenDeterministicFields} (e.g. `generatedAt`,
35
+ * `traceId`) that would break deterministic reproducibility.
36
+ */
37
+ deterministic: boolean;
38
+ /**
39
+ * The canonical payload matches the canonical envelope-without-metadata, confirming
40
+ * that metadata has not contaminated the deterministic signing scope.
41
+ */
42
+ metadataIsolation: boolean;
43
+ /**
44
+ * Cryptographic signature over the payload has been verified.
45
+ * Currently always `false` — cryptographic verification is not yet wired into
46
+ * `LocalValidator`. Use `@parmanasystems/verifier` for signature verification.
47
+ */
48
+ cryptographic: boolean;
49
+ }
50
+ /** Full validation result returned by {@link LocalValidator.validate}. */
51
+ interface ValidationResult {
52
+ /**
53
+ * `true` only when all five validation stages pass, including `cryptographic`.
54
+ * Currently always `false` because the cryptographic stage is not yet implemented.
55
+ */
56
+ valid: boolean;
57
+ /** `true` when cryptographic signature verification passed. Currently always `false`. */
58
+ verified: boolean;
59
+ /** Granular per-stage results for diagnostics. */
60
+ stages: ValidationStages;
61
+ /** Human-readable error messages for every failed stage. */
62
+ errors: string[];
63
+ }
64
+
65
+ /**
66
+ * Generic signed wrapper for deterministic governance payloads.
67
+ *
68
+ * Contains exactly two fields: the deterministic `payload` (signing scope)
69
+ * and the cryptographic `signature` over its canonical form.
70
+ *
71
+ * Metadata is structurally absent — not optional, not filtered at runtime.
72
+ * Any operational context (host, trace IDs, timestamps) must be stripped by
73
+ * the caller before constructing a SignedEnvelope. Callers that receive
74
+ * metadata from external sources should destructure it out at the boundary:
75
+ *
76
+ * const { metadata: _meta, ...envelope } = rawInput;
77
+ * validator.validate(envelope);
78
+ *
79
+ * Enforces: INV-078 (metadata non-interference), INV-004 (no time dependency).
80
+ */
81
+ interface SignedEnvelope<TPayload> {
82
+ /** The deterministic payload to be signed and verified. */
83
+ payload: TPayload;
84
+ /** Base64-encoded Ed25519 signature over the canonical `payload`. */
85
+ signature: string;
86
+ }
87
+
88
+ /**
89
+ * Multi-stage validator for {@link SignedEnvelope} values.
90
+ *
91
+ * Runs up to five sequential checks (structure → canonical → deterministic →
92
+ * metadata isolation → cryptographic) and returns a detailed
93
+ * {@link ValidationResult} with per-stage flags and error messages.
94
+ *
95
+ * **Note:** the `cryptographic` stage is not yet implemented and always returns
96
+ * `false`, so `valid` is always `false`. Use `@parmanasystems/verifier` for
97
+ * cryptographic attestation verification.
98
+ */
99
+ declare class LocalValidator {
100
+ private readonly config;
101
+ /**
102
+ * @param config - Optional override for {@link ValidatorConfig}.
103
+ * Defaults to using {@link forbiddenDeterministicFields}.
104
+ */
105
+ constructor(config?: ValidatorConfig);
106
+ private extractDeterministicPayload;
107
+ /** Returns `true` when `envelope` has `payload` (any value) and `signature` (string). */
108
+ validateStructure(envelope: SignedEnvelope<unknown>): boolean;
109
+ /** Returns `true` when `payload` can be serialized through the canonical JSON pipeline without error. */
110
+ validateCanonical(payload: unknown): boolean;
111
+ /**
112
+ * Returns `true` when the canonical form of the payload alone equals the
113
+ * canonical form of `{ payload }`, confirming that no metadata fields have
114
+ * leaked into the deterministic signing scope.
115
+ */
116
+ validateMetadataIsolation(envelope: SignedEnvelope<unknown>): boolean;
117
+ /**
118
+ * Runs all five validation stages against `envelope` and returns a
119
+ * {@link ValidationResult} with per-stage flags and accumulated error messages.
120
+ */
121
+ validate(envelope: SignedEnvelope<unknown>): ValidationResult;
122
+ }
123
+
124
+ /** Returns `true` when `value` is a non-empty, non-whitespace-only string. */
125
+ declare function assertNonEmptyString(value: unknown): boolean;
126
+ /** Returns `true` when `value` is an array. */
127
+ declare function assertArray(value: unknown): boolean;
128
+ /**
129
+ * Recursively scans `payload` and returns `false` if any object key matches
130
+ * a name in `forbiddenFields`.
131
+ *
132
+ * Used by {@link LocalValidator} to enforce that operational-metadata fields
133
+ * have not contaminated the deterministic signing scope.
134
+ *
135
+ * @param payload - The payload object to inspect.
136
+ * @param forbiddenFields - Field names that must not appear anywhere in the payload.
137
+ */
138
+ declare function assertNoOperationalMetadata(payload: unknown, forbiddenFields: readonly string[]): boolean;
139
+
140
+ /** Deterministic payload for a release artifact attestation. */
141
+ interface ReleasePayload {
142
+ /** Semantic version of the release (e.g. `"1.0.5"`). */
143
+ version: string;
144
+ /** List of artifact identifiers (e.g. package names or SHA-256 hashes) included in the release. */
145
+ artifacts: string[];
146
+ }
147
+ /** Deterministic payload for a runtime version attestation. */
148
+ interface RuntimePayload {
149
+ /** Runtime identifier. */
150
+ runtime: string;
151
+ /** Semantic version of the runtime. */
152
+ version: string;
153
+ /** Schema or protocol versions the runtime is compatible with. */
154
+ compatibility: string[];
155
+ }
156
+ /** Deterministic payload for a governance decision attestation. */
157
+ interface AttestationPayload {
158
+ /** The governance decision (e.g. `"approve"` or `"deny"`). */
159
+ decision: string;
160
+ /** The policy version that produced the decision. */
161
+ policyVersion: string;
162
+ /** ISO 8601 UTC timestamp of when the decision was made. */
163
+ timestamp: string;
164
+ }
165
+
166
+ /**
167
+ * Non-deterministic operational context attached to a governance envelope.
168
+ * Fields in this interface are in the {@link forbiddenDeterministicFields} list
169
+ * and must not appear inside a deterministic payload.
170
+ */
171
+ interface OperationalMetadata {
172
+ /** ISO 8601 timestamp of when the envelope was generated. */
173
+ generatedAt?: string;
174
+ /** Deployment environment (e.g. `"production"`, `"staging"`). */
175
+ environment?: string;
176
+ /** Hostname of the generating process. */
177
+ host?: string;
178
+ /** Runtime identifier or version of the generating process. */
179
+ runtime?: string;
180
+ /** Distributed trace identifier. */
181
+ traceId?: string;
182
+ }
183
+ /** Immutable provenance information that links an envelope to a specific runtime build. */
184
+ interface ProvenanceMetadata {
185
+ /** Semantic version of the governance runtime. */
186
+ runtimeVersion?: string;
187
+ /** SHA-256 bundle hash of the executing policy. */
188
+ bundleHash?: string;
189
+ /** Version of the trust root used for verification. */
190
+ trustRootVersion?: string;
191
+ /** CI build identifier that produced the artifact. */
192
+ buildId?: string;
193
+ }
194
+ /**
195
+ * Container for governance envelope metadata.
196
+ * Split into `operational` (non-deterministic, excluded from signing) and
197
+ * `provenance` (deterministic, included in signing) sections.
198
+ */
199
+ interface GovernanceMetadata {
200
+ /** Non-deterministic operational context — excluded from determinism checks. */
201
+ operational?: OperationalMetadata;
202
+ /** Immutable provenance information — included in determinism checks. */
203
+ provenance?: ProvenanceMetadata;
204
+ }
205
+
206
+ /**
207
+ * Field names that must not appear inside a deterministic payload.
208
+ *
209
+ * These are operational-metadata fields that introduce non-determinism
210
+ * (timestamps, hostnames, trace IDs, deployment context) and would break
211
+ * reproducible verification if present in the signed payload scope.
212
+ *
213
+ * Used as the default for {@link ValidatorConfig.forbiddenDeterministicFields}.
214
+ */
215
+ declare const forbiddenDeterministicFields: readonly ["generatedAt", "environment", "host", "runtime", "traceId"];
216
+
217
+ export { type AttestationPayload, type GovernanceMetadata, LocalValidator, type OperationalMetadata, type ProvenanceMetadata, type ReleasePayload, type RuntimePayload, type SignedEnvelope, type ValidationResult, type ValidationStages, type ValidatorConfig, assertArray, assertNoOperationalMetadata, assertNonEmptyString, canonicalize, forbiddenDeterministicFields };
package/dist/index.js ADDED
@@ -0,0 +1,237 @@
1
+ // src/index.ts
2
+ import {
3
+ createPolicy,
4
+ upgradePolicy,
5
+ validatePolicy,
6
+ generateBundle
7
+ } from "@parmanasystems/governance";
8
+ import {
9
+ executeFromSignals,
10
+ executeDecision,
11
+ issueToken,
12
+ verifyExecutionToken,
13
+ getRuntimeManifest,
14
+ signRuntimeManifest,
15
+ verifyRuntimeManifest,
16
+ LocalSigner,
17
+ LocalVerifier,
18
+ MemoryReplayStore
19
+ } from "@parmanasystems/execution";
20
+ import {
21
+ verifyAttestation,
22
+ verifyBundle,
23
+ verifyRuntime,
24
+ verifyRuntimeCompatibility,
25
+ verifyExecutionRequirements
26
+ } from "@parmanasystems/verifier";
27
+ import {
28
+ INVARIANT_REGISTRY,
29
+ InvariantViolation,
30
+ violate,
31
+ hashInput
32
+ } from "@parmanasystems/execution";
33
+
34
+ // src/canonicalize.ts
35
+ function sortKeys(value) {
36
+ if (Array.isArray(value)) {
37
+ return value.map(sortKeys);
38
+ }
39
+ if (value && typeof value === "object") {
40
+ return Object.keys(value).sort().reduce((acc, key) => {
41
+ acc[key] = sortKeys(value[key]);
42
+ return acc;
43
+ }, {});
44
+ }
45
+ return value;
46
+ }
47
+ function canonicalize(value) {
48
+ return JSON.stringify(sortKeys(value));
49
+ }
50
+
51
+ // src/invariants.ts
52
+ function assertNonEmptyString(value) {
53
+ return typeof value === "string" && value.trim().length > 0;
54
+ }
55
+ function assertArray(value) {
56
+ return Array.isArray(value);
57
+ }
58
+ function scanObject(value, forbiddenFields) {
59
+ if (typeof value !== "object" || value === null) {
60
+ return true;
61
+ }
62
+ if (Array.isArray(value)) {
63
+ return value.every(
64
+ (item) => scanObject(
65
+ item,
66
+ forbiddenFields
67
+ )
68
+ );
69
+ }
70
+ for (const [key, nested] of Object.entries(value)) {
71
+ if (forbiddenFields.includes(
72
+ key
73
+ )) {
74
+ return false;
75
+ }
76
+ if (!scanObject(
77
+ nested,
78
+ forbiddenFields
79
+ )) {
80
+ return false;
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+ function assertNoOperationalMetadata(payload, forbiddenFields) {
86
+ return scanObject(
87
+ payload,
88
+ forbiddenFields
89
+ );
90
+ }
91
+
92
+ // src/deterministic-policy.ts
93
+ var forbiddenDeterministicFields = [
94
+ "generatedAt",
95
+ "environment",
96
+ "host",
97
+ "runtime",
98
+ "traceId"
99
+ ];
100
+
101
+ // src/validator.ts
102
+ var LocalValidator = class {
103
+ config;
104
+ /**
105
+ * @param config - Optional override for {@link ValidatorConfig}.
106
+ * Defaults to using {@link forbiddenDeterministicFields}.
107
+ */
108
+ constructor(config = {}) {
109
+ this.config = {
110
+ forbiddenDeterministicFields,
111
+ ...config
112
+ };
113
+ }
114
+ extractDeterministicPayload(envelope) {
115
+ return envelope.payload;
116
+ }
117
+ /** Returns `true` when `envelope` has `payload` (any value) and `signature` (string). */
118
+ validateStructure(envelope) {
119
+ return typeof envelope === "object" && envelope !== null && "payload" in envelope && "signature" in envelope && typeof envelope.signature === "string";
120
+ }
121
+ /** Returns `true` when `payload` can be serialized through the canonical JSON pipeline without error. */
122
+ validateCanonical(payload) {
123
+ try {
124
+ canonicalize(payload);
125
+ return true;
126
+ } catch {
127
+ return false;
128
+ }
129
+ }
130
+ /**
131
+ * Returns `true` when the canonical form of the payload alone equals the
132
+ * canonical form of `{ payload }`, confirming that no metadata fields have
133
+ * leaked into the deterministic signing scope.
134
+ */
135
+ validateMetadataIsolation(envelope) {
136
+ try {
137
+ const canonicalPayload = canonicalize(
138
+ this.extractDeterministicPayload(
139
+ envelope
140
+ )
141
+ );
142
+ const canonicalEnvelope = canonicalize({
143
+ payload: this.extractDeterministicPayload(
144
+ envelope
145
+ )
146
+ });
147
+ return canonicalPayload === canonicalEnvelope;
148
+ } catch {
149
+ return false;
150
+ }
151
+ }
152
+ /**
153
+ * Runs all five validation stages against `envelope` and returns a
154
+ * {@link ValidationResult} with per-stage flags and accumulated error messages.
155
+ */
156
+ validate(envelope) {
157
+ const structure = this.validateStructure(
158
+ envelope
159
+ );
160
+ const canonical = structure && this.validateCanonical(
161
+ envelope.payload
162
+ );
163
+ const deterministic = structure && assertNoOperationalMetadata(
164
+ envelope.payload,
165
+ this.config.forbiddenDeterministicFields ?? []
166
+ );
167
+ const metadataIsolation = structure && this.validateMetadataIsolation(
168
+ envelope
169
+ );
170
+ const cryptographic = false;
171
+ const errors = [];
172
+ if (!structure) {
173
+ errors.push(
174
+ "Invalid structure."
175
+ );
176
+ }
177
+ if (!canonical) {
178
+ errors.push(
179
+ "Canonicalization validation failed."
180
+ );
181
+ }
182
+ if (!deterministic) {
183
+ errors.push(
184
+ "Operational metadata contamination detected."
185
+ );
186
+ }
187
+ if (!metadataIsolation) {
188
+ errors.push(
189
+ "Metadata isolation validation failed."
190
+ );
191
+ }
192
+ return {
193
+ valid: structure && canonical && deterministic && metadataIsolation && cryptographic,
194
+ verified: cryptographic,
195
+ stages: {
196
+ structure,
197
+ canonical,
198
+ deterministic,
199
+ metadataIsolation,
200
+ cryptographic
201
+ },
202
+ errors
203
+ };
204
+ }
205
+ };
206
+ export {
207
+ INVARIANT_REGISTRY,
208
+ InvariantViolation,
209
+ LocalSigner,
210
+ LocalValidator,
211
+ LocalVerifier,
212
+ MemoryReplayStore,
213
+ assertArray,
214
+ assertNoOperationalMetadata,
215
+ assertNonEmptyString,
216
+ canonicalize,
217
+ createPolicy,
218
+ executeDecision,
219
+ executeFromSignals,
220
+ forbiddenDeterministicFields,
221
+ generateBundle,
222
+ getRuntimeManifest,
223
+ hashInput,
224
+ issueToken,
225
+ signRuntimeManifest,
226
+ upgradePolicy,
227
+ validatePolicy,
228
+ verifyAttestation,
229
+ verifyBundle,
230
+ verifyExecutionRequirements,
231
+ verifyExecutionToken,
232
+ verifyRuntime,
233
+ verifyRuntimeCompatibility,
234
+ verifyRuntimeManifest,
235
+ violate
236
+ };
237
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/canonicalize.ts","../src/invariants.ts","../src/deterministic-policy.ts","../src/validator.ts"],"sourcesContent":["// -----------------------------\n// Governance Lifecycle\n// -----------------------------\nexport {\n createPolicy,\n upgradePolicy,\n validatePolicy,\n generateBundle\n} from \"@parmanasystems/governance\";\n\n// -----------------------------\n// Deterministic Execution\n// -----------------------------\nexport {\n executeFromSignals,\n executeDecision,\n issueToken,\n verifyExecutionToken,\n getRuntimeManifest,\n signRuntimeManifest,\n verifyRuntimeManifest,\n LocalSigner,\n LocalVerifier,\n MemoryReplayStore\n} from \"@parmanasystems/execution\";\n\n// -----------------------------\n// Portable Verification\n// -----------------------------\nexport {\n verifyAttestation,\n verifyBundle,\n verifyRuntime,\n verifyRuntimeCompatibility,\n verifyExecutionRequirements\n} from \"@parmanasystems/verifier\";\n\n// -----------------------------\n// Canonical Governance Types\n// -----------------------------\nexport type {\n ExecutionContext,\n ExecutionAttestation,\n ExecutionToken,\n RuntimeManifest,\n Signer,\n Verifier,\n ReplayStore,\n DecisionResult\n} from \"@parmanasystems/execution\";\n\nexport type {\n RuntimeRequirements,\n} from \"@parmanasystems/governance\";\n\n// -----------------------------\n// Invariant Registry\n// -----------------------------\nexport type {\n InvariantBoundary,\n InvariantEntry,\n InvariantId,\n ViolationReport,\n} from \"@parmanasystems/execution\";\n\nexport {\n INVARIANT_REGISTRY,\n InvariantViolation,\n violate,\n hashInput,\n} from \"@parmanasystems/execution\";\n\n// -----------------------------\n// Deterministic Validation\n// -----------------------------\nexport * from \"./canonicalize\";\nexport * from \"./validator\";\nexport * from \"./invariants\";\n\n// -----------------------------\n// Validation Types\n// -----------------------------\nexport * from \"./types/envelope\";\nexport * from \"./types/payloads\";\nexport * from \"./types/validation\";\nexport * from \"./types/metadata\";\nexport * from \"./deterministic-policy\";\nexport * from \"./types/validator-config\";","function sortKeys(value: any): any {\n if (Array.isArray(value)) {\n return value.map(sortKeys);\n }\n\n if (value && typeof value === \"object\") {\n return Object.keys(value)\n .sort()\n .reduce((acc, key) => {\n acc[key] = sortKeys(value[key]);\n return acc;\n }, {} as Record<string, unknown>);\n }\n\n return value;\n}\n\n/**\n * Serializes `value` to a stable, compact JSON string with object keys sorted\n * recursively. Used by the core validation pipeline for determinism checks.\n *\n * Note: unlike `@parmanasystems/bundle`'s `canonicalize`, this variant uses\n * compact output (`JSON.stringify` without indentation) for in-memory comparisons.\n */\nexport function canonicalize(value: unknown): string {\n return JSON.stringify(sortKeys(value));\n}","/** Returns `true` when `value` is a non-empty, non-whitespace-only string. */\nexport function assertNonEmptyString(\n value: unknown\n): boolean {\n return (\n typeof value === \"string\" &&\n value.trim().length > 0\n );\n}\n\n/** Returns `true` when `value` is an array. */\nexport function assertArray(\n value: unknown\n): boolean {\n return Array.isArray(value);\n}\n\nfunction scanObject(\n value: unknown,\n forbiddenFields:\n readonly string[]\n): boolean {\n\n if (\n typeof value !== \"object\" ||\n value === null\n ) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return value.every(\n (item) =>\n scanObject(\n item,\n forbiddenFields\n )\n );\n }\n\n for (\n const [key, nested]\n of Object.entries(value)\n ) {\n\n if (\n forbiddenFields.includes(\n key\n )\n ) {\n return false;\n }\n\n if (\n !scanObject(\n nested,\n forbiddenFields\n )\n ) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Recursively scans `payload` and returns `false` if any object key matches\n * a name in `forbiddenFields`.\n *\n * Used by {@link LocalValidator} to enforce that operational-metadata fields\n * have not contaminated the deterministic signing scope.\n *\n * @param payload - The payload object to inspect.\n * @param forbiddenFields - Field names that must not appear anywhere in the payload.\n */\nexport function assertNoOperationalMetadata(\n payload: unknown,\n forbiddenFields:\n readonly string[]\n): boolean {\n\n return scanObject(\n payload,\n forbiddenFields\n );\n}","/**\n * Field names that must not appear inside a deterministic payload.\n *\n * These are operational-metadata fields that introduce non-determinism\n * (timestamps, hostnames, trace IDs, deployment context) and would break\n * reproducible verification if present in the signed payload scope.\n *\n * Used as the default for {@link ValidatorConfig.forbiddenDeterministicFields}.\n */\nexport const forbiddenDeterministicFields = [\n \"generatedAt\",\n \"environment\",\n \"host\",\n \"runtime\",\n \"traceId\"\n] as const;","import { canonicalize } from \"./canonicalize\";\n\nimport {\n assertNoOperationalMetadata\n} from \"./invariants\";\n\nimport {\n forbiddenDeterministicFields\n} from \"./deterministic-policy\";\n\nimport {\n ValidatorConfig\n} from \"./types/validator-config\";\n\nimport { ValidationResult } from \"./types/validation\";\n\nimport { SignedEnvelope } from \"./types/envelope\";\n\n/**\n * Multi-stage validator for {@link SignedEnvelope} values.\n *\n * Runs up to five sequential checks (structure → canonical → deterministic →\n * metadata isolation → cryptographic) and returns a detailed\n * {@link ValidationResult} with per-stage flags and error messages.\n *\n * **Note:** the `cryptographic` stage is not yet implemented and always returns\n * `false`, so `valid` is always `false`. Use `@parmanasystems/verifier` for\n * cryptographic attestation verification.\n */\nexport class LocalValidator {\n\n private readonly config:\n ValidatorConfig;\n\n /**\n * @param config - Optional override for {@link ValidatorConfig}.\n * Defaults to using {@link forbiddenDeterministicFields}.\n */\n constructor(\n config: ValidatorConfig = {}\n ) {\n this.config = {\n forbiddenDeterministicFields,\n ...config\n };\n }\n\n private extractDeterministicPayload(\n envelope: SignedEnvelope<unknown>\n ): unknown {\n return envelope.payload;\n }\n\n /** Returns `true` when `envelope` has `payload` (any value) and `signature` (string). */\n validateStructure(\n envelope: SignedEnvelope<unknown>\n ): boolean {\n\n return (\n typeof envelope === \"object\" &&\n envelope !== null &&\n \"payload\" in envelope &&\n \"signature\" in envelope &&\n typeof envelope.signature === \"string\"\n );\n }\n\n /** Returns `true` when `payload` can be serialized through the canonical JSON pipeline without error. */\n validateCanonical(\n payload: unknown\n ): boolean {\n\n try {\n\n canonicalize(payload);\n\n return true;\n\n } catch {\n\n return false;\n }\n }\n\n /**\n * Returns `true` when the canonical form of the payload alone equals the\n * canonical form of `{ payload }`, confirming that no metadata fields have\n * leaked into the deterministic signing scope.\n */\n validateMetadataIsolation(\n envelope: SignedEnvelope<unknown>\n ): boolean {\n\n try {\n\n const canonicalPayload =\n canonicalize(\n this.extractDeterministicPayload(\n envelope\n )\n );\n\n const canonicalEnvelope =\n canonicalize({\n payload:\n this.extractDeterministicPayload(\n envelope\n )\n });\n\n return (\n canonicalPayload ===\n canonicalEnvelope\n );\n\n } catch {\n\n return false;\n }\n }\n\n /**\n * Runs all five validation stages against `envelope` and returns a\n * {@link ValidationResult} with per-stage flags and accumulated error messages.\n */\n validate(\n envelope: SignedEnvelope<unknown>\n ): ValidationResult {\n\n const structure =\n this.validateStructure(\n envelope\n );\n\n const canonical =\n structure &&\n this.validateCanonical(\n envelope.payload\n );\n\n const deterministic =\n structure &&\n assertNoOperationalMetadata(\n envelope.payload,\n this.config\n .forbiddenDeterministicFields ??\n []\n );\n\n const metadataIsolation =\n structure &&\n this.validateMetadataIsolation(\n envelope\n );\n\n const cryptographic =\n false;\n\n const errors: string[] =\n [];\n\n if (!structure) {\n errors.push(\n \"Invalid structure.\"\n );\n }\n\n if (!canonical) {\n errors.push(\n \"Canonicalization validation failed.\"\n );\n }\n\n if (!deterministic) {\n errors.push(\n \"Operational metadata contamination detected.\"\n );\n }\n\n if (!metadataIsolation) {\n errors.push(\n \"Metadata isolation validation failed.\"\n );\n }\n\n return {\n valid:\n structure &&\n canonical &&\n deterministic &&\n metadataIsolation &&\n cryptographic,\n\n verified:\n cryptographic,\n\n stages: {\n structure,\n canonical,\n deterministic,\n metadataIsolation,\n cryptographic\n },\n\n errors\n };\n }\n}"],"mappings":"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","names":[]}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@parmanasystems/core",
3
+ "version": "1.0.19",
4
+ "private": false,
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsup"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "sideEffects": false,
20
+ "dependencies": {
21
+ "@parmanasystems/bundle": "^1.0.19",
22
+ "@parmanasystems/crypto": "^1.0.19",
23
+ "@parmanasystems/execution": "^1.0.19",
24
+ "@parmanasystems/governance": "^1.0.19",
25
+ "@parmanasystems/verifier": "^1.0.19"
26
+ },
27
+ "description": "Public orchestration and SDK surface for parmanasystems deterministic governance infrastructure.",
28
+ "license": "Apache-2.0",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/pavancharak/parmanasystems-core.git"
32
+ },
33
+ "homepage": "https://github.com/pavancharak/parmanasystems-core",
34
+ "bugs": {
35
+ "url": "https://github.com/pavancharak/parmanasystems-core/issues"
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "keywords": [
41
+ "sdk",
42
+ "governance",
43
+ "orchestration",
44
+ "deterministic",
45
+ "runtime",
46
+ "verification"
47
+ ],
48
+ "main": "./dist/index.js",
49
+ "types": "./dist/index.d.ts"
50
+ }