Skip to content

Instantly share code, notes, and snippets.

@giansalex
Last active April 21, 2022 02:27
Show Gist options
  • Save giansalex/e7e0443d9e7faeef9f1f1da2ed393e9b to your computer and use it in GitHub Desktop.
Save giansalex/e7e0443d9e7faeef9f1f1da2ed393e9b to your computer and use it in GitHub Desktop.

Revisions

  1. giansalex revised this gist Apr 21, 2022. No changes.
  2. giansalex revised this gist Feb 28, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion eth-sign.js
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ function ascii_to_hex(str)
    console.log('Message to sign:', message);
    console.log('Sign with account:', accountToSignWith);
    var messageHex = '0x' + ascii_to_hex(message);
    // var messageHex = keccak256(signDocBytes); // cosmos chain
    // var messageHex = '0x' + keccak256(signDocBytes); // cosmos chain

    window.ethereum.enable().then(function() {
    web3.eth.sign(messageHex, accountToSignWith, signHandler);
  3. giansalex revised this gist Feb 28, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions eth-sign.js
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ function ascii_to_hex(str)
    console.log('Message to sign:', message);
    console.log('Sign with account:', accountToSignWith);
    var messageHex = '0x' + ascii_to_hex(message);
    // var messageHex = keccak256(signDocBytes); // cosmos chain

    window.ethereum.enable().then(function() {
    web3.eth.sign(messageHex, accountToSignWith, signHandler);
  4. giansalex revised this gist Feb 19, 2022. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions eth-sign.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    var Web3 = require('web3');
    var web3 = new Web3(window.web3.currentProvider);

    var accountToSignWith = '0x64D356169841B3E18fd7415780Cf01Bb4d22B872';
    var accountToSignWith = '0xbedcf417ff2752d996d2ade98b97a6f0bef4beb9';
    var message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tubulum fuisse, qua illum, cuius is condemnatus est rogatione, P. Eaedem res maneant alio modo.'

    function signHandler(err, signature) {
    @@ -24,7 +24,7 @@ function ascii_to_hex(str)
    {
    var arr1 = [];
    for (var n = 0, l = str.length; n < l; n ++)
    {
    {
    var hex = Number(str.charCodeAt(n)).toString(16);
    arr1.push(hex);
    }
    @@ -33,6 +33,8 @@ function ascii_to_hex(str)

    console.log('Message to sign:', message);
    console.log('Sign with account:', accountToSignWith);

    var messageHex = '0x' + ascii_to_hex(message);
    web3.eth.sign(messageHex, accountToSignWith, signHandler);

    window.ethereum.enable().then(function() {
    web3.eth.sign(messageHex, accountToSignWith, signHandler);
    });
  5. giansalex created this gist Feb 19, 2022.
    38 changes: 38 additions & 0 deletions eth-sign.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    var Web3 = require('web3');
    var web3 = new Web3(window.web3.currentProvider);

    var accountToSignWith = '0x64D356169841B3E18fd7415780Cf01Bb4d22B872';
    var message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tubulum fuisse, qua illum, cuius is condemnatus est rogatione, P. Eaedem res maneant alio modo.'

    function signHandler(err, signature) {
    if (!err) {
    console.log('Signature:', signature);
    signature = signature.substr(2);
    r = '0x' + signature.substr(0, 64);
    s = '0x' + signature.substr(64, 64);
    v = '0x' + signature.substr(128, 2)

    console.log(' r:', r)
    console.log(' s:', s)
    console.log(' v:', v)
    } else {
    console.error('Coult not sign message:', err);
    }
    }

    function ascii_to_hex(str)
    {
    var arr1 = [];
    for (var n = 0, l = str.length; n < l; n ++)
    {
    var hex = Number(str.charCodeAt(n)).toString(16);
    arr1.push(hex);
    }
    return arr1.join('');
    }

    console.log('Message to sign:', message);
    console.log('Sign with account:', accountToSignWith);

    var messageHex = '0x' + ascii_to_hex(message);
    web3.eth.sign(messageHex, accountToSignWith, signHandler);