|
@ -34,6 +34,24 @@ Message.magicHash = function(messagebuf) { |
|
|
return hashbuf; |
|
|
return hashbuf; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Message.sign = function(messagebuf, key) { |
|
|
|
|
|
var m = Message(messagebuf, key); |
|
|
|
|
|
m.sign(); |
|
|
|
|
|
var sigbuf = m.sig.toCompact(); |
|
|
|
|
|
var sigstr = sigbuf.toString('base64'); |
|
|
|
|
|
return sigstr; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Message.verify = function(messagebuf, sigstr, address) { |
|
|
|
|
|
var sigbuf = new Buffer(sigstr, 'base64'); |
|
|
|
|
|
var message = new Message(); |
|
|
|
|
|
message.messagebuf = messagebuf; |
|
|
|
|
|
message.sig = Signature().fromCompact(sigbuf); |
|
|
|
|
|
message.address = address; |
|
|
|
|
|
|
|
|
|
|
|
return message.verify().verified; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Message.prototype.sign = function() { |
|
|
Message.prototype.sign = function() { |
|
|
var hashbuf = Message.magicHash(this.messagebuf); |
|
|
var hashbuf = Message.magicHash(this.messagebuf); |
|
|
var ecdsa = ECDSA(hashbuf, this.key); |
|
|
var ecdsa = ECDSA(hashbuf, this.key); |
|
@ -43,14 +61,6 @@ Message.prototype.sign = function() { |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Message.sign = function(messagebuf, key) { |
|
|
|
|
|
var m = Message(messagebuf, key); |
|
|
|
|
|
m.sign(); |
|
|
|
|
|
var sigbuf = m.sig.toCompact(); |
|
|
|
|
|
var sigstr = sigbuf.toString('base64'); |
|
|
|
|
|
return sigstr; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Message.prototype.verify = function() { |
|
|
Message.prototype.verify = function() { |
|
|
var hashbuf = Message.magicHash(this.messagebuf); |
|
|
var hashbuf = Message.magicHash(this.messagebuf); |
|
|
|
|
|
|
|
@ -75,14 +85,4 @@ Message.prototype.verify = function() { |
|
|
return this; |
|
|
return this; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Message.verify = function(messagebuf, sigstr, address) { |
|
|
|
|
|
var sigbuf = new Buffer(sigstr, 'base64'); |
|
|
|
|
|
var message = new Message(); |
|
|
|
|
|
message.messagebuf = messagebuf; |
|
|
|
|
|
message.sig = Signature().fromCompact(sigbuf); |
|
|
|
|
|
message.address = address; |
|
|
|
|
|
|
|
|
|
|
|
return message.verify().verified; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Message; |
|
|
module.exports = Message; |
|
|