{"id":13773018,"url":"https://github.com/bitcoinjs/bitcoinjs-message","last_synced_at":"2025-04-04T09:08:18.887Z","repository":{"id":45333282,"uuid":"41949523","full_name":"bitcoinjs/bitcoinjs-message","owner":"bitcoinjs","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-09T11:01:08.000Z","size":73,"stargazers_count":133,"open_issues_count":4,"forks_count":80,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-18T19:16:45.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitcoinjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-05T04:55:01.000Z","updated_at":"2025-03-08T20:32:31.000Z","dependencies_parsed_at":"2024-06-18T12:35:21.309Z","dependency_job_id":"14feca85-a52d-4065-8f48-3fcdcf606481","html_url":"https://github.com/bitcoinjs/bitcoinjs-message","commit_stats":{"total_commits":56,"total_committers":9,"mean_commits":6.222222222222222,"dds":0.5714285714285714,"last_synced_commit":"c43430f4c03c292c719e7801e425d887cbdf7464"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fbitcoinjs-message","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fbitcoinjs-message/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fbitcoinjs-message/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoinjs%2Fbitcoinjs-message/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitcoinjs","download_url":"https://codeload.github.com/bitcoinjs/bitcoinjs-message/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244745760,"owners_count":20503050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T17:01:10.329Z","updated_at":"2025-03-21T06:08:22.590Z","avatar_url":"https://github.com/bitcoinjs.png","language":"JavaScript","readme":"# bitcoinjs-message\n[![NPM Package](https://img.shields.io/npm/v/bitcoinjs-message.svg?style=flat-square)](https://www.npmjs.org/package/bitcoinjs-message)\n[![Build Status](https://img.shields.io/travis/bitcoinjs/bitcoinjs-message.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/bitcoinjs/bitcoinjs-message)\n[![Dependency status](https://img.shields.io/david/bitcoinjs/bitcoinjs-message.svg?style=flat-square)](https://david-dm.org/bitcoinjs/bitcoinjs-message#info=dependencies)\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## Examples (Note about Electrum support at the bottom)\n\n``` javascript\nvar bitcoin = require('bitcoinjs-lib') // v4.x.x\nvar bitcoinMessage = require('bitcoinjs-message')\n```\n\n\u003e sign(message, privateKey, compressed[, network.messagePrefix, sigOptions])\n\u003e - If you pass the sigOptions arg instead of messagePrefix it will dynamically replace.\n\u003e - sigOptions contains two attributes\n\u003e   - `segwitType` should be one of `'p2sh(p2wpkh)'` or `'p2wpkh'`\n\u003e   - `extraEntropy` will be used to create non-deterministic signatures using the RFC6979 extra entropy parameter. R value reuse is not an issue.\n\nSign a Bitcoin message\n``` javascript\nvar keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')\nvar privateKey = keyPair.privateKey\nvar message = 'This is an example of a signed message.'\n\nvar signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)\nconsole.log(signature.toString('base64'))\n// =\u003e 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n```\n\nTo produce non-deterministic signatures you can pass an extra option to sign()\n``` javascript\nvar { randomBytes } = require('crypto')\nvar keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')\nvar privateKey = keyPair.privateKey\nvar message = 'This is an example of a signed message.'\n\nvar signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { extraEntropy: randomBytes(32) })\nconsole.log(signature.toString('base64'))\n// =\u003e different (but valid) signature each time\n```\n\nSign a Bitcoin message (with segwit addresses)\n``` javascript\n// P2SH(P2WPKH) address 'p2sh(p2wpkh)'\nvar signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2sh(p2wpkh)' })\nconsole.log(signature.toString('base64'))\n// =\u003e 'I9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n\n// P2WPKH address 'p2wpkh'\nvar signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed, { segwitType: 'p2wpkh' })\nconsole.log(signature.toString('base64'))\n// =\u003e 'J9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n```\n\nSign a Bitcoin message using a Signer interface.\n``` javascript\nvar keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')\nvar privateKey = keyPair.privateKey\nvar message = 'This is an example of a signed message.'\n\nvar secp256k1 = require('secp256k1')\n// Notice we are using the privateKey var from the outer scope inside the sign function.\nvar signer = { sign: (hash, extraData) =\u003e secp256k1.sign(hash, privateKey, { data: extraData }) }\n\nvar signature = bitcoinMessage.sign(message, signer, keyPair.compressed)\nconsole.log(signature.toString('base64'))\n// =\u003e 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n```\n\n\u003e signAsync(message, privateKey, compressed[, network.messagePrefix, sigOptions])\n\u003e Same as sign, except returns a promise, and can accept a SignerAsync interface instead of privateKey\n\nSign a Bitcoin message asynchronously\n``` javascript\nvar keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')\nvar privateKey = keyPair.privateKey\nvar message = 'This is an example of a signed message.'\n\nbitcoinMessage.signAsync(message, privateKey, keyPair.compressed).then(signature =\u003e {\n  console.log(signature.toString('base64'))\n})\n// =\u003e 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n```\n\nSign a Bitcoin message asynchronously using SignerAsync interface\n``` javascript\nvar keyPair = bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')\nvar privateKey = keyPair.privateKey\nvar message = 'This is an example of a signed message.'\n\nvar secp256k1 = require('secp256k1')\n// Note that a Signer will also work\nvar signerAsync = { sign: (hash, extraData) =\u003e Promise.resolve(secp256k1.sign(hash, privateKey, { data: extraData })) }\nvar signer = { sign: (hash, extraData) =\u003e secp256k1.sign(hash, privateKey, { data: extraData }) }\n\nbitcoinMessage.signAsync(message, signerAsync, keyPair.compressed).then(signature =\u003e {\n  console.log(signature.toString('base64'))\n})\n// =\u003e 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\nbitcoinMessage.signAsync(message, signer, keyPair.compressed).then(signature =\u003e {\n  console.log(signature.toString('base64'))\n})\n// =\u003e 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='\n```\n\n\u003e verify(message, address, signature[, network.messagePrefix, checkSegwitAlways])\n\nVerify a Bitcoin message\n``` javascript\nvar address = '1F3sAm6ZtwLAUnj7d38pGFxtP3RVEvtsbV'\n\nconsole.log(bitcoinMessage.verify(message, address, signature))\n// =\u003e true\n```\n\n## About Electrum segwit signature support\n\n- For Signing: Use the non-segwit compressed signing parameters for both segwit types (p2sh-p2wpkh and p2wpkh)\n- For Verifying: Pass the checkSegwitAlways argument as true. (messagePrefix should be set to null to default to Bitcoin messagePrefix)\n\n## LICENSE [MIT](LICENSE)\n","funding_links":[],"categories":["List of content"],"sub_categories":["Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinjs%2Fbitcoinjs-message","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitcoinjs%2Fbitcoinjs-message","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoinjs%2Fbitcoinjs-message/lists"}