Skip to content

Commit 494efd0

Browse files
add support for certhash
1 parent e0eb8cd commit 494efd0

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.17
44

55
require (
66
github.com/ipfs/go-cid v0.0.7
7+
github.com/multiformats/go-multibase v0.0.3
78
github.com/multiformats/go-multihash v0.0.14
89
github.com/multiformats/go-varint v0.0.6
910
github.com/stretchr/testify v1.7.0
@@ -16,7 +17,6 @@ require (
1617
github.com/mr-tron/base58 v1.1.3 // indirect
1718
github.com/multiformats/go-base32 v0.0.3 // indirect
1819
github.com/multiformats/go-base36 v0.1.0 // indirect
19-
github.com/multiformats/go-multibase v0.0.3 // indirect
2020
github.com/pmezard/go-difflib v1.0.0 // indirect
2121
github.com/spaolacci/murmur3 v1.1.0 // indirect
2222
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 // indirect

multiaddr_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func TestConstructFails(t *testing.T) {
7474
"/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa",
7575
"/ip4/127.0.0.1/tcp",
7676
"/ip4/127.0.0.1/quic/1234",
77+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash",
7778
"/ip4/127.0.0.1/ipfs",
7879
"/ip4/127.0.0.1/ipfs/tcp",
7980
"/ip4/127.0.0.1/p2p",
@@ -158,6 +159,8 @@ func TestConstructSucceeds(t *testing.T) {
158159
"/ip4/127.0.0.1/tcp/1234/",
159160
"/ip4/127.0.0.1/udp/1234/quic",
160161
"/ip4/127.0.0.1/udp/1234/quic/webtransport",
162+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ",
163+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ/certhash/zt1Zv2yaY",
161164
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
162165
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
163166
"/ip4/127.0.0.1/ipfs/k2k4r8oqamigqdo6o7hsbfwd45y70oyynp98usk7zmyfrzpqxh1pohl7",
@@ -543,6 +546,8 @@ func TestRoundTrip(t *testing.T) {
543546
"/ip4/127.0.0.1/tcp/123/tls",
544547
"/ip4/127.0.0.1/udp/123",
545548
"/ip4/127.0.0.1/udp/123/ip6/::",
549+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ",
550+
"/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/zt1Zv2yaZ/certhash/zt1Zv2yaY",
546551
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
547552
"/p2p/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP/unix/a/b/c",
548553
} {

protocols.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
P_IPCIDR = 0x002B
1717
P_QUIC = 0x01CC
1818
P_WEBTRANSPORT = 0x01D1
19+
P_CERTHASH = 0x01D2
1920
P_SCTP = 0x0084
2021
P_CIRCUIT = 0x0122
2122
P_UDT = 0x012D
@@ -184,6 +185,13 @@ var (
184185
Code: P_WEBTRANSPORT,
185186
VCode: CodeToVarint(P_WEBTRANSPORT),
186187
}
188+
protoCERTHASH = Protocol{
189+
Name: "certhash",
190+
Code: P_CERTHASH,
191+
VCode: CodeToVarint(P_CERTHASH),
192+
Size: LengthPrefixedVarSize,
193+
Transcoder: TranscoderCertHash,
194+
}
187195
protoHTTP = Protocol{
188196
Name: "http",
189197
Code: P_HTTP,
@@ -264,6 +272,7 @@ func init() {
264272
protoUDT,
265273
protoQUIC,
266274
protoWEBTRANSPORT,
275+
protoCERTHASH,
267276
protoHTTP,
268277
protoHTTPS,
269278
protoP2P,

transcoders.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/ipfs/go-cid"
14+
"github.com/multiformats/go-multibase"
1415
mh "github.com/multiformats/go-multihash"
1516
)
1617

@@ -373,3 +374,14 @@ func dnsStB(s string) ([]byte, error) {
373374
func dnsBtS(b []byte) (string, error) {
374375
return string(b), nil
375376
}
377+
378+
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, nil)
379+
380+
func certHashStB(s string) ([]byte, error) {
381+
_, data, err := multibase.Decode(s)
382+
return data, err
383+
}
384+
385+
func certHashBtS(b []byte) (string, error) {
386+
return multibase.Encode(multibase.Base58BTC, b)
387+
}

0 commit comments

Comments
 (0)