bitcoinjs-message
![Dependency status](https://img.shields.io/david/bitcoinjs/bitcoinjs-message.svg?style=flat-square)
![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)
Examples
var bitcoin = require('bitcoinjs-lib')
var bitcoinMessage = require('bitcoinjs-message')
sign(message, privateKey, compressed[, network.messagePrefix, sigOptions])
- If you pass the sigOptions arg instead of messagePrefix it will dynamically replace.
- sigOptions contains two attributes
segwitType
should be one of 'p2sh(p2wpkh)'
or 'p2wpkh'
extraEntropy
will be used to create non-deterministic signatures using the RFC6979 extra entropy parameter. R value reuse is not an issue.
Sign a Bitcoin message
var keyPair = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss')
var privateKey = keyPair.privateKey
var message = 'This is an example of a signed message.'
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)
console.log(signature.toString('base64'))
To produce non-deterministic signatures you can pass an extra option to sign()
var { randomBytes } = require('crypto')
var keyPair = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss')
var privateKey = keyPair.privateKey
var message = 'This is an example of a signed message.'
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { extraEntropy: randomBytes(32) })
console.log(signature.toString('base64'))
Sign a Bitcoin message (with segwit addresses)
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2sh(p2wpkh)' })
console.log(signature.toString('base64'))
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2wpkh' })
console.log(signature.toString('base64'))
verify(message, address, signature[, network.messagePrefix])
Verify a Bitcoin message
var address = '1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN'
console.log(bitcoinMessage.verify(message, address, signature))
LICENSE MIT