Skip to content
This repository has been 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 opened this issue Nov 24, 2021 · 2 comments · Fixed by #4042
Closed

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

fawazahmed0 opened this issue Nov 24, 2021 · 2 comments · Fixed by #4042
Labels
need/triage Needs initial labeling and prioritization

Comments

@fawazahmed0
Copy link

fawazahmed0 commented Nov 24, 2021

  • 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

@fawazahmed0 fawazahmed0 added the need/triage Needs initial labeling and prioritization label Nov 24, 2021
@welcome
Copy link

welcome bot commented Nov 24, 2021

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@fawazahmed0 fawazahmed0 changed the title hashAlg option in ipfs.add does not work , it's overridden by sha2-256 hashAlg option in ipfs.add does not work , it's overridden by sha2-256 algo Nov 24, 2021
@lidel
Copy link
Member

lidel commented Nov 26, 2021

HTTP RPC API in go-ipfs uses hash: https://docs.ipfs.io/reference/http/api/#api-v0-add

@fawazahmed0 if you use go-ipfs on backend the workaround here is to pass hash instead of hashAlg

@achingbrain would the fix here be adding hashAlghash normalization to the ipfs-http-client and switching ipfs-http-server from hash-alg to hash? we should unify this.

achingbrain added a commit that referenced this issue Feb 4, 2022
Looks like this got missed during the multiformats migration.

Fixes #3952
achingbrain added a commit that referenced this issue Feb 5, 2022
Looks like this got missed during the multiformats migration.

Fixes #3952
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants