@nakafa/aksara-contracts 2.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/artifact/integrity.d.ts +3 -3
- package/dist/artifact/integrity.js +2 -2
- package/dist/artifact/source.d.ts +2 -2
- package/dist/artifact/source.js +2 -8
- package/dist/artifact/spec.d.ts +0 -16
- package/dist/artifact/spec.js +0 -6
- package/dist/artifact/verify.d.ts +1 -1
- package/dist/assessment/hash.d.ts +6 -6
- package/dist/assessment/snapshot.d.ts +3 -3
- package/dist/date.js +1 -1
- package/dist/hash/digest.d.ts +7 -7
- package/dist/hash/digest.js +9 -30
- package/dist/hash/stream.d.ts +1 -1
- package/dist/hash/text.d.ts +3 -12
- package/dist/hash/text.js +3 -6
- package/dist/ids.js +8 -8
- package/dist/preview/auth.d.ts +1 -1
- package/dist/preview/auth.js +29 -25
- package/dist/program/snapshot/digest.d.ts +1 -2
- package/dist/program/snapshot/digest.js +2 -4
- package/dist/program/snapshot/hash.d.ts +6 -21
- package/dist/program/snapshot/hash.js +3 -9
- package/dist/projection/digest.d.ts +7 -16
- package/dist/projection/digest.js +7 -13
- package/dist/projection/hash.d.ts +2 -11
- package/dist/projection/hash.js +2 -5
- package/dist/projection/material.js +1 -1
- package/dist/projection/verify.d.ts +1 -1
- package/dist/projection/verify.js +1 -1
- package/dist/quran/notes.js +1 -1
- package/dist/quran/provenance.d.ts +2 -8
- package/dist/quran/provenance.js +1 -4
- package/dist/quran/snapshot/digest.d.ts +1 -2
- package/dist/quran/snapshot/digest.js +2 -2
- package/dist/quran/snapshot/hash.d.ts +3 -10
- package/dist/quran/snapshot/hash.js +2 -5
- package/dist/quran/snapshot/row/hash.d.ts +3 -12
- package/dist/quran/snapshot/row/hash.js +2 -5
- package/dist/release/digest.d.ts +7 -16
- package/dist/release/digest.js +7 -13
- package/dist/release/hash.d.ts +2 -11
- package/dist/release/hash.js +2 -6
- package/dist/release/items.d.ts +1 -1
- package/dist/release/items.js +1 -1
- package/dist/release/result/digest.d.ts +5 -13
- package/dist/release/result/digest.js +4 -9
- package/dist/release/rollback/digest.d.ts +7 -16
- package/dist/release/rollback/digest.js +7 -13
- package/dist/release/route/digest.d.ts +7 -16
- package/dist/release/route/digest.js +7 -13
- package/dist/release/route/verify.d.ts +1 -1
- package/dist/release/route/verify.js +1 -1
- package/dist/release/snapshot/evidence/assessment.d.ts +1 -1
- package/dist/release/snapshot/evidence/program.d.ts +1 -1
- package/dist/release/snapshot/evidence/quran.d.ts +1 -1
- package/dist/release/snapshot/evidence.d.ts +1 -1
- package/dist/release/snapshot/verify.d.ts +1 -1
- package/dist/release/verify.d.ts +2 -2
- package/dist/renderer/compatibility.d.ts +1 -1
- package/dist/renderer/component.js +1 -1
- package/dist/renderer/contract.d.ts +0 -8
- package/dist/renderer/contract.js +0 -3
- package/dist/renderer/manifest.d.ts +3 -3
- package/dist/renderer/manifest.js +2 -2
- package/dist/runtime/verify.d.ts +2 -2
- package/dist/signature/key.d.ts +0 -2
- package/dist/signature/key.js +37 -88
- package/dist/signature/verify.js +31 -46
- package/dist/tree.js +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import { type ReleaseId } from "#contracts/ids";
|
|
3
2
|
import { type RollbackSnapshotEntry } from "#contracts/release/rollback/spec";
|
|
4
3
|
import type { ContentReleaseManifest } from "#contracts/release/spec";
|
|
5
|
-
declare const RollbackSnapshotHashError_base: Schema.Class<RollbackSnapshotHashError, Schema.TaggedStruct<"RollbackSnapshotHashError", {
|
|
6
|
-
readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
|
|
7
|
-
}>, import("effect/Cause").YieldableError & {
|
|
8
|
-
readonly brand: unique symbol;
|
|
9
|
-
}>;
|
|
10
|
-
/** SHA-256 computation failed before rollback-state integrity was established. */
|
|
11
|
-
export declare class RollbackSnapshotHashError extends RollbackSnapshotHashError_base {
|
|
12
|
-
}
|
|
13
4
|
declare const RollbackSnapshotCountMismatchError_base: Schema.Class<RollbackSnapshotCountMismatchError, Schema.TaggedStruct<"RollbackSnapshotCountMismatchError", {
|
|
14
5
|
readonly actualCount: Schema.Finite;
|
|
15
6
|
readonly expectedCount: Schema.Finite;
|
|
@@ -39,16 +30,16 @@ declare class RollbackSnapshotDigestState {
|
|
|
39
30
|
/** Adds one canonical prior state to the snapshot digest. */
|
|
40
31
|
update(entry: RollbackSnapshotEntry): void;
|
|
41
32
|
/** Digests the complete stream once and returns its branded immutable identity. */
|
|
42
|
-
digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">,
|
|
33
|
+
digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
|
|
43
34
|
}
|
|
44
35
|
/** Creates a fresh domain-separated digest state for one rollback snapshot. */
|
|
45
36
|
export declare const createRollbackSnapshotDigest: Effect.Effect<RollbackSnapshotDigestState, never, never>;
|
|
46
37
|
/** Adds one canonical prior state to an incremental rollback digest. */
|
|
47
38
|
export declare function updateRollbackSnapshotDigest(state: RollbackSnapshotDigestState, entry: RollbackSnapshotEntry): Effect.Effect<RollbackSnapshotDigestState, never, never>;
|
|
48
|
-
/** Finalizes one rollback snapshot digest
|
|
49
|
-
export declare function finalizeRollbackSnapshotDigest(
|
|
50
|
-
/** Digests one rollback snapshot stream. Its canonical bytes are held until one
|
|
51
|
-
export declare const digestRollbackSnapshot: <E, R>(
|
|
39
|
+
/** Finalizes one rollback snapshot digest. */
|
|
40
|
+
export declare function finalizeRollbackSnapshotDigest(state: RollbackSnapshotDigestState): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
|
|
41
|
+
/** Digests one rollback snapshot stream. Its canonical bytes are held until one digest runs. */
|
|
42
|
+
export declare const digestRollbackSnapshot: <E, R>(entries: Stream.Stream<{
|
|
52
43
|
readonly index: number;
|
|
53
44
|
readonly releaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">;
|
|
54
45
|
readonly snapshot: {
|
|
@@ -105,7 +96,7 @@ export declare const digestRollbackSnapshot: <E, R>(releaseId: string & import("
|
|
|
105
96
|
}, E, R>) => Effect.Effect<{
|
|
106
97
|
count: number;
|
|
107
98
|
digest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
108
|
-
}, E
|
|
99
|
+
}, E, R>;
|
|
109
100
|
/** Authenticates a replayed prior-state stream against its signed release. */
|
|
110
101
|
export declare const verifyRollbackSnapshot: <E, R>(input: {
|
|
111
102
|
readonly entries: Stream.Stream<RollbackSnapshotEntry, E, R>;
|
|
@@ -113,5 +104,5 @@ export declare const verifyRollbackSnapshot: <E, R>(input: {
|
|
|
113
104
|
}) => Effect.Effect<{
|
|
114
105
|
count: number;
|
|
115
106
|
digest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
116
|
-
}, E | RollbackSnapshotCountMismatchError | RollbackSnapshotDigestMismatchError
|
|
107
|
+
}, E | RollbackSnapshotCountMismatchError | RollbackSnapshotDigestMismatchError, R>;
|
|
117
108
|
export {};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import { DigestStream } from "#contracts/hash/stream";
|
|
3
|
-
import { ReleaseIdSchema } from "#contracts/ids";
|
|
4
3
|
import { ReleaseCountMismatchFields, ReleaseDigestMismatchFields, } from "#contracts/release/mismatch";
|
|
5
4
|
import { canonicalizeRollbackSnapshotEntry, } from "#contracts/release/rollback/spec";
|
|
6
5
|
const ROLLBACK_SNAPSHOT_DIGEST_DOMAIN = "nakafa.aksara.rollback-snapshot";
|
|
7
|
-
/** SHA-256 computation failed before rollback-state integrity was established. */
|
|
8
|
-
export class RollbackSnapshotHashError extends Schema.TaggedError()("RollbackSnapshotHashError", { releaseId: ReleaseIdSchema }) {
|
|
9
|
-
}
|
|
10
6
|
/** A replayed rollback snapshot has a different signed entry count. */
|
|
11
7
|
export class RollbackSnapshotCountMismatchError extends Schema.TaggedError()("RollbackSnapshotCountMismatchError", { ...ReleaseCountMismatchFields }) {
|
|
12
8
|
}
|
|
@@ -44,22 +40,20 @@ export function updateRollbackSnapshotDigest(state, entry) {
|
|
|
44
40
|
return state;
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
|
-
/** Finalizes one rollback snapshot digest
|
|
48
|
-
export function finalizeRollbackSnapshotDigest(
|
|
49
|
-
return state
|
|
50
|
-
.digest()
|
|
51
|
-
.pipe(Effect.mapError(() => new RollbackSnapshotHashError({ releaseId })));
|
|
43
|
+
/** Finalizes one rollback snapshot digest. */
|
|
44
|
+
export function finalizeRollbackSnapshotDigest(state) {
|
|
45
|
+
return state.digest();
|
|
52
46
|
}
|
|
53
|
-
/** Digests one rollback snapshot stream. Its canonical bytes are held until one
|
|
54
|
-
export const digestRollbackSnapshot = Effect.fn("AksaraContracts.digestRollbackSnapshot")(function* (
|
|
47
|
+
/** Digests one rollback snapshot stream. Its canonical bytes are held until one digest runs. */
|
|
48
|
+
export const digestRollbackSnapshot = Effect.fn("AksaraContracts.digestRollbackSnapshot")(function* (entries) {
|
|
55
49
|
const initial = yield* createRollbackSnapshotDigest;
|
|
56
50
|
const state = yield* entries.pipe(Stream.runFoldEffect(() => initial, (current, entry) => updateRollbackSnapshotDigest(current, entry)));
|
|
57
|
-
const digest = yield* finalizeRollbackSnapshotDigest(
|
|
51
|
+
const digest = yield* finalizeRollbackSnapshotDigest(state);
|
|
58
52
|
return { count: state.count, digest };
|
|
59
53
|
});
|
|
60
54
|
/** Authenticates a replayed prior-state stream against its signed release. */
|
|
61
55
|
export const verifyRollbackSnapshot = Effect.fn("AksaraContracts.verifyRollbackSnapshot")(function* (input) {
|
|
62
|
-
const summary = yield* digestRollbackSnapshot(input.
|
|
56
|
+
const summary = yield* digestRollbackSnapshot(input.entries);
|
|
63
57
|
if (summary.count !== input.manifest.rollbackCount) {
|
|
64
58
|
return yield* new RollbackSnapshotCountMismatchError({
|
|
65
59
|
actualCount: summary.count,
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { Effect,
|
|
2
|
-
import { type ReleaseId } from "#contracts/ids";
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
3
2
|
import { type ContentRouteItem } from "#contracts/release/route/spec";
|
|
4
|
-
declare const RouteHashError_base: Schema.Class<RouteHashError, Schema.TaggedStruct<"RouteHashError", {
|
|
5
|
-
readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
|
|
6
|
-
}>, import("effect/Cause").YieldableError & {
|
|
7
|
-
readonly brand: unique symbol;
|
|
8
|
-
}>;
|
|
9
|
-
/** SHA-256 computation failed before route integrity was established. */
|
|
10
|
-
export declare class RouteHashError extends RouteHashError_base {
|
|
11
|
-
}
|
|
12
3
|
/** Keeps incremental route digest state private to one release preparation. */
|
|
13
4
|
declare class RouteDigestState {
|
|
14
5
|
#private;
|
|
@@ -18,16 +9,16 @@ declare class RouteDigestState {
|
|
|
18
9
|
/** Adds one canonical route item to this invocation-owned digest. */
|
|
19
10
|
update(item: ContentRouteItem): void;
|
|
20
11
|
/** Digests the complete route stream once and returns its branded identity. */
|
|
21
|
-
digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">,
|
|
12
|
+
digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
|
|
22
13
|
}
|
|
23
14
|
/** Creates fresh domain-separated route digest state. */
|
|
24
15
|
export declare const createRouteDigest: Effect.Effect<RouteDigestState, never, never>;
|
|
25
16
|
/** Adds one canonical route item to an incremental digest. */
|
|
26
17
|
export declare function updateRouteDigest(state: RouteDigestState, item: ContentRouteItem): Effect.Effect<RouteDigestState, never, never>;
|
|
27
|
-
/** Completes one incremental route digest
|
|
28
|
-
export declare function completeRouteDigest(
|
|
29
|
-
/** Digests a canonical route stream. Its canonical bytes are held until one
|
|
30
|
-
export declare const digestRoutes: <E, R>(
|
|
18
|
+
/** Completes one incremental route digest. */
|
|
19
|
+
export declare function completeRouteDigest(state: RouteDigestState): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, never, never>;
|
|
20
|
+
/** Digests a canonical route stream. Its canonical bytes are held until one digest runs. */
|
|
21
|
+
export declare const digestRoutes: <E, R>(routes: Stream.Stream<{
|
|
31
22
|
readonly change: {
|
|
32
23
|
readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
33
24
|
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
@@ -43,5 +34,5 @@ export declare const digestRoutes: <E, R>(releaseId: string & import("effect/Bra
|
|
|
43
34
|
}, E, R>) => Effect.Effect<{
|
|
44
35
|
count: number;
|
|
45
36
|
digest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
46
|
-
}, E
|
|
37
|
+
}, E, R>;
|
|
47
38
|
export {};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
2
|
import { DigestStream } from "#contracts/hash/stream";
|
|
3
|
-
import { ReleaseIdSchema } from "#contracts/ids";
|
|
4
3
|
import { canonicalizeContentRouteItem, } from "#contracts/release/route/spec";
|
|
5
4
|
const CONTENT_ROUTE_DIGEST_DOMAIN = "nakafa.aksara.content-routes";
|
|
6
|
-
/** SHA-256 computation failed before route integrity was established. */
|
|
7
|
-
export class RouteHashError extends Schema.TaggedError()("RouteHashError", { releaseId: ReleaseIdSchema }) {
|
|
8
|
-
}
|
|
9
5
|
/** Keeps incremental route digest state private to one release preparation. */
|
|
10
6
|
class RouteDigestState {
|
|
11
7
|
#stream = new DigestStream();
|
|
@@ -35,16 +31,14 @@ export function updateRouteDigest(state, item) {
|
|
|
35
31
|
return state;
|
|
36
32
|
});
|
|
37
33
|
}
|
|
38
|
-
/** Completes one incremental route digest
|
|
39
|
-
export function completeRouteDigest(
|
|
40
|
-
return state
|
|
41
|
-
.digest()
|
|
42
|
-
.pipe(Effect.mapError(() => new RouteHashError({ releaseId })));
|
|
34
|
+
/** Completes one incremental route digest. */
|
|
35
|
+
export function completeRouteDigest(state) {
|
|
36
|
+
return state.digest();
|
|
43
37
|
}
|
|
44
|
-
/** Digests a canonical route stream. Its canonical bytes are held until one
|
|
45
|
-
export const digestRoutes = Effect.fn("AksaraContracts.digestRoutes")(function* (
|
|
38
|
+
/** Digests a canonical route stream. Its canonical bytes are held until one digest runs. */
|
|
39
|
+
export const digestRoutes = Effect.fn("AksaraContracts.digestRoutes")(function* (routes) {
|
|
46
40
|
const initial = yield* createRouteDigest;
|
|
47
41
|
const state = yield* routes.pipe(Stream.runFoldEffect(() => initial, (current, route) => updateRouteDigest(current, route)));
|
|
48
|
-
const digest = yield* completeRouteDigest(
|
|
42
|
+
const digest = yield* completeRouteDigest(state);
|
|
49
43
|
return { count: state.count, digest };
|
|
50
44
|
});
|
|
@@ -73,5 +73,5 @@ export declare const verifyContentRoutes: <E, R>(input: {
|
|
|
73
73
|
readonly routes: Stream.Stream<unknown, E, R>;
|
|
74
74
|
}) => Effect.Effect<{
|
|
75
75
|
count: number;
|
|
76
|
-
}, E | RouteCountError | RouteDecodeError | RouteDigestError | RouteDuplicateError |
|
|
76
|
+
}, E | RouteCountError | RouteDecodeError | RouteDigestError | RouteDuplicateError | RouteIdentityError, R>;
|
|
77
77
|
export {};
|
|
@@ -55,7 +55,7 @@ export function decodeContentRoutes(input) {
|
|
|
55
55
|
}
|
|
56
56
|
/** Authenticates a replayable route stream against its signed manifest. */
|
|
57
57
|
export const verifyContentRoutes = Effect.fn("AksaraContracts.verifyContentRoutes")(function* (input) {
|
|
58
|
-
const summary = yield* digestRoutes(
|
|
58
|
+
const summary = yield* digestRoutes(decodeContentRoutes(input));
|
|
59
59
|
if (summary.count !== input.manifest.routeCount) {
|
|
60
60
|
return yield* new RouteCountError({
|
|
61
61
|
actualCount: summary.count,
|
|
@@ -23,4 +23,4 @@ export declare const verifyAssessmentSnapshotRows: <E, R>(snapshot: {
|
|
|
23
23
|
readonly format: "assessment-snapshot";
|
|
24
24
|
readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
25
25
|
};
|
|
26
|
-
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("#contracts/assessment/closure").AssessmentClosureError | import("#contracts/assessment/snapshot").AssessmentRowsError | import("effect/
|
|
26
|
+
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("#contracts/assessment/closure").AssessmentClosureError | import("#contracts/assessment/snapshot").AssessmentRowsError | import("effect/Schema").SchemaError | import("#contracts/release/snapshot/evidence/requirement").SnapshotEvidenceError, R>;
|
|
@@ -14,4 +14,4 @@ export declare const verifyProgramSnapshotRows: <E, R>(snapshot: {
|
|
|
14
14
|
readonly format: "localized-program-snapshot";
|
|
15
15
|
readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
16
16
|
};
|
|
17
|
-
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("#contracts/program/snapshot/digest").ProgramDigestError | import("#contracts/
|
|
17
|
+
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("#contracts/program/snapshot/digest").ProgramDigestError | import("#contracts/release/snapshot/evidence/requirement").SnapshotEvidenceError, R>;
|
|
@@ -24,4 +24,4 @@ export declare const verifyQuranSnapshotRows: <E, R>(snapshot: {
|
|
|
24
24
|
readonly format: "localized-quran-snapshot";
|
|
25
25
|
readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
26
26
|
};
|
|
27
|
-
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("
|
|
27
|
+
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("#contracts/quran/snapshot/digest").QuranRowIntegrityError | import("#contracts/quran/snapshot/digest").QuranRowOrderError | import("#contracts/release/snapshot/evidence/requirement").SnapshotEvidenceError, R>;
|
|
@@ -55,4 +55,4 @@ export declare const verifySnapshotRows: <E, R>(snapshot: {
|
|
|
55
55
|
readonly format: "localized-quran-snapshot";
|
|
56
56
|
readonly snapshotId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
57
57
|
};
|
|
58
|
-
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("../../assessment/closure.js").AssessmentClosureError | import("../../assessment/snapshot.js").AssessmentRowsError | import("
|
|
58
|
+
}, rows: SnapshotRowSource<E, R>) => Effect.Effect<number, E | import("../../assessment/closure.js").AssessmentClosureError | import("../../assessment/snapshot.js").AssessmentRowsError | import("../../program/snapshot/digest.js").ProgramDigestError | import("../../quran/snapshot/digest.js").QuranRowIntegrityError | import("../../quran/snapshot/digest.js").QuranRowOrderError | import("effect/Schema").SchemaError | import("#contracts/release/snapshot/evidence/requirement").SnapshotEvidenceError, R>;
|
|
@@ -1752,5 +1752,5 @@ export declare const verifyContentSnapshots: <ManifestError, ManifestContext, Ro
|
|
|
1752
1752
|
};
|
|
1753
1753
|
};
|
|
1754
1754
|
stagedRows: number;
|
|
1755
|
-
}, ManifestError | RowError | import("../../assessment/closure.js").AssessmentClosureError | import("#contracts/assessment/snapshot").AssessmentRowsError | import("
|
|
1755
|
+
}, ManifestError | RowError | import("../../assessment/closure.js").AssessmentClosureError | import("#contracts/assessment/snapshot").AssessmentRowsError | import("../../program/snapshot/digest.js").ProgramDigestError | import("../../quran/snapshot/digest.js").QuranRowIntegrityError | import("../../quran/snapshot/digest.js").QuranRowOrderError | Schema.SchemaError | import("./evidence/requirement.js").SnapshotEvidenceError | SnapshotManifestDecodeError | SnapshotManifestOrderError | SnapshotRowDecodeError | SnapshotRowFamilyError | SnapshotStagedCountError | SnapshotTransitionError, ManifestContext | RowContext>;
|
|
1756
1756
|
export {};
|
package/dist/release/verify.d.ts
CHANGED
|
@@ -88,9 +88,9 @@ export declare const verifySignedContentRelease: (input: unknown) => Effect.Effe
|
|
|
88
88
|
};
|
|
89
89
|
readonly manifestHash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
90
90
|
readonly signature: string & import("effect/Brand").Brand<"@NakafaAI/AksaraEd25519Signature">;
|
|
91
|
-
}, import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError |
|
|
91
|
+
}, import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | ReleaseManifestHashMismatchError | ReleaseVerificationDecodeError | 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>;
|
|
92
92
|
/** Strictly decodes and authenticates one renderer-bound release bundle. */
|
|
93
|
-
declare function verifyBundle<A extends ContentReleaseBundle, I>(schema: Schema.Codec<A, I>, input: unknown): Effect.Effect<A, import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | ReleaseBundleVerificationDecodeError |
|
|
93
|
+
declare function verifyBundle<A extends ContentReleaseBundle, I>(schema: Schema.Codec<A, I>, input: unknown): Effect.Effect<A, import("../errors.js").ContractDecodeError | import("../signature/spec.js").PublicKeyParseError | import("../signature/spec.js").PublicKeyTypeError | ReleaseBundleVerificationDecodeError | ReleaseManifestHashMismatchError | ReleaseVerificationDecodeError | 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>;
|
|
94
94
|
/** Authenticates one signed release and its frozen renderer contract together. */
|
|
95
95
|
export declare const verifyContentReleaseBundle: (input: unknown) => Effect.Effect<ContentReleaseBundle, Effect.Error<ReturnType<typeof verifyBundle>>, Effect.Services<ReturnType<typeof verifyBundle>>>;
|
|
96
96
|
/** Authenticates a renderer-bound release only when rollback owns its origin. */
|
|
@@ -46,5 +46,5 @@ export declare const verifyContentRendererCompatibility: (args_0: {
|
|
|
46
46
|
readonly format: "nakafa-mdx-renderer";
|
|
47
47
|
readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
48
48
|
readonly publishedDomains: readonly ("ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math")[];
|
|
49
|
-
}, ArtifactRendererComponentMissingError | ArtifactRendererDomainUnpublishedError | import("../errors.js").ContractDecodeError | import("#contracts/renderer/contract").RendererDomainCapabilityMissingError | import("#contracts/renderer/contract").
|
|
49
|
+
}, ArtifactRendererComponentMissingError | ArtifactRendererDomainUnpublishedError | import("../errors.js").ContractDecodeError | import("#contracts/renderer/contract").RendererDomainCapabilityMissingError | import("#contracts/renderer/contract").RendererManifestHashMismatchError, never>;
|
|
50
50
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array as Arr, Order, Schema } from "effect";
|
|
2
2
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
3
|
-
const COMPONENT_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]
|
|
3
|
+
const COMPONENT_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/u;
|
|
4
4
|
/** Renderer names identify one current implementation, never member paths. */
|
|
5
5
|
export const RendererComponentNameSchema = Schema.String.check(Schema.isPattern(COMPONENT_NAME_PATTERN));
|
|
6
6
|
/** Checks that each current name occurs once in canonical code-unit order. */
|
|
@@ -52,14 +52,6 @@ export declare const selectRendererDomainCapability: (manifest: {
|
|
|
52
52
|
readonly components: readonly string[];
|
|
53
53
|
readonly name: "ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math";
|
|
54
54
|
}, RendererDomainCapabilityMissingError, never>;
|
|
55
|
-
declare const RendererManifestHashComputeError_base: Schema.Class<RendererManifestHashComputeError, Schema.TaggedStruct<"RendererManifestHashComputeError", {
|
|
56
|
-
readonly cause: Schema.Unknown;
|
|
57
|
-
}>, import("effect/Cause").YieldableError & {
|
|
58
|
-
readonly brand: unique symbol;
|
|
59
|
-
}>;
|
|
60
|
-
/** SHA-256 could not be calculated for the renderer contract bytes. */
|
|
61
|
-
export declare class RendererManifestHashComputeError extends RendererManifestHashComputeError_base {
|
|
62
|
-
}
|
|
63
55
|
declare const RendererManifestHashMismatchError_base: Schema.Class<RendererManifestHashMismatchError, Schema.TaggedStruct<"RendererManifestHashMismatchError", {
|
|
64
56
|
readonly actualHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
65
57
|
readonly expectedHash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
@@ -64,9 +64,6 @@ export const selectRendererDomainCapability = Effect.fn("AksaraContracts.selectR
|
|
|
64
64
|
}
|
|
65
65
|
return capability.value;
|
|
66
66
|
});
|
|
67
|
-
/** SHA-256 could not be calculated for the renderer contract bytes. */
|
|
68
|
-
export class RendererManifestHashComputeError extends Schema.TaggedError()("RendererManifestHashComputeError", { cause: Schema.Unknown }) {
|
|
69
|
-
}
|
|
70
67
|
/** The renderer envelope hash does not authenticate its canonical tuple. */
|
|
71
68
|
export class RendererManifestHashMismatchError extends Schema.TaggedError()("RendererManifestHashMismatchError", { ...Sha256MismatchFields }) {
|
|
72
69
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { RendererManifestHashMismatchError } from "#contracts/renderer/contract";
|
|
3
3
|
/** Creates a complete authenticated manifest from one current name set. */
|
|
4
4
|
export declare const createRendererManifest: (input: unknown) => Effect.Effect<{
|
|
5
5
|
readonly base: readonly string[];
|
|
@@ -10,7 +10,7 @@ export declare const createRendererManifest: (input: unknown) => Effect.Effect<{
|
|
|
10
10
|
readonly format: "nakafa-mdx-renderer";
|
|
11
11
|
readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
12
12
|
readonly publishedDomains: readonly ("ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math")[];
|
|
13
|
-
}, import("../errors.js").ContractDecodeError
|
|
13
|
+
}, import("../errors.js").ContractDecodeError, never>;
|
|
14
14
|
/** Authenticates the complete current renderer contract without normalization. */
|
|
15
15
|
export declare const validateRendererManifestHash: (input: unknown) => Effect.Effect<{
|
|
16
16
|
readonly base: readonly string[];
|
|
@@ -21,4 +21,4 @@ export declare const validateRendererManifestHash: (input: unknown) => Effect.Ef
|
|
|
21
21
|
readonly format: "nakafa-mdx-renderer";
|
|
22
22
|
readonly hash: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
23
23
|
readonly publishedDomains: readonly ("ai-ds" | "biology" | "chemistry" | "mathematics" | "physics" | "politics" | "site" | "snbt-general" | "snbt-math" | "snbt-plain" | "snbt-quant" | "tka-math")[];
|
|
24
|
-
}, import("../errors.js").ContractDecodeError |
|
|
24
|
+
}, import("../errors.js").ContractDecodeError | RendererManifestHashMismatchError, never>;
|
|
@@ -2,7 +2,7 @@ import { Array as Arr, Effect, Order, Schema } from "effect";
|
|
|
2
2
|
import { decodeContract } from "#contracts/decode";
|
|
3
3
|
import { hashText } from "#contracts/hash/text";
|
|
4
4
|
import { RendererComponentNameSchema, sortRendererComponents, } from "#contracts/renderer/component";
|
|
5
|
-
import { canonicalizeRendererManifestContract, RENDERER_MANIFEST_FORMAT, RendererManifestDomainsSchema, RendererManifestEnvelopeSchema,
|
|
5
|
+
import { canonicalizeRendererManifestContract, RENDERER_MANIFEST_FORMAT, RendererManifestDomainsSchema, RendererManifestEnvelopeSchema, RendererManifestHashMismatchError, sortRendererDomains, } from "#contracts/renderer/contract";
|
|
6
6
|
import { RendererDomainSchema } from "#contracts/renderer/domain";
|
|
7
7
|
const RendererManifestCreationSchema = Schema.Struct({
|
|
8
8
|
base: Schema.Array(RendererComponentNameSchema),
|
|
@@ -13,7 +13,7 @@ const RendererManifestCreationSchema = Schema.Struct({
|
|
|
13
13
|
publishedDomains: Schema.Array(RendererDomainSchema),
|
|
14
14
|
});
|
|
15
15
|
/** Hashes the canonical current names and their physical domain ownership. */
|
|
16
|
-
const hashRendererContract = Effect.fn("AksaraContracts.hashRendererContract")((input) => hashText(canonicalizeRendererManifestContract(input))
|
|
16
|
+
const hashRendererContract = Effect.fn("AksaraContracts.hashRendererContract")((input) => hashText(canonicalizeRendererManifestContract(input)));
|
|
17
17
|
/** Creates a complete authenticated manifest from one current name set. */
|
|
18
18
|
export const createRendererManifest = Effect.fn("AksaraContracts.createRendererManifest")(function* (input) {
|
|
19
19
|
const wire = yield* decodeContract(RendererManifestCreationSchema, "RendererManifestCreation", input);
|
package/dist/runtime/verify.d.ts
CHANGED
|
@@ -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").
|
|
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
|
*
|
|
@@ -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").
|
|
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>;
|
package/dist/signature/key.d.ts
CHANGED
|
@@ -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. */
|
package/dist/signature/key.js
CHANGED
|
@@ -1,104 +1,53 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
80
|
-
|
|
81
|
-
.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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*
|
|
102
|
-
const signature = yield*
|
|
103
|
-
|
|
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));
|