Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bytes32 fingerprint = keccak256(channelId, nonce, balanceA, balanceB);
- bytes32 signTypedDataFingerprint = keccak256(
- keccak256("bytes32 hash"),
- keccak256(fingerprint)
- );
- require(ECTools.isSignedBy(signTypedDataFingerprint, sigA, channel.agentA) == true);
- async signTx ({ channelId, nonce, balanceA, balanceB }) {
- // fingerprint = keccak256(channelId, nonce, balanceA, balanceB)
- let hash = abi
- .soliditySHA3(
- ['bytes32', 'uint256', 'uint256', 'uint256'],
- [channelId, nonce, balanceA, balanceB]
- )
- .toString('hex')
- hash = `0x${hash}`
- console.log('hash: ', hash)
- const sig = await new Promise((resolve, reject) => {
- this.web3.currentProvider.sendAsync(
- {
- method: 'eth_signTypedData',
- params: [
- [
- {
- type: 'bytes32',
- name: 'hash',
- value: hash
- }
- ],
- this.web3.eth.accounts[0]
- ],
- from: this.web3.eth.accounts[0]
- },
- function (err, result) {
- if (err) reject(err)
- if (result.error) {
- reject(result.error.message)
- }
- resolve(result)
- }
- )
- })
- console.log('sig: ', sig)
- return sig
- }
Add Comment
Please, Sign In to add comment