@@ -133,28 +133,27 @@ func createCborDataForIpnsEntry(e *pb.IpnsEntry) ([]byte, error) {
133
133
// Validates validates the given IPNS entry against the given public key.
134
134
func Validate (pk ic.PubKey , entry * pb.IpnsEntry ) error {
135
135
// Check the ipns record signature with the public key
136
-
137
- // Check v2 signature if it's available
138
- if entry .GetSignatureV2 () != nil {
139
- sig2Data , err := ipnsEntryDataForSigV2 (entry )
140
- if err != nil {
141
- return fmt .Errorf ("could not compute signature data: %w" , err )
142
- }
143
- if ok , err := pk .Verify (sig2Data , entry .GetSignatureV2 ()); err != nil || ! ok {
144
- return ErrSignature
145
- }
146
-
147
- // TODO: If we switch from pb.IpnsEntry to a more generic IpnsRecord type then perhaps we should only check
148
- // this if there is no v1 signature. In the meanwhile this helps avoid some potential rough edges around people
149
- // checking the entry fields instead of doing CBOR decoding everywhere.
150
- if err := validateCborDataMatchesPbData (entry ); err != nil {
151
- return err
152
- }
153
- } else {
136
+ if entry .GetSignatureV2 () == nil {
154
137
// always error if no valid signature could be found
155
138
return ErrSignature
156
139
}
157
140
141
+ sig2Data , err := ipnsEntryDataForSigV2 (entry )
142
+ if err != nil {
143
+ return fmt .Errorf ("could not compute signature data: %w" , err )
144
+ }
145
+ if ok , err := pk .Verify (sig2Data , entry .GetSignatureV2 ()); err != nil || ! ok {
146
+ return ErrSignature
147
+ }
148
+
149
+ // TODO: If we switch from pb.IpnsEntry to a more generic IpnsRecord type then perhaps we should only check
150
+ // this if there is no v1 signature. In the meanwhile this helps avoid some potential rough edges around people
151
+ // checking the entry fields instead of doing CBOR decoding everywhere.
152
+ // See https://github.com/ipfs/go-ipns/pull/42 for next steps here
153
+ if err := validateCborDataMatchesPbData (entry ); err != nil {
154
+ return err
155
+ }
156
+
158
157
eol , err := GetEOL (entry )
159
158
if err != nil {
160
159
return err
0 commit comments