Import util via {...} (#236)

* Import util via {...}

* Fix test failures
This commit is contained in:
Jaco Greeff
2018-10-18 15:24:13 +02:00
committed by GitHub
parent 3bb5a3ea04
commit 65b8468e5b
62 changed files with 98 additions and 158 deletions
+1 -2
View File
@@ -6,8 +6,7 @@ import { ProgressCb } from '../types';
import { Slot } from './types';
import fs from 'fs';
import assert from '@polkadot/util/assert';
import logger from '@polkadot/util/logger';
import { assert, logger } from '@polkadot/util/index';
import defaults from './defaults';
+1 -6
View File
@@ -11,12 +11,7 @@ import mkdirp from 'mkdirp';
import path from 'path';
import snappy from 'snappy';
import asNibbles from '@polkadot/trie-hash/util/asNibbles';
import assert from '@polkadot/util/assert';
import logger from '@polkadot/util/logger';
import isUndefined from '@polkadot/util/is/undefined';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { assert, bufferToU8a, isUndefined, logger, u8aToBuffer, u8aToHex } from '@polkadot/util/index';
import Compact from './Compact';
import defaults from './defaults';
+1 -4
View File
@@ -6,10 +6,7 @@ import { BaseDb, ProgressCb } from '../types';
import fs from 'fs';
import mkdirp from 'mkdirp';
import logger from '@polkadot/util/logger';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { bufferToU8a, logger, u8aToBuffer, u8aToHex } from '@polkadot/util/index';
type FilePath = {
directory: string,
+1 -1
View File
@@ -5,7 +5,7 @@
import { BaseDb, ProgressCb } from '../types';
import { LRUMap } from 'lru_map';
import logger from '@polkadot/util/logger';
import { logger } from '@polkadot/util/index';
type CachedValue = {
value: Uint8Array | null
+1 -1
View File
@@ -4,7 +4,7 @@
import { BaseDb, BaseDbOptions, ProgressCb } from '../types';
import logger from '@polkadot/util/logger';
import { logger } from '@polkadot/util/index';
type Storage = {
[index: string]: Uint8Array
+1 -3
View File
@@ -4,9 +4,7 @@
import { BaseDb, TxDb, ProgressCb } from '../types';
import assert from '@polkadot/util/assert';
import logger from '@polkadot/util/logger';
import isNull from '@polkadot/util/is/null';
import { assert, isNull, logger } from '@polkadot/util/index';
type Overlay = {
[index: string]: {
+3 -8
View File
@@ -7,13 +7,8 @@ import { Prefix } from './types';
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L6
import bs58 from 'bs58';
import assert from '@polkadot/util/assert';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import isHex from '@polkadot/util/is/hex';
import isU8a from '@polkadot/util/is/u8a';
import u8aToU8a from '@polkadot/util/u8a/toU8a';
import blake2b from '@polkadot/util-crypto/blake2/asU8a';
import { assert, bufferToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util/index';
import { blake2AsU8a } from '@polkadot/util-crypto/index';
import defaults from './defaults';
@@ -39,7 +34,7 @@ export default function decode (encoded: string | Uint8Array, prefix: Prefix = d
const endPos = decoded.length - (isPublicKey ? 2 : 1);
// calculate the hash and do the checksum byte checks
const hash = blake2b(decoded.subarray(0, endPos), 512);
const hash = blake2AsU8a(decoded.subarray(0, endPos), 512);
const checks = isPublicKey
? decoded[decoded.length - 2] === hash[0] && decoded[decoded.length - 1] === hash[1]
: decoded[decoded.length - 1] === hash[0];
+3 -7
View File
@@ -7,12 +7,8 @@ import { Prefix } from './types';
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L34
import bs58 from 'bs58';
import assert from '@polkadot/util/assert';
import u8aConcat from '@polkadot/util/u8a/concat';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
import u8aToU8a from '@polkadot/util/u8a/toU8a';
import blake2b from '@polkadot/util-crypto/blake2/asU8a';
import { assert, u8aConcat, u8aToBuffer, u8aToU8a } from '@polkadot/util/index';
import { blake2AsU8a } from '@polkadot/util-crypto/index';
import defaults from './defaults';
@@ -25,7 +21,7 @@ export default function encode (_key: Uint8Array | string, prefix: Prefix = defa
// generate an input with the prefix and calculate hash
const input = u8aConcat(new Uint8Array([prefix]), key);
const hash = blake2b(input, 512);
const hash = blake2AsU8a(input, 512);
return bs58.encode(
u8aToBuffer(
+2 -3
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import u8aFromString from '@polkadot/util/string/toU8a';
import { hexToU8a, stringToU8a } from '@polkadot/util/index';
import Keyring from './index';
import setPrefix from './address/setPrefix';
@@ -11,7 +10,7 @@ import setPrefix from './address/setPrefix';
describe('keypair', () => {
const publicKeyOne = new Uint8Array([47, 140, 97, 41, 216, 22, 207, 81, 195, 116, 188, 127, 8, 195, 230, 62, 209, 86, 207, 120, 174, 251, 74, 101, 80, 217, 123, 135, 153, 121, 119, 238]);
const publicKeyTwo = new Uint8Array([215, 90, 152, 1, 130, 177, 10, 183, 213, 75, 254, 211, 201, 100, 7, 58, 14, 225, 114, 243, 218, 166, 35, 37, 175, 2, 26, 104, 247, 7, 81, 26]);
const seedOne = u8aFromString('12345678901234567890123456789012');
const seedOne = stringToU8a('12345678901234567890123456789012');
const seedTwo = hexToU8a('0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60');
let keypair;
+2 -3
View File
@@ -4,9 +4,8 @@
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from './types';
import mnemonicToSeed from '@polkadot/util-crypto/mnemonic/toSeed';
import naclKeypairFromSeed from '@polkadot/util-crypto/nacl/keypair/fromSeed';
import hexToU8a from '@polkadot/util/hex/toU8a';
import { hexToU8a } from '@polkadot/util/index';
import { mnemonicToSeed , naclKeypairFromSeed } from '@polkadot/util-crypto/index';
import { decodeAddress, encodeAddress, setAddressPrefix } from './address';
import createPair from './pair';
+3 -7
View File
@@ -2,12 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import stringToU8a from '@polkadot/util/string/toU8a';
import u8aConcat from '@polkadot/util/u8a/concat';
import u8aFixLength from '@polkadot/util/u8a/fixLength';
import assert from '@polkadot/util/assert';
import naclDecrypt from '@polkadot/util-crypto/nacl/decrypt';
import naclFromSeed from '@polkadot/util-crypto/nacl/keypair/fromSeed';
import { assert, stringToU8a, u8aConcat, u8aFixLength } from '@polkadot/util/index';
import { naclDecrypt, naclKeypairFromSeed } from '@polkadot/util-crypto/index';
import { PKCS8_DIVIDER, PKCS8_HEADER } from './defaults';
@@ -38,7 +34,7 @@ export default function decode (passphrase?: string, _encrypted?: Uint8Array) {
const publicKey = encoded.subarray(PUBLIC_OFFSET, PUBLIC_OFFSET + KEY_LENGTH);
const seed = encoded.subarray(SEED_OFFSET, SEED_OFFSET + KEY_LENGTH);
const secretKey = u8aConcat(seed, publicKey);
const validate = naclFromSeed(seed);
const validate = naclKeypairFromSeed(seed);
assert(validate.publicKey.toString() === publicKey.toString(), 'Pkcs8 decoded publicKeys are not matching');
+2 -4
View File
@@ -2,10 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import stringToU8a from '@polkadot/util/string/toU8a';
import u8aConcat from '@polkadot/util/u8a/concat';
import u8aFixLength from '@polkadot/util/u8a/fixLength';
import naclEncrypt from '@polkadot/util-crypto/nacl/encrypt';
import { stringToU8a, u8aConcat, u8aFixLength } from '@polkadot/util/index';
import { naclEncrypt } from '@polkadot/util-crypto/index';
import { PKCS8_DIVIDER, PKCS8_HEADER } from './defaults';
+1 -2
View File
@@ -6,8 +6,7 @@ import { KeypairType } from '@polkadot/util-crypto/types';
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
import { PairState } from './types';
import naclSign from '@polkadot/util-crypto/nacl/sign';
import naclVerify from '@polkadot/util-crypto/nacl/verify';
import { naclSign, naclVerify } from '@polkadot/util-crypto/index';
import encodeAddress from '../address/encode';
import decode from './decode';
+1 -1
View File
@@ -5,7 +5,7 @@
import { KeyringPair$Json } from '../types';
import { PairState } from './types';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
export default function toJson ({ address, meta }: PairState, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
return {
+1 -5
View File
@@ -4,11 +4,7 @@
import { KeyringPairs, KeyringPair } from './types';
import assert from '@polkadot/util/assert';
import isHex from '@polkadot/util/is/hex';
import isU8a from '@polkadot/util/is/u8a';
import u8aToHex from '@polkadot/util/u8a/toHex';
import u8aToU8a from '@polkadot/util/u8a/toU8a';
import { assert, isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util/index';
import addressDecode from './address/decode';
+1 -1
View File
@@ -4,7 +4,7 @@
import { KeyringInstance } from './types';
import stringToU8a from '@polkadot/util/string/toU8a';
import { stringToU8a } from '@polkadot/util/index';
import Keyring from './index';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hashing from '@polkadot/util-crypto/keccak/asU8a';
import { keccakAsU8a as hashing } from '@polkadot/util-crypto/index';
import trieRoot from '@polkadot/trie-hash/root';
const EMPTY_NODE = new Uint8Array();
+2 -4
View File
@@ -6,10 +6,8 @@ import { TxDb, ProgressCb } from '@polkadot/db/types';
import { TrieDb, Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType } from './types';
import MemoryDb from '@polkadot/db/Memory';
import isNull from '@polkadot/util/is/null';
import logger from '@polkadot/util/logger';
import u8aConcat from '@polkadot/util/u8a/concat';
import hashing from '@polkadot/util-crypto/keccak/asU8a';
import { isNull, logger , u8aConcat } from '@polkadot/util/index';
import { keccakAsU8a as hashing } from '@polkadot/util-crypto/index';
import toNibbles from '@polkadot/trie-hash/util/asNibbles';
import { isBranchNode, isEmptyNode, isExtensionNode, isKvNode, isLeafNode } from './util/is';
+1 -1
View File
@@ -4,7 +4,7 @@
import { Node, NodeBranch, NodeKv, NodeEmpty, NodeType } from '../types';
import isNull from '@polkadot/util/is/null';
import { isNull } from '@polkadot/util/index';
import { getNodeType } from './node';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isNull from '@polkadot/util/is/null';
import { isNull } from '@polkadot/util/index';
import { EncodedPath, Node } from '../types';
+1 -1
View File
@@ -4,7 +4,7 @@
import { Node, NodeType, NodeNotEmpty } from '../types';
import isNull from '@polkadot/util/is/null';
import { isNull } from '@polkadot/util/index';
import nodeDecode from '@polkadot/util-rlp/decode';
import nodeEncode from '@polkadot/util-rlp/encode';
+6 -6
View File
@@ -17,12 +17,12 @@ 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 { stringToU8a } from '@polkadot/util';
import { trieRoot } from '@polkadot/trie-hash';
trieRoot([{
k: u8aFromString('A'),
v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
k: stringToU8a('A'),
v: stringToU8a('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
}]) // => 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab
```
@@ -38,11 +38,11 @@ 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 { stringToU8a } from '@polkadot/util';
import { trieRootOrdered } from '@polkadot/trie-hash';
trieRootOrdered([
u8aFromString('doe'),
u8aFromString('reindeer')
stringToU8a('doe'),
stringToU8a('reindeer')
]) // => 0xe766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3
```
+1 -1
View File
@@ -4,7 +4,7 @@
import { Trie$Pairs } from '../types';
import keccakAsU8a from '@polkadot/util-crypto/keccak/asU8a';
import { keccakAsU8a } from '@polkadot/util-crypto/index';
import rlpEncode from '@polkadot/util-rlp/encode';
import encode from './index';
+11 -11
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aFromString from '@polkadot/util/string/toU8a';
import stringToU8a from '@polkadot/util/string/toU8a';
import hexToU8a from '@polkadot/util/hex/toU8a';
import { trieRoot } from './index';
@@ -22,8 +22,8 @@ describe('trieRoot', () => {
it('encodes a simple k/v pair', () => {
expect(
trieRoot([{
k: u8aFromString('A'),
v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
k: stringToU8a('A'),
v: stringToU8a('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
}])
).toEqual(
hexToU8a(
@@ -35,8 +35,8 @@ describe('trieRoot', () => {
it('encodes two simple k/v pairs', () => {
expect(
trieRoot([
{ k: u8aFromString('A'), v: u8aFromString('aaaa') },
{ k: u8aFromString('B'), v: u8aFromString('bbbb') }
{ k: stringToU8a('A'), v: stringToU8a('aaaa') },
{ k: stringToU8a('B'), v: stringToU8a('bbbb') }
])
).toEqual(
hexToU8a(
@@ -50,16 +50,16 @@ describe('trieRoot', () => {
expect(
trieRoot([
{
k: u8aFromString('doe'),
v: u8aFromString('reindeer')
k: stringToU8a('doe'),
v: stringToU8a('reindeer')
},
{
k: u8aFromString('dog'),
v: u8aFromString('puppy')
k: stringToU8a('dog'),
v: stringToU8a('puppy')
},
{
k: u8aFromString('dogglesworth'),
v: u8aFromString('cat')
k: stringToU8a('dogglesworth'),
v: stringToU8a('cat')
}
])
).toEqual(
+3 -3
View File
@@ -15,12 +15,12 @@ import pairsUniq from './util/pairsUniq';
* @description
* From an `Array<{k: Uint8Array, v: Uint8Array}>` input, calculate the triehash and return the result as a `Uint8Array`.
* @example
* import { u8aFromString } from '@polkadot/util';
* import { stringToU8a } from '@polkadot/util';
* import { trieRoot } from '@polkadot/trie-hash';
*
* trieRoot([{
* k: u8aFromString('A'),
* v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
* k: stringToU8a('A'),
* v: stringToU8a('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
* }]) // => 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab
*/
export default function trieRoot (pairs: Trie$Pairs): Uint8Array {
+3 -4
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import u8aFromString from '@polkadot/util/string/toU8a';
import { hexToU8a, stringToU8a } from '@polkadot/util/index';
import { trieRootOrdered } from './index';
@@ -12,8 +11,8 @@ describe('trieRootOrdered', () => {
it('encodes a values', () => {
expect(
trieRootOrdered([
u8aFromString('doe'),
u8aFromString('reindeer')
stringToU8a('doe'),
stringToU8a('reindeer')
])
).toEqual(
hexToU8a(
+3 -3
View File
@@ -14,12 +14,12 @@ import pairsUniq from './util/pairsUniq';
* @description
* From an `Array<Uint8Array>` input, calculate the ordered triehash and return the result as a `Uint8Array`.
* @example
* import { u8aFromString } from '@polkadot/util';
* import { stringToU8a } from '@polkadot/util';
* import { trieRootOrdered } from '@polkadot/trie-hash';
*
* trieRootOrdered([
* u8aFromString('doe'),
* u8aFromString('reindeer')
* stringToU8a('doe'),
* stringToU8a('reindeer')
* ]) // => 0xe766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3
*/
export default function trieRootOrdered (values: Array<Uint8Array>): Uint8Array {
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aFromString from '@polkadot/util/string/toU8a';
import stringToU8a from '@polkadot/util/string/toU8a';
import asNibbles from './asNibbles';
@@ -20,7 +20,7 @@ describe('asNibbles', () => {
it('converts a single', () => {
expect(
asNibbles(
u8aFromString('A')
stringToU8a('A')
)
).toEqual(
new Uint8Array([4, 1])
+1 -1
View File
@@ -4,7 +4,7 @@
import { Trie$Pairs } from '../types';
import keccakAsU8a from '@polkadot/util-crypto/keccak/asU8a';
import { keccakAsU8a } from '@polkadot/util-crypto/index';
import rlpEncode from '@polkadot/util-rlp/encode';
import encode from '../encode';
+1 -1
View File
@@ -4,7 +4,7 @@
import { Trie$Pair, Trie$Pairs } from '../types';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
type PairMap = {
[index: string]: Trie$Pair
@@ -2,7 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
import blake2bAsU8a from './asU8a';
/**
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
import keccakAsU8a from './asU8a';
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import stringToU8a from '@polkadot/util/string/toU8a';
import { hexToU8a, stringToU8a } from '@polkadot/util/index';
import { keccakAsU8a } from './index';
@@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
import { mnemonicToSeed } from 'bip39';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import { bufferToU8a } from '@polkadot/util/index';
export default function toSecret (mnemonic: string): Uint8Array {
return bufferToU8a(
@@ -2,13 +2,13 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aFromString from '@polkadot/util/string/toU8a';
import { stringToU8a } from '@polkadot/util/index';
import { naclKeypairFromSeed } from '../index';
describe('naclKeypairFromSeed', () => {
// NOTE: Aligned with Rust test, b"12345678901234567890123456789012"
const TEST = u8aFromString('12345678901234567890123456789012');
const TEST = stringToU8a('12345678901234567890123456789012');
const RESULT = {
publicKey: new Uint8Array([
0x2f, 0x8c, 0x61, 0x29, 0xd8, 0x16, 0xcf, 0x51,
@@ -4,7 +4,7 @@
import { KeypairType } from '../../types';
import stringToU8a from '@polkadot/util/string/toU8a';
import { stringToU8a } from '@polkadot/util/index';
import blake2AsU8a from '../../blake2/asU8a';
import fromSeed from './fromSeed';
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aFromString from '@polkadot/util/string/toU8a';
import { stringToU8a } from '@polkadot/util/index';
import { naclSign, naclKeypairFromSeed } from './index';
@@ -11,7 +11,7 @@ describe('naclSign', () => {
beforeEach(() => {
secretKey = naclKeypairFromSeed(
u8aFromString('12345678901234567890123456789012')
stringToU8a('12345678901234567890123456789012')
).secretKey;
});
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aFromString from '@polkadot/util/string/toU8a';
import { stringToU8a } from '@polkadot/util/index';
import { naclVerify, naclKeypairFromSeed } from './index';
@@ -12,7 +12,7 @@ describe('naclSign', () => {
beforeEach(() => {
publicKey = naclKeypairFromSeed(
u8aFromString('12345678901234567890123456789012')
stringToU8a('12345678901234567890123456789012')
).publicKey;
signature = new Uint8Array([28, 58, 206, 239, 249, 70, 59, 191, 166, 40, 219, 218, 235, 170, 25, 79, 10, 94, 9, 197, 34, 126, 1, 150, 246, 68, 28, 238, 36, 26, 172, 163, 168, 90, 202, 211, 126, 246, 57, 212, 43, 24, 88, 197, 240, 113, 118, 76, 37, 81, 91, 110, 236, 50, 144, 134, 100, 223, 220, 238, 34, 185, 211, 7]);
});
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isHex from '@polkadot/util/is/hex';
import { isHex } from '@polkadot/util/index';
import { randomAsHex } from './index';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
import randomAsU8a from './asU8a';
+1 -1
View File
@@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
import BN from 'bn.js';
import hexToBn from '@polkadot/util/hex/toBn';
import { hexToBn } from '@polkadot/util/index';
import randomAsHex from './asHex';
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isU8a from '@polkadot/util/is/u8a';
import { isU8a } from '@polkadot/util/index';
import { randomAsU8a } from './index';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
import xxhashAsU8a from './asU8a';
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import { hexToU8a } from '@polkadot/util/index';
import { xxhashAsU8a } from './index';
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexAddPrefix from '@polkadot/util/hex/addPrefix';
import { hexAddPrefix } from '@polkadot/util/index';
import xxhash64AsRaw from './asRaw';
@@ -2,10 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isBuffer from '@polkadot/util/is/buffer';
import isString from '@polkadot/util/is/string';
import u8aToBuffer from '@polkadot/util/u8a/toBuffer';
import xxhashjs from 'xxhashjs';
import { isBuffer, isString, u8aToBuffer } from '@polkadot/util/index';
export default function xxhash64AsValue (data: Buffer | Uint8Array | string, seed: number): number {
if (isBuffer(data) || isString(data)) {
+1 -2
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { hexToU8a, u8aToHex } from '@polkadot/util/index';
import { decode, encode } from './index';
+1 -1
View File
@@ -4,7 +4,7 @@
import { DecodeFunc, DecodeOutput } from './types';
import assert from '@polkadot/util/assert';
import { assert } from '@polkadot/util/index';
import decodeListLong from './listLong';
import decodeListShort from './listShort';
+1 -2
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import assert from '@polkadot/util/assert';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { assert, u8aToHex } from '@polkadot/util/index';
import internalDecode from './decode';
+1 -1
View File
@@ -4,7 +4,7 @@
import { DecodeFunc, DecodeOutput } from './types';
import assert from '@polkadot/util/assert';
import { assert } from '@polkadot/util/index';
import safeParseInt from './safeParseInt';
+1 -1
View File
@@ -4,7 +4,7 @@
import { DecodeFunc, DecodeOutput } from './types';
import assert from '@polkadot/util/assert';
import { assert } from '@polkadot/util/index';
import safeParseInt from './safeParseInt';
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import assert from '@polkadot/util/assert';
import { assert } from '@polkadot/util/index';
export default function safeParseInt (input: Uint8Array): number {
assert(input[0] > 0, 'invalid rlp, extra zeros found');
+1 -1
View File
@@ -4,7 +4,7 @@
import { DecodeFunc, DecodeOutput } from './types';
import assert from '@polkadot/util/assert';
import { assert } from '@polkadot/util/index';
export default function decodeString (decode: DecodeFunc, input: Uint8Array): DecodeOutput {
const firstByte = input[0];
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import u8aToHex from '@polkadot/util/u8a/toHex';
import { u8aToHex } from '@polkadot/util/index';
import { encode } from './index';
+1 -1
View File
@@ -4,7 +4,7 @@
import { EncodeFunc } from './types';
import u8aConcat from '@polkadot/util/u8a/concat';
import { u8aConcat } from '@polkadot/util/index';
import encodeLength from './length';
+1 -2
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import numberToHex from '@polkadot/util/number/toHex';
import hexToU8a from '@polkadot/util/hex/toU8a';
import { hexToU8a, numberToHex } from '@polkadot/util/index';
export default function encodeLength (length: number, offset: number): Uint8Array {
if (length < 56) {
+1 -14
View File
@@ -2,20 +2,7 @@
// This software may be modified and distributed under the terms
// of the MPL-2.0 license. See the LICENSE file for details.
import assert from '@polkadot/util/assert';
import bnToU8a from '@polkadot/util/bn/toU8a';
import bufferToU8a from '@polkadot/util/buffer/toU8a';
import hexHasPrefix from '@polkadot/util/hex/hasPrefix';
import hexToU8a from '@polkadot/util/hex/toU8a';
import isBn from '@polkadot/util/is/bn';
import isBuffer from '@polkadot/util/is/buffer';
import isNull from '@polkadot/util/is/null';
import isNumber from '@polkadot/util/is/number';
import isString from '@polkadot/util/is/string';
import isU8a from '@polkadot/util/is/u8a';
import isUndefined from '@polkadot/util/is/undefined';
import numberToU8a from '@polkadot/util/number/toU8a';
import stringToU8a from '@polkadot/util/string/toU8a';
import { assert, bnToU8a, bufferToU8a, hexHasPrefix, hexToU8a, isBn, isBuffer, isNull, isNumber, isString, isU8a, isUndefined, numberToU8a, stringToU8a } from '@polkadot/util/index';
type Encoder = {
check: (value: any) => boolean,
+1 -1
View File
@@ -4,7 +4,7 @@
import { EncodeFunc } from './types';
import u8aConcat from '@polkadot/util/u8a/concat';
import { u8aConcat } from '@polkadot/util/index';
import encodeLength from './length';
-6
View File
@@ -26,12 +26,6 @@ Functions can be imported directly from the package, e.g.
import { isHex } from '@polkadot/util';
```
Alternatively the function can be accessed directly,
```js
import isHex from '@polkadot/util/is/hex';
```
## Available Utilities
For a list of currently exposed methods, see the [library documentation](docs/README.md).
+1 -1
View File
@@ -14,7 +14,7 @@ type MessageFn = () => string;
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
* @example
* const assert from '@polkadot/util/assert');
* import assert from '@polkadot/util/assert';
*
* assert(true, 'True should be true'); // true returned
* assert(false, 'False should not be true'); // ExtError thrown
+2 -2
View File
@@ -12,9 +12,9 @@ import isBuffer from './is/buffer';
import isFunction from './is/function';
import isObject from './is/object';
import isNull from './is/null';
import isU8a from '@polkadot/util/is/u8a';
import isU8a from './is/u8a';
import isUndefined from './is/undefined';
import u8aToHex from '@polkadot/util/u8a/toHex';
import u8aToHex from './u8a/toHex';
type ConsoleType = 'error' | 'log' | 'warn';
type LogType = ConsoleType | 'debug';
+1 -1
View File
@@ -9,7 +9,7 @@
* @description
* Wraps the supplied async function `fn` that has a standard JS callback `(error: Error, result: any)` into a `Promise`, passing the supplied parameters. When `error` is set, the Promise is rejected, else the Promise resolves with the `result` value.
* @example
* const promisify from '@polkadot/util/promisify');
* import { promisify } from '@polkadot/util';
*
* await promisify(null, ((a, cb) => cb(null, a), true); // resolves with `true`
* await promisify(null, (cb) => cb(new Error('error!'))); // rejects with `error!`