Skip to content

Commit

Permalink
feat: upgrade fr32-sha2-256-trunc254-padded-binary-tree-multihash for…
Browse files Browse the repository at this point in the history
  • Loading branch information
travis authored Oct 30, 2023
1 parent 157b3f1 commit 22ea6aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/upload-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@ucanto/interface": "^9.0.0",
"@ucanto/transport": "^9.0.0",
"@web3-storage/capabilities": "workspace:^",
"fr32-sha2-256-trunc254-padded-binary-tree-multihash": "^3.0.0",
"fr32-sha2-256-trunc254-padded-binary-tree-multihash": "^3.1.0",
"ipfs-utils": "^9.0.14",
"multiformats": "^12.1.2",
"p-retry": "^5.1.2",
Expand Down
12 changes: 2 additions & 10 deletions packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Parallel } from 'parallel-transform-web'
import * as PieceHasher from 'fr32-sha2-256-trunc254-padded-binary-tree-multihash'
import * as PieceHasher from 'fr32-sha2-256-trunc254-padded-binary-tree-multihash/async'
import * as Link from 'multiformats/link'
import * as Digest from 'multiformats/hashes/digest'
import * as raw from 'multiformats/codecs/raw'
import * as Store from './store.js'
import * as Upload from './upload.js'
Expand Down Expand Up @@ -128,14 +127,7 @@ async function uploadBlockStream(conf, blocks, options = {}) {
const [cid, piece] = await Promise.all([
Store.add(conf, bytes, options),
(async () => {
const hasher = PieceHasher.create()
hasher.write(bytes)
const digest = new Uint8Array(hasher.multihashByteLength())
hasher.digestInto(digest, 0, true)
// There's no GC (yet) in WASM so you should free up
// memory manually once you're done.
hasher.free()
const multihashDigest = Digest.decode(digest)
const multihashDigest = await PieceHasher.digest(bytes)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, multihashDigest)
)
Expand Down
34 changes: 7 additions & 27 deletions pnpm-lock.yaml

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

0 comments on commit 22ea6aa

Please sign in to comment.