From 1f09bcef42cde9e7395f12e4b236c7ee804225a8 Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 00:14:18 +0530 Subject: [PATCH 1/3] Change default encoding of CIDv1 to base32 --- cid/cid.py | 2 +- tests/test_cid.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cid/cid.py b/cid/cid.py index 07b1bed..27489c7 100644 --- a/cid/cid.py +++ b/cid/cid.py @@ -255,7 +255,7 @@ def buffer(self) -> bytes: """ return b"".join([bytes([self.version]), multicodec.add_prefix(self.codec, self.multihash)]) - def encode(self, encoding: str | None = "base58btc") -> bytes: + def encode(self, encoding: str | None = "base32") -> bytes: """ Encoded version of the raw representation diff --git a/tests/test_cid.py b/tests/test_cid.py index 9554eb0..da7b6f3 100644 --- a/tests/test_cid.py +++ b/tests/test_cid.py @@ -81,8 +81,8 @@ def test_buffer(self, cid): assert buffer[1:] == multicodec.add_prefix(self.TEST_CODEC, cid.multihash) def test_encode_default(self, cid): - """#encode defaults to base58btc encoding""" - assert cid.encode() == b"zdj7WhuEjrB52m1BisYCtmjH1hSKa7yZ3jEZ9JcXaFRD51wVz" + """#encode defaults to base32 encoding""" + assert cid.encode() == b"bafybeifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e" @pytest.mark.parametrize("codec", ENCODINGS) def test_encode_encoding(self, cid, codec): From 93964b9cfb511678ad036cd1f89672ef34d5609a Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 00:20:30 +0530 Subject: [PATCH 2/3] added newsfragment --- newsfragments/66.breaking.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/66.breaking.rst diff --git a/newsfragments/66.breaking.rst b/newsfragments/66.breaking.rst new file mode 100644 index 0000000..831d882 --- /dev/null +++ b/newsfragments/66.breaking.rst @@ -0,0 +1 @@ +Change CIDv1.encode() default encoding to base32 to conform with CID specification. From fddabc924567952f1d0c9b8e9a0c472cb89b4b6a Mon Sep 17 00:00:00 2001 From: acul71 Date: Mon, 7 Sep 2026 18:54:17 +0200 Subject: [PATCH 3/3] Document CIDv1 base32 default and expand breaking newsfragment Address maintainer review: docstring states the new default, and the changelog notes impact on str(cid) and IPLD JSON serialization. Co-authored-by: Cursor --- cid/cid.py | 7 +++++-- newsfragments/66.breaking.rst | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cid/cid.py b/cid/cid.py index 27489c7..6f8ad8b 100644 --- a/cid/cid.py +++ b/cid/cid.py @@ -257,10 +257,13 @@ def buffer(self) -> bytes: def encode(self, encoding: str | None = "base32") -> bytes: """ - Encoded version of the raw representation + Encoded version of the raw representation. + + The default encoding is ``base32`` (CID specification default for CIDv1). + Callers that need the previous default can pass ``"base58btc"`` explicitly. :param str encoding: the encoding to use to encode the raw representation, - should be supported by ``py-multibase`` + should be supported by ``py-multibase``. Defaults to ``base32``. :return: encoded raw representation with the given encoding :rtype: bytes """ diff --git a/newsfragments/66.breaking.rst b/newsfragments/66.breaking.rst index 831d882..4390717 100644 --- a/newsfragments/66.breaking.rst +++ b/newsfragments/66.breaking.rst @@ -1 +1,3 @@ -Change CIDv1.encode() default encoding to base32 to conform with CID specification. +Change CIDv1.encode() default encoding from base58btc to base32 to conform with the CID specification. + +This also changes ``str(cid)`` for CIDv1 objects (which uses ``encode()``), and therefore IPLD JSON serialization via ``to_json_dict()`` / ``CIDJSONEncoder``, which emit the string form. Callers that require base58btc must pass ``encode("base58btc")`` explicitly.