Skip to content

Commit 73c2cec

Browse files
committed
Slight crypto cleanup
1 parent 19618b9 commit 73c2cec

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

server/crypto.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { create, getNumericDate, verify } from "djwt";
22
import type { KvPrimitives } from "$lib/data/kv_primitives.ts";
3+
import type { KvKey } from "@silverbulletmd/silverbullet/types";
34

4-
const jwtSecretKey = "jwtSecretKey";
5+
const jwtSecretKey: KvKey = ["jwtSecretKey"];
56

67
export class JWTIssuer {
78
private key!: CryptoKey;
@@ -11,7 +12,7 @@ export class JWTIssuer {
1112

1213
// authString is only used to compare hashes to see if the auth has changed
1314
async init(authString: string) {
14-
const [secret] = await this.kv.batchGet([[jwtSecretKey]]);
15+
const [secret] = await this.kv.batchGet([jwtSecretKey]);
1516
if (!secret) {
1617
console.log("Generating new JWT secret key");
1718
return this.generateNewKey();
@@ -53,7 +54,7 @@ export class JWTIssuer {
5354
["sign", "verify"],
5455
);
5556
await this.kv.batchSet([{
56-
key: [jwtSecretKey],
57+
key: jwtSecretKey,
5758
value: await crypto.subtle.exportKey("jwk", this.key),
5859
}]);
5960
}

server/http_server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export class HttpServer {
145145
this.spaceServer = new SpaceServer(
146146
this.options,
147147
this.plugAssetBundle,
148-
this.baseKvPrimitives,
149148
);
150149
await this.spaceServer.init();
151150

server/space_server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { FilteredSpacePrimitives } from "../lib/spaces/filtered_space_primitives
33
import { ReadOnlySpacePrimitives } from "../lib/spaces/ro_space_primitives.ts";
44
import type { SpacePrimitives } from "../lib/spaces/space_primitives.ts";
55
import type { AssetBundle } from "../lib/asset_bundle/bundle.ts";
6-
import type { KvPrimitives } from "$lib/data/kv_primitives.ts";
76
import { JWTIssuer } from "./crypto.ts";
87
import { compile as gitIgnoreCompiler } from "gitignore-parser";
98
import { determineShellBackend, NotSupportedShell } from "./shell_backend.ts";
@@ -32,7 +31,6 @@ export class SpaceServer {
3231
constructor(
3332
options: ServerOptions,
3433
private plugAssetBundle: AssetBundle,
35-
private kvPrimitives: KvPrimitives,
3634
) {
3735
this.pagesPath = options.pagesPath;
3836
this.hostname = options.hostname;
@@ -42,7 +40,7 @@ export class SpaceServer {
4240
this.enableSpaceScript = options.enableSpaceScript;
4341
this.spaceIgnore = options.spaceIgnore;
4442

45-
this.jwtIssuer = new JWTIssuer(kvPrimitives);
43+
this.jwtIssuer = new JWTIssuer(options.baseKvPrimitives);
4644

4745
this.shellBackend = options.readOnly
4846
? new NotSupportedShell() // No shell for read only mode

0 commit comments

Comments
 (0)