Introduce key suri (path derivation) (#358)

* Introduce key suri (path derivation)

* Errant console.log

* let -> const

* Add seed derivation from path

* Allow new-generation derivation

* Add addFromUri to keyring

* Use addFromUri in testing keyring

* Add suri tests

* Prepare for sr25519 derivation

* CHANGELOG entry

* ed25519 is aligned with substrate

* Bump version
This commit is contained in:
Jaco Greeff
2019-03-13 14:39:10 +01:00
committed by GitHub
parent a1e56cfb81
commit f1ca4eef0e
37 changed files with 564 additions and 120 deletions
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../../types';
import { Keypair } from '../../types';
import { naclKeypairFromRandom } from '../index';
describe('naclKeypairFromRandom', () => {
let keypair: KeypairType;
let keypair: Keypair;
beforeEach(() => {
keypair = naclKeypairFromRandom();
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../../types';
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
@@ -20,6 +20,6 @@ import nacl from 'tweetnacl';
* naclKeypairFromRandom(); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export default function naclKeypairFromRandom (): KeypairType {
export default function naclKeypairFromRandom (): Keypair {
return nacl.sign.keyPair();
}
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../../types';
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
@@ -20,6 +20,6 @@ import nacl from 'tweetnacl';
* naclKeypairFromSecret(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export default function naclKeypairFromSecret (secret: Uint8Array): KeypairType {
export default function naclKeypairFromSecret (secret: Uint8Array): Keypair {
return nacl.sign.keyPair.fromSecretKey(secret);
}
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../../types';
import { Keypair } from '../../types';
import nacl from 'tweetnacl';
@@ -20,6 +20,6 @@ import nacl from 'tweetnacl';
* naclKeypairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export default function naclKeypairFromSeed (seed: Uint8Array): KeypairType {
export default function naclKeypairFromSeed (seed: Uint8Array): Keypair {
return nacl.sign.keyPair.fromSeed(seed);
}
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../../types';
import { Keypair } from '../../types';
import { stringToU8a } from '@polkadot/util/index';
@@ -23,7 +23,7 @@ import fromSeed from './fromSeed';
* naclKeypairFromString('test'); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export default function naclKeypairFromString (value: string): KeypairType {
export default function naclKeypairFromString (value: string): Keypair {
return fromSeed(
blake2AsU8a(
stringToU8a(value),
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeypairType } from '../types';
import { Keypair } from '../types';
import nacl from 'tweetnacl';
import { assert } from '@polkadot/util/index';
@@ -21,7 +21,7 @@ import { assert } from '@polkadot/util/index';
* naclSign([...], [...]); // => [...]
* ```
*/
export default function naclSign (message: Uint8Array, { secretKey }: Partial<KeypairType>): Uint8Array {
export default function naclSign (message: Uint8Array, { secretKey }: Partial<Keypair>): Uint8Array {
assert(secretKey && secretKey.length === 64, 'Expected valid secretKey, 64 bytes');
return nacl.sign.detached(message, secretKey as Uint8Array);