Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Small updates on keygen stuff
Browse files Browse the repository at this point in the history
Strangely, ethjs-account produces the wrong public key in react-native... ethjs/ethjs-account#3
  • Loading branch information
alex-miller-0 committed Aug 7, 2017
1 parent 728fc09 commit eba739c
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Components/Util/Eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ exports.formUnsigned = function(from, to, data, _gas, _gasPrice, _value) {

exports.submitTx = function(unsigned, privateKey) {
return new Promise((resolve, reject) => {
console.log('unsigned', unsigned)
console.log('privatekey', privateKey)
let raw = signer.sign(unsigned, privateKey);
console.log('raw', raw)
config.eth.sendRawTransaction(raw)
Expand Down
3 changes: 1 addition & 2 deletions Components/Util/Fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function write(path, data, encoding) {

function read(path) {
return new Promise((resolve, reject) => {
console.log('bas_dir', ifs.DocumentDirectoryPath)
ifs.exists(path)
.then((exists) => {
if (exists) { return ifs.readFile(path) }
Expand Down Expand Up @@ -77,7 +76,7 @@ function writeState(obj) {
function readState() {
return new Promise((resolve, reject) => {
read(STATE_PATH)
.then((state) => { console.log('STATE?', state); resolve(JSON.parse(state)) })
.then((state) => { resolve(JSON.parse(state)) })
.catch((err) => { reject(err) })
})
}
Expand Down
17 changes: 11 additions & 6 deletions Components/Util/Keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,17 @@ function getAddress() {
// Get the Ethereum address of a saved mnemonic
function address(mnemonic) {
// Convert seed mnemonic to private key via BIP39
let priv = '0x'+bip39.mnemonicToSeedHex(mnemonic).substr(0, 64)
// Convert to a buffer and derive public key via secp256k1
let pbuf = Buffer.from(priv)
let pub = secp256k1.keyFromPrivate(pbuf).getPublic(false, 'hex')
// Hash public key and shave off first 24 characters (12 bytes)
let addr = '0x'+sha3('0x'+pub).slice(24).toString('hex')
let priv = '0x' + bip39.mnemonicToSeedHex(mnemonic).substr(0, 64)
console.log('priv', priv)
let pub = ethutil.privateToPublic(priv).toString('hex')
console.log('pub', pub)

let pre_addr = sha3(pub).slice(12).toString('hex')
console.log('pre-addr', pre_addr)

// ethjs-account functions not handled properly in RN and ethereumjs-util doesn't work either
let addr = ethutil.getAddress(pre_addr)
console.log('addr', addr)
return addr;
}

Expand Down
Loading

0 comments on commit eba739c

Please sign in to comment.