decentralised message store

feat: allow setting service did

serenity 1bf370e9 d26f15c6

Changed files
+33 -1
src
lib
+9 -1
.example.env
···
# optional, for at-rest encryption of the contents of your shard. if omitted, no encryption at rest is performed.
ENC_PASSPHRASE=
-
# port for the shard server to run on. defaults to 7337.
+
# port for the shard server to run on.
+
# defaults to 7337.
SERVER_PORT="7337"
+
+
# optional, used for verifying inter-service jwts
+
# you may specify a did at which this shard may be found. may also include a service identifier.
+
# for more information on the service identifier, you may see https://atproto.com/specs/xrpc#inter-service-authentication-jwt
+
# usually a did:web, but if you're crazy you can put a did:plc, the verifier supports either anyway.
+
# defaults to did:web:localhost
+
SERVICE_DID="did:web:localhost"
+16
src/lib/env.ts
···
+
import { didSchema } from "@/lib/types/atproto";
import "dotenv/config";
+
import { z } from "zod";
const dbUrl = process.env.DB_URL;
if (!dbUrl)
···
"Environment variable SERVER_PORT not set. Defaulting to 7337",
);
export const SERVER_PORT = Number.parseInt(serverPort ?? "7337");
+
+
const serviceDid = process.env.SERVICE_DID;
+
const {
+
success: serviceDidSuccess,
+
error: serviceDidError,
+
data: serviceDidValidated,
+
} = didSchema.safeParse(serviceDid);
+
if (!serviceDidSuccess) {
+
console.warn(serviceDidError);
+
console.warn(
+
"Environment variable SERVICE_DID not set. Defaulting to `did:web:localhost`",
+
);
+
}
+
export const SERVICE_DID = serviceDidValidated ?? "did:web:localhost";
+8
src/lib/types/atproto.ts
···
export const didWebSchema = z.templateLiteral(["did:web:", z.string()]);
export type DidWeb = z.infer<typeof didWebSchema>;
+
export const didSchema = z.templateLiteral([
+
"did:",
+
z.string(),
+
":",
+
z.string(),
+
]);
+
export type Did = z.infer<typeof didSchema>;
+
export const nsidSchema = z
.string()
.regex(