diff --git a/packages/db/src/FileFlatDb/Compact.ts b/packages/db/src/FileFlatDb/Compact.ts index 79ad7cd7d..25f3457eb 100644 --- a/packages/db/src/FileFlatDb/Compact.ts +++ b/packages/db/src/FileFlatDb/Compact.ts @@ -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'; diff --git a/packages/db/src/FileFlatDb/index.ts b/packages/db/src/FileFlatDb/index.ts index eb0df4fbf..c25137fff 100644 --- a/packages/db/src/FileFlatDb/index.ts +++ b/packages/db/src/FileFlatDb/index.ts @@ -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'; diff --git a/packages/db/src/engines/FileTreeDb.ts b/packages/db/src/engines/FileTreeDb.ts index be7c9b325..563034cf5 100644 --- a/packages/db/src/engines/FileTreeDb.ts +++ b/packages/db/src/engines/FileTreeDb.ts @@ -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, diff --git a/packages/db/src/engines/LruDb.ts b/packages/db/src/engines/LruDb.ts index b3d067518..954d4670d 100644 --- a/packages/db/src/engines/LruDb.ts +++ b/packages/db/src/engines/LruDb.ts @@ -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 diff --git a/packages/db/src/engines/MemoryDb.ts b/packages/db/src/engines/MemoryDb.ts index 9d8e08c9d..df20257e7 100644 --- a/packages/db/src/engines/MemoryDb.ts +++ b/packages/db/src/engines/MemoryDb.ts @@ -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 diff --git a/packages/db/src/engines/TransactionDb.ts b/packages/db/src/engines/TransactionDb.ts index c06f78a03..939439119 100644 --- a/packages/db/src/engines/TransactionDb.ts +++ b/packages/db/src/engines/TransactionDb.ts @@ -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]: { diff --git a/packages/keyring/src/address/decode.ts b/packages/keyring/src/address/decode.ts index ab6824144..0b572b016 100644 --- a/packages/keyring/src/address/decode.ts +++ b/packages/keyring/src/address/decode.ts @@ -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]; diff --git a/packages/keyring/src/address/encode.ts b/packages/keyring/src/address/encode.ts index 31a75be53..4fd2dd7e9 100644 --- a/packages/keyring/src/address/encode.ts +++ b/packages/keyring/src/address/encode.ts @@ -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( diff --git a/packages/keyring/src/index.spec.js b/packages/keyring/src/index.spec.js index 90f236a63..4e6bcccb7 100644 --- a/packages/keyring/src/index.spec.js +++ b/packages/keyring/src/index.spec.js @@ -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; diff --git a/packages/keyring/src/index.ts b/packages/keyring/src/index.ts index 06244c546..7c90584cb 100644 --- a/packages/keyring/src/index.ts +++ b/packages/keyring/src/index.ts @@ -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'; diff --git a/packages/keyring/src/pair/decode.ts b/packages/keyring/src/pair/decode.ts index c847564b3..2c3efef9a 100644 --- a/packages/keyring/src/pair/decode.ts +++ b/packages/keyring/src/pair/decode.ts @@ -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'); diff --git a/packages/keyring/src/pair/encode.ts b/packages/keyring/src/pair/encode.ts index c9aed60c2..b03eec2e6 100644 --- a/packages/keyring/src/pair/encode.ts +++ b/packages/keyring/src/pair/encode.ts @@ -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'; diff --git a/packages/keyring/src/pair/index.ts b/packages/keyring/src/pair/index.ts index c3bfe4e0f..e8b488524 100644 --- a/packages/keyring/src/pair/index.ts +++ b/packages/keyring/src/pair/index.ts @@ -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'; diff --git a/packages/keyring/src/pair/toJson.ts b/packages/keyring/src/pair/toJson.ts index ce5c20006..46a6b0833 100644 --- a/packages/keyring/src/pair/toJson.ts +++ b/packages/keyring/src/pair/toJson.ts @@ -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 { diff --git a/packages/keyring/src/pairs.ts b/packages/keyring/src/pairs.ts index 2a89df0e2..82daf878d 100644 --- a/packages/keyring/src/pairs.ts +++ b/packages/keyring/src/pairs.ts @@ -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'; diff --git a/packages/keyring/src/testing.ts b/packages/keyring/src/testing.ts index 9d8ec9122..1c911787a 100644 --- a/packages/keyring/src/testing.ts +++ b/packages/keyring/src/testing.ts @@ -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'; diff --git a/packages/trie-db/src/constants.ts b/packages/trie-db/src/constants.ts index 5b1a36f88..06baeead2 100644 --- a/packages/trie-db/src/constants.ts +++ b/packages/trie-db/src/constants.ts @@ -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(); diff --git a/packages/trie-db/src/index.ts b/packages/trie-db/src/index.ts index 4428be47b..f68120a54 100644 --- a/packages/trie-db/src/index.ts +++ b/packages/trie-db/src/index.ts @@ -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'; diff --git a/packages/trie-db/src/util/is.ts b/packages/trie-db/src/util/is.ts index 78a86a92a..846302704 100644 --- a/packages/trie-db/src/util/is.ts +++ b/packages/trie-db/src/util/is.ts @@ -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'; diff --git a/packages/trie-db/src/util/key.ts b/packages/trie-db/src/util/key.ts index 5c0df4be2..285295b9e 100644 --- a/packages/trie-db/src/util/key.ts +++ b/packages/trie-db/src/util/key.ts @@ -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'; diff --git a/packages/trie-db/src/util/node.ts b/packages/trie-db/src/util/node.ts index 03f952db9..80b6f24e5 100644 --- a/packages/trie-db/src/util/node.ts +++ b/packages/trie-db/src/util/node.ts @@ -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'; diff --git a/packages/trie-hash/docs/README.md b/packages/trie-hash/docs/README.md index ca669df99..00c6649a7 100644 --- a/packages/trie-hash/docs/README.md +++ b/packages/trie-hash/docs/README.md @@ -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 From an `Array` 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 ``` diff --git a/packages/trie-hash/src/encode/aux.ts b/packages/trie-hash/src/encode/aux.ts index d8c89fcc6..b71b16b58 100644 --- a/packages/trie-hash/src/encode/aux.ts +++ b/packages/trie-hash/src/encode/aux.ts @@ -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'; diff --git a/packages/trie-hash/src/root.spec.js b/packages/trie-hash/src/root.spec.js index b7fdd824c..1c99ae410 100644 --- a/packages/trie-hash/src/root.spec.js +++ b/packages/trie-hash/src/root.spec.js @@ -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( diff --git a/packages/trie-hash/src/root.ts b/packages/trie-hash/src/root.ts index 5ab56b5ab..4c9cb1c78 100644 --- a/packages/trie-hash/src/root.ts +++ b/packages/trie-hash/src/root.ts @@ -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 { diff --git a/packages/trie-hash/src/rootOrdered.spec.js b/packages/trie-hash/src/rootOrdered.spec.js index 6bd4c155b..fed7fc0a1 100644 --- a/packages/trie-hash/src/rootOrdered.spec.js +++ b/packages/trie-hash/src/rootOrdered.spec.js @@ -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( diff --git a/packages/trie-hash/src/rootOrdered.ts b/packages/trie-hash/src/rootOrdered.ts index eda3e34db..4cbd73f30 100644 --- a/packages/trie-hash/src/rootOrdered.ts +++ b/packages/trie-hash/src/rootOrdered.ts @@ -14,12 +14,12 @@ import pairsUniq from './util/pairsUniq'; * @description * From an `Array` 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 { diff --git a/packages/trie-hash/src/util/asNibbles.spec.js b/packages/trie-hash/src/util/asNibbles.spec.js index db19b4e86..bf500ed11 100644 --- a/packages/trie-hash/src/util/asNibbles.spec.js +++ b/packages/trie-hash/src/util/asNibbles.spec.js @@ -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]) diff --git a/packages/trie-hash/src/util/genRoot.ts b/packages/trie-hash/src/util/genRoot.ts index 4411a0746..0d3a90b60 100644 --- a/packages/trie-hash/src/util/genRoot.ts +++ b/packages/trie-hash/src/util/genRoot.ts @@ -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'; diff --git a/packages/trie-hash/src/util/pairsUniq.ts b/packages/trie-hash/src/util/pairsUniq.ts index 744284636..b6a5e9724 100644 --- a/packages/trie-hash/src/util/pairsUniq.ts +++ b/packages/trie-hash/src/util/pairsUniq.ts @@ -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 diff --git a/packages/util-crypto/src/blake2/blake2b/asHex.ts b/packages/util-crypto/src/blake2/blake2b/asHex.ts index 5aba61d33..0f2949e3e 100644 --- a/packages/util-crypto/src/blake2/blake2b/asHex.ts +++ b/packages/util-crypto/src/blake2/blake2b/asHex.ts @@ -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'; /** diff --git a/packages/util-crypto/src/keccak/asHex.ts b/packages/util-crypto/src/keccak/asHex.ts index f690928fa..5baad58c1 100644 --- a/packages/util-crypto/src/keccak/asHex.ts +++ b/packages/util-crypto/src/keccak/asHex.ts @@ -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'; diff --git a/packages/util-crypto/src/keccak/asU8a.spec.js b/packages/util-crypto/src/keccak/asU8a.spec.js index bcae9a623..914351e00 100644 --- a/packages/util-crypto/src/keccak/asU8a.spec.js +++ b/packages/util-crypto/src/keccak/asU8a.spec.js @@ -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'; diff --git a/packages/util-crypto/src/mnemonic/toSecret.ts b/packages/util-crypto/src/mnemonic/toSecret.ts index b50b500cb..31511ee18 100644 --- a/packages/util-crypto/src/mnemonic/toSecret.ts +++ b/packages/util-crypto/src/mnemonic/toSecret.ts @@ -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( diff --git a/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js b/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js index da994dc9c..29690e29a 100644 --- a/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js +++ b/packages/util-crypto/src/nacl/keypair/fromSeed.spec.js @@ -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, diff --git a/packages/util-crypto/src/nacl/keypair/fromString.ts b/packages/util-crypto/src/nacl/keypair/fromString.ts index 3f3caad1d..4321cf7e9 100644 --- a/packages/util-crypto/src/nacl/keypair/fromString.ts +++ b/packages/util-crypto/src/nacl/keypair/fromString.ts @@ -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'; diff --git a/packages/util-crypto/src/nacl/sign.spec.js b/packages/util-crypto/src/nacl/sign.spec.js index 51de73c83..08b6b79db 100644 --- a/packages/util-crypto/src/nacl/sign.spec.js +++ b/packages/util-crypto/src/nacl/sign.spec.js @@ -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; }); diff --git a/packages/util-crypto/src/nacl/verify.spec.js b/packages/util-crypto/src/nacl/verify.spec.js index 862133658..a71680332 100644 --- a/packages/util-crypto/src/nacl/verify.spec.js +++ b/packages/util-crypto/src/nacl/verify.spec.js @@ -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]); }); diff --git a/packages/util-crypto/src/random/asHex.spec.js b/packages/util-crypto/src/random/asHex.spec.js index 306110869..258b8da96 100644 --- a/packages/util-crypto/src/random/asHex.spec.js +++ b/packages/util-crypto/src/random/asHex.spec.js @@ -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'; diff --git a/packages/util-crypto/src/random/asHex.ts b/packages/util-crypto/src/random/asHex.ts index a617c0e70..587410105 100644 --- a/packages/util-crypto/src/random/asHex.ts +++ b/packages/util-crypto/src/random/asHex.ts @@ -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'; diff --git a/packages/util-crypto/src/random/asNumber.ts b/packages/util-crypto/src/random/asNumber.ts index 992402b47..b6238ed9e 100644 --- a/packages/util-crypto/src/random/asNumber.ts +++ b/packages/util-crypto/src/random/asNumber.ts @@ -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'; diff --git a/packages/util-crypto/src/random/asU8a.spec.js b/packages/util-crypto/src/random/asU8a.spec.js index 88d9ffb62..0e57f80c6 100644 --- a/packages/util-crypto/src/random/asU8a.spec.js +++ b/packages/util-crypto/src/random/asU8a.spec.js @@ -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'; diff --git a/packages/util-crypto/src/xxhash/asHex.ts b/packages/util-crypto/src/xxhash/asHex.ts index 7385d52b0..ec67bf757 100644 --- a/packages/util-crypto/src/xxhash/asHex.ts +++ b/packages/util-crypto/src/xxhash/asHex.ts @@ -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'; diff --git a/packages/util-crypto/src/xxhash/asU8a.spec.js b/packages/util-crypto/src/xxhash/asU8a.spec.js index 4a7e1d6ec..86cf6a080 100644 --- a/packages/util-crypto/src/xxhash/asU8a.spec.js +++ b/packages/util-crypto/src/xxhash/asU8a.spec.js @@ -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'; diff --git a/packages/util-crypto/src/xxhash/xxhash64/asHex.ts b/packages/util-crypto/src/xxhash/xxhash64/asHex.ts index e1b118f27..b721ef00e 100644 --- a/packages/util-crypto/src/xxhash/xxhash64/asHex.ts +++ b/packages/util-crypto/src/xxhash/xxhash64/asHex.ts @@ -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'; diff --git a/packages/util-crypto/src/xxhash/xxhash64/asValue.ts b/packages/util-crypto/src/xxhash/xxhash64/asValue.ts index a741ad2e7..c4ae3f7dc 100644 --- a/packages/util-crypto/src/xxhash/xxhash64/asValue.ts +++ b/packages/util-crypto/src/xxhash/xxhash64/asValue.ts @@ -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)) { diff --git a/packages/util-rlp/src/decode.spec.js b/packages/util-rlp/src/decode.spec.js index 4f7e46403..95e270866 100644 --- a/packages/util-rlp/src/decode.spec.js +++ b/packages/util-rlp/src/decode.spec.js @@ -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'; diff --git a/packages/util-rlp/src/decoder/decode.ts b/packages/util-rlp/src/decoder/decode.ts index 02860302b..2352df00d 100644 --- a/packages/util-rlp/src/decoder/decode.ts +++ b/packages/util-rlp/src/decoder/decode.ts @@ -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'; diff --git a/packages/util-rlp/src/decoder/index.ts b/packages/util-rlp/src/decoder/index.ts index 7ae9eba50..3fa19af77 100644 --- a/packages/util-rlp/src/decoder/index.ts +++ b/packages/util-rlp/src/decoder/index.ts @@ -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'; diff --git a/packages/util-rlp/src/decoder/listLong.ts b/packages/util-rlp/src/decoder/listLong.ts index a317ba0db..637e62feb 100644 --- a/packages/util-rlp/src/decoder/listLong.ts +++ b/packages/util-rlp/src/decoder/listLong.ts @@ -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'; diff --git a/packages/util-rlp/src/decoder/number.ts b/packages/util-rlp/src/decoder/number.ts index 5a61f4ebb..8784f217f 100644 --- a/packages/util-rlp/src/decoder/number.ts +++ b/packages/util-rlp/src/decoder/number.ts @@ -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'; diff --git a/packages/util-rlp/src/decoder/safeParseInt.ts b/packages/util-rlp/src/decoder/safeParseInt.ts index 5798a7e57..f4445221c 100644 --- a/packages/util-rlp/src/decoder/safeParseInt.ts +++ b/packages/util-rlp/src/decoder/safeParseInt.ts @@ -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'); diff --git a/packages/util-rlp/src/decoder/string.ts b/packages/util-rlp/src/decoder/string.ts index 2bdeb8f7d..0b3cf8364 100644 --- a/packages/util-rlp/src/decoder/string.ts +++ b/packages/util-rlp/src/decoder/string.ts @@ -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]; diff --git a/packages/util-rlp/src/encode.spec.js b/packages/util-rlp/src/encode.spec.js index d1d7e178d..dbb1c6ba7 100644 --- a/packages/util-rlp/src/encode.spec.js +++ b/packages/util-rlp/src/encode.spec.js @@ -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'; diff --git a/packages/util-rlp/src/encoder/array.ts b/packages/util-rlp/src/encoder/array.ts index 0fc2189d6..30762f210 100644 --- a/packages/util-rlp/src/encoder/array.ts +++ b/packages/util-rlp/src/encoder/array.ts @@ -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'; diff --git a/packages/util-rlp/src/encoder/length.ts b/packages/util-rlp/src/encoder/length.ts index 84717918b..323ca433a 100644 --- a/packages/util-rlp/src/encoder/length.ts +++ b/packages/util-rlp/src/encoder/length.ts @@ -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) { diff --git a/packages/util-rlp/src/encoder/toU8a.ts b/packages/util-rlp/src/encoder/toU8a.ts index d1e5f3fce..b0532203f 100644 --- a/packages/util-rlp/src/encoder/toU8a.ts +++ b/packages/util-rlp/src/encoder/toU8a.ts @@ -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, diff --git a/packages/util-rlp/src/encoder/u8a.ts b/packages/util-rlp/src/encoder/u8a.ts index fc1925f30..82c4cd7bf 100644 --- a/packages/util-rlp/src/encoder/u8a.ts +++ b/packages/util-rlp/src/encoder/u8a.ts @@ -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'; diff --git a/packages/util/README.md b/packages/util/README.md index e28c444c2..1f0be8b81 100644 --- a/packages/util/README.md +++ b/packages/util/README.md @@ -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). diff --git a/packages/util/src/assert.ts b/packages/util/src/assert.ts index c3c00e9c0..c4acc7bdc 100644 --- a/packages/util/src/assert.ts +++ b/packages/util/src/assert.ts @@ -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 diff --git a/packages/util/src/logger.ts b/packages/util/src/logger.ts index 29b2fcc0a..d85294409 100644 --- a/packages/util/src/logger.ts +++ b/packages/util/src/logger.ts @@ -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'; diff --git a/packages/util/src/promisify.ts b/packages/util/src/promisify.ts index 8dfdb9a98..3636f7503 100644 --- a/packages/util/src/promisify.ts +++ b/packages/util/src/promisify.ts @@ -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!`