getAddress working!
This commit is contained in:
parent
090faf62a2
commit
b5fbd55d89
|
@ -23,12 +23,12 @@ Addressable.prototype.addAddress = function (isChange) {
|
|||
};
|
||||
|
||||
Addressable.prototype.getCurrentAddressPath = function (isChange) {
|
||||
return HDPath.FullBranch(isChange ? this.changeAddressIndex : this.receiveAddressIndex, isChange, this.copayerIndex);
|
||||
return HDPath.Branch(isChange ? this.changeAddressIndex : this.receiveAddressIndex, isChange, this.copayerIndex);
|
||||
};
|
||||
|
||||
Addressable.prototype.getNewAddressPath = function (isChange) {
|
||||
this.addAddress(isChange);
|
||||
return this.currentAddressPath(isChange);
|
||||
return this.getCurrentAddressPath(isChange);
|
||||
};
|
||||
|
||||
module.exports = Addressable;
|
||||
|
|
|
@ -166,7 +166,7 @@ CopayServer.prototype._verifySignature = function(text, signature, pubKey) {
|
|||
*/
|
||||
CopayServer.prototype.createAddress = function (opts, cb) {
|
||||
var self = this;
|
||||
var isChange = opts.isChange;
|
||||
var isChange = opts.isChange || false;
|
||||
|
||||
Utils.checkRequired(opts, ['walletId', 'isChange']);
|
||||
|
||||
|
@ -177,6 +177,7 @@ CopayServer.prototype._verifySignature = function(text, signature, pubKey) {
|
|||
var copayer = wallet.copayers[0]; // TODO: Assign copayer from authentication.
|
||||
|
||||
var path = copayer.getNewAddressPath(isChange);
|
||||
|
||||
self.storage.storeWallet(wallet, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
|
|
@ -12,16 +12,16 @@ describe('Copayer', function() {
|
|||
describe('#getCurrentAddressPath', function() {
|
||||
it('return a valid BIP32 path for defaut copayer Index', function() {
|
||||
var c = new Copayer();
|
||||
c.getCurrentAddressPath(false).should.equal('m/45\'/0/0/0');
|
||||
c.getCurrentAddressPath(true).should.equal('m/45\'/0/1/0');
|
||||
c.getCurrentAddressPath(false).should.equal('m/0/0/0');
|
||||
c.getCurrentAddressPath(true).should.equal('m/0/1/0');
|
||||
});
|
||||
|
||||
it('return a valid BIP32 path for given index', function() {
|
||||
var c = new Copayer({
|
||||
copayerIndex: 4
|
||||
});
|
||||
c.getCurrentAddressPath(false).should.equal('m/45\'/4/0/0');
|
||||
c.getCurrentAddressPath(true).should.equal('m/45\'/4/1/0');
|
||||
c.getCurrentAddressPath(false).should.equal('m/4/0/0');
|
||||
c.getCurrentAddressPath(true).should.equal('m/4/1/0');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -546,11 +546,7 @@ describe('Copay server', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should create address', function(done) {
|
||||
server._doCreateAddress = sinon.stub().returns(new Address({
|
||||
address: 'addr1',
|
||||
path: 'path1',
|
||||
}));
|
||||
it('should create main address', function(done) {
|
||||
helpers.createAndJoinWallet('123', 2, 2, function(err, wallet) {
|
||||
server.createAddress({
|
||||
walletId: '123',
|
||||
|
@ -558,12 +554,29 @@ describe('Copay server', function() {
|
|||
}, function(err, address) {
|
||||
should.not.exist(err);
|
||||
address.should.exist;
|
||||
address.address.should.equal('addr1');
|
||||
address.path.should.equal('path1');
|
||||
address.address.should.equal('3BPfHzwq5j72TBYtYv3Uggk3vyHFHX3QpA');
|
||||
address.path.should.equal('m/0/0/1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should create change address', function(done) {
|
||||
helpers.createAndJoinWallet('123', 2, 2, function(err, wallet) {
|
||||
server.createAddress({
|
||||
walletId: '123',
|
||||
isChange: true,
|
||||
}, function(err, address) {
|
||||
should.not.exist(err);
|
||||
address.should.exist;
|
||||
address.address.should.equal('39Dzj5mBJWvzH7bDfmYzXDvTbZS5HdQ4a4');
|
||||
address.path.should.equal('m/0/1/1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createTx', function() {
|
||||
|
|
|
@ -27,8 +27,8 @@ describe('Wallet', function() {
|
|||
describe('#getCurrentAddressPath', function() {
|
||||
it('return a valid BIP32 path for defaut wallet Index', function() {
|
||||
var w = new Wallet();
|
||||
w.getCurrentAddressPath(false).should.equal('m/45\'/2147483647/0/0');
|
||||
w.getCurrentAddressPath(true).should.equal('m/45\'/2147483647/1/0');
|
||||
w.getCurrentAddressPath(false).should.equal('m/2147483647/0/0');
|
||||
w.getCurrentAddressPath(true).should.equal('m/2147483647/1/0');
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue