UNPKG

2.12 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BNLike } from './types';
3export interface ECDSASignature {
4 v: number;
5 r: Buffer;
6 s: Buffer;
7}
8export interface ECDSASignatureBuffer {
9 v: Buffer;
10 r: Buffer;
11 s: Buffer;
12}
13/**
14 * Returns the ECDSA signature of a message hash.
15 */
16export declare function ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: number): ECDSASignature;
17export declare function ecsign(msgHash: Buffer, privateKey: Buffer, chainId: BNLike): ECDSASignatureBuffer;
18/**
19 * ECDSA public key recovery from signature.
20 * @returns Recovered public key
21 */
22export declare const ecrecover: (msgHash: Buffer, v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike | undefined) => Buffer;
23/**
24 * Convert signature parameters into the format of `eth_sign` RPC method.
25 * @returns Signature
26 */
27export declare const toRpcSig: (v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike | undefined) => string;
28/**
29 * Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
30 * @returns Signature
31 */
32export declare const toCompactSig: (v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike | undefined) => string;
33/**
34 * Convert signature format of the `eth_sign` RPC method to signature parameters
35 * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
36 */
37export declare const fromRpcSig: (sig: string) => ECDSASignature;
38/**
39 * Validate a ECDSA signature.
40 * @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
41 */
42export declare const isValidSignature: (v: BNLike, r: Buffer, s: Buffer, homesteadOrLater?: boolean, chainId?: BNLike | undefined) => boolean;
43/**
44 * Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
45 * The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
46 * call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
47 * used to produce the signature.
48 */
49export declare const hashPersonalMessage: (message: Buffer) => Buffer;