github.com/ethersphere/bee/v2@v2.2.0/pkg/soc/validator.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package soc
     6  
     7  import (
     8  	"bytes"
     9  
    10  	"github.com/ethersphere/bee/v2/pkg/swarm"
    11  )
    12  
    13  // Valid checks if the chunk is a valid single-owner chunk.
    14  func Valid(ch swarm.Chunk) bool {
    15  	s, err := FromChunk(ch)
    16  	if err != nil {
    17  		return false
    18  	}
    19  
    20  	// disperse replica validation
    21  	if bytes.Equal(s.owner, swarm.ReplicasOwner) && !bytes.Equal(s.WrappedChunk().Address().Bytes()[1:32], s.id[1:32]) {
    22  		return false
    23  	}
    24  
    25  	address, err := s.Address()
    26  	if err != nil {
    27  		return false
    28  	}
    29  	return ch.Address().Equal(address)
    30  }