Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions go.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ flowchart LR
chainlink-common --> grpc-proxy
chainlink-common --> libocr
click chainlink-common href "https://github.com/smartcontractkit/chainlink-common"
chainlink-common/keystore --> chainlink-common
chainlink-common/keystore --> chainlink-evm
click chainlink-common/keystore href "https://github.com/smartcontractkit/chainlink-common"
chainlink-common/pkg/chipingress
click chainlink-common/pkg/chipingress href "https://github.com/smartcontractkit/chainlink-common"
chainlink-common/pkg/monitoring --> chainlink-common
click chainlink-common/pkg/monitoring href "https://github.com/smartcontractkit/chainlink-common"
chainlink-common/pkg/values
click chainlink-common/pkg/values href "https://github.com/smartcontractkit/chainlink-common"
chainlink-evm --> chainlink-common/keystore
click chainlink-evm href "https://github.com/smartcontractkit/chainlink-evm"
chainlink-evm/gethwrappers
click chainlink-evm/gethwrappers href "https://github.com/smartcontractkit/chainlink-evm"
chainlink-framework/capabilities
click chainlink-framework/capabilities href "https://github.com/smartcontractkit/chainlink-framework"
chainlink-framework/chains --> chainlink-common
chainlink-framework/chains --> chainlink-framework/multinode
click chainlink-framework/chains href "https://github.com/smartcontractkit/chainlink-framework"
chainlink-framework/metrics
click chainlink-framework/metrics href "https://github.com/smartcontractkit/chainlink-framework"
chainlink-framework/multinode
click chainlink-framework/multinode href "https://github.com/smartcontractkit/chainlink-framework"
chainlink-protos/billing/go --> chainlink-protos/workflows/go
click chainlink-protos/billing/go href "https://github.com/smartcontractkit/chainlink-protos"
chainlink-protos/cre/go --> chain-selectors
Expand All @@ -33,14 +46,27 @@ flowchart LR
click chainlink-protos/node-platform href "https://github.com/smartcontractkit/chainlink-protos"
chainlink-protos/storage-service
click chainlink-protos/storage-service href "https://github.com/smartcontractkit/chainlink-protos"
chainlink-protos/svr
click chainlink-protos/svr href "https://github.com/smartcontractkit/chainlink-protos"
chainlink-protos/workflows/go
click chainlink-protos/workflows/go href "https://github.com/smartcontractkit/chainlink-protos"
chainlink-tron/relayer
click chainlink-tron/relayer href "https://github.com/smartcontractkit/chainlink-tron"
freeport
click freeport href "https://github.com/smartcontractkit/freeport"
go-sumtype2
click go-sumtype2 href "https://github.com/smartcontractkit/go-sumtype2"
grpc-proxy
click grpc-proxy href "https://github.com/smartcontractkit/grpc-proxy"
libocr
libocr --> go-sumtype2
click libocr href "https://github.com/smartcontractkit/libocr"
smdkg --> libocr
smdkg --> tdh2/go/tdh2
click smdkg href "https://github.com/smartcontractkit/smdkg"
tdh2/go/tdh2
click tdh2/go/tdh2 href "https://github.com/smartcontractkit/tdh2"
wsrpc
click wsrpc href "https://github.com/smartcontractkit/wsrpc"

subgraph chainlink-common-repo[chainlink-common]
chainlink-common
Expand All @@ -51,16 +77,31 @@ flowchart LR
end
click chainlink-common-repo href "https://github.com/smartcontractkit/chainlink-common"

subgraph chainlink-evm-repo[chainlink-evm]
chainlink-evm
chainlink-evm/gethwrappers
end
click chainlink-evm-repo href "https://github.com/smartcontractkit/chainlink-evm"

subgraph chainlink-framework-repo[chainlink-framework]
chainlink-framework/capabilities
chainlink-framework/chains
chainlink-framework/metrics
chainlink-framework/multinode
end
click chainlink-framework-repo href "https://github.com/smartcontractkit/chainlink-framework"

subgraph chainlink-protos-repo[chainlink-protos]
chainlink-protos/billing/go
chainlink-protos/cre/go
chainlink-protos/linking-service/go
chainlink-protos/node-platform
chainlink-protos/storage-service
chainlink-protos/svr
chainlink-protos/workflows/go
end
click chainlink-protos-repo href "https://github.com/smartcontractkit/chainlink-protos"

