pull/15/head
pubkey 7 years ago
parent 226e89a878
commit 16ff91d695
  1. 11
      dist/es/recover-public-key.js
  2. 15
      dist/lib/recover-public-key.js
  3. 2
      package.json

@ -1,6 +1,4 @@
import { recover } from 'secp256k1';
import * as vrs from './vrs';
import { removeTrailing0x } from './util';
/**
@ -10,12 +8,13 @@ import { removeTrailing0x } from './util';
* @return {string} publicKey
*/
export default function recoverPublicKey(signature, hash) {
var vals = vrs.fromString(signature);
signature = removeTrailing0x(signature);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = removeTrailing0x(sigOnly);
// split into v-value and sig
var sigOnly = signature.substring(0, signature.length - 2); // all but last 2 chars
var vValue = signature.slice(-2); // last 2 chars
var recoveryNumber = vals.v === '0x1c' ? 1 : 0;
var recoveryNumber = vValue === '1c' ? 1 : 0;
var pubKey = recover(new Buffer(removeTrailing0x(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');

@ -7,14 +7,8 @@ exports['default'] = recoverPublicKey;
var _secp256k = require('secp256k1');
var _vrs = require('./vrs');
var vrs = _interopRequireWildcard(_vrs);
var _util = require('./util');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
/**
* returns the publicKey for the privateKey with which the messageHash was signed
* @param {string} signature
@ -22,12 +16,13 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
* @return {string} publicKey
*/
function recoverPublicKey(signature, hash) {
var vals = vrs.fromString(signature);
signature = (0, _util.removeTrailing0x)(signature);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = (0, _util.removeTrailing0x)(sigOnly);
// split into v-value and sig
var sigOnly = signature.substring(0, signature.length - 2); // all but last 2 chars
var vValue = signature.slice(-2); // last 2 chars
var recoveryNumber = vals.v === '0x1c' ? 1 : 0;
var recoveryNumber = vValue === '1c' ? 1 : 0;
var pubKey = (0, _secp256k.recover)(new Buffer((0, _util.removeTrailing0x)(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');

@ -1,6 +1,6 @@
{
"name": "eth-crypto",
"version": "1.1.0",
"version": "1.1.1",
"description": "Cryptographic functions for ethereum and how to use them with web3 and solidity",
"keywords": [
"ethereum",

Loading…
Cancel
Save