bitcoinjs-message
Advanced tools
Comparing version 1.0.1 to 2.0.0
27
index.js
@@ -7,10 +7,10 @@ var bs58check = require('bs58check') | ||
function sha256 (b) { | ||
return createHash('sha256').update(b).digest() | ||
} | ||
function hash256 (buffer) { | ||
var t = createHash('sha256').update(buffer).digest() | ||
return createHash('sha256').update(t).digest() | ||
return sha256(sha256(buffer)) | ||
} | ||
function hash160 (buffer) { | ||
var t = createHash('sha256').update(buffer).digest() | ||
return createHash('ripemd160').update(t).digest() | ||
return createHash('ripemd160').update(sha256(buffer)).digest() | ||
} | ||
@@ -20,3 +20,3 @@ | ||
if (compressed) recovery += 4 | ||
return Buffer.concat([new Buffer([recovery + 27]), signature]) | ||
return Buffer.concat([Buffer.alloc(1, recovery + 27), signature]) | ||
} | ||
@@ -38,13 +38,14 @@ | ||
function magicHash (message, messagePrefix) { | ||
messagePrefix = messagePrefix || '\u0018Bitcoin Signed Message:\n' | ||
if (!Buffer.isBuffer(messagePrefix)) messagePrefix = Buffer.from(messagePrefix, 'utf8') | ||
var messageVISize = varuint.encodingLength(message.length) | ||
var buffer = new Buffer(messagePrefix.length + messageVISize + message.length) | ||
buffer.write(messagePrefix, 0) | ||
var buffer = Buffer.allocUnsafe(messagePrefix.length + messageVISize + message.length) | ||
messagePrefix.copy(buffer, 0) | ||
varuint.encode(message.length, buffer, messagePrefix.length) | ||
buffer.write(message, messagePrefix.length + messageVISize) | ||
return hash256(buffer) | ||
} | ||
function sign (message, messagePrefix, privateKey, compressed) { | ||
function sign (message, privateKey, compressed, messagePrefix) { | ||
var hash = magicHash(message, messagePrefix) | ||
@@ -55,4 +56,4 @@ var sigObj = secp256k1.sign(hash, privateKey) | ||
function verify (message, messagePrefix, address, signature) { | ||
if (!Buffer.isBuffer(signature)) signature = new Buffer(signature, 'base64') | ||
function verify (message, address, signature, messagePrefix) { | ||
if (!Buffer.isBuffer(signature)) signature = Buffer.from(signature, 'base64') | ||
@@ -59,0 +60,0 @@ var parsed = decodeSignature(signature) |
{ | ||
"name": "bitcoinjs-message", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "bitcoinjs-message", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"bs58check": "^1.0.8", | ||
"bs58check": "^2.0.2", | ||
"buffer-equals": "^1.0.3", | ||
@@ -39,4 +39,4 @@ "create-hash": "^1.1.2", | ||
"bigi": "^1.4.1", | ||
"bitcoinjs-lib": "^2.2.0", | ||
"nyc": "^8.3.1", | ||
"bitcoinjs-lib": "^3.2.0", | ||
"nyc": "^11.2.1", | ||
"standard": "*", | ||
@@ -43,0 +43,0 @@ "tape": "^4.5.1" |
# bitcoinjs-message | ||
[![NPM Package](https://img.shields.io/npm/v/bitcoinjs-message.svg?style=flat-square)](https://www.npmjs.org/package/bitcoinjs-message) | ||
@@ -12,8 +11,9 @@ [![Build Status](https://img.shields.io/travis/bitcoinjs/bitcoinjs-message.svg?branch=master&style=flat-square)](https://travis-ci.org/bitcoinjs/bitcoinjs-message) | ||
``` javascript | ||
var bitcoin = require('bitcoinjs-lib') // v2.x.x | ||
var bitcoin = require('bitcoinjs-lib') // v3.x.x | ||
var bitcoinMessage = require('bitcoinjs-message') | ||
``` | ||
> sign(message, privateKey, compressed[, network.messagePrefix]) | ||
Sign a Bitcoin message | ||
``` javascript | ||
@@ -23,5 +23,4 @@ var keyPair = bitcoin.ECPair.fromWIF('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss') | ||
var message = 'This is an example of a signed message.' | ||
var messagePrefix = bitcoin.networks.bitcoin.messagePrefix | ||
var signature = bitcoinMessage.sign(message, messagePrefix, privateKey, keyPair.compressed) | ||
var signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed) | ||
console.log(signature.toString('base64')) | ||
@@ -31,4 +30,5 @@ // => 'G9L5yLFjti0QTHhPyFrZCT1V/MMnBtXKmoiKDZ78NDBjERki6ZTQZdSMCtkgoNmp17By9ItJr8o7ChX0XxY91nk=' | ||
> verify(message, address, signature[, network.messagePrefix]) | ||
Verify a Bitcoin message | ||
``` javascript | ||
@@ -38,5 +38,4 @@ var address = '1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN' | ||
var message = 'This is an example of a signed message.' | ||
var messagePrefix = bitcoin.networks.bitcoin.messagePrefix | ||
console.log(bitcoinMessage.verify(message, messagePrefix, address, signature)) | ||
console.log(bitcoinMessage.verify(message, address, signature)) | ||
// => true | ||
@@ -43,0 +42,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
6163
5
57
0
41
+ Addedbase-x@3.0.10(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbs58check@2.1.2(transitive)
- Removedbase-x@1.1.0(transitive)
- Removedbs58@3.1.0(transitive)
- Removedbs58check@1.3.4(transitive)
Updatedbs58check@^2.0.2