# Sign a message

### 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 [o](/0.1.14/utils/generate-wallet.md)n [Generate a random address](/0.1.14/utils/generate-wallet.md) page.

```javascript
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**

```javascript
{
  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="
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://obytejs.com/0.1.14/utils/sign-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
