UNPKG

4.87 kBTypeScriptView Raw
1/// <reference types="node" />
2import BN from 'bn.js';
3import { BNLike, BufferLike } from './types';
4export interface AccountData {
5 nonce?: BNLike;
6 balance?: BNLike;
7 stateRoot?: BufferLike;
8 codeHash?: BufferLike;
9}
10export declare class Account {
11 nonce: BN;
12 balance: BN;
13 stateRoot: Buffer;
14 codeHash: Buffer;
15 static fromAccountData(accountData: AccountData): Account;
16 static fromRlpSerializedAccount(serialized: Buffer): Account;
17 static fromValuesArray(values: Buffer[]): Account;
18 /**
19 * This constructor assigns and validates the values.
20 * Use the static factory methods to assist in creating an Account from varying data types.
21 */
22 constructor(nonce?: BN, balance?: BN, stateRoot?: Buffer, codeHash?: Buffer);
23 private _validate;
24 /**
25 * Returns a Buffer Array of the raw Buffers for the account, in order.
26 */
27 raw(): Buffer[];
28 /**
29 * Returns the RLP serialization of the account as a `Buffer`.
30 */
31 serialize(): Buffer;
32 /**
33 * Returns a `Boolean` determining if the account is a contract.
34 */
35 isContract(): boolean;
36 /**
37 * Returns a `Boolean` determining if the account is empty complying to the definition of
38 * account emptiness in [EIP-161](https://eips.ethereum.org/EIPS/eip-161):
39 * "An account is considered empty when it has no code and zero nonce and zero balance."
40 */
41 isEmpty(): boolean;
42}
43/**
44 * Checks if the address is a valid. Accepts checksummed addresses too.
45 */
46export declare const isValidAddress: (hexAddress: string) => boolean;
47/**
48 * Returns a checksummed address.
49 *
50 * If an eip1191ChainId is provided, the chainId will be included in the checksum calculation. This
51 * has the effect of checksummed addresses for one chain having invalid checksums for others.
52 * For more details see [EIP-1191](https://eips.ethereum.org/EIPS/eip-1191).
53 *
54 * WARNING: Checksums with and without the chainId will differ and the EIP-1191 checksum is not
55 * backwards compatible to the original widely adopted checksum format standard introduced in
56 * [EIP-55](https://eips.ethereum.org/EIPS/eip-55), so this will break in existing applications.
57 * Usage of this EIP is therefore discouraged unless you have a very targeted use case.
58 */
59export declare const toChecksumAddress: (hexAddress: string, eip1191ChainId?: BNLike | undefined) => string;
60/**
61 * Checks if the address is a valid checksummed address.
62 *
63 * See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
64 */
65export declare const isValidChecksumAddress: (hexAddress: string, eip1191ChainId?: BNLike | undefined) => boolean;
66/**
67 * Generates an address of a newly created contract.
68 * @param from The address which is creating this new address
69 * @param nonce The nonce of the from account
70 */
71export declare const generateAddress: (from: Buffer, nonce: Buffer) => Buffer;
72/**
73 * Generates an address for a contract created using CREATE2.
74 * @param from The address which is creating this new address
75 * @param salt A salt
76 * @param initCode The init code of the contract being created
77 */
78export declare const generateAddress2: (from: Buffer, salt: Buffer, initCode: Buffer) => Buffer;
79/**
80 * Checks if the private key satisfies the rules of the curve secp256k1.
81 */
82export declare const isValidPrivate: (privateKey: Buffer) => boolean;
83/**
84 * Checks if the public key satisfies the rules of the curve secp256k1
85 * and the requirements of Ethereum.
86 * @param publicKey The two points of an uncompressed key, unless sanitize is enabled
87 * @param sanitize Accept public keys in other formats
88 */
89export declare const isValidPublic: (publicKey: Buffer, sanitize?: boolean) => boolean;
90/**
91 * Returns the ethereum address of a given public key.
92 * Accepts "Ethereum public keys" and SEC1 encoded keys.
93 * @param pubKey The two points of an uncompressed key, unless sanitize is enabled
94 * @param sanitize Accept public keys in other formats
95 */
96export declare const pubToAddress: (pubKey: Buffer, sanitize?: boolean) => Buffer;
97export declare const publicToAddress: (pubKey: Buffer, sanitize?: boolean) => Buffer;
98/**
99 * Returns the ethereum public key of a given private key.
100 * @param privateKey A private key must be 256 bits wide
101 */
102export declare const privateToPublic: (privateKey: Buffer) => Buffer;
103/**
104 * Returns the ethereum address of a given private key.
105 * @param privateKey A private key must be 256 bits wide
106 */
107export declare const privateToAddress: (privateKey: Buffer) => Buffer;
108/**
109 * Converts a public key to the Ethereum format.
110 */
111export declare const importPublic: (publicKey: Buffer) => Buffer;
112/**
113 * Returns the zero address.
114 */
115export declare const zeroAddress: () => string;
116/**
117 * Checks if a given address is the zero address.
118 */
119export declare const isZeroAddress: (hexAddress: string) => boolean;
120
\No newline at end of file