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;
}
};
export function btcVerifyMessage (msg: BTCVerifyMessage): Promise {
const signature = Base64.fromByteArray(fromHexString(msg.signature))
return verify(msg.message, msg.address, signature)
}
APIClient.prototype.verifyMessage = function(message, address, signature, cb) {
var self = this;
var deferred = q.defer();
deferred.promise.nodeify(cb);
try {
var result = bitcoinMessage.verify(address, self.network.messagePrefix, message, new Buffer(signature, 'base64'));
deferred.resolve(result);
} catch (e) {
deferred.reject(e);
}
return deferred.promise;
};
function VerifySig(address, data, sig) {
return btcMessage.verify(data, address, sig, "\x18Bitcoin Signed Message:\n")
}
export async function btcVerifyMessage (msg: BTCVerifyMessage): Promise {
const signature = Base64.fromByteArray(fromHexString(msg.signature))
return verify(msg.message, msg.address, signature)
}