Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating ed25519.go to Go 1.20 #46

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions crypto/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func ParseAddress(hrp, saddr string) (PublicKey, error) {
if len(pk) < PublicKeyLen {
return EmptyPublicKey, ErrInvalidPublicKey
}
var p PublicKey
copy(p[:], pk[:PublicKeyLen])
return p, nil
return PublicKey(pk[:PublicKeyLen]), nil
}

// GeneratePrivateKey returns a Ed25519 PrivateKey.
Expand All @@ -74,19 +72,13 @@ func GeneratePrivateKey() (PrivateKey, error) {
if err != nil {
return EmptyPrivateKey, err
}
var pk PrivateKey
copy(pk[:], k)
return pk, nil
return PrivateKey(k), nil
}

// PublicKey returns a PublicKey associated with the Ed25519 PrivateKey p.
// The PublicKey is the last 32 bytes of p.
func (p PrivateKey) PublicKey() PublicKey {
// TODO: https://github.com/ava-labs/hypersdk/issues/23
rpk := p[PrivateKeySeedLen:]
var pk PublicKey
copy(pk[:], rpk)
return pk
return PublicKey(p[PrivateKeySeedLen:])
}

// ToHex converts a PrivateKey to a hex string.
Expand All @@ -111,17 +103,13 @@ func LoadKey(filename string) (PrivateKey, error) {
if len(bytes) != ed25519.PrivateKeySize {
return EmptyPrivateKey, ErrInvalidPrivateKey
}
var pk PrivateKey
copy(pk[:], bytes)
return pk, nil
return PrivateKey(bytes), nil
}

// Sign returns a valid signature for msg using pk.
func Sign(msg []byte, pk PrivateKey) Signature {
sig := ed25519.Sign(pk[:], msg)
var s Signature
copy(s[:], sig)
return s
return Signature(sig)
}

// Verify returns whether s is a valid signature of msg by p.
Expand All @@ -139,7 +127,5 @@ func HexToKey(key string) (PrivateKey, error) {
if len(bytes) != ed25519.PrivateKeySize {
return EmptyPrivateKey, ErrInvalidPrivateKey
}
var pk PrivateKey
copy(pk[:], bytes)
return pk, nil
return PrivateKey(bytes), nil
}