Curve conversion tests (#1214)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { convertPublicKeyToCurve25519, convertSecretKeyToCurve25519 } from '.';
|
||||
|
||||
describe('convertPublicKeyToCurve25519', (): void => {
|
||||
it('converts a known key correctly', (): void => {
|
||||
expect(
|
||||
u8aToHex(convertPublicKeyToCurve25519(
|
||||
new Uint8Array([
|
||||
180, 114, 93, 155, 165, 255, 217, 82,
|
||||
16, 250, 209, 11, 193, 10, 88, 218,
|
||||
190, 190, 41, 193, 236, 252, 1, 152,
|
||||
216, 214, 0, 41, 45, 138, 13, 53
|
||||
])
|
||||
))
|
||||
).toEqual('0x5e05848ceeef4f306d6e285a26faf1a8070cf0c89f8d28ab966002fe4ad17746');
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertSecretKeyToCurve25519', (): void => {
|
||||
it('converts a known key correctly', (): void => {
|
||||
expect(
|
||||
u8aToHex(convertSecretKeyToCurve25519(
|
||||
new Uint8Array([
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8
|
||||
])
|
||||
))
|
||||
).toEqual('0xd875a82940b9174dabb1c0c895485810cc2870f5808565b59d4ef708bdcf526c');
|
||||
});
|
||||
});
|
||||
@@ -3,10 +3,12 @@
|
||||
|
||||
import ed2curve from 'ed2curve';
|
||||
|
||||
import { assertReturn } from '@polkadot/util';
|
||||
|
||||
export function convertSecretKeyToCurve25519 (secretKey: Uint8Array): Uint8Array {
|
||||
return ed2curve.convertSecretKey(secretKey);
|
||||
}
|
||||
|
||||
export function convertPublicKeyToCurve25519 (publicKey: Uint8Array): Uint8Array {
|
||||
return ed2curve.convertPublicKey(publicKey) as Uint8Array;
|
||||
return assertReturn(ed2curve.convertPublicKey(publicKey), 'Unable to convert publicKey to ed25519');
|
||||
}
|
||||
|
||||
@@ -7,7 +7,12 @@ import { waitReady } from '@polkadot/wasm-crypto';
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { pbkdf2Encode } from '.';
|
||||
|
||||
const KNOWN_SALT = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]);
|
||||
const KNOWN_SALT = new Uint8Array([
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24,
|
||||
25, 26, 27, 28, 29, 30, 31, 32
|
||||
]);
|
||||
const TEST_PASSWORD = 'test password';
|
||||
|
||||
describe('pbkdf2Encode', (): void => {
|
||||
|
||||
Reference in New Issue
Block a user