github.com/annchain/OG@v0.0.9/p2p/enr/schema.go (about)

     1  package enr
     2  
     3  // An IdentityScheme is capable of verifying record Signatures and
     4  // deriving node addresses.
     5  type IdentityScheme interface {
     6  	Verify(r *Record, sig []byte) error
     7  	NodeAddr(r *Record) []byte
     8  }
     9  
    10  // SchemeMap is a registry of named identity schemes.
    11  type SchemeMap map[string]IdentityScheme
    12  
    13  func (m SchemeMap) Verify(r *Record, sig []byte) error {
    14  	s := m[r.IdentityScheme()]
    15  	if s == nil {
    16  		return ErrInvalidSig
    17  	}
    18  	return s.Verify(r, sig)
    19  }
    20  
    21  func (m SchemeMap) NodeAddr(r *Record) []byte {
    22  	s := m[r.IdentityScheme()]
    23  	if s == nil {
    24  		return nil
    25  	}
    26  	return s.NodeAddr(r)
    27  }