Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

IPFS hash generation #1611

Closed
Closed
@hdriqi

Description

@hdriqi

Type: Question

Description:

Hi, so i am trying to generate IPFS hash of a file but not using ipfs cli. So what I want to achieve is to have js module that generate IPFS hash that have exactly the same IPFS hash when using ipfs cli e.g "ipfs add -n [filename]".

The reason I'm not using js-ipfs is because its overkill, I mean what we need is just the hash generation algorithm nothing else.

I tried it using "js-ipld-dag-pb" to generate the merkle dag hash but when I compare it with "ipfs add -n", the hash result is different. Am I missing some steps in IPFS hash generation?

Steps to reproduce the error:

hash.js

const multihashes = require('multihashes')
const dagPB = require('ipld-dag-pb')

import { readFileSync } from 'fs'

const fileBuffer = readFileSync('./index.js')

dagPB.DAGNode.create(fileBuffer, (err, node) => {
	if(err) return console.error(err)
	console.log(multihashes.toB58String(node._cid.multihash)) 
	// output QmUkfFWUDiDDTX7pPpXusfVj31RwoQqSyFVgnx1cN7b14R

	// but [ipfs add index.js] output QmPPopR6vsHuujdQw5SnLY8u4GPCCJyLHLBWyoX7nAYNXn
})

index.js

console.log('hello world!')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions