@parmanasystems/core 1.71.12 → 1.71.18

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 CHANGED
@@ -20,6 +20,82 @@ npm install @parmanasystems/core
20
20
 
21
21
  ---
22
22
 
23
+ ## ESM / CJS note
24
+
25
+ `@parmanasystems/core` bundles CJS dependencies. Do **not** set `"type": "module"` in `package.json` — it will break bundled transitive imports. Wrap all SDK calls in an `async` function instead of using top-level `await`:
26
+
27
+ ```typescript
28
+ // ✅ Correct
29
+ async function main() {
30
+ const result = await executeFromSignals(...);
31
+ }
32
+ main().catch(console.error);
33
+
34
+ // ❌ Incorrect — top-level await fails in CJS mode
35
+ const result = await executeFromSignals(...);
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Policy files
41
+
42
+ `executeFromSignals` reads policy rules from disk at:
43
+
44
+ ```
45
+ ./policies/{policyId}/{policyVersion}/policy.json
46
+ ```
47
+
48
+ Create this directory structure **before** calling `executeFromSignals`. Example for `policyId: "trade-risk-approval"`, `policyVersion: "1.0.0"`:
49
+
50
+ ```
51
+ policies/
52
+ trade-risk-approval/
53
+ 1.0.0/
54
+ policy.json
55
+ ```
56
+
57
+ Minimal `policy.json` with all required fields:
58
+
59
+ ```json
60
+ {
61
+ "policyId": "trade-risk-approval",
62
+ "policyVersion": "1.0.0",
63
+ "schemaVersion": "1.0.0",
64
+ "signalsSchema": {
65
+ "amount_usd": { "type": "integer" },
66
+ "risk_score": { "type": "integer" },
67
+ "counterparty": { "type": "string" }
68
+ },
69
+ "rules": [
70
+ {
71
+ "id": "low-risk-approve",
72
+ "condition": {
73
+ "all": [
74
+ { "signal": "risk_score", "less_than": 30 },
75
+ { "signal": "amount_usd", "less_than": 500000 }
76
+ ]
77
+ },
78
+ "outcome": { "action": "approve", "requires_override": false, "reason": "low_risk_trade" }
79
+ },
80
+ {
81
+ "id": "catch-all-reject",
82
+ "condition": { "all": [] },
83
+ "outcome": { "action": "reject", "requires_override": true, "reason": "requires_review" }
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ | Field | Required | Description |
90
+ |---|---|---|
91
+ | `policyId` | ✅ | Must match the directory name under `policies/` |
92
+ | `policyVersion` | ✅ | Must match the subdirectory name (e.g. `"1.0.0"`) |
93
+ | `schemaVersion` | ✅ | Always `"1.0.0"` for the current schema |
94
+ | `signalsSchema` | ✅ | Map of signal names to `{ "type": "integer" \| "boolean" \| "string" }` |
95
+ | `rules` | ✅ | Ordered list — evaluated top-to-bottom, first match wins |
96
+
97
+ ---
98
+
23
99
  ## Usage
24
100
 
25
101
  ```typescript
@@ -33,38 +109,42 @@ import {
33
109
  getRuntimeManifest,
34
110
  } from "@parmanasystems/core";
35
111
 
36
- const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519", {
37
- privateKeyEncoding: { type: "pkcs8", format: "pem" },
38
- publicKeyEncoding: { type: "spki", format: "pem" },
39
- });
40
-
41
- const signer = new LocalSigner(privateKey);
42
- const verifier = new LocalVerifier(publicKey);
43
- const replayStore = new MemoryReplayStore();
44
-
45
- const attestation = await executeFromSignals(
46
- {
47
- policyId: "trade-risk-approval",
48
- policyVersion: "1.0.0",
49
- signals: {
50
- amount_usd: 450_000,
51
- risk_score: 18,
52
- counterparty: "acme-corp",
112
+ async function main() {
113
+ const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519", {
114
+ privateKeyEncoding: { type: "pkcs8", format: "pem" },
115
+ publicKeyEncoding: { type: "spki", format: "pem" },
116
+ });
117
+
118
+ const signer = new LocalSigner(privateKey);
119
+ const verifier = new LocalVerifier(publicKey);
120
+ const replayStore = new MemoryReplayStore();
121
+
122
+ const attestation = await executeFromSignals(
123
+ {
124
+ policyId: "trade-risk-approval",
125
+ policyVersion: "1.0.0",
126
+ signals: {
127
+ amount_usd: 450_000,
128
+ risk_score: 18,
129
+ counterparty: "acme-corp",
130
+ },
53
131
  },
54
- },
55
- signer,
56
- verifier,
57
- replayStore
58
- );
59
-
60
- console.log(attestation.execution_state); // "completed"
61
- console.log(attestation.decision.action); // "approve"
62
- console.log(attestation.signature); // Ed25519 over canonical attestation JSON
63
-
64
- // Independently verify — no runtime state required beyond the manifest
65
- const manifest = getRuntimeManifest();
66
- const result = verifyAttestation(attestation, verifier, manifest);
67
- console.log(result.valid); // true
132
+ signer,
133
+ verifier,
134
+ replayStore
135
+ );
136
+
137
+ console.log(attestation.execution_state); // "completed"
138
+ console.log(attestation.decision.action); // "approve"
139
+ console.log(attestation.signature); // Ed25519 over canonical attestation JSON
140
+
141
+ // Independently verify — no runtime state required beyond the manifest
142
+ const manifest = getRuntimeManifest();
143
+ const result = verifyAttestation(attestation, verifier, manifest);
144
+ console.log(result.valid); // true
145
+ }
146
+
147
+ main().catch(console.error);
68
148
  ```
69
149
 
70
150
  ---
package/dist/index.js CHANGED
@@ -10499,7 +10499,8 @@ import {
10499
10499
  evaluatePolicy,
10500
10500
  loadPolicy,
10501
10501
  canonicalizeForSigning,
10502
- validateSignalsStrict
10502
+ validateSignalsStrict,
10503
+ violate
10503
10504
  } from "@parmanasystems/execution";
10504
10505
  import crypto from "crypto";
10505
10506
  import {
@@ -10535,6 +10536,17 @@ async function executeFromSignals(input, signer, verifier, replayStore) {
10535
10536
  signals: input.signals
10536
10537
  })
10537
10538
  ).digest("hex");
10539
+ const hasRun = await replayStore.hasExecuted(
10540
+ execution_fingerprint
10541
+ );
10542
+ if (hasRun) {
10543
+ violate(
10544
+ "INV-013",
10545
+ "replay",
10546
+ `[INV-013@replay] Replay detected: execution_fingerprint ${execution_fingerprint} has already been consumed`,
10547
+ execution_fingerprint
10548
+ );
10549
+ }
10538
10550
  await replayStore.markExecuted(
10539
10551
  execution_fingerprint
10540
10552
  );
@@ -10640,7 +10652,7 @@ import {
10640
10652
  import {
10641
10653
  INVARIANT_REGISTRY,
10642
10654
  InvariantViolation,
10643
- violate,
10655
+ violate as violate2,
10644
10656
  hashInput
10645
10657
  } from "@parmanasystems/execution";
10646
10658
 
@@ -10877,6 +10889,6 @@ export {
10877
10889
  verifyRuntime,
10878
10890
  verifyRuntimeCompatibility,
10879
10891
  verifyRuntimeManifest,
10880
- violate
10892
+ violate2 as violate
10881
10893
  };
10882
10894
  //# sourceMappingURL=index.js.map