3

I am attempting to calculate a hash from an image file which is stored as .png on Arweave.

The method I am using is shown below, but I'm not sure I'm actually using the methods of the Node fetch function and the ethers.js slidityKeccak256 function properly. The function returns a result that looks right, but I'm not sure if the I'm handling the 'blob, stream and readers functions properly, and about using the type "bytes" in solidityKeccak256, (so that somebody who hasn't seen my code would come up with a similar result when they attempt to derive a Keccak hash of the file.)

I'm not confident that I have used "blob", and "stream" properly and whether "bytes" is the right type to supply to solidityKeccak256

[Typescript Node.js]
let file = await fetch(imageUrl);  //an arweave url which return a .png
let blob = await file.blob()
let  ar =  (await blob.stream().getReader().read()).value;
let hash = ethers.utils.solidityKeccak256(["bytes"], [ar ]);
return hash;

I'm also uncertain how to the same process on files stored on my local machine (although outside of the project directory) because fetch doesn't work locally. (Can use fs though) I need to make sure whether stored locally in arweave or ipfs or elsewhere, the hash returned is the same and is not hard to replicate.

GGizmos
  • 3,443
  • 4
  • 27
  • 72

0 Answers0