Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function KeychainGenerator(keyString) {
if (keyString) {
this.rootKeychain = new HDPrivateKey(keyString)
} else {
this.rootKeychain = new HDPrivateKey()
}
}
API.prototype._getSignaturesFor = function(txp, wcd) {
//Derive proper key to sign, for each input
var privs = [],
derived = {};
var network = new Bitcore.Address(txp.toAddress).network.name;
var xpriv = new Bitcore.HDPrivateKey(wcd.xPrivKey, network);
_.each(txp.inputs, function(i) {
if (!derived[i.path]) {
derived[i.path] = xpriv.derive(i.path).privateKey;
privs.push(derived[i.path]);
}
});
var t = new Bitcore.Transaction();
_.each(txp.inputs, function(i) {
t.from(i, i.publicKeys, txp.requiredSignatures);
});
t.to(txp.toAddress, txp.amount)
.change(txp.changeAddress.address);
Credentials.create = function(network) {
var x = new Credentials();
x.network = network;
x.xPrivKey = (new Bitcore.HDPrivateKey(network)).toString();
x._expand();
return x;
};
function _createXPrivKey() {
return new Bitcore.HDPrivateKey().toString();
};
function _initWcd(network) {
$.checkArgument(network);
var xPrivKey = new Bitcore.HDPrivateKey(network);
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
var roPrivKey = xPrivKey.derive('m/1/0').privateKey;
var rwPrivKey = xPrivKey.derive('m/1/1').privateKey;
var copayerId = WalletUtils.xPubToCopayerId(xPubKey);
return {
copayerId: copayerId,
xPrivKey: xPrivKey.toString(),
publicKeyRing: [xPubKey],
network: network,
roPrivKey: roPrivKey.toWIF(),
rwPrivKey: rwPrivKey.toWIF(),
};
};
function KeychainGenerator(keyString) {
if (keyString) {
this.rootKeychain = new HDPrivateKey(keyString)
} else {
this.rootKeychain = new HDPrivateKey()
}
}
this.storage.load(function(err, wcd) {
if (wcd)
return cb('Storage already contains a wallet');
wcd = {};
var inData = JSON.parse(str);
var i = 0;
_.each(WALLET_CRITICAL_DATA.concat(WALLET_EXTRA_DATA), function(k) {
wcd[k] = inData[i++];
});
if (wcd.xPrivKey) {
var xpriv = new Bitcore.HDPrivateKey(wcd.xPrivKey);
var xPubKey = new Bitcore.HDPublicKey(xpriv).toString();
wcd.publicKeyRing.unshift(xPubKey);
wcd.copayerId = WalletUtils.xPubToCopayerId(xPubKey);
wcd.roPrivKey = xpriv.derive('m/1/0').privateKey.toWIF();
wcd.rwPrivKey = xpriv.derive('m/1/1').privateKey.toWIF();
}
if (!wcd.publicKeyRing)
return cb('Invalid source wallet');
wcd.network = wcd.publicKeyRing[0].substr(0, 4) == 'tpub' ? 'testnet' : 'livenet';
self.save(wcd, function(err) {
return cb(err, WalletUtils.accessFromData(wcd));
});
});