Incorrect public key derivation on react-native
Issue Type
Bug
Description
Given the private key:
0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d
I can successfully derive the following (correct) information on my node (v8) console:
account.privateToPublic('0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d').toString('hex')
> '253caada10d4ffc3ad90a8b20658a524df51b884ab0c213fce48b024f6dce4661539d81e2f776a4b087298b66fa4a46b020a2eb46046aeec171548539bcc679b'
account.publicToAddress(account.privateToPublic('0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d')).toString('hex')
> '0x5C6a4899f99cd6A6c41a2aef0B3d355546e46F92'
However, React-Native gives me an incorrect public key:
047a0b7043c722b88ab914b3e07a4d323ee689104673f89ccd7dd3efd3a8ea932f2e1e120ad525f4c6de93053280f7a8e820145a0091f733a082ed3f3429dd6cd5
This is unfortunate because ethjs-account is the only account util I can find that doesn't error out in the RN environment.
- react-native-cli: 2.0.1
- react-native: 0.47.1
Hey Alex, how are you using the module? Is it the prebuild or an install of the module?
That is crazy it derives improperly and super dangerous.
Tell me more
Sent from my iPhone
On Aug 7, 2017, at 7:29 PM, Alex Miller [email protected] wrote:
Issue Type
Bug
Description
Given the private key:
0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d I can successfully derive the following (correct) information on my node (v8) console:
account.privateToPublic('0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d').toString('hex')
'253caada10d4ffc3ad90a8b20658a524df51b884ab0c213fce48b024f6dce4661539d81e2f776a4b087298b66fa4a46b020a2eb46046aeec171548539bcc679b'
account.publicToAddress(account.privateToPublic('0x4735f8b1af5002ce677ae96bbf8958d7213a858f76166047346f89e5597f964d')).toString('hex')
'0x5C6a4899f99cd6A6c41a2aef0B3d355546e46F92' However, when I run the following code in a utility function within React-Native:
let pub = account.privateToPublic(priv).toString('hex') I get an incorrect public key:
04253caada10d4ffc3ad90a8b20658a524df51b884ab0c213fce48b024f6dce4661539d81e2f776a4b087298b66fa4a46b020a2eb46046aeec171548539bcc679b Where priv is the 0x-prefixed private key specified above.
This is unfortunate because ethjs-account is the only account util I can find that doesn't error our in the RN environment.
react-native-cli: 2.0.1 react-native: 0.47.1 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
I was using an npm installation.
I just imported ethjs-account as a pre-build, which solves the problem. This is likely an issue with something in the internals of secp256k1 not liking the RN environment, but it may be helpful to include a pre-build distribution and make a note for RN users.
I think this issue should perhaps stay open, since ethjs-account is using elliptic directly and not secp256k1 (which detects the presence of a binary addon, and if missing uses elliptic). That could have explained a difference, but the same underlying lib should have resulted in the same result. No?
Hey Matt, any chance at a PR? This thing runs on smart individuals like yourself ;)
Would love sep256 and RN support.
Sent from my iPhone
On Aug 7, 2017, at 9:19 PM, Alex Miller [email protected] wrote:
Reopened #3.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.