Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
otherParties: ['test_counterparty_1'],
walletPassphrase: TestV2BitGo.OFC_TEST_PASSWORD
});
should.exist(payload);
// The payload should be a valid JSON object
// NOTE: we shouldn't do any more validation than this, as the schema is subject to change often
(() => { JSON.parse(payload); }).should.not.throw();
should.exist(signature);
// signature should be a hex string
signature.should.match(/^[0-9a-f]+$/);
const address = HDNode.fromBase58(xpub).getAddress();
bitcoinMessage.verify(payload, address, Buffer.from(signature, 'hex')).should.be.True();
msScope.isDone().should.be.True();
platformScope.isDone().should.be.True();
}));
});
/* Delete signs (as we can't verify ourselves in the signature). */
delete config.signs;
/* Convert the JSON to a string. */
// NOTE: This matches the functionality of Python's `json.dumps` spacing.
config = JSON.stringify(config)
.replace(/":/g, '": ')
.replace(/,"/g, ', "');
/* Escape all unicode characters. */
// NOTE: This matches the functionality of Python's `unicode` handling.
config = escapeUnicode(config);
/* Verify the Bitcoin signature. */
const isValid = bitcoinMessage.verify(config, address, signature);
console.info('content.json isValid', isValid);
let test3Txt = this.state.test3Txt + '\n' + isValid;
this.setState({test3Txt});
} catch (err) {
// FIXME WTF is going on here with `config.signs` being undefined.
console.log('VERIFICATION ERROR: (we may just ignore)', err);
}
}
}
if (userPrivateKey.neutered().toBase58() !== userPub) {
throw new Error('user private key does not match public key');
}
}
const backupPubSignature = keySignatures.backupPub;
const bitgoPubSignature = keySignatures.bitgoPub;
// verify the signatures against the user public key
const signingAddress = userKey.keyPair.getAddress();
// BG-5703: use BTC mainnet prefix for all key signature operations
// (this means do not pass a prefix parameter, and let it use the default prefix instead)
const isValidBackupSignature = bitcoinMessage.verify(keychains.backup.pub, signingAddress, Buffer.from(backupPubSignature, 'hex'));
const isValidBitgoSignature = bitcoinMessage.verify(keychains.bitgo.pub, signingAddress, Buffer.from(bitgoPubSignature, 'hex'));
if (!isValidBackupSignature || !isValidBitgoSignature) {
throw new Error('secondary public key signatures invalid');
}
} else if (!disableNetworking) {
// these keys were obtained online and their signatures were not verified
// this could be dangerous
console.log('unsigned keys obtained online are being used for address verification');
}
const missingOutputs = parsedTransaction.missingOutputs;
if (missingOutputs.length !== 0) {
// there are some outputs in the recipients list that have not made it into the actual transaction
throw new Error('expected outputs missing in transaction prebuild');
}
const verifyMessage = ({ message = "", address = "", signature = "", selectedCrypto = "" } = {}) => {
try {
const network = networks[selectedCrypto];
const messagePrefix = network.messagePrefix;
return bitcoinMessage.verify(message, address, signature, messagePrefix);
} catch (e) {
console.log(e);
return false;
}
};
const signMessage = (message, encodedPrivateKey) => {
const keyPair = bitcoincash.ECPair.fromWIF(encodedPrivateKey, bch.network)
const privateKey = keyPair.d.toBuffer(32)
const signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)
return signature.toString('base64')
}
const signMessage = (message, encodedPrivateKey) => {
const keyPair = bitcoin.ECPair.fromWIF(encodedPrivateKey, [bitcoin.networks.bitcoin, bitcoin.networks.testnet])
const privateKey = keyPair.d.toBuffer(32)
const signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)
return signature.toString('base64')
}
signMessageWithPrivKey(privateKeyWIF, message) {
let network = privateKeyWIF.charAt(0) === 'c' ? 'testnet' : 'bitcoincash';
let bitcoincash;
if(network === 'bitcoincash') {
bitcoincash = coininfo.bitcoincash.main;
} else {
bitcoincash = coininfo.bitcoincash.test;
}
let bitcoincashBitcoinJSLib = bitcoincash.toBitcoinJS();
let keyPair = Bitcoin.ECPair.fromWIF(privateKeyWIF, bitcoincashBitcoinJSLib)
let privateKey = keyPair.d.toBuffer(32)
return bitcoinMessage.sign(message, privateKey, keyPair.compressed).toString('base64');
}
const signMessage = (message, encodedPrivateKey) => {
const keyPair = bitcoin.ECPair.fromWIF(encodedPrivateKey, [bitcoin.networks.bitcoin, bitcoin.networks.testnet])
const privateKey = keyPair.d.toBuffer(32)
const signature = bitcoinMessage.sign(message, privateKey, keyPair.compressed)
return signature.toString('base64')
}
async signMessage (message, from) {
const address = await this.getWalletAddress(from)
const keyPair = await this.keyPair(address.derivationPath)
const signature = bitcoinMessage.sign(message, keyPair.privateKey, keyPair.compressed)
return signature.toString('hex')
}
if (typeof compressed !== 'boolean') {
throw new Error('Second argument must be a boolean');
}
if (!(Buffer.isBuffer(iv) && iv.length === 16)) {
throw new Error('Argument "iv" must be a 16 bytes buffer');
}
let decrypted = null;
try {
decrypted = this._decrypt(key, iv);
} catch (err) {
throw new Error('Failed to decrypt key');
}
return message.sign(msg, decrypted, compressed).toString('base64');
}