/** * @dev Class for managing secp256k1 keys and performing operations with them */ import { BigNumber } from '../ethers'; import { RandomNumber } from './RandomNumber'; import { CompressedPublicKey, EncryptedPayload, EthersProvider } from '../types'; export declare class KeyPair { readonly publicKeyHex: string; readonly privateKeyHex: string | null; /** * @notice Creates new instance from a public key or private key * @param key Can be either (1) hex public key with 0x04 prefix, or (2) hex private key with 0x prefix */ constructor(key: string); /** * @notice Returns the private key as a hex string without the 0x prefix */ get privateKeyHexSlim(): string | null; /** * @notice Returns the uncompressed public key as a hex string without the 0x prefix */ get publicKeyHexSlim(): string; /** * @notice Returns checksum address derived from this key */ get address(): string; /** * @notice Encrypt a number with the instance's public key * @param randomNumber Number as instance of RandomNumber class * @returns Hex strings of uncompressed 65 byte public key and 32 byte ciphertext */ encrypt(number: RandomNumber): EncryptedPayload; /** * @notice Decrypt a random number with the instance's private key and return the plaintext * @param output Output from the encrypt method, which can be constructed from on-chain events * @returns Decrypted ciphertext as hex string */ decrypt(output: EncryptedPayload): string; /** * @notice Returns new KeyPair instance after multiplying this public key by some value * @param value number to multiply by, as RandomNumber or hex string with 0x prefix */ mulPublicKey(value: RandomNumber | string): KeyPair; /** * @notice Returns new KeyPair instance after multiplying this private key by some value * @param value number to multiply by, as class RandomNumber or hex string with 0x prefix */ mulPrivateKey(value: RandomNumber | string): KeyPair; /** * @notice Generate KeyPair instance asynchronously from a transaction hash * @param txHash Transaction hash to recover public key from * @param provider ethers provider to use */ static instanceFromTransaction(txHash: string, provider: EthersProvider): Promise; /** * @notice Takes an uncompressed public key and returns the compressed public key * @param publicKey Uncompressed public key, as hex string starting with 0x * @returns Object containing the prefix as an integer and compressed public key as hex, as separate parameters */ static compressPublicKey(publicKey: string): CompressedPublicKey; /** * @notice Given the x-coordinate of a public key, without the identifying prefix bit, returns * the uncompressed public key assuming the identifying bit is 02 * @dev We don't know if the identifying bit is 02 or 03 when uncompressing for the scanning use case, but it * doesn't actually matter since we are not deriving an address from the public key. We use the public key to * compute the shared secret to decrypt the random number, and since that involves multiplying this public key * by a private key, we can ensure the result is the same shared secret regardless of whether we assume the 02 or * 03 prefix by using the compressed form of the hex shared secret and ignoring the prefix. Therefore if no prefix * is provided, we can assume 02, and it's up to the user to make sure they are using this method safely. This is * done because it saves gas in the StealthPay contract * @param pkx x-coordinate of compressed public key, as BigNumber or hex string * @param prefix Prefix bit, must be 2 or 3 */ static getUncompressedFromX(pkx: BigNumber | string, prefix?: number | string | undefined): string; }