commit 2148b42ddc218ef90cd31c487449277389dc6dee
parent e5422d7b6fde54aec993ae7a2ac328a79f5eb1bc
Author: William Muli <willi.wambu@gmail.com>
Date: Tue, 8 Aug 2023 11:19:17 +0300
Update content schema
Diffstat:
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/src/components/ProposalForm.svelte b/src/components/ProposalForm.svelte
@@ -37,7 +37,11 @@
try {
submitting = true
- const contentSchema = generateSchema(description, descriptionFile)
+ let walaContentHash: string | undefined
+ if (descriptionFile) {
+ walaContentHash = await new Wala().put(descriptionFile, descriptionFile.type)
+ }
+ const contentSchema = generateSchema(description, walaContentHash, descriptionFile)
const signedSchema = await createSignedSchema(contentSchema, $configuredChain, $connectionDetails.userAddress)
await createWithoutOptions(signedSchema, blockWait, targetVote)
submitting = false
@@ -48,11 +52,11 @@
}
const createWithoutOptions = async (signedSchema: string, blockWait: number, targetVote: number) => {
- const localHash = await computeHash(signedSchema, 'SHA-256')
- const descriptionHash = await new Wala().put(signedSchema, 'text/plain')
+ const localSchemaHash = await computeHash(signedSchema, 'SHA-256')
+ const schemaHash = await new Wala().put(signedSchema, 'text/plain')
// compare hashes
- if (localHash !== descriptionHash) {
- console.error(`Computed description hash does not match wala hash. Local Hash: ${localHash}, Wala Hash: ${descriptionHash}`)
+ if (localSchemaHash !== schemaHash) {
+ console.error(`Computed description hash does not match wala hash. Local Hash: ${localSchemaHash}, Wala Hash: ${schemaHash}`)
} else {
console.log('Description hashes match.')
}
@@ -61,7 +65,7 @@
address: PUBLIC_VOTE_CONTRACT_ADDRESS as `0x${string}`,
abi: voteContractAbi,
functionName: 'propose',
- args: [`0x${descriptionHash}`, BigInt(blockWait), targetVote],
+ args: [`0x${schemaHash}`, BigInt(blockWait), targetVote],
account: $connectionDetails.userAddress
})
const hash = await walletClient($configuredChain).writeContract(request)
diff --git a/src/components/ProposalView.svelte b/src/components/ProposalView.svelte
@@ -85,22 +85,12 @@
}
}
- const downloadFile = () => {
- if(descriptionContent?.body === undefined) return
- // Remove the data URI prefix (e.g., "data:image/png;base64,")
- const base64WithoutPrefix = descriptionContent.body.replace(/^data:[^;]+;base64,/, '');
-
- // Convert the base64 string to a byte array
- const byteCharacters = atob(base64WithoutPrefix);
- const byteArrays = new Array(byteCharacters.length);
- for (let i = 0; i < byteCharacters.length; i++) {
- byteArrays[i] = byteCharacters.charCodeAt(i);
- }
- const byteArray = new Uint8Array(byteArrays);
-
- // Create a Blob from the byte array
- const blob = new Blob([byteArray], { type: 'application/octet-stream' });
-
+ const downloadFile = async () => {
+ if(descriptionContent?.["content-digest"] === undefined) return
+ const contentDigest = descriptionContent["content-digest"]
+ const descriptionFileHash = atob(contentDigest)
+ console.log('Description File Content Hash: ', descriptionFileHash)
+ const blob = await new Wala().get(descriptionFileHash) as Blob
// Create a download link
const downloadLink = document.createElement('a');
downloadLink.href = URL.createObjectURL(blob);
@@ -124,6 +114,7 @@
const { signature, ...contentSchema } = signedSchema
description = contentSchema.subject
descriptionContent = contentSchema.content[1] as Content
+ console.log('Content Schema', descriptionContent)
}
if(proposal.options) {
@@ -143,7 +134,7 @@
{description}
</p>
- {#if descriptionContent !== undefined && descriptionContent.body !== undefined}
+ {#if descriptionContent !== undefined && descriptionContent["content-digest"] !== undefined}
<button
class="btn btn-primary text-white btn-sm normal-case my-4 w-[200px]"
on:click={downloadFile}
diff --git a/src/shared/types.ts b/src/shared/types.ts
@@ -56,7 +56,9 @@ export interface Content {
'content-type': string;
'content-transfer-encoding': string;
'content-disposition': string;
- body: string;
+ 'content-digest-algorithm'?: string;
+ 'content-digest'?: string;
+ body?: string
}
export interface ContentSchema {