feat: added hashes.json in zip
All checks were successful
Release / build_and_release (push) Successful in 56s
All checks were successful
Release / build_and_release (push) Successful in 56s
This commit is contained in:
parent
9fa3df3850
commit
d879c7d45a
@ -214,8 +214,16 @@ export const HomePage = () => {
|
||||
|
||||
try {
|
||||
const stringifiedMeta = JSON.stringify(meta, null, 2)
|
||||
|
||||
zip.file('meta.json', stringifiedMeta)
|
||||
|
||||
const metaHash = await getHash(stringifiedMeta)
|
||||
if (!metaHash) return
|
||||
|
||||
const metaHashJson = {
|
||||
[usersPubkey!]: metaHash
|
||||
}
|
||||
|
||||
zip.file('hashes.json', JSON.stringify(metaHashJson, null, 2))
|
||||
} catch (err) {
|
||||
toast.error('An error occurred in converting meta json to string')
|
||||
}
|
||||
|
@ -78,7 +78,27 @@ export const SignDocument = () => {
|
||||
return null
|
||||
})
|
||||
|
||||
if (!meta) return
|
||||
const hashesFileContent = await readContentOfZipEntry(
|
||||
zip,
|
||||
'hashes.json',
|
||||
'string'
|
||||
)
|
||||
|
||||
if (!hashesFileContent) {
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
const hashes = await parseJson(hashesFileContent).catch((err) => {
|
||||
console.log('err in parsing the content of hashes.json :>> ', err)
|
||||
toast.error(
|
||||
err.message || 'error occurred in parsing the content of hashes.json'
|
||||
)
|
||||
setIsLoading(false)
|
||||
return null
|
||||
})
|
||||
|
||||
if (!hashes) return
|
||||
|
||||
setLoadingSpinnerDesc('Generating hashes for files')
|
||||
|
||||
@ -117,12 +137,12 @@ export const SignDocument = () => {
|
||||
// if current user is the last signer, then send DMs to all viewers
|
||||
if (isLastSigner) {
|
||||
for (const viewer of meta.viewers) {
|
||||
await signAndSendToNext(zip, meta, viewer, fileHashes, false)
|
||||
await signAndSendToNext(zip, meta, hashes, viewer, fileHashes, false)
|
||||
}
|
||||
} else {
|
||||
const nextSigner = meta.signers[signerIndex + 1]
|
||||
|
||||
await signAndSendToNext(zip, meta, nextSigner, fileHashes, true)
|
||||
await signAndSendToNext(zip, meta, hashes, nextSigner, fileHashes, true)
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
@ -131,6 +151,7 @@ export const SignDocument = () => {
|
||||
const signAndSendToNext = async (
|
||||
zip: JSZip,
|
||||
meta: any,
|
||||
hashes: any,
|
||||
receiver: string,
|
||||
fileHashes: {
|
||||
[key: string]: string
|
||||
@ -155,6 +176,16 @@ export const SignDocument = () => {
|
||||
const stringifiedMeta = JSON.stringify(meta, null, 2)
|
||||
zip.file('meta.json', stringifiedMeta)
|
||||
|
||||
const metaHash = await getHash(stringifiedMeta)
|
||||
if (!metaHash) return
|
||||
|
||||
hashes = {
|
||||
...hashes,
|
||||
[usersPubkey!]: metaHash
|
||||
}
|
||||
|
||||
zip.file('hashes.json', JSON.stringify(hashes, null, 2))
|
||||
|
||||
const arrayBuffer = await zip
|
||||
.generateAsync({
|
||||
type: 'arraybuffer',
|
||||
|
@ -6,12 +6,12 @@ import { toast } from 'react-toastify'
|
||||
* @param arrayBuffer The ArrayBuffer to hash.
|
||||
* @returns A Promise resolving to the SHA-256 hash as a hexadecimal string, or null if hashing fails.
|
||||
*/
|
||||
export const getHash = async (arrayBuffer: ArrayBuffer) => {
|
||||
export const getHash = async (input: ArrayBuffer | string) => {
|
||||
// Compute the SHA-256 hash of the array buffer
|
||||
const hash = await sha256(arrayBuffer).catch((err) => {
|
||||
const hash = await sha256(input).catch((err) => {
|
||||
// Handle error if hashing fails
|
||||
console.log(`error occurred in hashing arrayBuffer :>> `, err)
|
||||
toast.error(err.message || `error occurred in hashing arrayBuffer`)
|
||||
toast.error(err.message || `error occurred in hashing`)
|
||||
return null // Return null if hashing fails
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user