@bcts/crypto 1.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["nobleSha256","nobleSha512","x25519","secp256k1","secp256k1","SecureRandomNumberGenerator","schnorr","ed25519"],"sources":["../src/error.ts","../src/memzero.ts","../src/hash.ts","../src/symmetric-encryption.ts","../src/public-key-encryption.ts","../src/ecdsa-keys.ts","../src/ecdsa-signing.ts","../src/schnorr-signing.ts","../src/ed25519-signing.ts","../src/scrypt.ts","../src/argon.ts"],"sourcesContent":["// Ported from bc-crypto-rust/src/error.rs\n\n/**\n * AEAD-specific error for authentication failures\n */\nexport class AeadError extends Error {\n constructor(message = \"AEAD authentication failed\") {\n super(message);\n this.name = \"AeadError\";\n }\n}\n\n/**\n * Generic crypto error type\n */\nexport class CryptoError extends Error {\n override readonly cause?: Error | undefined;\n\n constructor(message: string, cause?: Error) {\n super(message);\n this.name = \"CryptoError\";\n this.cause = cause;\n }\n\n /**\n * Create a CryptoError for AEAD authentication failures.\n *\n * @param error - Optional underlying AeadError\n * @returns A CryptoError wrapping the AEAD error\n */\n static aead(error?: AeadError): CryptoError {\n return new CryptoError(\"AEAD error\", error ?? new AeadError());\n }\n\n /**\n * Create a CryptoError for invalid parameter values.\n *\n * @param message - Description of the invalid parameter\n * @returns A CryptoError describing the invalid parameter\n */\n static invalidParameter(message: string): CryptoError {\n return new CryptoError(`Invalid parameter: ${message}`);\n }\n}\n\n/**\n * Result type for crypto operations (using standard Error)\n */\nexport type CryptoResult<T> = T;\n","// Ported from bc-crypto-rust/src/memzero.rs\n\n/**\n * Securely zero out a typed array.\n *\n * **IMPORTANT: This is a best-effort implementation.** Unlike the Rust reference\n * implementation which uses `std::ptr::write_volatile()` for guaranteed volatile\n * writes, JavaScript engines and JIT compilers can still potentially optimize\n * away these zeroing operations. The check at the end helps prevent optimization,\n * but it is not foolproof.\n *\n * For truly sensitive cryptographic operations, consider using the Web Crypto API's\n * `crypto.subtle` with non-extractable keys when possible, as it provides stronger\n * guarantees than what can be achieved with pure JavaScript.\n *\n * This function attempts to prevent the compiler from optimizing away\n * the zeroing operation by using a verification check after the zeroing loop.\n */\nexport function memzero(data: Uint8Array | Uint32Array): void {\n const len = data.length;\n for (let i = 0; i < len; i++) {\n data[i] = 0;\n }\n // Force a side effect to prevent optimization\n if (data.length > 0 && data[0] !== 0) {\n throw new Error(\"memzero failed\");\n }\n}\n\n/**\n * Securely zero out an array of Uint8Arrays.\n */\nexport function memzeroVecVecU8(arrays: Uint8Array[]): void {\n for (const arr of arrays) {\n memzero(arr);\n }\n}\n","// Ported from bc-crypto-rust/src/hash.rs\n\nimport { sha256 as nobleSha256, sha512 as nobleSha512 } from \"@noble/hashes/sha2\";\nimport { hmac } from \"@noble/hashes/hmac\";\nimport { pbkdf2 } from \"@noble/hashes/pbkdf2\";\nimport { hkdf } from \"@noble/hashes/hkdf\";\n\n// Constants\nexport const CRC32_SIZE = 4;\nexport const SHA256_SIZE = 32;\nexport const SHA512_SIZE = 64;\n\n// CRC-32 lookup table (IEEE polynomial 0xedb88320)\nconst CRC32_TABLE = new Uint32Array(256);\nfor (let i = 0; i < 256; i++) {\n let crc = i;\n for (let j = 0; j < 8; j++) {\n crc = (crc & 1) !== 0 ? (crc >>> 1) ^ 0xedb88320 : crc >>> 1;\n }\n CRC32_TABLE[i] = crc >>> 0;\n}\n\n/**\n * Calculate CRC-32 checksum\n */\nexport function crc32(data: Uint8Array): number {\n let crc = 0xffffffff;\n for (const byte of data) {\n crc = CRC32_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n\n/**\n * Calculate CRC-32 checksum and return as a 4-byte big-endian array\n */\nexport function crc32Data(data: Uint8Array): Uint8Array {\n return crc32DataOpt(data, false);\n}\n\n/**\n * Calculate CRC-32 checksum and return as a 4-byte array\n * @param data - Input data\n * @param littleEndian - If true, returns little-endian; otherwise big-endian\n */\nexport function crc32DataOpt(data: Uint8Array, littleEndian: boolean): Uint8Array {\n const checksum = crc32(data);\n const result = new Uint8Array(4);\n const view = new DataView(result.buffer);\n view.setUint32(0, checksum, littleEndian);\n return result;\n}\n\n/**\n * Calculate SHA-256 hash\n */\nexport function sha256(data: Uint8Array): Uint8Array {\n return nobleSha256(data);\n}\n\n/**\n * Calculate double SHA-256 hash (SHA-256 of SHA-256)\n * This is the standard Bitcoin hashing function\n */\nexport function doubleSha256(message: Uint8Array): Uint8Array {\n return sha256(sha256(message));\n}\n\n/**\n * Calculate SHA-512 hash\n */\nexport function sha512(data: Uint8Array): Uint8Array {\n return nobleSha512(data);\n}\n\n/**\n * Calculate HMAC-SHA-256\n */\nexport function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array {\n return hmac(nobleSha256, key, message);\n}\n\n/**\n * Calculate HMAC-SHA-512\n */\nexport function hmacSha512(key: Uint8Array, message: Uint8Array): Uint8Array {\n return hmac(nobleSha512, key, message);\n}\n\n/**\n * Derive a key using PBKDF2 with HMAC-SHA-256\n */\nexport function pbkdf2HmacSha256(\n password: Uint8Array,\n salt: Uint8Array,\n iterations: number,\n keyLen: number,\n): Uint8Array {\n return pbkdf2(nobleSha256, password, salt, { c: iterations, dkLen: keyLen });\n}\n\n/**\n * Derive a key using PBKDF2 with HMAC-SHA-512\n */\nexport function pbkdf2HmacSha512(\n password: Uint8Array,\n salt: Uint8Array,\n iterations: number,\n keyLen: number,\n): Uint8Array {\n return pbkdf2(nobleSha512, password, salt, { c: iterations, dkLen: keyLen });\n}\n\n/**\n * Derive a key using HKDF with HMAC-SHA-256\n */\nexport function hkdfHmacSha256(\n keyMaterial: Uint8Array,\n salt: Uint8Array,\n keyLen: number,\n): Uint8Array {\n return hkdf(nobleSha256, keyMaterial, salt, undefined, keyLen);\n}\n\n/**\n * Derive a key using HKDF with HMAC-SHA-512\n */\nexport function hkdfHmacSha512(\n keyMaterial: Uint8Array,\n salt: Uint8Array,\n keyLen: number,\n): Uint8Array {\n return hkdf(nobleSha512, keyMaterial, salt, undefined, keyLen);\n}\n","// Ported from bc-crypto-rust/src/symmetric_encryption.rs\n\nimport { chacha20poly1305 } from \"@noble/ciphers/chacha\";\nimport { CryptoError, AeadError } from \"./error.js\";\n\n// Constants\nexport const SYMMETRIC_KEY_SIZE = 32;\nexport const SYMMETRIC_NONCE_SIZE = 12;\nexport const SYMMETRIC_AUTH_SIZE = 16;\n\n/**\n * Encrypt data using ChaCha20-Poly1305 AEAD cipher.\n *\n * **Security Warning**: The nonce MUST be unique for every encryption operation\n * with the same key. Reusing a nonce completely breaks the security of the\n * encryption scheme and can reveal plaintext.\n *\n * @param plaintext - The data to encrypt\n * @param key - 32-byte encryption key\n * @param nonce - 12-byte nonce (MUST be unique per encryption with the same key)\n * @returns Tuple of [ciphertext, authTag] where authTag is 16 bytes\n * @throws {CryptoError} If key is not 32 bytes or nonce is not 12 bytes\n */\nexport function aeadChaCha20Poly1305Encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n): [Uint8Array, Uint8Array] {\n return aeadChaCha20Poly1305EncryptWithAad(plaintext, key, nonce, new Uint8Array(0));\n}\n\n/**\n * Encrypt data using ChaCha20-Poly1305 AEAD cipher with additional authenticated data.\n *\n * **Security Warning**: The nonce MUST be unique for every encryption operation\n * with the same key. Reusing a nonce completely breaks the security of the\n * encryption scheme and can reveal plaintext.\n *\n * @param plaintext - The data to encrypt\n * @param key - 32-byte encryption key\n * @param nonce - 12-byte nonce (MUST be unique per encryption with the same key)\n * @param aad - Additional authenticated data (not encrypted, but integrity-protected)\n * @returns Tuple of [ciphertext, authTag] where authTag is 16 bytes\n * @throws {CryptoError} If key is not 32 bytes or nonce is not 12 bytes\n */\nexport function aeadChaCha20Poly1305EncryptWithAad(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n aad: Uint8Array,\n): [Uint8Array, Uint8Array] {\n if (key.length !== SYMMETRIC_KEY_SIZE) {\n throw CryptoError.invalidParameter(`Key must be ${SYMMETRIC_KEY_SIZE} bytes`);\n }\n if (nonce.length !== SYMMETRIC_NONCE_SIZE) {\n throw CryptoError.invalidParameter(`Nonce must be ${SYMMETRIC_NONCE_SIZE} bytes`);\n }\n\n const cipher = chacha20poly1305(key, nonce, aad);\n const sealed = cipher.encrypt(plaintext);\n\n // The sealed output contains ciphertext + 16-byte auth tag\n const ciphertext = sealed.slice(0, sealed.length - SYMMETRIC_AUTH_SIZE);\n const authTag = sealed.slice(sealed.length - SYMMETRIC_AUTH_SIZE);\n\n return [ciphertext, authTag];\n}\n\n/**\n * Decrypt data using ChaCha20-Poly1305 AEAD cipher.\n *\n * @param ciphertext - The encrypted data\n * @param key - 32-byte encryption key (must match key used for encryption)\n * @param nonce - 12-byte nonce (must match nonce used for encryption)\n * @param authTag - 16-byte authentication tag from encryption\n * @returns Decrypted plaintext\n * @throws {CryptoError} If key/nonce/authTag sizes are invalid\n * @throws {CryptoError} If authentication fails (tampered data or wrong key/nonce)\n */\nexport function aeadChaCha20Poly1305Decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n authTag: Uint8Array,\n): Uint8Array {\n return aeadChaCha20Poly1305DecryptWithAad(ciphertext, key, nonce, new Uint8Array(0), authTag);\n}\n\n/**\n * Decrypt data using ChaCha20-Poly1305 AEAD cipher with additional authenticated data.\n *\n * @param ciphertext - The encrypted data\n * @param key - 32-byte encryption key (must match key used for encryption)\n * @param nonce - 12-byte nonce (must match nonce used for encryption)\n * @param aad - Additional authenticated data (must exactly match AAD used for encryption)\n * @param authTag - 16-byte authentication tag from encryption\n * @returns Decrypted plaintext\n * @throws {CryptoError} If key/nonce/authTag sizes are invalid\n * @throws {CryptoError} If authentication fails (tampered data, wrong key/nonce, or AAD mismatch)\n */\nexport function aeadChaCha20Poly1305DecryptWithAad(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n aad: Uint8Array,\n authTag: Uint8Array,\n): Uint8Array {\n if (key.length !== SYMMETRIC_KEY_SIZE) {\n throw CryptoError.invalidParameter(`Key must be ${SYMMETRIC_KEY_SIZE} bytes`);\n }\n if (nonce.length !== SYMMETRIC_NONCE_SIZE) {\n throw CryptoError.invalidParameter(`Nonce must be ${SYMMETRIC_NONCE_SIZE} bytes`);\n }\n if (authTag.length !== SYMMETRIC_AUTH_SIZE) {\n throw CryptoError.invalidParameter(`Auth tag must be ${SYMMETRIC_AUTH_SIZE} bytes`);\n }\n\n // Combine ciphertext and auth tag for decryption\n const sealed = new Uint8Array(ciphertext.length + authTag.length);\n sealed.set(ciphertext);\n sealed.set(authTag, ciphertext.length);\n\n try {\n const cipher = chacha20poly1305(key, nonce, aad);\n return cipher.decrypt(sealed);\n } catch (error) {\n // Preserve the original error for debugging while wrapping in our error type\n const aeadError = new AeadError(\n `Decryption failed: ${error instanceof Error ? error.message : \"authentication error\"}`,\n );\n throw CryptoError.aead(aeadError);\n }\n}\n","// Ported from bc-crypto-rust/src/public_key_encryption.rs\n\nimport { x25519 } from \"@noble/curves/ed25519\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { hkdfHmacSha256 } from \"./hash.js\";\n\n// Constants\nexport const GENERIC_PRIVATE_KEY_SIZE = 32;\nexport const GENERIC_PUBLIC_KEY_SIZE = 32;\nexport const X25519_PRIVATE_KEY_SIZE = 32;\nexport const X25519_PUBLIC_KEY_SIZE = 32;\n\n/**\n * Derive an X25519 agreement private key from key material.\n * Uses HKDF with \"agreement\" as domain separation salt.\n */\nexport function deriveAgreementPrivateKey(keyMaterial: Uint8Array): Uint8Array {\n const salt = new TextEncoder().encode(\"agreement\");\n return hkdfHmacSha256(keyMaterial, salt, X25519_PRIVATE_KEY_SIZE);\n}\n\n/**\n * Derive a signing private key from key material.\n * Uses HKDF with \"signing\" as domain separation salt.\n */\nexport function deriveSigningPrivateKey(keyMaterial: Uint8Array): Uint8Array {\n const salt = new TextEncoder().encode(\"signing\");\n return hkdfHmacSha256(keyMaterial, salt, 32);\n}\n\n/**\n * Generate a new random X25519 private key.\n */\nexport function x25519NewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array {\n return rng.randomData(X25519_PRIVATE_KEY_SIZE);\n}\n\n/**\n * Derive an X25519 public key from a private key.\n */\nexport function x25519PublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n if (privateKey.length !== X25519_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${X25519_PRIVATE_KEY_SIZE} bytes`);\n }\n return x25519.getPublicKey(privateKey);\n}\n\n/**\n * Compute a shared secret using X25519 key agreement (ECDH).\n *\n * **Security Note**: The resulting shared secret should be used with a KDF\n * (like HKDF) before using it as an encryption key. Never use the raw\n * shared secret directly for encryption.\n *\n * @param x25519Private - 32-byte X25519 private key\n * @param x25519Public - 32-byte X25519 public key from the other party\n * @returns 32-byte shared secret\n * @throws {Error} If private key is not 32 bytes or public key is not 32 bytes\n */\nexport function x25519SharedKey(x25519Private: Uint8Array, x25519Public: Uint8Array): Uint8Array {\n if (x25519Private.length !== X25519_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${X25519_PRIVATE_KEY_SIZE} bytes`);\n }\n if (x25519Public.length !== X25519_PUBLIC_KEY_SIZE) {\n throw new Error(`Public key must be ${X25519_PUBLIC_KEY_SIZE} bytes`);\n }\n return x25519.getSharedSecret(x25519Private, x25519Public);\n}\n","// Ported from bc-crypto-rust/src/ecdsa_keys.rs\n\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { hkdfHmacSha256 } from \"./hash.js\";\n\n// Constants\nexport const ECDSA_PRIVATE_KEY_SIZE = 32;\nexport const ECDSA_PUBLIC_KEY_SIZE = 33; // Compressed\nexport const ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;\nexport const ECDSA_MESSAGE_HASH_SIZE = 32;\nexport const ECDSA_SIGNATURE_SIZE = 64;\nexport const SCHNORR_PUBLIC_KEY_SIZE = 32; // x-only\n\n/**\n * Generate a new random ECDSA private key using secp256k1.\n *\n * Note: Unlike some implementations, this directly returns the random bytes\n * without validation. The secp256k1 library will handle any edge cases when\n * the key is used.\n */\nexport function ecdsaNewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array {\n return rng.randomData(ECDSA_PRIVATE_KEY_SIZE);\n}\n\n/**\n * Derive a compressed ECDSA public key from a private key.\n */\nexport function ecdsaPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n if (privateKey.length !== ECDSA_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ECDSA_PRIVATE_KEY_SIZE} bytes`);\n }\n return secp256k1.getPublicKey(privateKey, true); // true = compressed\n}\n\n/**\n * Decompress a compressed public key to uncompressed format.\n */\nexport function ecdsaDecompressPublicKey(compressed: Uint8Array): Uint8Array {\n if (compressed.length !== ECDSA_PUBLIC_KEY_SIZE) {\n throw new Error(`Compressed public key must be ${ECDSA_PUBLIC_KEY_SIZE} bytes`);\n }\n const point = secp256k1.ProjectivePoint.fromHex(compressed);\n return point.toRawBytes(false); // false = uncompressed\n}\n\n/**\n * Compress an uncompressed public key.\n */\nexport function ecdsaCompressPublicKey(uncompressed: Uint8Array): Uint8Array {\n if (uncompressed.length !== ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE) {\n throw new Error(`Uncompressed public key must be ${ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE} bytes`);\n }\n const point = secp256k1.ProjectivePoint.fromHex(uncompressed);\n return point.toRawBytes(true); // true = compressed\n}\n\n/**\n * Derive an ECDSA private key from key material using HKDF.\n *\n * Note: This directly returns the HKDF output without validation,\n * matching the Rust reference implementation behavior.\n */\nexport function ecdsaDerivePrivateKey(keyMaterial: Uint8Array): Uint8Array {\n const salt = new TextEncoder().encode(\"signing\");\n return hkdfHmacSha256(keyMaterial, salt, ECDSA_PRIVATE_KEY_SIZE);\n}\n\n/**\n * Extract the x-only (Schnorr) public key from a private key.\n * This is used for BIP-340 Schnorr signatures.\n */\nexport function schnorrPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n if (privateKey.length !== ECDSA_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ECDSA_PRIVATE_KEY_SIZE} bytes`);\n }\n // Get the full public key and extract just the x-coordinate\n const fullPubKey = secp256k1.getPublicKey(privateKey, false); // uncompressed\n // Skip the 0x04 prefix and take only x-coordinate (first 32 bytes after prefix)\n return fullPubKey.slice(1, 33);\n}\n","// Ported from bc-crypto-rust/src/ecdsa_signing.rs\n\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\nimport { doubleSha256 } from \"./hash.js\";\nimport {\n ECDSA_PRIVATE_KEY_SIZE,\n ECDSA_PUBLIC_KEY_SIZE,\n ECDSA_SIGNATURE_SIZE,\n} from \"./ecdsa-keys.js\";\n\n/**\n * Sign a message using ECDSA with secp256k1.\n *\n * The message is hashed with double SHA-256 before signing (Bitcoin standard).\n *\n * **Security Note**: The private key must be kept secret. ECDSA requires\n * cryptographically secure random nonces internally; this is handled by\n * the underlying library using RFC 6979 deterministic nonces.\n *\n * @param privateKey - 32-byte secp256k1 private key\n * @param message - Message to sign (any length, will be double-SHA256 hashed)\n * @returns 64-byte compact signature (r || s format)\n * @throws {Error} If private key is not 32 bytes\n */\nexport function ecdsaSign(privateKey: Uint8Array, message: Uint8Array): Uint8Array {\n if (privateKey.length !== ECDSA_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ECDSA_PRIVATE_KEY_SIZE} bytes`);\n }\n\n const messageHash = doubleSha256(message);\n const signature = secp256k1.sign(messageHash, privateKey);\n\n // Return compact signature (r || s)\n return signature.toCompactRawBytes();\n}\n\n/**\n * Verify an ECDSA signature with secp256k1.\n *\n * The message is hashed with double SHA-256 before verification (Bitcoin standard).\n *\n * @param publicKey - 33-byte compressed secp256k1 public key\n * @param signature - 64-byte compact signature (r || s format)\n * @param message - Original message that was signed\n * @returns `true` if signature is valid, `false` if signature verification fails\n * @throws {Error} If public key is not 33 bytes or signature is not 64 bytes\n */\nexport function ecdsaVerify(\n publicKey: Uint8Array,\n signature: Uint8Array,\n message: Uint8Array,\n): boolean {\n if (publicKey.length !== ECDSA_PUBLIC_KEY_SIZE) {\n throw new Error(`Public key must be ${ECDSA_PUBLIC_KEY_SIZE} bytes`);\n }\n if (signature.length !== ECDSA_SIGNATURE_SIZE) {\n throw new Error(`Signature must be ${ECDSA_SIGNATURE_SIZE} bytes`);\n }\n\n try {\n const messageHash = doubleSha256(message);\n return secp256k1.verify(signature, messageHash, publicKey);\n } catch {\n return false;\n }\n}\n","// Ported from bc-crypto-rust/src/schnorr_signing.rs\n\nimport { schnorr } from \"@noble/curves/secp256k1\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { ECDSA_PRIVATE_KEY_SIZE, SCHNORR_PUBLIC_KEY_SIZE } from \"./ecdsa-keys.js\";\n\n// Constants\nexport const SCHNORR_SIGNATURE_SIZE = 64;\n\n/**\n * Sign a message using Schnorr signature (BIP-340).\n * Uses secure random auxiliary randomness.\n *\n * @param ecdsaPrivateKey - 32-byte private key\n * @param message - Message to sign (not pre-hashed, per BIP-340)\n * @returns 64-byte Schnorr signature\n */\nexport function schnorrSign(ecdsaPrivateKey: Uint8Array, message: Uint8Array): Uint8Array {\n const rng = new SecureRandomNumberGenerator();\n return schnorrSignUsing(ecdsaPrivateKey, message, rng);\n}\n\n/**\n * Sign a message using Schnorr signature with a custom RNG.\n *\n * @param ecdsaPrivateKey - 32-byte private key\n * @param message - Message to sign\n * @param rng - Random number generator for auxiliary randomness\n * @returns 64-byte Schnorr signature\n */\nexport function schnorrSignUsing(\n ecdsaPrivateKey: Uint8Array,\n message: Uint8Array,\n rng: RandomNumberGenerator,\n): Uint8Array {\n const auxRand = rng.randomData(32);\n return schnorrSignWithAuxRand(ecdsaPrivateKey, message, auxRand);\n}\n\n/**\n * Sign a message using Schnorr signature with specific auxiliary randomness.\n * This is useful for deterministic signing in tests.\n *\n * @param ecdsaPrivateKey - 32-byte private key\n * @param message - Message to sign\n * @param auxRand - 32-byte auxiliary randomness (per BIP-340)\n * @returns 64-byte Schnorr signature\n */\nexport function schnorrSignWithAuxRand(\n ecdsaPrivateKey: Uint8Array,\n message: Uint8Array,\n auxRand: Uint8Array,\n): Uint8Array {\n if (ecdsaPrivateKey.length !== ECDSA_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ECDSA_PRIVATE_KEY_SIZE} bytes`);\n }\n if (auxRand.length !== 32) {\n throw new Error(\"Auxiliary randomness must be 32 bytes\");\n }\n\n return schnorr.sign(message, ecdsaPrivateKey, auxRand);\n}\n\n/**\n * Verify a Schnorr signature (BIP-340).\n *\n * @param schnorrPublicKey - 32-byte x-only public key\n * @param signature - 64-byte Schnorr signature\n * @param message - Original message\n * @returns true if signature is valid\n */\nexport function schnorrVerify(\n schnorrPublicKey: Uint8Array,\n signature: Uint8Array,\n message: Uint8Array,\n): boolean {\n if (schnorrPublicKey.length !== SCHNORR_PUBLIC_KEY_SIZE) {\n throw new Error(`Public key must be ${SCHNORR_PUBLIC_KEY_SIZE} bytes`);\n }\n if (signature.length !== SCHNORR_SIGNATURE_SIZE) {\n throw new Error(`Signature must be ${SCHNORR_SIGNATURE_SIZE} bytes`);\n }\n\n try {\n return schnorr.verify(signature, message, schnorrPublicKey);\n } catch {\n return false;\n }\n}\n","// Ported from bc-crypto-rust/src/ed25519_signing.rs\n\nimport { ed25519 } from \"@noble/curves/ed25519\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\n\n// Constants\nexport const ED25519_PUBLIC_KEY_SIZE = 32;\nexport const ED25519_PRIVATE_KEY_SIZE = 32;\nexport const ED25519_SIGNATURE_SIZE = 64;\n\n/**\n * Generate a new random Ed25519 private key.\n */\nexport function ed25519NewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array {\n return rng.randomData(ED25519_PRIVATE_KEY_SIZE);\n}\n\n/**\n * Derive an Ed25519 public key from a private key.\n */\nexport function ed25519PublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array {\n if (privateKey.length !== ED25519_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ED25519_PRIVATE_KEY_SIZE} bytes`);\n }\n return ed25519.getPublicKey(privateKey);\n}\n\n/**\n * Sign a message using Ed25519.\n *\n * **Security Note**: The private key must be kept secret. The same private key\n * can safely sign multiple messages.\n *\n * @param privateKey - 32-byte Ed25519 private key\n * @param message - Message to sign (any length)\n * @returns 64-byte Ed25519 signature\n * @throws {Error} If private key is not 32 bytes\n */\nexport function ed25519Sign(privateKey: Uint8Array, message: Uint8Array): Uint8Array {\n if (privateKey.length !== ED25519_PRIVATE_KEY_SIZE) {\n throw new Error(`Private key must be ${ED25519_PRIVATE_KEY_SIZE} bytes`);\n }\n return ed25519.sign(message, privateKey);\n}\n\n/**\n * Verify an Ed25519 signature.\n *\n * @param publicKey - 32-byte Ed25519 public key\n * @param message - Original message that was signed\n * @param signature - 64-byte Ed25519 signature\n * @returns `true` if signature is valid, `false` if signature verification fails\n * @throws {Error} If public key is not 32 bytes or signature is not 64 bytes\n */\nexport function ed25519Verify(\n publicKey: Uint8Array,\n message: Uint8Array,\n signature: Uint8Array,\n): boolean {\n if (publicKey.length !== ED25519_PUBLIC_KEY_SIZE) {\n throw new Error(`Public key must be ${ED25519_PUBLIC_KEY_SIZE} bytes`);\n }\n if (signature.length !== ED25519_SIGNATURE_SIZE) {\n throw new Error(`Signature must be ${ED25519_SIGNATURE_SIZE} bytes`);\n }\n\n try {\n return ed25519.verify(signature, message, publicKey);\n } catch {\n return false;\n }\n}\n","// Ported from bc-crypto-rust/src/scrypt.rs\n\nimport { scrypt as nobleScrypt } from \"@noble/hashes/scrypt\";\n\n/**\n * Derive a key using Scrypt with recommended parameters.\n * Uses N=2^15 (32768), r=8, p=1 as recommended defaults.\n *\n * @param password - Password or passphrase\n * @param salt - Salt value\n * @param outputLen - Desired output length\n * @returns Derived key\n */\nexport function scrypt(password: Uint8Array, salt: Uint8Array, outputLen: number): Uint8Array {\n return scryptOpt(password, salt, outputLen, 15, 8, 1);\n}\n\n/**\n * Derive a key using Scrypt with custom parameters.\n *\n * @param password - Password or passphrase\n * @param salt - Salt value\n * @param outputLen - Desired output length\n * @param logN - Log2 of the CPU/memory cost parameter N (must be <64)\n * @param r - Block size parameter (must be >0)\n * @param p - Parallelization parameter (must be >0)\n * @returns Derived key\n */\nexport function scryptOpt(\n password: Uint8Array,\n salt: Uint8Array,\n outputLen: number,\n logN: number,\n r: number,\n p: number,\n): Uint8Array {\n if (logN >= 64) {\n throw new Error(\"logN must be <64\");\n }\n if (r === 0) {\n throw new Error(\"r must be >0\");\n }\n if (p === 0) {\n throw new Error(\"p must be >0\");\n }\n\n const N = 1 << logN; // 2^logN\n\n return nobleScrypt(password, salt, { N, r, p, dkLen: outputLen });\n}\n","// Ported from bc-crypto-rust/src/argon.rs\n\nimport { argon2id } from \"@noble/hashes/argon2\";\n\n/**\n * Derive a key using Argon2id with default parameters.\n *\n * @param password - Password or passphrase\n * @param salt - Salt value (must be at least 8 bytes)\n * @param outputLen - Desired output length\n * @returns Derived key\n */\nexport function argon2idHash(\n password: Uint8Array,\n salt: Uint8Array,\n outputLen: number,\n): Uint8Array {\n // Use default parameters similar to the Rust implementation\n return argon2idHashOpt(password, salt, outputLen, 3, 65536, 4);\n}\n\n/**\n * Derive a key using Argon2id with custom parameters.\n *\n * @param password - Password or passphrase\n * @param salt - Salt value (must be at least 8 bytes)\n * @param outputLen - Desired output length\n * @param iterations - Number of iterations (t)\n * @param memory - Memory in KiB (m)\n * @param parallelism - Degree of parallelism (p)\n * @returns Derived key\n */\nexport function argon2idHashOpt(\n password: Uint8Array,\n salt: Uint8Array,\n outputLen: number,\n iterations: number,\n memory: number,\n parallelism: number,\n): Uint8Array {\n return argon2id(password, salt, {\n t: iterations,\n m: memory,\n p: parall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eAAe;AAEjC,KAAI,MAAM,EACR,OAAM,IAAI,MAAM,eAAe;AAKjC,0CAAmB,UAAU,MAAM;EAAE,GAF3B,KAAK;EAEyB;EAAG;EAAG,OAAO;EAAW,CAAC;;;;;;;;;;;;;ACpCnE,SAAgB,aACd,UACA,MACA,WACY;AAEZ,QAAO,gBAAgB,UAAU,MAAM,WAAW,GAAG,OAAO,EAAE;;;;;;;;;;;;;AAchE,SAAgB,gBACd,UACA,MACA,WACA,YACA,QACA,aACY;AACZ,4CAAgB,UAAU,MAAM;EAC9B,GAAG;EACH,GAAG;EACH,GAAG;EACH,OAAO;EACR,CAAC"}
@@ -0,0 +1,403 @@
1
+ import { RandomNumberGenerator } from "@bcts/rand";
2
+
3
+ //#region src/error.d.ts
4
+ /**
5
+ * AEAD-specific error for authentication failures
6
+ */
7
+ declare class AeadError extends Error {
8
+ constructor(message?: string);
9
+ }
10
+ /**
11
+ * Generic crypto error type
12
+ */
13
+ declare class CryptoError extends Error {
14
+ readonly cause?: Error | undefined;
15
+ constructor(message: string, cause?: Error);
16
+ /**
17
+ * Create a CryptoError for AEAD authentication failures.
18
+ *
19
+ * @param error - Optional underlying AeadError
20
+ * @returns A CryptoError wrapping the AEAD error
21
+ */
22
+ static aead(error?: AeadError): CryptoError;
23
+ /**
24
+ * Create a CryptoError for invalid parameter values.
25
+ *
26
+ * @param message - Description of the invalid parameter
27
+ * @returns A CryptoError describing the invalid parameter
28
+ */
29
+ static invalidParameter(message: string): CryptoError;
30
+ }
31
+ /**
32
+ * Result type for crypto operations (using standard Error)
33
+ */
34
+ type CryptoResult<T> = T;
35
+ //#endregion
36
+ //#region src/memzero.d.ts
37
+ /**
38
+ * Securely zero out a typed array.
39
+ *
40
+ * **IMPORTANT: This is a best-effort implementation.** Unlike the Rust reference
41
+ * implementation which uses `std::ptr::write_volatile()` for guaranteed volatile
42
+ * writes, JavaScript engines and JIT compilers can still potentially optimize
43
+ * away these zeroing operations. The check at the end helps prevent optimization,
44
+ * but it is not foolproof.
45
+ *
46
+ * For truly sensitive cryptographic operations, consider using the Web Crypto API's
47
+ * `crypto.subtle` with non-extractable keys when possible, as it provides stronger
48
+ * guarantees than what can be achieved with pure JavaScript.
49
+ *
50
+ * This function attempts to prevent the compiler from optimizing away
51
+ * the zeroing operation by using a verification check after the zeroing loop.
52
+ */
53
+ declare function memzero(data: Uint8Array | Uint32Array): void;
54
+ /**
55
+ * Securely zero out an array of Uint8Arrays.
56
+ */
57
+ declare function memzeroVecVecU8(arrays: Uint8Array[]): void;
58
+ //#endregion
59
+ //#region src/hash.d.ts
60
+ declare const CRC32_SIZE = 4;
61
+ declare const SHA256_SIZE = 32;
62
+ declare const SHA512_SIZE = 64;
63
+ /**
64
+ * Calculate CRC-32 checksum
65
+ */
66
+ declare function crc32(data: Uint8Array): number;
67
+ /**
68
+ * Calculate CRC-32 checksum and return as a 4-byte big-endian array
69
+ */
70
+ declare function crc32Data(data: Uint8Array): Uint8Array;
71
+ /**
72
+ * Calculate CRC-32 checksum and return as a 4-byte array
73
+ * @param data - Input data
74
+ * @param littleEndian - If true, returns little-endian; otherwise big-endian
75
+ */
76
+ declare function crc32DataOpt(data: Uint8Array, littleEndian: boolean): Uint8Array;
77
+ /**
78
+ * Calculate SHA-256 hash
79
+ */
80
+ declare function sha256(data: Uint8Array): Uint8Array;
81
+ /**
82
+ * Calculate double SHA-256 hash (SHA-256 of SHA-256)
83
+ * This is the standard Bitcoin hashing function
84
+ */
85
+ declare function doubleSha256(message: Uint8Array): Uint8Array;
86
+ /**
87
+ * Calculate SHA-512 hash
88
+ */
89
+ declare function sha512(data: Uint8Array): Uint8Array;
90
+ /**
91
+ * Calculate HMAC-SHA-256
92
+ */
93
+ declare function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
94
+ /**
95
+ * Calculate HMAC-SHA-512
96
+ */
97
+ declare function hmacSha512(key: Uint8Array, message: Uint8Array): Uint8Array;
98
+ /**
99
+ * Derive a key using PBKDF2 with HMAC-SHA-256
100
+ */
101
+ declare function pbkdf2HmacSha256(password: Uint8Array, salt: Uint8Array, iterations: number, keyLen: number): Uint8Array;
102
+ /**
103
+ * Derive a key using PBKDF2 with HMAC-SHA-512
104
+ */
105
+ declare function pbkdf2HmacSha512(password: Uint8Array, salt: Uint8Array, iterations: number, keyLen: number): Uint8Array;
106
+ /**
107
+ * Derive a key using HKDF with HMAC-SHA-256
108
+ */
109
+ declare function hkdfHmacSha256(keyMaterial: Uint8Array, salt: Uint8Array, keyLen: number): Uint8Array;
110
+ /**
111
+ * Derive a key using HKDF with HMAC-SHA-512
112
+ */
113
+ declare function hkdfHmacSha512(keyMaterial: Uint8Array, salt: Uint8Array, keyLen: number): Uint8Array;
114
+ //#endregion
115
+ //#region src/symmetric-encryption.d.ts
116
+ declare const SYMMETRIC_KEY_SIZE = 32;
117
+ declare const SYMMETRIC_NONCE_SIZE = 12;
118
+ declare const SYMMETRIC_AUTH_SIZE = 16;
119
+ /**
120
+ * Encrypt data using ChaCha20-Poly1305 AEAD cipher.
121
+ *
122
+ * **Security Warning**: The nonce MUST be unique for every encryption operation
123
+ * with the same key. Reusing a nonce completely breaks the security of the
124
+ * encryption scheme and can reveal plaintext.
125
+ *
126
+ * @param plaintext - The data to encrypt
127
+ * @param key - 32-byte encryption key
128
+ * @param nonce - 12-byte nonce (MUST be unique per encryption with the same key)
129
+ * @returns Tuple of [ciphertext, authTag] where authTag is 16 bytes
130
+ * @throws {CryptoError} If key is not 32 bytes or nonce is not 12 bytes
131
+ */
132
+ declare function aeadChaCha20Poly1305Encrypt(plaintext: Uint8Array, key: Uint8Array, nonce: Uint8Array): [Uint8Array, Uint8Array];
133
+ /**
134
+ * Encrypt data using ChaCha20-Poly1305 AEAD cipher with additional authenticated data.
135
+ *
136
+ * **Security Warning**: The nonce MUST be unique for every encryption operation
137
+ * with the same key. Reusing a nonce completely breaks the security of the
138
+ * encryption scheme and can reveal plaintext.
139
+ *
140
+ * @param plaintext - The data to encrypt
141
+ * @param key - 32-byte encryption key
142
+ * @param nonce - 12-byte nonce (MUST be unique per encryption with the same key)
143
+ * @param aad - Additional authenticated data (not encrypted, but integrity-protected)
144
+ * @returns Tuple of [ciphertext, authTag] where authTag is 16 bytes
145
+ * @throws {CryptoError} If key is not 32 bytes or nonce is not 12 bytes
146
+ */
147
+ declare function aeadChaCha20Poly1305EncryptWithAad(plaintext: Uint8Array, key: Uint8Array, nonce: Uint8Array, aad: Uint8Array): [Uint8Array, Uint8Array];
148
+ /**
149
+ * Decrypt data using ChaCha20-Poly1305 AEAD cipher.
150
+ *
151
+ * @param ciphertext - The encrypted data
152
+ * @param key - 32-byte encryption key (must match key used for encryption)
153
+ * @param nonce - 12-byte nonce (must match nonce used for encryption)
154
+ * @param authTag - 16-byte authentication tag from encryption
155
+ * @returns Decrypted plaintext
156
+ * @throws {CryptoError} If key/nonce/authTag sizes are invalid
157
+ * @throws {CryptoError} If authentication fails (tampered data or wrong key/nonce)
158
+ */
159
+ declare function aeadChaCha20Poly1305Decrypt(ciphertext: Uint8Array, key: Uint8Array, nonce: Uint8Array, authTag: Uint8Array): Uint8Array;
160
+ /**
161
+ * Decrypt data using ChaCha20-Poly1305 AEAD cipher with additional authenticated data.
162
+ *
163
+ * @param ciphertext - The encrypted data
164
+ * @param key - 32-byte encryption key (must match key used for encryption)
165
+ * @param nonce - 12-byte nonce (must match nonce used for encryption)
166
+ * @param aad - Additional authenticated data (must exactly match AAD used for encryption)
167
+ * @param authTag - 16-byte authentication tag from encryption
168
+ * @returns Decrypted plaintext
169
+ * @throws {CryptoError} If key/nonce/authTag sizes are invalid
170
+ * @throws {CryptoError} If authentication fails (tampered data, wrong key/nonce, or AAD mismatch)
171
+ */
172
+ declare function aeadChaCha20Poly1305DecryptWithAad(ciphertext: Uint8Array, key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, authTag: Uint8Array): Uint8Array;
173
+ //#endregion
174
+ //#region src/public-key-encryption.d.ts
175
+ declare const GENERIC_PRIVATE_KEY_SIZE = 32;
176
+ declare const GENERIC_PUBLIC_KEY_SIZE = 32;
177
+ declare const X25519_PRIVATE_KEY_SIZE = 32;
178
+ declare const X25519_PUBLIC_KEY_SIZE = 32;
179
+ /**
180
+ * Derive an X25519 agreement private key from key material.
181
+ * Uses HKDF with "agreement" as domain separation salt.
182
+ */
183
+ declare function deriveAgreementPrivateKey(keyMaterial: Uint8Array): Uint8Array;
184
+ /**
185
+ * Derive a signing private key from key material.
186
+ * Uses HKDF with "signing" as domain separation salt.
187
+ */
188
+ declare function deriveSigningPrivateKey(keyMaterial: Uint8Array): Uint8Array;
189
+ /**
190
+ * Generate a new random X25519 private key.
191
+ */
192
+ declare function x25519NewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array;
193
+ /**
194
+ * Derive an X25519 public key from a private key.
195
+ */
196
+ declare function x25519PublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
197
+ /**
198
+ * Compute a shared secret using X25519 key agreement (ECDH).
199
+ *
200
+ * **Security Note**: The resulting shared secret should be used with a KDF
201
+ * (like HKDF) before using it as an encryption key. Never use the raw
202
+ * shared secret directly for encryption.
203
+ *
204
+ * @param x25519Private - 32-byte X25519 private key
205
+ * @param x25519Public - 32-byte X25519 public key from the other party
206
+ * @returns 32-byte shared secret
207
+ * @throws {Error} If private key is not 32 bytes or public key is not 32 bytes
208
+ */
209
+ declare function x25519SharedKey(x25519Private: Uint8Array, x25519Public: Uint8Array): Uint8Array;
210
+ //#endregion
211
+ //#region src/ecdsa-keys.d.ts
212
+ declare const ECDSA_PRIVATE_KEY_SIZE = 32;
213
+ declare const ECDSA_PUBLIC_KEY_SIZE = 33;
214
+ declare const ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;
215
+ declare const ECDSA_MESSAGE_HASH_SIZE = 32;
216
+ declare const ECDSA_SIGNATURE_SIZE = 64;
217
+ declare const SCHNORR_PUBLIC_KEY_SIZE = 32;
218
+ /**
219
+ * Generate a new random ECDSA private key using secp256k1.
220
+ *
221
+ * Note: Unlike some implementations, this directly returns the random bytes
222
+ * without validation. The secp256k1 library will handle any edge cases when
223
+ * the key is used.
224
+ */
225
+ declare function ecdsaNewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array;
226
+ /**
227
+ * Derive a compressed ECDSA public key from a private key.
228
+ */
229
+ declare function ecdsaPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
230
+ /**
231
+ * Decompress a compressed public key to uncompressed format.
232
+ */
233
+ declare function ecdsaDecompressPublicKey(compressed: Uint8Array): Uint8Array;
234
+ /**
235
+ * Compress an uncompressed public key.
236
+ */
237
+ declare function ecdsaCompressPublicKey(uncompressed: Uint8Array): Uint8Array;
238
+ /**
239
+ * Derive an ECDSA private key from key material using HKDF.
240
+ *
241
+ * Note: This directly returns the HKDF output without validation,
242
+ * matching the Rust reference implementation behavior.
243
+ */
244
+ declare function ecdsaDerivePrivateKey(keyMaterial: Uint8Array): Uint8Array;
245
+ /**
246
+ * Extract the x-only (Schnorr) public key from a private key.
247
+ * This is used for BIP-340 Schnorr signatures.
248
+ */
249
+ declare function schnorrPublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
250
+ //#endregion
251
+ //#region src/ecdsa-signing.d.ts
252
+ /**
253
+ * Sign a message using ECDSA with secp256k1.
254
+ *
255
+ * The message is hashed with double SHA-256 before signing (Bitcoin standard).
256
+ *
257
+ * **Security Note**: The private key must be kept secret. ECDSA requires
258
+ * cryptographically secure random nonces internally; this is handled by
259
+ * the underlying library using RFC 6979 deterministic nonces.
260
+ *
261
+ * @param privateKey - 32-byte secp256k1 private key
262
+ * @param message - Message to sign (any length, will be double-SHA256 hashed)
263
+ * @returns 64-byte compact signature (r || s format)
264
+ * @throws {Error} If private key is not 32 bytes
265
+ */
266
+ declare function ecdsaSign(privateKey: Uint8Array, message: Uint8Array): Uint8Array;
267
+ /**
268
+ * Verify an ECDSA signature with secp256k1.
269
+ *
270
+ * The message is hashed with double SHA-256 before verification (Bitcoin standard).
271
+ *
272
+ * @param publicKey - 33-byte compressed secp256k1 public key
273
+ * @param signature - 64-byte compact signature (r || s format)
274
+ * @param message - Original message that was signed
275
+ * @returns `true` if signature is valid, `false` if signature verification fails
276
+ * @throws {Error} If public key is not 33 bytes or signature is not 64 bytes
277
+ */
278
+ declare function ecdsaVerify(publicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;
279
+ //#endregion
280
+ //#region src/schnorr-signing.d.ts
281
+ declare const SCHNORR_SIGNATURE_SIZE = 64;
282
+ /**
283
+ * Sign a message using Schnorr signature (BIP-340).
284
+ * Uses secure random auxiliary randomness.
285
+ *
286
+ * @param ecdsaPrivateKey - 32-byte private key
287
+ * @param message - Message to sign (not pre-hashed, per BIP-340)
288
+ * @returns 64-byte Schnorr signature
289
+ */
290
+ declare function schnorrSign(ecdsaPrivateKey: Uint8Array, message: Uint8Array): Uint8Array;
291
+ /**
292
+ * Sign a message using Schnorr signature with a custom RNG.
293
+ *
294
+ * @param ecdsaPrivateKey - 32-byte private key
295
+ * @param message - Message to sign
296
+ * @param rng - Random number generator for auxiliary randomness
297
+ * @returns 64-byte Schnorr signature
298
+ */
299
+ declare function schnorrSignUsing(ecdsaPrivateKey: Uint8Array, message: Uint8Array, rng: RandomNumberGenerator): Uint8Array;
300
+ /**
301
+ * Sign a message using Schnorr signature with specific auxiliary randomness.
302
+ * This is useful for deterministic signing in tests.
303
+ *
304
+ * @param ecdsaPrivateKey - 32-byte private key
305
+ * @param message - Message to sign
306
+ * @param auxRand - 32-byte auxiliary randomness (per BIP-340)
307
+ * @returns 64-byte Schnorr signature
308
+ */
309
+ declare function schnorrSignWithAuxRand(ecdsaPrivateKey: Uint8Array, message: Uint8Array, auxRand: Uint8Array): Uint8Array;
310
+ /**
311
+ * Verify a Schnorr signature (BIP-340).
312
+ *
313
+ * @param schnorrPublicKey - 32-byte x-only public key
314
+ * @param signature - 64-byte Schnorr signature
315
+ * @param message - Original message
316
+ * @returns true if signature is valid
317
+ */
318
+ declare function schnorrVerify(schnorrPublicKey: Uint8Array, signature: Uint8Array, message: Uint8Array): boolean;
319
+ //#endregion
320
+ //#region src/ed25519-signing.d.ts
321
+ declare const ED25519_PUBLIC_KEY_SIZE = 32;
322
+ declare const ED25519_PRIVATE_KEY_SIZE = 32;
323
+ declare const ED25519_SIGNATURE_SIZE = 64;
324
+ /**
325
+ * Generate a new random Ed25519 private key.
326
+ */
327
+ declare function ed25519NewPrivateKeyUsing(rng: RandomNumberGenerator): Uint8Array;
328
+ /**
329
+ * Derive an Ed25519 public key from a private key.
330
+ */
331
+ declare function ed25519PublicKeyFromPrivateKey(privateKey: Uint8Array): Uint8Array;
332
+ /**
333
+ * Sign a message using Ed25519.
334
+ *
335
+ * **Security Note**: The private key must be kept secret. The same private key
336
+ * can safely sign multiple messages.
337
+ *
338
+ * @param privateKey - 32-byte Ed25519 private key
339
+ * @param message - Message to sign (any length)
340
+ * @returns 64-byte Ed25519 signature
341
+ * @throws {Error} If private key is not 32 bytes
342
+ */
343
+ declare function ed25519Sign(privateKey: Uint8Array, message: Uint8Array): Uint8Array;
344
+ /**
345
+ * Verify an Ed25519 signature.
346
+ *
347
+ * @param publicKey - 32-byte Ed25519 public key
348
+ * @param message - Original message that was signed
349
+ * @param signature - 64-byte Ed25519 signature
350
+ * @returns `true` if signature is valid, `false` if signature verification fails
351
+ * @throws {Error} If public key is not 32 bytes or signature is not 64 bytes
352
+ */
353
+ declare function ed25519Verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
354
+ //#endregion
355
+ //#region src/scrypt.d.ts
356
+ /**
357
+ * Derive a key using Scrypt with recommended parameters.
358
+ * Uses N=2^15 (32768), r=8, p=1 as recommended defaults.
359
+ *
360
+ * @param password - Password or passphrase
361
+ * @param salt - Salt value
362
+ * @param outputLen - Desired output length
363
+ * @returns Derived key
364
+ */
365
+ declare function scrypt(password: Uint8Array, salt: Uint8Array, outputLen: number): Uint8Array;
366
+ /**
367
+ * Derive a key using Scrypt with custom parameters.
368
+ *
369
+ * @param password - Password or passphrase
370
+ * @param salt - Salt value
371
+ * @param outputLen - Desired output length
372
+ * @param logN - Log2 of the CPU/memory cost parameter N (must be <64)
373
+ * @param r - Block size parameter (must be >0)
374
+ * @param p - Parallelization parameter (must be >0)
375
+ * @returns Derived key
376
+ */
377
+ declare function scryptOpt(password: Uint8Array, salt: Uint8Array, outputLen: number, logN: number, r: number, p: number): Uint8Array;
378
+ //#endregion
379
+ //#region src/argon.d.ts
380
+ /**
381
+ * Derive a key using Argon2id with default parameters.
382
+ *
383
+ * @param password - Password or passphrase
384
+ * @param salt - Salt value (must be at least 8 bytes)
385
+ * @param outputLen - Desired output length
386
+ * @returns Derived key
387
+ */
388
+ declare function argon2idHash(password: Uint8Array, salt: Uint8Array, outputLen: number): Uint8Array;
389
+ /**
390
+ * Derive a key using Argon2id with custom parameters.
391
+ *
392
+ * @param password - Password or passphrase
393
+ * @param salt - Salt value (must be at least 8 bytes)
394
+ * @param outputLen - Desired output length
395
+ * @param iterations - Number of iterations (t)
396
+ * @param memory - Memory in KiB (m)
397
+ * @param parallelism - Degree of parallelism (p)
398
+ * @returns Derived key
399
+ */
400
+ declare function argon2idHashOpt(password: Uint8Array, salt: Uint8Array, outputLen: number, iterations: number, memory: number, parallelism: number): Uint8Array;
401
+ //#endregion
402
+ export { AeadError, CRC32_SIZE, CryptoError, type CryptoResult, ECDSA_MESSAGE_HASH_SIZE, ECDSA_PRIVATE_KEY_SIZE, ECDSA_PUBLIC_KEY_SIZE, ECDSA_SIGNATURE_SIZE, ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE, ED25519_PRIVATE_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, GENERIC_PRIVATE_KEY_SIZE, GENERIC_PUBLIC_KEY_SIZE, SCHNORR_PUBLIC_KEY_SIZE, SCHNORR_SIGNATURE_SIZE, SHA256_SIZE, SHA512_SIZE, SYMMETRIC_AUTH_SIZE, SYMMETRIC_KEY_SIZE, SYMMETRIC_NONCE_SIZE, X25519_PRIVATE_KEY_SIZE, X25519_PUBLIC_KEY_SIZE, aeadChaCha20Poly1305Decrypt, aeadChaCha20Poly1305DecryptWithAad, aeadChaCha20Poly1305Encrypt, aeadChaCha20Poly1305EncryptWithAad, argon2idHash, argon2idHashOpt, crc32, crc32Data, crc32DataOpt, deriveAgreementPrivateKey, deriveSigningPrivateKey, doubleSha256, ecdsaCompressPublicKey, ecdsaDecompressPublicKey, ecdsaDerivePrivateKey, ecdsaNewPrivateKeyUsing, ecdsaPublicKeyFromPrivateKey, ecdsaSign, ecdsaVerify, ed25519NewPrivateKeyUsing, ed25519PublicKeyFromPrivateKey, ed25519Sign, ed25519Verify, hkdfHmacSha256, hkdfHmacSha512, hmacSha256, hmacSha512, memzero, memzeroVecVecU8, pbkdf2HmacSha256, pbkdf2HmacSha512, schnorrPublicKeyFromPrivateKey, schnorrSign, schnorrSignUsing, schnorrSignWithAuxRand, schnorrVerify, scrypt, scryptOpt, sha256, sha512, x25519NewPrivateKeyUsing, x25519PublicKeyFromPrivateKey, x25519SharedKey };
403
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/error.ts","../src/memzero.ts","../src/hash.ts","../src/symmetric-encryption.ts","../src/public-key-encryption.ts","../src/ecdsa-keys.ts","../src/ecdsa-signing.ts","../src/schnorr-signing.ts","../src/ed25519-signing.ts","../src/scrypt.ts","../src/argon.ts"],"sourcesContent":[],"mappings":";;;;;;AAKa,cAAA,SAAA,SAAkB,KAAA,CAAK;EAUvB,WAAA,CAAA,OAAY,CAAA,EAAA,MAAA;;;;;AAyBmB,cAzB/B,WAAA,SAAoB,KAAA,CAyBW;EAzBX,SAAA,KAAA,CAAA,EACL,KADK,GAAA,SAAA;EAAK,WAAA,CAAA,OAAA,EAAA,MAAA,EAAA,KAAA,CAAA,EAGC,KAHD;EAiC1B;;;;AC9BZ;AAcA;sBDFsB,YAAY;;;A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