github.com/Finschia/finschia-sdk@v0.48.1/crypto/keys/secp256r1/pubkey.go (about)

     1  package secp256r1
     2  
     3  import (
     4  	tmcrypto "github.com/Finschia/ostracon/crypto"
     5  	"github.com/gogo/protobuf/proto"
     6  
     7  	ecdsa "github.com/Finschia/finschia-sdk/crypto/keys/internal/ecdsa"
     8  	cryptotypes "github.com/Finschia/finschia-sdk/crypto/types"
     9  )
    10  
    11  // String implements proto.Message interface.
    12  func (m *PubKey) String() string {
    13  	return m.Key.String(name)
    14  }
    15  
    16  // Bytes implements SDK PubKey interface.
    17  func (m *PubKey) Bytes() []byte {
    18  	if m == nil {
    19  		return nil
    20  	}
    21  	return m.Key.Bytes()
    22  }
    23  
    24  // Equals implements SDK PubKey interface.
    25  func (m *PubKey) Equals(other cryptotypes.PubKey) bool {
    26  	pk2, ok := other.(*PubKey)
    27  	if !ok {
    28  		return false
    29  	}
    30  	return m.Key.Equal(&pk2.Key.PublicKey)
    31  }
    32  
    33  // Address implements SDK PubKey interface.
    34  func (m *PubKey) Address() tmcrypto.Address {
    35  	return m.Key.Address(proto.MessageName(m))
    36  }
    37  
    38  // Type returns key type name. Implements SDK PubKey interface.
    39  func (m *PubKey) Type() string {
    40  	return name
    41  }
    42  
    43  // VerifySignature implements SDK PubKey interface.
    44  func (m *PubKey) VerifySignature(msg []byte, sig []byte) bool {
    45  	return m.Key.VerifySignature(msg, sig)
    46  }
    47  
    48  type ecdsaPK struct {
    49  	ecdsa.PubKey
    50  }
    51  
    52  // Size implements proto.Marshaler interface
    53  func (pk *ecdsaPK) Size() int {
    54  	if pk == nil {
    55  		return 0
    56  	}
    57  	return pubKeySize
    58  }
    59  
    60  // Unmarshal implements proto.Marshaler interface
    61  func (pk *ecdsaPK) Unmarshal(bz []byte) error {
    62  	return pk.PubKey.Unmarshal(bz, secp256r1, pubKeySize)
    63  }