Message.prototype.set
This commit is contained in:
parent
a5f79c7651
commit
0ca390d45b
|
@ -7,14 +7,20 @@ var Hash = require('./hash');
|
|||
var Address = require('./address');
|
||||
var Signature = require('./signature');
|
||||
|
||||
var Message = function Message(messagebuf, key, sig, address, verified) {
|
||||
var Message = function Message(obj) {
|
||||
if (!(this instanceof Message))
|
||||
return new Message(messagebuf, key, sig);
|
||||
this.messagebuf = messagebuf;
|
||||
this.key = key;
|
||||
this.sig = sig;
|
||||
this.address = address;
|
||||
this.verified = verified;
|
||||
return new Message(obj);
|
||||
if (obj)
|
||||
this.set(obj);
|
||||
};
|
||||
|
||||
Message.prototype.set = function(obj) {
|
||||
this.messagebuf = obj.messagebuf || this.messagebuf;
|
||||
this.key = obj.key || this.key;
|
||||
this.sig = obj.sig || this.sig;
|
||||
this.address = obj.address || this.address;
|
||||
this.verified = typeof obj.verified !== 'undefined' ? obj.verified : this.verified;
|
||||
return this;
|
||||
};
|
||||
|
||||
Message.magicBytes = new Buffer('Bitcoin Signed Message:\n');
|
||||
|
@ -35,7 +41,7 @@ Message.magicHash = function(messagebuf) {
|
|||
};
|
||||
|
||||
Message.sign = function(messagebuf, key) {
|
||||
var m = Message(messagebuf, key);
|
||||
var m = Message({messagebuf: messagebuf, key: key});
|
||||
m.sign();
|
||||
var sigbuf = m.sig.toCompact();
|
||||
var sigstr = sigbuf.toString('base64');
|
||||
|
|
|
@ -14,6 +14,15 @@ describe('Message', function() {
|
|||
var message = Message();
|
||||
should.exist(message);
|
||||
});
|
||||
|
||||
describe('#set', function() {
|
||||
|
||||
it('should set the messagebuf', function() {
|
||||
var messagebuf = new Buffer('message');
|
||||
should.exist(Message().set({messagebuf: messagebuf}).messagebuf);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('@sign', function() {
|
||||
var messagebuf = new Buffer('this is my message');
|
||||
|
|
Loading…
Reference in New Issue