diff --git a/src/components/Apps/useQortalMessageListener.tsx b/src/components/Apps/useQortalMessageListener.tsx index 677a02f..bebbeeb 100644 --- a/src/components/Apps/useQortalMessageListener.tsx +++ b/src/components/Apps/useQortalMessageListener.tsx @@ -33,6 +33,7 @@ const allowedParams= ["name", "service", "identifier", "mimeType", "fileName", " .join("&"); // Join with `&` }; export const createAndCopyEmbedLink = async (data) => { + const requiredFields = [ "type", ]; @@ -239,7 +240,7 @@ const UIQortalRequests = [ 'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE', 'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER', 'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', - 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA' + 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY' ]; @@ -615,7 +616,7 @@ isDOMContentLoaded: false } else if(event?.data?.action === 'CREATE_AND_COPY_EMBED_LINK'){ try { - const link = await createAndCopyEmbedLink(event?.data?.payload) + const link = await createAndCopyEmbedLink(event?.data) event.ports[0].postMessage({ result: link, error: null, diff --git a/src/qdn/encryption/group-encryption.ts b/src/qdn/encryption/group-encryption.ts index 12c9310..860b6a8 100644 --- a/src/qdn/encryption/group-encryption.ts +++ b/src/qdn/encryption/group-encryption.ts @@ -65,7 +65,7 @@ export const createSymmetricKeyAndNonce = () => { }; -export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey }: any) => { +export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey, customSymmetricKey }: any) => { let combinedPublicKeys = [...publicKeys, userPublicKey] const decodedPrivateKey = Base58.decode(privateKey) @@ -76,9 +76,16 @@ export const encryptDataGroup = ({ data64, publicKeys, privateKey, userPublicKey throw new Error("The Uint8ArrayData you've submitted is invalid") } try { - // Generate a random symmetric key for the message. - const messageKey = new Uint8Array(32) + let messageKey + if(customSymmetricKey){ + messageKey = base64ToUint8Array(customSymmetricKey) + } else { + messageKey = new Uint8Array(32) crypto.getRandomValues(messageKey) + } + + if(!messageKey) throw new Error('Cannot create symmetric key') + const nonce = new Uint8Array(24) crypto.getRandomValues(nonce) // Encrypt the data with the symmetric key. @@ -461,7 +468,6 @@ export function decryptDeprecatedSingle(uint8Array, publicKey, privateKey) { } export const decryptGroupEncryptionWithSharingKey = async ({ data64EncryptedData, key }: any) => { - const allCombined = base64ToUint8Array(data64EncryptedData) const str = "qortalGroupEncryptedData" const strEncoder = new TextEncoder() @@ -487,7 +493,6 @@ export const decryptGroupEncryptionWithSharingKey = async ({ data64EncryptedData const encryptedDataEndPosition = allCombined.length - ((count * (32 + 16)) + 4) const encryptedData = allCombined.slice(encryptedDataStartPosition, encryptedDataEndPosition) const symmetricKey = base64ToUint8Array(key); - // Decrypt the data using the nonce and messageKey const decryptedData = nacl.secretbox.open(encryptedData, nonce, symmetricKey) diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts index d2b6a08..28a6004 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -841,9 +841,7 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) => ) { throw new Error("Encrypting data requires public keys"); } - if (!data.encrypt && data.service.endsWith("_PRIVATE")) { - throw new Error("Only encrypted data can go into private services"); - } + if (data.fileId) { data64 = await getFileFromContentScript(data.fileId, sender); } @@ -3353,7 +3351,6 @@ export const encryptDataWithSharingKey = async (data, sender) => { export const decryptDataWithSharingKey = async (data, sender) => { const { encryptedData, key } = data; - if (!encryptedData) { throw new Error("Please include data to decrypt");