Add secp256k1Recover (#323)

This commit is contained in:
Jaco Greeff
2019-02-21 14:27:35 +01:00
committed by GitHub
parent c340f7dbf5
commit c5e0faca60
6 changed files with 143 additions and 9 deletions
+1
View File
@@ -10,6 +10,7 @@ export * from './mnemonic';
export * from './nacl';
export * from './random';
export * from './schnorrkel';
export * from './secp256k1';
export * from './sha512';
export * from './xxhash';
@@ -0,0 +1,5 @@
// 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.
export { default as secp256k1Recover } from './recover';
@@ -0,0 +1,19 @@
// 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 secp256k1 from 'secp256k1';
import { bufferToU8a, u8aToBuffer } from '@polkadot/util/index';
/**
* @name secp256k1Recover
* @description Recovers a publicKey from the supplied signature
*/
export default function secp256k1Recover (_message: Uint8Array, _signature: Uint8Array, recovery: number): Uint8Array {
const message = u8aToBuffer(_message);
const signature = u8aToBuffer(_signature);
return bufferToU8a(
secp256k1.recover(message, signature, recovery)
);
}