Files
common/packages/util-triehash/docs/README.md
T
Jaco Greeff e832aebb07 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
2018-02-08 14:50:54 +01:00

48 lines
1.2 KiB
Markdown

# Available interfaces
Utility methods to create [Ethereum Trie hashes](https://github.com/ethereum/wiki/wiki/Patricia-Tree)
# Available methods
## trieRoot
Creates a trie hash from the supplied pairs.
```js
trieRoot (pairs: Trie$Pairs): Uint8Array
```
From an `Array<{k: Uint8Array, v: Uint8Array}>` input, calculate the triehash and return the result as a `Uint8Array`.
```js
import { u8aFromString } from '@polkadot/util';
import { trieRoot } from '@polkadot/util-triehash';
trieRoot([{
k: u8aFromString('A'),
v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
}]) // => 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab
```
## trieRootOrdered
Creates a trie hash from the supplied values.
```js
trieRootOrdered (values: Array<Uint8Array>): Uint8Array
```
From an `Array<Uint8Array>` input, calculate the ordered triehash and return the result as a `Uint8Array`.
```js
import { u8aFromString } from '@polkadot/util';
import { trieRootOrdered } from '@polkadot/util-triehash';
trieRootOrdered([
u8aFromString('doe'),
u8aFromString('reindeer')
]) // => 0xe766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3
```