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

51 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-01-27 05:18:45 -08:00
'use strict';
var _ = require('lodash');
2015-02-02 06:55:03 -08:00
var util = require('util');
2015-02-01 11:50:58 -08:00
var Bitcore = require('bitcore');
var HDPublicKey = Bitcore.HDPublicKey;
2015-02-02 06:55:03 -08:00
var Addressable = require('./Addressable');
2015-02-01 11:50:58 -08:00
var VERSION = '1.0.0';
var MESSAGE_SIGNING_PATH = "m/1/0";
2015-01-27 05:18:45 -08:00
function Copayer(opts) {
2015-02-02 12:07:18 -08:00
opts = opts || {};
2015-02-02 11:16:14 -08:00
opts.copayerIndex = opts.copayerIndex || 0;
Copayer.super_.apply(this, [opts]);
2015-01-27 05:18:45 -08:00
2015-02-02 10:29:14 -08:00
this.version = VERSION;
2015-02-02 11:16:14 -08:00
this.createdOn = Math.floor(Date.now() / 1000);
this.id = opts.id;
this.name = opts.name;
this.xPubKey = opts.xPubKey;
this.xPubKeySignature = opts.xPubKeySignature; // So third parties can check independently
2015-02-02 04:21:29 -08:00
this.signingPubKey = opts.signingPubKey || this.getSigningPubKey();
2015-02-01 11:50:58 -08:00
};
2015-02-02 06:55:03 -08:00
util.inherits(Copayer, Addressable);
2015-02-01 11:50:58 -08:00
Copayer.prototype.getSigningPubKey = function () {
if (!this.xPubKey) return null;
return HDPublicKey.fromString(this.xPubKey).derive(MESSAGE_SIGNING_PATH).publicKey.toString();
2015-01-27 05:18:45 -08:00
};
Copayer.fromObj = function (obj) {
2015-02-02 12:07:18 -08:00
var x = new Copayer();
2015-01-27 05:18:45 -08:00
2015-02-02 12:07:18 -08:00
x.createdOn = obj.createdOn;
x.id = obj.id;
x.name = obj.name;
x.xPubKey = obj.xPubKey;
x.xPubKeySignature = obj.xPubKeySignature;
2015-02-02 10:29:14 -08:00
x.signingPubKey = obj.signingPubKey;
2015-01-27 05:18:45 -08:00
2015-02-02 06:55:03 -08:00
Wallet.super_.prototype.fromObj.apply(this, [obj]);
return x;
};
2015-01-27 05:18:45 -08:00
module.exports = Copayer;