Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Question? Bug? About Multihashing func #84

Closed
Schwartz10 opened this issue Nov 3, 2020 · 1 comment
Closed

Question? Bug? About Multihashing func #84

Schwartz10 opened this issue Nov 3, 2020 · 1 comment

Comments

@Schwartz10
Copy link

Schwartz10 commented Nov 3, 2020

Hi there! I'm working on a large project, where multihashing gets depended on. I'm not sure if this is a bug isolated in this package, or if it's introduced from some outer-dep (I don't expect this to be true but in this case, its ipld-dag-cbor@0.17.0).

The Multihashing.digest func, in the code comments, is supposed to return a Uint8Array. yet when I log digest instanceof Uint8Array, it returns false. This causes the following multihash.encode call to throw the error: digest should be a Uint8Array

The alg param in this instance is 0x18 or shake-128

For more clarity:

async function Multihashing (buf, alg, length) {
  console.log('buff instance of Uint8Array? ', buf instanceof Uint8Array) // => logs true
  const digest = await Multihashing.digest(buf, alg, length)
  console.log('digest instance of Uint8Array?', digest instanceof Uint8Array) // => logs false
  return multihash.encode(digest, alg, length)
}

This is obviously not going to play nicely with this line

@Schwartz10
Copy link
Author

Turns out this is a problem with jest most likely - jestjs/jest#4422

The fix was to use https://www.npmjs.com/package/jest-environment-uint8array as the jest test environment. Thanks to @oed for the tip on this one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant