@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.
Files changed (105) hide show
  1. package/dist/artifact/integrity.d.ts +15 -2
  2. package/dist/artifact/integrity.js +3 -15
  3. package/dist/artifact/limits.js +3 -4
  4. package/dist/artifact/source.js +4 -8
  5. package/dist/artifact/spec.d.ts +30 -10
  6. package/dist/assessment/hash.d.ts +251 -213
  7. package/dist/assessment/item.d.ts +44 -7
  8. package/dist/assessment/item.js +19 -9
  9. package/dist/assessment/joint.d.ts +62 -0
  10. package/dist/assessment/joint.js +85 -0
  11. package/dist/assessment/paper.d.ts +22 -2
  12. package/dist/assessment/profile.d.ts +6 -0
  13. package/dist/assessment/scoring.d.ts +55 -2
  14. package/dist/assessment/scoring.js +63 -8
  15. package/dist/assessment/stimulus.d.ts +3 -3
  16. package/dist/assessment/stimulus.js +2 -2
  17. package/dist/errors.d.ts +3 -1
  18. package/dist/graph/family.d.ts +6 -2
  19. package/dist/graph/identity.d.ts +3 -1
  20. package/dist/hash/digest.d.ts +10 -0
  21. package/dist/hash/digest.js +40 -0
  22. package/dist/hash/stream.d.ts +12 -0
  23. package/dist/hash/stream.js +27 -0
  24. package/dist/hash/text.d.ts +3 -1
  25. package/dist/hash/text.js +2 -15
  26. package/dist/locale.d.ts +9 -0
  27. package/dist/locale.js +25 -1
  28. package/dist/preview/auth.d.ts +4 -2
  29. package/dist/preview/auth.js +26 -12
  30. package/dist/program/snapshot/digest.d.ts +3 -1
  31. package/dist/program/snapshot/digest.js +14 -22
  32. package/dist/program/snapshot/hash.d.ts +6 -2
  33. package/dist/program/snapshot/hash.js +10 -21
  34. package/dist/projection/digest.d.ts +11 -9
  35. package/dist/projection/digest.js +23 -32
  36. package/dist/projection/hash.d.ts +222 -2
  37. package/dist/projection/hash.js +6 -8
  38. package/dist/projection/verify.d.ts +16 -6
  39. package/dist/question/item.d.ts +3 -1
  40. package/dist/question/item.js +3 -1
  41. package/dist/quran/notes.d.ts +3 -1
  42. package/dist/quran/provenance.d.ts +6 -2
  43. package/dist/quran/provenance.js +8 -15
  44. package/dist/quran/snapshot/digest.d.ts +9 -5
  45. package/dist/quran/snapshot/digest.js +33 -41
  46. package/dist/quran/snapshot/hash.d.ts +3 -1
  47. package/dist/quran/snapshot/hash.js +9 -15
  48. package/dist/quran/snapshot/row/hash.d.ts +3 -1
  49. package/dist/quran/snapshot/row/hash.js +2 -8
  50. package/dist/release/digest.d.ts +10 -8
  51. package/dist/release/digest.js +22 -31
  52. package/dist/release/hash.d.ts +3 -1
  53. package/dist/release/hash.js +3 -8
  54. package/dist/release/items.d.ts +25 -9
  55. package/dist/release/items.js +12 -3
  56. package/dist/release/policy.d.ts +3 -1
  57. package/dist/release/result/digest.d.ts +23 -13
  58. package/dist/release/result/digest.js +20 -29
  59. package/dist/release/rollback/digest.d.ts +16 -10
  60. package/dist/release/rollback/digest.js +25 -32
  61. package/dist/release/route/digest.d.ts +10 -8
  62. package/dist/release/route/digest.js +22 -31
  63. package/dist/release/route/verify.d.ts +16 -6
  64. package/dist/release/route/verify.js +8 -2
  65. package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
  66. package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
  67. package/dist/release/snapshot/evidence/tryout.js +1 -1
  68. package/dist/release/snapshot/evidence.d.ts +1 -1
  69. package/dist/release/snapshot/verify.d.ts +19 -7
  70. package/dist/release/snapshot/verify.js +20 -18
  71. package/dist/release/verify.d.ts +9 -3
  72. package/dist/renderer/compatibility.d.ts +6 -2
  73. package/dist/renderer/compatibility.js +3 -1
  74. package/dist/renderer/contract.d.ts +9 -3
  75. package/dist/renderer/contract.js +3 -1
  76. package/dist/runtime/error.d.ts +3 -1
  77. package/dist/runtime/protected/verify.d.ts +1 -1
  78. package/dist/runtime/verify.d.ts +2 -2
  79. package/dist/runtime/verify.js +2 -1
  80. package/dist/signature/key.d.ts +21 -0
  81. package/dist/signature/key.js +104 -0
  82. package/dist/signature/spec.d.ts +18 -6
  83. package/dist/signature/spec.js +16 -4
  84. package/dist/transport/request.d.ts +728 -728
  85. package/dist/transport/response.d.ts +26 -26
  86. package/dist/tryout/canonical.d.ts +11 -1
  87. package/dist/tryout/canonical.js +6 -10
  88. package/dist/tryout/closure/accounting.d.ts +3 -1
  89. package/dist/tryout/digest.d.ts +12 -6
  90. package/dist/tryout/digest.js +21 -14
  91. package/dist/tryout/hash/catalog.d.ts +228 -3
  92. package/dist/tryout/hash/catalog.js +5 -7
  93. package/dist/tryout/hash/content.d.ts +113 -2
  94. package/dist/tryout/hash/content.js +10 -8
  95. package/dist/tryout/hash/placement.d.ts +236 -5
  96. package/dist/tryout/hash/placement.js +7 -8
  97. package/dist/tryout/runtime/hash.d.ts +3 -1
  98. package/dist/tryout/runtime/hash.js +3 -1
  99. package/dist/tryout/runtime/source.d.ts +3 -1
  100. package/dist/tryout/runtime/verify.d.ts +13 -5
  101. package/dist/tryout/runtime/verify.js +1 -1
  102. package/dist/tryout/scoring.d.ts +3 -1
  103. package/dist/tryout/snapshot/hash.d.ts +45 -4
  104. package/dist/tryout/snapshot/hash.js +9 -7
  105. 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 function hashCompiledContentPayload(payload: CompiledContentPayload): string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
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 { Sha256HashSchema } from "#contracts/ids";
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 function hashCompiledContentPayload(payload) {
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* hashPayload(artifact.payload);
24
+ const actualHash = yield* hashCompiledContentPayload(artifact.payload);
37
25
  yield* validateArtifactHash(artifact, actualHash);
38
26
  yield* verifyEd25519Signature({
39
27
  keyId: artifact.keyId,
@@ -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 = Buffer.byteLength(canonicalizeSignedContentArtifact(artifact), "utf8");
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 = Buffer.byteLength(value, "utf8");
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 = Buffer.byteLength(payload.compiledCode, "utf8");
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,
@@ -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 { Sha256HashSchema } from "#contracts/ids";
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.try({
8
- catch: () => new ArtifactSourceHashComputationError({
9
- contentKey: payload.contentKey,
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) => {
@@ -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
  }