Skip to content

Commit

Permalink
fix: upgrade fr32-sha2-256-trunc-254-padded-binary-tree-multihash (#997)
Browse files Browse the repository at this point in the history
Upgrades lib in `upload-client` to use PieceCidv2
  • Loading branch information
vasco-santos authored Oct 26, 2023
1 parent f0456d2 commit f6828ec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/upload-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build": "tsc --build",
"check": "tsc --build",
"test": "npm-run-all -p -r mock test:all",
"test:all": "run-s test:browser test:node",
"test:all": "run-s test:node test:browser",
"test:node": "hundreds -r html -r text mocha 'test/**/!(*.browser).test.js' -n experimental-vm-modules -n no-warnings",
"test:browser": "playwright-test 'test/**/!(*.node).test.js'",
"mock": "run-p mock:*",
Expand Down 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": "^1.1.4",
"fr32-sha2-256-trunc254-padded-binary-tree-multihash": "^3.0.0",
"ipfs-utils": "^9.0.14",
"multiformats": "^12.1.2",
"p-retry": "^5.1.2",
Expand Down
12 changes: 7 additions & 5 deletions packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export { Store, Upload, UnixFS, CAR }
export * from './sharding.js'

const CONCURRENT_REQUESTS = 3
const PIECE_MULTIHASH_SIZE = PieceHasher.prefix.length + PieceHasher.size

/**
* Uploads a file to the service and returns the root data CID for the
Expand Down Expand Up @@ -130,12 +129,15 @@ async function uploadBlockStream(conf, blocks, options = {}) {
Store.add(conf, bytes, options),
(async () => {
const hasher = PieceHasher.create()
const digestBytes = new Uint8Array(PIECE_MULTIHASH_SIZE)
hasher.write(bytes)
hasher.digestInto(digestBytes, 0, true)
const digest = Digest.decode(digestBytes)
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)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, digest)
Link.create(raw.code, multihashDigest)
)
})(),
])
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-client/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ describe('uploadCAR', () => {
assert.equal(pieceCIDs.length, 1)
assert.equal(
pieceCIDs[0].toString(),
'bafkzcibbammseumg3mjlev5odi5bpcsrp4gg62d7xnx44zkxzvgedq7nxldbc'
'bafkzcibcoibrsisrq3nrfmsxvynduf4kkf7qy33ip65w7ttfk7guyqod5w5mmei'
)
})
})
8 changes: 4 additions & 4 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 f6828ec

Please sign in to comment.