parent
d4fc858aac
commit
17364c9ad4
@ -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; |
||||
} |
@ -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,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; |
||||
} |
@ -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; |
||||
} |
Loading…
Reference in new issue