|
|
|
@ -85,6 +85,9 @@ proxy.mailboxes = {
|
|
|
|
|
if (!keys) { return void cb({error: "missing asymmetric encryption keys"}); }
|
|
|
|
|
if (!user || !user.channel || !user.curvePublic) { return void cb({error: "no notification channel"}); }
|
|
|
|
|
|
|
|
|
|
var anonRpc = Util.find(ctx, [ 'store', 'anon_rpc', ]);
|
|
|
|
|
if (!anonRpc) { return void cb({error: "anonymous rpc session not ready"}); }
|
|
|
|
|
|
|
|
|
|
var crypto = Crypto.Mailbox.createEncryptor(keys);
|
|
|
|
|
var network = ctx.store.network;
|
|
|
|
|
|
|
|
|
@ -94,29 +97,16 @@ proxy.mailboxes = {
|
|
|
|
|
});
|
|
|
|
|
var ciphertext = crypto.encrypt(text, user.curvePublic);
|
|
|
|
|
|
|
|
|
|
network.join(user.channel).then(function (wc) {
|
|
|
|
|
wc.bcast(ciphertext).then(function () {
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
|
|
// If we've just sent a message to one of our mailboxes, we have to trigger the handler manually
|
|
|
|
|
// (the server won't send back our message to us)
|
|
|
|
|
// If it isn't one of our mailboxes, we can close it now
|
|
|
|
|
var box;
|
|
|
|
|
if (Object.keys(ctx.boxes).some(function (t) {
|
|
|
|
|
var _box = ctx.boxes[t];
|
|
|
|
|
if (_box.channel === user.channel) {
|
|
|
|
|
box = _box;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
})) {
|
|
|
|
|
var hash = ciphertext.slice(0, 64);
|
|
|
|
|
box.onMessage(text, null, null, null, hash, user.curvePublic);
|
|
|
|
|
} else {
|
|
|
|
|
wc.leave();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, function (err) {
|
|
|
|
|
cb({error: err});
|
|
|
|
|
anonRpc.send("WRITE_PRIVATE_MESSAGE", [
|
|
|
|
|
user.channel,
|
|
|
|
|
ciphertext
|
|
|
|
|
], function (err, response) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return void cb({
|
|
|
|
|
error: err,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return void cb();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|