npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

groestlcoinjs-message

v2.2.0

Published

groestlcoinjs-message

Downloads

41

Readme

groestlcoinjs-message

Examples (Note about Electrum-GRS support at the bottom)

var bitcoin = require('groestlcoinjs-lib') // v4.x.x
var bitcoinMessage = require('groestlcoinjs-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 Groestlcoin message

var keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrnZQVUG')
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'))
// => 'IOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

To produce non-deterministic signatures you can pass an extra option to sign()

var { randomBytes } = require('crypto')
var keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrnZQVUG')
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'))
// => different (but valid) signature each time

Sign a Groestlcoin message (with segwit addresses)

// P2SH(P2WPKH) address 'p2sh(p2wpkh)'
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2sh(p2wpkh)' })
console.log(signature.toString('base64'))
// => 'JOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

// P2WPKH address 'p2wpkh'
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2wpkh' })
console.log(signature.toString('base64'))
// => 'KOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

Sign a Groestlcoin message using a Signer interface.

var keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrnZQVUG')
var privateKey = keyPair.privateKey
var message = 'This is an example of a signed message.'

var secp256k1 = require('secp256k1')
// Notice we are using the privateKey var from the outer scope inside the sign function.
var signer = { sign: (hash, extraData) => secp256k1.sign(hash, privateKey, { data: extraData }) }

var signature = bitcoinMessage.sign(message, signer, keyPair.compressed)
console.log(signature.toString('base64'))
// => 'IOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

signAsync(message, privateKey, compressed[, network.messagePrefix, sigOptions]) Same as sign, except returns a promise, and can accept a SignerAsync interface instead of privateKey

Sign a Groestlcoin message asynchronously

var keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrnZQVUG')
var privateKey = keyPair.privateKey
var message = 'This is an example of a signed message.'

bitcoinMessage.signAsync(message, privateKey, keyPair.compressed).then(signature => {
  console.log(signature.toString('base64'))
})
// => 'IOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

Sign a Groestlcoin message asynchronously using SignerAsync interface

var keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrnZQVUG')
var privateKey = keyPair.privateKey
var message = 'This is an example of a signed message.'

var secp256k1 = require('secp256k1')
// Note that a Signer will also work
var signerAsync = { sign: (hash, extraData) => Promise.resolve(secp256k1.sign(hash, privateKey, { data: extraData })) }
var signer = { sign: (hash, extraData) => secp256k1.sign(hash, privateKey, { data: extraData }) }

bitcoinMessage.signAsync(message, signerAsync, keyPair.compressed).then(signature => {
  console.log(signature.toString('base64'))
})
// => 'IOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='
bitcoinMessage.signAsync(message, signer, keyPair.compressed).then(signature => {
  console.log(signature.toString('base64'))
})
// => 'IOES8hMhdoZFP0QaMJXTExZPmrTneGfbDmJib7Jt3gTaN0CfsYjBLWRvnDtd9aKlTt8BXxV95PYFOYhdiM1x90w='

verify(message, address, signature[, network.messagePrefix, checkSegwitAlways])

Verify a Groestlcoin message

var address = 'FjDacfpwTS1hvPkEW98HimmD3ChSpZQuss'

console.log(bitcoinMessage.verify(message, address, signature))
// => true

About Electrum-GRS segwit signature support

  • For Signing: Use the non-segwit compressed signing parameters for both segwit types (p2sh-p2wpkh and p2wpkh)
  • For Verifying: Pass the checkSegwitAlways argument as true. (messagePrefix should be set to null to default to Groestlcoin messagePrefix)

LICENSE MIT