From 102a25ae9c5910d082ab6c49ad0be2fc4c69747c Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Mon, 30 Oct 2023 14:31:03 -0700 Subject: [PATCH] feat: upgrade fr32-sha2-256-trunc254-padded-binary-tree-multihash for async hasher --- packages/upload-client/package.json | 2 +- packages/upload-client/src/index.js | 12 ++-------- pnpm-lock.yaml | 34 ++++++----------------------- 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/packages/upload-client/package.json b/packages/upload-client/package.json index 3ce3ca099..86c4198f9 100644 --- a/packages/upload-client/package.json +++ b/packages/upload-client/package.json @@ -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", diff --git a/packages/upload-client/src/index.js b/packages/upload-client/src/index.js index 234a08eee..3336ee0fd 100644 --- a/packages/upload-client/src/index.js +++ b/packages/upload-client/src/index.js @@ -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' @@ -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) ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 316911440..49d2774ad 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -426,8 +426,8 @@ importers: specifier: workspace:^ version: link:../capabilities fr32-sha2-256-trunc254-padded-binary-tree-multihash: - specifier: ^3.0.0 - version: 3.0.0 + specifier: ^3.1.0 + version: 3.1.0 ipfs-utils: specifier: ^9.0.14 version: 9.0.14 @@ -3317,7 +3317,7 @@ packages: '@typescript-eslint/parser': 5.62.0(eslint@8.50.0)(typescript@5.2.2) '@typescript-eslint/scope-manager': 5.62.0 '@typescript-eslint/type-utils': 5.62.0(eslint@8.50.0)(typescript@5.2.2) - '@typescript-eslint/utils': 5.62.0(eslint@8.50.0)(typescript@5.2.2) + '@typescript-eslint/utils': 5.62.0(eslint@8.50.0)(typescript@4.9.5) debug: 4.3.4(supports-color@8.1.1) eslint: 8.50.0 graphemer: 1.4.0 @@ -3450,7 +3450,7 @@ packages: optional: true dependencies: '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.2.2) - '@typescript-eslint/utils': 5.62.0(eslint@8.50.0)(typescript@5.2.2) + '@typescript-eslint/utils': 5.62.0(eslint@8.50.0)(typescript@4.9.5) debug: 4.3.4(supports-color@8.1.1) eslint: 8.50.0 tsutils: 3.21.0(typescript@5.2.2) @@ -3525,26 +3525,6 @@ packages: - typescript dev: true - /@typescript-eslint/utils@5.62.0(eslint@8.50.0)(typescript@5.2.2): - resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} - engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - dependencies: - '@eslint-community/eslint-utils': 4.4.0(eslint@8.50.0) - '@types/json-schema': 7.0.13 - '@types/semver': 7.5.3 - '@typescript-eslint/scope-manager': 5.62.0 - '@typescript-eslint/types': 5.62.0 - '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.2.2) - eslint: 8.50.0 - eslint-scope: 5.1.1 - semver: 7.5.4 - transitivePeerDependencies: - - supports-color - - typescript - dev: true - /@typescript-eslint/utils@5.62.0(eslint@8.51.0)(typescript@5.2.2): resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -6802,8 +6782,8 @@ packages: engines: {node: '>= 0.6'} dev: true - /fr32-sha2-256-trunc254-padded-binary-tree-multihash@3.0.0: - resolution: {integrity: sha512-oMeQEx55rNJ9j3tigMsxahmYOy6ch0o+pitFK0DBSClTLMZV7y+IAifE+H8OzTfeYygKEkaq0XsDfk91l0Q8GQ==} + /fr32-sha2-256-trunc254-padded-binary-tree-multihash@3.1.0: + resolution: {integrity: sha512-rpE+Ex1Hke2lPMonENYjqNJSF00fQqDMlECV8KvCLUlkv+l/PkLeZfo2/VFu909hOJQfGXHk/TXrANic0Z/Ymg==} dev: false /fraction.js@4.3.6: