@nakafa/aksara-contracts 2.0.0 → 3.0.1

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 (71) hide show
  1. package/README.md +2 -2
  2. package/dist/artifact/integrity.d.ts +3 -3
  3. package/dist/artifact/integrity.js +2 -2
  4. package/dist/artifact/source.d.ts +2 -2
  5. package/dist/artifact/source.js +2 -8
  6. package/dist/artifact/spec.d.ts +0 -16
  7. package/dist/artifact/spec.js +0 -6
  8. package/dist/artifact/verify.d.ts +1 -1
  9. package/dist/assessment/hash.d.ts +6 -6
  10. package/dist/assessment/snapshot.d.ts +3 -3
  11. package/dist/date.js +1 -1
  12. package/dist/hash/digest.d.ts +7 -7
  13. package/dist/hash/digest.js +9 -30
  14. package/dist/hash/stream.d.ts +1 -1
  15. package/dist/hash/text.d.ts +3 -12
  16. package/dist/hash/text.js +3 -6
  17. package/dist/ids.js +8 -8
  18. package/dist/preview/auth.d.ts +1 -1
  19. package/dist/preview/auth.js +29 -25
  20. package/dist/program/snapshot/digest.d.ts +1 -2
  21. package/dist/program/snapshot/digest.js +2 -4
  22. package/dist/program/snapshot/hash.d.ts +6 -21
  23. package/dist/program/snapshot/hash.js +3 -9
  24. package/dist/projection/digest.d.ts +7 -16
  25. package/dist/projection/digest.js +7 -13
  26. package/dist/projection/hash.d.ts +2 -11
  27. package/dist/projection/hash.js +2 -5
  28. package/dist/projection/material.js +1 -1
  29. package/dist/projection/verify.d.ts +1 -1
  30. package/dist/projection/verify.js +1 -1
  31. package/dist/quran/notes.js +1 -1
  32. package/dist/quran/provenance.d.ts +2 -8
  33. package/dist/quran/provenance.js +1 -4
  34. package/dist/quran/snapshot/digest.d.ts +1 -2
  35. package/dist/quran/snapshot/digest.js +2 -2
  36. package/dist/quran/snapshot/hash.d.ts +3 -10
  37. package/dist/quran/snapshot/hash.js +2 -5
  38. package/dist/quran/snapshot/row/hash.d.ts +3 -12
  39. package/dist/quran/snapshot/row/hash.js +2 -5
  40. package/dist/release/digest.d.ts +7 -16
  41. package/dist/release/digest.js +7 -13
  42. package/dist/release/hash.d.ts +2 -11
  43. package/dist/release/hash.js +2 -6
  44. package/dist/release/items.d.ts +1 -1
  45. package/dist/release/items.js +1 -1
  46. package/dist/release/result/digest.d.ts +5 -13
  47. package/dist/release/result/digest.js +4 -9
  48. package/dist/release/rollback/digest.d.ts +7 -16
  49. package/dist/release/rollback/digest.js +7 -13
  50. package/dist/release/route/digest.d.ts +7 -16
  51. package/dist/release/route/digest.js +7 -13
  52. package/dist/release/route/verify.d.ts +1 -1
  53. package/dist/release/route/verify.js +1 -1
  54. package/dist/release/snapshot/evidence/assessment.d.ts +1 -1
  55. package/dist/release/snapshot/evidence/program.d.ts +1 -1
  56. package/dist/release/snapshot/evidence/quran.d.ts +1 -1
  57. package/dist/release/snapshot/evidence.d.ts +1 -1
  58. package/dist/release/snapshot/verify.d.ts +1 -1
  59. package/dist/release/verify.d.ts +2 -2
  60. package/dist/renderer/compatibility.d.ts +1 -1
  61. package/dist/renderer/component.js +1 -1
  62. package/dist/renderer/contract.d.ts +0 -8
  63. package/dist/renderer/contract.js +0 -3
  64. package/dist/renderer/manifest.d.ts +3 -3
  65. package/dist/renderer/manifest.js +2 -2
  66. package/dist/runtime/verify.d.ts +2 -2
  67. package/dist/signature/key.d.ts +0 -2
  68. package/dist/signature/key.js +37 -88
  69. package/dist/signature/verify.js +31 -46
  70. package/dist/tree.js +1 -1
  71. package/package.json +2 -2
package/README.md CHANGED
@@ -6,12 +6,12 @@ package, its immutable release archive, and the renderer manifest that its
6
6
  releases sign.
7
7
 
8
8
  This package contains schemas, branded identifiers, canonical wire encodings,
9
- and Web Crypto signature verification. It contains no corpus, renderer
9
+ and Ed25519 signature verification on Effect's `effect/crypto` services. It contains no corpus, renderer
10
10
  implementation, signing key, deployment credential, or browser-side MDX
11
11
  runtime.
12
12
 
13
13
  Consumers install the exact `@nakafa/aksara-contracts` version from npm and
14
- commit its pnpm lockfile integrity. npm provenance and the matching immutable
14
+ commit its `bun.lock` integrity. npm provenance and the matching immutable
15
15
  GitHub Release bind those package bytes to the reviewed Aksara source. A contract
16
16
  change ships with the Nakafa renderer that consumes it, in one step.
17
17
 
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { ArtifactHashComputationError, ArtifactHashMismatchError, ArtifactTreeComponentUnlistedError, ArtifactVerificationDecodeError } from "#contracts/artifact/spec";
2
+ import { ArtifactHashMismatchError, ArtifactTreeComponentUnlistedError, ArtifactVerificationDecodeError } from "#contracts/artifact/spec";
3
3
  /** Computes the immutable identity of one canonical compiled payload. */
4
4
  export declare const hashCompiledContentPayload: (payload: {
5
5
  readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
@@ -21,7 +21,7 @@ export declare const hashCompiledContentPayload: (payload: {
21
21
  readonly rendererDomain: "ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math";
22
22
  readonly requiredComponents: readonly string[];
23
23
  readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
24
- }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ArtifactHashComputationError, never>;
24
+ }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
25
25
  /** Strictly authenticates artifact integrity without renderer compatibility. */
26
26
  export declare const verifySignedContentArtifactIntegrity: (input: unknown) => Effect.Effect<{
27
27
  readonly artifactHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
@@ -48,4 +48,4 @@ export declare const verifySignedContentArtifactIntegrity: (input: unknown) => E
48
48
  readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
49
49
  };
50
50
  readonly signature: string & import("effect/Brand").Brand<"@NakafaAI/AksaraEd25519Signature">;
51
- }, ArtifactHashComputationError | ArtifactHashMismatchError | import("#contracts/artifact/spec").ArtifactPayloadFieldByteLimitError | import("#contracts/artifact/spec").ArtifactSourceHashComputationError | import("#contracts/artifact/spec").ArtifactSourceHashMismatchError | ArtifactTreeComponentUnlistedError | import("#contracts/artifact/spec").ArtifactVerificationByteLimitError | ArtifactVerificationDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("../signature/spec.js").SignatureCheckError | import("../signature/spec.js").SignatureInvalidError | import("../signature/spec.js").SigningKeyNotFoundError | import("../signature/spec.js").SigningKeyResolutionError, import("../signature/spec.js").ContentVerificationKeyResolver>;
51
+ }, ArtifactHashMismatchError | import("#contracts/artifact/spec").ArtifactPayloadFieldByteLimitError | import("#contracts/artifact/spec").ArtifactSourceHashMismatchError | ArtifactTreeComponentUnlistedError | import("#contracts/artifact/spec").ArtifactVerificationByteLimitError | ArtifactVerificationDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("../signature/spec.js").SignatureCheckError | import("../signature/spec.js").SignatureInvalidError | import("../signature/spec.js").SigningKeyNotFoundError | import("../signature/spec.js").SigningKeyResolutionError, import("../signature/spec.js").ContentVerificationKeyResolver>;
@@ -1,13 +1,13 @@
1
1
  import { Array as Arr, Effect, Option, Schema } from "effect";
2
2
  import { validateArtifactByteIntegrity } from "#contracts/artifact/limits";
3
3
  import { verifyCompiledContentSourceHash } from "#contracts/artifact/source";
4
- import { ArtifactHashComputationError, ArtifactHashMismatchError, ArtifactTreeComponentUnlistedError, ArtifactVerificationDecodeError, } from "#contracts/artifact/spec";
4
+ import { ArtifactHashMismatchError, ArtifactTreeComponentUnlistedError, ArtifactVerificationDecodeError, } from "#contracts/artifact/spec";
5
5
  import { canonicalizeCompiledContentPayload, canonicalizeContentArtifactSigningInput, SignedContentArtifactSchema, } from "#contracts/content";
6
6
  import { hashText } from "#contracts/hash/text";
7
7
  import { verifyEd25519Signature } from "#contracts/signature/verify";
8
8
  import { contentTreeComponentNames } from "#contracts/tree";
9
9
  /** Computes the immutable identity of one canonical compiled payload. */
10
- export const hashCompiledContentPayload = Effect.fn("AksaraContracts.hashCompiledContentPayload")((payload) => hashText(canonicalizeCompiledContentPayload(payload)).pipe(Effect.mapError(() => new ArtifactHashComputationError({ contentKey: payload.contentKey }))));
10
+ export const hashCompiledContentPayload = Effect.fn("AksaraContracts.hashCompiledContentPayload")((payload) => hashText(canonicalizeCompiledContentPayload(payload)));
11
11
  /** Confirms that an artifact envelope identifies its canonical payload. */
12
12
  function validateArtifactHash(artifact, actualHash) {
13
13
  if (artifact.artifactHash === actualHash) {
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { ArtifactSourceHashComputationError, ArtifactSourceHashMismatchError } from "#contracts/artifact/spec";
2
+ import { ArtifactSourceHashMismatchError } from "#contracts/artifact/spec";
3
3
  /** Verifies that sourceHash identifies the complete authenticated raw MDX. */
4
4
  export declare const verifyCompiledContentSourceHash: (payload: {
5
5
  readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
@@ -21,4 +21,4 @@ export declare const verifyCompiledContentSourceHash: (payload: {
21
21
  readonly rendererDomain: "ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math";
22
22
  readonly requiredComponents: readonly string[];
23
23
  readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
24
- }) => Effect.Effect<void, ArtifactSourceHashComputationError | ArtifactSourceHashMismatchError, never>;
24
+ }) => Effect.Effect<void, ArtifactSourceHashMismatchError, never>;
@@ -1,14 +1,8 @@
1
1
  import { Effect } from "effect";
2
- import { ArtifactSourceHashComputationError, ArtifactSourceHashMismatchError, } from "#contracts/artifact/spec";
2
+ import { ArtifactSourceHashMismatchError } from "#contracts/artifact/spec";
3
3
  import { hashText } from "#contracts/hash/text";
4
- /** Computes the authenticated hash of the complete authored MDX source. */
5
- function hashAuthoredSource(payload) {
6
- return hashText(payload.rawMdx).pipe(Effect.mapError(() => new ArtifactSourceHashComputationError({
7
- contentKey: payload.contentKey,
8
- })));
9
- }
10
4
  /** Verifies that sourceHash identifies the complete authenticated raw MDX. */
11
- export const verifyCompiledContentSourceHash = Effect.fn("AksaraContracts.verifyCompiledContentSourceHash")((payload) => hashAuthoredSource(payload).pipe(Effect.flatMap((actualHash) => {
5
+ export const verifyCompiledContentSourceHash = Effect.fn("AksaraContracts.verifyCompiledContentSourceHash")((payload) => hashText(payload.rawMdx).pipe(Effect.flatMap((actualHash) => {
12
6
  if (actualHash === payload.sourceHash) {
13
7
  return Effect.void;
14
8
  }
@@ -74,14 +74,6 @@ declare const ArtifactPayloadFieldByteLimitError_base: Schema.Class<ArtifactPayl
74
74
  /** One authenticated payload field exceeded its shared runtime ceiling. */
75
75
  export declare class ArtifactPayloadFieldByteLimitError extends ArtifactPayloadFieldByteLimitError_base {
76
76
  }
77
- declare const ArtifactHashComputationError_base: Schema.Class<ArtifactHashComputationError, Schema.TaggedStruct<"ArtifactHashComputationError", {
78
- readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
79
- }>, import("effect/Cause").YieldableError & {
80
- readonly brand: unique symbol;
81
- }>;
82
- /** SHA-256 computation failed before authenticity could be established. */
83
- export declare class ArtifactHashComputationError extends ArtifactHashComputationError_base {
84
- }
85
77
  declare const ArtifactHashMismatchError_base: Schema.Class<ArtifactHashMismatchError, Schema.TaggedStruct<"ArtifactHashMismatchError", {
86
78
  readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
87
79
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
@@ -92,14 +84,6 @@ declare const ArtifactHashMismatchError_base: Schema.Class<ArtifactHashMismatchE
92
84
  /** The signed artifact hash does not identify its canonical payload. */
93
85
  export declare class ArtifactHashMismatchError extends ArtifactHashMismatchError_base {
94
86
  }
95
- declare const ArtifactSourceHashComputationError_base: Schema.Class<ArtifactSourceHashComputationError, Schema.TaggedStruct<"ArtifactSourceHashComputationError", {
96
- readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
97
- }>, import("effect/Cause").YieldableError & {
98
- readonly brand: unique symbol;
99
- }>;
100
- /** SHA-256 could not be calculated for the authenticated authored source. */
101
- export declare class ArtifactSourceHashComputationError extends ArtifactSourceHashComputationError_base {
102
- }
103
87
  declare const ArtifactSourceHashMismatchError_base: Schema.Class<ArtifactSourceHashMismatchError, Schema.TaggedStruct<"ArtifactSourceHashMismatchError", {
104
88
  readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
105
89
  readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
@@ -33,9 +33,6 @@ export class ArtifactPayloadFieldByteLimitError extends Schema.TaggedError()("Ar
33
33
  maxBytes: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThan(0))),
34
34
  }) {
35
35
  }
36
- /** SHA-256 computation failed before authenticity could be established. */
37
- export class ArtifactHashComputationError extends Schema.TaggedError()("ArtifactHashComputationError", { contentKey: ContentKeySchema }) {
38
- }
39
36
  /** Fields that name one content hash, its content key, and the hash that failed. */
40
37
  const ContentHashMismatchFields = {
41
38
  actualHash: Sha256HashSchema,
@@ -45,9 +42,6 @@ const ContentHashMismatchFields = {
45
42
  /** The signed artifact hash does not identify its canonical payload. */
46
43
  export class ArtifactHashMismatchError extends Schema.TaggedError()("ArtifactHashMismatchError", { ...ContentHashMismatchFields }) {
47
44
  }
48
- /** SHA-256 could not be calculated for the authenticated authored source. */
49
- export class ArtifactSourceHashComputationError extends Schema.TaggedError()("ArtifactSourceHashComputationError", { contentKey: ContentKeySchema }) {
50
- }
51
45
  /** The authenticated source hash does not identify the complete raw MDX. */
52
46
  export class ArtifactSourceHashMismatchError extends Schema.TaggedError()("ArtifactSourceHashMismatchError", { ...ContentHashMismatchFields }) {
53
47
  }
@@ -26,4 +26,4 @@ export declare const verifySignedContentArtifact: (input: unknown) => Effect.Eff
26
26
  readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
27
27
  };
28
28
  readonly signature: string & import("effect/Brand").Brand<"@NakafaAI/AksaraEd25519Signature">;
29
- }, import("#contracts/artifact/spec").ArtifactHashComputationError | import("#contracts/artifact/spec").ArtifactHashMismatchError | import("#contracts/artifact/spec").ArtifactPayloadFieldByteLimitError | import("#contracts/artifact/spec").ArtifactRendererComponentMissingError | import("#contracts/artifact/spec").ArtifactRendererDomainUnpublishedError | import("#contracts/artifact/spec").ArtifactSourceHashComputationError | import("#contracts/artifact/spec").ArtifactSourceHashMismatchError | import("#contracts/artifact/spec").ArtifactTreeComponentUnlistedError | import("#contracts/artifact/spec").ArtifactVerificationByteLimitError | ArtifactVerificationDecodeError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("../renderer/contract.js").RendererDomainCapabilityMissingError | import("../renderer/contract.js").RendererManifestHashComputeError | import("../renderer/contract.js").RendererManifestHashMismatchError | import("../signature/spec.js").SignatureCheckError | import("../signature/spec.js").SignatureInvalidError | import("../signature/spec.js").SigningKeyNotFoundError | import("../signature/spec.js").SigningKeyResolutionError, import("../signature/spec.js").ContentVerificationKeyResolver>;
29
+ }, import("#contracts/artifact/spec").ArtifactHashMismatchError | import("#contracts/artifact/spec").ArtifactPayloadFieldByteLimitError | import("#contracts/artifact/spec").ArtifactRendererComponentMissingError | import("#contracts/artifact/spec").ArtifactRendererDomainUnpublishedError | import("#contracts/artifact/spec").ArtifactSourceHashMismatchError | import("#contracts/artifact/spec").ArtifactTreeComponentUnlistedError | import("#contracts/artifact/spec").ArtifactVerificationByteLimitError | ArtifactVerificationDecodeError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("../renderer/contract.js").RendererDomainCapabilityMissingError | import("../renderer/contract.js").RendererManifestHashMismatchError | import("../signature/spec.js").SignatureCheckError | import("../signature/spec.js").SignatureInvalidError | import("../signature/spec.js").SigningKeyNotFoundError | import("../signature/spec.js").SigningKeyResolutionError, import("../signature/spec.js").ContentVerificationKeyResolver>;
@@ -737,7 +737,7 @@ export declare const hashItemVersion: (body: Omit<{
737
737
  readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
738
738
  };
739
739
  readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
740
- }, "hash">) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
740
+ }, "hash">) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError, never>;
741
741
  /** Computes the hash that a stimulus version carries, from all of its other fields. */
742
742
  export declare const hashStimulusVersion: (body: Omit<{
743
743
  readonly deliveryLanguage: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentLanguage">;
@@ -747,7 +747,7 @@ export declare const hashStimulusVersion: (body: Omit<{
747
747
  };
748
748
  readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
749
749
  readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
750
- }, "hash">) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
750
+ }, "hash">) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError, never>;
751
751
  /**
752
752
  * Computes the hash of an exam profile, which a paper names beside its
753
753
  * identifier, so a paper follows one exact profile.
@@ -853,7 +853,7 @@ export declare const hashExamProfile: (profile: {
853
853
  }[]];
854
854
  readonly totalSeconds: number;
855
855
  readonly writeAllowanceSeconds: number;
856
- }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
856
+ }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError, never>;
857
857
  /**
858
858
  * Computes the hash of a paper, the name a frozen paper is known by: equal
859
859
  * places, profile, and readings have one hash.
@@ -887,7 +887,7 @@ export declare const hashPaper: (paper: {
887
887
  readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
888
888
  readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
889
889
  }[];
890
- }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
890
+ }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError, never>;
891
891
  /** Requires an item version to carry the hash of its own content. */
892
892
  export declare const verifyItemVersion: (version: {
893
893
  readonly deliveryLanguage: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentLanguage">;
@@ -1608,7 +1608,7 @@ export declare const verifyItemVersion: (version: {
1608
1608
  readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
1609
1609
  };
1610
1610
  readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
1611
- }) => Effect.Effect<undefined, Schema.SchemaError | import("#contracts/hash/text").TextHashError | VersionHashMismatchError, never>;
1611
+ }) => Effect.Effect<undefined, Schema.SchemaError | VersionHashMismatchError, never>;
1612
1612
  /** Requires a stimulus version to carry the hash of its own content. */
1613
1613
  export declare const verifyStimulusVersion: (version: {
1614
1614
  readonly deliveryLanguage: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentLanguage">;
@@ -1618,5 +1618,5 @@ export declare const verifyStimulusVersion: (version: {
1618
1618
  };
1619
1619
  readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
1620
1620
  readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
1621
- }) => Effect.Effect<undefined, Schema.SchemaError | import("#contracts/hash/text").TextHashError | VersionHashMismatchError, never>;
1621
+ }) => Effect.Effect<undefined, Schema.SchemaError | VersionHashMismatchError, never>;
1622
1622
  export {};
@@ -2467,7 +2467,7 @@ export declare const hashAssessmentRow: (row: {
2467
2467
  readonly version: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
2468
2468
  };
2469
2469
  readonly kind: "explanation";
2470
- }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
2470
+ }) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, Schema.SchemaError, never>;
2471
2471
  declare const AssessmentRowsError_base: Schema.Class<AssessmentRowsError, Schema.TaggedStruct<"AssessmentRowsError", {
2472
2472
  readonly identity: Schema.String;
2473
2473
  readonly kind: Schema.Literals<["catalog" | "explanation" | "family" | "item" | "key" | "paper" | "profile" | "stimulus", ...("catalog" | "explanation" | "family" | "item" | "key" | "paper" | "profile" | "stimulus")[]]>;
@@ -3742,7 +3742,7 @@ export declare const digestAssessmentRows: <E, R>(records: Stream.Stream<{
3742
3742
  readonly stimulus: number;
3743
3743
  };
3744
3744
  rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
3745
- }, E | AssessmentRowsError | import("effect/PlatformError").PlatformError | Schema.SchemaError | import("#contracts/hash/text").TextHashError, R>;
3745
+ }, E | AssessmentRowsError | Schema.SchemaError, R>;
3746
3746
  /** Creates one complete content-addressed snapshot from its facts. */
3747
3747
  export declare const makeAssessmentSnapshot: (facts: {
3748
3748
  readonly activeAppLocales: readonly [("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">, ...(("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">)[]];
@@ -3772,7 +3772,7 @@ export declare const makeAssessmentSnapshot: (facts: {
3772
3772
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
3773
3773
  readonly format: "assessment-snapshot";
3774
3774
  readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
3775
- }, Schema.SchemaError | import("#contracts/hash/text").TextHashError, never>;
3775
+ }, Schema.SchemaError, never>;
3776
3776
  /** Counts every row of a snapshot. */
3777
3777
  export declare function assessmentRowCount(counts: AssessmentCounts): number;
3778
3778
  export {};
package/dist/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DateTime, Schema } from "effect";
2
- const DATE_ONLY_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/u;
2
+ const DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
3
3
  /** Checks a source-authored date against the real ISO calendar. */
4
4
  function isDateOnly(value) {
5
5
  if (!DATE_ONLY_PATTERN.test(value)) {
@@ -1,10 +1,10 @@
1
- import { Crypto, Effect, PlatformError } from "effect";
1
+ import { Effect } from "effect";
2
2
  /**
3
- * Web Crypto behind Effect's `Crypto` service. Every runtime that Aksara
4
- * contracts run in has `crypto.subtle`, so digests need no runtime layer.
3
+ * Computes the SHA-256 digest bytes of one byte sequence through Effect's
4
+ * `Digest` service on Web Crypto. Every runtime that Aksara contracts run in
5
+ * has `crypto.subtle`, so digests need no runtime layer, and a runtime without
6
+ * it is a defect rather than an expected failure.
5
7
  */
6
- export declare const webCryptoService: Crypto.Crypto;
7
- /** Computes the SHA-256 digest bytes of one byte sequence through Effect's Crypto service. */
8
- export declare const digestSha256: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, PlatformError.PlatformError, never>;
8
+ export declare const digestSha256: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, never, never>;
9
9
  /** Computes the `sha256:` identity of one byte sequence, the form every stored hash uses. */
10
- export declare const hashBytes: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, PlatformError.PlatformError, never>;
10
+ export declare const hashBytes: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
@@ -1,38 +1,17 @@
1
- import { Crypto, Effect, PlatformError } from "effect";
1
+ import { Effect } from "effect";
2
+ import { Digest } from "effect/crypto";
2
3
  import { Hex } from "effect/encoding";
3
4
  import { Sha256HashSchema } from "#contracts/ids";
4
- /** Largest byte count that one `crypto.getRandomValues` call accepts. */
5
- const RANDOM_CHUNK_BYTES = 65_536;
6
5
  /**
7
- * Web Crypto behind Effect's `Crypto` service. Every runtime that Aksara
8
- * contracts run in has `crypto.subtle`, so digests need no runtime layer.
6
+ * Computes the SHA-256 digest bytes of one byte sequence through Effect's
7
+ * `Digest` service on Web Crypto. Every runtime that Aksara contracts run in
8
+ * has `crypto.subtle`, so digests need no runtime layer, and a runtime without
9
+ * it is a defect rather than an expected failure.
9
10
  */
10
- export const webCryptoService = Crypto.make({
11
- digest: (algorithm, data) => Effect.tryPromise({
12
- catch: (cause) => PlatformError.systemError({
13
- _tag: "Unknown",
14
- cause,
15
- description: "Could not compute digest",
16
- method: "digest",
17
- module: "Crypto",
18
- }),
19
- try: () => globalThis.crypto.subtle
20
- .digest(algorithm, new Uint8Array(data))
21
- .then((digest) => new Uint8Array(digest)),
22
- }),
23
- randomBytes: (size) => {
24
- const bytes = new Uint8Array(size);
25
- for (let offset = 0; offset < size; offset += RANDOM_CHUNK_BYTES) {
26
- globalThis.crypto.getRandomValues(bytes.subarray(offset, offset + RANDOM_CHUNK_BYTES));
27
- }
28
- return bytes;
29
- },
30
- });
31
- /** Computes the SHA-256 digest bytes of one byte sequence through Effect's Crypto service. */
32
11
  export const digestSha256 = Effect.fn("AksaraContracts.digestSha256")(function* (bytes) {
33
- const crypto = yield* Crypto.Crypto;
34
- return yield* crypto.digest("SHA-256", bytes);
35
- }, Effect.provideService(Crypto.Crypto, webCryptoService));
12
+ const digest = yield* Digest.Digest;
13
+ return yield* digest.digest(Digest.sha256, bytes);
14
+ }, Effect.provide(Digest.layerWebCrypto));
36
15
  /** Computes the `sha256:` identity of one byte sequence, the form every stored hash uses. */
37
16
  export const hashBytes = Effect.fn("AksaraContracts.hashBytes")(function* (bytes) {
38
17
  const digest = yield* digestSha256(bytes);
@@ -8,5 +8,5 @@ export declare class DigestStream {
8
8
  /** Appends one piece of text in the order the stream was built. */
9
9
  add(text: string): void;
10
10
  /** Digests every piece in order and returns the branded sha256 identity. */
11
- digest(): import("effect/Effect").Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, import("effect/PlatformError").PlatformError, never>;
11
+ digest(): import("effect/Effect").Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
12
12
  }
@@ -1,12 +1,3 @@
1
- import { Effect, Schema } from "effect";
2
- declare const TextHashError_base: Schema.Class<TextHashError, Schema.TaggedStruct<"TextHashError", {
3
- readonly cause: Schema.Unknown;
4
- }>, import("effect/Cause").YieldableError & {
5
- readonly brand: unique symbol;
6
- }>;
7
- /** Web Crypto could not hash one UTF-8 contract value. */
8
- export declare class TextHashError extends TextHashError_base {
9
- }
10
- /** Hashes exact UTF-8 text through the Web Crypto contract. */
11
- export declare const hashText: (value: string) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, TextHashError, never>;
12
- export {};
1
+ import { Effect } from "effect";
2
+ /** Hashes exact UTF-8 text through the SHA-256 contract. */
3
+ export declare const hashText: (value: string) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
package/dist/hash/text.js CHANGED
@@ -1,7 +1,4 @@
1
- import { Effect, Schema } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { hashBytes } from "#contracts/hash/digest";
3
- /** Web Crypto could not hash one UTF-8 contract value. */
4
- export class TextHashError extends Schema.TaggedError()("TextHashError", { cause: Schema.Unknown }) {
5
- }
6
- /** Hashes exact UTF-8 text through the Web Crypto contract. */
7
- export const hashText = Effect.fn("AksaraContracts.hashText")((value) => hashBytes(new TextEncoder().encode(value)).pipe(Effect.mapError((cause) => new TextHashError({ cause }))));
3
+ /** Hashes exact UTF-8 text through the SHA-256 contract. */
4
+ export const hashText = Effect.fn("AksaraContracts.hashText")((value) => hashBytes(new TextEncoder().encode(value)));
package/dist/ids.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { Schema } from "effect";
2
- const HEX_40_PATTERN = /^[a-f\d]{40}$/;
3
- const SHA256_PATTERN = /^sha256:[a-f\d]{64}$/;
4
- const ED25519_SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{85}[AQgw]$/;
5
- const SIGNING_KEY_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
2
+ const HEX_40_PATTERN = /^[a-f\d]{40}$/u;
3
+ const SHA256_PATTERN = /^sha256:[a-f\d]{64}$/u;
4
+ const ED25519_SIGNATURE_PATTERN = /^[A-Za-z0-9_-]{85}[AQgw]$/u;
5
+ const SIGNING_KEY_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/u;
6
6
  /** Maximum wire length shared by every published content identity. */
7
7
  export const CONTENT_KEY_MAX_LENGTH = 512;
8
- const CONTENT_KEY_PATTERN = /^[a-z0-9][a-z0-9._:/-]*$/;
9
- const RELEASE_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,127}$/;
10
- const PUBLIC_PATH_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/;
11
- const CORPUS_SOURCE_PATH_PATTERN = /^packages\/corpus\/[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)+$/;
8
+ const CONTENT_KEY_PATTERN = /^[a-z0-9][a-z0-9._:/-]*$/u;
9
+ const RELEASE_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,127}$/u;
10
+ const PUBLIC_PATH_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/u;
11
+ const CORPUS_SOURCE_PATH_PATTERN = /^packages\/corpus\/[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)+$/u;
12
12
  /** Checks whether a value is a complete lowercase Git commit SHA. */
13
13
  function isGitCommitSha(value) {
14
14
  return HEX_40_PATTERN.test(value);
@@ -46,7 +46,7 @@ export declare const computePreviewRendererProof: (input: {
46
46
  readonly nonce: PreviewRendererNonce;
47
47
  readonly secret: PreviewRendererSecret;
48
48
  }) => Effect.Effect<string, PreviewRendererAuthError, never>;
49
- /** Verifies one proof with the HMAC verification of Web Crypto, which compares in constant time. */
49
+ /** Verifies one proof with Effect's HMAC verification, which compares in constant time. */
50
50
  export declare const verifyPreviewRendererProof: (input: {
51
51
  readonly manifestHash: typeof Sha256HashSchema.Type;
52
52
  readonly nonce: PreviewRendererNonce;
@@ -1,4 +1,5 @@
1
- import { Effect, Schema } from "effect";
1
+ import { Effect, Layer, Schema } from "effect";
2
+ import { Mac, SecureRandom } from "effect/crypto";
2
3
  import { Base64Url } from "effect/encoding";
3
4
  import { RendererManifestEnvelopeSchema } from "#contracts/renderer/contract";
4
5
  import { encodeJsonText } from "#contracts/text/json";
@@ -30,35 +31,38 @@ export function canonicalizePreviewRendererAuth(input) {
30
31
  input.manifestHash,
31
32
  ]);
32
33
  }
33
- /** Imports the process-local secret as one HMAC-SHA256 key through Web Crypto. */
34
- const importPreviewRendererKey = Effect.fn("AksaraContracts.importPreviewRendererKey")(function* (secret) {
35
- const raw = yield* Effect.fromResult(Base64Url.decode(secret)).pipe(Effect.orDie);
36
- return yield* Effect.tryPromise({
37
- catch: () => new PreviewRendererAuthError({ reason: "compute" }),
38
- try: () => globalThis.crypto.subtle.importKey("raw", raw, { hash: "SHA-256", name: "HMAC" }, false, ["sign", "verify"]),
39
- });
40
- });
34
+ /**
35
+ * HMAC on Web Crypto. Every runtime that Aksara contracts run in has
36
+ * `crypto.subtle`, so the layer is provided here and callers need no runtime
37
+ * layer.
38
+ */
39
+ const MacLayer = Mac.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto));
40
+ /**
41
+ * Reads the process-local secret as one HMAC-SHA256 key. Its schema admits
42
+ * only the 43-character base64url text of 32 bytes, so it always decodes.
43
+ */
44
+ function previewRendererKey(secret) {
45
+ return Effect.fromResult(Base64Url.decode(secret)).pipe(Effect.flatMap((raw) => Mac.key(Mac.hmacSha256, raw)), Effect.orDie);
46
+ }
41
47
  /** Computes one renderer response proof from a process-local secret. */
42
48
  export const computePreviewRendererProof = Effect.fn("AksaraContracts.computePreviewRendererProof")(function* (input) {
43
- const key = yield* importPreviewRendererKey(input.secret);
44
- const message = new TextEncoder().encode(canonicalizePreviewRendererAuth(input));
45
- const tag = yield* Effect.tryPromise({
46
- catch: () => new PreviewRendererAuthError({ reason: "compute" }),
47
- try: () => globalThis.crypto.subtle.sign("HMAC", key, message),
48
- });
49
- return PreviewRendererProofSchema.make(Base64Url.encode(new Uint8Array(tag)));
50
- });
51
- /** Verifies one proof with the HMAC verification of Web Crypto, which compares in constant time. */
49
+ const key = yield* previewRendererKey(input.secret);
50
+ const mac = yield* Mac.Mac;
51
+ const tag = yield* mac
52
+ .sign(key, new TextEncoder().encode(canonicalizePreviewRendererAuth(input)))
53
+ .pipe(Effect.mapError(() => new PreviewRendererAuthError({ reason: "compute" })));
54
+ return PreviewRendererProofSchema.make(Base64Url.encode(tag));
55
+ }, Effect.provide(MacLayer));
56
+ /** Verifies one proof with Effect's HMAC verification, which compares in constant time. */
52
57
  export const verifyPreviewRendererProof = Effect.fn("AksaraContracts.verifyPreviewRendererProof")(function* (input) {
53
- const key = yield* importPreviewRendererKey(input.secret);
54
- const message = new TextEncoder().encode(canonicalizePreviewRendererAuth(input));
58
+ const key = yield* previewRendererKey(input.secret);
55
59
  const tag = yield* Effect.fromResult(Base64Url.decode(input.proof)).pipe(Effect.orDie);
56
- const valid = yield* Effect.tryPromise({
57
- catch: () => new PreviewRendererAuthError({ reason: "compute" }),
58
- try: () => globalThis.crypto.subtle.verify("HMAC", key, tag, message),
59
- });
60
+ const mac = yield* Mac.Mac;
61
+ const valid = yield* mac
62
+ .verify(key, tag, new TextEncoder().encode(canonicalizePreviewRendererAuth(input)))
63
+ .pipe(Effect.mapError(() => new PreviewRendererAuthError({ reason: "compute" })));
60
64
  if (valid) {
61
65
  return;
62
66
  }
63
67
  return yield* new PreviewRendererAuthError({ reason: "invalid" });
64
- });
68
+ }, Effect.provide(MacLayer));
@@ -1,6 +1,5 @@
1
1
  import { Effect, Schema, Stream } from "effect";
