Expand keyring tests for sr25519 (#302)
* Expand keyring tests for sr25519 * Update index.spec.ts * Update index.spec.ts * Support type conversion, type per pair * toType tests
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as schnorrkelKeypairFromRandom } from './keypair/fromRandom';
|
||||
export { default as schnorrkelKeypairFromSeed } from './keypair/fromSeed';
|
||||
export { default as schnorrkelSign } from './sign';
|
||||
export { default as schnorrkelVerify } from './verify';
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { schnorrkelKeypairFromRandom } from '../index';
|
||||
|
||||
describe('schnorrkelKeypairFromRandom', () => {
|
||||
it('generates a valid publicKey', () => {
|
||||
expect(
|
||||
schnorrkelKeypairFromRandom().publicKey
|
||||
).toHaveLength(32);
|
||||
});
|
||||
|
||||
it('generates a valid secretKey', () => {
|
||||
expect(
|
||||
schnorrkelKeypairFromRandom().secretKey
|
||||
).toHaveLength(64);
|
||||
});
|
||||
});
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// 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 randomAsU8a from '../../random/asU8a';
|
||||
import fromSeed from './fromSeed';
|
||||
|
||||
/**
|
||||
* @name schnorrkelKeypairFromRandom
|
||||
* @description Returns a new generate object containing a `publicKey` & `secretKey`.
|
||||
*/
|
||||
export default function schnorrkelKeypairFromRandom (): KeypairType {
|
||||
return fromSeed(randomAsU8a(32));
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
import { stringToU8a } from '@polkadot/util/index';
|
||||
|
||||
import pairFromRandom from './keypair/fromRandom';
|
||||
import randomAsU8a from '../random/asU8a';
|
||||
import pairFromSeed from './keypair/fromSeed';
|
||||
import sign from './sign';
|
||||
import verify from './verify';
|
||||
|
||||
@@ -12,13 +13,13 @@ const MESSAGE = stringToU8a('this is a message');
|
||||
|
||||
describe('sign and verify', () => {
|
||||
it('has 64-byte signatures', () => {
|
||||
const pair = pairFromRandom();
|
||||
const pair = pairFromSeed(randomAsU8a());
|
||||
|
||||
expect(sign(MESSAGE, pair)).toHaveLength(64);
|
||||
});
|
||||
|
||||
it('can sign and verify a message', () => {
|
||||
const pair = pairFromRandom();
|
||||
const pair = pairFromSeed(randomAsU8a());
|
||||
const signature = sign(MESSAGE, pair);
|
||||
|
||||
expect(verify(MESSAGE, signature, pair.publicKey)).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user