@nakafa/aksara-contracts 0.50.0 → 1.0.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 (111) hide show
  1. package/LICENSE +207 -152
  2. package/README.md +3 -0
  3. package/dist/artifact/integrity.d.ts +33 -8
  4. package/dist/artifact/integrity.js +19 -17
  5. package/dist/artifact/limits.d.ts +13 -7
  6. package/dist/artifact/limits.js +7 -15
  7. package/dist/artifact/source.d.ts +10 -4
  8. package/dist/artifact/source.js +4 -8
  9. package/dist/artifact/spec.d.ts +54 -22
  10. package/dist/artifact/spec.js +7 -8
  11. package/dist/artifact/verify.d.ts +11 -5
  12. package/dist/assessment/hash.d.ts +3 -1
  13. package/dist/assessment/paper.d.ts +3 -1
  14. package/dist/content.d.ts +37 -11
  15. package/dist/content.js +7 -21
  16. package/dist/errors.d.ts +3 -1
  17. package/dist/graph/family.d.ts +6 -2
  18. package/dist/graph/identity.d.ts +3 -1
  19. package/dist/hash/digest.d.ts +10 -0
  20. package/dist/hash/digest.js +40 -0
  21. package/dist/hash/stream.d.ts +12 -0
  22. package/dist/hash/stream.js +27 -0
  23. package/dist/hash/text.d.ts +3 -1
  24. package/dist/hash/text.js +2 -15
  25. package/dist/limits.d.ts +2 -2
  26. package/dist/limits.js +2 -2
  27. package/dist/preview/auth.d.ts +4 -2
  28. package/dist/preview/auth.js +26 -12
  29. package/dist/program/snapshot/digest.d.ts +3 -1
  30. package/dist/program/snapshot/digest.js +14 -22
  31. package/dist/program/snapshot/hash.d.ts +6 -2
  32. package/dist/program/snapshot/hash.js +10 -21
  33. package/dist/projection/digest.d.ts +11 -9
  34. package/dist/projection/digest.js +23 -32
  35. package/dist/projection/hash.d.ts +222 -2
  36. package/dist/projection/hash.js +6 -8
  37. package/dist/projection/verify.d.ts +16 -6
  38. package/dist/question/item.d.ts +3 -1
  39. package/dist/question/item.js +3 -1
  40. package/dist/quran/notes.d.ts +3 -1
  41. package/dist/quran/provenance.d.ts +6 -2
  42. package/dist/quran/provenance.js +8 -15
  43. package/dist/quran/snapshot/digest.d.ts +9 -5
  44. package/dist/quran/snapshot/digest.js +33 -41
  45. package/dist/quran/snapshot/hash.d.ts +3 -1
  46. package/dist/quran/snapshot/hash.js +9 -15
  47. package/dist/quran/snapshot/row/hash.d.ts +3 -1
  48. package/dist/quran/snapshot/row/hash.js +2 -8
  49. package/dist/release/digest.d.ts +10 -8
  50. package/dist/release/digest.js +22 -31
  51. package/dist/release/hash.d.ts +3 -1
  52. package/dist/release/hash.js +3 -8
  53. package/dist/release/items.d.ts +25 -9
  54. package/dist/release/items.js +12 -3
  55. package/dist/release/policy.d.ts +3 -1
  56. package/dist/release/result/digest.d.ts +23 -13
  57. package/dist/release/result/digest.js +20 -29
  58. package/dist/release/rollback/digest.d.ts +16 -10
  59. package/dist/release/rollback/digest.js +25 -32
  60. package/dist/release/rollback/spec.d.ts +102 -24
  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/spec.d.ts +61 -16
  78. package/dist/runtime/protected/verify.d.ts +11 -5
  79. package/dist/runtime/spec.d.ts +44 -12
  80. package/dist/runtime/verify.d.ts +22 -10
  81. package/dist/runtime/verify.js +2 -1
  82. package/dist/signature/key.d.ts +21 -0
  83. package/dist/signature/key.js +104 -0
  84. package/dist/signature/spec.d.ts +18 -6
  85. package/dist/signature/spec.js +16 -4
  86. package/dist/transport/batch.d.ts +34 -8
  87. package/dist/transport/group.d.ts +51 -12
  88. package/dist/transport/request.d.ts +826 -764
  89. package/dist/transport/response.d.ts +148 -58
  90. package/dist/tree.d.ts +52 -0
  91. package/dist/tree.js +162 -0
  92. package/dist/tryout/canonical.d.ts +11 -1
  93. package/dist/tryout/canonical.js +6 -10
  94. package/dist/tryout/closure/accounting.d.ts +3 -1
  95. package/dist/tryout/digest.d.ts +12 -6
  96. package/dist/tryout/digest.js +21 -14
  97. package/dist/tryout/hash/catalog.d.ts +228 -3
  98. package/dist/tryout/hash/catalog.js +5 -7
  99. package/dist/tryout/hash/content.d.ts +113 -2
  100. package/dist/tryout/hash/content.js +10 -8
  101. package/dist/tryout/hash/placement.d.ts +236 -5
  102. package/dist/tryout/hash/placement.js +7 -8
  103. package/dist/tryout/runtime/hash.d.ts +3 -1
  104. package/dist/tryout/runtime/hash.js +3 -1
  105. package/dist/tryout/runtime/source.d.ts +3 -1
  106. package/dist/tryout/runtime/verify.d.ts +13 -5
  107. package/dist/tryout/runtime/verify.js +1 -1
  108. package/dist/tryout/scoring.d.ts +3 -1
  109. package/dist/tryout/snapshot/hash.d.ts +45 -4
  110. package/dist/tryout/snapshot/hash.js +9 -7
  111. package/package.json +22 -2
@@ -2,13 +2,17 @@ import { Effect, Schema, Stream } from "effect";
2
2
  import type { ContentReleaseManifest } from "#contracts/release/spec";
3
3
  declare const ProjectionDecodeError_base: Schema.Class<ProjectionDecodeError, Schema.TaggedStruct<"ProjectionDecodeError", {
4
4
  readonly projectionIndex: Schema.Finite;
5
- }>, import("effect/Cause").YieldableError>;
5
+ }>, import("effect/Cause").YieldableError & {
6
+ readonly brand: unique symbol;
7
+ }>;
6
8
  /** One streamed projection failed strict schema decoding. */
7
9
  export declare class ProjectionDecodeError extends ProjectionDecodeError_base {
8
10
  }
9
11
  declare const ProjectionOrderError_base: Schema.Class<ProjectionOrderError, Schema.TaggedStruct<"ProjectionOrderError", {
10
12
  readonly projectionIndex: Schema.Finite;
11
- }>, import("effect/Cause").YieldableError>;
13
+ }>, import("effect/Cause").YieldableError & {
14
+ readonly brand: unique symbol;
15
+ }>;
12
16
  /** Projections are duplicated or not in canonical content-head order. */
13
17
  export declare class ProjectionOrderError extends ProjectionOrderError_base {
14
18
  }
@@ -16,7 +20,9 @@ declare const ProjectionRouteError_base: Schema.Class<ProjectionRouteError, Sche
16
20
  readonly duplicateIndex: Schema.Finite;
17
21
  readonly firstIndex: Schema.Finite;
18
22
  readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
19
- }>, import("effect/Cause").YieldableError>;
23
+ }>, import("effect/Cause").YieldableError & {
24
+ readonly brand: unique symbol;
25
+ }>;
20
26
  /** Two content projections claim the same locale-specific public route. */
21
27
  export declare class ProjectionRouteError extends ProjectionRouteError_base {
22
28
  }
@@ -24,7 +30,9 @@ declare const ProjectionCountError_base: Schema.Class<ProjectionCountError, Sche
24
30
  readonly actualCount: Schema.Finite;
25
31
  readonly expectedCount: Schema.Finite;
26
32
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
27
- }>, import("effect/Cause").YieldableError>;
33
+ }>, import("effect/Cause").YieldableError & {
34
+ readonly brand: unique symbol;
35
+ }>;
28
36
  /** The streamed projection count differs from the signed manifest. */
29
37
  export declare class ProjectionCountError extends ProjectionCountError_base {
30
38
  }
@@ -32,14 +40,16 @@ declare const ProjectionDigestError_base: Schema.Class<ProjectionDigestError, Sc
32
40
  readonly actualDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
33
41
  readonly expectedDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
34
42
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
35
- }>, import("effect/Cause").YieldableError>;
43
+ }>, import("effect/Cause").YieldableError & {
44
+ readonly brand: unique symbol;
45
+ }>;
36
46
  /** The streamed projection digest differs from the signed manifest. */
37
47
  export declare class ProjectionDigestError extends ProjectionDigestError_base {
38
48
  }
39
49
  declare const VerifiedContentProjectionsSchema: Schema.Struct<{
40
50
  readonly count: Schema.Finite;
41
51
  }>;
42
- /** Count authenticated without retaining complete projection bodies. */
52
+ /** Count authenticated against the signed manifest. The digest holds every canonical byte until its one final call, so its memory grows with the stream. */
43
53
  export type VerifiedContentProjections = typeof VerifiedContentProjectionsSchema.Type;
44
54
  /** Strictly decodes a replayable canonical content projection stream. */
45
55
  export declare function decodeContentProjections<E, R>(projections: Stream.Stream<unknown, E, R>): Stream.Stream<{
@@ -148,7 +148,9 @@ export declare function canonicalQuestionBlueprint(blueprint: QuestionBlueprint)
148
148
  };
149
149
  declare const QuestionResponseLocaleMissingError_base: Schema.Class<QuestionResponseLocaleMissingError, Schema.TaggedStruct<"QuestionResponseLocaleMissingError", {
150
150
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
151
- }>, import("effect/Cause").YieldableError>;
151
+ }>, import("effect/Cause").YieldableError & {
152
+ readonly brand: unique symbol;
153
+ }>;
152
154
  /** One item does not contain the exact artifact locale it must assess. */
153
155
  export declare class QuestionResponseLocaleMissingError extends QuestionResponseLocaleMissingError_base {
154
156
  }
@@ -160,7 +160,9 @@ export function canonicalQuestionBlueprint(blueprint) {
160
160
  };
161
161
  }
162
162
  /** One item does not contain the exact artifact locale it must assess. */
163
- export class QuestionResponseLocaleMissingError extends Schema.TaggedError()("QuestionResponseLocaleMissingError", { artifactLocale: ArtifactLocaleSchema }) {
163
+ export class QuestionResponseLocaleMissingError extends Schema.TaggedError()("QuestionResponseLocaleMissingError", {
164
+ artifactLocale: ArtifactLocaleSchema,
165
+ }) {
164
166
  }
165
167
  /** Resolves and freezes one exact-locale response from an authored item. */
166
168
  export const questionResponseFor = Effect.fn("AksaraContracts.questionResponseFor")(function* (item, artifactLocale) {
@@ -19,7 +19,9 @@ export declare const QuranTranslationDocumentSchema: Schema.Struct<{
19
19
  export type QuranTranslationDocument = typeof QuranTranslationDocumentSchema.Type;
20
20
  declare const QuranTranslationNotesError_base: Schema.Class<QuranTranslationNotesError, Schema.TaggedStruct<"QuranTranslationNotesError", {
21
21
  readonly reason: Schema.Literals<readonly ["empty-note", "invalid-marker", "invalid-source", "mismatched-markers"]>;
22
- }>, import("effect/Cause").YieldableError>;
22
+ }>, import("effect/Cause").YieldableError & {
23
+ readonly brand: unique symbol;
24
+ }>;
23
25
  /** The translation and note markers do not form one exact projection. */
24
26
  export declare class QuranTranslationNotesError extends QuranTranslationNotesError_base {
25
27
  }
@@ -117,11 +117,15 @@ export declare const QuranProvenanceManifestSchema: Schema.Struct<{
117
117
  export type QuranProvenanceManifest = typeof QuranProvenanceManifestSchema.Type;
118
118
  declare const QuranProvenanceCoverageError_base: Schema.Class<QuranProvenanceCoverageError, Schema.TaggedStruct<"QuranProvenanceCoverageError", {
119
119
  readonly actualScopes: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["arabic-text", "metadata"]>, Schema.Literals<readonly ["en-tafsir-access", "de-tafsir-access"]>, Schema.Literal<"id-tafsir">]>, Schema.TemplateLiteral<readonly [Schema.Literals<readonly ["en", "id", "de"]>, "-surah-name"]>, Schema.TemplateLiteral<readonly [Schema.Literals<readonly ["en", "id", "de"]>, "-translation"]>]>>;
120
- }>, import("effect/Cause").YieldableError>;
120
+ }>, import("effect/Cause").YieldableError & {
121
+ readonly brand: unique symbol;
122
+ }>;
121
123
  /** Quran provenance omitted or misordered an active-locale scope. */
122
124
  export declare class QuranProvenanceCoverageError extends QuranProvenanceCoverageError_base {
123
125
  }
124
- declare const QuranProvenanceHashError_base: Schema.Class<QuranProvenanceHashError, Schema.TaggedStruct<"QuranProvenanceHashError", {}>, import("effect/Cause").YieldableError>;
126
+ declare const QuranProvenanceHashError_base: Schema.Class<QuranProvenanceHashError, Schema.TaggedStruct<"QuranProvenanceHashError", {}>, import("effect/Cause").YieldableError & {
127
+ readonly brand: unique symbol;
128
+ }>;
125
129
  /** Node could not compute the deterministic provenance digest. */
126
130
  export declare class QuranProvenanceHashError extends QuranProvenanceHashError_base {
127
131
  }
@@ -1,5 +1,5 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Array as Arr, Effect, MutableList, Schema } from "effect";
2
+ import { hashText } from "#contracts/hash/text";
3
3
  import { Sha256HashSchema } from "#contracts/ids";
4
4
  import { ActiveAppLocaleListSchema, AppLocaleSchema, ENGLISH_APP_LOCALE_CODE, GERMAN_APP_LOCALE_CODE, INDONESIAN_APP_LOCALE_CODE, } from "#contracts/locale";
5
5
  import { canonicalizeQuranAttribution } from "#contracts/quran/attribution";
@@ -116,20 +116,13 @@ export function canonicalizeQuranProvenance(record) {
116
116
  });
117
117
  }
118
118
  /** Digests exact ordered provenance records under their active locale set. */