classDef outline stroke-dasharray:6,fill:none;
class chainlink-common-repo,chainlink-protos-repo outline
class chainlink-common-repo,chainlink-evm-repo,chainlink-framework-repo,chainlink-protos-repo outline
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.22.0
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/scylladb/go-reflectx v1.0.1
Expand Down Expand Up @@ -131,7 +132,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.2.0 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.65.0 // indirect
Expand Down
7 changes: 4 additions & 3 deletions keystore/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
gethcrypto "github.com/ethereum/go-ethereum/crypto"

"github.com/smartcontractkit/chainlink-common/keystore"
"github.com/smartcontractkit/chainlink-common/keystore/scrypt"
)

func TestKeystore_CreateDeleteReadKeys(t *testing.T) {
Expand Down Expand Up @@ -114,7 +115,7 @@ func TestKeystore_CreateDeleteReadKeys(t *testing.T) {
for _, tt := range tt {
t.Run(tt.name, func(t *testing.T) {
storage := keystore.NewMemoryStorage()
ks, err := keystore.LoadKeystore(ctx, storage, "test-password", keystore.WithScryptParams(keystore.FastScryptParams))
ks, err := keystore.LoadKeystore(ctx, storage, "test-password", keystore.WithScryptParams(scrypt.FastScryptParams))
require.NoError(t, err)
for _, op := range tt.keyOps {
switch op.op {
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestKeystore_ConcurrentCreateAndRead(t *testing.T) {

ctx := context.Background()
st := keystore.NewMemoryStorage()
ks, err := keystore.LoadKeystore(ctx, st, "test", keystore.WithScryptParams(keystore.FastScryptParams))
ks, err := keystore.LoadKeystore(ctx, st, "test", keystore.WithScryptParams(scrypt.FastScryptParams))
require.NoError(t, err)

const (
Expand Down Expand Up @@ -217,7 +218,7 @@ func TestKeystore_ExportImport(t *testing.T) {
t.Run("export and import", func(t *testing.T) {
exportParams := keystore.EncryptionParams{
Password: "export-pass",
ScryptParams: keystore.FastScryptParams,
ScryptParams: scrypt.FastScryptParams,
}
_, err = ks1.CreateKeys(t.Context(), keystore.CreateKeysRequest{
Keys: []keystore.CreateKeyRequest{
Expand Down
3 changes: 2 additions & 1 deletion keystore/core_keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/keystore"
"github.com/smartcontractkit/chainlink-common/keystore/scrypt"
)

func TestCoreKeystore(t *testing.T) {
ctx := t.Context()

ks, err := keystore.LoadKeystore(t.Context(), keystore.NewMemoryStorage(), "test-password", keystore.WithScryptParams(keystore.FastScryptParams))
ks, err := keystore.LoadKeystore(t.Context(), keystore.NewMemoryStorage(), "test-password", keystore.WithScryptParams(scrypt.FastScryptParams))
require.NoError(t, err)
coreKs := keystore.NewCoreKeystore(ks)

Expand Down
47 changes: 47 additions & 0 deletions keystore/corekeys/aptoskey/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package aptoskey

import (
"encoding/hex"

"github.com/ethereum/go-ethereum/accounts/keystore"

"github.com/smartcontractkit/chainlink-common/keystore/internal"
"github.com/smartcontractkit/chainlink-common/keystore/scrypt"
)

const keyTypeIdentifier = "Aptos"

// FromEncryptedJSON gets key from json and password
func FromEncryptedJSON(keyJSON []byte, password string) (Key, error) {
return internal.FromEncryptedJSON(
keyTypeIdentifier,
keyJSON,
password,
adulteratedPassword,
func(_ internal.EncryptedKeyExport, rawPrivKey internal.Raw) (Key, error) {
return KeyFor(rawPrivKey), nil
},
)
}

// ToEncryptedJSON returns encrypted JSON representing key
func (key Key) ToEncryptedJSON(password string, scryptParams scrypt.ScryptParams) (export []byte, err error) {
return internal.ToEncryptedJSON(
keyTypeIdentifier,
key,
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) internal.EncryptedKeyExport {
return internal.EncryptedKeyExport{
KeyType: id,
PublicKey: hex.EncodeToString(key.pubKey),
Crypto: cryptoJSON,
}
},
)
}

func adulteratedPassword(password string) string {
return "aptoskey" + password
}
19 changes: 19 additions & 0 deletions keystore/corekeys/aptoskey/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package aptoskey

import (
"testing"

"github.com/smartcontractkit/chainlink-common/keystore/corekeys"
)

func TestAptosKeys_ExportImport(t *testing.T) {
corekeys.RunKeyExportImportTestcase(t, createKey, decryptKey)
}

func createKey() (corekeys.KeyType, error) {
return New()
}

func decryptKey(keyJSON []byte, password string) (corekeys.KeyType, error) {
return FromEncryptedJSON(keyJSON, password)
}
87 changes: 87 additions & 0 deletions keystore/corekeys/aptoskey/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package aptoskey

import (
"crypto"
"crypto/ed25519"
crypto_rand "crypto/rand"
"fmt"
"io"

"golang.org/x/crypto/sha3"

"github.com/smartcontractkit/chainlink-common/keystore/internal"
)

// Key represents Aptos key
type Key struct {
// TODO: store initial Account() derivation to support key rotation
raw internal.Raw
signFn func(io.Reader, []byte, crypto.SignerOpts) ([]byte, error)
pubKey ed25519.PublicKey
}

func KeyFor(raw internal.Raw) Key {
privKey := ed25519.NewKeyFromSeed(internal.Bytes(raw))
pubKey := privKey.Public().(ed25519.PublicKey)
return Key{
raw: raw,
signFn: privKey.Sign,
pubKey: pubKey,
}
}

// New creates new Key
func New() (Key, error) {
return newFrom(crypto_rand.Reader)
}

// MustNewInsecure return Key if no error
func MustNewInsecure(reader io.Reader) Key {
key, err := newFrom(reader)
if err != nil {
panic(err)
}
return key
}

// newFrom creates new Key from a provided random reader
func newFrom(reader io.Reader) (Key, error) {
pub, priv, err := ed25519.GenerateKey(reader)
if err != nil {
return Key{}, err
}
return Key{
raw: internal.NewRaw(priv.Seed()),
signFn: priv.Sign,
pubKey: pub,
}, nil
}

// ID gets Key ID
func (key Key) ID() string {
return key.PublicKeyStr()
}

// https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md#long
func (key Key) Account() string {
authKey := sha3.Sum256(append([]byte(key.pubKey), 0x00))
return fmt.Sprintf("%064x", authKey)
}

// GetPublic get Key's public key
func (key Key) GetPublic() ed25519.PublicKey {
return key.pubKey
}

// PublicKeyStr returns hex encoded public key
func (key Key) PublicKeyStr() string {
return fmt.Sprintf("%064x", key.pubKey)
}

// Raw returns the seed from private key
func (key Key) Raw() internal.Raw { return key.raw }

// Sign is used to sign a message
func (key Key) Sign(msg []byte) ([]byte, error) {
return key.signFn(crypto_rand.Reader, msg, crypto.Hash(0)) // no specific hash function used
}
19 changes: 19 additions & 0 deletions keystore/corekeys/aptoskey/key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package aptoskey

import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/keystore/internal"
)

func TestAptosKey(t *testing.T) {
bytes, err := hex.DecodeString("f0d07ab448018b2754475f9a3b580218b0675a1456aad96ad607c7bbd7d9237b")
require.NoError(t, err)
k := KeyFor(internal.NewRaw(bytes))
assert.Equal(t, "2acd605efc181e2af8a0b8c0686a5e12578efa1253d15a235fa5e5ad970c4b29", k.PublicKeyStr())
assert.Equal(t, "69d8b07f5945185873c622ea66873b0e1fb921de7b94d904d3ef9be80770682e", k.Account())
}
47 changes: 47 additions & 0 deletions keystore/corekeys/cosmoskey/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cosmoskey

import (
"encoding/hex"

"github.com/ethereum/go-ethereum/accounts/keystore"

"github.com/smartcontractkit/chainlink-common/keystore/internal"
"github.com/smartcontractkit/chainlink-common/keystore/scrypt"
)

const keyTypeIdentifier = "Cosmos"

// FromEncryptedJSON gets key from json and password
func FromEncryptedJSON(keyJSON []byte, password string) (Key, error) {
return internal.FromEncryptedJSON(
keyTypeIdentifier,
keyJSON,
password,
adulteratedPassword,
func(_ internal.EncryptedKeyExport, rawPrivKey internal.Raw) (Key, error) {
return KeyFor(rawPrivKey), nil
},
)
}

// ToEncryptedJSON returns encrypted JSON representing key
func (key Key) ToEncryptedJSON(password string, scryptParams scrypt.ScryptParams) (export []byte, err error) {
return internal.ToEncryptedJSON(
keyTypeIdentifier,
key,
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) internal.EncryptedKeyExport {
return internal.EncryptedKeyExport{
KeyType: id,
PublicKey: hex.EncodeToString(key.PublicKey().Bytes()),
Crypto: cryptoJSON,
}
},
)
}

func adulteratedPassword(password string) string {
return "cosmoskey" + password
}
Loading
Loading