BIP32 PrivateKey wrapper
This commit is contained in:
parent
e0993c90a6
commit
5e2120b0e9
5 changed files with 115 additions and 36 deletions
35
js/models/PrivateKey.js
Normal file
35
js/models/PrivateKey.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var bitcore = require('bitcore');
|
||||
var BIP32 = bitcore.BIP32;
|
||||
var WalletKey = bitcore.WalletKey;
|
||||
var networks = bitcore.networks;
|
||||
var PublicKeyRing = require('./PublicKeyRing');
|
||||
|
||||
function PrivateKey(opts) {
|
||||
this.id = opts.id;
|
||||
this.network = opts.networkName === 'testnet' ?
|
||||
networks.testnet : networks.livenet;
|
||||
this.BIP32 = opts.BIP32 || new BIP32(this.network.name);
|
||||
};
|
||||
|
||||
|
||||
PrivateKey.prototype.getBIP32 = function(index,isChange) {
|
||||
if (typeof index === 'undefined') {
|
||||
return this.BIP32;
|
||||
}
|
||||
return this.BIP32.derive( isChange ?
|
||||
PublicKeyRing.ChangeBranch(index):PublicKeyRing.PublicBranch(index) );
|
||||
};
|
||||
|
||||
PrivateKey.prototype.get = function(index,isChange) {
|
||||
var derivedBIP32 = this.getBIP32(index,isChange);
|
||||
var wk = new WalletKey({network: this.network});
|
||||
var p = derivedBIP32.eckey.private.toString('hex');
|
||||
wk.fromObj({priv: p});
|
||||
return wk;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(PrivateKey);
|
||||
|
|
@ -12,17 +12,13 @@ var buffertools = bitcore.buffertools;
|
|||
var Storage = imports.Storage || require('./Storage');
|
||||
var storage = Storage.default();
|
||||
|
||||
/*
|
||||
* This follow Electrum convetion, as described in
|
||||
* https://bitcointalk.org/index.php?topic=274182.0
|
||||
*
|
||||
* We should probably adopt the next standard once it's ready, as discussed in:
|
||||
* http://sourceforge.net/p/bitcoin/mailman/message/32148600/
|
||||
*
|
||||
*/
|
||||
function TxProposal(opts) {
|
||||
this.tx = opts.tx;
|
||||
this.seenBy = {};
|
||||
this.signedBy = {};
|
||||
};
|
||||
module.exports = require('soop')(TxProposal);
|
||||
|
||||
var PUBLIC_BRANCH = 'm/0/';
|
||||
var CHANGE_BRANCH = 'm/1/';
|
||||
|
||||
function TxProposals(opts) {
|
||||
opts = opts || {};
|
||||
|
|
@ -36,9 +32,9 @@ function TxProposals(opts) {
|
|||
this.dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
TxProposals.prototype.list = function() {
|
||||
var ret = [];
|
||||
var ret = [];
|
||||
|
||||
this.txs.forEach(function(tx) {
|
||||
});
|
||||
|
|
@ -66,9 +62,16 @@ TxProposals.prototype.create = function(toAddress, amountSat, utxos, onePrivKey)
|
|||
}
|
||||
|
||||
var tx = b.build();
|
||||
var txHex = tx.serialize();
|
||||
this.txs.push(txHex);
|
||||
return txHex;
|
||||
this.txs.push(
|
||||
new TxProposal({
|
||||
signedBy: {
|
||||
},
|
||||
seenBy: {
|
||||
},
|
||||
tx: tx
|
||||
})
|
||||
);
|
||||
return tx;
|
||||
};
|
||||
|
||||
TxProposals.prototype.sign = function(index) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue