How to create an IPFS compatible multihash

前端 未结 5 1879
天命终不由人
天命终不由人 2020-12-30 07:00

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

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 07:35

    const { randomBytes } = require('crypto')
    const multihash = require('multihashes')
    
    const buffer = Buffer.from(randomBytes(32), 'hex')
    const encoded = multihash.encode(buffer, 'sha2-256')
    const hash = multihash.toB58String(encoded)
    console.log(hash)
    

提交回复
热议问题