@nakafa/aksara-contracts 0.50.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 (94) 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 +3 -1
  7. package/dist/assessment/paper.d.ts +3 -1
  8. package/dist/errors.d.ts +3 -1
  9. package/dist/graph/family.d.ts +6 -2
  10. package/dist/graph/identity.d.ts +3 -1
  11. package/dist/hash/digest.d.ts +10 -0
  12. package/dist/hash/digest.js +40 -0
  13. package/dist/hash/stream.d.ts +12 -0
  14. package/dist/hash/stream.js +27 -0
  15. package/dist/hash/text.d.ts +3 -1
  16. package/dist/hash/text.js +2 -15
  17. package/dist/preview/auth.d.ts +4 -2
  18. package/dist/preview/auth.js +26 -12
  19. package/dist/program/snapshot/digest.d.ts +3 -1
  20. package/dist/program/snapshot/digest.js +14 -22
  21. package/dist/program/snapshot/hash.d.ts +6 -2
  22. package/dist/program/snapshot/hash.js +10 -21
  23. package/dist/projection/digest.d.ts +11 -9
  24. package/dist/projection/digest.js +23 -32
  25. package/dist/projection/hash.d.ts +222 -2
  26. package/dist/projection/hash.js +6 -8
  27. package/dist/projection/verify.d.ts +16 -6
  28. package/dist/question/item.d.ts +3 -1
  29. package/dist/question/item.js +3 -1
  30. package/dist/quran/notes.d.ts +3 -1
  31. package/dist/quran/provenance.d.ts +6 -2
  32. package/dist/quran/provenance.js +8 -15
  33. package/dist/quran/snapshot/digest.d.ts +9 -5
  34. package/dist/quran/snapshot/digest.js +33 -41
  35. package/dist/quran/snapshot/hash.d.ts +3 -1
  36. package/dist/quran/snapshot/hash.js +9 -15
  37. package/dist/quran/snapshot/row/hash.d.ts +3 -1
  38. package/dist/quran/snapshot/row/hash.js +2 -8
  39. package/dist/release/digest.d.ts +10 -8
  40. package/dist/release/digest.js +22 -31
  41. package/dist/release/hash.d.ts +3 -1
  42. package/dist/release/hash.js +3 -8
  43. package/dist/release/items.d.ts +25 -9
  44. package/dist/release/items.js +12 -3
  45. package/dist/release/policy.d.ts +3 -1
  46. package/dist/release/result/digest.d.ts +23 -13
  47. package/dist/release/result/digest.js +20 -29
  48. package/dist/release/rollback/digest.d.ts +16 -10
  49. package/dist/release/rollback/digest.js +25 -32
  50. package/dist/release/route/digest.d.ts +10 -8
  51. package/dist/release/route/digest.js +22 -31
  52. package/dist/release/route/verify.d.ts +16 -6
  53. package/dist/release/route/verify.js +8 -2
  54. package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
  55. package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
  56. package/dist/release/snapshot/evidence/tryout.js +1 -1
  57. package/dist/release/snapshot/evidence.d.ts +1 -1
  58. package/dist/release/snapshot/verify.d.ts +19 -7
  59. package/dist/release/snapshot/verify.js +20 -18
  60. package/dist/release/verify.d.ts +9 -3
  61. package/dist/renderer/compatibility.d.ts +6 -2
  62. package/dist/renderer/compatibility.js +3 -1
  63. package/dist/renderer/contract.d.ts +9 -3
  64. package/dist/renderer/contract.js +3 -1
  65. package/dist/runtime/error.d.ts +3 -1
  66. package/dist/runtime/protected/verify.d.ts +1 -1
  67. package/dist/runtime/verify.d.ts +2 -2
  68. package/dist/runtime/verify.js +2 -1
  69. package/dist/signature/key.d.ts +21 -0
  70. package/dist/signature/key.js +104 -0
  71. package/dist/signature/spec.d.ts +18 -6
  72. package/dist/signature/spec.js +16 -4
  73. package/dist/transport/request.d.ts +728 -728
  74. package/dist/transport/response.d.ts +26 -26
  75. package/dist/tryout/canonical.d.ts +11 -1
  76. package/dist/tryout/canonical.js +6 -10
  77. package/dist/tryout/closure/accounting.d.ts +3 -1
  78. package/dist/tryout/digest.d.ts +12 -6
  79. package/dist/tryout/digest.js +21 -14
  80. package/dist/tryout/hash/catalog.d.ts +228 -3
  81. package/dist/tryout/hash/catalog.js +5 -7
  82. package/dist/tryout/hash/content.d.ts +113 -2
  83. package/dist/tryout/hash/content.js +10 -8
  84. package/dist/tryout/hash/placement.d.ts +236 -5
  85. package/dist/tryout/hash/placement.js +7 -8
  86. package/dist/tryout/runtime/hash.d.ts +3 -1
  87. package/dist/tryout/runtime/hash.js +3 -1
  88. package/dist/tryout/runtime/source.d.ts +3 -1
  89. package/dist/tryout/runtime/verify.d.ts +13 -5
  90. package/dist/tryout/runtime/verify.js +1 -1
  91. package/dist/tryout/scoring.d.ts +3 -1
  92. package/dist/tryout/snapshot/hash.d.ts +45 -4
  93. package/dist/tryout/snapshot/hash.js +9 -7
  94. package/package.json +18 -2
@@ -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 }))));
@@ -2,14 +2,18 @@ import { Effect, Schema, Stream } from "effect";
2
2
  import { type ContentReleaseManifest } from "#contracts/release/spec";
3
3
  declare const ReleaseItemDecodeError_base: Schema.Class<ReleaseItemDecodeError, Schema.TaggedStruct<"ReleaseItemDecodeError", {
4
4
  readonly itemOffset: Schema.Finite;
5
- }>, import("effect/Cause").YieldableError>;
5
+ }>, import("effect/Cause").YieldableError & {
6
+ readonly brand: unique symbol;
7
+ }>;
6
8
  /** One release item failed strict wire decoding. */
7
9
  export declare class ReleaseItemDecodeError extends ReleaseItemDecodeError_base {
8
10
  }
9
11
  declare const ReleaseItemCountMismatchError_base: Schema.Class<ReleaseItemCountMismatchError, Schema.TaggedStruct<"ReleaseItemCountMismatchError", {
10
12
  readonly actualCount: Schema.Finite;
11
13
  readonly expectedCount: Schema.Finite;
12
- }>, import("effect/Cause").YieldableError>;
14
+ }>, import("effect/Cause").YieldableError & {
15
+ readonly brand: unique symbol;
16
+ }>;
13
17
  /** The separate item stream does not have the signed manifest length. */
14
18
  export declare class ReleaseItemCountMismatchError extends ReleaseItemCountMismatchError_base {
15
19
  }
@@ -18,33 +22,43 @@ declare const ReleaseItemOperationCountMismatchError_base: Schema.Class<ReleaseI
18
22
  readonly actualUpserts: Schema.Finite;
19
23
  readonly expectedDeletes: Schema.Finite;
20
24
  readonly expectedUpserts: Schema.Finite;
21
- }>, import("effect/Cause").YieldableError>;
25
+ }>, import("effect/Cause").YieldableError & {
26
+ readonly brand: unique symbol;
27
+ }>;
22
28
  /** Upsert and delete totals do not match the counts signed by the manifest. */
23
29
  export declare class ReleaseItemOperationCountMismatchError extends ReleaseItemOperationCountMismatchError_base {
24
30
  }
25
31
  declare const ReleaseItemReleaseMismatchError_base: Schema.Class<ReleaseItemReleaseMismatchError, Schema.TaggedStruct<"ReleaseItemReleaseMismatchError", {
26
32
  readonly itemOffset: Schema.Finite;
27
33
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
28
- }>, import("effect/Cause").YieldableError>;
34
+ }>, import("effect/Cause").YieldableError & {
35
+ readonly brand: unique symbol;
36
+ }>;
29
37
  /** An item belongs to another release envelope. */
30
38
  export declare class ReleaseItemReleaseMismatchError extends ReleaseItemReleaseMismatchError_base {
31
39
  }
