-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BCI-2953] Initial Aptos keystore (#13564)
* chain type to include aptos * aptos key ed25519 implementation * add aptos to keystore master * added exports for keys * removed sdk dependency * updated go mod * Added tests for account sdk deps * added aptos keystore * added interface assertion to solana * added aptos keyring * added aptos keystore mocks * added aptos key controller & router * Added aptos keys command * added aptos keystore e2e tests * Added Aptos network ORM test for key * Added aptos ocr2 keys support * Revert "Added Aptos network ORM test for key" This reverts commit 444fe95. * Added Aptos export functionality * Modified Aptos Accounts for key rotation * added aptos keystore to orm validation * Addded Change logs * Updated keys implementation to remove address * Revert "updated go mod" This reverts commit a8f7e84. * Update changeset * Updated GraphQL to include Aptos * Linting fixes * added aptos configs for keystore * Changed Aptos config to RawConfig * Added Mock file for general config * using *bool type for aptos enabled * added debug for error * Fixed tests + added ORM * Added Test Scripts * Updated type of raw config * update all packages go mod tidy * update all packages go mod * Update core/services/chainlink/config.go Co-authored-by: Jordan Krage <[email protected]> * Removed Address in key * Fixed merge conflicts * nit changes based on reviews * Added typecast check for keyring * Added config type cast check * make generate update version * update validation method * update config validation * Removed Pointer type for RawConfig * Updated Validate with better error message * Added Error config * Update struct of RawConfig * removed uncessary config validation * Added missing starknet keystore tests * added styling feedback * Update core/services/keystore/keys/aptoskey/account.go Co-authored-by: Jordan Krage <[email protected]> * Removed empty array table for config * fixed lint --------- Co-authored-by: Jordan Krage <[email protected]>
- Loading branch information
1 parent
0b7d2c4
commit 2c2ca6a
Showing
45 changed files
with
1,737 additions
and
10 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,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.