bitcore-wallet-service/lib/model/address.js

36 lines
742 B
JavaScript
Raw Normal View History

2015-01-27 05:18:45 -08:00
'use strict';
2015-02-03 11:46:28 -08:00
var Bitcore = require('bitcore');
2015-01-27 05:18:45 -08:00
function Address(opts) {
2015-02-02 12:07:18 -08:00
opts = opts || {};
2015-01-27 05:18:45 -08:00
2015-02-02 12:07:18 -08:00
this.createdOn = Math.floor(Date.now() / 1000);
this.address = opts.address;
this.path = opts.path;
2015-02-03 11:46:28 -08:00
this.publicKeys = opts.publicKeys;
2015-01-27 05:18:45 -08:00
};
Address.fromObj = function (obj) {
2015-02-02 12:07:18 -08:00
var x = new Address();
2015-01-27 05:18:45 -08:00
2015-02-02 12:07:18 -08:00
x.createdOn = obj.createdOn;
x.address = obj.address;
x.path = obj.path;
2015-02-03 11:46:28 -08:00
x.publicKeys = obj.publicKeys;
2015-02-02 12:07:18 -08:00
return x;
2015-01-27 05:18:45 -08:00
};
2015-02-03 11:46:28 -08:00
/**
* getScriptPubKey
*
* @param {number} threshold - amount of required signatures to spend the output
* @return {Script}
*/
Address.prototype.getScriptPubKey = function (threshold) {
2015-02-03 18:17:06 -08:00
return Bitcore.Script.buildMultisigOut(this.publicKeys, threshold).toScriptHashOut();
2015-02-03 11:46:28 -08:00
};
2015-01-27 05:18:45 -08:00
module.exports = Address;