@@ -25,7 +25,7 @@ const (
25
25
// [Multihash]: https://multiformats.io/multihash/
26
26
// [IPNS Name]: https://specs.ipfs.tech/ipns/ipns-record/#ipns-name
27
27
type Name struct {
28
- src string
28
+ multihash string // binary Multihash without multibase envelope
29
29
}
30
30
31
31
// NameFromString creates a [Name] from the given IPNS Name in its [string representation].
@@ -57,7 +57,7 @@ func NameFromRoutingKey(data []byte) (Name, error) {
57
57
58
58
// NameFromPeer creates a [Name] from the given [peer.ID].
59
59
func NameFromPeer (pid peer.ID ) Name {
60
- return Name {src : string (pid )}
60
+ return Name {multihash : string (pid )}
61
61
}
62
62
63
63
// NameFromCid creates a [Name] from the given [cid.Cid].
@@ -66,7 +66,7 @@ func NameFromCid(c cid.Cid) (Name, error) {
66
66
if code != mc .Libp2pKey {
67
67
return Name {}, fmt .Errorf ("CID codec %q is not allowed for IPNS Names, use %q instead" , code , mc .Libp2pKey )
68
68
}
69
- return Name {src : string (c .Hash ())}, nil
69
+ return Name {multihash : string (c .Hash ())}, nil
70
70
}
71
71
72
72
// RoutingKey returns the binary IPNS Routing Key for the given [Name]. Note that
@@ -77,14 +77,14 @@ func NameFromCid(c cid.Cid) (Name, error) {
77
77
func (n Name ) RoutingKey () []byte {
78
78
var buffer bytes.Buffer
79
79
buffer .WriteString (NamespacePrefix )
80
- buffer .WriteString (n .src ) // Note: we append raw multihash bytes (no multibase)
80
+ buffer .WriteString (n .multihash ) // Note: we append raw multihash bytes (no multibase)
81
81
return buffer .Bytes ()
82
82
}
83
83
84
84
// Cid returns [Name] encoded as a [cid.Cid] of the public key. If the IPNS Name
85
85
// is invalid (e.g., empty), this will return the empty Cid.
86
86
func (n Name ) Cid () cid.Cid {
87
- m , err := mh .Cast ([]byte (n .src ))
87
+ m , err := mh .Cast ([]byte (n .multihash ))
88
88
if err != nil {
89
89
return cid .Undef
90
90
}
@@ -93,7 +93,7 @@ func (n Name) Cid() cid.Cid {
93
93
94
94
// Peer returns [Name] as a [peer.ID].
95
95
func (n Name ) Peer () peer.ID {
96
- return peer .ID (n .src )
96
+ return peer .ID (n .multihash )
97
97
}
98
98
99
99
// String returns the human-readable IPNS Name, encoded as a CIDv1 with libp2p-key
@@ -132,7 +132,7 @@ func (n Name) MarshalJSON() ([]byte, error) {
132
132
133
133
// Equal returns whether the records are equal.
134
134
func (n Name ) Equal (other Name ) bool {
135
- return n .src == other .src
135
+ return n .multihash == other .multihash
136
136
}
137
137
138
138
// AsPath returns the IPNS Name as a [path.Path] prefixed by [path.IPNSNamespace].
0 commit comments