-
Notifications
You must be signed in to change notification settings - Fork 24
[ARCH-334] Pre-requisites for EVM support #1664
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
Open
connorwstein
wants to merge
9
commits into
main
Choose a base branch
from
ARCH-334-evm-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+210
−1
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f693385
Wip
connorwstein a822f15
Switch to get for more consistent naming
connorwstein 2c5771a
Merge branch 'main' into ARCH-334-evm-support
connorwstein 24a4712
mod tidy
connorwstein c5bdae6
Merge branch 'ARCH-334-evm-support' of github.com:smartcontractkit/ch…
connorwstein 335e0da
Merge branch 'main' into ARCH-334-evm-support
connorwstein 53c9124
Fix test
connorwstein 41d7f33
Remove dup fn
connorwstein 322eb0b
Merge branch 'main' into ARCH-334-evm-support
connorwstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,99 @@ | ||
| package ragep2p | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/ed25519" | ||
| "errors" | ||
|
|
||
| commonks "github.com/smartcontractkit/chainlink-common/keystore" | ||
| ragetypes "github.com/smartcontractkit/libocr/ragep2p/types" | ||
| ) | ||
|
|
||
| var _ ragetypes.PeerKeyring = (*PeerKeyring)(nil) | ||
|
|
||
| const ( | ||
| PeerKeyringPrefix = "ragep2p_peer" | ||
| ) | ||
|
|
||
| type PeerKeyring struct { | ||
| ks commonks.Keystore | ||
| keyPath commonks.KeyPath | ||
| pubKey ragetypes.PeerPublicKey | ||
| } | ||
|
|
||
| func (k *PeerKeyring) KeyPath() commonks.KeyPath { | ||
| return k.keyPath | ||
| } | ||
|
|
||
| func (k *PeerKeyring) PublicKey() ragetypes.PeerPublicKey { | ||
| return k.pubKey | ||
| } | ||
|
|
||
| func (k *PeerKeyring) PeerID() (string, error) { | ||
| peerID, err := ragetypes.PeerIDFromPublicKey(ed25519.PublicKey(k.pubKey[:])) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return peerID.String(), nil | ||
| } | ||
|
|
||
| func (k *PeerKeyring) MustPeerID() string { | ||
| peerID, err := k.PeerID() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return peerID | ||
| } | ||
|
|
||
| func (k *PeerKeyring) Sign(msg []byte) ([]byte, error) { | ||
| resp, err := k.ks.Sign(context.Background(), commonks.SignRequest{ | ||
| KeyName: k.keyPath.String(), | ||
| Data: msg, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return resp.Signature, nil | ||
| } | ||
|
|
||
| func CreatePeerKeyring(ctx context.Context, ks commonks.Keystore, name string) (*PeerKeyring, error) { | ||
| keyPath := commonks.NewKeyPath(PeerKeyringPrefix, name) | ||
| createReq := commonks.CreateKeysRequest{ | ||
| Keys: []commonks.CreateKeyRequest{ | ||
| {KeyName: keyPath.String(), KeyType: commonks.Ed25519}, | ||
| }, | ||
| } | ||
| resp, err := ks.CreateKeys(ctx, createReq) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if len(resp.Keys) != 1 { | ||
| return nil, errors.New("expected 1 key") | ||
| } | ||
| var peerPubKey ragetypes.PeerPublicKey | ||
| copy(peerPubKey[:], resp.Keys[0].KeyInfo.PublicKey) | ||
| return &PeerKeyring{ks: ks, keyPath: keyPath, pubKey: peerPubKey}, nil | ||
| } | ||
|
|
||
| func GetPeerKeyrings(ctx context.Context, ks commonks.Keystore, keyRingNames []string) ([]*PeerKeyring, error) { | ||
| var keyNames []string | ||
| if len(keyRingNames) > 0 { | ||
| for _, name := range keyRingNames { | ||
| keyNames = append(keyNames, commonks.NewKeyPath(PeerKeyringPrefix, name).String()) | ||
| } | ||
| } | ||
| keys, err := ks.GetKeys(ctx, commonks.GetKeysRequest{ | ||
| KeyNames: keyNames, | ||
| }) | ||
| if err != nil { | ||
| return nil, errors.Join(errors.New("failed to list peer keyrings"), err) | ||
| } | ||
| var peerKeyrings []*PeerKeyring | ||
| for _, key := range keys.Keys { | ||
| keyPath := commonks.NewKeyPathFromString(key.KeyInfo.Name) | ||
| var peerPubKey ragetypes.PeerPublicKey | ||
| copy(peerPubKey[:], key.KeyInfo.PublicKey) | ||
| peerKeyrings = append(peerKeyrings, &PeerKeyring{ks: ks, keyPath: keyPath, pubKey: peerPubKey}) | ||
| } | ||
| return peerKeyrings, nil | ||
| } |
This file contains hidden or 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,57 @@ | ||
| package ragep2p_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| commonks "github.com/smartcontractkit/chainlink-common/keystore" | ||
| "github.com/smartcontractkit/chainlink-common/keystore/ragep2p" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestPeerKeyring(t *testing.T) { | ||
| storage := commonks.NewMemoryStorage() | ||
| ctx := t.Context() | ||
| ks, err := commonks.LoadKeystore(ctx, storage, "test-password") | ||
| require.NoError(t, err) | ||
| peerKeyring, err := ragep2p.CreatePeerKeyring(ctx, ks, "test-peer-keyring") | ||
| require.NoError(t, err) | ||
| msg := []byte("test-message") | ||
| signature, err := peerKeyring.Sign(msg) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, signature) | ||
|
|
||
| peerKeyrings, err := ragep2p.GetPeerKeyrings(ctx, ks, []string{"test-peer-keyring"}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, len(peerKeyrings)) | ||
| require.Equal(t, peerKeyring.PublicKey(), peerKeyrings[0].PublicKey()) | ||
| require.Equal(t, peerKeyring.KeyPath(), peerKeyrings[0].KeyPath()) | ||
|
|
||
| // List all works | ||
| peerKeyRings, err := ragep2p.GetPeerKeyrings(ctx, ks, []string{}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, len(peerKeyRings)) | ||
|
|
||
| // List non-existent errors. | ||
| peerKeyRings, err = ragep2p.GetPeerKeyrings(ctx, ks, []string{"non-existent-peer-keyring"}) | ||
| require.Error(t, err) | ||
|
|
||
| // Can create multiple. | ||
| peerKeyring2, err := ragep2p.CreatePeerKeyring(ctx, ks, "test-peer-keyring-2") | ||
| require.NoError(t, err) | ||
| msg2 := []byte("test-message-2") | ||
| signature2, err := peerKeyring2.Sign(msg2) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, signature2) | ||
|
|
||
| // List by name works. | ||
| peerKeyRings, err = ragep2p.GetPeerKeyrings(ctx, ks, []string{"test-peer-keyring-2"}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, len(peerKeyRings)) | ||
| require.Equal(t, peerKeyring2.PublicKey(), peerKeyRings[0].PublicKey()) | ||
| require.Equal(t, peerKeyring2.KeyPath(), peerKeyRings[0].KeyPath()) | ||
|
|
||
| // List all works with multiple. | ||
| peerKeyRings, err = ragep2p.GetPeerKeyrings(ctx, ks, []string{}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 2, len(peerKeyRings)) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.