From 7075495efd7ee56d0ae487bd9a999e5f44cb7323 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 22 May 2018 15:44:34 +0200 Subject: [PATCH] Update keyring usage (#128) * Update keyring usage * Remove "fluffy" asU8a{128,256,512} operations --- packages/util-crypto/docs/blake2.md | 108 ------------------ packages/util-crypto/docs/xxhash.md | 72 ------------ packages/util-crypto/src/blake2/asHex128.js | 21 ---- .../util-crypto/src/blake2/asHex128.spec.js | 13 --- packages/util-crypto/src/blake2/asHex256.js | 21 ---- .../util-crypto/src/blake2/asHex256.spec.js | 13 --- packages/util-crypto/src/blake2/asHex512.js | 21 ---- .../util-crypto/src/blake2/asHex512.spec.js | 13 --- packages/util-crypto/src/blake2/asU8a128.js | 21 ---- .../util-crypto/src/blake2/asU8a128.spec.js | 15 --- packages/util-crypto/src/blake2/asU8a256.js | 21 ---- .../util-crypto/src/blake2/asU8a256.spec.js | 15 --- packages/util-crypto/src/blake2/asU8a512.js | 21 ---- .../util-crypto/src/blake2/asU8a512.spec.js | 17 --- packages/util-crypto/src/blake2/index.js | 14 +-- packages/util-crypto/src/kdf/asU8a.js | 4 +- .../src/nacl/keypair/fromString.js | 7 +- packages/util-crypto/src/xxhash/asHex128.js | 21 ---- .../util-crypto/src/xxhash/asHex128.spec.js | 25 ---- packages/util-crypto/src/xxhash/asHex256.js | 21 ---- .../util-crypto/src/xxhash/asHex256.spec.js | 13 --- packages/util-crypto/src/xxhash/asU8a128.js | 21 ---- .../util-crypto/src/xxhash/asU8a128.spec.js | 17 --- packages/util-crypto/src/xxhash/asU8a256.js | 21 ---- .../util-crypto/src/xxhash/asU8a256.spec.js | 17 --- packages/util-crypto/src/xxhash/index.js | 10 +- packages/util-keyring/src/address/decode.js | 4 +- packages/util-keyring/src/address/encode.js | 4 +- packages/util-keyring/src/pair/decode.js | 2 +- packages/util-keyring/src/pair/decode.spec.js | 2 +- packages/util-keyring/src/pair/index.js | 4 +- packages/util-keyring/src/types.js | 2 +- 32 files changed, 17 insertions(+), 584 deletions(-) delete mode 100644 packages/util-crypto/src/blake2/asHex128.js delete mode 100644 packages/util-crypto/src/blake2/asHex128.spec.js delete mode 100644 packages/util-crypto/src/blake2/asHex256.js delete mode 100644 packages/util-crypto/src/blake2/asHex256.spec.js delete mode 100644 packages/util-crypto/src/blake2/asHex512.js delete mode 100644 packages/util-crypto/src/blake2/asHex512.spec.js delete mode 100644 packages/util-crypto/src/blake2/asU8a128.js delete mode 100644 packages/util-crypto/src/blake2/asU8a128.spec.js delete mode 100644 packages/util-crypto/src/blake2/asU8a256.js delete mode 100644 packages/util-crypto/src/blake2/asU8a256.spec.js delete mode 100644 packages/util-crypto/src/blake2/asU8a512.js delete mode 100644 packages/util-crypto/src/blake2/asU8a512.spec.js delete mode 100644 packages/util-crypto/src/xxhash/asHex128.js delete mode 100644 packages/util-crypto/src/xxhash/asHex128.spec.js delete mode 100644 packages/util-crypto/src/xxhash/asHex256.js delete mode 100644 packages/util-crypto/src/xxhash/asHex256.spec.js delete mode 100644 packages/util-crypto/src/xxhash/asU8a128.js delete mode 100644 packages/util-crypto/src/xxhash/asU8a128.spec.js delete mode 100644 packages/util-crypto/src/xxhash/asU8a256.js delete mode 100644 packages/util-crypto/src/xxhash/asU8a256.spec.js diff --git a/packages/util-crypto/docs/blake2.md b/packages/util-crypto/docs/blake2.md index 799cb2dc7..155d6c236 100644 --- a/packages/util-crypto/docs/blake2.md +++ b/packages/util-crypto/docs/blake2.md @@ -3,13 +3,7 @@ Create blake2b values with specified bitlengths - [blake2AsHex](#blake2ashex) Creates a blake2b hex from the input. -- [blake2AsHex128](#blake2ashex128) Creates a blake2b hex with 128-bits from the input. -- [blake2AsHex256](#blake2ashex256) Creates a blake2b hex with 256-bits from the input. -- [blake2AsHex512](#blake2ashex512) Creates a blake2b hex with 512-bits from the input. - [blake2AsU8a](#blake2asu8a) Creates a blake2b u8a from the input. -- [blake2AsU8a128](#blake2asu8a128) Creates a blake2b u8a with 128-bits from the input. -- [blake2AsU8a256](#blake2asu8a256) Creates a blake2b u8a with 256-bits from the input. -- [blake2AsU8a512](#blake2asu8a512) Creates a blake2b u8a with 512-bits from the input. ## blake2AsHex @@ -28,57 +22,6 @@ import { blake2AsHex } from '@polkadot/util-crypto'; blake2AsHex('abc') // => 0xba80a53f981c4d0d ``` -## blake2AsHex128 - -Creates a blake2b hex with 128-bits from the input. - -```js -blake2AsHex128 (data: Uint8Array): string -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a hex string with 128 bits. - -```js -import { blake2AsHex128 } from '@polkadot/util-crypto'; - -blake2AsHex128('abc') // => 0x44bc2cf5ad770999 -``` - -## blake2AsHex256 - -Creates a blake2b hex with 256-bits from the input. - -```js -blake2AsHex256 (data: Uint8Array): string -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a hex string with 256 bits. - -```js -import { blake2AsHex256 } from '@polkadot/util-crypto'; - -blake2AsHex256('abc') // => 0x44bc2cf5ad770999 -``` - -## blake2AsHex512 - -Creates a blake2b hex with 512-bits from the input. - -```js -blake2AsHex512 (data: Uint8Array): string -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a hex string with 512 bits. - -```js -import { blake2AsHex512 } from '@polkadot/util-crypto'; - -blake2AsHex512('abc') // => 0x44bc2cf5ad770999 -``` - ## blake2AsU8a Creates a blake2b u8a from the input. @@ -94,55 +37,4 @@ From a `Uint8Array` input, create the blake2b and return the result as a u8a wit import { blake2AsU8a } from '@polkadot/util-crypto'; blake2AsU8a('abc') // => [0xba, 0x80, 0xa53, 0xf98, 0x1c, 0x4d, 0x0d] -``` - -## blake2AsU8a128 - -Creates a blake2b u8a with 128-bits from the input. - -```js -blake2AsU8a128 (data: Uint8Array): Uint8Array -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 128 bits. - -```js -import { blake2AsU8a128 } from '@polkadot/util-crypto'; - -blake2AsU8a128('abc') // => 0x44bc2cf5ad770999 -``` - -## blake2AsU8a256 - -Creates a blake2b u8a with 256-bits from the input. - -```js -blake2AsU8a256 (data: Uint8Array): Uint8Array -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 256 bits. - -```js -import { blake2AsU8a256 } from '@polkadot/util-crypto'; - -blake2AsU8a256('abc') // => 0x44bc2cf5ad770999 -``` - -## blake2AsU8a512 - -Creates a blake2b u8a with 512-bits from the input. - -```js -blake2AsU8a512 (data: Uint8Array): Uint8Array -``` - - -From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 512 bits. - -```js -import { blake2AsU8a512 } from '@polkadot/util-crypto'; - -blake2AsU8a512('abc') // => 0x44bc2cf5ad770999 ``` \ No newline at end of file diff --git a/packages/util-crypto/docs/xxhash.md b/packages/util-crypto/docs/xxhash.md index 70e5746fa..4c5a9bf07 100644 --- a/packages/util-crypto/docs/xxhash.md +++ b/packages/util-crypto/docs/xxhash.md @@ -3,11 +3,7 @@ Create xxhash64 values with specified bitlengths - [xxhashAsHex](#xxhashashex) Creates a xxhash64 hex from the input. -- [xxhashAsHex128](#xxhashashex128) Creates a xxhash64 hex with 128-bits from the input. -- [xxhashAsHex256](#xxhashashex256) Creates a xxhash64 hex with 256-bits from the input. - [xxhashAsU8a](#xxhashasu8a) Creates a xxhash64 u8a from the input. -- [xxhashAsU8a128](#xxhashasu8a128) Creates a xxhash64 u8a with 128-bits from the input. -- [xxhashAsU8a256](#xxhashasu8a256) Creates a xxhash64 u8a with 256-bits from the input. ## xxhashAsHex @@ -26,40 +22,6 @@ import { xxhashAsHex } from '@polkadot/util-crypto'; xxhashAsHex('abc') // => 0x44bc2cf5ad770999 ``` -## xxhashAsHex128 - -Creates a xxhash64 hex with 128-bits from the input. - -```js -xxhashAsHex128 (data: Buffer | Uint8Array | string): string -``` - - -From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with 128 bits. - -```js -import { xxhashAsHex128 } from '@polkadot/util-crypto'; - -xxhashAsHex128('abc') // => 0x44bc2cf5ad770999 -``` - -## xxhashAsHex256 - -Creates a xxhash64 hex with 256-bits from the input. - -```js -xxhashAsHex256 (data: Buffer | Uint8Array | string): string -``` - - -From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with 256 bits. - -```js -import { xxhashAsHex256 } from '@polkadot/util-crypto'; - -xxhashAsHex256('abc') // => 0x44bc2cf5ad770999bea9ca8199328908 -``` - ## xxhashAsU8a Creates a xxhash64 u8a from the input. @@ -75,38 +37,4 @@ From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 an import { xxhashAsU8a } from '@polkadot/util-crypto'; xxhashAsU8a('abc') // => 0x44bc2cf5ad770999 -``` - -## xxhashAsU8a128 - -Creates a xxhash64 u8a with 128-bits from the input. - -```js -xxhashAsU8a128 (data: Buffer | Uint8Array | string): Uint8Array -``` - - -From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a Uint8Array with 128 bits. - -```js -import { xxhashAsU8a128 } from '@polkadot/util-crypto'; - -xxhashAsU8a128('abc') // => 0x44bc2cf5ad770999 -``` - -## xxhashAsU8a256 - -Creates a xxhash64 u8a with 256-bits from the input. - -```js -xxhashAsU8a256 (data: Buffer | Uint8Array | string): Uint8Array -``` - - -From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a Uint8Array with 256 bits. - -```js -import { xxhashAsU8a256 } from '@polkadot/util-crypto'; - -xxhashAsU8a256('abc') // => 0x44bc2cf5ad770999 ``` \ No newline at end of file diff --git a/packages/util-crypto/src/blake2/asHex128.js b/packages/util-crypto/src/blake2/asHex128.js deleted file mode 100644 index c18d94c3d..000000000 --- a/packages/util-crypto/src/blake2/asHex128.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsHex = require('./asHex'); - -/** - @name blake2AsHex128 - @signature blake2AsHex128 (data: Uint8Array): string - @summary Creates a blake2b hex with 128-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a hex string with 128 bits. - @example - import { blake2AsHex128 } from '@polkadot/util-crypto'; - - blake2AsHex128('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsHex128 (data: Uint8Array): string { - return blake2AsHex(data, 128); -}; diff --git a/packages/util-crypto/src/blake2/asHex128.spec.js b/packages/util-crypto/src/blake2/asHex128.spec.js deleted file mode 100644 index c35ecbeca..000000000 --- a/packages/util-crypto/src/blake2/asHex128.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { blake2AsHex128 } = require('./index'); - -describe('blake2AsHex128', () => { - it('returns a 128-bit value (as specified)', () => { - expect( - blake2AsHex128('abc') - ).toEqual('0xcf4ab791c62b8d2b2109c90275287816'); - }); -}); diff --git a/packages/util-crypto/src/blake2/asHex256.js b/packages/util-crypto/src/blake2/asHex256.js deleted file mode 100644 index 79547b79a..000000000 --- a/packages/util-crypto/src/blake2/asHex256.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsHex = require('./asHex'); - -/** - @name blake2AsHex256 - @signature blake2AsHex256 (data: Uint8Array): string - @summary Creates a blake2b hex with 256-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a hex string with 256 bits. - @example - import { blake2AsHex256 } from '@polkadot/util-crypto'; - - blake2AsHex256('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsHex256 (data: Uint8Array): string { - return blake2AsHex(data, 256); -}; diff --git a/packages/util-crypto/src/blake2/asHex256.spec.js b/packages/util-crypto/src/blake2/asHex256.spec.js deleted file mode 100644 index 9ac2af697..000000000 --- a/packages/util-crypto/src/blake2/asHex256.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { blake2AsHex256 } = require('./index'); - -describe('blake2AsHex256', () => { - it('returns a 256-bit value (as specified)', () => { - expect( - blake2AsHex256('abc') - ).toEqual('0xbddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319'); - }); -}); diff --git a/packages/util-crypto/src/blake2/asHex512.js b/packages/util-crypto/src/blake2/asHex512.js deleted file mode 100644 index 75c0784c2..000000000 --- a/packages/util-crypto/src/blake2/asHex512.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsHex = require('./asHex'); - -/** - @name blake2AsHex512 - @signature blake2AsHex512 (data: Uint8Array): string - @summary Creates a blake2b hex with 512-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a hex string with 512 bits. - @example - import { blake2AsHex512 } from '@polkadot/util-crypto'; - - blake2AsHex512('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsHex512 (data: Uint8Array): string { - return blake2AsHex(data, 512); -}; diff --git a/packages/util-crypto/src/blake2/asHex512.spec.js b/packages/util-crypto/src/blake2/asHex512.spec.js deleted file mode 100644 index 8a3441088..000000000 --- a/packages/util-crypto/src/blake2/asHex512.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { blake2AsHex512 } = require('./index'); - -describe('blake2AsHex512', () => { - it('returns a 512-bit value (as specified)', () => { - expect( - blake2AsHex512('abc') - ).toEqual('0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923'); - }); -}); diff --git a/packages/util-crypto/src/blake2/asU8a128.js b/packages/util-crypto/src/blake2/asU8a128.js deleted file mode 100644 index 3e70d02f3..000000000 --- a/packages/util-crypto/src/blake2/asU8a128.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsU8a = require('./asU8a'); - -/** - @name blake2AsU8a128 - @signature blake2AsU8a128 (data: Uint8Array): Uint8Array - @summary Creates a blake2b u8a with 128-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 128 bits. - @example - import { blake2AsU8a128 } from '@polkadot/util-crypto'; - - blake2AsU8a128('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsU8a128 (data: Uint8Array): Uint8Array { - return blake2AsU8a(data, 128); -}; diff --git a/packages/util-crypto/src/blake2/asU8a128.spec.js b/packages/util-crypto/src/blake2/asU8a128.spec.js deleted file mode 100644 index cfb6f98ca..000000000 --- a/packages/util-crypto/src/blake2/asU8a128.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { blake2AsU8a128 } = require('./index'); - -describe('blake2AsU8a128', () => { - it('returns a 128-bit value (as specified)', () => { - expect( - blake2AsU8a128('abc') - ).toEqual( - new Uint8Array([207, 74, 183, 145, 198, 43, 141, 43, 33, 9, 201, 2, 117, 40, 120, 22]) - ); - }); -}); diff --git a/packages/util-crypto/src/blake2/asU8a256.js b/packages/util-crypto/src/blake2/asU8a256.js deleted file mode 100644 index 41819e3a9..000000000 --- a/packages/util-crypto/src/blake2/asU8a256.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsU8a = require('./asU8a'); - -/** - @name blake2AsU8a256 - @signature blake2AsU8a256 (data: Uint8Array): Uint8Array - @summary Creates a blake2b u8a with 256-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 256 bits. - @example - import { blake2AsU8a256 } from '@polkadot/util-crypto'; - - blake2AsU8a256('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsU8a256 (data: Uint8Array, key?: Uint8Array): Uint8Array { - return blake2AsU8a(data, 256, key); -}; diff --git a/packages/util-crypto/src/blake2/asU8a256.spec.js b/packages/util-crypto/src/blake2/asU8a256.spec.js deleted file mode 100644 index d02f99ea6..000000000 --- a/packages/util-crypto/src/blake2/asU8a256.spec.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { blake2AsU8a256 } = require('./index'); - -describe('blake2AsU8a256', () => { - it('returns a 256-bit value (as specified)', () => { - expect( - blake2AsU8a256('abc') - ).toEqual( - new Uint8Array([189, 221, 129, 60, 99, 66, 57, 114, 49, 113, 239, 63, 238, 152, 87, 155, 148, 150, 78, 59, 177, 203, 62, 66, 114, 98, 200, 192, 104, 213, 35, 25]) - ); - }); -}); diff --git a/packages/util-crypto/src/blake2/asU8a512.js b/packages/util-crypto/src/blake2/asU8a512.js deleted file mode 100644 index 4de94d7ea..000000000 --- a/packages/util-crypto/src/blake2/asU8a512.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const blake2AsU8a = require('./asU8a'); - -/** - @name blake2AsU8a512 - @signature blake2AsU8a512 (data: Uint8Array): Uint8Array - @summary Creates a blake2b u8a with 512-bits from the input. - @description - From a `Uint8Array` input, create the blake2b and return the result as a Uint8Array with 512 bits. - @example - import { blake2AsU8a512 } from '@polkadot/util-crypto'; - - blake2AsU8a512('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function blake2AsU8a512 (data: Uint8Array): Uint8Array { - return blake2AsU8a(data, 512); -}; diff --git a/packages/util-crypto/src/blake2/asU8a512.spec.js b/packages/util-crypto/src/blake2/asU8a512.spec.js deleted file mode 100644 index bf773ae89..000000000 --- a/packages/util-crypto/src/blake2/asU8a512.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const hexToU8a = require('@polkadot/util/hex/toU8a'); - -const { blake2AsU8a512 } = require('./index'); - -describe('blake2AsU8a512', () => { - it('returns a 512-bit value (as specified)', () => { - expect( - blake2AsU8a512('abc') - ).toEqual( - hexToU8a('0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923') - ); - }); -}); diff --git a/packages/util-crypto/src/blake2/index.js b/packages/util-crypto/src/blake2/index.js index 3f652f4ff..ee65e38d8 100644 --- a/packages/util-crypto/src/blake2/index.js +++ b/packages/util-crypto/src/blake2/index.js @@ -4,24 +4,12 @@ // @flow const blake2AsHex = require('./asHex'); -const blake2AsHex128 = require('./asHex128'); -const blake2AsHex256 = require('./asHex256'); -const blake2AsHex512 = require('./asHex512'); const blake2AsU8a = require('./asU8a'); -const blake2AsU8a128 = require('./asU8a128'); -const blake2AsU8a256 = require('./asU8a256'); -const blake2AsU8a512 = require('./asU8a512'); /** @summary Create blake2b values with specified bitlengths */ module.exports = { blake2AsHex, - blake2AsHex128, - blake2AsHex256, - blake2AsHex512, - blake2AsU8a, - blake2AsU8a128, - blake2AsU8a256, - blake2AsU8a512 + blake2AsU8a }; diff --git a/packages/util-crypto/src/kdf/asU8a.js b/packages/util-crypto/src/kdf/asU8a.js index d45c29e55..ce25f370d 100644 --- a/packages/util-crypto/src/kdf/asU8a.js +++ b/packages/util-crypto/src/kdf/asU8a.js @@ -12,7 +12,7 @@ type KdfU8a = { const isU8a = require('@polkadot/util/is/u8a'); const u8aFromUtf8 = require('@polkadot/util/u8a/fromUtf8'); -const blake2AsU8a256 = require('../blake2/asU8a256'); +const blake2AsU8a = require('../blake2/asU8a'); const randomAsU8a = require('../random/asU8a'); /** @@ -35,7 +35,7 @@ module.exports = function kdfAsU8a (secret: Uint8Array | string, _rounds: number : u8aFromUtf8(((secret: any): string)); for (let count = 0; count < rounds; count++) { - key = blake2AsU8a256(key, salt); + key = blake2AsU8a(key, 256, salt); } return { diff --git a/packages/util-crypto/src/nacl/keypair/fromString.js b/packages/util-crypto/src/nacl/keypair/fromString.js index 19fc35dbf..322f187c5 100644 --- a/packages/util-crypto/src/nacl/keypair/fromString.js +++ b/packages/util-crypto/src/nacl/keypair/fromString.js @@ -7,7 +7,7 @@ import type { KeypairType } from '../../types'; const u8aFromUtf8 = require('@polkadot/util/u8a/fromUtf8'); -const blake2AsU8a256 = require('../../blake2/asU8a256'); +const blake2AsU8a = require('../../blake2/asU8a'); const fromSeed = require('./fromSeed'); /** @@ -23,8 +23,9 @@ const fromSeed = require('./fromSeed'); */ module.exports = function naclKeypairFromString (value: string): KeypairType { return fromSeed( - blake2AsU8a256( - u8aFromUtf8(value) + blake2AsU8a( + u8aFromUtf8(value), + 256 ) ); }; diff --git a/packages/util-crypto/src/xxhash/asHex128.js b/packages/util-crypto/src/xxhash/asHex128.js deleted file mode 100644 index f4cf976d0..000000000 --- a/packages/util-crypto/src/xxhash/asHex128.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const xxhashAsHex = require('./asHex'); - -/** - @name xxhashAsHex128 - @signature xxhashAsHex128 (data: Buffer | Uint8Array | string): string - @summary Creates a xxhash64 hex with 128-bits from the input. - @description - From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with 128 bits. - @example - import { xxhashAsHex128 } from '@polkadot/util-crypto'; - - xxhashAsHex128('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function xxhashAsHex128 (data: Buffer | Uint8Array | string): string { - return xxhashAsHex(data, 128); -}; diff --git a/packages/util-crypto/src/xxhash/asHex128.spec.js b/packages/util-crypto/src/xxhash/asHex128.spec.js deleted file mode 100644 index 6105c5a9c..000000000 --- a/packages/util-crypto/src/xxhash/asHex128.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const hexToU8a = require('@polkadot/util/hex/toU8a'); - -const { xxhashAsHex128 } = require('./index'); - -describe('xxhashAsHex128', () => { - it('returns a 128-bit value (as specified)', () => { - expect( - xxhashAsHex128('abc') - ).toEqual('0x990977adf52cbc440889329981caa9be'); - }); - - it('matches with Rust implementation', () => { - expect( - xxhashAsHex128( - hexToU8a('0x7379733a6e6f6e3a2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee') - ) - ).toEqual( - '0xc7f790aa4fc95a8813b0d5734a8c195b' - ); - }); -}); diff --git a/packages/util-crypto/src/xxhash/asHex256.js b/packages/util-crypto/src/xxhash/asHex256.js deleted file mode 100644 index 754e9ecb2..000000000 --- a/packages/util-crypto/src/xxhash/asHex256.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const xxhashAsHex = require('./asHex'); - -/** - @name xxhashAsHex256 - @signature xxhashAsHex256 (data: Buffer | Uint8Array | string): string - @summary Creates a xxhash64 hex with 256-bits from the input. - @description - From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with 256 bits. - @example - import { xxhashAsHex256 } from '@polkadot/util-crypto'; - - xxhashAsHex256('abc') // => 0x44bc2cf5ad770999bea9ca8199328908 -*/ -module.exports = function xxhashAsHex256 (data: Buffer | Uint8Array | string): string { - return xxhashAsHex(data, 256); -}; diff --git a/packages/util-crypto/src/xxhash/asHex256.spec.js b/packages/util-crypto/src/xxhash/asHex256.spec.js deleted file mode 100644 index 2af877d0b..000000000 --- a/packages/util-crypto/src/xxhash/asHex256.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const { xxhashAsHex256 } = require('./index'); - -describe('xxhashAsHex256', () => { - it('returns a 256-bit value (as specified)', () => { - expect( - xxhashAsHex256('abc') - ).toEqual('0x990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b'); - }); -}); diff --git a/packages/util-crypto/src/xxhash/asU8a128.js b/packages/util-crypto/src/xxhash/asU8a128.js deleted file mode 100644 index 5bbec928c..000000000 --- a/packages/util-crypto/src/xxhash/asU8a128.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const xxhashAsU8a = require('./asU8a'); - -/** - @name xxhashAsU8a128 - @signature xxhashAsU8a128 (data: Buffer | Uint8Array | string): Uint8Array - @summary Creates a xxhash64 u8a with 128-bits from the input. - @description - From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a Uint8Array with 128 bits. - @example - import { xxhashAsU8a128 } from '@polkadot/util-crypto'; - - xxhashAsU8a128('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function xxhashAsU8a128 (data: Buffer | Uint8Array | string): Uint8Array { - return xxhashAsU8a(data, 128); -}; diff --git a/packages/util-crypto/src/xxhash/asU8a128.spec.js b/packages/util-crypto/src/xxhash/asU8a128.spec.js deleted file mode 100644 index e457b4c54..000000000 --- a/packages/util-crypto/src/xxhash/asU8a128.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const hexToU8a = require('@polkadot/util/hex/toU8a'); - -const { xxhashAsU8a128 } = require('./index'); - -describe('xxhashAsU8a128', () => { - it('returns a 128-bit value (as specified)', () => { - expect( - xxhashAsU8a128('abc') - ).toEqual( - hexToU8a('0x990977adf52cbc440889329981caa9be') - ); - }); -}); diff --git a/packages/util-crypto/src/xxhash/asU8a256.js b/packages/util-crypto/src/xxhash/asU8a256.js deleted file mode 100644 index 97bd8ba53..000000000 --- a/packages/util-crypto/src/xxhash/asU8a256.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. -// @flow - -const xxhashAsU8a = require('./asU8a'); - -/** - @name xxhashAsU8a256 - @signature xxhashAsU8a256 (data: Buffer | Uint8Array | string): Uint8Array - @summary Creates a xxhash64 u8a with 256-bits from the input. - @description - From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a Uint8Array with 256 bits. - @example - import { xxhashAsU8a256 } from '@polkadot/util-crypto'; - - xxhashAsU8a256('abc') // => 0x44bc2cf5ad770999 -*/ -module.exports = function xxhashAsU8a256 (data: Buffer | Uint8Array | string): Uint8Array { - return xxhashAsU8a(data, 256); -}; diff --git a/packages/util-crypto/src/xxhash/asU8a256.spec.js b/packages/util-crypto/src/xxhash/asU8a256.spec.js deleted file mode 100644 index 2b1e86dd5..000000000 --- a/packages/util-crypto/src/xxhash/asU8a256.spec.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017-2018 Jaco Greeff -// This software may be modified and distributed under the terms -// of the ISC license. See the LICENSE file for details. - -const hexToU8a = require('@polkadot/util/hex/toU8a'); - -const { xxhashAsU8a256 } = require('./index'); - -describe('xxhashAsU8a256', () => { - it('returns a 256-bit value (as specified)', () => { - expect( - xxhashAsU8a256('abc') - ).toEqual( - hexToU8a('0x990977adf52cbc440889329981caa9bef7da5770b2b8a05303b75d95360dd62b') - ); - }); -}); diff --git a/packages/util-crypto/src/xxhash/index.js b/packages/util-crypto/src/xxhash/index.js index 1580977e5..1c760ffb9 100644 --- a/packages/util-crypto/src/xxhash/index.js +++ b/packages/util-crypto/src/xxhash/index.js @@ -4,20 +4,12 @@ // @flow const xxhashAsHex = require('./asHex'); -const xxhashAsHex128 = require('./asHex128'); -const xxhashAsHex256 = require('./asHex256'); const xxhashAsU8a = require('./asU8a'); -const xxhashAsU8a128 = require('./asU8a128'); -const xxhashAsU8a256 = require('./asU8a256'); /** @summary Create xxhash64 values with specified bitlengths */ module.exports = { xxhashAsHex, - xxhashAsHex128, - xxhashAsHex256, - xxhashAsU8a, - xxhashAsU8a128, - xxhashAsU8a256 + xxhashAsU8a }; diff --git a/packages/util-keyring/src/address/decode.js b/packages/util-keyring/src/address/decode.js index 3a46ce178..adb2e4372 100644 --- a/packages/util-keyring/src/address/decode.js +++ b/packages/util-keyring/src/address/decode.js @@ -11,7 +11,7 @@ const bufferToU8a = require('@polkadot/util/buffer/toU8a'); const isHex = require('@polkadot/util/is/hex'); const isU8a = require('@polkadot/util/is/u8a'); const u8aToU8a = require('@polkadot/util/u8a/toU8a'); -const blake2b = require('@polkadot/util-crypto/blake2/asU8a512'); +const blake2b = require('@polkadot/util-crypto/blake2/asU8a'); module.exports = function decode (encoded: string | Uint8Array): Uint8Array { if (isU8a(encoded) || isHex(encoded)) { @@ -24,7 +24,7 @@ module.exports = function decode (encoded: string | Uint8Array): Uint8Array { assert(decoded[0] === 42, 'Invalid decoded address prefix'); assert(decoded.length === 32 + 1 + 2, 'Invalid decoded address length'); - const hash = blake2b(decoded.subarray(0, 33)); + const hash = blake2b(decoded.subarray(0, 33), 512); assert(decoded[33] === hash[0] && decoded[34] === hash[1], 'Invalid decoded address checksum'); diff --git a/packages/util-keyring/src/address/encode.js b/packages/util-keyring/src/address/encode.js index 1ab64ad0c..d7a776657 100644 --- a/packages/util-keyring/src/address/encode.js +++ b/packages/util-keyring/src/address/encode.js @@ -10,7 +10,7 @@ const assert = require('@polkadot/util/assert'); const u8aConcat = require('@polkadot/util/u8a/concat'); const u8aToBuffer = require('@polkadot/util/u8a/toBuffer'); const u8aToU8a = require('@polkadot/util/u8a/toU8a'); -const blake2b = require('@polkadot/util-crypto/blake2/asU8a512'); +const blake2b = require('@polkadot/util-crypto/blake2/asU8a'); const PREFIX = new Uint8Array([42]); @@ -20,7 +20,7 @@ module.exports = function encode (_publicKey: Uint8Array | string): string { assert(publicKey.length === 32, `Expected a valid publicKey to convert`); const input = u8aConcat(PREFIX, publicKey); - const hash = blake2b(input); + const hash = blake2b(input, 512); return bs58.encode( u8aToBuffer( diff --git a/packages/util-keyring/src/pair/decode.js b/packages/util-keyring/src/pair/decode.js index e99fdc171..c5c977543 100644 --- a/packages/util-keyring/src/pair/decode.js +++ b/packages/util-keyring/src/pair/decode.js @@ -17,7 +17,7 @@ const SEED_OFFSET = PKCS8_HEADER.length; const DIV_OFFSET = SEED_OFFSET + KEY_LENGTH; const PUBLIC_OFFSET = SEED_OFFSET + KEY_LENGTH + PKCS8_DIVIDER.length; -module.exports = function decode (_encrypted?: Uint8Array, passphrase?: string) { +module.exports = function decode (passphrase?: string, _encrypted?: Uint8Array) { assert(_encrypted, `No encrypted data available to decode`); // flowlint-next-line unclear-type:off diff --git a/packages/util-keyring/src/pair/decode.spec.js b/packages/util-keyring/src/pair/decode.spec.js index 10e37c57b..251e2569b 100644 --- a/packages/util-keyring/src/pair/decode.spec.js +++ b/packages/util-keyring/src/pair/decode.spec.js @@ -14,7 +14,7 @@ describe('decode', () => { it('returns correct publicKey from encoded', () => { expect( () => keyring.alice.decodePkcs8( - keyring.alice.encodePkcs8('testing'), 'testing' + 'testing', keyring.alice.encodePkcs8('testing') ) ).not.toThrow(); }); diff --git a/packages/util-keyring/src/pair/index.js b/packages/util-keyring/src/pair/index.js index 8d6222d0e..65c607007 100644 --- a/packages/util-keyring/src/pair/index.js +++ b/packages/util-keyring/src/pair/index.js @@ -26,8 +26,8 @@ module.exports = function pair ({ publicKey, secretKey }: $Shape, m return { address: (): string => state.address, - decodePkcs8: (encoded?: Uint8Array, passphrase?: string): void => { - const decoded = decode(encoded || defaultEncoded, passphrase); + decodePkcs8: (passphrase?: string, encoded?: Uint8Array): void => { + const decoded = decode(passphrase, encoded || defaultEncoded); publicKey = decoded.publicKey; secretKey = decoded.secretKey; diff --git a/packages/util-keyring/src/types.js b/packages/util-keyring/src/types.js index 9e67a9dc2..03f2d2523 100644 --- a/packages/util-keyring/src/types.js +++ b/packages/util-keyring/src/types.js @@ -21,7 +21,7 @@ export type KeyringPair$Json = { export type KeyringPair = { address: () => string, - decodePkcs8: (encoded: Uint8Array, passphrase?: string) => void, + decodePkcs8: (passphrase?: string, encoded?: Uint8Array) => void, encodePkcs8: (passphrase?: string) => Uint8Array, getMeta: () => KeyringPair$Meta, hasSecretKey: () => boolean,