Bitcoinjs howto

bitcoinjs howto

Bitcoin (₿) is a cryptocurrency invented in 2008 by an unknown person or group of people Bitcoins are created as a reward for a process known as mining. For example, in 2013 one user claimed to have lost 7,500 bitcoins, worth $7.5. bitcoinjs-lib is an awesome library for all sort of Bitcoin operations written for Node.js. It's used in many projects and services you probably. If you're familiar with how to use browserify, ignore this and carry on, otherwise, it is recommended to read the tutorial at https://browserify.org/. NOTE: We use.

Bitcoinjs howto - think

And the: Bitcoinjs howto

Vender bitcoin cash 39
Btcusd tradeview 365
Hitbtc snc usd 26
Portfel do bitcoin gold 964
Tt 85/2017 btc 647
bitcoinjs howto

npm

Examples (Note about Electrum support at the bottom)

varbitcoin=require('bitcoinjs-lib')// v4.x.xvarbitcoinMessage=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
    • should be one of or
    • 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

varkeyPair=bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')varprivateKey=keyPair.privateKeyvarmessage='This is an example of a signed message.'varsignature=bitcoinMessage.sign(message,privateKey,keyPair.compressed)console.log(signature.toString('base64'))// => 'H9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk='

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

var{ randomBytes }=require('crypto')varkeyPair=bitcoin.ECPair.fromWIF('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1')varprivateKey=keyPair.privateKeyvarmessage='This is an example of a signed message.'varsignature=bitcoinMessage.sign(message,privateKey,keyPair.compressed,{extraEntropy: randomBytes(32)})console.log(signature.toString('base64'))// => different (but valid) signature each time

Sign a Bitcoin message (with segwit addresses)

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

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

Verify a Bitcoin message

varaddress='1F3sAm6ZtwLAUnj7d38pGFxtP3RVEvtsbV'console.log(bitcoinMessage.verify(message,address,signature))// => true

About Electrum 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 Bitcoin messagePrefix)

LICENSE MIT

Источник: https://www.npmjs.com/package/bitcoinjs-message

3 thoughts to “Bitcoinjs howto”

Leave a Reply

Your email address will not be published. Required fields are marked *