How to use the eth-sig-util.typedSignatureHash function in eth-sig-util

To help you get started, we’ve selected a few eth-sig-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raiden-network / microraiden / microraiden / microraiden / webui / microraiden / src / index.ts View on Github external
const result = await promisify<{ result: string, error: Error }>(
        this.web3.currentProvider, 'sendAsync'
      )({
        method: 'eth_signTypedData',
        params: [params, this.channel.account],
        from: this.channel.account
      });
      if (result.error)
        throw result.error;
      sign = result.result;
    } catch (err) {
      if (err.message && err.message.includes('User denied')) {
        throw err;
      }
      console.log('Error on signTypedData', err);
      const hash = typedSignatureHash(params);
      // ask for signing of the hash
      sign = await this.signMessage(hash);
    }
    //debug
    const recovered = recoverTypedSignature({ data: params, sig: sign  });
    console.log('signTypedData =', sign, recovered);

    proof.sign = sign;

    // return signed message
    if (proof.balance === this.channel.proof.balance) {
      this.setChannel(Object.assign(
        {},
        this.channel,
        { proof, next_proof: proof }
      ));
github NoahZinsmeister / web3-webpacked / src / web3Utilities.js View on Github external
let returnData = {}
      returnData.signature = result.result

      // ensure that the signature matches
      const recoveredAddress = ethUtil.toChecksumAddress(ethSigUtil.recoverTypedSignature({
        data: typedData,
        sig: returnData.signature
      }))
      if (ethUtil.toChecksumAddress(recoveredAddress) !== from) {
        return reject(Error(
          `The returned signature '${returnData.signature}' originated from '${recoveredAddress}', not '${from}'.`
        ))
      }
      returnData.from = from

      returnData.messageHash = ethSigUtil.typedSignatureHash(typedData)

      const signature = ethUtil.fromRpcSig(returnData.signature)
      returnData.r = ethUtil.addHexPrefix(Buffer.from(signature.r).toString('hex'))
      returnData.s = ethUtil.addHexPrefix(Buffer.from(signature.s).toString('hex'))
      returnData.v = signature.v

      resolve(returnData)
    })
  })
github DSiSc / contracts_library / maheshmurthy / ethereum_voting_dapp / chapter4 / migrations / 2_deploy_contracts.js View on Github external
var Voting = artifacts.require("./Voting.sol");
var ECRecovery = artifacts.require("./ECRecovery.sol");

const sigUtil = require("eth-sig-util")

var alice_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Alice"}])
var bob_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Bob"}])
var carol_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Carol"}])

module.exports = function(deployer) {
  deployer.deploy(ECRecovery);
  deployer.link(ECRecovery, Voting);
  deployer.deploy(Voting, ['Alice', 'Bob', 'Carol'], [alice_vote_hash, bob_vote_hash, carol_vote_hash]);
};
github MetaMask / gaba / src / util.ts View on Github external
export function validateTypedSignMessageDataV1(messageData: TypedMessageParams) {
	if (!messageData.from || typeof messageData.from !== 'string' || !isValidAddress(messageData.from)) {
		throw new Error(`Invalid "from" address: ${messageData.from} must be a valid string.`);
	}
	if (!messageData.data || !Array.isArray(messageData.data)) {
		throw new Error(`Invalid message "data": ${messageData.data} must be a valid array.`);
	}
	try {
		sigUtil.typedSignatureHash(messageData.data);
	} catch (e) {
		throw new Error(`Expected EIP712 typed data.`);
	}
}
github DSiSc / contracts_library / authorized / migrations / 2_deploy_contracts.js View on Github external
var fravollSolidityPatternsRandomnessRandomness = artifacts.require("./fravoll/solidity-patterns/Randomness/Randomness.sol");
var fravollSolidityPatternsEternalStorageEternalStorage = artifacts.require("./fravoll/solidity-patterns/EternalStorage/EternalStorage.sol");
var fravollSolidityPatternsEmergencyStopEmergencyStop = artifacts.require("./fravoll/solidity-patterns/EmergencyStop/EmergencyStop.sol");
var fravollSolidityPatternsChecksEffectsInteractionChecksEffectsInteractions = artifacts.require("./fravoll/solidity-patterns/ChecksEffectsInteraction/ChecksEffectsInteractions.sol");
var fravollSolidityPatternsTightVariablePackingTightVariablePacking = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/StructPackingExample.sol");
var fravollSolidityPatternsTightVariablePackingCheapStructPackingExample = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/CheapStructPackingExample.sol");
var fravollSolidityPatternsTightVariablePackingExpensiveStructPackingExample = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/ExpensiveStructPackingExample.sol");
var fravollSolidityPatternsOracleoracle = artifacts.require("./fravoll/solidity-patterns/Oracle/Oracle.sol");
var fravollSolidityPatternsStateMachineStateMachine = artifacts.require("./fravoll/solidity-patterns/StateMachine/StateMachine.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuildingCheap = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuildingCheap.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuildingExpensive = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuildingExpensive.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuilding = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuilding.sol");

const sigUtil = require("eth-sig-util")

var alice_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Alice" }])
var bob_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Bob" }])
var carol_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Carol" }])

