This repository was archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathtypes.ts
More file actions
64 lines (56 loc) · 1.46 KB
/
types.ts
File metadata and controls
64 lines (56 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as BN from 'bn.js'
import { Address } from './address'
import { unpadBuffer } from './bytes'
/*
* A type that represents a BNLike input that can be converted to a BN.
*/
export type BNLike = BN | string | number
/*
* A type that represents a BufferLike input that can be converted to a Buffer.
*/
export type BufferLike =
| Buffer
| Uint8Array
| number[]
| number
| BN
| TransformableToBuffer
| PrefixedHexString
/*
* A type that represents a `0x`-prefixed hex string.
*/
export type PrefixedHexString = string
/**
* A type that represents an Address-like value.
* To convert to address, use `new Address(toBuffer(value))`
*/
export type AddressLike = Address | Buffer | string
/*
* A type that represents an object that has a `toArray()` method.
*/
export interface TransformableToArray {
toArray(): Uint8Array
toBuffer?(): Buffer
}
/*
* A type that represents an object that has a `toBuffer()` method.
*/
export interface TransformableToBuffer {
toBuffer(): Buffer
toArray?(): Uint8Array
}
/**
* Convert BN to 0x-prefixed hex string.
*/
export function bnToHex(value: BN): PrefixedHexString {
return `0x${value.toString(16)}`
}
/**
* 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))
}