/// import type { PublicKey, PrivateKey, KeyPair, PublicKeyX, PrivateKeyX, KeyPairX, Signature, JWK, JWKEncrypted } from '../types.js'; import type { NodeId } from '../../ids/types.js'; /** * Use this to make a key pair if you only have public key and private key * The returned secret key is guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function makeKeyPair(publicKey: PublicKey, privateKey: PrivateKey): KeyPair; declare function publicKeyFromData(data: BufferSource): PublicKey | undefined; declare function privateKeyFromData(data: BufferSource): PrivateKey | undefined; /** * Copies PublicKey to NodeId. * This copies to prevent mutations like * `bufferUnlock` from affecting the output. */ declare function publicKeyToNodeId(publicKey: PublicKey): NodeId; /** * Copies NodeId to PublicKey * This copies to prevent mutations like * `bufferUnlock` from affecting the input. */ declare function publicKeyFromNodeId(nodeId: NodeId): PublicKey; /** * Extracts Ed25519 Public Key from Ed25519 Private Key * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function publicKeyFromPrivateKeyEd25519(privateKey: PrivateKey): PublicKey; /** * Extracts X25519 Public Key from X25519 Private Key * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function publicKeyFromPrivateKeyX25519(privateKey: PrivateKeyX): PublicKeyX; /** * Maps Ed25519 public key to X25519 public key * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function publicKeyEd25519ToX25519(publicKey: PublicKey): PublicKeyX; /** * Maps Ed25519 private key to X25519 private key * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function privateKeyEd25519ToX25519(privateKey: PrivateKey): PrivateKeyX; /** * Maps Ed25519 keypair to X25519 keypair * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function keyPairEd25519ToX25519(keyPair: KeyPair): KeyPairX; /** * Asymmetric public key encryption also known as ECIES. * The sender key pair will be randomly generated if not supplied. * If it is randomly generated, then we are using an ephemeral sender. * * Using a static sender key pair means there is no forward secrecy. * If the private key of the sender or receiver is compromised, all messages * are compromised. * * Using an ephemeral sender key pair provides 1-way forward secrecy. * Only if the private key of the receiver is compromised, all messages * are compromised. * * Using both ephemeral sender and receiver maintains forward secrecy. * However this requires live negotiation between the sender and receiver. * * This supports: * - ECDH-ES - ephemeral sender, static receiver * - ECDH-SS - static sender, static receiver * * The static receiver could be ephemeral, but that depends on where you get * the sender key pair. * * More information: https://crypto.stackexchange.com/a/61760/102416 * * Under ECDH-SS, the result will have the following format: * `iv<24> || mac<16> || cipherText` * Note that the sender public key is not attached in the result. * You can do that if you want to. * * Under ECDH-ES, the result will have the following format: * `publicKeyX<32> || mac<16> || cipherText` * Where `publicKeyX` is the X25519 public key. * * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function encryptWithPublicKey(receiverPublicKey: PublicKey, plainText: Buffer, senderKeyPair?: KeyPair): Buffer; /** * Asymmetric public key decryption also known as ECIES. * * Under ECDH-SS, the cipher text should have the following format: * `iv<24> || cipherText || mac<16>` * * Under ECDH-ES and ECDH-EE, the cipher text should have the following format: * `publicKey<32> || cihperText || mac<16>` * * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function decryptWithPrivateKey(receiverKeyPair: KeyPair, cipherText: Buffer, senderPublicKey?: PublicKey): Buffer | undefined; /** * Sign with private key. * This returns a signature buffer. * * The returned buffers are guaranteed to unpooled. * This means the underlying `ArrayBuffer` is safely transferrable. */ declare function signWithPrivateKey(privateKeyOrKeyPair: PrivateKey | KeyPair, data: Buffer): Signature; /** * Verifies signature with public key */ declare function verifyWithPublicKey(publicKey: PublicKey, data: Buffer, signature: Buffer): boolean; /** * Checks if data is a signature */ declare function isSignature(signature: unknown): signature is Signature; /** * Key Encapsulation Mechanism (KEM). * This encapsulates a JWK with a public key and produces a custom JWE. * This applies the ECIES protocol in `encryptWithPublicKey` from libsodium to JWE. * This JWE uses custom header properties. * * For ECDH-SS: * - alg: "ECDH-SS-NaCl" * - enc: "XSalsa20-Poly1305" * * For ECDH-ES: * - alg: "ECDH-ES-NaCl" * - enc: "XSalsa20-Poly1305" */ declare function encapsulateWithPublicKey(receiverPublicKey: PublicKey, keyJWK: JWK, senderKeyPair?: KeyPair): JWKEncrypted; /** * Key Decapsulation Mechanism. * This decapsulates a JWE with a private key and produces a JWK. * This uses the same ECIES scheme as `decryptWithPrivateKey`. */ declare function decapsulateWithPrivateKey(receiverKeyPair: KeyPair, keyJWE: any, senderPublicKey?: PublicKey): JWK | undefined; /** * Checks if the public key is a point on the Ed25519 curve */ declare function validatePublicKey(publicKey: Buffer): publicKey is PublicKey; /** * Parses buffer source into a public key */ declare function parsePublicKey(data: any): PublicKey; /** * Parses buffer source into a private key */ declare function parsePrivateKey(data: any): PrivateKey; export { makeKeyPair, publicKeyFromData, privateKeyFromData, publicKeyToNodeId, publicKeyFromNodeId, publicKeyFromPrivateKeyEd25519, publicKeyFromPrivateKeyX25519, publicKeyEd25519ToX25519, privateKeyEd25519ToX25519, keyPairEd25519ToX25519, encryptWithPublicKey, decryptWithPrivateKey, signWithPrivateKey, verifyWithPublicKey, isSignature, encapsulateWithPublicKey, decapsulateWithPrivateKey, validatePublicKey, parsePublicKey, parsePrivateKey, };