mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
unsealing own channels as well in webapp
This commit is contained in:
parent
76ce83f0c0
commit
011a439870
@ -131,9 +131,24 @@ export function useChannelContext() {
|
|||||||
return await addChannel(access.current, 'sealed', cards, data);
|
return await addChannel(access.current, 'sealed', cards, data);
|
||||||
},
|
},
|
||||||
unsealChannelSubject: (channelId, sealKey) => {
|
unsealChannelSubject: (channelId, sealKey) => {
|
||||||
console.log("unseal: ", channelId);
|
const channel = channels.current.get(channelId);
|
||||||
let sealed = channels.current.get(channelId);
|
|
||||||
console.log(sealed);
|
const { subjectEncrypted, subjectIv, seals } = JSON.parse(channel.data.channelDetail.data);
|
||||||
|
seals.forEach(seal => {
|
||||||
|
if (seal.publicKey === sealKey.public) {
|
||||||
|
let crypto = new JSEncrypt();
|
||||||
|
crypto.setPrivateKey(sealKey.private);
|
||||||
|
const unsealedKey = crypto.decrypt(seal.sealedKey);
|
||||||
|
const iv = CryptoJS.enc.Hex.parse(subjectIv);
|
||||||
|
const key = CryptoJS.enc.Hex.parse(unsealedKey);
|
||||||
|
const enc = CryptoJS.enc.Base64.parse(subjectEncrypted);
|
||||||
|
let cipher = CryptoJS.lib.CipherParams.create({ ciphertext: enc, iv: iv });
|
||||||
|
const dec = CryptoJS.AES.decrypt(cipher, key, { iv: iv });
|
||||||
|
channel.data.unsealedChannel = JSON.parse(dec.toString(CryptoJS.enc.Utf8));
|
||||||
|
channels.current.set(channel.id, { ...channel });
|
||||||
|
updateState({ channels: channels.current });
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
setChannelSubject: async (channelId, subject) => {
|
setChannelSubject: async (channelId, subject) => {
|
||||||
return await setChannelSubject(access.current, channelId, subject);
|
return await setChannelSubject(access.current, channelId, subject);
|
||||||
|
Loading…
Reference in New Issue
Block a user