Skip to content

Commit

Permalink
fix: replace blake3-multihash with hash-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Nov 30, 2023
1 parent 09589ca commit 8a85612
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"cytoscape": "^3.18.1",
"cytoscape-dagre": "^2.3.2",
"filesize": "^6.1.0",
"hash-wasm": "^4.11.0",
"helia": "^2.1.0",
"ipfs-unixfs": "^11.1.0",
"libp2p": "^1.0.0",
Expand Down
7 changes: 5 additions & 2 deletions src/lib/hash-importer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global globalThis */
import * as sha3 from '@multiformats/sha3'
import { createBLAKE3 } from 'hash-wasm'
import { type Hasher, from } from 'multiformats/hashes/hasher'
import * as sha2 from 'multiformats/hashes/sha2'

Expand Down Expand Up @@ -54,8 +55,10 @@ export async function getHasherForCode (code: number): Promise<SupportedHashers>
name: 'blake3',
code,
encode: async (data: Uint8Array): Promise<Uint8Array> => {
const { digest } = await import('blake3-multihash')
return (await digest(data)).digest
const blake3Hasher = await createBLAKE3()
blake3Hasher.init()
blake3Hasher.update(data)
return blake3Hasher.digest('binary')
}
}))
default:
Expand Down

0 comments on commit 8a85612

Please sign in to comment.