2
2
  import type { ActiveAppLocaleList } from "#contracts/locale";
3
- import { ProgramRowHashError } from "#contracts/program/snapshot/hash";
4
3
  import { type ProgramSnapshotRow } from "#contracts/program/snapshot/row";
5
4
  import type { ProgramCounts } from "#contracts/program/snapshot/spec";
6
5
  declare const ProgramDigestError_base: Schema.Class<ProgramDigestError, Schema.TaggedStruct<"ProgramDigestError", {
@@ -24,5 +23,5 @@ export declare const digestProgramRows: <E, R>(input: {
24
23
  sitemapCount: number;
25
24
  slugCount: number;
26
25
  rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
27
- }, E | ProgramDigestError | ProgramRowHashError, R>;
26
+ }, E | ProgramDigestError, R>;
28
27
  export {};
@@ -1,7 +1,7 @@
1
1
  import { Array as Arr, Effect, MutableHashMap, MutableHashSet, Option, Schema, Stream, } from "effect";
2
2
  import { DigestStream } from "#contracts/hash/stream";
3
3
  import { curriculumNamespace, } from "#contracts/program/curriculum";
4
- import { ProgramRowHashError, verifyProgramSnapshotRowHash, } from "#contracts/program/snapshot/hash";
4
+ import { verifyProgramSnapshotRowHash } from "#contracts/program/snapshot/hash";
5
5
  import { canonicalizeProgramSnapshotRow, } from "#contracts/program/snapshot/row";
6
6
  import { encodeJsonText } from "#contracts/text/json";
7
7
  import { compareCodeUnits } from "#contracts/text/order";
@@ -114,9 +114,7 @@ class ProgramDigestState {
114
114
  }
115
115
  /** Digests the complete canonical stream once. */
116
116
  digest() {
117
- return this.#stream
118
- .digest()
119
- .pipe(Effect.mapError(() => new ProgramRowHashError({ scope: "digest" })));
117
+ return this.#stream.digest();
120
118
  }
121
119
  /** Adds one catalog row before any current curriculum records. */
122
120
  #addProgram(record) {
@@ -1,20 +1,6 @@
1
- import { Effect, Schema } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { type ProgramSnapshotRow } from "#contracts/program/snapshot/row";
3
3
  import { type ProgramSnapshot, type ProgramSnapshotFacts } from "#contracts/program/snapshot/spec";
4
- declare const ProgramSnapshotHashError_base: Schema.Class<ProgramSnapshotHashError, Schema.TaggedStruct<"ProgramSnapshotHashError", {}>, import("effect/Cause").YieldableError & {
5
- readonly brand: unique symbol;
6
- }>;
7
- /** Node could not compute a deterministic program snapshot identity. */
8
- export declare class ProgramSnapshotHashError extends ProgramSnapshotHashError_base {
9
- }
10
- declare const ProgramRowHashError_base: Schema.Class<ProgramRowHashError, Schema.TaggedStruct<"ProgramRowHashError", {
11
- readonly scope: Schema.Literals<readonly ["digest", "row"]>;
12
- }>, import("effect/Cause").YieldableError & {
13
- readonly brand: unique symbol;
14
- }>;
15
- /** Node could not compute one deterministic program row identity. */
16
- export declare class ProgramRowHashError extends ProgramRowHashError_base {
17
- }
18
4
  /** Serializes current program facts in stable signed field order. */
19
5
  export declare function canonicalizeProgramSnapshot(input: ProgramSnapshotFacts): string;
20
6
  /** Creates the content-addressed identity of one complete program snapshot. */
@@ -36,9 +22,9 @@ export declare const makeProgramSnapshot: (input: {
36
22
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
37
23
  readonly format: "localized-program-snapshot";
38
24
  readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
39
- }, ProgramSnapshotHashError, never>;
25
+ }, never, never>;
40
26
  /** Recomputes the content identity of one stored current snapshot. */
41
- export declare function verifyProgramSnapshotHash(snapshot: ProgramSnapshot): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ProgramSnapshotHashError, never>;
27
+ export declare function verifyProgramSnapshotHash(snapshot: ProgramSnapshot): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
42
28
  /** Creates one authenticated current program record. */
43
29
  export declare const makeProgramSnapshotRow: (row: {
44
30
  readonly defaultCoverageStatus: "archived" | "available" | "hidden" | "partial" | "planned";
@@ -130,7 +116,7 @@ export declare const makeProgramSnapshotRow: (row: {
130
116
  };
131
117
  };
132
118
  readonly rowHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
133
- }, ProgramRowHashError, never>;
119
+ }, never, never>;
134
120
  /** Creates one authenticated current curriculum record. */
135
121
  export declare const makeCurriculumSnapshotRow: (row: {
136
122
  readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
@@ -182,7 +168,6 @@ export declare const makeCurriculumSnapshotRow: (row: {
182
168
  readonly title: string;
183
169
  };
184
170
  readonly rowHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
185
- }, ProgramRowHashError, never>;
171
+ }, never, never>;
186
172
  /** Recomputes one current row identity for streamed integrity checks. */
187
- export declare function verifyProgramSnapshotRowHash(record: ProgramSnapshotRow): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ProgramRowHashError, never>;
188
- export {};
173
+ export declare function verifyProgramSnapshotRowHash(record: ProgramSnapshotRow): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
@@ -1,16 +1,10 @@
1
- import { Effect, Schema } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { hashText } from "#contracts/hash/text";
3
3
  import { CurriculumRouteRecordSchema, canonicalizeProgramSnapshotRow, LearningProgramRecordSchema, } from "#contracts/program/snapshot/row";
4
4
  import { PROGRAM_SNAPSHOT_FORMAT, ProgramSnapshotSchema, } from "#contracts/program/snapshot/spec";
5
5
  import { encodeJsonText } from "#contracts/text/json";
6
6
  const SNAPSHOT_DOMAIN = "nakafa.aksara.localized-program-snapshot";
7
7
  const ROW_DOMAIN = "nakafa.aksara.program-row";
8
- /** Node could not compute a deterministic program snapshot identity. */
9
- export class ProgramSnapshotHashError extends Schema.TaggedError()("ProgramSnapshotHashError", {}) {
10
- }
11
- /** Node could not compute one deterministic program row identity. */
12
- export class ProgramRowHashError extends Schema.TaggedError()("ProgramRowHashError", { scope: Schema.Literals(["digest", "row"]) }) {
13
- }
14
8
  /** Serializes current program facts in stable signed field order. */
15
9
  export function canonicalizeProgramSnapshot(input) {
16
10
  return encodeJsonText({
@@ -26,7 +20,7 @@ export function canonicalizeProgramSnapshot(input) {
26
20
  }
27
21
  /** Creates the content-addressed identity of one complete program snapshot. */
28
22
  export const makeProgramSnapshot = Effect.fn("AksaraContracts.makeProgramSnapshot")(function* (input) {
29
- const snapshotId = yield* hashText(`${SNAPSHOT_DOMAIN}\n${canonicalizeProgramSnapshot(input)}`).pipe(Effect.mapError(() => new ProgramSnapshotHashError()));
23
+ const snapshotId = yield* hashText(`${SNAPSHOT_DOMAIN}\n${canonicalizeProgramSnapshot(input)}`);
30
24
  return ProgramSnapshotSchema.make({
31
25
  ...input,
32
26
  format: PROGRAM_SNAPSHOT_FORMAT,
@@ -40,7 +34,7 @@ export function verifyProgramSnapshotHash(snapshot) {
40
34
  }
41
35
  /** Hashes one current program or curriculum row. */
42
36
  function hashProgramRow(record) {
43
- return hashText(`${ROW_DOMAIN}\n${canonicalizeProgramSnapshotRow(record)}`).pipe(Effect.mapError(() => new ProgramRowHashError({ scope: "row" })));
37
+ return hashText(`${ROW_DOMAIN}\n${canonicalizeProgramSnapshotRow(record)}`);
44
38
  }
45
39
  /** Creates one authenticated current program record. */
46
40
  export const makeProgramSnapshotRow = Effect.fn("AksaraContracts.makeProgramSnapshotRow")(function* (row) {