Files
evm/utils/utilstest/key.go
zeekay 8bc9dd01a8 Fix CI: Go version and script permissions
- Change Go version from 1.24.6 to 1.22.8 (stable version)
- Ensure all build scripts have executable permissions
- Fix covdata issue by using stable Go version
- CI should now pass all checks
2025-09-19 05:56:47 +00:00

34 lines
864 B
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package utilstest
import (
"crypto/ecdsa"
"crypto/rand"
"testing"
"github.com/luxfi/crypto"
"github.com/luxfi/geth/common"
"github.com/stretchr/testify/require"
)
// Key contains an ecdsa private key field as well as an address field
// obtained from converting the ecdsa public key.
type Key struct {
Address common.Address
PrivateKey *ecdsa.PrivateKey
}
// NewKey generates a new key pair and returns a pointer to a [Key].
func NewKey(t *testing.T) *Key {
t.Helper()
privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
require.NoError(t, err)
cryptoAddr := crypto.PubkeyToAddress(privateKeyECDSA.PublicKey)
return &Key{
Address: common.BytesToAddress(cryptoAddr[:]),
PrivateKey: privateKeyECDSA,
}
}