Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Sep 28, 2020
1 parent 6c89111 commit 18e90bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
33 changes: 19 additions & 14 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,19 @@ export class Account {
* Returns a `Boolean` determining if the account is empty.
*/
isEmpty(): boolean {
return this.balance.isZero() && this.nonce.isZero() && this.stateRoot.equals(KECCAK256_RLP) && this.codeHash.equals(KECCAK256_NULL)
return (
this.balance.isZero() &&
this.nonce.isZero() &&
this.stateRoot.equals(KECCAK256_RLP) &&
this.codeHash.equals(KECCAK256_NULL)
)
}
}

/**
* Checks if the address is a valid. Accepts checksummed addresses too.
*/
export const isValidAddress = function (hexAddress: string): boolean {
export const isValidAddress = function(hexAddress: string): boolean {
assertIsHexString(hexAddress)
return /^0x[0-9a-fA-F]{40}$/.test(hexAddress)
}
Expand All @@ -123,7 +128,7 @@ export const isValidAddress = function (hexAddress: string): boolean {
* 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.
*/
export const toChecksumAddress = function (hexAddress: string, eip1191ChainId?: number): string {
export const toChecksumAddress = function(hexAddress: string, eip1191ChainId?: number): string {
assertIsHexString(hexAddress)
const address = stripHexPrefix(hexAddress).toLowerCase()

Expand All @@ -148,7 +153,7 @@ export const toChecksumAddress = function (hexAddress: string, eip1191ChainId?:
*
* See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
*/
export const isValidChecksumAddress = function (
export const isValidChecksumAddress = function(
hexAddress: string,
eip1191ChainId?: number,
): boolean {
Expand All @@ -160,7 +165,7 @@ export const isValidChecksumAddress = function (
* @param from The address which is creating this new address
* @param nonce The nonce of the from account
*/
export const generateAddress = function (from: Buffer, nonce: Buffer): Buffer {
export const generateAddress = function(from: Buffer, nonce: Buffer): Buffer {
assertIsBuffer(from)
assertIsBuffer(nonce)
const nonceBN = new BN(nonce)
Expand All @@ -181,7 +186,7 @@ export const generateAddress = function (from: Buffer, nonce: Buffer): Buffer {
* @param salt A salt
* @param initCode The init code of the contract being created
*/
export const generateAddress2 = function (from: Buffer, salt: Buffer, initCode: Buffer): Buffer {
export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: Buffer): Buffer {
assertIsBuffer(from)
assertIsBuffer(salt)
assertIsBuffer(initCode)
Expand All @@ -199,7 +204,7 @@ export const generateAddress2 = function (from: Buffer, salt: Buffer, initCode:
/**
* Checks if the private key satisfies the rules of the curve secp256k1.
*/
export const isValidPrivate = function (privateKey: Buffer): boolean {
export const isValidPrivate = function(privateKey: Buffer): boolean {
return privateKeyVerify(privateKey)
}

Expand All @@ -209,7 +214,7 @@ export const isValidPrivate = function (privateKey: Buffer): boolean {
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = false): boolean {
export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = false): boolean {
assertIsBuffer(publicKey)
if (publicKey.length === 64) {
// Convert to SEC1 for secp256k1
Expand All @@ -229,7 +234,7 @@ export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = fa
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
* @param sanitize Accept public keys in other formats
*/
export const pubToAddress = function (pubKey: Buffer, sanitize: boolean = false): Buffer {
export const pubToAddress = function(pubKey: Buffer, sanitize: boolean = false): Buffer {
assertIsBuffer(pubKey)
if (sanitize && pubKey.length !== 64) {
pubKey = Buffer.from(publicKeyConvert(pubKey, false).slice(1))
Expand All @@ -244,15 +249,15 @@ export const publicToAddress = pubToAddress
* Returns the ethereum address of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
export const privateToAddress = function (privateKey: Buffer): Buffer {
export const privateToAddress = function(privateKey: Buffer): Buffer {
return publicToAddress(privateToPublic(privateKey))
}

/**
* Returns the ethereum public key of a given private key.
* @param privateKey A private key must be 256 bits wide
*/
export const privateToPublic = function (privateKey: Buffer): Buffer {
export const privateToPublic = function(privateKey: Buffer): Buffer {
assertIsBuffer(privateKey)
// skip the type flag and use the X, Y points
return Buffer.from(publicKeyCreate(privateKey, false)).slice(1)
Expand All @@ -261,7 +266,7 @@ export const privateToPublic = function (privateKey: Buffer): Buffer {
/**
* Converts a public key to the Ethereum format.
*/
export const importPublic = function (publicKey: Buffer): Buffer {
export const importPublic = function(publicKey: Buffer): Buffer {
assertIsBuffer(publicKey)
if (publicKey.length !== 64) {
publicKey = Buffer.from(publicKeyConvert(publicKey, false).slice(1))
Expand All @@ -272,7 +277,7 @@ export const importPublic = function (publicKey: Buffer): Buffer {
/**
* Returns a zero address.
*/
export const zeroAddress = function (): string {
export const zeroAddress = function(): string {
const addressLength = 20
const addr = zeros(addressLength)
return bufferToHex(addr)
Expand All @@ -281,7 +286,7 @@ export const zeroAddress = function (): string {
/**
* Checks if a given address is a zero address.
*/
export const isZeroAddress = function (hexAddress: string): boolean {
export const isZeroAddress = function(hexAddress: string): boolean {
assertIsHexString(hexAddress)
const zeroAddr = zeroAddress()
return zeroAddr === hexAddress
Expand Down
10 changes: 5 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unpadBuffer } from './bytes'
* Throws if a string is not hex prefixed
* @param {string} input string to check hex prefix of
*/
export const assertIsHexString = function (input: string): void {
export const assertIsHexString = function(input: string): void {
if (!isHexString(input)) {
const msg = `This method only supports 0x-prefixed hex strings but input was: ${input}`
throw new Error(msg)
Expand All @@ -17,7 +17,7 @@ export const assertIsHexString = function (input: string): void {
* Throws if input is not a buffer
* @param {Buffer} input value to check
*/
export const assertIsBuffer = function (input: Buffer): void {
export const assertIsBuffer = function(input: Buffer): void {
if (!Buffer.isBuffer(input)) {
const msg = `This method only supports Buffer but input was: ${input}`
throw new Error(msg)
Expand All @@ -28,7 +28,7 @@ export const assertIsBuffer = function (input: Buffer): void {
* Throws if input is not an array
* @param {number[]} input value to check
*/
export const assertIsArray = function (input: number[]): void {
export const assertIsArray = function(input: number[]): void {
if (!Array.isArray(input)) {
const msg = `This method only supports number arrays but input was: ${input}`
throw new Error(msg)
Expand All @@ -39,7 +39,7 @@ export const assertIsArray = function (input: number[]): void {
* Throws if input is not a string
* @param {string} input value to check
*/
export const assertIsString = function (input: string): void {
export const assertIsString = function(input: string): void {
if (typeof input !== 'string') {
const msg = `This method only supports strings but input was: ${input}`
throw new Error(msg)
Expand All @@ -54,4 +54,4 @@ export function bnToRlp(value: BN): Buffer {
// Using `bn.toArrayLike(Buffer)` instead of `bn.toBuffer()`
// for compatibility with browserify and similar tools
return unpadBuffer(value.toArrayLike(Buffer))
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ export * from './types'
/**
* Export ethjs-util methods
*/
export * from 'ethjs-util'
export * from 'ethjs-util'
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export type BufferLike = Buffer | TransformableToBuffer | PrefixedHexString | nu
export type PrefixedHexString = string

export interface TransformableToBuffer {
toBuffer(): Buffer
}
toBuffer(): Buffer
}

0 comments on commit 18e90bf

Please sign in to comment.