- KECCAK256_NULL
- KECCAK256_NULL_S
- KECCAK256_RLP
- KECCAK256_RLP_ARRAY
- KECCAK256_RLP_ARRAY_S
- KECCAK256_RLP_S
- MAX_INTEGER
- TWO_POW256
- publicToAddress
- setLength
- stripZeros
- addHexPrefix
- baToJSON
- bufferToHex
- bufferToInt
- defineProperties
- ecrecover
- ecsign
- fromRpcSig
- fromSigned
- generateAddress
- generateAddress2
- hashPersonalMessage
- importPublic
- isPrecompiled
- isValidAddress
- isValidChecksumAddress
- isValidPrivate
- isValidPublic
- isValidSignature
- isZeroAddress
- keccak
- keccak256
- privateToAddress
- privateToPublic
- pubToAddress
- ripemd160
- rlphash
- setLengthLeft
- setLengthRight
- sha256
- toBuffer
- toChecksumAddress
- toRpcSig
- toUnsigned
- unpad
- zeroAddress
- zeros
● KECCAK256_NULL: Buffer
= Buffer.from(KECCAK256_NULL_S, 'hex')
Defined in constants.ts:28
Keccak-256 hash of null
● KECCAK256_NULL_S: string
= "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
Defined in constants.ts:22
Keccak-256 hash of null
● KECCAK256_RLP: Buffer
= Buffer.from(KECCAK256_RLP_S, 'hex')
Defined in constants.ts:50
Keccak-256 hash of the RLP of null
● KECCAK256_RLP_ARRAY: Buffer
= Buffer.from(KECCAK256_RLP_ARRAY_S, 'hex')
Defined in constants.ts:39
Keccak-256 of an RLP of an empty array
● KECCAK256_RLP_ARRAY_S: string
= "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
Defined in constants.ts:33
Keccak-256 of an RLP of an empty array
● KECCAK256_RLP_S: string
= "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
Defined in constants.ts:44
Keccak-256 hash of the RLP of null
● MAX_INTEGER: BN
= new BN(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
16,
)
Defined in constants.ts:6
The max integer that this VM can handle
● TWO_POW256: BN
= new BN(
'10000000000000000000000000000000000000000000000000000000000000000',
16,
)
Defined in constants.ts:14
2^256
● publicToAddress: pubToAddress = pubToAddress
Defined in account.ts:163
● setLength: setLengthLeft = setLengthLeft
Defined in bytes.ts:37
● stripZeros: unpad = unpad
Defined in bytes.ts:64
▸ addHexPrefix(str: string
): string
Defined in bytes.ts:135
Adds "0x" to a given String
if it does not already start with "0x".
Parameters:
Name | Type |
---|---|
str | string |
Returns: string
▸ baToJSON(ba: any
): any
Defined in bytes.ts:148
Converts a Buffer
or Array
to JSON.
Parameters:
Name | Type | Description |
---|---|---|
ba | any |
(Buffer|Array) |
Returns: any
(Array|String|null)
▸ bufferToHex(buf: Buffer
): string
Defined in bytes.ts:111
Converts a Buffer
into a 0x
-prefixed hex String
.
Parameters:
Name | Type | Description |
---|---|---|
buf | Buffer |
`Buffer` object to convert |
Returns: string
▸ bufferToInt(buf: Buffer
): number
Defined in bytes.ts:103
Converts a Buffer
to a Number
.
Parameters:
Name | Type | Description |
---|---|---|
buf | Buffer |
`Buffer` object to convert |
Returns: number
▸ defineProperties(self: any
, fields: any
, data: any
): void
Defined in object.ts:17
Defines properties on a Object
. It make the assumption that underlying data is binary.
Parameters:
Name | Type | Description |
---|---|---|
self | any |
the `Object` to define properties on |
fields | any |
an array fields to define. Fields can contain:* `name` - the name of the properties* `length` - the number of bytes the field can have* `allowLess` - if the field can be less than the length* `allowEmpty` |
data | any |
data to be validated against the definitions |
Returns: void
▸ ecrecover(msgHash: Buffer
, v: number
, r: Buffer
, s: Buffer
, chainId?: undefined
| number
): Buffer
Defined in signature.ts:36
ECDSA public key recovery from signature.
Parameters:
Name | Type |
---|---|
msgHash | Buffer |
v | number |
r | Buffer |
s | Buffer |
Optional chainId |
undefined | number |
Returns: Buffer
Recovered public key
▸ ecsign(msgHash: Buffer
, privateKey: Buffer
, chainId?: undefined
| number
): ECDSASignature
Defined in signature.ts:15
Returns the ECDSA signature of a message hash.
Parameters:
Name | Type |
---|---|
msgHash | Buffer |
privateKey | Buffer |
Optional chainId |
undefined | number |
Returns: ECDSASignature
▸ fromRpcSig(sig: string
): ECDSASignature
Defined in signature.ts:70
Convert signature format of the eth_sign
RPC method to signature parameters NOTE: all because of a bug in geth: ethereum/go-ethereum#2053
Parameters:
Name | Type |
---|---|
sig | string |
Returns: ECDSASignature
▸ fromSigned(num: Buffer
): BN
Defined in bytes.ts:120
Interprets a Buffer
as a signed integer and returns a BN
. Assumes 256-bit numbers.
Parameters:
Name | Type | Description |
---|---|---|
num | Buffer |
Signed integer value |
Returns: BN
▸ generateAddress(from: Buffer
, nonce: Buffer
): Buffer
Defined in account.ts:75
Generates an address of a newly created contract.
Parameters:
Name | Type | Description |
---|---|---|
from | Buffer |
The address which is creating this new address |
nonce | Buffer |
The nonce of the from account |
Returns: Buffer
▸ generateAddress2(from: Buffer
| string
, salt: Buffer
| string
, initCode: Buffer
| string
): Buffer
Defined in account.ts:95
Generates an address for a contract created using CREATE2.
Parameters:
Name | Type | Description |
---|---|---|
from | Buffer | string |
The address which is creating this new address |
salt | Buffer | string |
A salt |
initCode | Buffer | string |
The init code of the contract being created |
Returns: Buffer
▸ hashPersonalMessage(message: Buffer
): Buffer
Defined in signature.ts:136
Returns the keccak-256 hash of message
, prefixed with the header used by the eth_sign
RPC call. The output of this function can be fed into ecsign
to produce the same signature as the eth_sign
call for a given message
, or fed to ecrecover
along with a signature to recover the public key used to produce the signature.
Parameters:
Name | Type |
---|---|
message | Buffer |
Returns: Buffer
▸ importPublic(publicKey: Buffer
): Buffer
Defined in account.ts:186
Converts a public key to the Ethereum format.
Parameters:
Name | Type |
---|---|
publicKey | Buffer |
Returns: Buffer
▸ isPrecompiled(address: Buffer
| string
): boolean
Defined in account.ts:117
Returns true if the supplied address belongs to a precompiled account (Byzantium).
Parameters:
Name | Type |
---|---|
address | Buffer | string |
Returns: boolean
▸ isValidAddress(address: string
): boolean
Defined in account.ts:20
Checks if the address is a valid. Accepts checksummed addresses too.
Parameters:
Name | Type |
---|---|
address | string |
Returns: boolean
▸ isValidChecksumAddress(address: string
, eip1191ChainId?: undefined
| number
): boolean
Defined in account.ts:66
Checks if the address is a valid checksummed address.
See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
Parameters:
Name | Type |
---|---|
address | string |
Optional eip1191ChainId |
undefined | number |
Returns: boolean
▸ isValidPrivate(privateKey: Buffer
): boolean
Defined in account.ts:125
Checks if the private key satisfies the rules of the curve secp256k1.
Parameters:
Name | Type |
---|---|
privateKey | Buffer |
Returns: boolean
▸ isValidPublic(publicKey: Buffer
, sanitize?: boolean
): boolean
Defined in account.ts:135
Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of Ethereum.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
publicKey | Buffer |
- | The two points of an uncompressed key, unless sanitize is enabled |
Default value sanitize |
boolean |
false | Accept public keys in other formats |
Returns: boolean
▸ isValidSignature(v: number
, r: Buffer
, s: Buffer
, homesteadOrLater?: boolean
, chainId?: undefined
| number
): boolean
Defined in signature.ts:95
Validate a ECDSA signature.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
v | number |
- | |
r | Buffer |
- | |
s | Buffer |
- | |
Default value homesteadOrLater |
boolean |
true | Indicates whether this is being used on either the homestead hardfork or a later one |
Optional chainId |
undefined | number |
- |
Returns: boolean
▸ isZeroAddress(address: string
): boolean
Defined in account.ts:27
Checks if a given address is a zero address.
Parameters:
Name | Type |
---|---|
address | string |
Returns: boolean
▸ keccak(a: any
, bits?: number
): Buffer
Defined in hash.ts:13
Creates Keccak hash of the input
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
a | any |
- | The input data (Buffer|Array|String|Number) If the string is a 0x-prefixed hex value it's interpreted as hexadecimal, otherwise as utf8. |
Default value bits |
number |
256 | The Keccak width |
Returns: Buffer
▸ keccak256(a: any
): Buffer
Defined in hash.ts:31
Creates Keccak-256 hash of the input, alias for keccak(a, 256).
Parameters:
Name | Type | Description |
---|---|---|
a | any |
The input data (Buffer|Array|String|Number) |
Returns: Buffer
▸ privateToAddress(privateKey: Buffer
): Buffer
Defined in account.ts:169
Returns the ethereum address of a given private key.
Parameters:
Name | Type | Description |
---|---|---|
privateKey | Buffer |
A private key must be 256 bits wide |
Returns: Buffer
▸ privateToPublic(privateKey: Buffer
): Buffer
Defined in account.ts:177
Returns the ethereum public key of a given private key.
Parameters:
Name | Type | Description |
---|---|---|
privateKey | Buffer |
A private key must be 256 bits wide |
Returns: Buffer
▸ pubToAddress(pubKey: Buffer
, sanitize?: boolean
): Buffer
Defined in account.ts:154
Returns the ethereum address of a given public key. Accepts "Ethereum public keys" and SEC1 encoded keys.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
pubKey | Buffer |
- | The two points of an uncompressed key, unless sanitize is enabled |
Default value sanitize |
boolean |
false | Accept public keys in other formats |
Returns: Buffer
▸ ripemd160(a: any
, padded: boolean
): Buffer
Defined in hash.ts:51
Creates RIPEMD160 hash of the input.
Parameters:
Name | Type | Description |
---|---|---|
a | any |
The input data (Buffer|Array|String|Number) |
padded | boolean |
Whether it should be padded to 256 bits or not |
Returns: Buffer
▸ rlphash(a: rlp.Input
): Buffer
Defined in hash.ts:67
Creates SHA-3 hash of the RLP encoded version of the input.
Parameters:
Name | Type | Description |
---|---|---|
a | rlp.Input |
The input data |
Returns: Buffer
▸ setLengthLeft(msg: any
, length: number
, right?: boolean
): any
Defined in bytes.ts:20
Left Pads an Array
or Buffer
with leading zeros till it has length
bytes. Or it truncates the beginning if it exceeds.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
msg | any |
- | the value to pad (Buffer|Array) |
length | number |
- | the number of bytes the output should be |
Default value right |
boolean |
false | whether to start padding form the left or right |
Returns: any
(Buffer|Array)
▸ setLengthRight(msg: any
, length: number
): any
Defined in bytes.ts:46
Right Pads an Array
or Buffer
with leading zeros till it has length
bytes. Or it truncates the beginning if it exceeds.
Parameters:
Name | Type | Description |
---|---|---|
msg | any |
the value to pad (Buffer|Array) |
length | number |
the number of bytes the output should be |
Returns: any
(Buffer|Array)
▸ sha256(a: any
): Buffer
Defined in hash.ts:39
Creates SHA256 hash of the input.
Parameters:
Name | Type | Description |
---|---|---|
a | any |
The input data (Buffer|Array|String|Number) |
Returns: Buffer
▸ toBuffer(v: any
): Buffer
Defined in bytes.ts:70
Attempts to turn a value into a Buffer
. As input it supports Buffer
, String
, Number
, null/undefined, BN
and other objects with a toArray()
method.
Parameters:
Name | Type | Description |
---|---|---|
v | any |
the value |
Returns: Buffer
▸ toChecksumAddress(address: string
, eip1191ChainId?: undefined
| number
): string
Defined in account.ts:42
Returns a checksummed address.
If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This has the effect of checksummed addresses for one chain having invalid checksums for others. For more details, consult EIP-1191.
WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly used variation in Ethereum was without the chainId. This may change in the future.
Parameters:
Name | Type |
---|---|
address | string |
Optional eip1191ChainId |
undefined | number |
Returns: string
▸ toRpcSig(v: number
, r: Buffer
, s: Buffer
, chainId?: undefined
| number
): string
Defined in signature.ts:56
Convert signature parameters into the format of eth_sign
RPC method.
Parameters:
Name | Type |
---|---|
v | number |
r | Buffer |
s | Buffer |
Optional chainId |
undefined | number |
Returns: string
Signature
▸ toUnsigned(num: BN
): Buffer
Defined in bytes.ts:128
Converts a BN
to an unsigned integer and returns it as a Buffer
. Assumes 256-bit numbers.
Parameters:
Name | Type | Description |
---|---|---|
num | BN |
Returns: Buffer
▸ unpad(a: any
): any
Defined in bytes.ts:55
Trims leading zeros from a Buffer
or an Array
.
Parameters:
Name | Type | Description |
---|---|---|
a | any |
(Buffer|Array|String) |
Returns: any
(Buffer|Array|String)
▸ zeroAddress(): string
Defined in account.ts:11
Returns a zero address.
Returns: string
▸ zeros(bytes: number
): Buffer
Defined in bytes.ts:8
Returns a buffer filled with 0s.
Parameters:
Name | Type | Description |
---|---|---|
bytes | number |
the number of bytes the buffer should be |
Returns: Buffer