I\'m trying to create an IPFS compatible mutihash but it is not matching. I am asking here because I have not yet found an example that takes this from hashing to the end r
Some of the other answers are outdated. This is what worked for me:
const Unixfs = require('ipfs-unixfs'); // @0.1.16
const { DAGNode } = require('ipld-dag-pb'); // @0.18.1
const bs58 = require('bs58'); // @4.0.1
// ...
const data = Buffer.from('hello world');
const unixFs = new Unixfs('file', data)
const dagNode = new DAGNode(unixFs.marshal());
const link = await dagNode.toDAGLink();
const multihash = bs58.encode(link._cid.multihash).toString();
console.log(multihash); // Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD