@nakafa/aksara-contracts 1.0.1 → 3.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 (214) hide show
  1. package/README.md +10 -27
  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/{question → assessment}/answer.d.ts +14 -58
  10. package/dist/{question → assessment}/answer.js +13 -60
  11. package/dist/assessment/catalog.d.ts +235 -0
  12. package/dist/assessment/catalog.js +115 -0
  13. package/dist/assessment/chart.d.ts +62 -0
  14. package/dist/assessment/chart.js +64 -0
  15. package/dist/assessment/closure.d.ts +28 -0
  16. package/dist/assessment/closure.js +164 -0
  17. package/dist/assessment/explanation.d.ts +13 -8
  18. package/dist/assessment/explanation.js +14 -8
  19. package/dist/assessment/figure.d.ts +140 -1
  20. package/dist/assessment/figure.js +9 -2
  21. package/dist/assessment/hash.d.ts +352 -212
  22. package/dist/assessment/hash.js +14 -0
  23. package/dist/assessment/inline.d.ts +3 -1
  24. package/dist/assessment/inline.js +20 -5
  25. package/dist/assessment/item.d.ts +8 -4
  26. package/dist/assessment/item.js +6 -2
  27. package/dist/assessment/key.js +6 -6
  28. package/dist/assessment/paper.d.ts +74 -74
  29. package/dist/assessment/snapshot.d.ts +3778 -0
  30. package/dist/assessment/snapshot.js +192 -0
  31. package/dist/cache/content.d.ts +4 -4
  32. package/dist/canonical.d.ts +6 -0
  33. package/dist/canonical.js +8 -1
  34. package/dist/content.d.ts +1 -1
  35. package/dist/content.js +0 -1
  36. package/dist/delivery.d.ts +0 -3
  37. package/dist/delivery.js +0 -5
  38. package/dist/hash/digest.d.ts +7 -7
  39. package/dist/hash/digest.js +9 -30
  40. package/dist/hash/stream.d.ts +1 -1
  41. package/dist/hash/text.d.ts +3 -12
  42. package/dist/hash/text.js +3 -6
  43. package/dist/ids.js +8 -8
  44. package/dist/preview/artifact.d.ts +1 -120
  45. package/dist/preview/auth.d.ts +1 -1
  46. package/dist/preview/auth.js +29 -25
  47. package/dist/preview/document.d.ts +0 -586
  48. package/dist/preview/document.js +1 -47
  49. package/dist/preview/spec.d.ts +6 -1984
  50. package/dist/preview/spec.js +7 -47
  51. package/dist/preview/target.d.ts +0 -173
  52. package/dist/preview/target.js +1 -70
  53. package/dist/program/snapshot/digest.d.ts +1 -2
  54. package/dist/program/snapshot/digest.js +2 -4
  55. package/dist/program/snapshot/hash.d.ts +6 -21
  56. package/dist/program/snapshot/hash.js +3 -9
  57. package/dist/projection/digest.d.ts +7 -143
  58. package/dist/projection/digest.js +7 -13
  59. package/dist/projection/hash.d.ts +2 -138
  60. package/dist/projection/hash.js +2 -5
  61. package/dist/projection/material.js +1 -1
  62. package/dist/projection/spec.d.ts +6 -211
  63. package/dist/projection/spec.js +4 -18
  64. package/dist/projection/verify.d.ts +1 -128
  65. package/dist/projection/verify.js +1 -4
  66. package/dist/quran/provenance.d.ts +2 -8
  67. package/dist/quran/provenance.js +1 -4
  68. package/dist/quran/snapshot/digest.d.ts +1 -2
  69. package/dist/quran/snapshot/digest.js +2 -2
  70. package/dist/quran/snapshot/hash.d.ts +3 -10
  71. package/dist/quran/snapshot/hash.js +2 -5
  72. package/dist/quran/snapshot/row/hash.d.ts +3 -12
  73. package/dist/quran/snapshot/row/hash.js +2 -5
  74. package/dist/release/canonical.d.ts +2 -2
  75. package/dist/release/current/evidence.d.ts +24 -24
  76. package/dist/release/current/state.d.ts +28 -56
  77. package/dist/release/current/state.js +1 -6
  78. package/dist/release/digest.d.ts +9 -18
  79. package/dist/release/digest.js +7 -13
  80. package/dist/release/hash.d.ts +7 -16
  81. package/dist/release/hash.js +2 -6
  82. package/dist/release/head.d.ts +10 -57
  83. package/dist/release/head.js +3 -14
  84. package/dist/release/identity.d.ts +3 -3
  85. package/dist/release/items.d.ts +3 -3
  86. package/dist/release/items.js +1 -1
  87. package/dist/release/lifecycle.d.ts +18 -18
  88. package/dist/release/policy.d.ts +3 -4
  89. package/dist/release/policy.js +2 -11
  90. package/dist/release/result/digest.d.ts +11 -31
  91. package/dist/release/result/digest.js +5 -11
  92. package/dist/release/rollback/digest.d.ts +11 -35
  93. package/dist/release/rollback/digest.js +7 -13
  94. package/dist/release/rollback/spec.d.ts +30 -792
  95. package/dist/release/rollback/spec.js +1 -4
  96. package/dist/release/route/digest.d.ts +7 -16
  97. package/dist/release/route/digest.js +7 -13
  98. package/dist/release/route/verify.d.ts +1 -1
  99. package/dist/release/route/verify.js +1 -1
  100. package/dist/release/snapshot/data.d.ts +599 -249
  101. package/dist/release/snapshot/data.js +11 -28
  102. package/dist/release/snapshot/evidence/assessment.d.ts +26 -0
  103. package/dist/release/snapshot/evidence/assessment.js +44 -0
  104. package/dist/release/snapshot/evidence/program.d.ts +1 -1
  105. package/dist/release/snapshot/evidence/quran.d.ts +1 -1
  106. package/dist/release/snapshot/evidence/requirement.d.ts +1 -1
  107. package/dist/release/snapshot/evidence.d.ts +19 -19
  108. package/dist/release/snapshot/evidence.js +2 -2
  109. package/dist/release/snapshot/scope.d.ts +5 -5
  110. package/dist/release/snapshot/scope.js +1 -1
  111. package/dist/release/snapshot/spec.d.ts +15 -15
  112. package/dist/release/snapshot/spec.js +8 -8
  113. package/dist/release/snapshot/verify.d.ts +1278 -268
  114. package/dist/release/snapshot/verify.js +8 -5
  115. package/dist/release/spec.d.ts +33 -33
  116. package/dist/release/verify.d.ts +7 -7
  117. package/dist/renderer/compatibility.d.ts +1 -1
  118. package/dist/renderer/component.js +1 -1
  119. package/dist/renderer/contract.d.ts +0 -8
  120. package/dist/renderer/contract.js +0 -3
  121. package/dist/renderer/manifest.d.ts +3 -3
  122. package/dist/renderer/manifest.js +2 -2
  123. package/dist/runtime/spec.d.ts +38 -38
  124. package/dist/runtime/spec.js +4 -5
  125. package/dist/runtime/verify.d.ts +42 -42
  126. package/dist/signature/key.d.ts +0 -2
  127. package/dist/signature/key.js +37 -88
  128. package/dist/signature/spec.d.ts +5 -5
  129. package/dist/signature/spec.js +0 -1
  130. package/dist/signature/verify.js +31 -46
  131. package/dist/transport/batch.d.ts +6 -244
  132. package/dist/transport/failure.d.ts +6 -20
  133. package/dist/transport/failure.js +0 -10
  134. package/dist/transport/group.d.ts +1969 -1369
  135. package/dist/transport/group.js +0 -2
  136. package/dist/transport/request.d.ts +10691 -5086
  137. package/dist/transport/request.js +0 -3
  138. package/dist/transport/response.d.ts +219 -1442
  139. package/dist/transport/response.js +0 -4
  140. package/dist/transport/snapshot.d.ts +1187 -487
  141. package/dist/tree.js +1 -1
  142. package/package.json +188 -296
  143. package/dist/projection/question.d.ts +0 -1067
  144. package/dist/projection/question.js +0 -121
  145. package/dist/question/identity.d.ts +0 -175
  146. package/dist/question/identity.js +0 -207
  147. package/dist/question/item.d.ts +0 -450
  148. package/dist/question/item.js +0 -174
  149. package/dist/question/label.d.ts +0 -3
  150. package/dist/question/label.js +0 -3
  151. package/dist/question/points.d.ts +0 -18
  152. package/dist/question/points.js +0 -22
  153. package/dist/question/response.d.ts +0 -289
  154. package/dist/question/response.js +0 -167
  155. package/dist/question/rubric.d.ts +0 -234
  156. package/dist/question/rubric.js +0 -186
  157. package/dist/release/current/runtime.d.ts +0 -4
  158. package/dist/release/current/runtime.js +0 -15
  159. package/dist/release/snapshot/evidence/tryout.d.ts +0 -22
  160. package/dist/release/snapshot/evidence/tryout.js +0 -91
  161. package/dist/runtime/protected/limits.d.ts +0 -10
  162. package/dist/runtime/protected/limits.js +0 -16
  163. package/dist/runtime/protected/spec.d.ts +0 -310
  164. package/dist/runtime/protected/spec.js +0 -80
  165. package/dist/runtime/protected/verify.d.ts +0 -83
  166. package/dist/runtime/protected/verify.js +0 -70
  167. package/dist/transport/runtime.d.ts +0 -77
  168. package/dist/transport/runtime.js +0 -33
  169. package/dist/tryout/canonical.d.ts +0 -12
  170. package/dist/tryout/canonical.js +0 -7
  171. package/dist/tryout/catalog.d.ts +0 -396
  172. package/dist/tryout/catalog.js +0 -155
  173. package/dist/tryout/closure/accounting.d.ts +0 -20
  174. package/dist/tryout/closure/accounting.js +0 -70
  175. package/dist/tryout/closure/locale.d.ts +0 -14
  176. package/dist/tryout/closure/locale.js +0 -113
  177. package/dist/tryout/closure/placement.d.ts +0 -5
  178. package/dist/tryout/closure/placement.js +0 -32
  179. package/dist/tryout/digest.d.ts +0 -34
  180. package/dist/tryout/digest.js +0 -57
  181. package/dist/tryout/hash/catalog.d.ts +0 -364
  182. package/dist/tryout/hash/catalog.js +0 -209
  183. package/dist/tryout/hash/content.d.ts +0 -215
  184. package/dist/tryout/hash/content.js +0 -75
  185. package/dist/tryout/hash/placement.d.ts +0 -242
  186. package/dist/tryout/hash/placement.js +0 -56
  187. package/dist/tryout/identity.d.ts +0 -12
  188. package/dist/tryout/identity.js +0 -47
  189. package/dist/tryout/key.d.ts +0 -4
  190. package/dist/tryout/key.js +0 -8
  191. package/dist/tryout/language.d.ts +0 -24
  192. package/dist/tryout/language.js +0 -30
  193. package/dist/tryout/placement.d.ts +0 -331
  194. package/dist/tryout/placement.js +0 -96
  195. package/dist/tryout/runtime/canonical.d.ts +0 -8
  196. package/dist/tryout/runtime/canonical.js +0 -34
  197. package/dist/tryout/runtime/hash.d.ts +0 -34
  198. package/dist/tryout/runtime/hash.js +0 -13
  199. package/dist/tryout/runtime/source.d.ts +0 -44
  200. package/dist/tryout/runtime/source.js +0 -47
  201. package/dist/tryout/runtime/spec.d.ts +0 -58
  202. package/dist/tryout/runtime/spec.js +0 -21
  203. package/dist/tryout/runtime/verify.d.ts +0 -69
  204. package/dist/tryout/runtime/verify.js +0 -67
  205. package/dist/tryout/scoring.d.ts +0 -148
  206. package/dist/tryout/scoring.js +0 -98
  207. package/dist/tryout/snapshot/canonical.d.ts +0 -7
  208. package/dist/tryout/snapshot/canonical.js +0 -18
  209. package/dist/tryout/snapshot/hash.d.ts +0 -49
  210. package/dist/tryout/snapshot/hash.js +0 -22
  211. package/dist/tryout/snapshot/spec.d.ts +0 -46
  212. package/dist/tryout/snapshot/spec.js +0 -30
  213. package/dist/tryout/spec.d.ts +0 -41
  214. package/dist/tryout/spec.js +0 -46
@@ -0,0 +1,192 @@
1
+ import { Array as Arr, Effect, Option, Order, Schema, Stream } from "effect";
2
+ import { CatalogRowSchema, catalogRowIdentity, } from "#contracts/assessment/catalog";
3
+ import { ItemExplanationSchema } from "#contracts/assessment/explanation";
4
+ import { canonicalJson } from "#contracts/assessment/hash";
5
+ import { ItemFamilySchema, ItemVersionSchema, } from "#contracts/assessment/item";
6
+ import { ItemKeySchema } from "#contracts/assessment/key";
7
+ import { PaperSchema } from "#contracts/assessment/paper";
8
+ import { ExamProfileSchema } from "#contracts/assessment/profile";
9
+ import { StimulusVersionSchema } from "#contracts/assessment/stimulus";
10
+ import { canonicalOrder } from "#contracts/canonical";
11
+ import { DigestStream } from "#contracts/hash/stream";
12
+ import { hashText } from "#contracts/hash/text";
13
+ import { Sha256HashSchema } from "#contracts/ids";
14
+ import { ActiveAppLocaleListSchema } from "#contracts/locale";
15
+ import { compareCodeUnits } from "#contracts/text/order";
16
+ /** Semantic wire identity of the assessment snapshot. */
17
+ export const ASSESSMENT_SNAPSHOT_FORMAT = "assessment-snapshot";
18
+ /** Separates the hash of one snapshot row from the hash of any other record. */
19
+ const ROW_DOMAIN = "nakafa.aksara.assessment-row";
20
+ /** Separates the digest of the rows of a snapshot from any other digest. */
21
+ const ROWS_DOMAIN = "nakafa.aksara.assessment-rows";
22
+ /** Separates the identity of a snapshot from the hash of any other record. */
23
+ const SNAPSHOT_DOMAIN = "nakafa.aksara.assessment-snapshot";
24
+ /**
25
+ * Every row of an assessment snapshot, by kind, in the order a snapshot
26
+ * streams them: the catalog first, then the profiles and papers it names,
27
+ * then the items, their readings, keys, and explanations.
28
+ */
29
+ export const AssessmentRowSchema = Schema.Union([
30
+ Schema.Struct({ kind: Schema.Literal("catalog"), row: CatalogRowSchema }),
31
+ Schema.Struct({
32
+ hash: Sha256HashSchema,
33
+ kind: Schema.Literal("profile"),
34
+ profile: ExamProfileSchema,
35
+ }),
36
+ Schema.Struct({
37
+ hash: Sha256HashSchema,
38
+ kind: Schema.Literal("paper"),
39
+ paper: PaperSchema,
40
+ }),
41
+ Schema.Struct({ family: ItemFamilySchema, kind: Schema.Literal("family") }),
42
+ Schema.Struct({ kind: Schema.Literal("item"), version: ItemVersionSchema }),
43
+ Schema.Struct({
44
+ kind: Schema.Literal("stimulus"),
45
+ version: StimulusVersionSchema,
46
+ }),
47
+ Schema.Struct({ key: ItemKeySchema, kind: Schema.Literal("key") }),
48
+ Schema.Struct({
49
+ explanation: ItemExplanationSchema,
50
+ kind: Schema.Literal("explanation"),
51
+ }),
52
+ ]);
53
+ /** The kinds of row in the order a snapshot streams them. */
54
+ export const ASSESSMENT_ROW_KINDS = Arr.map(AssessmentRowSchema.members, ({ fields }) => fields.kind.literal);
55
+ /** One row bound to the hash of its canonical encoding. */
56
+ export const AssessmentRecordSchema = Schema.Struct({
57
+ row: AssessmentRowSchema,
58
+ rowHash: Sha256HashSchema,
59
+ });
60
+ const NonNegativeCountSchema = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
61
+ /** How many rows of each kind one snapshot holds. */
62
+ export const AssessmentCountsSchema = Schema.Struct({
63
+ catalog: NonNegativeCountSchema,
64
+ explanation: NonNegativeCountSchema,
65
+ family: NonNegativeCountSchema,
66
+ item: NonNegativeCountSchema,
67
+ key: NonNegativeCountSchema,
68
+ paper: NonNegativeCountSchema,
69
+ profile: NonNegativeCountSchema,
70
+ stimulus: NonNegativeCountSchema,
71
+ });
72
+ const SnapshotFactFields = {
73
+ activeAppLocales: ActiveAppLocaleListSchema,
74
+ counts: AssessmentCountsSchema,
75
+ rowDigest: Sha256HashSchema,
76
+ };
77
+ /** The facts of a snapshot that its identity covers. */
78
+ export const AssessmentSnapshotFactsSchema = Schema.Struct(SnapshotFactFields);
79
+ /** One content-addressed assessment snapshot, selected by a release. */
80
+ export const AssessmentSnapshotSchema = Schema.Struct({
81
+ ...SnapshotFactFields,
82
+ format: Schema.Literal(ASSESSMENT_SNAPSHOT_FORMAT),
83
+ snapshotId: Sha256HashSchema,
84
+ });
85
+ /**
86
+ * The identity of one row, unique within its kind, which orders the rows of a
87
+ * kind in a snapshot: a catalog node, a profile or a paper by identifier, a
88
+ * family by identifier, a version by its family or reading and its language, a
89
+ * key by the version it answers, and an explanation by its version and
90
+ * language.
91
+ */
92
+ export function assessmentRowIdentity(row) {
93
+ if (row.kind === "catalog") {
94
+ return catalogRowIdentity(row.row);
95
+ }
96
+ if (row.kind === "profile") {
97
+ return row.profile.id;
98
+ }
99
+ if (row.kind === "paper") {
100
+ return row.paper.id;
101
+ }
102
+ if (row.kind === "family") {
103
+ return row.family.id;
104
+ }
105
+ if (row.kind === "item") {
106
+ return `${row.version.family}\0${row.version.deliveryLanguage}`;
107
+ }
108
+ if (row.kind === "stimulus") {
109
+ return `${row.version.id}\0${row.version.deliveryLanguage}`;
110
+ }
111
+ if (row.kind === "key") {
112
+ return row.key.version;
113
+ }
114
+ return `${row.explanation.version}\0${row.explanation.language}`;
115
+ }
116
+ /** Orders rows as a snapshot streams them: by kind, then by identity. */
117
+ export const AssessmentRowOrder = Order.combine(Order.mapInput(canonicalOrder(ASSESSMENT_ROW_KINDS), (row) => row.kind), Order.mapInput(Order.make(compareCodeUnits), assessmentRowIdentity));
118
+ /** Computes the hash of one row from its canonical encoding. */
119
+ export const hashAssessmentRow = Effect.fn("AksaraContracts.hashAssessmentRow")(function* (row) {
120
+ return yield* hashText(`${ROW_DOMAIN}\n${yield* canonicalJson(row)}`);
121
+ });
122
+ /** A row stream is out of canonical order, holds a row twice, or carries a wrong hash. */
123
+ export class AssessmentRowsError extends Schema.TaggedError()("AssessmentRowsError", {
124
+ identity: Schema.String,
125
+ kind: Schema.Literals(ASSESSMENT_ROW_KINDS),
126
+ reason: Schema.Literals(["hash", "order"]),
127
+ }) {
128
+ }
129
+ /**
130
+ * Digests one row stream in canonical order. Each row must carry the hash of
131
+ * its own canonical encoding and follow the row before it, so a stream that
132
+ * is tampered, duplicated, or unsorted fails. Returns the count of each kind
133
+ * and the digest over every row.
134
+ */
135
+ export const digestAssessmentRows = Effect.fn("AksaraContracts.digestAssessmentRows")(function* (records) {
136
+ const stream = new DigestStream();
137
+ stream.add(`${ROWS_DOMAIN}\n`);
138
+ const initial = {
139
+ counts: AssessmentCountsSchema.make({
140
+ catalog: 0,
141
+ explanation: 0,
142
+ family: 0,
143
+ item: 0,
144
+ key: 0,
145
+ paper: 0,
146
+ profile: 0,
147
+ stimulus: 0,
148
+ }),
149
+ previous: Option.none(),
150
+ };
151
+ const state = yield* records.pipe(Stream.runFoldEffect(() => initial, (current, record) => Effect.gen(function* () {
152
+ const identity = assessmentRowIdentity(record.row);
153
+ if (Option.isSome(current.previous) &&
154
+ AssessmentRowOrder(current.previous.value, record.row) >= 0) {
155
+ return yield* new AssessmentRowsError({
156
+ identity,
157
+ kind: record.row.kind,
158
+ reason: "order",
159
+ });
160
+ }
161
+ const canonical = yield* canonicalJson(record.row);
162
+ if ((yield* hashText(`${ROW_DOMAIN}\n${canonical}`)) !== record.rowHash) {
163
+ return yield* new AssessmentRowsError({
164
+ identity,
165
+ kind: record.row.kind,
166
+ reason: "hash",
167
+ });
168
+ }
169
+ stream.add(`${canonical}\0${record.rowHash}\n`);
170
+ return {
171
+ counts: {
172
+ ...current.counts,
173
+ [record.row.kind]: current.counts[record.row.kind] + 1,
174
+ },
175
+ previous: Option.some(record.row),
176
+ };
177
+ })));
178
+ return { counts: state.counts, rowDigest: yield* stream.digest() };
179
+ });
180
+ /** Creates one complete content-addressed snapshot from its facts. */
181
+ export const makeAssessmentSnapshot = Effect.fn("AksaraContracts.makeAssessmentSnapshot")(function* (facts) {
182
+ const snapshotId = yield* hashText(`${SNAPSHOT_DOMAIN}\n${yield* canonicalJson(facts)}`);
183
+ return AssessmentSnapshotSchema.make({
184
+ ...facts,
185
+ format: ASSESSMENT_SNAPSHOT_FORMAT,
186
+ snapshotId,
187
+ });
188
+ });
189
+ /** Counts every row of a snapshot. */
190
+ export function assessmentRowCount(counts) {
191
+ return Arr.reduce(ASSESSMENT_ROW_KINDS, 0, (total, kind) => total + counts[kind]);
192
+ }
@@ -1,26 +1,26 @@
1
1
  import { Schema } from "effect";
