You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

10 years ago
'use strict';
var $ = require('preconditions').singleton();
10 years ago
var _ = require('lodash');
var util = require('util');
var Bitcore = require('bitcore');
var HDPublicKey = Bitcore.HDPublicKey;
10 years ago
var Uuid = require('uuid');
var AddressManager = require('./addressmanager');
var Utils = require('../bitcoinutils');
var VERSION = '1.0.0';
var MESSAGE_SIGNING_PATH = "m/1/0";
10 years ago
function Copayer(opts) {
$.checkArgument(opts && opts.xPubKey, 'need to provide an xPubKey');
10 years ago
opts.copayerIndex = opts.copayerIndex || 0;
10 years ago
this.xPubKey = opts.xPubKey;
this.id = Utils.xpubToCopayerId(this.xPubKey);
this.version = VERSION;
10 years ago
this.createdOn = Math.floor(Date.now() / 1000);
this.name = opts.name;
this.xPubKeySignature = opts.xPubKeySignature; // So third parties can check independently
10 years ago
if (this.xPubKey)
this.signingPubKey = this.getSigningPubKey();
this.addressManager = new AddressManager({ copayerIndex: opts.copayerIndex });
};
Copayer.prototype.getPublicKey = function(path) {
return HDPublicKey
.fromString(this.xPubKey)
.derive(path)
.publicKey
.toString();
};
10 years ago
Copayer.prototype.getSigningPubKey = function() {
return this.getPublicKey(MESSAGE_SIGNING_PATH);
10 years ago
};
10 years ago
Copayer.fromObj = function(obj) {
var x = new Copayer({
xPubKey: obj.xPubKey,
});
10 years ago
x.createdOn = obj.createdOn;
x.id = obj.id;
x.name = obj.name;
x.xPubKeySignature = obj.xPubKeySignature;
x.addressManager = AddressManager.fromObj(obj.addressManager);
10 years ago
return x;
};
10 years ago
module.exports = Copayer;