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); }