|
@ -31,12 +31,12 @@ var _ = binary.RegisterInterface( |
|
|
//-------------------------------------
|
|
|
//-------------------------------------
|
|
|
|
|
|
|
|
|
// Implements PubKey
|
|
|
// Implements PubKey
|
|
|
type PubKeyEd25519 []byte |
|
|
|
|
|
|
|
|
type PubKeyEd25519 [32]byte |
|
|
|
|
|
|
|
|
func (pubKey PubKeyEd25519) IsNil() bool { return false } |
|
|
func (pubKey PubKeyEd25519) IsNil() bool { return false } |
|
|
|
|
|
|
|
|
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
|
|
|
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
|
|
|
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey) } |
|
|
|
|
|
|
|
|
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) } |
|
|
|
|
|
|
|
|
// TODO: Consider returning a reason for failure, or logging a runtime type mismatch.
|
|
|
// TODO: Consider returning a reason for failure, or logging a runtime type mismatch.
|
|
|
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool { |
|
|
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool { |
|
@ -44,25 +44,23 @@ func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool { |
|
|
if !ok { |
|
|
if !ok { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
pubKeyBytes := new([32]byte) |
|
|
|
|
|
copy(pubKeyBytes[:], pubKey) |
|
|
|
|
|
sigBytes := new([64]byte) |
|
|
|
|
|
copy(sigBytes[:], sig) |
|
|
|
|
|
return ed25519.Verify(pubKeyBytes, msg, sigBytes) |
|
|
|
|
|
|
|
|
pubKeyBytes := [32]byte(pubKey) |
|
|
|
|
|
sigBytes := [64]byte(sig) |
|
|
|
|
|
return ed25519.Verify(&pubKeyBytes, msg, &sigBytes) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// For use with golang/crypto/nacl/box
|
|
|
// For use with golang/crypto/nacl/box
|
|
|
// If error, returns nil.
|
|
|
// If error, returns nil.
|
|
|
func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte { |
|
|
func (pubKey PubKeyEd25519) ToCurve25519() *[32]byte { |
|
|
keyEd25519, keyCurve25519 := new([32]byte), new([32]byte) |
|
|
|
|
|
copy(keyEd25519[:], pubKey) |
|
|
|
|
|
ok := extra25519.PublicKeyToCurve25519(keyCurve25519, keyEd25519) |
|
|
|
|
|
|
|
|
keyCurve25519, pubKeyBytes := new([32]byte), [32]byte(pubKey) |
|
|
|
|
|
ok := extra25519.PublicKeyToCurve25519(keyCurve25519, &pubKeyBytes) |
|
|
if !ok { |
|
|
if !ok { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
return keyCurve25519 |
|
|
return keyCurve25519 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// redundant: compiler does it for us
|
|
|
func (pubKey PubKeyEd25519) ValidateBasic() error { |
|
|
func (pubKey PubKeyEd25519) ValidateBasic() error { |
|
|
if len(pubKey) != ed25519.PublicKeySize { |
|
|
if len(pubKey) != ed25519.PublicKeySize { |
|
|
return errors.New("Invalid PubKeyEd25519 key size") |
|
|
return errors.New("Invalid PubKeyEd25519 key size") |
|
@ -71,18 +69,18 @@ func (pubKey PubKeyEd25519) ValidateBasic() error { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (pubKey PubKeyEd25519) String() string { |
|
|
func (pubKey PubKeyEd25519) String() string { |
|
|
return Fmt("PubKeyEd25519{%X}", []byte(pubKey)) |
|
|
|
|
|
|
|
|
return Fmt("PubKeyEd25519{%X}", pubKey[:]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Must return the full bytes in hex.
|
|
|
// Must return the full bytes in hex.
|
|
|
// Used for map keying, etc.
|
|
|
// Used for map keying, etc.
|
|
|
func (pubKey PubKeyEd25519) KeyString() string { |
|
|
func (pubKey PubKeyEd25519) KeyString() string { |
|
|
return Fmt("%X", []byte(pubKey)) |
|
|
|
|
|
|
|
|
return Fmt("%X", pubKey[:]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (pubKey PubKeyEd25519) Equals(other PubKey) bool { |
|
|
func (pubKey PubKeyEd25519) Equals(other PubKey) bool { |
|
|
if _, ok := other.(PubKeyEd25519); ok { |
|
|
|
|
|
return bytes.Equal(pubKey, other.(PubKeyEd25519)) |
|
|
|
|
|
|
|
|
if otherEd, ok := other.(PubKeyEd25519); ok { |
|
|
|
|
|
return bytes.Equal(pubKey[:], otherEd[:]) |
|
|
} else { |
|
|
} else { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|