@nakafa/aksara-contracts 0.50.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +207 -152
- package/README.md +3 -0
- package/dist/artifact/integrity.d.ts +33 -8
- package/dist/artifact/integrity.js +19 -17
- package/dist/artifact/limits.d.ts +13 -7
- package/dist/artifact/limits.js +7 -15
- package/dist/artifact/source.d.ts +10 -4
- package/dist/artifact/source.js +4 -8
- package/dist/artifact/spec.d.ts +54 -22
- package/dist/artifact/spec.js +7 -8
- package/dist/artifact/verify.d.ts +11 -5
- package/dist/assessment/hash.d.ts +3 -1
- package/dist/assessment/paper.d.ts +3 -1
- package/dist/content.d.ts +37 -11
- package/dist/content.js +7 -21
- package/dist/errors.d.ts +3 -1
- package/dist/graph/family.d.ts +6 -2
- package/dist/graph/identity.d.ts +3 -1
- package/dist/hash/digest.d.ts +10 -0
- package/dist/hash/digest.js +40 -0
- package/dist/hash/stream.d.ts +12 -0
- package/dist/hash/stream.js +27 -0
- package/dist/hash/text.d.ts +3 -1
- package/dist/hash/text.js +2 -15
- package/dist/limits.d.ts +2 -2
- package/dist/limits.js +2 -2
- package/dist/preview/auth.d.ts +4 -2
- package/dist/preview/auth.js +26 -12
- package/dist/program/snapshot/digest.d.ts +3 -1
- package/dist/program/snapshot/digest.js +14 -22
- package/dist/program/snapshot/hash.d.ts +6 -2
- package/dist/program/snapshot/hash.js +10 -21
- package/dist/projection/digest.d.ts +11 -9
- package/dist/projection/digest.js +23 -32
- package/dist/projection/hash.d.ts +222 -2
- package/dist/projection/hash.js +6 -8
- package/dist/projection/verify.d.ts +16 -6
- package/dist/question/item.d.ts +3 -1
- package/dist/question/item.js +3 -1
- package/dist/quran/notes.d.ts +3 -1
- package/dist/quran/provenance.d.ts +6 -2
- package/dist/quran/provenance.js +8 -15
- package/dist/quran/snapshot/digest.d.ts +9 -5
- package/dist/quran/snapshot/digest.js +33 -41
- package/dist/quran/snapshot/hash.d.ts +3 -1
- package/dist/quran/snapshot/hash.js +9 -15
- package/dist/quran/snapshot/row/hash.d.ts +3 -1
- package/dist/quran/snapshot/row/hash.js +2 -8
- package/dist/release/digest.d.ts +10 -8
- package/dist/release/digest.js +22 -31
- package/dist/release/hash.d.ts +3 -1
- package/dist/release/hash.js +3 -8
- package/dist/release/items.d.ts +25 -9
- package/dist/release/items.js +12 -3
- package/dist/release/policy.d.ts +3 -1
- package/dist/release/result/digest.d.ts +23 -13
- package/dist/release/result/digest.js +20 -29
- package/dist/release/rollback/digest.d.ts +16 -10
- package/dist/release/rollback/digest.js +25 -32
- package/dist/release/rollback/spec.d.ts +102 -24
- package/dist/release/route/digest.d.ts +10 -8
- package/dist/release/route/digest.js +22 -31
- package/dist/release/route/verify.d.ts +16 -6
- package/dist/release/route/verify.js +8 -2
- package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
- package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
- package/dist/release/snapshot/evidence/tryout.js +1 -1
- package/dist/release/snapshot/evidence.d.ts +1 -1
- package/dist/release/snapshot/verify.d.ts +19 -7
- package/dist/release/snapshot/verify.js +20 -18
- package/dist/release/verify.d.ts +9 -3
- package/dist/renderer/compatibility.d.ts +6 -2
- package/dist/renderer/compatibility.js +3 -1
- package/dist/renderer/contract.d.ts +9 -3
- package/dist/renderer/contract.js +3 -1
- package/dist/runtime/error.d.ts +3 -1
- package/dist/runtime/protected/spec.d.ts +61 -16
- package/dist/runtime/protected/verify.d.ts +11 -5
- package/dist/runtime/spec.d.ts +44 -12
- package/dist/runtime/verify.d.ts +22 -10
- package/dist/runtime/verify.js +2 -1
- package/dist/signature/key.d.ts +21 -0
- package/dist/signature/key.js +104 -0
- package/dist/signature/spec.d.ts +18 -6
- package/dist/signature/spec.js +16 -4
- package/dist/transport/batch.d.ts +34 -8
- package/dist/transport/group.d.ts +51 -12
- package/dist/transport/request.d.ts +826 -764
- package/dist/transport/response.d.ts +148 -58
- package/dist/tree.d.ts +52 -0
- package/dist/tree.js +162 -0
- package/dist/tryout/canonical.d.ts +11 -1
- package/dist/tryout/canonical.js +6 -10
- package/dist/tryout/closure/accounting.d.ts +3 -1
- package/dist/tryout/digest.d.ts +12 -6
- package/dist/tryout/digest.js +21 -14
- package/dist/tryout/hash/catalog.d.ts +228 -3
- package/dist/tryout/hash/catalog.js +5 -7
- package/dist/tryout/hash/content.d.ts +113 -2
- package/dist/tryout/hash/content.js +10 -8
- package/dist/tryout/hash/placement.d.ts +236 -5
- package/dist/tryout/hash/placement.js +7 -8
- package/dist/tryout/runtime/hash.d.ts +3 -1
- package/dist/tryout/runtime/hash.js +3 -1
- package/dist/tryout/runtime/source.d.ts +3 -1
- package/dist/tryout/runtime/verify.d.ts +13 -5
- package/dist/tryout/runtime/verify.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -1
- package/dist/tryout/snapshot/hash.d.ts +45 -4
- package/dist/tryout/snapshot/hash.js +9 -7
- package/package.json +22 -2
|
@@ -3,12 +3,18 @@ import { ArtifactSourceHashComputationError, ArtifactSourceHashMismatchError } f
|
|
|
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">;
|
|
6
|
-
readonly byteLength: number;
|
|
7
|
-
readonly compiledCode: string;
|
|
8
6
|
readonly compilerConfigHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
9
|
-
readonly compilerVersion: "0.
|
|
7
|
+
readonly compilerVersion: "0.2.0";
|
|
10
8
|
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
11
|
-
readonly
|
|
9
|
+
readonly contentTree: {
|
|
10
|
+
readonly $node: "element";
|
|
11
|
+
readonly children: readonly import("../tree.js").ContentTreeChild[];
|
|
12
|
+
readonly name: import("../tree.js").ContentTreeElementName;
|
|
13
|
+
readonly props: {
|
|
14
|
+
readonly [key: string]: import("../tree.js").ContentTreeValue;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
readonly format: "content-tree";
|
|
12
18
|
readonly mdxCompilerVersion: "3.1.1";
|
|
13
19
|
readonly plainText: string;
|
|
14
20
|
readonly rawMdx: string;
|
package/dist/artifact/source.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Effect } from "effect";
|
|
3
2
|
import { ArtifactSourceHashComputationError, ArtifactSourceHashMismatchError, } from "#contracts/artifact/spec";
|
|
4
|
-
import {
|
|
3
|
+
import { hashText } from "#contracts/hash/text";
|
|
5
4
|
/** Computes the authenticated hash of the complete authored MDX source. */
|
|
6
5
|
function hashAuthoredSource(payload) {
|
|
7
|
-
return Effect.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}),
|
|
11
|
-
try: () => Sha256HashSchema.make(`sha256:${createHash("sha256").update(payload.rawMdx).digest("hex")}`),
|
|
12
|
-
});
|
|
6
|
+
return hashText(payload.rawMdx).pipe(Effect.mapError(() => new ArtifactSourceHashComputationError({
|
|
7
|
+
contentKey: payload.contentKey,
|
|
8
|
+
})));
|
|
13
9
|
}
|
|
14
10
|
/** Verifies that sourceHash identifies the complete authenticated raw MDX. */
|
|
15
11
|
export const verifyCompiledContentSourceHash = Effect.fn("AksaraContracts.verifyCompiledContentSourceHash")((payload) => hashAuthoredSource(payload).pipe(Effect.flatMap((actualHash) => {
|
package/dist/artifact/spec.d.ts
CHANGED
|
@@ -6,12 +6,25 @@ export declare const ArtifactVerificationRequestSchema: Schema.Struct<{
|
|
|
6
6
|
readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
|
|
7
7
|
readonly payload: Schema.Struct<{
|
|
8
8
|
readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
|
|
9
|
-
readonly byteLength: Schema.Finite;
|
|
10
|
-
readonly compiledCode: Schema.String;
|
|
11
9
|
readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
12
|
-
readonly compilerVersion: Schema.Literal<"0.
|
|
10
|
+
readonly compilerVersion: Schema.Literal<"0.2.0">;
|
|
13
11
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
14
|
-
readonly
|
|
12
|
+
readonly contentTree: Schema.Codec<{
|
|
13
|
+
readonly $node: "element";
|
|
14
|
+
readonly children: readonly import("../tree.js").ContentTreeChild[];
|
|
15
|
+
readonly name: import("../tree.js").ContentTreeElementName;
|
|
16
|
+
readonly props: {
|
|
17
|
+
readonly [key: string]: import("../tree.js").ContentTreeValue;
|
|
18
|
+
};
|
|
19
|
+
}, {
|
|
20
|
+
readonly $node: "element";
|
|
21
|
+
readonly children: readonly import("../tree.js").ContentTreeChild[];
|
|
22
|
+
readonly name: import("../tree.js").ContentTreeElementName;
|
|
23
|
+
readonly props: {
|
|
24
|
+
readonly [key: string]: import("../tree.js").ContentTreeValue;
|
|
25
|
+
};
|
|
26
|
+
}, never, never>;
|
|
27
|
+
readonly format: Schema.Literal<"content-tree">;
|
|
15
28
|
readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
|
|
16
29
|
readonly plainText: Schema.String;
|
|
17
30
|
readonly rawMdx: Schema.String;
|
|
@@ -35,37 +48,37 @@ export declare const ArtifactVerificationRequestSchema: Schema.Struct<{
|
|
|
35
48
|
export type ArtifactVerificationRequest = typeof ArtifactVerificationRequestSchema.Type;
|
|
36
49
|
declare const ArtifactVerificationDecodeError_base: Schema.Class<ArtifactVerificationDecodeError, Schema.TaggedStruct<"ArtifactVerificationDecodeError", {
|
|
37
50
|
readonly message: Schema.Literal<"Artifact verification input does not satisfy its exact wire contract.">;
|
|
38
|
-
}>, import("effect/Cause").YieldableError
|
|
51
|
+
}>, import("effect/Cause").YieldableError & {
|
|
52
|
+
readonly brand: unique symbol;
|
|
53
|
+
}>;
|
|
39
54
|
/** Unknown artifact input did not exactly satisfy the verification contract. */
|
|
40
55
|
export declare class ArtifactVerificationDecodeError extends ArtifactVerificationDecodeError_base {
|
|
41
56
|
}
|
|
42
57
|
declare const ArtifactVerificationByteLimitError_base: Schema.Class<ArtifactVerificationByteLimitError, Schema.TaggedStruct<"ArtifactVerificationByteLimitError", {
|
|
43
58
|
readonly actualBytes: Schema.Finite;
|
|
44
59
|
readonly maxBytes: Schema.Finite;
|
|
45
|
-
}>, import("effect/Cause").YieldableError
|
|
60
|
+
}>, import("effect/Cause").YieldableError & {
|
|
61
|
+
readonly brand: unique symbol;
|
|
62
|
+
}>;
|
|
46
63
|
/** A signed artifact exceeded the canonical UTF-8 wire ceiling. */
|
|
47
64
|
export declare class ArtifactVerificationByteLimitError extends ArtifactVerificationByteLimitError_base {
|
|
48
65
|
}
|
|
49
|
-
declare const ArtifactCompiledByteLengthMismatchError_base: Schema.Class<ArtifactCompiledByteLengthMismatchError, Schema.TaggedStruct<"ArtifactCompiledByteLengthMismatchError", {
|
|
50
|
-
readonly actualBytes: Schema.Finite;
|
|
51
|
-
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
52
|
-
readonly declaredBytes: Schema.Finite;
|
|
53
|
-
}>, import("effect/Cause").YieldableError>;
|
|
54
|
-
/** Declared compiled bytes differ from the authenticated function body. */
|
|
55
|
-
export declare class ArtifactCompiledByteLengthMismatchError extends ArtifactCompiledByteLengthMismatchError_base {
|
|
56
|
-
}
|
|
57
66
|
declare const ArtifactPayloadFieldByteLimitError_base: Schema.Class<ArtifactPayloadFieldByteLimitError, Schema.TaggedStruct<"ArtifactPayloadFieldByteLimitError", {
|
|
58
67
|
readonly actualBytes: Schema.Finite;
|
|
59
68
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
60
|
-
readonly field: Schema.Literals<readonly ["rawMdx", "
|
|
69
|
+
readonly field: Schema.Literals<readonly ["rawMdx", "contentTree", "plainText", "canonicalPayload"]>;
|
|
61
70
|
readonly maxBytes: Schema.Finite;
|
|
62
|
-
}>, import("effect/Cause").YieldableError
|
|
71
|
+
}>, import("effect/Cause").YieldableError & {
|
|
72
|
+
readonly brand: unique symbol;
|
|
73
|
+
}>;
|
|
63
74
|
/** One authenticated payload field exceeded its shared runtime ceiling. */
|
|
64
75
|
export declare class ArtifactPayloadFieldByteLimitError extends ArtifactPayloadFieldByteLimitError_base {
|
|
65
76
|
}
|
|
66
77
|
declare const ArtifactHashComputationError_base: Schema.Class<ArtifactHashComputationError, Schema.TaggedStruct<"ArtifactHashComputationError", {
|
|
67
78
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
68
|
-
}>, import("effect/Cause").YieldableError
|
|
79
|
+
}>, import("effect/Cause").YieldableError & {
|
|
80
|
+
readonly brand: unique symbol;
|
|
81
|
+
}>;
|
|
69
82
|
/** SHA-256 computation failed before authenticity could be established. */
|
|
70
83
|
export declare class ArtifactHashComputationError extends ArtifactHashComputationError_base {
|
|
71
84
|
}
|
|
@@ -73,13 +86,17 @@ declare const ArtifactHashMismatchError_base: Schema.Class<ArtifactHashMismatchE
|
|
|
73
86
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
74
87
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
75
88
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
76
|
-
}>, import("effect/Cause").YieldableError
|
|
89
|
+
}>, import("effect/Cause").YieldableError & {
|
|
90
|
+
readonly brand: unique symbol;
|
|
91
|
+
}>;
|
|
77
92
|
/** The signed artifact hash does not identify its canonical payload. */
|
|
78
93
|
export declare class ArtifactHashMismatchError extends ArtifactHashMismatchError_base {
|
|
79
94
|
}
|
|
80
95
|
declare const ArtifactSourceHashComputationError_base: Schema.Class<ArtifactSourceHashComputationError, Schema.TaggedStruct<"ArtifactSourceHashComputationError", {
|
|
81
96
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
82
|
-
}>, import("effect/Cause").YieldableError
|
|
97
|
+
}>, import("effect/Cause").YieldableError & {
|
|
98
|
+
readonly brand: unique symbol;
|
|
99
|
+
}>;
|
|
83
100
|
/** SHA-256 could not be calculated for the authenticated authored source. */
|
|
84
101
|
export declare class ArtifactSourceHashComputationError extends ArtifactSourceHashComputationError_base {
|
|
85
102
|
}
|
|
@@ -87,21 +104,36 @@ declare const ArtifactSourceHashMismatchError_base: Schema.Class<ArtifactSourceH
|
|
|
87
104
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
88
105
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
89
106
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
90
|
-
}>, import("effect/Cause").YieldableError
|
|
107
|
+
}>, import("effect/Cause").YieldableError & {
|
|
108
|
+
readonly brand: unique symbol;
|
|
109
|
+
}>;
|
|
91
110
|
/** The authenticated source hash does not identify the complete raw MDX. */
|
|
92
111
|
export declare class ArtifactSourceHashMismatchError extends ArtifactSourceHashMismatchError_base {
|
|
93
112
|
}
|
|
94
113
|
declare const ArtifactRendererComponentMissingError_base: Schema.Class<ArtifactRendererComponentMissingError, Schema.TaggedStruct<"ArtifactRendererComponentMissingError", {
|
|
95
114
|
readonly componentName: Schema.String;
|
|
96
115
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
97
|
-
}>, import("effect/Cause").YieldableError
|
|
116
|
+
}>, import("effect/Cause").YieldableError & {
|
|
117
|
+
readonly brand: unique symbol;
|
|
118
|
+
}>;
|
|
98
119
|
/** A custom component required by the artifact is absent from the renderer. */
|
|
99
120
|
export declare class ArtifactRendererComponentMissingError extends ArtifactRendererComponentMissingError_base {
|
|
100
121
|
}
|
|
122
|
+
declare const ArtifactTreeComponentUnlistedError_base: Schema.Class<ArtifactTreeComponentUnlistedError, Schema.TaggedStruct<"ArtifactTreeComponentUnlistedError", {
|
|
123
|
+
readonly componentName: Schema.String;
|
|
124
|
+
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
125
|
+
}>, import("effect/Cause").YieldableError & {
|
|
126
|
+
readonly brand: unique symbol;
|
|
127
|
+
}>;
|
|
128
|
+
/** The content tree uses a component that the artifact does not declare as required. */
|
|
129
|
+
export declare class ArtifactTreeComponentUnlistedError extends ArtifactTreeComponentUnlistedError_base {
|
|
130
|
+
}
|
|
101
131
|
declare const ArtifactRendererDomainUnpublishedError_base: Schema.Class<ArtifactRendererDomainUnpublishedError, Schema.TaggedStruct<"ArtifactRendererDomainUnpublishedError", {
|
|
102
132
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
103
133
|
readonly rendererDomain: Schema.Literals<readonly ["ai-ds", "biology", "chemistry", "mathematics", "physics", "politics", "site", "snbt-general", "snbt-math", "snbt-plain", "snbt-quant", "tka-math"]>;
|
|
104
|
-
}>, import("effect/Cause").YieldableError
|
|
134
|
+
}>, import("effect/Cause").YieldableError & {
|
|
135
|
+
readonly brand: unique symbol;
|
|
136
|
+
}>;
|
|
105
137
|
/** The deployed Nakafa app cannot route this artifact's renderer domain. */
|
|
106
138
|
export declare class ArtifactRendererDomainUnpublishedError extends ArtifactRendererDomainUnpublishedError_base {
|
|
107
139
|
}
|
package/dist/artifact/spec.js
CHANGED
|
@@ -20,20 +20,13 @@ export class ArtifactVerificationByteLimitError extends Schema.TaggedError()("Ar
|
|
|
20
20
|
maxBytes: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThan(0))),
|
|
21
21
|
}) {
|
|
22
22
|
}
|
|
23
|
-
/** Declared compiled bytes differ from the authenticated function body. */
|
|
24
|
-
export class ArtifactCompiledByteLengthMismatchError extends Schema.TaggedError()("ArtifactCompiledByteLengthMismatchError", {
|
|
25
|
-
actualBytes: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
26
|
-
contentKey: ContentKeySchema,
|
|
27
|
-
declaredBytes: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
28
|
-
}) {
|
|
29
|
-
}
|
|
30
23
|
/** One authenticated payload field exceeded its shared runtime ceiling. */
|
|
31
24
|
export class ArtifactPayloadFieldByteLimitError extends Schema.TaggedError()("ArtifactPayloadFieldByteLimitError", {
|
|
32
25
|
actualBytes: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
33
26
|
contentKey: ContentKeySchema,
|
|
34
27
|
field: Schema.Literals([
|
|
35
28
|
"rawMdx",
|
|
36
|
-
"
|
|
29
|
+
"contentTree",
|
|
37
30
|
"plainText",
|
|
38
31
|
"canonicalPayload",
|
|
39
32
|
]),
|
|
@@ -64,6 +57,12 @@ export class ArtifactRendererComponentMissingError extends Schema.TaggedError()(
|
|
|
64
57
|
contentKey: ContentKeySchema,
|
|
65
58
|
}) {
|
|
66
59
|
}
|
|
60
|
+
/** The content tree uses a component that the artifact does not declare as required. */
|
|
61
|
+
export class ArtifactTreeComponentUnlistedError extends Schema.TaggedError()("ArtifactTreeComponentUnlistedError", {
|
|
62
|
+
componentName: Schema.String.check(Schema.isNonEmpty()),
|
|
63
|
+
contentKey: ContentKeySchema,
|
|
64
|
+
}) {
|
|
65
|
+
}
|
|
67
66
|
/** The deployed Nakafa app cannot route this artifact's renderer domain. */
|
|
68
67
|
export class ArtifactRendererDomainUnpublishedError extends Schema.TaggedError()("ArtifactRendererDomainUnpublishedError", {
|
|
69
68
|
contentKey: ContentKeySchema,
|
|
@@ -6,12 +6,18 @@ export declare const verifySignedContentArtifact: (input: unknown) => Effect.Eff
|
|
|
6
6
|
readonly keyId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSigningKeyId">;
|
|
7
7
|
readonly payload: {
|
|
8
8
|
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
9
|
-
readonly byteLength: number;
|
|
10
|
-
readonly compiledCode: string;
|
|
11
9
|
readonly compilerConfigHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
12
|
-
readonly compilerVersion: "0.
|
|
10
|
+
readonly compilerVersion: "0.2.0";
|
|
13
11
|
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
14
|
-
readonly
|
|
12
|
+
readonly contentTree: {
|
|
13
|
+
readonly $node: "element";
|
|
14
|
+
readonly children: readonly import("../tree.js").ContentTreeChild[];
|
|
15
|
+
readonly name: import("../tree.js").ContentTreeElementName;
|
|
16
|
+
readonly props: {
|
|
17
|
+
readonly [key: string]: import("../tree.js").ContentTreeValue;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
readonly format: "content-tree";
|
|
15
21
|
readonly mdxCompilerVersion: "3.1.1";
|
|
16
22
|
readonly plainText: string;
|
|
17
23
|
readonly rawMdx: string;
|
|
@@ -20,4 +26,4 @@ export declare const verifySignedContentArtifact: (input: unknown) => Effect.Eff
|
|
|
20
26
|
readonly sourceHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
21
27
|
};
|
|
22
28
|
readonly signature: string & import("effect/Brand").Brand<"@NakafaAI/AksaraEd25519Signature">;
|
|
23
|
-
}, import("#contracts/artifact/spec").
|
|
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>;
|
|
@@ -11,7 +11,9 @@ export declare const canonicalJson: (value: unknown) => Effect.Effect<string, Sc
|
|
|
11
11
|
declare const VersionHashMismatchError_base: Schema.Class<VersionHashMismatchError, Schema.TaggedStruct<"VersionHashMismatchError", {
|
|
12
12
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
13
13
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
14
|
-
}>, import("effect/Cause").YieldableError
|
|
14
|
+
}>, import("effect/Cause").YieldableError & {
|
|
15
|
+
readonly brand: unique symbol;
|
|
16
|
+
}>;
|
|
15
17
|
/** A stored hash is not the hash of the content that carries it. */
|
|
16
18
|
export declare class VersionHashMismatchError extends VersionHashMismatchError_base {
|
|
17
19
|
}
|
|
@@ -50,7 +50,9 @@ declare const PaperStimuliMismatchError_base: Schema.Class<PaperStimuliMismatchE
|
|
|
50
50
|
readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
51
51
|
readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
|
|
52
52
|
}>>;
|
|
53
|
-
}>, import("effect/Cause").YieldableError
|
|
53
|
+
}>, import("effect/Cause").YieldableError & {
|
|
54
|
+
readonly brand: unique symbol;
|
|
55
|
+
}>;
|
|
54
56
|
/**
|
|
55
57
|
* A paper does not list the stimulus versions that its item versions use.
|
|
56
58
|
* `missing` are the ones the items use and the paper leaves out, and `unused`
|
package/dist/content.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare function routeIdentity(input: {
|
|
|
26
26
|
/** Compares content heads using deterministic Unicode code-unit order. */
|
|
27
27
|
export declare function compareContentHeads(left: ContentHeadIdentity, right: ContentHeadIdentity): -1 | 0 | 1;
|
|
28
28
|
/** Compiler protocol implemented by this Aksara compiler release. */
|
|
29
|
-
export declare const AKSARA_COMPILER_VERSION = "0.
|
|
29
|
+
export declare const AKSARA_COMPILER_VERSION = "0.2.0";
|
|
30
30
|
/** Official MDX compiler version used to produce function-body artifacts. */
|
|
31
31
|
export declare const MDX_COMPILER_VERSION = "3.1.1";
|
|
32
32
|
/** Authored source identity accepted before deterministic compilation. */
|
|
@@ -57,15 +57,28 @@ export declare const CompileDocumentRequestSchema: Schema.Struct<{
|
|
|
57
57
|
}>;
|
|
58
58
|
}>;
|
|
59
59
|
export type CompileDocumentRequest = typeof CompileDocumentRequestSchema.Type;
|
|
60
|
-
/**
|
|
60
|
+
/** Compiled trusted payload: its evaluated content tree is what Nakafa renders. */
|
|
61
61
|
export declare const CompiledContentPayloadSchema: Schema.Struct<{
|
|
62
62
|
readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
|
|
63
|
-
readonly byteLength: Schema.Finite;
|
|
64
|
-
readonly compiledCode: Schema.String;
|
|
65
63
|
readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
66
|
-
readonly compilerVersion: Schema.Literal<"0.
|
|
64
|
+
readonly compilerVersion: Schema.Literal<"0.2.0">;
|
|
67
65
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
68
|
-
readonly
|
|
66
|
+
readonly contentTree: Schema.Codec<{
|
|
67
|
+
readonly $node: "element";
|
|
68
|
+
readonly children: readonly import("#contracts/tree").ContentTreeChild[];
|
|
69
|
+
readonly name: import("#contracts/tree").ContentTreeElementName;
|
|
70
|
+
readonly props: {
|
|
71
|
+
readonly [key: string]: import("#contracts/tree").ContentTreeValue;
|
|
72
|
+
};
|
|
73
|
+
}, {
|
|
74
|
+
readonly $node: "element";
|
|
75
|
+
readonly children: readonly import("#contracts/tree").ContentTreeChild[];
|
|
76
|
+
readonly name: import("#contracts/tree").ContentTreeElementName;
|
|
77
|
+
readonly props: {
|
|
78
|
+
readonly [key: string]: import("#contracts/tree").ContentTreeValue;
|
|
79
|
+
};
|
|
80
|
+
}, never, never>;
|
|
81
|
+
readonly format: Schema.Literal<"content-tree">;
|
|
69
82
|
readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
|
|
70
83
|
readonly plainText: Schema.String;
|
|
71
84
|
readonly rawMdx: Schema.String;
|
|
@@ -80,12 +93,25 @@ export declare const SignedContentArtifactSchema: Schema.Struct<{
|
|
|
80
93
|
readonly keyId: Schema.brand<Schema.String, "@NakafaAI/AksaraSigningKeyId">;
|
|
81
94
|
readonly payload: Schema.Struct<{
|
|
82
95
|
readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
|
|
83
|
-
readonly byteLength: Schema.Finite;
|
|
84
|
-
readonly compiledCode: Schema.String;
|
|
85
96
|
readonly compilerConfigHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
86
|
-
readonly compilerVersion: Schema.Literal<"0.
|
|
97
|
+
readonly compilerVersion: Schema.Literal<"0.2.0">;
|
|
87
98
|
readonly contentKey: Schema.brand<Schema.String, "@NakafaAI/AksaraContentKey">;
|
|
88
|
-
readonly
|
|
99
|
+
readonly contentTree: Schema.Codec<{
|
|
100
|
+
readonly $node: "element";
|
|
101
|
+
readonly children: readonly import("#contracts/tree").ContentTreeChild[];
|
|
102
|
+
readonly name: import("#contracts/tree").ContentTreeElementName;
|
|
103
|
+
readonly props: {
|
|
104
|
+
readonly [key: string]: import("#contracts/tree").ContentTreeValue;
|
|
105
|
+
};
|
|
106
|
+
}, {
|
|
107
|
+
readonly $node: "element";
|
|
108
|
+
readonly children: readonly import("#contracts/tree").ContentTreeChild[];
|
|
109
|
+
readonly name: import("#contracts/tree").ContentTreeElementName;
|
|
110
|
+
readonly props: {
|
|
111
|
+
readonly [key: string]: import("#contracts/tree").ContentTreeValue;
|
|
112
|
+
};
|
|
113
|
+
}, never, never>;
|
|
114
|
+
readonly format: Schema.Literal<"content-tree">;
|
|
89
115
|
readonly mdxCompilerVersion: Schema.Literal<"3.1.1">;
|
|
90
116
|
readonly plainText: Schema.String;
|
|
91
117
|
readonly rawMdx: Schema.String;
|
|
@@ -96,7 +122,7 @@ export declare const SignedContentArtifactSchema: Schema.Struct<{
|
|
|
96
122
|
readonly signature: Schema.brand<Schema.String, "@NakafaAI/AksaraEd25519Signature">;
|
|
97
123
|
}>;
|
|
98
124
|
export type SignedContentArtifact = typeof SignedContentArtifactSchema.Type;
|
|
99
|
-
/** Serializes a compiled payload with stable field and
|
|
125
|
+
/** Serializes a compiled payload with stable field, prop, and element order. */
|
|
100
126
|
export declare function canonicalizeCompiledContentPayload(payload: CompiledContentPayload): string;
|
|
101
127
|
/** Returns the domain-separated canonical bytes covered by Ed25519. */
|
|
102
128
|
export declare function canonicalizeContentArtifactSigningInput(artifactHash: typeof Sha256HashSchema.Type, payload: CompiledContentPayload): string;
|
package/dist/content.js
CHANGED
|
@@ -7,6 +7,7 @@ import { RendererManifestEnvelopeSchema } from "#contracts/renderer/contract";
|
|
|
7
7
|
import { RendererDomainSchema } from "#contracts/renderer/domain";
|
|
8
8
|
import { encodeJsonText } from "#contracts/text/json";
|
|
9
9
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
10
|
+
import { ContentTreeSchema, canonicalizeContentTree } from "#contracts/tree";
|
|
10
11
|
/** Published content families backed by real Aksara source registries. */
|
|
11
12
|
export const ContentFamilySchema = Schema.Literals([
|
|
12
13
|
"article",
|
|
@@ -36,7 +37,7 @@ export function compareContentHeads(left, right) {
|
|
|
36
37
|
compareCodeUnits(left.artifactLocale, right.artifactLocale));
|
|
37
38
|
}
|
|
38
39
|
/** Compiler protocol implemented by this Aksara compiler release. */
|
|
39
|
-
export const AKSARA_COMPILER_VERSION = "0.
|
|
40
|
+
export const AKSARA_COMPILER_VERSION = "0.2.0";
|
|
40
41
|
/** Official MDX compiler version used to produce function-body artifacts. */
|
|
41
42
|
export const MDX_COMPILER_VERSION = "3.1.1";
|
|
42
43
|
/** Authored source identity accepted before deterministic compilation. */
|
|
@@ -52,15 +53,14 @@ export const CompileDocumentRequestSchema = Schema.Struct({
|
|
|
52
53
|
...CompileDocumentSourceSchema.fields,
|
|
53
54
|
rendererManifest: RendererManifestEnvelopeSchema,
|
|
54
55
|
});
|
|
55
|
-
/**
|
|
56
|
+
/** Compiled trusted payload: its evaluated content tree is what Nakafa renders. */
|
|
56
57
|
export const CompiledContentPayloadSchema = Schema.Struct({
|
|
57
58
|
artifactLocale: ArtifactLocaleSchema,
|
|
58
|
-
byteLength: Schema.Finite.pipe(Schema.check(Schema.isInt()), Schema.check(Schema.isGreaterThanOrEqualTo(0))),
|
|
59
|
-
compiledCode: Schema.String,
|
|
60
59
|
compilerConfigHash: Sha256HashSchema,
|
|
61
60
|
compilerVersion: Schema.Literal(AKSARA_COMPILER_VERSION),
|
|
62
61
|
contentKey: ContentKeySchema,
|
|
63
|
-
|
|
62
|
+
contentTree: ContentTreeSchema,
|
|
63
|
+
format: Schema.Literal("content-tree"),
|
|
64
64
|
mdxCompilerVersion: Schema.Literal(MDX_COMPILER_VERSION),
|
|
65
65
|
plainText: Schema.String,
|
|
66
66
|
rawMdx: Schema.String,
|
|
@@ -76,23 +76,9 @@ export const SignedContentArtifactSchema = Schema.Struct({
|
|
|
76
76
|
signature: Ed25519SignatureSchema,
|
|
77
77
|
});
|
|
78
78
|
const CONTENT_ARTIFACT_SIGNATURE_DOMAIN = "nakafa.aksara.content-artifact";
|
|
79
|
-
/** Serializes a compiled payload with stable field and
|
|
79
|
+
/** Serializes a compiled payload with stable field, prop, and element order. */
|
|
80
80
|
export function canonicalizeCompiledContentPayload(payload) {
|
|
81
|
-
return encodeJsonText({
|
|
82
|
-
artifactLocale: payload.artifactLocale,
|
|
83
|
-
byteLength: payload.byteLength,
|
|
84
|
-
compiledCode: payload.compiledCode,
|
|
85
|
-
compilerConfigHash: payload.compilerConfigHash,
|
|
86
|
-
compilerVersion: payload.compilerVersion,
|
|
87
|
-
contentKey: payload.contentKey,
|
|
88
|
-
format: payload.format,
|
|
89
|
-
mdxCompilerVersion: payload.mdxCompilerVersion,
|
|
90
|
-
plainText: payload.plainText,
|
|
91
|
-
rawMdx: payload.rawMdx,
|
|
92
|
-
rendererDomain: payload.rendererDomain,
|
|
93
|
-
requiredComponents: payload.requiredComponents,
|
|
94
|
-
sourceHash: payload.sourceHash,
|
|
95
|
-
});
|
|
81
|
+
return `{"artifactLocale":${encodeJsonText(payload.artifactLocale)},"compilerConfigHash":${encodeJsonText(payload.compilerConfigHash)},"compilerVersion":${encodeJsonText(payload.compilerVersion)},"contentKey":${encodeJsonText(payload.contentKey)},"contentTree":${canonicalizeContentTree(payload.contentTree)},"format":${encodeJsonText(payload.format)},"mdxCompilerVersion":${encodeJsonText(payload.mdxCompilerVersion)},"plainText":${encodeJsonText(payload.plainText)},"rawMdx":${encodeJsonText(payload.rawMdx)},"rendererDomain":${encodeJsonText(payload.rendererDomain)},"requiredComponents":${encodeJsonText(payload.requiredComponents)},"sourceHash":${encodeJsonText(payload.sourceHash)}}`;
|
|
96
82
|
}
|
|
97
83
|
/** Returns the domain-separated canonical bytes covered by Ed25519. */
|
|
98
84
|
export function canonicalizeContentArtifactSigningInput(artifactHash, payload) {
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ declare const ContractDecodeError_base: Schema.Class<ContractDecodeError, Schema
|
|
|
3
3
|
readonly cause: Schema.Unknown;
|
|
4
4
|
readonly contract: Schema.Trimmed;
|
|
5
5
|
readonly message: Schema.Trimmed;
|
|
6
|
-
}>, import("effect/Cause").YieldableError
|
|
6
|
+
}>, import("effect/Cause").YieldableError & {
|
|
7
|
+
readonly brand: unique symbol;
|
|
8
|
+
}>;
|
|
7
9
|
/** Describes a wire value that failed its named Effect Schema contract. */
|
|
8
10
|
export declare class ContractDecodeError extends ContractDecodeError_base {
|
|
9
11
|
}
|
package/dist/graph/family.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export declare const LearningGraphAssetOwnerSchema: Schema.Struct<{
|
|
|
13
13
|
export type LearningGraphAssetOwner = typeof LearningGraphAssetOwnerSchema.Type;
|
|
14
14
|
declare const LearningGraphAssetFamilyError_base: Schema.Class<LearningGraphAssetFamilyError, Schema.TaggedStruct<"LearningGraphAssetFamilyError", {
|
|
15
15
|
readonly assetId: Schema.String;
|
|
16
|
-
}>, import("effect/Cause").YieldableError
|
|
16
|
+
}>, import("effect/Cause").YieldableError & {
|
|
17
|
+
readonly brand: unique symbol;
|
|
18
|
+
}>;
|
|
17
19
|
/** One asset ID cannot address a supported current semantic content family. */
|
|
18
20
|
export declare class LearningGraphAssetFamilyError extends LearningGraphAssetFamilyError_base {
|
|
19
21
|
}
|
|
@@ -25,7 +27,9 @@ declare const LearningGraphFamilyError_base: Schema.Class<LearningGraphFamilyErr
|
|
|
25
27
|
readonly learningObjectId: Schema.String;
|
|
26
28
|
readonly lensId: Schema.String;
|
|
27
29
|
}>;
|
|
28
|
-
}>, import("effect/Cause").YieldableError
|
|
30
|
+
}>, import("effect/Cause").YieldableError & {
|
|
31
|
+
readonly brand: unique symbol;
|
|
32
|
+
}>;
|
|
29
33
|
/** One graph identity does not coherently belong to a current semantic family. */
|
|
30
34
|
export declare class LearningGraphFamilyError extends LearningGraphFamilyError_base {
|
|
31
35
|
}
|
package/dist/graph/identity.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export declare const LearningGraphSegmentsSchema: Schema.Struct<{
|
|
|
10
10
|
export type LearningGraphSegments = typeof LearningGraphSegmentsSchema.Type;
|
|
11
11
|
declare const LearningGraphIdentityError_base: Schema.Class<LearningGraphIdentityError, Schema.TaggedStruct<"LearningGraphIdentityError", {
|
|
12
12
|
readonly cause: Schema.Unknown;
|
|
13
|
-
}>, import("effect/Cause").YieldableError
|
|
13
|
+
}>, import("effect/Cause").YieldableError & {
|
|
14
|
+
readonly brand: unique symbol;
|
|
15
|
+
}>;
|
|
14
16
|
/** Source segments could not produce valid stable graph identities. */
|
|
15
17
|
export declare class LearningGraphIdentityError extends LearningGraphIdentityError_base {
|
|
16
18
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Crypto, Effect, PlatformError } from "effect";
|
|
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.
|
|
5
|
+
*/
|
|
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>;
|
|
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>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Crypto, Effect, PlatformError } from "effect";
|
|
2
|
+
import { Hex } from "effect/encoding";
|
|
3
|
+
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
|
+
/** Largest byte count that one `crypto.getRandomValues` call accepts. */
|
|
5
|
+
const RANDOM_CHUNK_BYTES = 65_536;
|
|
6
|
+
/**
|
|
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.
|
|
9
|
+
*/
|
|
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
|
+
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));
|
|
36
|
+
/** Computes the `sha256:` identity of one byte sequence, the form every stored hash uses. */
|
|
37
|
+
export const hashBytes = Effect.fn("AksaraContracts.hashBytes")(function* (bytes) {
|
|
38
|
+
const digest = yield* digestSha256(bytes);
|
|
39
|
+
return Sha256HashSchema.make(`sha256:${Hex.encode(digest)}`);
|
|
40
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collects the UTF-8 bytes of one digest stream so that Web Crypto can digest
|
|
3
|
+
* it in one call. Each piece is encoded on its own, exactly as an incremental
|
|
4
|
+
* hash encoded it, so a lone surrogate keeps the bytes it always had.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DigestStream {
|
|
7
|
+
#private;
|
|
8
|
+
/** Appends one piece of text in the order the stream was built. */
|
|
9
|
+
add(text: string): void;
|
|
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>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MutableList } from "effect";
|
|
2
|
+
import { hashBytes } from "#contracts/hash/digest";
|
|
3
|
+
/**
|
|
4
|
+
* Collects the UTF-8 bytes of one digest stream so that Web Crypto can digest
|
|
5
|
+
* it in one call. Each piece is encoded on its own, exactly as an incremental
|
|
6
|
+
* hash encoded it, so a lone surrogate keeps the bytes it always had.
|
|
7
|
+
*/
|
|
8
|
+
export class DigestStream {
|
|
9
|
+
#pieces = MutableList.make();
|
|
10
|
+
#length = 0;
|
|
11
|
+
/** Appends one piece of text in the order the stream was built. */
|
|
12
|
+
add(text) {
|
|
13
|
+
const bytes = new TextEncoder().encode(text);
|
|
14
|
+
MutableList.append(this.#pieces, bytes);
|
|
15
|
+
this.#length += bytes.byteLength;
|
|
16
|
+
}
|
|
17
|
+
/** Digests every piece in order and returns the branded sha256 identity. */
|
|
18
|
+
digest() {
|
|
19
|
+
const bytes = new Uint8Array(this.#length);
|
|
20
|
+
let offset = 0;
|
|
21
|
+
for (const piece of MutableList.toArray(this.#pieces)) {
|
|
22
|
+
bytes.set(piece, offset);
|
|
23
|
+
offset += piece.byteLength;
|
|
24
|
+
}
|
|
25
|
+
return hashBytes(bytes);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/hash/text.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
declare const TextHashError_base: Schema.Class<TextHashError, Schema.TaggedStruct<"TextHashError", {
|
|
3
3
|
readonly cause: Schema.Unknown;
|
|
4
|
-
}>, import("effect/Cause").YieldableError
|
|
4
|
+
}>, import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly brand: unique symbol;
|
|
6
|
+
}>;
|
|
5
7
|
/** Web Crypto could not hash one UTF-8 contract value. */
|
|
6
8
|
export declare class TextHashError extends TextHashError_base {
|
|
7
9
|
}
|
package/dist/hash/text.js
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { hashBytes } from "#contracts/hash/digest";
|
|
3
3
|
/** Web Crypto could not hash one UTF-8 contract value. */
|
|
4
4
|
export class TextHashError extends Schema.TaggedError()("TextHashError", { cause: Schema.Unknown }) {
|
|
5
5
|
}
|
|
6
|
-
/** Encodes one SHA-256 digest without depending on a Node runtime. */
|
|
7
|
-
function encodeDigest(value) {
|
|
8
|
-
let hex = "";
|
|
9
|
-
for (const byte of new Uint8Array(value)) {
|
|
10
|
-
hex += byte.toString(16).padStart(2, "0");
|
|
11
|
-
}
|
|
12
|
-
return Sha256HashSchema.make(`sha256:${hex}`);
|
|
13
|
-
}
|
|
14
6
|
/** Hashes exact UTF-8 text through the Web Crypto contract. */
|
|
15
|
-
export const hashText = Effect.fn("AksaraContracts.hashText")((value) => Effect.
|
|
16
|
-
catch: (cause) => new TextHashError({ cause }),
|
|
17
|
-
try: () => crypto.subtle
|
|
18
|
-
.digest("SHA-256", new TextEncoder().encode(value))
|
|
19
|
-
.then(encodeDigest),
|
|
20
|
-
}));
|
|
7
|
+
export const hashText = Effect.fn("AksaraContracts.hashText")((value) => hashBytes(new TextEncoder().encode(value)).pipe(Effect.mapError((cause) => new TextHashError({ cause }))));
|
package/dist/limits.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Maximum UTF-8 bytes accepted for one authored MDX source. */
|
|
2
2
|
export declare const MAX_RAW_MDX_BYTES: number;
|
|
3
|
-
/** Maximum UTF-8 bytes accepted for one
|
|
4
|
-
export declare const
|
|
3
|
+
/** Maximum UTF-8 bytes accepted for one canonical content tree. */
|
|
4
|
+
export declare const MAX_CONTENT_TREE_BYTES: number;
|
|
5
5
|
/** Maximum UTF-8 bytes accepted for one extracted plain-text projection. */
|
|
6
6
|
export declare const MAX_PLAIN_TEXT_BYTES: number;
|
|
7
7
|
/** Maximum UTF-8 bytes for all canonical compiled payload fields. */
|
package/dist/limits.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Maximum UTF-8 bytes accepted for one authored MDX source. */
|
|
2
2
|
export const MAX_RAW_MDX_BYTES = 128 * 1024;
|
|
3
|
-
/** Maximum UTF-8 bytes accepted for one
|
|
4
|
-
export const
|
|
3
|
+
/** Maximum UTF-8 bytes accepted for one canonical content tree. */
|
|
4
|
+
export const MAX_CONTENT_TREE_BYTES = 384 * 1024;
|
|
5
5
|
/** Maximum UTF-8 bytes accepted for one extracted plain-text projection. */
|
|
6
6
|
export const MAX_PLAIN_TEXT_BYTES = 128 * 1024;
|
|
7
7
|
/** Maximum UTF-8 bytes for all canonical compiled payload fields. */
|