Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named variables? #5

Closed
julien51 opened this issue Nov 11, 2017 · 2 comments
Closed

Named variables? #5

julien51 opened this issue Nov 11, 2017 · 2 comments

Comments

@julien51
Copy link

Hi!
I think your example is one of the clearest... Yet, it would be helpful if you used more descriptive variable names in the method signature ;)

@ppoliani
Copy link

ppoliani commented Dec 19, 2017

There is currently an open issue regarding the documentation of ecrecover function. ethereum/solidity#681

However, you can look into the web3 docs for more details.

I can try to explain how it works:

Bob signs a hash of (contract_address, value): this can be done using the web3 helper function:

const h = web3.sha3(`${contract_address}${value}`);
const sig = web3.eth.sign(address, h);

Alice will get the sig and when she wants to close the channel she can send a transaction that will call the CloseChannel function of the smart contract. But she must first pass all the required parameters. That's actually quite simple if you have the sig:

 const r = `0x${sig.slice(0, 64)}`
 const s = `0x${sig.slice(64, 128)}`
 const v = web3.toDecimal(sig.slice(128, 130)) + 27

Then the smart contract can use ecrecover which as stated in the Solidity docs:

ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address):
recover the address associated with the public key from elliptic curve signature or return zero on error

The parameter names are kind of a convention when using ECDSA values.

@julien51
Copy link
Author

Thanks a lot! this clarifies things a little bit...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants