@nakafa/aksara-contracts 0.49.0 → 0.51.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.
- package/dist/artifact/integrity.d.ts +15 -2
- package/dist/artifact/integrity.js +3 -15
- package/dist/artifact/limits.js +3 -4
- package/dist/artifact/source.js +4 -8
- package/dist/artifact/spec.d.ts +30 -10
- package/dist/assessment/hash.d.ts +251 -213
- package/dist/assessment/item.d.ts +44 -7
- package/dist/assessment/item.js +19 -9
- package/dist/assessment/joint.d.ts +62 -0
- package/dist/assessment/joint.js +85 -0
- package/dist/assessment/paper.d.ts +22 -2
- package/dist/assessment/profile.d.ts +6 -0
- package/dist/assessment/scoring.d.ts +55 -2
- package/dist/assessment/scoring.js +63 -8
- package/dist/assessment/stimulus.d.ts +3 -3
- package/dist/assessment/stimulus.js +2 -2
- package/dist/errors.d.ts +3 -1
- package/dist/graph/family.d.ts +6 -2
- package/dist/graph/identity.d.ts +3 -1
- package/dist/hash/digest.d.ts +10 -0
- package/dist/hash/digest.js +40 -0
- package/dist/hash/stream.d.ts +12 -0
- package/dist/hash/stream.js +27 -0
- package/dist/hash/text.d.ts +3 -1
- package/dist/hash/text.js +2 -15
- package/dist/locale.d.ts +9 -0
- package/dist/locale.js +25 -1
- package/dist/preview/auth.d.ts +4 -2
- package/dist/preview/auth.js +26 -12
- package/dist/program/snapshot/digest.d.ts +3 -1
- package/dist/program/snapshot/digest.js +14 -22
- package/dist/program/snapshot/hash.d.ts +6 -2
- package/dist/program/snapshot/hash.js +10 -21
- package/dist/projection/digest.d.ts +11 -9
- package/dist/projection/digest.js +23 -32
- package/dist/projection/hash.d.ts +222 -2
- package/dist/projection/hash.js +6 -8
- package/dist/projection/verify.d.ts +16 -6
- package/dist/question/item.d.ts +3 -1
- package/dist/question/item.js +3 -1
- package/dist/quran/notes.d.ts +3 -1
- package/dist/quran/provenance.d.ts +6 -2
- package/dist/quran/provenance.js +8 -15
- package/dist/quran/snapshot/digest.d.ts +9 -5
- package/dist/quran/snapshot/digest.js +33 -41
- package/dist/quran/snapshot/hash.d.ts +3 -1
- package/dist/quran/snapshot/hash.js +9 -15
- package/dist/quran/snapshot/row/hash.d.ts +3 -1
- package/dist/quran/snapshot/row/hash.js +2 -8
- package/dist/release/digest.d.ts +10 -8
- package/dist/release/digest.js +22 -31
- package/dist/release/hash.d.ts +3 -1
- package/dist/release/hash.js +3 -8
- package/dist/release/items.d.ts +25 -9
- package/dist/release/items.js +12 -3
- package/dist/release/policy.d.ts +3 -1
- package/dist/release/result/digest.d.ts +23 -13
- package/dist/release/result/digest.js +20 -29
- package/dist/release/rollback/digest.d.ts +16 -10
- package/dist/release/rollback/digest.js +25 -32
- package/dist/release/route/digest.d.ts +10 -8
- package/dist/release/route/digest.js +22 -31
- package/dist/release/route/verify.d.ts +16 -6
- package/dist/release/route/verify.js +8 -2
- package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
- package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
- package/dist/release/snapshot/evidence/tryout.js +1 -1
- package/dist/release/snapshot/evidence.d.ts +1 -1
- package/dist/release/snapshot/verify.d.ts +19 -7
- package/dist/release/snapshot/verify.js +20 -18
- package/dist/release/verify.d.ts +9 -3
- package/dist/renderer/compatibility.d.ts +6 -2
- package/dist/renderer/compatibility.js +3 -1
- package/dist/renderer/contract.d.ts +9 -3
- package/dist/renderer/contract.js +3 -1
- package/dist/runtime/error.d.ts +3 -1
- package/dist/runtime/protected/verify.d.ts +1 -1
- package/dist/runtime/verify.d.ts +2 -2
- package/dist/runtime/verify.js +2 -1
- package/dist/signature/key.d.ts +21 -0
- package/dist/signature/key.js +104 -0
- package/dist/signature/spec.d.ts +18 -6
- package/dist/signature/spec.js +16 -4
- package/dist/transport/request.d.ts +728 -728
- package/dist/transport/response.d.ts +26 -26
- package/dist/tryout/canonical.d.ts +11 -1
- package/dist/tryout/canonical.js +6 -10
- package/dist/tryout/closure/accounting.d.ts +3 -1
- package/dist/tryout/digest.d.ts +12 -6
- package/dist/tryout/digest.js +21 -14
- package/dist/tryout/hash/catalog.d.ts +228 -3
- package/dist/tryout/hash/catalog.js +5 -7
- package/dist/tryout/hash/content.d.ts +113 -2
- package/dist/tryout/hash/content.js +10 -8
- package/dist/tryout/hash/placement.d.ts +236 -5
- package/dist/tryout/hash/placement.js +7 -8
- package/dist/tryout/runtime/hash.d.ts +3 -1
- package/dist/tryout/runtime/hash.js +3 -1
- package/dist/tryout/runtime/source.d.ts +3 -1
- package/dist/tryout/runtime/verify.d.ts +13 -5
- package/dist/tryout/runtime/verify.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -1
- package/dist/tryout/snapshot/hash.d.ts +45 -4
- package/dist/tryout/snapshot/hash.js +9 -7
- package/package.json +22 -2
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { ArtifactHashComputationError, ArtifactHashMismatchError, ArtifactVerificationDecodeError } from "#contracts/artifact/spec";
|
|
3
|
-
import { type CompiledContentPayload } from "#contracts/content";
|
|
4
3
|
/** Computes the immutable identity of one canonical compiled payload. */
|
|
5
|
-
export declare
|
|
4
|
+
export declare const hashCompiledContentPayload: (payload: {
|
|
5
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
6
|
+
readonly byteLength: number;
|
|
7
|
+
readonly compiledCode: string;
|
|
8
|
+
readonly compilerConfigHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
9
|
+
readonly compilerVersion: "0.1.0";
|
|
10
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
11
|
+
readonly format: "mdx-function-body";
|
|
12
|
+
readonly mdxCompilerVersion: "3.1.1";
|
|
13
|
+
readonly plainText: string;
|
|
14
|
+
readonly rawMdx: string;
|
|
15
|
+
readonly rendererDomain: "ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math";
|
|
16
|
+
readonly requiredComponents: readonly string[];
|
|
17
|
+
readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
18
|
+
}) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ArtifactHashComputationError, never>;
|
|
6
19
|
/** Strictly authenticates artifact integrity without renderer compatibility. */
|
|
7
20
|
export declare const verifySignedContentArtifactIntegrity: (input: unknown) => Effect.Effect<{
|
|
8
21
|
readonly artifactHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Effect, Schema } from "effect";
|
|
3
2
|
import { validateArtifactByteIntegrity } from "#contracts/artifact/limits";
|
|
4
3
|
import { verifyCompiledContentSourceHash } from "#contracts/artifact/source";
|
|
5
4
|
import { ArtifactHashComputationError, ArtifactHashMismatchError, ArtifactVerificationDecodeError, } from "#contracts/artifact/spec";
|
|
6
5
|
import { canonicalizeCompiledContentPayload, canonicalizeContentArtifactSigningInput, SignedContentArtifactSchema, } from "#contracts/content";
|
|
7
|
-
import {
|
|
6
|
+
import { hashText } from "#contracts/hash/text";
|
|
8
7
|
import { verifyEd25519Signature } from "#contracts/signature/verify";
|
|
9
8
|
/** Computes the immutable identity of one canonical compiled payload. */
|
|
10
|
-
export
|
|
11
|
-
return Sha256HashSchema.make(`sha256:${createHash("sha256")
|
|
12
|
-
.update(canonicalizeCompiledContentPayload(payload))
|
|
13
|
-
.digest("hex")}`);
|
|
14
|
-
}
|
|
15
|
-
/** Computes an artifact hash while preserving typed computation failures. */
|
|
16
|
-
function hashPayload(payload) {
|
|
17
|
-
return Effect.try({
|
|
18
|
-
catch: () => new ArtifactHashComputationError({ contentKey: payload.contentKey }),
|
|
19
|
-
try: () => hashCompiledContentPayload(payload),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
9
|
+
export const hashCompiledContentPayload = Effect.fn("AksaraContracts.hashCompiledContentPayload")((payload) => hashText(canonicalizeCompiledContentPayload(payload)).pipe(Effect.mapError(() => new ArtifactHashComputationError({ contentKey: payload.contentKey }))));
|
|
22
10
|
/** Confirms that an artifact envelope identifies its canonical payload. */
|
|
23
11
|
function validateArtifactHash(artifact, actualHash) {
|
|
24
12
|
if (artifact.artifactHash === actualHash) {
|
|
@@ -33,7 +21,7 @@ function validateArtifactHash(artifact, actualHash) {
|
|
|
33
21
|
/** Verifies immutable bytes, hashes, source, and signature without a renderer. */
|
|
34
22
|
function authenticateSignedArtifact(artifact) {
|
|
35
23
|
return Effect.gen(function* () {
|
|
36
|
-
const actualHash = yield*
|
|
24
|
+
const actualHash = yield* hashCompiledContentPayload(artifact.payload);
|
|
37
25
|
yield* validateArtifactHash(artifact, actualHash);
|
|
38
26
|
yield* verifyEd25519Signature({
|
|
39
27
|
keyId: artifact.keyId,
|
package/dist/artifact/limits.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
1
|
import { Effect } from "effect";
|
|
3
2
|
import { ArtifactCompiledByteLengthMismatchError, ArtifactPayloadFieldByteLimitError, ArtifactVerificationByteLimitError, } from "#contracts/artifact/spec";
|
|
4
3
|
import { canonicalizeCompiledContentPayload, canonicalizeSignedContentArtifact, } from "#contracts/content";
|
|
5
4
|
import { MAX_CANONICAL_PAYLOAD_BYTES, MAX_COMPILED_CODE_BYTES, MAX_PLAIN_TEXT_BYTES, MAX_RAW_MDX_BYTES, MAX_SIGNED_ARTIFACT_BYTES, } from "#contracts/limits";
|
|
6
5
|
/** Rejects a complete signed artifact envelope above its wire ceiling. */
|
|
7
6
|
function enforceSignedWireLimit(artifact) {
|
|
8
|
-
const actualBytes =
|
|
7
|
+
const actualBytes = new TextEncoder().encode(canonicalizeSignedContentArtifact(artifact)).byteLength;
|
|
9
8
|
if (actualBytes <= MAX_SIGNED_ARTIFACT_BYTES) {
|
|
10
9
|
return Effect.void;
|
|
11
10
|
}
|
|
@@ -16,7 +15,7 @@ function enforceSignedWireLimit(artifact) {
|
|
|
16
15
|
}
|
|
17
16
|
/** Rejects one authenticated payload field above its shared ceiling. */
|
|
18
17
|
function enforcePayloadFieldLimit(payload, field, value, maxBytes) {
|
|
19
|
-
const actualBytes =
|
|
18
|
+
const actualBytes = new TextEncoder().encode(value).byteLength;
|
|
20
19
|
if (actualBytes <= maxBytes) {
|
|
21
20
|
return Effect.void;
|
|
22
21
|
}
|
|
@@ -31,7 +30,7 @@ function enforcePayloadFieldLimit(payload, field, value, maxBytes) {
|
|
|
31
30
|
export const validateArtifactByteIntegrity = Effect.fn("AksaraContracts.validateArtifactByteIntegrity")(function* (artifact) {
|
|
32
31
|
yield* enforceSignedWireLimit(artifact);
|
|
33
32
|
const { payload } = artifact;
|
|
34
|
-
const compiledBytes =
|
|
33
|
+
const compiledBytes = new TextEncoder().encode(payload.compiledCode).byteLength;
|
|
35
34
|
if (payload.byteLength !== compiledBytes) {
|
|
36
35
|
return yield* new ArtifactCompiledByteLengthMismatchError({
|
|
37
36
|
actualBytes: compiledBytes,
|
package/dist/artifact/source.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Effect } from "effect";
|
|
3
2
|
import { ArtifactSourceHashComputationError, ArtifactSourceHashMismatchError, } from "#contracts/artifact/spec";
|
|
4
|
-
import {
|
|
3
|
+
import { hashText } from "#contracts/hash/text";
|
|
5
4
|
/** Computes the authenticated hash of the complete authored MDX source. */
|
|
6
5
|
function hashAuthoredSource(payload) {
|
|
7
|
-
return Effect.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}),
|
|
11
|
-
try: () => Sha256HashSchema.make(`sha256:${createHash("sha256").update(payload.rawMdx).digest("hex")}`),
|
|
12
|
-
});
|
|
6
|
+
return hashText(payload.rawMdx).pipe(Effect.mapError(() => new ArtifactSourceHashComputationError({
|
|
7
|
+
contentKey: payload.contentKey,
|
|
8
|
+
})));
|
|
13
9
|
}
|
|
14
10
|
/** Verifies that sourceHash identifies the complete authenticated raw MDX. */
|
|
15
11
|
export const verifyCompiledContentSourceHash = Effect.fn("AksaraContracts.verifyCompiledContentSourceHash")((payload) => hashAuthoredSource(payload).pipe(Effect.flatMap((actualHash) => {
|
package/dist/artifact/spec.d.ts
CHANGED
|
@@ -35,14 +35,18 @@ export declare const ArtifactVerificationRequestSchema: Schema.Struct<{
|
|
|
35
35
|
export type ArtifactVerificationRequest = typeof ArtifactVerificationRequestSchema.Type;
|
|
36
36
|
declare const ArtifactVerificationDecodeError_base: Schema.Class<ArtifactVerificationDecodeError, Schema.TaggedStruct<"ArtifactVerificationDecodeError", {
|
|
37
37
|
readonly message: Schema.Literal<"Artifact verification input does not satisfy its exact wire contract.">;
|
|
38
|
-
}>, import("effect/Cause").YieldableError
|
|
38
|
+
}>, import("effect/Cause").YieldableError & {
|
|
39
|
+
readonly brand: unique symbol;
|
|
40
|
+
}>;
|
|
39
41
|
/** Unknown artifact input did not exactly satisfy the verification contract. */
|
|
40
42
|
export declare class ArtifactVerificationDecodeError extends ArtifactVerificationDecodeError_base {
|
|
41
43
|
}
|
|
42
44
|
declare const ArtifactVerificationByteLimitError_base: Schema.Class<ArtifactVerificationByteLimitError, Schema.TaggedStruct<"ArtifactVerificationByteLimitError", {
|
|
43
45
|
readonly actualBytes: Schema.Finite;
|
|
44
46
|
readonly maxBytes: Schema.Finite;
|
|
45
|
-
}>, import("effect/Cause").YieldableError
|
|
47
|
+
}>, import("effect/Cause").YieldableError & {
|
|
48
|
+
readonly brand: unique symbol;
|
|
49
|
+
}>;
|
|
46
50
|
/** A signed artifact exceeded the canonical UTF-8 wire ceiling. */
|
|
47
51
|
export declare class ArtifactVerificationByteLimitError extends ArtifactVerificationByteLimitError_base {
|
|
48
52
|
}
|
|
@@ -50,7 +54,9 @@ declare const ArtifactCompiledByteLengthMismatchError_base: Schema.Class<Artifac
|
|
|
50
54
|
readonly actualBytes: Schema.Finite;
|
|
51
55
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
52
56
|
readonly declaredBytes: Schema.Finite;
|
|
53
|
-
}>, import("effect/Cause").YieldableError
|
|
57
|
+
}>, import("effect/Cause").YieldableError & {
|
|
58
|
+
readonly brand: unique symbol;
|
|
59
|
+
}>;
|
|
54
60
|
/** Declared compiled bytes differ from the authenticated function body. */
|
|
55
61
|
export declare class ArtifactCompiledByteLengthMismatchError extends ArtifactCompiledByteLengthMismatchError_base {
|
|
56
62
|
}
|
|
@@ -59,13 +65,17 @@ declare const ArtifactPayloadFieldByteLimitError_base: Schema.Class<ArtifactPayl
|
|
|
59
65
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
60
66
|
readonly field: Schema.Literals<readonly ["rawMdx", "compiledCode", "plainText", "canonicalPayload"]>;
|
|
61
67
|
readonly maxBytes: Schema.Finite;
|
|
62
|
-
}>, import("effect/Cause").YieldableError
|
|
68
|
+
}>, import("effect/Cause").YieldableError & {
|
|
69
|
+
readonly brand: unique symbol;
|
|
70
|
+
}>;
|
|
63
71
|
/** One authenticated payload field exceeded its shared runtime ceiling. */
|
|
64
72
|
export declare class ArtifactPayloadFieldByteLimitError extends ArtifactPayloadFieldByteLimitError_base {
|
|
65
73
|
}
|
|
66
74
|
declare const ArtifactHashComputationError_base: Schema.Class<ArtifactHashComputationError, Schema.TaggedStruct<"ArtifactHashComputationError", {
|
|
67
75
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
68
|
-
}>, import("effect/Cause").YieldableError
|
|
76
|
+
}>, import("effect/Cause").YieldableError & {
|
|
77
|
+
readonly brand: unique symbol;
|
|
78
|
+
}>;
|
|
69
79
|
/** SHA-256 computation failed before authenticity could be established. */
|
|
70
80
|
export declare class ArtifactHashComputationError extends ArtifactHashComputationError_base {
|
|
71
81
|
}
|
|
@@ -73,13 +83,17 @@ declare const ArtifactHashMismatchError_base: Schema.Class<ArtifactHashMismatchE
|
|
|
73
83
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
74
84
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
75
85
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
76
|
-
}>, import("effect/Cause").YieldableError
|
|
86
|
+
}>, import("effect/Cause").YieldableError & {
|
|
87
|
+
readonly brand: unique symbol;
|
|
88
|
+
}>;
|
|
77
89
|
/** The signed artifact hash does not identify its canonical payload. */
|
|
78
90
|
export declare class ArtifactHashMismatchError extends ArtifactHashMismatchError_base {
|
|
79
91
|
}
|
|
80
92
|
declare const ArtifactSourceHashComputationError_base: Schema.Class<ArtifactSourceHashComputationError, Schema.TaggedStruct<"ArtifactSourceHashComputationError", {
|
|
81
93
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
82
|
-
}>, import("effect/Cause").YieldableError
|
|
94
|
+
}>, import("effect/Cause").YieldableError & {
|
|
95
|
+
readonly brand: unique symbol;
|
|
96
|
+
}>;
|
|
83
97
|
/** SHA-256 could not be calculated for the authenticated authored source. */
|
|
84
98
|
export declare class ArtifactSourceHashComputationError extends ArtifactSourceHashComputationError_base {
|
|
85
99
|
}
|
|
@@ -87,21 +101,27 @@ declare const ArtifactSourceHashMismatchError_base: Schema.Class<ArtifactSourceH
|
|
|
87
101
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
88
102
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
89
103
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
90
|
-
}>, import("effect/Cause").YieldableError
|
|
104
|
+
}>, import("effect/Cause").YieldableError & {
|
|
105
|
+
readonly brand: unique symbol;
|
|
106
|
+
}>;
|
|
91
107
|
/** The authenticated source hash does not identify the complete raw MDX. */
|
|
92
108
|
export declare class ArtifactSourceHashMismatchError extends ArtifactSourceHashMismatchError_base {
|
|
93
109
|
}
|
|
94
110
|
declare const ArtifactRendererComponentMissingError_base: Schema.Class<ArtifactRendererComponentMissingError, Schema.TaggedStruct<"ArtifactRendererComponentMissingError", {
|
|
95
111
|
readonly componentName: Schema.String;
|
|
96
112
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
97
|
-
}>, import("effect/Cause").YieldableError
|
|
113
|
+
}>, import("effect/Cause").YieldableError & {
|
|
114
|
+
readonly brand: unique symbol;
|
|
115
|
+
}>;
|
|
98
116
|
/** A custom component required by the artifact is absent from the renderer. */
|
|
99
117
|
export declare class ArtifactRendererComponentMissingError extends ArtifactRendererComponentMissingError_base {
|
|
100
118
|
}
|
|
101
119
|
declare const ArtifactRendererDomainUnpublishedError_base: Schema.Class<ArtifactRendererDomainUnpublishedError, Schema.TaggedStruct<"ArtifactRendererDomainUnpublishedError", {
|
|
102
120
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
103
121
|
readonly rendererDomain: Schema.Literals<readonly ["ai-ds", "biology", "chemistry", "mathematics", "physics", "politics", "site", "snbt-general", "snbt-math", "snbt-plain", "snbt-quant", "tka-math"]>;
|
|
104
|
-
}>, import("effect/Cause").YieldableError
|
|
122
|
+
}>, import("effect/Cause").YieldableError & {
|
|
123
|
+
readonly brand: unique symbol;
|
|
124
|
+
}>;
|
|
105
125
|
/** The deployed Nakafa app cannot route this artifact's renderer domain. */
|
|
106
126
|
export declare class ArtifactRendererDomainUnpublishedError extends ArtifactRendererDomainUnpublishedError_base {
|
|
107
127
|
}
|