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
+2
View File
@@ -32,11 +32,13 @@
"@polkadot/schnorrkel-js": "^0.1.2-1",
"@polkadot/util": "^0.34.21",
"@types/bip39": "^2.4.2",
"@types/secp256k1": "^3.5.0",
"@types/webassembly-js-api": "^0.0.2",
"@types/xxhashjs": "^0.2.0",
"bip39": "^2.5.0",
"blakejs": "^1.1.0",
"js-sha3": "^0.8.0",
"secp256k1": "^3.6.2",
"tweetnacl": "^1.0.1",
"xxhashjs": "^0.2.2"
}
+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)
);
}