state-channel
pubkey 7 years ago
parent 51b91c4057
commit 57afda2939
  1. 28
      dist/es/recover-public-key.js
  2. 10
      dist/es/recover.js
  3. 1
      dist/es/vrs.js
  4. 34
      dist/lib/recover-public-key.js
  5. 14
      dist/lib/recover.js
  6. 4
      dist/lib/vrs.js
  7. 2
      package.json

@ -1,9 +1,7 @@
import { decodeSignature, toChecksum } from 'eth-lib/lib/account';
import Bytes from 'eth-lib/lib/bytes';
import * as vrs from './vrs';
import * as secp256k1 from 'secp256k1';
import elliptic from 'elliptic';
var secp256k1 = new elliptic.ec('secp256k1');
import * as vrs from './vrs';
import * as util from './util';
/**
* returns the publicKey for the privateKEy with which the messageHash was signed
@ -12,17 +10,17 @@ var secp256k1 = new elliptic.ec('secp256k1');
* @return {string} publicKey
*/
export default function recoverPublicKey(signature, hash) {
// parse signature
var vals = vrs.fromString(signature);
var vrsOfSig = {
v: Bytes.toNumber(vals.v),
r: vals.r.slice(2),
s: vals.s.slice(2)
};
// because odd vals mean v=0... sadly that means v=0 means v=1... I hate that
var ecPublicKey = secp256k1.recoverPubKey(new Buffer(hash.slice(2), 'hex'), vrsOfSig, vrsOfSig.v < 2 ? vrsOfSig.v : 1 - vrsOfSig.v % 2);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = util.removeTrailing0x(sigOnly);
var recoveryNumber = vals.v === '0x1c' ? 1 : 0;
var pubKey = secp256k1.recover(new Buffer(util.removeTrailing0x(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
// remove trailing '04'
pubKey = pubKey.slice(2);
var publicKey = ecPublicKey.encode('hex', false).slice(2);
return publicKey;
return pubKey;
}

10
dist/es/recover.js vendored

@ -1,12 +1,14 @@
import Account from 'eth-lib/lib/account';
import vrs from './vrs';
import recoverPublicKey from './recover-public-key';
import addressByPublicKey from './address-by-public-key';
/**
* returns the adress with which the messageHash was signed
* @param {string} hexString
* @param {string} sigString
* @param {string} hash
* @return {string} address
*/
export default function recover(sigString, hash) {
return Account.recover(hash, sigString);
var pubkey = recoverPublicKey(sigString, hash);
var address = addressByPublicKey(pubkey);
return address;
}

1
dist/es/vrs.js vendored

@ -1,5 +1,4 @@
import Account from 'eth-lib/lib/account';
import Bytes from 'eth-lib/lib/bytes';
/**
* split signature-hex into parts

@ -5,26 +5,20 @@ Object.defineProperty(exports, "__esModule", {
});
exports['default'] = recoverPublicKey;
var _account = require('eth-lib/lib/account');
var _secp256k = require('secp256k1');
var _bytes = require('eth-lib/lib/bytes');
var _bytes2 = _interopRequireDefault(_bytes);
var secp256k1 = _interopRequireWildcard(_secp256k);
var _vrs = require('./vrs');
var vrs = _interopRequireWildcard(_vrs);
var _elliptic = require('elliptic');
var _util = require('./util');
var _elliptic2 = _interopRequireDefault(_elliptic);
var util = _interopRequireWildcard(_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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var secp256k1 = new _elliptic2['default'].ec('secp256k1');
/**
* returns the publicKey for the privateKEy with which the messageHash was signed
* @param {string} signature
@ -32,17 +26,17 @@ var secp256k1 = new _elliptic2['default'].ec('secp256k1');
* @return {string} publicKey
*/
function recoverPublicKey(signature, hash) {
// parse signature
var vals = vrs.fromString(signature);
var vrsOfSig = {
v: _bytes2['default'].toNumber(vals.v),
r: vals.r.slice(2),
s: vals.s.slice(2)
};
// because odd vals mean v=0... sadly that means v=0 means v=1... I hate that
var ecPublicKey = secp256k1.recoverPubKey(new Buffer(hash.slice(2), 'hex'), vrsOfSig, vrsOfSig.v < 2 ? vrsOfSig.v : 1 - vrsOfSig.v % 2);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = util.removeTrailing0x(sigOnly);
var recoveryNumber = vals.v === '0x1c' ? 1 : 0;
var pubKey = secp256k1.recover(new Buffer(util.removeTrailing0x(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
// remove trailing '04'
pubKey = pubKey.slice(2);
var publicKey = ecPublicKey.encode('hex', false).slice(2);
return publicKey;
return pubKey;
}

@ -5,22 +5,24 @@ Object.defineProperty(exports, "__esModule", {
});
exports['default'] = recover;
var _account = require('eth-lib/lib/account');
var _recoverPublicKey = require('./recover-public-key');
var _account2 = _interopRequireDefault(_account);
var _recoverPublicKey2 = _interopRequireDefault(_recoverPublicKey);
var _vrs = require('./vrs');
var _addressByPublicKey = require('./address-by-public-key');
var _vrs2 = _interopRequireDefault(_vrs);
var _addressByPublicKey2 = _interopRequireDefault(_addressByPublicKey);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* returns the adress with which the messageHash was signed
* @param {string} hexString
* @param {string} sigString
* @param {string} hash
* @return {string} address
*/
function recover(sigString, hash) {
return _account2['default'].recover(hash, sigString);
var pubkey = (0, _recoverPublicKey2['default'])(sigString, hash);
var address = (0, _addressByPublicKey2['default'])(pubkey);
return address;
}

4
dist/lib/vrs.js vendored

@ -10,10 +10,6 @@ var _account = require('eth-lib/lib/account');
var _account2 = _interopRequireDefault(_account);
var _bytes = require('eth-lib/lib/bytes');
var _bytes2 = _interopRequireDefault(_bytes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**

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

Loading…
Cancel
Save