mirror of https://github.com/BTCPrivate/copay.git
change encryption to work on hex strings
..instead of binary, to work around an issue with bitcore/sjcl. I'm not sure what the issue is exactly, except that encryption of binary data isn't working correctly due to some kind of string stuff involving decodeURIComponent inside sjcl. I haven't fully figured it out. For now I am changing the network protocol to hex to workaround the issue. See this: https://github.com/bitpay/bitcore/pull/416
This commit is contained in:
parent
88ab38eb00
commit
643cad3a39
|
@ -21,7 +21,8 @@ Message.encode = function(topubkey, fromkey, payload, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
|
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
|
||||||
var encrypted = Message._encrypt(topubkey, toencrypt);
|
var toencrypthexbuf = new Buffer(toencrypt.toString('hex')); //due to bug in sjcl/bitcore, must use hex string
|
||||||
|
var encrypted = Message._encrypt(topubkey, toencrypthexbuf);
|
||||||
var sig = Message._sign(fromkey, encrypted);
|
var sig = Message._sign(fromkey, encrypted);
|
||||||
var encoded = {
|
var encoded = {
|
||||||
pubkey: fromkey.public.toString('hex'),
|
pubkey: fromkey.public.toString('hex'),
|
||||||
|
@ -63,7 +64,8 @@ Message.decode = function(key, encoded, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var decrypted = Message._decrypt(key.private, encrypted);
|
var decryptedhexbuf = Message._decrypt(key.private, encrypted);
|
||||||
|
var decrypted = new Buffer(decryptedhexbuf.toString(), 'hex'); //workaround for bug in bitcore/sjcl
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('Cannot decrypt data: ' + e);
|
throw new Error('Cannot decrypt data: ' + e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ describe('Message model', function() {
|
||||||
var version2 = new Buffer([0]);
|
var version2 = new Buffer([0]);
|
||||||
var nonce = new Buffer([0, 0, 0, 0, 0, 0, 0, 0]);
|
var nonce = new Buffer([0, 0, 0, 0, 0, 0, 0, 0]);
|
||||||
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
|
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
|
||||||
var encrypted = Message._encrypt(topubkey, toencrypt);
|
var toencrypt_workaround = new Buffer(toencrypt.toString('hex'));
|
||||||
|
var encrypted = Message._encrypt(topubkey, toencrypt_workaround);
|
||||||
var sig = Message._sign(fromkey, encrypted);
|
var sig = Message._sign(fromkey, encrypted);
|
||||||
var encoded = {
|
var encoded = {
|
||||||
pubkey: fromkey.public.toString('hex'),
|
pubkey: fromkey.public.toString('hex'),
|
||||||
|
|
Loading…
Reference in New Issue