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

Commit

Permalink
move bnToRlp to types file so it can be exported in the main packag…
Browse files Browse the repository at this point in the history
…e for use in monorepo
  • Loading branch information
ryanio committed Sep 29, 2020
1 parent 36a0700 commit 69a5ef4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { stripHexPrefix } from 'ethjs-util'
import { KECCAK256_RLP, KECCAK256_NULL } from './constants'
import { zeros, bufferToHex, toBuffer } from './bytes'
import { keccak, keccak256, keccakFromString, rlphash } from './hash'
import { assertIsHexString, assertIsBuffer, bnToRlp } from './helpers'
import { BNLike, BufferLike } from './types'
import { assertIsHexString, assertIsBuffer } from './helpers'
import { BNLike, BufferLike, bnToRlp } from './types'

const {
privateKeyVerify,
Expand Down
12 changes: 0 additions & 12 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as BN from 'bn.js'
import { isHexString } from 'ethjs-util'
import { unpadBuffer } from './bytes'

/**
* Throws if a string is not hex prefixed
Expand Down Expand Up @@ -45,13 +43,3 @@ export const assertIsString = function(input: string): void {
throw new Error(msg)
}
}

/**
* Convert value from BN to RLP (unpadded buffer)
* @param value value to convert
*/
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))
}
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as BN from 'bn.js'
import { unpadBuffer } from './bytes'

export type BNLike = BN | string | number

Expand All @@ -9,3 +10,13 @@ export type PrefixedHexString = string
export interface TransformableToBuffer {
toBuffer(): Buffer
}

/**
* Convert value from BN to RLP (unpadded buffer)
* @param value value to convert
*/
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))
}

0 comments on commit 69a5ef4

Please sign in to comment.