mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-14 17:41:20 +00:00
added utils
This commit is contained in:
parent
418c2c79a9
commit
d1580a3162
@ -2,7 +2,7 @@ import React, { createContext, useContext, useMemo } from "react";
|
||||
import { useAuth, UseAuthProps } from "../hooks/useAuth";
|
||||
import { useResources } from "../hooks/useResources";
|
||||
import { useAppInfo } from "../hooks/useAppInfo";
|
||||
import { addAndEncryptSymmetricKeys, IdentifierBuilder } from "../utils/encryption";
|
||||
import { addAndEncryptSymmetricKeys, decryptWithSymmetricKeys, encryptWithSymmetricKeys, IdentifierBuilder } from "../utils/encryption";
|
||||
import { useIdentifiers } from "../hooks/useIdentifiers";
|
||||
import { objectToBase64 } from "../utils/base64";
|
||||
import { base64ToObject } from "../utils/publish";
|
||||
@ -11,7 +11,9 @@ import { base64ToObject } from "../utils/publish";
|
||||
const utils = {
|
||||
objectToBase64,
|
||||
base64ToObject,
|
||||
addAndEncryptSymmetricKeys
|
||||
addAndEncryptSymmetricKeys,
|
||||
encryptWithSymmetricKeys,
|
||||
decryptWithSymmetricKeys
|
||||
}
|
||||
|
||||
|
||||
|
@ -179,7 +179,7 @@ export const addAndEncryptSymmetricKeys = async ({
|
||||
}) => {
|
||||
try {
|
||||
let highestKey = 0;
|
||||
if (previousData) {
|
||||
if (previousData && Object.keys(previousData)?.length > 0) {
|
||||
highestKey = Math.max(
|
||||
...Object.keys(previousData || {})
|
||||
.filter((item) => !isNaN(+item))
|
||||
@ -203,7 +203,7 @@ export const addAndEncryptSymmetricKeys = async ({
|
||||
});
|
||||
|
||||
if (encryptedData) {
|
||||
return encryptedData;
|
||||
return {encryptedData, publicKeys: groupmemberPublicKeys, symmetricKeys: objectToSave};
|
||||
} else {
|
||||
throw new Error("Cannot encrypt content");
|
||||
}
|
||||
@ -213,7 +213,7 @@ export const addAndEncryptSymmetricKeys = async ({
|
||||
};
|
||||
|
||||
export const encryptWithSymmetricKeys = async ({
|
||||
data64,
|
||||
base64,
|
||||
secretKeyObject,
|
||||
typeNumber = 2,
|
||||
}: any) => {
|
||||
@ -226,7 +226,7 @@ export const encryptWithSymmetricKeys = async ({
|
||||
const highestKeyObject = secretKeyObject[highestKey];
|
||||
|
||||
// Convert data and keys from base64
|
||||
const Uint8ArrayData = base64ToUint8Array(data64);
|
||||
const Uint8ArrayData = base64ToUint8Array(base64);
|
||||
const messageKey = base64ToUint8Array(highestKeyObject.messageKey);
|
||||
|
||||
if (!(Uint8ArrayData instanceof Uint8Array)) {
|
||||
@ -294,11 +294,11 @@ export const encryptWithSymmetricKeys = async ({
|
||||
return finalEncryptedData;
|
||||
};
|
||||
|
||||
interface SecretKeyValue {
|
||||
export interface SecretKeyValue {
|
||||
messageKey: string;
|
||||
}
|
||||
|
||||
export const decryptSingle = async ({
|
||||
export const decryptWithSymmetricKeys = async ({
|
||||
base64,
|
||||
secretKeyObject,
|
||||
}: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user