Data Signing

Data Signing

HandCash users can sign transactions publicly.


This can be used by the developer to issue a public record of the user’s intent to publish.

This feature requires the Data Signing permission. Otherwise you will receive an error.



Sign data

There are three different types of data you can sign:

"Sign this message!!!"
'IlNpZ24gdGhpcyBtZXNzYWdlISEhIgo='
'225369676E2074686973206D65737361676521212122'

Publicly sign a message using the code example below:

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const account =  handCashConnect.getAccountFromAuthToken(token);

const message = Buffer.from("Sign this message!!!").toString('hex')
const { publicKey, signature } = await account.profile.signData({
    value: message,
    format: 'hex'
})

Verify a public signature with the following:

const { PublicKey } = require('bsv')
const Message = require('bsv/message');

const message = '225369676E2074686973206D65737361676521212122';
console.log(Buffer.from(message).toString())

const verified = Message.verify(Buffer.from(message, 'hex'), PublicKey(publicKey).toAddress(), signature);
console.log(verified);

Output:

Sign this message!!!
true

Combine with a transaction.

Attach data with signature to a transaction:

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const text = "Sign this message!!!"
const message = Buffer.from(text).toString('hex')

const { signature } = await account.profile.signData({
    value: message,
    format: 'hex'
})

const account = handCashConnect.getAccountFromAuthToken(token);
const paymentParameters = {
    appAction: "publish",
    payments: [
        { destination: 'nosetwo', currencyCode: 'USD', sendAmount: 0.25 },
    ],
    attachment: { 
        format: 'json', 
        value: {
            "message": message, 
            "signature": signature
        } 
    },
};

const paymentResult = await account.wallet.pay(paymentParameters);
console.log(paymentResult);