diff --git a/net/web/src/api/setChannelSubject.js b/net/web/src/api/setChannelSubject.js index 49c95e04..8dd6a080 100644 --- a/net/web/src/api/setChannelSubject.js +++ b/net/web/src/api/setChannelSubject.js @@ -1,8 +1,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; -export async function setChannelSubject(token, channelId, subject ) { - let data = { subject }; - let params = { dataType: 'superbasic', data: JSON.stringify(data) }; +export async function setChannelSubject(token, channelId, dataType, data ) { + let params = { dataType, data: JSON.stringify(data) }; let channel = await fetchWithTimeout(`/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} ); checkResponse(channel); return await channel.json(); diff --git a/net/web/src/context/useChannelContext.hook.js b/net/web/src/context/useChannelContext.hook.js index d6f0d42f..5d59e211 100644 --- a/net/web/src/context/useChannelContext.hook.js +++ b/net/web/src/context/useChannelContext.hook.js @@ -48,7 +48,7 @@ export function useChannelContext() { else { let detail = await getChannelDetail(access.current, channel.id); cur.data.channelDetail = detail; - cur.data.unsealedSubject = null; + cur.data.unsealedChannel = null; } cur.data.detailRevision = channel.data.detailRevision; } @@ -151,7 +151,27 @@ export function useChannelContext() { }); }, setChannelSubject: async (channelId, subject) => { - return await setChannelSubject(access.current, channelId, subject); + return await setChannelSubject(access.current, channelId, 'superbasic', { subject }); + }, + setChannelSealedSubject: async (channelId, subject, sealKey) => { + const channel = channels.current.get(channelId); + + let { seals, subjectEncrypted, subjectIv } = 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 key = CryptoJS.enc.Hex.parse(unsealedKey); + + const iv = CryptoJS.lib.WordArray.random(128 / 8); + const encrypted = CryptoJS.AES.encrypt(JSON.stringify({ subject }), key, { iv: iv }); + subjectEncrypted = encrypted.ciphertext.toString(CryptoJS.enc.Base64) + subjectIv = iv.toString(); + } + }); + const data = { subjectEncrypted, subjectIv, seals }; + return await setChannelSubject(access.current, channelId, 'sealed', data); }, setChannelCard: async (channelId, cardId) => { return await setChannelCard(access.current, channelId, cardId); diff --git a/net/web/src/session/details/Details.jsx b/net/web/src/session/details/Details.jsx index a1633fc2..0b6df911 100644 --- a/net/web/src/session/details/Details.jsx +++ b/net/web/src/session/details/Details.jsx @@ -7,6 +7,7 @@ import { EditOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { CardSelect } from '../cardSelect/CardSelect'; import { EditSubject } from './editSubject/EditSubject'; import { EditMembers } from './editMembers/EditMembers'; +import { UnlockOutlined, LockFilled } from '@ant-design/icons'; export function Details({ cardId, channelId, closeDetails, closeConversation, openContact }) { @@ -117,15 +118,31 @@ export function Details({ cardId, channelId, closeDetails, closeConversation, op