- 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 index.ts:271
● setLength: setLengthLeft = setLengthLeft
Defined in index.ts:79
● stripZeros: unpad = unpad
Defined in index.ts:106
▸ addHexPrefix(str: string
): string
Defined in index.ts:488
Adds "0x" to a given String
if it does not already start with "0x".
Parameters:
Name | Type |
---|---|
str | string |
Returns: string
▸ baToJSON(ba: any
): undefined
| string
| any
[]
Defined in index.ts:540
Converts a Buffer
or Array
to JSON.
Parameters:
Name | Type | Description |
---|---|---|
ba | any |
(Buffer|Array) |
Returns: undefined
| string
| any
[]
(Array|String|null)
▸ bufferToHex(buf: Buffer
): string
Defined in index.ts:151
Converts a Buffer
into a hex String
.
Parameters:
Name | Type | Description |
---|---|---|
buf | Buffer |
`Buffer` object to convert |
Returns: string
▸ bufferToInt(buf: Buffer
): number
Defined in index.ts:143
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 index.ts:562
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 index.ts:329
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 index.ts:297
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 index.ts:363
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 index.ts:160
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 index.ts:438
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 index.ts:458
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: any
): Buffer
Defined in index.ts:320
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 | any |
Returns: Buffer
▸ importPublic(publicKey: Buffer
): Buffer
Defined in index.ts:286
Converts a public key to the Ethereum format.
Parameters:
Name | Type |
---|---|
publicKey | Buffer |
Returns: Buffer
▸ isPrecompiled(address: Buffer
| string
): boolean
Defined in index.ts:480
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 index.ts:395
Checks if the address is a valid. Accepts checksummed addresses too.
Parameters:
Name | Type |
---|---|
address | string |
Returns: boolean
▸ isValidChecksumAddress(address: string
): boolean
Defined in index.ts:429
Checks if the address is a valid checksummed address.
Parameters:
Name | Type |
---|---|
address | string |
Returns: boolean
▸ isValidPrivate(privateKey: Buffer
): boolean
Defined in index.ts:233
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 index.ts:243
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 index.ts:500
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 index.ts:402
Checks if a given address is a zero address.
Parameters:
Name | Type |
---|---|
address | string |
Returns: boolean
▸ keccak(a: any
, bits?: number
): Buffer
Defined in index.ts:177
Creates Keccak hash of the input
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
a | any |
- | The input data (Buffer|Array|String|Number) |
Default value bits |
number |
256 | The Keccak width |
Returns: Buffer
▸ keccak256(a: any
): Buffer
Defined in index.ts:190
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 index.ts:388
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 index.ts:277
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 index.ts:262
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 index.ts:210
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 index.ts:226
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 index.ts:62
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 index.ts:88
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 index.ts:198
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 index.ts:112
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
): string
Defined in index.ts:410
Returns a checksummed address.
Parameters:
Name | Type |
---|---|
address | string |
Returns: string
▸ toRpcSig(v: number
, r: Buffer
, s: Buffer
, chainId?: undefined
| number
): string
Defined in index.ts:349
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 index.ts:168
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 index.ts:97
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 index.ts:48
Returns a zero address.
Returns: string
▸ zeros(bytes: number
): Buffer
Defined in index.ts:41
Returns a buffer filled with 0s.
Parameters:
Name | Type | Description |
---|---|---|
bytes | number |
the number of bytes the buffer should be |
Returns: Buffer