Message Verification and Signing

Bitcore implementation of bitcoin message signing and verification. This is used to cryptographically prove that a certain message was signed by the holder of an address private key.

For more information refer to the bitcore-message github repo.

Installation

Message Verification and Signing is implemented as a separate module and you must add it to your dependencies:

For node projects:

npm install bitcore-message --save

For client-side projects:

bower install bitcore-message --save

Example

To sign a message:

var privateKey = PrivateKey.fromWIF('cPBn5A4ikZvBTQ8D7NnvHZYCAxzDZ5Z2TSGW2LkyPiLxqYaJPBW4');
var signature = Message('hello, world').sign(privateKey);

To verify a message:

var address = 'n1ZCYg9YXtB5XCZazLxSmPDa8iwJRZHhGx';
var signature = 'H/DIn8uA1scAuKLlCx+/9LnAcJtwQQ0PmcPrJUq90aboLv3fH5fFvY+vmbfOSFEtGarznYli6ShPr9RXwY9UrIY=';
var verified = Message('hello, world').verify(address, signature);

Message(message) ⇒ Message

constructs a new message to sign and verify.

Kind: global function

Param Type
message String

message.sign(privateKey) ⇒ String

Will sign a message with a given bitcoin private key.

Kind: instance method of Message
Returns: String - A base64 encoded compact signature

Param Type Description
privateKey PrivateKey An instance of PrivateKey

message.verify(bitcoinAddress, signatureString) ⇒ Boolean

Will return a boolean of the signature is valid for a given bitcoin address. If it isn't the specific reason is accessible via the "error" member.

Kind: instance method of Message

Param Type Description
bitcoinAddress Address | String A bitcoin address
signatureString String A base64 encoded compact signature

message.toObject() ⇒ Object

Kind: instance method of Message
Returns: Object - A plain object with the message information

message.toJSON() ⇒ String

Kind: instance method of Message
Returns: String - A JSON representation of the message information

message.toString() ⇒ String

Will return a the string representation of the message

Kind: instance method of Message
Returns: String - Message

message.inspect() ⇒ String

Will return a string formatted for the console

Kind: instance method of Message
Returns: String - Message

Message.fromString(str) ⇒ Message

Instantiate a message from a message string

Kind: static method of Message
Returns: Message - A new instance of a Message

Param Type Description
str String A string of the message

Message.fromJSON(json) ⇒ Message

Instantiate a message from JSON

Kind: static method of Message
Returns: Message - A new instance of a Message

Param Type Description
json String An JSON string or Object with keys: message