mirror of
https://github.com/open-reception/appointment-booking-software.git
synced 2026-08-31 20:29:44 +02:00
36 lines
892 B
TypeScript
36 lines
892 B
TypeScript
import { createHash } from "node:crypto";
|
|
|
|
export const NEW_CLIENT_BOOTSTRAP_DIFFICULTY = 4;
|
|
|
|
export function createBootstrapBinding(input: {
|
|
tenantId: string;
|
|
tunnelId: string;
|
|
clientPublicKey: string;
|
|
emailHash?: string;
|
|
}): string {
|
|
return createHash("sha256")
|
|
.update(
|
|
[input.tenantId, input.tunnelId, input.clientPublicKey, input.emailHash ?? ""].join(":"),
|
|
"utf8",
|
|
)
|
|
.digest("hex");
|
|
}
|
|
|
|
export function createBootstrapPowDigest(input: {
|
|
nonce: string;
|
|
tunnelId: string;
|
|
clientPublicKey: string;
|
|
counter: number;
|
|
}): string {
|
|
return createHash("sha256")
|
|
.update(
|
|
[input.nonce, input.tunnelId, input.clientPublicKey, input.counter.toString()].join(":"),
|
|
"utf8",
|
|
)
|
|
.digest("hex");
|
|
}
|
|
|
|
export function matchesPowDifficulty(digest: string, difficulty: number): boolean {
|
|
return digest.startsWith("0".repeat(difficulty));
|
|
}
|