From b97b305ced1af7b9642f873be71167f673b84728 Mon Sep 17 00:00:00 2001 From: rk <59029880+rrr523@users.noreply.github.com> Date: Fri, 1 Dec 2023 18:51:23 +0800 Subject: [PATCH] fix: Multi cal hash (#409) --- .changeset/quiet-llamas-scream.md | 5 +++++ examples/nextjs/src/components/object/create/index.tsx | 5 +++++ packages/file-handle/src/browser/worker/index.js | 4 ++-- packages/file-handle/types/expose.d.ts | 6 +++--- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 .changeset/quiet-llamas-scream.md diff --git a/.changeset/quiet-llamas-scream.md b/.changeset/quiet-llamas-scream.md new file mode 100644 index 00000000..be8ba854 --- /dev/null +++ b/.changeset/quiet-llamas-scream.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfiled-file-handle': patch +--- + +fix: Multi cal hash diff --git a/examples/nextjs/src/components/object/create/index.tsx b/examples/nextjs/src/components/object/create/index.tsx index 861e2b6d..93858841 100644 --- a/examples/nextjs/src/components/object/create/index.tsx +++ b/examples/nextjs/src/components/object/create/index.tsx @@ -3,6 +3,7 @@ import { ACCOUNT_PRIVATEKEY } from '@/config/env'; import { getOffchainAuthKeys } from '@/utils/offchainAuth'; import { ChangeEvent, useState } from 'react'; import { useAccount } from 'wagmi'; +import { getCheckSumsWorker } from '@bnb-chain/greenfiled-file-handle'; export const CreateObject = () => { const { address, connector } = useAccount(); @@ -59,6 +60,10 @@ export const CreateObject = () => { return; } + const checksumWorker = getCheckSumsWorker(); + const multiCal = await checksumWorker.generateCheckSumV2(file); + console.log('multiCal', multiCal); + const fileBytes = await file.arrayBuffer(); const hashResult = await (window as any).FileHandle.getCheckSums( new Uint8Array(fileBytes), diff --git a/packages/file-handle/src/browser/worker/index.js b/packages/file-handle/src/browser/worker/index.js index 52a92709..170885cc 100644 --- a/packages/file-handle/src/browser/worker/index.js +++ b/packages/file-handle/src/browser/worker/index.js @@ -68,7 +68,7 @@ export function getChecksumApi() { const workerScript = ` importScripts('https://unpkg.com/hash-wasm@4.11.0/dist/sha256.umd.min.js') - importScripts('http://unpkg.com/@bnb-chain/greenfiled-file-handle/dist/browser/esm/wasm_exec-worker.js'); + importScripts('https://unpkg.com/@bnb-chain/greenfiled-file-handle/dist/browser/esm/wasm_exec-worker.js'); function getDecodeBase64Length(data) { let bufferLength = Math.floor(data.length * 0.75); const len = data.length; @@ -114,7 +114,7 @@ export function getChecksumApi() { const init = async () => { const go = new Go(); const result = await WebAssembly.instantiateStreaming( - fetch('https://unpkg.com/@bnb-chain/greenfiled-file-handle/dist/browser/esm/index.js'), + fetch('https://unpkg.com/@bnb-chain/greenfiled-file-handle/dist/node/file-handle-worker.wasm'), go.importObject, ); if (result) { diff --git a/packages/file-handle/types/expose.d.ts b/packages/file-handle/types/expose.d.ts index 8814289b..2daceea5 100644 --- a/packages/file-handle/types/expose.d.ts +++ b/packages/file-handle/types/expose.d.ts @@ -15,6 +15,6 @@ export function getCheckSums( redundancyVal: number; }>; -export async function generateCheckSumV2(file: File): Promise; - -export function getCheckSumsWorker(): generateCheckSumV2; +export function getCheckSumsWorker(): { + generateCheckSumV2(file: File): Promise; +};