mirror of https://github.com/BTCPrivate/copay.git
add sign in block
This commit is contained in:
parent
972ffb34b6
commit
307d3aaeec
|
@ -32,4 +32,17 @@ PrivateKey.prototype.get = function(index,isChange) {
|
|||
return wk;
|
||||
};
|
||||
|
||||
PrivateKey.prototype.getAll = function(addressIndex, changeAddressIndex) {
|
||||
var ret = [];
|
||||
for(var i=0;i<addressIndex; i++) {
|
||||
ret.push(this.get(i,false));
|
||||
}
|
||||
for(var i=0; i<changeAddressIndex; i++) {
|
||||
ret.push(this.get(i,true));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = require('soop')(PrivateKey);
|
||||
|
|
|
@ -26,7 +26,6 @@ function PublicKeyRing(opts) {
|
|||
|
||||
this.id = opts.id || PublicKeyRing.getRandomId();
|
||||
|
||||
this.dirty = 1;
|
||||
this.copayersBIP32 = [];
|
||||
|
||||
this.changeAddressIndex=0;
|
||||
|
@ -79,27 +78,21 @@ PublicKeyRing.fromObj = function (data) {
|
|||
return new BIP32(pk);
|
||||
});
|
||||
|
||||
w.dirty = 0;
|
||||
|
||||
return w;
|
||||
};
|
||||
|
||||
PublicKeyRing.read = function (id, passphrase) {
|
||||
var encPayload = storage.get(id);
|
||||
PublicKeyRing.read = function (encPayload, id, passphrase) {
|
||||
if (!encPayload)
|
||||
throw new Error('Could not find wallet data');
|
||||
var data;
|
||||
try {
|
||||
data = JSON.parse( PublicKeyRing.decrypt( passphrase, encPayload ));
|
||||
} catch (e) {
|
||||
throw new Error('error in storage: '+ e.toString());
|
||||
return;
|
||||
};
|
||||
throw new Error('error in read: '+ e.toString());
|
||||
}
|
||||
|
||||
if (data.id !== id)
|
||||
throw new Error('Wrong id in data');
|
||||
|
||||
|
||||
return PublicKeyRing.fromObj(data);
|
||||
};
|
||||
|
||||
|
@ -124,14 +117,11 @@ PublicKeyRing.prototype.serialize = function () {
|
|||
};
|
||||
|
||||
|
||||
PublicKeyRing.prototype.store = function (passphrase) {
|
||||
|
||||
PublicKeyRing.prototype.toStore = function (passphrase) {
|
||||
if (!this.id)
|
||||
throw new Error('wallet has no id');
|
||||
storage.set(this.id, PublicKeyRing.encrypt(passphrase,this.serialize()));
|
||||
this.dirty = 0;
|
||||
|
||||
return true;
|
||||
return PublicKeyRing.encrypt(passphrase,this.serialize());
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.registeredCopayers = function () {
|
||||
|
@ -171,7 +161,6 @@ PublicKeyRing.prototype.addCopayer = function (newEpk) {
|
|||
});
|
||||
|
||||
this.copayersBIP32.push(new BIP32(newEpk));
|
||||
this.dirty = 1;
|
||||
return newEpk;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ TxProposals.prototype.list = function() {
|
|||
});
|
||||
};
|
||||
|
||||
TxProposals.prototype.create = function(toAddress, amountSat, utxos, onePrivKey) {
|
||||
TxProposals.prototype.create = function(toAddress, amountSat, utxos, privs) {
|
||||
var pkr = this.publicKeyRing;
|
||||
|
||||
if (! pkr.isComplete() ) {
|
||||
|
@ -57,8 +57,8 @@ TxProposals.prototype.create = function(toAddress, amountSat, utxos, onePrivKey)
|
|||
.setOutputs([{address: toAddress, amountSat: amountSat}])
|
||||
;
|
||||
|
||||
if (onePrivKey) {
|
||||
b.sign([onePrivKey]);
|
||||
if (privs) {
|
||||
b.sign(privs);
|
||||
}
|
||||
|
||||
var tx = b.build();
|
||||
|
|
|
@ -47,4 +47,24 @@ describe('PrivateKey model', function() {
|
|||
}
|
||||
}
|
||||
});
|
||||
it('should derive priv keys array', function () {
|
||||
var w = new PrivateKey(config);
|
||||
var wks = w.getAll(2,3);
|
||||
wks.length.should.equal(5);
|
||||
for(var j=0; j<wks.length; j++) {
|
||||
var wk = wks[j];
|
||||
should.exist(wk);
|
||||
var o=wk.storeObj();
|
||||
should.exist(o);
|
||||
should.exist(o.priv);
|
||||
should.exist(o.pub);
|
||||
should.exist(o.addr);
|
||||
var a = new Address(o.addr);
|
||||
a.isValid().should.equal(true);
|
||||
(function() {
|
||||
var p = new PrivateKey(o.priv)
|
||||
}).should.not.throw();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,10 +6,7 @@ var bitcore = bitcore || require('bitcore');
|
|||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var copay = copay || require('../copay');
|
||||
var fakeStorage = copay.FakeStorage;
|
||||
|
||||
var PublicKeyRing = (typeof process.versions === 'undefined') ? copay.PublicKeyRing :
|
||||
require('soop').load('../js/models/PublicKeyRing', {Storage: fakeStorage});
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
|
||||
var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ';
|
||||
|
||||
|
@ -72,7 +69,7 @@ describe('PublicKeyRing model', function() {
|
|||
w.addCopayer.bind(copayers[i]).should.throw();
|
||||
});
|
||||
|
||||
it('show be able to store and retrieve', function () {
|
||||
it('show be able to tostore and read', function () {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
var copayers = k.copayers;
|
||||
|
@ -81,12 +78,12 @@ describe('PublicKeyRing model', function() {
|
|||
for(var i=0; i<5; i++)
|
||||
w.generateAddress(false);
|
||||
|
||||
w.store().should.equal(true);
|
||||
var ID = w.id;
|
||||
delete w['id'];
|
||||
w.store.bind().should.throw();
|
||||
var data = w.toStore();
|
||||
should.exist(data);
|
||||
|
||||
var w2 = PublicKeyRing.read(ID);
|
||||
var ID = w.id;
|
||||
|
||||
var w2 = PublicKeyRing.read(data, ID, 'dummy' );
|
||||
w2.isComplete().should.equal(true);
|
||||
w2.addCopayer.bind().should.throw();
|
||||
for(var i =0; i<5; i++)
|
||||
|
|
|
@ -84,7 +84,7 @@ describe('TxProposals model', function() {
|
|||
tx.isComplete().should.equal(false);
|
||||
});
|
||||
|
||||
it('#create. Singing with derivate keys', function () {
|
||||
it('#create. Signing with derivate keys', function () {
|
||||
|
||||
var priv = new PrivateKey(config);
|
||||
var w = new TxProposals({
|
||||
|
@ -104,7 +104,37 @@ describe('TxProposals model', function() {
|
|||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
unspentTest,
|
||||
priv.get(index,isChange)
|
||||
[priv.get(index,isChange)]
|
||||
);
|
||||
should.exist(tx);
|
||||
tx.isComplete().should.equal(false);
|
||||
tx.countInputMissingSignatures(0).should.equal(2);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
it('#create. Signing with derivate keys block', function () {
|
||||
|
||||
var priv = new PrivateKey(config);
|
||||
|
||||
var privs = priv.getAll(3,3);
|
||||
|
||||
var w = new TxProposals({
|
||||
networkName: config.networkName,
|
||||
publicKeyRing: createW([priv.getBIP32()]),
|
||||
});
|
||||
should.exist(w);
|
||||
w.network.name.should.equal('livenet');
|
||||
|
||||
for (var isChange=0; isChange<2; isChange++) {
|
||||
for (var index=0; index<3; index++) {
|
||||
unspentTest[0].address = w.publicKeyRing.getAddress(index, isChange);
|
||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getRedeemScript(index, isChange).getBuffer();
|
||||
var tx = w.create(
|
||||
'15q6HKjWHAksHcH91JW23BJEuzZgFwydBt',
|
||||
bignum('123456789'),
|
||||
unspentTest,
|
||||
privs
|
||||
);
|
||||
should.exist(tx);
|
||||
tx.isComplete().should.equal(false);
|
||||
|
|
Loading…
Reference in New Issue