From 921097dea103ea94723c6996a50a902ff85a9380 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 8 Jun 2021 14:09:14 -0400 Subject: [PATCH] Accept epub for faster decrypting/encrypting --- services/gunDB/rpc/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/gunDB/rpc/index.js b/services/gunDB/rpc/index.js index 114836d2..b3cca30a 100644 --- a/services/gunDB/rpc/index.js +++ b/services/gunDB/rpc/index.js @@ -81,6 +81,7 @@ async function deepEncryptIfNeeded(value) { } const pk = /** @type {string|undefined} */ (value.$$__ENCRYPT__FOR) + const epub = /** @type {string|undefined} */ (value.$$__EPUB__FOR) if (!pk) { return Bluebird.props(mapValues(value, deepEncryptIfNeeded)) @@ -93,7 +94,15 @@ async function deepEncryptIfNeeded(value) { if (pk === u.is.pub || pk === 'me') { encryptedValue = await SEA.encrypt(actualValue, getMySecret()) } else { - const sec = await SEA.secret(await pubToEpub(pk), u._.sea) + const sec = await SEA.secret( + await (() => { + if (epub) { + return epub + } + return pubToEpub(pk) + })(), + u._.sea + ) encryptedValue = await SEA.encrypt(actualValue, sec) }