Update keyring usage (#128)

* Update keyring usage

* Remove "fluffy" asU8a{128,256,512} operations
This commit is contained in:
Jaco Greeff
2018-05-22 15:44:34 +02:00
committed by GitHub
parent 07871bdc54
commit 7075495efd
32 changed files with 17 additions and 584 deletions
-108
View File
@@ -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
```
-72
View File
@@ -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
```
@@ -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);
};
@@ -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');
});
});
@@ -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);
};
@@ -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');
});
});
@@ -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);
};
@@ -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');
});
});
@@ -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);
};
@@ -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])
);
});
});
@@ -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);
};
@@ -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])
);
});
});
@@ -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);
};
@@ -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')
);
});
});
+1 -13
View File
@@ -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
};
+2 -2
View File
@@ -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 {
@@ -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
)
);
};
@@ -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);
};
@@ -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'
);
});
});
@@ -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);
};
@@ -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');
});
});
@@ -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);
};
@@ -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')
);
});
});
@@ -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);
};
@@ -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')
);
});
});
+1 -9
View File
@@ -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
};
+2 -2
View File
@@ -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');
+2 -2
View File
@@ -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(
+1 -1
View File
@@ -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
@@ -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();
});
+2 -2
View File
@@ -26,8 +26,8 @@ module.exports = function pair ({ publicKey, secretKey }: $Shape<KeypairType>, 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;
+1 -1
View File
@@ -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,