/** * @module crypto * @description Cryptographic utilities for Nostr * * IMPORTANT: Nostr Protocol Cryptographic Requirements * While secp256k1 is the underlying elliptic curve used by Nostr, the protocol specifically * requires schnorr signatures as defined in NIP-01. This means: * * 1. Always use schnorr-specific functions: * - schnorr.getPublicKey() for public key generation * - schnorr.sign() for signing * - schnorr.verify() for verification * * 2. Avoid using secp256k1 functions directly: * - DON'T use secp256k1.getPublicKey() * - DON'T use secp256k1.sign() * - DON'T use secp256k1.verify() * * While both might work in some cases (as they use the same curve), the schnorr signature * scheme has specific requirements for key and signature formats that aren't guaranteed * when using the lower-level secp256k1 functions directly. */ import { KeyPair, PublicKeyDetails, NostrEvent, SignedNostrEvent, PublicKey } from './types/index'; /** * Custom crypto interface for cross-platform compatibility */ export interface CryptoSubtle { subtle: { generateKey(algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, keyUsages: readonly KeyUsage[]): Promise; importKey(format: 'raw' | 'pkcs8' | 'spki', keyData: ArrayBuffer, algorithm: RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: readonly KeyUsage[]): Promise; encrypt(algorithm: { name: string; iv: Uint8Array; }, key: CryptoKey, data: ArrayBuffer): Promise; decrypt(algorithm: { name: string; iv: Uint8Array; }, key: CryptoKey, data: ArrayBuffer): Promise; }; getRandomValues(array: T): T; } declare global { interface Window { crypto: CryptoSubtle; } interface Global { crypto: CryptoSubtle; } } /** * Crypto implementation that works in both Node.js and browser environments */ declare class CustomCrypto { private cryptoInstance; private initPromise; constructor(); private initialize; private ensureInitialized; getSubtle(): Promise; getRandomValues(array: T): Promise; } export declare const customCrypto: CustomCrypto; export declare const signSchnorr: (message: Uint8Array, secretKey: Uint8Array, auxRand?: Uint8Array) => Uint8Array; export declare const verifySchnorrSignature: (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) => boolean; /** * Gets the compressed public key (33 bytes with prefix) */ export declare function getCompressedPublicKey(privateKeyBytes: Uint8Array): Uint8Array; /** * Gets the schnorr public key (32 bytes x-coordinate) as per BIP340 */ export declare function getSchnorrPublicKey(privateKeyBytes: Uint8Array): Uint8Array; /** * Generates a new key pair */ export declare function generateKeyPair(): Promise; /** * Gets a public key from a private key */ export declare function getPublicKey(privateKey: string): Promise; /** * Validates a key pair */ export declare function validateKeyPair(keyPair: KeyPair): Promise; /** * Creates a new event */ export declare function createEvent(event: Partial): NostrEvent; /** * Signs an event * @param event - Event to sign * @param privateKey - Private key as hex string or Uint8Array */ export declare function signEvent(event: NostrEvent, privateKey: string | Uint8Array): Promise; /** * Gets a public key hex string from a private key (synchronous) * @param privateKey - Private key as hex string or Uint8Array * @returns Hex-encoded public key (32-byte x-only schnorr key) */ export declare function getPublicKeySync(privateKey: string | Uint8Array): string; /** * Creates, hashes, and signs a Nostr event in one step * @param event - Partial event (kind, content, tags required; pubkey derived if missing) * @param privateKey - Private key as hex string or Uint8Array * @returns Fully signed event with id, pubkey, and sig */ export declare function finalizeEvent(event: Partial, privateKey: string | Uint8Array): Promise; /** * Verifies an event signature */ export declare function verifySignature(event: SignedNostrEvent): Promise; /** * Encrypts a message using NIP-04 */ export declare function encrypt(message: string, recipientPubKey: PublicKey | string, senderPrivKey: string): Promise; /** * Decrypts a message using NIP-04 */ export declare function decrypt(encryptedMessage: string, senderPubKey: PublicKey | string, recipientPrivKey: string): Promise; export {}; //# sourceMappingURL=crypto.d.ts.map