-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e15704
commit c8f841d
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"crypto": { | ||
"cipher": "aes-128-ctr", | ||
"cipherparams": { | ||
"iv": "6087dab2f9fdbbfaddc31a909735c1e6" | ||
}, | ||
"ciphertext": "5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46", | ||
"kdf": "pbkdf2", | ||
"kdfparams": { | ||
"c": 262144, | ||
"dklen": 32, | ||
"prf": "hmac-sha256", | ||
"salt": "ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd" | ||
}, | ||
"mac": "517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2" | ||
}, | ||
"id": "3198bc9c-6672-5ab3-d995-4942343ae5b6", | ||
"version": 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package signerv2_test | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/signerv2" | ||
"github.com/Layr-Labs/eigensdk-go/testutils" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPrivateKeySignerFn(t *testing.T) { | ||
privateKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" | ||
privateKey, err := crypto.HexToECDSA(privateKeyHex) | ||
require.NoError(t, err) | ||
chainID := big.NewInt(1) | ||
|
||
signer, err := signerv2.PrivateKeySignerFn(privateKey, chainID) | ||
require.NoError(t, err) | ||
|
||
address := crypto.PubkeyToAddress(privateKey.PublicKey) | ||
tx := types.NewTx(&types.DynamicFeeTx{ | ||
Nonce: 0, | ||
Value: big.NewInt(0), | ||
ChainID: chainID, | ||
Data: common.Hex2Bytes("6057361d00000000000000000000000000000000000000000000000000000000000f4240"), | ||
}) | ||
signedTx, err := signer(address, tx) | ||
require.NoError(t, err) | ||
|
||
// Verify the sender address of the signed transaction | ||
from, err := types.Sender(types.LatestSignerForChainID(chainID), signedTx) | ||
require.NoError(t, err) | ||
require.Equal(t, address, from) | ||
} | ||
|
||
func TestKeyStoreSignerFn(t *testing.T) { | ||
keystorePath := "mockdata/dummy.key.json" | ||
keystorePassword := "testpassword" | ||
chainID := big.NewInt(1) | ||
signer, err := signerv2.KeyStoreSignerFn(keystorePath, keystorePassword, chainID) | ||
require.NoError(t, err) | ||
|
||
privateKey, err := crypto.HexToECDSA("7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d") | ||
require.NoError(t, err) | ||
|
||
address := crypto.PubkeyToAddress(privateKey.PublicKey) | ||
tx := types.NewTx(&types.DynamicFeeTx{ | ||
Nonce: 0, | ||
Value: big.NewInt(0), | ||
ChainID: chainID, | ||
Data: common.Hex2Bytes("6057361d00000000000000000000000000000000000000000000000000000000000f4240"), | ||
}) | ||
signedTx, err := signer(address, tx) | ||
require.NoError(t, err) | ||
|
||
// Verify the sender address of the signed transaction | ||
from, err := types.Sender(types.LatestSignerForChainID(chainID), signedTx) | ||
require.NoError(t, err) | ||
require.Equal(t, address, from) | ||
} | ||
|
||
func TestWeb3SignerFn(t *testing.T) { | ||
anvilC, err := testutils.StartAnvilContainer(testutils.GetDefaultTestConfig().AnvilStateFileName) | ||
require.NoError(t, err) | ||
|
||
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") | ||
require.NoError(t, err) | ||
|
||
signer, err := signerv2.Web3SignerFn(anvilHttpEndpoint) | ||
require.NoError(t, err) | ||
|
||
privateKey, err := crypto.HexToECDSA("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") | ||
require.NoError(t, err) | ||
anvilChainID := big.NewInt(31337) | ||
address := crypto.PubkeyToAddress(privateKey.PublicKey) | ||
tx := types.NewTx(&types.DynamicFeeTx{ | ||
Nonce: 0, | ||
Value: big.NewInt(0), | ||
To: &address, | ||
ChainID: anvilChainID, | ||
Data: common.Hex2Bytes("6057361d00000000000000000000000000000000000000000000000000000000000f4240"), | ||
}) | ||
|
||
signedTx, err := signer(address, tx) | ||
require.NoError(t, err) | ||
|
||
// Verify the sender address of the signed transaction | ||
from, err := types.Sender(types.LatestSignerForChainID(anvilChainID), signedTx) | ||
require.NoError(t, err) | ||
require.Equal(t, address, from) | ||
} |