Skip to content

Commit 8c1d32a

Browse files
committed
refactor(ipns) Name.src → Name.multihash
1 parent 3501551 commit 8c1d32a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ipns/name.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
// [Multihash]: https://multiformats.io/multihash/
2626
// [IPNS Name]: https://specs.ipfs.tech/ipns/ipns-record/#ipns-name
2727
type Name struct {
28-
src string
28+
multihash string // binary Multihash without multibase envelope
2929
}
3030

3131
// NameFromString creates a [Name] from the given IPNS Name in its [string representation].
@@ -57,7 +57,7 @@ func NameFromRoutingKey(data []byte) (Name, error) {
5757

5858
// NameFromPeer creates a [Name] from the given [peer.ID].
5959
func NameFromPeer(pid peer.ID) Name {
60-
return Name{src: string(pid)}
60+
return Name{multihash: string(pid)}
6161
}
6262

6363
// NameFromCid creates a [Name] from the given [cid.Cid].
@@ -66,7 +66,7 @@ func NameFromCid(c cid.Cid) (Name, error) {
6666
if code != mc.Libp2pKey {
6767
return Name{}, fmt.Errorf("CID codec %q is not allowed for IPNS Names, use %q instead", code, mc.Libp2pKey)
6868
}
69-
return Name{src: string(c.Hash())}, nil
69+
return Name{multihash: string(c.Hash())}, nil
7070
}
7171

7272
// RoutingKey returns the binary IPNS Routing Key for the given [Name]. Note that
@@ -77,14 +77,14 @@ func NameFromCid(c cid.Cid) (Name, error) {
7777
func (n Name) RoutingKey() []byte {
7878
var buffer bytes.Buffer
7979
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)
8181
return buffer.Bytes()
8282
}
8383

8484
// Cid returns [Name] encoded as a [cid.Cid] of the public key. If the IPNS Name
8585
// is invalid (e.g., empty), this will return the empty Cid.
8686
func (n Name) Cid() cid.Cid {
87-
m, err := mh.Cast([]byte(n.src))
87+
m, err := mh.Cast([]byte(n.multihash))
8888
if err != nil {
8989
return cid.Undef
9090
}
@@ -93,7 +93,7 @@ func (n Name) Cid() cid.Cid {
9393

9494
// Peer returns [Name] as a [peer.ID].
9595
func (n Name) Peer() peer.ID {
96-
return peer.ID(n.src)
96+
return peer.ID(n.multihash)
9797
}
9898

9999
// String returns the human-readable IPNS Name, encoded as a CIDv1 with libp2p-key
@@ -132,7 +132,7 @@ func (n Name) MarshalJSON() ([]byte, error) {
132132

133133
// Equal returns whether the records are equal.
134134
func (n Name) Equal(other Name) bool {
135-
return n.src == other.src
135+
return n.multihash == other.multihash
136136
}
137137

138138
// AsPath returns the IPNS Name as a [path.Path] prefixed by [path.IPNSNamespace].

0 commit comments

Comments
 (0)