pull/15/head
pubkey 7 years ago
parent d4fc858aac
commit 17364c9ad4
  1. 13
      dist/es/address-by-public-key.js
  2. 15
      dist/es/create-identity.js
  3. 10
      dist/es/encrypt-with-public-key.js
  4. 14
      dist/es/hash.js
  5. 8
      dist/es/hex.js
  6. 7
      dist/es/index.js
  7. 39
      dist/es/public-key.js
  8. 10
      dist/es/recover-public-key.js
  9. 8
      dist/es/recover.js
  10. 2
      dist/es/sign-transaction.js
  11. 8
      dist/es/sign.js
  12. 25
      dist/lib/address-by-public-key.js
  13. 20
      dist/lib/create-identity.js
  14. 11
      dist/lib/encrypt-with-public-key.js
  15. 15
      dist/lib/hash.js
  16. 10
      dist/lib/hex.js
  17. 14
      dist/lib/index.js
  18. 53
      dist/lib/public-key.js
  19. 10
      dist/lib/recover-public-key.js
  20. 12
      dist/lib/recover.js
  21. 6
      dist/lib/sign-transaction.js
  22. 10
      dist/lib/sign.js
  23. 2
      package.json

@ -1,13 +0,0 @@
import EthUtil from 'ethereumjs-util';
import { web3 } from './util';
/**
* generates the ethereum-adress of the publicKey
* We create the checksum-adress which is case-sensitive
* @returns {string} address
*/
export default function addressByPublicKey(publicKey) {
var addressBuffer = EthUtil.pubToAddress(new Buffer(publicKey, 'hex'));
var checkSumAdress = web3.utils.toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,18 +1,13 @@
import { web3 } from './util';
import publicKeyByPrivateKey from './public-key-by-private-key';
import Account from 'eth-lib/lib/account';
/**
* creates a new object with
* private-, public-Key and address
*/
export default function createIdentity() {
var account = web3.eth.accounts.create();
var identity = {
address: account.address,
privateKey: account.privateKey,
publicKey: publicKeyByPrivateKey(account.privateKey)
};
return identity;
var identity = Account.create();
identity.publicKey = publicKeyByPrivateKey(identity.privateKey);
return identity;
}

@ -1,6 +1,7 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
import _asyncToGenerator from 'babel-runtime/helpers/asyncToGenerator';
import eccrypto from 'eccrypto';
import { decompress } from './public-key';
export default (function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(publicKey, message) {
@ -10,12 +11,15 @@ export default (function () {
switch (_context.prev = _context.next) {
case 0:
// ensure its an uncompressed publicKey
publicKey = decompress(publicKey);
// re-add the compression-flag
pubString = '04' + publicKey;
_context.next = 3;
_context.next = 4;
return eccrypto.encrypt(new Buffer(pubString, 'hex'), Buffer(message));
case 3:
case 4:
encryptedBuffers = _context.sent;
encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
@ -25,7 +29,7 @@ export default (function () {
};
return _context.abrupt('return', encrypted);
case 6:
case 7:
case 'end':
return _context.stop();
}

14
dist/es/hash.js vendored

@ -12,16 +12,4 @@ export function keccak256(params) {
return (_web3$utils = web3.utils).soliditySha3.apply(_web3$utils, params);
}
export var SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';
/**
* hashes the given hash with the web3-prefix
* '\x19Ethereum Signed Message:\n32'
*/
export function prefixedHash(hash) {
if (!web3.utils.isHexStrict(hash)) throw new Error('EthCrypto.hash.prefixedHash(): please insert an hash');
return web3.eth.accounts.hashMessage({
type: 'bytes32',
value: hash
});
}
export var SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';

8
dist/es/hex.js vendored

@ -4,12 +4,12 @@
* @link https://stackoverflow.com/a/40471908/3443137
*/
import * as util from './util';
import { removeTrailing0x, addTrailing0x } from './util';
export function compress(hex) {
var base64 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
hex = util.removeTrailing0x(hex);
hex = removeTrailing0x(hex);
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) return new Buffer(hex, 'hex').toString('base64');
@ -33,7 +33,7 @@ export function decompress(compressedString) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) {
var ret = new Buffer(compressedString, 'base64').toString('hex');
return util.addTrailing0x(ret);
return addTrailing0x(ret);
}
var hex = '';
@ -42,5 +42,5 @@ export function decompress(compressedString) {
hex += ((i == 0 ? '' : '000') + compressedString.charCodeAt(i).toString(16)).slice(-4);
}
hex = hex.toLowerCase();
return util.addTrailing0x(hex);
return addTrailing0x(hex);
}

7
dist/es/index.js vendored

@ -1,5 +1,6 @@
import addressByPublicKey from './address-by-public-key';
import createIdentity from './create-identity';
import * as publicKey from './public-key';
import decryptWithPrivateKey from './decrypt-with-private-key';
import encryptWithPublicKey from './encrypt-with-public-key';
import publicKeyByPrivateKey from './public-key-by-private-key';
@ -14,11 +15,11 @@ import * as hex from './hex';
import * as vrs from './vrs';
import * as util from './util';
export { addressByPublicKey, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, publicKeyByPrivateKey, recover, recoverPublicKey, sign, signTransaction, txDataByCompiled, calculateContractAddress, hash, hex, vrs, util };
export { createIdentity, publicKey, decryptWithPrivateKey, encryptWithPublicKey, publicKeyByPrivateKey, recover, recoverPublicKey, sign, signTransaction, txDataByCompiled, calculateContractAddress, hash, hex, vrs, util };
export default {
addressByPublicKey: addressByPublicKey,
createIdentity: createIdentity,
publicKey: publicKey,
decryptWithPrivateKey: decryptWithPrivateKey,
encryptWithPublicKey: encryptWithPublicKey,
publicKeyByPrivateKey: publicKeyByPrivateKey,

@ -0,0 +1,39 @@
import { publicKeyConvert } from 'secp256k1';
import ethUtil from 'ethereumjs-util';
export function compress(startsWith04) {
// add trailing 04 if not done before
var testBuffer = new Buffer(startsWith04, 'hex');
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04;
return publicKeyConvert(new Buffer(startsWith04, 'hex'), true).toString('hex');
};
export function decompress(startsWith02Or03) {
// if already decompressed an not has trailing 04
var testBuffer = new Buffer(startsWith02Or03, 'hex');
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03;
var decompressed = publicKeyConvert(new Buffer(startsWith02Or03, 'hex'), false).toString('hex');
// remove trailing 04
decompressed = decompressed.substring(2);
return decompressed;
};
/**
* generates the ethereum-adress of the publicKey
* We create the checksum-adress which is case-sensitive
* @returns {string} address
*/
export function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
var addressBuffer = ethUtil.pubToAddress(new Buffer(publicKey, 'hex'));
var checkSumAdress = ethUtil.toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,10 +1,10 @@
import * as secp256k1 from 'secp256k1';
import { recover } from 'secp256k1';
import * as vrs from './vrs';
import * as util from './util';
import { removeTrailing0x } from './util';
/**
* returns the publicKey for the privateKEy with which the messageHash was signed
* returns the publicKey for the privateKey with which the messageHash was signed
* @param {string} signature
* @param {string} hash
* @return {string} publicKey
@ -13,11 +13,11 @@ export default function recoverPublicKey(signature, hash) {
var vals = vrs.fromString(signature);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = util.removeTrailing0x(sigOnly);
sigOnly = 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');
var pubKey = recover(new Buffer(removeTrailing0x(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
// remove trailing '04'
pubKey = pubKey.slice(2);

@ -1,5 +1,5 @@
import recoverPublicKey from './recover-public-key';
import addressByPublicKey from './address-by-public-key';
import { toAddress as addressByPublicKey } from './public-key';
/**
* returns the adress with which the messageHash was signed
@ -8,7 +8,7 @@ import addressByPublicKey from './address-by-public-key';
* @return {string} address
*/
export default function recover(sigString, hash) {
var pubkey = recoverPublicKey(sigString, hash);
var address = addressByPublicKey(pubkey);
return address;
var pubkey = recoverPublicKey(sigString, hash);
var address = addressByPublicKey(pubkey);
return address;
}

@ -1,6 +1,6 @@
import Tx from 'ethereumjs-tx';
import publicKeyByPrivateKey from './public-key-by-private-key';
import addressByPublicKey from './address-by-public-key';
import { toAddress as addressByPublicKey } from './public-key';
export default function signTransaction(rawTx, privateKey) {

8
dist/es/sign.js vendored

@ -1,5 +1,5 @@
import * as secp256k1 from 'secp256k1';
import * as util from './util';
import { sign as secp256k1_sign } from 'secp256k1';
import { addTrailing0x, removeTrailing0x } from './util';
/**
* signs the given message
@ -9,10 +9,10 @@ import * as util from './util';
* @return {string} hexString
*/
export default function sign(privateKey, hash) {
hash = util.addTrailing0x(hash);
hash = addTrailing0x(hash);
if (hash.length !== 66) throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);
var sigObj = secp256k1.sign(new Buffer(util.removeTrailing0x(hash), 'hex'), new Buffer(util.removeTrailing0x(privateKey), 'hex'));
var sigObj = secp256k1_sign(new Buffer(removeTrailing0x(hash), 'hex'), new Buffer(removeTrailing0x(privateKey), 'hex'));
var recoveryId = sigObj.recovery === 1 ? '1c' : '1b';

@ -1,25 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = addressByPublicKey;
var _ethereumjsUtil = require('ethereumjs-util');
var _ethereumjsUtil2 = _interopRequireDefault(_ethereumjsUtil);
var _util = require('./util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* generates the ethereum-adress of the publicKey
* We create the checksum-adress which is case-sensitive
* @returns {string} address
*/
function addressByPublicKey(publicKey) {
var addressBuffer = _ethereumjsUtil2['default'].pubToAddress(new Buffer(publicKey, 'hex'));
var checkSumAdress = _util.web3.utils.toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -1,16 +1,18 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports['default'] = createIdentity;
var _util = require('./util');
var _publicKeyByPrivateKey = require('./public-key-by-private-key');
var _publicKeyByPrivateKey2 = _interopRequireDefault(_publicKeyByPrivateKey);
var _account = require('eth-lib/lib/account');
var _account2 = _interopRequireDefault(_account);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
@ -18,13 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
* private-, public-Key and address
*/
function createIdentity() {
var account = _util.web3.eth.accounts.create();
var identity = {
address: account.address,
privateKey: account.privateKey,
publicKey: (0, _publicKeyByPrivateKey2['default'])(account.privateKey)
};
return identity;
var identity = _account2['default'].create();
identity.publicKey = (0, _publicKeyByPrivateKey2['default'])(identity.privateKey);
return identity;
}

@ -16,6 +16,8 @@ var _eccrypto = require('eccrypto');
var _eccrypto2 = _interopRequireDefault(_eccrypto);
var _publicKey = require('./public-key');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports['default'] = function () {
@ -26,12 +28,15 @@ exports['default'] = function () {
switch (_context.prev = _context.next) {
case 0:
// ensure its an uncompressed publicKey
publicKey = (0, _publicKey.decompress)(publicKey);
// re-add the compression-flag
pubString = '04' + publicKey;
_context.next = 3;
_context.next = 4;
return _eccrypto2['default'].encrypt(new Buffer(pubString, 'hex'), Buffer(message));
case 3:
case 4:
encryptedBuffers = _context.sent;
encrypted = {
iv: encryptedBuffers.iv.toString('hex'),
@ -41,7 +46,7 @@ exports['default'] = function () {
};
return _context.abrupt('return', encrypted);
case 6:
case 7:
case 'end':
return _context.stop();
}

15
dist/lib/hash.js vendored

@ -10,7 +10,6 @@ var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
exports.keccak256 = keccak256;
exports.prefixedHash = prefixedHash;
var _util = require('./util');
@ -28,16 +27,4 @@ function keccak256(params) {
return (_web3$utils = _util.web3.utils).soliditySha3.apply(_web3$utils, (0, _toConsumableArray3['default'])(params));
}
var SIGN_PREFIX = exports.SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';
/**
* hashes the given hash with the web3-prefix
* '\x19Ethereum Signed Message:\n32'
*/
function prefixedHash(hash) {
if (!_util.web3.utils.isHexStrict(hash)) throw new Error('EthCrypto.hash.prefixedHash(): please insert an hash');
return _util.web3.eth.accounts.hashMessage({
type: 'bytes32',
value: hash
});
}
var SIGN_PREFIX = exports.SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';

10
dist/lib/hex.js vendored

@ -8,14 +8,10 @@ exports.decompress = decompress;
var _util = require('./util');
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 compress(hex) {
var base64 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
hex = util.removeTrailing0x(hex);
hex = (0, _util.removeTrailing0x)(hex);
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) return new Buffer(hex, 'hex').toString('base64');
@ -43,7 +39,7 @@ function decompress(compressedString) {
// if base64:true, we use our own function because it results in a smaller output
if (base64 === true) {
var ret = new Buffer(compressedString, 'base64').toString('hex');
return util.addTrailing0x(ret);
return (0, _util.addTrailing0x)(ret);
}
var hex = '';
@ -52,5 +48,5 @@ function decompress(compressedString) {
hex += ((i == 0 ? '' : '000') + compressedString.charCodeAt(i).toString(16)).slice(-4);
}
hex = hex.toLowerCase();
return util.addTrailing0x(hex);
return (0, _util.addTrailing0x)(hex);
}

14
dist/lib/index.js vendored

@ -3,16 +3,16 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.util = exports.vrs = exports.hex = exports.hash = exports.calculateContractAddress = exports.txDataByCompiled = exports.signTransaction = exports.sign = exports.recoverPublicKey = exports.recover = exports.publicKeyByPrivateKey = exports.encryptWithPublicKey = exports.decryptWithPrivateKey = exports.createIdentity = exports.addressByPublicKey = undefined;
var _addressByPublicKey = require('./address-by-public-key');
var _addressByPublicKey2 = _interopRequireDefault(_addressByPublicKey);
exports.util = exports.vrs = exports.hex = exports.hash = exports.calculateContractAddress = exports.txDataByCompiled = exports.signTransaction = exports.sign = exports.recoverPublicKey = exports.recover = exports.publicKeyByPrivateKey = exports.encryptWithPublicKey = exports.decryptWithPrivateKey = exports.publicKey = exports.createIdentity = undefined;
var _createIdentity = require('./create-identity');
var _createIdentity2 = _interopRequireDefault(_createIdentity);
var _publicKey = require('./public-key');
var publicKey = _interopRequireWildcard(_publicKey);
var _decryptWithPrivateKey = require('./decrypt-with-private-key');
var _decryptWithPrivateKey2 = _interopRequireDefault(_decryptWithPrivateKey);
@ -69,8 +69,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports.addressByPublicKey = _addressByPublicKey2['default'];
exports.createIdentity = _createIdentity2['default'];
exports.publicKey = publicKey;
exports.decryptWithPrivateKey = _decryptWithPrivateKey2['default'];
exports.encryptWithPublicKey = _encryptWithPublicKey2['default'];
exports.publicKeyByPrivateKey = _publicKeyByPrivateKey2['default'];
@ -85,8 +85,8 @@ exports.hex = hex;
exports.vrs = vrs;
exports.util = util;
exports['default'] = {
addressByPublicKey: _addressByPublicKey2['default'],
createIdentity: _createIdentity2['default'],
publicKey: publicKey,
decryptWithPrivateKey: _decryptWithPrivateKey2['default'],
encryptWithPublicKey: _encryptWithPublicKey2['default'],
publicKeyByPrivateKey: _publicKeyByPrivateKey2['default'],

@ -0,0 +1,53 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.compress = compress;
exports.decompress = decompress;
exports.toAddress = toAddress;
var _secp256k = require('secp256k1');
var _ethereumjsUtil = require('ethereumjs-util');
var _ethereumjsUtil2 = _interopRequireDefault(_ethereumjsUtil);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function compress(startsWith04) {
// add trailing 04 if not done before
var testBuffer = new Buffer(startsWith04, 'hex');
if (testBuffer.length === 64) startsWith04 = '04' + startsWith04;
return (0, _secp256k.publicKeyConvert)(new Buffer(startsWith04, 'hex'), true).toString('hex');
};
function decompress(startsWith02Or03) {
// if already decompressed an not has trailing 04
var testBuffer = new Buffer(startsWith02Or03, 'hex');
if (testBuffer.length === 64) startsWith02Or03 = '04' + startsWith02Or03;
var decompressed = (0, _secp256k.publicKeyConvert)(new Buffer(startsWith02Or03, 'hex'), false).toString('hex');
// remove trailing 04
decompressed = decompressed.substring(2);
return decompressed;
};
/**
* generates the ethereum-adress of the publicKey
* We create the checksum-adress which is case-sensitive
* @returns {string} address
*/
function toAddress(publicKey) {
// normalize key
publicKey = decompress(publicKey);
var addressBuffer = _ethereumjsUtil2['default'].pubToAddress(new Buffer(publicKey, 'hex'));
var checkSumAdress = _ethereumjsUtil2['default'].toChecksumAddress(addressBuffer.toString('hex'));
return checkSumAdress;
}

@ -7,20 +7,16 @@ exports['default'] = recoverPublicKey;
var _secp256k = require('secp256k1');
var secp256k1 = _interopRequireWildcard(_secp256k);
var _vrs = require('./vrs');
var vrs = _interopRequireWildcard(_vrs);
var _util = require('./util');
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; } }
/**
* returns the publicKey for the privateKEy with which the messageHash was signed
* returns the publicKey for the privateKey with which the messageHash was signed
* @param {string} signature
* @param {string} hash
* @return {string} publicKey
@ -29,11 +25,11 @@ function recoverPublicKey(signature, hash) {
var vals = vrs.fromString(signature);
var sigOnly = signature.substring(0, signature.length - 1);
sigOnly = util.removeTrailing0x(sigOnly);
sigOnly = (0, _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');
var pubKey = (0, _secp256k.recover)(new Buffer((0, _util.removeTrailing0x)(hash), 'hex'), new Buffer(sigOnly, 'hex'), recoveryNumber, false).toString('hex');
// remove trailing '04'
pubKey = pubKey.slice(2);

@ -1,7 +1,7 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports['default'] = recover;
@ -9,9 +9,7 @@ var _recoverPublicKey = require('./recover-public-key');
var _recoverPublicKey2 = _interopRequireDefault(_recoverPublicKey);
var _addressByPublicKey = require('./address-by-public-key');
var _addressByPublicKey2 = _interopRequireDefault(_addressByPublicKey);
var _publicKey = require('./public-key');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
@ -22,7 +20,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
* @return {string} address
*/
function recover(sigString, hash) {
var pubkey = (0, _recoverPublicKey2['default'])(sigString, hash);
var address = (0, _addressByPublicKey2['default'])(pubkey);
return address;
var pubkey = (0, _recoverPublicKey2['default'])(sigString, hash);
var address = (0, _publicKey.toAddress)(pubkey);
return address;
}

@ -13,9 +13,7 @@ var _publicKeyByPrivateKey = require('./public-key-by-private-key');
var _publicKeyByPrivateKey2 = _interopRequireDefault(_publicKeyByPrivateKey);
var _addressByPublicKey = require('./address-by-public-key');
var _addressByPublicKey2 = _interopRequireDefault(_addressByPublicKey);
var _publicKey = require('./public-key');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
@ -23,7 +21,7 @@ function signTransaction(rawTx, privateKey) {
// check if privateKey->address matches rawTx.from
var publicKey = (0, _publicKeyByPrivateKey2['default'])(privateKey);
var address = (0, _addressByPublicKey2['default'])(publicKey);
var address = (0, _publicKey.toAddress)(publicKey);
if (address != rawTx.from) throw new Error('EthCrypto.signTransaction(): rawTx.from does not match the address of the privateKey');
var privateKeyBuffer = new Buffer(privateKey.replace(/^.{2}/g, ''), 'hex');

10
dist/lib/sign.js vendored

@ -7,14 +7,8 @@ exports['default'] = sign;
var _secp256k = require('secp256k1');
var secp256k1 = _interopRequireWildcard(_secp256k);
var _util = require('./util');
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; } }
/**
* signs the given message
* we do not use sign from eth-lib because the pure secp256k1-version is 90% faster
@ -23,10 +17,10 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
* @return {string} hexString
*/
function sign(privateKey, hash) {
hash = util.addTrailing0x(hash);
hash = (0, _util.addTrailing0x)(hash);
if (hash.length !== 66) throw new Error('EthCrypto.sign(): Can only sign hashes, given: ' + hash);
var sigObj = secp256k1.sign(new Buffer(util.removeTrailing0x(hash), 'hex'), new Buffer(util.removeTrailing0x(privateKey), 'hex'));
var sigObj = (0, _secp256k.sign)(new Buffer((0, _util.removeTrailing0x)(hash), 'hex'), new Buffer((0, _util.removeTrailing0x)(privateKey), 'hex'));
var recoveryId = sigObj.recovery === 1 ? '1c' : '1b';

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

Loading…
Cancel
Save