rchain / rchain-api

Obsoleted in favor of https://github.com/rchain-community/rchain-api. Use at your own risk.
Other
8 stars 4 forks source link

string hashing compatible with ethereum, bitcoin #8

Closed dckc closed 5 years ago

dckc commented 5 years ago

@JoshOrndorff made a comment asking that we consider this developer story:

I'm a dApp developer who has written a rholang smart contract. I'm now writing the frontend in javacscript. I want to use RChain-API to connect to the blockchain, but I don't want to dig into it's guts or fiddle with bit tweezers. What's my best way to hash the string "Hello World" in such a way that it will verify correctly on chain, and preferably on ethereum or even bitcoin as well?

dckc commented 5 years ago

I just looked at sha3 in web3. It's got a crazy-nutso exception for strings starting with 0x:

web3.utils.sha3('234'); // taken as string
> "0xc1912fee45d61c87cc5ea59dae311904cd86b84fee17cc96966216f811ce6a79"

...

web3.utils.sha3('0xea'); // will be converted to a byte array first, and then hashed
> "0x2f20677459120677484f7104c76deb6846a2c071f9b3152c103bb12cd54d1a4a"

So I guess if you want to hash the string 0xdeadbeef you have to use 0x30786465616462656566???

dckc commented 5 years ago

We have address this, to my satisfaction, in e95c909ce636512e0cd74af043d3e9e6381cdd43 and related commits.

Anybody who isn't satisfied, please open an issue in https://github.com/rchain-community/rchain-api/issues