2
2
  import { type Sha256Hash } from "#contracts/ids";
3
3
  /** Mutable publication dependencies owned by the signed source contracts. */
4
- export declare const ContentCacheScopeSchema: Schema.Literals<readonly ["article", "material", "page", "question", "program", "quran", "tryout"]>;
4
+ export declare const ContentCacheScopeSchema: Schema.Literals<readonly ["article", "material", "page", "assessment", "program", "quran"]>;
5
5
  export type ContentCacheScope = typeof ContentCacheScopeSchema.Type;
6
6
  /** One immutable published-artifact cache tag derived only from its hash. */
7
7
  export declare const ArtifactCacheTagSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraArtifactCacheTag">;
8
8
  export type ArtifactCacheTag = typeof ArtifactCacheTagSchema.Type;
9
9
  /** A changed item or snapshot invalidates its mutable selection dependency. */
10
10
  export declare const ContentCacheChangeSchema: Schema.Struct<{
11
- readonly scope: Schema.Literals<readonly ["article", "material", "page", "question", "program", "quran", "tryout"]>;
11
+ readonly scope: Schema.Literals<readonly ["article", "material", "page", "assessment", "program", "quran"]>;
12
12
  }>;
13
13
  export type ContentCacheChange = typeof ContentCacheChangeSchema.Type;
14
14
  /** One release-bound invalidation cannot name global or immutable cache tags. */
15
15
  export declare const ContentCacheRequestSchema: Schema.Struct<{
16
16
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
17
- readonly scope: Schema.Literals<readonly ["article", "material", "page", "question", "program", "quran", "tryout"]>;
17
+ readonly scope: Schema.Literals<readonly ["article", "material", "page", "assessment", "program", "quran"]>;
18
18
  }>;
19
19
  export type ContentCacheRequest = typeof ContentCacheRequestSchema.Type;
20
20
  /** Nakafa proof that one exact release-bound dependency was invalidated. */
21
21
  export declare const ContentCacheReceiptSchema: Schema.Struct<{
22
22
  readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
23
- readonly scope: Schema.Literals<readonly ["article", "material", "page", "question", "program", "quran", "tryout"]>;
23
+ readonly scope: Schema.Literals<readonly ["article", "material", "page", "assessment", "program", "quran"]>;
24
24
  readonly revalidated: Schema.Literal<true>;
25
25
  }>;
26
26
  export type ContentCacheReceipt = typeof ContentCacheReceiptSchema.Type;
@@ -1,3 +1,9 @@
1
+ import { Order } from "effect";
2
+ /**
3
+ * Orders values by their place in one canonical list. A value outside the list
4
+ * sorts after every member.
5
+ */
6
+ export declare function canonicalOrder<A extends string>(canonical: readonly A[]): Order.Order<A>;
1
7
  /**
2
8
  * Checks that a list names members of one canonical list, each at most once,
3
9
  * in the canonical order. A value outside the canonical list fails the check.
package/dist/canonical.js CHANGED
@@ -1,4 +1,11 @@
1
- import { Array as Arr } from "effect";
1
+ import { Array as Arr, Option, Order } from "effect";
2
+ /**
3
+ * Orders values by their place in one canonical list. A value outside the list
4
+ * sorts after every member.
5
+ */
6
+ export function canonicalOrder(canonical) {
7
+ return Order.mapInput(Order.Number, (value) => Option.getOrElse(Arr.findFirstIndex(canonical, (member) => member === value), () => canonical.length));
8
+ }
2
9
  /**
3
10
  * Checks that a list names members of one canonical list, each at most once,
4
11
  * in the canonical order. A value outside the canonical list fails the check.
package/dist/content.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
2
2
  import { type PublicPath, Sha256HashSchema } from "#contracts/ids";
3
3
  import { type AppLocale } from "#contracts/locale";
4
4
  /** Published content families backed by real Aksara source registries. */
5
- export declare const ContentFamilySchema: Schema.Literals<readonly ["article", "material", "page", "question"]>;
5
+ export declare const ContentFamilySchema: Schema.Literals<readonly ["article", "material", "page"]>;
6
6
  export type ContentFamily = typeof ContentFamilySchema.Type;
7
7
  /** Exact authored person identity exposed by Nakafa content metadata. */
8
8
  export declare const ContentAuthorSchema: Schema.Struct<{
package/dist/content.js CHANGED
@@ -13,7 +13,6 @@ export const ContentFamilySchema = Schema.Literals([
13
13
  "article",
14
14
  "material",
15
15
  "page",
16
- "question",
17
16
  ]);
18
17
  /** Exact authored person identity exposed by Nakafa content metadata. */
19
18
  export const ContentAuthorSchema = Schema.Struct({ name: Schema.String });
@@ -2,6 +2,3 @@ import { Schema } from "effect";
2
2
  /** Access boundary enforced before any published artifact body is returned. */
3
3
  export declare const ContentDeliveryClassSchema: Schema.Literals<readonly ["public", "authenticated", "entitled"]>;
4
4
  export type ContentDeliveryClass = typeof ContentDeliveryClassSchema.Type;
5
- /** Delivery classes whose artifact bodies need a product-authorized runtime read. */
6
- export declare const ProtectedContentDeliverySchema: Schema.Literals<readonly ["authenticated", "entitled"]>;
7
- export type ProtectedContentDelivery = typeof ProtectedContentDeliverySchema.Type;
package/dist/delivery.js CHANGED
@@ -5,8 +5,3 @@ export const ContentDeliveryClassSchema = Schema.Literals([
5
5
  "authenticated",
6
6
  "entitled",
7
7
  ]);
8
- /** Delivery classes whose artifact bodies need a product-authorized runtime read. */
9
- export const ProtectedContentDeliverySchema = ContentDeliveryClassSchema.pick([
10
- "authenticated",
11
- "entitled",
12
- ]);
@@ -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);
@@ -90,125 +90,6 @@ export declare const PreviewArtifactSchema: Schema.Struct<{
90
90
  }>;
91
91
  readonly sitemap: Schema.Literal<true>;
92
92
  readonly sourcePath: Schema.brand<Schema.String, "@NakafaAI/AksaraCorpusSourcePath">;
93
- }>, Schema.Union<readonly [Schema.Struct<{
94
- readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
95
- readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
96
- readonly peerContentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
97
- readonly questionKey: Schema.brand<Schema.String, "@NakafaAI/AksaraQuestionKey">;
98
- readonly questionNumber: Schema.Finite;
99
- readonly setKey: Schema.brand<Schema.String, "@NakafaAI/AksaraQuestionSetKey">;
100
- readonly bodyKind: Schema.Literal<"question">;
101
- readonly blueprint: Schema.optionalKey<Schema.Struct<{
102
- readonly cognitiveLevel: Schema.String;
103
- readonly contentDomain: Schema.String;
104
- readonly topic: Schema.String;
105
- }>>;
106
- readonly kind: Schema.Literal<"question-body">;
107
- readonly metadata: Schema.Struct<{
108
- readonly dateModified: Schema.optionalKey<Schema.String>;
109
- readonly datePublished: Schema.String;
110
- readonly authors: Schema.$Array<Schema.Struct<{
111
- readonly name: Schema.String;
112
- }>>;
113
- readonly title: Schema.String;
114
- }>;
115
- readonly stimulusKey: Schema.optionalKey<Schema.String>;
116
- readonly response: Schema.Union<readonly [Schema.Struct<{
117
- readonly categories: Schema.$Array<Schema.Struct<{
118
- readonly categoryKey: Schema.String;
119
- readonly label: Schema.String;
120
- readonly order: Schema.Int;
121
- }>>;
122
- readonly kind: Schema.Literal<"category">;
123
- readonly statements: Schema.$Array<Schema.Struct<{
124
- readonly correctCategoryKey: Schema.String;
125
- readonly label: Schema.String;
126
- readonly order: Schema.Int;
127
- readonly statementKey: Schema.String;
128
- }>>;
129
- }>, Schema.Struct<{
130
- readonly kind: Schema.Literal<"multiple-choice">;
131
- readonly options: Schema.$Array<Schema.Struct<{
132
- readonly isCorrect: Schema.Boolean;
133
- readonly label: Schema.String;
134
- readonly optionKey: Schema.String;
135
- readonly order: Schema.Int;
136
- }>>;
137
- }>, Schema.Struct<{
138
- readonly criteria: Schema.$Array<Schema.Struct<{
139
- readonly criterionKey: Schema.String;
140
- readonly finalAnswer: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
141
- readonly acceptsFractions: Schema.Boolean;
142
- readonly kind: Schema.Literal<"number">;
143
- readonly tolerance: Schema.optionalKey<Schema.Struct<{
144
- readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
145
- readonly value: Schema.String;
146
- }>>;
147
- readonly value: Schema.String;
148
- }>, Schema.Struct<{
149
- readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
150
- readonly collapseWhitespace: Schema.Boolean;
151
- readonly ignoreCase: Schema.Boolean;
152
- readonly kind: Schema.Literal<"text">;
153
- }>]>>;
154
- readonly order: Schema.Int;
155
- readonly label: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.String>;
156
- readonly levels: Schema.$Array<Schema.Struct<{
157
- readonly levelKey: Schema.String;
158
- readonly order: Schema.Int;
159
- readonly points: Schema.Int;
160
- readonly label: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.String>;
161
- }>>;
162
- }>>;
163
- readonly kind: Schema.Literal<"rubric">;
164
- }>, Schema.Struct<{
165
- readonly key: Schema.Union<readonly [Schema.Struct<{
166
- readonly acceptsFractions: Schema.Boolean;
167
- readonly kind: Schema.Literal<"number">;
168
- readonly tolerance: Schema.optionalKey<Schema.Struct<{
169
- readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
170
- readonly value: Schema.String;
171
- }>>;
172
- readonly value: Schema.String;
173
- }>, Schema.Struct<{
174
- readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
175
- readonly collapseWhitespace: Schema.Boolean;
176
- readonly ignoreCase: Schema.Boolean;
177
- readonly kind: Schema.Literal<"text">;
178
- }>]>;
179
- readonly kind: Schema.Literal<"short-answer">;
180
- }>, Schema.Struct<{
181
- readonly kind: Schema.Literal<"single-choice">;
182
- readonly options: Schema.$Array<Schema.Struct<{
183
- readonly isCorrect: Schema.Boolean;
184
- readonly label: Schema.String;
185
- readonly optionKey: Schema.String;
186
- readonly order: Schema.Int;
187
- }>>;
188
- }>]>;
189
- }>, Schema.Struct<{
190
- readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
191
- readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
192
- readonly peerContentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
193
- readonly questionKey: Schema.brand<Schema.String, "@NakafaAI/AksaraQuestionKey">;
194
- readonly questionNumber: Schema.Finite;
195
- readonly setKey: Schema.brand<Schema.String, "@NakafaAI/AksaraQuestionSetKey">;
196
- readonly bodyKind: Schema.Literal<"answer">;
197
- readonly blueprint: Schema.optionalKey<Schema.Struct<{
198
- readonly cognitiveLevel: Schema.String;
199
- readonly contentDomain: Schema.String;
200
- readonly topic: Schema.String;
201
- }>>;
202
- readonly kind: Schema.Literal<"question-body">;
203
- readonly metadata: Schema.Struct<{
204
- readonly dateModified: Schema.optionalKey<Schema.String>;
205
- readonly datePublished: Schema.String;
206
- readonly authors: Schema.$Array<Schema.Struct<{
207
- readonly name: Schema.String;
208
- }>>;
209
- readonly title: Schema.String;
210
- }>;
211
- readonly stimulusKey: Schema.optionalKey<Schema.String>;
212
- }>]>]>;
93
+ }>]>;
213
94
  }>;
214
95
  export type PreviewArtifact = typeof PreviewArtifactSchema.Type;
@@ -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));