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

Commit eba739c

Browse files
committed
Small updates on keygen stuff
Strangely, ethjs-account produces the wrong public key in react-native... ethjs/ethjs-account#3
1 parent 728fc09 commit eba739c

File tree

5 files changed

+419
-10
lines changed

5 files changed

+419
-10
lines changed

Components/Util/Eth.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ exports.formUnsigned = function(from, to, data, _gas, _gasPrice, _value) {
3737

3838
exports.submitTx = function(unsigned, privateKey) {
3939
return new Promise((resolve, reject) => {
40+
console.log('unsigned', unsigned)
41+
console.log('privatekey', privateKey)
4042
let raw = signer.sign(unsigned, privateKey);
4143
console.log('raw', raw)
4244
config.eth.sendRawTransaction(raw)

Components/Util/Fs.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function write(path, data, encoding) {
2626

2727
function read(path) {
2828
return new Promise((resolve, reject) => {
29-
console.log('bas_dir', ifs.DocumentDirectoryPath)
3029
ifs.exists(path)
3130
.then((exists) => {
3231
if (exists) { return ifs.readFile(path) }
@@ -77,7 +76,7 @@ function writeState(obj) {
7776
function readState() {
7877
return new Promise((resolve, reject) => {
7978
read(STATE_PATH)
80-
.then((state) => { console.log('STATE?', state); resolve(JSON.parse(state)) })
79+
.then((state) => { resolve(JSON.parse(state)) })
8180
.catch((err) => { reject(err) })
8281
})
8382
}

Components/Util/Keys.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,17 @@ function getAddress() {
9191
// Get the Ethereum address of a saved mnemonic
9292
function address(mnemonic) {
9393
// Convert seed mnemonic to private key via BIP39
94-
let priv = '0x'+bip39.mnemonicToSeedHex(mnemonic).substr(0, 64)
95-
// Convert to a buffer and derive public key via secp256k1
96-
let pbuf = Buffer.from(priv)
97-
let pub = secp256k1.keyFromPrivate(pbuf).getPublic(false, 'hex')
98-
// Hash public key and shave off first 24 characters (12 bytes)
99-
let addr = '0x'+sha3('0x'+pub).slice(24).toString('hex')
94+
let priv = '0x' + bip39.mnemonicToSeedHex(mnemonic).substr(0, 64)
95+
console.log('priv', priv)
96+
let pub = ethutil.privateToPublic(priv).toString('hex')
97+
console.log('pub', pub)
98+
99+
let pre_addr = sha3(pub).slice(12).toString('hex')
100+
console.log('pre-addr', pre_addr)
101+
102+
// ethjs-account functions not handled properly in RN and ethereumjs-util doesn't work either
103+
let addr = ethutil.getAddress(pre_addr)
104+
console.log('addr', addr)
100105
return addr;
101106
}
102107

0 commit comments

Comments
 (0)