Introduce @polkadot/util-rlp (#76)
* Add toU8a conversions * Add u8a utilities * @polkadot/rlp with encoding * Decoding test runthrough * Update util locations * Convert util-triehash to use util-rlp * Allow keccak from Uint8Array * Pass Uint8Array to keccak input * Update documentation * Skip some doc generation * Update @polkadot/dev * Update doc typo * Update allocations * Retrieve tests from ethereumjs-testing * Simplify test retrieval * Exclude etereumjs-testing from flow
This commit is contained in:
@@ -4,6 +4,7 @@ Utility methods to convert to and from `BN` objects
|
||||
|
||||
- [bnFromHex](#bnfromhex) Creates a BN.js bignumber object from a hex string.
|
||||
- [bnToHex](#bntohex) Creates a hex value from a BN.js bignumber object.
|
||||
- [bnToU8a](#bntou8a) Creates a Uint8Array object from a BN.
|
||||
|
||||
## bnFromHex
|
||||
|
||||
@@ -33,4 +34,21 @@ import BN from 'bn.js';
|
||||
import { bnToHex } from '@polkadot/util';
|
||||
|
||||
bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
```
|
||||
|
||||
## bnToU8a
|
||||
|
||||
Creates a Uint8Array object from a BN.
|
||||
|
||||
```js
|
||||
bnToU8a (value?: BN): Uint8Array
|
||||
```
|
||||
|
||||
|
||||
`null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`.
|
||||
|
||||
```js
|
||||
import { bnToU8a } from '@polkadot/util';
|
||||
|
||||
bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
```
|
||||
@@ -6,6 +6,7 @@ Utility methods to convert to and from `number` values
|
||||
- [numberFromHex](#numberfromhex) Creates a Number value from a Buffer object.
|
||||
- [numberToBuffer](#numbertobuffer) Creates a Buffer object from a number.
|
||||
- [numberToHex](#numbertohex) Creates a hex value from a number.
|
||||
- [numberToU8a](#numbertou8a) Creates a Uint8Array object from a number.
|
||||
|
||||
## numberFromBuffer
|
||||
|
||||
@@ -63,4 +64,21 @@ numberToHex (value?: number): string
|
||||
import { numberToHex } from '@polkadot/util';
|
||||
|
||||
const hex = numberToHex(0x1234); // => '0x1234'
|
||||
```
|
||||
|
||||
## numberToU8a
|
||||
|
||||
Creates a Uint8Array object from a number.
|
||||
|
||||
```js
|
||||
numberToBuffer (value?: number): Uint8Array
|
||||
```
|
||||
|
||||
|
||||
`null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `number` input values return the actual bytes value converted to a `Uint8Array`.
|
||||
|
||||
```js
|
||||
import { numberToU8a } from '@polkadot/util';
|
||||
|
||||
numberToU8a(0x1234); // => [0x12, 0x34]
|
||||
```
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
Utility methods to convert to and from `Uint8Array` objects
|
||||
|
||||
- [u8aConcat](#u8aconcat) Creates a concatenated Uint8Array from the inputs.
|
||||
- [u8aFromBn](#u8afrombn) Creates a Uint8Array value from a BN object.
|
||||
- [u8aFromBuffer](#u8afrombuffer) Creates a Uint8Array value from a Buffer object.
|
||||
- [u8aFromHex](#u8afromhex) Creates a Uint8Array value from a hex string.
|
||||
- [u8aFromString](#u8afromstring) Creates a Uint8Array object from a string.
|
||||
@@ -10,6 +12,38 @@ Utility methods to convert to and from `Uint8Array` objects
|
||||
- [u8aToHex](#u8atohex) Creates a hex string from a Uint8Array object.
|
||||
- [u8aToUtf8](#u8atoutf8) Creates a utf-8 string from a Uint8Array object.
|
||||
|
||||
## u8aConcat
|
||||
|
||||
Creates a concatenated Uint8Array from the inputs.
|
||||
|
||||
```js
|
||||
u8aConcat (values: Array<Uint8Array>): Uint8Array
|
||||
```
|
||||
|
||||
|
||||
Concatenates the input arrays into a single `UInt8Array`.
|
||||
|
||||
```js
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
|
||||
u8aConcat([
|
||||
new Uint8Array([1, 2, 3]),
|
||||
new Uint8Array([4, 5, 6])
|
||||
]); // [1, 2, 3, 4, 5, 6]
|
||||
```
|
||||
|
||||
## u8aFromBn
|
||||
|
||||
Creates a Uint8Array value from a BN object. [(alias of bnToU8a)](bn.md#bntou8a)
|
||||
|
||||
```js
|
||||
u8aFromBn (value?: BN): Uint8Array
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## u8aFromBuffer
|
||||
|
||||
Creates a Uint8Array value from a Buffer object. [(alias of bufferToU8a)](buffer.md#buffertou8a)
|
||||
|
||||
Reference in New Issue
Block a user