Sign a message

Sign a message with specific address

Example

signMessage function takes 2 parameters: first parameter as message to be signed and second parameter as WIF of specific wallet address. Second parameter can also be object that contains binary privateKey or wif string and boolean testnet switch.

Documentation how to generate WIF can be found on Generate a random address page.

const { signMessage } = require('obyte/lib/utils');
const privateKey = window.atob('base64 of private key'); // convert to binary
const address_wif = 'wif string';
//const address_key = { privateKey, testnet: false }; // optional way
//const address_key = { wif: address_wif, testnet: false }; // optional way
const address_key = wallet_wif;
const message = 'Hello world';

const objSignedMessage = signMessage(message, address_key);
const signedMessageBase64 = window.btoa(JSON.stringify(objSignedMessage));

console.log(objSignedMessage, signedMessageBase64);

Returns

{
  authors: [
    {
      address: 'TMWNLXR42CKIP4A774BQGNVBZAPHY7GH',
      definition: [
        'sig',
        {
          pubkey: 'AsD2GQ3+CSHfFO9CfX8+gBxmxSm9TGweKjWVie0rt/0p'
        }
      ],
      authentifiers: {
        r: 'Xfw43Kiu+q+L/1b+z+daKe784V3KcvxWXedwcyC/Yvp+ziR1Jomo7Og7ZoPUPUwQeM4UPpIVU/cTtgurH0LzvA=='
      }
    }
  ],
  signed_message: 'Hello world',
  version: '3.0'
}

"eyJ2ZXJzaW9uIjoiMy4wIiwic2lnbmVkX21lc3NhZ2UiOiJIZWxsbyB3b3JsZCIsImF1dGhvcnMiOlt7ImFkZHJlc3MiOiJUTVdOTFhSNDJDS0lQNEE3NzRCUUdOVkJaQVBIWTdHSCIsImRlZmluaXRpb24iOlsic2lnIix7InB1YmtleSI6IkFzRDJHUTMrQ1NIZkZPOUNmWDgrZ0J4bXhTbTlUR3dlS2pXVmllMHJ0LzBwIn1dLCJhdXRoZW50aWZpZXJzIjp7InIiOiJYZnc0M0tpdStxK0wvMWIreitkYUtlNzg0VjNLY3Z4V1hlZHdjeUMvWXZwK3ppUjFKb21vN09nN1pvUFVQVXdRZU00VVBwSVZVL2NUdGd1ckgwTHp2QT09In19XX0="

Last updated