ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
16.18k stars 3.01k forks source link

cid command: should error on CID v0 with multibase prefix #9556

Closed lidel closed 1 year ago

lidel commented 1 year ago

Version

0.18.0-rc2

Description

UX Bug found while investigating https://github.com/multiformats/js-multiformats/issues/240:

cid format ignores the explicitly passed multibase prefix (-b) when CIDv0 is used

$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ -b z --mc dag-pb -v 0 
QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ

$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ -b z --mc dag-pb
QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ

Fix

We already return an explicit error when both custom --mc and -v 0 are passed:

$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ -b z --mc raw -v 0
Error: cannot convert to CIDv0 with any codec other than dag-pb

In the same spirit, Kubo should:

(1) error when -v 0 is present and a custom -b is passed:

$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ -b z  -v 0 
Error: cannot convert to CIDv0 with any multibase other than the implicit base58btc

(2) upgrade CID to v1 when passing a custom -b and no -v is specified, just like we do with --mc other than dag-pb:

$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ --mc raw
zb2rhY9jZ8RCMjxqDzk1eVDkNendBibd42BbRMP5UB4Ei7de2
$ ipfs cid format QmPr755CxWUwt39C2Yiw4UGKrv16uZhSgeZJmoHUUS9TSJ -b z
bafybeiawm5lgdgchgrhep4kxo2g4tptewtpcnfzusyfcopytpuj2fnzf2m
susarlanikhilesh commented 1 year ago

https://github.com/ipfs/kubo/pull/9968

Worked on the first point. Need to still work on the second point.