💥 Breaking Changes 💥 - Ditched Bun for Deno 🦕: Migrated from Bun to Deno due to recurring memory leaks and crashes on our test server. - SQL Simplification 📈: Removed Prisma and now using Libsql alone - Hono Takes the Stage: Switched from Elysia to Hono, a cleaner and more compatible framework that plays nice with Deno. 🧹 Code Cleanup 💪 Removed unnecessary clutter and streamlined the codebase for better readability and maintainability.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import NDK from "@nostr-dev-kit/ndk";
|
|
import * as crypto from "node:crypto";
|
|
import {decodeHex} from "@std/encoding/hex";
|
|
|
|
export * from "./logs.ts";
|
|
export * from "../models.ts";
|
|
|
|
export function getNDK() {
|
|
return new NDK({
|
|
explicitRelayUrls: [
|
|
"wss://relay.primal.net",
|
|
"wss://relay.nostr.band",
|
|
"wss://offchain.pub",
|
|
],
|
|
autoConnectUserRelays: false,
|
|
enableOutboxModel: true,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Derive a nostr private key from a master private key and an email address.
|
|
*
|
|
* This is done by taking the SHA-256 hash of the email address, and then taking
|
|
* the SHA-256 hash of the master private key concatenated with the email hash.
|
|
* The resulting hash is the nostr private key.
|
|
*
|
|
* @param masterNsec - The master nostr private key.
|
|
* @param email - The email address.
|
|
* @returns The nostr private key derived from the master key and email address as a uint8array.
|
|
*/
|
|
export function deriveNsecForEmail(
|
|
masterNsec: string,
|
|
email: string,
|
|
): Uint8Array {
|
|
const masterNsecHash = crypto.createHash("sha256").update(masterNsec).digest(
|
|
"hex",
|
|
);
|
|
const emailHash = crypto.createHash("sha256").update(email).digest("hex");
|
|
const sharedSecret = crypto.createHash("sha256").update(
|
|
masterNsecHash + emailHash,
|
|
).digest("hex");
|
|
return decodeHex(sharedSecret);
|
|
}
|