@nakafa/aksara-contracts 0.48.0 → 0.48.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/dist/canonical.d.ts +5 -0
- package/dist/canonical.js +10 -0
- package/dist/graph/identity.js +2 -2
- package/dist/locale.js +2 -9
- package/dist/math/arc.js +3 -3
- package/dist/math/base.js +11 -11
- package/dist/math/bounds.d.ts +1 -1
- package/dist/math/bounds.js +13 -12
- package/dist/math/collision.js +21 -23
- package/dist/math/coordinate.js +3 -3
- package/dist/math/extent.js +10 -14
- package/dist/math/plane.js +6 -6
- package/dist/math/precision.js +7 -10
- package/dist/math/proximity.js +17 -14
- package/dist/math/resolution.js +6 -6
- package/dist/math/scene.js +8 -8
- package/dist/math/vector.js +16 -18
- package/dist/math/visual.js +2 -2
- package/dist/preview/target.js +5 -5
- package/dist/program/curriculum.js +3 -3
- package/dist/program/snapshot/digest.js +13 -13
- package/dist/program/spec.js +5 -9
- package/dist/projection/article.js +3 -3
- package/dist/projection/material.js +2 -2
- package/dist/projection/question.js +2 -2
- package/dist/question/answer.js +3 -3
- package/dist/question/identity.js +9 -7
- package/dist/question/item.js +10 -10
- package/dist/question/response.js +12 -12
- package/dist/question/rubric.js +9 -9
- package/dist/quran/attribution.d.ts +12 -4
- package/dist/quran/attribution.js +2 -1
- package/dist/quran/notes.js +24 -17
- package/dist/quran/provenance.js +14 -13
- package/dist/quran/snapshot/digest.js +27 -18
- package/dist/quran/snapshot/row/hash.js +6 -6
- package/dist/quran/snapshot/row.js +4 -8
- package/dist/quran/snapshot/spec.js +2 -2
- package/dist/quran/source.js +12 -16
- package/dist/release/current/evidence.js +2 -2
- package/dist/release/head.js +2 -2
- package/dist/release/items.js +2 -2
- package/dist/release/policy.js +8 -8
- package/dist/release/rollback/spec.js +8 -9
- package/dist/release/route/page.js +6 -6
- package/dist/release/snapshot/scope.js +3 -14
- package/dist/release/snapshot/spec.js +6 -5
- package/dist/release/spec.js +2 -2
- package/dist/renderer/compatibility.js +3 -3
- package/dist/renderer/component.js +2 -2
- package/dist/renderer/contract.js +9 -10
- package/dist/renderer/manifest.js +3 -4
- package/dist/runtime/protected/spec.js +3 -3
- package/dist/runtime/verify.js +2 -2
- package/dist/signature/trusted.js +3 -3
- package/dist/signature/verify.js +9 -14
- package/dist/transport/batch.js +3 -3
- package/dist/transport/group.js +2 -2
- package/dist/transport/snapshot.js +2 -2
- package/dist/tryout/closure/accounting.js +3 -3
- package/dist/tryout/hash/catalog.js +5 -5
- package/dist/tryout/identity.js +7 -6
- package/dist/tryout/language.d.ts +1 -1
- package/dist/tryout/language.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -3
- package/dist/tryout/scoring.js +4 -4
- package/dist/tryout/snapshot/hash.js +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { hasCanonicalOrder } from "#contracts/canonical";
|
|
2
3
|
import { ContentFamilySchema } from "#contracts/content";
|
|
3
4
|
/** Fixed structured families selected by the one global release pointer. */
|
|
4
5
|
export const ContentSnapshotKindSchema = Schema.Literals([
|
|
@@ -8,20 +9,8 @@ export const ContentSnapshotKindSchema = Schema.Literals([
|
|
|
8
9
|
]);
|
|
9
10
|
/** Checks strict canonical ordering for selected content and snapshot families. */
|
|
10
11
|
function hasCanonicalPublicationScope(input) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return (previous === undefined ||
|
|
14
|
-
ContentSnapshotKindSchema.literals.indexOf(previous) <
|
|
15
|
-
ContentSnapshotKindSchema.literals.indexOf(family));
|
|
16
|
-
});
|
|
17
|
-
const familiesAreCanonical = input.families.every((family, index) => {
|
|
18
|
-
const previous = input.families[index - 1];
|
|
19
|
-
return (previous === undefined ||
|
|
20
|
-
ContentFamilySchema.literals.indexOf(previous) <
|
|
21
|
-
ContentFamilySchema.literals.indexOf(family));
|
|
22
|
-
});
|
|
23
|
-
return (familiesAreCanonical &&
|
|
24
|
-
snapshotsAreCanonical &&
|
|
12
|
+
return (hasCanonicalOrder(ContentFamilySchema.literals, input.families) &&
|
|
13
|
+
hasCanonicalOrder(ContentSnapshotKindSchema.literals, input.snapshots) &&
|
|
25
14
|
input.families.length + input.snapshots.length > 0);
|
|
26
15
|
}
|
|
27
16
|
/** Whole content and structured families authenticated by one signed release. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Signed structured snapshot transition contracts. */
|
|
2
|
-
import { Record as Rec, Schema } from "effect";
|
|
2
|
+
import { Array as Arr, Record as Rec, Schema } from "effect";
|
|
3
3
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { ContentSnapshotKindSchema, } from "#contracts/release/snapshot/scope";
|
|
5
5
|
import { encodeJsonText } from "#contracts/text/json";
|
|
@@ -24,7 +24,8 @@ export const ContentSnapshotSetSchema = Schema.Struct({
|
|
|
24
24
|
});
|
|
25
25
|
/** Requires every unselected structured family to remain inherited. */
|
|
26
26
|
export function hasScopedSnapshotTransitions(scope, snapshots) {
|
|
27
|
-
return ContentSnapshotKindSchema.literals
|
|
27
|
+
return Arr.every(ContentSnapshotKindSchema.literals, (family) => Arr.contains(scope.snapshots, family) ||
|
|
28
|
+
snapshots[family].mode === "inherit");
|
|
28
29
|
}
|
|
29
30
|
/** Checks inheritance, replacement, and forward restore row semantics. */
|
|
30
31
|
export function hasCoherentSnapshotState(state) {
|
|
@@ -98,15 +99,15 @@ export function invertContentSnapshots(snapshots) {
|
|
|
98
99
|
}
|
|
99
100
|
/** Checks that an initial release does not claim an unstated snapshot base. */
|
|
100
101
|
export function hasEmptySnapshotBases(snapshots) {
|
|
101
|
-
return Rec.values(snapshots)
|
|
102
|
+
return Arr.every(Rec.values(snapshots), ({ baseSnapshotId }) => baseSnapshotId === null);
|
|
102
103
|
}
|
|
103
104
|
/** Checks that a rollback only inherits or restores immutable snapshots. */
|
|
104
105
|
export function hasRollbackSnapshotModes(snapshots) {
|
|
105
|
-
return Rec.values(snapshots)
|
|
106
|
+
return Arr.every(Rec.values(snapshots), ({ mode }) => mode !== "replace");
|
|
106
107
|
}
|
|
107
108
|
/** Checks that reviewed Git sources only inherit or replace snapshots. */
|
|
108
109
|
export function hasGitSnapshotModes(snapshots) {
|
|
109
|
-
return Rec.values(snapshots)
|
|
110
|
+
return Arr.every(Rec.values(snapshots), ({ mode }) => mode !== "restore");
|
|
110
111
|
}
|
|
111
112
|
/** Returns the number of rows that must be staged for this release. */
|
|
112
113
|
export function snapshotRowCount(snapshots) {
|
package/dist/release/spec.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentFamilySchema } from "#contracts/content";
|
|
3
3
|
import { ContentDeliveryClassSchema } from "#contracts/delivery";
|
|
4
4
|
import { ContentKeySchema, CorpusSourcePathSchema, Ed25519SignatureSchema, ReleaseIdSchema, Sha256HashSchema, SigningKeyIdSchema, } from "#contracts/ids";
|
|
@@ -110,7 +110,7 @@ export const SignedContentReleaseSchema = Schema.Struct({
|
|
|
110
110
|
});
|
|
111
111
|
/** Checks whether one application locale is active in a signed release. */
|
|
112
112
|
export function releaseActivatesAppLocale(release, appLocale) {
|
|
113
|
-
return release.manifest.activeAppLocales
|
|
113
|
+
return Arr.contains(release.manifest.activeAppLocales, appLocale);
|
|
114
114
|
}
|
|
115
115
|
/** Signed release contract accepted only for rollback-owned operations. */
|
|
116
116
|
export const RollbackSignedContentReleaseSchema = SignedContentReleaseSchema.pipe(Schema.refine((release) => release.manifest.origin.kind === "rollback", { message: "Expected a signed rollback release." }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, HashSet, Schema } from "effect";
|
|
2
2
|
import { ArtifactRendererComponentMissingError, ArtifactRendererDomainUnpublishedError, } from "#contracts/artifact/spec";
|
|
3
3
|
import { RendererComponentNameSchema, } from "#contracts/renderer/component";
|
|
4
4
|
import { selectRendererDomainCapability, } from "#contracts/renderer/contract";
|
|
@@ -37,7 +37,7 @@ export const verifyRendererManifestCompatibility = Effect.fn("AksaraContracts.ve
|
|
|
37
37
|
}
|
|
38
38
|
yield* verifyCapabilitySuperset(input.frozen.base, input.live.base, "base");
|
|
39
39
|
for (const rendererDomain of input.frozen.publishedDomains) {
|
|
40
|
-
if (!input.live.publishedDomains
|
|
40
|
+
if (!Arr.contains(input.live.publishedDomains, rendererDomain)) {
|
|
41
41
|
return yield* new RendererManifestDomainUnpublishedError({
|
|
42
42
|
rendererDomain,
|
|
43
43
|
});
|
|
@@ -51,7 +51,7 @@ export const verifyRendererManifestCompatibility = Effect.fn("AksaraContracts.ve
|
|
|
51
51
|
/** Verifies that a deployed live renderer can route and execute one artifact. */
|
|
52
52
|
export const verifyContentRendererCompatibility = Effect.fn("AksaraContracts.verifyContentRendererCompatibility")(function* ({ payload, rendererManifest, }) {
|
|
53
53
|
const manifest = yield* validateRendererManifestHash(rendererManifest);
|
|
54
|
-
if (!manifest.publishedDomains
|
|
54
|
+
if (!Arr.contains(manifest.publishedDomains, payload.rendererDomain)) {
|
|
55
55
|
return yield* new ArtifactRendererDomainUnpublishedError({
|
|
56
56
|
contentKey: payload.contentKey,
|
|
57
57
|
rendererDomain: payload.rendererDomain,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Order, Schema } from "effect";
|
|
2
2
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
3
3
|
const COMPONENT_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
4
4
|
/** Renderer names identify one current implementation, never member paths. */
|
|
@@ -20,5 +20,5 @@ export const RendererComponentsSchema = Schema.Array(RendererComponentNameSchema
|
|
|
20
20
|
}));
|
|
21
21
|
/** Sorts current names without discarding duplicate input. */
|
|
22
22
|
export function sortRendererComponents(names) {
|
|
23
|
-
return
|
|
23
|
+
return Arr.sort(names, Order.String);
|
|
24
24
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Effect, HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, HashSet, Option, Order, Schema } from "effect";
|
|
2
2
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
3
3
|
import { RendererComponentsSchema, } from "#contracts/renderer/component";
|
|
4
4
|
import { RENDERER_DOMAINS, RendererDomainSchema, } from "#contracts/renderer/domain";
|
|
5
5
|
import { encodeJsonText } from "#contracts/text/json";
|
|
6
|
-
import { compareCodeUnits } from "#contracts/text/order";
|
|
7
6
|
/** Stable format for the one current domain-scoped renderer manifest. */
|
|
8
7
|
export const RENDERER_MANIFEST_FORMAT = "nakafa-mdx-renderer";
|
|
9
8
|
/** One route-domain component contract with an exact real domain name. */
|
|
@@ -13,8 +12,8 @@ export const RendererDomainCapabilitySchema = Schema.Struct({
|
|
|
13
12
|
});
|
|
14
13
|
/** Checks published route domains are unique and ordered by code unit. */
|
|
15
14
|
function hasCanonicalPublishedDomains(domains) {
|
|
16
|
-
const canonical =
|
|
17
|
-
return
|
|
15
|
+
const canonical = Arr.sort(domains, Order.String);
|
|
16
|
+
return Arr.every(domains, (domain, index) => domain === canonical[index] && domain !== domains[index - 1]);
|
|
18
17
|
}
|
|
19
18
|
/** Canonical route domains that the deployed Nakafa app can publish. */
|
|
20
19
|
export const RendererPublishedDomainsSchema = Schema.Array(RendererDomainSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.makeFilter(hasCanonicalPublishedDomains, {
|
|
@@ -22,11 +21,11 @@ export const RendererPublishedDomainsSchema = Schema.Array(RendererDomainSchema)
|
|
|
22
21
|
})));
|
|
23
22
|
/** Sorts route-domain registries with cross-machine code-unit ordering. */
|
|
24
23
|
export function sortRendererDomains(domains) {
|
|
25
|
-
return
|
|
24
|
+
return Arr.sortWith(domains, (domain) => domain.name, Order.String);
|
|
26
25
|
}
|
|
27
26
|
/** Complete current domain set shared by published and deployed manifests. */
|
|
28
27
|
export const RendererManifestDomainsSchema = Schema.Array(RendererDomainCapabilitySchema).check(Schema.makeFilter((domains) => domains.length === RENDERER_DOMAINS.length &&
|
|
29
|
-
|
|
28
|
+
Arr.every(domains, ({ name }, index) => name === RENDERER_DOMAINS[index]), {
|
|
30
29
|
message: "Expected every renderer domain exactly once in canonical order.",
|
|
31
30
|
}));
|
|
32
31
|
/** Keeps base component names out of every route-owned registry. */
|
|
@@ -56,11 +55,11 @@ export class RendererDomainCapabilityMissingError extends Schema.TaggedError()("
|
|
|
56
55
|
}
|
|
57
56
|
/** Selects the one physical route registry authorized for a document. */
|
|
58
57
|
export const selectRendererDomainCapability = Effect.fn("AksaraContracts.selectRendererDomainCapability")(function* (manifest, rendererDomain) {
|
|
59
|
-
const capability = manifest.domains
|
|
60
|
-
if (
|
|
58
|
+
const capability = Arr.findFirst(manifest.domains, ({ name }) => name === rendererDomain);
|
|
59
|
+
if (Option.isNone(capability)) {
|
|
61
60
|
return yield* new RendererDomainCapabilityMissingError({ rendererDomain });
|
|
62
61
|
}
|
|
63
|
-
return capability;
|
|
62
|
+
return capability.value;
|
|
64
63
|
});
|
|
65
64
|
/** SHA-256 could not be calculated for the renderer contract bytes. */
|
|
66
65
|
export class RendererManifestHashComputeError extends Schema.TaggedError()("RendererManifestHashComputeError", { cause: Schema.Unknown }) {
|
|
@@ -76,7 +75,7 @@ export function canonicalizeRendererManifestContract(input) {
|
|
|
76
75
|
return encodeJsonText([
|
|
77
76
|
RENDERER_MANIFEST_FORMAT,
|
|
78
77
|
input.base,
|
|
79
|
-
sortRendererDomains(input.domains)
|
|
78
|
+
Arr.map(sortRendererDomains(input.domains), ({ name, components }) => ({
|
|
80
79
|
components,
|
|
81
80
|
name,
|
|
82
81
|
})),
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Order, Schema } from "effect";
|
|
2
2
|
import { decodeContract } from "#contracts/decode";
|
|
3
3
|
import { hashText } from "#contracts/hash/text";
|
|
4
4
|
import { RendererComponentNameSchema, sortRendererComponents, } from "#contracts/renderer/component";
|
|
5
5
|
import { canonicalizeRendererManifestContract, RENDERER_MANIFEST_FORMAT, RendererManifestDomainsSchema, RendererManifestEnvelopeSchema, RendererManifestHashComputeError, RendererManifestHashMismatchError, sortRendererDomains, } from "#contracts/renderer/contract";
|
|
6
6
|
import { RendererDomainSchema } from "#contracts/renderer/domain";
|
|
7
|
-
import { compareCodeUnits } from "#contracts/text/order";
|
|
8
7
|
const RendererManifestCreationSchema = Schema.Struct({
|
|
9
8
|
base: Schema.Array(RendererComponentNameSchema),
|
|
10
9
|
domains: Schema.Array(Schema.Struct({
|
|
@@ -18,14 +17,14 @@ const hashRendererContract = Effect.fn("AksaraContracts.hashRendererContract")((
|
|
|
18
17
|
/** Creates a complete authenticated manifest from one current name set. */
|
|
19
18
|
export const createRendererManifest = Effect.fn("AksaraContracts.createRendererManifest")(function* (input) {
|
|
20
19
|
const wire = yield* decodeContract(RendererManifestCreationSchema, "RendererManifestCreation", input);
|
|
21
|
-
const domains = yield* decodeContract(RendererManifestDomainsSchema, "RendererManifestDomains", sortRendererDomains(wire.domains
|
|
20
|
+
const domains = yield* decodeContract(RendererManifestDomainsSchema, "RendererManifestDomains", sortRendererDomains(Arr.map(wire.domains, ({ name, components }) => ({
|
|
22
21
|
components: sortRendererComponents(components),
|
|
23
22
|
name,
|
|
24
23
|
}))));
|
|
25
24
|
const contract = {
|
|
26
25
|
base: sortRendererComponents(wire.base),
|
|
27
26
|
domains,
|
|
28
|
-
publishedDomains:
|
|
27
|
+
publishedDomains: Arr.sort(wire.publishedDomains, Order.String),
|
|
29
28
|
};
|
|
30
29
|
const hash = yield* hashRendererContract(contract);
|
|
31
30
|
return yield* decodeContract(RendererManifestEnvelopeSchema, "RendererManifestEnvelope", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, HashSet, Schema } from "effect";
|
|
2
2
|
import { SignedContentArtifactSchema, } from "#contracts/content";
|
|
3
3
|
import { decodeContract } from "#contracts/decode";
|
|
4
4
|
import { ContentKeySchema, CorpusSourcePathSchema, Sha256HashSchema, } from "#contracts/ids";
|
|
@@ -32,7 +32,7 @@ export const ProtectedContentRuntimeSelectorSchema = Schema.Struct({
|
|
|
32
32
|
})));
|
|
33
33
|
/** Checks a batch never requests the same immutable artifact twice. */
|
|
34
34
|
function hasUniqueSelectors(selectors) {
|
|
35
|
-
const hashes =
|
|
35
|
+
const hashes = Arr.map(selectors, ({ artifactHash }) => artifactHash);
|
|
36
36
|
return HashSet.size(HashSet.fromIterable(hashes)) === hashes.length;
|
|
37
37
|
}
|
|
38
38
|
const ProtectedContentRuntimeSelectorsSchema = Schema.Array(ProtectedContentRuntimeSelectorSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(MAX_PROTECTED_RUNTIME_SELECTORS)), Schema.check(Schema.makeFilter(hasUniqueSelectors, {
|
|
@@ -52,7 +52,7 @@ export const ProtectedContentRuntimeItemSchema = Schema.Struct({
|
|
|
52
52
|
});
|
|
53
53
|
/** Checks one protected response never repeats an immutable artifact. */
|
|
54
54
|
function hasUniqueArtifacts(items) {
|
|
55
|
-
const hashes =
|
|
55
|
+
const hashes = Arr.map(items, ({ artifact }) => artifact.artifactHash);
|
|
56
56
|
return HashSet.size(HashSet.fromIterable(hashes)) === hashes.length;
|
|
57
57
|
}
|
|
58
58
|
const ProtectedContentRuntimeItemsSchema = Schema.Array(ProtectedContentRuntimeItemSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(MAX_PROTECTED_RUNTIME_SELECTORS)), Schema.check(Schema.makeFilter(hasUniqueArtifacts, {
|
package/dist/runtime/verify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Array as Arr, Effect } from "effect";
|
|
2
2
|
import { verifySignedContentArtifact } from "#contracts/artifact/verify";
|
|
3
3
|
import { hashContentProjection } from "#contracts/projection/hash";
|
|
4
4
|
import { verifyContentReleaseBundle } from "#contracts/release/verify";
|
|
@@ -15,7 +15,7 @@ function hasArticleSourcePath(projection, sourcePath) {
|
|
|
15
15
|
}
|
|
16
16
|
const sourceRoot = sourcePath.slice(prefix.length, -suffix.length);
|
|
17
17
|
const segments = sourceRoot.split("/");
|
|
18
|
-
return segments.length === 2 &&
|
|
18
|
+
return (segments.length === 2 && Arr.join(segments, "-") === projection.articleSlug);
|
|
19
19
|
}
|
|
20
20
|
/** Checks one page path matches its signed source-owned provenance. */
|
|
21
21
|
function hasPageSourcePath(projection, sourcePath) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { SigningKeyIdSchema } from "#contracts/ids";
|
|
3
3
|
import { ContentVerificationKeyResolver, SigningKeyNotFoundError, SigningKeyResolutionError, } from "#contracts/signature/spec";
|
|
4
4
|
/** One code-reviewed Ed25519 public key retained for release verification. */
|
|
@@ -16,10 +16,10 @@ export const ACTIVE_SIGNING_KEY_ID = ACTIVE_CONTENT_KEY.keyId;
|
|
|
16
16
|
export const TRUSTED_CONTENT_KEYS = Object.freeze([ACTIVE_CONTENT_KEY]);
|
|
17
17
|
/** Builds an immutable exact-ID resolver from code-owned retained entries. */
|
|
18
18
|
export function makeTrustedKeyResolver(entries) {
|
|
19
|
-
const retained =
|
|
19
|
+
const retained = Arr.map(entries, (entry) => ({ ...entry }));
|
|
20
20
|
return ContentVerificationKeyResolver.of({
|
|
21
21
|
resolve: (keyId) => {
|
|
22
|
-
const [match, ...duplicates] =
|
|
22
|
+
const [match, ...duplicates] = Arr.filter(retained, (entry) => entry.keyId === keyId);
|
|
23
23
|
if (match === undefined) {
|
|
24
24
|
return Effect.fail(new SigningKeyNotFoundError({ keyId }));
|
|
25
25
|
}
|
package/dist/signature/verify.js
CHANGED
|
@@ -24,20 +24,15 @@ function decodePublicKeyPem(keyId, publicKeyPem, subject) {
|
|
|
24
24
|
normalizedPublicKeyPem.trimEnd().endsWith(PUBLIC_KEY_FOOTER))) {
|
|
25
25
|
return Effect.fail(new PublicKeyParseError({ keyId, subject }));
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw new TypeError("Invalid public-key base64");
|
|
37
|
-
}
|
|
38
|
-
return decodeBase64(body);
|
|
39
|
-
},
|
|
40
|
-
});
|
|
27
|
+
const body = normalizedPublicKeyPem
|
|
28
|
+
.slice(PUBLIC_KEY_HEADER.length)
|
|
29
|
+
.replace(PUBLIC_KEY_FOOTER, "")
|
|
30
|
+
.replaceAll("\n", "")
|
|
31
|
+
.trim();
|
|
32
|
+
if (!PUBLIC_KEY_BASE64_PATTERN.test(body) || body.length % 4 !== 0) {
|
|
33
|
+
return Effect.fail(new PublicKeyParseError({ keyId, subject }));
|
|
34
|
+
}
|
|
35
|
+
return Effect.succeed(decodeBase64(body));
|
|
41
36
|
}
|
|
42
37
|
/** Imports one exact Ed25519 SPKI key through Web Crypto. */
|
|
43
38
|
function importEd25519PublicKey(keyId, publicKeyPem, subject) {
|
package/dist/transport/batch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { SignedContentArtifactSchema } from "#contracts/content";
|
|
3
3
|
import { ReleaseIdSchema } from "#contracts/ids";
|
|
4
4
|
import { ContentProjectionSchema } from "#contracts/projection/spec";
|
|
@@ -15,7 +15,7 @@ const StageItemBatchFields = {
|
|
|
15
15
|
/** Checks batch ownership and contiguous signed item indexes. */
|
|
16
16
|
function hasBoundReleaseItems(input) {
|
|
17
17
|
const [first] = input.items;
|
|
18
|
-
return input.items
|
|
18
|
+
return Arr.every(input.items, (item, offset) => item.releaseId === input.releaseId && item.index === first.index + offset);
|
|
19
19
|
}
|
|
20
20
|
/** Canonical input for one bounded ordered-item staging operation. */
|
|
21
21
|
export const StageItemBatchInputSchema = Schema.Struct(StageItemBatchFields).pipe(Schema.check(Schema.makeFilter(hasBoundReleaseItems, {
|
|
@@ -42,7 +42,7 @@ const StageRouteBatchFields = {
|
|
|
42
42
|
/** Checks batch ownership and contiguous signed route indexes. */
|
|
43
43
|
function hasBoundRouteItems(input) {
|
|
44
44
|
const [first] = input.routes;
|
|
45
|
-
return input.routes
|
|
45
|
+
return Arr.every(input.routes, (route, offset) => route.releaseId === input.releaseId &&
|
|
46
46
|
route.index === first.index + offset);
|
|
47
47
|
}
|
|
48
48
|
/** Canonical input for one bounded ordered-route staging operation. */
|
package/dist/transport/group.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ReleaseIdSchema } from "#contracts/ids";
|
|
3
3
|
import { StageArtifactBatchRequestSchema, StageItemBatchRequestSchema, StageProjectionBatchRequestSchema, StageRouteBatchRequestSchema, } from "#contracts/transport/batch";
|
|
4
4
|
import { MAX_STAGE_GROUP_COUNT } from "#contracts/transport/limits";
|
|
@@ -20,7 +20,7 @@ const StageGroupFields = {
|
|
|
20
20
|
};
|
|
21
21
|
/** Requires every grouped transaction to belong to the outer release. */
|
|
22
22
|
function hasBoundRequests(input) {
|
|
23
|
-
return input.requests
|
|
23
|
+
return Arr.every(input.requests, (request) => request.releaseId === input.releaseId);
|
|
24
24
|
}
|
|
25
25
|
/** Canonical target input for one bounded authenticated request group. */
|
|
26
26
|
export const StageGroupInputSchema = Schema.Struct(StageGroupFields).pipe(Schema.check(Schema.makeFilter(hasBoundRequests, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ReleaseIdSchema, Sha256HashSchema } from "#contracts/ids";
|
|
3
3
|
import { ContentSnapshotManifestSchema, ContentSnapshotRowSchema, } from "#contracts/release/snapshot/data";
|
|
4
4
|
import { ContentSnapshotKindSchema } from "#contracts/release/snapshot/scope";
|
|
@@ -27,7 +27,7 @@ const StageSnapshotBatchFields = {
|
|
|
27
27
|
};
|
|
28
28
|
/** Checks that every row belongs to the envelope and Quran snapshot identity. */
|
|
29
29
|
function hasBoundSnapshotRows(input) {
|
|
30
|
-
return input.rows
|
|
30
|
+
return Arr.every(input.rows, (row) => {
|
|
31
31
|
if (row.family !== input.family) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, MutableHashMap, MutableHashSet, Option, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, MutableHashMap, MutableHashSet, Option, Schema, } from "effect";
|
|
2
2
|
import { encodeJsonText } from "#contracts/text/json";
|
|
3
3
|
/** A try-out snapshot is incomplete or inconsistent across app locales. */
|
|
4
4
|
export class TryoutClosureError extends Schema.TaggedError()("TryoutClosureError", {
|
|
@@ -18,11 +18,11 @@ export class TryoutClosureError extends Schema.TaggedError()("TryoutClosureError
|
|
|
18
18
|
}
|
|
19
19
|
/** Serializes locale sets through the active list's signed canonical order. */
|
|
20
20
|
function localeSetIdentity(locales, activeAppLocales) {
|
|
21
|
-
return encodeJsonText(
|
|
21
|
+
return encodeJsonText(Arr.filter(activeAppLocales, (locale) => MutableHashSet.has(locales, locale)));
|
|
22
22
|
}
|
|
23
23
|
/** Adds one active locale to a logical identity without duplicates. */
|
|
24
24
|
export function addLocale(localesByIdentity, activeAppLocales, identity, appLocale) {
|
|
25
|
-
if (!
|
|
25
|
+
if (!Arr.contains(activeAppLocales, appLocale)) {
|
|
26
26
|
return Effect.fail(new TryoutClosureError({
|
|
27
27
|
actual: appLocale,
|
|
28
28
|
code: "inactive-locale",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Array as Arr, Effect } from "effect";
|
|
2
2
|
import { canonicalizeLearningGraphIdentity } from "#contracts/graph/spec";
|
|
3
3
|
import { encodeJsonText } from "#contracts/text/json";
|
|
4
4
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
@@ -18,25 +18,25 @@ export function compareTryoutCatalog(left, right) {
|
|
|
18
18
|
}
|
|
19
19
|
/** Builds one locale-neutral hierarchy identity for closure checks. */
|
|
20
20
|
export function tryoutCatalogLogicalIdentity(row) {
|
|
21
|
-
return [
|
|
21
|
+
return Arr.join([
|
|
22
22
|
row.kind,
|
|
23
23
|
row.countryKey,
|
|
24
24
|
"examKey" in row ? row.examKey : "",
|
|
25
25
|
"trackKey" in row ? row.trackKey : "",
|
|
26
26
|
"setKey" in row ? row.setKey : "",
|
|
27
27
|
"sectionKey" in row ? row.sectionKey : "",
|
|
28
|
-
]
|
|
28
|
+
], "\0");
|
|
29
29
|
}
|
|
30
30
|
/** Builds the locale-neutral catalog identity of one section reference. */
|
|
31
31
|
export function tryoutSectionLogicalIdentity(input) {
|
|
32
|
-
return [
|
|
32
|
+
return Arr.join([
|
|
33
33
|
"section",
|
|
34
34
|
input.countryKey,
|
|
35
35
|
input.examKey,
|
|
36
36
|
input.trackKey,
|
|
37
37
|
input.setKey,
|
|
38
38
|
input.sectionKey,
|
|
39
|
-
]
|
|
39
|
+
], "\0");
|
|
40
40
|
}
|
|
41
41
|
/** Serializes locale-neutral catalog facts for cross-locale closure checks. */
|
|
42
42
|
export function canonicalizeTryoutCatalogFacts(row) {
|
package/dist/tryout/identity.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
1
2
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
2
3
|
/** Builds one deterministic current node identity before its row is loaded. */
|
|
3
4
|
export function tryoutCatalogNodeIdentity(input) {
|
|
4
|
-
return [
|
|
5
|
+
return Arr.join([
|
|
5
6
|
input.appLocale,
|
|
6
7
|
input.kind,
|
|
7
8
|
input.countryKey,
|
|
@@ -9,7 +10,7 @@ export function tryoutCatalogNodeIdentity(input) {
|
|
|
9
10
|
"trackKey" in input ? input.trackKey : "",
|
|
10
11
|
"setKey" in input ? input.setKey : "",
|
|
11
12
|
"sectionKey" in input ? input.sectionKey : "",
|
|
12
|
-
]
|
|
13
|
+
], "\0");
|
|
13
14
|
}
|
|
14
15
|
/** Builds one deterministic current hierarchy identity from its signed row. */
|
|
15
16
|
export function tryoutCatalogIdentity(row) {
|
|
@@ -17,7 +18,7 @@ export function tryoutCatalogIdentity(row) {
|
|
|
17
18
|
}
|
|
18
19
|
/** Builds the deterministic placement identity across application locales. */
|
|
19
20
|
export function tryoutPlacementIdentity(row) {
|
|
20
|
-
return [
|
|
21
|
+
return Arr.join(Arr.map([
|
|
21
22
|
row.countryKey,
|
|
22
23
|
row.examKey,
|
|
23
24
|
row.trackKey,
|
|
@@ -26,11 +27,11 @@ export function tryoutPlacementIdentity(row) {
|
|
|
26
27
|
row.questionOrder,
|
|
27
28
|
row.questionContentKey,
|
|
28
29
|
row.appLocale,
|
|
29
|
-
]
|
|
30
|
+
], String), "\0");
|
|
30
31
|
}
|
|
31
32
|
/** Builds one locale-neutral placement identity for closure checks. */
|
|
32
33
|
export function tryoutPlacementLogicalIdentity(row) {
|
|
33
|
-
return [
|
|
34
|
+
return Arr.join(Arr.map([
|
|
34
35
|
row.countryKey,
|
|
35
36
|
row.examKey,
|
|
36
37
|
row.trackKey,
|
|
@@ -38,7 +39,7 @@ export function tryoutPlacementLogicalIdentity(row) {
|
|
|
38
39
|
row.sectionKey,
|
|
39
40
|
row.questionOrder,
|
|
40
41
|
row.questionContentKey,
|
|
41
|
-
]
|
|
42
|
+
], String), "\0");
|
|
42
43
|
}
|
|
43
44
|
/** Compares placements in the order used by question-head binding. */
|
|
44
45
|
export function compareTryoutPlacements(left, right) {
|
|
@@ -13,7 +13,7 @@ export declare function deliveryLanguageForPolicy(policy: AssessmentLanguagePoli
|
|
|
13
13
|
/** Resolves the exact immutable question artifact locale for one app locale. */
|
|
14
14
|
export declare function questionArtifactLocaleForPolicy(policy: AssessmentLanguagePolicy, appLocale: AppLocale): ArtifactLocale;
|
|
15
15
|
/** Lists unique prompt and response locales required by one section policy. */
|
|
16
|
-
export declare function questionArtifactLocalesForPolicy(policy: AssessmentLanguagePolicy): readonly
|
|
16
|
+
export declare function questionArtifactLocalesForPolicy(policy: AssessmentLanguagePolicy): readonly ArtifactLocale[];
|
|
17
17
|
/** Returns policy facts in stable field order for signed canonicalizers. */
|
|
18
18
|
export declare function canonicalAssessmentLanguagePolicy(policy: AssessmentLanguagePolicy): {
|
|
19
19
|
kind: "fixed";
|
package/dist/tryout/language.js
CHANGED
|
@@ -20,7 +20,7 @@ export function questionArtifactLocaleForPolicy(policy, appLocale) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Lists unique prompt and response locales required by one section policy. */
|
|
22
22
|
export function questionArtifactLocalesForPolicy(policy) {
|
|
23
|
-
return Object.freeze(Arr.dedupe(
|
|
23
|
+
return Object.freeze(Arr.dedupe(Arr.map(ACTIVE_APP_LOCALES, (appLocale) => questionArtifactLocaleForPolicy(policy, appLocale))));
|
|
24
24
|
}
|
|
25
25
|
/** Returns policy facts in stable field order for signed canonicalizers. */
|
|
26
26
|
export function canonicalAssessmentLanguagePolicy(policy) {
|
package/dist/tryout/scoring.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, MutableHashMap, Schema } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, MutableList, Schema } from "effect";
|
|
2
2
|
import type { TryoutCatalogRow, TryoutSection, TryoutSet } from "#contracts/tryout/catalog";
|
|
3
3
|
import type { TryoutPlacement } from "#contracts/tryout/placement";
|
|
4
4
|
import type { TryoutScoring } from "#contracts/tryout/spec";
|
|
@@ -17,7 +17,7 @@ export declare class TryoutScoringError extends TryoutScoringError_base {
|
|
|
17
17
|
/** Creates empty scoring facts for one snapshot verification pass. */
|
|
18
18
|
export declare function makeTryoutScoringFacts(): {
|
|
19
19
|
readonly exams: MutableHashMap.MutableHashMap<string, TryoutScoring>;
|
|
20
|
-
readonly sections: TryoutSection
|
|
20
|
+
readonly sections: MutableList.MutableList<TryoutSection>;
|
|
21
21
|
readonly sets: MutableHashMap.MutableHashMap<string, TryoutSet>;
|
|
22
22
|
};
|
|
23
23
|
/** Exam strategies, sets, and sections gathered while a catalog is read. */
|
|
@@ -30,7 +30,7 @@ export declare function recordTryoutScoringFacts(facts: TryoutScoringFacts, row:
|
|
|
30
30
|
*/
|
|
31
31
|
export declare const validateTryoutScoringFacts: (facts: {
|
|
32
32
|
readonly exams: MutableHashMap.MutableHashMap<string, TryoutScoring>;
|
|
33
|
-
readonly sections: TryoutSection
|
|
33
|
+
readonly sections: MutableList.MutableList<TryoutSection>;
|
|
34
34
|
readonly sets: MutableHashMap.MutableHashMap<string, TryoutSet>;
|
|
35
35
|
}) => Effect.Effect<void, TryoutScoringError, never>;
|
|
36
36
|
/**
|
package/dist/tryout/scoring.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, MutableHashMap, Option, Schema } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, MutableList, Option, Schema } from "effect";
|
|
2
2
|
import { tryoutCatalogIdentity, tryoutCatalogNodeIdentity, tryoutPlacementIdentity, } from "#contracts/tryout/identity";
|
|
3
3
|
/**
|
|
4
4
|
* A signed try-out row cannot be scored as published. `strategy` means a set
|
|
@@ -15,7 +15,7 @@ export class TryoutScoringError extends Schema.TaggedError()("TryoutScoringError
|
|
|
15
15
|
export function makeTryoutScoringFacts() {
|
|
16
16
|
return {
|
|
17
17
|
exams: MutableHashMap.empty(),
|
|
18
|
-
sections:
|
|
18
|
+
sections: MutableList.make(),
|
|
19
19
|
sets: MutableHashMap.empty(),
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -28,7 +28,7 @@ export function recordTryoutScoringFacts(facts, row) {
|
|
|
28
28
|
MutableHashMap.set(facts.sets, tryoutCatalogIdentity(row), row);
|
|
29
29
|
}
|
|
30
30
|
if (row.kind === "section") {
|
|
31
|
-
facts.sections
|
|
31
|
+
MutableList.append(facts.sections, row);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -81,7 +81,7 @@ function validateSectionMarks(facts, row) {
|
|
|
81
81
|
*/
|
|
82
82
|
export const validateTryoutScoringFacts = Effect.fn("AksaraContracts.validateTryoutScoringFacts")(function* (facts) {
|
|
83
83
|
yield* Effect.forEach(MutableHashMap.values(facts.sets), (row) => validateSetStrategy(facts, row), { discard: true });
|
|
84
|
-
yield* Effect.forEach(facts.sections, (row) => validateSectionMarks(facts, row), { discard: true });
|
|
84
|
+
yield* Effect.forEach(MutableList.toArray(facts.sections), (row) => validateSectionMarks(facts, row), { discard: true });
|
|
85
85
|
});
|
|
86
86
|
/**
|
|
87
87
|
* Requires one rubric placement to belong to a raw-scored set, because a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Record as Rec } from "effect";
|
|
1
|
+
import { Array as Arr, Record as Rec } from "effect";
|
|
2
2
|
import { hashTryoutCanonical } from "#contracts/tryout/canonical";
|
|
3
3
|
import { canonicalizeTryoutSnapshot, TRYOUT_SNAPSHOT_DOMAIN, TRYOUT_SNAPSHOT_ROWS_DOMAIN, } from "#contracts/tryout/snapshot/canonical";
|
|
4
4
|
import { TRYOUT_SNAPSHOT_FORMAT, TryoutSnapshotSchema, } from "#contracts/tryout/snapshot/spec";
|
|
@@ -13,7 +13,7 @@ export function makeTryoutSnapshot(input) {
|
|
|
13
13
|
/** Returns exact structured row evidence authenticated by a snapshot. */
|
|
14
14
|
export function tryoutSnapshotRowEvidence(input) {
|
|
15
15
|
return {
|
|
16
|
-
rowCount: Rec.values(input.counts)
|
|
16
|
+
rowCount: Arr.reduce(Rec.values(input.counts), 0, (total, count) => total + count) +
|
|
17
17
|
input.placementCount,
|
|
18
18
|
rowDigest: hashTryoutCanonical(TRYOUT_SNAPSHOT_ROWS_DOMAIN, `${input.catalogDigest}\n${input.placementDigest}`),
|
|
19
19
|
};
|
package/package.json
CHANGED