32
40
  declare const ReleaseItemIndexMismatchError_base: Schema.Class<ReleaseItemIndexMismatchError, Schema.TaggedStruct<"ReleaseItemIndexMismatchError", {
33
41
  readonly actualIndex: Schema.Finite;
34
42
  readonly expectedIndex: Schema.Finite;
35
- }>, import("effect/Cause").YieldableError>;
43
+ }>, import("effect/Cause").YieldableError & {
44
+ readonly brand: unique symbol;
45
+ }>;
36
46
  /** An item is missing, duplicated, or out of its signed sequence. */
37
47
  export declare class ReleaseItemIndexMismatchError extends ReleaseItemIndexMismatchError_base {
38
48
  }
39
49
  declare const ReleaseItemOrderError_base: Schema.Class<ReleaseItemOrderError, Schema.TaggedStruct<"ReleaseItemOrderError", {
40
50
  readonly itemOffset: Schema.Finite;
41
- }>, import("effect/Cause").YieldableError>;
51
+ }>, import("effect/Cause").YieldableError & {
52
+ readonly brand: unique symbol;
53
+ }>;
42
54
  /** Item heads are duplicated or not in canonical content-head order. */
43
55
  export declare class ReleaseItemOrderError extends ReleaseItemOrderError_base {
44
56
  }
45
57
  declare const ReleaseItemScopeError_base: Schema.Class<ReleaseItemScopeError, Schema.TaggedStruct<"ReleaseItemScopeError", {
46
58
  readonly itemOffset: Schema.Finite;
47
- }>, import("effect/Cause").YieldableError>;
59
+ }>, import("effect/Cause").YieldableError & {
60
+ readonly brand: unique symbol;
61
+ }>;
48
62
  /** One signed item falls outside the release's exact publication scope. */
49
63
  export declare class ReleaseItemScopeError extends ReleaseItemScopeError_base {
50
64
  }
@@ -52,7 +66,9 @@ declare const ReleaseItemsDigestMismatchError_base: Schema.Class<ReleaseItemsDig
52
66
  readonly actualDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
53
67
  readonly expectedDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
54
68
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
55
- }>, import("effect/Cause").YieldableError>;
69
+ }>, import("effect/Cause").YieldableError & {
70
+ readonly brand: unique symbol;
71
+ }>;
56
72
  /** The separate ordered items do not match the signed digest. */
57
73
  export declare class ReleaseItemsDigestMismatchError extends ReleaseItemsDigestMismatchError_base {
58
74
  }
@@ -60,7 +76,7 @@ declare const VerifiedContentReleaseItemsSchema: Schema.Struct<{
60
76
  readonly deleteCount: Schema.Finite;
61
77
  readonly upsertCount: Schema.Finite;
62
78
  }>;
63
- /** Counts derived without retaining a complete release-item collection. */
79
+ /** Counts derived from one authenticated item stream. The digest holds every canonical byte until its one final call, so its memory grows with the stream. */
64
80
  export type VerifiedContentReleaseItems = typeof VerifiedContentReleaseItemsSchema.Type;
65
81
  /**
66
82
  * Strictly decodes a replayable item stream without retaining its bodies.
@@ -9,7 +9,10 @@ import { ContentReleaseItemSchema, } from "#contracts/release/spec";
9
9
  export class ReleaseItemDecodeError extends Schema.TaggedError()("ReleaseItemDecodeError", { itemOffset: ReleaseCountSchema }) {
10
10
  }
11
11
  /** The separate item stream does not have the signed manifest length. */
