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.

hashAlg option in ipfs.add does not work , it's overridden by sha2-256 algo #3952

Closed
@fawazahmed0

Description

@fawazahmed0
  • Version:
{
  version: '0.12.2',
  commit: '6178708aedf5ea86bf537862c08db49f5b8ea20b',
  repo: '11',
  'ipfs-core': '0.12.2',
  'interface-ipfs-core': '^0.152.2'
}
  • Platform:
    Windows 10, NodeJS v17.1.0

Severity:

Medium

Description:

The hashAlg option doesn't work in ipfs.add

Works Good(sha2-256 algo):

const fs = require('fs');
const path = require('path');
const IPFS =  require('ipfs-core')  

async function test() {

const ipfs = await IPFS.create({start: false})
const pathToFile = path.join(__dirname,'heart.pdf')
const stream = fs.createReadStream(pathToFile)
const { cid } = await ipfs.add(stream,{onlyHash:true,cidVersion:1,hashAlg:'sha2-256'})
console.info(cid.toString())
}
test()

Output:

bafybeic7kx44net5cnqaa7j54knakxm6dz52fv25mmhqsl4p7d7bfjb2xq

Confirmation:

ipfs add --only-hash --cid-version 1 --hash sha2-256 heart.pdf
added bafybeic7kx44net5cnqaa7j54knakxm6dz52fv25mmhqsl4p7d7bfjb2xq heart.pdf
 29.24 MiB / 29.24 MiB [====================================================================] 100.00%

Doesn't Work (blake2b-256 algo):

const fs = require('fs');
const path = require('path');
const IPFS =  require('ipfs-core')  

async function test() {

const ipfs = await IPFS.create({start: false})
const pathToFile = path.join(__dirname,'heart.pdf')
const stream = fs.createReadStream(pathToFile)
const { cid } = await ipfs.add(stream,{onlyHash:true,cidVersion:1,hashAlg:'blake2b-256'})
console.info(cid.toString())
}
test()

Output:

bafybeic7kx44net5cnqaa7j54knakxm6dz52fv25mmhqsl4p7d7bfjb2xq

Confirmation:

ipfs add --only-hash --cid-version 1 --hash blake2b-256 heart.pdf
added bafykbzaceakadezxvjej3mqeh7hjjlyd2sjkk4zn3mkmxdk6q5v2o2ccmw7ds heart.pdf
 29.24 MiB / 29.24 MiB [====================================================================] 100.00%

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions