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

dgb-message-verifier

v1.0.0

Published

JavaScript library used to verify a message that had been signed using Bitcoin's approach.

Downloads

2

Readme

Bitcoin Message Verifier

A JavaScript library used to verify a message that had been signed using Bitcoin's approach.

Rationale

Bitcoin's client reference implementation, Bitcoin Core, provides an RPC method to sign a message with a bitcoin address (signmessage) and another to verify the signed message (verifymessage). However, as of this writing, Bitcoin Core is not able to sign and verify messages using segregated witness (bech32) addresses. Also, it is not possible to verify a signed message using a public key hash instead of a bitcoin address.

This library was put together to overcome these two limitations.

Implementation

This library uses bitcoinjs-message module's approach to sign messages with bech32 addresses where a bit (0x08) in the signature's first byte is used to flag that a bech32 address was used to sign the message.

Installation

On Node.js:

npm install btc-message-verifier

On the browser:

<script src="https://unpkg.com/btc-message-verifier"></script>

Browser compatibility

The Bitcoin Message Verifier library is compatible with modern web browsers.

It has been tested on the following web browsers:

  • Safari ver. 13.1 (on macOS Catalina 10.15)
  • Google Chrome ver. 83.0 64 bits (on macOS Catalina 10.15, Windows 10)
  • Google Chrome ver. 83.0 32 bits (on Windows 8.1)
  • Firefox ver. 78.0 64-bits (on macOS Catalina 10.15)
  • Microsoft Edge ver. 83.0 64 bits (on macOS Catalina 10.15, Windows 8.1, Windows 10)

Note: Internet Explorer is not supported.

Usage

Call the library's single method verifyMessage() to verify a signed message. A boolean value is then returned indicating whether the message is valid or not.

On Node.js:

const btcMsgVerifier = require('btc-msg-verifier');

const result = btcMsgVerifier.verifyMessage(...);

On the browser:

<script>
const result = btcMsgVerifier.verifyMessage(...);
</script>

Input parameters:

  • addrOrPubKeyHash [String|Buffer] - The bitcoin address or public key hash that was originally used to sign the message. If a buffer is passed, it is assumed to be a public key hash. Otherwise, it is assumed to be a bitcoin address.
  • signature [String|Buffer] - The message's signature. If a string is passed, it is assumed to be base64 encoded.
  • message [String] - The original message.
  • network [String] - (optional, default: 'bitcoin') The name of the Bitcoin blockchain network for which the message was signed. Valid values:
    • 'bitcoin'
    • 'regtest'
    • 'testnet'

Examples

Verify message signed with a legacy bitcoin address

On Node.js:

try {
  const result = btcMsgVerifier.verifyMessage(
    'mkPa87aADjgNYfiVNV7tUkxmbB3qmbE7cg',
    'H+dKQFYTbZwwqcExYap/ykVG23qRuxEbFOVfFoPBnBKWfI5jDPt61Y9pchdGkDULQ+x79ke8SosVpYygyVX8TDg=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}

On the browser:

<script>
try {
  const result = btcMsgVerifier.verifyMessage(
    'mkPa87aADjgNYfiVNV7tUkxmbB3qmbE7cg',
    'H+dKQFYTbZwwqcExYap/ykVG23qRuxEbFOVfFoPBnBKWfI5jDPt61Y9pchdGkDULQ+x79ke8SosVpYygyVX8TDg=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}
</script>

Verify message signed with a bech32 address

On Node.js:

try {
  const result = btcMsgVerifier.verifyMessage(
    'bcrt1qwfwu4tawzwdh233qlqwknk2r3quefyalvpwqyg',
    'KBbtz1fqBrQdioHfM452V8pHWsMAAxyakjmVkxq3BuJiZgU5ln5nepJfs/3MrY6eeivElMIOM+nVVbbocU6zzmU=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}

On the browser:

<script>
try {
  const result = btcMsgVerifier.verifyMessage(
    'bcrt1qwfwu4tawzwdh233qlqwknk2r3quefyalvpwqyg',
    'KBbtz1fqBrQdioHfM452V8pHWsMAAxyakjmVkxq3BuJiZgU5ln5nepJfs/3MrY6eeivElMIOM+nVVbbocU6zzmU=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}
</script>

Verify message passing a public key hash

On Node.js:

try {
  const result = btcMsgVerifier.verifyMessage(
    Buffer.from('543fc89cd1e5bda2ba3c82f4b48e3a82694498be', 'hex'),
    'IEk3JJnp8iKhAgp50hWCE7TCNciaDdrb8YNXWvqZzIUgcLvESYJO/ZFigJ726vpQ12tY6SDGg92aouzUMXKAgUE=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}

On the browser:

<script>
try {
  const result = btcMsgVerifier.verifyMessage(
    btcMsgVerifier.Buffer.from('543fc89cd1e5bda2ba3c82f4b48e3a82694498be', 'hex'),
    'IEk3JJnp8iKhAgp50hWCE7TCNciaDdrb8YNXWvqZzIUgcLvESYJO/ZFigJ726vpQ12tY6SDGg92aouzUMXKAgUE=',
    'Text to sign'
  );

  if (result) {
    console.log('Message successfully verified');
  }
  else {
    console.log('Message could not be verified');
  }
}
catch (err) {
  console.error(err);
}
</script>

License

This JavaScript library is released under the MIT License. Feel free to fork, and modify!

Copyright © 2020, Blockchain of Things Inc.