multiaddr 0.0.12__tar.gz → 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {multiaddr-0.0.12 → multiaddr-0.1.0}/HISTORY.rst +15 -0
  2. {multiaddr-0.0.12 → multiaddr-0.1.0}/PKG-INFO +4 -2
  3. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/__init__.py +1 -1
  4. multiaddr-0.1.0/multiaddr/codecs/certhash.py +85 -0
  5. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/protocols.py +8 -0
  6. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/PKG-INFO +4 -2
  7. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/SOURCES.txt +1 -0
  8. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/requires.txt +2 -0
  9. {multiaddr-0.0.12 → multiaddr-0.1.0}/pyproject.toml +5 -3
  10. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/test_multiaddr.py +13 -0
  11. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/test_protocols.py +65 -1
  12. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/test_thin_waist_addresses.py +0 -9
  13. {multiaddr-0.0.12 → multiaddr-0.1.0}/AUTHORS +0 -0
  14. {multiaddr-0.0.12 → multiaddr-0.1.0}/CONTRIBUTING.rst +0 -0
  15. {multiaddr-0.0.12 → multiaddr-0.1.0}/LICENSE-APACHE2 +0 -0
  16. {multiaddr-0.0.12 → multiaddr-0.1.0}/LICENSE-MIT +0 -0
  17. {multiaddr-0.0.12 → multiaddr-0.1.0}/MANIFEST.in +0 -0
  18. {multiaddr-0.0.12 → multiaddr-0.1.0}/README.rst +0 -0
  19. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/__init__.py +0 -0
  20. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/cid.py +0 -0
  21. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/domain.py +0 -0
  22. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/fspath.py +0 -0
  23. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/garlic32.py +0 -0
  24. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/garlic64.py +0 -0
  25. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/http_path.py +0 -0
  26. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/ip4.py +0 -0
  27. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/ip6.py +0 -0
  28. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/ipcidr.py +0 -0
  29. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/memory.py +0 -0
  30. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/onion.py +0 -0
  31. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/onion3.py +0 -0
  32. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/uint16be.py +0 -0
  33. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/codecs/utf8.py +0 -0
  34. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/exceptions.py +0 -0
  35. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/multiaddr.py +0 -0
  36. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/resolvers/__init__.py +0 -0
  37. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/resolvers/base.py +0 -0
  38. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/resolvers/dns.py +0 -0
  39. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/transforms.py +0 -0
  40. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr/utils.py +0 -0
  41. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/dependency_links.txt +0 -0
  42. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/not-zip-safe +0 -0
  43. {multiaddr-0.0.12 → multiaddr-0.1.0}/multiaddr.egg-info/top_level.txt +0 -0
  44. {multiaddr-0.0.12 → multiaddr-0.1.0}/setup.cfg +0 -0
  45. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/__init__.py +0 -0
  46. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/test_resolvers.py +0 -0
  47. {multiaddr-0.0.12 → multiaddr-0.1.0}/tests/test_transforms.py +0 -0
@@ -3,6 +3,21 @@ History
3
3
 
4
4
  .. towncrier release notes start
5
5
 
6
+ py-multiaddr v0.1.0 (2025-10-27)
7
+ --------------------------------
8
+
9
+ Features
10
+ ~~~~~~~~
11
+
12
+ - Added the following protocols in reference with go-multiaddr
13
+
14
+ - SNI: 0x01C1
15
+ - NOISE: 0x01C6
16
+ - CERTHASH:
17
+ - WEBRTC:
18
+ - WEBRTC-DIRECT: (`#181 <https://github.com/multiformats/py-multiaddr/issues/181>`__)
19
+
20
+
6
21
  py-multiaddr v0.0.12 (2025-10-21)
7
22
  ---------------------------------
8
23
 
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiaddr
3
- Version: 0.0.12
3
+ Version: 0.1.0
4
4
  Summary: Python implementation of jbenet's multiaddr
5
5
  Author-email: Steven Buss <steven.buss@gmail.com>
6
6
  Maintainer: acul71
7
7
  Maintainer-email: pacrob <pacrob@protonmail.com>, Manu Sheel Gupta <manu@seeta.in>
8
8
  License: MIT License
9
9
  Project-URL: Homepage, https://github.com/multiformats/py-multiaddr
10
- Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.12
10
+ Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.1.0
11
11
  Keywords: multiaddr
12
12
  Classifier: Development Status :: 2 - Pre-Alpha
13
13
  Classifier: Intended Audience :: Developers
@@ -30,6 +30,8 @@ Requires-Dist: netaddr
30
30
  Requires-Dist: psutil
31
31
  Requires-Dist: py-cid>=0.3.1
32
32
  Requires-Dist: py-multicodec>=0.2.0
33
+ Requires-Dist: py-multibase
34
+ Requires-Dist: py-multihash
33
35
  Requires-Dist: trio-typing>=0.0.4
34
36
  Requires-Dist: trio>=0.26.0
35
37
  Requires-Dist: varint
@@ -2,4 +2,4 @@ from .multiaddr import Multiaddr # NOQA
2
2
 
3
3
  __author__ = "Steven Buss"
4
4
  __email__ = "steven.buss@gmail.com"
5
- __version__ = "0.0.12"
5
+ __version__ = "0.1.0"
@@ -0,0 +1,85 @@
1
+ from typing import Any
2
+
3
+ import multibase
4
+ import multihash
5
+
6
+ from ..codecs import CodecBase
7
+
8
+ SIZE = -1
9
+ IS_PATH = False
10
+
11
+
12
+ class Codec(CodecBase):
13
+ """
14
+ Codec for certificate hashes (certhash).
15
+
16
+ A certhash is a multihash of a certificate, encoded as a multibase string
17
+ using the 'base64url' encoding.
18
+ """
19
+
20
+ SIZE = SIZE
21
+ IS_PATH = IS_PATH
22
+
23
+ def validate(self, b: bytes) -> None:
24
+ """
25
+ Validates that the byte representation is a valid multihash.
26
+
27
+ Args:
28
+ b: The bytes to validate.
29
+
30
+ Raises:
31
+ ValueError: If the bytes cannot be decoded as a multihash.
32
+ """
33
+ try:
34
+ multihash.decode(b)
35
+ except Exception as e:
36
+ raise ValueError("Invalid certhash: not a valid multihash") from e
37
+
38
+ def to_bytes(self, proto: Any, string: str) -> bytes:
39
+ """
40
+ Converts the multibase string representation of a certhash to bytes.
41
+
42
+ This involves decoding the multibase string and then validating that
43
+ the resulting bytes are a valid multihash.
44
+
45
+ Args:
46
+ proto: The multiaddr protocol code (unused).
47
+ string: The string representation of the certhash.
48
+
49
+ Returns:
50
+ The raw multihash bytes.
51
+
52
+ Raises:
53
+ ValueError: If the string is not valid multibase or not a multihash.
54
+ """
55
+ try:
56
+ # Decode the multibase string to get the raw multihash bytes.
57
+ decoded_bytes = multibase.decode(string)
58
+ except Exception as e:
59
+ raise ValueError(f"Failed to decode multibase string: {string}") from e
60
+
61
+ # Validate that the decoded bytes are a valid multihash.
62
+ self.validate(decoded_bytes)
63
+ return decoded_bytes
64
+
65
+ def to_string(self, proto: Any, buf: bytes) -> str:
66
+ """
67
+ Converts the raw multihash bytes of a certhash to its string form.
68
+
69
+ This involves validating the bytes first and then encoding them as a
70
+ 'base64url' multibase string.
71
+
72
+ Args:
73
+ proto: The multiaddr protocol code (unused).
74
+ buf: The raw multihash bytes.
75
+
76
+ Returns:
77
+ The multibase string representation of the certhash.
78
+ """
79
+ # Validate the bytes before encoding.
80
+ self.validate(buf)
81
+
82
+ # Encode the bytes using base64url, which is standard for certhash.
83
+ # The result from `multibase.encode` is bytes, so we decode to a string.
84
+ encoded_string = multibase.encode("base64url", buf)
85
+ return encoded_string.decode("utf-8")
@@ -81,7 +81,10 @@ P_HTTP_PATH = 0x01E1
81
81
  P_SNI = 0x01C1
82
82
  P_NOISE = 0x01C6
83
83
  P_WEBTRANSPORT = 0x01D1
84
+ P_WEBRTC_DIRECT = 0x118
85
+ P_WEBRTC = 0x119
84
86
  P_MEMORY = 0x309
87
+ P_CERTHASH = 0x1D2
85
88
 
86
89
 
87
90
  class Protocol:
@@ -152,6 +155,8 @@ PROTOCOLS = [
152
155
  Protocol(P_DNS4, "dns4", "domain"),
153
156
  Protocol(P_DNS6, "dns6", "domain"),
154
157
  Protocol(P_DNSADDR, "dnsaddr", "domain"),
158
+ Protocol(P_SNI, "sni", "domain"),
159
+ Protocol(P_NOISE, "noise", None),
155
160
  Protocol(P_SCTP, "sctp", "uint16be"),
156
161
  Protocol(P_UDT, "udt", None),
157
162
  Protocol(P_UTP, "utp", None),
@@ -174,7 +179,10 @@ PROTOCOLS = [
174
179
  Protocol(P_P2P_CIRCUIT, "p2p-circuit", None),
175
180
  Protocol(P_WEBTRANSPORT, "webtransport", None),
176
181
  Protocol(P_UNIX, "unix", "fspath"),
182
+ Protocol(P_WEBRTC_DIRECT, "webrtc-direct", None),
183
+ Protocol(P_WEBRTC, "webrtc", None),
177
184
  Protocol(P_MEMORY, "memory", "memory"),
185
+ Protocol(P_CERTHASH, "certhash", "certhash"),
178
186
  ]
179
187
 
180
188
 
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multiaddr
3
- Version: 0.0.12
3
+ Version: 0.1.0
4
4
  Summary: Python implementation of jbenet's multiaddr
5
5
  Author-email: Steven Buss <steven.buss@gmail.com>
6
6
  Maintainer: acul71
7
7
  Maintainer-email: pacrob <pacrob@protonmail.com>, Manu Sheel Gupta <manu@seeta.in>
8
8
  License: MIT License
9
9
  Project-URL: Homepage, https://github.com/multiformats/py-multiaddr
10
- Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.0.12
10
+ Project-URL: Download, https://github.com/multiformats/py-multiaddr/tarball/0.1.0
11
11
  Keywords: multiaddr
12
12
  Classifier: Development Status :: 2 - Pre-Alpha
13
13
  Classifier: Intended Audience :: Developers
@@ -30,6 +30,8 @@ Requires-Dist: netaddr
30
30
  Requires-Dist: psutil
31
31
  Requires-Dist: py-cid>=0.3.1
32
32
  Requires-Dist: py-multicodec>=0.2.0
33
+ Requires-Dist: py-multibase
34
+ Requires-Dist: py-multihash
33
35
  Requires-Dist: trio-typing>=0.0.4
34
36
  Requires-Dist: trio>=0.26.0
35
37
  Requires-Dist: varint
@@ -19,6 +19,7 @@ multiaddr.egg-info/not-zip-safe
19
19
  multiaddr.egg-info/requires.txt
20
20
  multiaddr.egg-info/top_level.txt
21
21
  multiaddr/codecs/__init__.py
22
+ multiaddr/codecs/certhash.py
22
23
  multiaddr/codecs/cid.py
23
24
  multiaddr/codecs/domain.py
24
25
  multiaddr/codecs/fspath.py
@@ -5,6 +5,8 @@ netaddr
5
5
  psutil
6
6
  py-cid>=0.3.1
7
7
  py-multicodec>=0.2.0
8
+ py-multibase
9
+ py-multihash
8
10
  trio-typing>=0.0.4
9
11
  trio>=0.26.0
10
12
  varint
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "multiaddr"
7
- version = "0.0.12"
7
+ version = "0.1.0"
8
8
  description = "Python implementation of jbenet's multiaddr"
9
9
  readme = "README.rst"
10
10
  authors = [{ name = "Steven Buss", email = "steven.buss@gmail.com" }]
@@ -35,6 +35,8 @@ dependencies = [
35
35
  "psutil",
36
36
  "py-cid >= 0.3.1",
37
37
  "py-multicodec >= 0.2.0",
38
+ "py-multibase",
39
+ "py-multihash",
38
40
  "trio-typing>=0.0.4",
39
41
  "trio>=0.26.0",
40
42
  "varint",
@@ -42,7 +44,7 @@ dependencies = [
42
44
 
43
45
  [project.urls]
44
46
  Homepage = "https://github.com/multiformats/py-multiaddr"
45
- Download = "https://github.com/multiformats/py-multiaddr/tarball/0.0.12"
47
+ Download = "https://github.com/multiformats/py-multiaddr/tarball/0.1.0"
46
48
 
47
49
  [project.optional-dependencies]
48
50
  dev = [
@@ -135,7 +137,7 @@ name = "Removals"
135
137
  showcontent = true
136
138
 
137
139
  [tool.bumpversion]
138
- current_version = "0.0.12"
140
+ current_version = "0.1.0"
139
141
  parse = """
140
142
  (?P<major>\\d+)
141
143
  \\.(?P<minor>\\d+)
@@ -67,6 +67,8 @@ from multiaddr.protocols import (
67
67
  "/garlic32/566niximlxdzpanmn4qouucvua3k7neniwss47li5r6ugoertzu:80",
68
68
  "/garlic32/566niximlxdzpanmn4qouucvua3k7neniwss47li5r6ugoertzuq:-1",
69
69
  "/garlic32/566niximlxdzpanmn4qouucvua3k7neniwss47li5r6ugoertzu@",
70
+ "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy",
71
+ "/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/b2uaraocy6yrdblb4sfptaddgimjmmpy/certhash/zQmbWTwYGcmdyK9CYfNBcfs9nhZs17a6FQ4Y8oea278xx41",
70
72
  "/udp/1234/sctp",
71
73
  "/udp/1234/udt/1234",
72
74
  "/udp/1234/utp/1234",
@@ -125,10 +127,21 @@ def test_invalid(addr_str):
125
127
  "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
126
128
  "/unix/a/b/c/d/e",
127
129
  "/unix/stdio",
130
+ "/ip4/127.0.0.1/tcp/127/noise",
128
131
  "/ip4/1.2.3.4/tcp/80/unix/a/b/c/d/e/f",
129
132
  "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio",
130
133
  "/dns/example.com",
131
134
  "/dns4/موقع.وزارة-الاتصالات.مصر",
135
+ "/ip4/127.0.0.1/tcp/443/tls/sni/example.com/http/http-path/foo",
136
+ "/memory/4",
137
+ "/http-path/tmp%2Fbar",
138
+ "/http-path/tmp%2Fbar%2Fbaz",
139
+ "/http-path/foo",
140
+ "/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct",
141
+ "/ip4/127.0.0.1/tcp/127/webrtc-direct",
142
+ "/ip4/127.0.0.1/tcp/127/webrtc",
143
+ "/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g"
144
+ "/ip4/127.0.0.1/udp/9090/webrtc-direct/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
132
145
  ],
133
146
  ) # nopep8
134
147
  def test_valid(addr_str):
@@ -1,11 +1,13 @@
1
1
  import base64
2
2
  import os
3
3
 
4
+ import multibase
5
+ import multihash
4
6
  import pytest
5
7
  import varint
6
8
 
7
9
  from multiaddr import Multiaddr, exceptions, protocols
8
- from multiaddr.codecs import garlic32, garlic64, http_path, ipcidr, memory
10
+ from multiaddr.codecs import certhash, garlic32, garlic64, http_path, ipcidr, memory
9
11
  from multiaddr.exceptions import BinaryParseError, StringParseError
10
12
 
11
13
 
@@ -559,3 +561,65 @@ def test_ipcidr_invalid_bytes_inputs():
559
561
 
560
562
  with pytest.raises(ValueError):
561
563
  codec.validate(b"\x01\x02")
564
+
565
+
566
+ # --------CERT-HASH---------
567
+
568
+ VALID_MULTIHASH_BYTES = multihash.encode(b"hello world", "sha2-256")
569
+ VALID_CERTHASH_STRING = multibase.encode("base64url", VALID_MULTIHASH_BYTES).decode("utf-8")
570
+
571
+ INVALID_BYTES = b"this is not a multihash"
572
+ INVALID_CONTENT_STRING = multibase.encode("base64url", INVALID_BYTES).decode("utf-8")
573
+
574
+
575
+ def test_certhash_valid_roundtrip():
576
+ codec = certhash.Codec()
577
+ b = codec.to_bytes(None, VALID_CERTHASH_STRING)
578
+ assert isinstance(b, bytes)
579
+ assert b == VALID_MULTIHASH_BYTES
580
+
581
+
582
+ def test_certhash_invalid_multihash_bytes_raises():
583
+ """
584
+ Tests that calling to_string() with bytes that are not a valid
585
+ multihash raises a ValueError.
586
+ """
587
+ codec = certhash.Codec()
588
+ with pytest.raises(ValueError):
589
+ codec.to_string(None, INVALID_BYTES)
590
+
591
+
592
+ def test_certhash_valid_multibase_but_invalid_content_raises():
593
+ """
594
+ Tests that to_bytes() raises an error if the string is valid multibase
595
+ but its decoded content is not a valid multihash.
596
+ """
597
+ codec = certhash.Codec()
598
+ with pytest.raises(ValueError):
599
+ codec.to_bytes(None, INVALID_CONTENT_STRING)
600
+
601
+
602
+ def test_certhash_invalid_multibase_string_raises():
603
+ """
604
+ Tests that passing a string with an invalid multibase prefix or
605
+ encoding raises an error.
606
+ """
607
+ codec = certhash.Codec()
608
+ # 'z' is a valid multibase prefix, but the content is not valid base58.
609
+ invalid_string = "z-this-is-not-valid"
610
+ with pytest.raises(Exception): # Catches errors from the multibase library
611
+ codec.to_bytes(None, invalid_string)
612
+
613
+
614
+ def test_certhash_validate_function():
615
+ """
616
+ Directly tests the validate method.
617
+ """
618
+ codec = certhash.Codec()
619
+
620
+ # A valid multihash should not raise an error
621
+ codec.validate(VALID_MULTIHASH_BYTES)
622
+
623
+ # Invalid bytes should raise a ValueError
624
+ with pytest.raises(ValueError):
625
+ codec.validate(INVALID_BYTES)
@@ -1,7 +1,4 @@
1
- import pytest
2
-
3
1
  from multiaddr import Multiaddr
4
- from multiaddr.exceptions import StringParseError
5
2
  from multiaddr.utils import get_thin_waist_addresses
6
3
 
7
4
 
@@ -22,12 +19,6 @@ def test_specific_address_override_port():
22
19
  assert addrs == [Multiaddr("/ip4/123.123.123.123/tcp/100")]
23
20
 
24
21
 
25
- def test_ignore_non_thin_waist():
26
- # Should raise StringParseError for unknown protocol (e.g. /webrtc)
27
- with pytest.raises(StringParseError):
28
- Multiaddr("/ip4/123.123.123.123/udp/1234/webrtc")
29
-
30
-
31
22
  def test_ipv4_wildcard():
32
23
  input_addr = Multiaddr("/ip4/0.0.0.0/tcp/1234")
33
24
  addrs = get_thin_waist_addresses(input_addr)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes