diff --git a/ipns/name.go b/ipns/name.go index c1ef506a38..e76a3ae33d 100644 --- a/ipns/name.go +++ b/ipns/name.go @@ -25,7 +25,7 @@ const ( // [Multihash]: https://multiformats.io/multihash/ // [IPNS Name]: https://specs.ipfs.tech/ipns/ipns-record/#ipns-name type Name struct { - src string + multihash string // binary Multihash without multibase envelope } // NameFromString creates a [Name] from the given IPNS Name in its [string representation]. @@ -57,7 +57,7 @@ func NameFromRoutingKey(data []byte) (Name, error) { // NameFromPeer creates a [Name] from the given [peer.ID]. func NameFromPeer(pid peer.ID) Name { - return Name{src: string(pid)} + return Name{multihash: string(pid)} } // NameFromCid creates a [Name] from the given [cid.Cid]. @@ -66,7 +66,7 @@ func NameFromCid(c cid.Cid) (Name, error) { if code != mc.Libp2pKey { return Name{}, fmt.Errorf("CID codec %q is not allowed for IPNS Names, use %q instead", code, mc.Libp2pKey) } - return Name{src: string(c.Hash())}, nil + return Name{multihash: string(c.Hash())}, nil } // RoutingKey returns the binary IPNS Routing Key for the given [Name]. Note that @@ -77,14 +77,14 @@ func NameFromCid(c cid.Cid) (Name, error) { func (n Name) RoutingKey() []byte { var buffer bytes.Buffer buffer.WriteString(NamespacePrefix) - buffer.WriteString(n.src) // Note: we append raw multihash bytes (no multibase) + buffer.WriteString(n.multihash) // Note: we append raw multihash bytes (no multibase) return buffer.Bytes() } // Cid returns [Name] encoded as a [cid.Cid] of the public key. If the IPNS Name // is invalid (e.g., empty), this will return the empty Cid. func (n Name) Cid() cid.Cid { - m, err := mh.Cast([]byte(n.src)) + m, err := mh.Cast([]byte(n.multihash)) if err != nil { return cid.Undef } @@ -93,7 +93,7 @@ func (n Name) Cid() cid.Cid { // Peer returns [Name] as a [peer.ID]. func (n Name) Peer() peer.ID { - return peer.ID(n.src) + return peer.ID(n.multihash) } // String returns the human-readable IPNS Name, encoded as a CIDv1 with libp2p-key @@ -132,7 +132,7 @@ func (n Name) MarshalJSON() ([]byte, error) { // Equal returns whether the records are equal. func (n Name) Equal(other Name) bool { - return n.src == other.src + return n.multihash == other.multihash } // AsPath returns the IPNS Name as a [path.Path] prefixed by [path.IPNSNamespace].