Guest User

Untitled

a guest
Apr 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. bytes32 fingerprint = keccak256(channelId, nonce, balanceA, balanceB);
  2. bytes32 signTypedDataFingerprint = keccak256(
  3. keccak256("bytes32 hash"),
  4. keccak256(fingerprint)
  5. );
  6. require(ECTools.isSignedBy(signTypedDataFingerprint, sigA, channel.agentA) == true);
  7.  
  8. async signTx ({ channelId, nonce, balanceA, balanceB }) {
  9. // fingerprint = keccak256(channelId, nonce, balanceA, balanceB)
  10. let hash = abi
  11. .soliditySHA3(
  12. ['bytes32', 'uint256', 'uint256', 'uint256'],
  13. [channelId, nonce, balanceA, balanceB]
  14. )
  15. .toString('hex')
  16. hash = `0x${hash}`
  17. console.log('hash: ', hash)
  18.  
  19. const sig = await new Promise((resolve, reject) => {
  20. this.web3.currentProvider.sendAsync(
  21. {
  22. method: 'eth_signTypedData',
  23. params: [
  24. [
  25. {
  26. type: 'bytes32',
  27. name: 'hash',
  28. value: hash
  29. }
  30. ],
  31. this.web3.eth.accounts[0]
  32. ],
  33. from: this.web3.eth.accounts[0]
  34. },
  35. function (err, result) {
  36. if (err) reject(err)
  37. if (result.error) {
  38. reject(result.error.message)
  39. }
  40. resolve(result)
  41. }
  42. )
  43. })
  44. console.log('sig: ', sig)
  45. return sig
  46. }
Add Comment
Please, Sign In to add comment