12
- export class ReleaseItemCountMismatchError extends Schema.TaggedError()("ReleaseItemCountMismatchError", { actualCount: ReleaseCountSchema, expectedCount: ReleaseCountSchema }) {
12
+ export class ReleaseItemCountMismatchError extends Schema.TaggedError()("ReleaseItemCountMismatchError", {
13
+ actualCount: ReleaseCountSchema,
14
+ expectedCount: ReleaseCountSchema,
15
+ }) {
13
16
  }
14
17
  /** Upsert and delete totals do not match the counts signed by the manifest. */
15
18
  export class ReleaseItemOperationCountMismatchError extends Schema.TaggedError()("ReleaseItemOperationCountMismatchError", {
@@ -20,10 +23,16 @@ export class ReleaseItemOperationCountMismatchError extends Schema.TaggedError()
20
23
  }) {
21
24
  }
22
25
  /** An item belongs to another release envelope. */
23
- export class ReleaseItemReleaseMismatchError extends Schema.TaggedError()("ReleaseItemReleaseMismatchError", { itemOffset: ReleaseCountSchema, releaseId: ReleaseIdSchema }) {
26
+ export class ReleaseItemReleaseMismatchError extends Schema.TaggedError()("ReleaseItemReleaseMismatchError", {
27
+ itemOffset: ReleaseCountSchema,
28
+ releaseId: ReleaseIdSchema,
29
+ }) {
24
30
  }
25
31
  /** An item is missing, duplicated, or out of its signed sequence. */
26
- export class ReleaseItemIndexMismatchError extends Schema.TaggedError()("ReleaseItemIndexMismatchError", { actualIndex: ReleaseCountSchema, expectedIndex: ReleaseCountSchema }) {
32
+ export class ReleaseItemIndexMismatchError extends Schema.TaggedError()("ReleaseItemIndexMismatchError", {
33
+ actualIndex: ReleaseCountSchema,
34
+ expectedIndex: ReleaseCountSchema,
35
+ }) {
27
36
  }
28
37
  /** Item heads are duplicated or not in canonical content-head order. */
29
38
  export class ReleaseItemOrderError extends Schema.TaggedError()("ReleaseItemOrderError", { itemOffset: ReleaseCountSchema }) {
@@ -15,7 +15,9 @@ declare const ReleasePolicyClosureError_base: Schema.Class<ReleasePolicyClosureE
15
15
  readonly expected: Schema.String;
16
16
  readonly family: Schema.Union<readonly [Schema.Literals<readonly ["program", "quran", "tryout"]>, Schema.Literals<readonly ["article", "material", "page", "question"]>]>;
17
17
  readonly field: Schema.Literals<readonly ["activeAppLocales", "manifest", "scope"]>;
18
- }>, import("effect/Cause").YieldableError>;
18
+ }>, import("effect/Cause").YieldableError & {
19
+ readonly brand: unique symbol;
20
+ }>;
19
21
  /** One structured scope does not close over the current release policy. */
20
22
  export declare class ReleasePolicyClosureError extends ReleasePolicyClosureError_base {
21
23
  }
@@ -1,10 +1,12 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
- import { type PublicPath, type ReleaseId, Sha256HashSchema } from "#contracts/ids";
2
+ import { type PublicPath, type ReleaseId, type Sha256HashSchema } from "#contracts/ids";
3
3
  import { type ArtifactLocale } from "#contracts/locale";
4
4
  import { type ContentHead } from "#contracts/release/head";
5
5
  declare const ResultCatalogHashError_base: Schema.Class<ResultCatalogHashError, Schema.TaggedStruct<"ResultCatalogHashError", {
6
6
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
7
- }>, import("effect/Cause").YieldableError>;
7
+ }>, import("effect/Cause").YieldableError & {
8
+ readonly brand: unique symbol;
9
+ }>;
8
10
  /** SHA-256 computation failed before result-catalog integrity was established. */
9
11
  export declare class ResultCatalogHashError extends ResultCatalogHashError_base {
10
12
  }
@@ -12,7 +14,9 @@ declare const ResultCatalogOrderError_base: Schema.Class<ResultCatalogOrderError
12
14
  readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
13
15
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
14
16
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
15
- }>, import("effect/Cause").YieldableError>;
17
+ }>, import("effect/Cause").YieldableError & {
18
+ readonly brand: unique symbol;
19
+ }>;
16
20
  /** A result catalog is duplicated or outside canonical content-head order. */
17
21
  export declare class ResultCatalogOrderError extends ResultCatalogOrderError_base {
18
22
  }
@@ -21,7 +25,9 @@ declare const ResultCatalogRouteError_base: Schema.Class<ResultCatalogRouteError
21
25
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
22
26
  readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
23
27
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
24
- }>, import("effect/Cause").YieldableError>;
28
+ }>, import("effect/Cause").YieldableError & {
29
+ readonly brand: unique symbol;
30
+ }>;
25
31
  /** Two complete result heads claim the same locale-specific public route. */
26
32
  export declare class ResultCatalogRouteError extends ResultCatalogRouteError_base {
27
33
  }
@@ -29,7 +35,9 @@ declare const ResultCatalogCountMismatchError_base: Schema.Class<ResultCatalogCo
29
35
  readonly actualCount: Schema.Finite;
30
36
  readonly expectedCount: Schema.Finite;
31
37
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
32
- }>, import("effect/Cause").YieldableError>;
38
+ }>, import("effect/Cause").YieldableError & {
39
+ readonly brand: unique symbol;
40
+ }>;
33
41
  /** A replayed result catalog has a different signed head count. */
34
42
  export declare class ResultCatalogCountMismatchError extends ResultCatalogCountMismatchError_base {
35
43
  }
@@ -37,31 +45,33 @@ declare const ResultCatalogDigestMismatchError_base: Schema.Class<ResultCatalogD
37
45
  readonly actualDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
38
46
  readonly expectedDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
39
47
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
40
- }>, import("effect/Cause").YieldableError>;
48
+ }>, import("effect/Cause").YieldableError & {
49
+ readonly brand: unique symbol;
50
+ }>;
41
51
  /** A replayed result catalog does not match its signed digest. */
42
52
  export declare class ResultCatalogDigestMismatchError extends ResultCatalogDigestMismatchError_base {
43
53
  }
44
- /** Keeps mutable hash and ordering state private to one catalog replay. */
54
+ /** Keeps mutable digest and ordering state private to one catalog replay. */
45
55
  declare class ResultCatalogDigestState {
46
56
  #private;
47
57
  count: number;
48
58
  previous: ContentHead | undefined;
49
- /** Initializes one domain-separated result-catalog hash. */
59
+ /** Starts one domain-separated result-catalog digest. */
50
60
  constructor();
51
61
  /** Claims one public route and reports whether it was globally unique. */
52
62
  claimRoute(artifactLocale: ArtifactLocale, publicPath: PublicPath): boolean;
53
63
  /** Adds one canonical compact head and advances ordering evidence. */
54
64
  update(head: ContentHead): void;
55
- /** Consumes the hash and returns its branded immutable identity. */
56
- digest(): string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
65
+ /** Digests the complete stream once and returns its branded immutable identity. */
66
+ digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, import("effect/PlatformError").PlatformError, never>;
57
67
  }
58
68
  /** Creates a fresh domain-separated digest state for one result catalog. */
59
- export declare function createResultCatalogDigest(releaseId: ReleaseId): Effect.Effect<ResultCatalogDigestState, ResultCatalogHashError, never>;
69
+ export declare const createResultCatalogDigest: Effect.Effect<ResultCatalogDigestState, never, never>;
60
70
  /** Adds one canonically ordered compact head to a result digest. */
61
- export declare function updateResultCatalogDigest(releaseId: ReleaseId, state: ResultCatalogDigestState, head: ContentHead): Effect.Effect<ResultCatalogDigestState, ResultCatalogHashError | ResultCatalogOrderError | ResultCatalogRouteError>;
71
+ export declare function updateResultCatalogDigest(releaseId: ReleaseId, state: ResultCatalogDigestState, head: ContentHead): Effect.Effect<ResultCatalogDigestState, ResultCatalogOrderError | ResultCatalogRouteError>;
62
72
  /** Finalizes one incremental result-catalog digest. */
63
73
  export declare function finalizeResultCatalogDigest(releaseId: ReleaseId, state: ResultCatalogDigestState): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ResultCatalogHashError, never>;
64
- /** Digests one complete compact-head stream without retaining the catalog. */
74
+ /** Digests one complete compact-head stream. Its canonical bytes are held until one Web Crypto digest runs. */
65
75
  export declare const digestResultCatalog: <E, R>(releaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">, heads: Stream.Stream<{
66
76
  readonly artifactHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
67
77
  readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;