CIDv1.encode() defaults to base58btc encoding. The CID specification recommends base32 as the default encoding for CIDv1 strings. Go's Cid.String() uses base32 for CIDv1.
Problem
In cid/cid.py:
class CIDv1(BaseCID):
def encode(self, encoding: str | None = "base58btc") -> bytes:
return multibase.encode(encoding, self.buffer)
cid = CIDv1("dag-pb", some_hash)
str(cid) # → "zdj7Wh..." (base58btc)
Go's implementation:
func (c Cid) String() string {
switch c.Version() {
case 0:
return c.Hash().B58String()
case 1:
mbstr, _ := mbase.Encode(mbase.Base32, c.Bytes())
return mbstr // → "bafybei..." (base32)
}
}
The CID spec says:
"The default base encoding for CIDv1 is base32 (lowercase, no padding)."
Proposed Solution
Change the default encoding to base32:
class CIDv1(BaseCID):
def encode(self, encoding: str | None = "base32") -> bytes:
return multibase.encode(encoding, self.buffer)
⚠️ Breaking change: This changes the output of str(cid) for all CIDv1 objects. Consider:
- Adding a deprecation warning for one release cycle
- Or documenting this as a breaking change in the changelog
Update all tests that check CIDv1 string representations.
Related
CIDv1.encode()defaults tobase58btcencoding. The CID specification recommendsbase32as the default encoding for CIDv1 strings. Go'sCid.String()uses base32 for CIDv1.Problem
In
cid/cid.py:Go's implementation:
The CID spec says:
Proposed Solution
Change the default encoding to
base32:str(cid)for all CIDv1 objects. Consider:Update all tests that check CIDv1 string representations.
Related
cid.goString()