module.exports = function (deployer) {
  deployer.deploy(maheshmurthyEthereumVotingDappECRecovery);
  deployer.link(maheshmurthyEthereumVotingDappECRecovery, maheshmurthyEthereumVotingDappVoting);
  deployer.deploy(maheshmurthyEthereumVotingDappVoting, ['Alice', 'Bob', 'Carol'], [alice_vote_hash, bob_vote_hash, carol_vote_hash]);

  deployer.deploy(willitscaleLearningSolidityTutorial28SolidityAddressBook);
  deployer.deploy(willitscaleLearningSolidityTutorial21ConvertLib);
  deployer.link(willitscaleLearningSolidityTutorial21ConvertLib, willitscaleLearningSolidityTutorial21MetaCoin);
  deployer.deploy(willitscaleLearningSolidityTutorial21MetaCoin);

  deployer.deploy(willitscaleLearningSolidityTutorial22SafeMath);
  deployer.link(willitscaleLearningSolidityTutorial22SafeMath, willitscaleLearningSolidityTutorial22MyToken);
  deployer.deploy(willitscaleLearningSolidityTutorial22Addresses);
github DSiSc / contracts_library / authorized / migrations / 2_deploy_contracts.js View on Github external
var fravollSolidityPatternsEternalStorageEternalStorage = artifacts.require("./fravoll/solidity-patterns/EternalStorage/EternalStorage.sol");
var fravollSolidityPatternsEmergencyStopEmergencyStop = artifacts.require("./fravoll/solidity-patterns/EmergencyStop/EmergencyStop.sol");
var fravollSolidityPatternsChecksEffectsInteractionChecksEffectsInteractions = artifacts.require("./fravoll/solidity-patterns/ChecksEffectsInteraction/ChecksEffectsInteractions.sol");
var fravollSolidityPatternsTightVariablePackingTightVariablePacking = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/StructPackingExample.sol");
var fravollSolidityPatternsTightVariablePackingCheapStructPackingExample = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/CheapStructPackingExample.sol");
var fravollSolidityPatternsTightVariablePackingExpensiveStructPackingExample = artifacts.require("./fravoll/solidity-patterns/TightVariablePacking/ExpensiveStructPackingExample.sol");
var fravollSolidityPatternsOracleoracle = artifacts.require("./fravoll/solidity-patterns/Oracle/Oracle.sol");
var fravollSolidityPatternsStateMachineStateMachine = artifacts.require("./fravoll/solidity-patterns/StateMachine/StateMachine.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuildingCheap = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuildingCheap.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuildingExpensive = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuildingExpensive.sol");
var fravollSolidityPatternsMemoryArrayBuildingMemoryArrayBuilding = artifacts.require("./fravoll/solidity-patterns/MemoryArrayBuilding/MemoryArrayBuilding.sol");

const sigUtil = require("eth-sig-util")

var alice_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Alice" }])
var bob_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Bob" }])
var carol_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Carol" }])

module.exports = function (deployer) {
  deployer.deploy(maheshmurthyEthereumVotingDappECRecovery);
  deployer.link(maheshmurthyEthereumVotingDappECRecovery, maheshmurthyEthereumVotingDappVoting);
  deployer.deploy(maheshmurthyEthereumVotingDappVoting, ['Alice', 'Bob', 'Carol'], [alice_vote_hash, bob_vote_hash, carol_vote_hash]);

  deployer.deploy(willitscaleLearningSolidityTutorial28SolidityAddressBook);
  deployer.deploy(willitscaleLearningSolidityTutorial21ConvertLib);
  deployer.link(willitscaleLearningSolidityTutorial21ConvertLib, willitscaleLearningSolidityTutorial21MetaCoin);
  deployer.deploy(willitscaleLearningSolidityTutorial21MetaCoin);

  deployer.deploy(willitscaleLearningSolidityTutorial22SafeMath);
  deployer.link(willitscaleLearningSolidityTutorial22SafeMath, willitscaleLearningSolidityTutorial22MyToken);
  deployer.deploy(willitscaleLearningSolidityTutorial22Addresses);
  deployer.link(willitscaleLearningSolidityTutorial22Addresses, willitscaleLearningSolidityTutorial22MyToken);
github DSiSc / contracts_library / maheshmurthy / ethereum_voting_dapp / chapter4 / migrations / 2_deploy_contracts.js View on Github external
var Voting = artifacts.require("./Voting.sol");
var ECRecovery = artifacts.require("./ECRecovery.sol");

const sigUtil = require("eth-sig-util")

var alice_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Alice"}])
var bob_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Bob"}])
var carol_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Carol"}])

module.exports = function(deployer) {
  deployer.deploy(ECRecovery);
  deployer.link(ECRecovery, Voting);
  deployer.deploy(Voting, ['Alice', 'Bob', 'Carol'], [alice_vote_hash, bob_vote_hash, carol_vote_hash]);
};
github DSiSc / contracts_library / maheshmurthy / ethereum_voting_dapp / chapter4 / migrations / 2_deploy_contracts.js View on Github external
var Voting = artifacts.require("./Voting.sol");
var ECRecovery = artifacts.require("./ECRecovery.sol");

const sigUtil = require("eth-sig-util")

var alice_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Alice"}])
var bob_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Bob"}])
var carol_vote_hash = sigUtil.typedSignatureHash([{ type: 'string', name: 'Message', value: "Vote for Carol"}])

module.exports = function(deployer) {
  deployer.deploy(ECRecovery);
  deployer.link(ECRecovery, Voting);
  deployer.deploy(Voting, ['Alice', 'Bob', 'Carol'], [alice_vote_hash, bob_vote_hash, carol_vote_hash]);
};