@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
@@ -3,7 +3,7 @@ import { SignedContentArtifactSchema, } from "#contracts/content";
3
3
  import { decodeContract } from "#contracts/decode";
4
4
  import { CorpusSourcePathSchema, PublicPathSchema, ReleaseIdSchema, Sha256HashSchema, } from "#contracts/ids";
5
5
  import { AppLocaleSchema } from "#contracts/locale";
6
- import { RoutedContentProjectionSchema, } from "#contracts/projection/spec";
6
+ import { ContentProjectionSchema, } from "#contracts/projection/spec";
7
7
  import { SignedContentReleaseSchema } from "#contracts/release/spec";
8
8
  import { RendererManifestEnvelopeSchema } from "#contracts/renderer/contract";
9
9
  import { ContentRuntimeFailureSchema, ContentRuntimeMissingSchema, } from "#contracts/runtime/result";
@@ -27,9 +27,8 @@ function hasCoherentContent(input) {
27
27
  * Server-only content selected by trusted Convex publication state.
28
28
  *
29
29
  * The signed release, renderer, and artifact are authenticated independently.
30
- * Public route and head membership or protected snapshot membership remain
31
- * target authority. This envelope is deliberately not a cryptographic
32
- * inclusion proof.
30
+ * Public route and head membership remain target authority. This envelope
31
+ * is deliberately not a cryptographic inclusion proof.
33
32
  */
34
33
  const PublicContentRuntimeFoundFields = {
35
34
  artifact: SignedContentArtifactSchema,
@@ -44,7 +43,7 @@ export const PublicContentRuntimeFoundSchema = Schema.Struct({
44
43
  activeManifestHash: Sha256HashSchema,
45
44
  activeReleaseId: ReleaseIdSchema,
46
45
  delivery: Schema.Literal("public"),
47
- projection: RoutedContentProjectionSchema,
46
+ projection: ContentProjectionSchema,
48
47
  projectionHash: Sha256HashSchema,
49
48
  }).pipe(Schema.check(Schema.makeFilter(hasCoherentContent, {
50
49
  message: "Expected the runtime artifact and projection to share one identity.",
@@ -66,25 +66,25 @@ export declare const verifyContentRuntimeEvidenceExchange: (input: {
66
66
  readonly routeCount: number;
67
67
  readonly routeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
68
68
  readonly scope: {
69
- readonly families: readonly ("article" | "material" | "page" | "question")[];
70
- readonly snapshots: readonly ("program" | "quran" | "tryout")[];
69
+ readonly families: readonly ("article" | "material" | "page")[];
70
+ readonly snapshots: readonly ("assessment" | "program" | "quran")[];
71
71
  };
72
72
  readonly snapshots: {
73
- readonly program: {
73
+ readonly assessment: {
74
74
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
75
75
  readonly mode: "inherit" | "replace" | "restore";
76
76
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
77
77
  readonly rowCount: number;
78
78
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
79
79
  };
80
- readonly quran: {
80
+ readonly program: {
81
81
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
82
82
  readonly mode: "inherit" | "replace" | "restore";
83
83
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
84
84
  readonly rowCount: number;
85
85
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
86
86
  };
87
- readonly tryout: {
87
+ readonly quran: {
88
88
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
89
89
  readonly mode: "inherit" | "replace" | "restore";
90
90
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
@@ -114,6 +114,21 @@ export declare const verifyContentRuntimeEvidenceExchange: (input: {
114
114
  readonly activeReleaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">;
115
115
  readonly delivery: "public";
116
116
  readonly projection: {
117
+ readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
118
+ readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
119
+ readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
120
+ readonly pageKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPageKey">;
121
+ readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
122
+ readonly kind: "public-page";
123
+ readonly metadata: {
124
+ readonly dateModified?: string;
125
+ readonly datePublished: string;
126
+ readonly description: string;
127
+ readonly title: string;
128
+ };
129
+ readonly sitemap: true;
130
+ readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
131
+ } | {
117
132
  readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
118
133
  readonly articleRouteSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleRouteSlug">;
119
134
  readonly articleSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleSlug">;
@@ -182,21 +197,6 @@ export declare const verifyContentRuntimeEvidenceExchange: (input: {
182
197
  readonly parentPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
183
198
  readonly sitemap: true;
184
199
  readonly topicTitle: string;
185
- } | {
186
- readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
187
- readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
188
- readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
189
- readonly pageKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPageKey">;
190
- readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
191
- readonly kind: "public-page";
192
- readonly metadata: {
193
- readonly dateModified?: string;
194
- readonly datePublished: string;
195
- readonly description: string;
196
- readonly title: string;
197
- };
198
- readonly sitemap: true;
199
- readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
200
200
  };
201
201
  readonly projectionHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
202
202
  } | {
@@ -204,7 +204,7 @@ export declare const verifyContentRuntimeEvidenceExchange: (input: {
204
204
  } | {
205
205
  readonly code: "CONTENT_RUNTIME_INTERNAL" | "CONTENT_RUNTIME_INVALID" | "CONTENT_RUNTIME_RESPONSE_TOO_LARGE" | "CONTENT_RUNTIME_UNAUTHORIZED";
206
206
  readonly kind: "failure";
207
- }, import("../artifact/spec.js").ArtifactHashComputationError | import("../artifact/spec.js").ArtifactHashMismatchError | import("../artifact/spec.js").ArtifactPayloadFieldByteLimitError | import("../artifact/spec.js").ArtifactRendererComponentMissingError | import("../artifact/spec.js").ArtifactRendererDomainUnpublishedError | import("../artifact/spec.js").ArtifactSourceHashComputationError | import("../artifact/spec.js").ArtifactSourceHashMismatchError | import("../artifact/spec.js").ArtifactTreeComponentUnlistedError | import("../artifact/spec.js").ArtifactVerificationByteLimitError | import("../artifact/spec.js").ArtifactVerificationDecodeError | import("#contracts/projection/hash").ContentProjectionHashError | ContentRuntimeMismatchError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("#contracts/release/verify").ReleaseBundleVerificationDecodeError | import("../release/hash.js").ReleaseHashComputationError | import("#contracts/release/verify").ReleaseManifestHashMismatchError | import("#contracts/release/verify").ReleaseVerificationDecodeError | 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>;
207
+ }, import("../artifact/spec.js").ArtifactHashMismatchError | import("../artifact/spec.js").ArtifactPayloadFieldByteLimitError | import("../artifact/spec.js").ArtifactRendererComponentMissingError | import("../artifact/spec.js").ArtifactRendererDomainUnpublishedError | import("../artifact/spec.js").ArtifactSourceHashMismatchError | import("../artifact/spec.js").ArtifactTreeComponentUnlistedError | import("../artifact/spec.js").ArtifactVerificationByteLimitError | import("../artifact/spec.js").ArtifactVerificationDecodeError | ContentRuntimeMismatchError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("#contracts/release/verify").ReleaseBundleVerificationDecodeError | import("#contracts/release/verify").ReleaseManifestHashMismatchError | import("#contracts/release/verify").ReleaseVerificationDecodeError | 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>;
208
208
  /**
209
209
  * Verifies independently signed runtime values selected for one exact request.
210
210
  *
@@ -272,25 +272,25 @@ export declare const verifyContentRuntimeExchange: (input: {
272
272
  readonly routeCount: number;
273
273
  readonly routeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
274
274
  readonly scope: {
275
- readonly families: readonly ("article" | "material" | "page" | "question")[];
276
- readonly snapshots: readonly ("program" | "quran" | "tryout")[];
275
+ readonly families: readonly ("article" | "material" | "page")[];
276
+ readonly snapshots: readonly ("assessment" | "program" | "quran")[];
277
277
  };
278
278
  readonly snapshots: {
279
- readonly program: {
279
+ readonly assessment: {
280
280
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
281
281
  readonly mode: "inherit" | "replace" | "restore";
282
282
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
283
283
  readonly rowCount: number;
284
284
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
285
285
  };
286
- readonly quran: {
286
+ readonly program: {
287
287
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
288
288
  readonly mode: "inherit" | "replace" | "restore";
289
289
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
290
290
  readonly rowCount: number;
291
291
  readonly rowDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
292
292
  };
293
- readonly tryout: {
293
+ readonly quran: {
294
294
  readonly baseSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
295
295
  readonly mode: "inherit" | "replace" | "restore";
296
296
  readonly resultSnapshotId: (string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">) | null;
@@ -320,6 +320,21 @@ export declare const verifyContentRuntimeExchange: (input: {
320
320
  readonly activeReleaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">;
321
321
  readonly delivery: "public";
322
322
  readonly projection: {
323
+ readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
324
+ readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
325
+ readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
326
+ readonly pageKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPageKey">;
327
+ readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
328
+ readonly kind: "public-page";
329
+ readonly metadata: {
330
+ readonly dateModified?: string;
331
+ readonly datePublished: string;
332
+ readonly description: string;
333
+ readonly title: string;
334
+ };
335
+ readonly sitemap: true;
336
+ readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
337
+ } | {
323
338
  readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
324
339
  readonly articleRouteSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleRouteSlug">;
325
340
  readonly articleSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleSlug">;
@@ -388,21 +403,6 @@ export declare const verifyContentRuntimeExchange: (input: {
388
403
  readonly parentPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
389
404
  readonly sitemap: true;
390
405
  readonly topicTitle: string;
391
- } | {
392
- readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
393
- readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
394
- readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
395
- readonly pageKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPageKey">;
396
- readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
397
- readonly kind: "public-page";
398
- readonly metadata: {
399
- readonly dateModified?: string;
400
- readonly datePublished: string;
401
- readonly description: string;
402
- readonly title: string;
403
- };
404
- readonly sitemap: true;
405
- readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
406
406
  };
407
407
  readonly projectionHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
408
408
  } | {
@@ -410,4 +410,4 @@ export declare const verifyContentRuntimeExchange: (input: {
410
410
  } | {
411
411
  readonly code: "CONTENT_RUNTIME_INTERNAL" | "CONTENT_RUNTIME_INVALID" | "CONTENT_RUNTIME_RESPONSE_TOO_LARGE" | "CONTENT_RUNTIME_UNAUTHORIZED";
412
412
  readonly kind: "failure";
413
- }, import("../artifact/spec.js").ArtifactHashComputationError | import("../artifact/spec.js").ArtifactHashMismatchError | import("../artifact/spec.js").ArtifactPayloadFieldByteLimitError | import("../artifact/spec.js").ArtifactRendererComponentMissingError | import("../artifact/spec.js").ArtifactRendererDomainUnpublishedError | import("../artifact/spec.js").ArtifactSourceHashComputationError | import("../artifact/spec.js").ArtifactSourceHashMismatchError | import("../artifact/spec.js").ArtifactTreeComponentUnlistedError | import("../artifact/spec.js").ArtifactVerificationByteLimitError | import("../artifact/spec.js").ArtifactVerificationDecodeError | import("#contracts/projection/hash").ContentProjectionHashError | ContentRuntimeMismatchError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("#contracts/release/verify").ReleaseBundleVerificationDecodeError | import("../release/hash.js").ReleaseHashComputationError | import("#contracts/release/verify").ReleaseManifestHashMismatchError | import("#contracts/release/verify").ReleaseVerificationDecodeError | 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>;
413
+ }, import("../artifact/spec.js").ArtifactHashMismatchError | import("../artifact/spec.js").ArtifactPayloadFieldByteLimitError | import("../artifact/spec.js").ArtifactRendererComponentMissingError | import("../artifact/spec.js").ArtifactRendererDomainUnpublishedError | import("../artifact/spec.js").ArtifactSourceHashMismatchError | import("../artifact/spec.js").ArtifactTreeComponentUnlistedError | import("../artifact/spec.js").ArtifactVerificationByteLimitError | import("../artifact/spec.js").ArtifactVerificationDecodeError | ContentRuntimeMismatchError | import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | import("#contracts/release/verify").ReleaseBundleVerificationDecodeError | import("#contracts/release/verify").ReleaseManifestHashMismatchError | import("#contracts/release/verify").ReleaseVerificationDecodeError | 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>;
@@ -7,8 +7,6 @@ declare const Ed25519KeyError_base: Schema.Class<Ed25519KeyError, Schema.TaggedS
7
7
  /** An Ed25519 key could not be generated, imported from PEM, derived as a public key, or used to sign. */
8
8
  export declare class Ed25519KeyError extends Ed25519KeyError_base {
9
9
  }
10
- /** Reads the 32 raw public-key bytes from the `x` member of an exported Ed25519 JSON Web Key. */
11
- export declare const ed25519PublicKeyBytes: (x: string | undefined) => Effect.Effect<Uint8Array<ArrayBufferLike>, Ed25519KeyError, never>;
12
10
  /** Derives the SPKI PEM public key of one Ed25519 PKCS#8 private key PEM. */
13
11
  export declare const ed25519PublicKeyPem: (privateKeyPem: string) => Effect.Effect<string, Ed25519KeyError, never>;
14
12
  /** Generates one Ed25519 key pair as PKCS#8 and SPKI PEM text, from a random seed. */
@@ -1,104 +1,53 @@
1
- import { Effect, Schema } from "effect";
2
- import { Base64, Base64Url } from "effect/encoding";
3
- import { webCryptoService } from "#contracts/hash/digest";
1
+ import { Effect, Layer, Schema } from "effect";
2
+ import { KeyFormat, SecureRandom, Signature } from "effect/crypto";
3
+ import { Base64Url } from "effect/encoding";
4
4
  import { Ed25519SignatureSchema } from "#contracts/ids";
5
- /** The DER prefix of one PKCS#8 Ed25519 private key, before its 32-byte seed. */
6
- const ED25519_PKCS8_HEADER = Uint8Array.of(0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20);
7
- const ED25519_SEED_BYTES = 32;
8
5
  const PRIVATE_KEY_HEADER = "-----BEGIN PRIVATE KEY-----\n";
9
- const PRIVATE_KEY_FOOTER = "-----END PRIVATE KEY-----";
10
- const PUBLIC_KEY_HEADER = "-----BEGIN PUBLIC KEY-----\n";
11
- const PUBLIC_KEY_FOOTER = "-----END PUBLIC KEY-----";
12
- /** The DER header that wraps one 32-byte Ed25519 public key as SubjectPublicKeyInfo. */
13
- const ED25519_SPKI_HEADER = Uint8Array.of(0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00);
14
- const ED25519_PUBLIC_KEY_BYTES = 32;
15
- /** PEM bodies wrap base64 text at this many characters per line. */
16
- const PEM_LINE_LENGTH = 64;
6
+ /** PKCS#8 PEM, the form a private signing key is stored and read in. */
7
+ const PRIVATE_KEY_PEM = KeyFormat.pem(KeyFormat.pkcs8);
8
+ /** SubjectPublicKeyInfo PEM, the form a trusted public key is published in. */
9
+ const PUBLIC_KEY_PEM = KeyFormat.pem(KeyFormat.spki);
10
+ /**
11
+ * Ed25519 on Web Crypto, with Web Crypto's random source for new seeds. Every
12
+ * runtime that Aksara contracts run in has `crypto.subtle`, so the layer is
13
+ * provided here and callers need no runtime layer.
14
+ */
15
+ const SignatureLayer = Signature.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto));
17
16
  /** An Ed25519 key could not be generated, imported from PEM, derived as a public key, or used to sign. */
18
17
  export class Ed25519KeyError extends Schema.TaggedError()("Ed25519KeyError", {
19
18
  stage: Schema.Literals(["derive", "import", "sign"]),
20
19
  }) {
21
20
  }
22
- /** Decodes the DER bytes of one unencrypted PKCS#8 private key PEM. */
23
- function decodePrivateKeyPem(privateKeyPem) {
24
- const pem = privateKeyPem.replaceAll("\r\n", "\n");
25
- const end = pem.trimEnd();
26
- if (!(pem.startsWith(PRIVATE_KEY_HEADER) && end.endsWith(PRIVATE_KEY_FOOTER))) {
21
+ /**
22
+ * Decodes one unencrypted Ed25519 PKCS#8 PEM private key. The text must start
23
+ * at its BEGIN line, as the production key check requires.
24
+ */
25
+ function decodePrivateKey(privateKeyPem) {
26
+ if (!privateKeyPem.replaceAll("\r\n", "\n").startsWith(PRIVATE_KEY_HEADER)) {
27
27
  return Effect.fail(new Ed25519KeyError({ stage: "import" }));
28
28
  }
29
- const body = end
30
- .slice(PRIVATE_KEY_HEADER.length, end.length - PRIVATE_KEY_FOOTER.length)
31
- .replaceAll("\n", "");
32
- return Effect.fromResult(Base64.decode(body)).pipe(Effect.mapError(() => new Ed25519KeyError({ stage: "import" })));
29
+ return KeyFormat.decodePrivate(PRIVATE_KEY_PEM, Signature.ed25519, privateKeyPem).pipe(Effect.mapError(() => new Ed25519KeyError({ stage: "import" })));
33
30
  }
34
- /** Imports one Ed25519 PKCS#8 key through Web Crypto, extractable only when asked. */
35
- function importPkcs8(der, extractable) {
36
- return Effect.tryPromise({
37
- catch: () => new Ed25519KeyError({ stage: "import" }),
38
- try: () => globalThis.crypto.subtle.importKey("pkcs8", new Uint8Array(der), { name: "Ed25519" }, extractable, ["sign"]),
39
- });
40
- }
41
- /** Encodes DER bytes as PEM text with 64-character lines, the layout that Node writes. */
42
- function encodePem(der, header, footer) {
43
- const base64 = Base64.encode(der);
44
- let body = "";
45
- for (let offset = 0; offset < base64.length; offset += PEM_LINE_LENGTH) {
46
- body += `${base64.slice(offset, offset + PEM_LINE_LENGTH)}\n`;
47
- }
48
- return `${header}${body}${footer}\n`;
49
- }
50
- /** Imports one unencrypted Ed25519 PKCS#8 PEM private key as a non-extractable signing key. */
51
- const importPrivateKey = Effect.fn("AksaraContracts.importEd25519PrivateKey")(function* (privateKeyPem) {
52
- const der = yield* decodePrivateKeyPem(privateKeyPem);
53
- return yield* importPkcs8(der, false);
54
- });
55
- /** Reads the 32 raw public-key bytes from the `x` member of an exported Ed25519 JSON Web Key. */
56
- export const ed25519PublicKeyBytes = Effect.fn("AksaraContracts.ed25519PublicKeyBytes")(function* (x) {
57
- const bytes = yield* Effect.fromResult(Base64Url.decode(x ?? "")).pipe(Effect.mapError(() => new Ed25519KeyError({ stage: "derive" })));
58
- if (bytes.byteLength !== ED25519_PUBLIC_KEY_BYTES) {
59
- return yield* new Ed25519KeyError({ stage: "derive" });
60
- }
61
- return bytes;
62
- });
63
31
  /** Derives the SPKI PEM public key of one Ed25519 PKCS#8 private key PEM. */
64
32
  export const ed25519PublicKeyPem = Effect.fn("AksaraContracts.ed25519PublicKeyPem")(function* (privateKeyPem) {
65
- const der = yield* decodePrivateKeyPem(privateKeyPem);
66
- const key = yield* importPkcs8(der, true);
67
- const jwk = yield* Effect.tryPromise({
68
- catch: () => new Ed25519KeyError({ stage: "derive" }),
69
- try: () => globalThis.crypto.subtle.exportKey("jwk", key),
70
- });
71
- const publicKey = yield* ed25519PublicKeyBytes(jwk.x);
72
- const spki = new Uint8Array(ED25519_SPKI_HEADER.byteLength + ED25519_PUBLIC_KEY_BYTES);
73
- spki.set(ED25519_SPKI_HEADER);
74
- spki.set(publicKey, ED25519_SPKI_HEADER.byteLength);
75
- return encodePem(spki, PUBLIC_KEY_HEADER, PUBLIC_KEY_FOOTER);
76
- });
33
+ const privateKey = yield* decodePrivateKey(privateKeyPem);
34
+ const signature = yield* Signature.Signature;
35
+ return yield* signature.publicKeyOf(privateKey).pipe(Effect.flatMap((publicKey) => KeyFormat.encode(PUBLIC_KEY_PEM, publicKey)), Effect.mapError(() => new Ed25519KeyError({ stage: "derive" })));
36
+ }, Effect.provide(SignatureLayer));
77
37
  /** Generates one Ed25519 key pair as PKCS#8 and SPKI PEM text, from a random seed. */
78
38
  export const generateEd25519KeyPem = Effect.fn("AksaraContracts.generateEd25519KeyPem")(function* () {
79
- const seed = yield* webCryptoService
80
- .randomBytes(ED25519_SEED_BYTES)
81
- .pipe(Effect.orDie);
82
- const der = new Uint8Array(ED25519_PKCS8_HEADER.byteLength + seed.byteLength);
83
- der.set(ED25519_PKCS8_HEADER);
84
- der.set(seed, ED25519_PKCS8_HEADER.byteLength);
85
- const privateKeyPem = encodePem(der, PRIVATE_KEY_HEADER, PRIVATE_KEY_FOOTER);
86
- return {
87
- privateKeyPem,
88
- publicKeyPem: yield* ed25519PublicKeyPem(privateKeyPem),
89
- };
90
- });
91
- /** Signs one exact message with an imported Ed25519 key, returning the raw 64-byte signature. */
92
- const signBytes = Effect.fn("AksaraContracts.signEd25519")(function* (privateKey, message) {
93
- const signature = yield* Effect.tryPromise({
94
- catch: () => new Ed25519KeyError({ stage: "sign" }),
95
- try: () => globalThis.crypto.subtle.sign("Ed25519", privateKey, new Uint8Array(message)),
96
- });
97
- return new Uint8Array(signature);
98
- });
39
+ const signature = yield* Signature.Signature;
40
+ return yield* signature.generateKeyPair(Signature.ed25519).pipe(Effect.flatMap(({ privateKey, publicKey }) => Effect.all({
41
+ privateKeyPem: KeyFormat.encode(PRIVATE_KEY_PEM, privateKey),
42
+ publicKeyPem: KeyFormat.encode(PUBLIC_KEY_PEM, publicKey),
43
+ })), Effect.mapError(() => new Ed25519KeyError({ stage: "derive" })));
44
+ }, Effect.provide(SignatureLayer));
99
45
  /** Signs the UTF-8 bytes of one canonical message with an unencrypted Ed25519 PKCS#8 PEM private key, returning the unpadded base64url signature. */
100
46
  export const signEd25519Message = Effect.fn("AksaraContracts.signEd25519Message")(function* (privateKeyPem, message) {
101
- const privateKey = yield* importPrivateKey(privateKeyPem);
102
- const signature = yield* signBytes(privateKey, new TextEncoder().encode(message));
103
- return Ed25519SignatureSchema.make(Base64Url.encode(signature));
104
- });
47
+ const privateKey = yield* decodePrivateKey(privateKeyPem);
48
+ const signature = yield* Signature.Signature;
49
+ const bytes = yield* signature
50
+ .sign(privateKey, new TextEncoder().encode(message))
51
+ .pipe(Effect.mapError(() => new Ed25519KeyError({ stage: "sign" })));
52
+ return Ed25519SignatureSchema.make(Base64Url.encode(bytes));
53
+ }, Effect.provide(SignatureLayer));
@@ -1,7 +1,7 @@
1
1
  import { Context, type Effect, Schema } from "effect";
2
2
  import { type SigningKeyId } from "#contracts/ids";
3
3
  /** Authenticated object whose Ed25519 signature is being checked. */
4
- export declare const ContentSignatureSubjectSchema: Schema.Literals<readonly ["artifact", "release", "tryout-runtime-bundle"]>;
4
+ export declare const ContentSignatureSubjectSchema: Schema.Literals<readonly ["artifact", "release"]>;
5
5
  export type ContentSignatureSubject = typeof ContentSignatureSubjectSchema.Type;
6
6
  declare const SigningKeyNotFoundError_base: Schema.Class<SigningKeyNotFoundError, Schema.TaggedStruct<"SigningKeyNotFoundError", {
7
7
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
@@ -21,7 +21,7 @@ export declare class SigningKeyResolutionError extends SigningKeyResolutionError
21
21
  }
22
22
  declare const PublicKeyParseError_base: Schema.Class<PublicKeyParseError, Schema.TaggedStruct<"PublicKeyParseError", {
23
23
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
24
- readonly subject: Schema.Literals<readonly ["artifact", "release", "tryout-runtime-bundle"]>;
24
+ readonly subject: Schema.Literals<readonly ["artifact", "release"]>;
25
25
  }>, import("effect/Cause").YieldableError & {
26
26
  readonly brand: unique symbol;
27
27
  }>;
@@ -30,7 +30,7 @@ export declare class PublicKeyParseError extends PublicKeyParseError_base {
30
30
  }
31
31
  declare const PublicKeyTypeError_base: Schema.Class<PublicKeyTypeError, Schema.TaggedStruct<"PublicKeyTypeError", {
32
32
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
33
- readonly subject: Schema.Literals<readonly ["artifact", "release", "tryout-runtime-bundle"]>;
33
+ readonly subject: Schema.Literals<readonly ["artifact", "release"]>;
34
34
  }>, import("effect/Cause").YieldableError & {
35
35
  readonly brand: unique symbol;
36
36
  }>;
@@ -39,7 +39,7 @@ export declare class PublicKeyTypeError extends PublicKeyTypeError_base {
39
39
  }
40
40
  declare const SignatureCheckError_base: Schema.Class<SignatureCheckError, Schema.TaggedStruct<"SignatureCheckError", {
41
41
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
42
- readonly subject: Schema.Literals<readonly ["artifact", "release", "tryout-runtime-bundle"]>;
42
+ readonly subject: Schema.Literals<readonly ["artifact", "release"]>;
43
43
  }>, import("effect/Cause").YieldableError & {
44
44
  readonly brand: unique symbol;
45
45
  }>;
@@ -48,7 +48,7 @@ export declare class SignatureCheckError extends SignatureCheckError_base {
48
48
  }
49
49
  declare const SignatureInvalidError_base: Schema.Class<SignatureInvalidError, Schema.TaggedStruct<"SignatureInvalidError", {
50
50
  readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
51
- readonly subject: Schema.Literals<readonly ["artifact", "release", "tryout-runtime-bundle"]>;
51
+ readonly subject: Schema.Literals<readonly ["artifact", "release"]>;
52
52
  }>, import("effect/Cause").YieldableError & {
53
53
  readonly brand: unique symbol;
54
54
  }>;
@@ -4,7 +4,6 @@ import { SigningKeyIdSchema } from "#contracts/ids";
4
4
  export const ContentSignatureSubjectSchema = Schema.Literals([
5
5
  "artifact",
6
6
  "release",
7
- "tryout-runtime-bundle",
8
7
  ]);
9
8
  /** No trusted public key exists for the requested key identifier. */
10
9
  export class SigningKeyNotFoundError extends Schema.TaggedError()("SigningKeyNotFoundError", { keyId: SigningKeyIdSchema }) {
@@ -1,22 +1,18 @@
1
- import { Effect } from "effect";
1
+ import { Effect, Layer } from "effect";
2
+ import { KeyFormat, SecureRandom, Signature } from "effect/crypto";
3
+ import { Base64, Base64Url, Hex } from "effect/encoding";
2
4
  import { ContentVerificationKeyResolver, PublicKeyParseError, PublicKeyTypeError, SignatureCheckError, SignatureInvalidError, } from "#contracts/signature/spec";
3
5
  const PUBLIC_KEY_HEADER = "-----BEGIN PUBLIC KEY-----\n";
4
6
  const PUBLIC_KEY_FOOTER = "-----END PUBLIC KEY-----";
7
+ /** The DER header of one Ed25519 SubjectPublicKeyInfo, before its 32-byte key. */
5
8
  const ED25519_SPKI_PREFIX = "302a300506032b6570032100";
6
- const PUBLIC_KEY_BASE64_PATTERN = /^[A-Za-z0-9+/]+={0,2}$/u;
7
- /** Decodes canonical base64 text without a Node Buffer dependency. */
8
- function decodeBase64(value) {
9
- const decoded = atob(value);
10
- return Uint8Array.from(decoded, (character) => character.charCodeAt(0));
11
- }
12
- /** Encodes bytes as lowercase hexadecimal for one exact key-type check. */
13
- function encodeHex(value) {
14
- let hex = "";
15
- for (const byte of value) {
16
- hex += byte.toString(16).padStart(2, "0");
17
- }
18
- return hex;
19
- }
9
+ const ED25519_SPKI_BYTES = 44;
10
+ /**
11
+ * Ed25519 verification on Web Crypto. Every runtime that Aksara contracts run
12
+ * in has `crypto.subtle`, so the layer is provided here and callers need no
13
+ * runtime layer.
14
+ */
15
+ const SignatureLayer = Signature.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto));
20
16
  /** Reads the reviewed SPKI bytes from one exact public-key PEM. */
21
17
  function decodePublicKeyPem(keyId, publicKeyPem, subject) {
22
18
  const normalizedPublicKeyPem = publicKeyPem.replaceAll("\r\n", "\n");
@@ -29,44 +25,33 @@ function decodePublicKeyPem(keyId, publicKeyPem, subject) {
29
25
  .replace(PUBLIC_KEY_FOOTER, "")
30
26
  .replaceAll("\n", "")
31
27
  .trim();
32
- if (!PUBLIC_KEY_BASE64_PATTERN.test(body) || body.length % 4 !== 0) {
33
- return Effect.fail(new PublicKeyParseError({ keyId, subject }));
34
- }
35
- return Effect.succeed(decodeBase64(body));
36
- }
37
- /** Imports one exact Ed25519 SPKI key through Web Crypto. */
38
- function importEd25519PublicKey(keyId, publicKeyPem, subject) {
39
- return Effect.gen(function* () {
40
- const bytes = yield* decodePublicKeyPem(keyId, publicKeyPem, subject);
41
- if (bytes.byteLength !== 44 ||
42
- !encodeHex(bytes.slice(0, 12)).startsWith(ED25519_SPKI_PREFIX)) {
43
- return yield* new PublicKeyTypeError({ keyId, subject });
44
- }
45
- return yield* Effect.tryPromise({
46
- catch: () => new PublicKeyParseError({ keyId, subject }),
47
- try: () => crypto.subtle.importKey("spki", bytes, { name: "Ed25519" }, false, [
48
- "verify",
49
- ]),
50
- });
51
- });
28
+ return Effect.fromResult(Base64.decode(body)).pipe(Effect.mapError(() => new PublicKeyParseError({ keyId, subject })));
52
29
  }
53
- /** Decodes one unpadded base64url Ed25519 signature. */
30
+ /** Imports one exact Ed25519 SPKI key, refusing a key of any other type before it reaches Web Crypto. */
31
+ const importEd25519PublicKey = Effect.fn("AksaraContracts.importEd25519PublicKey")(function* (keyId, publicKeyPem, subject) {
32
+ const der = yield* decodePublicKeyPem(keyId, publicKeyPem, subject);
33
+ if (der.byteLength !== ED25519_SPKI_BYTES ||
34
+ !Hex.encode(der).startsWith(ED25519_SPKI_PREFIX)) {
35
+ return yield* new PublicKeyTypeError({ keyId, subject });
36
+ }
37
+ return yield* KeyFormat.decodePublic(KeyFormat.spki, Signature.ed25519, der).pipe(Effect.mapError(() => new PublicKeyParseError({ keyId, subject })));
38
+ });
39
+ /** Decodes one unpadded base64url Ed25519 signature, which its schema has already checked. */
54
40
  function decodeSignature(signature) {
55
- const base64 = signature.replaceAll("-", "+").replaceAll("_", "/");
56
- return decodeBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
41
+ return Effect.fromResult(Base64Url.decode(signature)).pipe(Effect.orDie);
57
42
  }
58
43
  /** Resolves trust and verifies domain-separated canonical bytes with Ed25519. */
59
44
  export const verifyEd25519Signature = Effect.fn("AksaraContracts.verifyEd25519Signature")(function* (input) {
60
45
  const resolver = yield* ContentVerificationKeyResolver;
61
46
  const publicKeyPem = yield* resolver.resolve(input.keyId);
62
47
  const publicKey = yield* importEd25519PublicKey(input.keyId, publicKeyPem, input.subject);
63
- const valid = yield* Effect.tryPromise({
64
- catch: () => new SignatureCheckError({
65
- keyId: input.keyId,
66
- subject: input.subject,
67
- }),
68
- try: () => crypto.subtle.verify("Ed25519", publicKey, decodeSignature(input.signature), new TextEncoder().encode(input.message)),
69
- });
48
+ const signature = yield* Signature.Signature;
49
+ const valid = yield* signature
50
+ .verify(publicKey, yield* decodeSignature(input.signature), new TextEncoder().encode(input.message))
51
+ .pipe(Effect.mapError(() => new SignatureCheckError({
52
+ keyId: input.keyId,
53
+ subject: input.subject,
54
+ })));
70
55
  if (valid) {
71
56
  return;
72
57
  }
@@ -74,4 +59,4 @@ export const verifyEd25519Signature = Effect.fn("AksaraContracts.verifyEd25519Si
74
59
  keyId: input.keyId,
75
60
  subject: input.subject,
76
61
  });
77
- });
62
+ }, Effect.provide(SignatureLayer));