119
- export const hashQuranProvenance = Effect.fn("AksaraContracts.hashQuranProvenance")((input) => Effect.try({
120
- catch: () => new QuranProvenanceHashError(),
121
- try: () => {
122
- const hash = createHash("sha256")
123
- .update(`${PROVENANCE_DOMAIN}\n`)
124
- .update(encodeJsonText(input.activeAppLocales))
125
- .update("\n");
126
- for (const record of input.records) {
127
- hash.update(canonicalizeQuranProvenance(record));
128
- hash.update("\n");
129
- }
130
- return Sha256HashSchema.make(`sha256:${hash.digest("hex")}`);
131
- },
132
- }));
119
+ export const hashQuranProvenance = Effect.fn("AksaraContracts.hashQuranProvenance")(function* (input) {
120
+ let canonical = `${PROVENANCE_DOMAIN}\n${encodeJsonText(input.activeAppLocales)}\n`;
121
+ for (const record of input.records) {
122
+ canonical += `${canonicalizeQuranProvenance(record)}\n`;
123
+ }
124
+ return yield* hashText(canonical).pipe(Effect.mapError(() => new QuranProvenanceHashError()));
125
+ });
133
126
  /** Builds a snapshot provenance gate from exact reviewed source records. */
134
127
  export const makeQuranProvenanceManifest = Effect.fn("AksaraContracts.makeQuranProvenanceManifest")(function* (input) {
135
128
  const decoded = yield* Schema.decodeUnknownEffect(Schema.Struct({
@@ -5,14 +5,18 @@ import { QuranRowHashError } from "#contracts/quran/snapshot/row/hash";
5
5
  declare const QuranRowIntegrityError_base: Schema.Class<QuranRowIntegrityError, Schema.TaggedStruct<"QuranRowIntegrityError", {
6
6
  readonly actual: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
7
7
  readonly expected: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
8
- }>, import("effect/Cause").YieldableError>;
8
+ }>, import("effect/Cause").YieldableError & {
9
+ readonly brand: unique symbol;
10
+ }>;
9
11
  /** A current row hash does not authenticate its structured payload. */
10
12
  export declare class QuranRowIntegrityError extends QuranRowIntegrityError_base {
11
13
  }
12
14
  declare const QuranRowOrderError_base: Schema.Class<QuranRowOrderError, Schema.TaggedStruct<"QuranRowOrderError", {
13
15
  readonly actual: Schema.String;
14
16
  readonly expected: Schema.String;
15
- }>, import("effect/Cause").YieldableError>;
17
+ }>, import("effect/Cause").YieldableError & {
18
+ readonly brand: unique symbol;
19
+ }>;
16
20
  /** A current row does not match the next deterministic snapshot identity. */
17
21
  export declare class QuranRowOrderError extends QuranRowOrderError_base {
18
22
  }
@@ -21,13 +25,13 @@ export declare const digestQuranRows: <E, R>(input: {
21
25
  readonly activeAppLocales: ActiveAppLocaleList;
22
26
  readonly rows: Stream.Stream<Pick<QuranSnapshotRow, "payload" | "rowHash">, E, R>;
23
27
  }) => Effect.Effect<{
28
+ projectionDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
29
+ runtimeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
30
+ searchDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
24
31
  attributionCount: number;
25
32
  chunkCount: number;
26
33
  projectionCount: number;
27
- projectionDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
28
34
  runtimeCount: number;
29
- runtimeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
30
35
  searchCount: number;
31
- searchDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
32
36
  }, E | QuranRowHashError | QuranRowIntegrityError | QuranRowOrderError, R>;
33
37
  export {};
@@ -1,5 +1,5 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Array as Arr, Effect, Option, Schema, Stream } from "effect";
2
+ import { DigestStream } from "#contracts/hash/stream";
3
3
  import { Sha256HashSchema } from "#contracts/ids";
4
4
  import { AppLocaleSchema } from "#contracts/locale";
5
5
  import { hashQuranRow, QuranRowHashError, } from "#contracts/quran/snapshot/row/hash";
@@ -25,10 +25,6 @@ export class QuranRowOrderError extends Schema.TaggedError()("QuranRowOrderError
25
25
  function joinIdentity(parts) {
26
26
  return Arr.join(Arr.map(parts, String), ":");
27
27
  }
28
- /** Formats one finished digest as the signed sha256 hash of a Quran domain. */
29
- function sha256Digest(hash) {
30
- return Sha256HashSchema.make(`sha256:${hash.digest("hex")}`);
31
- }
32
28
  /** Resolves one complete stable current row identity. */
33
29
  function rowIdentity(payload) {
34
30
  if (payload.kind === "quran-attribution") {
@@ -62,9 +58,9 @@ function rowIdentity(payload) {
62
58
  /** Keeps current locale closure and digest state private to one replay. */
63
59
  class QuranDigestState {
64
60
  #activeAppLocales;
65
- #runtime = createHash("sha256").update(`${RUNTIME_DOMAIN}\n`);
66
- #search = createHash("sha256").update(`${SEARCH_DOMAIN}\n`);
67
- #projection = createHash("sha256").update(`${PROJECTION_DOMAIN}\n`);
61
+ #runtime = new DigestStream();
62
+ #search = new DigestStream();
63
+ #projection = new DigestStream();
68
64
  #nextQuranNumber = 1;
69
65
  #nextSearchLocale;
70
66
  #nextSearchSurah = 1;
@@ -76,10 +72,13 @@ class QuranDigestState {
76
72
  projectionCount = 0;
77
73
  runtimeCount = 0;
78
74
  searchCount = 0;
79
- /** Initializes one isolated replay under the signed active locale set. */
75
+ /** Starts one isolated replay under the signed active locale set. */
80
76
  constructor(activeAppLocales) {
81
77
  this.#activeAppLocales = activeAppLocales;
82
78
  this.#nextSearchLocale = activeAppLocales[0];
79
+ this.#runtime.add(`${RUNTIME_DOMAIN}\n`);
80
+ this.#search.add(`${SEARCH_DOMAIN}\n`);
81
+ this.#projection.add(`${PROJECTION_DOMAIN}\n`);
83
82
  }
84
83
  /** Returns the only row identity valid at the current stream position. */
85
84
  expectedIdentity() {
@@ -164,25 +163,22 @@ class QuranDigestState {
164
163
  }
165
164
  this.advance(row.payload);
166
165
  const canonical = `${row.payload.kind}\n${row.rowHash}\n`;
167
- return Effect.try({
168
- catch: () => new QuranRowHashError({ scope: "row" }),
169
- try: () => {
170
- this.#projection.update(canonical);
171
- this.projectionCount += 1;
172
- if (row.payload.kind === "quran-search") {
173
- this.#search.update(canonical);
174
- this.searchCount += 1;
175
- return;
176
- }
177
- this.#runtime.update(canonical);
178
- this.runtimeCount += 1;
179
- if (row.payload.kind === "quran-attribution") {
180
- this.attributionCount += 1;
181
- }
182
- if (row.payload.kind === "quran-chunk") {
183
- this.chunkCount += 1;
184
- }
185
- },
166
+ return Effect.sync(() => {
167
+ this.#projection.add(canonical);
168
+ this.projectionCount += 1;
169
+ if (row.payload.kind === "quran-search") {
170
+ this.#search.add(canonical);
171
+ this.searchCount += 1;
172
+ return;
173
+ }
174
+ this.#runtime.add(canonical);
175
+ this.runtimeCount += 1;
176
+ if (row.payload.kind === "quran-attribution") {
177
+ this.attributionCount += 1;
178
+ }
179
+ if (row.payload.kind === "quran-chunk") {
180
+ this.chunkCount += 1;
181
+ }
186
182
  });
187
183
  }
188
184
  /** Rejects an incomplete stream before consuming digest state. */
@@ -204,16 +200,18 @@ class QuranDigestState {
204
200
  }
205
201
  /** Finalizes all ordered current Quran digest domains. */
206
202
  digest() {
207
- return {
203
+ return Effect.all({
204
+ projectionDigest: this.#projection.digest(),
205
+ runtimeDigest: this.#runtime.digest(),
206
+ searchDigest: this.#search.digest(),
207
+ }).pipe(Effect.map((digests) => ({
208
208
  attributionCount: this.attributionCount,
209
209
  chunkCount: this.chunkCount,
210
210
  projectionCount: this.projectionCount,
211
- projectionDigest: sha256Digest(this.#projection),
212
211
  runtimeCount: this.runtimeCount,
213
- runtimeDigest: sha256Digest(this.#runtime),
214
212
  searchCount: this.searchCount,
215
- searchDigest: sha256Digest(this.#search),
216
- };
213
+ ...digests,
214
+ })), Effect.mapError(() => new QuranRowHashError({ scope: "row" })));
217
215
  }
218
216
  }
219
217
  /** Authenticates one current row before advancing ordered state. */
@@ -229,14 +227,8 @@ const updateQuranDigest = Effect.fn("AksaraContracts.updateQuranDigest")(functio
229
227
  });
230
228
  /** Digests authenticated current rows under one active locale set. */
231
229
  export const digestQuranRows = Effect.fn("AksaraContracts.digestQuranRows")(function* (input) {
232
- const state = yield* Effect.try({
233
- catch: () => new QuranRowHashError({ scope: "row" }),
234
- try: () => new QuranDigestState(input.activeAppLocales),
235
- });
230
+ const state = new QuranDigestState(input.activeAppLocales);
236
231
  yield* input.rows.pipe(Stream.runForEach((row) => updateQuranDigest(state, row)));
237
232
  yield* state.validateComplete();
238
- return yield* Effect.try({
239
- catch: () => new QuranRowHashError({ scope: "row" }),
240
- try: () => state.digest(),
241
- });
233
+ return yield* state.digest();
242
234
  });
@@ -1,6 +1,8 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { type QuranSnapshot, type QuranSnapshotFacts } from "#contracts/quran/snapshot/spec";
3
- declare const QuranSnapshotHashError_base: Schema.Class<QuranSnapshotHashError, Schema.TaggedStruct<"QuranSnapshotHashError", {}>, import("effect/Cause").YieldableError>;
3
+ declare const QuranSnapshotHashError_base: Schema.Class<QuranSnapshotHashError, Schema.TaggedStruct<"QuranSnapshotHashError", {}>, import("effect/Cause").YieldableError & {
4
+ readonly brand: unique symbol;
5
+ }>;
4
6
  /** Node could not compute a deterministic Quran snapshot identity. */
5
7
  export declare class QuranSnapshotHashError extends QuranSnapshotHashError_base {
6
8
  }
@@ -1,6 +1,5 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Effect, Schema } from "effect";
3
- import { Sha256HashSchema } from "#contracts/ids";
2
+ import { hashText } from "#contracts/hash/text";
4
3
  import { QURAN_SNAPSHOT_FORMAT, QuranSnapshotSchema, } from "#contracts/quran/snapshot/spec";
5
4
  import { encodeJsonText } from "#contracts/text/json";
6
5
  const SNAPSHOT_DOMAIN = "nakafa.aksara.localized-quran-snapshot";
@@ -31,19 +30,14 @@ export function canonicalizeQuranSnapshot(input) {
31
30
  });
32
31
  }
33
32
  /** Creates the content-addressed identity of one complete Quran snapshot. */
34
- export const makeQuranSnapshot = Effect.fn("AksaraContracts.makeQuranSnapshot")((input) => Effect.try({
35
- catch: () => new QuranSnapshotHashError(),
36
- try: () => {
37
- const snapshotId = Sha256HashSchema.make(`sha256:${createHash("sha256")
38
- .update(`${SNAPSHOT_DOMAIN}\n${canonicalizeQuranSnapshot(input)}`)
39
- .digest("hex")}`);
40
- return QuranSnapshotSchema.make({
41
- ...input,
42
- format: QURAN_SNAPSHOT_FORMAT,
43
- snapshotId,
44
- });
45
- },
46
- }));
33
+ export const makeQuranSnapshot = Effect.fn("AksaraContracts.makeQuranSnapshot")(function* (input) {
34
+ const snapshotId = yield* hashText(`${SNAPSHOT_DOMAIN}\n${canonicalizeQuranSnapshot(input)}`).pipe(Effect.mapError(() => new QuranSnapshotHashError()));
35
+ return QuranSnapshotSchema.make({
36
+ ...input,
37
+ format: QURAN_SNAPSHOT_FORMAT,
38
+ snapshotId,
39
+ });
40
+ });
47
41
  /** Recomputes the content identity of one stored current snapshot. */
48
42
  export function verifyQuranSnapshotHash(snapshot) {
49
43
  const { format: _format, snapshotId: _snapshotId, ...facts } = snapshot;
@@ -2,7 +2,9 @@ import { Effect, Schema } from "effect";
2
2
  import { type QuranRowPayload } from "#contracts/quran/snapshot/row";
3
3
  declare const QuranRowHashError_base: Schema.Class<QuranRowHashError, Schema.TaggedStruct<"QuranRowHashError", {
4
4
  readonly scope: Schema.Literals<readonly ["digest", "row"]>;
5
- }>, import("effect/Cause").YieldableError>;
5
+ }>, import("effect/Cause").YieldableError & {
6
+ readonly brand: unique symbol;
7
+ }>;
6
8
  /** Node could not compute a deterministic Quran row identity. */
7
9
  export declare class QuranRowHashError extends QuranRowHashError_base {
8
10
  }
@@ -1,7 +1,6 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Array as Arr, Effect, Schema } from "effect";
3
2
  import { canonicalizeLearningGraphIdentity } from "#contracts/graph/spec";
4
- import { Sha256HashSchema } from "#contracts/ids";
3
+ import { hashText } from "#contracts/hash/text";
5
4
  import { canonicalizeQuranAttribution } from "#contracts/quran/attribution";
6
5
  import { QuranSnapshotRowSchema, } from "#contracts/quran/snapshot/row";
7
6
  import { encodeJsonText } from "#contracts/text/json";
@@ -103,12 +102,7 @@ export function canonicalizeQuranRow(payload) {
103
102
  });
104
103
  }
105
104
  /** Computes one current row's domain-separated identity. */
106
- export const hashQuranRow = Effect.fn("AksaraContracts.hashQuranRow")((payload) => Effect.try({
107
- catch: () => new QuranRowHashError({ scope: "row" }),
108
- try: () => Sha256HashSchema.make(`sha256:${createHash("sha256")
109
- .update(`${ROW_DOMAIN}\n${canonicalizeQuranRow(payload)}`)
110
- .digest("hex")}`),
111
- }));
105
+ export const hashQuranRow = Effect.fn("AksaraContracts.hashQuranRow")((payload) => hashText(`${ROW_DOMAIN}\n${canonicalizeQuranRow(payload)}`).pipe(Effect.mapError(() => new QuranRowHashError({ scope: "row" }))));
112
106
  /** Creates one snapshot-bound current row. */
113
107
  export const bindQuranRow = Effect.fn("AksaraContracts.bindQuranRow")(function* (snapshotId, payload) {
114
108
  const rowHash = yield* hashQuranRow(payload);
@@ -3,30 +3,32 @@ import { type ReleaseId } from "#contracts/ids";
3
3
  import type { ContentReleaseItem } from "#contracts/release/spec";
4
4
  declare const ReleaseItemsHashComputationError_base: Schema.Class<ReleaseItemsHashComputationError, Schema.TaggedStruct<"ReleaseItemsHashComputationError", {
5
5
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
6
- }>, import("effect/Cause").YieldableError>;
6
+ }>, import("effect/Cause").YieldableError & {
7
+ readonly brand: unique symbol;
8
+ }>;
7
9
  /** SHA-256 computation failed before item integrity was established. */
8
10
  export declare class ReleaseItemsHashComputationError extends ReleaseItemsHashComputationError_base {
9
11
  }
10
- /** Keeps Node hash state private while exposing canonical operation counts. */
12
+ /** Keeps the digest stream private while exposing canonical operation counts. */
11
13
  declare class ReleaseItemsDigestState {
12
14
  #private;
13
15
  count: number;
14
16
  deleteCount: number;
15
17
  upsertCount: number;
16
- /** Initializes a domain-separated incremental release-item hash. */
18
+ /** Starts one domain-separated release-item digest. */
17
19
  constructor();
18
20
  /** Adds one canonical release item and updates operation counts. */
19
21
  update(item: ContentReleaseItem): void;
20
- /** Consumes the hash and returns its branded immutable identity. */
21
- digest(): string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
22
+ /** Digests the complete stream once and returns its branded identity. */
23
+ digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, import("effect/PlatformError").PlatformError, never>;
22
24
  }
23
25
  /** Creates a fresh domain-separated digest state for one release stream. */
24
- export declare function createReleaseItemsDigest(releaseId: ReleaseId): Effect.Effect<ReleaseItemsDigestState, ReleaseItemsHashComputationError, never>;
26
+ export declare const createReleaseItemsDigest: Effect.Effect<ReleaseItemsDigestState, never, never>;
25
27
  /** Adds one canonical release item to its incremental digest and counts. */
26
- export declare function updateReleaseItemsDigest(releaseId: ReleaseId, state: ReleaseItemsDigestState, item: ContentReleaseItem): Effect.Effect<ReleaseItemsDigestState, ReleaseItemsHashComputationError, never>;
28
+ export declare function updateReleaseItemsDigest(state: ReleaseItemsDigestState, item: ContentReleaseItem): Effect.Effect<ReleaseItemsDigestState, never, never>;
27
29
  /** Finalizes one incremental release-item digest with typed hash failures. */
28
30
  export declare function finalizeReleaseItemsDigest(releaseId: ReleaseId, state: ReleaseItemsDigestState): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ReleaseItemsHashComputationError, never>;
29
- /** Digests a release-item stream without retaining its content changes. */
31
+ /** Digests a release-item stream. Its canonical bytes are held until one Web Crypto digest runs. */
30
32
  export declare const digestItems: <E, R>(releaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">, items: Stream.Stream<{
31
33
  readonly change: {
32
34
  readonly artifactHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
@@ -1,26 +1,26 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Effect, Schema, Stream } from "effect";
3
- import { ReleaseIdSchema, Sha256HashSchema, } from "#contracts/ids";
2
+ import { DigestStream } from "#contracts/hash/stream";
3
+ import { ReleaseIdSchema } from "#contracts/ids";
4
4
  import { canonicalizeContentReleaseItem } from "#contracts/release/canonical";
5
5
  const CONTENT_RELEASE_ITEMS_DIGEST_DOMAIN = "nakafa.aksara.content-release-items";
6
6
  /** SHA-256 computation failed before item integrity was established. */
7
7
  export class ReleaseItemsHashComputationError extends Schema.TaggedError()("ReleaseItemsHashComputationError", { releaseId: ReleaseIdSchema }) {
8
8
  }
9
- /** Keeps Node hash state private while exposing canonical operation counts. */
9
+ /** Keeps the digest stream private while exposing canonical operation counts. */
10
10
  class ReleaseItemsDigestState {
11
- #hash = createHash("sha256");
11
+ #stream = new DigestStream();
12
12
  count = 0;
13
13
  deleteCount = 0;
14
14
  upsertCount = 0;
15
- /** Initializes a domain-separated incremental release-item hash. */
15
+ /** Starts one domain-separated release-item digest. */
16
16
  constructor() {
17
- this.#hash.update(CONTENT_RELEASE_ITEMS_DIGEST_DOMAIN);
18
- this.#hash.update("\n");
17
+ this.#stream.add(CONTENT_RELEASE_ITEMS_DIGEST_DOMAIN);
18
+ this.#stream.add("\n");
19
19
  }
20
20
  /** Adds one canonical release item and updates operation counts. */
21
21
  update(item) {
22
- this.#hash.update(canonicalizeContentReleaseItem(item));
23
- this.#hash.update("\n");
22
+ this.#stream.add(canonicalizeContentReleaseItem(item));
23
+ this.#stream.add("\n");
24
24
  this.count += 1;
25
25
  if (item.change.operation === "delete") {
26
26
  this.deleteCount += 1;
@@ -28,39 +28,30 @@ class ReleaseItemsDigestState {
28
28
  }
29
29
  this.upsertCount += 1;
30
30
  }
31
- /** Consumes the hash and returns its branded immutable identity. */
31
+ /** Digests the complete stream once and returns its branded identity. */
32
32
  digest() {
33
- return Sha256HashSchema.make(`sha256:${this.#hash.digest("hex")}`);
33
+ return this.#stream.digest();
34
34
  }
35
35
  }
36
36
  /** Creates a fresh domain-separated digest state for one release stream. */
37
- export function createReleaseItemsDigest(releaseId) {
38
- return Effect.try({
39
- catch: () => new ReleaseItemsHashComputationError({ releaseId }),
40
- try: () => new ReleaseItemsDigestState(),
41
- });
42
- }
37
+ export const createReleaseItemsDigest = Effect.sync(() => new ReleaseItemsDigestState());
43
38
  /** Adds one canonical release item to its incremental digest and counts. */
44
- export function updateReleaseItemsDigest(releaseId, state, item) {
45
- return Effect.try({
46
- catch: () => new ReleaseItemsHashComputationError({ releaseId }),
47
- try: () => {
48
- state.update(item);
49
- return state;
50
- },
39
+ export function updateReleaseItemsDigest(state, item) {
40
+ return Effect.sync(() => {
41
+ state.update(item);
42
+ return state;
51
43
  });
52
44
  }
53
45
  /** Finalizes one incremental release-item digest with typed hash failures. */
54
46
  export function finalizeReleaseItemsDigest(releaseId, state) {
55
- return Effect.try({
56
- catch: () => new ReleaseItemsHashComputationError({ releaseId }),
57
- try: () => state.digest(),
58
- });
47
+ return state
48
+ .digest()
49
+ .pipe(Effect.mapError(() => new ReleaseItemsHashComputationError({ releaseId })));
59
50
  }
60
- /** Digests a release-item stream without retaining its content changes. */
51
+ /** Digests a release-item stream. Its canonical bytes are held until one Web Crypto digest runs. */
61
52
  export const digestItems = Effect.fn("AksaraContracts.digestItems")(function* (releaseId, items) {
62
- const initial = yield* createReleaseItemsDigest(releaseId);
63
- const state = yield* items.pipe(Stream.runFoldEffect(() => initial, (current, item) => updateReleaseItemsDigest(releaseId, current, item)));
53
+ const initial = yield* createReleaseItemsDigest;
54
+ const state = yield* items.pipe(Stream.runFoldEffect(() => initial, (current, item) => updateReleaseItemsDigest(current, item)));
64
55
  const digest = yield* finalizeReleaseItemsDigest(releaseId, state);
65
56
  return {
66
57
  count: state.count,
@@ -1,7 +1,9 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  declare const ReleaseHashComputationError_base: Schema.Class<ReleaseHashComputationError, Schema.TaggedStruct<"ReleaseHashComputationError", {
3
3
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
4
- }>, import("effect/Cause").YieldableError>;
4
+ }>, import("effect/Cause").YieldableError & {
5
+ readonly brand: unique symbol;
6
+ }>;
5
7
  /** SHA-256 computation failed before release authenticity was established. */
6
8
  export declare class ReleaseHashComputationError extends ReleaseHashComputationError_base {
7
9
  }
@@ -1,14 +1,9 @@
1
- import { createHash } from "node:crypto";
2
1
  import { Effect, Schema } from "effect";
3
- import { ReleaseIdSchema, Sha256HashSchema } from "#contracts/ids";
2
+ import { hashText } from "#contracts/hash/text";
3
+ import { ReleaseIdSchema } from "#contracts/ids";
4
4
  import { canonicalizeContentReleaseManifest } from "#contracts/release/signing";
5
5
  /** SHA-256 computation failed before release authenticity was established. */
6
6
  export class ReleaseHashComputationError extends Schema.TaggedError()("ReleaseHashComputationError", { releaseId: ReleaseIdSchema }) {
7
7
  }
8
8
  /** Computes the immutable identity of one canonical release manifest. */
9
- export const hashContentReleaseManifest = Effect.fn("AksaraContracts.hashContentReleaseManifest")((manifest) => Effect.try({
10
- catch: () => new ReleaseHashComputationError({ releaseId: manifest.releaseId }),
11
- try: () => Sha256HashSchema.make(`sha256:${createHash("sha256")
12
- .update(canonicalizeContentReleaseManifest(manifest))
13
- .digest("hex")}`),
14
- }));
9
+ export const hashContentReleaseManifest = Effect.fn("AksaraContracts.hashContentReleaseManifest")((manifest) => hashText(canonicalizeContentReleaseManifest(manifest)).pipe(Effect.mapError(() => new ReleaseHashComputationError({ releaseId: manifest.releaseId }))));