Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
$.checkState(this.xPrivKey || (this.xPubKey && this.entropySource));
var network = Credentials._getNetworkFromExtendedKey(this.xPrivKey || this.xPubKey);
if (this.network) {
$.checkState(this.network == network);
} else {
this.network = network;
}
if (this.xPrivKey) {
console.log('_expand path: ' + this.getBaseAddressDerivationPath());
var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey);
// this extra derivation is not to share a non hardened xPubKey to the server.
var addressDerivation = xPrivKey.derive(this.getBaseAddressDerivationPath());
this.xPubKey = (new Bitcore.HDPublicKey(addressDerivation)).toString();
console.log('_expand xPubKey: ' + this.xPubKey);
} else {
}
this.publicKeyRing = [{
xPubKey: this.xPubKey,
}];
};
$.checkState(this.xPrivKey || (this.xPubKey && this.entropySource));
var network = Credentials._getNetworkFromExtendedKey(this.xPrivKey || this.xPubKey);
if (this.network) {
$.checkState(this.network == network);
} else {
this.network = network;
}
if (this.xPrivKey) {
console.log('_expand path: '+this.getBaseAddressDerivationPath());
var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey);
// this extra derivation is not to share a non hardened xPubKey to the server.
var addressDerivation = xPrivKey.derive(this.getBaseAddressDerivationPath());
this.xPubKey = (new Bitcore.HDPublicKey(addressDerivation)).toString();
console.log('_expand xPubKey: '+this.xPubKey);
} else {
}
this.publicKeyRing = [{
xPubKey: this.xPubKey,
}];
};
var pkr = _.map(w.publicKeyRing.copayersExtPubKeys, function(xPubStr) {
var isMe = xPubStr === credentials.xPubKey;
var requestDerivation;
if (isMe) {
var path = Constants.PATHS.REQUEST_KEY;
requestDerivation = (new Bitcore.HDPrivateKey(credentials.xPrivKey))
.derive(path).hdPublicKey;
} else {
// this
var path = Constants.PATHS.REQUEST_KEY_AUTH;
requestDerivation = (new Bitcore.HDPublicKey(xPubStr)).derive(path);
}
// Grab Copayer Name
var hd = new Bitcore.HDPublicKey(xPubStr).derive('m/2147483646/0/0');
var pubKey = hd.publicKey.toString('hex');
var copayerName = w.publicKeyRing.nicknameFor[pubKey];
if (isMe) {
credentials.copayerName = copayerName;
}
return {
xPubKey: xPubStr,
requestPubKey: requestDerivation.publicKey.toString(),
copayerName: copayerName,
};
});
_.each(_.range(n), function(c) {
var xpriv = new Bitcore.HDPrivateKey();
var xpub = Bitcore.HDPublicKey(xpriv);
var xpriv_45H = xpriv.derive(45, true);
var xpub_45H = Bitcore.HDPublicKey(xpriv_45H);
var id45 = Copayer._xPubToCopayerId(xpub_45H.toString());
var xpriv_44H_0H_0H = xpriv.derive(44, true).derive(0, true).derive(0, true);
var xpub_44H_0H_0H = Bitcore.HDPublicKey(xpriv_44H_0H_0H);
var id44 = Copayer._xPubToCopayerId(xpub_44H_0H_0H.toString());
var xpriv_1H = xpriv.derive(1, true);
var xpub_1H = Bitcore.HDPublicKey(xpriv_1H);
var priv = xpriv_1H.derive(0).privateKey;
var pub = xpub_1H.derive(0).publicKey;
console.log('{id44: ', "'" + id44 + "',");
console.log('id45: ', "'" + id45 + "',");
console.log('xPrivKey: ', "'" + xpriv.toString() + "',");
console.log('xPubKey: ', "'" + xpub.toString() + "',");
console.log('xPrivKey_45H: ', "'" + xpriv_45H.toString() + "',");
it('should fail to check a request pub key with wrong key', function() {
var reqPubKey = '02c2c1c6e75cfc50235ff4a2eb848385c2871b8c94e285ee82eaced1dcd5dd568e';
var xPrivKey = new Bitcore.HDPrivateKey();
var xPubKey = new Bitcore.HDPublicKey(xPrivKey);
var sig = Utils.signRequestPubKey(reqPubKey, xPrivKey);
var xPrivKey2 = new Bitcore.HDPrivateKey();
var xPubKey2 = new Bitcore.HDPublicKey(xPrivKey2);
var valid = Utils.verifyRequestPubKey(reqPubKey, sig, xPubKey2);
valid.should.be.equal(false);
});
});
function setCurrentWallet() {
xPubKey = Bitcore.HDPublicKey(self.xPrivKey.derive("m/44'/0'/" + currentWalletIndex + "'"));
checkAndAddCurrentAddresses(0);
}
const verifyRequestSignature = (params: VerificationPayload): boolean => {
const { message, pubKey, signature } = params;
const pub = new bitcoreLib.HDPublicKey(pubKey)
.deriveChild('m/2')
.publicKey.toBuffer();
const messageHash = bitcoreLib.crypto.Hash.sha256sha256(Buffer.from(message));
if (typeof signature === 'string') {
return secp256k1.verify(messageHash, Buffer.from(signature, 'hex'), pub);
} else {
throw new Error('Signature must exist');
}
};
function setCurrentWallet() {
xPubKey = Bitcore.HDPublicKey(self.xPrivKey.derive("m/44'/0'/" + currentWalletIndex + "'"));
checkAndAddCurrentAddresses(0);
}
function testLiveKeys() {
var words;
try {
words = c.getMnemonic();
} catch (ex) {}
var xpriv;
if (words && (!c.mnemonicHasPassphrase || opts.passphrase)) {
var m = new Mnemonic(words);
xpriv = m.toHDPrivateKey(opts.passphrase, c.network);
}
if (!xpriv) {
xpriv = new Bitcore.HDPrivateKey(c.xPrivKey);
}
xpriv = xpriv.deriveChild(c.getBaseAddressDerivationPath());
var xpub = new Bitcore.HDPublicKey(c.xPubKey);
return testMessageSigning(xpriv, xpub);
};
opts,
['walletId', 'name', 'xPubKey', 'requestPubKey', 'copayerSignature'],
cb
)
)
return;
if (_.isEmpty(opts.name)) return cb(new ClientError('Invalid copayer name'));
opts.coin = opts.coin || Defaults.COIN;
if (!Utils.checkValueInCollection(opts.coin, Constants.COINS))
return cb(new ClientError('Invalid coin'));
var xPubKey;
try {
xPubKey = Bitcore.HDPublicKey(opts.xPubKey);
} catch (ex) {
return cb(new ClientError('Invalid extended public key'));
}
if (_.isUndefined(xPubKey.network)) {
return cb(new ClientError('Invalid extended public key'));
}
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH)
? opts.supportBIP44AndP2PKH
: true;
self.walletId = opts.walletId;
self._runLocked(cb, function(cb) {
self.storage.fetchWallet(opts.walletId, function(err, wallet) {
if (err) return cb(err);
if (!wallet) return cb(Errors.WALLET_NOT_FOUND);