obyte.js
GitHubDiscord
0.1.14
0.1.14
  • Obyte.js
  • Getting started
    • Quick start
    • Testnet
  • API
    • Get witnesses
    • Get peers
    • Get joint
    • Get last MCI
    • Get history
    • Get attestation
    • Get attestations
    • Get bots
    • Get asset metadata
    • Get definition
    • Get balances
    • Get profile units
    • Get data feed
    • Autonomous Agents
      • Dry run AA
      • Get AA state vars
      • Get AAs by base AAs
      • Get AA responses
      • Get AA response chain
    • Core
      • Catchup
      • Get hash tree
      • Get light props
      • Post joint
      • Pick divisible coins for amount
      • Heartbeat
  • Post
    • Address definition change
    • Attestation
    • Asset
    • Asset attestors
    • Data
    • Data feed
    • Definition
    • Definition template
    • Payment
    • Poll
    • Vote
    • Profile
    • Text
    • Multi
  • Client
    • Subscribe
    • Just saying
    • Requests
  • Utils
    • Sign a message
    • Validate signed message
    • Generate a random address
    • Get definition address
    • Is valid address
    • Keep connection alive
  • About
    • About
    • Links
    • Tutorials
Powered by GitBook
On this page
  • Example
  • Returns
  1. Utils

Sign a message

Sign a message with specific address

PreviousRequestsNextValidate signed message

Last updated 4 years ago

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 n 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="

o
Generate a random address