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

Commit e8bc2c6

Browse files
committed
add AddressLike, bnToHex
1 parent ce3511b commit e8bc2c6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as BN from 'bn.js'
2+
import { Address } from './address'
23
import { unpadBuffer } from './bytes'
34

45
/*
@@ -23,6 +24,12 @@ export type BufferLike =
2324
*/
2425
export type PrefixedHexString = string
2526

27+
/**
28+
* A type that represents an Address-like value.
29+
* To convert to address, use `new Address(toBuffer(value))`
30+
*/
31+
export type AddressLike = Address | Buffer | string
32+
2633
/*
2734
* A type that represents an object that has a `toArray()` method.
2835
*/
@@ -39,6 +46,13 @@ export interface TransformableToBuffer {
3946
toArray?(): Uint8Array
4047
}
4148

49+
/**
50+
* Convert BN to 0x-prefixed hex string.
51+
*/
52+
export function bnToHex(value: BN): PrefixedHexString {
53+
return `0x${value.toString(16)}`
54+
}
55+
4256
/**
4357
* Convert value from BN to RLP (unpadded buffer)
4458
* @param value value to convert

0 commit comments

Comments
 (0)