-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[BCI-2953] Initial Aptos keystore #13564
Merged
Merged
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
04aa1ed
chain type to include aptos
yongkangchia fb33e75
aptos key ed25519 implementation
yongkangchia bf0d6cd
add aptos to keystore master
yongkangchia 794f319
added exports for keys
yongkangchia 176ee2e
removed sdk dependency
yongkangchia 12c35d5
updated go mod
yongkangchia 0bc9679
Added tests for account sdk deps
yongkangchia 1aafd02
added aptos keystore
yongkangchia d0f516a
added interface assertion to solana
yongkangchia 684d3a6
added aptos keyring
yongkangchia 3cc7061
added aptos keystore mocks
yongkangchia faf6717
added aptos key controller & router
yongkangchia 53e5391
Added aptos keys command
yongkangchia cea7964
added aptos keystore e2e tests
yongkangchia 360a792
Added Aptos network ORM test for key
yongkangchia a3db03d
Added aptos ocr2 keys support
yongkangchia cb34e55
Revert "Added Aptos network ORM test for key"
yongkangchia e66b7d8
Added Aptos export functionality
yongkangchia f438e06
Modified Aptos Accounts for key rotation
yongkangchia 038017f
added aptos keystore to orm validation
yongkangchia 87bcc83
Addded Change logs
yongkangchia 56d2f07
Updated keys implementation to remove address
yongkangchia 56bf81b
Revert "updated go mod"
yongkangchia 1ff903d
Update changeset
yongkangchia d81f7a4
Updated GraphQL to include Aptos
yongkangchia ce41adc
Linting fixes
yongkangchia 76a3b82
added aptos configs for keystore
yongkangchia a4599a5
Changed Aptos config to RawConfig
yongkangchia ae9bfb2
Added Mock file for general config
yongkangchia bee29ec
using *bool type for aptos enabled
yongkangchia df8ecfa
added debug for error
yongkangchia 7e2940c
Fixed tests + added ORM
yongkangchia 37d7f67
Added Test Scripts
yongkangchia 053d843
Updated type of raw config
yongkangchia 71431cf
update all packages go mod tidy
yongkangchia 7f5228a
update all packages go mod
yongkangchia af9b808
Update core/services/chainlink/config.go
yongkangchia c0b1203
Removed Address in key
yongkangchia 52984ad
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia 26d66da
Fixed merge conflicts
yongkangchia 5484ddb
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia fe40501
nit changes based on reviews
yongkangchia 22f72df
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia e840f5d
Added typecast check for keyring
yongkangchia 3ad8c9e
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia eace378
Added config type cast check
yongkangchia b2af408
make generate update version
yongkangchia 1fd2ca6
update validation method
yongkangchia 4ae0848
update config validation
yongkangchia badba0e
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia b0beb7a
Removed Pointer type for RawConfig
yongkangchia 8e9d51e
Updated Validate with better error message
yongkangchia c2ebf42
Added Error config
yongkangchia 4adc736
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia f704847
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia 9247f70
Update struct of RawConfig
yongkangchia 4090a87
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia 05d87de
removed uncessary config validation
yongkangchia 6903844
Added missing starknet keystore tests
yongkangchia 2ca056b
added styling feedback
yongkangchia 62712ba
Update core/services/keystore/keys/aptoskey/account.go
yongkangchia 202519a
Removed empty array table for config
yongkangchia 4e92975
fixed lint
yongkangchia af142e5
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia ab26fc0
Merge branch 'develop' into BCI-2953-Aptos-Keystore
yongkangchia 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 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,5 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
#changed Added Aptos Keystore to Core. This includes Aptos Key which uses ED25519, Keystore, Relevant tests |
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
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,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/smartcontractkit/chainlink-common/pkg/utils" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/aptoskey" | ||
"github.com/smartcontractkit/chainlink/v2/core/web/presenters" | ||
) | ||
|
||
type AptosKeyPresenter struct { | ||
JAID | ||
presenters.AptosKeyResource | ||
} | ||
|
||
// RenderTable implements TableRenderer | ||
func (p AptosKeyPresenter) RenderTable(rt RendererTable) error { | ||
headers := []string{"ID", "Aptos Public Key"} | ||
rows := [][]string{p.ToRow()} | ||
|
||
if _, err := rt.Write([]byte("🔑 Aptos Keys\n")); err != nil { | ||
return err | ||
} | ||
renderList(headers, rows, rt.Writer) | ||
|
||
return utils.JustError(rt.Write([]byte("\n"))) | ||
} | ||
|
||
func (p *AptosKeyPresenter) ToRow() []string { | ||
row := []string{ | ||
p.ID, | ||
p.PubKey, | ||
} | ||
|
||
return row | ||
} | ||
|
||
type AptosKeyPresenters []AptosKeyPresenter | ||
|
||
// RenderTable implements TableRenderer | ||
func (ps AptosKeyPresenters) RenderTable(rt RendererTable) error { | ||
headers := []string{"ID", "Aptos Public Key"} | ||
rows := [][]string{} | ||
|
||
for _, p := range ps { | ||
rows = append(rows, p.ToRow()) | ||
} | ||
|
||
if _, err := rt.Write([]byte("🔑 Aptos Keys\n")); err != nil { | ||
return err | ||
} | ||
renderList(headers, rows, rt.Writer) | ||
|
||
return utils.JustError(rt.Write([]byte("\n"))) | ||
} | ||
|
||
func NewAptosKeysClient(s *Shell) KeysClient { | ||
return newKeysClient[aptoskey.Key, AptosKeyPresenter, AptosKeyPresenters]("Aptos", s) | ||
} |
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,175 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/utils" | ||
"github.com/smartcontractkit/chainlink/v2/core/cmd" | ||
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest" | ||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/aptoskey" | ||
"github.com/smartcontractkit/chainlink/v2/core/web/presenters" | ||
) | ||
|
||
func TestAptosKeyPresenter_RenderTable(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
id = "1" | ||
pubKey = "somepubkey" | ||
buffer = bytes.NewBufferString("") | ||
r = cmd.RendererTable{Writer: buffer} | ||
) | ||
|
||
p := cmd.AptosKeyPresenter{ | ||
JAID: cmd.JAID{ID: id}, | ||
AptosKeyResource: presenters.AptosKeyResource{ | ||
JAID: presenters.NewJAID(id), | ||
PubKey: pubKey, | ||
}, | ||
} | ||
|
||
// Render a single resource | ||
require.NoError(t, p.RenderTable(r)) | ||
|
||
output := buffer.String() | ||
assert.Contains(t, output, id) | ||
assert.Contains(t, output, pubKey) | ||
|
||
// Render many resources | ||
buffer.Reset() | ||
ps := cmd.AptosKeyPresenters{p} | ||
require.NoError(t, ps.RenderTable(r)) | ||
|
||
output = buffer.String() | ||
assert.Contains(t, output, id) | ||
assert.Contains(t, output, pubKey) | ||
} | ||
|
||
func TestShell_AptosKeys(t *testing.T) { | ||
app := startNewApplicationV2(t, nil) | ||
ks := app.GetKeyStore().Aptos() | ||
cleanup := func() { | ||
ctx := context.Background() | ||
keys, err := ks.GetAll() | ||
require.NoError(t, err) | ||
for _, key := range keys { | ||
require.NoError(t, utils.JustError(ks.Delete(ctx, key.ID()))) | ||
} | ||
requireAptosKeyCount(t, app, 0) | ||
} | ||
|
||
t.Run("ListAptosKeys", func(tt *testing.T) { | ||
defer cleanup() | ||
ctx := testutils.Context(t) | ||
client, r := app.NewShellAndRenderer() | ||
key, err := app.GetKeyStore().Aptos().Create(ctx) | ||
require.NoError(t, err) | ||
requireAptosKeyCount(t, app, 1) | ||
assert.Nil(t, cmd.NewAptosKeysClient(client).ListKeys(cltest.EmptyCLIContext())) | ||
require.Equal(t, 1, len(r.Renders)) | ||
keys := *r.Renders[0].(*cmd.AptosKeyPresenters) | ||
assert.True(t, key.PublicKeyStr() == keys[0].PubKey) | ||
}) | ||
|
||
t.Run("CreateAptosKey", func(tt *testing.T) { | ||
defer cleanup() | ||
client, _ := app.NewShellAndRenderer() | ||
require.NoError(t, cmd.NewAptosKeysClient(client).CreateKey(nilContext)) | ||
keys, err := app.GetKeyStore().Aptos().GetAll() | ||
require.NoError(t, err) | ||
require.Len(t, keys, 1) | ||
}) | ||
|
||
t.Run("DeleteAptosKey", func(tt *testing.T) { | ||
defer cleanup() | ||
ctx := testutils.Context(t) | ||
client, _ := app.NewShellAndRenderer() | ||
key, err := app.GetKeyStore().Aptos().Create(ctx) | ||
require.NoError(t, err) | ||
requireAptosKeyCount(t, app, 1) | ||
set := flag.NewFlagSet("test", 0) | ||
flagSetApplyFromAction(cmd.NewAptosKeysClient(client).DeleteKey, set, "aptos") | ||
|
||
require.NoError(tt, set.Set("yes", "true")) | ||
|
||
strID := key.ID() | ||
err = set.Parse([]string{strID}) | ||
require.NoError(t, err) | ||
c := cli.NewContext(nil, set, nil) | ||
err = cmd.NewAptosKeysClient(client).DeleteKey(c) | ||
require.NoError(t, err) | ||
requireAptosKeyCount(t, app, 0) | ||
}) | ||
|
||
t.Run("ImportExportAptosKey", func(tt *testing.T) { | ||
defer cleanup() | ||
defer deleteKeyExportFile(t) | ||
ctx := testutils.Context(t) | ||
client, _ := app.NewShellAndRenderer() | ||
|
||
_, err := app.GetKeyStore().Aptos().Create(ctx) | ||
require.NoError(t, err) | ||
|
||
keys := requireAptosKeyCount(t, app, 1) | ||
key := keys[0] | ||
keyName := keyNameForTest(t) | ||
|
||
// Export test invalid id | ||
set := flag.NewFlagSet("test Aptos export", 0) | ||
flagSetApplyFromAction(cmd.NewAptosKeysClient(client).ExportKey, set, "aptos") | ||
|
||
require.NoError(tt, set.Parse([]string{"0"})) | ||
require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) | ||
require.NoError(tt, set.Set("output", keyName)) | ||
|
||
c := cli.NewContext(nil, set, nil) | ||
err = cmd.NewAptosKeysClient(client).ExportKey(c) | ||
require.Error(t, err, "Error exporting") | ||
require.Error(t, utils.JustError(os.Stat(keyName))) | ||
|
||
// Export test | ||
set = flag.NewFlagSet("test Aptos export", 0) | ||
flagSetApplyFromAction(cmd.NewAptosKeysClient(client).ExportKey, set, "aptos") | ||
|
||
require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) | ||
require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) | ||
require.NoError(tt, set.Set("output", keyName)) | ||
|
||
c = cli.NewContext(nil, set, nil) | ||
|
||
require.NoError(t, cmd.NewAptosKeysClient(client).ExportKey(c)) | ||
require.NoError(t, utils.JustError(os.Stat(keyName))) | ||
|
||
require.NoError(t, utils.JustError(app.GetKeyStore().Aptos().Delete(ctx, key.ID()))) | ||
requireAptosKeyCount(t, app, 0) | ||
|
||
set = flag.NewFlagSet("test Aptos import", 0) | ||
flagSetApplyFromAction(cmd.NewAptosKeysClient(client).ImportKey, set, "aptos") | ||
|
||
require.NoError(tt, set.Parse([]string{keyName})) | ||
require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) | ||
c = cli.NewContext(nil, set, nil) | ||
require.NoError(t, cmd.NewAptosKeysClient(client).ImportKey(c)) | ||
|
||
requireAptosKeyCount(t, app, 1) | ||
}) | ||
} | ||
|
||
func requireAptosKeyCount(t *testing.T, app chainlink.Application, length int) []aptoskey.Key { | ||
t.Helper() | ||
keys, err := app.GetKeyStore().Aptos().GetAll() | ||
require.NoError(t, err) | ||
require.Len(t, keys, length) | ||
return keys | ||
} |
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
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -159,6 +159,9 @@ APIKey = 'key' | |
|
||
[[Starknet]] | ||
|
||
[[Aptos]] | ||
Enabled = 1 | ||
|
||
[OCR2] | ||
Enabled = true | ||
|
||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is formatted this way due to one test