@actuarial-ts/compliance 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,216 @@
1
+ import { CORE_PACKAGE_VERSION, canonicalJson, fnv1a64, getMetricDiagnosticsResultIdentity, getPreparedDiagnosticDataIdentity, runMetricDiagnostics, verifyPreparedDiagnosticDataIntegrity, } from "@actuarial-ts/core";
2
+ import { DATA_PACKAGE_VERSION, assertCompletedValidatedMetricDiagnosticsRun, reviewPreparedDiagnosticData, } from "@actuarial-ts/data";
3
+ import { ComplianceError } from "./errors.js";
4
+ import { COMPLIANCE_PACKAGE_VERSION } from "./version.js";
5
+ const verified = new WeakMap();
6
+ const token = (value, path) => {
7
+ if (value.length === 0 || /^[\t-\r ]|[\t-\r ]$/.test(value) || value.includes("\0"))
8
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `${path} must be a nonempty token`, path);
9
+ for (let index = 0; index < value.length; index++) {
10
+ const unit = value.charCodeAt(index);
11
+ if (unit >= 0xd800 && unit <= 0xdbff) {
12
+ const next = value.charCodeAt(index + 1);
13
+ if (!(next >= 0xdc00 && next <= 0xdfff))
14
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `${path} contains malformed Unicode`, path);
15
+ index++;
16
+ }
17
+ else if (unit >= 0xdc00 && unit <= 0xdfff)
18
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `${path} contains malformed Unicode`, path);
19
+ }
20
+ };
21
+ function freeze(value, seen = new WeakSet()) { if (value === null || typeof value !== "object" || seen.has(value))
22
+ return value; seen.add(value); for (const child of Object.values(value))
23
+ freeze(child, seen); return Object.freeze(value); }
24
+ function tag(kind, key, value) { return `fnv1a64-jcs-v1:${fnv1a64(canonicalJson({ identityVersion: 1, kind, [key]: value }))}`; }
25
+ function snapshotArtifacts(evidence) {
26
+ const seen = new Set();
27
+ const result = [];
28
+ for (const [index, item] of evidence.entries()) {
29
+ token(item.id, `$.artifacts[${index}].id`);
30
+ token(item.scope, `$.artifacts[${index}].scope`);
31
+ if (seen.has(item.id))
32
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Duplicate artifact ID ${item.id}`, `$.artifacts[${index}].id`);
33
+ seen.add(item.id);
34
+ if (item.assurance === "sdk-computed") {
35
+ if (!(item.bytes instanceof Uint8Array))
36
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "SDK-computed artifact evidence requires actual Uint8Array bytes", `$.artifacts[${index}].bytes`);
37
+ const bytes = new Uint8Array(item.bytes.byteLength);
38
+ bytes.set(item.bytes);
39
+ result.push({ id: item.id, scope: item.scope, assurance: item.assurance, bytes });
40
+ }
41
+ else {
42
+ token(item.algorithm, `$.artifacts[${index}].algorithm`);
43
+ token(item.value, `$.artifacts[${index}].value`);
44
+ if (!Number.isSafeInteger(item.byteLength) || item.byteLength < 0)
45
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Artifact byteLength must be a nonnegative safe integer", `$.artifacts[${index}].byteLength`);
46
+ result.push({ ...item });
47
+ }
48
+ }
49
+ return result.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
50
+ }
51
+ async function digestArtifacts(snapshot) {
52
+ if (snapshot.some((item) => "bytes" in item) && globalThis.crypto?.subtle === undefined)
53
+ throw new ComplianceError("CRYPTO_UNAVAILABLE", "Web Crypto SHA-256 is unavailable", "$.artifacts");
54
+ return Promise.all(snapshot.map(async (item) => { if (!("bytes" in item))
55
+ return item; const hash = await globalThis.crypto.subtle.digest("SHA-256", item.bytes); return { id: item.id, scope: item.scope, assurance: item.assurance, algorithm: "sha-256", value: [...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, "0")).join(""), byteLength: item.bytes.byteLength }; }));
56
+ }
57
+ function snapshotLineage(lineage) {
58
+ return lineage.map((item, index) => { token(item.artifactId, `$.lineage[${index}].artifactId`); if (!Array.isArray(item.inputArtifactIds))
59
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Lineage inputs must be an array", `$.lineage[${index}].inputArtifactIds`); const inputs = item.inputArtifactIds.map((id, inputIndex) => { token(id, `$.lineage[${index}].inputArtifactIds[${inputIndex}]`); return id; }); if (new Set(inputs).size !== inputs.length)
60
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Lineage inputs must be unique", `$.lineage[${index}].inputArtifactIds`); return { artifactId: item.artifactId, inputArtifactIds: [...inputs].sort() }; }).sort((a, b) => a.artifactId < b.artifactId ? -1 : a.artifactId > b.artifactId ? 1 : 0);
61
+ }
62
+ function validateArtifactGraph(run, artifacts, lineage) {
63
+ const byId = new Map(artifacts.map((item) => [item.id, item]));
64
+ const referenced = new Set();
65
+ const requireArtifact = (id, scope, path) => { const artifact = byId.get(id); if (!artifact)
66
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Artifact reference ${id} is unresolved`, path); if (artifact.scope !== scope)
67
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Artifact ${id} must have ${scope} scope`, path); referenced.add(id); };
68
+ let unsourced = false;
69
+ for (const [index, item] of run.prepared.inputAudit.entries()) {
70
+ const source = item.record.source;
71
+ if (source)
72
+ requireArtifact(source.artifactId, "input", `$.completedRun.prepared.inputAudit[${index}].record.source.artifactId`);
73
+ else
74
+ unsourced = true;
75
+ }
76
+ const evidence = run.review.evidence;
77
+ if (evidence) {
78
+ for (const [index, item] of evidence.groupingAssignments.entries()) {
79
+ if (item.source)
80
+ requireArtifact(item.source.artifactId, "input", `$.completedRun.review.evidence.groupingAssignments[${index}].source.artifactId`);
81
+ else
82
+ unsourced = true;
83
+ }
84
+ for (const [index, item] of evidence.cachedFormulas.entries()) {
85
+ if (item.source)
86
+ requireArtifact(item.source.artifactId, "input", `$.completedRun.review.evidence.cachedFormulas[${index}].source.artifactId`);
87
+ else
88
+ unsourced = true;
89
+ }
90
+ }
91
+ if (unsourced) {
92
+ if (run.datasetArtifactId === null)
93
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Unsourced diagnostic input requires datasetArtifactId", "$.completedRun.datasetArtifactId");
94
+ const fallback = byId.get(run.datasetArtifactId);
95
+ if (!fallback || fallback.scope !== "input" || fallback.assurance !== "sdk-computed")
96
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "datasetArtifactId must resolve to SDK-computed input evidence", "$.completedRun.datasetArtifactId");
97
+ referenced.add(run.datasetArtifactId);
98
+ }
99
+ else if (run.datasetArtifactId !== null)
100
+ requireArtifact(run.datasetArtifactId, "input", "$.completedRun.datasetArtifactId");
101
+ for (const [basisIndex, basis] of run.prepared.definition.definition.amountBases.entries())
102
+ for (const [componentIndex, component] of basis.components.entries())
103
+ if (component.limitation.kind !== "unlimited" && component.limitation.kind !== "unknown" && component.limitation.derivation.kind === "external")
104
+ requireArtifact(component.limitation.derivation.transformationRef, "preparation", `$.definition.amountBases[${basisIndex}].components[${componentIndex}].limitation.derivation.transformationRef`);
105
+ for (const [ruleIndex, rule] of run.prepared.definition.definition.reviewRules.entries())
106
+ if (rule.kind === "layer-order" && rule.comparability.kind === "caller-asserted")
107
+ requireArtifact(rule.comparability.rationaleArtifactId, "preparation", `$.definition.reviewRules[${ruleIndex}].comparability.rationaleArtifactId`);
108
+ if (run.gate.rationaleRef !== null)
109
+ requireArtifact(run.gate.rationaleRef, "preparation", "$.completedRun.gate.rationaleRef");
110
+ const edges = new Map();
111
+ for (const [index, edge] of lineage.entries()) {
112
+ if (edges.has(edge.artifactId))
113
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "An artifact may have only one producing lineage edge", `$.lineage[${index}].artifactId`);
114
+ const downstream = byId.get(edge.artifactId);
115
+ if (!downstream)
116
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Lineage artifact ${edge.artifactId} is unresolved`, `$.lineage[${index}].artifactId`);
117
+ if (downstream.scope !== "input")
118
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Lineage downstream artifact must have input scope", `$.lineage[${index}].artifactId`);
119
+ for (const [inputIndex, id] of edge.inputArtifactIds.entries()) {
120
+ if (id === edge.artifactId)
121
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Lineage may not reference itself", `$.lineage[${index}].inputArtifactIds[${inputIndex}]`);
122
+ if (!byId.has(id))
123
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Lineage reference ${id} is unresolved`, `$.lineage[${index}].inputArtifactIds[${inputIndex}]`);
124
+ }
125
+ edges.set(edge.artifactId, edge.inputArtifactIds);
126
+ }
127
+ const visiting = new Set(), visited = new Set();
128
+ const walk = (id, path) => { if (visiting.has(id))
129
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Artifact lineage contains a cycle", path); if (visited.has(id))
130
+ return; visiting.add(id); for (const upstream of edges.get(id) ?? []) {
131
+ referenced.add(upstream);
132
+ walk(upstream, path);
133
+ } visiting.delete(id); visited.add(id); };
134
+ for (const id of [...referenced])
135
+ walk(id, "$.lineage");
136
+ for (const [index, artifact] of artifacts.entries())
137
+ if (!referenced.has(artifact.id))
138
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", `Artifact ${artifact.id} is orphaned`, `$.artifacts[${index}].id`);
139
+ }
140
+ function rerunAndVerify(run) {
141
+ assertCompletedValidatedMetricDiagnosticsRun(run);
142
+ verifyPreparedDiagnosticDataIntegrity(run.prepared);
143
+ const review = reviewPreparedDiagnosticData({ prepared: run.prepared, evidence: run.review.evidence });
144
+ if (review.reportFingerprint !== run.review.reportFingerprint || canonicalJson(review.identityBody) !== canonicalJson(run.review.identityBody))
145
+ throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Stored diagnostic review does not match a regenerated review", "$.review");
146
+ const rerun = runMetricDiagnostics({ prepared: run.prepared, groupMap: run.groupMap, groupDimensions: run.groupDimensions });
147
+ if (canonicalJson(getMetricDiagnosticsResultIdentity(rerun)) !== canonicalJson(getMetricDiagnosticsResultIdentity(run.result)))
148
+ throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Stored diagnostic result does not match deterministic replay", "$.result");
149
+ const reviewBlocked = review.report.checks.some((check) => !run.gate.allowedReviewStatuses.includes(check.status));
150
+ const metricBlocked = rerun.findings.some((finding) => finding.category !== "structural" && !run.gate.allowedMetricFindingSeverities.includes(finding.severity));
151
+ if (reviewBlocked || metricBlocked || run.gate.reviewGate !== "passed" || run.gate.metricGate !== "passed")
152
+ throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Diagnostic execution gates do not recompute as passed", "$.gate");
153
+ return { review, result: getMetricDiagnosticsResultIdentity(run.result) };
154
+ }
155
+ export async function createDiagnosticRunIdentity(input) {
156
+ const run = input.completedRun;
157
+ const authenticated = rerunAndVerify(run);
158
+ const artifactSnapshot = snapshotArtifacts(input.artifacts ?? []);
159
+ const lineage = snapshotLineage(input.lineage ?? []);
160
+ const artifacts = await digestArtifacts(artifactSnapshot);
161
+ validateArtifactGraph(run, artifacts, lineage);
162
+ const preparation = getPreparedDiagnosticDataIdentity(run.prepared);
163
+ const expectedGridFingerprint = preparation.expectedCellsProvided ? tag("diagnostic-expected-grid", "expectedCells", preparation.expectedCells) : null;
164
+ const manifest = freeze({ definitionIntegrity: run.prepared.definition.definitionIntegrity, runPresetId: run.runPresetId, datasetArtifactId: run.datasetArtifactId, packageVersions: { "@actuarial-ts/core": CORE_PACKAGE_VERSION, "@actuarial-ts/data": DATA_PACKAGE_VERSION, "@actuarial-ts/compliance": COMPLIANCE_PACKAGE_VERSION }, preparation, preparationFingerprint: run.prepared.preparationFingerprint, expectedGridFingerprint, executionPolicy: { review: { body: authenticated.review.identityBody, reportFingerprint: authenticated.review.reportFingerprint }, gate: run.gate }, groupMap: { ...run.groupMap }, groupDimensions: { ...run.groupDimensions }, artifacts, lineage });
165
+ const runFingerprint = tag("diagnostic-run", "run", manifest);
166
+ const resultFingerprint = tag("diagnostic-result", "result", authenticated.result);
167
+ const runResultFingerprint = tag("diagnostic-run-result", "binding", { runFingerprint, resultFingerprint });
168
+ const definition = run.prepared.definition;
169
+ const provenance = freeze({ definition: definition.definition, definitionIdentities: { algorithm: "fnv1a64-jcs-v1", formulaById: { ...definition.formulaFingerprints }, calculationByInstanceId: { ...definition.calculationFingerprints }, definition: definition.definitionIntegrity }, manifest, review: authenticated.review, result: run.result, runFingerprint, resultFingerprint, runResultFingerprint });
170
+ verified.set(provenance, run);
171
+ return provenance;
172
+ }
173
+ export function assertVerifiedDiagnosticRunProvenance(value) { if (value === null || typeof value !== "object" || !verified.has(value))
174
+ throw new ComplianceError("BAD_DIAGNOSTIC_RUN", "Value is not authentic verified diagnostic provenance", "$"); }
175
+ /** @internal Bundle authoring uses owner state rather than trusting the public snapshot. */
176
+ export function verifiedDefinitionForBundle(value) { assertVerifiedDiagnosticRunProvenance(value); return verified.get(value).prepared.definition; }
177
+ export async function verifyDiagnosticRunIdentity(candidate, input) {
178
+ const regenerated = await createDiagnosticRunIdentity(input);
179
+ let left;
180
+ try {
181
+ left = canonicalJson(candidate);
182
+ }
183
+ catch {
184
+ throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Stored diagnostic provenance is not canonical JSON", "$");
185
+ }
186
+ if (left !== canonicalJson(regenerated))
187
+ throw new ComplianceError("DIAGNOSTIC_MISMATCH", "Stored diagnostic provenance differs from regenerated provenance", firstDifference(candidate, regenerated, "$") ?? "$");
188
+ return regenerated;
189
+ }
190
+ function plain(value) { if (value === null || typeof value !== "object" || Array.isArray(value))
191
+ return false; const prototype = Object.getPrototypeOf(value); return prototype === Object.prototype || prototype === null; }
192
+ function firstDifference(left, right, path) { if (plain(left) && plain(right)) {
193
+ const keys = [...new Set([...Object.keys(left), ...Object.keys(right)])].sort();
194
+ for (const key of keys) {
195
+ if (!(key in left) || !(key in right))
196
+ return `${path}.${key}`;
197
+ const found = firstDifference(left[key], right[key], `${path}.${key}`);
198
+ if (found)
199
+ return found;
200
+ }
201
+ return null;
202
+ } if (Array.isArray(left) && Array.isArray(right)) {
203
+ const shared = Math.min(left.length, right.length);
204
+ for (let index = 0; index < shared; index++) {
205
+ const found = firstDifference(left[index], right[index], `${path}[${index}]`);
206
+ if (found)
207
+ return found;
208
+ }
209
+ return left.length === right.length ? null : `${path}[${shared}]`;
210
+ } try {
211
+ return canonicalJson(left) === canonicalJson(right) ? null : path;
212
+ }
213
+ catch {
214
+ return path;
215
+ } }
216
+ //# sourceMappingURL=diagnosticRun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnosticRun.js","sourceRoot":"","sources":["../src/diagnosticRun.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,OAAO,EACP,kCAAkC,EAClC,iCAAiC,EACjC,oBAAoB,EACpB,qCAAqC,GAOtC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,4CAA4C,EAC5C,4BAA4B,GAI7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAyC1D,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAkD,CAAC;AAC/E,MAAM,KAAK,GAAG,CAAC,KAAY,EAAC,IAAW,EAAE,EAAE;IACzC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,eAAe,CAAC,oBAAoB,EAAE,GAAG,IAAI,2BAA2B,EAAE,IAAI,CAAC,CAAC;IAC/K,KAAI,IAAI,KAAK,GAAC,CAAC,EAAC,KAAK,GAAC,KAAK,CAAC,MAAM,EAAC,KAAK,EAAE,EAAC,CAAC;QAAA,MAAM,IAAI,GAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAAA,IAAG,IAAI,IAAE,MAAM,IAAE,IAAI,IAAE,MAAM,EAAC,CAAC;YAAA,MAAM,IAAI,GAAC,KAAK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CAAA,CAAC,CAAA,IAAI,CAAA,CAAC,CAAA,IAAI,CAAA;AAAA,CAAC;AAAA,MAAK,CAAC;IAAA,OAAO,IAAI,CAAA;AAAA,CAAC,CAAA,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const COMPLIANCE_ERROR_CODES: readonly ["BAD_BUNDLE", "BAD_CDF", "MISSING_RATIONALE", "BAD_DIAGNOSTIC_RUN", "DIAGNOSTIC_MISMATCH", "CRYPTO_UNAVAILABLE"];
2
+ export type ComplianceErrorCode = (typeof COMPLIANCE_ERROR_CODES)[number];
3
+ export declare class ComplianceError extends Error {
4
+ readonly code: ComplianceErrorCode;
5
+ readonly path?: string;
6
+ constructor(code: ComplianceErrorCode, message: string, path?: string);
7
+ }
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,4HAGzB,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1E,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBACX,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAGtE"}
package/dist/errors.js ADDED
@@ -0,0 +1,16 @@
1
+ export const COMPLIANCE_ERROR_CODES = [
2
+ "BAD_BUNDLE", "BAD_CDF", "MISSING_RATIONALE", "BAD_DIAGNOSTIC_RUN",
3
+ "DIAGNOSTIC_MISMATCH", "CRYPTO_UNAVAILABLE",
4
+ ];
5
+ export class ComplianceError extends Error {
6
+ code;
7
+ path;
8
+ constructor(code, message, path) {
9
+ super(message);
10
+ this.name = "ComplianceError";
11
+ this.code = code;
12
+ if (path !== undefined)
13
+ this.path = path;
14
+ }
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,YAAY,EAAE,SAAS,EAAE,mBAAmB,EAAE,oBAAoB;IAClE,qBAAqB,EAAE,oBAAoB;CACnC,CAAC;AAEX,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,IAAI,CAAsB;IAC1B,IAAI,CAAU;IACvB,YAAY,IAAyB,EAAE,OAAe,EAAE,IAAa;QACnE,KAAK,CAAC,OAAO,CAAC,CAAC;QAAA,IAAI,CAAC,IAAI,GAAC,iBAAiB,CAAC;QAAA,IAAI,CAAC,IAAI,GAAC,IAAI,CAAC;QAAA,IAAG,IAAI,KAAG,SAAS;YAAC,IAAI,CAAC,IAAI,GAAC,IAAI,CAAC;IAC/F,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from "./metadata.js";
2
+ export * from "./errors.js";
3
+ export * from "./version.js";
2
4
  export * from "./ledger.js";
3
5
  export * from "./modelCards.js";
4
6
  export * from "./disclosure.js";
5
- export * from "./diagnostics.js";
7
+ export * from "./diagnosticRun.js";
6
8
  export * from "./bundle.js";
7
9
  export * from "./ave.js";
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from "./metadata.js";
2
+ export * from "./errors.js";
3
+ export * from "./version.js";
2
4
  export * from "./ledger.js";
3
5
  export * from "./modelCards.js";
4
6
  export * from "./disclosure.js";
5
- export * from "./diagnostics.js";
7
+ export * from "./diagnosticRun.js";
6
8
  export * from "./bundle.js";
7
9
  export * from "./ave.js";
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const COMPLIANCE_PACKAGE_VERSION = "0.6.0";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const COMPLIANCE_PACKAGE_VERSION = "0.6.0";
2
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actuarial-ts/compliance",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "ASOP-compliance-support layer for the actuarial-ts SDK: estimate metadata, assumption ledger, disclosures, model cards, diagnostics provenance, reproducibility bundles, and actual-vs-expected roll-forward. Responsibility for compliance remains with the credentialed actuary.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -46,8 +46,9 @@
46
46
  "prepack": "tsc -p tsconfig.build.json"
47
47
  },
48
48
  "dependencies": {
49
- "@actuarial-ts/core": "^0.5.0",
50
- "@actuarial-ts/interchange": "^0.5.0"
49
+ "@actuarial-ts/core": "^0.6.0",
50
+ "@actuarial-ts/data": "^0.6.0",
51
+ "@actuarial-ts/interchange": "^0.6.0"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/node": "^22.10.5",
package/src/bundle.ts CHANGED
@@ -27,13 +27,22 @@
27
27
  */
28
28
 
29
29
  import { canonicalJson, fnv1a64 } from "@actuarial-ts/core";
30
- import type {
30
+ import {
31
+ INTERCHANGE_SPEC_VERSION,
32
+ diagnosticDefinitionToDoc,
33
+ type DiagnosticDefinitionDoc,
31
34
  BundleDoc,
32
35
  MethodResultDoc,
33
36
  SelectionDoc,
34
37
  StochasticResultDoc,
35
38
  TriangleDoc,
36
39
  } from "@actuarial-ts/interchange";
40
+ import type { VerifiedDiagnosticRunProvenance } from "./diagnosticRun.js";
41
+ import { assertVerifiedDiagnosticRunProvenance, verifiedDefinitionForBundle } from "./diagnosticRun.js";
42
+ import { ComplianceError } from "./errors.js";
43
+ import { COMPLIANCE_PACKAGE_VERSION } from "./version.js";
44
+ export { ComplianceError, COMPLIANCE_ERROR_CODES, type ComplianceErrorCode } from "./errors.js";
45
+ export { COMPLIANCE_PACKAGE_VERSION } from "./version.js";
37
46
 
38
47
  export { canonicalJson, fnv1a64 };
39
48
 
@@ -54,23 +63,6 @@ export type WrappedBundleDoc = BundleDoc;
54
63
  * of this package. Add the code here when introducing a new throw.
55
64
  * (UNSUPPORTED_VALUE moved to core's registry with canonicalJson in 0.2.0.)
56
65
  */
57
- export const COMPLIANCE_ERROR_CODES = [
58
- "BAD_BUNDLE",
59
- "BAD_CDF",
60
- "MISSING_RATIONALE",
61
- ] as const;
62
-
63
- export type ComplianceErrorCode = (typeof COMPLIANCE_ERROR_CODES)[number];
64
-
65
- /** Thrown for invalid compliance input (bad bundles, judgment without rationale, non-positive CDFs). */
66
- export class ComplianceError extends Error {
67
- readonly code: ComplianceErrorCode;
68
- constructor(code: ComplianceErrorCode, message: string) {
69
- super(message);
70
- this.name = "ComplianceError";
71
- this.code = code;
72
- }
73
- }
74
66
 
75
67
 
76
68
 
@@ -81,7 +73,7 @@ export class ComplianceError extends Error {
81
73
  * test parses the emitted doc with the real interchange parser, which
82
74
  * refuses a wrong-major version — drift fails loudly.
83
75
  */
84
- export const WRAPPED_BUNDLE_INTERCHANGE_VERSION = "1.0.0";
76
+ export const WRAPPED_BUNDLE_INTERCHANGE_VERSION = INTERCHANGE_SPEC_VERSION;
85
77
 
86
78
  /**
87
79
  * This package's version, stamped into a wrapped bundle's `generator`
@@ -89,7 +81,6 @@ export const WRAPPED_BUNDLE_INTERCHANGE_VERSION = "1.0.0";
89
81
  * silently drift (mirroring interchange's INTERCHANGE_PACKAGE_VERSION
90
82
  * discipline).
91
83
  */
92
- export const COMPLIANCE_PACKAGE_VERSION = "0.5.0";
93
84
 
94
85
  /**
95
86
  * The interchange mirror for a wrapped bundle (spec 3.2): the triangles the
@@ -136,6 +127,8 @@ export interface CreateBundleInput {
136
127
  * Wrapped-mode only; the inner payload never carries it.
137
128
  */
138
129
  generator?: { name: string; version: string };
130
+ /** Authenticated diagnostic runs included in the canonical body and, when wrapped, as typed definition documents. */
131
+ diagnosticRuns?: readonly VerifiedDiagnosticRunProvenance[];
139
132
  }
140
133
 
141
134
  export interface ReproducibilityBundle {
@@ -176,6 +169,11 @@ export function createBundle(input: CreateBundleInput): ReproducibilityBundle |
176
169
  sdkVersions: input.sdkVersions,
177
170
  };
178
171
  if (input.seeds !== undefined) body["seeds"] = input.seeds;
172
+ if (input.diagnosticRuns !== undefined) {
173
+ for (const run of input.diagnosticRuns) assertVerifiedDiagnosticRunProvenance(run);
174
+ if(input.diagnosticRuns.length>0){const expected=input.diagnosticRuns[0]!.manifest.packageVersions;for(const [runIndex,run] of input.diagnosticRuns.entries()){if(canonicalJson(run.manifest.packageVersions)!==canonicalJson(expected))throw new ComplianceError("BAD_DIAGNOSTIC_RUN","Diagnostic runs disagree on SDK package versions",`$.diagnosticRuns[${runIndex}].manifest.packageVersions`)}for(const [name,version] of Object.entries(expected))if(input.sdkVersions[name]!==version)throw new ComplianceError("BAD_DIAGNOSTIC_RUN",`Outer sdkVersions must record ${name} at ${version}`,`$.sdkVersions.${name}`);if(input.wrap!==undefined&&input.generator!==undefined&&(input.generator.name!=="@actuarial-ts/compliance"||input.generator.version!==COMPLIANCE_PACKAGE_VERSION))throw new ComplianceError("BAD_DIAGNOSTIC_RUN","Wrapped diagnostic bundles require the actual compliance generator stamp","$.generator")}
175
+ body["diagnosticRuns"] = input.diagnosticRuns;
176
+ }
179
177
  const payload = canonicalJson(body);
180
178
  const inner: ReproducibilityBundle = { payload, hash: fnv1a64(payload) };
181
179
  if (input.wrap === undefined) return inner;
@@ -184,10 +182,19 @@ export function createBundle(input: CreateBundleInput): ReproducibilityBundle |
184
182
  // tag is fnv1a64(canonicalJson({ bundle, interchange })) — exactly
185
183
  // interchange's semanticBodyOf for kind "bundle" (spec 3.2).
186
184
  const bundleSegment: Record<string, unknown> = { hash: inner.hash, payload: inner.payload };
185
+ const definitions = new Map<string, DiagnosticDefinitionDoc>();
186
+ for (const run of input.diagnosticRuns ?? []) {
187
+ const compiled = verifiedDefinitionForBundle(run);
188
+ definitions.set(run.definitionIdentities.definition, diagnosticDefinitionToDoc(compiled, {
189
+ createdAt: input.createdAt,
190
+ generator: { name: "@actuarial-ts/compliance", version: COMPLIANCE_PACKAGE_VERSION },
191
+ }));
192
+ }
187
193
  const interchange = {
188
194
  triangles: [...input.wrap.triangles],
189
195
  selections: [...input.wrap.selections],
190
196
  results: [...input.wrap.results],
197
+ ...(definitions.size === 0 ? {} : { diagnosticDefinitions: [...definitions.values()].sort((a,b)=>a.diagnosticDefinition.identities.definition<b.diagnosticDefinition.identities.definition?-1:1) }),
191
198
  };
192
199
  const wrapped: WrappedBundleDoc = {
193
200
  interchangeVersion: WRAPPED_BUNDLE_INTERCHANGE_VERSION,