Project is in active development and has been moved to the EthereumJS monorepo.
This release adds support for very high chainId
numbers exceeding MAX_SAFE_INTEGER
(an example is the chain ID 34180983699157880
used for the ephemeral Yolov3 testnet preparing for the berlin
hardfork, but high chain IDs might be used for things like private test networks and the like as well).
Function signatures for methods in address
and signature
are therefore expanded to allow for a BNLike
input type (BN | PrefixedHexString | number | Buffer
) for chain ID related parameters.
All function signatures are still taking in a number
input for backwards-compatibility reasons. If you use one of the following functions to implement generic use cases in your library where the chain ID is not yet known it is recommended to updated to one of the other input types (with plain Buffer
likely be the most future-proof). Note that on some functions this changes the return value as well.
account
: toChecksumAddresss(hexAddress: string, eip1191ChainId?: number): string
toChecksumAddress = function(hexAddress: string, eip1191ChainId?: BNLike): string
account
: isValidChecksumAddress(hexAddress: string, eip1191ChainId?: number)
isValidChecksumAddress(hexAddress: string, eip1191ChainId?: BNLike)
signature
: ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: number): ECDSASignature
ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: number): ECDSASignature
(return value stays the same on number
input)ecsign(msgHash: Buffer, privateKey: Buffer, chainId: BNLike): ECDSASignatureBuffer
(changed return value for other type inputs)signature
: ecrecover(msgHash: Buffer, v: number, r: Buffer, s: Buffer, chainId?: number): Buffer
ecrecover(msgHash: Buffer, v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike): Buffer
signature
: toRpcSig(v: number, r: Buffer, s: Buffer, chainId?: number): string
toRpcSig(v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike): string
signature
: isValidSignature(v: number, r: Buffer, s: Buffer, homesteadOrLater: boolean = true, chainId?: number)
isValidSignature(v: BNLike, r: Buffer, s: Buffer, homesteadOrLater: boolean = true, chainId?: BNLike)
Account
classThis release adds a new Account
class intended as a modern replacement for ethereumjs-account
. It has a shape of Account(nonce?: BN, balance?: BN, stateRoot?: Buffer, codeHash?: Buffer)
.
Instantiation
The static factory methods assist in creating an Account
object from varying data types: Object: fromAccountData
, RLP: fromRlpSerializedAccount
, and Array: fromValuesArray
.
Methods: isEmpty(): boolean
, isContract(): boolean
, serialize(): Buffer
Example usage:
import { Account, BN } from 'ethereumjs-util'
const account = new Account(
new BN(0), // nonce, default: 0
new BN(10).pow(new BN(18)), // balance, default: 0
undefined, // stateRoot, default: KECCAK256_RLP (hash of RLP of null)
undefined, // codeHash, default: KECCAK256_NULL (hash of null)
)
For more info see the documentation, examples of usage in test/account.spec.ts
or PR #275.
A new file with helpful TypeScript types has been added to the exports of this project, see PR #275.
In this release it contains BNLike
, BufferLike
, and TransformableToBuffer
.
The Address class has as a new method address.toBuffer()
that will give you a copy of the underlying address.buf
(PR #277).
toBuffer()
now converts TransformableToBufferThe toBuffer()
exported function now additionally converts any object with a toBuffer()
method (PR #277).
This release adds a new module address
- see README - with a new Address
class and type which can be used for creating and representing Ethereum addresses.
Example usage:
import { Address } from 'ethereumjs-util'
const pubKey = Buffer.from(
'3a443d8381a6798a70c6ff9304bdc8cb0163c23211d11628fae52ef9e0dca11a001cf066d56a8156fc201cd5df8a36ef694eecd258903fca7086c1fae7441e1d',
'hex',
)
const address = Address.fromPublicKey(pubKey)
In TypeScript
the associated Address
type can be used to more strictly enforce type checks (e.g. on the length of an address) on function parameters expecting an address input. So you can declare a function like the following: myAddressRelatedFunction(address: Address)
to get more assurance that the address input is correct.
See PR #186
This release replaces the native secp256k1
and keccak
dependencies with ethereum-cryptopgraphy which doesn't need native compilation.
This release replaces the native secp256k1
and keccak
dependencies with ethereum-cryptopgraphy which doesn't need native compilation.
This release replaces the native secp256k1
and keccak
dependencies with ethereum-cryptopgraphy which doesn't need native compilation.
This release replaces the keccak
and secp256k1
dependencies (PR #257) and instead uses the ethereum-cryptography package that uses native JS implementations for cryptographic primitives and makes use of modern and forward-compatible N-API implementations in Node wherever possible.
This is part of a larger initiative led by Nomic Labs to improve the developer experience within the Ethereum developer ecosystem, see https://github.com/ethereum/js-organization/issues/18 for context.
Other Changes: