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

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-01-27 05:18:45 -08:00
'use strict';
var _ = require('lodash');
2015-02-01 11:50:58 -08:00
var Bitcore = require('bitcore');
var HDPublicKey = Bitcore.HDPublicKey;
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-01-27 05:18:45 -08:00
2015-02-02 10:29:14 -08:00
this.version = VERSION;
2015-02-02 12:07:18 -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
};
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
};
2015-02-02 04:36:55 -08:00
Copayer.prototype.addAddress = function (isChange) {
if (isChange) {
this.changeAddressIndex++;
} else {
this.receiveAddressIndex++;
}
};
Copayer.prototype.getCurrentAddressPath = function (isChange) {
return
};
Copayer.prototype.getNewAddressPath = function (isChange) {
this.addAddress(isChange);
return this.currentAddressPath(isChange);
};
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
};
module.exports = Copayer;