/** * @file Hive crypto helpers. * @author Johan Nordberg * @license * Copyright (c) 2017 Johan Nordberg. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * You acknowledge that this software is not designed, licensed or intended for use * in the design, construction, operation or maintenance of any military facility. */ import { SignedTransaction, Transaction } from "./chain/transaction.js"; /** * Network marker byte used by Hive WIF private keys. */ export declare const NETWORK_ID: Uint8Array; /** * Return ripemd160 hash of input. */ declare function ripemd160(input: Uint8Array | string): Uint8Array; /** * Return sha256 hash of input. */ declare function sha256(input: Uint8Array | string): Uint8Array; /** * Return 2-round sha256 hash of input. */ declare function doubleSha256(input: Uint8Array | string): Uint8Array; /** * Encode public key with bs58+ripemd160-checksum. */ declare function encodePublic(key: Uint8Array, prefix: string): string; /** * Encode bs58+doubleSha256-checksum private key. */ declare function encodePrivate(key: Uint8Array): string; /** * Decode bs58+doubleSha256-checksum encoded private key. */ declare function decodePrivate(encodedKey: string): Uint8Array; /** * Return true if signature is canonical, otherwise false. */ declare function isCanonicalSignature(signature: Uint8Array): boolean; /** * Return true if string is wif, otherwise false. */ declare function isWif(privWif: string | Uint8Array): boolean; /** * Hive public key backed by the secp256k1 elliptic curve. */ export declare class PublicKey { readonly key: Uint8Array; readonly prefix: string; readonly uncompressed: Uint8Array; constructor(key: Uint8Array, prefix?: string); static fromBuffer(key: Uint8Array): PublicKey; /** * Creates a public key from its Hive string representation. */ static fromString(wif: string): PublicKey; /** * Normalizes a public-key input into a {@link PublicKey} instance. */ static from(value: string | PublicKey): PublicKey; /** * Verifies a compact ECDSA signature against a 32-byte digest. */ verify(message: Uint8Array, signature: Signature): boolean; /** * Renders the key as a Hive public-key string. */ toString(): string; /** * Return JSON representation of this key, same as toString(). */ toJSON(): string; /** * Used by `utils.inspect` and `console.log` in node.js. */ inspect(): string; } /** * Hive authority role used for password-derived account keys. */ export type KeyRole = "owner" | "active" | "posting" | "memo"; /** * Hive private key backed by the secp256k1 elliptic curve. */ export declare class PrivateKey { private key; constructor(key: Uint8Array); /** * Normalizes a WIF string or raw 32-byte secret into a private key. * * @remarks * Raw secrets are accepted as `Uint8Array` values so Pollen's key path stays * independent of Node `Buffer` while still working in browser builds. */ static from(value: string | Uint8Array): PrivateKey; /** * Parses a WIF-encoded Hive private key. */ static fromString(wif: string): PrivateKey; /** * Derives a private key by hashing an arbitrary seed string. */ static fromSeed(seed: string): PrivateKey; /** * Derives a Hive role key from an account name and master password. */ static fromLogin(username: string, password: string, role?: KeyRole): PrivateKey; /** * Signs a 32-byte digest with this private key. */ sign(message: Uint8Array): Signature; /** * Derives the compressed public key for this private key. */ createPublic(prefix?: string): PublicKey; /** * Renders the private key as a WIF string. */ toString(): string; /** * Used by `utils.inspect` and `console.log` in node.js. */ inspect(): string; /** * Derives the shared secret used by encrypted Hive memos. */ get_shared_secret(public_key: PublicKey): Uint8Array; } /** * Compact recoverable secp256k1 signature. */ export declare class Signature { data: Uint8Array; recovery: number; constructor(data: Uint8Array, recovery: number); static fromBuffer(buffer: Uint8Array): Signature; static fromString(string: string): Signature; /** * Recovers the public key that produced this signature. */ recover(message: Uint8Array, prefix?: string): PublicKey; toBuffer(): Uint8Array; toString(): string; } /** * Return the sha256 transaction digest. */ declare function transactionDigest(transaction: Transaction | SignedTransaction, chainId?: Uint8Array): Uint8Array; /** * Returns a copy of a transaction with one or more signatures appended. */ declare function signTransaction(transaction: Transaction, keys: PrivateKey | PrivateKey[], chainId?: Uint8Array): SignedTransaction; declare function generateTrxId(transaction: Transaction): string; /** * Low-level cryptographic utility namespace. */ export declare const cryptoUtils: { decodePrivate: typeof decodePrivate; doubleSha256: typeof doubleSha256; encodePrivate: typeof encodePrivate; encodePublic: typeof encodePublic; generateTrxId: typeof generateTrxId; isCanonicalSignature: typeof isCanonicalSignature; isWif: typeof isWif; ripemd160: typeof ripemd160; sha256: typeof sha256; signTransaction: typeof signTransaction; transactionDigest: typeof transactionDigest; }; export {};